91 m_equ[0]->PrintSummary(out);
95 m_equ[0]->DoInitialise();
102 bool isHomogeneous1D;
103 int nRuns, minP, maxP, sensorVar;
105 m_session->LoadParameter(
"NumRuns", nRuns, 1);
106 m_session->LoadParameter(
"AdaptiveMinModes", minP, 4);
107 m_session->LoadParameter(
"AdaptiveMaxModes", maxP, 12);
108 m_session->LoadParameter(
"AdaptiveLowerTolerance", lowerTol, 1e-8);
109 m_session->LoadParameter(
"AdaptiveUpperTolerance", upperTol, 1e-6);
110 m_session->LoadParameter(
"AdaptiveSensorVariable", sensorVar, 0);
111 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
117 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
118 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().size();
122 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
125 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
127 int nFields =
m_equ[0]->UpdateFields().size();
128 int numSteps =
m_session->GetParameter(
"NumSteps");
142 for (
int i = 1; i < nRuns; i++)
146 m_equ[0]->UpdateFields();
149 map<int, int> deltaP;
151 for (
int n = 0; n < nExp; n++)
153 offset = fields[sensorVar]->GetPhys_Offset(n);
154 Exp = fields[sensorVar]->GetExp(n);
156 for (
int k = 0; k < expdim; ++k)
158 P[k] = Exp->GetBasis(k)->GetNumModes();
159 numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
161 numPoints[k], Exp->GetBasis(k)->GetPointsType());
166 switch (Exp->GetGeom()->GetShapeType())
241 ASSERTL0(
false,
"Shape not supported.");
245 int nq = OrthoExp->GetTotPoints();
256 for (
int plane = 0; plane < nPlanes; plane++)
261 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
265 phys = fields[sensorVar]->GetPhys() + offset;
269 OrthoExp->FwdTrans(phys, coeffs);
270 OrthoExp->BwdTrans(coeffs, physReduced);
273 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
274 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
275 tmp = Exp->Integral(tmpArray);
278 fac = Exp->Integral(tmpArray);
280 tmp =
abs(tmp / fac);
285 "Adaptive procedure encountered NaN value.");
289 error = (tmp > error) ? tmp : error;
293 m_session->GetComm()->GetColumnComm()->AllReduce(
297 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
299 int nq = Exp->GetTotPoints();
306 Exp->GetCoords(xc0, xc1, xc2);
311 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
312 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
316 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
318 int nq = Exp->GetTotPoints();
325 Exp->GetCoords(xc0, xc1, xc2);
330 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
331 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
336 if ((error > upperTol) && (
P[0] < maxP))
338 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
340 else if ((error < lowerTol) &&
P[0] > minP)
342 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
346 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
360 PoolCreated(std::string(
"GlobalLinSys")))
364 ClearManager(std::string(
"GlobalLinSys"));
367 int chkNumber =
m_equ[0]->GetCheckpointNumber();
368 int chkSteps =
m_equ[0]->GetCheckpointSteps();
374 mapping->ReplaceField(
m_equ[0]->UpdateFields());
377 m_equ[0]->SetCheckpointSteps(0);
380 m_equ[0]->DoInitialise();
381 m_equ[0]->SetInitialStep(i * numSteps);
382 m_equ[0]->SetSteps(i * numSteps + numSteps);
383 m_equ[0]->SetTime(startTime + i * period);
384 m_equ[0]->SetBoundaryConditions(startTime + i * period);
385 m_equ[0]->SetCheckpointNumber(chkNumber);
386 m_equ[0]->SetCheckpointSteps(chkSteps);
389 for (
int n = 0; n < nFields; n++)
391 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
392 fields[n], fields[n]->GetCoeffs(),
393 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
394 m_equ[0]->UpdateFields()[n]->BwdTrans(
395 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
396 m_equ[0]->UpdateFields()[n]->UpdatePhys());
407 if (
m_comm->GetRank() == 0)
409 CPUtime = timer.
Elapsed().count();
410 cout <<
"-------------------------------------------" << endl;
411 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
412 cout <<
"-------------------------------------------" << endl;
420 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
425 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetTime());
430 if (
m_comm->GetRank() == 0)
432 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
433 <<
") : " << vL2Error << endl;
434 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
435 <<
") : " << vLinfError << endl;
451 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
454 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
455 fields[0]->GetFieldDefinitions();
457 if (fielddefs[0]->m_numHomogeneousDir == 1)
467 for (
int i = 0; i < fielddefs.size(); ++i)
469 for (
int j = 0; j < fields.size(); ++j)
471 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
476 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
482 for (
int f = 0; f < fielddefs.size(); ++f)
484 nExp = fielddefs[f]->m_elementIDs.size();
488 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
489 exp_tag->LinkEndChild(elemTag);
492 std::string fieldsString;
494 std::stringstream fieldsStringStream;
496 for (std::vector<int>::size_type i = 0;
497 i < fielddefs[f]->m_fields.size(); i++)
501 fieldsStringStream <<
",";
503 fieldsStringStream << fielddefs[f]->m_fields[i];
506 fieldsString = fieldsStringStream.str();
508 elemTag->SetAttribute(
"FIELDS", fieldsString);
511 std::string shapeString;
513 std::stringstream shapeStringStream;
516 if (fielddefs[f]->m_numHomogeneousDir == 1)
518 shapeStringStream <<
"-HomogenousExp1D";
520 else if (fielddefs[f]->m_numHomogeneousDir == 2)
522 shapeStringStream <<
"-HomogenousExp2D";
525 shapeString = shapeStringStream.str();
527 elemTag->SetAttribute(
"SHAPE", shapeString);
530 std::string basisString;
532 std::stringstream basisStringStream;
534 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
535 i < fielddefs[f]->m_basis.size(); i++)
539 basisStringStream <<
",";
545 basisString = basisStringStream.str();
547 elemTag->SetAttribute(
"BASIS", basisString);
550 if (fielddefs[f]->m_numHomogeneousDir)
552 std::string homoLenString;
554 std::stringstream homoLenStringStream;
556 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
560 homoLenStringStream <<
",";
563 << fielddefs[f]->m_homogeneousLengths[i];
566 homoLenString = homoLenStringStream.str();
568 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
572 if (fielddefs[f]->m_numHomogeneousDir)
574 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
576 std::string homoYIDsString;
578 std::stringstream homoYIDsStringStream;
580 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
585 homoYIDsStringStream <<
",";
588 << fielddefs[f]->m_homogeneousYIDs[i];
591 homoYIDsString = homoYIDsStringStream.str();
593 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
596 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
598 std::string homoZIDsString;
600 std::stringstream homoZIDsStringStream;
602 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
607 homoZIDsStringStream <<
",";
610 << fielddefs[f]->m_homogeneousZIDs[i];
613 homoZIDsString = homoZIDsStringStream.str();
615 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
620 std::string numModesString;
622 std::stringstream numModesStringStream;
624 numModesStringStream <<
"MIXORDER:";
628 for (
int n = 0; n < nExp; n++)
630 eId = fielddefs[f]->m_elementIDs[n];
632 for (
int i = 0; i < expdim; i++)
634 order[i] = deltaP[eId];
637 for (
int i = 0; i < nDim; i++)
639 if (fielddefs[f]->m_uniOrder)
641 order[i] += fielddefs[f]->m_numModes[i];
645 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
650 numModesStringStream <<
",";
653 numModesStringStream << order[i];
657 numModesString = numModesStringStream.str();
659 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
663 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.
SOLVER_UTILS_EXPORT ~DriverAdaptive() override
Destructor.
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.
SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout) override
Virtual function for initialisation implementation.
SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout) override
Virtual function for solve implementation.
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
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)