Nektar++
Driver.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Driver.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Base class for Drivers
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <SolverUtils/Driver.h>
36
37using namespace std;
38
39namespace Nektar
40{
41namespace SolverUtils
42{
43
46 "Nonlinear", eNonlinear),
48 "Direct", eDirect),
50 "Adjoint", eAdjoint),
52 "EvolutionOperator", "TransientGrowth", eTransientGrowth),
54 "EvolutionOperator", "SkewSymmetric", eSkewSymmetric),
56 "EvolutionOperator", "AdaptiveSFD", eAdaptiveSFD)};
59 "Nonlinear");
60std::string Driver::driverDefault =
62 "Standard");
63
64/**
65 *
66 */
68{
69 static DriverFactory instance;
70 return instance;
71}
72
73/**
74 *
75 */
78 : m_comm(pSession->GetComm()), m_session(pSession), m_graph(pGraph)
79{
80}
81
82/**
83 *
84 */
86
87{
88}
89
90/**
91 *
92 */
93void Driver::v_InitObject(ostream &out)
94{
95 try
96 {
97 // Retrieve the equation system to solve.
98 ASSERTL0(m_session->DefinesSolverInfo("EqType"),
99 "EqType SolverInfo tag must be defined.");
100 std::string vEquation = m_session->GetSolverInfo("EqType");
101 if (m_session->DefinesSolverInfo("SolverType"))
102 {
103 vEquation = m_session->GetSolverInfo("SolverType");
104 }
105
106 // Check such a module exists for this equation.
107 ASSERTL0(
108 GetEquationSystemFactory().ModuleExists(vEquation),
109 "EquationSystem '" + vEquation +
110 "' is not defined.\n"
111 "Ensure equation name is correct and module is compiled.\n");
112
113 // Retrieve the type of evolution operator to use
114 /// @todo At the moment this is Navier-Stokes specific - generalise?
116 m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
117 "EvolutionOperator");
118
121 ? 2
122 : 1);
123
125
126 // Set the AdvectiveType tag and create EquationSystem objects.
127 switch (m_EvolutionOperator)
128 {
129 case eNonlinear:
130 m_session->SetTag("AdvectiveType", "Convective");
132 vEquation, m_session, m_graph);
133 break;
134 case eDirect:
135 m_session->SetTag("AdvectiveType", "Linearised");
137 vEquation, m_session, m_graph);
138 break;
139 case eAdjoint:
140 m_session->SetTag("AdvectiveType", "Adjoint");
142 vEquation, m_session, m_graph);
143 break;
144 case eTransientGrowth:
145 // forward timestepping
146 m_session->SetTag("AdvectiveType", "Linearised");
148 vEquation, m_session, m_graph);
149
150 // backward timestepping
151 m_session->SetTag("AdvectiveType", "Adjoint");
153 vEquation, m_session, m_graph);
154 break;
155 case eSkewSymmetric:
156 m_session->SetTag("AdvectiveType", "SkewSymmetric");
158 vEquation, m_session, m_graph);
159 break;
160 case eAdaptiveSFD:
161 {
162 // Coupling SFD method and Arnoldi algorithm
163 // For having 2 equation systems defined into 2 different
164 // session files (with the mesh into a file named 'session'.gz)
165 string LinNSCondFile;
166 vector<string> LinNSFilename;
167
168 // assume that the conditions file is the last
169 // filename on intiialisation and so copy all other
170 // files to new session. This will include the mesh
171 // file and possibly the optimsaiton file
172 for (int i = 0; i < m_session->GetFilenames().size() - 1; ++i)
173 {
174 LinNSFilename.push_back(m_session->GetFilenames()[i]);
175 }
176
177 LinNSCondFile = m_session->GetSessionName();
178 LinNSCondFile += "_LinNS.xml";
179 LinNSFilename.push_back(LinNSCondFile);
180
181 char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
182 nullptr};
184 1, argv, LinNSFilename, m_comm);
185
188
189 // For running stability analysis
190 session_LinNS->SetTag("AdvectiveType", "Linearised");
192 vEquation, session_LinNS, graph_linns);
193
194 // For running the SFD method on the nonlinear problem
195 m_session->SetTag("AdvectiveType", "Convective");
197 vEquation, m_session, m_graph);
198 }
199 break;
200 default:
201 ASSERTL0(false, "Unrecognised evolution operator.");
202 }
203 }
204 catch (int e)
205 {
206 ASSERTL0(e == -1, "No such class class defined.");
207 out << "An error occurred during driver initialisation." << endl;
208 }
209}
210
211} // namespace SolverUtils
212} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
Provides a generic Factory class.
Definition: NekFactory.hpp:105
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
LibUtilities::SessionReaderSharedPtr session_LinNS
Coupling between SFD and arnoldi.
Definition: Driver.h:88
virtual ~Driver()
Destructor.
Definition: Driver.cpp:85
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:85
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Virtual function for initialisation implementation.
Definition: Driver.cpp:93
static std::string evolutionOperatorLookupIds[]
Definition: Driver.h:114
Driver(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Initialises EquationSystem class members.
Definition: Driver.cpp:76
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:82
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Definition: Driver.h:91
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:100
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:94
static std::string driverDefault
Definition: Driver.h:116
int m_nequ
number of equations
Definition: Driver.h:97
static std::string evolutionOperatorDef
Definition: Driver.h:115
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Definition: MeshGraph.cpp:116
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:67
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:176
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2