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 */
83void Driver::v_InitObject(ostream &out)
84{
85 try
86 {
87 // Retrieve the equation system to solve.
88 ASSERTL0(m_session->DefinesSolverInfo("EqType"),
89 "EqType SolverInfo tag must be defined.");
90 std::string vEquation = m_session->GetSolverInfo("EqType");
91 if (m_session->DefinesSolverInfo("SolverType"))
92 {
93 vEquation = m_session->GetSolverInfo("SolverType");
94 }
95
96 // Check such a module exists for this equation.
98 GetEquationSystemFactory().ModuleExists(vEquation),
99 "EquationSystem '" + vEquation +
100 "' is not defined.\n"
101 "Ensure equation name is correct and module is compiled.\n");
102
103 // Retrieve the type of evolution operator to use
104 /// @todo At the moment this is Navier-Stokes specific - generalise?
106 m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
107 "EvolutionOperator");
108
111 ? 2
112 : 1);
113
115
116 // Set the AdvectiveType tag and create EquationSystem objects.
117 switch (m_EvolutionOperator)
118 {
119 case eNonlinear:
120 m_session->SetTag("AdvectiveType", "Convective");
122 vEquation, m_session, m_graph);
123 break;
124 case eDirect:
125 m_session->SetTag("AdvectiveType", "Linearised");
127 vEquation, m_session, m_graph);
128 break;
129 case eAdjoint:
130 m_session->SetTag("AdvectiveType", "Adjoint");
132 vEquation, m_session, m_graph);
133 break;
134 case eTransientGrowth:
135 // forward timestepping
136 m_session->SetTag("AdvectiveType", "Linearised");
138 vEquation, m_session, m_graph);
139
140 // backward timestepping
141 m_session->SetTag("AdvectiveType", "Adjoint");
143 vEquation, m_session, m_graph);
144 break;
145 case eSkewSymmetric:
146 m_session->SetTag("AdvectiveType", "SkewSymmetric");
148 vEquation, m_session, m_graph);
149 break;
150 case eAdaptiveSFD:
151 {
152 // Coupling SFD method and Arnoldi algorithm
153 // For having 2 equation systems defined into 2 different
154 // session files (with the mesh into a file named 'session'.gz)
155 string LinNSCondFile;
156 vector<string> LinNSFilename;
157
158 // assume that the conditions file is the last
159 // filename on intiialisation and so copy all other
160 // files to new session. This will include the mesh
161 // file and possibly the optimsaiton file
162 for (int i = 0; i < m_session->GetFilenames().size() - 1; ++i)
163 {
164 LinNSFilename.push_back(m_session->GetFilenames()[i]);
165 }
166
167 LinNSCondFile = m_session->GetSessionName();
168 LinNSCondFile += "_LinNS.xml";
169 LinNSFilename.push_back(LinNSCondFile);
170
171 char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
172 nullptr};
174 1, argv, LinNSFilename, m_comm);
175
178
179 // For running stability analysis
180 session_LinNS->SetTag("AdvectiveType", "Linearised");
182 vEquation, session_LinNS, graph_linns);
183
184 // For running the SFD method on the nonlinear problem
185 m_session->SetTag("AdvectiveType", "Convective");
187 vEquation, m_session, m_graph);
188 }
189 break;
190 default:
191 ASSERTL0(false, "Unrecognised evolution operator.");
192 }
193 }
194 catch (int e)
195 {
196 ASSERTL0(e == -1, "No such class class defined.");
197 out << "An error occurred during driver initialisation." << endl;
198 }
199}
200
201} // 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:83
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
STL namespace.