Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace SolverUtils
43 {
44 
45 std::string Driver::evolutionOperatorLookupIds[6] = {
46  LibUtilities::SessionReader::RegisterEnumValue(
47  "EvolutionOperator","Nonlinear" ,eNonlinear),
48  LibUtilities::SessionReader::RegisterEnumValue(
49  "EvolutionOperator","Direct" ,eDirect),
50  LibUtilities::SessionReader::RegisterEnumValue(
51  "EvolutionOperator","Adjoint" ,eAdjoint),
52  LibUtilities::SessionReader::RegisterEnumValue(
53  "EvolutionOperator","TransientGrowth",eTransientGrowth),
54  LibUtilities::SessionReader::RegisterEnumValue(
55  "EvolutionOperator","SkewSymmetric" ,eSkewSymmetric),
56  LibUtilities::SessionReader::RegisterEnumValue(
57  "EvolutionOperator","AdaptiveSFD" ,eAdaptiveSFD)
58 };
59 std::string Driver::evolutionOperatorDef =
60  LibUtilities::SessionReader::RegisterDefaultSolverInfo(
61  "EvolutionOperator","Nonlinear");
62 std::string Driver::driverDefault =
63  LibUtilities::SessionReader::RegisterDefaultSolverInfo(
64  "Driver", "Standard");
65 
67 {
68  typedef Loki::SingletonHolder<DriverFactory,
69  Loki::CreateUsingNew,
70  Loki::NoDestroy,
71  Loki::SingleThreaded> Type;
72  return Type::Instance();
73 }
74 
75 /**
76  *
77  */
78 Driver::Driver(const LibUtilities::SessionReaderSharedPtr pSession)
79  : m_comm(pSession->GetComm()),
80  m_session(pSession)
81 {
82 }
83 
85 
86 {
87 }
88 
89 /**
90  *
91  */
92 void Driver::v_InitObject(ostream &out)
93 {
94  try
95  {
96  // Retrieve the equation system to solve.
97  ASSERTL0(m_session->DefinesSolverInfo("EqType"),
98  "EqType SolverInfo tag must be defined.");
99  std::string vEquation = m_session->GetSolverInfo("EqType");
100  if (m_session->DefinesSolverInfo("SolverType"))
101  {
102  vEquation = m_session->GetSolverInfo("SolverType");
103  }
104 
105  // Check such a module exists for this equation.
106  ASSERTL0(GetEquationSystemFactory().ModuleExists(vEquation),
107  "EquationSystem '" + vEquation + "' is not defined.\n"
108  "Ensure equation name is correct and module is compiled.\n");
109 
110  // Retrieve the type of evolution operator to use
111  /// @todo At the moment this is Navier-Stokes specific - generalise?
113  m_session->GetSolverInfoAsEnum<EvolutionOperatorType>(
114  "EvolutionOperator");
115 
117  m_EvolutionOperator == eAdaptiveSFD) ? 2 : 1);
118 
120 
121  // Set the AdvectiveType tag and create EquationSystem objects.
122  switch (m_EvolutionOperator)
123  {
124  case eNonlinear:
125  m_session->SetTag("AdvectiveType","Convective");
127  vEquation, m_session);
128  break;
129  case eDirect:
130  m_session->SetTag("AdvectiveType","Linearised");
132  vEquation, m_session);
133  break;
134  case eAdjoint:
135  m_session->SetTag("AdvectiveType","Adjoint");
137  vEquation, m_session);
138  break;
139  case eTransientGrowth:
140  //forward timestepping
141  m_session->SetTag("AdvectiveType","Linearised");
143  vEquation, m_session);
144 
145  //backward timestepping
146  m_session->SetTag("AdvectiveType","Adjoint");
148  vEquation, m_session);
149  break;
150  case eSkewSymmetric:
151  m_session->SetTag("AdvectiveType","SkewSymmetric");
153  vEquation, m_session);
154  break;
155  case eAdaptiveSFD:
156  {
157  // Coupling SFD method and Arnoldi algorithm
158  // For having 2 equation systems defined into 2 different
159  // session files (with the mesh into a file named 'session'.gz)
160  string meshfile;
161  string LinNSCondFile;
162  vector<string> LinNSFilename;
163  meshfile = m_session->GetFilenames()[0];
164  LinNSCondFile = m_session->GetSessionName();
165  LinNSCondFile += "_LinNS.xml";
166  LinNSFilename.push_back(meshfile);
167  LinNSFilename.push_back(LinNSCondFile);
169  0, NULL, LinNSFilename, m_session->GetComm());
170 
171  //For running stability analysis
172  session_LinNS->SetTag("AdvectiveType","Linearised");
174  vEquation, session_LinNS);
175 
176  //For running the SFD method on the nonlinear problem
177  m_session->SetTag("AdvectiveType","Convective");
179  vEquation, m_session);
180  }
181  break;
182  default:
183  ASSERTL0(false, "Unrecognised evolution operator.");
184 
185  }
186  }
187  catch (int e)
188  {
189  ASSERTL0(e == -1, "No such class class defined.");
190  out << "An error occurred during driver initialisation." << endl;
191  }
192 }
193 
195 {
196  ASSERTL0(false,"This routine is not valid in this class");
197  return NullNekDouble1DArray;
198 }
199 
201 {
202  ASSERTL0(false,"This routine is not valid in this class");
203  return NullNekDouble1DArray;
204 }
205 
206 }
207 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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 Array< OneD, NekDouble > NullNekDouble1DArray
virtual ~Driver()
Destructor.
Definition: Driver.cpp:84
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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 SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:92
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()
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:200
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetRealEvl(void)
Definition: Driver.cpp:194
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:66
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