Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geometric_Metrics_2.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Geometric_Metrics_2.C,v 1.5 2008/12/06 08:45:24 mtcampbe Exp $
24 
35 #include "geometry.h"
36 #include "Geometric_Metrics_2.h"
37 #include <cmath>
38 #include <vector>
39 #include <cassert>
40 #include <iostream>
41 
43 
44 using namespace std;
45 
46 void Geo_Metric_Base_2::initialize(Element_node_enumerator &ene){
47  type_ = ene.type();
48  Element_node_vectors_k_const<double> n;
49  n.set(ene.pane()->attribute("nc"),ene);
50  if(type_ == COM::Connectivity::TRI3){
51  v[0][0]=n(2,0)-n(1,0); v[0][1]=n(2,1)-n(1,1); v[0][2]=n(2,2)-n(1,2);
52  v[1][0]=n(1,0)-n(2,0); v[1][1]=n(1,1)-n(2,1); v[1][2]=n(1,2)-n(2,2);
53  v[2][0]=n(2,0)-n(0,0); v[2][1]=n(2,1)-n(0,1); v[2][2]=n(2,2)-n(0,2);
54  v[3][0]=n(1,0)-n(0,0); v[3][1]=n(1,1)-n(0,1); v[3][2]=n(1,2)-n(0,2);
55  }
56  else if (type_ == COM::Connectivity::QUAD4){
57  v[0][0]=n(1,0)-n(0,0); v[0][1]=n(1,1)-n(0,1); v[0][2]=n(1,2)-n(0,2);
58  v[1][0]=n(3,0)-n(0,0); v[1][1]=n(3,1)-n(0,1); v[1][2]=n(3,2)-n(0,2);
59  v[2][0]=n(1,0)-n(2,0); v[2][1]=n(1,1)-n(2,1); v[2][2]=n(1,2)-n(2,2);
60  v[3][0]=n(3,0)-n(2,0); v[3][1]=n(3,1)-n(2,1); v[3][2]=n(3,2)-n(2,2);
61  }
62  else COM_assertion_msg(0,"Element type not supported for 2D geometric metrics");
63 }
64 
66  int type){
67  type_ = type;
68  if (type_ == COM::Connectivity::TRI3){
69  v[0]= n[2]-n[1]; v[1]= n[1]-n[2]; v[2]= n[2]-n[0]; v[3]= n[1]-n[0];
70  }
71  else if (type_ == COM::Connectivity::QUAD4){
72  v[0]= n[1]-n[0]; v[1]= n[3]-n[0]; v[2]= n[1]-n[2]; v[3]= n[3] - n[2];
73  }
74 }
75 
76 void Geo_Metric_Base_2::compute_angles(double& min, double& max) const{
77  if (type_ == COM::Connectivity::TRI3){
78  double a1,a2,a3;
79  a1= angle(v[0],v[2]); a2= angle(v[1],v[3]); a3= angle(v[2],v[3]);
80  min_max3(a1,a2,a3,min,max);
81  }
82  if (type_ == COM::Connectivity::QUAD4){
83  double a1,a2,a3,a4;
84  a1 = angle (v[0],v[1]); a2 = angle (v[0],v[2]);
85  a3 = angle (v[2],v[3]); a4 = angle (v[1],v[3]);
86  min_max4(a1,a2,a3,a4,min,max);
87  }
88 }
89 
90 void Geo_Metric_Base_2::compute_aspects(double& R, double& r, double& l) const {
91  // Defined for Triangles only
92  assert (type_ == COM::Connectivity::TRI3);
93 
94  double a = edge_length(v[0]);
95  double b = edge_length(v[2]);
96  double c = edge_length(v[3]);
97 
98  // Use formulas from mathworld to find circumradius (R),
99  // inradius (r), and shortest edge length (l)
100 
101  l = ( a < b )? a : b;
102  l = ( l < c ) ? l : c;
103  R = (a*b*c) / sqrt( (a+b+c)*(b+c-a)*(c+a-b)*(a+b-c) );
104  r = .5*sqrt( ((b+c-a)*(c+a-b)*(a+b-c))/(a+b+c) );
105 
106 }
107 
108 void Angle_Metric_2::compute(double atts[]) const {
109  compute_angles(atts[0],atts[1]);
110 }
111 
112 double Angle_Metric_2::maxValue() const {
113 return 180.0;
114 }
115 
116 double Angle_Metric_2::minValue() const {
117 return 0.0;
118 }
119 
120 void Aspect_Metric_2::compute(double atts[]) const {
121  if (type_ == COM::Connectivity::QUAD4) {
122  atts[0] = -1;
123  atts[1] = -1;
124  }
125  else{
126  double R, r, l;
127  compute_aspects(R,r,l);
128  atts[0] = (r/R)*2.0;
129  atts[1] = (l/R)*.5773502692;
130  }
131 }
132 
133 double Aspect_Metric_2::maxValue() const {
134 return 1.0;
135 }
136 
137 double Aspect_Metric_2::minValue() const {
138 return 0.0;
139 }
140 
142 
143 
144 
145 
146 
147 
#define COM_assertion_msg(EX, msg)
virtual void compute(double atts[]) const
Calculate scaled R/r and R/l.
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
double maxValue() const
The maximum value for this metric.
double sqrt(double d)
Definition: double.h:73
void min_max4(double a1, double a2, double a3, double a4, double &min, double &max)
Find minimum and maximum of 4 numbers.
Definition: geometry.C:41
double minValue() const
The minimum value for this metric.
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
MOP_BEGIN_NAMESPACE void min_max3(double a1, double a2, double a3, double &min, double &max)
Find minimum and maximum of 3 numbers.
Definition: geometry.C:36
double minValue() const
The minimum value for this metric.
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
Definition: geometry.C:61
void compute_angles(double &min, double &max) const
Compute the min and max angles.
virtual void compute(double atts[]) const
Calculate max and min angles.
virtual void initialize(Vector_3< double > n[], int type)
Initialize a 2D Geometric Metric.
const NT & n
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
2D geometric quality Metric declarations.
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
double maxValue() const
The maximum value for this metric.
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
double edge_length(const Vector_3< double > &v)
Compute the edge length of a vector.
Definition: geometry.C:89
Geometric helper function header file.
void compute_aspects(double &R, double &r, double &l) const
Compute the circumradius, inradius, and shortest edge length.