OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
fluidmaterialevaluator.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 - 2013 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 
35 #include "fluidmaterialevaluator.h"
36 #include "inputrecord.h"
37 #include "timestep.h"
38 #include "domain.h"
39 #include "gausspoint.h"
40 #include "fluiddynamicmaterial.h"
41 #include "function.h"
42 #include "classfactory.h"
43 
44 #include <fstream>
45 
46 namespace oofem {
47 REGISTER_EngngModel(FluidMaterialEvaluator);
48 
50 {
51  this->ndomains = 1;
52 }
53 
55 { }
56 
58 {
59  IRResultType result;
60 
61  this->deltaT = 1.0;
64 
66 
71 
73 
74  // Compute the strain control (everything not controlled by stress)
75  int components = ( ndim * ( ndim + 1 ) ) / 2;
76  for ( int i = 1; i <= components; ++i ) {
77  if ( !sControl.contains(i) ) {
79  }
80  }
81 
82  return IRRT_OK;
83 }
84 
85 
87 {
88  Domain *d = this->giveDomain(1);
89 
90 
91  MaterialMode mode;
92  if ( ndim == 1 ) {
93  OOFEM_ERROR("1d flow not supported (should be added)")
94  //mode = _1dFlow;
95  mode = _Unknown;
96  } else if ( ndim == 2 ) {
97  mode = _2dFlow;
98  } else {
99  mode = _3dFlow;
100  }
101 
102  int components = ( ndim * ( ndim + 1 ) ) / 2;
103  FloatArray initialStrain(components);
104  initialStrain.zero();
105  gps.clear();
106  gps.reserve(d->giveNumberOfMaterialModels());
107  for ( int i = 1; i <= d->giveNumberOfMaterialModels(); i++ ) {
108  std :: unique_ptr< GaussPoint > gp(new GaussPoint(nullptr, i, FloatArray(), 1, mode));
109  gps.emplace_back( std :: move(gp));
110  // Initialize the strain vector;
111  FluidDynamicMaterial *mat = static_cast< FluidDynamicMaterial * >( d->giveMaterial(i) );
112  FluidDynamicMaterialStatus *status = static_cast< FluidDynamicMaterialStatus * >( mat->giveStatus( &*gps[i-1] ) );
113  status->letDeviatoricStrainRateVectorBe(initialStrain);
114  }
115 
116  std :: string outname = this->giveOutputBaseFileName() + ".matdata";
117  this->outfile.open( outname.c_str() );
118 
120 
121  TimeStep *tStep = giveNextStep();
122 
123  // Note, strain == strain-rate (kept as strain for brevity)
124  int maxiter = 100; // User input?
125  double tolerance = 1.e-6; // Needs to be normalized somehow, or user input
126  double strainVol, pressure, strainVolC = 0.;
127  FloatArray stressDevC, deltaStrain, strainDev, stressDev, res;
128  stressDevC.resize( sControl.giveSize() );
129  res.resize( sControl.giveSize() );
130 
131  FloatMatrix tangent, reducedTangent;
132  FloatArray dsdp, dedd;
133  double dedp;
134  for ( int istep = 1; istep <= this->numberOfSteps; ++istep ) {
136  for ( int imat = 1; imat <= d->giveNumberOfMaterialModels(); ++imat ) {
137  GaussPoint *gp = &*gps[imat-1];
138  FluidDynamicMaterial *mat = static_cast< FluidDynamicMaterial * >( d->giveMaterial(imat) );
139  FluidDynamicMaterialStatus *status = static_cast< FluidDynamicMaterialStatus * >( mat->giveStatus(gp) );
140 
141  strainDev = status->giveDeviatoricStrainRateVector();
142  pressure = 0.;
143  // Update the controlled parts
144  for ( int j = 1; j <= eControl.giveSize(); ++j ) {
145  int p = eControl.at(j);
146  strainDev.at(p) = d->giveFunction( cmpntFunctions.at(p) )->evaluateAtTime( tStep->giveIntrinsicTime() );
147  }
148 
149  for ( int j = 1; j <= sControl.giveSize(); ++j ) {
150  int p = sControl.at(j);
151  stressDevC.at(j) = d->giveFunction( cmpntFunctions.at(p) )->evaluateAtTime( tStep->giveIntrinsicTime() );
152  }
153 
154  if ( pressureControl ) {
155  pressure = d->giveFunction(volFunction)->evaluateAtTime( tStep->giveIntrinsicTime() );
156  } else {
157  strainVolC = d->giveFunction(volFunction)->evaluateAtTime( tStep->giveIntrinsicTime() );
158  }
159 
160  for ( int iter = 1; iter < maxiter; iter++ ) {
161  mat->computeDeviatoricStressVector(stressDev, strainVol, gp, strainDev, pressure, tStep);
162  for ( int j = 1; j <= sControl.giveSize(); ++j ) {
163  res.at(j) = stressDevC.at(j) - stressDev.at( sControl.at(j) );
164  }
165  double resVol = 0.;
166  if ( !pressureControl ) {
167  resVol = strainVolC - strainVol;
168  }
169 
170  OOFEM_LOG_RELEVANT( "Time step: %d, Material %d, Iteration: %d, Residual = %e, Resvol = %e\n", istep, imat, iter, res.computeNorm(), resVol );
171  if ( res.computeNorm() <= tolerance && resVol <= tolerance ) {
172  break;
173  }
174 
175  mat->giveStiffnessMatrices(tangent, dsdp, dedd, dedp, TangentStiffness, gp, tStep);
176  if ( res.giveSize() > 0 ) {
177  // Add mean part to make it invertible
178  double norm = tangent.computeFrobeniusNorm();
179  for ( int i = 1; i <= this->ndim; ++i ) {
180  for ( int j = 1; j <= this->ndim; ++j ) {
181  tangent.at(i, j) += norm;
182  }
183  }
184 
185  // Pick out the stress-controlled part;
186  reducedTangent.beSubMatrixOf(tangent, sControl, sControl);
187 
188  // Update stress-controlled part of the strain
189  reducedTangent.solveForRhs(res, deltaStrain);
190  for ( int j = 1; j <= sControl.giveSize(); ++j ) {
191  strainDev.at( sControl.at(j) ) += deltaStrain.at(j);
192  }
193  }
194  if ( !pressureControl ) {
195  pressure -= resVol/dedp;
196  }
197  }
198 
199  if ( res.computeNorm() > tolerance ) {
200  OOFEM_WARNING("Residual did not converge!");
201  }
202 
203  // This material model has converged, so we update it and go on to the next.
204  gp->updateYourself(tStep);
205  }
206 
208  this->doStepOutput(tStep);
209  tStep = giveNextStep();
210  }
211 
213  this->outfile.close();
214 }
215 
217 {
218  Domain *d = this->giveDomain(1);
219  for ( int i = 1; i <= d->giveNumberOfMaterialModels(); i++ ) {
220  if ( !dynamic_cast< FluidDynamicMaterial * >( d->giveMaterial(i) ) ) {
221  return 0;
222  }
223  }
224 
226 }
227 
229 {
230  FloatArray outputValue;
231  Domain *d = this->giveDomain(1);
232  if ( tStep->isTheFirstStep() ) {
233  this->outfile << "# Time";
234  for ( int var: this->vars ) {
235  this->outfile << ", " << __InternalStateTypeToString( ( InternalStateType ) var );
236  }
237 
238  this->outfile << '\n';
239  }
240 
241  outfile << tStep->giveIntrinsicTime();
242  for ( int i = 1; i <= d->giveNumberOfMaterialModels(); i++ ) {
243  GaussPoint *gp = &*gps[i-1];
244  FluidDynamicMaterial *mat = static_cast< FluidDynamicMaterial * >( d->giveMaterial(i) );
245  for ( int j = 1; j <= this->vars.giveSize(); ++j ) {
246  mat->giveIPValue(outputValue, gp, ( InternalStateType ) this->vars.at(j), tStep);
247  outfile << " " << outputValue;
248  }
249  }
250 
251  outfile << std :: endl;
252 }
253 
255 {
256  if ( !currentStep ) {
257  // first step -> generate initial step
258  //currentStep.reset( new TimeStep(*giveSolutionStepWhenIcApply()) );
259  currentStep.reset( new TimeStep(giveNumberOfTimeStepWhenIcApply(), this, 1, 0., this->deltaT, 0) );
260  }
261  previousStep = std :: move(currentStep);
262  currentStep.reset( new TimeStep(*previousStep, this->deltaT) );
263 
264  return currentStep.get();
265 
266 }
267 } // end namespace oofem
bool contains(int value) const
Definition: intarray.h:283
EngngModelTimer timer
E-model timer.
Definition: engngm.h:267
InternalStateType
Type representing the physical meaning of element or constitutive model internal variable.
std::unique_ptr< TimeStep > currentStep
Current time step.
Definition: engngm.h:231
virtual MaterialStatus * giveStatus(GaussPoint *gp) const
Returns material status of receiver in given integration point.
Definition: material.C:244
std::string giveOutputBaseFileName()
Returns base output file name to which extensions, like .out .vtu .osf should be added.
Definition: engngm.h:363
Class and object Domain.
Definition: domain.h:115
IntArray sControl
Time function controlling the volumetric/pressure part.
virtual int checkConsistency()
Allows programmer to test some receiver&#39;s internal data, before computation begins.
Abstract base class for all fluid materials.
bool solveForRhs(const FloatArray &b, FloatArray &answer, bool transpose=false)
Solves the system of linear equations .
Definition: floatmatrix.C:1112
void startTimer(EngngModelTimerType t)
Definition: timer.h:128
const FloatArray & giveDeviatoricStrainRateVector()
std::unique_ptr< TimeStep > previousStep
Previous time step.
Definition: engngm.h:233
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
#define _IFT_FluidMaterialEvaluator_volFunction
Integer of time function for volumetric part.
void beSubMatrixOf(const FloatMatrix &src, int topRow, int bottomRow, int topCol, int bottomCol)
Assigns to the receiver the sub-matrix of another matrix.
Definition: floatmatrix.C:962
#define _IFT_FluidMaterialEvaluator_numberOfTimeSteps
void letDeviatoricStrainRateVectorBe(FloatArray v)
std::vector< std::unique_ptr< GaussPoint > > gps
void stopTimer(EngngModelTimerType t)
Definition: timer.h:129
MaterialMode
Type representing material mode of integration point.
Definition: materialmode.h:89
virtual void giveStiffnessMatrices(FloatMatrix &dsdd, FloatArray &dsdp, FloatArray &dedd, double &dedp, MatResponseMode mode, GaussPoint *gp, TimeStep *tStep)
Computes the 4 tangents of the compressible material response in 3D.
REGISTER_EngngModel(ProblemSequence)
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
#define _IFT_FluidMaterialEvaluator_pressureControl
Bool(Integer) determining if pressure or volumetric strain-rate is controlled.
#define _IFT_FluidMaterialEvaluator_componentFunctions
Integer list of time functions for each component.
#define _IFT_FluidMaterialEvaluator_stressControl
Integer list of the stress components which are controlled.
#define OOFEM_LOG_RELEVANT(...)
Definition: logger.h:126
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description in input reader.
bool isTheFirstStep()
Check if receiver is first step.
Definition: timestep.C:134
virtual void updateYourself(TimeStep *tStep)
Updates internal state of receiver after finishing time step.
Definition: gausspoint.C:141
This class implements a transport material status information.
virtual void computeDeviatoricStressVector(FloatArray &stress_dev, double &epsp_vol, GaussPoint *gp, const FloatArray &eps, double pressure, TimeStep *tStep)
Computes the deviatoric stress vector and volumetric strain rate from given deviatoric strain and pre...
Material * giveMaterial(int n)
Service for accessing particular domain material model.
Definition: domain.C:281
virtual TimeStep * giveNextStep()
Returns next time step (next to current step) of receiver.
#define OOFEM_ERROR(...)
Definition: error.h:61
int numberOfSteps
Total number of time steps.
Definition: engngm.h:209
int ndomains
Number of receiver domains.
Definition: engngm.h:205
int giveNumberOfMaterialModels() const
Returns number of material models in domain.
Definition: domain.h:436
#define _IFT_FluidMaterialEvaluator_nDimensions
Number of dimensions (2 or 3)
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
double giveIntrinsicTime()
Returns intrinsic time, e.g. time in which constitutive model is evaluated.
Definition: timestep.h:148
const double tolerance
Definition: expczmaterial.C:45
Function * giveFunction(int n)
Service for accessing particular domain load time function.
Definition: domain.C:268
virtual int giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
Returns the integration point corresponding value in Reduced form.
Class representing vector of real numbers.
Definition: floatarray.h:82
virtual void solveYourself()
Starts solution process.
virtual int checkConsistency()
Allows programmer to test some receiver&#39;s internal data, before computation begins.
Definition: engngm.h:995
virtual void doStepOutput(TimeStep *tStep)
Prints the ouput of the solution step (using virtual this->printOutputAtservice) to the stream detemi...
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
double computeFrobeniusNorm() const
Computes the Frobenius norm of the receiver.
Definition: floatmatrix.C:1613
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
double norm(const FloatArray &x)
Definition: floatarray.C:985
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
Definition: engngm.h:754
double computeNorm() const
Computes the norm (or length) of the vector.
Definition: floatarray.C:840
int volFunction
Time functions controlling each component of the deviatoric part of the stress.
Class representing the general Input Record.
Definition: inputrecord.h:101
#define _IFT_FluidMaterialEvaluator_deltat
void followedBy(const IntArray &b, int allocChunk=0)
Appends array b at the end of receiver.
Definition: intarray.C:145
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
#define _IFT_FluidMaterialEvaluator_outputVariables
Variables (from integration point) to be written.
FluidMaterialEvaluator(int i, EngngModel *_master=NULL)
const char * __InternalStateTypeToString(InternalStateType _value)
Definition: cltypes.C:298
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
Domain * giveDomain(int n)
Service for accessing particular problem domain.
Definition: engngm.C:1720
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
virtual double evaluateAtTime(double t)
Returns the value of the function at given time.
Definition: function.C:76
IntArray cmpntFunctions
Number of spatial dimensions.
Class representing integration point in finite element program.
Definition: gausspoint.h:93
#define OOFEM_WARNING(...)
Definition: error.h:62
Class representing solution step.
Definition: timestep.h:80
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011