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>
37
38using namespace std;
39
40namespace Nektar::SolverUtils
41{
42
45 "Nonlinear", eNonlinear),
47 "Direct", eDirect),
49 "Adjoint", eAdjoint),
51 "EvolutionOperator", "TransientGrowth", eTransientGrowth),
53 "EvolutionOperator", "SkewSymmetric", eSkewSymmetric),
55 "EvolutionOperator", "AdaptiveSFD", eAdaptiveSFD)};
58 "Nonlinear");
59std::string Driver::driverDefault =
61 "Standard");
62
63/**
64 *
65 */
67{
68 static DriverFactory instance;
69 return instance;
70}
71
72/**
73 *
74 */
77 : m_comm(pSession->GetComm()), m_session(pSession), m_graph(pGraph)
78{
79}
80
81/**
82 *
83 */
84void Driver::v_InitObject(ostream &out)
85{
86 try
87 {
88 // Retrieve the equation system to solve.
89 ASSERTL0(m_session->DefinesSolverInfo("EqType"),
90 "EqType SolverInfo tag must be defined.");
91 std::string vEquation = m_session->GetSolverInfo("EqType");
92 if (m_session->DefinesSolverInfo("SolverType"))
93 {
94 vEquation = m_session->GetSolverInfo("SolverType");
95 }
96
97 // Check such a module exists for this equation.
99 GetEquationSystemFactory().ModuleExists(vEquation),
100 "EquationSystem '" + vEquation +
101 "' is not defined.\n"
102 "Ensure equation name is correct and module is compiled.\n");
103
104 // Retrieve the type of evolution operator to use
105 /// @todo At the moment this is Navier-Stokes specific - generalise?
107 m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
108 "EvolutionOperator");
109
112 ? 2
113 : 1);
114
116
117 // Set the AdvectiveType tag and create EquationSystem objects.
118 switch (m_EvolutionOperator)
119 {
120 case eNonlinear:
121 m_session->SetTag("AdvectiveType", "Convective");
123 vEquation, m_session, m_graph);
124 break;
125 case eDirect:
126 m_session->SetTag("AdvectiveType", "Linearised");
128 vEquation, m_session, m_graph);
129 break;
130 case eAdjoint:
131 m_session->SetTag("AdvectiveType", "Adjoint");
133 vEquation, m_session, m_graph);
134 break;
135 case eTransientGrowth:
136 // forward timestepping
137 m_session->SetTag("AdvectiveType", "Linearised");
139 vEquation, m_session, m_graph);
140
141 // backward timestepping
142 m_session->SetTag("AdvectiveType", "Adjoint");
144 vEquation, m_session, m_graph);
145 break;
146 case eSkewSymmetric:
147 m_session->SetTag("AdvectiveType", "SkewSymmetric");
149 vEquation, m_session, m_graph);
150 break;
151 case eAdaptiveSFD:
152 {
153 // use-opt-file
154 bool useOptFile =
155 m_session->DefinesCmdLineArgument("use-opt-file");
156 std::string optfilename =
157 useOptFile ? m_session->GetFilenames()[0] : "";
158
159 char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
160 const_cast<char *>("--use-opt-file"),
161 const_cast<char *>(optfilename.c_str()),
162 nullptr};
163
164 size_t argc = useOptFile ? 3 : 1;
165
166 std::vector<std::string> LinNSFilename;
167 if (m_comm->GetSize() == 1)
168 {
169 // Use .xml.gz file for serial case
170 LinNSFilename.push_back(m_session->GetSessionName() +
171 ".xml.gz");
172 }
173 else
174 {
175 // Use previous partition for parallel case
176 LinNSFilename.push_back(m_session->GetSessionName() +
177 "_xml");
178 }
179 LinNSFilename.push_back(m_session->GetSessionName() +
180 "_LinNS.xml");
181
183 argc, argv, LinNSFilename, m_comm);
184
185 // Set graph for LinNs solver.
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 Nektar::SolverUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
Provides a generic Factory class.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
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:86
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:83
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Virtual function for initialisation implementation.
Definition: Driver.cpp:84
static std::string evolutionOperatorLookupIds[]
Definition: Driver.h:112
Driver(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Initialises EquationSystem class members.
Definition: Driver.cpp:75
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:80
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Definition: Driver.h:89
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:98
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:92
static std::string driverDefault
Definition: Driver.h:114
int m_nequ
number of equations
Definition: Driver.h:95
static std::string evolutionOperatorDef
Definition: Driver.h:113
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Definition: MeshGraphIO.cpp:53
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:66
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
STL namespace.