Directory: | ./ |
---|---|
File: | Model/linearElasticityModel.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 42 | 58 | 72.4% |
Branches: | 9 | 48 | 18.8% |
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/linearElasticityModel.hpp" | ||
21 | #include "Solver/linearProblemLinearElasticity.hpp" | ||
22 | #ifdef FELISCE_WITH_CVGRAPH | ||
23 | #include "Model/cvgMainSlave.hpp" | ||
24 | #endif | ||
25 | |||
26 | namespace felisce { | ||
27 | // Called in Model::initializeLinearProblem, just after the mesh partitioning. | ||
28 | 4 | void LinearElasticityModel::initializeDerivedModel() { | |
29 | // Saving the lpb pointer after the static cast | ||
30 | 4 | m_lpbLE = static_cast<LinearProblemLinearElasticity*>(m_linearProblem[0]); | |
31 | // Initializing the PetscVectors | ||
32 | 4 | m_lpbLE->initPetscVectors(); | |
33 | 4 | } | |
34 | // Pre-assemble, called during initializeLinearProblem | ||
35 | 4 | void LinearElasticityModel::preAssemblingMatrixRHS(std::size_t iProblem) { | |
36 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if ( iProblem == (std::size_t) m_idLE) { |
37 | // Zero-ing the solution | ||
38 | 4 | m_lpbLE->solution().zeroEntries(); | |
39 | // Assembling the static part of the matrix. | ||
40 | 4 | m_lpbLE->assembleMatrixRHS(MpiInfo::rankProc(), FlagMatrixRHS::matrix_and_rhs); | |
41 | } | ||
42 | 4 | } | |
43 | |||
44 | // Forward | ||
45 | 120 | void LinearElasticityModel::forward() { | |
46 | // Preparation: write solution, update time, print banner.. | ||
47 | 120 | prepareForward(); | |
48 | // Assemble volume stuff | ||
49 | 120 | m_lpbLE->assembleMatrixRHS(MpiInfo::rankProc(),FlagMatrixRHS::matrix_and_rhs); | |
50 | // Sum static matrix into matrix(0) | ||
51 | 120 | m_lpbLE->addMatrixRHS(); | |
52 | // apply BC and solve | ||
53 | 120 | solveLinearElasticity(); | |
54 | // update of the velocity from the displacement | ||
55 | 120 | m_lpbLE->updateCurrentVelocity(); | |
56 | // update old displacement | ||
57 | 120 | finalizeForward(); | |
58 | 120 | } | |
59 | |||
60 | // Write solution, advance in time | ||
61 | 120 | void LinearElasticityModel::prepareForward( FlagMatrixRHS flag ) { | |
62 | 120 | writeNormal(); | |
63 | 120 | writeSolution(); | |
64 | 120 | updateTime(flag); | |
65 | 120 | printNewTimeIterationBanner(); | |
66 | 120 | } | |
67 | |||
68 | // Boundary conditions and solve | ||
69 | 120 | void LinearElasticityModel::solveLinearElasticity(FlagMatrixRHS flag) { | |
70 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | if (FelisceParam::verbose()) |
71 | 120 | PetscPrintf(MpiInfo::petscComm(),"Applying BC \n"); | |
72 | |||
73 | // finalize essential BC transient | ||
74 | 120 | m_lpbLE->finalizeEssBCTransient(); | |
75 | // Apply BC | ||
76 | #ifdef FELISCE_WITH_CVGRAPH | ||
77 |
2/6✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 120 times.
✗ Branch 9 not taken.
|
120 | if ( !FelisceParam::instance().withCVG || ! m_linearProblem[0]->slave()->redoTimeStepOnlyCVGData() ) { |
78 | 120 | m_lpbLE->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc(),flag,flag); | |
79 | } else { | ||
80 | ✗ | m_linearProblem[0]->applyOnlyCVGBoundaryCondition(); | |
81 | } | ||
82 | #else | ||
83 | m_lpbLE->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc(),flag,flag); | ||
84 | #endif | ||
85 | |||
86 | // For the elasticity and stokes coupled application | ||
87 |
2/6✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 120 times.
|
120 | if( m_lpbLE->coupled() && !FelisceParam::instance().withCVG ) { |
88 | ✗ | m_lpbLE->sumOnBoundary(m_lpbLE->vector(), m_lpbLE->get(LinearProblem::sequential,"externalStress"), m_lpbLE->dofBD(/*iBD*/0)); | |
89 | } | ||
90 | |||
91 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | if (FelisceParam::verbose()) |
92 | 120 | PetscPrintf(MpiInfo::petscComm(),"Solving linear elasticity system \n"); | |
93 | |||
94 | 120 | m_lpbLE->solve(MpiInfo::rankProc(), MpiInfo::numProc()); | |
95 | |||
96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
|
120 | if (FelisceParam::instance().withCVG ) { |
97 | ✗ | m_linearProblem[0]->computeResidual(); | |
98 | } | ||
99 | 120 | } | |
100 | |||
101 | // Update old variables + post-processing | ||
102 | 120 | void LinearElasticityModel::finalizeForward() { | |
103 | 120 | m_lpbLE->updateOldDisplacement(); | |
104 | 120 | writeNormal(); | |
105 | 120 | } | |
106 | |||
107 | 240 | void LinearElasticityModel::writeNormal() { | |
108 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 240 times.
|
240 | if (FelisceParam::instance().exportP1Normal ) { |
109 | ✗ | PetscVector vec; | |
110 | ✗ | if( m_fstransient->iteration == 0 ) { | |
111 | ✗ | vec.duplicateFrom(m_lpbLE->sequentialSolution()); | |
112 | ✗ | vec.zeroEntries(); | |
113 | } else { | ||
114 | ✗ | vec=m_lpbLE->get(LinearProblem::sequential,"normalField"); | |
115 | } | ||
116 | ✗ | m_lpbLE->writeSolutionFromVec(vec, MpiInfo::rankProc(), m_ios, m_fstransient->time, m_fstransient->iteration, std::string("normal")); | |
117 | } | ||
118 | 240 | } | |
119 | #ifdef FELISCE_WITH_CVGRAPH | ||
120 | void | ||
121 | ✗ | LinearElasticityModel::cvgraphNewTimeStep() { | |
122 | ✗ | m_lpbLE->updateCurrentVelocity(); | |
123 | ✗ | this->finalizeForward(); //advance in time | |
124 | ✗ | this->prepareForward(); | |
125 | ✗ | m_linearProblem[0]->assembleMatrixRHS(MpiInfo::rankProc(),FlagMatrixRHS::matrix_and_rhs); | |
126 | ✗ | m_linearProblem[0]->addMatrixRHS(); | |
127 | ✗ | m_linearProblem[0]->createAndCopyMatrixRHSWithoutBC(); | |
128 | } | ||
129 | #endif | ||
130 | } | ||
131 |