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 ClearManager(std::string(
"GlobalLinSys"));
300 int chkNumber =
m_equ[0]->GetCheckpointNumber();
301 int chkSteps =
m_equ[0]->GetCheckpointSteps();
307 mapping->ReplaceField(
m_equ[0]->UpdateFields());
310 m_equ[0]->SetCheckpointSteps(0);
313 m_equ[0]->DoInitialise();
314 m_equ[0]->SetInitialStep(i * numSteps);
315 m_equ[0]->SetSteps(i * numSteps + numSteps);
316 m_equ[0]->SetTime(startTime + i * period);
317 m_equ[0]->SetBoundaryConditions(startTime + i * period);
318 m_equ[0]->SetCheckpointNumber(chkNumber);
319 m_equ[0]->SetCheckpointSteps(chkSteps);
322 for (
int n = 0; n < nFields; n++)
324 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
325 fields[n], fields[n]->GetCoeffs(),
326 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
327 m_equ[0]->UpdateFields()[n]->BwdTrans_IterPerExp(
328 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
329 m_equ[0]->UpdateFields()[n]->UpdatePhys());
340 if (
m_comm->GetRank() == 0)
342 CPUtime = difftime(endtime, starttime);
343 cout <<
"-------------------------------------------" << endl;
344 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
345 cout <<
"-------------------------------------------" << endl;
353 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
358 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
363 if (
m_comm->GetRank() == 0)
365 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
366 <<
") : " << vL2Error << endl;
367 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
368 <<
") : " << vLinfError << endl;
382 map<int, int> deltaP)
387 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
388 fields[0]->GetFieldDefinitions();
392 if (fielddefs[0]->m_numHomogeneousDir == 1)
402 for (
int i = 0; i < fielddefs.size(); ++i)
404 for (
int j = 0; j < fields.num_elements(); ++j)
406 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
411 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
417 for (
int f = 0; f < fielddefs.size(); ++f)
419 nExp = fielddefs[f]->m_elementIDs.size();
423 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
424 exp_tag->LinkEndChild(elemTag);
427 std::string fieldsString;
429 std::stringstream fieldsStringStream;
431 for (std::vector<int>::size_type i = 0;
432 i < fielddefs[f]->m_fields.size(); i++)
436 fieldsStringStream <<
",";
438 fieldsStringStream << fielddefs[f]->m_fields[i];
441 fieldsString = fieldsStringStream.str();
443 elemTag->SetAttribute(
"FIELDS", fieldsString);
446 std::string shapeString;
448 std::stringstream shapeStringStream;
451 if (fielddefs[f]->m_numHomogeneousDir == 1)
453 shapeStringStream <<
"-HomogenousExp1D";
455 else if (fielddefs[f]->m_numHomogeneousDir == 2)
457 shapeStringStream <<
"-HomogenousExp2D";
460 shapeString = shapeStringStream.str();
462 elemTag->SetAttribute(
"SHAPE", shapeString);
465 std::string basisString;
467 std::stringstream basisStringStream;
469 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
470 i < fielddefs[f]->m_basis.size(); i++)
474 basisStringStream <<
",";
480 basisString = basisStringStream.str();
482 elemTag->SetAttribute(
"BASIS", basisString);
485 if (fielddefs[f]->m_numHomogeneousDir)
487 std::string homoLenString;
489 std::stringstream homoLenStringStream;
491 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
495 homoLenStringStream <<
",";
498 << fielddefs[f]->m_homogeneousLengths[i];
501 homoLenString = homoLenStringStream.str();
503 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
507 if (fielddefs[f]->m_numHomogeneousDir)
509 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
511 std::string homoYIDsString;
513 std::stringstream homoYIDsStringStream;
515 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
520 homoYIDsStringStream <<
",";
523 << fielddefs[f]->m_homogeneousYIDs[i];
526 homoYIDsString = homoYIDsStringStream.str();
528 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
531 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
533 std::string homoZIDsString;
535 std::stringstream homoZIDsStringStream;
537 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
542 homoZIDsStringStream <<
",";
545 << fielddefs[f]->m_homogeneousZIDs[i];
548 homoZIDsString = homoZIDsStringStream.str();
550 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
555 std::string numModesString;
557 std::stringstream numModesStringStream;
559 numModesStringStream <<
"MIXORDER:";
563 for (
int n = 0; n < nExp; n++)
565 eId = fielddefs[f]->m_elementIDs[n];
567 for (
int i = 0; i < expDim; i++)
569 order[i] = deltaP[eId];
572 for (
int i = 0; i < nDim; i++)
574 if (fielddefs[f]->m_uniOrder)
576 order[i] += fielddefs[f]->m_numModes[i];
580 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
585 numModesStringStream <<
",";
588 numModesStringStream << order[i];
592 numModesString = numModesStringStream.str();
594 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
598 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.