1 #ifndef MEDUSA_BITS_DOMAINS_GENERALFILL_HPP_
2 #define MEDUSA_BITS_DOMAINS_GENERALFILL_HPP_
21 template <
typename vec_t>
22 GeneralFill<vec_t>::GeneralFill() : seed_(
get_seed()) {}
25 template <
typename vec_t>
26 template <
typename func_t>
29 KDTreeMutable<vec_t> tree;
30 operator()(domain, h, tree, type);
33 template <
typename vec_t>
34 template <
typename func_t,
typename search_structure_t>
36 search_structure_t& search,
int type)
const {
37 if (type == 0) type = 1;
38 std::mt19937 gen(seed_);
39 KDTree<vec_t> boundary_search;
40 domain.makeDiscreteContainsStructure(boundary_search);
43 int end_node = domain.size();
45 vec_t lo_bound, hi_bound, random_node;
46 std::tie(lo_bound, hi_bound) = domain.shape().bbox();
47 std::vector<std::uniform_real_distribution<scalar_t>> distributions;
48 for (
int j = 0; j <
dim; ++j) distributions.emplace_back(lo_bound[j], hi_bound[j]);
51 for (
int j = 0; j <
dim; ++j) { random_node[j] = distributions[j](gen); }
52 if (++count >= 10000) {
53 std::string message =
"No suitable node in domain could be found after 10000 tries."
54 " This might happen if domain volume is very small compared "
55 "to the volume of the bounding box. Try manually supplying "
57 throw std::runtime_error(message);
59 }
while (!domain.contains(random_node, boundary_search));
60 domain.addInternalNode(random_node, type);
65 search.insert(domain.positions());
66 while (cur_node < end_node && end_node < max_points) {
67 vec_t p = domain.pos(cur_node);
69 assert_msg(r > 0,
"Nodal spacing radius should be > 0, got %g.", r);
74 for (
const auto& f : candidates) {
76 if (!domain.contains(node, boundary_search))
continue;
77 if (search.existsPointInSphere(node, r*zeta))
continue;
78 domain.addInternalNode(node, type);
84 if (end_node >= max_points) {
85 std::cerr <<
"Maximum number of points reached, fill may be incomplete." << std::endl;
89 template <
typename vec_t>
91 assert_msg((0 < zeta && zeta < 1),
"Zeta must be between 0 and 1, got %f.", zeta);
99 #endif // MEDUSA_BITS_DOMAINS_GENERALFILL_HPP_