OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
dofdistributedprimaryfield.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 
36 #include "dofmanager.h"
37 #include "dof.h"
38 #include "domain.h"
39 #include "timestep.h"
40 #include "floatarray.h"
41 #include "engngm.h"
42 #include "set.h"
43 #include "boundarycondition.h"
44 #include "initialcondition.h"
45 #include "element.h"
46 #include "activebc.h"
47 
48 
49 namespace oofem {
51  FieldType ft, int nHist) :
52  PrimaryField(a, idomain, ft, nHist)
53 { }
54 
56 { }
57 
58 double
60 {
61  if ( mode == VM_Total ) {
62  return dof->giveUnknownsDictionaryValue(tStep, mode);
63  } else {
64  double val1 = dof->giveUnknownsDictionaryValue(tStep, VM_Total);
65  double val0 = dof->giveUnknownsDictionaryValue(tStep->givePreviousStep(), VM_Total);
66  if ( mode == VM_Velocity ) {
67  return (val1 - val0) / tStep->giveTimeIncrement();
68  } else if ( mode == VM_Incremental ) {
69  return val1 - val0;
70  } else {
71  OOFEM_ERROR("Unknown value mode requested");
72  return 0;
73  }
74  }
75 
76  return 0.;
77 }
78 
79 FloatArray *
81 {
82  //OOFEM_ERROR("This function should not be called. initialize and update should be used instead");
84 }
85 
86 void
88 {
91 
92  answer.resize(neq);
93  answer.zero();
94 
95  for ( auto &node : d->giveDofManagers() ) {
96  for ( Dof *dof: *node ) {
97  if ( !dof->isPrimaryDof() ) continue;
98  int eqNum = dof->giveEquationNumber(s);
99  if ( eqNum ) {
100  answer.at(eqNum) = dof->giveUnknownsDictionaryValue(tStep, mode);
101  }
102  }
103  }
104 
105  for ( auto &elem : d->giveElements() ) {
106  int ndman = elem->giveNumberOfInternalDofManagers();
107  for ( int i = 1; i <= ndman; i++ ) {
108  for ( auto &dof : *elem->giveInternalDofManager(i) ) {
109  if ( !dof->isPrimaryDof() ) continue;
110  int eqNum = dof->giveEquationNumber(s);
111  if ( eqNum > 0 ) {
112  answer.at(eqNum) = dof->giveUnknownsDictionaryValue(tStep, mode);
113  }
114  }
115  }
116  }
117 
118  for ( auto &bc : d->giveBcs() ) {
119  int ndman = bc->giveNumberOfInternalDofManagers();
120  for ( int i = 1; i <= ndman; i++ ) {
121  for ( auto &dof : *bc->giveInternalDofManager(i) ) {
122  if ( !dof->isPrimaryDof() ) continue;
123  int eqNum = dof->giveEquationNumber(s);
124  if ( eqNum > 0 ) {
125  answer.at(eqNum) = dof->giveUnknownsDictionaryValue(tStep, mode);
126  }
127  }
128  }
129  }
130 }
131 
132 // project solutionVector to DoF unknowns dictionary
133 void
135 {
137 
138  for ( auto &node : d->giveDofManagers() ) {
139  for ( Dof *dof: *node ) {
140  if ( !dof->isPrimaryDof() ) continue;
141  int eqNum = dof->giveEquationNumber(s);
142  if ( eqNum > 0 ) {
143  dof->updateUnknownsDictionary(tStep, mode, vectorToStore.at(eqNum));
144  }
146  if ( mode == VM_Total ) {
147  if ( dof->hasBc(tStep) ) {
148  dof->updateUnknownsDictionary(tStep, mode, dof->giveBcValue(VM_Total, tStep));
149  }
150  }
151  }
152  }
153 
154  for ( auto &elem : d->giveElements() ) {
155  int ndman = elem->giveNumberOfInternalDofManagers();
156  for ( int i = 1; i <= ndman; i++ ) {
157  for ( auto &dof : *elem->giveInternalDofManager(i) ) {
158  if ( !dof->isPrimaryDof() ) continue;
159  int eqNum = dof->giveEquationNumber(s);
160  if ( eqNum > 0 ) {
161  dof->updateUnknownsDictionary(tStep, mode, vectorToStore.at(eqNum));
162  }
163  }
164  }
165  }
166 
167  for ( auto &bc : d->giveBcs() ) {
168  int ndman = bc->giveNumberOfInternalDofManagers();
169  for ( int i = 1; i <= ndman; i++ ) {
170  for ( auto &dof : *bc->giveInternalDofManager(i) ) {
171  if ( !dof->isPrimaryDof() ) continue;
172  int eqNum = dof->giveEquationNumber(s);
173  if ( eqNum > 0 ) {
174  dof->updateUnknownsDictionary(tStep, mode, vectorToStore.at(eqNum));
175  }
176  }
177  }
178  }
179 }
180 
181 
182 void
184 {
187  // Copy over the old dictionary values to the new step as the initial guess:
188  for ( auto &dman : d->giveDofManagers() ) {
189  if ( dman->isNull() ) continue;
190  for ( auto &dof : *dman ) {
191  dof->updateUnknownsDictionary(tStep, VM_Total, 0.);
192  int icid = dof->giveIcId();
193  if ( icid > 0 && dof->isPrimaryDof() ) {
194  InitialCondition *ic = d->giveIc(icid);
195  if ( ic->hasConditionOn(VM_Total) ) {
196  double val = ic->give(VM_Total);
197  dof->updateUnknownsDictionary(tStep, VM_Total, val);
198  }
199  }
200  }
201  }
202 
203  for ( auto &elem : d->giveElements() ) {
204  if ( elem->giveParallelMode() == Element_remote ) continue;
205  int ndman = elem->giveNumberOfInternalDofManagers();
206  for ( int i = 1; i <= ndman; i++ ) {
207  for ( auto &dof : *elem->giveInternalDofManager(i) ) {
208  dof->updateUnknownsDictionary(tStep, VM_Total, 0.);
209  }
210  }
211  }
212 
213  for ( auto &bc : d->giveBcs() ) {
214  int ndman = bc->giveNumberOfInternalDofManagers();
215  for ( int i = 1; i <= ndman; i++ ) {
216  if ( bc->giveInternalDofManager(i)->isNull() ) continue;
217  for ( auto &dof : *bc->giveInternalDofManager(i) ) {
218  dof->updateUnknownsDictionary(tStep, VM_Total, 0.);
219  }
220  }
221  }
222 
223  // Apply ICs that use sets.
224  for ( auto &ic : d->giveIcs() ) {
225  this->applyInitialCondition(*ic);
226  }
227 }
228 
229 void
231 {
232  if ( ic.giveSetNumber() == 0 ) {
233  return;
234  }
235 
236  Domain *d = ic.giveDomain();
237  Set *set = d->giveSet(ic.giveSetNumber());
239  //TimeStep *prev = tStep->givePreviousStep();
240 
241  // We have to set initial value, and velocity, for this particular primary field.
242  for ( int inode : set->giveNodeList() ) {
243  DofManager *dman = d->giveDofManager(inode);
244  if ( dman->isNull() ) continue;
245  double tot0 = 0;
246  if ( ic.hasConditionOn(VM_Total) ) {
247  tot0 = ic.give(VM_Total);
248  }
249 #if 0
250  Not relevant for this time discretization
251  double tot1 = 0.
252  if ( ic.hasConditionOn(VM_Incremental) ) {
253  tot1 = tot0 - ic.give(VM_Incremental);
254  } else if ( ic.hasConditionOn(VM_Velocity) ) {
255  tot1 = tot0 - ic.give(VM_Velocity) * tStep->giveTimeIncrement();
256  } else {
257  tot1 = tot0;
258  }
259 #endif
260  for ( int dofid : ic.giveDofIDs() ) {
261  if ( dman->findDofWithDofId((DofIDItem)dofid) != dman->end() ) {
262  Dof *dof = dman->giveDofWithID(dofid);
263  //dof->updateUnknownsDictionary(tStep, VM_Total, tot1);
264  dof->updateUnknownsDictionary(tStep, VM_Total, tot0);
265  }
266  }
267  }
268 }
269 
270 
271 void
273 {
275  for ( auto &dman : d->giveDofManagers() ) {
276  if ( dman->isNull() ) continue;
277  for ( auto &dof : *dman ) {
278  if ( dof->hasBc(tStep) && dof->isPrimaryDof() ) {
279  int bcid = dof->giveBcId();
280  double val = static_cast< BoundaryCondition* >(d->giveBc(bcid))->give(dof, VM_Total, tStep->giveTargetTime());
281  dof->updateUnknownsDictionary(tStep, VM_Total, val);
282  }
283  }
284  }
285 
286  for ( auto &bc : d->giveBcs() ) {
287  if ( bc->isImposed(tStep) ) {
288  BoundaryCondition *dbc = dynamic_cast< BoundaryCondition* >(bc.get());
289  ActiveBoundaryCondition *abc = dynamic_cast< ActiveBoundaryCondition* >(bc.get());
290  if ( dbc && dbc->isImposed(tStep) ) {
291  this->applyBoundaryCondition(*dbc, tStep);
292  } else if ( abc ) {
293  if ( abc->giveInternalDofManager(1)->isNull() ) continue;
294  for ( auto &dof : *abc->giveInternalDofManager(1) ) {
295  if ( dof->isPrimaryDof() && abc->hasBc(dof, tStep) ) {
296  dof->updateUnknownsDictionary( tStep, VM_Total, abc->giveBcValue(dof, VM_Total, tStep) );
297  }
298  }
299  }
300  }
301  }
302 }
303 
304 
305 void
307 {
308  if ( bc.giveSetNumber() == 0 ) {
309  return;
310  }
311 
312  Domain *d = bc.giveDomain();
313  Set *set = d->giveSet(bc.giveSetNumber());
314  for ( int inode : set->giveNodeList() ) {
315  DofManager *dman = d->giveDofManager(inode);
316  if ( dman->isNull() ) continue;
317  for ( auto &dofid : bc.giveDofIDs() ) {
318  if ( !dman->hasDofID((DofIDItem)dofid) ) {
319  continue;
320  }
321  Dof *dof = dman->giveDofWithID(dofid);
322  if ( dof->isPrimaryDof() ) {
323  dof->updateUnknownsDictionary( tStep, VM_Total, bc.give(dof, VM_Total, tStep->giveTargetTime()) );
324  }
325  }
326  }
327 }
328 
329 
330 void
332 {
333  for ( auto &dof : dman ) {
334  double val = dof->giveUnknownsDictionaryValue( prev, VM_Total );
335  dof->updateUnknownsDictionary( tStep, VM_Total, val );
336  }
337 }
338 
339 void
341 {
343 #if 0
344  // Copy over the old dictionary values to the new step as the initial guess:
345  Domain *d = emodel->giveDomain(1);
346  TimeStep *prev = tStep->givePreviousStep();
347  for ( auto &dman : d->giveDofManagers() ) {
348  if ( dman->isNull() ) continue;
349  this->setInitialGuess(*dman, tStep, prev);
350  }
351 
352  for ( auto &elem : d->giveElements() ) {
353  if ( elem->giveParallelMode() == Element_remote ) continue;
354  int ndman = elem->giveNumberOfInternalDofManagers();
355  for ( int i = 1; i <= ndman; i++ ) {
356  this->setInitialGuess(*elem->giveInternalDofManager(i), tStep, prev);
357  }
358  }
359 
360  for ( auto &bc : d->giveBcs() ) {
361  int ndman = bc->giveNumberOfInternalDofManagers();
362  for ( int i = 1; i <= ndman; i++ ) {
363  if ( abc->giveInternalDofManager(i)->isNull() ) continue;
364  this->setInitialGuess(*bc->giveInternalDofManager(i), tStep, prev);
365  }
366  }
367 
368  // Apply dirichlet b.c.s
369  //this->applyBoundaryCondition(tStep);
370 #endif
371 }
372 
373 
376 {
377  // all the job is done by dofs alone
378  return CIO_OK;
379 }
380 
383 {
384  return CIO_OK;
385 }
386 } // end namespace oofem
virtual FloatArray * giveSolutionVector(TimeStep *tStep)
Definition: primaryfield.C:443
virtual bool isImposed(TimeStep *tStep)
Returns nonzero if receiver representing BC is imposed at given time, otherwise returns zero...
const IntArray & giveDofIDs()
Gives the set number which initial condition is applied to.
void applyInitialCondition(InitialCondition &ic)
virtual void advanceSolution(TimeStep *tStep)
Brings up a new solution vector for given time step.
Definition: primaryfield.C:483
Class and object Domain.
Definition: domain.h:115
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
void setInitialGuess(DofManager &dman, TimeStep *tStep, TimeStep *prev)
FieldType
Physical type of field.
Definition: field.h:60
Class implementing general initial condition.
InitialCondition * giveIc(int n)
Service for accessing particular domain ic.
Definition: domain.C:255
virtual double give(Dof *dof, ValueModeType mode, TimeStep *tStep)
Returns the value of a prescribed unknown, respecting requested mode for given time.
Abstract class representing field of primary variables (those, which are unknown and are typically as...
Definition: primaryfield.h:104
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
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 const IntArray & giveDofIDs() const
Array with default dofs which b.c.
virtual double giveBcValue(Dof *dof, ValueModeType mode, TimeStep *tStep)
Returns the prescribed value of a dof (if any).
Definition: activebc.h:161
virtual void advanceSolution(TimeStep *tStep)
Brings up a new solution vector for given time step.
virtual DofManager * giveInternalDofManager(int i)
Gives an internal dof manager from receiver.
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
Base class for dof managers.
Definition: dofmanager.h:113
std::vector< std::unique_ptr< DofManager > > & giveDofManagers()
Definition: domain.h:400
virtual FloatArray * giveSolutionVector(TimeStep *tStep)
GeneralBoundaryCondition * giveBc(int n)
Service for accessing particular domain bc.
Definition: domain.C:243
double giveTimeIncrement()
Returns solution step associated time increment.
Definition: timestep.h:150
std::vector< std::unique_ptr< GeneralBoundaryCondition > > & giveBcs()
Definition: domain.h:322
int giveSetNumber()
Gives the set number which boundary condition is applied to.
Class implementing Dirichlet boundary condition on DOF (primary boundary condition).
virtual bool hasBc(Dof *dof, TimeStep *tStep)
Returns the prescribed value of a dof (if any).
Definition: activebc.h:166
#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.
virtual void updateUnknownsDictionary(TimeStep *tStep, ValueModeType mode, double dofValue)
Abstract function, allowing Dof to store its unknowns in its own private dictionary.
Definition: dof.h:366
Set of elements, boundaries, edges and/or nodes.
Definition: set.h:66
Abstract base class allowing to control the way, how equations are assigned to individual DOFs...
virtual bool isPrimaryDof()
Tests if receiver is primary DOF.
Definition: dof.h:287
EngngModel * emodel
Definition: primaryfield.h:113
Set * giveSet(int n)
Service for accessing particular domain set.
Definition: domain.C:363
std::vector< std::unique_ptr< InitialCondition > > & giveIcs()
Definition: domain.h:329
Abstract base class for all active boundary conditions.
Definition: activebc.h:63
virtual double giveUnknownValue(Dof *dof, ValueModeType mode, TimeStep *tStep)
TimeStep * givePreviousStep()
Returns pointer to previous solution step.
Definition: timestep.C:114
double give(ValueModeType mode)
Returns value of initial condition for given unknown mode (determines whether total or velocity or ac...
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode)
Stores receiver state to output stream.
Class representing vector of real numbers.
Definition: floatarray.h:82
bool isNull()
Returns true if receiver is shared.
Definition: dofmanager.h:540
bool hasDofID(DofIDItem id) const
Checks if receiver contains dof with given ID.
Definition: dofmanager.C:166
virtual double giveUnknownsDictionaryValue(TimeStep *tStep, ValueModeType mode)
Access dictionary value, if not present zero is returned.
Definition: dof.h:373
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode)
Restores the receiver state previously written in stream.
virtual void applyBoundaryCondition(TimeStep *tStep)
Applies all boundary conditions to all prescribed DOFs.
std::vector< Dof * >::const_iterator findDofWithDofId(DofIDItem dofID) const
Finds index of DOF with required physical meaning of receiver.
Definition: dofmanager.C:266
Dof * giveDofWithID(int dofID) const
Returns DOF with given dofID; issues error if not present.
Definition: dofmanager.C:119
virtual void applyDefaultInitialCondition()
Applies the default initial values values for all DOFs (0) in given domain.
void zero()
Zeroes all coefficients of receiver.
Definition: floatarray.C:658
virtual void update(ValueModeType mode, TimeStep *tStep, const FloatArray &vectorToStore, const UnknownNumberingScheme &s)
Project vectorToStore back to DOF&#39;s dictionary.
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
virtual void initialize(ValueModeType mode, TimeStep *tStep, FloatArray &answer, const UnknownNumberingScheme &s)
Copy unknowns from previous solution or DOF&#39;s dictionary to the solution vector.
Element in active domain is only mirror of some remote element.
Definition: element.h:102
int giveSetNumber()
Gives the set number which initial condition is applied to.
Domain * giveDomain() const
Definition: femcmpnn.h:100
virtual TimeStep * giveSolutionStepWhenIcApply(bool force=false)
Returns the solution step when Initial Conditions (IC) apply.
Definition: engngm.h:720
std::vector< std::unique_ptr< Element > > & giveElements()
Definition: domain.h:279
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
the oofem namespace is to define a context or scope in which all oofem names are defined.
std::vector< Dof * >::iterator end()
Definition: dofmanager.h:158
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
DofDistributedPrimaryField(EngngModel *a, int idomain, FieldType ft, int nHist)
Constructor.
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:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011