GCC Code Coverage Report


Directory: ./
File: Model/heatModel.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 31 50 62.0%
Branches: 5 22 22.7%

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/heatModel.hpp"
21 #ifdef FELISCE_WITH_CVGRAPH
22 #include "Model/cvgMainSlave.hpp"
23 #endif
24
25 namespace felisce {
26 76 HeatModel::HeatModel():Model() {
27
1/2
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
76 m_name = "Heat";
28 76 }
29 // Called in Model::initializeLinearProblem, just after the mesh partitioning.
30 76 void HeatModel::initializeDerivedModel() {
31 // Saving the lpb pointer after the static cast
32 76 m_lpb = static_cast<LinearProblemHeat*>(m_linearProblem[0]);
33 // Initializing the PetscVectors
34 76 m_lpb->initPetscVectors();
35 76 }
36
37 76 void HeatModel::preAssemblingMatrixRHS(std::size_t /*iProblem*/) {
38 // Zero-ing the solution
39 76 m_lpb->solution().zeroEntries();
40 // Assembling the static part of the matrix.
41 76 m_lpb->assembleMatrixRHS(MpiInfo::rankProc(), FlagMatrixRHS::matrix_and_rhs);
42 76 }
43
44 2896 void HeatModel::prepareForward() {
45 // Write solution for postprocessing (if required)
46 2896 writeSolution();
47
48 // Advance time step.
49 2896 updateTime();
50 2896 m_lpb->updateOldQuantities();
51 // Print time information
52 2896 printNewTimeIterationBanner();
53 2896 }
54 2896 void HeatModel::solveHeat() {
55 //Apply boundary conditions.
56 2896 m_lpb->finalizeEssBCTransient();
57 #ifdef FELISCE_WITH_CVGRAPH
58
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 2896 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2896 times.
✗ Branch 9 not taken.
2896 if ( !FelisceParam::instance().withCVG || ! m_linearProblem[0]->slave()->redoTimeStepOnlyCVGData() ) {
59 2896 m_linearProblem[0]->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc());
60 } else {
61 m_linearProblem[0]->applyOnlyCVGBoundaryCondition();
62 }
63 #else
64 m_linearProblem[0]->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc());
65 #endif
66
67 //Solve linear system.
68 2896 m_lpb->solve(MpiInfo::rankProc(), MpiInfo::numProc());
69
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2896 times.
2896 if (FelisceParam::instance().withCVG ) {
71 m_linearProblem[0]->computeResidual();
72 }
73 2896 }
74 2896 void HeatModel::forward() {
75 2896 prepareForward();
76 //Assembly loop on elements.
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2896 times.
2896 if (FelisceParam::instance().hasMoveMesh) {
78 m_lpb->readDataDisplacement(m_ios, m_fstransient->iteration);
79 m_lpb->meshLocal()->moveMesh(m_lpb->Displacement(),1.0);
80 }
81
82 2896 m_lpb->assembleMatrixRHS(MpiInfo::rankProc(), FlagMatrixRHS::matrix_and_rhs);
83 2896 m_lpb->matrix(0).axpy(1,m_lpb->matrix(1),SAME_NONZERO_PATTERN);
84
85 2896 solveHeat();
86 2896 }
87
88
89 #ifdef FELISCE_WITH_CVGRAPH
90 void HeatModel::cvgraphNewTimeStep() {
91 prepareForward();
92
93 m_lpb->assembleMatrixRHS(MpiInfo::rankProc(), FlagMatrixRHS::matrix_and_rhs);
94 m_lpb->matrix(0).axpy(1,m_lpb->matrix(1),SAME_NONZERO_PATTERN);
95 m_lpb->createAndCopyMatrixRHSWithoutBC();
96 }
97 #endif
98
99 // State functions!
100 int HeatModel::getNstate() const {
101 return m_lpb->numDof();
102 }
103 void HeatModel::getState(double* & state) {
104 m_lpb->getSolution(state, MpiInfo::numProc(), MpiInfo::rankProc());
105 }
106 void HeatModel::getState_swig(double* data, felInt numDof) {
107 double * state;
108 m_lpb->getSolution(state, MpiInfo::numProc(), MpiInfo::rankProc());
109 for (felInt i=0 ; i<numDof ; i++) {
110 data[i] = state[i];
111 }
112 }
113 void HeatModel::setState(double* & state) {
114 m_lpb->setSolution(state, MpiInfo::numProc(), MpiInfo::rankProc());
115 }
116 }
117