Nektar++
Functions
DiffusionSolver.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include <SpatialDomains/MeshGraph.h>
#include <MultiRegions/ContField2D.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 43 of file DiffusionSolver.cpp.

References Nektar::StdRegions::eFactorLambda, Nektar::NullFlagList, Vmath::Smul(), and Vmath::Zero().

44 {
49  LibUtilities::EquationSharedPtr icond, ex_sol;
51 
52  try
53  {
54  // Create session reader.
55  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
56 
57  // Read the geometry and the expansion information
58  graph = SpatialDomains::MeshGraph::Read(session);
59 
60  // Create Field I/O object.
61  fld = LibUtilities::FieldIO::CreateDefault(session);
62 
63  // Get some information about the session
64  string sessionName = session->GetSessionName();
65  string outFile = sessionName + ".fld";
66  unsigned int nSteps = session->GetParameter("NumSteps");
67  NekDouble delta_t = session->GetParameter("TimeStep");
68  NekDouble epsilon = session->GetParameter("epsilon" );
69 
70  // Create field
72  ::AllocateSharedPtr(session, graph, session->GetVariable(0));
73 
74  // Get coordinates of physical points
75  unsigned int nq = field->GetNpoints();
76  Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
77  field->GetCoords(x0,x1,x2);
78 
79  // Evaluate initial condition at these points
80  icond = session->GetFunction("InitialConditions", "u");
81  icond->Evaluate(x0, x1, x2, 0.0, field->UpdatePhys());
82 
83  // Compute lambda in the Helmholtz problem
84  factors[StdRegions::eFactorLambda] = 1.0/delta_t/epsilon;
85 
86  // Zero field coefficients for initial guess for linear solver.
87  Vmath::Zero(field->GetNcoeffs(), field->UpdateCoeffs(), 1);
88 
89  // Time integrate using backward Euler
90  for (unsigned int n = 0; n < nSteps; ++n)
91  {
92  Vmath::Smul(nq, -1.0/delta_t/epsilon, field->GetPhys(), 1,
93  field->UpdatePhys(), 1);
94 
95  field->HelmSolve(field->GetPhys(), field->UpdateCoeffs(),
96  NullFlagList, factors);
97 
98  field->BwdTrans(field->GetCoeffs(), field->UpdatePhys());
99  }
100 
101  // Write solution to file
102  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
103  = field->GetFieldDefinitions();
104  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
105  for(int i = 0; i < FieldDef.size(); ++i)
106  {
107  FieldDef[i]->m_fields.push_back("u");
108  field->AppendFieldData(FieldDef[i], FieldData[i]);
109  }
110  fld->Write(outFile, FieldDef, FieldData);
111 
112  // Check for exact solution
113  ex_sol = session->GetFunction("ExactSolution",0);
114  if(ex_sol)
115  {
116  // Allocate storage
117  Array<OneD, NekDouble> exact(nq);
118 
119  //----------------------------------------------
120  // evaluate exact solution
121  ex_sol->Evaluate(x0, x1, x2, (nSteps)*delta_t, exact);
122 
123  //--------------------------------------------
124  // Calculate errors
125  cout << "L inf error: "
126  << field->Linf(field->GetPhys(), exact) << endl;
127  cout << "L 2 error: "
128  << field->L2(field->GetPhys(), exact) << endl;
129  cout << "H 1 error: "
130  << field->H1(field->GetPhys(), exact) << endl;
131  //--------------------------------------------
132  }
133 
134  // Finalise session
135  session->Finalise();
136  }
137  catch (const std::runtime_error& e)
138  {
139  return 1;
140  }
141  catch (const std::string& eStr)
142  {
143  cout << "Error: " << eStr << endl;
144  }
145 
146  return 0;
147 }
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:163
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< ContField2D > ContField2DSharedPtr
Definition: ContField2D.h:289
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:294
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:216
double NekDouble
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:131
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:306
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static FlagList NullFlagList
An empty flag list.