OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
prescribedmean.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 "prescribedmean.h"
36 #include "classfactory.h"
37 #include "masterdof.h"
38 #include "domain.h"
39 #include "feinterpol.h"
40 #include "gausspoint.h"
41 #include "sparsemtrx.h"
42 #include "function.h"
43 #include "mathfem.h"
44 
45 namespace oofem
46 {
47 
49 
50 
51 REGISTER_BoundaryCondition(PrescribedMean);
52 
55 {
56  IRResultType result;
57 
59 
63 
64  elementEdges = false;
66 
67  int newdofid = this->domain->giveNextFreeDofID();
68  lambdaIDs.clear();
69  lambdaIDs.followedBy(newdofid);
70  lambdaDman->appendDof( new MasterDof( lambdaDman, ( DofIDItem )newdofid ));
71 
72  domainSize=-1.;
73 
74  return IRRT_OK;
75 
76 }
77 
78 void
80  const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s, double scale)
81 {
82 
83  if ( type != TangentStiffnessMatrix && type != StiffnessMatrix ) {
84  return;
85  }
86 
88 
89  IntArray c_loc, r_loc;
92 
93  for ( int i = 1; i <= elements.giveSize(); i++ ) {
94  int elementID = elements.at(i);
95  Element *thisElement = this->giveDomain()->giveElement(elementID);
96  FEInterpolation *interpolator = thisElement->giveInterpolation(DofIDItem(dofid));
97 
98  IntegrationRule *iRule = (elementEdges) ? (interpolator->giveBoundaryIntegrationRule(3, sides.at(i))) :
99  (interpolator->giveIntegrationRule(3));
100 
101  for ( GaussPoint * gp: * iRule ) {
102  FloatArray lcoords = gp->giveNaturalCoordinates();
103  FloatArray N; //, a;
104  FloatMatrix temp, tempT;
105  double detJ = 0.0;
106  IntArray boundaryNodes, dofids={(DofIDItem) this->dofid}, r_Sideloc, c_Sideloc;
107 
108  if (elementEdges) {
109  // Compute boundary integral
110  interpolator->boundaryGiveNodes( boundaryNodes, sides.at(i) );
111  interpolator->boundaryEvalN(N, sides.at(i), lcoords, FEIElementGeometryWrapper(thisElement));
112  detJ = fabs ( interpolator->boundaryGiveTransformationJacobian(sides.at(i), lcoords, FEIElementGeometryWrapper(thisElement)) );
113  // Retrieve locations for dofs on boundary
114  thisElement->giveBoundaryLocationArray(r_Sideloc, boundaryNodes, dofids, r_s);
115  thisElement->giveBoundaryLocationArray(c_Sideloc, boundaryNodes, dofids, c_s);
116  } else {
117  interpolator->evalN(N, lcoords, FEIElementGeometryWrapper(thisElement));
118  detJ = fabs ( interpolator->giveTransformationJacobian(lcoords, FEIElementGeometryWrapper(thisElement) ) );
119  IntArray DofIDStemp, rloc, cloc;
120 
121  thisElement->giveLocationArray(rloc, r_s, &DofIDStemp);
122  thisElement->giveLocationArray(cloc, c_s, &DofIDStemp);
123 
124  r_Sideloc.clear();
125  c_Sideloc.clear();
126  for (int j=1; j<=DofIDStemp.giveSize(); j++) {
127  if ( DofIDStemp.at(j) == dofids.at(1) ) {
128  r_Sideloc.followedBy(rloc.at(j));
129  c_Sideloc.followedBy(cloc.at(j));
130  }
131  }
132  }
133 
134  // delta p part:
135  temp = N * (scale * detJ * gp->giveWeight() / domainSize);
136  tempT.beTranspositionOf(temp);
137 
138  answer.assemble(r_Sideloc, c_loc, temp);
139  answer.assemble(r_loc, c_Sideloc, tempT);
140  }
141 
142  delete iRule;
143 
144  }
145 
146 }
147 
148 void
150  CharType type, ValueModeType mode,
151  const UnknownNumberingScheme &s, FloatArray *eNorm)
152 {
153 
154  if ( type == InternalForcesVector ) {
155  giveInternalForcesVector(answer, tStep, type, mode, s);
156  } else if ( type == ExternalForcesVector ) {
157  giveExternalForcesVector(answer, tStep, type, mode, s);
158  }
159 }
160 
161 void
163  CharType type, ValueModeType mode,
164  const UnknownNumberingScheme &s, FloatArray *eNorm)
165 {
167 
168  // Fetch unknowns of this boundary condition
169  IntArray lambdaLoc;
170  FloatArray lambda;
171  lambdaDman->giveUnknownVector(lambda, lambdaIDs, mode, tStep);
172  lambdaDman->giveLocationArray(lambdaIDs, lambdaLoc, s);
173 
174  for ( int i = 1; i <= elements.giveSize(); i++ ) {
175  int elementID = elements.at(i);
176  Element *thisElement = this->giveDomain()->giveElement(elementID);
177  FEInterpolation *interpolator = thisElement->giveInterpolation(DofIDItem(dofid));
178 
179  IntegrationRule *iRule = (elementEdges) ? (interpolator->giveBoundaryIntegrationRule(3, sides.at(i))) :
180  (interpolator->giveIntegrationRule(3));
181 
182  for ( auto &gp: * iRule ) {
183  FloatArray lcoords = gp->giveNaturalCoordinates();
184  FloatArray a, N, pressureEqns, lambdaEqns;
185  IntArray boundaryNodes, dofids={(DofIDItem) this->dofid}, locationArray;
186  double detJ = 0.0;
187 
188  if (elementEdges) {
189  // Compute integral
190  interpolator->boundaryGiveNodes( boundaryNodes, sides.at(i) );
191  thisElement->computeBoundaryVectorOf(boundaryNodes, dofids, VM_Total, tStep, a);
192  interpolator->boundaryEvalN(N, sides.at(i), lcoords, FEIElementGeometryWrapper(thisElement));
193  detJ = fabs ( interpolator->boundaryGiveTransformationJacobian(sides.at(i), lcoords, FEIElementGeometryWrapper(thisElement)) );
194 
195  // Retrieve locations for dofs with dofids
196  thisElement->giveBoundaryLocationArray(locationArray, boundaryNodes, dofids, s);
197  } else {
198  thisElement->computeVectorOf(dofids, VM_Total, tStep, a);
199  interpolator->evalN(N, lcoords, FEIElementGeometryWrapper(thisElement));
200  detJ = fabs ( interpolator->giveTransformationJacobian(lcoords, FEIElementGeometryWrapper(thisElement)));
201 
202  IntArray DofIDStemp, loc;
203 
204  thisElement->giveLocationArray(loc, s, &DofIDStemp);
205 
206  locationArray.clear();
207  for (int j=1; j<=DofIDStemp.giveSize(); j++) {
208  if ( DofIDStemp.at(j) == dofids.at(1) ) {
209  locationArray.followedBy(loc.at(j));
210  }
211  }
212  }
213 
214  // delta p part:
215  pressureEqns = N*detJ*gp->giveWeight()*lambda.at(1)*(1.0/domainSize);
216 
217  // delta lambda part
218  lambdaEqns.resize(1);
219  lambdaEqns.at(1) = N.dotProduct(a);
220  lambdaEqns.times(detJ*gp->giveWeight()*1.0/domainSize);
221  lambdaEqns.at(1) = lambdaEqns.at(1);
222 
223 
224  // delta p part
225  answer.assemble(pressureEqns, locationArray);
226 
227  // delta lambda part
228  answer.assemble(lambdaEqns, lambdaLoc);
229  }
230  delete iRule;
231  }
232 
233 }
234 
235 void
237  CharType type, ValueModeType mode,
238  const UnknownNumberingScheme &s)
239 {
241 
242  FloatArray temp;
243  IntArray lambdaLoc;
244 
245  temp.resize(1);
246  temp.at(1) = c;
247 
248  lambdaDman->giveLocationArray(lambdaIDs, lambdaLoc, s);
249  answer.assemble(temp, lambdaLoc);
250 
251  // Finally, compute value of loadtimefunction
252  double factor;
253  factor = this->giveTimeFunction()->evaluate(tStep, mode);
254  answer.times(factor);
255 }
256 
257 void
259 {
260  if ( domainSize > 0.0 ) return;
261 
262 
263  if ( elementEdges ) {
264  IntArray setList = ((GeneralBoundaryCondition *)this)->giveDomain()->giveSet(set)->giveBoundaryList();
265 
266  elements.resize(setList.giveSize() / 2);
267  sides.resize(setList.giveSize() / 2);
268 
269  for (int i = 1; i <= setList.giveSize(); i += 2) {
270  elements.at(i/2+1) = setList.at(i);
271  sides.at(i/2+1) = setList.at(i+1);
272  }
273  } else {
274  IntArray setList = ((GeneralBoundaryCondition *)this)->giveDomain()->giveSet(set)->giveElementList();
275  elements = setList;
276  }
277 
278  domainSize = 0.0;
279 
280  for ( int i = 1; i <= elements.giveSize(); i++ ) {
281  int elementID = elements.at(i);
282  Element *thisElement = this->giveDomain()->giveElement(elementID);
283  FEInterpolation *interpolator = thisElement->giveInterpolation(DofIDItem(dofid));
284 
285  IntegrationRule *iRule;
286 
287  if ( elementEdges ) {
288  iRule = interpolator->giveBoundaryIntegrationRule(3, sides.at(i));
289  } else {
290  iRule = interpolator->giveIntegrationRule(3);
291  }
292 
293  for ( GaussPoint * gp: * iRule ) {
294  FloatArray lcoords = gp->giveNaturalCoordinates();
295 
296  double detJ;
297  if ( elementEdges ) {
298  detJ = fabs ( interpolator->boundaryGiveTransformationJacobian(sides.at(i), lcoords, FEIElementGeometryWrapper(thisElement)) );
299  } else {
300  detJ = fabs ( interpolator->giveTransformationJacobian(lcoords, FEIElementGeometryWrapper(thisElement)) );
301  }
302  domainSize = domainSize + detJ*gp->giveWeight();
303  }
304 
305  delete iRule;
306  }
307 
308  printf("%f\n", domainSize);
309 
310 }
311 
312 }
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
REGISTER_BoundaryCondition(BoundaryCondition)
virtual void evalN(FloatArray &answer, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the array of interpolation functions (shape functions) at given point.
virtual int assemble(const IntArray &loc, const FloatMatrix &mat)=0
Assembles sparse matrix from contribution of local elements.
void computeVectorOf(ValueModeType u, TimeStep *tStep, FloatArray &answer)
Returns local vector of unknowns.
Definition: element.C:86
static double domainSize
void giveInternalForcesVector(FloatArray &answer, TimeStep *tStep, CharType type, ValueModeType mode, const UnknownNumberingScheme &s, FloatArray *eNorm=NULL)
virtual double giveTransformationJacobian(const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the determinant of the transformation.
Definition: feinterpol.C:43
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
virtual void assemble(SparseMtrx &answer, TimeStep *tStep, CharType type, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s, double scale=1.0)
Assembles B.C.
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
Abstract base class for all finite elements.
Definition: element.h:145
double evaluate(TimeStep *tStep, ValueModeType mode)
Returns the value of load time function at given time.
Definition: function.C:55
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual FEInterpolation * giveInterpolation() const
Definition: element.h:629
Abstract base class representing integration rule.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Class representing a general abstraction for finite element interpolation class.
Definition: feinterpol.h:132
Class representing "master" degree of freedom.
Definition: masterdof.h:92
virtual void assembleVector(FloatArray &answer, TimeStep *tStep, CharType type, ValueModeType mode, const UnknownNumberingScheme &s, FloatArray *eNorm=NULL)
Assembles B.C.
void giveUnknownVector(FloatArray &answer, const IntArray &dofMask, ValueModeType mode, TimeStep *tStep, bool padding=false)
Assembles the vector of unknowns in global c.s for given dofs of receiver.
Definition: dofmanager.C:685
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
double dotProduct(const FloatArray &x) const
Computes the dot product (or inner product) of receiver and argument.
Definition: floatarray.C:463
void clear()
Clears the array (zero size).
Definition: intarray.h:177
DofIDItem
Type representing particular dof type.
Definition: dofiditem.h:86
void giveLocationArray(IntArray &locationArray, const UnknownNumberingScheme &s, IntArray *dofIds=NULL) const
Returns the location array (array of code numbers) of receiver for given numbering scheme...
Definition: element.C:390
Abstract base class allowing to control the way, how equations are assigned to individual DOFs...
Wrapper around element definition to provide FEICellGeometry interface.
Definition: feinterpol.h:95
virtual double boundaryGiveTransformationJacobian(int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the determinant of the transformation Jacobian on the requested boundary.
#define N(p, q)
Definition: mdm.C:367
Abstract base class for all boundary conditions of problem.
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
void giveExternalForcesVector(FloatArray &answer, TimeStep *tStep, CharType type, ValueModeType mode, const UnknownNumberingScheme &s)
virtual void scale(double s)
Scales the receiver according to given value.
void appendDof(Dof *dof)
Adds the given Dof into the receiver.
Definition: dofmanager.C:134
virtual void boundaryGiveNodes(IntArray &answer, int boundary)=0
Gives the boundary nodes for requested boundary number.
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
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
virtual IntegrationRule * giveBoundaryIntegrationRule(int order, int boundary)
Sets up a suitable integration rule for integrating over the requested boundary.
Definition: feinterpol.C:63
void followedBy(const IntArray &b, int allocChunk=0)
Appends array b at the end of receiver.
Definition: intarray.C:145
virtual void giveBoundaryLocationArray(IntArray &locationArray, const IntArray &bNodes, const UnknownNumberingScheme &s, IntArray *dofIds=NULL)
Returns the location array for the boundary of the element.
Definition: element.C:446
void times(double s)
Multiplies receiver with scalar.
Definition: floatarray.C:818
void beTranspositionOf(const FloatMatrix &src)
Assigns to the receiver the transposition of parameter.
Definition: floatmatrix.C:323
Domain * giveDomain() const
Definition: femcmpnn.h:100
#define _IFT_PrescribedMean_Mean
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
virtual IntegrationRule * giveIntegrationRule(int order)
Sets up a suitable integration rule for numerical integrating over volume.
Definition: feinterpol.C:52
#define _IFT_PrescribedMean_Edge
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define _IFT_PrescribedMean_DofID
#define _IFT_GeneralBoundaryCondition_set
#define IR_GIVE_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:69
void computeBoundaryVectorOf(const IntArray &bNodes, const IntArray &dofIDMask, ValueModeType u, TimeStep *tStep, FloatArray &answer, bool padding=false)
Boundary version of computeVectorOf.
Definition: element.C:139
void giveLocationArray(const IntArray &dofIDArry, IntArray &locationArray, const UnknownNumberingScheme &s) const
Returns location array (array containing for each requested dof related equation number) for given nu...
Definition: dofmanager.C:177
virtual void boundaryEvalN(FloatArray &answer, int boundary, const FloatArray &lcoords, const FEICellGeometry &cellgeo)=0
Evaluates the basis functions on the requested boundary.
Class representing integration point in finite element program.
Definition: gausspoint.h:93
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:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011