55 "Adaptive", DriverAdaptive::create);
56 string DriverAdaptive::driverLookupId =
57 LibUtilities::SessionReader::RegisterEnumValue(
"Driver",
"Adaptive", 0);
62 DriverAdaptive::DriverAdaptive(
86 time_t starttime, endtime;
89 m_equ[0]->PrintSummary(out);
93 m_equ[0]->DoInitialise();
100 bool isHomogeneous1D;
101 int nRuns, minP, maxP, sensorVar;
103 m_session->LoadParameter (
"NumRuns", nRuns, 1);
104 m_session->LoadParameter (
"AdaptiveMinModes", minP, 4);
105 m_session->LoadParameter (
"AdaptiveMaxModes", maxP, 12);
106 m_session->LoadParameter (
"AdaptiveLowerTolerance", lowerTol, 1e-8);
107 m_session->LoadParameter (
"AdaptiveUpperTolerance", upperTol, 1e-6);
108 m_session->LoadParameter (
"AdaptiveSensorVariable", sensorVar, 0);
109 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
115 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
116 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().size();
120 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
123 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
125 int nFields =
m_equ[0]->UpdateFields().size();
126 int numSteps =
m_session->GetParameter(
"NumSteps");
134 m_equ[0]->UpdateFields());
141 for (
int i = 1; i < nRuns; i++)
145 m_equ[0]->UpdateFields();
148 map<int, int> deltaP;
150 for (
int n = 0; n < nExp; n++)
152 offset = fields[sensorVar]->GetPhys_Offset(n);
153 Exp = fields[sensorVar]->GetExp(n);
155 for(
int k = 0; k < expdim; ++k)
157 P[k] = Exp->GetBasis(k)->GetNumModes();
158 numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
160 Exp->GetBasis(k)->GetPointsType());
165 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_IterPerExp(
395 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
396 m_equ[0]->UpdateFields()[n]->UpdatePhys());
407 if (
m_comm->GetRank() == 0)
409 CPUtime = difftime(endtime, starttime);
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]->GetFinalTime());
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;
449 map<int, int> deltaP)
452 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
455 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
456 fields[0]->GetFieldDefinitions();
458 if (fielddefs[0]->m_numHomogeneousDir == 1)
468 for (
int i = 0; i < fielddefs.size(); ++i)
470 for (
int j = 0; j < fields.size(); ++j)
472 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
477 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
483 for (
int f = 0; f < fielddefs.size(); ++f)
485 nExp = fielddefs[f]->m_elementIDs.size();
489 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
490 exp_tag->LinkEndChild(elemTag);
493 std::string fieldsString;
495 std::stringstream fieldsStringStream;
497 for (std::vector<int>::size_type i = 0;
498 i < fielddefs[f]->m_fields.size(); i++)
502 fieldsStringStream <<
",";
504 fieldsStringStream << fielddefs[f]->m_fields[i];
507 fieldsString = fieldsStringStream.str();
509 elemTag->SetAttribute(
"FIELDS", fieldsString);
512 std::string shapeString;
514 std::stringstream shapeStringStream;
517 if (fielddefs[f]->m_numHomogeneousDir == 1)
519 shapeStringStream <<
"-HomogenousExp1D";
521 else if (fielddefs[f]->m_numHomogeneousDir == 2)
523 shapeStringStream <<
"-HomogenousExp2D";
526 shapeString = shapeStringStream.str();
528 elemTag->SetAttribute(
"SHAPE", shapeString);
531 std::string basisString;
533 std::stringstream basisStringStream;
535 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
536 i < fielddefs[f]->m_basis.size(); i++)
540 basisStringStream <<
",";
546 basisString = basisStringStream.str();
548 elemTag->SetAttribute(
"BASIS", basisString);
551 if (fielddefs[f]->m_numHomogeneousDir)
553 std::string homoLenString;
555 std::stringstream homoLenStringStream;
557 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
561 homoLenStringStream <<
",";
564 << fielddefs[f]->m_homogeneousLengths[i];
567 homoLenString = homoLenStringStream.str();
569 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
573 if (fielddefs[f]->m_numHomogeneousDir)
575 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
577 std::string homoYIDsString;
579 std::stringstream homoYIDsStringStream;
581 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
586 homoYIDsStringStream <<
",";
589 << fielddefs[f]->m_homogeneousYIDs[i];
592 homoYIDsString = homoYIDsStringStream.str();
594 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
597 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
599 std::string homoZIDsString;
601 std::stringstream homoZIDsStringStream;
603 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
608 homoZIDsStringStream <<
",";
611 << fielddefs[f]->m_homogeneousZIDs[i];
614 homoZIDsString = homoZIDsStringStream.str();
616 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
621 std::string numModesString;
623 std::stringstream numModesStringStream;
625 numModesStringStream <<
"MIXORDER:";
629 for (
int n = 0; n < nExp; n++)
631 eId = fielddefs[f]->m_elementIDs[n];
633 for (
int i = 0; i < expdim; i++)
635 order[i] = deltaP[eId];
638 for (
int i = 0; i < nDim; i++)
640 if (fielddefs[f]->m_uniOrder)
642 order[i] += fielddefs[f]->m_numModes[i];
646 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
651 numModesStringStream <<
",";
654 numModesStringStream << order[i];
658 numModesString = numModesStringStream.str();
660 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
664 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.
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.
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Second-stage initialisation.
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.
virtual SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout)
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)
LibUtilities::CommSharedPtr m_comm
Communication object.
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
const char *const BasisTypeMap[]
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
const char *const ShapeTypeMap[]
@ 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)