OOFEM 3.0
Loading...
Searching...
No Matches
masterdof.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
35#include "masterdof.h"
36#include "dofmanager.h"
37#include "domain.h"
38#include "timestep.h"
39#include "boundarycondition.h"
40#include "initialcondition.h"
41#include "primaryfield.h"
42#include "dictionary.h"
43#include "datastream.h"
44#include "contextioerr.h"
45#include "engngm.h"
46
47namespace oofem {
48MasterDof :: MasterDof(DofManager *aNode, int nbc, int nic, DofIDItem id) : Dof(aNode, id)
49 // Constructor. Creates a new d.o.f., with number i, belonging
50 // to aNode with bc=nbc, ic=nic
51{
52 equationNumber = 0; // means "uninitialized"
53 bc = nbc;
54 ic = nic;
55}
56
57MasterDof :: MasterDof(DofManager *aNode, DofIDItem id) : Dof(aNode, id)
58{
59 ic = bc = equationNumber = 0; // means "uninitialized"
60}
61
62
63MasterDof :: ~MasterDof()
64{
65}
66
67
68BoundaryCondition *MasterDof :: giveBc()
69// Returns the boundary condition the receiver is subjected to.
70{
71 if ( bc ) {
72 GeneralBoundaryCondition *bcptr = dofManager->giveDomain()->giveBc(bc);
73 if ( bcptr->giveType() == DirichletBT ) {
74 return static_cast< BoundaryCondition * >(bcptr);
75 }
76 }
77
78 OOFEM_ERROR("Incompatible BC (%d) applied as Dirichlet/Primary BC", bc);
79}
80
81
82int MasterDof :: __giveEquationNumber() const
83// Returns the number of the equation in the governing system of equations that corres-
84// ponds to the receiver. The equationNumber is <0 if the receiver is
85// subjected to a boundary condition and then the equationNumber is a Prescribed equation number
86// or equationNumber >0.
87
88{
89 //if (!equationNumber)
90 // OOFEM_ERROR("Dof has undefined equationNumber");
91 return ( equationNumber > 0 ) ? equationNumber : 0;
92}
93
94int MasterDof :: __givePrescribedEquationNumber()
95// Returns the number of the equation in the governing system of equations that corres-
96// ponds to the receiver. The equationNumber is <0 if the receiver is
97// subjected to a boundary condition and then the equationNumber is a Prescribed equation number
98// or equationNumber >0.
99{
100 //if (!equationNumber)
101 // OOFEM_ERROR("Dof has undefined equationNumber");
102 return ( equationNumber < 0 ) ? -1 * equationNumber : 0;
103}
104
105int MasterDof :: askNewEquationNumber(TimeStep *tStep)
106// Returns the newly obtained number of the equation in the governing system
107// of equations that corres-
108// ponds to the receiver. The equation number is 0 if the receiver is
109// subjected to a boundary condition, else it is n+1, where n is the
110// equation number of the most recently numbered degree of freedom.
111{
112 EngngModel *model = dofManager->giveDomain()->giveEngngModel();
113
114 if ( dofManager->giveParallelMode() == DofManager_null ) {
115 equationNumber = 0;
116 return 0;
117 }
118
119 if ( this->hasBc(tStep) ) {
120 equationNumber = -1 * model->giveNewPrescribedEquationNumber(dofManager->giveDomain()->giveNumber(), this->dofID);
121 } else {
122 equationNumber = model->giveNewEquationNumber(dofManager->giveDomain()->giveNumber(), this->dofID);
123 }
124
125 return equationNumber;
126}
127
128
129InitialCondition *MasterDof :: giveIc()
130// Returns the initial condition on the receiver. Not used.
131{
132 if ( ic ) {
133 return ( dofManager->giveDomain()->giveIc(ic) );
134 } else {
135 OOFEM_ERROR("does not know yet if has InitCond or not");
136 }
137}
138
139
140double MasterDof :: giveUnknown(ValueModeType mode, TimeStep *tStep)
141// The key method of class Dof. Returns the value of the unknown 'u'
142// (e.g., the displacement) of the receiver, at tStep. This value may,
143// or may not be already available. It may depend on a boundary (if it
144// is not a predicted unknown) or initial condition. tStep is not the
145// current time step n, it is assumed to be the previous one (n-1).
146{
147 if ( dofManager->giveParallelMode() == DofManager_null ) {
148 return 0.0;
149 }
150
151 if ( (! dofManager->giveDomain()->giveEngngModel()->newDofHandling() ) && (mode!=VM_Residual)) {
152 // first try if IC apply
153 if ( tStep->giveNumber() == dofManager->giveDomain()->giveEngngModel()->giveNumberOfTimeStepWhenIcApply() ) { // step when Ic apply
154 if ( this->hasIcOn(mode) ) {
155 FloatArray c = this->dofManager->giveCoordinates();
156 return this->giveIc()->give(mode, c);
157 } else if ( this->hasBc(tStep) ) {
158 return this->giveBcValue(mode, tStep);
159 } else {
160 return 0.;
161 }
162 }
163
164 // if ( dofManager->giveDomain()->giveEngngModel()->requiresUnknownsDictionaryUpdate() ) {
165 // if this feature is active, engng model must ensure
166 // valid data in unknowns dictionary
167 // the e-model must ensure that bc and ic values are correctly set in unknowns dictionaries
168 // they could not be obtained from bc (which are typically incremental)
169 // directly since dictionaries keep the history.
170
171 // return ( dofManager->giveDomain()->giveEngngModel()->
172 // giveUnknownComponent(mode, tStep, dofManager->giveDomain(), this) );
173
174 // int hash = dofManager->giveDomain()->giveEngngModel()->giveUnknownDictHashIndx(mode, tStep);
175 // if ( unknowns->includes(hash) ) {
176 // return unknowns->at(hash);
177 // } else {
178 // OOFEM_ERROR(Dof unknowns dictionary does not contain unknown of value mode (%s)", __ValueModeTypeToString(mode));
179 // }
180 // }
181
182 if ( !dofManager->giveDomain()->giveEngngModel()->requiresUnknownsDictionaryUpdate() && this->hasBc(tStep) ) {
183 return this->giveBcValue(mode, tStep);
184 }
185 }
186 return ( dofManager->giveDomain()->giveEngngModel()->
187 giveUnknownComponent(mode, tStep, dofManager->giveDomain(), this) );
188}
189
190double MasterDof :: giveUnknown(PrimaryField &field, ValueModeType mode, TimeStep *tStep)
191// The key method of class Dof. Returns the value of the unknown field
192// (e.g., the displacement) associated to the receiver, at tStep.
193{
194 if ( dofManager->giveParallelMode() == DofManager_null ) {
195 return 0.0;
196 }
197
198 // first try if IC apply
199 if ( tStep->giveNumber() == dofManager->giveDomain()->giveEngngModel()->giveNumberOfTimeStepWhenIcApply() ) { // step when Ic apply
200 if ( this->hasIcOn(mode) ) {
201 FloatArray c = this->dofManager->giveCoordinates();
202 return this->giveIc()->give(mode, c);
203 } else {
204 return 0.;
205 }
206 }
207
208 // then ask bor BC
209 if ( this->hasBc(tStep) ) { // bound . cond.
210 return this->giveBcValue(mode, tStep);
211 }
212
213 // try ask field for unknown
214 return field.giveUnknownValue(this, mode, tStep);
215}
216
217
218bool MasterDof :: hasBc(TimeStep *tStep)
219// Returns True if the receiver is subjected to a boundary condition, else
220// returns False. If necessary, reads the answer in the data file.
221{
222 if ( dofManager->giveParallelMode() == DofManager_null ) {
223 return true;
224 }
225
226 if ( bc == -1 ) {
227 OOFEM_ERROR("does not know yet if has InitCond or not");
228 }
229
230 if ( bc ) {
231 return this->dofManager->giveDomain()->giveBc(bc)->isImposed(tStep);
232 } else {
233 return false;
234 }
235}
236
237
238bool MasterDof :: hasIc()
239// Returns True if the receiver is subjected to an initial condition,
240// else returns False.
241{
242 if ( ic == -1 ) {
243 OOFEM_ERROR("does not know yet if has InitCond or not");
244 }
245
246 return ic > 0;
247}
248
249
250bool MasterDof :: hasIcOn(ValueModeType u)
251// Returns True if the unknown 'u' (e.g., the displacement 'd') of the
252// receiver is subjected to an initial condition, else returns False.
253{
254 if ( this->hasIc() ) {
255 return this->giveIc()->hasConditionOn(u);
256 } else {
257 return false;
258 }
259}
260
261int MasterDof :: giveBcId()
262{
263 return this->bc;
264}
265
266int MasterDof :: giveIcId()
267{
268 return this->ic;
269}
270
271void MasterDof :: updateYourself(TimeStep *tStep)
272// Updates the receiver at end of step.
273{
274 Dof :: updateYourself(tStep);
275}
276
277void MasterDof :: updateUnknownsDictionary(TimeStep *tStep, ValueModeType mode, double dofValue)
278{
279 // Updates the receiver's unknown dictionary at end of step.
280 // to value dofValue.
281
282 int hash = dofManager->giveDomain()->giveEngngModel()->giveUnknownDictHashIndx(mode, tStep);
283 unknowns.at(hash) = dofValue;
284}
285
286double MasterDof :: giveUnknownsDictionaryValue(TimeStep *tStep, ValueModeType mode)
287{
288 int hash = dofManager->giveDomain()->giveEngngModel()->giveUnknownDictHashIndx(mode, tStep);
289 return unknowns.at(hash);
290}
291
292void MasterDof :: printYourself()
293{
294 printf( "dof %d of %s %d :\n", dofID, dofManager->giveClassName(), dofManager->giveNumber() );
295 printf("equation %d bc %d \n", equationNumber, bc);
296}
297
298
299void MasterDof :: saveContext(DataStream &stream, ContextMode mode)
300{
301 Dof :: saveContext(stream, mode);
302
303 if ( mode & CM_Definition ) {
304 if ( !stream.write(bc) ) {
306 }
307
308 if ( !stream.write(ic) ) {
310 }
311 }
312
313 // store equation number of receiver
314 if ( !stream.write(equationNumber) ) {
316 }
317
318 if ( ( mode & CM_UnknownDictState ) || ( dofManager->giveDomain()->giveEngngModel()->requiresUnknownsDictionaryUpdate() ) ) {
319 unknowns.saveContext(stream);
320 }
321}
322
323
324void MasterDof :: restoreContext(DataStream &stream, ContextMode mode)
325{
326 Dof :: restoreContext(stream, mode);
327
328 if ( mode & CM_Definition ) {
329 if ( !stream.read(bc) ) {
331 }
332
333 if ( !stream.read(ic) ) {
335 }
336 }
337
338
339 // read equation number of receiver
340 if ( !stream.read(equationNumber) ) {
342 }
343
344 if ( ( mode & CM_UnknownDictState ) || ( dofManager->giveDomain()->giveEngngModel()->requiresUnknownsDictionaryUpdate() ) ) {
345 unknowns.restoreContext(stream);
346 }
347}
348} // end namespace oofem
virtual int read(int *data, std::size_t count)=0
Reads count integer values into array pointed by data.
virtual int write(const int *data, std::size_t count)=0
Writes count integer values from array pointed by data.
DofIDItem dofID
Physical meaning of DOF.
Definition dof.h:99
Dof(DofManager *aNode, DofIDItem id=Undef)
Definition dof.C:50
virtual double giveBcValue(ValueModeType mode, TimeStep *tStep)
Definition dof.C:120
DofManager * dofManager
Link to related DofManager.
Definition dof.h:97
virtual int giveNewPrescribedEquationNumber(int domain, DofIDItem)
Definition engngm.h:821
virtual int giveNewEquationNumber(int domain, DofIDItem)
Definition engngm.h:813
InitialCondition * giveIc() override
Definition masterdof.C:129
bool hasIcOn(ValueModeType) override
Definition masterdof.C:250
int ic
Initial condition number associated to dof.
Definition masterdof.h:100
int bc
Boundary condition number associated to dof.
Definition masterdof.h:98
bool hasBc(TimeStep *tStep) override
Definition masterdof.C:218
Dictionary unknowns
Unknowns dictionary to support changes of static system.
Definition masterdof.h:102
bool hasIc() override
Definition masterdof.C:238
int equationNumber
Corresponding equation number (positive value) or prescribed equation number (negative value).
Definition masterdof.h:96
virtual double giveUnknownValue(Dof *dof, ValueModeType mode, TimeStep *tStep)
int giveNumber()
Returns receiver's number.
Definition timestep.h:144
#define THROW_CIOERR(e)
#define CM_UnknownDictState
Definition contextmode.h:49
#define CM_Definition
Definition contextmode.h:47
#define OOFEM_ERROR(...)
Definition error.h:79
long ContextMode
Definition contextmode.h:43
@ DofManager_null
Definition dofmanager.h:74
@ DirichletBT
Prescribed value.
Definition bctype.h:42
@ CIO_IOERR
General IO error.

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