OOFEM 3.0
Loading...
Searching...
No Matches
integrationrule.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 "integrationrule.h"
36#include "material.h"
37#include "crosssection.h"
38#include "gausspoint.h"
39#include "datastream.h"
40#include "contextioerr.h"
41
42namespace oofem {
43
44IntegrationRule :: IntegrationRule(int n, Element *e, int startIndx, int endIndx, bool dynamic)
45{
46 number = n;
47 elem = e;
48 firstLocalStrainIndx = startIndx;
49 lastLocalStrainIndx = endIndx;
50 isDynamic = dynamic;
52}
53
54IntegrationRule :: IntegrationRule(int n, Element *e)
55{
56 number = n;
57 elem = e;
59 isDynamic = false;
61}
62
63
64IntegrationRule :: ~IntegrationRule()
65{
66 this->clear();
67}
68
69
70void
71IntegrationRule :: clear()
72{
73 for ( GaussPoint *gp: *this ) {
74 delete gp;
75 }
76
77 gaussPoints.clear();
78}
79
80
82IntegrationRule :: getIntegrationPoint(int i)
83{
84# ifdef DEBUG
85 if ( ( i < 0 ) || ( i >= this->giveNumberOfIntegrationPoints() ) ) {
86 OOFEM_ERROR("request out of bounds (%d)", i);
87 }
88
89# endif
90 return gaussPoints [ i ];
91}
92
93
95IntegrationRule :: findIntegrationPointClosestTo(const FloatArray &lcoord)
96{
97 double mindist = -1.;
98 GaussPoint *minGp = nullptr;
99 for ( GaussPoint *gp: *this ) {
100 double dist = distance_square(lcoord, gp->giveNaturalCoordinates());
101 if ( dist <= mindist || mindist < 0. ) {
102 mindist = dist;
103 minGp = gp;
104 }
105 }
106 return minGp;
107}
108
109
110void
111IntegrationRule :: printOutputAt(FILE *file, TimeStep *tStep)
112// Performs end-of-step operations.
113{
114 for ( auto &gp: *this ) {
115 gp->printOutputAt(file, tStep);
116 }
117}
118
119void
120IntegrationRule :: updateYourself(TimeStep *tStep)
121{
122 // Updates the receiver at end of step.
123 for ( auto &gp: *this ) {
124 gp->updateYourself(tStep);
125 }
126}
127
128
129void
130IntegrationRule :: saveContext(DataStream &stream, ContextMode mode)
131{
133
134 int isdyn = isDynamic;
135 if ( !stream.write(isdyn) ) {
137 }
138
139 if ( isDynamic ) {
140 mode |= CM_Definition; // store definition if dynamic
141 }
142
143 if ( mode & CM_Definition ) {
144 int numberOfIntegrationPoints = (int)this->gaussPoints.size();
145 if ( !stream.write(numberOfIntegrationPoints) ) {
147 }
148
149 // write first and last integration indices
150 if ( !stream.write(firstLocalStrainIndx) ) {
152 }
153
154 if ( !stream.write(lastLocalStrainIndx) ) {
156 }
157 }
158
159 for ( auto &gp: *this ) {
160 if ( mode & CM_Definition ) {
161 // write gp weight, coordinates, element number, and material mode
162 double dval = gp->giveWeight();
163 if ( !stream.write(dval) ) {
165 }
166
167 if ( ( iores = gp->giveNaturalCoordinates().storeYourself(stream) ) != CIO_OK ) {
168 THROW_CIOERR(iores);
169 }
170
171 //int ival = gp->giveElement()->giveNumber();
172 //if (!stream.write(&ival,1)) THROW_CIOERR(CIO_IOERR);
173 int mmode = gp->giveMaterialMode();
174 if ( !stream.write(mmode) ) {
176 }
177 }
178
179 // write gp data
180 gp->giveCrossSection()->saveIPContext(stream, mode, gp);
181 }
182}
183
184void
185IntegrationRule :: restoreContext(DataStream &stream, ContextMode mode)
186{
188 int size;
189
190 int isdyn;
191 if ( !stream.read(isdyn) ) {
193 }
194
195 isDynamic = ( bool ) isdyn;
196
197 if ( isDynamic ) {
198 mode |= CM_Definition; // store definition if dynamic
199 }
200
201 if ( mode & CM_Definition ) {
202 if ( !stream.read(size) ) {
204 }
205
206 // read first and last integration indices
207 if ( !stream.read(firstLocalStrainIndx) ) {
209 }
210
211 if ( !stream.read(lastLocalStrainIndx) ) {
213 }
214
215 this->clear();
216
217 this->gaussPoints.resize(size);
218 }
219
220 int i = 1;
221 for ( auto &gp: *this ) {
222 if ( mode & CM_Definition ) {
223 // read weight
224 double w;
225 if ( !stream.read(w) ) {
227 }
228
229 // read coords
230 FloatArray c;
231 if ( ( iores = c.restoreYourself(stream) ) != CIO_OK ) {
232 THROW_CIOERR(iores);
233 }
234
235 // restore element and material mode
236 //int n;
237 //if (!stream.read(n)) THROW_CIOERR(CIO_IOERR);
238 MaterialMode m;
239 int _m;
240 if ( !stream.read(_m) ) {
242 }
243
244 m = ( MaterialMode ) _m;
245 // read dynamic flag
246
247 gp = new GaussPoint(this, i, std :: move(c), w, m);
248 i++;
249 }
250
251 // read gp data
252 gp->giveCrossSection()->restoreIPContext(stream, mode, gp);
253 }
254}
255
256
257int
258IntegrationRule :: setUpIntegrationPoints(integrationDomain mode, int nPoints,
259 MaterialMode matMode)
260{
261 intdomain = mode;
262
263 switch ( mode ) {
264 case _Line:
265 return this->SetUpPointsOnLine(nPoints, matMode);
266
267 case _Triangle:
268 return this->SetUpPointsOnTriangle(nPoints, matMode);
269
270 case _Square:
271 return this->SetUpPointsOnSquare(nPoints, matMode);
272
273 case _Cube:
274 return this->SetUpPointsOnCube(nPoints, matMode);
275
276 case _Tetrahedra:
277 return this->SetUpPointsOnTetrahedra(nPoints, matMode);
278
279 case _Wedge:
280 // Limited wrapper for now;
281 if ( nPoints == 6 ) {
282 return this->SetUpPointsOnWedge(3, 2, matMode);
283 } else {
284 return this->SetUpPointsOnWedge(3, 3, matMode);
285 }
286
287 default:
288 OOFEM_ERROR("unknown mode (%d)", mode);
289 }
290
291 //return 0;
292}
293
294int
295IntegrationRule :: setUpIntegrationPoints(integrationDomain mode, int nPointsXY, int nPointsZ,
296 MaterialMode matMode)
297{
298 intdomain = mode;
299
300 switch ( mode ) {
301 case _3dDegShell:
302 return this->SetUpPointsOn3dDegShell(nPointsXY, nPointsZ, matMode);
303
304 default:
305 OOFEM_ERROR("Unknown mode (%d)", mode);
306 }
307 //return 0;
308}
309
310int
311IntegrationRule :: setUpEmbeddedIntegrationPoints(integrationDomain mode, int nPoints, MaterialMode matMode,
312 const std :: vector< FloatArray > &coords)
313{
314 intdomain = mode;
315
316 switch ( mode ) {
317 case _Embedded2dLine:
318 if ( coords.size() != 2 ) {
319 OOFEM_ERROR("Exactly 2 coordinates are required for 2D embedded lines!");
320 }
321 return this->SetUpPointsOn2DEmbeddedLine(nPoints, matMode, coords[0], coords[1]);
322
323 default:
324 OOFEM_ERROR("unknown mode");
325 }
326 //return 0;
327}
328
329
330int IntegrationRule :: SetUpPoint(MaterialMode mode)
331{
332 this->gaussPoints.resize(1);
333 this->gaussPoints [ 0 ] = new GaussPoint(this, 1, FloatArray(0), 1.0, mode);
334 this->intdomain = _Point;
335 return 1;
336}
337} // end namespace oofem
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.
contextIOResultType restoreYourself(DataStream &stream)
Definition floatarray.C:917
const FloatArray & giveNaturalCoordinates() const
Returns coordinate array of receiver.
Definition gausspoint.h:138
virtual int SetUpPointsOnLine(int, MaterialMode mode)
virtual int SetUpPointsOn3dDegShell(int nPointsXY, int nPointsZ, MaterialMode mode)
Element * elem
Element which integration rule is coupled to.
int giveNumberOfIntegrationPoints() const
std::vector< GaussPoint * > gaussPoints
Array containing integration points.
integrationDomain intdomain
Integration domain.
virtual int SetUpPointsOnWedge(int nPointsTri, int nPointsDepth, MaterialMode mode)
virtual int SetUpPointsOnSquare(int, MaterialMode mode)
virtual int SetUpPointsOnCube(int, MaterialMode mode)
virtual int SetUpPointsOnTriangle(int, MaterialMode mode)
virtual int SetUpPointsOn2DEmbeddedLine(int nPoints, MaterialMode mode, const FloatArray &coord0, const FloatArray &coord1)
virtual int SetUpPointsOnTetrahedra(int, MaterialMode mode)
#define THROW_CIOERR(e)
#define CM_Definition
Definition contextmode.h:47
#define OOFEM_ERROR(...)
Definition error.h:79
long ContextMode
Definition contextmode.h:43
@ _UnknownIntegrationDomain
double distance_square(const FloatArray &x, const FloatArray &y)
@ 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