Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
DiffusionSolver.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/FieldIO.h>
#include <SpatialDomains/MeshGraph.h>
#include <MultiRegions/ContField2D.h>
Include dependency graph for DiffusionSolver.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 44 of file DiffusionSolver.cpp.

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

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