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 
37 using namespace std;
38 
39 namespace Nektar
40 {
41 namespace SolverUtils
42 {
43 
44 std::string Driver::evolutionOperatorLookupIds[6] = {
45  LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator",
46  "Nonlinear", eNonlinear),
47  LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator",
48  "Direct", eDirect),
49  LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator",
50  "Adjoint", eAdjoint),
51  LibUtilities::SessionReader::RegisterEnumValue(
52  "EvolutionOperator", "TransientGrowth", eTransientGrowth),
53  LibUtilities::SessionReader::RegisterEnumValue(
54  "EvolutionOperator", "SkewSymmetric", eSkewSymmetric),
55  LibUtilities::SessionReader::RegisterEnumValue(
56  "EvolutionOperator", "AdaptiveSFD", eAdaptiveSFD)};
57 std::string Driver::evolutionOperatorDef =
58  LibUtilities::SessionReader::RegisterDefaultSolverInfo("EvolutionOperator",
59  "Nonlinear");
60 std::string Driver::driverDefault =
61  LibUtilities::SessionReader::RegisterDefaultSolverInfo("Driver",
62  "Standard");
63 
65 {
66  static DriverFactory instance;
67  return instance;
68 }
69 
70 /**
71  *
72  */
73 Driver::Driver(const LibUtilities::SessionReaderSharedPtr pSession,
75  : m_comm(pSession->GetComm()), m_session(pSession), m_graph(pGraph)
76 {
77 }
78 
80 
81 {
82 }
83 
84 /**
85  *
86  */
87 void Driver::v_InitObject(ostream &out)
88 {
89  try
90  {
91  // Retrieve the equation system to solve.
92  ASSERTL0(m_session->DefinesSolverInfo("EqType"),
93  "EqType SolverInfo tag must be defined.");
94  std::string vEquation = m_session->GetSolverInfo("EqType");
95  if (m_session->DefinesSolverInfo("SolverType"))
96  {
97  vEquation = m_session->GetSolverInfo("SolverType");
98  }
99 
100  // Check such a module exists for this equation.
101  ASSERTL0(
102  GetEquationSystemFactory().ModuleExists(vEquation),
103  "EquationSystem '" + vEquation +
104  "' is not defined.\n"
105  "Ensure equation name is correct and module is compiled.\n");
106 
107  // Retrieve the type of evolution operator to use
108  /// @todo At the moment this is Navier-Stokes specific - generalise?
110  m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
111  "EvolutionOperator");
112 
115  ? 2
116  : 1);
117 
119 
120  // Set the AdvectiveType tag and create EquationSystem objects.
121  switch (m_EvolutionOperator)
122  {
123  case eNonlinear:
124  m_session->SetTag("AdvectiveType", "Convective");
126  vEquation, m_session, m_graph);
127  break;
128  case eDirect:
129  m_session->SetTag("AdvectiveType", "Linearised");
131  vEquation, m_session, m_graph);
132  break;
133  case eAdjoint:
134  m_session->SetTag("AdvectiveType", "Adjoint");
136  vEquation, m_session, m_graph);
137  break;
138  case eTransientGrowth:
139  // forward timestepping
140  m_session->SetTag("AdvectiveType", "Linearised");
142  vEquation, m_session, m_graph);
143 
144  // backward timestepping
145  m_session->SetTag("AdvectiveType", "Adjoint");
147  vEquation, m_session, m_graph);
148  break;
149  case eSkewSymmetric:
150  m_session->SetTag("AdvectiveType", "SkewSymmetric");
152  vEquation, m_session, m_graph);
153  break;
154  case eAdaptiveSFD:
155  {
156  // Coupling SFD method and Arnoldi algorithm
157  // For having 2 equation systems defined into 2 different
158  // session files (with the mesh into a file named 'session'.gz)
159  string LinNSCondFile;
160  vector<string> LinNSFilename;
161 
162  // assume that the conditions file is the last
163  // filename on intiialisation and so copy all other
164  // files to new session. This will include the mesh
165  // file and possibly the optimsaiton file
166  for (int i = 0; i < m_session->GetFilenames().size() - 1; ++i)
167  {
168  LinNSFilename.push_back(m_session->GetFilenames()[i]);
169  }
170 
171  LinNSCondFile = m_session->GetSessionName();
172  LinNSCondFile += "_LinNS.xml";
173  LinNSFilename.push_back(LinNSCondFile);
174 
175  char *argv[] = {const_cast<char *>("IncNavierStokesSolver"),
176  nullptr};
178  1, argv, LinNSFilename, m_session->GetComm());
179 
182 
183  // For running stability analysis
184  session_LinNS->SetTag("AdvectiveType", "Linearised");
186  vEquation, session_LinNS, graph_linns);
187 
188  // For running the SFD method on the nonlinear problem
189  m_session->SetTag("AdvectiveType", "Convective");
191  vEquation, m_session, m_graph);
192  }
193  break;
194  default:
195  ASSERTL0(false, "Unrecognised evolution operator.");
196  }
197  }
198  catch (int e)
199  {
200  ASSERTL0(e == -1, "No such class class defined.");
201  out << "An error occurred during driver initialisation." << endl;
202  }
203 }
204 
206 {
207  ASSERTL0(false, "This routine is not valid in this class");
208  return NullNekDouble1DArray;
209 }
210 
212 {
213  ASSERTL0(false, "This routine is not valid in this class");
214  return NullNekDouble1DArray;
215 }
216 
217 } // namespace SolverUtils
218 } // 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 SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
LibUtilities::SessionReaderSharedPtr session_LinNS
I the Coupling between SFD and arnoldi.
Definition: Driver.h:91
virtual ~Driver()
Destructor.
Definition: Driver.cpp:79
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:88
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:87
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Definition: Driver.h:94
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:103
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:97
int m_nequ
number of equations
Definition: Driver.h:100
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetRealEvl(void)
Definition: Driver.cpp:205
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetImagEvl(void)
Definition: Driver.cpp:211
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true)
Definition: MeshGraph.cpp:111
std::shared_ptr< SessionReader > SessionReaderSharedPtr
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
static Array< OneD, NekDouble > NullNekDouble1DArray