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