Nektar++
CFLStep.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
4 #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 .xml file for input \n");
19  exit(1);
20  }
21 
24 
25  string vDriverModule;
26  DriverSharedPtr drv;
27  try
28  {
29  // Create session reader.
30  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
31 
32  // Create MeshGraph.
33  graph = SpatialDomains::MeshGraph::Read(session);
34 
35  // Create driver
36  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
37  drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
38 
39  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
40  IncNavierStokesSharedPtr IncNav = EqSys->as<IncNavierStokes>();
41 
42  IncNav->SetInitialConditions(0.0,false);
43  Array<OneD, NekDouble> cfl = IncNav->GetElmtCFLVals();
44 
45  // Reset Pressure field with CFL values
46  Array<OneD, MultiRegions::ExpListSharedPtr> fields = IncNav->UpdateFields();
47  int i,n,nquad,cnt;
48  int nfields = fields.size();
49  int nexp = fields[0]->GetExpSize();
50 
51  int elmtid = Vmath::Imax(nexp,cfl,1);
52 
53  cout << "Max CFL: "<< cfl[elmtid] << " In element " << elmtid << endl;
54 
55 
56  for(n = 0; n < nfields; ++n)
57  {
58  if(session->GetVariable(n) == "p")
59  {
60  break;
61  }
62  }
63 
64  ASSERTL0(n != nfields, "Could not find field named p in m_fields");
65 
66  Array<OneD, NekDouble> phys = fields[n]->UpdatePhys();
67 
68  cnt = 0;
69  for(i = 0; i < fields[n]->GetExpSize(); ++i)
70  {
71  nquad = fields[n]->GetExp(i)->GetTotPoints();
72  Vmath::Fill(nquad,cfl[i],&phys[cnt],1);
73  cnt += nquad;
74  }
75 
76  fields[n]->FwdTrans_IterPerExp(fields[n]->GetPhys(),fields[n]->UpdateCoeffs());
77 
78  // Need to reset varibale name for output
79  session->SetVariable(n,"CFL");
80 
81  // Reset session name for output file
82  std::string outname = IncNav->GetSessionName();
83 
84  outname += "_CFLStep";
85  IncNav->ResetSessionName(outname);
86  IncNav->Output();
87 
88  }
89  catch (const std::runtime_error&)
90  {
91  return 1;
92  }
93  catch (const std::string& eStr)
94  {
95  cout << "Error: " << eStr << endl;
96  }
97 
98 
99  return 0;
100 }
101 
int main(int argc, char *argv[])
Definition: CFLStep.cpp:13
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
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:145
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:65
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
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:866
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45