SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TetSamplingSchemes.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 #ifndef CORE_BASIS_TETSAMPLINGSCHEMES_H
30 #define CORE_BASIS_TETSAMPLINGSCHEMES_H 1
31 
32 #include <vector>
34 #include <Core/Utils/Exception.h>
35 
36 #include <Core/Basis/share.h>
37 
38 namespace SCIRun {
39 namespace Core {
40 namespace Basis {
41 
43 {
44  public:
45 
46  template <class ARRAY1, class ARRAY2>
47  void get_gaussian_scheme(ARRAY1& coords, ARRAY2& weights, int order)
48  {
49  typedef typename ARRAY1::value_type coords_type;
50  if (order == 1 || order == 0)
51  {
52  const double gaussian_weights[1] = { 1.0};
53  const double gaussian_coords[1][3] = { {1./4., 1./4., 1./4.}};
54  const unsigned int num_coords = 3;
55  const unsigned int num_points = 1;
56 
57  coords.resize(num_points);
58  weights.resize(num_points);
59  for (unsigned int i=0; i<num_points; i++)
60  {
61  coords[i].resize(num_coords);
62  for (unsigned int j=0; j<num_coords; j++)
63  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
64  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
65  }
66  }
67  else if (order == 2)
68  {
69  const double gaussian_weights[4] = {.25, .25, .25, .25};
70  const double gaussian_coords[4][3] = {
71  {0.138196601125011, 0.138196601125011, 0.138196601125011},
72  {0.585410196624969, 0.138196601125011, 0.138196601125011},
73  {0.138196601125011, 0.585410196624969, 0.138196601125011},
74  {0.138196601125011, 0.138196601125011, 0.585410196624969}};
75  const unsigned int num_coords = 3;
76  // Not sure why this is here? It seems to truncate the size of the weights
77  // vector and coords array. - PRJ June, 2013.
78  // const unsigned int num_points = 3;
79  const unsigned int num_points = 4;
80 
81  coords.resize(num_points);
82  weights.resize(num_points);
83  for (unsigned int i=0; i<num_points; i++)
84  {
85  coords[i].resize(num_coords);
86  for (unsigned int j=0; j<num_coords; j++)
87  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
88  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
89  }
90  }
91  else if (order == 3)
92  {
93  const double gaussian_weights[11] = {
94  // Note: weights here sum to 1/6 (which equals volume of unit element),
95  // whereas, above weights sum to 1. This might cause a few scaling
96  // problems depending on the order of integration chosen - PRJ June, 2013.
97  -0.01315556, // Should check this one Gaussian schemes should not have negative weights
98  0.007622222,
99  0.007622222,
100  0.007622222,
101  0.007622222,
102  0.02488889,
103  0.02488889,
104  0.02488889,
105  0.02488889,
106  0.02488889,
107  0.02488889};
108  const double gaussian_coords[11][3] = {
109  {0.2500000, 0.2500000, 0.2500000},
110  {0.7857143, 0.07142857, 0.07142857},
111  {0.07142857, 0.7857143, 0.07142857},
112  {0.07142857, 0.07142857, 0.7857143},
113  {0.07142857, 0.07142857, 0.07142857},
114  {0.1005964, 0.1005964, 0.3994034},
115  {0.1005964, 0.3994034, 0.1005964},
116  {0.1005964, 0.3994034, 0.3994034},
117  {0.3994034, 0.1005964, 0.1005964},
118  {0.3994034, 0.1005964, 0.3994034},
119  {0.3994034, 0.3994034, 0.1005964}};
120  const unsigned int num_coords = 3;
121  // Not sure why this is here? It seems to truncate the size of the weights
122  // vector and coords array. I have set it back to full size go get the
123  // routine BuildMassMatrix to work correctly. The same comment applies
124  // to order = 2 (above) as well - PRJ June, 2013.
125  // const unsigned int num_points = 7;
126  const unsigned int num_points = 11;
127 
128  coords.resize(num_points);
129  weights.resize(num_points);
130  for (unsigned int i=0; i<num_points; i++)
131  {
132  coords[i].resize(num_coords);
133  for (unsigned int j=0; j<num_coords; j++)
134  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
135  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
136  }
137  }
138  else
139  {
140  REPORT_NOT_IMPLEMENTED("Only Gaussian scheme 1, 2, and 3 are implemented");
141  }
142  }
143 
144  template <class ARRAY1, class ARRAY2>
145  void get_regular_scheme(ARRAY1& coords, ARRAY2& weights, int order)
146  {
147  typedef typename ARRAY1::value_type coords_type;
148  coords.resize(0);
149 
150  int m = 0;
151 
152  for (int p=0; p<order;p++)
153  for (int q=0; q<order;q++)
154  for (int r=0; r<order;r++)
155  {
156  if (p+q+r == (order-1))
157  {
158  coords_type c(3);
159  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/4.0)/static_cast<double>(order));
160  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/4.0)/static_cast<double>(order));
161  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/4.0)/static_cast<double>(order));
162  coords.push_back(c); m++;
163  }
164  if (p+q+r == (order-2))
165  {
166  coords_type c(3);
167  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+2.0/4.0)/static_cast<double>(order));
168  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/4.0)/static_cast<double>(order));
169  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/4.0)/static_cast<double>(order));
170  coords.push_back(c); m++;
171  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/4.0)/static_cast<double>(order));
172  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+2.0/4.0)/static_cast<double>(order));
173  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/4.0)/static_cast<double>(order));
174  coords.push_back(c); m++;
175  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/4.0)/static_cast<double>(order));
176  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/4.0)/static_cast<double>(order));
177  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+2.0/4.0)/static_cast<double>(order));
178  coords.push_back(c); m++;
179  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/3.0)/static_cast<double>(order));
180  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/3.0)/static_cast<double>(order));
181  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/3.0)/static_cast<double>(order));
182  coords.push_back(c); m++;
183  }
184  if (p+q+r < (order-2))
185  {
186  coords_type c(3);
187  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+2.0/4.0)/static_cast<double>(order));
188  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/4.0)/static_cast<double>(order));
189  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/4.0)/static_cast<double>(order));
190  coords.push_back(c); m++;
191  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/4.0)/static_cast<double>(order));
192  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+2.0/4.0)/static_cast<double>(order));
193  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/4.0)/static_cast<double>(order));
194  coords.push_back(c); m++;
195  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/4.0)/static_cast<double>(order));
196  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/4.0)/static_cast<double>(order));
197  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+2.0/4.0)/static_cast<double>(order));
198  coords.push_back(c); m++;
199  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+1.0/3.0)/static_cast<double>(order));
200  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+1.0/3.0)/static_cast<double>(order));
201  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/3.0)/static_cast<double>(order));
202  coords.push_back(c); m++;
203  c[0] = static_cast<typename coords_type::value_type>((static_cast<double>(p)+2.0/4.0)/static_cast<double>(order));
204  c[1] = static_cast<typename coords_type::value_type>((static_cast<double>(q)+2.0/4.0)/static_cast<double>(order));
205  c[2] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+2.0/4.0)/static_cast<double>(order));
206  coords.push_back(c); m++;
207  }
208  }
209 
210  weights.resize(m);
211  for (int p=0; p<m;p++) weights[p] = static_cast<typename ARRAY2::value_type>(1.0/static_cast<double>(m));
212  }
213 };
214 
215 }}}
216 
217 #endif
void get_regular_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: TetSamplingSchemes.h:145
#define SCISHARE
Definition: share.h:39
Utility for specifying data invariants (Assertions)
void get_gaussian_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: TetSamplingSchemes.h:47
#define REPORT_NOT_IMPLEMENTED(message)
Definition: Exception.h:106
Definition: TetSamplingSchemes.h:42