IFEM 90A354
SIMExplicitLMM.h
Go to the documentation of this file.
1//==============================================================================
11//==============================================================================
12
13#ifndef SIM_EXPLICIT_LMM_H_
14#define SIM_EXPLICIT_LMM_H_
15
16#include "SystemMatrix.h"
17#include "SIMenums.h"
18#include "TimeIntUtils.h"
19#include "TimeStep.h"
20
21#include <memory>
22#include <sstream>
23#include <utility>
24
25class DataExporter;
26
27
28namespace TimeIntegration {
29
33template<class Solver>
35{
36public:
42 SIMExplicitLMM(Solver& solv, Method type, bool standalone = true,
43 const std::string& solField = "") :
44 solver(solv), alone(standalone), fieldName(solField)
45 {
46 if (type == AB2)
47 order = 2;
48 else if (type == AB3)
49 order = 3;
50 else if (type == AB4)
51 order = 4;
52 else if (type == AB5)
53 order = 5;
54 else
55 order = 1;
56
57 loads.resize(order);
58
59 Solver::msgLevel = 1; // prints primary solution summary only
60 }
61
63 const ProcessAdm& getProcessAdm() const { return solver.getProcessAdm(); }
64
67 {
68 if (alone)
69 solver.getProcessAdm().cout <<"\n step = "<< tp.step <<" time = "<< tp.time.t << std::endl;
70
71 // Initialize time-dependent Dirichlet boundary conditions at start of step.
72 if (!solver.initDirichlet(tp.time.t))
73 return false;
74
75 TimeDomain time(tp.time);
76 time.t = tp.time.t - tp.time.dt;
77
78 // Set up constraints at stage time for assembly.
79 // Note: we don't apply absolute BCs before assembly like RK does;
80 // the assembly process handles the constraint formulation.
81 Vector zeroRef(solver.getSolution(1).size());
82 if (!solver.updateDirichlet(time.t, &zeroRef, true))
83 return false;
84
85 if (!solver.assembleSystem(time, Vectors(1, solver.getSolution(1)),
86 !linear || (tp.step == 1)))
87 return false;
88
89 loads[0].reset(solver.getRHSvector(0, true));
90
91 const std::vector<std::vector<double>> AB_coefs = {
92 {1.0},
93 {-0.5, 1.5},
94 {5.0/12.0, -16.0/12.0, 23.0/12.0},
95 {-9.0/24.0, 37.0/24, -59.0/24.0, 55.0/24.0},
96 {251.0/720.0, -1274.0/720.0, 2616.0/720.0, -2774.0/720.0, 1901.0/720.0}
97 };
98
99 const int c_order = hasICs ? order-1 : std::min(order-1, tp.step-1);
100 const std::vector<double>& AB_coef = AB_coefs[c_order];
101
102 SystemVector* rhs = solver.getRHSvector(0, false);
103 rhs->mult(AB_coef.back() * tp.time.dt);
104
105 for (size_t j = 0; j < AB_coef.size()-1; ++j)
106 solver.addToRHSvector(0, *loads[c_order-j], AB_coef[j]*tp.time.dt);
107
108 if (!solver.solveSystem(solver.getSolution()))
109 return false;
110
111 if (linear)
112 solver.setMode(SIM::RHS_ONLY);
113
114 solver.getSolution() += solver.getSolution(1);
115
116 // Enforce absolute boundary values at the new time level.
117 Vector dum;
118 if (!solver.updateDirichlet(tp.time.t, &dum))
119 return false;
120 if (!solver.applyDirichlet(solver.getSolution()))
121 return false;
122
123 if (alone)
124 solver.printSolutionSummary(solver.getSolution(), 0,
125 solver.getProblem()->getField1Name(1).c_str());
126
127 return true;
128 }
129
132 {
133 // Evaluate fluxes for initial conditions.
134 if (tp.step == 1) {
135 hasICs = true;
136 for (int j = 2; j <= order; ++j) {
137 std::stringstream str;
138 str << fieldName << j;
139 if (solver.hasIC(str.str())) {
140 TimeDomain time(tp.time);
141 time.t = tp.time.t - j*tp.time.dt;
142
143 Vector zeroRef(solver.getSolution(j-1).size());
144 if (!solver.updateDirichlet(time.t, &zeroRef, true))
145 return false;
146
147 if (!solver.assembleSystem(time, Vectors(1, solver.getSolution(j-1))))
148 return false;
149
150 loads[j-2].reset(solver.getRHSvector(0, true));
151 } else {
152 hasICs = false;
153 break;
154 }
155 }
156 }
157
158 loads.back().reset();
159 for (int j = order-2; j >= 0; --j)
160 loads[j+1] = std::move(loads[j]);
161 loads[0].reset();
162
163 return solver.advanceStep(tp);
164 }
165
167 bool saveModel(char* fileName, int& geoBlk, int& nBlock)
168 {
169 return solver.saveModel(fileName, geoBlk, nBlock);
170 }
171
173 bool saveStep(const TimeStep& tp, int& nBlock)
174 {
175 return solver.saveStep(tp, nBlock);
176 }
177
180 {
181 solver.registerFields(exporter);
182 }
183
186 bool serialize(std::map<std::string,std::string>& data)
187 {
188 return solver.serialize(data);
189 }
190
193 bool deSerialize(const std::map<std::string,std::string>& data)
194 {
195 return solver.deSerialize(data);
196 }
197
199 void setLinear(bool enable) { linear = enable; }
200
201protected:
202 Solver& solver;
203 std::vector<std::unique_ptr<SystemVector>> loads;
204 int order;
205 bool alone;
206 const std::string fieldName;
207 bool hasICs = false;
208 bool linear = false;
209};
210
211}
212
213#endif
std::vector< Vector > Vectors
An array of real-valued vectors with algebraic operations.
Definition MatVec.h:37
Various enums for simulation scope.
General representation of system matrices and vectors.
Various helpers for time integration.
Class for encapsulation of general time stepping parameters.
Administer and write data using DataWriters.
Definition DataExporter.h:38
Class for administration of MPI processes in IFEM library.
Definition ProcessAdm.h:33
Base class for representing a system vector on different formats.
Definition SystemMatrix.h:32
virtual void mult(Real alpha)=0
Multiplication with a scalar.
Explicit linear multistep time stepping for SIM classes.
Definition SIMExplicitLMM.h:35
bool serialize(std::map< std::string, std::string > &data)
Serialize internal state for restarting purposes.
Definition SIMExplicitLMM.h:186
bool hasICs
If true, start with full order.
Definition SIMExplicitLMM.h:207
bool saveStep(const TimeStep &tp, int &nBlock)
Saves the converged results of a given time step to VTF file.
Definition SIMExplicitLMM.h:173
bool linear
If true, mass matrix is constant.
Definition SIMExplicitLMM.h:208
bool solveStep(TimeStep &tp)
Computes the solution for the current time step.
Definition SIMExplicitLMM.h:66
Solver & solver
Reference to simulator.
Definition SIMExplicitLMM.h:202
bool advanceStep(TimeStep &tp)
Advances the time step one step forward.
Definition SIMExplicitLMM.h:131
const std::string fieldName
Name of primary solution fields (for ICs)
Definition SIMExplicitLMM.h:206
bool alone
If true, this is a standalone solver.
Definition SIMExplicitLMM.h:205
bool deSerialize(const std::map< std::string, std::string > &data)
Set internal state from a serialized state.
Definition SIMExplicitLMM.h:193
bool saveModel(char *fileName, int &geoBlk, int &nBlock)
Opens a new VTF-file and writes the model geometry to it.
Definition SIMExplicitLMM.h:167
std::vector< std::unique_ptr< SystemVector > > loads
Unscaled load vectors.
Definition SIMExplicitLMM.h:203
int order
Order of method.
Definition SIMExplicitLMM.h:204
const ProcessAdm & getProcessAdm() const
Returns the parallel process administrator.
Definition SIMExplicitLMM.h:63
SIMExplicitLMM(Solver &solv, Method type, bool standalone=true, const std::string &solField="")
Constructor.
Definition SIMExplicitLMM.h:42
void setLinear(bool enable)
Mark operator as linear to avoid repeated assembly and factorization.
Definition SIMExplicitLMM.h:199
void registerFields(DataExporter &exporter)
Registers fields for output to a data exporter.
Definition SIMExplicitLMM.h:179
Class for encapsulation of general time stepping parameters.
Definition TimeStep.h:31
int step
Time step counter.
Definition TimeStep.h:72
TimeDomain time
Time domain data.
Definition TimeStep.h:74
A vector class with some added algebraic operations.
Definition matrix.h:64
Utilities for time integration.
Definition BDF.h:21
Method
Enum defining various solution methods.
Definition TimeIntUtils.h:28
@ AB2
Second order Adams-Bashforth, explicit.
Definition TimeIntUtils.h:37
@ AB3
Third order Adams-Bashforth, explicit.
Definition TimeIntUtils.h:38
@ AB4
Fourth order Adams-Bashforth, explicit.
Definition TimeIntUtils.h:39
@ AB5
Fifth order Adams-Bashforth, explicit.
Definition TimeIntUtils.h:40
Struct representing the time domain.
Definition TimeDomain.h:23
double dt
Current timestep (or load parameter) increment.
Definition TimeDomain.h:25
double t
Current time (or pseudo time, load parameter)
Definition TimeDomain.h:24