OOFEM  2.4 OOFEM.org - Object Oriented Finite Element Solver
delaunaytriangle.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
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 "delaunaytriangle.h"
36 #include "dofmanager.h"
37 #include "math.h"
38 #include "octreelocalizert.h"
39 #include "mathfem.h"
40
41 namespace oofem {
42 DelaunayTriangle :: DelaunayTriangle(Domain *d, int node1, int node2, int node3) :
43  domain(d),
44  nodes(3),
45
46  circumCircle(3),
47  validFlag(true)
48 {
49  nodes.at(1) = node1;
50  nodes.at(2) = node2;
51  nodes.at(3) = node3;
52
54 }
55
57 {
58 }
59
60 void
61 DelaunayTriangle :: setCircumCircle(double x, double y, double r)
62 {
63  this->circumCircle.at(1) = x;
64  this->circumCircle.at(2) = y;
65  this->circumCircle.at(3) = r;
66 }
67
68 double
70 {
71  double x = coords.at(1);
72  double y = coords.at(2);
73
74  double xC = giveXCenterCoordinate();
75  double yC = giveYCenterCoordinate();
76
77  return ( sqrt( ( xC - x ) * ( xC - x ) + ( yC - y ) * ( yC - y ) ) );
78 }
79
80 void
82 {
83  double x1, x2, x3;
84  double y1, y2, y3;
85
86  double a, bx, by, c;
87
88  DofManager *dmanA, *dmanB, *dmanC;
89
90  dmanA = domain->giveDofManager( giveNode(1) );
91  x1 = dmanA->giveCoordinate(1);
92  y1 = dmanA->giveCoordinate(2);
93
94  dmanB = domain->giveDofManager( giveNode(2) );
95  x2 = dmanB->giveCoordinate(1);
96  y2 = dmanB->giveCoordinate(2);
97
98  dmanC = domain->giveDofManager( giveNode(3) );
99  x3 = dmanC->giveCoordinate(1);
100  y3 = dmanC->giveCoordinate(2);
101
102  a = x1 * y2 + y1 * x3 + x2 * y3 - 1.0 * ( x1 * y3 + y1 * x2 + y2 * x3 );
103  bx = -1.0 * ( ( ( x1 * x1 + y1 * y1 ) * y2 + y1 * ( x3 * x3 + y3 * y3 ) + ( x2 * x2 + y2 * y2 ) * y3 )
104  - 1.0 * ( ( x1 * x1 + y1 * y1 ) * y3 + y1 * ( x2 * x2 + y2 * y2 ) + y2 * ( x3 * x3 + y3 * y3 ) ) );
105  by = ( ( ( x1 * x1 + y1 * y1 ) * x2 + x1 * ( x3 * x3 + y3 * y3 ) + ( x2 * x2 + y2 * y2 ) * x3 )
106  - 1.0 * ( ( x1 * x1 + y1 * y1 ) * x3 + x1 * ( x2 * x2 + y2 * y2 ) + x2 * ( x3 * x3 + y3 * y3 ) ) );
107  c = ( ( ( x1 * x1 + y1 * y1 ) * x2 * y3 + x1 * y2 * ( x3 * x3 + y3 * y3 ) + y1 * ( x2 * x2 + y2 * y2 ) * x3 )
108  - 1.0 * ( ( x1 * x1 + y1 * y1 ) * y2 * x3 + x1 * ( x2 * x2 + y2 * y2 ) * y3 + y1 * x2 * ( x3 * x3 + y3 * y3 ) ) );
109
110  double xCenterCoordinate = ( -1.0 * bx / ( 2 * a ) );
111  double yCenterCoordinate = ( -1.0 * by / ( 2 * a ) );
112  double absA = a < 0 ? -1.0 * a : a;
113
114  double radius = ( ( sqrt(bx * bx + by * by + 4.0 * a * c) ) / ( 2.0 * absA ) );
115
117 }
118
119 std :: list< LocalInsertionData< DelaunayTriangle * > > *
121 {
123 }
124
125 double
127 {
128  double length1 = giveEdgeLength(1, 2);
129  double length2 = giveEdgeLength(2, 3);
130  double length3 = giveEdgeLength(3, 1);
131  return min( length1, min(length2, length3) );
132 }
133
134 double
136 {
137  DofManager *dmanA = domain->giveDofManager( giveNode(nodeA) );
138  DofManager *dmanB = domain->giveDofManager( giveNode(nodeB) );
139
140  return dmanA->giveCoordinates()->distance( dmanB->giveCoordinates() );
141 }
142 } // end namespace oofem
143
Class and object Domain.
Definition: domain.h:115
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
double giveShortestEdgeLength()
Gives the length of the shortest triangle edge.
void setCircumCircle(double x, double y, double r)
Sets up the parameters of the calculated circumscribed circle.
virtual FloatArray * giveCoordinates()
Definition: dofmanager.h:382
double giveDistanceToCenter(const FloatArray &coords)
Calculates the distance of a passed point to the center of the circumscribed circle.
Base class for dof managers.
Definition: dofmanager.h:113
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
std::list< LocalInsertionData< DelaunayTriangle * > > * giveListOfCellsAndPosition()
Returns a list of octree cells and with iterator position in their member lists.
FloatArray circumCircle
Parameters of the circumscribed circle: coordinates of center (x,y) and its radius.
double distance(const FloatArray &x) const
Computes the distance between position represented by receiver and position given as parameter...
Definition: floatarray.C:489
IntArray nodes
Nodes defining the triangle.
double giveEdgeLength(int nodeA, int nodeB)
Gives the length of the edge between two nodes.
double giveYCenterCoordinate() const
Gives the y coordinate of the center of the circumscribed circle.
void computeCircumcircle()
Calculates the parameters of the circumscribed circle.
double giveXCenterCoordinate() const
Gives the x coordinate of the center of the circumscribed circle.
Class representing vector of real numbers.
Definition: floatarray.h:82
int giveNode(int i)
Gives the i-node of the triangle.
int min(int i, int j)
Returns smaller value from two given decimals.
Definition: mathfem.h:59
Domain * domain
Domain where the nodes are defined.
~DelaunayTriangle()
Destructor.
virtual double giveCoordinate(int i)
Definition: dofmanager.h:380
the oofem namespace is to define a context or scope in which all oofem names are defined.
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
std::list< LocalInsertionData< DelaunayTriangle * > > listOfCellsContainedInAndPosition
In order to allow fast search in octree, every triangle stores list of octree cells where its circums...
DelaunayTriangle(Domain *d, int node1, int node2, int node3)
Constructor.