Virtual function for solve implementation.
89{
92
93 m_equ[0]->PrintSummary(out);
94
95
97 m_equ[0]->DoInitialise();
98
99
102
103
104 bool isHomogeneous1D;
105 int nRuns, minP, maxP, sensorVar;
107 m_session->LoadParameter(
"NumRuns", nRuns, 1);
108 m_session->LoadParameter(
"AdaptiveMinModes", minP, 4);
109 m_session->LoadParameter(
"AdaptiveMaxModes", maxP, 12);
110 m_session->LoadParameter(
"AdaptiveLowerTolerance", lowerTol, 1e-8);
111 m_session->LoadParameter(
"AdaptiveUpperTolerance", upperTol, 1e-6);
112 m_session->LoadParameter(
"AdaptiveSensorVariable", sensorVar, 0);
113 m_session->MatchSolverInfo(
"Homogeneous",
"1D", isHomogeneous1D,
false);
114
115
116 int nExp, nPlanes;
117 if (isHomogeneous1D)
118 {
119 nExp =
m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
120 nPlanes =
m_equ[0]->UpdateFields()[0]->GetZIDs().size();
121 }
122 else
123 {
124 nExp =
m_equ[0]->UpdateFields()[0]->GetExpSize();
125 nPlanes = 1;
126 }
127 int expdim =
m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
128
129 int nFields =
m_equ[0]->UpdateFields().size();
130 int numSteps =
m_session->GetParameter(
"NumSteps");
132
133 Array<OneD, NekDouble> coeffs, phys, physReduced, tmpArray;
134
135
138
139
140 Array<OneD, int>
P(expdim);
141 Array<OneD, int> numPoints(expdim);
142 Array<OneD, LibUtilities::PointsKey> ptsKey(expdim);
144 for (int i = 1; i < nRuns; i++)
145 {
146
147 Array<OneD, MultiRegions::ExpListSharedPtr> fields =
148 m_equ[0]->UpdateFields();
149
150
151 map<int, int> deltaP;
152 int offset = 0;
153 for (int n = 0; n < nExp; n++)
154 {
155 offset = fields[sensorVar]->GetPhys_Offset(n);
156 Exp = fields[sensorVar]->GetExp(n);
157
158 for (int k = 0; k < expdim; ++k)
159 {
160 P[k] = Exp->GetBasis(k)->GetNumModes();
161 numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
162 ptsKey[k] = LibUtilities::PointsKey(
163 numPoints[k], Exp->GetBasis(k)->GetPointsType());
164 }
165
166
168 switch (Exp->GetGeom()->GetShapeType())
169 {
171 {
173 ptsKey[0]);
175 ptsKey[1]);
176 OrthoExp = MemoryManager<
177 StdRegions::StdQuadExp>::AllocateSharedPtr(Ba, Bb);
178 break;
179 }
181 {
183 ptsKey[0]);
185 ptsKey[1]);
186 OrthoExp =
188 Ba, Bb);
189 break;
190 }
192 {
194 ptsKey[0]);
196 ptsKey[1]);
198 ptsKey[2]);
199 OrthoExp =
201 Ba, Bb, Bc);
202 break;
203 }
205 {
207 ptsKey[0]);
209 ptsKey[1]);
211 ptsKey[2]);
212 OrthoExp =
214 Ba, Bb, Bc);
215 break;
216 }
218 {
220 ptsKey[0]);
222 ptsKey[1]);
224 ptsKey[2]);
225 OrthoExp = MemoryManager<
226 StdRegions::StdPrismExp>::AllocateSharedPtr(Ba, Bb, Bc);
227 break;
228 }
230 {
232 ptsKey[0]);
234 ptsKey[1]);
236 ptsKey[2]);
237 OrthoExp =
239 Ba, Bb, Bc);
240 break;
241 }
242 default:
243 ASSERTL0(
false,
"Shape not supported.");
244 break;
245 }
246
247 int nq = OrthoExp->GetTotPoints();
248
252
253 coeffs = Array<OneD, NekDouble>(OrthoExp->GetNcoeffs());
254 physReduced = Array<OneD, NekDouble>(OrthoExp->GetTotPoints());
255 tmpArray = Array<OneD, NekDouble>(OrthoExp->GetTotPoints(), 0.0);
256
257
258 for (int plane = 0; plane < nPlanes; plane++)
259 {
260 if (isHomogeneous1D)
261 {
262 phys =
263 fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
264 }
265 else
266 {
267 phys = fields[sensorVar]->GetPhys() + offset;
268 }
269
270
271 OrthoExp->FwdTrans(phys, coeffs);
272 OrthoExp->BwdTrans(coeffs, physReduced);
273
274
275 Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
276 Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
277 tmp = Exp->Integral(tmpArray);
278
280 fac = Exp->Integral(tmpArray);
281
282 tmp =
abs(tmp / fac);
283
284 if (tmp != tmp)
285 {
287 "Adaptive procedure encountered NaN value.");
288 }
289
290
291 error = (tmp > error) ? tmp : error;
292 }
293
294
295 m_session->GetComm()->GetColumnComm()->AllReduce(
297
298
299 if (
m_session->DefinesFunction(
"AdaptiveLowerTolerance"))
300 {
301 int nq = Exp->GetTotPoints();
302
303
304 Array<OneD, NekDouble> xc0, xc1, xc2;
305 xc0 = Array<OneD, NekDouble>(nq, 0.0);
306 xc1 = Array<OneD, NekDouble>(nq, 0.0);
307 xc2 = Array<OneD, NekDouble>(nq, 0.0);
308 Exp->GetCoords(xc0, xc1, xc2);
309
310
311 Array<OneD, NekDouble> tolerance(nq, 0.0);
313 m_session->GetFunction(
"AdaptiveLowerTolerance", 0);
314 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
316 }
317
318 if (
m_session->DefinesFunction(
"AdaptiveUpperTolerance"))
319 {
320 int nq = Exp->GetTotPoints();
321
322
323 Array<OneD, NekDouble> xc0, xc1, xc2;
324 xc0 = Array<OneD, NekDouble>(nq, 0.0);
325 xc1 = Array<OneD, NekDouble>(nq, 0.0);
326 xc2 = Array<OneD, NekDouble>(nq, 0.0);
327 Exp->GetCoords(xc0, xc1, xc2);
328
329
330 Array<OneD, NekDouble> tolerance(nq, 0.0);
332 m_session->GetFunction(
"AdaptiveUpperTolerance", 0);
333 ffunc->Evaluate(xc0, xc1, xc2, tolerance);
335 }
336
337
338 if ((error > upperTol) && (
P[0] < maxP))
339 {
340 deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
341 }
342 else if ((error < lowerTol) &&
P[0] > minP)
343 {
344 deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
345 }
346 else
347 {
348 deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
349 }
350 }
351
352
355
356
357
358
359
360 if (LibUtilities::NekManager<MultiRegions::GlobalLinSysKey,
361 MultiRegions::GlobalLinSys>::
362 PoolCreated(std::string("GlobalLinSys")))
363 {
364 LibUtilities::NekManager<MultiRegions::GlobalLinSysKey,
365 MultiRegions::GlobalLinSys>::
366 ClearManager(std::string("GlobalLinSys"));
367 }
368
369 int chkNumber =
m_equ[0]->GetCheckpointNumber();
370 int chkSteps =
m_equ[0]->GetCheckpointSteps();
371
372
374
375
376 mapping->ReplaceField(
m_equ[0]->UpdateFields());
377
378
379 m_equ[0]->SetCheckpointSteps(0);
380
381
382 m_equ[0]->DoInitialise();
383 m_equ[0]->SetInitialStep(i * numSteps);
384 m_equ[0]->SetSteps(i * numSteps + numSteps);
385 m_equ[0]->SetTime(startTime + i * period);
386 m_equ[0]->SetBoundaryConditions(startTime + i * period);
387 m_equ[0]->SetCheckpointNumber(chkNumber);
388 m_equ[0]->SetCheckpointSteps(chkSteps);
389
390
391 for (int n = 0; n < nFields; n++)
392 {
393 m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
394 fields[n], fields[n]->GetCoeffs(),
395 m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
396 m_equ[0]->UpdateFields()[n]->BwdTrans(
397 m_equ[0]->UpdateFields()[n]->GetCoeffs(),
398 m_equ[0]->UpdateFields()[n]->UpdatePhys());
399 }
400
401
403 }
404
406
408
409 if (
m_comm->GetRank() == 0)
410 {
411 CPUtime = timer.
Elapsed().count();
412 cout << "-------------------------------------------" << endl;
413 cout << "Total Computation Time = " << CPUtime << "s" << endl;
414 cout << "-------------------------------------------" << endl;
415 }
416
417
418
419
420
421
422 for (
int i = 0; i <
m_equ[0]->GetNvariables(); ++i)
423 {
424 Array<OneD, NekDouble> exactsoln(
m_equ[0]->GetTotPoints(), 0.0);
425
426
427 m_equ[0]->EvaluateExactSolution(i, exactsoln,
m_equ[0]->GetFinalTime());
428
431
432 if (
m_comm->GetRank() == 0)
433 {
434 out <<
"L 2 error (variable " <<
m_equ[0]->GetVariable(i)
435 << ") : " << vL2Error << endl;
436 out <<
"L inf error (variable " <<
m_equ[0]->GetVariable(i)
437 << ") : " << vLinfError << endl;
438 }
439 }
440}
#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.
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_InitObject(std::ostream &out=std::cout)
Virtual function for initialisation implementation.
LibUtilities::CommSharedPtr m_comm
Communication object.
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
std::shared_ptr< Equation > EquationSharedPtr
@ P
Monomial polynomials .
@ eOrtho_A
Principle Orthogonal Functions .
@ eOrtho_C
Principle Orthogonal Functions .
@ eOrtho_B
Principle Orthogonal Functions .
std::shared_ptr< Expansion > ExpansionSharedPtr
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
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)