Nektar++
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Diffusion Class Reference

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::ContFieldSharedPtr field
 
LibUtilities::TimeIntegrationSchemeSharedPtr intScheme
 
LibUtilities::TimeIntegrationSchemeOperators ode
 
Array< OneD, Array< OneD, NekDouble > > fields
 
LibUtilities::TimeIntScheme timeInt
 
unsigned int nSteps
 
NekDouble delta_t
 
NekDouble epsilon
 
NekDouble lambda
 

Detailed Description

Definition at line 48 of file DiffusionSolverTimeInt.cpp.

Constructor & Destructor Documentation

◆ Diffusion()

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

Definition at line 82 of file DiffusionSolverTimeInt.cpp.

83{
84 // Create session reader.
85 session = LibUtilities::SessionReader::CreateInstance(argc, argv);
86
87 // Read the geometry and the expansion information
88 graph = SpatialDomains::MeshGraphIO::Read(session);
89
90 // Create Field I/O object.
91 fld = LibUtilities::FieldIO::CreateDefault(session);
92
93 // Get some information from the session
94 sessionName = session->GetSessionName();
95
96 // Create time integration scheme.
97 if (session->DefinesTimeIntScheme())
98 {
99 timeInt = session->GetTimeIntScheme();
100 }
101 else
102 {
103 timeInt.method = session->GetSolverInfo("TimeIntegrationMethod");
104 }
105
106 nSteps = session->GetParameter("NumSteps");
107 delta_t = session->GetParameter("TimeStep");
108 epsilon = session->GetParameter("epsilon");
109 lambda = 1.0 / delta_t / epsilon;
110
111 // Set up the field
113 session, graph, session->GetVariable(0));
114
116 fields[0] = field->UpdatePhys();
117
118 // Get coordinates of physical points
119 unsigned int nq = field->GetNpoints();
120 Array<OneD, NekDouble> x0(nq), x1(nq), x2(nq);
121 field->GetCoords(x0, x1, x2);
122
123 // Evaluate initial condition
125 session->GetFunction("InitialConditions", "u");
126 icond->Evaluate(x0, x1, x2, 0.0, field->UpdatePhys());
127}
LibUtilities::TimeIntScheme timeInt
MultiRegions::ContFieldSharedPtr field
SpatialDomains::MeshGraphSharedPtr graph
LibUtilities::FieldIOSharedPtr fld
unsigned int nSteps
LibUtilities::SessionReaderSharedPtr session
Array< OneD, Array< OneD, NekDouble > > fields
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::FieldIO::CreateDefault(), Nektar::LibUtilities::SessionReader::CreateInstance(), FilterPython_Function::field, and Nektar::SpatialDomains::MeshGraphIO::Read().

◆ ~Diffusion()

Diffusion::~Diffusion ( )

Member Function Documentation

◆ DoImplicitSolve()

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 158 of file DiffusionSolverTimeInt.cpp.

162{
165
166 for (int i = 0; i < inarray.size(); ++i)
167 {
168 // Multiply RHS by 1.0/timestep/lambda
170 inarray[i], 1, outarray[i], 1);
171
172 // Solve a system of equations with Helmholtz solver
173 field->HelmSolve(outarray[i], field->UpdateCoeffs(), factors);
174
175 // Transform to physical space and store in solution vector
176 field->BwdTrans(field->GetCoeffs(), outarray[i]);
177 }
178}
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:430
StdRegions::ConstFactorMap factors
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100

References Nektar::StdRegions::eFactorLambda, Nektar::VarcoeffHashingTest::factors, FilterPython_Function::field, and Vmath::Smul().

Referenced by TimeIntegrate().

◆ ExactSolution()

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: " << field->Linf(field->GetPhys(), exact)
211 << endl;
212 cout << "L 2 error: " << field->L2(field->GetPhys(), exact)
213 << endl;
214 cout << "H 1 error: " << field->H1(field->GetPhys(), exact)
215 << endl;
216 }
217}

References FilterPython_Function::field.

◆ TimeIntegrate()

void Diffusion::TimeIntegrate ( )

Definition at line 134 of file DiffusionSolverTimeInt.cpp.

135{
138
140
141 // Initialise the scheme for actual time integration scheme
142 intScheme->InitializeScheme(delta_t, fields, 0.0, ode);
143
144 // Zero field coefficients for initial guess for linear solver.
145 Vmath::Zero(field->GetNcoeffs(), field->UpdateCoeffs(), 1);
146
147 for (int n = 0; n < nSteps; ++n)
148 {
149 fields = intScheme->TimeIntegrate(n, delta_t);
150 }
151
152 Vmath::Vcopy(field->GetNpoints(), fields[0], 1, field->UpdatePhys(), 1);
153
156}
LibUtilities::TimeIntegrationSchemeOperators ode
void DoImplicitSolve(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time, const NekDouble lambda)
LibUtilities::TimeIntegrationSchemeSharedPtr intScheme
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
TimeIntegrationSchemeFactory & GetTimeIntegrationSchemeFactory()
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
std::vector< NekDouble > freeParams
Definition: SessionReader.h:87

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), DoImplicitSolve(), FilterPython_Function::field, Nektar::LibUtilities::GetTimeIntegrationSchemeFactory(), Vmath::Vcopy(), and Vmath::Zero().

◆ WriteSolution()

void Diffusion::WriteSolution ( )
private

Definition at line 180 of file DiffusionSolverTimeInt.cpp.

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

References FilterPython_Function::field.

Member Data Documentation

◆ delta_t

NekDouble Diffusion::delta_t
private

Definition at line 74 of file DiffusionSolverTimeInt.cpp.

◆ epsilon

NekDouble Diffusion::epsilon
private

Definition at line 75 of file DiffusionSolverTimeInt.cpp.

◆ field

MultiRegions::ContFieldSharedPtr Diffusion::field
private

◆ fields

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

Definition at line 70 of file DiffusionSolverTimeInt.cpp.

◆ fld

LibUtilities::FieldIOSharedPtr Diffusion::fld
private

Definition at line 63 of file DiffusionSolverTimeInt.cpp.

◆ graph

SpatialDomains::MeshGraphSharedPtr Diffusion::graph
private

Definition at line 65 of file DiffusionSolverTimeInt.cpp.

◆ intScheme

LibUtilities::TimeIntegrationSchemeSharedPtr Diffusion::intScheme
private

Definition at line 68 of file DiffusionSolverTimeInt.cpp.

◆ lambda

NekDouble Diffusion::lambda
private

Definition at line 76 of file DiffusionSolverTimeInt.cpp.

◆ nSteps

unsigned int Diffusion::nSteps
private

Definition at line 73 of file DiffusionSolverTimeInt.cpp.

◆ ode

Definition at line 69 of file DiffusionSolverTimeInt.cpp.

◆ session

LibUtilities::SessionReaderSharedPtr Diffusion::session
private

Definition at line 62 of file DiffusionSolverTimeInt.cpp.

◆ sessionName

string Diffusion::sessionName
private

Definition at line 64 of file DiffusionSolverTimeInt.cpp.

◆ timeInt

LibUtilities::TimeIntScheme Diffusion::timeInt
private

Definition at line 72 of file DiffusionSolverTimeInt.cpp.