Commit 60fce32c authored by JasonPries's avatar JasonPries
Browse files

Translate Use Case tests

parent 04aef445
......@@ -19,26 +19,27 @@
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertex.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Rotation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Tangency.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Rotation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Branch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/RotateCopy.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Star.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Symmetry.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Length.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constellation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Fixation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Horizontal.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Symmetry.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/MirrorCopy.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Star.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/MirrorCopy.cpp" isTestSource="false" />
......@@ -46,9 +47,8 @@
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/RotateCopy.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Tangency.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Distance.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/include/Sketch.hpp" isTestSource="false" />
......@@ -71,6 +71,8 @@
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/cmake/internal_utils.cmake" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Pattern.cpp" isTestSource="false" />
......@@ -81,8 +83,9 @@
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Star.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Sketch.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Mesh/test_Mesh.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_Rotor.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_Stator.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/UseCases/test_UseCases.hpp" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
......
......@@ -100,7 +100,7 @@ InsertPointResult Mesh::insert_point(const Point *vc, Edge *tri) {
}
// Test edges in current and adjacent triangles for encroachment
// These are the only possible edges that are encroached due to empy circumcircle property
// These are the only possible edges that are encroached due to empty circumcircle property
std::vector<Edge *> test_edges;
test_edges.reserve(9);
......@@ -511,8 +511,7 @@ void Mesh::create_boundary_polygon() {
Edges.reserve(Boundary->size());
Points.reserve(Boundary->size());
for (size_t i = 0; i != Boundary->size(); ++i) {
Edges.push_back(new Edge(Boundary->curve(i)->clone(), Boundary->orientation(
i))); //clone() to prevent alteration of input Contour when Edge is split
Edges.push_back(new Edge(Boundary->curve(i)->clone(), Boundary->orientation(i))); //clone() to prevent alteration of input Contour when Edge is split
Points.push_back(Edges[i]->Node);
}
......
......@@ -15,7 +15,11 @@ set(SOURCE_FILES
Sketch/test_Pattern.cpp
Mesh/test_Mesh.hpp
Mesh/test_Mesh.cpp)
Mesh/test_Mesh.cpp
UseCases/test_UseCases.hpp
UseCases/test_Stator.cpp
UseCases/test_Rotor.cpp)
add_executable(run_tests ${SOURCE_FILES})
......
......@@ -7,7 +7,7 @@
#include <cmath>
#define TOL 4e-8 //#TODO: Tolerance is limited by accuracy of tangency constraint
#define SAVE_DIR "./test/output/"
#define SAVE_DIR "./test/output/Sketch/"
using namespace std;
......
#include "test_UseCases.hpp"
#define SAVE_DIR "./test/output/UseCases/Rotor/"
TEST(ROTOR, 0) {
Sketch s;
double ri{25.0};
double ro{80.0};
double a{M_PI / 8.0};
double xi = ri * cos(a);
double xo = ro * cos(a);
double yi = ri * sin(a);
double yo = ro * sin(a);
double xm = 70.0 * cos(a);
double ym = yo - (xo - xm);
Vertex &origin = s.new_element<Vertex>(0.0, 0.0);
Vertex &v0 = s.new_element<Vertex>(xi, yi);
Vertex &v1 = s.new_element<Vertex>(xi, -yi);
Vertex &v2 = s.new_element<Vertex>(xo, -yo);
Vertex &v3 = s.new_element<Vertex>(xo, yo);
Vertex &v4 = s.new_element<Vertex>(xo, -ym);
Vertex &v5 = s.new_element<Vertex>(xo, ym);
Vertex &v6 = s.new_element<Vertex>(xm, ym);
Vertex &v7 = s.new_element<Vertex>(xm, -ym);
LineSegment &l0 = s.new_element<LineSegment>(v0, v3);
LineSegment &l1 = s.new_element<LineSegment>(v1, v2);
CircularArc &c0 = s.new_element<CircularArc>(v1, v0, origin, ri);
CircularArc &c1 = s.new_element<CircularArc>(v2, v3, origin, ro);
s.new_element<LineSegment>(v4, v5);
s.new_element<LineSegment>(v5, v6);
s.new_element<LineSegment>(v6, v7);
s.new_element<LineSegment>(v7, v4);
s.solve();
s.build();
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "rotor_0d0.csv");
Mesh m{s};
m.MaximumElementSize = 2.5;
m.MinimumElementSize = 0.25;
m.MinimumElementQuality = M_SQRT1_2;
m.create();
m.save_as(SAVE_DIR, "rotor_0_mesh.csv");
m.refine();
m.save_as(SAVE_DIR, "rotor_0_mesh_refine.csv");
}
TEST(ROTOR, CIRCULAR_BARRIER_SYNCREL) {
Sketch s;
size_t Np = 8;
double adeg = 180.0 / Np;
double arad = adeg * M_PI / 180.0;
double ri = 25.0;
double ro = 80.0;
double dmax = ro * sin(arad);
double pd = 0.2;
double rd0 = ro - pd * dmax;
double rd1 = rd0 - pd * dmax;
// Vertex
Vertex &origin = s.new_element<Vertex>(0.0, 0.0);
Vertex &vi0 = s.new_element<Vertex>(ri, 0.0);
Vertex &vo0 = s.new_element<Vertex>(ro, 0.0);
Vertex &vi1 = s.new_element<Vertex>(ri * cos(arad), ri * sin(arad));
Vertex &vo1 = s.new_element<Vertex>(ro * cos(arad), ro * sin(arad));
Vertex &vm0 = s.new_element<Vertex>(rd0 * cos(arad), rd0 * sin(arad));
Vertex &vr0 = s.new_element<Vertex>(ro * cos(arad * (1.0 - pd)), ro * sin(arad * (1.0 - pd)));
Vertex &vc0 = s.new_element<Vertex>(ro * cos(arad), ro * sin(arad));
Vertex &vm1 = s.new_element<Vertex>(rd1 * cos(arad), rd1 * sin(arad));
Vertex &vr1 = s.new_element<Vertex>(ro * cos(arad * (1.0 - 2.0 * pd)), ro * sin(arad * (1.0 - 2.0 * pd)));
// LineSegment
LineSegment &l0 = s.new_element<LineSegment>(vi0, vo0);
LineSegment &l1 = s.new_element<LineSegment>(vi1, vm1);
LineSegment &l2 = s.new_element<LineSegment>(vm1, vm0);
LineSegment &l3 = s.new_element<LineSegment>(vm0, vo1);
// CircularArc
CircularArc &c0 = s.new_element<CircularArc>(vi0, vi1, origin, ri);
CircularArc &c1 = s.new_element<CircularArc>(vo0, vr1, origin, ro);
CircularArc &c2 = s.new_element<CircularArc>(vr1, vr0, origin, ro);
CircularArc &c3 = s.new_element<CircularArc>(vr0, vo1, origin, ro);
CircularArc &c4 = s.new_element<CircularArc>(vm0, vr0, vc0, pd * dmax);
CircularArc &c5 = s.new_element<CircularArc>(vm1, vr1, vc0, 2.0 * pd * dmax);
// Fixation
Fixation &fo = s.new_element<Fixation>(origin);
// Horizontal
Horizontal &ho = s.new_element<Horizontal>(l0);
// Angles
Angle &ao = s.new_element<Angle>(l0, l1, adeg);
Angle &a1 = s.new_element<Angle>(l0, l2, adeg);
Angle &a2 = s.new_element<Angle>(l0, l3, adeg);
// Coincident
Coincident<LineSegment> &coinc0 = s.new_element<Coincident<LineSegment>>(vc0, l1);
// Radius
Radius &rad0 = s.new_element<Radius>(c0, ri);
Radius &rad1 = s.new_element<Radius>(c1, ro);
Radius &rad2 = s.new_element<Radius>(c2, ro);
Radius &rad3 = s.new_element<Radius>(c3, ro);
// Distance
Distance<Vertex> &dist0 = s.new_element<Distance<Vertex>>(vr0, vo1, pd * dmax);
Distance<Vertex> &dist1 = s.new_element<Distance<Vertex>>(vr1, vr0, pd * dmax);
// Solve
s.solve();
s.build();
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "rotor_1_circular_barrier_syncrel.csv");
// Mesh
Mesh m{s};
m.MaximumElementSize = 1.0;
m.MinimumElementSize = 0.1;
m.MinimumElementQuality = M_SQRT1_2;
m.create();
m.save_as(SAVE_DIR, "rotor_1_circular_barrier_syncrel_mesh.csv");
m.refine();
m.save_as(SAVE_DIR, "rotor_1_circular_barrier_syncrel_mesh_refine.csv");
}
\ No newline at end of file
#include "test_UseCases.hpp"
#define SAVE_DIR "./test/output/UseCases/Stator/"
TEST(STATOR, 0) {
Sketch sketch;
size_t Np{8};
size_t Nt{3 * Np};
double ri{80.0};
double ro{130.0};
double at{M_PI / Nt};
double as{at / 2.0};
double dt{ri * sin(as)};
double rb{ro - 4.0 * dt};
Vertex &origin = sketch.new_element<Vertex>(0.0, 0.0);
Vertex &v0 = sketch.new_element<Vertex>(ri, 0.0);
Vertex &v1 = sketch.new_element<Vertex>(ro, 0.0);
Vertex &v2 = sketch.new_element<Vertex>(ro * cos(at), ro * sin(at));
Vertex &v3 = sketch.new_element<Vertex>(rb * cos(at), rb * sin(at));
Vertex &v4 = sketch.new_element<Vertex>(ri * cos(at), ri * sin(at));
Vertex &v5 = sketch.new_element<Vertex>(ri * cos(as), ri * sin(as));
Vertex &v6 = sketch.new_element<Vertex>(rb * cos(as), rb * sin(as));
LineSegment &l0 = sketch.new_element<LineSegment>(v0, v1);
CircularArc &c0 = sketch.new_element<CircularArc>(v1, v2, origin, ro);
LineSegment &l1 = sketch.new_element<LineSegment>(v2, v3);
LineSegment &l2 = sketch.new_element<LineSegment>(v3, v4);
CircularArc &c1 = sketch.new_element<CircularArc>(v5, v4, origin, ri);
CircularArc &c2 = sketch.new_element<CircularArc>(v0, v5, origin, ri);
LineSegment &l3 = sketch.new_element<LineSegment>(v5, v6);
CircularArc &c3 = sketch.new_element<CircularArc>(v6, v3, origin, rb);
//std::vector<const Curve*> mv{ &l0,&l1,&l2,&l3,&c0,&c1,&c2,&c3 };
std::vector<const Curve*> mv{&l0, &l3, &c0, &c1, &c2, &c3};
// l1.ForConstruction = true; //TODO: Fixes segfault (#1) failure but should not be necessary, problem is related to MirrorCopy mirror line l1
MirrorCopy &m0 = sketch.new_element<MirrorCopy>(mv, &l1);
sketch.solve();
sketch.save_as<SaveMethod::Rasterize>(SAVE_DIR, "stator0d0.csv");
EXPECT_EQ(sketch.boundary()->size(), 8);
Fixation &f = sketch.new_element<Fixation>(origin);
Coincident<LineSegment> &coin0 = sketch.new_element<Coincident<LineSegment>>(origin, l0);
Coincident<LineSegment> &coin1 = sketch.new_element<Coincident<LineSegment>>(origin, l1);
Coincident<LineSegment> &coin2 = sketch.new_element<Coincident<LineSegment>>(origin, l2);
Horizontal &horz0 = sketch.new_element<Horizontal>(l0);
Radius &rad0 = sketch.new_element<Radius>(c0, ro);
Radius &rad1 = sketch.new_element<Radius>(c1, ri);
Radius &rad2 = sketch.new_element<Radius>(c2, ri);
Radius &rad3 = sketch.new_element<Radius>(c3, rb);
Angle &ang0 = sketch.new_element<Angle>(l1, l0, (at * 180.0 / M_PI));
Angle &ang1 = sketch.new_element<Angle>(l2, l0, (at * 180.0 / M_PI));
Distance<LineSegment> &dist0 = sketch.new_element<Distance<LineSegment>>(l0, l3, dt);
sketch.solve();
sketch.save_as<SaveMethod::Rasterize>(SAVE_DIR, "stator0d1.csv");
EXPECT_EQ(sketch.boundary()->size(), 8);
sketch.build();
Mesh mesh{sketch};
mesh.MinimumElementQuality = M_SQRT1_2;
mesh.MaximumElementSize = 2.5;
mesh.MinimumElementSize = 0.25;
/* TODO: Segfault (#1)
mesh.create();
mesh.save_as(SAVE_DIR, "stator_0.csv");
mesh.refine();
mesh.save_as(SAVE_DIR, "stator_0_refine.csv");
*/
}
\ No newline at end of file
#ifndef OERSTED_TEST_USECASES_HPP
#define OERSTED_TEST_USECASES_HPP
#include "Sketch.hpp"
#include "Mesh.hpp"
#include "gtest.h"
#endif //OERSTED_TEST_USECASES_HPP
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment