Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
36  IncNavierStokesSharedPtr IncNav = boost::dynamic_pointer_cast
37  <IncNavierStokes>(EqSys);
38 
39  IncNav->SetInitialConditions(0.0,false);
40  Array<OneD, NekDouble> cfl = IncNav->GetElmtCFLVals();
41 
42  // Reset Pressure field with CFL values
43  Array<OneD, MultiRegions::ExpListSharedPtr> fields = IncNav->UpdateFields();
44  int i,n,nquad,cnt;
45  int nfields = fields.num_elements();
46  int nexp = fields[0]->GetExpSize();
47 
48  int elmtid = Vmath::Imax(nexp,cfl,1);
49 
50  cout << "Max CFL: "<< cfl[elmtid] << " In element " << elmtid << endl;
51 
52 
53  for(n = 0; n < nfields; ++n)
54  {
55  if(session->GetVariable(n) == "p")
56  {
57  break;
58  }
59  }
60 
61  ASSERTL0(n != nfields, "Could not find field named p in m_fields");
62 
63  Array<OneD, NekDouble> phys = fields[n]->UpdatePhys();
64 
65  cnt = 0;
66  for(i = 0; i < fields[n]->GetExpSize(); ++i)
67  {
68  nquad = fields[n]->GetExp(i)->GetTotPoints();
69  Vmath::Fill(nquad,cfl[i],&phys[cnt],1);
70  cnt += nquad;
71  }
72 
73  fields[n]->FwdTrans_IterPerExp(fields[n]->GetPhys(),fields[n]->UpdateCoeffs());
74 
75  // Need to reset varibale name for output
76  session->SetVariable(n,"CFL");
77 
78  // Reset session name for output file
79  std::string outname = IncNav->GetSessionName();
80 
81  outname += "_CFLStep";
82  IncNav->ResetSessionName(outname);
83  IncNav->Output();
84 
85  }
86  catch (const std::runtime_error&)
87  {
88  return 1;
89  }
90  catch (const std::string& eStr)
91  {
92  cout << "Error: " << eStr << endl;
93  }
94 
95 
96  return 0;
97 }
98