Line |
Branch |
Exec |
Source |
1 |
|
|
// ______ ______ _ _ _____ ______ |
2 |
|
|
// | ____| ____| | (_)/ ____| | ____| |
3 |
|
|
// | |__ | |__ | | _| (___ ___| |__ |
4 |
|
|
// | __| | __| | | | |\___ \ / __| __| |
5 |
|
|
// | | | |____| |____| |____) | (__| |____ |
6 |
|
|
// |_| |______|______|_|_____/ \___|______| |
7 |
|
|
// Finite Elements for Life Sciences and Engineering |
8 |
|
|
// |
9 |
|
|
// License: LGL2.1 License |
10 |
|
|
// FELiScE default license: LICENSE in root folder |
11 |
|
|
// |
12 |
|
|
// Main authors: J. Foulon & M. Fragu |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
#ifndef _MODEL_HPP |
16 |
|
|
#define _MODEL_HPP |
17 |
|
|
|
18 |
|
|
// System includes |
19 |
|
|
#include <unordered_map> |
20 |
|
|
#include <string> |
21 |
|
|
#include <vector> |
22 |
|
|
|
23 |
|
|
// External includes |
24 |
|
|
#ifdef FELISCE_WITH_SLEPC |
25 |
|
|
#include "Core/NoThirdPartyWarning/Slepc/slepc.hpp" |
26 |
|
|
#endif |
27 |
|
|
|
28 |
|
|
// Project includes |
29 |
|
|
#include "Solver/linearProblem.hpp" |
30 |
|
|
#include "Core/commandLineOption.hpp" |
31 |
|
|
#include "Core/felisceParam.hpp" |
32 |
|
|
#include "Core/felisceTransient.hpp" |
33 |
|
|
#include "Core/mpiInfo.hpp" |
34 |
|
|
#include "Core/shared_pointers.hpp" |
35 |
|
|
#include "Model/initialCondition.hpp" |
36 |
|
|
#include "Model/solutionBackup.hpp" |
37 |
|
|
|
38 |
|
|
namespace felisce |
39 |
|
|
{ |
40 |
|
|
///@name felisce Globals |
41 |
|
|
///@{ |
42 |
|
|
|
43 |
|
|
///@} |
44 |
|
|
///@name Type Definitions |
45 |
|
|
///@{ |
46 |
|
|
|
47 |
|
|
///@} |
48 |
|
|
///@name Enum's |
49 |
|
|
///@{ |
50 |
|
|
|
51 |
|
|
///@} |
52 |
|
|
///@name Functions |
53 |
|
|
///@{ |
54 |
|
|
|
55 |
|
|
///@} |
56 |
|
|
///@name felisce Classes |
57 |
|
|
///@{ |
58 |
|
|
|
59 |
|
|
/*! |
60 |
|
|
\class Model |
61 |
|
|
\authors J. Foulon & M. Fragu |
62 |
|
|
\date 04/02/2011 |
63 |
|
|
\brief Manage a general Felisce Model. |
64 |
|
|
*/ |
65 |
|
|
class Model { |
66 |
|
|
public: |
67 |
|
|
///@name Type Definitions |
68 |
|
|
///@{ |
69 |
|
|
|
70 |
|
|
/// Pointer definition of Model |
71 |
|
|
FELISCE_CLASS_POINTER_DEFINITION(Model); |
72 |
|
|
|
73 |
|
|
///@} |
74 |
|
|
///@name Life Cycle |
75 |
|
|
///@{ |
76 |
|
|
|
77 |
|
|
///Constructor. |
78 |
|
|
//============= |
79 |
|
|
Model(); |
80 |
|
|
|
81 |
|
|
///Destructor. |
82 |
|
|
//============ |
83 |
|
|
virtual ~Model(); |
84 |
|
|
|
85 |
|
|
///@} |
86 |
|
|
///@name Operators |
87 |
|
|
///@{ |
88 |
|
|
|
89 |
|
|
///@} |
90 |
|
|
///@name Operations |
91 |
|
|
///@{ |
92 |
|
|
|
93 |
|
|
/// Function to initialize model |
94 |
|
|
//============================== |
95 |
|
|
virtual void initializeModel( |
96 |
|
|
CommandLineOption& opt, |
97 |
|
|
FelisceTransient& fstransient, |
98 |
|
|
const MPI_Comm comm = MPI_COMM_WORLD, |
99 |
|
|
const bool callPetscInitialize = true |
100 |
|
|
); |
101 |
|
|
|
102 |
|
239 |
virtual void initializeDerivedModel() {} |
103 |
|
|
|
104 |
|
451 |
virtual void initializeDerivedLinearProblem() {} |
105 |
|
|
|
106 |
|
163 |
virtual void setExternalVec() {} |
107 |
|
|
|
108 |
|
|
/*! |
109 |
|
|
* \brief Function to initialize linear problem m_linearProblem[k]. |
110 |
|
|
* |
111 |
|
|
* \param[in] doUseSNES True if you are handling an non-linear problem and using Petsc's SNES Newton-Raphson method |
112 |
|
|
* to manage it. |
113 |
|
|
*/ |
114 |
|
|
void initializeLinearProblem(LinearProblem* linearPb, bool doUseSNES = false); |
115 |
|
|
|
116 |
|
|
/*! |
117 |
|
|
\brief Initialization of all linear systems. |
118 |
|
|
\param[in] linearPb the vector of pointer to the linear problems. |
119 |
|
|
*/ |
120 |
|
|
void initializeLinearProblem(const std::vector<LinearProblem*>& linearPb, bool doUseSNES = false); |
121 |
|
|
|
122 |
|
|
void initializeLinearProblem(const std::vector<LinearProblem*>& linearPb, const std::vector<bool>& doUseSNES); |
123 |
|
|
|
124 |
|
|
/*! |
125 |
|
|
* \brief Function to finalizes linear problem m_linearProblem[k]. |
126 |
|
|
* |
127 |
|
|
* \param[in] doUseSNES True if you are handling an non-linear problem and using Petsc's SNES Newton-Raphson method |
128 |
|
|
* to manage it. |
129 |
|
|
*/ |
130 |
|
|
void finalizeLinearProblem(LinearProblem* linearPb); |
131 |
|
|
|
132 |
|
|
void finalizeLinearProblem(const std::vector<LinearProblem*>& linearPb); |
133 |
|
|
|
134 |
|
|
//================ |
135 |
|
|
|
136 |
|
|
/// Virtual function to specify special action before assembling(duplicate a matrix, work specific on RHS,...) |
137 |
|
296 |
virtual void preAssemblingMatrixRHS(std::size_t iProblem=0) { |
138 |
|
|
(void) iProblem; |
139 |
|
296 |
} |
140 |
|
|
|
141 |
|
|
/// Virtual function to specify special action after assembling(duplicate a matrix, work specific on RHS,...) |
142 |
|
✗ |
virtual void postAssemblingMatrixRHS(std::size_t iProblem=0) { |
143 |
|
|
(void) iProblem; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
/// Virtual function to specify special action before time loop (solve time-independent problem, ...) |
147 |
|
✗ |
virtual void preProcessing() {} |
148 |
|
|
|
149 |
|
|
/// Manage time iteration. |
150 |
|
|
virtual void updateTime(FlagMatrixRHS flagMatrixRHS=FlagMatrixRHS::matrix_and_rhs); |
151 |
|
|
|
152 |
|
|
/// Advance time step. |
153 |
|
|
virtual void forward()=0; |
154 |
|
|
|
155 |
|
|
/// Solve the problem with the initial conditions. |
156 |
|
|
virtual void SolveStaticProblem(); |
157 |
|
|
|
158 |
|
|
/** |
159 |
|
|
* @brief Solve the dynamic problem. |
160 |
|
|
* A call to this method performs all the work, including initial call to solve the static problem. |
161 |
|
|
*/ |
162 |
|
|
virtual void SolveDynamicProblem(); |
163 |
|
|
|
164 |
|
|
/// Get boolean to stop loop on time. |
165 |
|
|
bool hasFinished(); |
166 |
|
|
|
167 |
|
|
/// Make m_hasFinished true when stop loop on time according to |
168 |
|
|
/// another criterion (steady-state for example) before reaching timeMax or timeIterationMax |
169 |
|
|
void makeHasFinishedTrue() { |
170 |
|
|
m_hasFinished = true; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
///Input and output tools |
174 |
|
|
//======================= |
175 |
|
|
|
176 |
|
|
// reah mesh file to define problem |
177 |
|
|
virtual void readMesh(); |
178 |
|
|
|
179 |
|
|
// reah mesh file to define problem |
180 |
|
|
virtual void writeMesh(); |
181 |
|
|
|
182 |
|
|
// build edges of mesh |
183 |
|
|
void buildEdges(); |
184 |
|
|
|
185 |
|
|
// build faces of mesh |
186 |
|
|
void buildFaces(); |
187 |
|
|
|
188 |
|
|
// write solution with ensight |
189 |
|
|
void writeSolution(); |
190 |
|
|
|
191 |
|
|
/*! |
192 |
|
|
* \brief Write the matrix in Matlab format |
193 |
|
|
* |
194 |
|
|
* \param[in] filename Name of the file to be written |
195 |
|
|
* \param[in] index Index in the std::vector of the linear problem which matrix is printed |
196 |
|
|
*/ |
197 |
|
|
void writeMatrixForMatlab(const std::string& filename, unsigned int index = 0) const; |
198 |
|
|
|
199 |
|
|
/*! |
200 |
|
|
* \brief Write the RHS in Matlab format |
201 |
|
|
* |
202 |
|
|
* \param[in] filename Name of the file to be written |
203 |
|
|
* \param[in] index Index in the std::vector of the linear problem which rhs is printed |
204 |
|
|
*/ |
205 |
|
|
void writeRHSForMatlab(const std::string& filename, unsigned int index = 0) const; |
206 |
|
|
|
207 |
|
|
// Function tu compute boundary stress in a specific label |
208 |
|
|
void ComputeStress(int coef, int label, std::vector<double>& stress); |
209 |
|
|
|
210 |
|
|
virtual void setInitialCondition(); |
211 |
|
|
|
212 |
|
✗ |
virtual void userDefinedInitialConditions(std::size_t iProblem=0) {(void) iProblem;} |
213 |
|
|
|
214 |
|
|
//Callback functions. |
215 |
|
|
//================== |
216 |
|
|
|
217 |
|
|
/// Register a callable (function, functor) in the callback std::unordered_map. |
218 |
|
|
void addCallbackXYZ (const char *callbackName, const CallbackXYZ &callbackXYZ); |
219 |
|
|
void addCallbackXYZT(const char *callbackName, const CallbackXYZT &callbackXYZT); |
220 |
|
|
|
221 |
|
|
/// Get result of evaluation of callable named 'name' with given arguments. |
222 |
|
|
double evaluateCallback(const char *name, double x, double y, double z); |
223 |
|
|
double evaluateCallback(const char *name, double x, double y, double z, double t); |
224 |
|
|
|
225 |
|
|
// CVGraph |
226 |
|
|
//======== |
227 |
|
|
#ifdef FELISCE_WITH_CVGRAPH |
228 |
|
|
virtual void startIterationCVG(); |
229 |
|
✗ |
virtual void cvgraphNewTimeStep(){}; |
230 |
|
|
|
231 |
|
|
/// Impose the entire solution at the interface |
232 |
|
|
void ImposeCVGraphInterfaceSolution(double* ImpValue); |
233 |
|
|
|
234 |
|
|
/// Impose the solution corresponding to the variable with idVariable and a computed variable needed by the users |
235 |
|
|
void ImposeCVGraphInterfaceSolutionAndComputedVariable(double* ImpValue, int idVariable); |
236 |
|
|
|
237 |
|
|
/// Extract the entire solution at the interface |
238 |
|
|
virtual void ExtractCVGraphInterfaceSolution(double* valueDofInterface); |
239 |
|
|
|
240 |
|
|
/// Extract only the solution corresponding to the variable with idVariable |
241 |
|
|
void ExtractCVGraphInterfaceSolution(double* valueDofInterface, int idVariable); |
242 |
|
|
|
243 |
|
|
/// Extract the solution with idVariable and a specific variable computed by the user |
244 |
|
|
void ExtractCVGraphInterfaceSolutionAndComputedVariable(double* valueDofInterface,int idVariable,std::vector<double>& interfaceComputedVariable); |
245 |
|
|
|
246 |
|
|
/// Store the entire solution at the interface in order to use it as previous time step solution |
247 |
|
|
void StoreCVGraphInterfaceSolution(double* StoringValue); |
248 |
|
|
#endif |
249 |
|
|
|
250 |
|
|
///@} |
251 |
|
|
///@name Access |
252 |
|
|
///@{ |
253 |
|
|
|
254 |
|
25 |
IO* io(std::size_t i=0) { |
255 |
|
25 |
return m_ios[i].get(); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
335023 |
FelisceTransient::Pointer fstransient() { |
259 |
|
335023 |
return m_fstransient; |
260 |
|
|
} |
261 |
|
|
|
262 |
|
89 |
GeometricMeshRegion::Pointer mesh(const std::size_t i=0) { |
263 |
|
89 |
return m_mesh[i]; |
264 |
|
|
} |
265 |
|
|
|
266 |
|
1179 |
LinearProblem* linearProblem(const std::size_t i=0) { |
267 |
|
1179 |
return m_linearProblem[i]; |
268 |
|
|
} |
269 |
|
|
|
270 |
|
|
/// Get model name |
271 |
|
|
const std::string& name() const { |
272 |
|
|
return m_name; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
/// Get model instance index |
276 |
|
17088985 |
std::size_t& instanceIndex() { |
277 |
|
17088985 |
return m_instanceIndex; |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
std::size_t instanceIndex() const { |
281 |
|
|
return m_instanceIndex; |
282 |
|
|
} |
283 |
|
|
|
284 |
|
|
/// print a banner with text, the time and the iteration number |
285 |
|
|
void printNewTimeIterationBanner(); |
286 |
|
|
|
287 |
|
|
///Get Time. |
288 |
|
|
double getTime() const; |
289 |
|
|
///Set Time. |
290 |
|
|
void setTime(const double time); |
291 |
|
|
|
292 |
|
|
/// Function to get size of the state std::vector. |
293 |
|
✗ |
virtual int getNstate() const { |
294 |
|
✗ |
return 0; |
295 |
|
|
} |
296 |
|
✗ |
virtual int getNstate(PhysicalVariable variable) const { |
297 |
|
|
(void) variable; |
298 |
|
✗ |
return 0; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
/// Function to get state vector. |
302 |
|
✗ |
virtual void getState(double* & state) { |
303 |
|
|
(void) state; |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
/// Function to std::set state std::vector. |
307 |
|
✗ |
virtual void setState(double* & state) { |
308 |
|
|
(void) state; |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
inline const MapCallbackXYZ& mapCallbackXYZ () const { |
312 |
|
|
return m_mapCallbackXYZ; |
313 |
|
|
} |
314 |
|
|
inline MapCallbackXYZ& mapCallbackXYZ () { |
315 |
|
|
return m_mapCallbackXYZ; |
316 |
|
|
} |
317 |
|
|
inline const MapCallbackXYZT& mapCallbackXYZT() const { |
318 |
|
|
return m_mapCallbackXYZT; |
319 |
|
|
} |
320 |
|
|
inline MapCallbackXYZT& mapCallbackXYZT() { |
321 |
|
|
return m_mapCallbackXYZT; |
322 |
|
|
} |
323 |
|
|
|
324 |
|
|
CallbackXYZ& callbackXYZ (const char* name); |
325 |
|
|
CallbackXYZT& callbackXYZT(const char* name); |
326 |
|
|
|
327 |
|
|
///@} |
328 |
|
|
///@name Inquiry |
329 |
|
|
///@{ |
330 |
|
|
|
331 |
|
|
///@} |
332 |
|
|
///@name Input and output |
333 |
|
|
///@{ |
334 |
|
|
|
335 |
|
|
///@} |
336 |
|
|
///@name Friends |
337 |
|
|
///@{ |
338 |
|
|
|
339 |
|
|
///@} |
340 |
|
|
protected: |
341 |
|
|
///@name Protected Life Cycle |
342 |
|
|
///@{ |
343 |
|
|
|
344 |
|
|
///@} |
345 |
|
|
///@name Protected static Member Variables |
346 |
|
|
///@{ |
347 |
|
|
|
348 |
|
|
///@} |
349 |
|
|
///@name Protected member Variables |
350 |
|
|
///@{ |
351 |
|
|
|
352 |
|
|
/// model name |
353 |
|
|
std::string m_name = "GIVE_A_NAME_TO_YOUR_MODEL"; |
354 |
|
|
|
355 |
|
|
/// Instance index |
356 |
|
|
std::size_t m_instanceIndex = 0; |
357 |
|
|
|
358 |
|
|
/// Global mesh |
359 |
|
|
std::vector<GeometricMeshRegion::Pointer> m_mesh; |
360 |
|
|
|
361 |
|
|
/// InputOutput manager |
362 |
|
|
std::vector<IO::Pointer> m_ios; |
363 |
|
|
|
364 |
|
|
FelisceTransient::Pointer m_fstransient = nullptr; |
365 |
|
|
|
366 |
|
|
/// Linear Problem |
367 |
|
|
std::vector<LinearProblem*> m_linearProblem; |
368 |
|
|
|
369 |
|
|
// Has finished flag |
370 |
|
|
bool m_hasFinished = false; |
371 |
|
|
|
372 |
|
|
//CVGraphInterface |
373 |
|
|
CVGraphInterface::Pointer m_cvgraphInterf = nullptr; |
374 |
|
|
|
375 |
|
|
// initialization flags |
376 |
|
|
bool m_modelIsInitialized = false; |
377 |
|
|
bool m_linearProblemIsInitialized = false; |
378 |
|
|
bool m_eigenProblemIsInitialized = false; |
379 |
|
|
bool m_meshIsRead = false; |
380 |
|
|
bool m_meshIsWritten = false; |
381 |
|
|
bool m_initializeCVGraphInterface = false; |
382 |
|
|
bool m_callPetscInitialize = false; |
383 |
|
|
|
384 |
|
|
// Callback maps |
385 |
|
|
MapCallbackXYZ m_mapCallbackXYZ; |
386 |
|
|
MapCallbackXYZT m_mapCallbackXYZT; |
387 |
|
|
|
388 |
|
|
///Initialization vectors. |
389 |
|
|
PetscVector m_U_0; |
390 |
|
|
std::vector<SolutionBackup> m_solutionBackup; |
391 |
|
|
InitialCondition m_initialCondition; |
392 |
|
|
|
393 |
|
|
///@} |
394 |
|
|
///@name Protected Operators |
395 |
|
|
///@{ |
396 |
|
|
|
397 |
|
|
///@} |
398 |
|
|
///@name Protected Operations |
399 |
|
|
///@{ |
400 |
|
|
|
401 |
|
|
///@} |
402 |
|
|
///@name Protected Operators |
403 |
|
|
///@{ |
404 |
|
|
|
405 |
|
|
///@} |
406 |
|
|
///@name Protected Operations |
407 |
|
|
///@{ |
408 |
|
|
|
409 |
|
|
///@} |
410 |
|
|
///@name Protected Access |
411 |
|
|
///@{ |
412 |
|
|
|
413 |
|
|
///@} |
414 |
|
|
///@name Protected Inquiry |
415 |
|
|
///@{ |
416 |
|
|
|
417 |
|
|
///@} |
418 |
|
|
///@name Protected LifeCycle |
419 |
|
|
///@{ |
420 |
|
|
|
421 |
|
|
///@} |
422 |
|
|
private: |
423 |
|
|
///@name Private Life Cycle |
424 |
|
|
///@{ |
425 |
|
|
|
426 |
|
|
///@} |
427 |
|
|
///@name Private Operators |
428 |
|
|
///@{ |
429 |
|
|
|
430 |
|
|
///@} |
431 |
|
|
///@name Private Operations |
432 |
|
|
///@{ |
433 |
|
|
|
434 |
|
|
#ifdef FELISCE_WITH_CVGRAPH |
435 |
|
|
void rhsWithoutBC_zeroEntries(); |
436 |
|
|
void rhsWithoutBC_restore(); |
437 |
|
|
#endif |
438 |
|
|
|
439 |
|
|
///@} |
440 |
|
|
///@name Private static Member Variables |
441 |
|
|
///@{ |
442 |
|
|
|
443 |
|
|
///@} |
444 |
|
|
///@name Private member Variables |
445 |
|
|
///@{ |
446 |
|
|
|
447 |
|
|
#ifdef FELISCE_WITH_CVGRAPH |
448 |
|
|
PetscVector m_rhsWithForceTermWithoutBC; |
449 |
|
|
bool m_rhsWithoutBC_zeroed; |
450 |
|
|
#endif |
451 |
|
|
|
452 |
|
|
///@} |
453 |
|
|
///@name Private Operators |
454 |
|
|
///@{ |
455 |
|
|
|
456 |
|
|
///@} |
457 |
|
|
///@name Private Operations |
458 |
|
|
///@{ |
459 |
|
|
|
460 |
|
|
void checkConnectionVariablesMeshs(); |
461 |
|
|
|
462 |
|
|
///@} |
463 |
|
|
///@name Private Access |
464 |
|
|
///@{ |
465 |
|
|
|
466 |
|
|
///@} |
467 |
|
|
///@name Private Inquiry |
468 |
|
|
///@{ |
469 |
|
|
|
470 |
|
|
///@} |
471 |
|
|
///@name Private LifeCycle |
472 |
|
|
///@{ |
473 |
|
|
|
474 |
|
|
///@} |
475 |
|
|
}; |
476 |
|
|
|
477 |
|
|
///@} |
478 |
|
|
///@name Type Definitions |
479 |
|
|
///@{ |
480 |
|
|
|
481 |
|
|
///@} |
482 |
|
|
|
483 |
|
|
} // namespace felisce |
484 |
|
|
|
485 |
|
|
#endif |
486 |
|
|
|