Nektar++
CFLStep.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: CFLStep.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <cstdio>
36 #include <cstdlib>
37 
39 #include <SolverUtils/Driver.h>
40 
42 
43 using namespace std;
44 using namespace Nektar;
45 using namespace Nektar::SolverUtils;
46 
47 int main(int argc, char *argv[])
48 {
49  if (argc != 2)
50  {
51  fprintf(stderr, "Usage: ./CflStep file.xml \n");
52  fprintf(stderr, "\t Method will read intiial conditions section of "
53  ".xml file for input \n");
54  exit(1);
55  }
56 
59 
60  string vDriverModule;
61  DriverSharedPtr drv;
62  try
63  {
64  // Create session reader.
65  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
66 
67  // Create MeshGraph.
68  graph = SpatialDomains::MeshGraph::Read(session);
69 
70  // Create driver
71  session->LoadSolverInfo("Driver", vDriverModule, "Standard");
72  drv = GetDriverFactory().CreateInstance(vDriverModule, session, graph);
73 
74  EquationSystemSharedPtr EqSys = drv->GetEqu()[0];
75  IncNavierStokesSharedPtr IncNav = EqSys->as<IncNavierStokes>();
76 
77  IncNav->SetInitialConditions(0.0, false);
78  Array<OneD, NekDouble> cfl = IncNav->GetElmtCFLVals();
79 
80  // Reset Pressure field with CFL values
82  IncNav->UpdateFields();
83  int i, n, nquad, cnt;
84  int nfields = fields.size();
85  int nexp = fields[0]->GetExpSize();
86 
87  int elmtid = Vmath::Imax(nexp, cfl, 1);
88 
89  cout << "Max CFL: " << cfl[elmtid] << " In element " << elmtid << endl;
90 
91  for (n = 0; n < nfields; ++n)
92  {
93  if (session->GetVariable(n) == "p")
94  {
95  break;
96  }
97  }
98 
99  ASSERTL0(n != nfields, "Could not find field named p in m_fields");
100 
101  Array<OneD, NekDouble> phys = fields[n]->UpdatePhys();
102 
103  cnt = 0;
104  for (i = 0; i < fields[n]->GetExpSize(); ++i)
105  {
106  nquad = fields[n]->GetExp(i)->GetTotPoints();
107  Vmath::Fill(nquad, cfl[i], &phys[cnt], 1);
108  cnt += nquad;
109  }
110 
111  fields[n]->FwdTransLocalElmt(fields[n]->GetPhys(),
112  fields[n]->UpdateCoeffs());
113 
114  // Need to reset varibale name for output
115  session->SetVariable(n, "CFL");
116 
117  // Reset session name for output file
118  std::string outname = IncNav->GetSessionName();
119 
120  outname += "_CFLStep";
121  IncNav->ResetSessionName(outname);
122  IncNav->Output();
123  }
124  catch (const std::runtime_error &)
125  {
126  return 1;
127  }
128  catch (const std::string &eStr)
129  {
130  cout << "Error: " << eStr << endl;
131  }
132 
133  return 0;
134 }
int main(int argc, char *argv[])
Definition: CFLStep.cpp:47
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
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:144
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:64
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
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:918
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45