Shiokaze Framework
A research-oriented fluid solver for computer graphics
macarray3.h
Go to the documentation of this file.
1 /*
2 ** macarray3.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 Feb 25, 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_MACARRAY3_H
26 #define SHKZ_MACARRAY3_H
27 //
28 #include <shiokaze/array/array3.h>
29 #include <algorithm>
30 #include <array>
31 //
33 //
35 template<class T> class macarray3 : public recursive_configurable, public messageable {
38 public:
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) {
52  if( parent ) parent->add_child(this);
53  else setup_now();
54  }
63  macarray3( recursive_configurable *parent, std::string core_name="" ) : macarray3(parent,shape3(0,0,0),vec3<T>(),core_name) {}
70  macarray3 ( std::string core_name="") : macarray3(nullptr,shape3(0,0,0),vec3<T>(),core_name) {}
81  macarray3( const shape3 &shape, vec3<T> value=vec3<T>(), std::string core_name="") : macarray3(nullptr,shape,value,core_name) {}
88  macarray3 ( const macarray3& v ) : m_array_0(this), m_array_1(this), m_array_2(this){
89  copy(v);
90  }
101  virtual bool send_message( std::string message, void *ptr ) override {
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;
106  return handled;
107  }
118  virtual bool const_send_message( std::string message, void *ptr ) const override {
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;
123  return handled;
124  }
131  macarray3& operator=(const macarray3 &array) {
132  copy(array);
133  return *this;
134  }
141  void copy( const macarray3 &array ) {
142  if( this != &array ) {
143  set_type(array.type());
144  for( int dim : DIMS3 ) (*this)[dim].copy(array[dim]);
145  }
146  }
155  void initialize ( const shape3 &shape, vec3<T> value=vec3<T>() ) {
156  m_shape = shape;
157  for( int dim : DIMS3 ) (*this)[dim].initialize(shape.face(dim),value[dim]);
158  }
167  void set_touch_only_actives( bool touch_only_actives ) {
168  for( int dim : DIMS3 )(*this)[dim].set_touch_only_actives(touch_only_actives);
169  }
176  size_t count () const {
177  size_t sum (0);
178  for( int dim : DIMS3 ) sum += (*this)[dim].count();
179  return sum;
180  }
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();
191  });
192  return result;
193  }
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]);
205  });
206  }
215  template <class Y> void activate_as( const macarray3<Y> &array, const std::array<vec3i,DIM3> &offsets={vec3i(),vec3i(),vec3i()} ) {
216  m_parallel.for_each( DIM3, [&]( size_t dim ) {
217  (*this)[dim].activate_as(array[dim],offsets[dim]);
218  });
219  }
228  template <class Y> void activate_as_bit( const Y &array, const std::array<vec3i,DIM3> &offsets={vec3i(),vec3i()} ) {
229  m_parallel.for_each( DIM3, [&]( size_t dim ) {
230  (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
231  });
232  }
241  template <class Y> void activate_inside_as( const macarray3<Y> &array, const std::array<vec3i,DIM3> &offsets={vec3i(),vec3i(),vec3i()} ) {
242  m_parallel.for_each( DIM3, [&]( size_t dim ) {
243  (*this)[dim].activate_inside_as(array[dim],offsets[dim]);
244  });
245  }
250  void activate_all() {
251  m_parallel.for_each( DIM3, [&]( size_t dim ) {
252  (*this)[dim].activate_all();
253  });
254  }
260  m_parallel.for_each( DIM3, [&]( size_t dim ) {
261  (*this)[dim].activate_inside();
262  });
263  }
272  template <class Y> void copy_active_as( const macarray3<Y> &array, const vec3i &offset=vec3i() ) {
273  m_parallel.for_each( DIM3, [&]( size_t dim ) {
274  (*this)[dim].copy_active_as(array[dim],offset);
275  });
276  }
282  return vec3<T>(
283  m_array_0.get_background_value(),
284  m_array_1.get_background_value(),
285  m_array_2.get_background_value()
286  );
287  }
294  void set_background_value( const vec3<T>& 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]);
298  }
305  void convert_to_full( array3<vec3<T> > &cell_array ) const {
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 ) {
310  vec3i pi (fi-vec3i(dim==0,dim==1,dim==2));
311  if( ! m_shape.out_of_bounds(fi)) active_cells.push_back(fi);
312  if( ! m_shape.out_of_bounds(pi)) active_cells.push_back(pi);
313  }
314  }
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];
317  });
318  active_cells.erase( std::unique( active_cells.begin(), active_cells.end() ), active_cells.end() );
319  cell_array.clear(get_background_value());
320  cell_array.activate(active_cells);
321  cell_array.parallel_actives([&](int i, int j, int k, auto &it, int tn) {
322  vec3d v;
323  char valid_count (0);
324  for( unsigned dim : DIMS3 ) {
325  char wsum (0);
326  double value (0.0);
327  if( (*this)[dim].active(i,j,k)) {
328  value += (*this)[dim](i,j,k);
329  wsum ++;
330  }
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));
333  wsum ++;
334  }
335  if( wsum == 2 ) {
336  v[dim] = 0.5 * value;
337  valid_count ++;
338  }
339  }
340  if( valid_count == 3 ) it.set(v);
341  else it.set_off();
342  });
343  }
350  void convert_to_full( macarray3<vec3<T> > &face_array ) const {
351  //
352  face_array.clear();
353  face_array.activate_as(*this);
354  face_array.parallel_actives([&](int dim, int i, int j, int k, auto &it, int tn) {
355  //
356  vec3d u;
357  for( int u_dim : DIMS3 ) {
358  if( u_dim == dim ) u[u_dim] = (*this)[u_dim](i,j,k);
359  else {
360  const shape3 s = (*this)[u_dim].shape();
361  vec3i pi = vec3i(i,j,k)-vec3i(dim==0,dim==1,dim==2);
362  vec3i ivec = vec3i(dim==0,dim==1,dim==2);
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));
366  }
367  u[u_dim] /= 4.0;
368  }
369  }
370  it.set(u);
371  });
372  }
379  shape3 shape() const { return m_shape; }
386  shape3 shape(int dim) const { return (*this)[dim].shape(); }
395  void clear() {
396  for( int dim : DIMS3 ) (*this)[dim].clear();
397  }
406  void clear(vec3<T> v) {
407  for( int dim : DIMS3 ) (*this)[dim].clear(v[dim]);
408  }
417  bool operator!=( const macarray3<T> &v ) const {
418  return ! (*this == v);
419  }
428  bool operator==(const macarray3<T> &v) const {
429  for( int dim : DIMS3 ) {
430  if ((*this)[dim] != v[dim]) return false;
431  }
432  return true;
433  }
440  void operator=(T v) {
441  for( int dim : DIMS3 ) (*this)[dim] = v;
442  }
449  void operator+=(const macarray3<T> &v) {
450  for( int dim : DIMS3 ) (*this)[dim] += v[dim];
451  }
458  void operator-=(const macarray3<T> &v) {
459  for( int dim : DIMS3 ) (*this)[dim] -= v[dim];
460  }
467  void operator+=(const vec3<T> &v) {
468  for( int dim : DIMS3 ) (*this)[dim] += v[dim];
469  }
476  void operator+=(T v) {
477  for( int dim : DIMS3 ) (*this)[dim] += v;
478  }
485  void operator-=(const vec3<T> &v) {
486  for( int dim : DIMS3 ) (*this)[dim] -= v[dim];
487  }
494  void operator-=(T v) {
495  for( int dim : DIMS3 ) (*this)[dim] -= v;
496  }
503  void operator*=(T v) {
504  for( int dim : DIMS3 ) (*this)[dim] *= v;
505  }
512  void operator/=(const T &v) {
513  for( int dim : DIMS3 ) (*this)[dim] /= v;
514  }
521  const array3<T>& operator[](int dim) const {
522  return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
523  }
530  array3<T>& operator[](int dim) {
531  return dim==0 ? m_array_0 : (dim == 1 ? m_array_1 : m_array_2 );
532  }
539  void set_thread_num( int number ) {
540  for( int dim : DIMS3 ) (*this)[dim].set_thread_num(number);
541  }
548  int get_thread_num() const {
549  return m_array_0.get_thread_num();
550  }
551  //
552  enum { ACTIVES = true, ALL = false };
559  void parallel_actives( std::function<void(typename array3<T>::iterator& it)> func ) { parallel_op(func,ACTIVES); }
566  void parallel_all( std::function<void(typename array3<T>::iterator& it)> func ) { parallel_op(func,ALL); }
575  void parallel_op( std::function<void(typename array3<T>::iterator& it)> func, bool type=ALL ) {
576  parallel_op([func](int dim, int i, int j, int k, typename array3<T>::iterator& it, int thread_index){
577  func(it);
578  },type);
579  }
586  void parallel_actives( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { parallel_op(func,ACTIVES); }
593  void parallel_all( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { parallel_op(func,ALL); }
602  void parallel_op( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func, bool type=ALL ) {
603  parallel_op([func](int dim, int i, int j, int k, typename array3<T>::iterator& it, int thread_index){
604  func(dim,i,j,k,it);
605  },type);
606  }
613  void parallel_actives( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it, int thread_index)> func ) { parallel_op(func,ACTIVES); }
620  void parallel_all( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it, int thread_index)> func ) { parallel_op(func,ALL); }
629  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 ) {
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);
633  },type);
634  };
635  }
642  void const_parallel_actives( std::function<void(const typename array3<T>::const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
649  void const_parallel_all( std::function<void(const typename array3<T>::const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
658  void const_parallel_op( std::function<void(const typename array3<T>::const_iterator& it)> func, bool type=ALL ) const {
659  const_parallel_op([func](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it, int thread_index){
660  func(it);
661  },type);
662  }
669  void const_parallel_actives( std::function<void(int dim, int i, int j, int k, const typename array3<T>::const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
676  void const_parallel_all( std::function<void(int dim, int i, int j, int k, const typename array3<T>::const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
685  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 {
686  const_parallel_op([func](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it, int thread_index){
687  func(dim,i,j,k,it);
688  },type);
689  }
696  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 { const_parallel_op(func,ACTIVES); }
703  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 { const_parallel_op(func,ALL); }
712  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 {
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);
716  },type);
717  };
718  }
725  void serial_actives( std::function<void(typename array3<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
732  void serial_all( std::function<void(typename array3<T>::iterator& it)> func ) { serial_op(func,ALL); }
741  void serial_op( std::function<void(typename array3<T>::iterator& it)> func, bool type=ALL ) {
742  serial_op([func](int dim, int i, int j, int k, typename array3<T>::iterator& it) {
743  func(it);
744  },type);
745  }
752  void serial_actives( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
759  void serial_all( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { serial_op(func,ALL); }
768  void serial_op( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func, bool type=ALL ) {
769  for( int dim : DIMS3 ) {
770  (*this)[dim].serial_op([&](int i, int j, int k, typename array3<T>::iterator& it) {
771  func(dim,i,j,k,it);
772  },type );
773  }
774  }
781  void const_serial_actives( std::function<void(const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
788  void const_serial_all( std::function<void(const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
797  void const_serial_op( std::function<void(const typename array3<T>::const_iterator& it)> func, bool type=ALL ) const {
798  const_serial_op([func](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it) {
799  func(it);
800  },type);
801  }
808  void const_serial_actives( std::function<void(int dim, int i, int j, int k, const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
815  void const_serial_all( std::function<void(int dim, int i, int j, int k, const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
824  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 {
825  for( int dim : DIMS3 ) {
826  (*this)[dim].const_serial_op([&](int i, int j, int k, const typename array3<T>::const_iterator& it) {
827  func(dim,i,j,k,it);
828  },type);
829  }
830  }
837  void interruptible_serial_actives( std::function<bool(typename array3<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
844  void interruptible_serial_all( std::function<bool(typename array3<T>::iterator& it)> func ) { serial_op(func,ALL); }
853  void interruptible_serial_op( std::function<bool(typename array3<T>::iterator& it)> func, bool type=ALL ) {
854  serial_op([func](int dim, int i, int j, int k, typename array3<T>::iterator& it) {
855  func(it);
856  },type);
857  }
864  void interruptible_serial_actives( std::function<bool(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
871  void interruptible_serial_all( std::function<bool(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func ) { serial_op(func,ALL); }
880  void interruptible_serial_op( std::function<bool(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func, bool type=ALL ) {
881  for( int dim : DIMS3 ) {
882  (*this)[dim].serial_op([&](int i, int j, int k, typename array3<T>::iterator& it) {
883  func(dim,i,j,k,it);
884  },type);
885  }
886  }
893  void interruptible_const_serial_actives( std::function<bool(const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
900  void interruptible_const_serial_all( std::function<bool(const typename array3<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
909  void interruptible_const_serial_op( std::function<bool(const typename array3<T>::const_iterator& it)> func, bool type=ALL ) const {
910  const_serial_op([func](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it) {
911  func(it);
912  },type);
913  }
920  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 { const_serial_op(func,ACTIVES); }
927  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 { const_serial_op(func,ALL); }
936  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 {
937  for( int dim : DIMS3 ) {
938  (*this)[dim].const_serial_op([&](int i, int j, int k, const typename array3<T>::const_iterator& it) {
939  func(dim,i,j,k,it);
940  },type);
941  }
942  }
951  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 ) {
952  while( count -- ) {
953  m_parallel.for_each(DIM3,[&]( size_t dim ) {
954  operator[](dim).dilate([&](int i, int j, int k, typename array3<T>::iterator& it, int thread_index) {
955  func(dim,i,j,k,it,thread_index);
956  });
957  });
958  }
959  }
968  void dilate( std::function<void(int dim, int i, int j, int k, typename array3<T>::iterator& it)> func, int count=1 ) {
969  dilate([&](int dim, int i, int j, int k, typename array3<T>::iterator& it, int thread_index) {
970  func(dim,i,j,k,it);
971  },count);
972  }
979  void dilate( int count=1 ) {
980  dilate([&](int dim, int i, int j, int k, typename array3<T>::iterator& it){ it.set(it()); },count);
981  }
990  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 ) {
991  while( count -- ) {
992  m_parallel.for_each(DIM3,[&]( size_t dim ) {
993  operator[](dim).erode([&](int i, int j, int k, const typename array3<T>::const_iterator& it, int thread_index) {
994  func(dim,i,j,it,thread_index);
995  });
996  });
997  }
998  }
1007  void erode( std::function<void(int dim, int i, int j, int k, const typename array3<T>::const_iterator& it)> func, int count=1 ) {
1008  erode([&](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it, int thread_index) {
1009  func(dim,i,j,it);
1010  },count);
1011  }
1018  void erode( int count=1 ) {
1019  return erode([&](int dim, int i, int j, int k, const typename array3<T>::const_iterator& it){ it.set(it()); },count);
1020  }
1027  void set_core_name( std::string core_name ) {
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);
1031  }
1038  std::string get_core_name() const {
1039  return m_array_0.get_core_name();
1040  }
1043  struct type3 {
1048  std::string core_name;
1075  bool operator==( const type3 &type ) const {
1076  return
1077  core_name == type.core_name && shape == type.shape &&
1078  type0 == type.type0 && type1 == type.type1 && type2 == type.type2;
1079  }
1080  };
1087  type3 type() const {
1088  return { get_core_name(), m_shape, m_array_0.type(), m_array_1.type(), m_array_2.type() };
1089  }
1096  void set_type( const type3 &type ) {
1097  m_shape = type.shape;
1098  m_array_0.set_type(type.type0);
1099  m_array_1.set_type(type.type1);
1100  m_array_2.set_type(type.type2);
1101  }
1102 private:
1103  parallel_driver m_parallel{this};
1104  array3<T> m_array_0;
1105  array3<T> m_array_1;
1106  array3<T> m_array_2;
1107  shape3 m_shape;
1108  //
1109 };
1110 //
1111 template <class T> static inline macarray3<T> operator*(double s, const macarray3<T> &v) {
1112  return v*s;
1113 }
1114 //
1116 //
1117 #endif
macarray3::operator+=
void operator+=(T v)
Increment all the grid values with an input value.
Definition: macarray3.h:476
macarray3::copy
void copy(const macarray3 &array)
Deep copy function for macarray3.
Definition: macarray3.h:141
macarray3::activate_as
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
macarray3::type3::type2
array3< T >::type3 type2
Type for z dimensional grid.
Definition: macarray3.h:1068
macarray3::activate_all
void activate_all()
Activate all the cells.
Definition: macarray3.h:250
macarray3::const_serial_all
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
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
macarray3::type3
Collection of properties of this grid.
Definition: macarray3.h:1043
macarray3::activate_as_bit
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
macarray3::serial_op
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
macarray3::const_serial_actives
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
macarray3::interruptible_serial_op
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
macarray3::const_parallel_op
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
parallel_driver
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
macarray3::set_core_name
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: macarray3.h:1027
macarray3::type3::type1
array3< T >::type3 type1
Type for y dimensional grid.
Definition: macarray3.h:1063
macarray3::interruptible_const_serial_op
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
macarray3::type3::operator==
bool operator==(const type3 &type) const
Check equality.
Definition: macarray3.h:1075
macarray3::parallel_all
void parallel_all(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray3.h:566
macarray3::parallel_op
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
macarray3::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: macarray3.h:548
macarray3::activate_inside_as
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
recursive_configurable::setup_now
virtual void setup_now(configuration &config=get_global_configuration()) override
Run recursive_load - recursive_configure - recursive_initialize processes.
Definition: configurable.h:227
macarray3::serial_op
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
macarray3::set_thread_num
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: macarray3.h:539
macarray3::clear
void clear()
Clear out the grid.
Definition: macarray3.h:395
macarray3::parallel_op
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
macarray3::parallel_actives
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
shape3 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:707
macarray3::const_serial_all
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
array3::const_iterator
Read-only iterator.
Definition: array3.h:1090
macarray3::operator[]
const array3< T > & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: macarray3.h:521
macarray3::dilate
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
shape3
Structure that defines a three dimensional shape such as width, height and depth.
Definition: shape.h:478
macarray3::operator=
macarray3 & operator=(const macarray3 &array)
Deep copy operation for macarray3.
Definition: macarray3.h:131
macarray3::erode
void erode(int count=1)
Erode cells.
Definition: macarray3.h:1018
macarray3::set_background_value
void set_background_value(const vec3< T > &value)
Set the background value (alternatively, initial value) of the grid.
Definition: macarray3.h:294
macarray3::activate
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
macarray3::activate_inside
void activate_inside()
Activate all the filled cells.
Definition: macarray3.h:259
macarray3::get_background_value
vec3< T > get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: macarray3.h:281
macarray3::const_parallel_all
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
macarray3::operator+=
void operator+=(const vec3< T > &v)
Increment all the grid values with an input vector value.
Definition: macarray3.h:467
macarray3::const_send_message
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: macarray3.h:118
macarray3::interruptible_const_serial_all
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
macarray3::type
type3 type() const
Get the type of this grid.
Definition: macarray3.h:1087
macarray3::actives
std::array< std::vector< vec3i >, DIM3 > actives() const
Function to return the list of active cells positions.
Definition: macarray3.h:187
macarray3::interruptible_const_serial_op
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
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
macarray3::const_parallel_actives
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
macarray3::const_parallel_actives
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
macarray3::parallel_all
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
macarray3::interruptible_const_serial_actives
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::macarray3
macarray3(const macarray3 &v)
Copy constructor for macarray3.
Definition: macarray3.h:88
macarray3::type3::core_name
std::string core_name
Core name of the module.
Definition: macarray3.h:1048
array3::type3
Collection of properties of this grid.
Definition: array3.h:1821
macarray3::interruptible_const_serial_all
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
macarray3::operator[]
array3< T > & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: macarray3.h:530
macarray3::convert_to_full
void convert_to_full(array3< vec3< T > > &cell_array) const
Convert staggered values to a cell centered full vector grid.
Definition: macarray3.h:305
macarray3::const_serial_op
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
macarray3::send_message
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: macarray3.h:101
macarray3::serial_actives
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::macarray3
macarray3(recursive_configurable *parent, const shape3 &shape, vec3< T > value=vec3< T >(), std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:51
macarray3::set_touch_only_actives
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
array3::iterator
Writable iterator.
Definition: array3.h:959
macarray3::const_serial_op
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
array3.h
macarray3::operator==
bool operator==(const macarray3< T > &v) const
Return if the grid is same to an input array.
Definition: macarray3.h:428
macarray3::operator*=
void operator*=(T v)
Multiply all the grid values with an input value.
Definition: macarray3.h:503
macarray3::interruptible_serial_actives
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
macarray3::interruptible_serial_op
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
macarray3::copy_active_as
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
macarray3::shape
shape3 shape() const
Get the shape of the array.
Definition: macarray3.h:379
macarray3::macarray3
macarray3(const shape3 &shape, vec3< T > value=vec3< T >(), std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:81
macarray3::operator-=
void operator-=(const macarray3< T > &v)
Subtract all the values with the values of an input array.
Definition: macarray3.h:458
macarray3::clear
void clear(vec3< T > v)
Clear out the grid with the new backgroud value.
Definition: macarray3.h:406
macarray3::serial_actives
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
macarray3::parallel_op
void parallel_op(std::function< void(typename array3< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray3.h:575
macarray3::serial_all
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
macarray3::operator-=
void operator-=(const vec3< T > &v)
Subtract all the grid values with an input vector value.
Definition: macarray3.h:485
recursive_configurable
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
macarray3::shape
shape3 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: macarray3.h:386
macarray3::serial_all
void serial_all(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray3.h:732
vec
Fixed sized vector structure.
Definition: vec.h:38
array3::iterator::set
void set(const T &value)
Set a value.
Definition: array3.h:968
macarray3::const_parallel_op
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
macarray3::const_parallel_all
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
macarray3::dilate
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
macarray3::get_core_name
std::string get_core_name() const
Get the core name of module of this grid.
Definition: macarray3.h:1038
macarray3::count
size_t count() const
Function to count the number of active cells.
Definition: macarray3.h:176
macarray3::erode
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
macarray3::set_type
void set_type(const type3 &type)
Set the type of this grid.
Definition: macarray3.h:1096
shape3::clamp
vec3i clamp(const vec3i &pi) const
Get the new constrained position within the index space of this shape.
Definition: shape.h:777
macarray3::type3::type0
array3< T >::type3 type0
Type for x dimensional grid.
Definition: macarray3.h:1058
macarray3::interruptible_const_serial_actives
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
macarray3::operator!=
bool operator!=(const macarray3< T > &v) const
Return if the grid is different from an input array.
Definition: macarray3.h:417
macarray3::type3::shape
shape3 shape
Shape of the grid.
Definition: macarray3.h:1053
macarray3::interruptible_serial_actives
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
messageable
Message class.
Definition: messageable.h:36
macarray3::const_parallel_actives
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
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
macarray3
Three dimensional staggered grid class designed to be defined as instance member in recursive_configu...
Definition: macarray3.h:37
macarray3::operator=
void operator=(T v)
Set all the grid values with an input value.
Definition: macarray3.h:440
macarray3::operator+=
void operator+=(const macarray3< T > &v)
Increment all the values with the values of an input array.
Definition: macarray3.h:449
macarray3::erode
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::macarray3
macarray3(std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:70
recursive_configurable::add_child
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
macarray3::convert_to_full
void convert_to_full(macarray3< vec3< T > > &face_array) const
Convert staggered values to the a centered full vector grid.
Definition: macarray3.h:350
macarray3::interruptible_serial_all
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
macarray3::dilate
void dilate(int count=1)
Dilate cells.
Definition: macarray3.h:979
macarray3::parallel_actives
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
macarray3::const_serial_actives
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::macarray3
macarray3(recursive_configurable *parent, std::string core_name="")
Constructor for macarray3.
Definition: macarray3.h:63
macarray3::operator/=
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: macarray3.h:512
macarray3::const_parallel_all
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
macarray3::parallel_actives
void parallel_actives(std::function< void(typename array3< T >::iterator &it)> func)
Loop over all the active cells in parallel.
Definition: macarray3.h:559
parallel_driver::for_each
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
macarray3::operator-=
void operator-=(T v)
Subtract all the grid values with an input value.
Definition: macarray3.h:494
macarray3::initialize
void initialize(const shape3 &shape, vec3< T > value=vec3< T >())
Allocate grid memory with value.
Definition: macarray3.h:155
macarray3::parallel_all
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
macarray3::interruptible_serial_all
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
macarray3::const_parallel_op
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
array3
Three dimensional array class designed to be defined as instance member in recursive_configurable cla...
Definition: array3.h:42