IFEM 90A354
SIMSolverAdap.h
Go to the documentation of this file.
1// $Id$
2//==============================================================================
12//==============================================================================
13
14#ifndef _SIM_SOLVER_ADAP_H_
15#define _SIM_SOLVER_ADAP_H_
16
17#include "SIMSolver.h"
18#include "AdaptiveSIM.h"
19#include "TimeStep.h"
20
21
26template<class T1, bool SolutionTransfer = false>
28{
29public:
31 AdaptiveISolver(T1& sim, bool sa) : AdaptiveSIM(sim,sa), model(sim) {}
32
36 bool adaptMesh(int iStep, std::streamsize outPrec = 0)
37 {
38 if constexpr (SolutionTransfer) {
39 if (iStep > 1) {
41 this->prepareAdapt();
42 }
43 return this->AdaptiveSIM::adaptMesh(iStep, transfered, outPrec);
44 } else
45 return this->AdaptiveSIM::adaptMesh(iStep, outPrec);
46 }
47
48protected:
50 virtual void prepareAdapt() {}
51
53 virtual void prepareSolutionTransfer() {}
54
56 bool assembleAndSolveSystem() override
57 {
58 TimeStep dummy;
59 model.init(dummy);
60
61 if constexpr (SolutionTransfer) {
62 if (!transfered.empty()) {
64 for (size_t i = 0; i < transfered.size(); ++i)
65 model.setSolution(transfered[i], i);
66 }
67 }
68
69 if (model.solveStep(dummy))
70 solution = model.getSolutions();
71 else
72 return false;
73
74 return true;
75 }
76
79 bool savePoints(int iStep) const override
80 {
81 return model.savePoints(0.0,iStep);
82 }
83
86};
87
88
95template<class T1, class AdapSim>
97{
98public:
100 explicit SIMSolverAdapImpl(T1& s1) : SIMSolverStat<T1>(s1), aSim(s1,false)
101 {
102 this->S1.setSol(&aSim.getSolution());
103 this->S1.opt.saveNorms = true;
104 }
105
108
110 virtual bool read(const char* file) { return this->SIMadmin::read(file); }
111
113 virtual int solveProblem(char* infile, const char* = nullptr)
114 {
115 if (!aSim.initAdaptor())
116 return 1;
117
119 SIMSolverStat<T1>::exporter->setFieldValue(exporterName, &this->S1,
120 &aSim.getSolution(),
121 &aSim.getProjections(),
122 &aSim.getEnorm());
123
124 for (int iStep = 1; aSim.adaptMesh(iStep); iStep++)
125 if (!aSim.solveStep(infile,iStep))
126 return 1;
127 else if (!aSim.writeGlv(infile,iStep))
128 return 2;
130 SIMSolverStat<T1>::exporter->dumpTimeLevel(nullptr,true);
131
132 return 0;
133 }
134
136 void setExporterName(const std::string& name) { exporterName = name; }
137
138protected:
140 virtual bool parse(char* kyw, std::istream& is) { return aSim.parse(kyw,is); }
142 virtual bool parse(const tinyxml2::XMLElement* elem) { return aSim.parse(elem); }
143
144 AdapSim aSim;
145 std::string exporterName = "u";
146};
147
148
150template<class T1>
152
153
159template<class T1>
161{
162public:
164 explicit SIMSolverAdapInternal(T1& s1) : SIMSolverStat<T1>(s1) {}
165
168
170 bool read(const char* file) override { return this->SIMadmin::read(file); }
171
173 int solveProblem(char* infile, const char* = nullptr) override
174 {
175 if (!this->S1.initAdapPrm())
176 return 1;
177
178 int geoBlk = 0, nBlock = 0;
179 for (int iStep = 1; this->S1.adaptMesh(iStep); iStep++) {
180 IFEM::cout <<"\nAdaptive step "<< iStep << std::endl;
181 if (!this->S1.solveStep(infile,iStep))
182 return 1;
183 else if (!this->S1.projectNorms(iStep))
184 return 2;
185 else if (!this->saveState(geoBlk,nBlock,iStep,infile))
186 return 3;
187 }
188
189 return 0;
190 }
191
193 bool parse(const tinyxml2::XMLElement* elem) override
194 {
195 return this->S1.parse(elem);
196 }
197
198protected:
200 bool saveState(int& geoBlk, int& nBlock, int iStep, char* infile)
201 {
202 if (!this->S1.saveModel(iStep == 1 ? infile : nullptr,geoBlk,nBlock))
203 return false;
204
205 TimeStep tp;
206 tp.step = iStep;
207
208 if (!this->S1.saveElmNorms(iStep,nBlock))
209 return false;
210
211 if (!this->S1.saveProjections(iStep,nBlock))
212 return false;
213
214 if (!this->S1.saveStep(tp,nBlock))
215 return false;
216
217 return this->exporter ? this->exporter->dumpTimeLevel(&tp,true) : true;
218 }
219};
220
221#endif
Adaptive solution driver for linear static FEM simulators.
std::vector< Vector > Vectors
An array of real-valued vectors with algebraic operations.
Definition MatVec.h:37
SIM solver class template.
Class for encapsulation of general time stepping parameters.
static const double T1[2]
1-point rule coordinates.
Definition TriangleQuadrature.C:19
Adaptive simulator driver using the ISolver interface.
Definition SIMSolverAdap.h:28
virtual void prepareSolutionTransfer()
Hook for preparation steps before solution transfer.
Definition SIMSolverAdap.h:53
virtual void prepareAdapt()
Hook for preparation steps before mesh adaptation.
Definition SIMSolverAdap.h:50
bool assembleAndSolveSystem() override
Assembles and solves the linearized FE equation system.
Definition SIMSolverAdap.h:56
Vectors transfered
Transfered solutions.
Definition SIMSolverAdap.h:85
bool savePoints(int iStep) const override
Saves point results to output file for a given refinement step.
Definition SIMSolverAdap.h:79
T1 & model
Reference to the actual sim.
Definition SIMSolverAdap.h:84
AdaptiveISolver(T1 &sim, bool sa)
The constructor forwards to the parent class constructor.
Definition SIMSolverAdap.h:31
bool adaptMesh(int iStep, std::streamsize outPrec=0)
Refines the current mesh based on the element norms.
Definition SIMSolverAdap.h:36
Adaptive solution driver for linear static FEM simulators.
Definition AdaptiveSIM.h:28
Vectors solution
All solutions (including Galerkin projections)
Definition AdaptiveSIM.h:108
bool adaptMesh(int iStep, std::streamsize outPrec=0)
Refines the current mesh based on the element norms.
Definition AdaptiveSIM.C:190
bool dumpTimeLevel(const TimeStep *tp=nullptr, bool geoUpd=false, bool doLog=false)
Dumps all registered fields using the registered writers.
Definition DataExporter.C:95
static utl::LogStream cout
Combined standard out for parallel processes.
Definition IFEM.h:62
Template class for stationary adaptive simulator drivers.
Definition SIMSolverAdap.h:97
virtual int solveProblem(char *infile, const char *=nullptr)
Solves the problem on a sequence of adaptively refined meshes.
Definition SIMSolverAdap.h:113
SIMSolverAdapImpl(T1 &s1)
The constructor forwards to the parent class constructor.
Definition SIMSolverAdap.h:100
virtual bool parse(const tinyxml2::XMLElement *elem)
Parses a data section from an XML element.
Definition SIMSolverAdap.h:142
AdapSim aSim
Adaptive simulation driver.
Definition SIMSolverAdap.h:144
void setExporterName(const std::string &name)
Set name of data exporter registration to use.
Definition SIMSolverAdap.h:136
virtual ~SIMSolverAdapImpl()
Empty destructor.
Definition SIMSolverAdap.h:107
std::string exporterName
Name for data exporter registration to use.
Definition SIMSolverAdap.h:145
virtual bool read(const char *file)
Reads solver data from the specified input file.
Definition SIMSolverAdap.h:110
virtual bool parse(char *kyw, std::istream &is)
Parses a data section from an input stream.
Definition SIMSolverAdap.h:140
Template class for adaptive simulator drivers which handle adaptation internally.
Definition SIMSolverAdap.h:161
virtual ~SIMSolverAdapInternal()
Empty destructor.
Definition SIMSolverAdap.h:167
int solveProblem(char *infile, const char *=nullptr) override
Solves the problem on a sequence of adaptively refined meshes.
Definition SIMSolverAdap.h:173
bool parse(const tinyxml2::XMLElement *elem) override
Parse an element from an XML input file.
Definition SIMSolverAdap.h:193
bool read(const char *file) override
Reads solver data from the specified input file.
Definition SIMSolverAdap.h:170
SIMSolverAdapInternal(T1 &s1)
The constructor forwards to the parent class constructor.
Definition SIMSolverAdap.h:164
bool saveState(int &geoBlk, int &nBlock, int iStep, char *infile)
Saves geometry and results to VTF and HDF5 for current time step.
Definition SIMSolverAdap.h:200
Template class for stationary simulator drivers.
Definition SIMSolver.h:32
DataExporter * exporter
Administrator for result output to HDF5 file.
Definition SIMSolver.h:111
T1 & S1
The actual solver.
Definition SIMSolver.h:109
virtual bool read(const char *fileName)
Reads model data from the specified input file *fileName.
Definition SIMadmin.C:68
SIMoptions & opt
Simulation control parameters.
Definition SIMadmin.h:82
bool saveNorms
If true, save element norms.
Definition SIMoptions.h:92
Class for encapsulation of general time stepping parameters.
Definition TimeStep.h:31
int step
Time step counter.
Definition TimeStep.h:72