OOFEM 3.0
Loading...
Searching...
No Matches
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 - 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
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"
49
50#ifdef __MPI_PARALLEL_MODE
51 #include "problemcomm.h"
52 #include "communicator.h"
53#endif
54
55#include <typeinfo>
56
57namespace oofem {
59
60LinearStatic :: LinearStatic(int i, EngngModel *_master) : StructuralEngngModel(i, _master), loadVector(), displacementVector()
61{
62 ndomains = 1;
63 initFlag = 1;
65}
66
67
68LinearStatic :: ~LinearStatic() {}
69
70
71NumericalMethod *LinearStatic :: giveNumericalMethod(MetaStep *mStep)
72{
73 if ( !nMethod ) {
74 if ( isParallel() ) {
75 if ( ( solverType == ST_Petsc ) || ( solverType == ST_Feti ) ) {
76 nMethod = classFactory.createSparseLinSolver(solverType, this->giveDomain(1), this);
77 }
78 } else {
79 nMethod = classFactory.createSparseLinSolver(solverType, this->giveDomain(1), this);
80 }
81 if ( !nMethod ) {
82 OOFEM_ERROR("linear solver creation failed for lstype %d", solverType);
83 }
84 }
85
86
87 return nMethod.get();
88}
89
90void
91LinearStatic :: initializeFrom(InputRecord &ir)
92{
93 StructuralEngngModel :: initializeFrom(ir);
94
95 int val = 0;
98
99 val = 0;
102
103#ifdef __MPI_PARALLEL_MODE
104 if ( isParallel() ) {
106 communicator = new NodeCommunicator(this, commBuff, this->giveRank(),
107 this->giveNumberOfProcesses());
108 }
109
110#endif
111}
112
113
114double LinearStatic :: giveUnknownComponent(ValueModeType mode, TimeStep *tStep, Domain *d, Dof *dof)
115// returns unknown quantity like displacement, velocity of equation eq
116// This function translates this request to numerical method language
117{
118 int eq = dof->__giveEquationNumber();
119#ifdef DEBUG
120 if ( eq == 0 ) {
121 OOFEM_ERROR("invalid equation number");
122 }
123#endif
124
125 if ( tStep != this->giveCurrentStep() ) {
126 OOFEM_ERROR("unknown time step encountered");
127 }
128
129 switch ( mode ) {
130 case VM_Total:
131 case VM_Incremental:
132 if ( displacementVector.isNotEmpty() ) {
133 return displacementVector.at(eq);
134 } else {
135 return 0.;
136 }
137
138 default:
139 OOFEM_ERROR("Unknown is of undefined type for this problem");
140 }
141
142 return 0.;
143}
144
145
146TimeStep *LinearStatic :: giveNextStep()
147{
148 if ( !currentStep ) {
149 // first step -> generate initial step
150 //currentStep = std::make_unique<TimeStep>(*giveSolutionStepWhenIcApply());
151 currentStep = std::make_unique<TimeStep>(giveNumberOfTimeStepWhenIcApply(), this, 1, 0., 1., 0);
152 }
153 previousStep = std :: move(currentStep);
154 currentStep = std::make_unique<TimeStep>(*previousStep, 1.);
155
156 return currentStep.get();
157}
158
159
160void LinearStatic :: solveYourself()
161{
162 if ( this->isParallel() ) {
163#ifdef __VERBOSE_PARALLEL
164 // force equation numbering before setting up comm maps
165 int neq = this->giveNumberOfDomainEquations(1, this->giveEquationNumbering());
166 OOFEM_LOG_INFO("[process rank %d] neq is %d\n", this->giveRank(), neq);
167#endif
168
169 this->initializeCommMaps();
170 }
171
172 StructuralEngngModel :: solveYourself();
173}
174
175
176
177void LinearStatic :: solveYourselfAt(TimeStep *tStep)
178{
179 //
180 // creates system of governing eq's and solves them at given time step
181 //
182 // first assemble problem at current time step
183
184 if ( initFlag ) {
185#ifdef VERBOSE
186 OOFEM_LOG_DEBUG("Assembling stiffness matrix\n");
187#endif
188
189 //
190 // first step assemble stiffness Matrix
191 //
192 stiffnessMatrix = classFactory.createSparseMtrx(sparseMtrxType);
193 if ( !stiffnessMatrix ) {
194 OOFEM_ERROR("sparse matrix creation failed");
195 }
196
197 stiffnessMatrix->buildInternalStructure( this, 1, this->giveEquationNumbering() );
198
199 this->assemble( *stiffnessMatrix, tStep, TangentAssembler(TangentStiffness),
200 this->giveEquationNumbering(), this->giveDomain(1) );
201
202 initFlag = 0;
203 }
204
205#ifdef VERBOSE
206 OOFEM_LOG_DEBUG("Assembling load\n");
207#endif
208
209 //
210 // allocate space for displacementVector
211 //
212 displacementVector.resize( this->giveNumberOfDomainEquations( 1, this->giveEquationNumbering() ) ); // km?? replace EModelDefaultEquationNumbering() with this->giveEquationNumbering(). Use pointer?
213 displacementVector.zero();
214
215 //
216 // assembling the load vector
217 //
219 loadVector.zero();
220 this->assembleVector( loadVector, tStep, ExternalForceAssembler(), VM_Total,
221 this->giveEquationNumbering(), this->giveDomain(1) );
222
223 //
224 // internal forces (from Dirichlet b.c's, or thermal expansion, etc.)
225 //
226 FloatArray internalForces( this->giveNumberOfDomainEquations( 1, this->giveEquationNumbering() ) );
227 internalForces.zero();
228 this->assembleVector( internalForces, tStep, InternalForceAssembler(), VM_Total,
229 this->giveEquationNumbering(), this->giveDomain(1) );
230
231 loadVector.subtract(internalForces);
232
234
235 //
236 // set-up numerical model
237 //
238 this->giveNumericalMethod( this->giveMetaStep( tStep->giveMetaStepNumber() ) );
239
240 //
241 // call numerical model to solve arose problem
242 //
243#ifdef VERBOSE
244 OOFEM_LOG_INFO("\n\nSolving ...\n\n");
245#endif
247 if ( s != CR_CONVERGED ) {
248 OOFEM_ERROR("No success in solving system.");
249 }
250 tStep->numberOfIterations = 1;
251 tStep->convergedReason = s;
252 tStep->incrementStateCounter(); // update solution state counter
253}
254
255
256void LinearStatic :: saveContext(DataStream &stream, ContextMode mode)
257{
258 StructuralEngngModel :: saveContext(stream, mode);
259
261 if ( ( iores = displacementVector.storeYourself(stream) ) != CIO_OK ) {
262 THROW_CIOERR(iores);
263 }
264}
265
266
267void LinearStatic :: restoreContext(DataStream &stream, ContextMode mode)
268{
269 StructuralEngngModel :: restoreContext(stream, mode);
270
272 if ( ( iores = displacementVector.restoreYourself(stream) ) != CIO_OK ) {
273 THROW_CIOERR(iores);
274 }
275}
276
277
278void
279LinearStatic :: updateDomainLinks()
280{
281 EngngModel :: updateDomainLinks();
282 this->giveNumericalMethod( this->giveCurrentMetaStep() )->setDomain( this->giveDomain(1) );
283}
284
285
286int
287LinearStatic :: estimateMaxPackSize(IntArray &commMap, DataStream &buff, int packUnpackType)
288{
289 int count = 0, pcount = 0;
290 Domain *domain = this->giveDomain(1);
291
292 if ( packUnpackType == 0 ) {
293 for ( int map: commMap ) {
294 DofManager *dman = domain->giveDofManager( map );
295 for ( Dof *dof: *dman ) {
296 if ( dof->isPrimaryDof() && ( dof->__giveEquationNumber() ) ) {
297 count++;
298 } else {
299 pcount++;
300 }
301 }
302 }
303
304 // --------------------------------------------------------------------------------
305 // only pcount is relevant here, since only prescribed components are exchanged !!!!
306 // --------------------------------------------------------------------------------
307
308 return buff.givePackSizeOfDouble(1) * pcount;
309 } else if ( packUnpackType == 1 ) {
310 for ( int map: commMap ) {
311 count += domain->giveElement( map )->estimatePackSize(buff);
312 }
313
314 return count;
315 }
316
317 return 0;
318}
319
320} // end namespace oofem
#define REGISTER_EngngModel(class)
virtual int givePackSizeOfDouble(std::size_t count)=0
virtual int __giveEquationNumber() const =0
DofManager * giveDofManager(int n)
Definition domain.C:317
Element * giveElement(int n)
Definition domain.C:165
int estimatePackSize(DataStream &buff)
Definition element.C:1748
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
Definition engngm.h:787
void initializeCommMaps(bool forceInit=false)
Definition engngm.C:2147
virtual TimeStep * giveCurrentStep(bool force=false)
Definition engngm.h:717
virtual int giveNumberOfDomainEquations(int di, const UnknownNumberingScheme &num)
Definition engngm.C:452
int giveNumberOfProcesses() const
Returns the number of collaborating processes.
Definition engngm.h:1156
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1).
Definition engngm.h:1154
ProblemCommunicator * communicator
Communicator.
Definition engngm.h:315
std ::unique_ptr< TimeStep > previousStep
Previous time step.
Definition engngm.h:243
MetaStep * giveCurrentMetaStep()
Returns current meta step.
Definition engngm.C:1900
int ndomains
Number of receiver domains.
Definition engngm.h:215
Domain * giveDomain(int n)
Definition engngm.C:1936
std ::unique_ptr< TimeStep > currentStep
Current time step.
Definition engngm.h:241
MetaStep * giveMetaStep(int i)
Returns the i-th meta step.
Definition engngm.h:773
CommunicatorBuff * commBuff
Common Communicator buffer.
Definition engngm.h:313
bool isParallel() const
Returns true if receiver in parallel mode.
Definition engngm.h:1152
int updateSharedDofManagers(FloatArray &answer, const UnknownNumberingScheme &s, int ExchangeTag)
Definition engngm.C:2162
void assembleVector(FloatArray &answer, TimeStep *tStep, const VectorAssembler &va, ValueModeType mode, const UnknownNumberingScheme &s, Domain *domain, FloatArray *eNorms=NULL)
Definition engngm.C:1106
void zero()
Zeroes all coefficients of receiver.
Definition floatarray.C:683
SparseMtrxType sparseMtrxType
LinSystSolverType solverType
FloatArray displacementVector
virtual UnknownNumberingScheme & giveEquationNumbering()
NumericalMethod * giveNumericalMethod(MetaStep *mStep) override
Returns reference to receiver's numerical method.
FloatArray loadVector
std ::unique_ptr< SparseMtrx > stiffnessMatrix
std ::unique_ptr< SparseLinearSystemNM > nMethod
Numerical method used to solve the problem.
StructuralEngngModel(int i, EngngModel *master=nullptr)
Creates new StructuralEngngModel with number i, associated to domain d.
int giveMetaStepNumber()
Returns receiver's meta step number.
Definition timestep.h:150
void incrementStateCounter()
Updates solution state counter.
Definition timestep.h:213
ConvergedReason convergedReason
Status of solution step (Converged,.
Definition timestep.h:120
int numberOfIterations
Number of itarations needed to achieve convergence.
Definition timestep.h:116
#define THROW_CIOERR(e)
#define _IFT_EngngModel_lstype
Definition engngm.h:91
#define _IFT_EngngModel_smtype
Definition engngm.h:92
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define OOFEM_LOG_INFO(...)
Definition logger.h:143
#define OOFEM_LOG_DEBUG(...)
Definition logger.h:144
long ContextMode
Definition contextmode.h:43
FloatArrayF< N > assemble(const FloatArrayF< M > &x, int const (&c)[M])
Assemble components into zero matrix.
ClassFactory & classFactory

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