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(
46  "EvolutionOperator","Nonlinear" ,eNonlinear),
47  LibUtilities::SessionReader::RegisterEnumValue(
48  "EvolutionOperator","Direct" ,eDirect),
49  LibUtilities::SessionReader::RegisterEnumValue(
50  "EvolutionOperator","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 };
58 std::string Driver::evolutionOperatorDef =
59  LibUtilities::SessionReader::RegisterDefaultSolverInfo(
60  "EvolutionOperator","Nonlinear");
61 std::string Driver::driverDefault =
62  LibUtilities::SessionReader::RegisterDefaultSolverInfo(
63  "Driver", "Standard");
64 
66 {
67  static DriverFactory instance;
68  return instance;
69 }
70 
71 /**
72  *
73  */
74 Driver::Driver(const LibUtilities::SessionReaderSharedPtr pSession,
76  : m_comm(pSession->GetComm()),
77  m_session(pSession),
78  m_graph(pGraph)
79 {
80 }
81 
83 
84 {
85 }
86 
87 /**
88  *
89  */
90 void Driver::v_InitObject(ostream &out)
91 {
92  try
93  {
94  // Retrieve the equation system to solve.
95  ASSERTL0(m_session->DefinesSolverInfo("EqType"),
96  "EqType SolverInfo tag must be defined.");
97  std::string vEquation = m_session->GetSolverInfo("EqType");
98  if (m_session->DefinesSolverInfo("SolverType"))
99  {
100  vEquation = m_session->GetSolverInfo("SolverType");
101  }
102 
103  // Check such a module exists for this equation.
104  ASSERTL0(GetEquationSystemFactory().ModuleExists(vEquation),
105  "EquationSystem '" + vEquation + "' is not defined.\n"
106  "Ensure equation name is correct and module is compiled.\n");
107 
108  // Retrieve the type of evolution operator to use
109  /// @todo At the moment this is Navier-Stokes specific - generalise?
111  m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
112  "EvolutionOperator");
113 
115  m_EvolutionOperator == eAdaptiveSFD) ? 2 : 1);
116 
118 
119  // Set the AdvectiveType tag and create EquationSystem objects.
120  switch (m_EvolutionOperator)
121  {
122  case eNonlinear:
123  m_session->SetTag("AdvectiveType","Convective");
125  vEquation, m_session, m_graph);
126  break;
127  case eDirect:
128  m_session->SetTag("AdvectiveType","Linearised");
130  vEquation, m_session, m_graph);
131  break;
132  case eAdjoint:
133  m_session->SetTag("AdvectiveType","Adjoint");
135  vEquation, m_session, m_graph);
136  break;
137  case eTransientGrowth:
138  //forward timestepping
139  m_session->SetTag("AdvectiveType","Linearised");
141  vEquation, m_session, m_graph);
142 
143  //backward timestepping
144  m_session->SetTag("AdvectiveType","Adjoint");
146  vEquation, m_session, m_graph);
147  break;
148  case eSkewSymmetric:
149  m_session->SetTag("AdvectiveType","SkewSymmetric");
151  vEquation, m_session, m_graph);
152  break;
153  case eAdaptiveSFD:
154  {
155  // Coupling SFD method and Arnoldi algorithm
156  // For having 2 equation systems defined into 2 different
157  // session files (with the mesh into a file named 'session'.gz)
158  string meshfile;
159  string LinNSCondFile;
160  vector<string> LinNSFilename;
161  meshfile = m_session->GetFilenames()[0];
162  LinNSCondFile = m_session->GetSessionName();
163  LinNSCondFile += "_LinNS.xml";
164  LinNSFilename.push_back(meshfile);
165  LinNSFilename.push_back(LinNSCondFile);
166 
167  char *argv[] = {
168  const_cast<char*>("IncNavierStokesSolver"), nullptr };
170  1, argv, LinNSFilename, m_session->GetComm());
171 
174 
175  //For running stability analysis
176  session_LinNS->SetTag("AdvectiveType","Linearised");
178  vEquation, session_LinNS, graph_linns);
179 
180  //For running the SFD method on the nonlinear problem
181  m_session->SetTag("AdvectiveType","Convective");
183  vEquation, m_session, m_graph);
184  }
185  break;
186  default:
187  ASSERTL0(false, "Unrecognised evolution operator.");
188 
189  }
190  }
191  catch (int e)
192  {
193  ASSERTL0(e == -1, "No such class class defined.");
194  out << "An error occurred during driver initialisation." << endl;
195  }
196 }
197 
199 {
200  ASSERTL0(false,"This routine is not valid in this class");
201  return NullNekDouble1DArray;
202 }
203 
205 {
206  ASSERTL0(false,"This routine is not valid in this class");
207  return NullNekDouble1DArray;
208 }
209 
210 }
211 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
static Array< OneD, NekDouble > NullNekDouble1DArray
virtual ~Driver()
Destructor.
Definition: Driver.cpp:82
STL namespace.
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:92
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:90
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Definition: Driver.h:95
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:104
EquationSystemFactory & GetEquationSystemFactory()
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:98
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetImagEvl(void)
Definition: Driver.cpp:204
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetRealEvl(void)
Definition: Driver.cpp:198
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:65
std::shared_ptr< SessionReader > SessionReaderSharedPtr
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:89
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, DomainRangeShPtr rng=NullDomainRangeShPtr, bool fillGraph=true)
Definition: MeshGraph.cpp:113
int m_nequ
number of equations
Definition: Driver.h:101
Provides a generic Factory class.
Definition: NekFactory.hpp:103