79 time_t starttime, endtime;
82 m_equ[0]->PrintSummary(out);
86 m_equ[0]->DoInitialise();
94 int nRuns, minP, maxP, sensorVar;
96 m_session->LoadParameter (
"NumRuns", nRuns, 1);
97 m_session->LoadParameter (
"AdaptiveMinModes", minP, 4);
98 m_session->LoadParameter (
"AdaptiveMaxModes", maxP, 12);
99 m_session->LoadParameter (
"AdaptiveLowerTolerance", lowerTol, 1e-8);
100 m_session->LoadParameter (
"AdaptiveUpperTolerance", upperTol, 1e-6);
101 m_session->LoadParameter (
"AdaptiveSensorVariable", sensorVar, 0);
102 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
108 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
109 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().num_elements();
113 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
117 int nFields =
m_equ[0]->UpdateFields().num_elements();
118 int numSteps =
m_session->GetParameter(
"NumSteps");
126 m_equ[0]->UpdateFields());
130 for (
int i = 1; i < nRuns; i++)
134 m_equ[0]->UpdateFields();
137 map<int, int> deltaP;
139 for (
int n = 0; n < nExp; n++)
141 offset = fields[sensorVar]->GetPhys_Offset(n);
142 Exp = fields[sensorVar]->GetExp(n);
144 int P = Exp->GetBasis(0)->GetNumModes();
145 int Q = Exp->GetBasis(1)->GetNumModes();
146 int qa = Exp->GetBasis(0)->GetNumPoints();
147 int qb = Exp->GetBasis(1)->GetNumPoints();
154 switch (Exp->GetGeom()->GetShapeType())
178 ASSERTL0(
false,
"Shape not supported.");
182 int nq = OrthoExp->GetTotPoints();
193 for (
int plane = 0; plane < nPlanes; plane++)
198 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
202 phys = fields[sensorVar]->GetPhys() + offset;
206 OrthoExp->FwdTrans(phys, coeffs);
207 OrthoExp->BwdTrans(coeffs, physReduced);
210 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
211 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
212 tmp = Exp->Integral(tmpArray);
215 fac = Exp->Integral(tmpArray);
217 tmp = abs(tmp / fac);
222 "Adaptive procedure encountered NaN value.");
226 error = (tmp > error) ? tmp : error;
230 m_session->GetComm()->GetColumnComm()->AllReduce(
234 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
236 int nq = Exp->GetTotPoints();
243 Exp->GetCoords(xc0, xc1, xc2);
248 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
249 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
253 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
255 int nq = Exp->GetTotPoints();
262 Exp->GetCoords(xc0, xc1, xc2);
267 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
268 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
273 if ((error > upperTol) && (P < maxP))
275 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
277 else if ((error < lowerTol) && P > minP)
279 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
283 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
296 ClearManager(std::string(
"GlobalLinSys"));
298 int chkNumber =
m_equ[0]->GetCheckpointNumber();
299 int chkSteps =
m_equ[0]->GetCheckpointSteps();
305 mapping->ReplaceField(
m_equ[0]->UpdateFields());
308 m_equ[0]->SetCheckpointSteps(0);
311 m_equ[0]->DoInitialise();
312 m_equ[0]->SetInitialStep(i * numSteps);
313 m_equ[0]->SetSteps(i * numSteps + numSteps);
314 m_equ[0]->SetTime(startTime + i * period);
315 m_equ[0]->SetBoundaryConditions(startTime + i * period);
316 m_equ[0]->SetCheckpointNumber(chkNumber);
317 m_equ[0]->SetCheckpointSteps(chkSteps);
320 for (
int n = 0; n < nFields; n++)
322 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
323 fields[n], fields[n]->GetCoeffs(),
324 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
325 m_equ[0]->UpdateFields()[n]->BwdTrans_IterPerExp(
326 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
327 m_equ[0]->UpdateFields()[n]->UpdatePhys());
338 if (
m_comm->GetRank() == 0)
340 CPUtime = difftime(endtime, starttime);
341 cout <<
"-------------------------------------------" << endl;
342 cout <<
"Total Computation Time = " << CPUtime <<
"s" << endl;
343 cout <<
"-------------------------------------------" << endl;
351 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
356 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
361 if (
m_comm->GetRank() == 0)
363 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
364 <<
") : " << vL2Error << endl;
365 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
366 <<
") : " << vLinfError << endl;
380 map<int, int> deltaP)
385 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
386 fields[0]->GetFieldDefinitions();
390 if (fielddefs[0]->m_numHomogeneousDir == 1)
400 for (
int i = 0; i < fielddefs.size(); ++i)
402 for (
int j = 0; j < fields.num_elements(); ++j)
404 fielddefs[i]->m_fields.push_back(
m_session->GetVariable(j));
409 TiXmlElement *exp_tag =
m_session->GetElement(
"NEKTAR/EXPANSIONS");
415 for (
int f = 0; f < fielddefs.size(); ++f)
417 nExp = fielddefs[f]->m_elementIDs.size();
421 TiXmlElement *elemTag =
new TiXmlElement(
"ELEMENTS");
422 exp_tag->LinkEndChild(elemTag);
425 std::string fieldsString;
427 std::stringstream fieldsStringStream;
429 for (std::vector<int>::size_type i = 0;
430 i < fielddefs[f]->m_fields.size(); i++)
434 fieldsStringStream <<
",";
436 fieldsStringStream << fielddefs[f]->m_fields[i];
439 fieldsString = fieldsStringStream.str();
441 elemTag->SetAttribute(
"FIELDS", fieldsString);
444 std::string shapeString;
446 std::stringstream shapeStringStream;
449 if (fielddefs[f]->m_numHomogeneousDir == 1)
451 shapeStringStream <<
"-HomogenousExp1D";
453 else if (fielddefs[f]->m_numHomogeneousDir == 2)
455 shapeStringStream <<
"-HomogenousExp2D";
458 shapeString = shapeStringStream.str();
460 elemTag->SetAttribute(
"SHAPE", shapeString);
463 std::string basisString;
465 std::stringstream basisStringStream;
467 for (std::vector<LibUtilities::BasisType>::size_type i = 0;
468 i < fielddefs[f]->m_basis.size(); i++)
472 basisStringStream <<
",";
478 basisString = basisStringStream.str();
480 elemTag->SetAttribute(
"BASIS", basisString);
483 if (fielddefs[f]->m_numHomogeneousDir)
485 std::string homoLenString;
487 std::stringstream homoLenStringStream;
489 for (
int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
493 homoLenStringStream <<
",";
496 << fielddefs[f]->m_homogeneousLengths[i];
499 homoLenString = homoLenStringStream.str();
501 elemTag->SetAttribute(
"HOMOGENEOUSLENGTHS", homoLenString);
505 if (fielddefs[f]->m_numHomogeneousDir)
507 if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
509 std::string homoYIDsString;
511 std::stringstream homoYIDsStringStream;
513 for (
int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
518 homoYIDsStringStream <<
",";
521 << fielddefs[f]->m_homogeneousYIDs[i];
524 homoYIDsString = homoYIDsStringStream.str();
526 elemTag->SetAttribute(
"HOMOGENEOUSYIDS", homoYIDsString);
529 if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
531 std::string homoZIDsString;
533 std::stringstream homoZIDsStringStream;
535 for (
int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
540 homoZIDsStringStream <<
",";
543 << fielddefs[f]->m_homogeneousZIDs[i];
546 homoZIDsString = homoZIDsStringStream.str();
548 elemTag->SetAttribute(
"HOMOGENEOUSZIDS", homoZIDsString);
553 std::string numModesString;
555 std::stringstream numModesStringStream;
557 numModesStringStream <<
"MIXORDER:";
561 for (
int n = 0; n < nExp; n++)
563 eId = fielddefs[f]->m_elementIDs[n];
565 for (
int i = 0; i < expDim; i++)
567 order[i] = deltaP[eId];
570 for (
int i = 0; i < nDim; i++)
572 if (fielddefs[f]->m_uniOrder)
574 order[i] += fielddefs[f]->m_numModes[i];
578 order[i] += fielddefs[f]->m_numModes[n * nDim + i];
583 numModesStringStream <<
",";
586 numModesStringStream << order[i];
590 numModesString = numModesStringStream.str();
592 elemTag->SetAttribute(
"NUMMODESPERDIR", numModesString);
596 elemTag->SetAttribute(
virtual SOLVER_UTILS_EXPORT void v_Execute(ostream &out=cout)
Virtual function for solve implementation.
#define ASSERTL0(condition, msg)
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
virtual SOLVER_UTILS_EXPORT void v_InitObject(ostream &out=cout)
virtual SOLVER_UTILS_EXPORT void v_InitObject(ostream &out=cout)
Second-stage initialisation.
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 .
static std::string className
Name of the class.
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.
static std::string driverLookupId
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Creates an instance of this class.
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
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
SOLVER_UTILS_EXPORT DriverAdaptive(const LibUtilities::SessionReaderSharedPtr pSession)
Constructor.
SOLVER_UTILS_EXPORT void ReplaceExpansion(Array< OneD, MultiRegions::ExpListSharedPtr > &fields, map< int, int > deltaP)
Update EXPANSIONS tag inside XML schema to reflect new polynomial order distribution.
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.