Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_upsampler3.h
Go to the documentation of this file.
1 /*
2 ** array_upsampler3.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 Sep 16, 2018.
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_UPSAMPLER3_H
26 #define SHKZ_ARRAY_UPSAMPLER3_H
27 //
29 //
31 //
33 namespace array_upsampler3 {
44  template<class T> void upsample_to_double_cell( const array3<T> &array, double dx, array3<T> &doubled_array ) {
45  //
46  assert(doubled_array.shape() == 2*array.shape());
47  //
48  array.const_serial_actives([&]( int i, int j, int k, auto &it ) {
49  for( int ii=0; ii<2; ++ii ) for( int jj=0; jj<2; ++jj ) for( int kk=0; kk<2; ++kk ) {
50  vec3i pi (2*i+ii,2*j+jj,2*k+kk);
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, int k, auto &it, int tn) {
58  vec3d p = 0.5*vec3i(i,j,k).cell()-vec3d(0.5,0.5,0.5);
59  it.set(array_interpolator3::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 array3<T> &array, double dx, array3<T> &doubled_array ) {
77  //
78  assert(doubled_array.shape() == 2*array.shape()-shape3(1,1,1));
79  //
80  array.const_serial_actives([&]( int i, int j, int k, auto &it ) {
81  for( int ii=0; ii<2; ++ii ) for( int jj=0; jj<2; ++jj ) for( int kk=0; kk<2; ++kk ) {
82  vec3i pi (2*i+ii,2*j+jj,2*k+kk);
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, int k, auto &it, int tn) {
90  vec3d p = 0.5*vec3i(i,j,k).nodal();
91  it.set(array_interpolator3::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
array3::flood_fill
void flood_fill()
Perform flood fill. Grid should be set either level set of fillable beforehand.
Definition: array3.h:299
array_interpolator3.h
shape3::out_of_bounds
bool out_of_bounds(int i, int j, int k) const
Get if the position is outside of the index space of this shape.
Definition: shape.h:811
array3::is_levelset
bool is_levelset() const
Return if the grid is set level set.
Definition: array3.h:292
array3::set
void set(int i, int j, int k, const T &value)
Set value on grid.
Definition: array3.h:522
array3::get_background_value
T get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: array3.h:477
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
array3::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: array3.h:1420
array3::set_as_levelset
void set_as_levelset(double bandwidth_half)
Set the grid as level set.
Definition: array3.h:242
array_upsampler3
Namesampe for upsampling grids.
Definition: array_upsampler3.h:35
array3::parallel_actives
void parallel_actives(std::function< void(iterator &it)> func)
Loop over all the active cells in parallel.
Definition: array3.h:1143
vec::nodal
vec< Y, D > nodal() const
Compute the position of the nodal position from the index space.
Definition: vec.h:364
array_upsampler3::upsample_to_double_nodal
void upsample_to_double_nodal(const array3< T > &array, double dx, array3< T > &doubled_array)
Upsample a nodal grid to double sized.
Definition: array_upsampler3.h:76
vec
Fixed sized vector structure.
Definition: vec.h:38
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
array_upsampler3::upsample_to_double_cell
void upsample_to_double_cell(const array3< T > &array, double dx, array3< T > &doubled_array)
Upsample a cell-centerd grid to double sized.
Definition: array_upsampler3.h:44
array3::shape
shape3 shape() const
Get the shape of the array.
Definition: array3.h:218
vec::cell
vec< Y, D > cell() const
Compute the position of the center of a cell from the index space.
Definition: vec.h:353
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42