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
38namespace Nektar::SolverUtils
39{
40
43 "Nonlinear", eNonlinear),
45 "Direct", eDirect),
47 "Adjoint", eAdjoint),
49 "EvolutionOperator", "TransientGrowth", eTransientGrowth),
51 "EvolutionOperator", "SkewSymmetric", eSkewSymmetric),
53 "EvolutionOperator", "AdaptiveSFD", eAdaptiveSFD)};
56 "Nonlinear");
57std::string Driver::driverDefault =
59 "Standard");
60
61/**
62 *
63 */
65{
66 static DriverFactory instance;
67 return instance;
68}
69
70/**
71 *
72 */
75 : m_comm(pSession->GetComm()), m_session(pSession), m_graph(pGraph)
76{
77}
78
79/**
80 *
81 */
82void Driver::v_InitObject(std::ostream &out)
83{
84 try
85 {
86 // Retrieve the equation system to solve.
87 ASSERTL0(m_session->DefinesSolverInfo("EqType"),
88 "EqType SolverInfo tag must be defined.");
89 std::string vEquation = m_session->GetSolverInfo("EqType");
90 if (m_session->DefinesSolverInfo("SolverType"))
91 {
92 vEquation = m_session->GetSolverInfo("SolverType");
93 }
94
95 // Check such a module exists for this equation.
97 GetEquationSystemFactory().ModuleExists(vEquation),
98 "EquationSystem '" + vEquation +
99 "' is not defined.\n"
100 "Ensure equation name is correct and module is compiled.\n");
101
102 // Retrieve the type of evolution operator to use
103 /// @todo At the moment this is Navier-Stokes specific - generalise?
105 m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
106 "EvolutionOperator");
107
110 ? 2
111 : 1);
112
114
115 // Set the AdvectiveType tag and create EquationSystem objects.
116 switch (m_EvolutionOperator)
117 {
118 case eNonlinear:
119 m_session->SetTag("AdvectiveType", "Convective");
121 vEquation, m_session, m_graph);
122 break;
123 case eDirect:
124 m_session->SetTag("AdvectiveType", "Linearised");
126 vEquation, m_session, m_graph);
127 break;
128 case eAdjoint:
129 m_session->SetTag("AdvectiveType", "Adjoint");
131 vEquation, m_session, m_graph);
132 break;
133 case eTransientGrowth:
134 // forward timestepping
135 m_session->SetTag("AdvectiveType", "Linearised");
137 vEquation, m_session, m_graph);
138
139 // backward timestepping
140 m_session->SetTag("AdvectiveType", "Adjoint");
142 vEquation, m_session, m_graph);
143 break;
144 case eSkewSymmetric:
145 m_session->SetTag("AdvectiveType", "SkewSymmetric");
147 vEquation, m_session, m_graph);
148 break;
149 case eAdaptiveSFD:
150 {
151 // use-opt-file
152 bool useOptFile =
153 m_session->DefinesCmdLineArgument("use-opt-file");
154 std::string optfilename =
155 useOptFile ? m_session->GetFilenames()[0] : "";
156
157 char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
158 const_cast<char *>("--use-opt-file"),
159 const_cast<char *>(optfilename.c_str()),
160 nullptr};
161
162 size_t argc = useOptFile ? 3 : 1;
163
164 std::vector<std::string> LinNSFilename;
165 if (m_comm->GetSize() == 1)
166 {
167 // Use .xml.gz file for serial case
168 LinNSFilename.push_back(m_session->GetSessionName() +
169 ".xml.gz");
170 }
171 else
172 {
173 // Use previous partition for parallel case
174 LinNSFilename.push_back(m_session->GetSessionName() +
175 "_xml");
176 }
177 LinNSFilename.push_back(m_session->GetSessionName() +
178 "_LinNS.xml");
179
181 argc, argv, LinNSFilename, m_comm);
182
183 // Set graph for LinNs solver.
186
187 // For running stability analysis
188 session_LinNS->SetTag("AdvectiveType", "Linearised");
190 vEquation, session_LinNS, graph_linns);
191
192 // For running the SFD method on the nonlinear problem
193 m_session->SetTag("AdvectiveType", "Convective");
195 vEquation, m_session, m_graph);
196 }
197 break;
198 default:
199 ASSERTL0(false, "Unrecognised evolution operator.");
200 }
201 }
202 catch (int e)
203 {
204 ASSERTL0(e == -1, "No such class class defined.");
205 out << "An error occurred during driver initialisation." << std::endl;
206 }
207}
208
209} // 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:82
static std::string evolutionOperatorLookupIds[]
Definition: Driver.h:112
Driver(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Initialises EquationSystem class members.
Definition: Driver.cpp:73
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:51
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174