55 "Adaptive", DriverAdaptive::create);
56 string DriverAdaptive::driverLookupId =
57 LibUtilities::SessionReader::RegisterEnumValue(
"Driver",
"Adaptive", 0);
62 DriverAdaptive::DriverAdaptive(
85 time_t starttime, endtime;
88 m_equ[0]->PrintSummary(out);
92 m_equ[0]->DoInitialise();
100 int nRuns, minP, maxP, sensorVar;
102 m_session->LoadParameter (
"NumRuns", nRuns, 1);
103 m_session->LoadParameter (
"AdaptiveMinModes", minP, 4);
104 m_session->LoadParameter (
"AdaptiveMaxModes", maxP, 12);
105 m_session->LoadParameter (
"AdaptiveLowerTolerance", lowerTol, 1e-8);
106 m_session->LoadParameter (
"AdaptiveUpperTolerance", upperTol, 1e-6);
107 m_session->LoadParameter (
"AdaptiveSensorVariable", sensorVar, 0);
108 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
114 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
115 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().num_elements();
119 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
122 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
124 int nFields =
m_equ[0]->UpdateFields().num_elements();
125 int numSteps =
m_session->GetParameter(
"NumSteps");
133 m_equ[0]->UpdateFields());
140 for (
int i = 1; i < nRuns; i++)
144 m_equ[0]->UpdateFields();
147 map<int, int> deltaP;
149 for (
int n = 0; n < nExp; n++)
151 offset = fields[sensorVar]->GetPhys_Offset(n);
152 Exp = fields[sensorVar]->GetExp(n);
154 for(
int k = 0; k < expdim; ++k)
156 P[k] = Exp->GetBasis(k)->GetNumModes();
157 numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
159 Exp->GetBasis(k)->GetPointsType());
164 switch (Exp->GetGeom()->GetShapeType())
240 ASSERTL0(
false,
"Shape not supported.");
244 int nq = OrthoExp->GetTotPoints();
255 for (
int plane = 0; plane < nPlanes; plane++)
260 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
264 phys = fields[sensorVar]->GetPhys() + offset;
268 OrthoExp->FwdTrans(phys, coeffs);
269 OrthoExp->BwdTrans(coeffs, physReduced);
272 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
273 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
274 tmp = Exp->Integral(tmpArray);
277 fac = Exp->Integral(tmpArray);
279 tmp = abs(tmp / fac);
284 "Adaptive procedure encountered NaN value.");
288 error = (tmp > error) ? tmp : error;
292 m_session->GetComm()->GetColumnComm()->AllReduce(
296 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
298 int nq = Exp->GetTotPoints();
305 Exp->GetCoords(xc0, xc1, xc2);
310 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
311 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
315 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
317 int nq = Exp->GetTotPoints();
324 Exp->GetCoords(xc0, xc1, xc2);
329 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
330 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
335 if ((error > upperTol) && (P[0] < maxP))
337 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
339 else if ((error < lowerTol) && P[0] > minP)
341 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
345 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
358 PoolCreated(std::string(
"GlobalLinSys")))
362 ClearManager(std::string(
"GlobalLinSys"));
365 int chkNumber =
m_equ[0]->GetCheckpointNumber();
366 int chkSteps =
m_equ[0]->GetCheckpointSteps();
372 mapping->ReplaceField(
m_equ[0]->UpdateFields());
375 m_equ[0]->SetCheckpointSteps(0);
378 m_equ[0]->DoInitialise();
379 m_equ[0]->SetInitialStep(i * numSteps);
380 m_equ[0]->SetSteps(i * numSteps + numSteps);
381 m_equ[0]->SetTime(startTime + i * period);
382 m_equ[0]->SetBoundaryConditions(startTime + i * period);
383 m_equ[0]->SetCheckpointNumber(chkNumber);
384 m_equ[0]->SetCheckpointSteps(chkSteps);
387 for (
int n = 0; n < nFields; n++)
389 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
390 fields[n], fields[n]->GetCoeffs(),
391 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
392 m_equ[0]->UpdateFields()[n]->BwdTrans_IterPerExp(
393 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
394 m_equ[0]->UpdateFields()[n]->UpdatePhys());
405 if (
m_comm->GetRank() == 0)
407 CPUtime = difftime(endtime, starttime);
408 cout <<
"-------------------------------------------" << endl;
409 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
410 cout <<
"-------------------------------------------" << endl;
418 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
423 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
428 if (
m_comm->GetRank() == 0)
430 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
431 <<
") : " << vL2Error << endl;
432 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
433 <<
") : " << vLinfError << endl;
447 map<int, int> deltaP)
450 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
453 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
454 fields[0]->GetFieldDefinitions();
456 if (fielddefs[0]->m_numHomogeneousDir == 1)
466 for (
int i = 0; i < fielddefs.size(); ++i)
468 for (
int j = 0; j < fields.num_elements(); ++j)
470 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
475 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
481 for (
int f = 0; f < fielddefs.size(); ++f)
483 nExp = fielddefs[f]->m_elementIDs.size();
487 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
488 exp_tag->LinkEndChild(elemTag);
491 std::string fieldsString;
493 std::stringstream fieldsStringStream;
495 for (std::vector<int>::size_type i = 0;
496 i < fielddefs[f]->m_fields.size(); i++)
500 fieldsStringStream <<
",";
502 fieldsStringStream << fielddefs[f]->m_fields[i];
505 fieldsString = fieldsStringStream.str();
507 elemTag->SetAttribute(
"FIELDS", fieldsString);
510 std::string shapeString;
512 std::stringstream shapeStringStream;
515 if (fielddefs[f]->m_numHomogeneousDir == 1)
517 shapeStringStream <<
"-HomogenousExp1D";
519 else if (fielddefs[f]->m_numHomogeneousDir == 2)
521 shapeStringStream <<
"-HomogenousExp2D";
524 shapeString = shapeStringStream.str();
526 elemTag->SetAttribute(
"SHAPE", shapeString);
529 std::string basisString;
531 std::stringstream basisStringStream;
533 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
534 i < fielddefs[f]->m_basis.size(); i++)
538 basisStringStream <<
",";
544 basisString = basisStringStream.str();
546 elemTag->SetAttribute(
"BASIS", basisString);
549 if (fielddefs[f]->m_numHomogeneousDir)
551 std::string homoLenString;
553 std::stringstream homoLenStringStream;
555 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
559 homoLenStringStream <<
",";
562 << fielddefs[f]->m_homogeneousLengths[i];
565 homoLenString = homoLenStringStream.str();
567 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
571 if (fielddefs[f]->m_numHomogeneousDir)
573 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
575 std::string homoYIDsString;
577 std::stringstream homoYIDsStringStream;
579 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
584 homoYIDsStringStream <<
",";
587 << fielddefs[f]->m_homogeneousYIDs[i];
590 homoYIDsString = homoYIDsStringStream.str();
592 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
595 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
597 std::string homoZIDsString;
599 std::stringstream homoZIDsStringStream;
601 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
606 homoZIDsStringStream <<
",";
609 << fielddefs[f]->m_homogeneousZIDs[i];
612 homoZIDsString = homoZIDsStringStream.str();
614 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
619 std::string numModesString;
621 std::stringstream numModesStringStream;
623 numModesStringStream <<
"MIXORDER:";
627 for (
int n = 0; n < nExp; n++)
629 eId = fielddefs[f]->m_elementIDs[n];
631 for (
int i = 0; i < expdim; i++)
633 order[i] = deltaP[eId];
636 for (
int i = 0; i < nDim; i++)
638 if (fielddefs[f]->m_uniOrder)
640 order[i] += fielddefs[f]->m_numModes[i];
644 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
649 numModesStringStream <<
",";
652 numModesStringStream << order[i];
656 numModesString = numModesStringStream.str();
658 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
662 elemTag->SetAttribute(
#define ASSERTL0(condition, msg)
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.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
const char *const BasisTypeMap[]
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::string GenerateSeqString(const std::vector< unsigned int > &elmtids)
virtual SOLVER_UTILS_EXPORT ~DriverAdaptive()
Destructor.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
const char *const ShapeTypeMap[]
Principle Orthogonal Functions .
virtual SOLVER_UTILS_EXPORT void v_Execute(std::ostream &out=std::cout)
Virtual function for solve implementation.
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Principle Orthogonal Functions .
Principle Orthogonal Functions .
Defines a specification for a set of points.
boost::shared_ptr< Expansion > ExpansionSharedPtr
GLOBAL_MAPPING_EXPORT typedef boost::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Describe a linear system.
boost::shared_ptr< Equation > EquationSharedPtr
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.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Second-stage initialisation.
DriverFactory & GetDriverFactory()
LibUtilities::CommSharedPtr m_comm
Communication object.
Base class for the development of solvers.
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
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.
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.