Directory: | ./ |
---|---|
File: | Model/poroElasticityModel.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 37 | 60 | 61.7% |
Branches: | 7 | 40 | 17.5% |
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: | ||
13 | // | ||
14 | |||
15 | // System includes | ||
16 | |||
17 | // External includes | ||
18 | |||
19 | // Project includes | ||
20 | #include "Model/poroElasticityModel.hpp" | ||
21 | #ifdef FELISCE_WITH_CVGRAPH | ||
22 | #include "Model/cvgMainSlave.hpp" | ||
23 | #endif | ||
24 | #include "Core/mpiInfo.hpp" | ||
25 | |||
26 | namespace felisce { | ||
27 | 2 | PoroElasticityModel::PoroElasticityModel():Model() { | |
28 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | m_name = "Linear Poro Elasticity"; |
29 | 2 | m_idPE=0; | |
30 | 2 | } | |
31 | |||
32 | 2 | void PoroElasticityModel::initializeDerivedModel() { | |
33 | // The pointer to the linear problem | ||
34 | // is casted to a LinearProblemPoroElasticity pointer. | ||
35 | // In this way we can access functions defined only | ||
36 | // in that linear problem and not in linearProblem.hpp. | ||
37 | 2 | m_lpbPE = static_cast<LinearProblemPoroElasticity*>(m_linearProblem[m_idPE]); | |
38 | // The petscVectors stored in m_vecs and m_seqVecs are initialized: | ||
39 | // their structures are copied from the solution and from the sequential solution. | ||
40 | 2 | m_lpbPE->initPetscVectors(); | |
41 | // Custom initialization defined in the user files. | ||
42 | 2 | m_lpbPE->userInitialize(); | |
43 | 2 | } | |
44 | |||
45 | |||
46 | 2 | void PoroElasticityModel::preAssemblingMatrixRHS(std::size_t /*iProblem*/) { | |
47 | // Zeroing the solution. | ||
48 | 2 | m_lpbPE->solution().zeroEntries(); | |
49 | // Assembling the static part of the matrix. | ||
50 | 2 | m_lpbPE->assembleMatrixRHS(MpiInfo::rankProc());// no flag, by default it means matrix_and_rhs | |
51 | 2 | } | |
52 | |||
53 | 20 | void PoroElasticityModel::forward() { | |
54 | // Post-processing of last iteration, t=t+dt | ||
55 | 20 | prepareForward(); | |
56 | // Assembling the non-static part of the matrix | ||
57 | 20 | m_lpbPE->assembleMatrixRHS(MpiInfo::rankProc(),FlagMatrixRHS::matrix_and_rhs); | |
58 | // Summing static and non static part of the matrix | ||
59 | 20 | m_lpbPE->addMatrixRHS(); | |
60 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | if ( FelisceParam::instance().withCVG ) { |
61 | ✗ | m_lpbPE->createAndCopyMatrixRHSWithoutBC(); | |
62 | } | ||
63 | // Solving the problem ( BC + ksp ) | ||
64 | 20 | solvePoroElasticity(); | |
65 | 20 | } | |
66 | |||
67 | |||
68 | 20 | void PoroElasticityModel::prepareForward( FlagMatrixRHS flag ) { | |
69 | // Post processing of last time step + export | ||
70 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 18 times.
|
20 | if( m_fstransient->iteration == 0 ) { |
71 | 2 | m_lpbPE->exportInitialFiltrationVelocity(m_ios); | |
72 | } else { | ||
73 | 18 | m_lpbPE->advanceInTime(); | |
74 | 18 | m_lpbPE->exportFiltrationVelocity(m_ios); | |
75 | } | ||
76 | 20 | writeSolution(); | |
77 | // t=t+dt, plus clear matrix(1) and rhs | ||
78 | 20 | updateTime(flag); | |
79 | 20 | printNewTimeIterationBanner(); | |
80 | 20 | } | |
81 | |||
82 | 20 | void PoroElasticityModel::solvePoroElasticity(FlagMatrixRHS flag) { | |
83 | // Applying boundary conditions | ||
84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | if (FelisceParam::verbose()) |
85 | ✗ | PetscPrintf(MpiInfo::petscComm(),"Applying boundary conditions \n"); | |
86 | // Apply essential transient boundary conditions. | ||
87 | 20 | m_lpbPE->finalizeEssBCTransient(); | |
88 | 20 | m_lpbPE->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc(),flag,flag); | |
89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | if (FelisceParam::verbose()) |
90 | ✗ | PetscPrintf(MpiInfo::petscComm(),"Solving linear poro-elasticity system \n"); | |
91 | // Solve linear system. | ||
92 | 20 | m_lpbPE->solve(MpiInfo::rankProc(), MpiInfo::numProc()); | |
93 | // Computing residual stresses | ||
94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | if (FelisceParam::instance().withCVG ) { |
95 | ✗ | m_lpbPE->computeResidual(); | |
96 | } | ||
97 | 20 | } | |
98 | |||
99 | #ifdef FELISCE_WITH_CVGRAPH | ||
100 | ✗ | void PoroElasticityModel::startIterationCVG() { | |
101 | ✗ | cvgMainSlave* slave=m_lpbPE->slave(); | |
102 | ✗ | if (slave==nullptr) { | |
103 | ✗ | FEL_ERROR("slave not initialized"); | |
104 | } | ||
105 | ✗ | if( slave->newTimeStep() ) { | |
106 | ✗ | prepareForward(); | |
107 | ✗ | m_lpbPE->assembleMatrixRHS(MpiInfo::rankProc(),FlagMatrixRHS::matrix_and_rhs); | |
108 | ✗ | m_lpbPE->addMatrixRHS(); | |
109 | ✗ | m_lpbPE->createAndCopyMatrixRHSWithoutBC(); | |
110 | ✗ | } else if( slave->redoTimeStep() ) { | |
111 | ✗ | std::stringstream msg; | |
112 | ✗ | msg << "......................................" << std::endl; | |
113 | ✗ | msg << "Redo time step at time t= " << m_fstransient->time << std::endl; | |
114 | ✗ | PetscPrintf(MpiInfo::petscComm(),"%s",msg.str().c_str()); | |
115 | ✗ | m_linearProblem[0]->matrix(0).copyFrom(m_linearProblem[0]->matrixWithoutBC(),SAME_NONZERO_PATTERN); | |
116 | ✗ | m_linearProblem[0]->vector().copyFrom(m_linearProblem[0]->rhsWithoutBC()); | |
117 | // m_lpbPE->clearMatrixRHS(); | ||
118 | // m_lpbPE->assembleMatrixRHS(MpiInfo::rankProc(),FlagMatrixRHS::matrix_and_rhs); | ||
119 | // m_lpbPE->addMatrixRHS(); | ||
120 | // m_lpbPE->createAndCopyMatrixRHSWithoutBC(); | ||
121 | ✗ | } else { | |
122 | ✗ | slave->msgInfo().print(1); | |
123 | ✗ | FEL_ERROR("Error: strange timeStatus"); | |
124 | } | ||
125 | } | ||
126 | #endif | ||
127 | } | ||
128 |