Directory: | ./ |
---|---|
File: | Model/IOPcouplModel.cpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 182 | 224 | 81.2% |
Branches: | 232 | 558 | 41.6% |
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/IOPcouplModel.hpp" | ||
21 | #include "InputOutput/io.hpp" | ||
22 | |||
23 | namespace felisce { | ||
24 | // ====================================================================== | ||
25 | // the public methods | ||
26 | // ====================================================================== | ||
27 | |||
28 | // constructor: it first call constructor of mother class | ||
29 | 4 | IOPcouplModel::IOPcouplModel():NSSimplifiedFSIModel(),m_timeChecker(nullptr) { | |
30 | // change the name of the model | ||
31 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | m_name="Navier Stokes coupled with Perfect Fluid"; |
32 | // fixing the id of the perfect fluid problem | ||
33 | // this shuold be done automatically based on | ||
34 | // the names of the linearProblems or on | ||
35 | // same check on the type. | ||
36 | 4 | m_idPF=1; | |
37 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | m_interfaceLabels=FelisceParam::instance().labelIOPMesh; |
38 | 4 | } | |
39 | |||
40 | |||
41 | // this function override NSSimplifiedFSIModel::initializeDerivedModel() | ||
42 | // it is then call in initializeModel in the Model class | ||
43 | void | ||
44 | 4 | IOPcouplModel::initializeDerivedModel() { | |
45 | // first a call to the ovverriden method to initialize the mother class | ||
46 | 4 | NSSimplifiedFSIModel::initializeDerivedModel(); | |
47 | // Two static casts to initialize the pointers | ||
48 | // they are usufull to call functions defined in derived linear problems, | ||
49 | // but not declared in linearProblem class. | ||
50 | 4 | m_lpbNS = static_cast<LinearProblemNSSimplifiedFSI*> ( m_linearProblem[ m_idNSSimpl ]); | |
51 | 4 | m_lpbPF = static_cast<LinearProblemPerfectFluidRS*> ( m_linearProblem[ m_idPF ] ); | |
52 | // setting a flag in NS linProb to true to switch several functionalities on | ||
53 | 4 | m_lpbNS->coupled(true); | |
54 | |||
55 | // initialization of the boundary mappings | ||
56 | 4 | m_lpbNS->initializeDofBoundaryAndBD2VolMaps(); | |
57 | 4 | m_lpbPF->initializeDofBoundaryAndBD2VolMaps(); | |
58 | // We build the std::unordered_map the store the correspondence labels of the two meshes | ||
59 | // it needs to be called after the buildListOfBoundaryPetscDofs | ||
60 | 4 | this->defineMapLabelInterface(); | |
61 | |||
62 | // printing labels on the video to check everything is all right | ||
63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if ( FelisceParam::verbose() > 1 ) { |
64 | ✗ | std::stringstream labelsIOP, labelsNS; | |
65 | ✗ | labelsIOP<<"label IOP: "; | |
66 | ✗ | labelsNS <<"label NS : "; | |
67 | ✗ | for(auto it=m_labIOP2NS.begin(); it!=m_labIOP2NS.end(); ++it) { | |
68 | ✗ | labelsIOP<<it->first <<'\t'; | |
69 | ✗ | labelsNS <<it->second<<'\t'; | |
70 | } | ||
71 | ✗ | labelsIOP<<std::endl; | |
72 | ✗ | labelsNS <<std::endl; | |
73 | ✗ | PetscPrintf(MpiInfo::petscComm(), "%s",labelsNS.str().c_str()); | |
74 | ✗ | PetscPrintf(MpiInfo::petscComm(), "%s",labelsIOP.str().c_str()); | |
75 | } | ||
76 | |||
77 | 4 | m_scaleParam = FelisceParam::instance().porousParam; | |
78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if ( m_scaleParam <= 0) { |
79 | ✗ | double fluidDensity = 1.; | |
80 | ✗ | m_scaleParam = fluidDensity/FelisceParam::instance().timeStep; | |
81 | } | ||
82 | 4 | } | |
83 | |||
84 | // Function to initialize the std::unordered_map m_labIOP2NS | ||
85 | void | ||
86 | 4 | IOPcouplModel::defineMapLabelInterface() { | |
87 | //saving the std::unordered_map the associate the first point (in the lexicographical order) | ||
88 | //to each label | ||
89 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | std::map<int, Point > mapIOP = m_lpbPF->dofBD(/*iBD*/0).getMapLab2FirstPoint(); |
90 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | std::map<int, Point > mapNS = m_lpbNS->dofBD(/*iBD*/0).getMapLab2FirstPoint(); |
91 | |||
92 | // Checking that the number of labels from the surfaces are the same | ||
93 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | std::stringstream errLine; |
94 |
5/10✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
|
4 | errLine<<"different number of boundary labels describing the interface: "<<mapIOP.size()<< "!="<<mapNS.size()<<std::endl; |
95 |
1/10✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
4 | FEL_CHECK(mapIOP.size()==mapNS.size(),errLine.str().c_str()); |
96 | #ifndef NDEBUG | ||
97 | typedef std::map<int, std::vector< Point > > map_type; | ||
98 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | map_type allPointsPF = m_lpbPF->dofBD(/*iBD*/0).lab2AllPoints(); |
99 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | map_type allPointsNS = m_lpbNS->dofBD(/*iBD*/0).lab2AllPoints(); |
100 | 4 | int cFailed(0); | |
101 |
5/6✓ Branch 6 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
|
8 | for ( auto itPF = allPointsPF.begin(), itNS = allPointsNS.begin(); itPF != allPointsPF.end() && itNS != allPointsNS.end(); ++itPF, ++itNS ) { |
102 |
1/8✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
4 | FEL_CHECK(itPF->second.size()==itNS->second.size(), "different number of points at the interface"); |
103 |
5/6✓ Branch 9 taken 324 times.
✓ Branch 10 taken 4 times.
✓ Branch 14 taken 324 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 324 times.
✓ Branch 17 taken 4 times.
|
328 | for(auto itPPF = itPF->second.begin(), itPNS = itNS->second.begin(); itPPF != itPF->second.end() && itPNS != itNS->second.end(); ++itPPF, ++itPNS) { |
104 |
2/4✓ Branch 3 taken 324 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 324 times.
|
324 | if ( *itPPF != *itPNS ) { |
105 | //std::cout<<*itPPF<<'\t'<<*itPNS; | ||
106 | //std::cout<<" fail "<<std::endl; | ||
107 | ✗ | ++cFailed; | |
108 | } | ||
109 | // else { | ||
110 | // if ( FelisceParam::verbose() > 1 ) { | ||
111 | // std::cout<<*itPPF<<'\t'<<*itPNS; | ||
112 | // std::cout<<"\t ok "<<std::endl; | ||
113 | // } | ||
114 | // } | ||
115 | } | ||
116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if ( cFailed > 0 ) { |
117 | ✗ | std::stringstream aus; | |
118 | ✗ | aus<<"checking the interface: "<<cFailed<<" points differ, out of <<"<<itNS->second.size()<<std::endl; | |
119 | ✗ | FEL_ERROR(aus.str().c_str()); | |
120 | ✗ | } else { | |
121 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | std::cout<<"All right in the mapping: there is a one to one correspondance between all the nodes at the interface"<<std::endl; |
122 | } | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | //for each label of the IOP mesh interface | ||
127 |
2/2✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
|
8 | for(auto itIOP = mapIOP.begin(); itIOP != mapIOP.end(); ++itIOP) { |
128 | // we look for corresponding the label in the other mesh | ||
129 | 4 | bool Found=false; | |
130 | // for each label of the NS mesh | ||
131 |
5/6✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
|
8 | for(auto itNS = mapNS.begin(); itNS != mapNS.end() && !Found; ++itNS) { |
132 | // if the first point is the same for this couple of labels | ||
133 |
2/4✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
|
4 | if ( itIOP->second == itNS->second ) { |
134 | // then we found the corresponding label | ||
135 | 4 | Found=true; | |
136 | // we fill the std::unordered_map | ||
137 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | m_labIOP2NS [ itIOP->first ] = itNS->first; // <-- key line of the function |
138 | } | ||
139 | } | ||
140 | // if we arrived here and we did not find a label it means that ... | ||
141 |
1/8✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
4 | FEL_CHECK(Found," one label of the interface of the iop mesh is not present in the NS mesh"); |
142 | } | ||
143 | 4 | } | |
144 | |||
145 | |||
146 | // Forward function: | ||
147 | // it overrides NSSimplifiedFSI function, this time we really want to override | ||
148 | // and we are not going to call the forward method of the mother class inside | ||
149 | void | ||
150 | 12 | IOPcouplModel::forward() { | |
151 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 8 times.
|
12 | if ( m_fstransient->iteration == 0 ) { |
152 | 4 | m_timeChecker = felisce::make_shared<ChronoInstance>(); | |
153 | 4 | m_timeOnlyForIOP = felisce::make_shared<ChronoInstance>(); | |
154 | 4 | m_timeOnlyForNS = felisce::make_shared<ChronoInstance>(); | |
155 | |||
156 | 4 | m_lpbPF->initializePetscVectors(); | |
157 | } | ||
158 | 12 | m_timeChecker->start(); | |
159 | |||
160 | // We use the prepare forward of the NSModel | ||
161 | 12 | m_timeOnlyForNS->start(); | |
162 | 12 | this->prepareForward(); | |
163 | 12 | m_timeOnlyForNS->stop(); | |
164 | |||
165 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 8 times.
|
12 | if ( m_fstransient->iteration == 1 ) { |
166 | //! In the first time & fixed point iteration the P1 normal-field is exported from NS and read into PF | ||
167 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 4 times.
|
12 | for ( felInt iComp(0); iComp < m_lpbNS->dimension(); ++iComp ) { |
168 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | std::stringstream namevector; |
169 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | namevector << "normalVector" << iComp; |
170 |
4/8✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 13 not taken.
|
8 | m_lpbPF->readerInterface(m_lpbNS->dofBD(/*iBD*/0).listOfBoundaryPetscDofs(m_lpbNS->iUnknownVel(), iComp), |
171 | 8 | m_lpbNS->get(LinearProblemNSSimplifiedFSI::sequential,"normalField"), | |
172 | 8 | m_labIOP2NS, | |
173 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
16 | namevector.str() |
174 | ); | ||
175 | 8 | } | |
176 | 4 | m_lpbPF->exportNormalField(); | |
177 | } | ||
178 | // we initialize the flag to both matrix and rhs, however in navier-stokes I think only the advective part it is computed (if present) | ||
179 | 12 | FlagMatrixRHS flag=FlagMatrixRHS::matrix_and_rhs; | |
180 | |||
181 | // initialize the test quantity to one. | ||
182 | // and the corresponding tollerance from the data file | ||
183 | 12 | double testQuantity(1.0), toll(FelisceParam::instance().domainDecompositionToll); | |
184 | |||
185 | // this two integers store the current number of sub-iterations | ||
186 | // and of gmres iterations for the current time step | ||
187 | 12 | felInt cIteration(0), cGmresItNS(0), cGmresItPF(0); | |
188 | |||
189 | // subiteration of domain decomposition | ||
190 |
5/6✓ Branch 0 taken 152 times.
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 152 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 12 times.
|
164 | while ( testQuantity > toll && cIteration < FelisceParam::instance().domainDecompositionMaxIt) { |
191 | // update the it counter and display a nice banner | ||
192 | 152 | cIteration++; | |
193 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | this->displayBannerIterationInit(cIteration); |
194 | |||
195 | // solve the Navier Stokes problem without updating the structure | ||
196 | // the structure it is not updated because in the NSSimplifiedFSI class | ||
197 | // we refer, in the boudary condition, to the current displacement | ||
198 | // as the displacement available at that moment which is that one of the last time step. | ||
199 | // We also store the number of gmres iteration needed for that | ||
200 | 152 | m_timeOnlyForNS->start(); | |
201 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | this->solveNSSimplifiedFSI(flag); |
202 |
1/2✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
|
152 | m_timeOnlyForNS->stop(); |
203 |
1/2✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
|
152 | cGmresItNS += m_lpbNS->kspInterface().getNumOfIteration(); |
204 | |||
205 | // we update the normal velocity to the perfect fluid problem | ||
206 | // is going to be its neumann data | ||
207 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | m_lpbNS->updateNormalVelocityAndCurrentDisplacement(); |
208 | |||
209 | //! Comunication phase: PF reads several data coming from NS. | ||
210 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | PetscVector rescaledNormalVelocity; |
211 |
3/6✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | rescaledNormalVelocity.duplicateFrom(m_lpbNS->get(LinearProblemNSSimplifiedFSI::sequential,"normalVelocity")); |
212 |
3/6✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | rescaledNormalVelocity.copyFrom(m_lpbNS->get(LinearProblemNSSimplifiedFSI::sequential,"normalVelocity")); |
213 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | rescaledNormalVelocity.scale(m_scaleParam); |
214 | |||
215 |
3/6✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 152 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 152 times.
✗ Branch 10 not taken.
|
304 | m_lpbPF->readerInterface( m_lpbNS->dofBD(/*iBD*/0).listOfBoundaryPetscDofs(m_lpbNS->iUnknownPre(), /*icomp*/ 0 ), |
216 | rescaledNormalVelocity, | ||
217 | 152 | m_labIOP2NS, | |
218 | "velocityInterface"); | ||
219 | |||
220 | // this could be avoided in the case of simple fixed point iterations, | ||
221 | // but since we need the last available solution at interface for the relaxation | ||
222 | // and since we have changed with the acceleration.. | ||
223 |
5/10✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
✓ Branch 13 taken 152 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 152 times.
✗ Branch 17 not taken.
|
304 | m_lpbPF->readerInterface( m_lpbNS->dofBD(/*iBD*/0).listOfBoundaryPetscDofs(m_lpbNS->iUnknownPre(), /*icomp*/ 0), |
224 | 152 | m_lpbNS->get(LinearProblemNSSimplifiedFSI::sequential,"currentIop"), | |
225 | 152 | m_labIOP2NS, | |
226 | "currentIop" | ||
227 | ); | ||
228 | |||
229 | //! Solution phase | ||
230 | 152 | m_timeOnlyForIOP->start(); | |
231 |
8/10✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 152 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 68 times.
✓ Branch 7 taken 84 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 64 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 148 times.
|
152 | if ( FelisceParam::instance().computeSteklov && m_fstransient->iteration == 1 && cIteration == 1 ) { |
232 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
4 | if( FelisceParam::instance().useRoSteklov ) { |
233 | ✗ | int ivar = m_lpbPF->listVariable().getVariableIdList(iop); | |
234 | ✗ | int imesh = m_lpbPF->listVariable()[ivar].idMesh(); | |
235 | ✗ | m_lpbPF->assembleLowRankSteklov(imesh); | |
236 | ✗ | m_lpbPF->exportAllEig(imesh); | |
237 | } | ||
238 | else | ||
239 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | m_lpbPF->assembleFullRankSteklov(); |
240 | // in the function above the matrix is computed | ||
241 | 4 | flag = FlagMatrixRHS::only_rhs; | |
242 | // we clean the RHS: we are going to create a new one in solvePF | ||
243 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | m_lpbPF->clearMatrixRHS(flag); |
244 | } | ||
245 | //now that we have read the data we solve the perfect fluid problem | ||
246 | // and we store the number of gmres iteration needed for that | ||
247 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | this->solvePF(flag,cIteration); |
248 |
1/2✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
|
152 | m_timeOnlyForIOP->stop(); |
249 |
2/4✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 152 times.
|
152 | if ( ! FelisceParam::instance().computeSteklov ) |
250 | ✗ | cGmresItPF += m_lpbPF->kspInterface().getNumOfIteration(); | |
251 | |||
252 | // now we had to read the data from PF | ||
253 | // there is nothing to compute or to update like in NS | ||
254 | // it is enough to gather the solution | ||
255 | // because we simply read the iop at the interface | ||
256 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | m_lpbPF->gatherSolution(); |
257 | |||
258 | //! New Comunication phase | ||
259 |
3/6✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | m_lpbNS->accelerationPreStep(m_lpbNS->get(LinearProblem::sequential,"currentIop")); |
260 |
3/6✓ Branch 3 taken 152 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 152 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 152 times.
✗ Branch 10 not taken.
|
152 | m_lpbNS->readIOPInterface(m_lpbPF->dofBD(/*iBD*/0).listOfBoundaryPetscDofs(m_lpbPF->idUnknownIop() , /*icomp*/ 0 ), |
261 | 152 | m_lpbPF->sequentialSolution(), | |
262 | 152 | m_labIOP2NS, | |
263 |
2/4✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
|
152 | MpiInfo::rankProc()); |
264 | |||
265 | // we compute the test quantity which are the normalized norm of the increments | ||
266 | // of two quantities at the interface: | ||
267 | // - the normal velocity ( from NS to PF ) | ||
268 | // - the iop ( from PF to NS ) | ||
269 | //double testUN = m_lpbNS->computeL2Difference("normalVelocity","normalVelocityOld") / (m_lpbNS->computeL2Difference("normalVelocity") + 1e-12 ); | ||
270 | //double testIOP = m_lpbNS->computeL2Difference("currentIop","x1") / (m_lpbNS->computeL2Difference("currentIop") + 1e-12 ); | ||
271 | //testQuantity = testUN + testIOP; | ||
272 |
2/4✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
|
152 | std::pair<double, double> testQuantities=m_lpbNS->computeTestQuantities( FelisceParam::instance().lumpedTest ); |
273 | 152 | double testUN = testQuantities.first; | |
274 | 152 | double testIOP = testQuantities.second; | |
275 | 152 | testQuantity = testUN + testIOP; | |
276 |
3/6✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | m_lpbNS->accelerationPostStep(m_lpbNS->get(LinearProblem::sequential,"currentIop"),cIteration); |
277 | |||
278 | // now, for sure, we do not need to update the matrices for the other domain decomposition iterations | ||
279 | 152 | flag=FlagMatrixRHS::only_rhs; | |
280 | |||
281 | // we display a nice banner | ||
282 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | this->displayBannerIterationEnd(cIteration,testQuantity,testUN,testIOP); |
283 | |||
284 | // we clear only the RHS | ||
285 | // it is important to clear the rhs here, because otherwise you will sum into the previous one | ||
286 | // the former contribution | ||
287 | // of course we do not clear the matrix since we want to re-use it | ||
288 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | this->clearMatrixRHSOfPbs(flag); |
289 | 152 | } | |
290 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if ( cIteration == FelisceParam::instance().domainDecompositionMaxIt ) { |
291 | ✗ | std::stringstream war; | |
292 | ✗ | war<<"*************Maximum number of iterations reached in "<<__FILE__<<":"<<__LINE__<<std::endl; | |
293 | ✗ | FEL_WARNING(war.str().c_str()); | |
294 | } | ||
295 | //! we finalize the forward | ||
296 | 12 | this->finalizeForward(cIteration,cGmresItNS,cGmresItPF); | |
297 | 12 | m_timeChecker->stop(); | |
298 |
1/2✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
12 | m_cumulatedForwardTime.push_back(m_timeChecker->diff_cumul()); |
299 |
1/2✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
12 | m_cumulatedIOPTime.push_back(m_timeOnlyForIOP->diff_cumul()); |
300 |
1/2✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
12 | m_cumulatedNSTime.push_back(m_timeOnlyForNS->diff_cumul()); |
301 | 12 | writeTimeInfo(); | |
302 | 12 | } | |
303 | void | ||
304 | 12 | IOPcouplModel::writeTimeInfo() { | |
305 | |||
306 | // we convert the relaxation parameter into a std::string | ||
307 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | std::stringstream aus; |
308 |
2/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 | aus<<MpiInfo::rankProc(); |
309 | |||
310 | // we open a file in the folder before the result dir | ||
311 | // overwriting the previous content | ||
312 | // the information are described in the header prined here | ||
313 |
6/12✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 12 times.
✗ Branch 18 not taken.
|
24 | std::ofstream iterationFile( std::string(FelisceParam::instance().resultDir + "timeInfo"+aus.str()+".dat").c_str() , std::ios::trunc ); |
314 | iterationFile <<"TimeStep"<<'\t' | ||
315 | <<"fixedPointIterations"<<'\t' | ||
316 | <<"totalGmresIterationsNS"<<'\t' | ||
317 | <<"totalGmresIterationsPF"<<'\t' | ||
318 | <<"gmresIterationsPerFixedPointIt"<<'\t' | ||
319 | <<"cumulatedTime"<<'\t' | ||
320 | <<"onlyForIOP"<<'\t' | ||
321 |
15/30✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 12 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 12 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 12 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 12 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 12 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 12 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 12 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 12 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 12 times.
✗ Branch 44 not taken.
|
12 | <<"onlyForNS" |
322 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | <<std::endl; |
323 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 12 times.
|
36 | for ( std::size_t ts(0); ts<m_numFixedPointItPerTimeStep.size(); ++ts) { |
324 |
2/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
|
24 | iterationFile<<ts+1<<'\t' |
325 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | <<m_numFixedPointItPerTimeStep[ts]<<'\t' |
326 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | <<m_totNumOfGMRESItPerTimeStepNS[ts]<<'\t' |
327 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | <<m_totNumOfGMRESItPerTimeStepPF[ts]<<'\t' |
328 |
2/4✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 24 times.
✗ Branch 8 not taken.
|
24 | <<double(m_totNumOfGMRESItPerTimeStepNS[ts] + m_totNumOfGMRESItPerTimeStepPF[ts])/double(m_numFixedPointItPerTimeStep[ts])<<'\t' |
329 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | <<m_cumulatedForwardTime[ts]<<'\t' |
330 |
2/4✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | <<m_cumulatedIOPTime[ts]<<'\t' |
331 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | <<m_cumulatedNSTime[ts] |
332 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | <<std::endl; |
333 | } | ||
334 | //we close the file | ||
335 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | iterationFile.close(); |
336 | 12 | } | |
337 | // ====================================================================== | ||
338 | // now the privates methods | ||
339 | // ====================================================================== | ||
340 | |||
341 | // this function overrides | ||
342 | // NSSimplifiedFSIModel::finalizeForward(); | ||
343 | void | ||
344 | 12 | IOPcouplModel::finalizeForward(int cIteration, int cGmresItNS, int cGmresItPF) { | |
345 | // we call the function of the mother class | ||
346 | 12 | NSSimplifiedFSIModel::finalizeForward(); | |
347 | |||
348 | // the interface quantities of the NS problem are reset to zero | ||
349 | 12 | m_lpbNS->resetInterfaceQuantities(); | |
350 | 12 | m_lpbPF->resetInterfaceQuantities(); | |
351 | |||
352 | //first we store the new data | ||
353 | 12 | m_numFixedPointItPerTimeStep.push_back(cIteration); | |
354 | 12 | m_totNumOfGMRESItPerTimeStepNS.push_back(cGmresItNS); | |
355 | 12 | m_totNumOfGMRESItPerTimeStepPF.push_back(cGmresItPF); | |
356 | |||
357 | // in this part we export a file | ||
358 | // with the information about the sub-iteration | ||
359 | // and about the gmres iterations | ||
360 | // in order to have it even if the program is killed we re-write it all at each time step | ||
361 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 9 times.
|
12 | if ( MpiInfo::rankProc() == 0 ) { |
362 | // we convert the relaxation parameter into a std::string | ||
363 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | std::stringstream aus; |
364 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | aus<<FelisceParam::instance().relaxationParam; |
365 | |||
366 | // we open a file in the folder before the result dir | ||
367 | // overwriting the previous content | ||
368 | // the information are described in the header prined here | ||
369 |
6/12✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
|
6 | std::ofstream iterationFile( std::string(FelisceParam::instance().resultDir + "iterationsInfo"+aus.str()+".dat").c_str() , std::ios::trunc ); |
370 | iterationFile <<"TimeStep"<<'\t' | ||
371 | <<"fixedPointIterations"<<'\t' | ||
372 | <<"totalGmresIterationsNS"<<'\t' | ||
373 | <<"totalGmresIterationsPF"<<'\t' | ||
374 |
9/18✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 3 times.
✗ Branch 26 not taken.
|
3 | <<"gmresIterationsPerFixedPointIt" |
375 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | <<std::endl; |
376 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 3 times.
|
9 | for ( std::size_t ts(0); ts<m_numFixedPointItPerTimeStep.size(); ++ts) { |
377 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 | iterationFile<<ts+1<<'\t' |
378 |
2/4✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
6 | <<m_numFixedPointItPerTimeStep[ts]<<'\t' |
379 |
2/4✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
6 | <<m_totNumOfGMRESItPerTimeStepNS[ts]<<'\t' |
380 |
2/4✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
6 | <<m_totNumOfGMRESItPerTimeStepPF[ts]<<'\t' |
381 |
1/2✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 | <<double(m_totNumOfGMRESItPerTimeStepNS[ts] + m_totNumOfGMRESItPerTimeStepPF[ts])/double(m_numFixedPointItPerTimeStep[ts]) |
382 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | <<std::endl; |
383 | } | ||
384 | //we close the file | ||
385 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | iterationFile.close(); |
386 | 3 | } | |
387 | 12 | } | |
388 | |||
389 | // we reset the interface quantities of both problem | ||
390 | // typically we are going to use this function with | ||
391 | // flag = only-rhs | ||
392 | // but there is no default | ||
393 | void | ||
394 | 152 | IOPcouplModel::clearMatrixRHSOfPbs( FlagMatrixRHS flag) { | |
395 | 152 | m_linearProblem[m_idNSSimpl]->clearMatrixRHS(flag); | |
396 | 152 | m_lpbPF->clearMatrixRHS(flag); | |
397 | 152 | } | |
398 | |||
399 | // this function solve the PF problem | ||
400 | // we do not have a similar function for NS since it is in the mother class | ||
401 | void | ||
402 | 152 | IOPcouplModel::solvePF(FlagMatrixRHS flag, int nfp) { | |
403 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | if ( FelisceParam::instance().computeSteklov ) { |
404 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
|
152 | if ( FelisceParam::verbose() ) |
405 | ✗ | PetscPrintf(MpiInfo::petscComm(),"Perfect Fluid solved using Steklov operator\n"); | |
406 |
1/2✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
|
152 | m_lpbPF->solvePFUsingSteklov(m_fstransient, nfp); |
407 | } else { | ||
408 | ✗ | if ( FelisceParam::verbose() ) | |
409 | ✗ | PetscPrintf(MpiInfo::petscComm(),"Perfect Fluid \n"); | |
410 | ✗ | m_lpbPF->assembleMatrixRHS(MpiInfo::rankProc(), flag); | |
411 | ✗ | m_lpbPF->finalizeEssBCTransient(); | |
412 | ✗ | m_lpbPF->applyBC(FelisceParam::instance().essentialBoundaryConditionsMethod, MpiInfo::rankProc(), flag, flag); | |
413 | ✗ | m_lpbPF->solve(MpiInfo::rankProc(), MpiInfo::numProc()); | |
414 | ✗ | m_lpbPF->exportOutputSteklov(m_fstransient,nfp); | |
415 | ✗ | if ( FelisceParam::verbose() > 1) { | |
416 | ✗ | std::vector<double> meanPressure,meanIOP; | |
417 | ✗ | m_lpbNS->computeMeanQuantity(pressure, FelisceParam::instance().labelNSMesh, meanPressure); | |
418 | ✗ | m_lpbPF->computeMeanQuantity(iop, m_interfaceLabels, meanIOP); | |
419 | ✗ | std::stringstream msg; | |
420 | ✗ | for ( std::size_t cLab(0); cLab< m_interfaceLabels.size(); ++cLab) { | |
421 | ✗ | msg<<"meanIOP, label "<<m_interfaceLabels[cLab] <<", : "<<meanIOP[cLab]<<" -- "; | |
422 | ✗ | msg<<"meanPressure, label "<<FelisceParam::instance().labelNSMesh[cLab]<<", : "<<meanPressure[cLab]<<std::endl; | |
423 | } | ||
424 | ✗ | PetscPrintf(MpiInfo::petscComm(),"%s",msg.str().c_str()); | |
425 | } | ||
426 | } | ||
427 | 152 | } | |
428 | |||
429 | // two nice banners for the sub-iterations | ||
430 | void | ||
431 | 152 | IOPcouplModel::displayBannerIterationInit( felInt cIt ) const { | |
432 | |||
433 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | std::stringstream banner; |
434 |
2/2✓ Branch 0 taken 3800 times.
✓ Branch 1 taken 152 times.
|
3952 | for( felInt k(0); k<25; k++) |
435 |
1/2✓ Branch 1 taken 3800 times.
✗ Branch 2 not taken.
|
3800 | banner<<"="; |
436 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152 times.
✗ Branch 8 not taken.
|
152 | banner<<"> iteration "<<cIt<<std::endl; |
437 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | PetscPrintf(MpiInfo::petscComm(), "%s",banner.str().c_str()); |
438 | 152 | } | |
439 | void | ||
440 | 152 | IOPcouplModel::displayBannerIterationEnd( felInt /*cIt*/, double testQuantity, double testUN, double testIOP ) const { | |
441 | |||
442 |
1/2✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
|
152 | std::stringstream banner; |
443 |
2/2✓ Branch 0 taken 3800 times.
✓ Branch 1 taken 152 times.
|
3952 | for( felInt k(0); k<25; k++) |
444 |
1/2✓ Branch 1 taken 3800 times.
✗ Branch 2 not taken.
|
3800 | banner<<"="; |
445 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152 times.
✗ Branch 8 not taken.
|
152 | banner<<"> Test Quantity :"<<testQuantity<<std::endl; |
446 |
2/2✓ Branch 0 taken 3800 times.
✓ Branch 1 taken 152 times.
|
3952 | for( felInt k(0); k<25; k++) |
447 |
1/2✓ Branch 1 taken 3800 times.
✗ Branch 2 not taken.
|
3800 | banner<<" "; |
448 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152 times.
✗ Branch 8 not taken.
|
152 | banner<<" Normal Velocity :"<<testUN<<std::endl; |
449 |
2/2✓ Branch 0 taken 3800 times.
✓ Branch 1 taken 152 times.
|
3952 | for( felInt k(0); k<25; k++) |
450 |
1/2✓ Branch 1 taken 3800 times.
✗ Branch 2 not taken.
|
3800 | banner<<" "; |
451 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152 times.
✗ Branch 8 not taken.
|
152 | banner<<" Pressure at Interface :"<<testIOP<<std::endl; |
452 |
3/6✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 152 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 152 times.
✗ Branch 9 not taken.
|
152 | PetscPrintf(MpiInfo::petscComm(), "%s",banner.str().c_str()); |
453 | 152 | } | |
454 | } | ||
455 |