Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Algebraic_Metrics_3.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_3.h"
32 #include <vector>
33 #include <cassert>
34 #include <iostream>
35 
37 
38 using namespace std;
39 
40 void Alg_Metric_Base_3::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::TET4){
46  double premult = 1.0;
47  for ( int i = 0; i < 4; i ++){
48  for (int j = 0; j < 3; j ++){
49  v[0][j] = premult * (n((i+1)%4,j) - n(i,j));
50  v[1][j] = premult * (n((i+2)%4,j) - n(i,j));
51  v[2][j] = premult * (n((i+3)%4,j) - n(i,j));
52  }
53  A[i] = J_Matrix(&v[0],3);
54  L[i] ^= A[i];
55  alpha[i] = A[i].det();
56  premult *= -1.0;
57  }
58  }
59  else if (type_ == COM::Connectivity::HEX8){
60  double premult = 1.0;
61  for ( int i = 0; i < 8; i ++){
62 
63  if ( (i==0) || (i==3) || (i==5) || (i==6) ) { premult = 1.0; }
64  else if ( (i==1) || (i==2) || (i==4) || (i==7) ) { premult = -1.0; }
65  int a,b,c;
66  if ( (i == 0) || (i == 4) ) { a=1; b=3; c=4; }
67  else if ( (i ==3) || (i==7) ) { a=4;b=5;c=7; }
68  else {a=1;b=4;c=7;}
69 
70  for (int j = 0; j < 3; j ++){
71  v[0][j] = premult*( n((i+a)%8,j) - n(i,j));
72  v[1][j] = premult*( n((i+b)%8,j) - n(i,j));
73  v[2][j] = premult*( n((i+c)%8,j) - n(i,j));
74  }
75  A[i] = J_Matrix(&v[0],3);
76  L[i] ^= A[i];
77  alpha[i] = A[i].det();
78  }
79  }
80 }
81 
83  type_ = type;
84  vector<Vector_3<double> > v(3);
85  if (type_ == COM::Connectivity::TET4){
86  double premult = 1.0;
87  for ( int i = 0; i < 4; i ++){
88  for (int j = 0; j < 3; j ++){
89  v[0][j] = premult * (n[(i+1)%4][j] - n[i][j]);
90  v[1][j] = premult * (n[(i+2)%4][j] - n[i][j]);
91  v[2][j] = premult * (n[(i+3)%4][j] - n[i][j]);
92  }
93  A[i] = J_Matrix(&v[0],3);
94  L[i] ^= A[i];
95  alpha[i] = A[i].det();
96  premult *= -1.0;
97  }
98  }
99  else if (type_ == COM::Connectivity::HEX8){
100  double premult = 1.0;
101  for ( int i = 0; i < 8; i ++){
102 
103  if ( (i==0) || (i==3) || (i==5) || (i==6) ) { premult = 1.0; }
104  else if ( (i==1) || (i==2) || (i==4) || (i==7) ) { premult = -1.0; }
105  int a,b,c;
106  if ( (i == 0) || (i == 4) ) { a=1; b=3; c=4; }
107  else if ( (i ==3) || (i==7) ) { a=4;b=5;c=7; }
108  else {a=1;b=4;c=7;}
109 
110  for (int j = 0; j < 3; j ++){
111  v[0][j] = premult*( n[(i+a)%8][j] - n[i][j]);
112  v[1][j] = premult*( n[(i+b)%8][j] - n[i][j]);
113  v[2][j] = premult*( n[(i+c)%8][j] - n[i][j]);
114  }
115  A[i] = J_Matrix(&v[0],3);
116  L[i] ^= A[i];
117  alpha[i] = A[i].det();
118  }
119  }
120 }
121 
122 double Alg_Metric_Base_3::compute_size( double ref_vol) const {
123  double size = 0.0;
124  if (type_ == COM::Connectivity::TET4){
125  size = (alpha[0]/6.0)/ref_vol;
126  size = (size < (1/size))? size : (1/size);
127  }
128  if (type_ == COM::Connectivity::HEX8){
129  for (int i = 0; i < 8; i++){
130  size += alpha[i];
131  }
132  if (size < 0) {size = 0;}
133  else {
134  size = size / ( 8.0 * ref_vol );
135  size = (size < (1/size))? size: (1/size);
136  }
137  }
138  return size;
139 }
140 
142  if (type_ == COM::Connectivity::TET4){
143  double num = (3.0 * pow(alpha[0]*sqrt(2.0),(2.0/3.0)) );
144  double denom = 1.5*(L[0](0,0)+L[0](1,1)+L[0](2,2))-
145  (L[0](0,1)+L[0](1,2)+L[0](0,2));
146  return num/denom;
147  }
148  else{
149  assert (type_ == COM::Connectivity::HEX8);
150  double denom = 0;
151  for (int i = 0; i < 8; i ++){
152  denom += (L[i](0,0) + L[i](1,1) + L[i](2,2))/(pow(abs(alpha[i]),(2.0/3.0)));
153  }
154  return 24.0/denom;
155  }
156 }
157 
159  // Not defined for Tets, so we return 1
160  if (type_ == COM::Connectivity::TET4) {
161  return 1.0;
162  }
163 
164  // For quads, set flag in case of divide by zero (degenerate element)
165  else{
166  assert (type_ == COM::Connectivity::HEX8);
167  double denom = 0.0;
168  int flag = 0;
169  for (int i = 0; i < 8; i ++){
170  double root = sqrt(L[i](0,0)*L[i](1,1)*L[i](2,2));
171  if (root == 0) { flag = 1;}
172  denom += pow( abs(root/alpha[i]), (2.0/3.0));
173  }
174  if (flag) { return 0.0;}
175  else { return 8.0/denom; }
176  }
177 }
178 
179 void Shape_Metric_3::compute(double atts[]) const {
180  atts[0] = compute_shape();
181 }
182 
183 void Size_Metric_3::compute(double atts[]) const {
184  atts[0] = compute_size(ref_vol);
185 }
186 
187 void Size_Shape_Metric_3::compute(double atts[]) const {
188  atts[0] = compute_size(ref_vol) * compute_shape();
189 }
190 
191 void Skew_Metric_3::compute(double atts[]) const {
192  atts[0] = compute_skew();
193 }
194 
195 void Size_Skew_Metric_3::compute(double atts[]) const {
196  atts[0] = compute_size(ref_vol) * compute_skew();
197 }
198 
199 ostream & operator<<(ostream &output, const Alg_Metric_Base_3 &m){
200  for(int i =0; i < (m.type_-100); i ++){
201  output << "A[" << i << "]:" << endl << m.A[i];
202  output << "L[" << i << "]:" << endl << m.L[i];
203  output << "alpha"<<i << ": " << m.alpha[i] << endl << endl;
204  }
205  return output;
206 }
207 
209 
210 
211 
212 
213 
214 
double compute_size(double ref_voume=1.) const
Compute the size metric.
virtual void compute(double atts[]) const
Calculate the metric value on this element.
virtual void compute(double atts[]) const
Calculate the metric value on this element.
virtual void compute(double atts[]) const
Calculate the metric value on this element.
virtual void compute(double atts[]) const
Calculate the metric value on this element.
double sqrt(double d)
Definition: double.h:73
double compute_skew() const
Compute the skew 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
rational * A
Definition: vinci_lass.c:67
3D Algebraic Metric Base Class
virtual void initialize(Vector_3< double > n[], int type)
Initialize a 3D Algebraic Metric.
blockLoc i
Definition: read.cpp:79
const NT & n
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
3d algebraic quality Metric declarations.
j indices j
Definition: Indexing.h:6
virtual void compute(double atts[]) const
Calculate the metric value on this element.
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28
double compute_shape() const
Compute the shape metric.
NT abs(const NT &x)
Definition: number_utils.h:130
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
double pow(double value, const Exponent &exp)
CGAL_BEGIN_NAMESPACE void const NT NT NT NT & denom