Medusa  1.1
Coordinate Free Mehless Method implementation
DomainDiscretization_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_DOMAINS_DOMAINDISCRETIZATION_FWD_HPP_
2 #define MEDUSA_BITS_DOMAINS_DOMAINDISCRETIZATION_FWD_HPP_
3 
11 #include <medusa/Config.hpp>
16 #include <iosfwd>
17 #include <string>
18 
19 namespace mm {
20 
21 template <typename vec_t, typename OpFamilies>
23 
45 template <class vec_t>
47  public:
48  typedef vec_t vector_t;
49  typedef typename vec_t::Scalar scalar_t;
50  enum { dim = vec_t::dim };
52 
53  protected:
55 
73 
86 
98 
101 
102  public:
105 
123  template <typename hdf5_file>
124  static DomainDiscretization<vec_t> load(hdf5_file& file, const std::string& name);
125 
127  const Range<vec_t>& positions() const { return positions_; }
129  const vec_t& pos(int i) const { return positions_[i]; }
131  vec_t& pos(int i) { return positions_[i]; }
133  scalar_t pos(int i, int j) const { return positions_[i][j]; }
135  const Range<Range<int>>& supports() const { return support_; }
138  const Range<int>& support(int i) const { return support_[i]; }
140  Range<int>& support(int i) { return support_[i]; }
142  int support(int i, int j) const { return support_[i][j]; }
144  Range<vec_t> supportNodes(int i) const { return positions_[support_[i]]; }
146  vec_t supportNode(int i, int j) const { return positions_[support_[i][j]]; }
148  scalar_t dr(int i) const { return (positions_[i] - positions_[support_[i][1]]).norm(); }
150  int supportSize(int i) const { return support_[i].size(); }
152  Range<int> supportSizes() const;
154  const Range<int>& types() const { return types_; }
156  Range<int>& types() { return types_; }
158  int type(int i) const { return types_[i]; }
160  int& type(int i) { return types_[i]; }
162  const DomainShape<vec_t>& shape() const { return *shape_; }
163 
165  const Range<int>& bmap() const { return boundary_map_; }
170  int bmap(int node) const { return boundary_map_[node]; }
172  const Range<vec_t>& normals() const { return normals_; }
177  const vec_t& normal(int i) const;
179  vec_t& normal(int i);
180 
182  indexes_t boundary() const { return types_ < 0; }
184  indexes_t interior() const { return types_ > 0; }
186  indexes_t all() const { return types_ != 0; }
187 
189  int size() const { return positions_.size(); }
190 
198  int addInternalNode(const vec_t& point, int type);
199 
208  int addBoundaryNode(const vec_t& point, int type, const vec_t& normal);
209 
210  private:
212  int addNode(const vec_t& point, int type);
223  void chopOff(const DomainDiscretization<vec_t>& d, const Range<int>& relevant);
224 
225  public:
231 
233  void changeToBoundary(int i, const vec_t& point, int type, const vec_t& normal);
234 
236  void changeToInterior(int i, const vec_t& point, int type);
237 
241  template <typename func_t>
242  Range<int> addGhostNodes(func_t h, int type = 0);
244  Range<int> addGhostNodes(scalar_t h, int type, const indexes_t& indexes);
275  template <typename func_t>
276  Range<int> addGhostNodes(func_t h, int type, const indexes_t& indexes);
277 
288  void shuffleNodes(const indexes_t& permutation);
289 
300  template <typename compare_t = std::less<std::pair<vec_t, int>>>
301  Range<int> reorderNodes(const compare_t& cmp = compare_t());
302 
332 
362 
364  DomainDiscretization& translate(const vec_t& a);
365 
367  DomainDiscretization& rotate(const Eigen::Matrix<scalar_t, dim, dim>& Q);
368 
371 
376  void assert_is_valid() const;
377 
382  void clear();
383 
385  void removeNodes(const Range<int>& to_remove);
386 
389 
392 
399  bool contains(const vec_t& point) const;
400 
415  template <typename search_structure_t>
416  bool discreteContains(const vec_t& point, const search_structure_t& search) const;
417 
424  template <typename search_structure_t>
425  bool contains(const vec_t& point, const search_structure_t& search) const;
426 
433  template <typename search_structure_t>
434  void makeDiscreteContainsStructure(search_structure_t& search) const;
435 
436  // TODO(jureslak): optimize order of nodes for matrix fill -- sort by x coordinate or sth...
437  // TODO(jureslak): symmetrize support?
438 
439  // ENGINE PLUGINS
441  #define DOMAIN_PLUGIN(Name) \
442  template<typename callable_t, typename... Args> \
443  void Name(callable_t& callable, Args&&... args) { \
444  return callable(*this, std::forward<Args>(args)...); \
445  }
446 
448  #define DOMAIN_PLUGIN_CONST(Name) \
449  template<typename callable_t, typename... Args> \
450  void Name(const callable_t& callable, Args&&... args) { \
451  callable(*this, std::forward<Args>(args)...); \
452  }
453 
466 
467 
470  template <sh::shape_flags mask = sh::all, typename approx_t>
471  RaggedShapeStorage<vec_t, typename sh::operator_tuple<mask, vec_t::dim>::type> computeShapes(
472  approx_t approx, const indexes_t& indexes = {}) const;
474  template <typename OperatorTuple, typename approx_t>
476  approx_t approx, const indexes_t& indexes = {}) const;
478  template <typename OperatorTuple, typename approx_t>
479  RaggedShapeStorage<vec_t, OperatorTuple> computeShapes(OperatorTuple operators,
480  approx_t approx, const indexes_t& indexes = {}) const;
482  template <class V>
483  friend std::ostream& operator<<(std::ostream& os, const DomainDiscretization<V>& d);
484  private:
486  std::ostream& output_report(std::ostream& os = std::cout) const;
487 };
488 
490 template <class vec_t>
491 std::ostream& operator<<(std::ostream& os, const DomainDiscretization<vec_t>& d) {
492  os << "Domain:\n";
493  return d.output_report(os);
494 }
495 
496 } // namespace mm
497 
498 #endif // MEDUSA_BITS_DOMAINS_DOMAINDISCRETIZATION_FWD_HPP_
mm::DomainDiscretization::boundary_map_
Range< int > boundary_map_
Mapping index of a boundary node among all nodes, to its index among boundary nodes.
Definition: DomainDiscretization_fwd.hpp:85
mm::DomainDiscretization::support
int support(int i, int j) const
Returns j-th support node of i-th node.
Definition: DomainDiscretization_fwd.hpp:142
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::DomainDiscretization::addNodes
indexes_t addNodes(const DomainDiscretization< vec_t > &d)
Add nodes from another discretization to this discretization.
Definition: DomainDiscretization.hpp:104
shape_flags.hpp
mm::DomainDiscretization::dr
scalar_t dr(int i) const
Returns Euclidean distance to the second support node.
Definition: DomainDiscretization_fwd.hpp:148
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
mm::DomainDiscretization::interior
indexes_t interior() const
Returns indexes of all internal nodes.
Definition: DomainDiscretization_fwd.hpp:184
mm::DomainDiscretization::add
DomainDiscretization & add(const DomainDiscretization &d)
Merges given discretization to the current discretization.
Definition: DomainDiscretization.hpp:274
mm::DomainDiscretization::reorderNodes
Range< int > reorderNodes(const compare_t &cmp=compare_t())
Reorders nodes according to the compare function.
Definition: DomainDiscretization.hpp:441
mm::DomainDiscretization::all
indexes_t all() const
Returns indexes of all nodes, i.e. {0, 1, ..., N-1}.
Definition: DomainDiscretization_fwd.hpp:186
mm::DomainDiscretization::chopOff
void chopOff(const DomainDiscretization< vec_t > &d, const Range< int > &relevant)
Remove a portion of this domain which is contained in d or is only dx away.
Definition: DomainDiscretization.hpp:243
mm::DomainDiscretization::removeInternalNodes
void removeInternalNodes()
Removes all internal nodes.
Definition: DomainDiscretization_fwd.hpp:388
mm::DomainDiscretization::pos
vec_t & pos(int i)
Returns writeable position of i-th node.
Definition: DomainDiscretization_fwd.hpp:131
mm::DomainDiscretization::bmap
const Range< int > & bmap() const
Returns boundary map.
Definition: DomainDiscretization_fwd.hpp:165
mm::DomainDiscretization::clear
void clear()
Clears all data about this discretization.
Definition: DomainDiscretization.hpp:170
mm::DomainDiscretization::types_
Range< int > types_
Storing types of nodes aligned with positions.
Definition: DomainDiscretization_fwd.hpp:72
mm::DomainDiscretization::normals
const Range< vec_t > & normals() const
Returns normals of all boundary nodes.
Definition: DomainDiscretization_fwd.hpp:172
mm::DomainDiscretization::translate
DomainDiscretization & translate(const vec_t &a)
Translate the domain by a given vector a.
Definition: DomainDiscretization.hpp:411
mm::DomainDiscretization::output_report
std::ostream & output_report(std::ostream &os=std::cout) const
Outputs a simple report about out domain, like number of nodes, support size.
Definition: DomainDiscretization.hpp:209
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::DomainDiscretization::operator<<
friend std::ostream & operator<<(std::ostream &os, const DomainDiscretization< V > &d)
Output basic info about given domain.
mm::sh::shape_flags
unsigned int shape_flags
Type representing flags for shape functions.
Definition: shape_flags.hpp:22
mm::DomainDiscretization::supportNodes
Range< vec_t > supportNodes(int i) const
Returns positions of support nodes of i-th node.
Definition: DomainDiscretization_fwd.hpp:144
mm::DomainDiscretization::assert_is_valid
void assert_is_valid() const
Checks if domain is in valid state.
Definition: DomainDiscretization.hpp:179
mm::operator<<
std::ostream & operator<<(std::ostream &os, const Gaussian< S > &b)
Output basic information about given Gaussian RBF.
Definition: Gaussian.hpp:37
mm::DomainDiscretization::positions
const Range< vec_t > & positions() const
Returns positions of all nodes.
Definition: DomainDiscretization_fwd.hpp:127
mm::DomainDiscretization::operator-=
DomainDiscretization & operator-=(const DomainDiscretization &d)
Operator version of DomainDiscretization::subtract.
Definition: DomainDiscretization_fwd.hpp:361
mm::DomainDiscretization::support_
Range< Range< int > > support_
Attribute used to store support points of each node.
Definition: DomainDiscretization_fwd.hpp:60
mm::DomainDiscretization::dim
@ dim
Dimensionality of the domain.
Definition: DomainDiscretization_fwd.hpp:51
mm::DomainDiscretization::addGhostNodes
Range< int > addGhostNodes(scalar_t h, int type=0)
Overload of addGhostNodes with constant h and adds ghost nodes to all boundary nodes.
Definition: DomainDiscretization.hpp:137
mm::DomainShape
Base class for geometric shapes of domains.
Definition: DomainShape_fwd.hpp:52
mm::DomainDiscretization::supportSize
int supportSize(int i) const
Returns size of i-th node support.
Definition: DomainDiscretization_fwd.hpp:150
mm::DomainDiscretization::types
const Range< int > & types() const
Returns types of all nodes.
Definition: DomainDiscretization_fwd.hpp:154
Config.hpp
DOMAIN_PLUGIN_CONST
#define DOMAIN_PLUGIN_CONST(Name)
Const version of DOMAIN_PLUGIN.
Definition: DomainDiscretization_fwd.hpp:448
mm::DomainDiscretization::normal
const vec_t & normal(int i) const
Returns outside unit normal of i-th node.
Definition: DomainDiscretization.hpp:40
mm::DomainDiscretization::changeToBoundary
void changeToBoundary(int i, const vec_t &point, int type, const vec_t &normal)
Changes node i to boundary point with given type and normal.
Definition: DomainDiscretization.hpp:75
DOMAIN_PLUGIN
#define DOMAIN_PLUGIN(Name)
Define a method Name that calls its first argument.
Definition: DomainDiscretization_fwd.hpp:441
mm::DomainDiscretization::size
int size() const
Returns N, the number of nodes in this discretization.
Definition: DomainDiscretization_fwd.hpp:189
mm::DomainDiscretization::shape
const DomainShape< vec_t > & shape() const
Returns geometric shape of the underlying domain.
Definition: DomainDiscretization_fwd.hpp:162
mm::DomainDiscretization::type
int type(int i) const
Returns type of i-th node.
Definition: DomainDiscretization_fwd.hpp:158
mm::DomainDiscretization::relax
void relax(callable_t &callable, Args &&... args)
Enables more readable calls to relax engines.
Definition: DomainDiscretization_fwd.hpp:463
mm::indexes_t
std::vector< int > indexes_t
Class representing a collection of indices.
Definition: Config.hpp:36
mm::DomainDiscretization::type
int & type(int i)
Returns writeable type of i-th node.
Definition: DomainDiscretization_fwd.hpp:160
Range_fwd.hpp
mm::DomainDiscretization::contains
bool contains(const vec_t &point) const
Returns true if point is inside the domain.
Definition: DomainDiscretization.hpp:315
mm::DomainDiscretization::makeDiscreteContainsStructure
void makeDiscreteContainsStructure(search_structure_t &search) const
Fills the search structure search with boundary points for use with contains() or discreteContains().
Definition: DomainDiscretization.hpp:342
mm::DomainDiscretization::findSupport
void findSupport(callable_t &callable, Args &&... args)
Enables more readable calls to support engines.
Definition: DomainDiscretization_fwd.hpp:455
mm::DomainDiscretization::bmap
int bmap(int node) const
Returns index of node node among only boundary nodes.
Definition: DomainDiscretization_fwd.hpp:170
mm::DomainDiscretization::discreteContains
bool discreteContains(const vec_t &point, const search_structure_t &search) const
A discrete version of contains using given boundary discretization.
Definition: DomainDiscretization.hpp:323
mm::DomainDiscretization::rotate
DomainDiscretization & rotate(const Eigen::Matrix< scalar_t, dim, dim > &Q)
Transform the domain by given orthogonal matrix Q.
Definition: DomainDiscretization.hpp:420
mm::DomainDiscretization::support
Range< int > & support(int i)
Returns writeable array of support indices for i-th node.
Definition: DomainDiscretization_fwd.hpp:140
mm::DomainDiscretization::fill
void fill(callable_t &callable, Args &&... args)
Enables more readable calls to fill engines.
Definition: DomainDiscretization_fwd.hpp:459
mm::DomainDiscretization::removeNodes
void removeNodes(const Range< int > &to_remove)
Remove nodes with given indices. This removes their types and potential normals as well.
Definition: DomainDiscretization.hpp:117
mm::DomainDiscretization::vector_t
vec_t vector_t
Vector data type used in computations.
Definition: DomainDiscretization_fwd.hpp:48
mm::DomainDiscretization::addInternalNode
int addInternalNode(const vec_t &point, int type)
Adds a single interior node with specified type to this discretization.
Definition: DomainDiscretization.hpp:49
mm::DomainDiscretization::pos
const vec_t & pos(int i) const
Returns the position of i-th node.
Definition: DomainDiscretization_fwd.hpp:129
mm::DomainDiscretization::subtract
DomainDiscretization & subtract(const DomainDiscretization &d)
Subtracts given discretized domain from *this.
Definition: DomainDiscretization.hpp:298
mm::RaggedShapeStorage
Efficiently stores shape functions of different lengths.
Definition: DomainDiscretization_fwd.hpp:22
mm::DomainDiscretization::boundary
indexes_t boundary() const
Returns indexes of all boundary nodes.
Definition: DomainDiscretization_fwd.hpp:182
mm::DomainDiscretization::supportNode
vec_t supportNode(int i, int j) const
Returns position of j-th support node of i-th node.
Definition: DomainDiscretization_fwd.hpp:146
mm::DomainDiscretization::removeBoundaryNodes
void removeBoundaryNodes()
Removes all boundary nodes.
Definition: DomainDiscretization_fwd.hpp:391
mm::Range::size
int size() const
Returns number of elements.
Definition: Range_fwd.hpp:185
mm::DomainDiscretization::computeShapes
RaggedShapeStorage< vec_t, typename sh::operator_tuple< mask, vec_t::dim >::type > computeShapes(approx_t approx, const indexes_t &indexes={}) const
Compute shapes, specified with shape flags, for this domain with given approximation for given indexe...
mm::DomainDiscretization::shuffleNodes
void shuffleNodes(const indexes_t &permutation)
Shuffles node order according to given permutation.
Definition: DomainDiscretization.hpp:453
mm::DomainDiscretization::load
static DomainDiscretization< vec_t > load(hdf5_file &file, const std::string &name)
Load discretization from a HD5 file.
Definition: DomainDiscretization.hpp:354
mm::DomainDiscretization::scalar_t
vec_t::Scalar scalar_t
Scalar data type used in computation.
Definition: DomainDiscretization_fwd.hpp:49
mm::DomainDiscretization::supportSizes
Range< int > supportSizes() const
Returns a vector of support sizes for each node.
Definition: DomainDiscretization.hpp:21
mm::DomainDiscretization::operator+=
DomainDiscretization & operator+=(const DomainDiscretization &d)
Operator version of DomainDiscretization::add.
Definition: DomainDiscretization_fwd.hpp:331
mm::DomainDiscretization::support
const Range< int > & support(int i) const
Returns support indices for i-th node.
Definition: DomainDiscretization_fwd.hpp:138
mm::DomainDiscretization::DomainDiscretization
DomainDiscretization(const DomainShape< vec_t > &shape)
Construct an empty discretization for a given shape.
Definition: DomainDiscretization.hpp:239
mm::DomainDiscretization::types
Range< int > & types()
Returns mutable types of all nodes.
Definition: DomainDiscretization_fwd.hpp:156
mm::DomainDiscretization::normals_
Range< vec_t > normals_
List of normals of boundary nodes.
Definition: DomainDiscretization_fwd.hpp:97
mm::DomainDiscretization::positions_
Range< vec_t > positions_
Positions of internal discretization points.
Definition: DomainDiscretization_fwd.hpp:54
mm::DomainDiscretization::pos
scalar_t pos(int i, int j) const
Returns j-th coordinate of the position of i-th node.
Definition: DomainDiscretization_fwd.hpp:133
memutils.hpp
mm::Range< vec_t >
mm::DomainDiscretization::changeToInterior
void changeToInterior(int i, const vec_t &point, int type)
Changes node i to interior point with given type.
Definition: DomainDiscretization.hpp:88
mm::DomainDiscretization::supports
const Range< Range< int > > & supports() const
Returns support indices for all nodes.
Definition: DomainDiscretization_fwd.hpp:135
mm::DomainDiscretization::addNode
int addNode(const vec_t &point, int type)
Helper for adding points to the domain, which keeps the object consistent.
Definition: DomainDiscretization.hpp:66
mm::DomainDiscretization::shape_
deep_copy_unique_ptr< DomainShape< vec_t > > shape_
Geometric shape of the domain.
Definition: DomainDiscretization_fwd.hpp:100
mm::deep_copy_unique_ptr
Unique pointer with polymorphic deep copy semantics.
Definition: DomainShape_fwd.hpp:22
mm::DomainDiscretization::addBoundaryNode
int addBoundaryNode(const vec_t &point, int type, const vec_t &normal)
Adds a boundary node with given type and normal to the domain.
Definition: DomainDiscretization.hpp:56
DomainShape_fwd.hpp