BoundaryConstraint.cpp 1.98 KB
Newer Older
1
2
#include "BoundaryConstraint.h"
#include "DartConstraint.h"
3
#include "Mesh.h"
4
5
6
7
8
9
10
11
12
13
14

void BoundaryConstraint::add_to_queue(std::vector<std::unique_ptr<InsertionQueuer>> &queue, std::vector<DartConstraint> &constraints, size_t dart_constraint) {
    if (UniformDiscretization) {
        for (size_t dc : DartConstraints) {
            size_t dart = constraints[dc].dart();
            queue.push_back(std::make_unique<MidpointQueuer>(dart));
        }
    } else {
        size_t dart = constraints[dart_constraint].dart();
        queue.push_back(std::make_unique<MidpointQueuer>(dart));
    }
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
}

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) {
            DartConstraint const &dc = m.dart_constraint(i);

            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) {
                m.add_to_queue(std::make_unique<MidpointQueuer>(dc.dart()));

                err_max = std::max(err_max, err_i);
            }
        }

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        m.insert_from_queue();
    }
}

void BoundaryConstraint::make_uniform(Mesh &m) {
    double_t delta_min{DBL_MAX};

    for (size_t i : DartConstraints) {
        DartConstraint const &dc = m.dart_constraint(i);
        delta_min = std::min(delta_min, std::abs(dc.S1 - dc.S0));
    }
    delta_min *= (1 + FLT_EPSILON);

    double_t delta_max{DBL_MAX};
    while (delta_max > delta_min) {
        delta_max = delta_min;

        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);
            }
        }

63
64
        m.insert_from_queue();
    }
65
}