Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patchkernel: rework evaluation of characteristic size of three-dimensional elements #383

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/IO/STL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
\*---------------------------------------------------------------------------*/

#include <cassert>
#include <cstdint>
#include <cstring>

#include "bitpit_common.hpp"
Expand Down
71 changes: 70 additions & 1 deletion src/patchkernel/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,77 @@ double Element::evalSize(const std::array<double, 3> *coordinates) const
{
switch (m_type) {

case ElementType::POLYGON:
case ElementType::POLYHEDRON:
{
// The characteristics size of a polyhedron is evaluated as the
// volume divided by the area of the largest face.
int nFaces = getFaceCount();
BITPIT_CREATE_WORKSPACE(faceVertexCoords, std::array<double BITPIT_COMMA 3>, getVertexCount(), ReferenceElementInfo::MAX_ELEM_VERTICES);

double volume = evalVolume(coordinates);

double faceMaxArea = 0;
for (int face = 0; face < nFaces; ++face) {
ElementType faceType = getFaceType(face);
bool faceHasReferenceInfo = ReferenceElementInfo::hasInfo(faceType);

ConstProxyVector<int> faceLocalVertexIds = getFaceLocalVertexIds(face);
for (int n = 0; n < getFaceVertexCount(face); ++n) {
faceVertexCoords[n] = coordinates[faceLocalVertexIds[n]];
}

double faceArea;
if (faceHasReferenceInfo) {
const Reference2DElementInfo &faceInfo = static_cast<const Reference2DElementInfo &>(ReferenceElementInfo::getInfo(faceType));
faceArea = faceInfo.evalArea(faceVertexCoords);
} else {
ConstProxyVector<long> faceConnect = getFaceConnect(face);
std::size_t faceConnectSize = faceConnect.size();

Element faceElement(0, faceType, faceConnect.size());
long *faceElementConnect = faceElement.getConnect();
for (std::size_t i = 0; i < faceConnectSize; ++i) {
faceElementConnect[i] = faceConnect[i];
}

faceArea = faceElement.evalArea(faceVertexCoords);
}
faceMaxArea = std::max(faceArea, faceMaxArea);
}

double size = volume / faceMaxArea;

return size;
}

case ElementType::POLYGON:
{
// The characteristics size of a polygon is evaluated as the
// area divided by the length of the longest face.
int nFaces = getFaceCount();
BITPIT_CREATE_WORKSPACE(faceVertexCoords, std::array<double BITPIT_COMMA 3>, getVertexCount(), ReferenceElementInfo::MAX_ELEM_VERTICES);

double area = evalArea(coordinates);

double faceMaxLength = 0;
for (int face = 0; face < nFaces; ++face) {
ElementType faceType = getFaceType(face);
assert(ReferenceElementInfo::hasInfo(faceType));

ConstProxyVector<int> faceLocalVertexIds = getFaceLocalVertexIds(face);
for (int n = 0; n < getFaceVertexCount(face); ++n) {
faceVertexCoords[n] = coordinates[faceLocalVertexIds[n]];
}

const Reference1DElementInfo &faceInfo = static_cast<const Reference1DElementInfo &>(ReferenceElementInfo::getInfo(faceType));
faceMaxLength = std::max(faceInfo.evalLength(faceVertexCoords), faceMaxLength);
}

double size = area / faceMaxLength;

return size;
}

case ElementType::UNDEFINED:
{
return 0.;
Expand Down
Loading