Shiokaze Framework
A research-oriented fluid solver for computer graphics
array_gradient2.h
Go to the documentation of this file.
1 /*
2 ** array_gradient2.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 22, 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_GRADIENT2_H
26 #define SHKZ_ARRAY_GRADIENT2_H
27 //
28 #include "array2.h"
29 #include "macarray2.h"
30 //
32 //
34 namespace array_gradient2 {
37  //
38  template<class T> void compute_gradient( const array2<T> &array, macarray2<T> &gradient, double dx ) {
39  for( int dim : DIMS2 ) {
40  gradient[dim].clear();
41  gradient[dim].activate_as(array,vec2i(0,0));
42  gradient[dim].activate_as(array,vec2i(dim==0,dim==1));
43  }
44  shape2 shape = array.shape();
45  gradient.parallel_actives([&]( int dim, int i, int j, auto &it, int tn ) {
46  it.set(
47  (array(shape.clamp(i,j))
48  -array(shape.clamp(i-(dim==0),j-(dim==1)))
49  )/dx);
50  });
51  }
52 };
53 //
55 //
56 #endif
57 //
macarray2.h
array2.h
macarray2::parallel_actives
void parallel_actives(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray2.h:554
macarray2::activate_as
void activate_as(const macarray2< Y > &array, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: macarray2.h:214
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
macarray2::clear
void clear()
Clear out the grid.
Definition: macarray2.h:390
vec
Fixed sized vector structure.
Definition: vec.h:38
array_gradient2
Class that computes the gradient of physical quantities.
Definition: array_gradient2.h:36
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
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
shape2::clamp
vec2i clamp(const vec2i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:311
macarray2
Two dimensional staggered grid class designed to be defined as instance member in recursive_configura...
Definition: macarray2.h:37