Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Attributes | Friends | List of all members
Nektar::SolverUtils::DriverAdaptive Class Reference

Base class for the adaptive polynomial order driver. More...

#include <DriverAdaptive.h>

Inheritance diagram for Nektar::SolverUtils::DriverAdaptive:
[legend]

Static Public Member Functions

static DriverSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

SOLVER_UTILS_EXPORT DriverAdaptive (const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
 Constructor. More...
 
virtual SOLVER_UTILS_EXPORT ~DriverAdaptive ()
 Destructor. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (std::ostream &out=std::cout)
 Second-stage initialisation. More...
 
virtual SOLVER_UTILS_EXPORT void v_Execute (std::ostream &out=std::cout)
 Virtual function for solve implementation. More...
 
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. More...
 
- Protected Member Functions inherited from Nektar::SolverUtils::Driver
 Driver (const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
 Initialises EquationSystem class members. More...
 
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDoublev_GetRealEvl (void)
 
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDoublev_GetImagEvl (void)
 

Static Protected Attributes

static std::string driverLookupId
 
- Static Protected Attributes inherited from Nektar::SolverUtils::Driver
static std::string evolutionOperatorLookupIds []
 
static std::string evolutionOperatorDef
 
static std::string driverDefault
 

Friends

class MemoryManager< DriverAdaptive >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::SolverUtils::Driver
virtual ~Driver ()
 Destructor. More...
 
SOLVER_UTILS_EXPORT void InitObject (std::ostream &out=std::cout)
 Initialise Object. More...
 
SOLVER_UTILS_EXPORT void Execute (std::ostream &out=std::cout)
 Execute driver. More...
 
SOLVER_UTILS_EXPORT Array< OneD, EquationSystemSharedPtrGetEqu ()
 
SOLVER_UTILS_EXPORT Array< OneD, NekDoubleGetRealEvl (void)
 
SOLVER_UTILS_EXPORT Array< OneD, NekDoubleGetImagEvl (void)
 
- Protected Attributes inherited from Nektar::SolverUtils::Driver
LibUtilities::CommSharedPtr m_comm
 Communication object. More...
 
LibUtilities::SessionReaderSharedPtr m_session
 Session reader object. More...
 
LibUtilities::SessionReaderSharedPtr session_LinNS
 I the Coupling between SFD and arnoldi. More...
 
SpatialDomains::MeshGraphSharedPtr m_graph
 MeshGraph object. More...
 
Array< OneD, EquationSystemSharedPtrm_equ
 Equation system to solve. More...
 
int m_nequ
 number of equations More...
 
enum EvolutionOperatorType m_EvolutionOperator
 Evolution Operator. More...
 

Detailed Description

Base class for the adaptive polynomial order driver.

Definition at line 47 of file DriverAdaptive.h.

Constructor & Destructor Documentation

◆ DriverAdaptive()

Nektar::SolverUtils::DriverAdaptive::DriverAdaptive ( const LibUtilities::SessionReaderSharedPtr  pSession,
const SpatialDomains::MeshGraphSharedPtr  pGraph 
)
protected

Constructor.

Definition at line 62 of file DriverAdaptive.cpp.

65  : Driver(pSession, pGraph)
66 {
67 }
Driver(const LibUtilities::SessionReaderSharedPtr pSession, const SpatialDomains::MeshGraphSharedPtr pGraph)
Initialises EquationSystem class members.
Definition: Driver.cpp:74

◆ ~DriverAdaptive()

Nektar::SolverUtils::DriverAdaptive::~DriverAdaptive ( )
protectedvirtual

Destructor.

Definition at line 72 of file DriverAdaptive.cpp.

73 {
74 }

Member Function Documentation

◆ create()

static DriverSharedPtr Nektar::SolverUtils::DriverAdaptive::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const SpatialDomains::MeshGraphSharedPtr pGraph 
)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file DriverAdaptive.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

56  {
59  p->InitObject();
60  return p;
61  }
std::shared_ptr< Driver > DriverSharedPtr
A shared pointer to a Driver object.
Definition: Driver.h:51
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ ReplaceExpansion()

void Nektar::SolverUtils::DriverAdaptive::ReplaceExpansion ( Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
std::map< int, int >  deltaP 
)
protected

Update EXPANSIONS tag inside XML schema to reflect new polynomial order distribution.

Parameters
fieldsInput fields.
deltaPMap of polynomial order expansions

Definition at line 447 of file DriverAdaptive.cpp.

References Nektar::LibUtilities::BasisTypeMap, Nektar::ParseUtils::GenerateSeqString(), Nektar::SolverUtils::Driver::m_equ, Nektar::SolverUtils::Driver::m_session, and Nektar::LibUtilities::ShapeTypeMap.

Referenced by v_Execute().

450 {
451  int nExp, nDim;
452  int expdim = m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
453 
454  // Get field definitions
455  std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs =
456  fields[0]->GetFieldDefinitions();
457 
458  if (fielddefs[0]->m_numHomogeneousDir == 1)
459  {
460  nDim = expdim+1;
461  }
462  else
463  {
464  nDim = expdim;
465  }
466 
467  // Add variables to field definition
468  for (int i = 0; i < fielddefs.size(); ++i)
469  {
470  for (int j = 0; j < fields.num_elements(); ++j)
471  {
472  fielddefs[i]->m_fields.push_back(m_session->GetVariable(j));
473  }
474  }
475 
476  // Get tinyxml objects
477  TiXmlElement *exp_tag = m_session->GetElement("NEKTAR/EXPANSIONS");
478 
479  // Clear current expansions
480  exp_tag->Clear();
481 
482  // Write new expansion information
483  for (int f = 0; f < fielddefs.size(); ++f)
484  {
485  nExp = fielddefs[f]->m_elementIDs.size();
486 
487  //---------------------------------------------
488  // Write ELEMENTS
489  TiXmlElement *elemTag = new TiXmlElement("ELEMENTS");
490  exp_tag->LinkEndChild(elemTag);
491 
492  // Write FIELDS
493  std::string fieldsString;
494  {
495  std::stringstream fieldsStringStream;
496  bool first = true;
497  for (std::vector<int>::size_type i = 0;
498  i < fielddefs[f]->m_fields.size(); i++)
499  {
500  if (!first)
501  {
502  fieldsStringStream << ",";
503  }
504  fieldsStringStream << fielddefs[f]->m_fields[i];
505  first = false;
506  }
507  fieldsString = fieldsStringStream.str();
508  }
509  elemTag->SetAttribute("FIELDS", fieldsString);
510 
511  // Write SHAPE
512  std::string shapeString;
513  {
514  std::stringstream shapeStringStream;
515  shapeStringStream
516  << LibUtilities::ShapeTypeMap[fielddefs[f]->m_shapeType];
517  if (fielddefs[f]->m_numHomogeneousDir == 1)
518  {
519  shapeStringStream << "-HomogenousExp1D";
520  }
521  else if (fielddefs[f]->m_numHomogeneousDir == 2)
522  {
523  shapeStringStream << "-HomogenousExp2D";
524  }
525 
526  shapeString = shapeStringStream.str();
527  }
528  elemTag->SetAttribute("SHAPE", shapeString);
529 
530  // Write BASIS
531  std::string basisString;
532  {
533  std::stringstream basisStringStream;
534  bool first = true;
535  for (std::vector<LibUtilities::BasisType>::size_type i = 0;
536  i < fielddefs[f]->m_basis.size(); i++)
537  {
538  if (!first)
539  {
540  basisStringStream << ",";
541  }
542  basisStringStream
543  << LibUtilities::BasisTypeMap[fielddefs[f]->m_basis[i]];
544  first = false;
545  }
546  basisString = basisStringStream.str();
547  }
548  elemTag->SetAttribute("BASIS", basisString);
549 
550  // Write homogeneuous length details
551  if (fielddefs[f]->m_numHomogeneousDir)
552  {
553  std::string homoLenString;
554  {
555  std::stringstream homoLenStringStream;
556  bool first = true;
557  for (int i = 0; i < fielddefs[f]->m_numHomogeneousDir; ++i)
558  {
559  if (!first)
560  {
561  homoLenStringStream << ",";
562  }
563  homoLenStringStream
564  << fielddefs[f]->m_homogeneousLengths[i];
565  first = false;
566  }
567  homoLenString = homoLenStringStream.str();
568  }
569  elemTag->SetAttribute("HOMOGENEOUSLENGTHS", homoLenString);
570  }
571 
572  // Write homogeneuous planes/lines details
573  if (fielddefs[f]->m_numHomogeneousDir)
574  {
575  if (fielddefs[f]->m_homogeneousYIDs.size() > 0)
576  {
577  std::string homoYIDsString;
578  {
579  std::stringstream homoYIDsStringStream;
580  bool first = true;
581  for (int i = 0; i < fielddefs[f]->m_homogeneousYIDs.size();
582  i++)
583  {
584  if (!first)
585  {
586  homoYIDsStringStream << ",";
587  }
588  homoYIDsStringStream
589  << fielddefs[f]->m_homogeneousYIDs[i];
590  first = false;
591  }
592  homoYIDsString = homoYIDsStringStream.str();
593  }
594  elemTag->SetAttribute("HOMOGENEOUSYIDS", homoYIDsString);
595  }
596 
597  if (fielddefs[f]->m_homogeneousZIDs.size() > 0)
598  {
599  std::string homoZIDsString;
600  {
601  std::stringstream homoZIDsStringStream;
602  bool first = true;
603  for (int i = 0; i < fielddefs[f]->m_homogeneousZIDs.size();
604  i++)
605  {
606  if (!first)
607  {
608  homoZIDsStringStream << ",";
609  }
610  homoZIDsStringStream
611  << fielddefs[f]->m_homogeneousZIDs[i];
612  first = false;
613  }
614  homoZIDsString = homoZIDsStringStream.str();
615  }
616  elemTag->SetAttribute("HOMOGENEOUSZIDS", homoZIDsString);
617  }
618  }
619 
620  // Write NUMMODESPERDIR
621  std::string numModesString;
622  {
623  std::stringstream numModesStringStream;
624 
625  numModesStringStream << "MIXORDER:";
626  bool first = true;
627  int eId;
628  Array<OneD, int> order(nDim, 0);
629  for (int n = 0; n < nExp; n++)
630  {
631  eId = fielddefs[f]->m_elementIDs[n];
632 
633  for (int i = 0; i < expdim; i++)
634  {
635  order[i] = deltaP[eId];
636  }
637 
638  for (int i = 0; i < nDim; i++)
639  {
640  if (fielddefs[f]->m_uniOrder)
641  {
642  order[i] += fielddefs[f]->m_numModes[i];
643  }
644  else
645  {
646  order[i] += fielddefs[f]->m_numModes[n * nDim + i];
647  }
648 
649  if (!first)
650  {
651  numModesStringStream << ",";
652  }
653 
654  numModesStringStream << order[i];
655  first = false;
656  }
657  }
658  numModesString = numModesStringStream.str();
659  }
660  elemTag->SetAttribute("NUMMODESPERDIR", numModesString);
661 
662  // Write IDs. Should ideally look at ways of compressing this stream if
663  // just sequential.
664  elemTag->SetAttribute(
665  "ID", ParseUtils::GenerateSeqString(fielddefs[f]->m_elementIDs));
666  }
667 }
const char *const BasisTypeMap[]
Definition: Foundations.hpp:46
const char *const ShapeTypeMap[]
Definition: ShapeType.hpp:67
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers...
Definition: ParseUtils.h:71
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:98
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:89

◆ v_Execute()

void Nektar::SolverUtils::DriverAdaptive::v_Execute ( std::ostream &  out = std::cout)
protectedvirtual

Virtual function for solve implementation.

Implements Nektar::SolverUtils::Driver.

Definition at line 84 of file DriverAdaptive.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::eHexahedron, Nektar::LibUtilities::eOrtho_A, Nektar::LibUtilities::eOrtho_B, Nektar::LibUtilities::eOrtho_C, Nektar::LibUtilities::ePrism, Nektar::LibUtilities::ePyramid, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, Nektar::GlobalMapping::Mapping::Load(), Nektar::SolverUtils::Driver::m_comm, Nektar::SolverUtils::Driver::m_equ, Nektar::SolverUtils::Driver::m_graph, Nektar::SolverUtils::Driver::m_session, Nektar::GlobalMapping::MappingSharedPtr, class_topology::P, Nektar::LibUtilities::ReduceMax, ReplaceExpansion(), Nektar::SolverUtils::Driver::v_InitObject(), Vmath::Vmul(), Vmath::Vsub(), and Vmath::Vsum().

85 {
86  time_t starttime, endtime;
87  NekDouble CPUtime;
88 
89  m_equ[0]->PrintSummary(out);
90 
91  // First run using original order
92  time(&starttime);
93  m_equ[0]->DoInitialise();
94 
95  // Obtain initial time in case a restart was used
96  NekDouble startTime = m_equ[0]->GetFinalTime();
97  m_equ[0]->DoSolve();
98 
99  // Load session parameters and solver info
100  bool isHomogeneous1D;
101  int nRuns, minP, maxP, sensorVar;
102  NekDouble lowerTol, upperTol;
103  m_session->LoadParameter ("NumRuns", nRuns, 1);
104  m_session->LoadParameter ("AdaptiveMinModes", minP, 4);
105  m_session->LoadParameter ("AdaptiveMaxModes", maxP, 12);
106  m_session->LoadParameter ("AdaptiveLowerTolerance", lowerTol, 1e-8);
107  m_session->LoadParameter ("AdaptiveUpperTolerance", upperTol, 1e-6);
108  m_session->LoadParameter ("AdaptiveSensorVariable", sensorVar, 0);
109  m_session->MatchSolverInfo("Homogeneous", "1D", isHomogeneous1D, false);
110 
111  // Get number of elements and planes
112  int nExp, nPlanes;
113  if (isHomogeneous1D)
114  {
115  nExp = m_equ[0]->UpdateFields()[0]->GetPlane(0)->GetExpSize();
116  nPlanes = m_equ[0]->UpdateFields()[0]->GetZIDs().num_elements();
117  }
118  else
119  {
120  nExp = m_equ[0]->UpdateFields()[0]->GetExpSize();
121  nPlanes = 1;
122  }
123  int expdim = m_equ[0]->UpdateFields()[0]->GetGraph()->GetMeshDimension();
124 
125  int nFields = m_equ[0]->UpdateFields().num_elements();
126  int numSteps = m_session->GetParameter("NumSteps");
127  NekDouble period = m_session->GetParameter("TimeStep") * numSteps;
128 
129  Array<OneD, NekDouble> coeffs, phys, physReduced, tmpArray;
130 
131  // Get mapping
134  m_equ[0]->UpdateFields());
135 
136  // Adaptive loop
137  Array<OneD, int> P(expdim);
138  Array<OneD, int> numPoints(expdim);
139  Array<OneD, LibUtilities::PointsKey> ptsKey(expdim);
141  for (int i = 1; i < nRuns; i++)
142  {
143  // Get field expansions
144  Array<OneD, MultiRegions::ExpListSharedPtr> fields =
145  m_equ[0]->UpdateFields();
146 
147  // Determine the change to be applied in the order
148  map<int, int> deltaP;
149  int offset = 0;
150  for (int n = 0; n < nExp; n++)
151  {
152  offset = fields[sensorVar]->GetPhys_Offset(n);
153  Exp = fields[sensorVar]->GetExp(n);
154 
155  for( int k = 0; k < expdim; ++k)
156  {
157  P[k] = Exp->GetBasis(k)->GetNumModes();
158  numPoints[k] = Exp->GetBasis(k)->GetNumPoints();
159  ptsKey[k] = LibUtilities::PointsKey (numPoints[k],
160  Exp->GetBasis(k)->GetPointsType());
161  }
162 
163  // Declare orthogonal basis.
165  switch (Exp->GetGeom()->GetShapeType())
166  {
168  {
169  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
170  ptsKey[0]);
171  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_A, P[1] - 1,
172  ptsKey[1]);
173  OrthoExp = MemoryManager<
174  StdRegions::StdQuadExp>::AllocateSharedPtr(Ba, Bb);
175  break;
176  }
178  {
179  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
180  ptsKey[0]);
181  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_B, P[1] - 1,
182  ptsKey[1]);
183  OrthoExp =
185  Ba, Bb);
186  break;
187  }
189  {
190  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
191  ptsKey[0]);
192  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_B, P[1] - 1,
193  ptsKey[1]);
194  LibUtilities::BasisKey Bc(LibUtilities::eOrtho_C, P[2] - 1,
195  ptsKey[2]);
196  OrthoExp =
198  Ba, Bb, Bc);
199  break;
200  }
202  {
203  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
204  ptsKey[0]);
205  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_A, P[1] - 1,
206  ptsKey[1]);
207  LibUtilities::BasisKey Bc(LibUtilities::eOrtho_C, P[2] - 1,
208  ptsKey[2]);
209  OrthoExp =
211  Ba, Bb, Bc);
212  break;
213  }
215  {
216  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
217  ptsKey[0]);
218  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_A, P[1] - 1,
219  ptsKey[1]);
220  LibUtilities::BasisKey Bc(LibUtilities::eOrtho_B, P[2] - 1,
221  ptsKey[2]);
222  OrthoExp =
224  Ba, Bb, Bc);
225  break;
226  }
228  {
229  LibUtilities::BasisKey Ba(LibUtilities::eOrtho_A, P[0] - 1,
230  ptsKey[0]);
231  LibUtilities::BasisKey Bb(LibUtilities::eOrtho_A, P[1] - 1,
232  ptsKey[1]);
233  LibUtilities::BasisKey Bc(LibUtilities::eOrtho_A, P[2] - 1,
234  ptsKey[2]);
235  OrthoExp =
237  Ba, Bb, Bc);
238  break;
239  }
240  default:
241  ASSERTL0(false, "Shape not supported.");
242  break;
243  }
244 
245  int nq = OrthoExp->GetTotPoints();
246 
247  NekDouble error = 0;
248  NekDouble fac = 0;
249  NekDouble tmp = 0;
250 
251  coeffs = Array<OneD, NekDouble>(OrthoExp->GetNcoeffs());
252  physReduced = Array<OneD, NekDouble>(OrthoExp->GetTotPoints());
253  tmpArray = Array<OneD, NekDouble>(OrthoExp->GetTotPoints(), 0.0);
254 
255  // Refinement based only on one variable
256  for (int plane = 0; plane < nPlanes; plane++)
257  {
258  if (isHomogeneous1D)
259  {
260  phys =
261  fields[sensorVar]->GetPlane(plane)->GetPhys() + offset;
262  }
263  else
264  {
265  phys = fields[sensorVar]->GetPhys() + offset;
266  }
267 
268  // Project solution to lower order
269  OrthoExp->FwdTrans(phys, coeffs);
270  OrthoExp->BwdTrans(coeffs, physReduced);
271 
272  // Calculate error =||phys-physReduced||^2 / ||phys||^2
273  Vmath::Vsub(nq, phys, 1, physReduced, 1, tmpArray, 1);
274  Vmath::Vmul(nq, tmpArray, 1, tmpArray, 1, tmpArray, 1);
275  tmp = Exp->Integral(tmpArray);
276 
277  Vmath::Vmul(nq, phys, 1, phys, 1, tmpArray, 1);
278  fac = Exp->Integral(tmpArray);
279 
280  tmp = abs(tmp / fac);
281 
282  if (tmp != tmp)
283  {
284  ASSERTL0(false,
285  "Adaptive procedure encountered NaN value.");
286  }
287 
288  // Get maximum value along planes
289  error = (tmp > error) ? tmp : error;
290  }
291 
292  // Combine planes from different processes
293  m_session->GetComm()->GetColumnComm()->AllReduce(
294  error, LibUtilities::ReduceMax);
295 
296  // Override tolerances if function is defined
297  if (m_session->DefinesFunction("AdaptiveLowerTolerance"))
298  {
299  int nq = Exp->GetTotPoints();
300 
301  // Obtain points from the the element
302  Array<OneD, NekDouble> xc0, xc1, xc2;
303  xc0 = Array<OneD, NekDouble>(nq, 0.0);
304  xc1 = Array<OneD, NekDouble>(nq, 0.0);
305  xc2 = Array<OneD, NekDouble>(nq, 0.0);
306  Exp->GetCoords(xc0, xc1, xc2);
307 
308  // Evaluate function from session file
309  Array<OneD, NekDouble> tolerance(nq, 0.0);
311  m_session->GetFunction("AdaptiveLowerTolerance", 0);
312  ffunc->Evaluate(xc0, xc1, xc2, tolerance);
313  lowerTol = Vmath::Vsum(nq, tolerance, 1) / nq;
314  }
315 
316  if (m_session->DefinesFunction("AdaptiveUpperTolerance"))
317  {
318  int nq = Exp->GetTotPoints();
319 
320  // Obtain points from the the element
321  Array<OneD, NekDouble> xc0, xc1, xc2;
322  xc0 = Array<OneD, NekDouble>(nq, 0.0);
323  xc1 = Array<OneD, NekDouble>(nq, 0.0);
324  xc2 = Array<OneD, NekDouble>(nq, 0.0);
325  Exp->GetCoords(xc0, xc1, xc2);
326 
327  // Evaluate function from session file
328  Array<OneD, NekDouble> tolerance(nq, 0.0);
330  m_session->GetFunction("AdaptiveUpperTolerance", 0);
331  ffunc->Evaluate(xc0, xc1, xc2, tolerance);
332  upperTol = Vmath::Vsum(nq, tolerance, 1) / nq;
333  }
334 
335  // Determine what to do with the polynomial order
336  if ((error > upperTol) && (P[0] < maxP))
337  {
338  deltaP[Exp->GetGeom()->GetGlobalID()] = 1;
339  }
340  else if ((error < lowerTol) && P[0] > minP)
341  {
342  deltaP[Exp->GetGeom()->GetGlobalID()] = -1;
343  }
344  else
345  {
346  deltaP[Exp->GetGeom()->GetGlobalID()] = 0;
347  }
348  }
349 
350  // Write new expansion section to the session reader and re-read graph.
351  ReplaceExpansion(fields, deltaP);
352  m_graph->ReadExpansions();
353 
354  // Reset GlobalLinSys Manager to avoid using too much memory
355  //
356  // @todo This could be made better by replacing individual matrices
357  // within the linear system.
358  if (LibUtilities::NekManager<MultiRegions::GlobalLinSysKey,
359  MultiRegions::GlobalLinSys>::
360  PoolCreated(std::string("GlobalLinSys")))
361  {
362  LibUtilities::NekManager<MultiRegions::GlobalLinSysKey,
363  MultiRegions::GlobalLinSys>::
364  ClearManager(std::string("GlobalLinSys"));
365  }
366 
367  int chkNumber = m_equ[0]->GetCheckpointNumber();
368  int chkSteps = m_equ[0]->GetCheckpointSteps();
369 
370  // Initialise driver again
372 
373  // Update mapping (must be before m_equ[0]->DoInitialise();)
374  mapping->ReplaceField(m_equ[0]->UpdateFields());
375 
376  // Set chkSteps to zero to avoid writing initial condition
377  m_equ[0]->SetCheckpointSteps(0);
378 
379  // Initialise equation
380  m_equ[0]->DoInitialise();
381  m_equ[0]->SetInitialStep(i * numSteps);
382  m_equ[0]->SetSteps(i * numSteps + numSteps);
383  m_equ[0]->SetTime(startTime + i * period);
384  m_equ[0]->SetBoundaryConditions(startTime + i * period);
385  m_equ[0]->SetCheckpointNumber(chkNumber);
386  m_equ[0]->SetCheckpointSteps(chkSteps);
387 
388  // Project solution to new expansion
389  for (int n = 0; n < nFields; n++)
390  {
391  m_equ[0]->UpdateFields()[n]->ExtractCoeffsToCoeffs(
392  fields[n], fields[n]->GetCoeffs(),
393  m_equ[0]->UpdateFields()[n]->UpdateCoeffs());
394  m_equ[0]->UpdateFields()[n]->BwdTrans_IterPerExp(
395  m_equ[0]->UpdateFields()[n]->GetCoeffs(),
396  m_equ[0]->UpdateFields()[n]->UpdatePhys());
397  }
398 
399  // Solve equation
400  m_equ[0]->DoSolve();
401  }
402 
403  time(&endtime);
404 
405  m_equ[0]->Output();
406 
407  if (m_comm->GetRank() == 0)
408  {
409  CPUtime = difftime(endtime, starttime);
410  cout << "-------------------------------------------" << endl;
411  cout << "Total Computation Time = " << CPUtime << "s" << endl;
412  cout << "-------------------------------------------" << endl;
413  }
414 
415  // Evaluate and output computation time and solution accuracy.
416  // The specific format of the error output is essential for the
417  // regression tests to work.
418 
419  // Evaluate L2 Error
420  for (int i = 0; i < m_equ[0]->GetNvariables(); ++i)
421  {
422  Array<OneD, NekDouble> exactsoln(m_equ[0]->GetTotPoints(), 0.0);
423 
424  // Evaluate "ExactSolution" function, or zero array
425  m_equ[0]->EvaluateExactSolution(i, exactsoln, m_equ[0]->GetFinalTime());
426 
427  NekDouble vL2Error = m_equ[0]->L2Error (i, exactsoln);
428  NekDouble vLinfError = m_equ[0]->LinfError(i, exactsoln);
429 
430  if (m_comm->GetRank() == 0)
431  {
432  out << "L 2 error (variable " << m_equ[0]->GetVariable(i)
433  << ") : " << vL2Error << endl;
434  out << "L inf error (variable " << m_equ[0]->GetVariable(i)
435  << ") : " << vLinfError << endl;
436  }
437  }
438 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
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.
Principle Orthogonal Functions .
Definition: BasisType.h:46
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:90
SpatialDomains::MeshGraphSharedPtr m_graph
MeshGraph object.
Definition: Driver.h:95
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Principle Orthogonal Functions .
Definition: BasisType.h:47
Principle Orthogonal Functions .
Definition: BasisType.h:45
double NekDouble
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.
Definition: Vmath.cpp:346
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:131
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:65
Array< OneD, EquationSystemSharedPtr > m_equ
Equation system to solve.
Definition: Driver.h:98
LibUtilities::CommSharedPtr m_comm
Communication object.
Definition: Driver.h:86
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:50
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition: Vmath.cpp:740
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.
Definition: Mapping.cpp:268
LibUtilities::SessionReaderSharedPtr m_session
Session reader object.
Definition: Driver.h:89
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.
Definition: Vmath.cpp:186

◆ v_InitObject()

void Nektar::SolverUtils::DriverAdaptive::v_InitObject ( std::ostream &  out = std::cout)
protectedvirtual

Second-stage initialisation.

Reimplemented from Nektar::SolverUtils::Driver.

Definition at line 79 of file DriverAdaptive.cpp.

References Nektar::SolverUtils::Driver::v_InitObject().

80 {
82 }
virtual SOLVER_UTILS_EXPORT void v_InitObject(std::ostream &out=std::cout)
Definition: Driver.cpp:90

Friends And Related Function Documentation

◆ MemoryManager< DriverAdaptive >

friend class MemoryManager< DriverAdaptive >
friend

Definition at line 50 of file DriverAdaptive.h.

Member Data Documentation

◆ className

string Nektar::SolverUtils::DriverAdaptive::className
static
Initial value:

Name of the class.

Definition at line 64 of file DriverAdaptive.h.

◆ driverLookupId

string Nektar::SolverUtils::DriverAdaptive::driverLookupId
staticprotected
Initial value:

Definition at line 85 of file DriverAdaptive.h.