BoundaryConstraint.cpp 3 KB
Newer Older
1 2
#include "BoundaryConstraint.h"
#include "DartConstraint.h"
3
#include "Mesh.h"
4

5 6 7 8 9 10 11 12
bool BoundaryConstraint::is_uniform(Mesh const &m) const {
    DartConstraint const &dc = m.dart_constraint(DartConstraints[0]);
    double_t delta_0{dc.delta()};

    for(size_t i : DartConstraints) {
        double delta_i{m.dart_constraint(i).delta()};
        if (std::abs(delta_0 - delta_i) > FLT_EPSILON) {
            return false;
13 14
        }
    }
15 16

    return true;
17 18
}

19 20
double BoundaryConstraint::smallest_parametric_edge_length(Mesh &m) const {
    double_t delta_min{DBL_MAX};
21

22 23 24 25
    for (size_t i : DartConstraints) {
        DartConstraint const &dc = m.dart_constraint(i);
        delta_min = std::min(delta_min, std::abs(dc.S1 - dc.S0));
    }
26

27 28
    return delta_min;
}
29

30 31
double BoundaryConstraint::queue_uniform(Mesh &m, double delta_min) const {
    double delta_max{delta_min};
32

33 34 35 36 37 38 39
    for(size_t i : DartConstraints) {
        DartConstraint const &dc = m.dart_constraint(i);
        double_t delta = std::abs(dc.S1 - dc.S0);
        if (delta > delta_min) {
            m.add_to_queue(std::make_unique<MidpointQueuer>(dc.dart()));

            delta_max = std::max(delta_max, delta);
40
        }
41
    }
42

43 44 45 46 47 48 49 50
    return delta_max;
}

void BoundaryConstraint::add_to_queue(Mesh &m, size_t dart) const {
    if (UniformDiscretization) {
        queue_uniform(m, smallest_parametric_edge_length(m) / 2.0);
    } else {
        m.add_to_queue(std::make_unique<MidpointQueuer>(dart));
51 52 53 54
    }
}


55
void BoundaryConstraint::make_uniform(Mesh &m) { make_uniform(m, smallest_parametric_edge_length(m)); };
56

57 58
void BoundaryConstraint::make_uniform(Mesh &m, double delta_min) {
    delta_min *= (1 + FLT_EPSILON);
59 60
    double_t delta_max{DBL_MAX};
    while (delta_max > delta_min) {
61 62 63 64
        delta_max = queue_uniform(m, delta_min);
        m.insert_from_queue();
    }
}
65

66 67 68 69 70 71
void BoundaryConstraint::refine(Mesh &m, double_t tol) {
    double_t err_max{DBL_MAX};

    while (err_max > tol) {
        err_max = 0.0;
        for (size_t i : DartConstraints) {
72
            DartConstraint const &dc = m.dart_constraint(i);
73 74 75 76 77 78

            double_t len_c = ConstraintCurve->length(dc.S0, dc.S1);
            double_t len_e = m.edge(dc.dart()).length(m);
            double_t err_i = std::abs(len_c - len_e) / len_c;

            if (err_i > tol) {
79 80
                m.add_to_queue(std::make_unique<MidpointQueuer>(dc.dart()));

81
                err_max = std::max(err_max, err_i);
82 83 84
            }
        }

85 86
        m.insert_from_queue();
    }
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
}

void BoundaryConstraint::sort_dart_constraints(Mesh const &m) {
    std::sort(DartConstraints.begin(), DartConstraints.end(),
              [&](size_t i, size_t j) { return m.dart_constraint(i).S0 < m.dart_constraint(j).S0; }
    );
}

std::vector<size_t> BoundaryConstraint::nodes(Mesh const &m) {
    sort_dart_constraints(m);
    std::vector<size_t> n;
    n.reserve(DartConstraints.size());
    for (size_t i : DartConstraints) {
        n.push_back(m.dart_constraint(i).base(m));
    }
102
    n.push_back(m.dart_constraint(DartConstraints.back()).tip(m));
103 104

    return n;
105
}