Shiokaze Framework
A research-oriented fluid solver for computer graphics
WENO2.h
Go to the documentation of this file.
1 /*
2 ** WENO2.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_WENO2_H
26 #define SHKZ_WENO2_H
27 //
28 #include "WENO.h"
29 #include <shiokaze/math/vec.h>
30 #include <shiokaze/array/array2.h>
31 //
33 //
35 class WENO2 {
38 public:
51  static vec2d interpolate( const array2<vec2r> &array, const vec2d &p, unsigned order=6 ) {
52  //
53  const auto shape = array.shape();
54  double x = std::max(0.0,std::min(shape.w-1.,p[0]));
55  double y = std::max(0.0,std::min(shape.h-1.,p[1]));
56  //
57  int i = std::min(x,shape.w-2.);
58  int j = std::min(y,shape.h-2.);
59  //
60  vec2d result;
61  for( int dim : DIMS2 ) {
62  if( order == 6 ) {
63  double vv[6];
64  for( int jj=0; jj<6; ++jj ) {
65  double v[6];
66  for( int ii=0; ii<6; ++ii ) v[ii] = array(shape.clamp(i+ii-2,j+jj-2))[dim];
67  vv[jj] = WENO::interp6(x-i,v);
68  }
69  result[dim] = WENO::interp6(y-j,vv);
70  } else if( order == 4 ) {
71  double vv[4];
72  for( int jj=0; jj<4; ++jj ) {
73  double hv[4];
74  for( int ii=0; ii<4; ++ii ) hv[ii] = array(shape.clamp(i+ii-1,j+jj-1))[dim];
75  vv[jj] = WENO::interp4(x-i,hv);
76  }
77  result[dim] = WENO::interp4(y-j,vv);
78  } else {
79  printf( "Unsupported order (order=%d)\n", order );
80  exit(0);
81  }
82  }
83  return result;
84  }
97  static double interpolate( const array2<Real> &array, const vec2d &p, unsigned order=6 ) {
98  //
99  const auto shape = array.shape();
100  double x = std::max(0.0,std::min(shape.w-1.,p[0]));
101  double y = std::max(0.0,std::min(shape.h-1.,p[1]));
102  //
103  int i = std::min(x,shape.w-2.);
104  int j = std::min(y,shape.h-2.);
105  //
106  if( order == 6 ) {
107  double vv[6];
108  for( int jj=0; jj<6; ++jj ) {
109  double v[6];
110  for( int ii=0; ii<6; ++ii ) v[ii] = array(shape.clamp(i+ii-2,j+jj-2));
111  vv[jj] = WENO::interp6(x-i,v);
112  }
113  return WENO::interp6(y-j,vv);
114  } else if( order == 4 ) {
115  double vv[4];
116  for( int jj=0; jj<4; ++jj ) {
117  double v[4];
118  for( int ii=0; ii<4; ++ii ) v[ii] = array(shape.clamp(i+ii-1,j+jj-1));
119  vv[jj] = WENO::interp4(x-i,v);
120  }
121  return WENO::interp4(y-j,vv);
122  } else {
123  printf( "Unsupported order (order=%d)\n", order );
124  exit(0);
125  }
126  }
127 };
128 //
130 //
131 #endif
WENO2::interpolate
static vec2d interpolate(const array2< vec2r > &array, const vec2d &p, unsigned order=6)
Interpolate using WENO interpolation.
Definition: WENO2.h:51
array2.h
WENO.h
array2::shape
shape2 shape() const
Get the shape of the array.
Definition: array2.h:218
WENO2
Interface that provides two dimensional WENO interpolations.
Definition: WENO2.h:37
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
WENO2::interpolate
static double interpolate(const array2< Real > &array, const vec2d &p, unsigned order=6)
Interpolate using WENO interpolation.
Definition: WENO2.h:97
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
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
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