6 template <
int dim,
int order>
13 allSimplices.erase(std::vector<size_t>(newStart->xID.begin(), newStart->xID.end()));
14 const auto boundaryNeighbors(newStart->boundaryNeighbors());
15 for (
const auto &
neighbor : boundaryNeighbors)
17 const auto neighborRgnIDs(
neighbor->regionIDs());
18 if (neighborRgnIDs.find(this->regionID) != neighborRgnIDs.end()
19 && allSimplices.find(std::vector<size_t>(
neighbor->xID.begin(),
neighbor->xID.end())) !=
22 if ((newStart->outNormal() -
neighbor->outNormal()).norm() < FLT_EPSILON)
24 allSimplices.erase(std::vector<size_t>(
neighbor->xID.begin(),
neighbor->xID.end()));
26 buildSingleFace(
neighbor, newFace, allSimplices);
30 faces().emplace(newFace->sID, newFace);
34 template <
int dim,
int order>
35 void Polyhedron<dim, order>::buildFaces()
40 const auto t0 = std::chrono::system_clock::now();
41 std::cout <<
"MeshRegion " << this->regionID <<
" buiding PlanarMeshFace's " << std::flush;
43 std::map<std::vector<size_t>,
const Simplex<
dim,
dim - 1> *> allSimplices;
44 for (
const auto &simplex : simplices())
46 for (
const auto &child :
simplex->children())
48 if (child->isBoundarySimplex())
50 allSimplices.emplace(std::vector<size_t>(child->xID.begin(), child->xID.end()), child.get());
55 while (allSimplices.size())
57 auto newFace = cellFactory.owner->createFace(allSimplices.begin()->second);
58 buildSingleFace(allSimplices.begin()->second, newFace, allSimplices);
61 for (
auto &face :
faces())
63 face.second->finalize();
66 << (std::chrono::duration<double>(std::chrono::system_clock::now() -
t0)).
count() <<
" sec]"
70 template <
int dim,
int order>
72 requires(
order == dim)
76 template <
int dim,
int order>
78 requires(
order == dim)
81 for (
const auto id : ids)
85 const double norm =
result.norm();
86 return norm > FLT_EPSILON ? (
result / norm).
eval() : VectorDim::Zero();
89 template <
int dim,
int order>
91 requires(
order == dim - 1)
93 this->regionIDs = {*simplex->regionIDs().begin(), *simplex->regionIDs().rbegin()};
94 this->n = simplex->outNormal(this->regionIDs.first);
95 this->
c = simplex->center();
96 this->insert(simplex);
98 template <
int dim,
int order>
100 requires(
order == dim - 1)
106 template <
int dim,
int order>
108 requires(
order == dim - 1)
119 for (
const auto &simplex : *
this)
121 this->n += simplex->outNormal(this->regionIDs.first) / this->
simplices().size();
122 this->
c += simplex->center() / this->
simplices().size();
126 for (
const auto &simplex : *
this)
128 if (fabs((this->
c - simplex->center()).dot(this->n)) > FLT_EPSILON)
130 throw std::runtime_error(
"simplex does not belong to PlanarMeshFace.");
135 std::set<const Simplex<dim, 0> *>
vertices;
136 for (
const auto &simplex : *
this)
138 for (
const auto &
v : simplex->vertices())
146 if constexpr (dim < 3)
149 if constexpr (dim == 2)
151 const VectorDim tangent = (this->hull.back()->P0 - this->hull.front()->P0).normalized();
152 std::sort(this->hull.begin(), this->hull.end(), [&](
const auto *
a,
const auto *
b)
154 return a->P0.dot(tangent) < b->P0.dot(tangent);
156 this->hull = {this->hull.front(), this->hull.back()};
159 for (
const auto *
vertex : this->hull)
161 this->
c +=
vertex->P0 / this->hull.size();
173 const auto x(plane.localPosition(
v->P0));
174 hull.emplace(std::array<double, 2>{
x[0],
x[1]},
v);
177 const auto hullPts = hull.getPoints();
179 for (
const auto &hp : hullPts)
181 this->hull.push_back(hp.t);
183 if (this->hull.size() < 3)
185 std::cout <<
"vertices.size()=" <<
vertices.size() << std::endl;
186 throw std::runtime_error(
"PlanarMeshFace hull has size " + std::to_string(this->hull.size()));
191 for (
const auto &
v : convexHull())
193 this->
c +=
v->P0 / convexHull().size();
199 template <
int dim,
int order>
201 requires(
order == dim - 1)
203 return isExternal() ? this->n : Eigen::Matrix<double, dim, 1>::Zero();
207 template <
int dim,
int order>
209 requires(
order == dim - 1)
211 return k == this->regionIDs.first
213 : (
k == this->regionIDs.second ? (-this->n).eval() : Eigen::Matrix<double, dim, 1>::Zero());
217 template <
int dim,
int order>
219 requires(
order == dim - 1)
225 template <
int dim,
int order>
227 requires(
order == dim - 1)
size_t InstanceCount< Derived >::count
static std::string magentaColor
auto eval(const std::shared_ptr< T > &t)
static std::string defaultColor
Plane< dim > asPlane() const
const MeshFacesContainerType & faces() const
const SimplexContainerType & simplices() const
const VectorDim & center() const
VectorDim outNormal() const
Simplex< dim, order > SimplexType
Eigen::Matrix< double, dim, 1 > VectorDim
void initialize(const SimplexType *simplex)
const std::vector< const Simplex< dim, 0 > * > & convexHull() const