OOFEM 3.0
Loading...
Searching...
No Matches
rvestokesflow.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
36#include "util.h"
37#include "oofemtxtdatareader.h"
39#include "engngm.h"
40#include "contextioerr.h"
41#include "gausspoint.h"
42#include "mathfem.h"
43#include "classfactory.h"
44
45#include <cstdio>
46#include <cstring>
47#include <sstream>
48
49#ifdef __FM_MODULE
50
51namespace oofem {
53
54int RVEStokesFlow :: n = 1;
55
56RVEStokesFlowMaterialStatus :: RVEStokesFlowMaterialStatus(int n, int rank, GaussPoint *g, const std :: string &inputfile) :
58{
59 OOFEM_LOG_INFO( "************************** Instanciating microproblem from file %s\n", inputfile.c_str() );
60 OOFEMTXTDataReader dr( inputfile.c_str() );
61
62 auto e = InstanciateProblem(dr, _processor, 0);
63 dr.finish();
64
65 if ( dynamic_cast< StokesFlowVelocityHomogenization* >(e.get()) ) {
66 this->rve.reset( dynamic_cast< StokesFlowVelocityHomogenization* >(e.release()) );
67 } else {
68 OOFEM_ERROR("Unexpected RVE engineering model");
69 }
70
71 std :: ostringstream name;
72 name << this->rve->giveOutputBaseFileName() << "-gp" << n;
73 if ( rank >= 0 ) {
74 name << "." << rank;
75 }
76 this->rve->letOutputBaseFileNameBe( name.str() );
77
78 this->rve->setProblemScale(microScale);
79 this->rve->checkProblemConsistency();
80 this->rve->initMetaStepAttributes( this->rve->giveMetaStep(1) );
81 this->rve->giveNextStep();
82 this->rve->init();
83
84 OOFEM_LOG_INFO("************************** Microproblem at %p instanciated \n", rve.get());
85}
86
87
88void RVEStokesFlowMaterialStatus :: setTimeStep(TimeStep *tStep)
89{
90 TimeStep *rveTStep = this->rve->giveCurrentStep();
91 rveTStep->setNumber( tStep->giveNumber() );
92 rveTStep->setTime( tStep->giveTargetTime() );
93 rveTStep->setTimeIncrement( tStep->giveTimeIncrement() );
94}
95
96void
97RVEStokesFlowMaterialStatus :: initTempStatus()
98{
99 TransportMaterialStatus :: initTempStatus();
100}
101
102void
103RVEStokesFlowMaterialStatus :: updateYourself(TimeStep *tStep)
104{
105 TransportMaterialStatus :: updateYourself(tStep);
107
108 this->rve->updateYourself(tStep);
109 this->rve->terminate(tStep);
110}
111
112
113void
114RVEStokesFlowMaterialStatus :: saveContext(DataStream &stream, ContextMode mode)
115{
116 TransportMaterialStatus :: saveContext(stream, mode);
117}
118
119
120void
121RVEStokesFlowMaterialStatus :: restoreContext(DataStream &stream, ContextMode mode)
122{
123 TransportMaterialStatus :: restoreContext(stream, mode);
124}
125
126
127RVEStokesFlow :: RVEStokesFlow(int n, Domain *d) : TransportMaterial(n, d)
128{ }
129
130
131void RVEStokesFlow :: initializeFrom(InputRecord &ir)
132{
134}
135
136
137int
138RVEStokesFlow :: giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
139{
140 auto status = static_cast< RVEStokesFlowMaterialStatus * >( this->giveStatus(gp) );
141 answer.clear();
142
143 switch ( type ) {
144 case IST_Velocity:
145 answer = status->giveFlux();
146 return 1;
147 case IST_PressureGradient:
148 answer = status->giveGradient();
149 return 1;
150 case IST_TangentNorm:
151 answer.resize(1);
152 answer.at(1) = frobeniusNorm(status->giveTangentMatrix());
153 return 1;
154 case IST_Tangent:
155 {
156 const auto &temp = status->giveTangentMatrix();
157 answer = {temp(0,0), temp(0,1), temp(0,2), temp(1,0), temp(1,1), temp(1,2), temp(2,0), temp(2,1), temp(2,2)};
158 return 1;
159 }
160 default:
161 return TransportMaterial :: giveIPValue(answer, gp, type, tStep);
162 }
163
164 // return 0;
165}
166
167
169RVEStokesFlow :: computeFlux3D(const FloatArrayF<3> &grad, double field, GaussPoint *gp, TimeStep *tStep) const
170{
171 OOFEM_LOG_DEBUG("\n****** Enter giveFluxVector ********************** Element number %u, Gauss point %u\n",
172 gp->giveElement()->giveGlobalNumber(), gp->giveNumber());
173
174 auto status = static_cast< RVEStokesFlowMaterialStatus * >( this->giveStatus(gp) );
175 auto rveE = status->giveRVE();
176
177 OOFEM_LOG_DEBUG( "Solve RVE problem for macroscale pressure gradient gradP=[%f, %f, %f]\n ", grad[0], grad[1], grad[2] );
178
179 // Compute seepage velocity
180 rveE->applyPressureGradient(grad);
181 status->setTimeStep(tStep);
182 rveE->solveYourselfAt(rveE->giveCurrentStep());
183 FloatArray answer;
184 rveE->computeSeepage(answer, tStep);
185 answer.resizeWithValues(3);
186
187 OOFEM_LOG_DEBUG( "Pressure gradient gradP=[%f %f] yields velocity vector [%f %f]\n", grad.at(1), grad.at(2), answer.at(1), answer.at(2) );
188
189 status->setTempGradient(grad);
190 status->setTempFlux(answer);
191 status->oldTangent = true;
192
193 OOFEM_LOG_DEBUG("****** Exit giveFluxVector **************************************** \n");
194 return answer;
195}
196
197
199RVEStokesFlow :: computeTangent3D(MatResponseMode mode, GaussPoint *gp, TimeStep *tStep) const
200{
201 OOFEM_LOG_DEBUG("\n****** Enter giveDeviatoricStiffnessMatrix **********************\n");
202
203 auto status = static_cast< RVEStokesFlowMaterialStatus * >( this->giveStatus(gp) );
204
205 if ( status->oldTangent ) {
206 // Compute tangent
207 FloatMatrix answer;
208 status->giveRVE()->computeTangent(answer, tStep);
209 answer.resizeWithData(3, 3);
210 #pragma GCC diagnostic push
211 // answer is possible uninitialized
212 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
213 status->letTempTangentMatrixBe(answer);
214 #pragma GCC diagnostic pop
215 status->oldTangent = false;
216 return answer;
217 } else {
218 return status->giveTempTangentMatrix();
219 }
220
221 OOFEM_LOG_DEBUG("****** Exit giveDeviatoricStiffnessMatrix **************************************** \n");
222}
223
224
225std::unique_ptr<MaterialStatus>
226RVEStokesFlow :: CreateStatus(GaussPoint *gp) const
227{
228 int rank = -1;
229 if ( this->domain->giveEngngModel()->isParallel() && this->domain->giveEngngModel()->giveNumberOfProcesses() > 1 ) {
230 rank = this->domain->giveEngngModel()->giveRank();
231 }
232 return std::make_unique<RVEStokesFlowMaterialStatus>(n++, rank, gp, this->rveFilename);
233}
234
235}
236#endif // ifdef __FM_MODULE
#define REGISTER_Material(class)
int giveGlobalNumber() const
Definition element.h:1129
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition femcmpnn.h:79
double & at(std::size_t i)
void resize(Index s)
Definition floatarray.C:94
double & at(Index i)
Definition floatarray.h:202
void resizeWithValues(Index s, std::size_t allocChunk=0)
Definition floatarray.C:103
void resizeWithData(Index, Index)
Definition floatmatrix.C:91
int giveNumber()
Returns number of receiver.
Definition gausspoint.h:183
Element * giveElement()
Returns corresponding element to receiver.
Definition gausspoint.h:187
virtual MaterialStatus * giveStatus(GaussPoint *gp) const
Definition material.C:206
FloatMatrixF< 3, 3 > temp_TangentMatrix
FloatMatrixF< 3, 3 > tangentMatrix
StokesFlowVelocityHomogenization * giveRVE()
std ::unique_ptr< StokesFlowVelocityHomogenization > rve
double giveTimeIncrement()
Returns solution step associated time increment.
Definition timestep.h:168
void setNumber(int i)
Set receiver's number.
Definition timestep.h:146
double giveTargetTime()
Returns target time.
Definition timestep.h:164
void setTimeIncrement(double newDt)
Sets solution step time increment.
Definition timestep.h:170
int giveNumber()
Returns receiver's number.
Definition timestep.h:144
void setTime(double newt)
Sets target and intrinsic time to be equal.
Definition timestep.h:172
TransportMaterial(int n, Domain *d)
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67
#define OOFEM_LOG_INFO(...)
Definition logger.h:143
#define OOFEM_LOG_DEBUG(...)
Definition logger.h:144
long ContextMode
Definition contextmode.h:43
double frobeniusNorm(const FloatMatrixF< N, N > &mat)
std::unique_ptr< EngngModel > InstanciateProblem(DataReader &dr, problemMode mode, int contextFlag, EngngModel *_master, bool parallelFlag)
Definition util.C:153
@ _processor
Definition problemmode.h:40
@ microScale
Definition problemmode.h:47
#define _IFT_RVEStokesFlow_fileName

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011