OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
linearconstraintbc.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 "linearconstraintbc.h"
36 #include "classfactory.h"
37 #include "masterdof.h"
38 #include "floatmatrix.h"
39 #include "sparsemtrx.h"
40 #include "unknownnumberingscheme.h"
41 #include "function.h"
42 #include "timestep.h"
43 #include "datastream.h"
44 #include "contextioerr.h"
45 #include "node.h"
46 #include "domain.h"
47 
48 namespace oofem {
49 REGISTER_BoundaryCondition(LinearConstraintBC);
50 
52  md( new Node(0, domain) )
53 {
54  // this is internal lagrange multiplier used to enforce the receiver constrain
55  // this allocates a new equation related to this constraint
56  this->md->appendDof( new MasterDof( this->md.get(), ( DofIDItem ) ( d->giveNextFreeDofID() ) ) );
57  this->lhsType.clear();
58  this->rhsType.clear();
59 }
60 
61 
63 {
64 }
65 
66 
68 {
69  IRResultType result;
70  rhsTf = 0;
71 
76  if ( weights.giveSize() != dofmans.giveSize() ) {
77  OOFEM_WARNING("Size mismatch, weights %d and dofmans %d", weights.giveSize(), dofmans.giveSize());
78  return IRRT_BAD_FORMAT;
79  }
82 
85 
87 }
88 
89 
91 {
92  int size = this->weights.giveSize();
93 
94  locr.resize(size);
95  // assemble location array
96  for ( int _i = 1; _i <= size; _i++ ) {
97  Dof *idof = this->domain->giveDofManager( this->dofmans.at(_i) )->giveDofWithID( this->dofs.at(_i) );
98  locr.at(_i) = r_s.giveDofEquationNumber(idof);
99  }
100 
101  lambda_eq = r_s.giveDofEquationNumber( *md->begin() );
102 }
103 
104 
106  CharType type, const UnknownNumberingScheme &r_s,
107  const UnknownNumberingScheme &c_s, double scale)
108 {
109  int size = this->weights.giveSize();
110  IntArray lambdaeq(1);
111  FloatMatrix contrib(size, 1), contribt;
112  IntArray locr(size);
113 
114  if ( !this->lhsType.contains( ( int ) type ) ) {
115  return;
116  }
117  this->giveLocArray( r_s, locr, lambdaeq.at(1) );
118 
119  if ( this->isImposed(tStep) ) {
120  for ( int _i = 1; _i <= size; _i++ ) { // loop over dofs
121  double factor = 1.;
122  if ( weightsTf.giveSize() ) {
123  factor = domain->giveFunction( weightsTf.at(_i) )->evaluateAtTime( tStep->giveIntrinsicTime() );
124  }
125  contrib.at(_i, 1) = this->weights.at(_i) * factor;
126  }
127 
128  contribt.times(scale);
129  contribt.beTranspositionOf(contrib);
130 
131  answer.assemble(lambdaeq, locr, contribt);
132  answer.assemble(locr, lambdaeq, contrib);
133  } else {
134  // the bc is not imposed at specific time step, however in order to make the equation system regular
135  // we initialize the allocated equation to the following form 1*labmda = 0, forcing lagrange multiplier
136  // of inactive condition to be zero.
137  FloatMatrix help(1, 1);
138  help.at(1, 1) = 1.0;
139  answer.assemble(lambdaeq, lambdaeq, help);
140  }
141 }
142 
144  CharType type, ValueModeType mode,
145  const UnknownNumberingScheme &s, FloatArray *eNorms)
146 {
147  IntArray loc, lambdaeq(1);
148  FloatArray vec(1);
149  double factor = 1.;
150 
151  if ( !this->rhsType.contains( ( int ) type ) ) {
152  return;
153  }
154 
155  if ( type == InternalForcesVector ) {
156  // compute true residual
157  int size = this->weights.giveSize();
158  Dof *mdof = *md->begin();
159  Dof *idof;
160 
161  // assemble location array
162  for ( int _i = 1; _i <= size; _i++ ) {
163  factor = 1.;
164  if ( weightsTf.giveSize() ) {
165  factor = domain->giveFunction( weightsTf.at(_i) )->evaluateAtTime( tStep->giveIntrinsicTime() );
166  }
167  idof = this->domain->giveDofManager( this->dofmans.at(_i) )->giveDofWithID( this->dofs.at(_i) );
168  if ( s.giveDofEquationNumber(idof) ) {
169  answer.at( s.giveDofEquationNumber(idof) ) += mdof->giveUnknown(mode, tStep) * this->weights.at(_i) * factor;
170  }
171  if ( s.giveDofEquationNumber( mdof ) ) {
172  answer.at( s.giveDofEquationNumber( mdof ) ) += idof->giveUnknown(mode, tStep) * this->weights.at(_i) * factor;
173  }
174  }
175  } else if ( type == ExternalForcesVector ) {
176  // use rhs value
177 
178  if ( rhsTf ) {
179  factor = domain->giveFunction(rhsTf)->evaluateAtTime( tStep->giveIntrinsicTime() );
180  }
181  this->giveLocArray( s, loc, lambdaeq.at(1) );
182  vec.at(1) = rhs * factor;
183  answer.assemble(vec, lambdaeq);
184  }
185 }
186 
187 void LinearConstraintBC :: giveLocationArrays(std :: vector< IntArray > &rows, std :: vector< IntArray > &cols, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s)
188 {
189  rows.resize(3);
190  cols.resize(3);
191 
192  IntArray loc, lambdaeq(1);
193  this->giveLocArray( r_s, loc, lambdaeq.at(1) );
194  // column block
195  rows [ 0 ] = loc;
196  cols [ 0 ] = lambdaeq;
197  // row block
198  cols [ 1 ] = loc;
199  rows [ 1 ] = lambdaeq;
200  // diagonal enry (some sparse mtrx implementation requaire this)
201  rows [ 2 ] = lambdaeq;
202  cols [ 2 ] = lambdaeq;
203 }
204 
205 
208 {
209  contextIOResultType iores;
210  if ( mode & CM_Definition ) {
211  if ( ( iores = weights.storeYourself(stream) ) != CIO_OK ) {
212  THROW_CIOERR(iores);
213  }
214  if ( ( iores = weightsTf.storeYourself(stream) ) != CIO_OK ) {
215  THROW_CIOERR(iores);
216  }
217  if ( ( iores = dofmans.storeYourself(stream) ) != CIO_OK ) {
218  THROW_CIOERR(iores);
219  }
220  if ( ( iores = dofs.storeYourself(stream) ) != CIO_OK ) {
221  THROW_CIOERR(iores);
222  }
223  if ( !stream.write(rhs) ) {
225  }
226  if ( !stream.write(rhsTf) ) {
228  }
229  if ( ( iores = lhsType.storeYourself(stream) ) != CIO_OK ) {
230  THROW_CIOERR(iores);
231  }
232  if ( ( iores = rhsType.storeYourself(stream) ) != CIO_OK ) {
233  THROW_CIOERR(iores);
234  }
235  }
236 
237  if ( ( iores = md->saveContext(stream, mode) ) != CIO_OK ) {
238  THROW_CIOERR(iores);
239  }
240 
241  return CIO_OK;
242 }
243 
244 
247 {
248  contextIOResultType iores;
249  if ( mode & CM_Definition ) {
250  if ( ( iores = weights.restoreYourself(stream) ) != CIO_OK ) {
251  THROW_CIOERR(iores);
252  }
253  if ( ( iores = weightsTf.restoreYourself(stream) ) != CIO_OK ) {
254  THROW_CIOERR(iores);
255  }
256  if ( ( iores = dofmans.restoreYourself(stream) ) != CIO_OK ) {
257  THROW_CIOERR(iores);
258  }
259  if ( ( iores = dofs.restoreYourself(stream) ) != CIO_OK ) {
260  THROW_CIOERR(iores);
261  }
262  if ( !stream.read(rhs) ) {
264  }
265  if ( !stream.read(rhsTf) ) {
267  }
268  if ( ( iores = lhsType.restoreYourself(stream) ) != CIO_OK ) {
269  THROW_CIOERR(iores);
270  }
271  if ( ( iores = rhsType.restoreYourself(stream) ) != CIO_OK ) {
272  THROW_CIOERR(iores);
273  }
274  }
275 
276  if ( ( iores = md->restoreContext(stream, mode) ) != CIO_OK ) {
277  THROW_CIOERR(iores);
278  }
279 
280  return CIO_OK;
281 }
282 } //end of oofem namespace
bool contains(int value) const
Definition: intarray.h:283
virtual bool isImposed(TimeStep *tStep)
Returns nonzero if receiver representing BC is imposed at given time, otherwise returns zero...
contextIOResultType storeYourself(DataStream &stream) const
Stores array to output stream.
Definition: intarray.C:289
virtual void giveLocationArrays(std::vector< IntArray > &rows, std::vector< IntArray > &cols, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s)
Gives a list of location arrays that will be assembled.
REGISTER_BoundaryCondition(BoundaryCondition)
Class and object Domain.
Definition: domain.h:115
virtual int assemble(const IntArray &loc, const FloatMatrix &mat)=0
Assembles sparse matrix from contribution of local elements.
void giveLocArray(const UnknownNumberingScheme &r_s, IntArray &locr, int &lambdaeq)
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition: femcmpnn.h:82
Base class for all matrices stored in sparse format.
Definition: sparsemtrx.h:60
IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: activebc.h:75
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
std::unique_ptr< DofManager > md
contextIOResultType storeYourself(DataStream &stream) const
Definition: floatarray.C:872
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
#define _IFT_LinearConstraintBC_dofs
virtual double giveUnknown(ValueModeType mode, TimeStep *tStep)=0
The key method of class Dof.
virtual ~LinearConstraintBC()
Destructor.
General IO error.
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
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
virtual int giveDofEquationNumber(Dof *dof) const =0
Returns the equation number for corresponding DOF.
virtual int write(const int *data, int count)=0
Writes count integer values from array pointed by data.
Class representing "master" degree of freedom.
Definition: masterdof.h:92
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
void clear()
Clears the array (zero size).
Definition: intarray.h:177
DofIDItem
Type representing particular dof type.
Definition: dofiditem.h:86
#define _IFT_LinearConstraintBC_rhstype
void times(double f)
Multiplies receiver by factor f.
Definition: floatmatrix.C:1594
Abstract base class allowing to control the way, how equations are assigned to individual DOFs...
contextIOResultType restoreYourself(DataStream &stream)
Definition: floatarray.C:895
#define _IFT_LinearConstraintBC_weights
Abstract base class for all active boundary conditions.
Definition: activebc.h:63
#define _IFT_LinearConstraintBC_lhstype
#define _IFT_LinearConstraintBC_rhs
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
double giveIntrinsicTime()
Returns intrinsic time, e.g. time in which constitutive model is evaluated.
Definition: timestep.h:148
virtual void scale(double s)
Scales the receiver according to given value.
contextIOResultType restoreYourself(DataStream &stream)
Restores array from image on stream.
Definition: intarray.C:305
Function * giveFunction(int n)
Service for accessing particular domain load time function.
Definition: domain.C:268
int giveNextFreeDofID(int increment=1)
Gives the next free dof ID.
Definition: domain.C:1411
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
#define _IFT_LinearConstraintBC_dofmans
void assemble(const FloatArray &fe, const IntArray &loc)
Assembles the array fe (typically, the load vector of a finite element) into the receiver, using loc as location array.
Definition: floatarray.C:551
CharType
Definition: chartype.h:87
Class representing the general Input Record.
Definition: inputrecord.h:101
LinearConstraintBC(int n, Domain *d)
#define _IFT_LinearConstraintBC_weightsfuncs
void beTranspositionOf(const FloatMatrix &src)
Assigns to the receiver the transposition of parameter.
Definition: floatmatrix.C:323
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
#define new
#define CM_Definition
Definition: contextmode.h:47
virtual void assemble(SparseMtrx &answer, TimeStep *tStep, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s, double scale=1.0)
Assembles B.C.
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
int giveSize() const
Definition: intarray.h:203
virtual void assembleVector(FloatArray &answer, TimeStep *tStep, CharType type, ValueModeType mode, const UnknownNumberingScheme &s, FloatArray *eNorms=NULL)
Assembles B.C.
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.
Class implementing node in finite element mesh.
Definition: node.h:87
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
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
virtual double evaluateAtTime(double t)
Returns the value of the function at given time.
Definition: function.C:76
#define _IFT_LinearConstraintBC_rhsfuncs
#define OOFEM_WARNING(...)
Definition: error.h:62
Class representing solution step.
Definition: timestep.h:80
IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.

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