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