Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PN_patch.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 #include "PN_patch.h"
24 #include <cmath>
25 using namespace std;
26 
28 
29 
30 // Only need at most three coords, b_n = 1-(sum_{i=1}^{n-1}b_i)
31 Vector_3<double> PN_project(std::vector<int> v_ids,
32  Vector_3<double> bcoords,
33  const Vector_3<double> *pnts,
34  const Vector_3<double> *vnrms,
35  const Vector_3<double> *evects,
36  const Vector_3<double> *evals,
37  const Vector_3<double> *bs,
38  const int * tranks,
39  bool is_ridge[4]){
40  Vector_3<double> ans(0.0,0.0,0.0);
41  if(v_ids.size() == 3){
42 
43  Vector_3<double> cp[10]; // PN triangle control points
44  cp[0] = pnts[v_ids[0]-1];
45  cp[1] = pnts[v_ids[1]-1];
46  cp[2] = pnts[v_ids[2]-1];
47  cp[3] = (2.0*cp[0]+cp[2])/3.0;
48  cp[4] = (2.0*cp[0]+cp[1])/3.0;
49  cp[5] = (2.0*cp[1]+cp[0])/3.0;
50  cp[6] = (2.0*cp[1]+cp[2])/3.0;
51  cp[7] = (2.0*cp[2]+cp[1])/3.0;
52  cp[8] = (2.0*cp[2]+cp[0])/3.0;
53 
54  int r_ind[3] = {4,6,8};
55  int l_ind[3] = {3,5,7};
56 
57  for(int k =0; k < 3; ++k){
58  int v_ind = k, t_ind = (4+k)%3;
59  int v_id = v_ids[v_ind], t_id = v_ids[t_ind];
60  project_edge(v_id,t_id, v_ids[(5+k)%3],// Nodal ids
61  cp[v_ind], // PN coordinates
62  cp[t_ind],
63  cp[r_ind[v_id]],
64  cp[l_ind[t_id]],
65  pnts, // Nodal coords
66  vnrms, // Normals
67  evects, // Eigenvectors
68  evals,
69  bs,
70  tranks, // Tangent ranks
71  is_ridge[k]); // Is the edge on a ridge?
72 
73  project_edge(t_id,v_id,v_ids[(5+k)%3], // Nodal ids
74  cp[t_ind], // PN coordinates
75  cp[v_ind],
76  cp[l_ind[t_id]],
77  cp[r_ind[v_id]],
78  pnts, // Nodal coords
79  vnrms, // Normals
80  evects, // Eigenvectors
81  evals,
82  bs,
83  tranks, // Tangent ranks
84  is_ridge[k]); // Is the edge on a ridge?
85  }
86  Vector_3<double> E = (cp[3] + cp[4] + cp[5] +
87  cp[6]+cp[7]+cp[8])/6.0;
88  Vector_3<double> V = (cp[0] + cp[1] + cp[2])/3.0;
89  cp[9] = E+(E-V)/2.0;
90  double w = bcoords[0], u = bcoords[1];
91  double v = 1.0-(w+u);
92  double w2 = w*w, u2 = u*u, v2=v*v;
93 
94  ans = ( cp[0]*w2*w + cp[1]*u2*u + cp[2]*v2*v +
95  3.0*(cp[3]*w2*v + cp[4]*w2*u + cp[5]*u2*w +
96  cp[6]*u2*v + cp[7]*v2*u + cp[8]*v2*w) +
97  6.0*cp[9]*w*u*v);
98  }
99  return ans;
100 }
101 
102 
103 void project_edge(int v_id, int t_id, int id3,// Nodal ids
104  Vector_3<double> v_crd, // PN coordinates
105  Vector_3<double> t_crd,
106  Vector_3<double> & p_crd,
107  Vector_3<double> & p2_crd,
108  const Vector_3<double> * pnts, // Nodal coords
109  const Vector_3<double> * vnrms, // Normals
110  const Vector_3<double> * evects, // Eigenvectors
111  const Vector_3<double> *evals,
112  const Vector_3<double> * bs,
113  const int* tranks, // Tangent ranks
114  bool is_ridge) // Is the edge on a ridge?
115 {
116  // convert from ids to indices
117  v_id -=1;
118  t_id -=1;
119  Vector_3<double> vp_vect = (v_crd-p_crd);
120  Vector_3<double> f(0.0,0.0,0.0);
121  switch(tranks[v_id]) {
122  case 2:{ // V is smooth
123  f = (vp_vect)*evects[3*v_id]*evects[3*v_id];
124  break;
125  }
126  case 1:{ // V is a ridge
127  if(is_ridge) // edge VT is on the ridge
128  f = vp_vect - vp_vect*evects[3*v_id+2]*evects[3*v_id+2];
129  else{ // edge VT is not part of the ridge
130  Vector_3<double> n_os =
131  one_sided_normal(v_id+1,t_id+1,id3,
132  evects,
133  pnts,
134  evals,
135  vnrms,
136  bs);
137  // one_sided_normal(v_id,n_os);
138  f = vp_vect*n_os*n_os;
139  }
140  break;
141  }
142  case 0:{ // V is a corner, do nothing.
143  return;
144  }
145  default :
146  COM_assertion_msg(0, "Invalid tangent space size");
147  }
148  if(tranks[t_id]==0){// Other point is a corner, handle it here.
149  Vector_3<double> tangent = p_crd - v_crd;
150  tangent.normalize();
151  p2_crd += f - 2.0*f*tangent*tangent;
152  }
153  p_crd += f;
154 }
155 
156 Vector_3<double> one_sided_normal(int id1, int id2, int id3,
157  const Vector_3<double> *evects,
158  const Vector_3<double> *pnts,
159  const Vector_3<double> *evals,
160  const Vector_3<double> *vnorms,
161  const Vector_3<double> *bs){
162  int i = ((evects[3*id1-3]*bs[id1-1]/-evals[id1-1][0]) >
163  (evects[3*id1-2]*bs[id1-1]/-evals[id1-1][1])) ? 0 : 1;
164  int j = 1-i;
165  Vector_3<double> os = std::sqrt(evals[id1-1][i]) * vnorms[id1-1];
166  Vector_3<double> fnormal = Vector_3<double>::cross_product(pnts[id2-1]-pnts[id1-1],
167  pnts[id3-1]-pnts[id1-1]);
168  Vector_3<double> y = Vector_3<double>::cross_product(vnorms[id1-1],evects[3*id1-1]);
169  if(fnormal*y >= 0)
170  os += std::sqrt(evals[id1-1][j])*y;
171  else
172  os -= std::sqrt(evals[id1-1][j])*y;
173  os.normalize();
174  return os;
175 }
176 
178 
179 
180 
181 
182 
183 
j indices k indices k
Definition: Indexing.h:6
void int int REAL REAL * y
Definition: read.cpp:74
#define COM_assertion_msg(EX, msg)
double sqrt(double d)
Definition: double.h:73
Vector_3 & normalize()
Definition: mapbasic.h:114
MOP_BEGIN_NAMESPACE Vector_3< double > PN_project(std::vector< int * > v_ids, Vector_3< double > bcoords, const Vector_3< double > *pnts, const Vector_3< double > *vnrms, const Vector_3< double > *evects, const Vector_3< double > *evals, const Vector_3< double > *bs, const int *tranks, std::vector< bool > is_ridge[4])
Vector_3< double > one_sided_normal(int id1, int id2, int id3, const Vector_3< double > *evects, const Vector_3< double > *pnts, const Vector_3< double > *evals, const Vector_3< double > *vnorms, const Vector_3< double > *bs)
Definition: PN_patch.C:156
*********************************************************************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
blockLoc i
Definition: read.cpp:79
#define MOP_END_NAMESPACE
Definition: mopbasic.h:29
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
void project_edge(int v_id, int t_id, int id3, Vector_3< double > v_crd, Vector_3< double > t_crd, Vector_3< double > &p_crd, Vector_3< double > &p2_crd, const Vector_3< double > *pnts, const Vector_3< double > *vnrms, const Vector_3< double > *evects, const Vector_3< double > *evals, const Vector_3< double > *bs, const int *tranks, bool is_ridge)
Definition: PN_patch.C:103
j indices j
Definition: Indexing.h:6
#define MOP_BEGIN_NAMESPACE
Definition: mopbasic.h:28