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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Base class for Drivers
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <SolverUtils/Driver.h>
37 
38 namespace Nektar
39 {
40 namespace SolverUtils
41 {
42 
43 std::string Driver::evolutionOperatorLookupIds[6] = {
45  "EvolutionOperator","Nonlinear" ,eNonlinear),
47  "EvolutionOperator","Direct" ,eDirect),
49  "EvolutionOperator","Adjoint" ,eAdjoint),
51  "EvolutionOperator","TransientGrowth",eTransientGrowth),
53  "EvolutionOperator","SkewSymmetric" ,eSkewSymmetric),
55  "EvolutionOperator","AdaptiveSFD" ,eAdaptiveSFD)
56 };
57 std::string Driver::evolutionOperatorDef =
59  "EvolutionOperator","Nonlinear");
60 std::string Driver::driverDefault =
62  "Driver", "Standard");
63 
65 {
66  typedef Loki::SingletonHolder<DriverFactory,
67  Loki::CreateUsingNew,
68  Loki::NoDestroy,
69  Loki::SingleThreaded> Type;
70  return Type::Instance();
71 }
72 
73 /**
74  *
75  */
77  : m_comm(pSession->GetComm()),
78  m_session(pSession)
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);
126  break;
127  case eDirect:
128  m_session->SetTag("AdvectiveType","Linearised");
130  vEquation, m_session);
131  break;
132  case eAdjoint:
133  m_session->SetTag("AdvectiveType","Adjoint");
135  vEquation, m_session);
136  break;
137  case eTransientGrowth:
138  //forward timestepping
139  m_session->SetTag("AdvectiveType","Linearised");
141  vEquation, m_session);
142 
143  //backward timestepping
144  m_session->SetTag("AdvectiveType","Adjoint");
146  vEquation, m_session);
147  break;
148  case eSkewSymmetric:
149  m_session->SetTag("AdvectiveType","SkewSymmetric");
151  vEquation, m_session);
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);
167  0, NULL, LinNSFilename, m_session->GetComm());
168 
169  //For running stability analysis
170  session_LinNS->SetTag("AdvectiveType","Linearised");
172  vEquation, session_LinNS);
173 
174  //For running the SFD method on the nonlinear problem
175  m_session->SetTag("AdvectiveType","Convective");
177  vEquation, m_session);
178  }
179  break;
180  default:
181  ASSERTL0(false, "Unrecognised evolution operator.");
182 
183  }
184  }
185  catch (int e)
186  {
187  ASSERTL0(e == -1, "No such class class defined.");
188  out << "An error occurred during driver initialisation." << endl;
189  }
190 }
191 
193 {
194  ASSERTL0(false,"This routine is not valid in this class");
195  return NullNekDouble1DArray;
196 }
197 
199 {
200  ASSERTL0(false,"This routine is not valid in this class");
201  return NullNekDouble1DArray;
202 }
203 
204 }
205 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
virtual SOLVER_UTILS_EXPORT void v_InitObject(ostream &out=cout)
Definition: Driver.cpp:90
static Array< OneD, NekDouble > NullNekDouble1DArray
Driver(const LibUtilities::SessionReaderSharedPtr pSession)
Initialises EquationSystem class members.
Definition: Driver.cpp:76
virtual ~Driver()
Destructor.
Definition: Driver.cpp:82
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
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
static std::string evolutionOperatorLookupIds[]
Definition: Driver.h:115
LibUtilities::NekFactory< std::string, Driver, const LibUtilities::SessionReaderSharedPtr & > DriverFactory
Datatype of the NekFactory used to instantiate classes derived from the Driver class.
Definition: Driver.h:60
enum EvolutionOperatorType m_EvolutionOperator
Evolution Operator.
Definition: Driver.h:100
EquationSystemFactory & GetEquationSystemFactory()
static std::string evolutionOperatorDef
Definition: Driver.h:116
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:94
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetImagEvl(void)
Definition: Driver.cpp:198
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetRealEvl(void)
Definition: Driver.cpp:192
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:88
int m_nequ
number of equations
Definition: Driver.h:97
Provides a generic Factory class.
Definition: NekFactory.hpp:116
static std::string driverDefault
Definition: Driver.h:117