OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 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 "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 
47 namespace oofem {
48 MasterDof :: 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 
58 {
59  ic = bc = equationNumber = 0; // means "uninitialized"
60 }
61 
62 
64 {
65 }
66 
67 
69 // Returns the boundary condition the receiver is subjected to.
70 {
71  if ( 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  return NULL;
80 }
81 
82 
84 // Returns the number of the equation in the governing system of equations that corres-
85 // ponds to the receiver. The equationNumber is <0 if the receiver is
86 // subjected to a boundary condition and then the equationNumber is a Prescribed equation number
87 // or equationNumber >0.
88 
89 {
90  //if (!equationNumber)
91  // OOFEM_ERROR("Dof has undefined equationNumber");
92  return ( equationNumber > 0 ) ? equationNumber : 0;
93 }
94 
96 // Returns the number of the equation in the governing system of equations that corres-
97 // ponds to the receiver. The equationNumber is <0 if the receiver is
98 // subjected to a boundary condition and then the equationNumber is a Prescribed equation number
99 // or equationNumber >0.
100 {
101  //if (!equationNumber)
102  // OOFEM_ERROR("Dof has undefined equationNumber");
103  return ( equationNumber < 0 ) ? -1 * equationNumber : 0;
104 }
105 
107 // Returns the newly obtained number of the equation in the governing system
108 // of equations that corres-
109 // ponds to the receiver. The equation number is 0 if the receiver is
110 // subjected to a boundary condition, else it is n+1, where n is the
111 // equation number of the most recently numbered degree of freedom.
112 {
114 
116  equationNumber = 0;
117  return 0;
118  }
119 
120  if ( this->hasBc(tStep) ) {
122  } else {
124  }
125 
126  return equationNumber;
127 }
128 
129 
131 // Returns the initial condition on the receiver. Not used.
132 {
133  if ( ic ) {
134  return ( dofManager->giveDomain()->giveIc(ic) );
135  } else {
136  OOFEM_ERROR("does not know yet if has InitCond or not");
137  return NULL;
138  }
139 }
140 
141 
143 // The key method of class Dof. Returns the value of the unknown 'u'
144 // (e.g., the displacement) of the receiver, at tStep. This value may,
145 // or may not be already available. It may depend on a boundary (if it
146 // is not a predicted unknown) or initial condition. tStep is not the
147 // current time step n, it is assumed to be the previous one (n-1).
148 {
150  return 0.0;
151  }
152 #if 1
153  // first try if IC apply
154  if ( tStep->giveNumber() == dofManager->giveDomain()->giveEngngModel()->giveNumberOfTimeStepWhenIcApply() ) { // step when Ic apply
155  if ( this->hasIcOn(mode) ) {
156  return this->giveIc()->give(mode);
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 
183  return this->giveBcValue(mode, tStep);
184  }
185 #endif
186  return ( dofManager->giveDomain()->giveEngngModel()->
187  giveUnknownComponent(mode, tStep, dofManager->giveDomain(), this) );
188 }
189 
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 {
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  return this->giveIc()->give(mode);
202  } else {
203  return 0.;
204  }
205  }
206 
207  // then ask bor BC
208  if ( this->hasBc(tStep) ) { // bound . cond.
209  return this->giveBcValue(mode, tStep);
210  }
211 
212  // try ask field for unknown
213  return field.giveUnknownValue(this, mode, tStep);
214 }
215 
216 
218 // Returns True if the receiver is subjected to a boundary condition, else
219 // returns False. If necessary, reads the answer in the data file.
220 {
222  return true;
223  }
224 
225  if ( bc == -1 ) {
226  OOFEM_ERROR("does not know yet if has InitCond or not");
227  }
228 
229  if ( bc ) {
230  return this->dofManager->giveDomain()->giveBc(bc)->isImposed(tStep);
231  } else {
232  return false;
233  }
234 }
235 
236 
238 // Returns True if the receiver is subjected to an initial condition,
239 // else returns False.
240 {
241  if ( ic == -1 ) {
242  OOFEM_ERROR("does not know yet if has InitCond or not");
243  }
244 
245  return ic > 0;
246 }
247 
248 
250 // Returns True if the unknown 'u' (e.g., the displacement 'd') of the
251 // receiver is subjected to an initial condition, else returns False.
252 {
253  if ( this->hasIc() ) {
254  return this->giveIc()->hasConditionOn(u);
255  } else {
256  return false;
257  }
258 }
259 
261 {
262  return this->bc;
263 }
264 
266 {
267  return this->ic;
268 }
269 
271 // Updates the receiver at end of step.
272 {
273  Dof :: updateYourself(tStep);
274 }
275 
277 {
278  // Updates the receiver's unknown dictionary at end of step.
279  // to value dofValue.
280 
281  int hash = dofManager->giveDomain()->giveEngngModel()->giveUnknownDictHashIndx(mode, tStep);
282  unknowns.at(hash) = dofValue;
283 }
284 
286 {
287  int hash = dofManager->giveDomain()->giveEngngModel()->giveUnknownDictHashIndx(mode, tStep);
288  return unknowns.at(hash);
289 }
290 
292 {
293  printf( "dof %d of %s %d :\n", dofID, dofManager->giveClassName(), dofManager->giveNumber() );
294  printf("equation %d bc %d \n", equationNumber, bc);
295 }
296 
297 
299 //
300 // saves full node context (saves state variables, that completely describe
301 // current state)
302 //
303 {
304  contextIOResultType iores;
305 
306  if ( ( iores = Dof :: saveContext(stream, mode, obj) ) != CIO_OK ) {
307  THROW_CIOERR(iores);
308  }
309 
310  if ( mode & CM_Definition ) {
311  if ( !stream.write(bc) ) {
313  }
314 
315  if ( !stream.write(ic) ) {
317  }
318  }
319 
320  // store equation number of receiver
321  if ( !stream.write(equationNumber) ) {
323  }
324 
326  if ( ( iores = unknowns.saveContext(stream, mode, obj) ) != CIO_OK ) {
327  THROW_CIOERR(iores);
328  }
329  }
330 
331  return CIO_OK;
332 }
333 
334 
336 //
337 // restores full node context (saves state variables, that completely describe
338 // current state)
339 //
340 {
341  contextIOResultType iores;
342 
343  if ( ( iores = Dof :: restoreContext(stream, mode, obj) ) != CIO_OK ) {
344  THROW_CIOERR(iores);
345  }
346 
347  if ( mode & CM_Definition ) {
348  if ( !stream.read(bc) ) {
350  }
351 
352  if ( !stream.read(ic) ) {
354  }
355  }
356 
357 
358  // read equation number of receiver
359  if ( !stream.read(equationNumber) ) {
361  }
362 
364  if ( ( iores = unknowns.restoreContext(stream, mode, obj) ) != CIO_OK ) {
365  THROW_CIOERR(iores);
366  }
367  }
368 
369  return CIO_OK;
370 }
371 } // end namespace oofem
virtual bool isImposed(TimeStep *tStep)
Returns nonzero if receiver representing BC is imposed at given time, otherwise returns zero...
virtual void printYourself()
Prints the receiver state on stdout.
Definition: masterdof.C:291
DofManager in active domain is shared only by remote elements (these are only introduced for nonlocal...
Definition: dofmanager.h:88
Prescribed value.
Definition: bctype.h:42
int ic
Initial condition number associated to dof.
Definition: masterdof.h:100
InitialCondition * giveIc()
Returns initial condition of dof if it is prescribed.
Definition: masterdof.C:130
Class implementing general initial condition.
virtual int __giveEquationNumber() const
Returns equation number of receiver, usually assigned by emodel.
Definition: masterdof.C:83
InitialCondition * giveIc(int n)
Service for accessing particular domain ic.
Definition: domain.C:255
virtual int __givePrescribedEquationNumber()
Returns prescribed equation number of receiver.
Definition: masterdof.C:95
virtual int giveBcId()
Returns the id of associated boundary condition, if there is any.
Definition: masterdof.C:260
virtual double giveUnknownsDictionaryValue(TimeStep *tStep, ValueModeType mode)
Access dictionary value, if not present zero is returned.
Definition: masterdof.C:285
Abstract class representing field of primary variables (those, which are unknown and are typically as...
Definition: primaryfield.h:104
double & at(int aKey)
Returns the value of the pair which key is aKey.
Definition: dictionary.C:106
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
Definition: masterdof.C:335
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
ValueModeType
Type representing the mode of UnknownType or CharType, or similar types.
Definition: valuemodetype.h:78
virtual int requiresUnknownsDictionaryUpdate()
Indicates if EngngModel requires Dofs dictionaries to be updated.
Definition: engngm.h:845
Dictionary unknowns
Unknowns dictionary to support changes of static system.
Definition: masterdof.h:102
EngngModel * giveEngngModel()
Returns engineering model to which receiver is associated.
Definition: domain.C:433
contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Saves the receiver contends (state) to given stream.
Definition: dictionary.C:175
Base class for dof managers.
Definition: dofmanager.h:113
General IO error.
int giveNumber()
Returns domain number.
Definition: domain.h:266
virtual int giveNewPrescribedEquationNumber(int domain, DofIDItem)
Increases number of prescribed equations of receiver&#39;s domain and returns newly created equation numb...
Definition: engngm.h:777
virtual int askNewEquationNumber(TimeStep *tStep)
Asks EngngModel for new equation number.
Definition: masterdof.C:106
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
GeneralBoundaryCondition * giveBc(int n)
Service for accessing particular domain bc.
Definition: domain.C:243
virtual int write(const int *data, int count)=0
Writes count integer values from array pointed by data.
virtual int giveNewEquationNumber(int domain, DofIDItem)
Increases number of equations of receiver&#39;s domain and returns newly created equation number...
Definition: engngm.h:769
virtual double giveUnknown(ValueModeType mode, TimeStep *tStep)
The key method of class Dof.
Definition: masterdof.C:142
Class implementing Dirichlet boundary condition on DOF (primary boundary condition).
int giveNumber()
Returns receiver&#39;s number.
Definition: timestep.h:129
#define OOFEM_ERROR(...)
Definition: error.h:61
DofIDItem
Type representing particular dof type.
Definition: dofiditem.h:86
int hasConditionOn(int u)
Tests if receiver has initial condition for specific unknown-mode.
DofManager * dofManager
Link to related DofManager.
Definition: dof.h:97
virtual ~MasterDof()
Destructor.
Definition: masterdof.C:63
virtual void updateUnknownsDictionary(TimeStep *tStep, ValueModeType mode, double dofValue)
Abstract function, allowing Dof to store its unknowns in its own private dictionary.
Definition: masterdof.C:276
Abstract base class for all boundary conditions of problem.
MasterDof(DofManager *aNode, int nbc, int nic, DofIDItem id)
Constructor.
Definition: masterdof.C:48
virtual bool hasIcOn(ValueModeType)
Test if Dof has initial condition of required ValueModeType.
Definition: masterdof.C:249
double give(ValueModeType mode)
Returns value of initial condition for given unknown mode (determines whether total or velocity or ac...
int equationNumber
Corresponding equation number (positive value) or prescribed equation number (negative value)...
Definition: masterdof.h:96
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
Definition: masterdof.C:298
int bc
Boundary condition number associated to dof.
Definition: masterdof.h:98
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
Definition: dof.C:136
virtual const char * giveClassName() const =0
int giveNumberOfTimeStepWhenIcApply()
Returns the time step number, when initial conditions should apply.
Definition: engngm.h:754
DofIDItem dofID
Physical meaning of DOF.
Definition: dof.h:99
virtual int giveUnknownDictHashIndx(ValueModeType mode, TimeStep *tStep)
This method is responsible for computing unique dictionary id (ie hash value) from given valueModeTyp...
Definition: engngm.h:867
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
Definition: dof.C:148
virtual double giveBcValue(ValueModeType mode, TimeStep *tStep)
Returns value of boundary condition of dof if it is prescribed.
Definition: dof.C:120
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
#define CM_Definition
Definition: contextmode.h:47
virtual void updateYourself(TimeStep *tStep)
Updates receiver after finishing time step.
Definition: masterdof.C:270
virtual bool hasBc(TimeStep *tStep)
Test if Dof has active boundary condition.
Definition: masterdof.C:217
Domain * giveDomain() const
Definition: femcmpnn.h:100
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
virtual void updateYourself(TimeStep *tStep)
Updates receiver after finishing time step.
Definition: dof.h:336
the oofem namespace is to define a context or scope in which all oofem names are defined.
Abstract class Dof represents Degree Of Freedom in finite element mesh.
Definition: dof.h:93
int giveNumber() const
Definition: femcmpnn.h:107
contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver contents (state) from given stream.
Definition: dictionary.C:218
#define CM_UnknownDictState
Definition: contextmode.h:49
Class representing solution step.
Definition: timestep.h:80
virtual double giveUnknownValue(Dof *dof, ValueModeType mode, TimeStep *tStep)
Definition: primaryfield.C:319
dofManagerParallelMode giveParallelMode() const
Return dofManagerParallelMode of receiver.
Definition: dofmanager.h:512
BoundaryCondition * giveBc()
Returns boundary condition of dof if it is prescribed.
Definition: masterdof.C:68
virtual int giveIcId()
Returns the id of associated initial condition, if there is any.
Definition: masterdof.C:265
virtual bool hasIc()
Test if Dof has initial condition.
Definition: masterdof.C:237

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