186 lines
6.6 KiB
C++
186 lines
6.6 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <cmath>
|
|
#include "vde/brep/modeling.h"
|
|
#include "vde/brep/brep_boolean.h"
|
|
#include "vde/cae/cae_preprocess.h"
|
|
|
|
using namespace vde::brep;
|
|
using namespace vde::core;
|
|
|
|
TEST(VDE1346CaePreprocess, CylinderCenterline) {
|
|
auto cyl = make_cylinder_exact(2.0, 5.0);
|
|
const auto lines = vde::cae::extract_cylindrical_centerlines(cyl);
|
|
ASSERT_EQ(lines.size(), 1u);
|
|
EXPECT_NEAR(lines[0].radius, 2.0, 1e-9);
|
|
EXPECT_FALSE(lines[0].inner);
|
|
EXPECT_NEAR((lines[0].end - lines[0].start).norm(), 5.0, 1e-9);
|
|
}
|
|
|
|
TEST(VDE1346CaePreprocess, ThroughHoleCenterline) {
|
|
auto plate = make_box(60, 60, 20);
|
|
HoleSpec spec;
|
|
spec.diameter = 16.0;
|
|
spec.depth = 0.0;
|
|
auto body = make_hole(plate, Point3D(0, 0, 10), Vector3D(0, 0, -1), spec);
|
|
const auto lines = vde::cae::extract_cylindrical_centerlines(body);
|
|
ASSERT_EQ(lines.size(), 1u);
|
|
EXPECT_NEAR(lines[0].radius, 8.0, 1e-9);
|
|
EXPECT_TRUE(lines[0].inner);
|
|
EXPECT_NEAR((lines[0].end - lines[0].start).norm(), 20.0, 1e-9);
|
|
EXPECT_NEAR(lines[0].start.x(), 0.0, 1e-9);
|
|
EXPECT_NEAR(lines[0].start.y(), 0.0, 1e-9);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, ThinPlateMidsurface) {
|
|
auto plate = make_box(100, 60, 2);
|
|
const auto patches = vde::cae::extract_midsurface(plate);
|
|
ASSERT_EQ(patches.size(), 1u);
|
|
EXPECT_NEAR(patches[0].thickness, 2.0, 1e-9);
|
|
EXPECT_NEAR(std::abs(patches[0].normal.z()), 1.0, 1e-9);
|
|
EXPECT_NEAR(patches[0].origin.z(), 0.0, 1e-9);
|
|
ASSERT_EQ(patches[0].loops.size(), 1u);
|
|
EXPECT_GE(patches[0].loops[0].size(), 4u);
|
|
}
|
|
|
|
TEST(VDE1346CaePreprocess, ThinPlateWithHoleMidsurface) {
|
|
auto plate = make_box(100, 100, 2);
|
|
HoleSpec spec;
|
|
spec.diameter = 10.0;
|
|
spec.depth = 0.0;
|
|
auto body = make_hole(plate, Point3D(0, 0, 1), Vector3D(0, 0, -1), spec);
|
|
const auto patches = vde::cae::extract_midsurface(body);
|
|
ASSERT_EQ(patches.size(), 1u);
|
|
EXPECT_NEAR(patches[0].thickness, 2.0, 1e-9);
|
|
EXPECT_EQ(patches[0].loops.size(), 2u);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, ThinPlateShellMesh) {
|
|
auto plate = make_box(100, 60, 2);
|
|
const auto mesh = vde::cae::shell_mesh(plate);
|
|
ASSERT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
double area = 0.0;
|
|
for (const auto& t : mesh.triangles) {
|
|
const auto a = mesh.vertices[t[0]];
|
|
const auto b = mesh.vertices[t[1]];
|
|
const auto c = mesh.vertices[t[2]];
|
|
area += 0.5 * (b - a).cross(c - a).norm();
|
|
}
|
|
EXPECT_NEAR(area, 6000.0, 1.0);
|
|
for (const auto& p : mesh.vertices) EXPECT_NEAR(p.z(), 0.0, 1e-9);
|
|
}
|
|
|
|
TEST(VDE1346CaePreprocess, ThinPlateWithHoleShellMesh) {
|
|
auto plate = make_box(100, 100, 2);
|
|
HoleSpec spec;
|
|
spec.diameter = 10.0;
|
|
spec.depth = 0.0;
|
|
auto body = make_hole(plate, Point3D(0, 0, 1), Vector3D(0, 0, -1), spec);
|
|
const auto mesh = vde::cae::shell_mesh(body);
|
|
ASSERT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
double area = 0.0;
|
|
for (const auto& t : mesh.triangles) {
|
|
const auto a = mesh.vertices[t[0]];
|
|
const auto b = mesh.vertices[t[1]];
|
|
const auto c = mesh.vertices[t[2]];
|
|
area += 0.5 * (b - a).cross(c - a).norm();
|
|
}
|
|
EXPECT_NEAR(area, 10000.0 - 3.14159265358979323846 * 25.0, 10.0);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, CylindricalShellMidsurfaceAndMesh) {
|
|
auto outer = make_cylinder_exact(5.0, 20.0);
|
|
auto inner = make_cylinder_exact(4.5, 20.2);
|
|
auto tube = brep_difference(outer, inner);
|
|
const auto patches = vde::cae::extract_midsurface(tube, 0.2);
|
|
int cyl = 0;
|
|
for (const auto& p : patches) {
|
|
if (p.kind != vde::cae::MidsurfaceKind::Cylinder) continue;
|
|
++cyl;
|
|
EXPECT_NEAR(p.radius, 4.75, 1e-7);
|
|
EXPECT_NEAR(p.thickness, 0.5, 1e-7);
|
|
EXPECT_NEAR(p.v1 - p.v0, 20.0, 1e-7);
|
|
}
|
|
EXPECT_EQ(cyl, 1);
|
|
const auto mesh = vde::cae::shell_mesh(tube);
|
|
ASSERT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
double area = 0.0;
|
|
for (const auto& t : mesh.triangles) {
|
|
const auto a = mesh.vertices[t[0]];
|
|
const auto b = mesh.vertices[t[1]];
|
|
const auto c = mesh.vertices[t[2]];
|
|
area += 0.5 * (b - a).cross(c - a).norm();
|
|
}
|
|
EXPECT_NEAR(area, 2.0 * 3.14159265358979323846 * 4.75 * 20.0, 20.0);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, SphericalShellMidsurfaceAndMesh) {
|
|
auto outer = make_sphere(5.0, 32, 16);
|
|
auto inner = make_sphere(4.5, 32, 16);
|
|
auto shell = brep_difference(outer, inner);
|
|
const auto patches = vde::cae::extract_midsurface(shell, 0.25);
|
|
int sph = 0;
|
|
for (const auto& p : patches) {
|
|
if (p.kind != vde::cae::MidsurfaceKind::Sphere) continue;
|
|
++sph;
|
|
EXPECT_NEAR(p.radius, 4.75, 1e-3);
|
|
EXPECT_NEAR(p.thickness, 0.5, 1e-3);
|
|
}
|
|
EXPECT_EQ(sph, 1);
|
|
const auto mesh = vde::cae::shell_mesh(shell);
|
|
ASSERT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
double area = 0.0;
|
|
for (const auto& t : mesh.triangles) {
|
|
const auto a = mesh.vertices[t[0]];
|
|
const auto b = mesh.vertices[t[1]];
|
|
const auto c = mesh.vertices[t[2]];
|
|
area += 0.5 * (b - a).cross(c - a).norm();
|
|
}
|
|
EXPECT_NEAR(area, 4.0 * 3.14159265358979323846 * 4.75 * 4.75, 20.0);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, ToroidalShellMidsurfaceAndMesh) {
|
|
auto outer = make_torus_exact(5.0, 1.0);
|
|
auto inner = make_torus_exact(5.0, 0.8);
|
|
auto shell = brep_difference(outer, inner);
|
|
const auto patches = vde::cae::extract_midsurface(shell, 0.3);
|
|
int tori = 0;
|
|
for (const auto& p : patches) {
|
|
if (p.kind != vde::cae::MidsurfaceKind::Torus) continue;
|
|
++tori;
|
|
EXPECT_NEAR(p.major_radius, 5.0, 1e-3);
|
|
EXPECT_NEAR(p.minor_radius, 0.9, 1e-3);
|
|
}
|
|
EXPECT_EQ(tori, 1);
|
|
const auto mesh = vde::cae::shell_mesh(shell);
|
|
ASSERT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
double area = 0.0;
|
|
for (const auto& t : mesh.triangles) {
|
|
const auto a = mesh.vertices[t[0]];
|
|
const auto b = mesh.vertices[t[1]];
|
|
const auto c = mesh.vertices[t[2]];
|
|
area += 0.5 * (b - a).cross(c - a).norm();
|
|
}
|
|
EXPECT_NEAR(area, 4.0 * 3.14159265358979323846 * 3.14159265358979323846 *
|
|
5.0 * 0.9, 20.0);
|
|
}
|
|
|
|
|
|
TEST(VDE1346CaePreprocess, ConicalShellMidsurfaceAndMesh) {
|
|
auto outer = make_cone_exact(5.0, 2.5, 10.0);
|
|
auto inner = make_cone_exact(4.5, 2.0, 10.2);
|
|
auto shell = brep_difference(outer, inner);
|
|
const auto patches = vde::cae::extract_midsurface(shell, 0.3);
|
|
int cones = 0;
|
|
for (const auto& p : patches)
|
|
if (p.kind == vde::cae::MidsurfaceKind::Cone) ++cones;
|
|
EXPECT_EQ(cones, 1);
|
|
const auto mesh = vde::cae::shell_mesh(shell);
|
|
EXPECT_FALSE(mesh.triangles.empty()) << mesh.diagnostic;
|
|
}
|