Shiokaze Framework
A research-oriented fluid solver for computer graphics
WENO3.h
Go to the documentation of this file.
1 /*
2 ** WENO3.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on Feb 7, 2017.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_WENO3_H
26 #define SHKZ_WENO3_H
27 //
28 #include "WENO.h"
29 #include <shiokaze/math/vec.h>
30 #include <shiokaze/array/array3.h>
31 //
36 //
37 class WENO3 {
38 public:
51  static vec3d interpolate( const array3<vec3r> &array, const vec3d &p, unsigned order=6 ) {
52  const auto shape = array.shape();
53  double x = std::max(0.0,std::min(shape.w-1.,p[0]));
54  double y = std::max(0.0,std::min(shape.h-1.,p[1]));
55  double z = std::max(0.0,std::min(shape.d-1.,p[2]));
56  int i = std::min(x,shape.w-2.);
57  int j = std::min(y,shape.h-2.);
58  int k = std::min(z,shape.d-2.);
59  vec3d result;
60  for( int dim : DIMS3 ) {
61  if( order == 6 ) {
62  double vvv[6];
63  for( int kk=0; kk<6; ++kk ) {
64  double vv[6];
65  for( int jj=0; jj<6; ++jj ) {
66  double v[6];
67  for( int ii=0; ii<6; ++ii ) v[ii] = array(shape.clamp(i+ii-2,j+jj-2,k+kk-2))[dim];
68  vv[jj] = WENO::interp6(x-i,v);
69  }
70  vvv[kk] = WENO::interp6(y-j,vv);
71  }
72  result[dim] = WENO::interp6(z-k,vvv);
73  } else if( order == 4 ) {
74  double vvv[4];
75  for( int kk=0; kk<4; ++kk ) {
76  double vv[4];
77  for( int jj=0; jj<4; ++jj ) {
78  double hv[4];
79  for( int ii=0; ii<4; ++ii ) hv[ii] = array(shape.clamp(i+ii-1,j+jj-1,k+kk-1))[dim];
80  vv[jj] = WENO::interp4(x-i,hv);
81  }
82  vvv[kk] = WENO::interp4(y-j,vv);
83  }
84  result[dim] = WENO::interp4(z-k,vvv);
85  } else {
86  printf( "Unsupported order (order=%d)\n", order );
87  std::exit(0);
88  }
89  }
90  return result;
91  }
104  static double interpolate( const array3<Real> &array, const vec3d &p, unsigned order=6 ) {
105  const auto shape = array.shape();
106  double x = std::max(0.0,std::min(shape.w-1.,p[0]));
107  double y = std::max(0.0,std::min(shape.h-1.,p[1]));
108  double z = std::max(0.0,std::min(shape.d-1.,p[2]));
109  int i = std::min(x,shape.w-2.);
110  int j = std::min(y,shape.h-2.);
111  int k = std::min(z,shape.d-2.);
112  if( order == 6 ) {
113  double vvv[6];
114  for( int kk=0; kk<6; ++kk ) {
115  double vv[6];
116  for( int jj=0; jj<6; ++jj ) {
117  double v[6];
118  for( int ii=0; ii<6; ++ii ) v[ii] = array(shape.clamp(i+ii-2,j+jj-2,k+kk-2));
119  vv[jj] = WENO::interp6(x-i,v);
120  }
121  vvv[kk] = WENO::interp6(y-j,vv);
122  }
123  return WENO::interp6(z-k,vvv);
124  } else if( order == 4 ) {
125  double vvv[4];
126  for( int kk=0; kk<4; ++kk ) {
127  double vv[4];
128  for( int jj=0; jj<4; ++jj ) {
129  double v[4];
130  for( int ii=0; ii<4; ++ii ) v[ii] = array(shape.clamp(i+ii-1,j+jj-1,k+kk-1));
131  vv[jj] = WENO::interp4(x-i,v);
132  }
133  vvv[kk] = WENO::interp4(y-j,vv);
134  }
135  return WENO::interp4(z-k,vvv);
136  } else {
137  printf( "Unsupported order (order=%d)\n", order );
138  std::exit(0);
139  }
140  }
141  //
142 };
143 //
145 //
146 #endif
WENO.h
WENO3
Interface that provides two dimensional WENO interpolations.
Definition: WENO3.h:37
WENO3::interpolate
static double interpolate(const array3< Real > &array, const vec3d &p, unsigned order=6)
Interpolate using WENO interpolation.
Definition: WENO3.h:104
WENO3::interpolate
static vec3d interpolate(const array3< vec3r > &array, const vec3d &p, unsigned order=6)
Interpolate using WENO interpolation.
Definition: WENO3.h:51
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3.h
WENO::interp4
static double interp4(double x, const double v[4], const double eps=std::numeric_limits< double >::epsilon())
Interpolate using 4th order accurate WENO scheme.
Definition: WENO.h:97
vec
Fixed sized vector structure.
Definition: vec.h:38
vec.h
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array3::shape
shape3 shape() const
Get the shape of the array.
Definition: array3.h:218
WENO::interp6
static double interp6(double x, const double v[6], const double eps=std::numeric_limits< double >::epsilon())
Interpolate using 6th order accurate WENO scheme.
Definition: WENO.h:52
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42