Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_upsampler2.h
Go to the documentation of this file.
1 /*
2 ** array_upsampler2.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 May 30, 2019.
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_ARRAY_UPSAMPLER2_H
26 #define SHKZ_ARRAY_UPSAMPLER2_H
27 //
29 //
31 //
33 namespace array_upsampler2 {
44  template<class T> void upsample_to_double_cell( const array2<T> &array, double dx, array2<T> &doubled_array ) {
45  //
46  assert(doubled_array.shape() == 2*array.shape());
47  //
48  array.const_serial_actives([&]( int i, int j, auto &it ) {
49  for( int ii=0; ii<2; ++ii ) for( int jj=0; jj<2; ++jj ) {
50  vec2i pi (2*i+ii,2*j+jj);
51  if( ! doubled_array.shape().out_of_bounds(pi)) {
52  doubled_array.set(pi,0.0);
53  }
54  }
55  });
56  //
57  doubled_array.parallel_actives([&]( int i, int j, auto &it, int tn) {
58  vec2d p = 0.5*vec2i(i,j).cell()-vec2d(0.5,0.5);
59  it.set(array_interpolator2::interpolate<T>(array,p));
60  });
61  //
62  if( array.is_levelset()) {
63  doubled_array.set_as_levelset(0.5*array.get_background_value());
64  doubled_array.flood_fill();
65  }
66  }
67  //
76  template<class T> void upsample_to_double_nodal( const array2<T> &array, double dx, array2<T> &doubled_array ) {
77  //
78  assert(doubled_array.shape() == 2*array.shape()-shape2(1,1));
79  //
80  array.const_serial_actives([&]( int i, int j, auto &it ) {
81  for( int ii=0; ii<2; ++ii ) for( int jj=0; jj<2; ++jj ) {
82  vec2i pi (2*i+ii,2*j+jj);
83  if( ! doubled_array.shape().out_of_bounds(pi)) {
84  doubled_array.set(pi,0.0);
85  }
86  }
87  });
88  //
89  doubled_array.parallel_actives([&]( int i, int j, auto &it, int tn) {
90  vec2d p = 0.5*vec2i(i,j).nodal();
91  it.set(array_interpolator2::interpolate<T>(array,p));
92  });
93  //
94  if( array.is_levelset()) {
95  doubled_array.set_as_levelset(0.5*array.get_background_value());
96  doubled_array.flood_fill();
97  }
98  }
99 };
100 //
102 //
103 #endif
array2::flood_fill
void flood_fill()
Perform flood fill. Grid should be set either level set of fillable beforehand.
Definition: array2.h:299
array2::set
void set(int i, int j, const T &value)
Set value on grid.
Definition: array2.h:518
array_upsampler2::upsample_to_double_nodal
void upsample_to_double_nodal(const array2< T > &array, double dx, array2< T > &doubled_array)
Upsample a nodal grid to double sized.
Definition: array_upsampler2.h:76
array_interpolator2.h
array2::parallel_actives
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array2.h:1123
array_upsampler2
Namesampe for upsampling grids.
Definition: array_upsampler2.h:35
array2::is_levelset
bool is_levelset() const
Return if the grid is set level set.
Definition: array2.h:292
array2::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array2.h:475
array2::set_as_levelset
void set_as_levelset(double bandwidth_half)
Set the grid as level set.
Definition: array2.h:242
shape2::out_of_bounds
bool out_of_bounds(int i, int j) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:341
array2::shape
shape2 shape() const
Get the shape of the array.
Definition: array2.h:218
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
vec::nodal
vec< Y, D > nodal() const
Compute the position of the nodal position from the index space.
Definition: vec.h:364
vec
Fixed sized vector structure.
Definition: vec.h:38
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
array2::const_serial_actives
void const_serial_actives(std::function< void(const const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: array2.h:1400
shape2
Structure that defines shape such as width, height.
Definition: shape.h:42
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
vec::cell
vec< Y, D > cell() const
Compute the position of the center of a cell from the index space.
Definition: vec.h:353
array_upsampler2::upsample_to_double_cell
void upsample_to_double_cell(const array2< T > &array, double dx, array2< T > &doubled_array)
Upsample a cell-centerd grid to double sized.
Definition: array_upsampler2.h:44