Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Algebraic_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  *********************************************************************/
31 #include "Algebraic_Metrics_2.h"
32 #include <vector>
33 #include <cassert>
34 #include <iostream>
35 
36 using namespace std;
37 
39 
40 void Alg_Metric_Base_2::initialize(Element_node_enumerator &ene){
41  type_ = ene.type();
42  Element_node_vectors_k_const<double> n;
43  n.set(ene.pane()->attribute("nc"),ene);
44  vector<Vector_3<double> > v(2);
45  if (type_ == COM::Connectivity::TRI3){
46  for ( int i = 0; i < 3; i ++){
47  int i1 = (i+1)%3, i2 = (i+2)%3;
48 
49  v[0][0] = n(i1,0)-n(i,0);
50  v[0][1] = n(i1,1)-n(i,1);
51  v[0][2] = n(i1,2)-n(i,2);
52 
53  v[1][0] = n(i2,0)-n(i,0);
54  v[1][1] = n(i2,1)-n(i,1);
55  v[1][2] = n(i2,2)-n(i,2);
56 
57  A[i] = J_Matrix(&v[0],2);
58  L[i] ^= A[i];
59  alpha[i] = A[i].det();
60  }
61  }
62  else if (type_ == COM::Connectivity::QUAD4){
63  for ( int i = 0; i < 4; i ++){
64  for (int j = 0; j < 3; j ++){
65  int i1 = (i+1)%4, i3 = (i+3)%4;
66 
67  v[0][j] = n(i1,j)-n(i,j);
68  v[1][j] = n(i3,0)-n(i,j);
69  }
70  A[i] = J_Matrix(&v[0],2);
71  L[i] ^= A[i];
72  alpha[i] = A[i].det();
73  }
74  }
75  else COM_assertion_msg(0,"Element type not supported for 2D Algebraic Metrics");
76 }
77 
78 
80  type_ = type;
81  vector<Vector_3<double> > v(type_);
82  if (type_ == COM::Connectivity::TRI3){
83  for ( int i = 0; i < 3; i ++){
84  v[0] = n[(i+1)%3] - n[i];
85  v[1] = n[(i+2)%3] - n[i];
86  A[i] = J_Matrix(&v[0],2);
87  L[i] ^= A[i];
88  alpha[i] = A[i].det();
89  }
90  }
91  else if (type_ == COM::Connectivity::QUAD4){
92  for ( int i = 0; i < 4; i ++){
93  for (int j = 0; j < 3; j ++){
94  v[0][j] = (n[(i+1)%4][j] - n[i][j]);
95  v[1][j] = (n[(i+3)%4][j] - n[i][j]);
96  }
97  A[i] = J_Matrix(&v[0],2);
98  L[i] ^= A[i];
99  alpha[i] = A[i].det();
100  }
101  }
102 }
103 
104 double Alg_Metric_Base_2::compute_size( double ref_area) const {
105  double tau;
106  if (type_ == COM::Connectivity::TRI3){
107  tau = alpha[0]/(2.0*ref_area);
108  return (tau < (1/tau))? tau : (1/tau);
109  }
110  else {
111  assert (type_ == COM::Connectivity::QUAD4);
112  tau = (alpha[0] + alpha[2])/(2*ref_area);
113  return (tau < (1/tau))? tau : (1/tau);
114  }
115 }
116 
118  // Triangles
119  if (type_ == COM::Connectivity::TRI3){
120  return sqrt(3.0) * alpha[0] /
121  ( L[0](0,0) + L[0](1,1) - L[0](0,1));
122  }
123 
124  // Quads
125  else{
126  assert (type_ == COM::Connectivity::QUAD4);
127  double denom = 0;
128  for (int i = 0; i < 4; i ++){
129  denom += ( (L[i](0,0) + L[i](1,1))/alpha[i] );
130  }
131  return 8.0/denom;
132  }
133 }
134 
136  // only defined for quads, so return 1 if triangle
137  if (type_ == COM::Connectivity::TRI3) {
138  return 1;
139  }
140  // flag checks for divide by 0
141  else {
142  double denom = 0;
143  int flag = 0;
144  for (int i = 0; i < 4 ; i++) {
145  if (alpha[i]==0) { flag = 1;}
146  else {
147  denom += ( sqrt ( L[i](0,0) * L[i](1,1)) / alpha[i] );
148  }
149  }
150  if (flag){ return 0; }
151  else { return 4.0/denom; }
152  }
153 }
154 
155 void Shape_Metric_2::compute(double atts[]) const {
156  atts[0] = compute_shape();
157 }
158 
159 void Size_Metric_2::compute(double atts[]) const {
160  atts[0] = compute_size(ref_area);
161 }
162 
163 void Size_Shape_Metric_2::compute(double atts[]) const {
164  atts[0] = compute_size(ref_area) * compute_shape();
165 }
166 
167 void Skew_Metric_2::compute(double atts[]) const {
168  atts[0] = compute_skew();
169 }
170 
171 void Size_Skew_Metric_2::compute(double atts[]) const {
172  atts[0] = compute_size(ref_area) * compute_skew();
173 }
174 
175 ostream & operator<<(ostream &output, const Alg_Metric_Base_2 &m){
176  for(int i =0; i < m.type_; i ++){
177  output << "A[" << i << "]:" << endl << m.A[i];
178  output << "L[" << i << "]:" << endl << m.L[i];
179  output << "alpha"<<i << ": " << m.alpha[i] << endl << endl;
180  }
181  return output;
182 }
183 
185 
186 
187 
188 
189 
190 
double compute_shape() const
Compute the shape metric.
#define COM_assertion_msg(EX, msg)
virtual void compute(double atts[]) const
Calculate the shape metric value.
double compute_skew() const
Compute the skew metric.
double sqrt(double d)
Definition: double.h:73
*********************************************************************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
virtual void initialize(Vector_3< double > n[], int type)
Initialize a 2D Algebraic Metric.
rational * A
Definition: vinci_lass.c:67
virtual void compute(double atts[]) const
Calculate the metric value.
virtual void compute(double atts[]) const
Calculate the metric value.
blockLoc i
Definition: read.cpp:79
2D Algebraic Metric Base Class
virtual void compute(double atts[]) const
Calculate the metric value.
const NT & n
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
double compute_size(double ref_area=1.) const
Compute the size metric.
2D algebraic quality Metric declaration..
j indices j
Definition: Indexing.h:6
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
CGAL_BEGIN_NAMESPACE void const NT NT NT NT & denom
virtual void compute(double atts[]) const
Calculate the shape metric value.