Nektar++
CFLStep.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
5 #include <SolverUtils/Driver.h>
6 
8 
9 using namespace std;
10 using namespace Nektar;
11 using namespace Nektar::SolverUtils;
12 
13 int main(int argc, char *argv[])
14 {
15  if (argc != 2)
16  {
17  fprintf(stderr, "Usage: ./CflStep file.xml \n");
18  fprintf(stderr, "\t Method will read intiial conditions section of "
19  ".xml file for input \n");
20  exit(1);
21  }
22 
25 
26  string vDriverModule;
27  DriverSharedPtr drv;
28  try
29  {
30  // Create session reader.
31  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
32 
33  // Create MeshGraph.
34  graph = SpatialDomains::MeshGraph::Read(session);
35 
36  // Create driver
37  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
38  drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
39 
40  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
41  IncNavierStokesSharedPtr IncNav = EqSys->as<IncNavierStokes>();
42 
43  IncNav->SetInitialConditions(0.0, false);
44  Array<OneD, NekDouble> cfl = IncNav->GetElmtCFLVals();
45 
46  // Reset Pressure field with CFL values
48  IncNav->UpdateFields();
49  int i, n, nquad, cnt;
50  int nfields = fields.size();
51  int nexp = fields[0]->GetExpSize();
52 
53  int elmtid = Vmath::Imax(nexp, cfl, 1);
54 
55  cout << "Max CFL: " << cfl[elmtid] << " In element " << elmtid << endl;
56 
57  for (n = 0; n < nfields; ++n)
58  {
59  if (session->GetVariable(n) == "p")
60  {
61  break;
62  }
63  }
64 
65  ASSERTL0(n != nfields, "Could not find field named p in m_fields");
66 
67  Array<OneD, NekDouble> phys = fields[n]->UpdatePhys();
68 
69  cnt = 0;
70  for (i = 0; i < fields[n]->GetExpSize(); ++i)
71  {
72  nquad = fields[n]->GetExp(i)->GetTotPoints();
73  Vmath::Fill(nquad, cfl[i], &phys[cnt], 1);
74  cnt += nquad;
75  }
76 
77  fields[n]->FwdTransLocalElmt(fields[n]->GetPhys(),
78  fields[n]->UpdateCoeffs());
79 
80  // Need to reset varibale name for output
81  session->SetVariable(n, "CFL");
82 
83  // Reset session name for output file
84  std::string outname = IncNav->GetSessionName();
85 
86  outname += "_CFLStep";
87  IncNav->ResetSessionName(outname);
88  IncNav->Output();
89  }
90  catch (const std::runtime_error &)
91  {
92  return 1;
93  }
94  catch (const std::string &eStr)
95  {
96  cout << "Error: " << eStr << endl;
97  }
98 
99  return 0;
100 }
int main(int argc, char *argv[])
Definition: CFLStep.cpp:13
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
This class is the base class for Navier Stokes problems.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
SOLVER_UTILS_EXPORT void SetInitialConditions(NekDouble initialtime=0.0, bool dumpInitialConditions=true, const int domain=0)
Initialise the data in the dependent fields.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:51
DriverFactory & GetDriverFactory()
Definition: Driver.cpp:64
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::shared_ptr< IncNavierStokes > IncNavierStokesSharedPtr
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.cpp:918
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45