93 m_equ[0]->PrintSummary(out);
97 m_equ[0]->DoInitialise();
104 bool isHomogeneous1D;
105 int nRuns, minP, maxP, sensorVar;
107 m_session->LoadParameter(
"NumRuns", nRuns, 1);
108 m_session->LoadParameter(
"AdaptiveMinModes", minP, 4);
109 m_session->LoadParameter(
"AdaptiveMaxModes", maxP, 12);
110 m_session->LoadParameter(
"AdaptiveLowerTolerance", lowerTol, 1e-8);
111 m_session->LoadParameter(
"AdaptiveUpperTolerance", upperTol, 1e-6);
112 m_session->LoadParameter(
"AdaptiveSensorVariable", sensorVar, 0);
113 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
119 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
120 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().size();
124 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
127 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
129 int nFields =
m_equ[0]->UpdateFields().size();
130 int numSteps =
m_session->GetParameter(
"NumSteps");
144 for (
int i = 1; i < nRuns; i++)
148 m_equ[0]->UpdateFields();
151 map<int, int> deltaP;
153 for (
int n = 0; n < nExp; n++)
155 offset = fields[sensorVar]->GetPhys_Offset(n);
156 Exp = fields[sensorVar]->GetExp(n);
158 for (
int k = 0; k < expdim; ++k)
160 P[k] = Exp->GetBasis(k)->GetNumModes();
161 numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
163 numPoints[k], Exp->GetBasis(k)->GetPointsType());
168 switch (Exp->GetGeom()->GetShapeType())
243 ASSERTL0(
false,
"Shape not supported.");
247 int nq = OrthoExp->GetTotPoints();
258 for (
int plane = 0; plane < nPlanes; plane++)
263 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
267 phys = fields[sensorVar]->GetPhys() + offset;
271 OrthoExp->FwdTrans(phys, coeffs);
272 OrthoExp->BwdTrans(coeffs, physReduced);
275 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
276 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
277 tmp = Exp->Integral(tmpArray);
280 fac = Exp->Integral(tmpArray);
282 tmp =
abs(tmp / fac);
287 "Adaptive procedure encountered NaN value.");
291 error = (tmp > error) ? tmp : error;
295 m_session->GetComm()->GetColumnComm()->AllReduce(
299 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
301 int nq = Exp->GetTotPoints();
308 Exp->GetCoords(xc0, xc1, xc2);
313 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
314 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
318 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
320 int nq = Exp->GetTotPoints();
327 Exp->GetCoords(xc0, xc1, xc2);
332 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
333 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
338 if ((error > upperTol) && (
P[0] < maxP))
340 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
342 else if ((error < lowerTol) &&
P[0] > minP)
344 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
348 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
362 PoolCreated(std::string(
"GlobalLinSys")))
366 ClearManager(std::string(
"GlobalLinSys"));
369 int chkNumber =
m_equ[0]->GetCheckpointNumber();
370 int chkSteps =
m_equ[0]->GetCheckpointSteps();
376 mapping->ReplaceField(
m_equ[0]->UpdateFields());
379 m_equ[0]->SetCheckpointSteps(0);
382 m_equ[0]->DoInitialise();
383 m_equ[0]->SetInitialStep(i * numSteps);
384 m_equ[0]->SetSteps(i * numSteps + numSteps);
385 m_equ[0]->SetTime(startTime + i * period);
386 m_equ[0]->SetBoundaryConditions(startTime + i * period);
387 m_equ[0]->SetCheckpointNumber(chkNumber);
388 m_equ[0]->SetCheckpointSteps(chkSteps);
391 for (
int n = 0; n < nFields; n++)
393 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
394 fields[n], fields[n]->GetCoeffs(),
395 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
396 m_equ[0]->UpdateFields()[n]->BwdTrans(
397 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
398 m_equ[0]->UpdateFields()[n]->UpdatePhys());
409 if (
m_comm->GetRank() == 0)
411 CPUtime = timer.
Elapsed().count();
412 cout <<
"-------------------------------------------" << endl;
413 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
414 cout <<
"-------------------------------------------" << endl;
422 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
427 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
432 if (
m_comm->GetRank() == 0)
434 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
435 <<
") : " << vL2Error << endl;
436 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
437 <<
") : " << vLinfError << endl;
453 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
456 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
457 fields[0]->GetFieldDefinitions();
459 if (fielddefs[0]->m_numHomogeneousDir == 1)
469 for (
int i = 0; i < fielddefs.size(); ++i)
471 for (
int j = 0; j < fields.size(); ++j)
473 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
478 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
484 for (
int f = 0; f < fielddefs.size(); ++f)
486 nExp = fielddefs[f]->m_elementIDs.size();
490 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
491 exp_tag->LinkEndChild(elemTag);
494 std::string fieldsString;
496 std::stringstream fieldsStringStream;
498 for (std::vector<int>::size_type i = 0;
499 i < fielddefs[f]->m_fields.size(); i++)
503 fieldsStringStream <<
",";
505 fieldsStringStream << fielddefs[f]->m_fields[i];
508 fieldsString = fieldsStringStream.str();
510 elemTag->SetAttribute(
"FIELDS", fieldsString);
513 std::string shapeString;
515 std::stringstream shapeStringStream;
518 if (fielddefs[f]->m_numHomogeneousDir == 1)
520 shapeStringStream <<
"-HomogenousExp1D";
522 else if (fielddefs[f]->m_numHomogeneousDir == 2)
524 shapeStringStream <<
"-HomogenousExp2D";
527 shapeString = shapeStringStream.str();
529 elemTag->SetAttribute(
"SHAPE", shapeString);
532 std::string basisString;
534 std::stringstream basisStringStream;
536 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
537 i < fielddefs[f]->m_basis.size(); i++)
541 basisStringStream <<
",";
547 basisString = basisStringStream.str();
549 elemTag->SetAttribute(
"BASIS", basisString);
552 if (fielddefs[f]->m_numHomogeneousDir)
554 std::string homoLenString;
556 std::stringstream homoLenStringStream;
558 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
562 homoLenStringStream <<
",";
565 << fielddefs[f]->m_homogeneousLengths[i];
568 homoLenString = homoLenStringStream.str();
570 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
574 if (fielddefs[f]->m_numHomogeneousDir)
576 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
578 std::string homoYIDsString;
580 std::stringstream homoYIDsStringStream;
582 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
587 homoYIDsStringStream <<
",";
590 << fielddefs[f]->m_homogeneousYIDs[i];
593 homoYIDsString = homoYIDsStringStream.str();
595 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
598 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
600 std::string homoZIDsString;
602 std::stringstream homoZIDsStringStream;
604 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
609 homoZIDsStringStream <<
",";
612 << fielddefs[f]->m_homogeneousZIDs[i];
615 homoZIDsString = homoZIDsStringStream.str();
617 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
622 std::string numModesString;
624 std::stringstream numModesStringStream;
626 numModesStringStream <<
"MIXORDER:";
630 for (
int n = 0; n < nExp; n++)
632 eId = fielddefs[f]->m_elementIDs[n];
634 for (
int i = 0; i < expdim; i++)
636 order[i] = deltaP[eId];
639 for (
int i = 0; i < nDim; i++)
641 if (fielddefs[f]->m_uniOrder)
643 order[i] += fielddefs[f]->m_numModes[i];
647 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
652 numModesStringStream <<
",";
655 numModesStringStream << order[i];
659 numModesString = numModesStringStream.str();
661 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
665 elemTag->SetAttribute(
#define ASSERTL0(condition, msg)
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.
Describes the specification for a Basis.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Defines a specification for a set of points.
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Describe a linear system.
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers.
static std::string driverLookupId
static std::string className
Name of the class.
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
SOLVER_UTILS_EXPORT void ReplaceExpansion(Array< OneD, MultiRegions::ExpListSharedPtr > &fields, std::map< int, int > deltaP)
Update EXPANSIONS tag inside XML schema to reflect new polynomial order distribution.
SOLVER_UTILS_EXPORT DriverAdaptive(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Constructor.
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.
virtual SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout) override
Virtual function for solve implementation.
virtual SOLVER_UTILS_EXPORT ~DriverAdaptive()
Destructor.
Base class for the development of solvers.
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Virtual function for initialisation implementation.
LibUtilities::CommSharedPtr m_comm
Communication object.
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Class representing a prismatic element in reference space.
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
const char *const ShapeTypeMap[SIZE_ShapeType]
const char *const BasisTypeMap[]
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
@ P
Monomial polynomials .
@ eOrtho_A
Principle Orthogonal Functions .
@ eOrtho_C
Principle Orthogonal Functions .
@ eOrtho_B
Principle Orthogonal Functions .
std::shared_ptr< Expansion > ExpansionSharedPtr
DriverFactory & GetDriverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
The above copyright notice and this permission notice shall be included.
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
scalarT< T > abs(scalarT< T > in)