OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
darcyflow.C
Go to the documentation of this file.
1 /*
2  * DarcyFlow.C
3  *
4  * Created on: Feb 25, 2010
5  * Author: carl
6  */
7 
8 #include "darcyflow.h"
9 #include "element.h"
10 #include "inputrecord.h"
11 #include "timestep.h"
12 #include "classfactory.h"
13 #include "sparselinsystemnm.h"
14 #include "mathfem.h"
15 #include "sparsemtrx.h"
16 #include "nrsolver.h"
17 #include "primaryfield.h"
18 #include "unknownnumberingscheme.h"
19 
20 #include <iostream>
21 #include <fstream>
22 #include <cstdio>
23 
24 namespace oofem {
25 REGISTER_EngngModel(DarcyFlow);
26 
27 DarcyFlow :: DarcyFlow(int i, EngngModel *_master) : EngngModel(i, _master)
28 {
29  this->ndomains = 1;
30  this->hasAdvanced = false;
31 }
32 
34 {
35 }
36 
38 {
39  IRResultType result; // Required by IR_GIVE_FIELD macro
40 
41  result = EngngModel :: initializeFrom(ir);
42  if ( result != IRRT_OK ) return result;
43 
44  int val = 0;
46  solverType = ( LinSystSolverType ) val;
47 
48  val = 0;
51 
52  // Create solution space for pressure field
53  PressureField.reset( new PrimaryField(this, 1, FT_Pressure, 1) );
54  return IRRT_OK;
55 }
56 
58 {
59  /*
60  * Assemble and solve system of equations as given timestep tStep.
61  *
62  */
63 
64  OOFEM_LOG_INFO("Parallelflag: %u\n", parallelFlag);
65 
66  FloatArray *solutionVector = NULL;
68 
69  // Move solution space to current timestep
70  if ( !hasAdvanced ) {
71  PressureField->advanceSolution(tStep);
72  hasAdvanced = true;
73  }
74 
75  // Point pointer SolutionVector to current solution in VelocityPressureField
76  solutionVector = PressureField->giveSolutionVector(tStep);
77  solutionVector->resize(neq);
78  solutionVector->zero();
79 
80  // Create "stiffness matrix"
81  if ( !this->stiffnessMatrix ) {
83  this->stiffnessMatrix->buildInternalStructure( this, 1, EModelDefaultEquationNumbering() );
84  }
85 
86 
87  // Build initial/external load (LoadVector)
88  this->externalForces.resize(neq);
89  this->externalForces.zero();
90  this->assembleVectorFromElements( this->externalForces, tStep, ExternalForceAssembler(), VM_Total,
93 
94  this->incrementOfSolution.resize(neq);
95  this->internalForces.resize(neq);
96 
98  double loadLevel;
100  this->updateComponent( tStep, InternalRhs, this->giveDomain(1) );
101  this->updateComponent( tStep, NonLinearLhs, this->giveDomain(1) );
102 
103  NM_Status status = this->nMethod->solve(*this->stiffnessMatrix,
104  this->externalForces,
105  NULL,
106  * solutionVector,
107  this->incrementOfSolution,
108  this->internalForces,
109  this->ebeNorm,
110  loadLevel, // Only relevant for incrementalBCLoadVector?
111  SparseNonLinearSystemNM :: rlm_total, // Why this naming scheme? Should be RLM_Total, and ReferenceLoadInputModeType
112  currentIterations,
113  tStep);
114 
115  if ( status & NM_NoSuccess ) {
116  OOFEM_ERROR("couldn't solve for time step %d\n", tStep->giveNumber() );
117  }
118 
119 #define DUMPMATRICES 0
120 #if DUMPMATRICES
121  FloatMatrix LHS_backup;
122  lhs->toFloatMatrix(LHS_backup);
123  DumpMatricesToFile(& LHS_backup, & rhs, NULL);
124 #endif
125 }
126 
127 
129 {
130  FILE *rhsFile = fopen("RHS.txt", "w");
131  // rhs.printYourself();
132 
133  for ( int i = 1; i <= RHS->giveSize(); i++ ) {
134  fprintf( rhsFile, "%0.15e\n", RHS->at(i) );
135  }
136  fclose(rhsFile);
137 
138  FILE *lhsFile = fopen("LHS.txt", "w");
139 
140  for ( int i = 1; i <= this->giveNumberOfDomainEquations( 1, EModelDefaultEquationNumbering() ); i++ ) {
141  for ( int j = 1; j <= this->giveNumberOfDomainEquations( 1, EModelDefaultEquationNumbering() ); j++ ) {
142  fprintf( lhsFile, "%0.15e\t", LHS->at(i, j) );
143  }
144  fprintf(lhsFile, "\n");
145  }
146 
147  fclose(lhsFile);
148 
149  if ( SolutionVector == NULL ) {
150  return;
151  }
152 
153  FILE *SolutionFile = fopen("SolutionVector.txt", "w");
154  for ( int i = 1; i <= SolutionVector->giveSize(); i++ ) {
155  fprintf( SolutionFile, "%0.15e\n", SolutionVector->at(i) );
156  }
157  fclose(SolutionFile);
158 }
159 
161 {
163 }
164 
166 {
167  return PressureField->giveUnknownValue(dof, mode, tStep);
168 }
169 
171 {
172  switch ( cmpn ) {
173  case InternalRhs:
174  this->internalForces.zero();
175  this->assembleVector(this->internalForces, tStep, InternalForceAssembler(), VM_Total,
178  break;
179 
180  case NonLinearLhs:
181 
182  this->stiffnessMatrix->zero();
183  this->assemble( *this->stiffnessMatrix, tStep, TangentAssembler(TangentStiffness),
185  break;
186 
187  default:
188  OOFEM_ERROR("Unknown component id (%d)", ( int ) cmpn);
189  }
190 }
191 
192 int DarcyFlow :: forceEquationNumbering(int id) // Is this really needed???!?
193 {
195 
196  this->equationNumberingCompleted = false;
197  this->stiffnessMatrix.reset(NULL);
198 
199  return neq;
200 }
201 
203 {
204  /*
205  * Returns pointer to NumericalMethod object. The solver used for StokesFlow is SparseLinearSystemNM.
206  * If no solver has bee initialized, create one, otherwise, return the existing solver.
207  */
208 
209  if ( !this->nMethod ) {
210  this->nMethod.reset( new NRSolver(this->giveDomain(1), this) );
211  if ( !nMethod ) {
212  OOFEM_ERROR("numerical method creation failed");
213  }
214  }
215 
216  return this->nMethod.get();
217 }
218 
220 {
221  if ( !currentStep ) {
222  // first step -> generate initial step
223  //currentStep.reset( new TimeStep(*giveSolutionStepWhenIcApply()) );
224  currentStep.reset( new TimeStep(giveNumberOfTimeStepWhenIcApply(), this, 1, 0., 1.0, 0) );
225  }
226  previousStep = std :: move(currentStep);
227  currentStep.reset( new TimeStep(*previousStep, 1.0) );
228 
229  return currentStep.get();
230 }
231 
232 }
LinSystSolverType
The values of this type should be related not to specific solvers, but more to specific packages that...
The representation of EngngModel default unknown numbering.
std::unique_ptr< TimeStep > currentStep
Current time step.
Definition: engngm.h:231
virtual NumericalMethod * giveNumericalMethod(MetaStep *mStep)
Returns reference to receiver&#39;s numerical method.
Definition: darcyflow.C:202
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
This class implements Newton-Raphson Method, derived from abstract NumericalMethod class for solving ...
Definition: nrsolver.h:95
SparseMtrx * createSparseMtrx(SparseMtrxType type)
Creates new instance of sparse matrix corresponding to given keyword.
Definition: classfactory.C:105
Abstract class representing field of primary variables (those, which are unknown and are typically as...
Definition: primaryfield.h:104
virtual TimeStep * giveNextStep()
Returns next time step (next to current step) of receiver.
Definition: darcyflow.C:219
std::unique_ptr< TimeStep > previousStep
Previous time step.
Definition: engngm.h:233
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
ValueModeType
Type representing the mode of UnknownType or CharType, or similar types.
Definition: valuemodetype.h:78
virtual double giveUnknownComponent(ValueModeType, TimeStep *, Domain *, Dof *)
Returns requested unknown.
Definition: darcyflow.C:165
virtual void updateComponent(TimeStep *tStep, NumericalCmpn cmpn, Domain *d)
Updates components mapped to numerical method if necessary during solution process.
Definition: darcyflow.C:170
This base class is an abstraction for numerical algorithm.
Definition: nummet.h:80
virtual ~DarcyFlow()
Definition: darcyflow.C:33
int currentIterations
Definition: darcyflow.h:45
Implementation for assembling tangent matrices in standard monolithic FE-problems.
FloatArray externalForces
Definition: darcyflow.h:42
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
virtual void solveYourselfAt(TimeStep *tStep)
Solves problem for given time step.
Definition: darcyflow.C:57
#define NM_NoSuccess
Numerical method failed to solve problem.
Definition: nmstatus.h:48
virtual void updateYourself(TimeStep *tStep)
Updates internal state after finishing time step.
Definition: darcyflow.C:160
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
int giveNumber()
Returns receiver&#39;s number.
Definition: timestep.h:129
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
NumericalCmpn
Type representing numerical component.
Definition: numericalcmpn.h:46
#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.
The reference incremental load vector is defined as totalLoadVector assembled at given time...
Implementation for assembling external forces vectors in standard monolithic FE-problems.
FloatArray internalForces
Definition: darcyflow.h:41
virtual void updateYourself(TimeStep *tStep)
Updates internal state after finishing time step.
Definition: engngm.C:612
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
std::unique_ptr< PrimaryField > PressureField
Definition: darcyflow.h:36
LinSystSolverType solverType
Definition: darcyflow.h:33
virtual int forceEquationNumbering()
Forces equation renumbering on all domains associated to engng model.
Definition: engngm.C:473
Class representing vector of real numbers.
Definition: floatarray.h:82
std::unique_ptr< SparseMtrx > stiffnessMatrix
Definition: darcyflow.h:40
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
#define _IFT_EngngModel_lstype
Definition: engngm.h:81
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
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
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description in input reader.
Definition: darcyflow.C:37
int parallelFlag
Flag indicating that the receiver runs in parallel.
Definition: engngm.h:269
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
ClassFactory & classFactory
Definition: classfactory.C:59
void assembleVectorFromElements(FloatArray &answer, TimeStep *tStep, const VectorAssembler &va, ValueModeType mode, const UnknownNumberingScheme &s, Domain *domain, FloatArray *eNorms=NULL)
Assembles characteristic vector of required type from elements into given vector. ...
Definition: engngm.C:1198
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
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
Abstract class Dof represents Degree Of Freedom in finite element mesh.
Definition: dof.h:93
void DumpMatricesToFile(FloatMatrix *LHS, FloatArray *RHS, FloatArray *SolutionVector)
Definition: darcyflow.C:128
FloatArray incrementOfSolution
Definition: darcyflow.h:43
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
SparseMtrxType sparseMtrxType
Definition: darcyflow.h:37
std::unique_ptr< SparseNonLinearSystemNM > nMethod
Definition: darcyflow.h:38
DarcyFlow(int i, EngngModel *_master)
Definition: darcyflow.C:27
FloatArray ebeNorm
Definition: darcyflow.h:46
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631
int equationNumberingCompleted
Equation numbering completed flag.
Definition: engngm.h:223

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