OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
patchintegrationrule.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 "patchintegrationrule.h"
36 #include "xfemelementinterface.h"
37 //#include "patch.h"
38 #include "integrationrule.h"
39 #include "gaussintegrationrule.h"
40 #include "geometry.h"
41 #include "classfactory.h"
42 #include "contextioerr.h"
43 #include "datastream.h"
44 #include "gausspoint.h"
45 #include "fei2dtrlin.h"
46 #include "fei3dtrquad.h"
47 #include "XFEMDebugTools.h"
48 
49 #include "timestep.h"
50 #include "engngm.h"
51 
52 namespace oofem {
53 PatchIntegrationRule :: PatchIntegrationRule(int n, Element *e, const std :: vector< Triangle > &iTriangles) :
55  mTriangles(iTriangles)
56 { }
57 
59 { }
60 
63 
64 int
66 {
67  int pointsPassed = 0;
68 
69  // TODO: set properly
72 
73 
75  // Allocate Gauss point array
76 
77 
78  // It may happen that the patch contains triangles with
79  // zero area. This does no harm, since their weights in
80  // the quadrature will be zero. However, they invoke additional
81  // computational cost and therefore we want to avoid them.
82  // Thus, count the number of triangles with finite area
83  // and keep only those triangles.
84 
85  double totArea = 0.0;
86  for ( size_t i = 0; i < mTriangles.size(); i++ ) {
87  totArea += mTriangles [ i ].getArea();
88  }
89 
90  std :: vector< int >triToKeep;
91  const double triTol = ( 1.0e-6 ) * totArea;
92 
93  for ( size_t i = 0; i < mTriangles.size(); i++ ) {
94  if ( mTriangles [ i ].getArea() > triTol ) {
95  triToKeep.push_back(i);
96  }
97  }
98 
99  int nPointsTot = nPoints * triToKeep.size();
100  FloatArray coords_xi1, coords_xi2, weights;
101  this->giveTriCoordsAndWeights(nPoints, coords_xi1, coords_xi2, weights);
102  this->gaussPoints.resize(nPointsTot);
104 
105 
106  std :: vector< FloatArray >newGPCoord;
107 
108  double parentArea = this->elem->computeArea();
109 
110  // Loop over triangles
111  for ( int tri: triToKeep ) {
112  // TODO: Probably unnecessary to allocate here
113  std :: vector< FloatArray >coords( mTriangles [ tri ].giveNrVertices() );
114  // this we should put into the function before
115  for ( int k = 1; k <= mTriangles [ tri ].giveNrVertices(); k++ ) {
116  coords [ k - 1 ] = mTriangles [ tri ].giveVertex(k);
117  }
118 
119  // Can not be used because it writes to the start of the array instead of appending.
120  //int nPointsTri = GaussIntegrationRule :: SetUpPointsOnTriangle(nPoints, mode);
121 
122  for ( int j = 0; j < nPoints; j++ ) {
123  FloatArray global;
124  GaussPoint * &gp = this->gaussPoints [ pointsPassed ];
125 
126  gp = new GaussPoint(this, pointsPassed + 1,
127  {coords_xi1.at(j + 1), coords_xi2.at(j + 1)},
128  weights.at(j + 1), mode);
129 
130 
131 
134 
135  newGPCoord.push_back(global);
136 
137 
138  FloatArray local;
139  this->elem->computeLocalCoordinates(local, global);
140 
141  gp->setGlobalCoordinates(global);
142  gp->setNaturalCoordinates(local);
143  gp->setSubPatchCoordinates(local);
144 
145 
146 
147 
148  double refElArea = this->elem->giveParentElSize();
149 
150  gp->setWeight(2.0 * refElArea * gp->giveWeight() * mTriangles [ tri ].getArea() / parentArea); // update integration weight
151 
152 
153  pointsPassed++;
154  }
155  }
156 
158  if ( xMan != NULL ) {
159  if ( xMan->giveVtkDebug() ) {
160  double time = 0.0;
161 
162  Element *el = this->elem;
163  if ( el != NULL ) {
164  Domain *dom = el->giveDomain();
165  if ( dom != NULL ) {
166  EngngModel *em = dom->giveEngngModel();
167  if ( em != NULL ) {
168  TimeStep *ts = em->giveCurrentStep();
169  if ( ts != NULL ) {
170  time = ts->giveTargetTime();
171  }
172  }
173  }
174  }
175 
176  int elIndex = this->elem->giveGlobalNumber();
177  std :: stringstream str;
178  str << "GaussPointsTime" << time << "El" << elIndex << ".vtk";
179  std :: string name = str.str();
180 
181  XFEMDebugTools :: WritePointsToVTK(name, newGPCoord);
182  }
183  }
184 
185  return this->giveNumberOfIntegrationPoints();
186 }
187 
188 
189 
190 
191 int
192 PatchIntegrationRule :: SetUpPointsOnWedge(int nPointsTri, int nPointsDepth, MaterialMode mode)
193 {
194  //int pointsPassed = 0;
195 
196  // TODO: set properly
199 
200  double totArea = 0.0;
201  for ( size_t i = 0; i < mTriangles.size(); i++ ) {
202  totArea += mTriangles [ i ].getArea();
203  }
204 
205  std :: vector< int >triToKeep;
206  const double triTol = ( 1.0e-6 ) * totArea;
207 
208  for ( size_t i = 0; i < mTriangles.size(); i++ ) {
209  if ( mTriangles [ i ].getArea() > triTol ) {
210  triToKeep.push_back(i);
211  }
212  }
213 
214  int nPointsTot = nPointsTri * nPointsDepth * triToKeep.size();
215  FloatArray coords_xi1, coords_xi2, coords_xi3, weightsTri, weightsDepth;
216  this->giveTriCoordsAndWeights(nPointsTri, coords_xi1, coords_xi2, weightsTri);
217  this->giveLineCoordsAndWeights(nPointsDepth, coords_xi3, weightsDepth);
218  this->gaussPoints.resize(nPointsTot);
219 
220  std :: vector< FloatArray >newGPCoord;
221 
222  double parentArea = this->elem->computeArea();
223  int count = 0;
224 
225  // Loop over triangles
226  for ( int i = 0; i < int( triToKeep.size() ); i++ ) {
227  Triangle triangle = mTriangles [ triToKeep [ i ] ];
228 
229  // global coords of the the triangle verticies
230  std :: vector< FloatArray >gCoords( triangle.giveNrVertices() );
231  for ( int j = 0; j < triangle.giveNrVertices(); j++ ) {
232  gCoords [ j ] = ( triangle.giveVertex(j + 1) );
233  }
234 
235 
236  for ( int k = 1; k <= nPointsTri; k++ ) {
237  for ( int m = 1; m <= nPointsDepth; m++ ) {
238  // local coords in the parent triangle
239 
240  double refElArea = 0.5;
241  double oldWeight = weightsTri.at(k) * weightsDepth.at(m);
242  double newWeight = 2.0 * refElArea * oldWeight * triangle.getArea() / parentArea;
243 
244  GaussPoint *gp = new GaussPoint(this, count + 1,
245  {coords_xi1.at(k), coords_xi2.at(k), coords_xi3.at(m)},
246  newWeight, mode);
247  this->gaussPoints [ count ] = gp;
248  count++;
249 
250 
251  // Compute global gp coordinate in the element from local gp coord in the sub triangle
252  FloatArray global;
254  FEIVertexListGeometryWrapper(gCoords) );
255 
256 
257  // Compute local gp coordinate in the element from global gp coord in the element
258  FloatArray local;
259  this->elem->computeLocalCoordinates(local, global);
260  local.at(3) = coords_xi3.at(m); // manually set third coordinate
261  // compute global coords again, since interpolator dosn't give the z-coord
262  this->elem->computeGlobalCoordinates(global, local);
263 
264  gp->setGlobalCoordinates(global);
265  gp->setNaturalCoordinates(local);
266  gp->setSubPatchCoordinates(local);
267 
268  // Store new global gp coord for vtk output
269  newGPCoord.push_back(global);
270  }
271  }
272  }
273 
275  if ( xMan != NULL ) {
276  if ( xMan->giveVtkDebug() ) {
277  double time = 0.0;
278 
279  Element *el = this->elem;
280  if ( el != NULL ) {
281  Domain *dom = el->giveDomain();
282  if ( dom != NULL ) {
283  EngngModel *em = dom->giveEngngModel();
284  if ( em != NULL ) {
285  TimeStep *ts = em->giveCurrentStep();
286  if ( ts != NULL ) {
287  time = ts->giveTargetTime();
288  }
289  }
290  }
291  }
292 
293  int elIndex = this->elem->giveGlobalNumber();
294  std :: stringstream str;
295  str << "GaussPointsTime" << time << "El" << elIndex << ".vtk";
296  std :: string name = str.str();
297 
298  XFEMDebugTools :: WritePointsToVTK(name, newGPCoord);
299  }
300  }
301 
302 
303  return this->giveNumberOfIntegrationPoints();
304 }
305 
306 
309 {
310  // TODO: Implement
311 
312  //
313  // saves full context (saves state variables, that completely describe
314  // current state)
315  //
316 
317  // save parent data
318  contextIOResultType iores;
319 
320  if ( ( iores = IntegrationRule :: saveContext(stream, mode, obj) ) != CIO_OK ) {
321  THROW_CIOERR(iores);
322  }
323 
324  /*
325  * // save patch data
326  * if ( this->patch ) {
327  * // store patch type
328  * int _type = this->patch->givePatchType();
329  * if ( !stream.write(_type) ) {
330  * THROW_CIOERR(CIO_IOERR);
331  * }
332  *
333  * patch->saveContext(stream, mode, obj);
334  * } else {
335  * OOFEM_ERROR("can't store NULL patch");
336  * }
337  */
338  return CIO_OK;
339 }
340 
343 {
344  // TODO: Implement
345 
346  //
347  // restores full element context (saves state variables, that completely describe
348  // current state)
349  //
350 
351  contextIOResultType iores;
352 
353  if ( ( iores = IntegrationRule :: restoreContext(stream, mode, obj) ) != CIO_OK ) {
354  THROW_CIOERR(iores);
355  }
356 
357  int _ptype;
358  if ( !stream.read(_ptype) ) {
360  }
361 
362  return CIO_OK;
363 }
364 } // end namespace oofem
const FloatArray & giveVertex(int n) const
Definition: geometry.h:124
Element * elem
Element which integration rule is coupled to.
Class and object Domain.
Definition: domain.h:115
static void giveTriCoordsAndWeights(int nPoints, FloatArray &coords_xi1, FloatArray &coords_xi2, FloatArray &weights)
int firstLocalStrainIndx
firstLocalStrainIndx and lastLocalStrainIndx indexes describe range of components (strains for exampl...
static void giveLineCoordsAndWeights(int nPoints, FloatArray &coords_xi, FloatArray &weights)
Wrapper around cell with vertex coordinates stored in FloatArray**.
Definition: feinterpol.h:115
int giveNrVertices() const
Returns number of Geometry vertices.
Definition: geometry.h:144
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
int giveGlobalNumber() const
Definition: element.h:1059
EngngModel * giveEngngModel()
Returns engineering model to which receiver is associated.
Definition: domain.C:433
void setGlobalCoordinates(const FloatArray &iCoord)
Definition: gausspoint.h:171
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
Abstract base class for all finite elements.
Definition: element.h:145
General IO error.
void setWeight(double w)
Definition: gausspoint.h:182
MaterialMode
Type representing material mode of integration point.
Definition: materialmode.h:89
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
PatchIntegrationRule(int n, Element *e, const std::vector< Triangle > &iTriangles)
Constructor.
XfemManager * giveXfemManager()
Definition: domain.C:375
#define THROW_CIOERR(e)
Definition: contextioerr.h:61
void setSubPatchCoordinates(const FloatArray &c)
Definition: gausspoint.h:151
static void WritePointsToVTK(const std::string &iName, const std::vector< FloatArray > &iPoints)
bool giveVtkDebug() const
Definition: xfemmanager.h:243
Second order triangular interpolation in 3D space (6 nodes).
Definition: fei3dtrquad.h:47
Class representing a 2d triangular linear interpolation based on area coordinates.
Definition: fei2dtrlin.h:44
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj)
Restores receiver&#39;s context to stream.
virtual double giveWeight()
Returns integration weight of receiver.
Definition: gausspoint.h:181
virtual ~PatchIntegrationRule()
Destructor.
Class representing vector of real numbers.
Definition: floatarray.h:82
This class manages the xfem part.
Definition: xfemmanager.h:109
virtual double computeArea()
Computes the area (zero for all but 2d geometries).
Definition: element.C:1115
virtual void local2global(FloatArray &answer, const FloatArray &gcoords, const FEICellGeometry &cellgeo)
Evaluates global coordinates from given local ones.
Definition: fei2dtrlin.C:81
virtual int SetUpPointsOnTriangle(int nPoints, MaterialMode mode)
Sets up receiver&#39;s integration points on triangular (area coords) integration domain.
virtual double giveParentElSize() const
Returns the size (length, area or volume depending on element type) of the parent element...
Definition: element.h:906
void setNaturalCoordinates(const FloatArray &c)
Definition: gausspoint.h:139
int giveNumberOfIntegrationPoints() const
Returns number of integration points of receiver.
double getArea()
Definition: geometry.C:416
virtual bool computeLocalCoordinates(FloatArray &answer, const FloatArray &gcoords)
Computes the element local coordinates from given global coordinates.
Definition: element.C:1222
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
std::vector< Triangle > mTriangles
Domain * giveDomain() const
Definition: femcmpnn.h:100
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
virtual TimeStep * giveCurrentStep(bool force=false)
Returns current time step.
Definition: engngm.h:683
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj)
Saves receiver&#39;s context to stream.
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj)
Restores receiver&#39;s context to stream.
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj)
Saves receiver&#39;s context to stream.
Class representing integration point in finite element program.
Definition: gausspoint.h:93
Class representing solution step.
Definition: timestep.h:80
std::vector< GaussPoint * > gaussPoints
Array containing integration points.
virtual int computeGlobalCoordinates(FloatArray &answer, const FloatArray &lcoords)
Computes the global coordinates from given element&#39;s local coordinates.
Definition: element.C:1207
const FloatArray & giveNaturalCoordinates()
Returns coordinate array of receiver.
Definition: gausspoint.h:138
virtual int SetUpPointsOnWedge(int nPointsTri, int nPointsDepth, MaterialMode mode)
Sets up receiver&#39;s integration points on a wedge integration domain.
Class representing Gaussian-quadrature integration rule.

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