Medusa  1.1
Coordinate Free Mehless Method implementation
GridFill.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_DOMAINS_GRIDFILL_HPP_
2 #define MEDUSA_BITS_DOMAINS_GRIDFILL_HPP_
3 
9 #include "GridFill_fwd.hpp"
14 
15 namespace mm {
16 
17 template <typename vec_t>
18 GridFill<vec_t>::GridFill(const vec_t& bot, const vec_t& top) : bot(bot), top(top) {
19  for (int i = 0; i < dim; ++i) {
20  assert_msg(bot[i] <= top[i], "Bottom bounds %s must be below top bounds %s.", bot, top);
21  }
22 }
23 
24 template <typename vec_t>
26  int type) const {
27  if (type == 0) type = 1;
28  Vec<int, dim> counts;
29  for (int i = 0; i < dim; ++i) {
30  counts[i] = iceil((top[i] - bot[i]) / h) + 1;
31  }
32 
33  KDTree<vec_t> tree(domain.positions());
34  for (const auto& x : linspace(bot, top, counts)) {
35  if (domain.contains(x) && (tree.size() == 0 || tree.query(x, 1).second[0] >= h*h)) {
36  domain.addInternalNode(x, type);
37  }
38  }
39 }
40 
41 } // namespace mm
42 
43 #endif // MEDUSA_BITS_DOMAINS_GRIDFILL_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::GridFill::bot
vec_t bot
Bottom left corner of the box to fill.
Definition: GridFill_fwd.hpp:38
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
mm::Vec
Eigen::Matrix< scalar_t, dim, 1, Eigen::ColMajor|Eigen::AutoAlign, dim, 1 > Vec
Fixed size vector type, representing a mathematical 1d/2d/3d vector.
Definition: Vec_fwd.hpp:31
mm::KDTree
Class representing a static k-d tree data structure.
Definition: KDTree_fwd.hpp:36
DomainDiscretization.hpp
mm::GridFill::dim
@ dim
Dimensionality of the domain.
Definition: GridFill_fwd.hpp:35
mm::GridFill::scalar_t
vec_t::scalar_t scalar_t
Scalar type;.
Definition: GridFill_fwd.hpp:32
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
GridFill_fwd.hpp
mm::GridFill::GridFill
GridFill(const vec_t &bot, const vec_t &top)
Prepare to fill domain within [bot, top] bounding box.
Definition: GridFill.hpp:18
numutils.hpp
mm::DomainDiscretization::positions
const Range< vec_t > & positions() const
Returns positions of all nodes.
Definition: DomainDiscretization_fwd.hpp:127
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::KDTree::query
std::pair< Range< int >, Range< scalar_t > > query(const vec_t &point, int k=1) const
Find k nearest neighbors to given point.
Definition: KDTree.hpp:16
mm::iceil
int iceil(T x)
Ceils a floating point to an integer.
Definition: numutils.hpp:27
mm::linspace
Range< Vec< scalar_t, dim > > linspace(const Vec< scalar_t, dim > &beg, const Vec< scalar_t, dim > &end, const Vec< int, dim > &counts, const Vec< bool, dim > include_boundary=true)
Multidimensional clone of Matlab's linspace function.
Definition: numutils.hpp:210
mm::DomainDiscretization::contains
bool contains(const vec_t &point) const
Returns true if point is inside the domain.
Definition: DomainDiscretization.hpp:315
mm::KDTree::size
int size() const
Returns number of points in this tree.
Definition: KDTree_fwd.hpp:126
KDTree.hpp
assert.hpp
mm::GridFill::top
vec_t top
Top right corner of the box to fill.
Definition: GridFill_fwd.hpp:39
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::GridFill::operator()
void operator()(DomainDiscretization< vec_t > &domain, const scalar_t &h, int type=0) const
Fills domain with a grid node distribution with spacing h.
Definition: GridFill.hpp:25