51 "Adaptive", DriverAdaptive::create);
52 string DriverAdaptive::driverLookupId =
53 LibUtilities::SessionReader::RegisterEnumValue(
"Driver",
"Adaptive", 0);
58 DriverAdaptive::DriverAdaptive(
81 time_t starttime, endtime;
84 m_equ[0]->PrintSummary(out);
88 m_equ[0]->DoInitialise();
96 int nRuns, minP, maxP, sensorVar;
98 m_session->LoadParameter (
"NumRuns", nRuns, 1);
99 m_session->LoadParameter (
"AdaptiveMinModes", minP, 4);
100 m_session->LoadParameter (
"AdaptiveMaxModes", maxP, 12);
101 m_session->LoadParameter (
"AdaptiveLowerTolerance", lowerTol, 1e-8);
102 m_session->LoadParameter (
"AdaptiveUpperTolerance", upperTol, 1e-6);
103 m_session->LoadParameter (
"AdaptiveSensorVariable", sensorVar, 0);
104 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
110 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
111 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().num_elements();
115 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
119 int nFields =
m_equ[0]->UpdateFields().num_elements();
120 int numSteps =
m_session->GetParameter(
"NumSteps");
128 m_equ[0]->UpdateFields());
132 for (
int i = 1; i < nRuns; i++)
136 m_equ[0]->UpdateFields();
139 map<int, int> deltaP;
141 for (
int n = 0; n < nExp; n++)
143 offset = fields[sensorVar]->GetPhys_Offset(n);
144 Exp = fields[sensorVar]->GetExp(n);
146 int P = Exp->GetBasis(0)->GetNumModes();
147 int Q = Exp->GetBasis(1)->GetNumModes();
148 int qa = Exp->GetBasis(0)->GetNumPoints();
149 int qb = Exp->GetBasis(1)->GetNumPoints();
156 switch (Exp->GetGeom()->GetShapeType())
180 ASSERTL0(
false,
"Shape not supported.");
184 int nq = OrthoExp->GetTotPoints();
195 for (
int plane = 0; plane < nPlanes; plane++)
200 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
204 phys = fields[sensorVar]->GetPhys() + offset;
208 OrthoExp->FwdTrans(phys, coeffs);
209 OrthoExp->BwdTrans(coeffs, physReduced);
212 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
213 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
214 tmp = Exp->Integral(tmpArray);
217 fac = Exp->Integral(tmpArray);
219 tmp = abs(tmp / fac);
224 "Adaptive procedure encountered NaN value.");
228 error = (tmp > error) ? tmp : error;
232 m_session->GetComm()->GetColumnComm()->AllReduce(
236 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
238 int nq = Exp->GetTotPoints();
245 Exp->GetCoords(xc0, xc1, xc2);
250 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
251 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
255 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
257 int nq = Exp->GetTotPoints();
264 Exp->GetCoords(xc0, xc1, xc2);
269 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
270 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
275 if ((error > upperTol) && (P < maxP))
277 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
279 else if ((error < lowerTol) && P > minP)
281 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
285 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
298 PoolCreated(std::string(
"GlobalLinSys")))
302 ClearManager(std::string(
"GlobalLinSys"));
305 int chkNumber =
m_equ[0]->GetCheckpointNumber();
306 int chkSteps =
m_equ[0]->GetCheckpointSteps();
312 mapping->ReplaceField(
m_equ[0]->UpdateFields());
315 m_equ[0]->SetCheckpointSteps(0);
318 m_equ[0]->DoInitialise();
319 m_equ[0]->SetInitialStep(i * numSteps);
320 m_equ[0]->SetSteps(i * numSteps + numSteps);
321 m_equ[0]->SetTime(startTime + i * period);
322 m_equ[0]->SetBoundaryConditions(startTime + i * period);
323 m_equ[0]->SetCheckpointNumber(chkNumber);
324 m_equ[0]->SetCheckpointSteps(chkSteps);
327 for (
int n = 0; n < nFields; n++)
329 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
330 fields[n], fields[n]->GetCoeffs(),
331 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
332 m_equ[0]->UpdateFields()[n]->BwdTrans_IterPerExp(
333 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
334 m_equ[0]->UpdateFields()[n]->UpdatePhys());
345 if (
m_comm->GetRank() == 0)
347 CPUtime = difftime(endtime, starttime);
348 cout <<
"-------------------------------------------" << endl;
349 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
350 cout <<
"-------------------------------------------" << endl;
358 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
363 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
368 if (
m_comm->GetRank() == 0)
370 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
371 <<
") : " << vL2Error << endl;
372 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
373 <<
") : " << vLinfError << endl;
387 map<int, int> deltaP)
392 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
393 fields[0]->GetFieldDefinitions();
397 if (fielddefs[0]->m_numHomogeneousDir == 1)
407 for (
int i = 0; i < fielddefs.size(); ++i)
409 for (
int j = 0; j < fields.num_elements(); ++j)
411 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
416 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
422 for (
int f = 0; f < fielddefs.size(); ++f)
424 nExp = fielddefs[f]->m_elementIDs.size();
428 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
429 exp_tag->LinkEndChild(elemTag);
432 std::string fieldsString;
434 std::stringstream fieldsStringStream;
436 for (std::vector<int>::size_type i = 0;
437 i < fielddefs[f]->m_fields.size(); i++)
441 fieldsStringStream <<
",";
443 fieldsStringStream << fielddefs[f]->m_fields[i];
446 fieldsString = fieldsStringStream.str();
448 elemTag->SetAttribute(
"FIELDS", fieldsString);
451 std::string shapeString;
453 std::stringstream shapeStringStream;
456 if (fielddefs[f]->m_numHomogeneousDir == 1)
458 shapeStringStream <<
"-HomogenousExp1D";
460 else if (fielddefs[f]->m_numHomogeneousDir == 2)
462 shapeStringStream <<
"-HomogenousExp2D";
465 shapeString = shapeStringStream.str();
467 elemTag->SetAttribute(
"SHAPE", shapeString);
470 std::string basisString;
472 std::stringstream basisStringStream;
474 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
475 i < fielddefs[f]->m_basis.size(); i++)
479 basisStringStream <<
",";
485 basisString = basisStringStream.str();
487 elemTag->SetAttribute(
"BASIS", basisString);
490 if (fielddefs[f]->m_numHomogeneousDir)
492 std::string homoLenString;
494 std::stringstream homoLenStringStream;
496 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
500 homoLenStringStream <<
",";
503 << fielddefs[f]->m_homogeneousLengths[i];
506 homoLenString = homoLenStringStream.str();
508 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
512 if (fielddefs[f]->m_numHomogeneousDir)
514 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
516 std::string homoYIDsString;
518 std::stringstream homoYIDsStringStream;
520 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
525 homoYIDsStringStream <<
",";
528 << fielddefs[f]->m_homogeneousYIDs[i];
531 homoYIDsString = homoYIDsStringStream.str();
533 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
536 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
538 std::string homoZIDsString;
540 std::stringstream homoZIDsStringStream;
542 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
547 homoZIDsStringStream <<
",";
550 << fielddefs[f]->m_homogeneousZIDs[i];
553 homoZIDsString = homoZIDsStringStream.str();
555 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
560 std::string numModesString;
562 std::stringstream numModesStringStream;
564 numModesStringStream <<
"MIXORDER:";
568 for (
int n = 0; n < nExp; n++)
570 eId = fielddefs[f]->m_elementIDs[n];
572 for (
int i = 0; i < expDim; i++)
574 order[i] = deltaP[eId];
577 for (
int i = 0; i < nDim; i++)
579 if (fielddefs[f]->m_uniOrder)
581 order[i] += fielddefs[f]->m_numModes[i];
585 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
590 numModesStringStream <<
",";
593 numModesStringStream << order[i];
597 numModesString = numModesStringStream.str();
599 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
603 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 .
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.