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::SolverUtils
40{
41
44 "Nonlinear", eNonlinear),
46 "Direct", eDirect),
48 "Adjoint", eAdjoint),
50 "EvolutionOperator", "TransientGrowth", eTransientGrowth),
52 "EvolutionOperator", "SkewSymmetric", eSkewSymmetric),
54 "EvolutionOperator", "AdaptiveSFD", eAdaptiveSFD)};
57 "Nonlinear");
58std::string Driver::driverDefault =
60 "Standard");
61
62/**
63 *
64 */
66{
67 static DriverFactory instance;
68 return instance;
69}
70
71/**
72 *
73 */
76 : m_comm(pSession->GetComm()), m_session(pSession), m_graph(pGraph)
77{
78}
79
80/**
81 *
82 */
84
85{
86}
87
88/**
89 *
90 */
91void Driver::v_InitObject(ostream &out)
92{
93 try
94 {
95 // Retrieve the equation system to solve.
96 ASSERTL0(m_session->DefinesSolverInfo("EqType"),
97 "EqType SolverInfo tag must be defined.");
98 std::string vEquation = m_session->GetSolverInfo("EqType");
99 if (m_session->DefinesSolverInfo("SolverType"))
100 {
101 vEquation = m_session->GetSolverInfo("SolverType");
102 }
103
104 // Check such a module exists for this equation.
105 ASSERTL0(
106 GetEquationSystemFactory().ModuleExists(vEquation),
107 "EquationSystem '" + vEquation +
108 "' is not defined.\n"
109 "Ensure equation name is correct and module is compiled.\n");
110
111 // Retrieve the type of evolution operator to use
112 /// @todo At the moment this is Navier-Stokes specific - generalise?
114 m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
115 "EvolutionOperator");
116
119 ? 2
120 : 1);
121
123
124 // Set the AdvectiveType tag and create EquationSystem objects.
125 switch (m_EvolutionOperator)
126 {
127 case eNonlinear:
128 m_session->SetTag("AdvectiveType", "Convective");
130 vEquation, m_session, m_graph);
131 break;
132 case eDirect:
133 m_session->SetTag("AdvectiveType", "Linearised");
135 vEquation, m_session, m_graph);
136 break;
137 case eAdjoint:
138 m_session->SetTag("AdvectiveType", "Adjoint");
140 vEquation, m_session, m_graph);
141 break;
142 case eTransientGrowth:
143 // forward timestepping
144 m_session->SetTag("AdvectiveType", "Linearised");
146 vEquation, m_session, m_graph);
147
148 // backward timestepping
149 m_session->SetTag("AdvectiveType", "Adjoint");
151 vEquation, m_session, m_graph);
152 break;
153 case eSkewSymmetric:
154 m_session->SetTag("AdvectiveType", "SkewSymmetric");
156 vEquation, m_session, m_graph);
157 break;
158 case eAdaptiveSFD:
159 {
160 // Coupling SFD method and Arnoldi algorithm
161 // For having 2 equation systems defined into 2 different
162 // session files (with the mesh into a file named 'session'.gz)
163 string LinNSCondFile;
164 vector<string> LinNSFilename;
165
166 // assume that the conditions file is the last
167 // filename on intiialisation and so copy all other
168 // files to new session. This will include the mesh
169 // file and possibly the optimsaiton file
170 for (int i = 0; i < m_session->GetFilenames().size() - 1; ++i)
171 {
172 LinNSFilename.push_back(m_session->GetFilenames()[i]);
173 }
174
175 LinNSCondFile = m_session->GetSessionName();
176 LinNSCondFile += "_LinNS.xml";
177 LinNSFilename.push_back(LinNSCondFile);
178
179 char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
180 nullptr};
182 1, argv, LinNSFilename, m_comm);
183
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." << endl;
206 }
207}
208
209} // namespace Nektar::SolverUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
Provides a generic Factory class.
Definition: NekFactory.hpp:104
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:143
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
virtual ~Driver()
Destructor.
Definition: Driver.cpp:83
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:91
static std::string evolutionOperatorLookupIds[]
Definition: Driver.h:112
Driver(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Initialises EquationSystem class members.
Definition: Driver.cpp:74
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: MeshGraph.cpp:115
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:65
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174