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

Constructor & Destructor Documentation

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

Definition at line 83 of file DiffusionSolverTimeInt.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::SessionReader::CreateInstance(), and Nektar::SpatialDomains::MeshGraph::Read().

{
// Create session reader.
session = LibUtilities::SessionReader::CreateInstance(argc, argv);
// Create Field I/O object.
// Get some information from the session
sessionName = session->GetSessionName();
scheme = session->GetSolverInfo("TimeIntegrationMethod");
nSteps = session->GetParameter("NumSteps");
delta_t = session->GetParameter("TimeStep");
epsilon = session->GetParameter("epsilon");
// Read the geometry and the expansion information
graph = SpatialDomains::MeshGraph::Read(session);
// Set up the field
fields = Array<OneD, Array<OneD, NekDouble> >(1);
fields[0] = field->UpdatePhys();
// Get coordinates of physical points
unsigned int nq = field->GetNpoints();
Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
field->GetCoords(x0,x1,x2);
// Evaluate initial condition
= session->GetFunction("InitialConditions", "u");
icond->Evaluate(x0,x1,x2,0.0,field->UpdatePhys());
}
Diffusion::~Diffusion ( )

Definition at line 121 of file DiffusionSolverTimeInt.cpp.

{
session->Finalise();
}

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

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

Referenced by TimeIntegrate().

{
for (int i = 0; i < inarray.num_elements(); ++i)
{
// Multiply RHS by 1.0/timestep/lambda
Vmath::Smul(field->GetNpoints(), -factors[StdRegions::eFactorLambda],
inarray [i], 1,
outarray[i], 1);
// Solve a system of equations with Helmholtz solver
field->HelmSolve(outarray[i],
field->UpdateCoeffs(),
NullFlagList, factors);
// Transform to physical space and store in solution vector
field->BwdTrans (field->GetCoeffs(), outarray[i]);
}
}
void Diffusion::ExactSolution ( )
private

Definition at line 193 of file DiffusionSolverTimeInt.cpp.

{
unsigned int nq = field->GetNpoints();
Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
field->GetCoords(x0,x1,x2);
session->GetFunction("ExactSolution",0);
if(ex_sol)
{
// evaluate exact solution
Array<OneD, NekDouble> exact(nq);
ex_sol->Evaluate(x0, x1, x2, (nSteps)*delta_t, exact);
// Calculate errors
cout << "L inf error: "
<< field->Linf(field->GetPhys(), exact) << endl;
cout << "L 2 error: "
<< field->L2(field->GetPhys(), exact) << endl;
cout << "H 1 error: "
<< field->H1(field->GetPhys(), exact) << endl;
}
}
void Diffusion::TimeIntegrate ( )

Definition at line 126 of file DiffusionSolverTimeInt.cpp.

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

Referenced by main().

{
CreateInstance(scheme);
// Initialise the scheme for actual time integration scheme
u = IntScheme->InitializeScheme(delta_t, fields, 0.0, ode);
// Zero field coefficients for initial guess for linear solver.
Vmath::Zero(field->GetNcoeffs(), field->UpdateCoeffs(), 1);
for (int n = 0; n < nSteps; ++n)
{
fields = IntScheme->TimeIntegrate(n, delta_t, u, ode);
}
Vmath::Vcopy(field->GetNpoints(), fields[0], 1, field->UpdatePhys(), 1);
}
void Diffusion::WriteSolution ( )
private

Definition at line 177 of file DiffusionSolverTimeInt.cpp.

{
// Write solution to file
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
= field->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
for(int i = 0; i < FieldDef.size(); ++i)
{
FieldDef[i]->m_fields.push_back("u");
field->AppendFieldData(FieldDef[i], FieldData[i]);
}
fld->Write(session->GetSessionName() + ".fld", FieldDef, FieldData);
}

Member Data Documentation

NekDouble Diffusion::delta_t
private

Definition at line 74 of file DiffusionSolverTimeInt.cpp.

NekDouble Diffusion::epsilon
private

Definition at line 75 of file DiffusionSolverTimeInt.cpp.

MultiRegions::ContField2DSharedPtr Diffusion::field
private

Definition at line 65 of file DiffusionSolverTimeInt.cpp.

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

Definition at line 70 of file DiffusionSolverTimeInt.cpp.

LibUtilities::FieldIOSharedPtr Diffusion::fld
private

Definition at line 62 of file DiffusionSolverTimeInt.cpp.

SpatialDomains::MeshGraphSharedPtr Diffusion::graph
private

Definition at line 64 of file DiffusionSolverTimeInt.cpp.

LibUtilities::TimeIntegrationWrapperSharedPtr Diffusion::IntScheme
private

Definition at line 67 of file DiffusionSolverTimeInt.cpp.

NekDouble Diffusion::lambda
private

Definition at line 76 of file DiffusionSolverTimeInt.cpp.

unsigned int Diffusion::nSteps
private

Definition at line 73 of file DiffusionSolverTimeInt.cpp.

Definition at line 69 of file DiffusionSolverTimeInt.cpp.

string Diffusion::scheme
private

Definition at line 72 of file DiffusionSolverTimeInt.cpp.

LibUtilities::SessionReaderSharedPtr Diffusion::session
private

Definition at line 61 of file DiffusionSolverTimeInt.cpp.

string Diffusion::sessionName
private

Definition at line 63 of file DiffusionSolverTimeInt.cpp.

Definition at line 68 of file DiffusionSolverTimeInt.cpp.