Shiokaze Framework
A research-oriented fluid solver for computer graphics
macarray2.h
Go to the documentation of this file.
1 /*
2 ** macarray2.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_MACARRAY2_H
26 #define SHKZ_MACARRAY2_H
27 //
28 #include <shiokaze/array/array2.h>
29 #include <algorithm>
30 #include <array>
31 //
33 //
35 template<class T> class macarray2 : public recursive_configurable, public messageable {
38 public:
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) {
52  if( parent ) parent->add_child(this);
53  else setup_now();
54  }
63  macarray2( recursive_configurable *parent, std::string core_name="" ) : macarray2(parent,shape2(0,0),vec2<T>(),core_name) {}
70  macarray2 ( std::string core_name="") : macarray2(nullptr,shape2(0,0),vec2<T>(),core_name) {}
81  macarray2( const shape2 &shape, vec2<T> value=vec2<T>(), std::string core_name="") : macarray2(nullptr,shape,value,core_name) {}
88  macarray2 ( const macarray2& v ) : m_array_0(this), m_array_1(this) {
89  copy(v);
90  }
91  //
102  virtual bool send_message( std::string message, void *ptr ) override {
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;
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  return handled;
123  }
130  macarray2& operator=(const macarray2 &array) {
131  copy(array);
132  return *this;
133  }
140  void copy( const macarray2 &array ) {
141  if( this != &array ) {
142  set_type(array.type());
143  for( int dim : DIMS2 ) (*this)[dim].copy(array[dim]);
144  }
145  }
154  void initialize ( const shape2 &shape, vec2<T> value=vec2<T>() ) {
155  m_shape = shape;
156  for( int dim : DIMS2 )(*this)[dim].initialize(shape.face(dim),value[dim]);
157  }
166  void set_touch_only_actives( bool touch_only_actives ) {
167  for( int dim : DIMS2 )(*this)[dim].set_touch_only_actives(touch_only_actives);
168  }
175  size_t count () const {
176  size_t sum (0);
177  for( int dim : DIMS2 ) sum += (*this)[dim].count();
178  return sum;
179  }
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();
190  });
191  return result;
192  }
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]);
204  });
205  }
214  template <class Y> void activate_as( const macarray2<Y> &array, const std::array<vec2i,DIM2> &offsets={vec2i(),vec2i()} ) {
215  m_parallel.for_each( DIM2, [&]( size_t dim ) {
216  (*this)[dim].activate_as(array[dim],offsets[dim]);
217  });
218  }
227  template <class Y> void activate_as_bit( const Y &array, const std::array<vec2i,DIM2> &offsets={vec2i(),vec2i()} ) {
228  m_parallel.for_each( DIM2, [&]( size_t dim ) {
229  (*this)[dim].activate_as_bit(array[dim],offsets[dim]);
230  });
231  }
240  template <class Y> void activate_inside_as( const macarray2<Y> &array, const std::array<vec2i,DIM2> &offsets={vec2i(),vec2i()} ) {
241  m_parallel.for_each( DIM2, [&]( size_t dim ) {
242  (*this)[dim].activate_inside_as(array[dim],offsets[dim]);
243  });
244  }
249  void activate_all() {
250  m_parallel.for_each( DIM2, [&]( size_t dim ) {
251  (*this)[dim].activate_all();
252  });
253  }
259  m_parallel.for_each( DIM2, [&]( size_t dim ) {
260  (*this)[dim].activate_inside();
261  });
262  }
271  template <class Y> void copy_active_as( const macarray2<Y> &array, const vec2i &offset=vec2i() ) {
272  m_parallel.for_each( DIM2, [&]( size_t dim ) {
273  (*this)[dim].copy_active_as(array[dim],offset);
274  });
275  }
281  return vec2<T>(
282  m_array_0.get_background_value(),
283  m_array_1.get_background_value()
284  );
285  }
292  void set_background_value( const vec2<T>& value ) {
293  m_array_0.set_background_value(value[0]);
294  m_array_1.set_background_value(value[1]);
295  }
302  void convert_to_full( array2<vec2<T> > &cell_array ) const {
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 ) {
307  vec2i pi (fi-vec2i(dim==0,dim==1));
308  if( ! m_shape.out_of_bounds(fi)) active_cells.push_back(fi);
309  if( ! m_shape.out_of_bounds(pi)) active_cells.push_back(pi);
310  }
311  }
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];
314  });
315  active_cells.erase( std::unique( active_cells.begin(), active_cells.end() ), active_cells.end() );
316  cell_array.clear(get_background_value());
317  cell_array.activate(active_cells);
318  cell_array.parallel_actives([&](int i, int j, auto &it, int tn) {
319  vec2d v;
320  char valid_count (0);
321  for( unsigned dim : DIMS2 ) {
322  char wsum (0);
323  double value (0.0);
324  if( (*this)[dim].active(i,j)) {
325  value += (*this)[dim](i,j);
326  wsum ++;
327  }
328  if( (*this)[dim].active(i+(dim==0),j+(dim==1))) {
329  value += (*this)[dim](i+(dim==0),j+(dim==1));
330  wsum ++;
331  }
332  if( wsum == 2 ) {
333  v[dim] = 0.5 * value;
334  valid_count ++;
335  }
336  }
337  if( valid_count == 2 ) it.set(v);
338  else it.set_off();
339  });
340  }
347  void convert_to_full( macarray2<vec2<T> > &face_array ) const {
348  //
349  face_array.clear();
350  face_array.activate_as(*this);
351  face_array.parallel_actives([&](int dim, int i, int j, auto &it, int tn) {
352  //
353  vec2d u;
354  for( int u_dim : DIMS2 ) {
355  if( u_dim == dim ) u[u_dim] = (*this)[u_dim](i,j);
356  else {
357  vec2i pi = vec2i(i,j)-vec2i(dim==0,dim==1);
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));
361  }
362  u[u_dim] /= 4.0;
363  }
364  }
365  it.set(u);
366  });
367  }
374  shape2 shape() const { return m_shape; }
381  shape2 shape(int dim) const { return (*this)[dim].shape(); }
390  void clear() {
391  for( int dim : DIMS2 )(*this)[dim].clear();
392  }
401  void clear(vec2<T> v) {
402  for( int dim : DIMS2 )(*this)[dim].clear(v[dim]);
403  }
412  bool operator!=( const macarray2<T> &v ) const {
413  return ! (*this == v);
414  }
423  bool operator==(const macarray2<T> &v) const {
424  for( int dim : DIMS2 ) {
425  if((*this)[dim] != v[dim]) return false;
426  }
427  return true;
428  }
435  void operator=(T v) {
436  for( int dim : DIMS2 ) (*this)[dim] = v;
437  }
444  void operator+=(const macarray2<T> &v) {
445  for( int dim : DIMS2 ) (*this)[dim] += v[dim];
446  }
453  void operator-=(const macarray2<T> &v) {
454  for( int dim : DIMS2 ) (*this)[dim] -= v[dim];
455  }
462  void operator+=(const vec2<T> &v) {
463  for( int dim : DIMS2 ) (*this)[dim] += v[dim];
464  }
471  void operator+=(T v) {
472  for( int dim : DIMS2 ) (*this)[dim] += v;
473  }
480  void operator-=(const vec2<T> &v) {
481  for( int dim : DIMS2 ) (*this)[dim] -= v[dim];
482  }
489  void operator-=(T v) {
490  for( int dim : DIMS2 ) (*this)[dim] -= v;
491  }
498  void operator*=(T v) {
499  for( int dim : DIMS2 ) (*this)[dim] *= v;
500  }
507  void operator/=(const T &v) {
508  for( int dim : DIMS2 ) (*this)[dim] /= v;
509  }
516  const array2<T>& operator[](int dim) const {
517  return dim==0 ? m_array_0 : m_array_1;
518  }
525  array2<T>& operator[](int dim) {
526  return dim==0 ? m_array_0 : m_array_1;
527  }
534  void set_thread_num( int number ) {
535  for( int dim : DIMS2 ) (*this)[dim].set_thread_num(number);
536  }
543  int get_thread_num() const {
544  return m_array_0.get_thread_num();
545  }
546  //
547  enum { ACTIVES = true, ALL = false };
554  void parallel_actives( std::function<void(typename array2<T>::iterator& it)> func ) { parallel_op(func,ACTIVES); }
561  void parallel_all( std::function<void(typename array2<T>::iterator& it)> func ) { parallel_op(func,ALL); }
570  void parallel_op( std::function<void(typename array2<T>::iterator& it)> func, bool type=ALL ) {
571  parallel_op([func](int dim, int i, int j, typename array2<T>::iterator& it, int thread_index){
572  func(it);
573  },type);
574  }
581  void parallel_actives( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { parallel_op(func,ACTIVES); }
588  void parallel_all( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { parallel_op(func,ALL); }
597  void parallel_op( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func, bool type=ALL ) {
598  parallel_op([func](int dim, int i, int j, typename array2<T>::iterator& it, int thread_index){
599  func(dim,i,j,it);
600  },type);
601  }
608  void parallel_actives( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it, int thread_index)> func ) { parallel_op(func,ACTIVES); }
615  void parallel_all( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it, int thread_index)> func ) { parallel_op(func,ALL); }
624  void parallel_op( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it, int thread_index)> func, bool type=ALL ) {
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);
628  },type);
629  }
630  }
637  void const_parallel_actives( std::function<void(const typename array2<T>::const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
644  void const_parallel_all( std::function<void(const typename array2<T>::const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
653  void const_parallel_op( std::function<void(const typename array2<T>::const_iterator& it)> func, bool type=ALL ) const {
654  const_parallel_op([func](int dim, int i, int j, const typename array2<T>::const_iterator& it, int thread_index){
655  func(it);
656  },type);
657  }
664  void const_parallel_actives( std::function<void(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_parallel_op(func,ACTIVES); }
671  void const_parallel_all( std::function<void(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_parallel_op(func,ALL); }
680  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 {
681  const_parallel_op([func](int dim, int i, int j, const typename array2<T>::const_iterator& it, int thread_index){
682  func(dim,i,j,it);
683  },type);
684  }
691  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 { const_parallel_op(func,ACTIVES); }
698  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 { const_parallel_op(func,ALL); }
707  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 {
708  for( int dim : DIMS2 ) {
709  (*this)[dim].const_parallel_op([&](int i, int j, const typename array2<T>::const_iterator& it, int thread_index) {
710  func(dim,i,j,it,thread_index);
711  },type);
712  };
713  }
720  void serial_actives( std::function<void(typename array2<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
727  void serial_all( std::function<void(typename array2<T>::iterator& it)> func ) { serial_op(func,ALL); }
736  void serial_op( std::function<void(typename array2<T>::iterator& it)> func, bool type=ALL ) {
737  serial_op([func](int dim, int i, int j, typename array2<T>::iterator& it) {
738  func(it);
739  },type);
740  }
747  void serial_actives( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
754  void serial_all( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { serial_op(func,ALL); }
763  void serial_op( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func, bool type=ALL ) {
764  for( int dim : DIMS2 ) {
765  (*this)[dim].serial_op([&](int i, int j, typename array2<T>::iterator& it) {
766  func(dim,i,j,it);
767  },type);
768  }
769  }
776  void const_serial_actives( std::function<void(const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
783  void const_serial_all( std::function<void(const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
792  void const_serial_op( std::function<void(const typename array2<T>::const_iterator& it)> func, bool type=ALL ) const {
793  const_serial_op([func](int dim, int i, int j, const typename array2<T>::const_iterator& it) {
794  func(it);
795  },type);
796  }
803  void const_serial_actives( std::function<void(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
810  void const_serial_all( std::function<void(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
819  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 {
820  for( int dim : DIMS2 ) {
821  (*this)[dim].const_serial_op([&](int i, int j, const typename array2<T>::const_iterator& it) {
822  func(dim,i,j,it);
823  },type);
824  }
825  }
832  void interruptible_serial_actives( std::function<bool(typename array2<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
839  void interruptible_serial_all( std::function<bool(typename array2<T>::iterator& it)> func ) { serial_op(func,ALL); }
848  void interruptible_serial_op( std::function<bool(typename array2<T>::iterator& it)> func, bool type=ALL ) {
849  serial_op([func](int dim, int i, int j, typename array2<T>::iterator& it) {
850  func(it);
851  },type);
852  }
859  void interruptible_serial_actives( std::function<bool(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { serial_op(func,ACTIVES); }
866  void interruptible_serial_all( std::function<bool(int dim, int i, int j, typename array2<T>::iterator& it)> func ) { serial_op(func,ALL); }
875  void interruptible_serial_op( std::function<bool(int dim, int i, int j, typename array2<T>::iterator& it)> func, bool type=ALL ) {
876  for( int dim : DIMS2 ) {
877  (*this)[dim].serial_op([&](int i, int j, typename array2<T>::iterator& it) {
878  func(dim,i,j,it);
879  },type);
880  }
881  }
888  void interruptible_const_serial_actives( std::function<bool(const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
895  void interruptible_const_serial_all( std::function<bool(const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
904  void interruptible_const_serial_op( std::function<bool(const typename array2<T>::const_iterator& it)> func, bool type=ALL ) const {
905  const_serial_op([func](int dim, int i, int j, const typename array2<T>::const_iterator& it) {
906  func(it);
907  },type);
908  }
915  void interruptible_const_serial_actives( std::function<bool(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ACTIVES); }
922  void interruptible_const_serial_all( std::function<bool(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func ) const { const_serial_op(func,ALL); }
931  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 {
932  for( int dim : DIMS2 ) {
933  (*this)[dim].const_serial_op([&](int i, int j, const typename array2<T>::const_iterator& it) {
934  func(dim,i,j,it);
935  },type);
936  }
937  }
946  void dilate( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it, int thread_index)> func, int count=1 ) {
947  while( count -- ) {
948  m_parallel.for_each(DIM2,[&]( size_t dim ) {
949  operator[](dim).dilate([&](int i, int j, typename array2<T>::iterator& it, int thread_index) {
950  func(dim,i,j,it,thread_index);
951  });
952  });
953  }
954  }
963  void dilate( std::function<void(int dim, int i, int j, typename array2<T>::iterator& it)> func, int count=1 ) {
964  dilate([&](int dim, int i, int j, typename array2<T>::iterator& it, int thread_index) {
965  func(dim,i,j,it);
966  },count);
967  }
974  void dilate( int count=1 ) {
975  dilate([&](int dim, int i, int j, typename array2<T>::iterator& it){ it.set(it()); },count);
976  }
985  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 ) {
986  while( count -- ) {
987  m_parallel.for_each(DIM2,[&]( size_t dim ) {
988  operator[](dim).erode([&](int i, int j, const typename array2<T>::const_iterator& it, int thread_index) {
989  func(dim,i,j,it,thread_index);
990  });
991  });
992  }
993  }
1002  void erode( std::function<void(int dim, int i, int j, const typename array2<T>::const_iterator& it)> func, int count=1 ) {
1003  erode([&](int dim, int i, int j, const typename array2<T>::const_iterator& it, int thread_index) {
1004  func(dim,i,j,it);
1005  },count);
1006  }
1013  void erode( int count=1 ) {
1014  return erode([&](int dim, int i, int j, const typename array2<T>::const_iterator& it){ it.set(it()); },count);
1015  }
1022  void set_core_name( std::string core_name ) {
1023  m_array_0.set_core_name(core_name);
1024  m_array_1.set_core_name(core_name);
1025  }
1032  std::string get_core_name() const {
1033  return m_array_0.get_core_name();
1034  }
1037  struct type2 {
1042  std::string core_name;
1064  bool operator==( const type2 &type ) const {
1065  return
1066  core_name == type.core_name && shape == type.shape &&
1067  type0 == type.type0 && type1 == type.type1;
1068  }
1069  };
1076  type2 type() const {
1077  return { get_core_name(), m_shape, m_array_0.type(), m_array_1.type() };
1078  }
1085  void set_type( const type2 &type ) {
1086  m_shape = type.shape;
1087  m_array_0.set_type(type.type0);
1088  m_array_1.set_type(type.type1);
1089  }
1090 private:
1091  parallel_driver m_parallel{this};
1092  array2<T> m_array_0;
1093  array2<T> m_array_1;
1094  shape2 m_shape;
1095 };
1096 //
1097 template <class T> static inline macarray2<T> operator*(double s, const macarray2<T> &v) {
1098  return v*s;
1099 }
1100 //
1102 //
1103 #endif
macarray2::macarray2
macarray2(const macarray2 &v)
Copy constructor for macarray2.
Definition: macarray2.h:88
macarray2::dilate
void dilate(int count=1)
Dilate cells.
Definition: macarray2.h:974
macarray2::erode
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
macarray2::const_parallel_actives
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
macarray2::set_core_name
void set_core_name(std::string core_name)
Set the core name of module of this grid.
Definition: macarray2.h:1022
macarray2::const_serial_op
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
macarray2::erode
void erode(int count=1)
Erode cells.
Definition: macarray2.h:1013
macarray2::dilate
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
macarray2::parallel_all
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
array2.h
macarray2::serial_op
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=
macarray2 & operator=(const macarray2 &array)
Deep copy operation for macarray2.
Definition: macarray2.h:130
parallel_driver
Class that facilitates the use of parallel_core class for parallel loop.
Definition: parallel_driver.h:44
macarray2::interruptible_const_serial_actives
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
macarray2::const_send_message
virtual bool const_send_message(std::string message, void *ptr) const override
Send a message to the core module.
Definition: macarray2.h:118
macarray2::copy
void copy(const macarray2 &array)
Deep copy function for macarray2.
Definition: macarray2.h:140
macarray2::const_serial_actives
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
macarray2::interruptible_serial_all
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
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
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
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
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
macarray2::erode
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
macarray2::convert_to_full
void convert_to_full(array2< vec2< T > > &cell_array) const
Convert staggered values to a cell centered full vector grid.
Definition: macarray2.h:302
macarray2::type2
Collection of properties of this grid.
Definition: macarray2.h:1037
macarray2::type2::type1
array2< T >::type2 type1
Type for y dimensional grid.
Definition: macarray2.h:1057
macarray2::interruptible_serial_op
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
macarray2::activate_as_bit
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
macarray2::interruptible_serial_actives
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
macarray2::type2::operator==
bool operator==(const type2 &type) const
Check equality.
Definition: macarray2.h:1064
macarray2::operator+=
void operator+=(T v)
Increment all the grid values with an input value.
Definition: macarray2.h:471
macarray2::shape
shape2 shape() const
Get the shape of the array.
Definition: macarray2.h:374
macarray2::const_parallel_all
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::macarray2
macarray2(recursive_configurable *parent, const shape2 &shape, vec2< T > value=vec2< T >(), std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:51
macarray2::initialize
void initialize(const shape2 &shape, vec2< T > value=vec2< T >())
Allocate grid memory with value.
Definition: macarray2.h:154
array2::type2
Collection of properties of this grid.
Definition: array2.h:1797
macarray2::const_parallel_op
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
macarray2::convert_to_full
void convert_to_full(macarray2< vec2< T > > &face_array) const
Convert staggered values to the a centered full vector grid.
Definition: macarray2.h:347
array2::iterator::set
void set(const T &value)
Set a value.
Definition: array2.h:946
macarray2::operator-=
void operator-=(T v)
Subtract all the grid values with an input value.
Definition: macarray2.h:489
macarray2::count
size_t count() const
Function to count the number of active cells.
Definition: macarray2.h:175
macarray2::set_background_value
void set_background_value(const vec2< T > &value)
Set the background value (alternatively, initial value) of the grid.
Definition: macarray2.h:292
macarray2::macarray2
macarray2(std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:70
macarray2::const_serial_all
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
shape2::out_of_bounds
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
macarray2::clear
void clear(vec2< T > v)
Clear out the grid with the new backgroud value.
Definition: macarray2.h:401
macarray2::type2::core_name
std::string core_name
Core name of the module.
Definition: macarray2.h:1042
macarray2::actives
std::array< std::vector< vec2i >, DIM2 > actives() const
Function to return the list of active cells positions.
Definition: macarray2.h:186
macarray2::parallel_actives
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
macarray2::operator==
bool operator==(const macarray2< T > &v) const
Return if the grid is same to an input array.
Definition: macarray2.h:423
macarray2::operator[]
array2< T > & operator[](int dim)
Get the reference to the staggered array of a specified dimension.
Definition: macarray2.h:525
macarray2::interruptible_serial_actives
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
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
macarray2::serial_actives
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
macarray2::operator/=
void operator/=(const T &v)
Divide all the grid values with an input value.
Definition: macarray2.h:507
macarray2::copy_active_as
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
macarray2::interruptible_serial_op
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
macarray2::dilate
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
macarray2::const_serial_all
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
macarray2::parallel_actives
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
macarray2::const_serial_actives
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
macarray2::get_background_value
vec2< T > get_background_value() const
Get the background value (alternatively, initial value) of the grid.
Definition: macarray2.h:280
shape2::face
shape2 face(int dim) const
Get the shape for the staggered grid of a specified dimension from this shape.
Definition: shape.h:257
macarray2::get_thread_num
int get_thread_num() const
Get the current number of threads for parallel processing on this grid.
Definition: macarray2.h:543
macarray2::const_parallel_all
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
macarray2::parallel_all
void parallel_all(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the cells in parallel.
Definition: macarray2.h:561
macarray2::activate_inside
void activate_inside()
Activate all the filled cells.
Definition: macarray2.h:258
macarray2::serial_all
void serial_all(std::function< void(typename array2< T >::iterator &it)> func)
Loop over all the cells in serial order.
Definition: macarray2.h:727
macarray2::operator[]
const array2< T > & operator[](int dim) const
Get the read-only reference to the staggered array of a specified dimension.
Definition: macarray2.h:516
macarray2::const_serial_op
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
macarray2::type
type2 type() const
Get the type of this grid.
Definition: macarray2.h:1076
macarray2::parallel_op
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
macarray2::const_parallel_all
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
macarray2::operator*=
void operator*=(T v)
Multiply all the grid values with an input value.
Definition: macarray2.h:498
macarray2::operator-=
void operator-=(const macarray2< T > &v)
Subtract all the values with the values of an input array.
Definition: macarray2.h:453
macarray2::parallel_op
void parallel_op(std::function< void(typename array2< T >::iterator &it)> func, bool type=ALL)
Loop over cells in parallel.
Definition: macarray2.h:570
macarray2::clear
void clear()
Clear out the grid.
Definition: macarray2.h:390
recursive_configurable
Extended configurable class that holds multiple children of configurable.
Definition: configurable.h:126
macarray2::const_parallel_actives
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
macarray2::get_core_name
std::string get_core_name() const
Get the core name of module of this grid.
Definition: macarray2.h:1032
vec
Fixed sized vector structure.
Definition: vec.h:38
macarray2::interruptible_serial_all
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
macarray2::operator=
void operator=(T v)
Set all the grid values with an input value.
Definition: macarray2.h:435
macarray2::shape
shape2 shape(int dim) const
Get the shape of the staggered grid of a specified dimension.
Definition: macarray2.h:381
macarray2::interruptible_const_serial_all
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
macarray2::type2::shape
shape2 shape
Shape of the grid.
Definition: macarray2.h:1047
macarray2::macarray2
macarray2(const shape2 &shape, vec2< T > value=vec2< T >(), std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:81
array2
Two dimensional array class designed to be defined as instance member in recursive_configurable class...
Definition: array2.h:42
macarray2::parallel_all
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
macarray2::interruptible_const_serial_all
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
macarray2::operator+=
void operator+=(const macarray2< T > &v)
Increment all the values with the values of an input array.
Definition: macarray2.h:444
macarray2::serial_all
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
array2::iterator
Writable iterator.
Definition: array2.h:937
macarray2::operator+=
void operator+=(const vec2< T > &v)
Increment all the grid values with an input vector value.
Definition: macarray2.h:462
macarray2::serial_op
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
macarray2::const_parallel_op
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
macarray2::activate_all
void activate_all()
Activate all the cells.
Definition: macarray2.h:249
macarray2::serial_actives
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
macarray2::type2::type0
array2< T >::type2 type0
Type for x dimensional grid.
Definition: macarray2.h:1052
shape2
Structure that defines shape such as width, height.
Definition: shape.h:42
messageable
Message class.
Definition: messageable.h:36
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::const_parallel_actives
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
macarray2::send_message
virtual bool send_message(std::string message, void *ptr) override
Send a message to the core module.
Definition: macarray2.h:102
macarray2::set_thread_num
void set_thread_num(int number)
Set the number of threads for parallel processing on this grid.
Definition: macarray2.h:534
macarray2::macarray2
macarray2(recursive_configurable *parent, std::string core_name="")
Constructor for macarray2.
Definition: macarray2.h:63
macarray2::activate_inside_as
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
macarray2::operator-=
void operator-=(const vec2< T > &v)
Subtract all the grid values with an input vector value.
Definition: macarray2.h:480
macarray2::operator!=
bool operator!=(const macarray2< T > &v) const
Return if the grid is different from an input array.
Definition: macarray2.h:412
macarray2
Two dimensional staggered grid class designed to be defined as instance member in recursive_configura...
Definition: macarray2.h:37
macarray2::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: macarray2.h:166
macarray2::set_type
void set_type(const type2 &type)
Set the type of this grid.
Definition: macarray2.h:1085
recursive_configurable::add_child
virtual void add_child(configurable *child)
Add a child instance.
Definition: configurable.h:191
macarray2::parallel_op
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
macarray2::interruptible_const_serial_actives
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
array2::const_iterator
Read-only iterator.
Definition: array2.h:1069
macarray2::interruptible_const_serial_op
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
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
macarray2::const_parallel_op
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
macarray2::interruptible_const_serial_op
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