Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Diffusion Class Reference
Collaboration diagram for Diffusion:
Collaboration graph
[legend]

Public Member Functions

 Diffusion (int argc, char *argv[])
 
 ~Diffusion ()
 
void TimeIntegrate ()
 
void DoImplicitSolve (const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time, const NekDouble lambda)
 

Private Member Functions

void WriteSolution ()
 
void ExactSolution ()
 

Private Attributes

LibUtilities::SessionReaderSharedPtr session
 
LibUtilities::FieldIOSharedPtr fld
 
string sessionName
 
SpatialDomains::MeshGraphSharedPtr graph
 
MultiRegions::ContField2DSharedPtr field
 
LibUtilities::TimeIntegrationWrapperSharedPtr IntScheme
 
LibUtilities::TimeIntegrationSolutionSharedPtr u
 
LibUtilities::TimeIntegrationSchemeOperators ode
 
Array< OneD, Array< OneD,
NekDouble > > 
fields
 
string scheme
 
unsigned int nSteps
 
NekDouble delta_t
 
NekDouble epsilon
 
NekDouble lambda
 

Detailed Description

Definition at line 47 of file DiffusionSolverTimeInt.cpp.

Constructor & Destructor Documentation

Diffusion::Diffusion ( int  argc,
char *  argv[] 
)

Definition at line 84 of file DiffusionSolverTimeInt.cpp.

85 {
86  // Create session reader.
87  session = LibUtilities::SessionReader::CreateInstance(argc, argv);
88 
89  // Create Field I/O object.
91  AllocateSharedPtr(session->GetComm());
92 
93  // Get some information from the session
94  sessionName = session->GetSessionName();
95  scheme = session->GetSolverInfo("TimeIntegrationMethod");
96  nSteps = session->GetParameter("NumSteps");
97  delta_t = session->GetParameter("TimeStep");
98  epsilon = session->GetParameter("epsilon");
99  lambda = 1.0/delta_t/epsilon;
100 
101  // Read the geometry and the expansion information
102  graph = SpatialDomains::MeshGraph::Read(session);
103 
104  // Set up the field
106  AllocateSharedPtr(session, graph, session->GetVariable(0));
107 
109  fields[0] = field->UpdatePhys();
110 
111  // Get coordinates of physical points
112  unsigned int nq = field->GetNpoints();
113  Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
114  field->GetCoords(x0,x1,x2);
115 
116  // Evaluate initial condition
118  = session->GetFunction("InitialConditions", "u");
119  icond->Evaluate(x0,x1,x2,0.0,field->UpdatePhys());
120 }
MultiRegions::ContField2DSharedPtr field
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
LibUtilities::FieldIOSharedPtr fld
Array< OneD, Array< OneD, NekDouble > > fields
boost::shared_ptr< Equation > EquationSharedPtr
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
unsigned int nSteps
Diffusion::~Diffusion ( )

Definition at line 122 of file DiffusionSolverTimeInt.cpp.

123 {
124  session->Finalise();
125 }
LibUtilities::SessionReaderSharedPtr session

Member Function Documentation

void Diffusion::DoImplicitSolve ( const Array< OneD, const Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble  time,
const NekDouble  lambda 
)

Definition at line 152 of file DiffusionSolverTimeInt.cpp.

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

Referenced by TimeIntegrate().

157 {
160 
161  for (int i = 0; i < inarray.num_elements(); ++i)
162  {
163  // Multiply RHS by 1.0/timestep/lambda
164  Vmath::Smul(field->GetNpoints(), -factors[StdRegions::eFactorLambda],
165  inarray [i], 1,
166  outarray[i], 1);
167 
168  // Solve a system of equations with Helmholtz solver
169  field->HelmSolve(outarray[i],
170  field->UpdateCoeffs(),
171  NullFlagList, factors);
172 
173  // Transform to physical space and store in solution vector
174  field->BwdTrans (field->GetCoeffs(), outarray[i]);
175  }
176 }
MultiRegions::ContField2DSharedPtr field
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:251
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
static FlagList NullFlagList
An empty flag list.
void Diffusion::ExactSolution ( )
private

Definition at line 194 of file DiffusionSolverTimeInt.cpp.

195 {
196  unsigned int nq = field->GetNpoints();
197  Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
198  field->GetCoords(x0,x1,x2);
199 
201  session->GetFunction("ExactSolution",0);
202 
203  if(ex_sol)
204  {
205  // evaluate exact solution
206  Array<OneD, NekDouble> exact(nq);
207  ex_sol->Evaluate(x0, x1, x2, (nSteps)*delta_t, exact);
208 
209  // Calculate errors
210  cout << "L inf error: "
211  << field->Linf(field->GetPhys(), exact) << endl;
212  cout << "L 2 error: "
213  << field->L2(field->GetPhys(), exact) << endl;
214  cout << "H 1 error: "
215  << field->H1(field->GetPhys(), exact) << endl;
216  }
217 
218 }
MultiRegions::ContField2DSharedPtr field
boost::shared_ptr< Equation > EquationSharedPtr
LibUtilities::SessionReaderSharedPtr session
unsigned int nSteps
void Diffusion::TimeIntegrate ( )

Definition at line 127 of file DiffusionSolverTimeInt.cpp.

References DoImplicitSolve(), Nektar::LibUtilities::GetTimeIntegrationWrapperFactory(), Vmath::Vcopy(), and Vmath::Zero().

128 {
130  CreateInstance(scheme);
131 
133 
134  // Initialise the scheme for actual time integration scheme
135  u = IntScheme->InitializeScheme(delta_t, fields, 0.0, ode);
136 
137  // Zero field coefficients for initial guess for linear solver.
138  Vmath::Zero(field->GetNcoeffs(), field->UpdateCoeffs(), 1);
139 
140  for (int n = 0; n < nSteps; ++n)
141  {
142  fields = IntScheme->TimeIntegrate(n, delta_t, u, ode);
143  }
144  Vmath::Vcopy(field->GetNpoints(), fields[0], 1, field->UpdatePhys(), 1);
145 
146  WriteSolution();
147  ExactSolution();
148 
149 }
LibUtilities::TimeIntegrationWrapperSharedPtr IntScheme
MultiRegions::ContField2DSharedPtr field
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
LibUtilities::TimeIntegrationSolutionSharedPtr u
Array< OneD, Array< OneD, NekDouble > > fields
TimeIntegrationWrapperFactory & GetTimeIntegrationWrapperFactory()
void DoImplicitSolve(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time, const NekDouble lambda)
LibUtilities::TimeIntegrationSchemeOperators ode
unsigned int nSteps
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:359
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
void Diffusion::WriteSolution ( )
private

Definition at line 178 of file DiffusionSolverTimeInt.cpp.

179 {
180  // Write solution to file
181  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
182  = field->GetFieldDefinitions();
183  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
184  for(int i = 0; i < FieldDef.size(); ++i)
185  {
186  FieldDef[i]->m_fields.push_back("u");
187  field->AppendFieldData(FieldDef[i], FieldData[i]);
188  }
189  fld->Write(session->GetSessionName() + ".fld", FieldDef, FieldData);
190 
191 }
MultiRegions::ContField2DSharedPtr field
LibUtilities::FieldIOSharedPtr fld
LibUtilities::SessionReaderSharedPtr session

Member Data Documentation

NekDouble Diffusion::delta_t
private

Definition at line 75 of file DiffusionSolverTimeInt.cpp.

NekDouble Diffusion::epsilon
private

Definition at line 76 of file DiffusionSolverTimeInt.cpp.

MultiRegions::ContField2DSharedPtr Diffusion::field
private

Definition at line 66 of file DiffusionSolverTimeInt.cpp.

Array<OneD, Array<OneD, NekDouble> > Diffusion::fields
private

Definition at line 71 of file DiffusionSolverTimeInt.cpp.

LibUtilities::FieldIOSharedPtr Diffusion::fld
private

Definition at line 63 of file DiffusionSolverTimeInt.cpp.

SpatialDomains::MeshGraphSharedPtr Diffusion::graph
private

Definition at line 65 of file DiffusionSolverTimeInt.cpp.

LibUtilities::TimeIntegrationWrapperSharedPtr Diffusion::IntScheme
private

Definition at line 68 of file DiffusionSolverTimeInt.cpp.

NekDouble Diffusion::lambda
private

Definition at line 77 of file DiffusionSolverTimeInt.cpp.

unsigned int Diffusion::nSteps
private

Definition at line 74 of file DiffusionSolverTimeInt.cpp.

Definition at line 70 of file DiffusionSolverTimeInt.cpp.

string Diffusion::scheme
private

Definition at line 73 of file DiffusionSolverTimeInt.cpp.

LibUtilities::SessionReaderSharedPtr Diffusion::session
private

Definition at line 62 of file DiffusionSolverTimeInt.cpp.

string Diffusion::sessionName
private

Definition at line 64 of file DiffusionSolverTimeInt.cpp.

Definition at line 69 of file DiffusionSolverTimeInt.cpp.