OOFEM 3.0
Loading...
Searching...
No Matches
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 - 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 "linearconstraintbc.h"
36#include "classfactory.h"
37#include "masterdof.h"
38#include "floatmatrix.h"
39#include "sparsemtrx.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#ifdef _OPENMP
49#include <omp.h>
50#endif
51
52namespace oofem {
54
55LinearConstraintBC :: LinearConstraintBC(int n, Domain *d) : ActiveBoundaryCondition(n, d),
56 md( new Node(0, domain) )
57{
58 // this is internal lagrange multiplier used to enforce the receiver constrain
59 // this allocates a new equation related to this constraint
60 this->md->appendDof( new MasterDof( this->md.get(), ( DofIDItem ) ( d->giveNextFreeDofID() ) ) );
61 this->lhsType.clear();
62 this->rhsType.clear();
63}
64
65
66LinearConstraintBC :: ~LinearConstraintBC()
67{
68}
69
70
89
90
91void LinearConstraintBC :: giveLocArray(const UnknownNumberingScheme &r_s, IntArray &locr, int &lambda_eq)
92{
93 int size = this->weights.giveSize();
94
95 locr.resize(size);
96 // assemble location array
97 for ( int _i = 1; _i <= size; _i++ ) {
98 Dof *idof = this->domain->giveDofManager( this->dofmans.at(_i) )->giveDofWithID( this->dofs.at(_i) );
99 locr.at(_i) = r_s.giveDofEquationNumber(idof);
100 }
101
102 lambda_eq = r_s.giveDofEquationNumber( *md->begin() );
103}
104
105
106void LinearConstraintBC :: assemble(SparseMtrx &answer, TimeStep *tStep,
107 CharType type, const UnknownNumberingScheme &r_s,
108 const UnknownNumberingScheme &c_s, double scale,
109 void*lock)
110{
111 int size = this->weights.giveSize();
112 IntArray lambdaeq(1);
113 FloatMatrix contrib(size, 1), contribt;
114 IntArray locr(size);
115
116 if ( !this->lhsType.contains( ( int ) type ) ) {
117 return;
118 }
119 this->giveLocArray( r_s, locr, lambdaeq.at(1) );
120
121 if ( this->isImposed(tStep) ) {
122 for ( int _i = 1; _i <= size; _i++ ) { // loop over dofs
123 double factor = 1.;
124 if ( weightsTf.giveSize() ) {
125 factor = domain->giveFunction( weightsTf.at(_i) )->evaluateAtTime( tStep->giveIntrinsicTime() );
126 }
127 contrib.at(_i, 1) = this->weights.at(_i) * factor;
128 }
129
130 contribt.times(scale);
131 contribt.beTranspositionOf(contrib);
132#ifdef _OPENMP
133 if (lock) omp_set_lock(static_cast<omp_lock_t*>(lock));
134#endif
135 answer.assemble(lambdaeq, locr, contribt);
136 answer.assemble(locr, lambdaeq, contrib);
137#ifdef _OPENMP
138 if (lock) omp_unset_lock(static_cast<omp_lock_t*>(lock));
139#endif
140 } else {
141 // the bc is not imposed at specific time step, however in order to make the equation system regular
142 // we initialize the allocated equation to the following form 1*labmda = 0, forcing lagrange multiplier
143 // of inactive condition to be zero.
144 FloatMatrix help(1, 1);
145 help.at(1, 1) = 1.0;
146#ifdef _OPENMP
147 if (lock) omp_set_lock(static_cast<omp_lock_t*>(lock));
148#endif
149 answer.assemble(lambdaeq, lambdaeq, help);
150#ifdef _OPENMP
151 if (lock) omp_unset_lock(static_cast<omp_lock_t*>(lock));
152#endif
153 }
154}
155
156void LinearConstraintBC :: assembleVector(FloatArray &answer, TimeStep *tStep,
157 CharType type, ValueModeType mode,
158 const UnknownNumberingScheme &s,
159 FloatArray *eNorms,
160 void* lock)
161{
162 IntArray loc, lambdaeq(1);
163 FloatArray vec(1);
164 double factor = 1.;
165
166 if ( !this->rhsType.contains( ( int ) type ) ) {
167 return;
168 }
169
170 if ( type == InternalForcesVector ) {
171 // compute true residual
172 int size = this->weights.giveSize();
173 Dof *mdof = *md->begin();
174 Dof *idof;
175
176 // assemble location array
177 for ( int _i = 1; _i <= size; _i++ ) {
178 factor = 1.;
179 if ( weightsTf.giveSize() ) {
180 factor = domain->giveFunction( weightsTf.at(_i) )->evaluateAtTime( tStep->giveIntrinsicTime() );
181 }
182 idof = this->domain->giveDofManager( this->dofmans.at(_i) )->giveDofWithID( this->dofs.at(_i) );
183 if ( s.giveDofEquationNumber(idof) ) {
184#ifdef _OPENMP
185 if (lock) omp_set_lock(static_cast<omp_lock_t*>(lock));
186#endif
187 answer.at( s.giveDofEquationNumber(idof) ) += mdof->giveUnknown(mode, tStep) * this->weights.at(_i) * factor;
188#ifdef _OPENMP
189 if (lock) omp_unset_lock(static_cast<omp_lock_t*>(lock));
190#endif
191 }
192 if ( s.giveDofEquationNumber( mdof ) ) {
193#ifdef _OPENMP
194 if (lock) omp_set_lock(static_cast<omp_lock_t*>(lock));
195#endif
196 answer.at( s.giveDofEquationNumber( mdof ) ) += idof->giveUnknown(mode, tStep) * this->weights.at(_i) * factor;
197#ifdef _OPENMP
198 if (lock) omp_unset_lock(static_cast<omp_lock_t*>(lock));
199#endif
200 }
201 }
202 } else if ( type == ExternalForcesVector ) {
203 // use rhs value
204
205 if ( rhsTf ) {
206 factor = domain->giveFunction(rhsTf)->evaluateAtTime( tStep->giveIntrinsicTime() );
207 }
208 this->giveLocArray( s, loc, lambdaeq.at(1) );
209 vec.at(1) = rhs * factor;
210#ifdef _OPENMP
211 if (lock) omp_set_lock(static_cast<omp_lock_t*>(lock));
212#endif
213 answer.assemble(vec, lambdaeq);
214#ifdef _OPENMP
215 if (lock) omp_unset_lock(static_cast<omp_lock_t*>(lock));
216#endif
217 }
218}
219
220void LinearConstraintBC :: giveLocationArrays(std :: vector< IntArray > &rows, std :: vector< IntArray > &cols, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s)
221{
222 rows.resize(3);
223 cols.resize(3);
224
225 IntArray loc, lambdaeq(1);
226 this->giveLocArray( r_s, loc, lambdaeq.at(1) );
227 // column block
228 rows [ 0 ] = loc;
229 cols [ 0 ] = lambdaeq;
230 // row block
231 cols [ 1 ] = loc;
232 rows [ 1 ] = lambdaeq;
233 // diagonal enry (some sparse mtrx implementation requaire this)
234 rows [ 2 ] = lambdaeq;
235 cols [ 2 ] = lambdaeq;
236}
237
238
239void
240LinearConstraintBC :: saveContext(DataStream &stream, ContextMode mode)
241{
242 if ( mode & CM_Definition ) {
244 if ( ( iores = weights.storeYourself(stream) ) != CIO_OK ) {
245 THROW_CIOERR(iores);
246 }
247 if ( ( iores = weightsTf.storeYourself(stream) ) != CIO_OK ) {
248 THROW_CIOERR(iores);
249 }
250 if ( ( iores = dofmans.storeYourself(stream) ) != CIO_OK ) {
251 THROW_CIOERR(iores);
252 }
253 if ( ( iores = dofs.storeYourself(stream) ) != CIO_OK ) {
254 THROW_CIOERR(iores);
255 }
256 if ( !stream.write(rhs) ) {
258 }
259 if ( !stream.write(rhsTf) ) {
261 }
262 if ( ( iores = lhsType.storeYourself(stream) ) != CIO_OK ) {
263 THROW_CIOERR(iores);
264 }
265 if ( ( iores = rhsType.storeYourself(stream) ) != CIO_OK ) {
266 THROW_CIOERR(iores);
267 }
268 }
269
270 md->saveContext(stream, mode);
271}
272
273
274void
275LinearConstraintBC :: restoreContext(DataStream &stream, ContextMode mode)
276{
277 if ( mode & CM_Definition ) {
279 if ( ( iores = weights.restoreYourself(stream) ) != CIO_OK ) {
280 THROW_CIOERR(iores);
281 }
282 if ( ( iores = weightsTf.restoreYourself(stream) ) != CIO_OK ) {
283 THROW_CIOERR(iores);
284 }
285 if ( ( iores = dofmans.restoreYourself(stream) ) != CIO_OK ) {
286 THROW_CIOERR(iores);
287 }
288 if ( ( iores = dofs.restoreYourself(stream) ) != CIO_OK ) {
289 THROW_CIOERR(iores);
290 }
291 if ( !stream.read(rhs) ) {
293 }
294 if ( !stream.read(rhsTf) ) {
296 }
297 if ( ( iores = lhsType.restoreYourself(stream) ) != CIO_OK ) {
298 THROW_CIOERR(iores);
299 }
300 if ( ( iores = rhsType.restoreYourself(stream) ) != CIO_OK ) {
301 THROW_CIOERR(iores);
302 }
303 }
304
305 md->restoreContext(stream, mode);
306}
307} //end of oofem namespace
#define REGISTER_BoundaryCondition(class)
ActiveBoundaryCondition(int n, Domain *d)
Definition activebc.h:71
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.
virtual double giveUnknown(ValueModeType mode, TimeStep *tStep)=0
int giveNextFreeDofID(int increment=1)
Definition domain.C:1519
Domain * domain
Link to domain object, useful for communicating with other FEM components.
Definition femcmpnn.h:79
void assemble(const FloatArray &fe, const IntArray &loc)
Definition floatarray.C:616
double & at(Index i)
Definition floatarray.h:202
void times(double f)
void beTranspositionOf(const FloatMatrix &src)
double at(std::size_t i, std::size_t j) const
virtual bool isImposed(TimeStep *tStep)
void resize(int n)
Definition intarray.C:73
int & at(std::size_t i)
Definition intarray.h:104
std ::unique_ptr< DofManager > md
void giveLocArray(const UnknownNumberingScheme &r_s, IntArray &locr, int &lambdaeq)
virtual int assemble(const IntArray &loc, const FloatMatrix &mat)=0
double giveIntrinsicTime()
Returns intrinsic time, e.g. time in which constitutive model is evaluated.
Definition timestep.h:166
virtual int giveDofEquationNumber(Dof *dof) const =0
#define THROW_CIOERR(e)
#define CM_Definition
Definition contextmode.h:47
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67
#define _IFT_LinearConstraintBC_lhstype
#define _IFT_LinearConstraintBC_rhsfuncs
#define _IFT_LinearConstraintBC_rhs
#define _IFT_LinearConstraintBC_dofmans
#define _IFT_LinearConstraintBC_weightsfuncs
#define _IFT_LinearConstraintBC_dofs
#define _IFT_LinearConstraintBC_rhstype
#define _IFT_LinearConstraintBC_weights
long ContextMode
Definition contextmode.h:43
@ 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