OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
linearstatic.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 "../sm/EngineeringModels/linearstatic.h"
36 #include "../sm/Elements/structuralelement.h"
37 #include "../sm/Elements/structuralelementevaluator.h"
38 #include "nummet.h"
39 #include "timestep.h"
40 #include "element.h"
41 #include "dof.h"
42 #include "sparsemtrx.h"
43 #include "verbose.h"
44 #include "classfactory.h"
45 #include "datastream.h"
46 #include "contextioerr.h"
47 #include "classfactory.h"
48 #include "unknownnumberingscheme.h"
49 
50 #ifdef __PARALLEL_MODE
51  #include "problemcomm.h"
52  #include "communicator.h"
53 #endif
54 
55 #include <typeinfo>
56 
57 namespace oofem {
58 REGISTER_EngngModel(LinearStatic);
59 
60 LinearStatic :: LinearStatic(int i, EngngModel *_master) : StructuralEngngModel(i, _master), loadVector(), displacementVector()
61 {
62  ndomains = 1;
63  initFlag = 1;
66 }
67 
68 
70  delete equationNumbering;
71 }
72 
73 
75 {
76  if ( !nMethod ) {
77  if ( isParallel() ) {
78  if ( ( solverType == ST_Petsc ) || ( solverType == ST_Feti ) ) {
79  nMethod.reset( classFactory.createSparseLinSolver(solverType, this->giveDomain(1), this) );
80  }
81  } else {
82  nMethod.reset( classFactory.createSparseLinSolver(solverType, this->giveDomain(1), this) );
83  }
84  if ( !nMethod ) {
85  OOFEM_ERROR("linear solver creation failed for lstype %d", solverType);
86  }
87  }
88 
89 
90  return nMethod.get();
91 }
92 
95 {
96  IRResultType result; // Required by IR_GIVE_FIELD macro
97 
99  if ( result != IRRT_OK ) {
100  return result;
101  }
102 
103  int val = 0;
105  solverType = ( LinSystSolverType ) val;
106 
107  val = 0;
109  sparseMtrxType = ( SparseMtrxType ) val;
110 
111 #ifdef __PARALLEL_MODE
112  if ( isParallel() ) {
114  communicator = new NodeCommunicator(this, commBuff, this->giveRank(),
115  this->giveNumberOfProcesses());
116  }
117 
118 #endif
119 
120 
121  return IRRT_OK;
122 }
123 
124 
126 // returns unknown quantity like displacement, velocity of equation eq
127 // This function translates this request to numerical method language
128 {
129  int eq = dof->__giveEquationNumber();
130 #ifdef DEBUG
131  if ( eq == 0 ) {
132  OOFEM_ERROR("invalid equation number");
133  }
134 #endif
135 
136  if ( tStep != this->giveCurrentStep() ) {
137  OOFEM_ERROR("unknown time step encountered");
138  return 0.;
139  }
140 
141  switch ( mode ) {
142  case VM_Total:
143  case VM_Incremental:
144  if ( displacementVector.isNotEmpty() ) {
145  return displacementVector.at(eq);
146  } else {
147  return 0.;
148  }
149 
150  default:
151  OOFEM_ERROR("Unknown is of undefined type for this problem");
152  }
153 
154  return 0.;
155 }
156 
157 
159 {
160  if ( !currentStep ) {
161  // first step -> generate initial step
162  //currentStep.reset( new TimeStep(*giveSolutionStepWhenIcApply()) );
163  currentStep.reset( new TimeStep(giveNumberOfTimeStepWhenIcApply(), this, 1, 0., 1., 0) );
164  }
165  previousStep = std :: move(currentStep);
166  currentStep.reset( new TimeStep(*previousStep, 1.) );
167 
168  return currentStep.get();
169 }
170 
171 
173 {
174  if ( this->isParallel() ) {
175 #ifdef __VERBOSE_PARALLEL
176  // force equation numbering before setting up comm maps
177  int neq = this->giveNumberOfDomainEquations(1, *this->giveEquationNumbering());
178  OOFEM_LOG_INFO("[process rank %d] neq is %d\n", this->giveRank(), neq);
179 #endif
180 
181  this->initializeCommMaps();
182  }
183 
185 }
186 
187 
188 
190 {
191  //
192  // creates system of governing eq's and solves them at given time step
193  //
194  // first assemble problem at current time step
195 
196  if ( initFlag ) {
197 #ifdef VERBOSE
198  OOFEM_LOG_DEBUG("Assembling stiffness matrix\n");
199 #endif
200 
201  //
202  // first step assemble stiffness Matrix
203  //
205  if ( !stiffnessMatrix ) {
206  OOFEM_ERROR("sparse matrix creation failed");
207  }
208 
209  stiffnessMatrix->buildInternalStructure( this, 1, *this->giveEquationNumbering() );
210 
211  this->assemble( *stiffnessMatrix, tStep, TangentAssembler(TangentStiffness),
212  *this->giveEquationNumbering(), this->giveDomain(1) );
213 
214  initFlag = 0;
215  }
216 
217 #ifdef VERBOSE
218  OOFEM_LOG_DEBUG("Assembling load\n");
219 #endif
220 
221  //
222  // allocate space for displacementVector
223  //
224  displacementVector.resize( this->giveNumberOfDomainEquations( 1, *this->giveEquationNumbering() ) ); // km?? replace EModelDefaultEquationNumbering() with this->giveEquationNumbering(). Use pointer?
226 
227  //
228  // assembling the load vector
229  //
231  loadVector.zero();
232  this->assembleVector( loadVector, tStep, ExternalForceAssembler(), VM_Total,
233  *this->giveEquationNumbering(), this->giveDomain(1) );
234 
235  //
236  // internal forces (from Dirichlet b.c's, or thermal expansion, etc.)
237  //
238  FloatArray internalForces( this->giveNumberOfDomainEquations( 1, *this->giveEquationNumbering() ) );
239  internalForces.zero();
240  this->assembleVector( internalForces, tStep, InternalForceAssembler(), VM_Total,
241  *this->giveEquationNumbering(), this->giveDomain(1) );
242 
243  loadVector.subtract(internalForces);
244 
246 
247  //
248  // set-up numerical model
249  //
250  this->giveNumericalMethod( this->giveMetaStep( tStep->giveMetaStepNumber() ) );
251 
252  //
253  // call numerical model to solve arose problem
254  //
255 #ifdef VERBOSE
256  OOFEM_LOG_INFO("\n\nSolving ...\n\n");
257 #endif
259  if ( !( s & NM_Success ) ) {
260  OOFEM_ERROR("No success in solving system.");
261  }
262 
263  tStep->incrementStateCounter(); // update solution state counter
264 }
265 
266 
268 {
269  contextIOResultType iores;
270 
271  if ( ( iores = StructuralEngngModel :: saveContext(stream, mode) ) != CIO_OK ) {
272  THROW_CIOERR(iores);
273  }
274 
275  if ( ( iores = displacementVector.storeYourself(stream) ) != CIO_OK ) {
276  THROW_CIOERR(iores);
277  }
278 
279  return CIO_OK;
280 }
281 
282 
284 {
285  contextIOResultType iores;
286 
287  if ( ( iores = StructuralEngngModel :: restoreContext(stream, mode) ) != CIO_OK ) {
288  THROW_CIOERR(iores);
289  }
290 
291  if ( ( iores = displacementVector.restoreYourself(stream) ) != CIO_OK ) {
292  THROW_CIOERR(iores);
293  }
294 
295  return CIO_OK;
296 }
297 
298 
299 void
301 {
303  this->giveNumericalMethod( this->giveCurrentMetaStep() )->setDomain( this->giveDomain(1) );
304 }
305 
306 
307 int
308 LinearStatic :: estimateMaxPackSize(IntArray &commMap, DataStream &buff, int packUnpackType)
309 {
310  int count = 0, pcount = 0;
311  Domain *domain = this->giveDomain(1);
312 
313  if ( packUnpackType == 0 ) {
314  for ( int map: commMap ) {
315  DofManager *dman = domain->giveDofManager( map );
316  for ( Dof *dof: *dman ) {
317  if ( dof->isPrimaryDof() && ( dof->__giveEquationNumber() ) ) {
318  count++;
319  } else {
320  pcount++;
321  }
322  }
323  }
324 
325  // --------------------------------------------------------------------------------
326  // only pcount is relevant here, since only prescribed components are exchanged !!!!
327  // --------------------------------------------------------------------------------
328 
329  return ( buff.givePackSizeOfDouble(1) * pcount );
330  } else if ( packUnpackType == 1 ) {
331  for ( int map: commMap ) {
332  count += domain->giveElement( map )->estimatePackSize(buff);
333  }
334 
335  return count;
336  }
337 
338  return 0;
339 }
340 
341 } // end namespace oofem
LinSystSolverType
The values of this type should be related not to specific solvers, but more to specific packages that...
LinSystSolverType solverType
Definition: linearstatic.h:70
The representation of EngngModel default unknown numbering.
void subtract(const FloatArray &src)
Subtracts array src to receiver.
Definition: floatarray.C:258
virtual TimeStep * giveNextStep()
Returns next time step (next to current step) of receiver.
Definition: linearstatic.C:158
#define NM_Success
Numerical method exited with success.
Definition: nmstatus.h:47
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description in input reader.
Definition: linearstatic.C:94
virtual double giveUnknownComponent(ValueModeType type, TimeStep *tStep, Domain *d, Dof *dof)
Returns requested unknown.
Definition: linearstatic.C:125
std::unique_ptr< TimeStep > currentStep
Current time step.
Definition: engngm.h:231
Class and object Domain.
Definition: domain.h:115
Implementation for assembling internal forces vectors in standard monolithic, nonlinear FE-problems...
virtual int giveNumberOfDomainEquations(int di, const UnknownNumberingScheme &num)
Returns number of equations for given domain in active (current time step) time step.
Definition: engngm.C:391
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description in input reader.
Definition: engngm.C:262
Class representing meta step.
Definition: metastep.h:62
SparseMtrx * createSparseMtrx(SparseMtrxType type)
Creates new instance of sparse matrix corresponding to given keyword.
Definition: classfactory.C:105
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
contextIOResultType storeYourself(DataStream &stream) const
Definition: floatarray.C:872
std::unique_ptr< TimeStep > previousStep
Previous time step.
Definition: engngm.h:233
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
MetaStep * giveMetaStep(int i)
Returns the i-th meta step.
Definition: engngm.C:1765
ValueModeType
Type representing the mode of UnknownType or CharType, or similar types.
Definition: valuemodetype.h:78
virtual void solveYourselfAt(TimeStep *tStep)
Solves problem for given time step.
Definition: linearstatic.C:189
virtual ~LinearStatic()
Definition: linearstatic.C:69
This base class is an abstraction for numerical algorithm.
Definition: nummet.h:80
Implementation for assembling tangent matrices in standard monolithic FE-problems.
bool isParallel() const
Returns true if receiver in parallel mode.
Definition: engngm.h:1056
void incrementStateCounter()
Updates solution state counter.
Definition: timestep.h:190
Base class for dof managers.
Definition: dofmanager.h:113
int giveNumberOfProcesses() const
Returns the number of collaborating processes.
Definition: engngm.h:1060
virtual void solveYourself()
Starts solution process.
Definition: engngm.C:501
virtual int __giveEquationNumber() const =0
Returns equation number of receiver, usually assigned by emodel.
LinearStatic(int i, EngngModel *_master=NULL)
Definition: linearstatic.C:60
REGISTER_EngngModel(ProblemSequence)
unsigned long NM_Status
Mask defining NumMetod Status; which can be asked after finishing computation by Numerical Method...
Definition: nmstatus.h:44
#define OOFEM_LOG_DEBUG(...)
Definition: logger.h:128
Class implementing an array of integers.
Definition: intarray.h:61
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode)
Stores the state of model to output stream.
Definition: linearstatic.C:267
FloatArray loadVector
Definition: linearstatic.h:67
virtual void assemble(SparseMtrx &answer, TimeStep *tStep, const MatrixAssembler &ma, const UnknownNumberingScheme &s, Domain *domain)
Assembles characteristic matrix of required type into given sparse matrix.
Definition: engngm.C:803
MetaStep * giveCurrentMetaStep()
Returns current meta step.
Definition: engngm.C:1684
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
std::unique_ptr< SparseLinearSystemNM > nMethod
Numerical method used to solve the problem.
Definition: linearstatic.h:73
#define _IFT_EngngModel_smtype
Definition: engngm.h:82
#define OOFEM_ERROR(...)
Definition: error.h:61
int ndomains
Number of receiver domains.
Definition: engngm.h:205
int updateSharedDofManagers(FloatArray &answer, const UnknownNumberingScheme &s, int ExchangeTag)
Exchanges necessary remote DofManagers data.
Definition: engngm.C:1957
SparseMtrxType
Enumerative type used to identify the sparse matrix type.
Implementation for assembling external forces vectors in standard monolithic FE-problems.
contextIOResultType restoreYourself(DataStream &stream)
Definition: floatarray.C:895
ProblemCommunicator * communicator
Communicator.
Definition: engngm.h:303
virtual void solveYourself()
Starts solution process.
Definition: linearstatic.C:172
CommunicatorBuff * commBuff
Common Communicator buffer.
Definition: engngm.h:301
SparseMtrxType sparseMtrxType
Definition: linearstatic.h:71
virtual void updateDomainLinks()
Updates domain links after the domains of receiver have changed.
Definition: linearstatic.C:300
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode)
Stores the state of model to output stream.
Definition: engngm.C:1527
Initializes the variable VERBOSE, in order to get a few intermediate messages on screen: beginning an...
Class representing vector of real numbers.
Definition: floatarray.h:82
int estimatePackSize(DataStream &buff)
Estimates the necessary pack size to hold all packed data of receiver.
Definition: element.C:1575
SparseLinearSystemNM * createSparseLinSolver(LinSystSolverType st, Domain *d, EngngModel *m)
Creates new instance of SparseLinearSystemNM corresponding to given type.
Definition: classfactory.C:120
#define _IFT_EngngModel_lstype
Definition: engngm.h:81
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
virtual int givePackSizeOfDouble(int count)=0
std::unique_ptr< SparseMtrx > stiffnessMatrix
Definition: linearstatic.h:66
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode)
Restores the state of model from output stream.
Definition: linearstatic.C:283
int giveMetaStepNumber()
Returns receiver&#39;s meta step number.
Definition: timestep.h:135
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
Definition: engngm.h:754
Class representing the general Input Record.
Definition: inputrecord.h:101
EModelDefaultEquationNumbering * equationNumbering
Definition: linearstatic.h:76
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
FloatArray displacementVector
Definition: linearstatic.h:68
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1)
Definition: engngm.h:1058
void initializeCommMaps(bool forceInit=false)
Definition: engngm.C:1942
ClassFactory & classFactory
Definition: classfactory.C:59
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
virtual int estimateMaxPackSize(IntArray &commMap, DataStream &buff, int packUnpackType)
Determines the space necessary for send/receive buffer.
Definition: linearstatic.C:308
This class implements extension of EngngModel for structural models.
The Communicator and corresponding buffers (represented by this class) are separated in order to allo...
Definition: communicator.h:60
virtual NumericalMethod * giveNumericalMethod(MetaStep *mStep)
Returns reference to receiver&#39;s numerical method.
Definition: linearstatic.C:74
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
virtual void setDomain(Domain *d)
Definition: nummet.h:114
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
virtual TimeStep * giveCurrentStep(bool force=false)
Returns current time step.
Definition: engngm.h:683
virtual UnknownNumberingScheme * giveEquationNumbering()
Definition: linearstatic.h:97
virtual void updateDomainLinks()
Updates domain links after the domains of receiver have changed.
Definition: engngm.C:1521
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode)
Restores the state of model from output stream.
Definition: engngm.C:1592
the oofem namespace is to define a context or scope in which all oofem names are defined.
bool isNotEmpty() const
Returns true if receiver is not empty.
Definition: floatarray.h:220
Domain * giveDomain(int n)
Service for accessing particular problem domain.
Definition: engngm.C:1720
Abstract class Dof represents Degree Of Freedom in finite element mesh.
Definition: dof.h:93
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
void assembleVector(FloatArray &answer, TimeStep *tStep, const VectorAssembler &va, ValueModeType mode, const UnknownNumberingScheme &s, Domain *domain, FloatArray *eNorms=NULL)
Assembles characteristic vector of required type from dofManagers, element, and active boundary condi...
Definition: engngm.C:986
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:29 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011