Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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.
90  fld = LibUtilities::FieldIO::CreateDefault(session);
91 
92  // Get some information from the session
93  sessionName = session->GetSessionName();
94  scheme = session->GetSolverInfo("TimeIntegrationMethod");
95  nSteps = session->GetParameter("NumSteps");
96  delta_t = session->GetParameter("TimeStep");
97  epsilon = session->GetParameter("epsilon");
98  lambda = 1.0/delta_t/epsilon;
99 
100  // Read the geometry and the expansion information
101  graph = SpatialDomains::MeshGraph::Read(session);
102 
103  // Set up the field
105  AllocateSharedPtr(session, graph, session->GetVariable(0));
106 
108  fields[0] = field->UpdatePhys();
109 
110  // Get coordinates of physical points
111  unsigned int nq = field->GetNpoints();
112  Array<OneD,NekDouble> x0(nq), x1(nq), x2(nq);
113  field->GetCoords(x0,x1,x2);
114 
115  // Evaluate initial condition
117  = session->GetFunction("InitialConditions", "u");
118  icond->Evaluate(x0,x1,x2,0.0,field->UpdatePhys());
119 }
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 121 of file DiffusionSolverTimeInt.cpp.

122 {
123  session->Finalise();
124 }
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 151 of file DiffusionSolverTimeInt.cpp.

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

Referenced by TimeIntegrate().

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

Definition at line 193 of file DiffusionSolverTimeInt.cpp.

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

Definition at line 126 of file DiffusionSolverTimeInt.cpp.

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

127 {
129  CreateInstance(scheme);
130 
132 
133  // Initialise the scheme for actual time integration scheme
134  u = IntScheme->InitializeScheme(delta_t, fields, 0.0, ode);
135 
136  // Zero field coefficients for initial guess for linear solver.
137  Vmath::Zero(field->GetNcoeffs(), field->UpdateCoeffs(), 1);
138 
139  for (int n = 0; n < nSteps; ++n)
140  {
141  fields = IntScheme->TimeIntegrate(n, delta_t, u, ode);
142  }
143  Vmath::Vcopy(field->GetNpoints(), fields[0], 1, field->UpdatePhys(), 1);
144 
145  WriteSolution();
146  ExactSolution();
147 
148 }
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:373
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
void Diffusion::WriteSolution ( )
private

Definition at line 177 of file DiffusionSolverTimeInt.cpp.

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