35 #include <boost/core/ignore_unused.hpp> 58 #include <boost/format.hpp> 70 std::string EquationSystem::equationSystemTypeLookupIds[2] = {
71 LibUtilities::SessionReader::RegisterEnumValue(
"DEALIASING",
73 LibUtilities::SessionReader::RegisterEnumValue(
"DEALIASING",
101 EquationSystem::EquationSystem(
104 : m_comm (pSession->GetComm()),
105 m_session (pSession),
111 const vector<std::string> filenames =
m_session->GetFilenames();
113 for(
int i = 0; i < filenames.size(); ++i)
115 string sessionname =
"SessionName";
116 sessionname += boost::lexical_cast<std::string>(i);
118 m_fieldMetaDataMap[
"ChkFileNum"] =
119 boost::lexical_cast<std::string>(0);
152 if (
m_session->DefinesSolverInfo(
"HOMOGENEOUS"))
154 std::string HomoStr =
m_session->GetSolverInfo(
"HOMOGENEOUS");
157 if ((HomoStr ==
"HOMOGENEOUS1D") || (HomoStr ==
"Homogeneous1D")
158 || (HomoStr ==
"1D") || (HomoStr ==
"Homo1D"))
164 if(
m_session->DefinesSolverInfo(
"ModeType"))
166 m_session->MatchSolverInfo(
"ModeType",
"SingleMode",
168 m_session->MatchSolverInfo(
"ModeType",
"HalfMode",
170 m_session->MatchSolverInfo(
"ModeType",
"MultipleModes",
175 if (
m_session->DefinesSolverInfo(
"ModeType"))
191 ASSERTL0(
false,
"SolverInfo ModeType not valid");
200 if ((HomoStr ==
"HOMOGENEOUS2D") || (HomoStr ==
"Homogeneous2D")
201 || (HomoStr ==
"2D") || (HomoStr ==
"Homo2D"))
211 if ((HomoStr ==
"HOMOGENEOUS3D") || (HomoStr ==
"Homogeneous3D")
212 || (HomoStr ==
"3D") || (HomoStr ==
"Homo3D"))
224 m_session->MatchSolverInfo(
"DEALIASING",
"True",
234 m_session->MatchSolverInfo(
"SPECTRALHPDEALIASING",
"True",
238 m_session->MatchSolverInfo(
"SPECTRALHPDEALIASING",
"On",
244 if (
m_session->DefinesSolverInfo(
"PROJECTION"))
246 std::string ProjectStr =
m_session->GetSolverInfo(
"PROJECTION");
248 if ((ProjectStr ==
"Continuous") || (ProjectStr ==
"Galerkin") ||
249 (ProjectStr ==
"CONTINUOUS") || (ProjectStr ==
"GALERKIN"))
253 else if ((ProjectStr ==
"MixedCGDG") ||
254 (ProjectStr ==
"Mixed_CG_Discontinuous"))
258 else if(ProjectStr ==
"DisContinuous")
264 ASSERTL0(
false,
"PROJECTION value not recognised");
269 cerr <<
"Projection type not specified in SOLVERINFO," 270 "defaulting to continuous Galerkin" << endl;
278 int nvariables =
m_session->GetVariables().size();
279 bool DeclareCoeffPhysArrays =
true;
306 for (i = 0; i <
m_fields.num_elements(); i++)
309 ::ContField3DHomogeneous2D>
319 for (i = 0; i <
m_fields.num_elements(); i++)
346 for(i = 0; i <
m_fields.num_elements(); i++)
349 ::ContField3DHomogeneous1D>
374 for (i = 0; i <
m_fields.num_elements(); i++)
376 if(
m_session->GetVariable(i).compare(
"w")
380 ::ContField3DHomogeneous1D>
392 ::ContField3DHomogeneous1D>
413 for (i = 0; i <
m_fields.num_elements(); i++)
416 ::ContField3DHomogeneous1D>
431 ContField2D>::AllocateSharedPtr(
434 DeclareCoeffPhysArrays,
437 for (i = 1; i < m_fields.num_elements(); i++)
440 SameExpansions(
m_session->GetVariable(0),
444 ContField2D>::AllocateSharedPtr(
447 DeclareCoeffPhysArrays,
453 ::ContField2D>::AllocateSharedPtr(
456 DeclareCoeffPhysArrays,
475 m_fields[0]->GetTrace()->
493 for (i = 1; i < m_fields.num_elements(); i++)
500 ::ContField3D>::AllocateSharedPtr(
508 ::ContField3D>::AllocateSharedPtr(
530 for(i = 1; i < m_fields.num_elements(); ++i)
532 m_fields[i]->GetTrace();
538 ASSERTL0(
false,
"Expansion dimension not recognised");
561 for (i = 0; i <
m_fields.num_elements(); i++)
564 ::DisContField3DHomogeneous2D>
574 for (i = 0; i <
m_fields.num_elements(); i++)
577 DisContField1D>::AllocateSharedPtr(
594 for (i = 0; i <
m_fields.num_elements(); i++)
597 ::DisContField3DHomogeneous1D>
606 for (i = 0; i <
m_fields.num_elements(); i++)
609 DisContField2D>::AllocateSharedPtr(
622 "3D fully periodic problems not implemented yet");
626 for (i = 0; i <
m_fields.num_elements(); i++)
629 DisContField3D>::AllocateSharedPtr(
637 ASSERTL0(
false,
"Expansion dimension not recognised");
661 m_session->LoadParameter(
"NumQuadPointsError",
668 "Only one of IO_CheckTime and IO_CheckSteps " 728 int nvariables =
m_fields.num_elements();
729 for (
int i = 0; i < nvariables; ++i)
732 m_fields[i]->EvaluateBoundaryConditions(time, varName);
752 if (
m_fields[field]->GetPhysState() ==
false)
758 if (exactsoln.num_elements())
761 m_fields[field]->GetPhys(), exactsoln);
763 else if (
m_session->DefinesFunction(
"ExactSolution"))
772 m_fields[field]->GetPhys(), exactsoln);
779 if (Normalised ==
true)
787 L2error = sqrt(L2error*L2error/Vol);
813 if (
m_fields[field]->GetPhysState() ==
false)
819 if (exactsoln.num_elements())
822 m_fields[field]->GetPhys(), exactsoln);
824 else if (
m_session->DefinesFunction(
"ExactSolution"))
833 m_fields[field]->GetPhys(), exactsoln);
845 Linferror = L2INF[1];
884 int ErrorCoordim = ErrorExp->GetCoordim(0);
885 int ErrorNq = ErrorExp->GetTotPoints();
894 ErrorExp->GetCoords(ErrorXc0);
897 ErrorExp->GetCoords(ErrorXc0, ErrorXc1);
900 ErrorExp->GetCoords(ErrorXc0, ErrorXc1, ErrorXc2);
904 m_session->GetFunction(
"ExactSolution", field);
909 exSol->Evaluate(ErrorXc0,ErrorXc1,ErrorXc2,
m_time,ErrorSol);
913 ErrorExp->BwdTrans_IterPerExp(
m_fields[field]->GetCoeffs(),
914 ErrorExp->UpdatePhys());
916 L2INF[0] = ErrorExp->L2 (ErrorExp->GetPhys(), ErrorSol);
917 L2INF[1] = ErrorExp->Linf(ErrorExp->GetPhys(), ErrorSol);
930 bool dumpInitialConditions,
933 boost::ignore_unused(initialtime);
935 if (
m_session->GetComm()->GetRank() == 0)
937 cout <<
"Initial Conditions:" << endl;
940 if (
m_session->DefinesFunction(
"InitialConditions"))
945 if (
m_session->GetComm()->GetRank() == 0)
948 for (
int i = 0; i <
m_fields.num_elements(); ++i)
950 std::string varName =
m_session->GetVariable(i);
951 cout <<
" - Field " << varName <<
": " 952 <<
GetFunction(
"InitialConditions")->Describe(varName, domain)
960 for (
int i = 0; i <
m_fields.num_elements(); i++)
966 if (
m_session->GetComm()->GetRank() == 0)
968 cout <<
" - Field " <<
m_session->GetVariable(i)
969 <<
": 0 (default)" << endl;
988 "ExactSolution array size mismatch.");
990 if (
m_session->DefinesFunction(
"ExactSolution"))
993 m_session->GetVariable(field), outfield, time);
1062 for (
int i = 0; i <
m_fields.num_elements(); i++)
1074 for (
int i = 0; i <
m_fields.num_elements(); i++)
1089 boost::lexical_cast<std::string>(n);
1101 std::vector<std::string> &variables)
1104 boost::lexical_cast<std::string>(n);
1105 WriteFld(outname, field, fieldcoeffs, variables);
1115 boost::lexical_cast<std::string>(n);
1126 std::vector<Array<OneD, NekDouble> > fieldcoeffs(
1128 std::vector<std::string> variables(
m_fields.num_elements());
1130 for (
int i = 0; i <
m_fields.num_elements(); ++i)
1134 fieldcoeffs[i] =
m_fields[i]->UpdateCoeffs();
1162 const std::string &outname,
1165 std::vector<std::string> &variables)
1167 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
1168 = field->GetFieldDefinitions();
1169 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
1172 for(
int j = 0; j < fieldcoeffs.size(); ++j)
1174 for(
int i = 0; i < FieldDef.size(); ++i)
1177 FieldDef[i]->m_fields.push_back(variables[j]);
1178 field->AppendFieldData(FieldDef[i], FieldData[i],
1187 boost::lexical_cast<std::string>(
m_time);
1194 boost::lexical_cast<std::string>(
m_nchk);
1204 mapping->Output( fieldMetaDataMap, outname);
1206 #ifdef NEKTAR_DISABLE_BACKUPS 1207 bool backup =
false;
1212 m_fld->Write(outname, FieldDef, FieldData, fieldMetaDataMap, backup);
1223 const std::string &infile,
1226 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
1227 std::vector<std::vector<NekDouble> > FieldData;
1230 field_fld->Import(infile,FieldDef,FieldData);
1233 for(
int j = 0; j < pFields.num_elements(); ++j)
1236 pFields[j]->UpdateCoeffs(),1);
1238 for(
int i = 0; i < FieldDef.size(); ++i)
1242 std::string(
"Order of ") + infile
1243 + std::string(
" data and that defined in " 1244 "m_boundaryconditions differs"));
1246 pFields[j]->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
1248 pFields[j]->UpdateCoeffs());
1250 pFields[j]->BwdTrans(pFields[j]->GetCoeffs(),
1251 pFields[j]->UpdatePhys());
1266 const std::string &infile,
1270 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
1271 std::vector<std::vector<NekDouble> > FieldData;
1277 ASSERTL0(ndomains*nvariables == pFields.num_elements(),
1278 "Number of fields does not match the number of variables and domains");
1281 for(
int j = 0; j < ndomains; ++j)
1283 for(
int i = 0; i < nvariables; ++i)
1286 pFields[j*nvariables+i]->UpdateCoeffs(),1);
1288 for(
int n = 0; n < FieldDef.size(); ++n)
1291 std::string(
"Order of ") + infile
1292 + std::string(
" data and that defined in " 1293 "m_boundaryconditions differs"));
1295 pFields[j*nvariables+i]->ExtractDataToCoeffs(
1296 FieldDef[n], FieldData[n],
1298 pFields[j*nvariables+i]->UpdateCoeffs());
1300 pFields[j*nvariables+i]->BwdTrans(
1301 pFields[j*nvariables+i]->GetCoeffs(),
1302 pFields[j*nvariables+i]->UpdatePhys());
1313 const std::string &infile,
1315 std::string &pFieldName)
1317 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
1318 std::vector<std::vector<NekDouble> > FieldData;
1322 field_fld->Import(infile,FieldDef,FieldData);
1325 Vmath::Zero(pField->GetNcoeffs(),pField->UpdateCoeffs(),1);
1327 for(
int i = 0; i < FieldDef.size(); ++i)
1330 for(
int j = 0; j < FieldData.size(); ++j)
1332 if (FieldDef[i]->
m_fields[j] == pFieldName)
1337 ASSERTL1(idx >= 0,
"Field " + pFieldName +
" not found.");
1339 pField->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
1341 pField->UpdateCoeffs());
1343 pField->BwdTrans(pField->GetCoeffs(), pField->UpdatePhys());
1354 const std::string &infile,
1355 std::vector< std::string> &fieldStr,
1359 ASSERTL0(fieldStr.size() <= coeffs.num_elements(),
1360 "length of fieldstr should be the same as pFields");
1362 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
1363 std::vector<std::vector<NekDouble> > FieldData;
1367 field_fld->Import(infile,FieldDef,FieldData);
1370 for(
int j = 0; j < fieldStr.size(); ++j)
1372 Vmath::Zero(coeffs[j].num_elements(),coeffs[j],1);
1373 for(
int i = 0; i < FieldDef.size(); ++i)
1375 m_fields[0]->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
1376 fieldStr[j], coeffs[j]);
1392 m_fields[0]->EvalBasisNumModesMax());
1394 if (
m_session->GetComm()->GetSize() > 1)
1435 if (
m_session->DefinesSolverInfo(
"UpwindType"))
1438 m_session->GetSolverInfo(
"UpwindType"));
1441 if (
m_session->DefinesSolverInfo(
"AdvectionType"))
1443 std::string AdvectionType;
1444 AdvectionType =
m_session->GetSolverInfo(
"AdvectionType");
1446 GetClassDescription(AdvectionType));
1460 "Mixed Continuous Galerkin and Discontinuous");
1463 if (
m_session->DefinesSolverInfo(
"DiffusionType"))
1465 std::string DiffusionType;
1466 DiffusionType =
m_session->GetSolverInfo(
"DiffusionType");
1468 GetClassDescription(DiffusionType));
1479 ASSERTL0(
false,
"This function is not valid for the Base class");
1486 std::vector<std::string> &variables)
1488 boost::ignore_unused(fieldcoeffs, variables);
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &l)
Virtual function for generating summary information.
bool m_singleMode
Flag to determine if single homogeneous mode is used.
#define ASSERTL0(condition, msg)
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
NekDouble m_time
Current time of simulation.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > &ElementIDs)
This function allows for data to be imported from an FLD file when a session and/or communicator is n...
NekDouble m_timestep
Time step size.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::vector< std::pair< std::string, std::string > > SummaryList
SOLVER_UTILS_EXPORT int GetNvariables()
bool m_halfMode
Flag to determine if half homogeneous mode is used.
NekDouble m_LhomZ
physical length in Z direction (if homogeneous)
virtual SOLVER_UTILS_EXPORT NekDouble v_L2Error(unsigned int field, const Array< OneD, NekDouble > &exactsoln=NullNekDouble1DArray, bool Normalised=false)
Virtual function for the L_2 error computation between fields and a given exact solution.
Array< OneD, bool > m_checkIfSystemSingular
Flag to indicate if the fields should be checked for singularity.
int m_expdim
Expansion dimension.
std::shared_ptr< ContField2D > ContField2DSharedPtr
SOLVER_UTILS_EXPORT void Checkpoint_Output(const int n)
Write checkpoint file of m_fields.
DiffusionFactory & GetDiffusionFactory()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
Principle Modified Functions .
SOLVER_UTILS_EXPORT Array< OneD, NekDouble > ErrorExtraPoints(unsigned int field)
Compute error (L2 and L_inf) over an larger set of quadrature points return [L2 Linf].
NekDouble m_checktime
Time between checkpoints.
bool m_useFFT
Flag to determine if FFT is used for homogeneous transform.
NekDouble m_LhomY
physical length in Y direction (if homogeneous)
bool m_specHP_dealiasing
Flag to determine if dealisising is usde for the Spectral/hp element discretisation.
SOLVER_UTILS_EXPORT int GetNumExpModes()
virtual SOLVER_UTILS_EXPORT void v_ExtraFldOutput(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables)
virtual SOLVER_UTILS_EXPORT NekDouble v_LinfError(unsigned int field, const Array< OneD, NekDouble > &exactsoln=NullNekDouble1DArray)
Virtual function for the L_inf error computation between fields and a given exact solution...
int m_npointsZ
number of points in Z direction (if homogeneous)
std::shared_ptr< ExpList2D > ExpList2DSharedPtr
Shared pointer to an ExpList2D object.
virtual SOLVER_UTILS_EXPORT ~EquationSystem()
Destructor.
std::string m_sessionName
Name of the session.
int m_nchk
Number of checkpoints written so far.
std::map< std::string, std::string > FieldMetaDataMap
int m_checksteps
Number of steps between checkpoints.
LibUtilities::CommSharedPtr m_comm
Communicator.
Gauss Radau pinned at x=-1, .
NekDouble m_fintime
Finish time of the simulation.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Initialisation object for EquationSystem.
int m_steps
Number of steps to take.
Array< OneD, Array< OneD, NekDouble > > m_traceNormals
Array holding trace normals for DG simulations in the forwards direction.
int m_HomoDirec
number of homogenous directions
std::shared_ptr< ContField3D > ContField3DSharedPtr
SOLVER_UTILS_EXPORT void FwdTransFields()
1D Evenly-spaced points using Fourier Fit
bool m_multipleModes
Flag to determine if use multiple homogenenous modes are used.
Fourier Modified expansions with just the real part of the first mode .
virtual SOLVER_UTILS_EXPORT Array< OneD, bool > v_GetSystemSingularChecks()
int m_npointsY
number of points in Y direction (if homogeneous)
Abstraction of a global continuous one-dimensional spectral/hp element expansion which approximates t...
std::map< std::string, SolverUtils::SessionFunctionSharedPtr > m_sessionFunctions
Map of known SessionFunctions.
NekMatrix< NekMatrix< NekMatrix< NekDouble, StandardMatrixTag >, ScaledMatrixTag >, BlockMatrixTag > DNekScalBlkMat
virtual SOLVER_UTILS_EXPORT void v_TransPhysToCoeff()
Virtual function for transformation to coefficient space.
Principle Modified Functions .
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
virtual SOLVER_UTILS_EXPORT void v_Output(void)
SpatialDomains::BoundaryConditionsSharedPtr m_boundaryConditions
Pointer to boundary conditions object.
int m_spacedim
Spatial dimension (>= expansion dim).
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
LibUtilities::FieldMetaDataMap m_fieldMetaDataMap
Map to identify relevant solver info to dump in output fields.
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Defines a specification for a set of points.
virtual SOLVER_UTILS_EXPORT void v_SetInitialConditions(NekDouble initialtime=0.0, bool dumpInitialConditions=true, const int domain=0)
SOLVER_UTILS_EXPORT LibUtilities::SessionReaderSharedPtr GetSession()
Get Session name.
virtual SOLVER_UTILS_EXPORT void v_DoInitialise()
Virtual function for initialisation implementation.
bool m_homogen_dealiasing
Flag to determine if dealiasing is used for homogeneous simulations.
EquationSystemFactory & GetEquationSystemFactory()
Fourier Modified expansions with just the imaginary part of the first mode .
SOLVER_UTILS_EXPORT void ImportFldToMultiDomains(const std::string &infile, Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const int ndomains)
Input field data from the given file to multiple domains.
SOLVER_UTILS_EXPORT void SetBoundaryConditions(NekDouble time)
Evaluates the boundary conditions at the given time.
std::shared_ptr< Equation > EquationSharedPtr
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction(std::string name, const MultiRegions::ExpListSharedPtr &field=MultiRegions::NullExpListSharedPtr, bool cache=false)
Get a SessionFunction by name.
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
SOLVER_UTILS_EXPORT void WriteFld(const std::string &outname)
Write field data to the given filename.
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
SOLVER_UTILS_EXPORT int GetNpoints()
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
Fourier ModifiedExpansion with just the first mode .
SOLVER_UTILS_EXPORT int GetTraceNpoints()
SOLVER_UTILS_EXPORT int GetNcoeffs()
1D Non Evenly-spaced points for Single Mode analysis
LibUtilities::FieldIOSharedPtr m_fld
Field input/output.
virtual SOLVER_UTILS_EXPORT bool v_NegatedOp()
Virtual function to identify if operator is negated in DoSolve.
virtual SOLVER_UTILS_EXPORT MultiRegions::ExpListSharedPtr v_GetPressure(void)
SOLVER_UTILS_EXPORT void ZeroPhysFields()
SOLVER_UTILS_EXPORT void SessionSummary(SummaryList &vSummary)
Write out a session summary.
SpatialDomains::MeshGraphSharedPtr m_graph
Pointer to graph defining mesh.
SOLVER_UTILS_EXPORT void ExtraFldOutput(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables)
Used to lookup the create function in NekManager.
SOLVER_UTILS_EXPORT void Checkpoint_BaseFlow(const int n)
Write base flow file of m_fields.
virtual SOLVER_UTILS_EXPORT void v_DoSolve()
Virtual function for solve implementation.
std::shared_ptr< SessionFunction > SessionFunctionSharedPtr
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
void Zero(int n, T *x, const int incx)
Zero vector.
int m_NumQuadPointsError
Number of Quadrature points used to work out the error.
std::shared_ptr< FieldIO > FieldIOSharedPtr
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
static FieldMetaDataMap NullFieldMetaDataMap
NekMatrix< NekMatrix< NekDouble, StandardMatrixTag >, ScaledMatrixTag > DNekScalMat
static GLOBAL_MAPPING_EXPORT MappingSharedPtr Load(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Return a pointer to the mapping, creating it on first call.
virtual SOLVER_UTILS_EXPORT void v_EvaluateExactSolution(unsigned int field, Array< OneD, NekDouble > &outfield, const NekDouble time)
virtual SOLVER_UTILS_EXPORT void v_TransCoeffToPhys()
Virtual function for transformation to physical space.
Describes the specification for a Basis.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
enum HomogeneousType m_HomogeneousType
1D Gauss-Lobatto-Legendre quadrature points
Provides a generic Factory class.
SOLVER_UTILS_EXPORT void ImportFld(const std::string &infile, Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Input field data from the given file.