Commit 7acb9b2f authored by Jason Pries's avatar Jason Pries Committed by GitHub
Browse files

Refactor after move to CMake/GoogleTest (#1)

* Translate tests from CMake to GoogleTest
* Split Branch/Star/Constellation into multiple files
* Update Sketch.save_as to create directory if it does not exist using Boost::Filesystem
* Split Constraint.h/Constraint.cpp into multiple h/cpp files
* Split Pattern.h/Pattern.cpp into multiple h/cpp files
* Separate mesh/Point class in to own Point.h/Point.cpp files
* Separate mesh/utility functions into own util.h/util.cpp files
* Fixed problem with Sketch Contour/Boundary parsing related to supremum calculations
* Added .oesk extension for sketch output files
* Added .oeme extension for mesh output files
* Add python script. Parses ./build/test/output directory for .oesk and .oeme files and saves images using matplotlib
* Removed using namespace std
* Updated implementation of RotateCopy
* Added RemoveInternalBoundary option to Pattern and subclasses
* Rewrote Mesh::locate_triangle function
* Changed type of Mesh.Points from vector<Point*> to vector<Point>
* Changed Edge members from type Edge* to type size_t
* Cleanup of Edge and Node access interface in Mesh
* Change Mesh::Edges from type std::vector<Edge*> to std::Vector<Edge>
* Add std::vector<DartConstraint> Constraints to Mesh. Revamp of constraint handling.
* Change Sketch Variable and Vertex vectors from raw pointers to shared pointers
* Change Sketch Boundary and Contour vector from raw pointers to shared pointers
* Change Sketch Pattern vector from raw pointers to shared pointers
* Change Sketch Constraint and Curve vectors from raw pointers to shared pointers
* Fix memory leaks
* Cleanup of Sketch and reorganization of dependencies
* Add shared_ptr const correctness to Sketch
* Robustified implementation of Sketch::solve()
* Started refactorization of mesh refinement control algorithm
parent 8a5e489b
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4"> <module classpath="CMake" type="CPP_MODULE" version="4" />
<component name="NewModuleRootManager"> \ No newline at end of file
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/src/" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/src/" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/GoogleTest/googletest/CMakeLists.txt" isTestSource="false" />
<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$/src/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Curve.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/CircularArc.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertex.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constellation.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Pattern.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Vertex.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constellation.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Contour.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Sketch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/src/Constraint.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/include/Sketch.hpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/Sketch/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Sketch.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_LineSegment.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/Sketch/test_Vertex.cpp" isTestSource="false" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Header Search Paths">
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-redhat-linux/6.2.1/include" />
<root url="file:///usr/local/include" />
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-redhat-linux/6.2.1/include" />
<root url="file:///usr/local/include" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
<pair source="cpp" header="h" />
<pair source="c" header="h" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<dictionary name="jpries"> <dictionary name="jpries">
<words> <words>
<w>eigen</w> <w>eigen</w>
<w>tangency</w> <w>tangency</w>
<w>verticies</w> <w>verticies</w>
</words> </words>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> <component name="CidrRootsConfiguration">
<OptionsSetting value="true" id="Add" /> <excludeRoots>
<OptionsSetting value="true" id="Remove" /> <file path="$PROJECT_DIR$/cmake-build-debug/CMakeFiles" />
<OptionsSetting value="true" id="Checkout" /> <file path="$PROJECT_DIR$/cmake-build-minsizerel/CMakeFiles" />
<OptionsSetting value="true" id="Update" /> <file path="$PROJECT_DIR$/cmake-build-release/CMakeFiles" />
<OptionsSetting value="true" id="Status" /> </excludeRoots>
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -10,12 +10,13 @@ matrix: ...@@ -10,12 +10,13 @@ matrix:
apt: apt:
sources: sources:
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
- boost-latest
- george-edison55-precise-backports - george-edison55-precise-backports
packages: packages:
- cmake - cmake
- cmake-data - cmake-data
- g++-6 - g++-6
#- lcov - libboost1.55-all-dev
before_install: before_install:
- mkdir -p $HOME/bin - mkdir -p $HOME/bin
...@@ -2,13 +2,23 @@ cmake_minimum_required(VERSION 3.2) ...@@ -2,13 +2,23 @@ cmake_minimum_required(VERSION 3.2)
project(Oersted) project(Oersted)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
find_package(Boost REQUIRED COMPONENTS system filesystem)
include_directories(./lib/ ./lib/Eigen/ ./lib/GoogleTest/googletest/include/gtest)
add_subdirectory(./lib/) add_subdirectory(./lib/)
include_directories(./src/ ./src/Sketch/include) include_directories(./src/)
add_subdirectory(./src/) add_subdirectory(./src/)
add_subdirectory(./test/) add_subdirectory(./test/)
\ No newline at end of file
# ØRSTED :: Oak Ridge Simulation Toolkit for Electromechanical Devices # ØRSTED :: Oak Ridge Simulation Toolkit for Electromechanical Devices
[![Build Status](]( [![Build Status](](
[![Coverage Status](]( [![Coverage Status](](
\ No newline at end of file
...@@ -10,8 +10,9 @@ mkdir -p coverage ...@@ -10,8 +10,9 @@ mkdir -p coverage
COV_FILE="coverage/" COV_FILE="coverage/"
COV_DIR=".coverage" COV_DIR=".coverage"
COV_SITE=$COV_DIR/"index.html" COV_SITE=$COV_DIR/"index.html"
lcov -c -d .. -o $COV_FILE lcov -c -d .. -o $COV_FILE
lcov -r $COV_FILE "*Oersted/lib/*" "*Oersted/test/*" "/usr/include/*" "/usr/lib/*" -o $COV_FILE lcov -r $COV_FILE "*Oersted/lib/*" "*Oersted/test/*" "/usr/include/*" "/usr/lib/*" -o $COV_FILE
genhtml $COV_FILE -o $COV_DIR genhtml $COV_FILE -o $COV_DIR -p $RM_PREFIX
google-chrome $COV_SITE google-chrome $COV_SITE
import os
import numpy as np
import matplotlib.pyplot as plt
imgtypes = ['.pdf','.png']
def plot_sketch(fname):
print('Sketch: ' +fname)
data = np.genfromtxt(fname, dtype=float, delimiter=',')
plt.plot(data[:,0], data[:,1])
for ext in imgtypes:
def plot_mesh(fname):
print('Mesh: '+fname)
data = np.genfromtxt(fname, dtype=float, delimiter=',')
x = data[:,[0,1,2,0]].transpose()
y = data[:,[3,4,5,3]].transpose()
for ext in imgtypes:
root = os.getcwd()
root += '/build/test/output/'
for path, _, files in os.walk(root):
for name in files:
_, fext = os.path.splitext(name)
fpath = os.path.join(path, name)
if fext == '.oesk':
elif fext == '.oeme':
\ No newline at end of file
include_directories(./Sketch/) include_directories(./Sketch/)
add_subdirectory(./Sketch/) add_subdirectory(./Sketch/)
\ No newline at end of file
./src/Mesh.h ./src/Mesh.cpp
./src/Edge.h ./src/Edge.cpp
./src/Point.h ./src/Point.cpp)
add_library(mesh STATIC ${SOURCE_FILES})
target_link_libraries(mesh ${Boost_LIBRARIES})
\ No newline at end of file
#include <boost/filesystem.hpp>
#include "../src/Mesh.h"
#include "../src/Edge.h"
#include "../src/Point.h"
\ No newline at end of file
#include "Mesh.hpp"
\ No newline at end of file
#include "Point.h"
class Mesh;
class Edge {
friend class Mesh;
Edge() : Node(SIZE_MAX), Self(SIZE_MAX), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), Constraint(SIZE_MAX), Orientation(true), Mark(false) {};
Edge(size_t s) : Node(SIZE_MAX), Self(s), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), Constraint(SIZE_MAX), Orientation(true), Mark(false) {};
Edge(size_t n, size_t s, Edge &nx, Edge &pr, Edge &tw) : Node(n), Self(s), Next(nx.Self), Twin(tw.Self), Prev(pr.Self), Constraint(SIZE_MAX), Orientation(true), Mark(false) {};
Edge(size_t n, size_t s, size_t c, bool d) : Node(n), Self(s), Next(SIZE_MAX), Twin(SIZE_MAX), Prev(SIZE_MAX), Constraint(c), Orientation(d), Mark(false) {};
size_t node() const { return Node; };
size_t self() const { return Self; };
size_t next() const { return Next; };
size_t twin() const { return Twin; };
size_t prev() const { return Prev; };
bool orientation() const { return Orientation; };
bool mark() const { return Mark; };
bool operator==(Edge const &e) const {
return (Node == e.Node &&
Self == e.Self &&
Next == e.Next &&
Twin == e.Twin &&
Prev == e.Prev &&
Constraint == e.Constraint &&
Orientation == e.Orientation);
size_t Node; //Point at start of this edge
size_t Self; //This edge in this triangle
size_t Next; //Next edge in this triangle
size_t Twin; //Twin edge in adjacent triangle
size_t Prev; //Previous edge in this triangle
size_t Constraint; //DartConstraint index
bool Orientation; //don't care if unconstrained
bool Mark; //Auxiliary variable for mesh refinement
This diff is collapsed.
#include "Sketch.hpp"
#include "Point.h"
#include "Edge.h"
#include <algorithm>
#include <fstream>
#include <numeric>
enum class LocateTriangleResult {
Interior, Exterior, Boundary, Point // TODO: Enumerate cases in function when triangle is located by a point near the boundary
enum class InsertPointResult {
Success, Midpoint, Duplicate, Failure
class DartConstraint {
DartConstraint() : S0(DBL_MAX), S1(DBL_MAX), ConstraintCurve(nullptr) {};
DartConstraint(double s0, double s1, std::shared_ptr<Curve const> cc) : S0(s0), S1(s1), ConstraintCurve(cc) {};
double S0;
double S1;
std::shared_ptr<Curve const> ConstraintCurve;
class Mesh {
double MinimumElementQuality = 0.0;
double MinimumElementSize = 0.0;
double MaximumElementSize = DBL_MAX;
Mesh(Sketch &s);
bool are_intersecting(size_t ei, size_t ej) const;
bool edges_are_valid() const;
bool in_triangle(Point const p, size_t ei) const;
bool is_constrained(size_t ei) const { return Edges[ei].Constraint != 0; };
bool is_encroached(Point const p, size_t ei) const;
bool is_locally_optimal(size_t ei) const;
bool is_protruding(size_t ei) const;
bool is_valid(size_t ei) const;
bool orientation(size_t ei) const { return Edges[ei].Orientation; };
bool refine();
bool refine_once();
double circumradius(size_t ei) const;
double length(size_t ei) const;
double shortest_edge_length(size_t ei) const;
size_t next(size_t ei) const { return Edges[ei].Next; };
size_t node(size_t ei) const { return Edges[ei].Node; };
size_t node(Edge const e) const { return e.Node; };
size_t num_points() const { return Points.size(); };
size_t num_edges() const;
size_t num_triangles() const { return Triangles.size(); };
size_t prev(size_t ei) const { return Edges[ei].Prev; };
size_t size_points() const { return Points.size(); };
size_t size_edges() const { return Edges.size(); };
size_t size_triangles() const { return Triangles.size(); };
size_t twin(size_t ei) const { return Edges[ei].Twin; };
void create();
void save_as(std::string path, std::string file_name) const;
DartConstraint const constraint(size_t ei) const { return Constraints[Edges[ei].Constraint]; };
std::shared_ptr<Curve const> constraint_curve(size_t ei) const { return Constraints[Edges[ei].Constraint].ConstraintCurve; };
Point circumcenter(size_t ei) const;
Point const base(Edge const e) const { return Points[e.Node]; };
Point const base(size_t ei) const { return Points[node(ei)]; };
Point const point(size_t i) const {
if (i >= Points.size()) {
} else {
return Points[i];
}; //return Points[i]; };
Point const point(Edge const e) const { return Points[e.Node]; };
Point const tip(Edge const e) const { return Points[next(e).Node]; };
Point const tip(size_t ei) const { return Points[node(next(ei))]; };
Edge const edge(size_t i) const { return Edges[i]; };
Edge const next(Edge const e) const { return Edges[e.Next]; };
Edge const prev(Edge const e) const { return Edges[e.Prev]; };
Edge const twin(Edge const e) const { return Edges[e.Twin]; };
Edge const triangle(size_t i) const { return Edges[Triangles[i]]; };
LocateTriangleResult locate_triangle(Point const p, size_t &ei) const;
LocateTriangleResult locate_triangle(Point const p) const {
size_t ei = Edges.size() - 1;
return locate_triangle(p, ei);
InsertPointResult insert_point(Point const p) { return insert_point(p, Edges.size() - 1); };
std::shared_ptr<Contour const> Boundary;
std::vector<std::shared_ptr<Curve const>> Curves;
std::vector<std::shared_ptr<Contour const>> Contours;
std::vector<Point> Points;
std::vector<Edge> Edges;
std::vector<DartConstraint> Constraints;
std::vector<size_t> Triangles;
bool find_attached(Point const p, size_t &ei);
bool recursive_swap(size_t ei);
bool swap(size_t ei);
size_t new_edges(size_t num_new) {
for (size_t i = 0; i != num_new; ++i) {
Edges.back().Constraint = 0;
return Edges.size();
Edge &new_edge(size_t p, size_t c, bool dir) {
Edges.push_back(Edge(p, Edges.size(), c, dir));
return Edges.back();
void create_boundary_polygon();
void element_quality(std::vector<double> &radii, std::vector<double> &quality);
void get_triangles();
void insert_internal_boundaries();
void mark_triangles();
void refine_once(std::vector<size_t> index, std::vector<double> circumradius, std::vector<double> quality);
void sort_permutation_ascending(std::vector<double> &value, std::vector<size_t> &index) const;
void sort_permutation_descending(std::vector<double> &values, std::vector<size_t> &index) const;
void split_edge(size_t ei);
void split_encroached_edges();
void triangulate_boundary_polygon();
InsertPointResult insert_circumcenter(size_t ei);
InsertPointResult insert_point(Point const p, size_t ei);
InsertPointResult insert_midpoint(size_t ei);
#include "Mesh.hpp"
double dist(Point const &p0, Point const &p1) {
return std::sqrt((p0.X - p1.X) * (p0.X - p1.X) + (p0.Y - p1.Y) * (p0.Y - p1.Y));
\ No newline at end of file
#include "Mesh.h"
class Point {
Point() : X{0.0}, Y{0.0} {};
Point(double x, double y) : X{x}, Y{y} {};
Point(std::shared_ptr<Vertex const> const &v) : X{v->x()}, Y{v->y()} {};
Point(double2 const p) : X{p.X}, Y{p.Y} {};
//double W; // Nurbs weight?
double X;
double Y;
//double Z; // 3-Dimensions?
bool operator==(Point const &p) const { return (X == p.X) && (Y == p.Y); };
bool operator==(Vertex const &v) const { return (X == v.x()) && (Y == v.y()); };
bool operator==(double2 const &p) const { return (X == p.X) && (Y == p.Y); };
bool operator!=(Point const &p) const { return (X != p.X) || (Y != p.Y); };
bool operator!=(Vertex const &v) const { return (X != v.x()) || (Y != v.y()); };
bool operator!=(double2 const &p) const { return (X != p.X) || (Y != p.Y); };
double dist(Point const &p0, Point const &p1);
PROJECT(Oersted_Sketch) PROJECT(Oersted_Sketch)
./include/Sketch.hpp ./src/Sketch.h ./src/Sketch.cpp ./include/Sketch.hpp
./src/Vertex.h ./src/Vertex.cpp ./src/Sketch.h ./src/Sketch.cpp
./src/Curve.h ./src/Curve.cpp ./src/Variable.h ./src/Variable.cpp
./src/SketchElement.h ./src/SketchElement.cpp
./src/Vertex.h ./src/Vertex.cpp
src/doublen.h src/doublen.cpp