Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Aliasing.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: ./Aliasing 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, MultiRegions::ExpListSharedPtr> fields = IncNav->UpdateFields();
41 
42  int i;
43  int nConvectiveFields = IncNav->GetNConvectiveFields();
44  int nphys = fields[0]->GetTotPoints();
45  Array<OneD, Array<OneD, NekDouble> > VelFields(nConvectiveFields);
46  Array<OneD, Array<OneD, NekDouble> > NonLinear(nConvectiveFields);
47  Array<OneD, Array<OneD, NekDouble> > NonLinearDealiased(nConvectiveFields);
48 
49  for(i = 0; i < nConvectiveFields; ++i)
50  {
51  VelFields[i] = fields[i]->UpdatePhys();
52  NonLinear[i] = Array<OneD, NekDouble> (nphys);
53  NonLinearDealiased[i] = Array<OneD, NekDouble> (nphys);
54  }
55 
56  // calculate non-linear terms without dealiasing
57  IncNav->GetAdvObject()->SetSpecHPDealiasing(false);
58  IncNav->GetAdvObject()->DoAdvection(fields,nConvectiveFields,
59  IncNav->GetVelocity(), VelFields,
60  NonLinear, 0.0);
61 
62 
63  // calculate non-linear terms with dealiasing
64  IncNav->GetAdvObject()->SetSpecHPDealiasing(true);
65  IncNav->GetAdvObject()->DoAdvection(fields,nConvectiveFields,
66  IncNav->GetVelocity(), VelFields,
67  NonLinearDealiased, 0.0);
68 
69  // Evaulate Difference and put into fields;
70  for(i = 0; i < nConvectiveFields; ++i)
71  {
72  Vmath::Vsub(nphys,NonLinearDealiased[i],1,NonLinear[i],1,NonLinear[i],1);
73  fields[i]->FwdTrans_IterPerExp(NonLinear[i],fields[i]->UpdateCoeffs());
74  // Need to reset varibale name for output
75  string name = "NL_Aliasing_"+session->GetVariable(i);
76  session->SetVariable(i,name.c_str());
77  }
78 
79 
80  // Reset session name for output file
81  std::string outname = IncNav->GetSessionName();
82 
83  outname += "_NonLinear_Aliasing";
84  IncNav->ResetSessionName(outname);
85  IncNav->Output();
86 
87  }
88  catch (const std::runtime_error&)
89  {
90  return 1;
91  }
92  catch (const std::string& eStr)
93  {
94  cout << "Error: " << eStr << endl;
95  }
96 
97 
98  return 0;
99 }
100