 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_MACARRAY2_H
26 #define SHKZ_MACARRAY2_H
51 macarray2 (
recursive_configurable *parent,
const shape2 &
shape,
vec2<T> value=
vec2<T>(), std::string core_name=
"") : m_shape(
shape), m_array_0(this,
shape.face(0),value[0],core_name), m_array_1(this,
shape.face(1),value[1],core_name) {
103 bool handled (
false);
104 if( m_array_0.send_message(message,ptr)) handled =
true;
105 if( m_array_1.send_message(message,ptr)) handled =
true;
119 bool handled (
false);
120 if( m_array_0.const_send_message(message,ptr)) handled =
true;
121 if( m_array_1.const_send_message(message,ptr)) handled =
true;
141 if(
this != &array ) {
143 for(
int dim : DIMS2 ) (*this)[dim].copy(array[dim]);
156 for(
int dim : DIMS2 )(*this)[dim].initialize(
shape.
face(dim),value[dim]);
167 for(
int dim : DIMS2 )(*this)[dim].set_touch_only_actives(touch_only_actives);
177 for(
int dim : DIMS2 ) sum += (*this)[dim].count();
186 std::array<std::vector<vec2i>,DIM2>
actives()
const {
187 std::array<std::vector<vec2i>,DIM2> result;
188 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
189 result[dim] = (*this)[dim].actives();
201 void activate(
const std::array<std::vector<vec2i>,DIM2> &active_entries,
const std::array<vec2i,DIM2> &offsets={
vec2i(),
vec2i()} ) {
202 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
203 (*this)[dim].activate(active_entries[dim],offsets[dim]);
215 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
216 (*this)[dim].activate_as(array[dim],offsets[dim]);
228 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
229 (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
241 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
242 (*this)[dim].activate_inside_as(array[dim],offsets[dim]);
250 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
251 (*this)[dim].activate_all();
259 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
260 (*this)[dim].activate_inside();
272 m_parallel.
for_each( DIM2, [&](
size_t dim ) {
273 (*this)[dim].copy_active_as(array[dim],offset);
282 m_array_0.get_background_value(),
283 m_array_1.get_background_value()
293 m_array_0.set_background_value(value[0]);
294 m_array_1.set_background_value(value[1]);
303 std::vector<vec2i> active_cells;
304 for(
int dim : DIMS2 ) {
305 std::vector<vec2i> active_faces = (*this)[dim].actives();
306 for(
const auto& fi : active_faces ) {
312 std::sort( active_cells.begin(), active_cells.end(),[&](
const vec2i &a,
const vec2i &b) ->
bool {
313 return a[0]+m_shape.w*a[1] < b[0]+m_shape.w*b[1];
315 active_cells.erase( std::unique( active_cells.begin(), active_cells.end() ), active_cells.end() );
317 cell_array.activate(active_cells);
318 cell_array.parallel_actives([&](
int i,
int j,
auto &it,
int tn) {
320 char valid_count (0);
321 for(
unsigned dim : DIMS2 ) {
324 if( (*
this)[dim].active(i,j)) {
325 value += (*this)[dim](i,j);
328 if( (*
this)[dim].active(i+(dim==0),j+(dim==1))) {
329 value += (*this)[dim](i+(dim==0),j+(dim==1));
333 v[dim] = 0.5 * value;
337 if( valid_count == 2 ) it.set(v);
350 face_array.activate_as(*
this);
351 face_array.parallel_actives([&](
int dim,
int i,
int j,
auto &it,
int tn) {
354 for(
int u_dim : DIMS2 ) {
355 if( u_dim == dim ) u[u_dim] = (*
this)[u_dim](i,j);
358 const shape2 s = (*this)[u_dim].shape();
359 for(
int ii=0; ii<2; ++ii )
for(
int jj=0; jj<2; ++jj ) {
360 u[u_dim] += (*this)[u_dim](s.
clamp(pi[0]+ii,pi[1]+jj));
391 for(
int dim : DIMS2 )(*this)[dim].clear();
402 for(
int dim : DIMS2 )(*this)[dim].clear(v[dim]);
413 return ! (*
this == v);
424 for(
int dim : DIMS2 ) {
425 if((*
this)[dim] != v[dim])
return false;
436 for(
int dim : DIMS2 ) (*this)[dim] = v;
445 for(
int dim : DIMS2 ) (*this)[dim] += v[dim];
454 for(
int dim : DIMS2 ) (*this)[dim] -= v[dim];
463 for(
int dim : DIMS2 ) (*this)[dim] += v[dim];
472 for(
int dim : DIMS2 ) (*this)[dim] += v;
481 for(
int dim : DIMS2 ) (*this)[dim] -= v[dim];
490 for(
int dim : DIMS2 ) (*this)[dim] -= v;
499 for(
int dim : DIMS2 ) (*this)[dim] *= v;
508 for(
int dim : DIMS2 ) (*this)[dim] /= v;
517 return dim==0 ? m_array_0 : m_array_1;
526 return dim==0 ? m_array_0 : m_array_1;
535 for(
int dim : DIMS2 ) (*this)[dim].set_thread_num(number);
544 return m_array_0.get_thread_num();
547 enum { ACTIVES =
true, ALL =
false };
625 for(
int dim : DIMS2 ) {
626 (*this)[dim].parallel_op([&](
int i,
int j,
typename array2<T>::iterator& it,
int thread_index) {
627 func(dim,i,j,it,thread_index);
708 for(
int dim : DIMS2 ) {
710 func(dim,i,j,it,thread_index);
764 for(
int dim : DIMS2 ) {
820 for(
int dim : DIMS2 ) {
876 for(
int dim : DIMS2 ) {
932 for(
int dim : DIMS2 ) {
948 m_parallel.
for_each(DIM2,[&](
size_t dim ) {
950 func(dim,i,j,it,thread_index);
987 m_parallel.
for_each(DIM2,[&](
size_t dim ) {
989 func(dim,i,j,it,thread_index);
1023 m_array_0.set_core_name(core_name);
1024 m_array_1.set_core_name(core_name);
1033 return m_array_0.get_core_name();
1077 return {
get_core_name(), m_shape, m_array_0.type(), m_array_1.type() };
macarray2(const macarray2 &v)
Copy constructor for macarray2.
Definition: macarray2.h:88
void dilate(int count=1)
Dilate cells.
Definition: macarray2.h:974
void erode(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func, int count=1)
Erode cells.
Definition: macarray2.h:1002
void const_parallel_actives(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray2.h:691
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: macarray2.h:1022
void const_serial_op(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray2.h:819
void erode(int count=1)
Erode cells.
Definition: macarray2.h:1013
void dilate(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func, int count=1)
Dilate cells.
Definition: macarray2.h:963
void parallel_all(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: macarray2.h:615
void serial_op(std::function< void(typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray2.h:736
macarray2 & operator=(const macarray2 &array)
Deep copy operation for macarray2.
Definition: macarray2.h:130
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
void interruptible_const_serial_actives(std::function< bool(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray2.h:915
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: macarray2.h:118
void copy(const macarray2 &array)
Deep copy function for macarray2.
Definition: macarray2.h:140
void const_serial_actives(std::function< void(const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray2.h:776
void interruptible_serial_all(std::function< bool(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray2.h:866
void parallel_actives(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray2.h:554
void activate(const std::array< std::vector< vec2i >, DIM2 > &active_entries, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the positons of active_entries.
Definition: macarray2.h:201
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
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
void erode(std::function< bool(int dim, int i, int j, const typename array2< T >::const_iterator &it, int thread_index)> func, int count=1)
Erode cells.
Definition: macarray2.h:985
void convert_to_full(array2< vec2< T > > &cell_array) const
Convert staggered values to a cell centered full vector grid.
Definition: macarray2.h:302
Collection of properties of this grid.
Definition: macarray2.h:1037
array2< T >::type2 type1
Type for y dimensional grid.
Definition: macarray2.h:1057
void interruptible_serial_op(std::function< bool(int dim, int i, int j, typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray2.h:875
void activate_as_bit(const 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:227
void interruptible_serial_actives(std::function< bool(typename array2< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray2.h:832
bool operator==(const type2 &type) const
Check equality.
Definition: macarray2.h:1064
void operator+=(T v)
Increment all the grid values with an input value.
Definition: macarray2.h:471
shape2 shape() const
Get the shape of the array.
Definition: macarray2.h:374
void const_parallel_all(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray2.h:698
macarray2(recursive_configurable *parent, const shape2 &shape, vec2< T > value=vec2< T >(), std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:51
void initialize(const shape2 &shape, vec2< T > value=vec2< T >())
Allocate grid memory with value.
Definition: macarray2.h:154
Collection of properties of this grid.
Definition: array2.h:1797
void const_parallel_op(std::function< void(const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray2.h:653
void convert_to_full(macarray2< vec2< T > > &face_array) const
Convert staggered values to the a centered full vector grid.
Definition: macarray2.h:347
void set(const T &value)
Set a value.
Definition: array2.h:946
void operator-=(T v)
Subtract all the grid values with an input value.
Definition: macarray2.h:489
size_t count() const
Function to count the number of active cells.
Definition: macarray2.h:175
void set_background_value(const vec2< T > &value)
Set the background value (alternatively, initial value) of the grid.
Definition: macarray2.h:292
macarray2(std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:70
void const_serial_all(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray2.h:810
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
void clear(vec2< T > v)
Clear out the grid with the new backgroud value.
Definition: macarray2.h:401
std::string core_name
Core name of the module.
Definition: macarray2.h:1042
std::array< std::vector< vec2i >, DIM2 > actives() const
Function to return the list of active cells positions.
Definition: macarray2.h:186
void parallel_actives(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray2.h:581
bool operator==(const macarray2< T > &v) const
Return if the grid is same to an input array.
Definition: macarray2.h:423
array2< T > & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: macarray2.h:525
void interruptible_serial_actives(std::function< bool(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray2.h:859
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
void serial_actives(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray2.h:747
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: macarray2.h:507
void copy_active_as(const macarray2< Y > &array, const vec2i &offset=vec2i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: macarray2.h:271
void interruptible_serial_op(std::function< bool(typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray2.h:848
void dilate(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: macarray2.h:946
void const_serial_all(std::function< void(const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray2.h:783
void parallel_actives(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: macarray2.h:608
void const_serial_actives(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray2.h:803
vec2< T > get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: macarray2.h:280
shape2 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:257
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: macarray2.h:543
void const_parallel_all(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray2.h:671
void parallel_all(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray2.h:561
void activate_inside()
Activate all the filled cells.
Definition: macarray2.h:258
void serial_all(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray2.h:727
const array2< T > & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: macarray2.h:516
void const_serial_op(std::function< void(const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over the cells in serial order by read-only fashion.
Definition: macarray2.h:792
type2 type() const
Get the type of this grid.
Definition: macarray2.h:1076
void parallel_op(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray2.h:624
void const_parallel_all(std::function< void(const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray2.h:644
void operator*=(T v)
Multiply all the grid values with an input value.
Definition: macarray2.h:498
void operator-=(const macarray2< T > &v)
Subtract all the values with the values of an input array.
Definition: macarray2.h:453
void parallel_op(std::function< void(typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray2.h:570
void clear()
Clear out the grid.
Definition: macarray2.h:390
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
void const_parallel_actives(std::function< void(const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray2.h:637
std::string get_core_name() const
Get the core name of module of this grid.
Definition: macarray2.h:1032
Fixed sized vector structure.
Definition: vec.h:38
void interruptible_serial_all(std::function< bool(typename array2< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray2.h:839
void operator=(T v)
Set all the grid values with an input value.
Definition: macarray2.h:435
shape2 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: macarray2.h:381
void interruptible_const_serial_all(std::function< bool(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray2.h:922
shape2 shape
Shape of the grid.
Definition: macarray2.h:1047
macarray2(const shape2 &shape, vec2< T > value=vec2< T >(), std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:81
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
void parallel_all(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray2.h:588
void interruptible_const_serial_all(std::function< bool(const typename array2< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray2.h:895
void operator+=(const macarray2< T > &v)
Increment all the values with the values of an input array.
Definition: macarray2.h:444
void serial_all(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray2.h:754
Writable iterator.
Definition: array2.h:937
void operator+=(const vec2< T > &v)
Increment all the grid values with an input vector value.
Definition: macarray2.h:462
void serial_op(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray2.h:763
void const_parallel_op(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray2.h:680
void activate_all()
Activate all the cells.
Definition: macarray2.h:249
void serial_actives(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray2.h:720
array2< T >::type2 type0
Type for x dimensional grid.
Definition: macarray2.h:1052
Structure that defines shape such as width, height.
Definition: shape.h:42
Message class.
Definition: messageable.h:36
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
vec2i clamp(const vec2i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:311
void const_parallel_actives(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray2.h:664
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: macarray2.h:102
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: macarray2.h:534
macarray2(recursive_configurable *parent, std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:63
void activate_inside_as(const macarray2< Y > &array, const std::array< vec2i, DIM2 > &offsets={vec2i(), vec2i()})
Activate cells at the same positons where an input array is filled with an offset.
Definition: macarray2.h:240
void operator-=(const vec2< T > &v)
Subtract all the grid values with an input vector value.
Definition: macarray2.h:480
bool operator!=(const macarray2< T > &v) const
Return if the grid is different from an input array.
Definition: macarray2.h:412
Two dimensional staggered grid class designed to be defined as instance member in recursive_configura...
Definition: macarray2.h:37
void set_touch_only_actives(bool touch_only_actives)
Set whether to force grid manipulation only on active cells. If true, operatios such operator+=() onl...
Definition: macarray2.h:166
void set_type(const type2 &type)
Set the type of this grid.
Definition: macarray2.h:1085
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
void parallel_op(std::function< void(int dim, int i, int j, typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray2.h:597
void interruptible_const_serial_actives(std::function< bool(const typename array2< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray2.h:888
Read-only iterator.
Definition: array2.h:1069
void interruptible_const_serial_op(std::function< bool(const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray2.h:904
void for_each(size_t size, std::function< void(size_t n, int thread_index)> func) const
Perform a parallel loop operation.
Definition: parallel_driver.h:141
void const_parallel_op(std::function< void(int dim, int i, int j, const typename array2< T >::const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray2.h:707
void interruptible_const_serial_op(std::function< bool(int dim, int i, int j, const typename array2< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray2.h:931