OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
geometry.h
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 #ifndef geometry_h
36 #define geometry_h
37 
38 #include "oofemcfg.h"
39 #include "error.h"
40 #include "floatarray.h"
41 #include "inputrecord.h"
42 #include "contextioresulttype.h"
43 #include "contextmode.h"
44 
45 #include <list>
46 #ifdef __BOOST_MODULE
47  #include <BoostInterface.h>
48 #endif
49 
51 
52 #define _IFT_Circle_Name "circle"
53 #define _IFT_Circle_radius "radius"
54 #define _IFT_Circle_center "center"
55 
56 #define _IFT_Line_Name "line"
57 #define _IFT_Line_start "start"
58 #define _IFT_Line_end "end"
59 
60 #define _IFT_PointSwarm_Name "pointswarm" // just temporary
61 #define _IFT_PointSwarm_nodeID "nodeid"
62 
63 
64 #define _IFT_PolygonLine_Name "polygonline"
65 #define _IFT_PolygonLine_points "points"
66 
68 
69 namespace oofem {
70 
71 class Element;
72 class DynamicInputRecord;
73 class oofegGraphicContext;
74 class TipInfo;
75 
81 class OOFEM_EXPORT BasicGeometry //: public Geometry
82 {
83 protected:
85  std :: vector< FloatArray >mVertices;
86 public:
88  BasicGeometry();
89 
91  BasicGeometry(const BasicGeometry & iBasicGeometry);
92 
94  virtual ~BasicGeometry();
95 
96  virtual BasicGeometry *Clone() = 0;
97 
99  virtual double computeDistanceTo(const FloatArray *point) { return 0; }
100 
101 
102  // For debugging
103  virtual void printVTK(int iTStepIndex, int iIndex) {};
104 
107  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const = 0;
108  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const = 0;
109  virtual void computeLocalCoordinates(FloatArray &oLocCoord, const FloatArray &iPoint) const { OOFEM_ERROR("not implemented."); }
110  virtual void giveSubPolygon(std :: vector< FloatArray > &oPoints, const double &iXiStart, const double &iXiEnd) const { OOFEM_ERROR("?"); }
111  virtual void giveGlobalCoordinates(FloatArray &oGlobalCoord, const double &iArcPos) const {OOFEM_ERROR("Not implemented.")};
112 
114  virtual void giveTangent(FloatArray &oTangent, const double &iArcPosition) const {printf("BasicGeometry::giveTangent() not implemented.\n");}
115 
116 
118  virtual bool intersects(Element *element) { return false; }
120  virtual int computeNumberOfIntersectionPoints(Element *element) { return 0; }
122  virtual void computeIntersectionPoints(Element *element, std :: vector< FloatArray > &oIntersectionPoints) { }
123 
124  inline const FloatArray &giveVertex(int n) const { return mVertices [ n - 1 ]; }
125 
126  void setVertices(const std::vector<FloatArray> &iVertices) {mVertices = iVertices;}
127 
128  void removeDuplicatePoints(const double &iTolSquare);
129 
130  void insertVertexFront(const FloatArray &iP) { mVertices.insert(mVertices.begin(), iP); }
131  void insertVertexBack(const FloatArray &iP) { mVertices.push_back(iP); }
132 
133  void clear() {mVertices.clear();}
134 
135  void translate(const FloatArray &iTrans);
136 
139  virtual void giveInputRecord(DynamicInputRecord &input) { OOFEM_ERROR("not implemented"); }
141  virtual const char *giveClassName() const { return NULL; }
142  std :: string errorInfo(const char *func) const { return std :: string(giveClassName()) + func; }
144  int giveNrVertices() const { return (int)mVertices.size(); }
145  virtual bool isOutside(BasicGeometry *bg) { return false; }
146  virtual bool isInside(Element *el) { return false; }
147  virtual bool isInside(FloatArray &point) { return false; }
148  virtual void printYourself() { }
157  virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj = NULL) { return CIO_OK; }
166  virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj = NULL) { return CIO_OK; }
167 
168 #ifdef __OOFEG
169  virtual void draw(oofegGraphicContext &gc) { }
170 #endif
171 
172 
178  static double computeLineDistance(const FloatArray &iP1, const FloatArray &iP2, const FloatArray &iQ1, const FloatArray &iQ2);
179 
183  virtual bool giveTips(TipInfo &oStartTipInfo, TipInfo &oEndTipInfo) const {return false;}
184 
185  virtual void giveBoundingSphere(FloatArray &oCenter, double &oRadius) {OOFEM_ERROR("Not implemented.")};
186 
187 };
188 
189 class OOFEM_EXPORT Line : public BasicGeometry
190 {
191 public:
192  Line() : BasicGeometry() { }
193  virtual ~Line() { }
194  Line(const FloatArray &iPointA, const FloatArray &iPointB);
195 
196  virtual BasicGeometry *Clone() { return new Line(*this); }
197 
198  virtual double computeDistanceTo(const FloatArray *point);
200 
201  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const { OOFEM_ERROR("not implemented"); }
202 
203  double computeTangentialDistanceToEnd(FloatArray *point);
204 
205  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const;
206 
207  void computeProjection(FloatArray &answer);
208  virtual int computeNumberOfIntersectionPoints(Element *element);
209  virtual void computeIntersectionPoints(Element *element, std :: vector< FloatArray > &oIntersectionPoints);
210  double computeInclinationAngle();
211  void computeTransformationMatrix(FloatMatrix &answer);
212  void transformIntoPolar(FloatArray *point, FloatArray &answer);
213  virtual IRResultType initializeFrom(InputRecord *ir);
214  bool isPointInside(FloatArray *point);
215  virtual bool intersects(Element *element);
216  virtual bool isOutside(BasicGeometry *bg);
217 
218  double giveLength() const {return mVertices[0].distance( mVertices[1] );}
219 };
220 
221 class OOFEM_EXPORT Triangle : public BasicGeometry
222 {
223 public:
224  Triangle(const FloatArray & iP1, const FloatArray & iP2, const FloatArray & iP3);
225  virtual ~Triangle() { }
226 
227  virtual BasicGeometry *Clone() { return new Triangle(*this); }
228 
229  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const { OOFEM_ERROR("not implemented"); }
230  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const { OOFEM_ERROR("not implemented"); }
231 
232  double getArea();
233  void computeBarycentrCoor(FloatArray &answer) const;
234  double getRadiusOfCircumCircle();
235  void computeCenterOfCircumCircle(FloatArray &answer) const;
236  virtual void printYourself();
237  virtual int computeNumberOfIntersectionPoints(Element *element) { return 0; }
238  bool isOrientedAnticlockwise();
239  void changeToAnticlockwise();
240 
246  bool pointIsInTriangle(const FloatArray &iP) const;
247 
251  static void refineTriangle(std::vector<Triangle> &oRefinedTri, const Triangle &iTri);
252 };
253 
254 class OOFEM_EXPORT Circle : public BasicGeometry
255 {
256 protected:
257  double radius;
258  const double mTangSignDist;
259 public:
260  Circle() : BasicGeometry(), radius(0.0), mTangSignDist(1.0) { }
261  virtual ~Circle() { }
262  Circle(FloatArray &center, double radius);
263 
264  virtual BasicGeometry *Clone() { return new Circle(*this); }
265 
266  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const;
267 
268  // Irrelevant for a closed interface: we can always consider ourselves to be "inside" a closed interface in
269  // tangential direction. Therefore, we may return any positive number.
270  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const { oDist = mTangSignDist; }
271 
272  virtual void giveGlobalCoordinates(FloatArray &oGlobalCoord, const double &iArcPos) const;
273 
274  virtual void giveTangent(FloatArray &oTangent, const double &iArcPosition) const { }
275 
276  virtual IRResultType initializeFrom(InputRecord *ir);
277  virtual const char *giveClassName() const { return "Circle"; }
278  virtual bool intersects(Element *element);
279  virtual void computeIntersectionPoints(Element *element, std :: vector< FloatArray > &oIntersectionPoints);
280  virtual void computeIntersectionPoints(Line *l, std :: vector< FloatArray > &oIntersectionPoints);
281  virtual int computeNumberOfIntersectionPoints(Element *element);
282  virtual bool isOutside(BasicGeometry *bg);
283  virtual bool isInside(Element *element);
284  virtual bool isInside(FloatArray &point);
285  virtual void printYourself();
286 
287  double giveRadius() const {return radius;}
288 
289  virtual void giveBoundingSphere(FloatArray &oCenter, double &oRadius);
290 
291 };
292 
293 class OOFEM_EXPORT PolygonLine : public BasicGeometry
294 {
295  bool mDebugVtk;
296 public:
297  PolygonLine();
298  virtual ~PolygonLine() { }
299 
300  virtual BasicGeometry *Clone() { return new PolygonLine(*this); }
301 
302  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const;
303  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const;
304 
306  virtual void computeLocalCoordinates(FloatArray &oLocCoord, const FloatArray &iPoint) const;
307  double computeLength() const;
308 
309  virtual void giveSubPolygon(std :: vector< FloatArray > &oPoints, const double &iXiStart, const double &iXiEnd) const;
310  virtual void giveGlobalCoordinates(FloatArray &oGlobalCoord, const double &iArcPos) const;
311  void giveNormal(FloatArray &oNormal, const double &iArcPosition) const;
312  virtual void giveTangent(FloatArray &oTangent, const double &iArcPosition) const;
313 
314  virtual IRResultType initializeFrom(InputRecord *ir);
315  virtual void giveInputRecord(DynamicInputRecord &input);
316  virtual const char *giveClassName() const { return "PolygonLine"; }
317 
318 #ifdef __BOOST_MODULE
319  virtual bool boundingBoxIntersects(Element *element);
320 #endif
321 
322  virtual bool intersects(Element *element);
323  virtual void computeIntersectionPoints(Element *element, std :: vector< FloatArray > &oIntersectionPoints);
324  virtual void computeIntersectionPoints(Line *l, std :: vector< FloatArray > &oIntersectionPoints);
325  void computeIntersectionPoints(const PolygonLine &iPolygonLine, std :: vector< FloatArray > &oIntersectionPoints) const;
326  void computeIntersectionPoints(const FloatArray &iXStart, const FloatArray &iXEnd, std :: vector< FloatArray > &oIntersectionPoints) const;
327 
328  virtual int computeNumberOfIntersectionPoints(Element *element);
329  virtual bool isOutside(BasicGeometry *bg);
330  virtual bool isInside(Element *element);
331  virtual bool isInside(FloatArray &point);
332 
333 #ifdef __BOOST_MODULE
334  virtual void calcBoundingBox(bPoint2 &oLC, bPoint2 &oUC);
335 #endif
336 
337  virtual void printYourself();
338 
339  // For debugging
340  virtual void printVTK(int iTStepIndex, int iLineIndex);
341 
342 #ifdef __BOOST_MODULE
343  // Upper and lower corner
344  bPoint2 LC, UC;
345 #endif
346 
347  virtual bool giveTips(TipInfo &oStartTipInfo, TipInfo &oEndTipInfo) const;
348 
349  virtual void giveBoundingSphere(FloatArray &oCenter, double &oRadius);
350 
355  void cropPolygon(const double &iArcPosStart, const double &iArcPosEnd);
356 
357 };
358 
359 
360 class OOFEM_EXPORT PointSwarm : public BasicGeometry
361 {
362 protected:
363  std :: list< int >idList;
364 public:
366  virtual ~PointSwarm() { }
367  PointSwarm(std :: list< int >pointsID);
368 
369  virtual BasicGeometry *Clone() { return new PointSwarm(*this); }
370 
371  virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const { OOFEM_ERROR("not implemented"); }
372  virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const { OOFEM_ERROR("not implemented"); }
373 
375  // virtual double computeDistanceTo(FloatArray *point);
376  virtual IRResultType initializeFrom(InputRecord *ir);
377  // virtual const char *giveClassName() const { return "Circle"; }
378  // virtual bool intersects(Element *element);
379  // virtual void computeIntersectionPoints(Element *element, std :: vector< FloatArray > *intersecPoints);
380  // virtual void computeIntersectionPoints(Line *l, std :: vector< FloatArray > *intersecPoints);
381  // virtual bool isOutside(BasicGeometry *bg);
382  // virtual bool isInside(Element *element);
383  // virtual bool isInside(FloatArray &point);
384 };
385 } // end namespace oofem
386 #endif // geometry_h
virtual void giveInputRecord(DynamicInputRecord &input)
Definition: geometry.h:139
const FloatArray & giveVertex(int n) const
Definition: geometry.h:124
virtual ~Line()
Definition: geometry.h:193
int giveNrVertices() const
Returns number of Geometry vertices.
Definition: geometry.h:144
void insertVertexBack(const FloatArray &iP)
Definition: geometry.h:131
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
virtual BasicGeometry * Clone()
Definition: geometry.h:300
virtual ~PointSwarm()
Definition: geometry.h:366
TipInfo gathers useful information about a crack tip, like its position and tangent direction...
Definition: tipinfo.h:24
oofem::oofegGraphicContext gc[OOFEG_LAST_LAYER]
virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const
Definition: geometry.h:230
Abstract base class for all finite elements.
Definition: element.h:145
virtual void computeLocalCoordinates(FloatArray &oLocCoord, const FloatArray &iPoint) const
Definition: geometry.h:109
virtual void printYourself()
Definition: geometry.h:148
virtual void giveGlobalCoordinates(FloatArray &oGlobalCoord, const double &iArcPos) const
Definition: geometry.h:111
virtual const char * giveClassName() const
Gives class name.
Definition: geometry.h:141
virtual BasicGeometry * Clone()
Definition: geometry.h:264
virtual void computeIntersectionPoints(Element *element, std::vector< FloatArray > &oIntersectionPoints)
Gives intersection points between this Geometry and Element.
Definition: geometry.h:122
virtual bool intersects(Element *element)
Checks whether an element is interacted, Element reference will be later replaced by Geometry...
Definition: geometry.h:118
Abstract representation of Geometry.
Definition: geometry.h:81
virtual BasicGeometry * Clone()
Definition: geometry.h:369
virtual void giveTangent(FloatArray &oTangent, const double &iArcPosition) const
Computes tangential direction at given local coordinate (arcPos)
Definition: geometry.h:114
virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const
Definition: geometry.h:372
virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const
Functions for computing signed distance in normal and tangential direction.
Definition: geometry.h:229
virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const
Definition: geometry.h:270
virtual double computeDistanceTo(const FloatArray *point)
Computes normal signed distance between this object and a point.
Definition: geometry.h:99
virtual bool isInside(Element *el)
Definition: geometry.h:146
virtual BasicGeometry * Clone()
Definition: geometry.h:227
virtual void giveBoundingSphere(FloatArray &oCenter, double &oRadius)
Definition: geometry.h:185
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes the Geometry from the InputRecord.
Definition: geometry.h:138
virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const
Functions for computing signed distance in normal and tangential direction.
Definition: geometry.h:371
virtual void giveTangent(FloatArray &oTangent, const double &iArcPosition) const
Computes tangential direction at given local coordinate (arcPos)
Definition: geometry.h:274
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the state of receiver from output stream.
Definition: geometry.h:166
std::vector< FloatArray > mVertices
List of geometry vertices.
Definition: geometry.h:85
#define OOFEM_ERROR(...)
Definition: error.h:61
void setVertices(const std::vector< FloatArray > &iVertices)
Definition: geometry.h:126
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores the state of receiver to output stream.
Definition: geometry.h:157
virtual void draw(oofegGraphicContext &gc)
Definition: geometry.h:169
virtual bool isOutside(BasicGeometry *bg)
Definition: geometry.h:145
std::list< int > idList
Definition: geometry.h:363
virtual const char * giveClassName() const
Gives class name.
Definition: geometry.h:316
virtual int computeNumberOfIntersectionPoints(Element *element)
Gives number of intersection points of Geometry entity with an element, Element reference will be lat...
Definition: geometry.h:120
virtual BasicGeometry * Clone()
Definition: geometry.h:196
virtual void printVTK(int iTStepIndex, int iIndex)
Definition: geometry.h:103
Class representing vector of real numbers.
Definition: floatarray.h:82
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
virtual ~PolygonLine()
Definition: geometry.h:298
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
virtual int computeNumberOfIntersectionPoints(Element *element)
Gives number of intersection points of Geometry entity with an element, Element reference will be lat...
Definition: geometry.h:237
Class representing the general Input Record.
Definition: inputrecord.h:101
const double mTangSignDist
Definition: geometry.h:258
double radius
Definition: geometry.h:257
Class representing the a dynamic Input Record.
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
Definition: contextmode.h:43
void insertVertexFront(const FloatArray &iP)
Definition: geometry.h:130
virtual ~Circle()
Definition: geometry.h:261
virtual bool giveTips(TipInfo &oStartTipInfo, TipInfo &oEndTipInfo) const
Returns start and end tip of the geometry, if applicable.
Definition: geometry.h:183
virtual void giveSubPolygon(std::vector< FloatArray > &oPoints, const double &iXiStart, const double &iXiEnd) const
Definition: geometry.h:110
double giveRadius() const
Definition: geometry.h:287
virtual const char * giveClassName() const
Gives class name.
Definition: geometry.h:277
the oofem namespace is to define a context or scope in which all oofem names are defined.
double giveLength() const
Definition: geometry.h:218
virtual ~Triangle()
Definition: geometry.h:225
virtual void computeNormalSignDist(double &oDist, const FloatArray &iPoint) const
Computes tangential distance to a point.
Definition: geometry.h:201
std::string errorInfo(const char *func) const
Definition: geometry.h:142
virtual bool isInside(FloatArray &point)
Definition: geometry.h:147

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:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011