 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_MACARRAY3_H
26 #define SHKZ_MACARRAY3_H
51 macarray3 (
recursive_configurable *parent,
const shape3 &
shape,
vec3<T> value=
vec3<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), m_array_2(this,
shape.face(2),value[2],core_name) {
102 bool handled (
false);
103 if( m_array_0.send_message(message,ptr)) handled =
true;
104 if( m_array_1.send_message(message,ptr)) handled =
true;
105 if( m_array_2.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;
122 if( m_array_2.const_send_message(message,ptr)) handled =
true;
142 if(
this != &array ) {
144 for(
int dim : DIMS3 ) (*this)[dim].copy(array[dim]);
157 for(
int dim : DIMS3 ) (*this)[dim].initialize(
shape.
face(dim),value[dim]);
168 for(
int dim : DIMS3 )(*this)[dim].set_touch_only_actives(touch_only_actives);
178 for(
int dim : DIMS3 ) sum += (*this)[dim].count();
187 std::array<std::vector<vec3i>,DIM3>
actives()
const {
188 std::array<std::vector<vec3i>,DIM3> result;
189 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
190 result[dim] = (*this)[dim].actives();
202 void activate(
const std::array<std::vector<vec3i>,DIM3> &active_entries,
const std::array<vec3i,DIM3> &offsets={
vec3i(),
vec3i(),
vec3i()} ) {
203 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
204 (*this)[dim].activate(active_entries[dim],offsets[dim]);
216 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
217 (*this)[dim].activate_as(array[dim],offsets[dim]);
229 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
230 (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
242 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
243 (*this)[dim].activate_inside_as(array[dim],offsets[dim]);
251 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
252 (*this)[dim].activate_all();
260 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
261 (*this)[dim].activate_inside();
273 m_parallel.
for_each( DIM3, [&](
size_t dim ) {
274 (*this)[dim].copy_active_as(array[dim],offset);
283 m_array_0.get_background_value(),
284 m_array_1.get_background_value(),
285 m_array_2.get_background_value()
295 m_array_0.set_background_value(value[0]);
296 m_array_1.set_background_value(value[1]);
297 m_array_2.set_background_value(value[2]);
306 std::vector<vec3i> active_cells;
307 for(
int dim : DIMS3 ) {
308 std::vector<vec3i> active_faces = (*this)[dim].actives();
309 for(
const auto& fi : active_faces ) {
315 std::sort( active_cells.begin(), active_cells.end(),[&](
const vec3i &a,
const vec3i &b) ->
bool {
316 return a[0]+m_shape.w*a[1]+(m_shape.w*m_shape.h)*a[2] < b[0]+m_shape.w*b[1]+(m_shape.w*m_shape.h)*b[2];
318 active_cells.erase( std::unique( active_cells.begin(), active_cells.end() ), active_cells.end() );
320 cell_array.activate(active_cells);
321 cell_array.parallel_actives([&](
int i,
int j,
int k,
auto &it,
int tn) {
323 char valid_count (0);
324 for(
unsigned dim : DIMS3 ) {
327 if( (*
this)[dim].active(i,j,k)) {
328 value += (*this)[dim](i,j,k);
331 if( (*
this)[dim].active(i+(dim==0),j+(dim==1),k+(dim==2))) {
332 value += (*this)[dim](i+(dim==0),j+(dim==1),k+(dim==2));
336 v[dim] = 0.5 * value;
340 if( valid_count == 3 ) it.set(v);
353 face_array.activate_as(*
this);
354 face_array.parallel_actives([&](
int dim,
int i,
int j,
int k,
auto &it,
int tn) {
357 for(
int u_dim : DIMS3 ) {
358 if( u_dim == dim ) u[u_dim] = (*
this)[u_dim](i,j,k);
360 const shape3 s = (*this)[u_dim].shape();
363 vec3i jvec =
vec3i(u_dim==0,u_dim==1,u_dim==2);
364 for(
int ii=0; ii<2; ++ii )
for(
int jj=0; jj<2; ++jj ) {
365 u[u_dim] += (*this)[u_dim](s.
clamp(pi+ii*ivec+jj*jvec));
396 for(
int dim : DIMS3 ) (*this)[dim].clear();
407 for(
int dim : DIMS3 ) (*this)[dim].clear(v[dim]);
418 return ! (*
this == v);
429 for(
int dim : DIMS3 ) {
430 if ((*
this)[dim] != v[dim])
return false;
441 for(
int dim : DIMS3 ) (*this)[dim] = v;
450 for(
int dim : DIMS3 ) (*this)[dim] += v[dim];
459 for(
int dim : DIMS3 ) (*this)[dim] -= v[dim];
468 for(
int dim : DIMS3 ) (*this)[dim] += v[dim];
477 for(
int dim : DIMS3 ) (*this)[dim] += v;
486 for(
int dim : DIMS3 ) (*this)[dim] -= v[dim];
495 for(
int dim : DIMS3 ) (*this)[dim] -= v;
504 for(
int dim : DIMS3 ) (*this)[dim] *= v;
513 for(
int dim : DIMS3 ) (*this)[dim] /= v;
522 return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
531 return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
540 for(
int dim : DIMS3 ) (*this)[dim].set_thread_num(number);
549 return m_array_0.get_thread_num();
552 enum { ACTIVES =
true, ALL =
false };
630 for(
int dim : DIMS3 ) {
631 (*this)[dim].parallel_op([&](
int i,
int j,
int k,
typename array3<T>::iterator& it,
int thread_index) {
632 func(dim,i,j,k,it,thread_index);
713 for(
int dim : DIMS3 ) {
714 (*this)[dim].const_parallel_op([&](
int i,
int j,
int k,
const typename array3<T>::const_iterator& it,
int thread_index) {
715 func(dim,i,j,k,it,thread_index);
769 for(
int dim : DIMS3 ) {
825 for(
int dim : DIMS3 ) {
881 for(
int dim : DIMS3 ) {
937 for(
int dim : DIMS3 ) {
953 m_parallel.
for_each(DIM3,[&](
size_t dim ) {
955 func(dim,i,j,k,it,thread_index);
992 m_parallel.
for_each(DIM3,[&](
size_t dim ) {
994 func(dim,i,j,it,thread_index);
1028 m_array_0.set_core_name(core_name);
1029 m_array_1.set_core_name(core_name);
1030 m_array_2.set_core_name(core_name);
1039 return m_array_0.get_core_name();
1088 return {
get_core_name(), m_shape, m_array_0.type(), m_array_1.type(), m_array_2.type() };
void operator+=(T v)
Increment all the grid values with an input value.
Definition: macarray3.h:476
void copy(const macarray3 &array)
Deep copy function for macarray3.
Definition: macarray3.h:141
void activate_as(const macarray3< Y > &array, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: macarray3.h:215
array3< T >::type3 type2
Type for z dimensional grid.
Definition: macarray3.h:1068
void activate_all()
Activate all the cells.
Definition: macarray3.h:250
void const_serial_all(std::function< void(const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray3.h:788
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
Collection of properties of this grid.
Definition: macarray3.h:1043
void activate_as_bit(const Y &array, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i()})
Activate cells at the same positons where an input array is active with an offset.
Definition: macarray3.h:228
void serial_op(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray3.h:768
void const_serial_actives(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray3.h:808
void interruptible_serial_op(std::function< bool(typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray3.h:853
void const_parallel_op(std::function< void(const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray3.h:658
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: macarray3.h:1027
array3< T >::type3 type1
Type for y dimensional grid.
Definition: macarray3.h:1063
void interruptible_const_serial_op(std::function< bool(const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray3.h:909
bool operator==(const type3 &type) const
Check equality.
Definition: macarray3.h:1075
void parallel_all(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray3.h:566
void parallel_op(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it, int thread_index)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray3.h:629
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: macarray3.h:548
void activate_inside_as(const macarray3< Y > &array, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the same positons where an input array is filled with an offset.
Definition: macarray3.h:241
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
void serial_op(std::function< void(typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray3.h:741
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: macarray3.h:539
void clear()
Clear out the grid.
Definition: macarray3.h:395
void parallel_op(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray3.h:602
void parallel_actives(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it, int thread_index)> func)
Loop over all the active cells in parallel.
Definition: macarray3.h:613
shape3 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:707
void const_serial_all(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray3.h:815
Read-only iterator.
Definition: array3.h:1090
const array3< T > & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: macarray3.h:521
void dilate(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func, int count=1)
Dilate cells.
Definition: macarray3.h:968
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
macarray3 & operator=(const macarray3 &array)
Deep copy operation for macarray3.
Definition: macarray3.h:131
void erode(int count=1)
Erode cells.
Definition: macarray3.h:1018
void set_background_value(const vec3< T > &value)
Set the background value (alternatively, initial value) of the grid.
Definition: macarray3.h:294
void activate(const std::array< std::vector< vec3i >, DIM3 > &active_entries, const std::array< vec3i, DIM3 > &offsets={vec3i(), vec3i(), vec3i()})
Activate cells at the positons of active_entries.
Definition: macarray3.h:202
void activate_inside()
Activate all the filled cells.
Definition: macarray3.h:259
vec3< T > get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: macarray3.h:281
void const_parallel_all(std::function< void(const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray3.h:649
void operator+=(const vec3< T > &v)
Increment all the grid values with an input vector value.
Definition: macarray3.h:467
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: macarray3.h:118
void interruptible_const_serial_all(std::function< bool(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray3.h:927
type3 type() const
Get the type of this grid.
Definition: macarray3.h:1087
std::array< std::vector< vec3i >, DIM3 > actives() const
Function to return the list of active cells positions.
Definition: macarray3.h:187
void interruptible_const_serial_op(std::function< bool(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray3.h:936
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
void const_parallel_actives(std::function< void(const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray3.h:642
void const_parallel_actives(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray3.h:669
void parallel_all(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it, int thread_index)> func)
Loop over all the cells in parallel.
Definition: macarray3.h:620
void interruptible_const_serial_actives(std::function< bool(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray3.h:920
macarray3(const macarray3 &v)
Copy constructor for macarray3.
Definition: macarray3.h:88
std::string core_name
Core name of the module.
Definition: macarray3.h:1048
Collection of properties of this grid.
Definition: array3.h:1821
void interruptible_const_serial_all(std::function< bool(const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in serial order by read-only fashion.
Definition: macarray3.h:900
array3< T > & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: macarray3.h:530
void convert_to_full(array3< vec3< T > > &cell_array) const
Convert staggered values to a cell centered full vector grid.
Definition: macarray3.h:305
void const_serial_op(std::function< void(const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over the cells in serial order by read-only fashion.
Definition: macarray3.h:797
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: macarray3.h:101
void serial_actives(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray3.h:725
macarray3(recursive_configurable *parent, const shape3 &shape, vec3< T > value=vec3< T >(), std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:51
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: macarray3.h:167
Writable iterator.
Definition: array3.h:959
void const_serial_op(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in serial order by read-only fashion.
Definition: macarray3.h:824
bool operator==(const macarray3< T > &v) const
Return if the grid is same to an input array.
Definition: macarray3.h:428
void operator*=(T v)
Multiply all the grid values with an input value.
Definition: macarray3.h:503
void interruptible_serial_actives(std::function< bool(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray3.h:864
void interruptible_serial_op(std::function< bool(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in serial order.
Definition: macarray3.h:880
void copy_active_as(const macarray3< Y > &array, const vec3i &offset=vec3i())
Copy the states of active and inactive cells as same as input array with an offset.
Definition: macarray3.h:272
shape3 shape() const
Get the shape of the array.
Definition: macarray3.h:379
macarray3(const shape3 &shape, vec3< T > value=vec3< T >(), std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:81
void operator-=(const macarray3< T > &v)
Subtract all the values with the values of an input array.
Definition: macarray3.h:458
void clear(vec3< T > v)
Clear out the grid with the new backgroud value.
Definition: macarray3.h:406
void serial_actives(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray3.h:752
void parallel_op(std::function< void(typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray3.h:575
void serial_all(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray3.h:759
void operator-=(const vec3< T > &v)
Subtract all the grid values with an input vector value.
Definition: macarray3.h:485
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
shape3 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: macarray3.h:386
void serial_all(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray3.h:732
Fixed sized vector structure.
Definition: vec.h:38
void set(const T &value)
Set a value.
Definition: array3.h:968
void const_parallel_op(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray3.h:685
void const_parallel_all(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it, int thread_index)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray3.h:703
void dilate(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it, int thread_index)> func, int count=1)
Dilate cells.
Definition: macarray3.h:951
std::string get_core_name() const
Get the core name of module of this grid.
Definition: macarray3.h:1038
size_t count() const
Function to count the number of active cells.
Definition: macarray3.h:176
void erode(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func, int count=1)
Erode cells.
Definition: macarray3.h:1007
void set_type(const type3 &type)
Set the type of this grid.
Definition: macarray3.h:1096
vec3i clamp(const vec3i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:777
array3< T >::type3 type0
Type for x dimensional grid.
Definition: macarray3.h:1058
void interruptible_const_serial_actives(std::function< bool(const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray3.h:893
bool operator!=(const macarray3< T > &v) const
Return if the grid is different from an input array.
Definition: macarray3.h:417
shape3 shape
Shape of the grid.
Definition: macarray3.h:1053
void interruptible_serial_actives(std::function< bool(typename array3< T >::iterator &it)> func)
Loop over all the active cells in serial order.
Definition: macarray3.h:837
Message class.
Definition: messageable.h:36
void const_parallel_actives(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it, int thread_index)> func) const
Loop over all the active cells in parallel by read-only fashion.
Definition: macarray3.h:696
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
Three dimensional staggered grid class designed to be defined as instance member in recursive_configu...
Definition: macarray3.h:37
void operator=(T v)
Set all the grid values with an input value.
Definition: macarray3.h:440
void operator+=(const macarray3< T > &v)
Increment all the values with the values of an input array.
Definition: macarray3.h:449
void erode(std::function< bool(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it, int thread_index)> func, int count=1)
Erode cells.
Definition: macarray3.h:990
macarray3(std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:70
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
void convert_to_full(macarray3< vec3< T > > &face_array) const
Convert staggered values to the a centered full vector grid.
Definition: macarray3.h:350
void interruptible_serial_all(std::function< bool(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray3.h:871
void dilate(int count=1)
Dilate cells.
Definition: macarray3.h:979
void parallel_actives(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray3.h:586
void const_serial_actives(std::function< void(const typename array3< T >::const_iterator &it)> func) const
Loop over all the active cells in serial order by read-only fashion.
Definition: macarray3.h:781
macarray3(recursive_configurable *parent, std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:63
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: macarray3.h:512
void const_parallel_all(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it)> func) const
Loop over all the cells in parallel by read-only fashion.
Definition: macarray3.h:676
void parallel_actives(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray3.h:559
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 operator-=(T v)
Subtract all the grid values with an input value.
Definition: macarray3.h:494
void initialize(const shape3 &shape, vec3< T > value=vec3< T >())
Allocate grid memory with value.
Definition: macarray3.h:155
void parallel_all(std::function< void(int dim, int i, int j, int k, typename array3< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray3.h:593
void interruptible_serial_all(std::function< bool(typename array3< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray3.h:844
void const_parallel_op(std::function< void(int dim, int i, int j, int k, const typename array3< T >::const_iterator &it, int thread_index)> func, bool type=ALL) const
Loop over cells in parallel by read-only fashion.
Definition: macarray3.h:712
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42