Nektar++
Aliasing.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
4 #include <SolverUtils/Driver.h>
6 
9 
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: ./Aliasing file.xml \n");
18  fprintf(stderr,"\t Method will read intiial conditions section of .xml file for input \n");
19  exit(1);
20  }
21 
23  string vDriverModule;
24  DriverSharedPtr drv;
25  try
26  {
27  // Create session reader.
28  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
29 
30  // Create driver
31  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
32  drv = GetDriverFactory().CreateInstance(vDriverModule, session);
33 
34 
35  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
36  IncNavierStokesSharedPtr IncNav = EqSys->as<IncNavierStokes>();
37 
38  IncNav->SetInitialConditions(0.0,false);
39  Array<OneD, MultiRegions::ExpListSharedPtr> fields = IncNav->UpdateFields();
40 
41  int i;
42  int nConvectiveFields = IncNav->GetNConvectiveFields();
43  int nphys = fields[0]->GetTotPoints();
44  Array<OneD, Array<OneD, NekDouble> > VelFields(nConvectiveFields);
45  Array<OneD, Array<OneD, NekDouble> > NonLinear(nConvectiveFields);
46  Array<OneD, Array<OneD, NekDouble> > NonLinearDealiased(nConvectiveFields);
47 
48  for(i = 0; i < nConvectiveFields; ++i)
49  {
50  VelFields[i] = fields[i]->UpdatePhys();
51  NonLinear[i] = Array<OneD, NekDouble> (nphys);
52  NonLinearDealiased[i] = Array<OneD, NekDouble> (nphys);
53  }
54 
55  boost::shared_ptr<NavierStokesAdvection> A
56  = boost::dynamic_pointer_cast<NavierStokesAdvection>(IncNav->GetAdvObject());
57 
58  if (!A)
59  {
60  cout << "Must use non-linear Navier-Stokes advection" << endl;
61  exit(-1);
62  }
63 
64  // calculate non-linear terms without dealiasing
65  A->SetSpecHPDealiasing(false);
66  A->Advect(nConvectiveFields, fields,
67  VelFields, VelFields,
68  NonLinear, 0.0);
69 
70 
71  // calculate non-linear terms with dealiasing
72  A->SetSpecHPDealiasing(true);
73  A->Advect(nConvectiveFields, fields,
74  VelFields, VelFields,
75  NonLinearDealiased, 0.0);
76 
77  // Evaulate Difference and put into fields;
78  for(i = 0; i < nConvectiveFields; ++i)
79  {
80  Vmath::Vsub(nphys,NonLinearDealiased[i],1,NonLinear[i],1,NonLinear[i],1);
81  fields[i]->FwdTrans_IterPerExp(NonLinear[i],fields[i]->UpdateCoeffs());
82  // Need to reset varibale name for output
83  string name = "NL_Aliasing_"+session->GetVariable(i);
84  session->SetVariable(i,name.c_str());
85  }
86 
87 
88  // Reset session name for output file
89  std::string outname = IncNav->GetSessionName();
90 
91  outname += "_NonLinear_Aliasing";
92  IncNav->ResetSessionName(outname);
93  IncNav->Output();
94 
95  }
96  catch (const std::runtime_error&)
97  {
98  return 1;
99  }
100  catch (const std::string& eStr)
101  {
102  cout << "Error: " << eStr << endl;
103  }
104 
105 
106  return 0;
107 }
108 
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
boost::shared_ptr< IncNavierStokes > IncNavierStokesSharedPtr
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
int main(int argc, char *argv[])
Definition: Aliasing.cpp:13
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.
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:329
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.