Backup commit
This commit is contained in:
parent
01dff95f9d
commit
266aca08c2
|
|
@ -45,7 +45,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${DRMSimulationModelDir})
|
||||||
#add_compile_definitions(DLIB_DEFINED)
|
#add_compile_definitions(DLIB_DEFINED)
|
||||||
|
|
||||||
## polyscope
|
## polyscope
|
||||||
#if(NOT TARGET polyscope AND ${USE_POLYSCOPE})
|
if(#[[NOT TARGET polyscope AND]] ${USE_POLYSCOPE})
|
||||||
|
message("Using polyscope")
|
||||||
FetchContent_Declare(polyscope
|
FetchContent_Declare(polyscope
|
||||||
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git
|
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git
|
||||||
GIT_TAG master
|
GIT_TAG master
|
||||||
|
|
@ -55,7 +56,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${DRMSimulationModelDir})
|
||||||
# target_include_directories(${PROJECT_NAME} PUBLIC ${polyscope_SOURCE_DIR}/deps/imgui)
|
# target_include_directories(${PROJECT_NAME} PUBLIC ${polyscope_SOURCE_DIR}/deps/imgui)
|
||||||
target_sources(${PROJECT_NAME} PUBLIC ${polyscope_SOURCE_DIR}/deps/imgui/imgui/misc/cpp/imgui_stdlib.h ${polyscope_SOURCE_DIR}/deps/imgui/imgui/misc/cpp/imgui_stdlib.cpp)
|
target_sources(${PROJECT_NAME} PUBLIC ${polyscope_SOURCE_DIR}/deps/imgui/imgui/misc/cpp/imgui_stdlib.h ${polyscope_SOURCE_DIR}/deps/imgui/imgui/misc/cpp/imgui_stdlib.cpp)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC polyscope)
|
target_link_libraries(${PROJECT_NAME} PUBLIC polyscope)
|
||||||
#endif()
|
endif()
|
||||||
#if(NOT TARGET polyscope AND ${USE_POLYSCOPE})
|
#if(NOT TARGET polyscope AND ${USE_POLYSCOPE})
|
||||||
# set(POLYSCOPE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/polyscope)
|
# set(POLYSCOPE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/polyscope)
|
||||||
# download_project(PROJ POLYSCOPE
|
# download_project(PROJ POLYSCOPE
|
||||||
|
|
@ -149,8 +150,9 @@ add_subdirectory(${ARMADILLO_SOURCE_DIR} ${ARMADILLO_BIN_DIR})
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ARMADILLO_SOURCE_DIR}/include)
|
target_include_directories(${PROJECT_NAME} PUBLIC ${ARMADILLO_SOURCE_DIR}/include)
|
||||||
add_compile_definitions(ARMA_DONT_USE_WRAPPER)
|
add_compile_definitions(ARMA_DONT_USE_WRAPPER)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/armadillo/build/libarmadillo.a" #[[blas lapack]])
|
target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/armadillo/build/libarmadillo.a" #[[blas lapack]])
|
||||||
find_package(Armadillo REQUIRED)
|
#find_package(Armadillo REQUIRED)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${ARMADILLO_LIBRARIES})
|
#target_link_libraries(${PROJECT_NAME} PUBLIC ${ARMADILLO_LIBRARIES})
|
||||||
|
|
||||||
#if(NOT TARGET ThreedBeamFEA)
|
#if(NOT TARGET ThreedBeamFEA)
|
||||||
#FetchContent_Declare(armadillo
|
#FetchContent_Declare(armadillo
|
||||||
# GIT_REPOSITORY https://gitlab.com/conradsnicta/armadillo-code.git
|
# GIT_REPOSITORY https://gitlab.com/conradsnicta/armadillo-code.git
|
||||||
|
|
@ -203,7 +205,7 @@ add_compile_definitions(USE_ENSMALLEN)
|
||||||
# LINK_FLAGS "${CHRONO_LINKER_FLAGS}")
|
# LINK_FLAGS "${CHRONO_LINKER_FLAGS}")
|
||||||
#include_directories(${CHRONO_INCLUDE_DIRS})
|
#include_directories(${CHRONO_INCLUDE_DIRS})
|
||||||
#target_link_libraries(${PROJECT_NAME} PUBLIC ${CHRONO_LIBRARIES})
|
#target_link_libraries(${PROJECT_NAME} PUBLIC ${CHRONO_LIBRARIES})
|
||||||
#target_include_directories(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/chrono-7.0.3/src" #[[${CHRONO_INCLUDE_DIRS}]] #[["/home/iason/Coding/Libraries/chrono-7.0.3/src"]] #[["/usr/include/irrlicht"]] )
|
target_include_directories(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/chrono-7.0.3/src" #[[${CHRONO_INCLUDE_DIRS}]] #[["/home/iason/Coding/Libraries/chrono-7.0.3/src"]] #[["/usr/include/irrlicht"]] )
|
||||||
#target_link_directories(${PROJECT_NAME} PRIVATE "/home/iason/Coding/build/external dependencies/CHRONO-src/build/RelWithDebInfo/lib")
|
#target_link_directories(${PROJECT_NAME} PRIVATE "/home/iason/Coding/build/external dependencies/CHRONO-src/build/RelWithDebInfo/lib")
|
||||||
#target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/build/external dependencies/CHRONO-src/build/RelWithDebInfo/lib/libChronoEngine.a")
|
#target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/build/external dependencies/CHRONO-src/build/RelWithDebInfo/lib/libChronoEngine.a")
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/chrono-7.0.3/build/Release/lib/libChronoEngine.a")
|
target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/chrono-7.0.3/build/Release/lib/libChronoEngine.a")
|
||||||
|
|
@ -252,11 +254,12 @@ if(NOT TARGET tbb_static AND NOT TARGET tbb)
|
||||||
# option(TBB_BUILD_TESTS "Build TBB tests and enable testing infrastructure" OFF)
|
# option(TBB_BUILD_TESTS "Build TBB tests and enable testing infrastructure" OFF)
|
||||||
# add_subdirectory(${TBB_SOURCE_DIR} ${TBB_BINARY_DIR})
|
# add_subdirectory(${TBB_SOURCE_DIR} ${TBB_BINARY_DIR})
|
||||||
#link_directories(${TBB_BINARY_DIR})
|
#link_directories(${TBB_BINARY_DIR})
|
||||||
|
message("Using tbb")
|
||||||
FetchContent_Declare(tbb
|
FetchContent_Declare(tbb
|
||||||
GIT_REPOSITORY https://github.com/wjakob/tbb.git
|
GIT_REPOSITORY https://github.com/wjakob/tbb.git
|
||||||
GIT_TAG master
|
GIT_TAG master
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(tbb)
|
FetchContent_MakeAvailable(tbb)
|
||||||
# target_link_libraries(${PROJECT_NAME} PRIVATE tbb_static)
|
# target_link_libraries(${PROJECT_NAME} PRIVATE tbb_static)
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE tbb)
|
|
||||||
endif()
|
endif()
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE tbb_static)
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,33 @@ void ChronosEulerSimulationModel::parseForces(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChronosEulerSimulationModel::parseForcedDisplacements(
|
||||||
|
const std::shared_ptr<const SimulationJob>& pJob,
|
||||||
|
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
|
edgeMeshVertsToChronoNodes,
|
||||||
|
chrono::ChSystemSMC& my_system) {
|
||||||
|
assert(!edgeMeshVertsToChronoNodes.empty());
|
||||||
|
|
||||||
|
ChState x;
|
||||||
|
ChStateDelta v;
|
||||||
|
double t;
|
||||||
|
for (const std::pair<VertexIndex, Eigen::Vector3d>& forcedDisplacement :
|
||||||
|
pJob->nodalForcedDisplacements) {
|
||||||
|
assert(false);
|
||||||
|
std::cerr << "Forced displacements dont work" << std::endl;
|
||||||
|
// std::terminate();
|
||||||
|
const int& constrainedVi = forcedDisplacement.first;
|
||||||
|
ChVector<double> displacementVector(
|
||||||
|
pJob->nodalForcedDisplacements.at(constrainedVi));
|
||||||
|
const std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>& constrainedChronoNode =
|
||||||
|
edgeMeshVertsToChronoNodes[constrainedVi];
|
||||||
|
constrainedChronoNode->NodeIntStateGather(0, x, 0, v, t);
|
||||||
|
std::cout << "state rows:" << x.rows() << std::endl;
|
||||||
|
std::cout << "state cols:" << x.cols() << std::endl;
|
||||||
|
// x = x + displacementVector;
|
||||||
|
constrainedChronoNode->NodeIntStateScatter(0, x, 0, v, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
void ChronosEulerSimulationModel::parseConstrainedVertices(
|
void ChronosEulerSimulationModel::parseConstrainedVertices(
|
||||||
const std::shared_ptr<const SimulationJob>& pJob,
|
const std::shared_ptr<const SimulationJob>& pJob,
|
||||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
|
|
@ -120,30 +147,17 @@ void ChronosEulerSimulationModel::parseConstrainedVertices(
|
||||||
auto truss = chrono_types::make_shared<ChBody>();
|
auto truss = chrono_types::make_shared<ChBody>();
|
||||||
truss->SetBodyFixed(true);
|
truss->SetBodyFixed(true);
|
||||||
my_system.Add(truss);
|
my_system.Add(truss);
|
||||||
const auto& constrainedChronoNode =
|
const std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>& constrainedChronoNode =
|
||||||
edgeMeshVertsToChronoNodes[constrainedVi];
|
edgeMeshVertsToChronoNodes[constrainedVi];
|
||||||
// Create a constraint at the end of the beam
|
auto constraint = chrono_types::make_shared<ChLinkMateGeneric>();
|
||||||
auto constr_a = chrono_types::make_shared<ChLinkMateGeneric>();
|
constraint->SetConstrainedCoords(
|
||||||
constr_a->SetConstrainedCoords(
|
|
||||||
constrainedDoF.contains(0), constrainedDoF.contains(1),
|
constrainedDoF.contains(0), constrainedDoF.contains(1),
|
||||||
constrainedDoF.contains(2), constrainedDoF.contains(3),
|
constrainedDoF.contains(2), constrainedDoF.contains(3),
|
||||||
constrainedDoF.contains(4), constrainedDoF.contains(5));
|
constrainedDoF.contains(4), constrainedDoF.contains(5));
|
||||||
constr_a->Initialize(constrainedChronoNode, truss, false,
|
constraint->Initialize(constrainedChronoNode, truss, false,
|
||||||
constrainedChronoNode->Frame(),
|
constrainedChronoNode->Frame(),
|
||||||
constrainedChronoNode->Frame());
|
constrainedChronoNode->Frame());
|
||||||
// const auto frameNode = constrainedChronoNode->Frame();
|
my_system.Add(constraint);
|
||||||
my_system.Add(constr_a);
|
|
||||||
|
|
||||||
// edgeMeshVertsToChronoNodes[constrainedVi]->SetFixed(true);
|
|
||||||
// if (vertexIsFullyConstrained) {
|
|
||||||
// } else {
|
|
||||||
// std::cerr << "Currently only rigid vertices are handled." <<
|
|
||||||
// std::endl;
|
|
||||||
// // SimulationResults simulationResults;
|
|
||||||
// // simulationResults.converged = false;
|
|
||||||
// // assert(false);
|
|
||||||
// // return simulationResults;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,6 +191,7 @@ SimulationResults ChronosEulerSimulationModel::executeSimulation(
|
||||||
// -1));
|
// -1));
|
||||||
// my_system.SetTimestepperType(chrono::ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED);
|
// my_system.SetTimestepperType(chrono::ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED);
|
||||||
// parse forces
|
// parse forces
|
||||||
|
parseForcedDisplacements(pJob, edgeMeshVertsToChronoNodes, my_system);
|
||||||
parseForces(mesh_chronos, edgeMeshVertsToChronoNodes,
|
parseForces(mesh_chronos, edgeMeshVertsToChronoNodes,
|
||||||
pJob->nodalExternalForces);
|
pJob->nodalExternalForces);
|
||||||
// parse constrained vertices
|
// parse constrained vertices
|
||||||
|
|
@ -198,20 +213,29 @@ SimulationResults ChronosEulerSimulationModel::executeSimulation(
|
||||||
|
|
||||||
auto solver = chrono_types::make_shared<ChSolverMINRES>();
|
auto solver = chrono_types::make_shared<ChSolverMINRES>();
|
||||||
my_system.SetSolver(solver);
|
my_system.SetSolver(solver);
|
||||||
// solver->SetMaxIterations(1e5);
|
solver->SetMaxIterations(1e5);
|
||||||
// solver->SetTolerance(1e-12);
|
|
||||||
solver->EnableWarmStart(
|
solver->EnableWarmStart(
|
||||||
true); // IMPORTANT for convergence when using EULER_IMPLICIT_LINEARIZED
|
true); // IMPORTANT for convergence when using EULER_IMPLICIT_LINEARIZED
|
||||||
solver->EnableDiagonalPreconditioner(true);
|
solver->EnableDiagonalPreconditioner(true);
|
||||||
my_system.SetSolverForceTolerance(1e-9);
|
// solver->SetTolerance(1e-15);
|
||||||
solver->SetVerbose(false);
|
my_system.SetSolverForceTolerance(1e-15);
|
||||||
|
|
||||||
SimulationResults simulationResults;
|
SimulationResults simulationResults;
|
||||||
|
//#ifdef POLYSCOPE_DEFINED
|
||||||
|
// solver->SetVerbose(true);
|
||||||
|
// // edgeMeshVertsToChronoNodes[10]->Frame().Move({0, 0, 1e-1});
|
||||||
|
// simulationResults.converged = my_system.DoEntireKinematics(5e2);
|
||||||
|
//// edgeMeshVertsToChronoNodes[10]->SetForce({0, 0, 1e6});
|
||||||
|
//#else
|
||||||
|
solver->SetVerbose(false);
|
||||||
if (settings.analysisType == Settings::AnalysisType::Linear) {
|
if (settings.analysisType == Settings::AnalysisType::Linear) {
|
||||||
simulationResults.converged = my_system.DoStaticLinear();
|
simulationResults.converged = my_system.DoStaticLinear();
|
||||||
|
// simulationResults.converged = my_system.DoStaticRelaxing();
|
||||||
} else {
|
} else {
|
||||||
simulationResults.converged = my_system.DoStaticNonlinear();
|
simulationResults.converged = my_system.DoStaticNonlinear();
|
||||||
|
// simulationResults.converged = my_system.DoStaticRelaxing();
|
||||||
}
|
}
|
||||||
|
//#endif
|
||||||
if (!simulationResults.converged) {
|
if (!simulationResults.converged) {
|
||||||
std::cerr << "Simulation failed" << std::endl;
|
std::cerr << "Simulation failed" << std::endl;
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
|
||||||
|
|
@ -8,39 +8,48 @@ class ChSystemSMC;
|
||||||
namespace fea {
|
namespace fea {
|
||||||
class ChMesh;
|
class ChMesh;
|
||||||
class ChNodeFEAxyzrot;
|
class ChNodeFEAxyzrot;
|
||||||
} // namespace fea
|
} // namespace fea
|
||||||
} // namespace chrono
|
} // namespace chrono
|
||||||
|
|
||||||
class ChronosEulerSimulationModel : public SimulationModel
|
class ChronosEulerSimulationModel : public SimulationModel {
|
||||||
{
|
std::shared_ptr<chrono::fea::ChMesh> mesh_chronos;
|
||||||
std::shared_ptr<chrono::fea::ChMesh> mesh_chronos;
|
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>
|
||||||
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> edgeMeshVertsToChronoNodes;
|
edgeMeshVertsToChronoNodes;
|
||||||
|
|
||||||
static void parseConstrainedVertices(
|
static void parseConstrainedVertices(
|
||||||
const std::shared_ptr<const SimulationJob> &pJob,
|
const std::shared_ptr<const SimulationJob>& pJob,
|
||||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> &edgeMeshVertsToChronoNodes,
|
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
chrono::ChSystemSMC &my_system);
|
edgeMeshVertsToChronoNodes,
|
||||||
static void parseForces(
|
chrono::ChSystemSMC& my_system);
|
||||||
const std::shared_ptr<chrono::fea::ChMesh> &mesh_chronos,
|
static void parseForces(
|
||||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> &edgeMeshVertsToChronoNodes,
|
const std::shared_ptr<chrono::fea::ChMesh>& mesh_chronos,
|
||||||
const std::unordered_map<VertexIndex, Vector6d> &nodalExternalForces);
|
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
|
edgeMeshVertsToChronoNodes,
|
||||||
|
const std::unordered_map<VertexIndex, Vector6d>& nodalExternalForces);
|
||||||
|
|
||||||
public:
|
static void parseForcedDisplacements(
|
||||||
ChronosEulerSimulationModel();
|
const std::shared_ptr<const SimulationJob>& pJob,
|
||||||
SimulationResults executeSimulation(const std::shared_ptr<SimulationJob> &pJob) override;
|
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
void setStructure(const std::shared_ptr<SimulationEdgeMesh> &pMesh) override;
|
edgeMeshVertsToChronoNodes,
|
||||||
static std::shared_ptr<chrono::fea::ChMesh> convertToChronosMesh_Euler(
|
chrono::ChSystemSMC& my_system);
|
||||||
const std::shared_ptr<SimulationEdgeMesh> &pMesh,
|
|
||||||
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> &edgeMeshVertsToChronosNodes);
|
|
||||||
|
|
||||||
inline const static std::string label{"Chronos_Euler"};
|
public:
|
||||||
|
ChronosEulerSimulationModel();
|
||||||
|
SimulationResults executeSimulation(
|
||||||
|
const std::shared_ptr<SimulationJob>& pJob) override;
|
||||||
|
void setStructure(const std::shared_ptr<SimulationEdgeMesh>& pMesh) override;
|
||||||
|
static std::shared_ptr<chrono::fea::ChMesh> convertToChronosMesh_Euler(
|
||||||
|
const std::shared_ptr<SimulationEdgeMesh>& pMesh,
|
||||||
|
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||||
|
edgeMeshVertsToChronosNodes);
|
||||||
|
|
||||||
struct Settings
|
inline const static std::string label{"Chronos_Euler"};
|
||||||
{
|
|
||||||
enum AnalysisType { Linear = 0, NonLinear };
|
struct Settings {
|
||||||
AnalysisType analysisType{NonLinear};
|
enum AnalysisType { Linear = 0, NonLinear };
|
||||||
};
|
AnalysisType analysisType{NonLinear};
|
||||||
Settings settings;
|
};
|
||||||
|
Settings settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHRONOSEULERSIMULATIONMODEL_HPP
|
#endif // CHRONOSEULERSIMULATIONMODEL_HPP
|
||||||
|
|
|
||||||
297
polymesh.hpp
297
polymesh.hpp
|
|
@ -1,297 +0,0 @@
|
||||||
#ifndef POLYMESH_HPP
|
|
||||||
#define POLYMESH_HPP
|
|
||||||
#include "mesh.hpp"
|
|
||||||
#include "utilities.hpp"
|
|
||||||
#include "vcg/complex/complex.h"
|
|
||||||
#include <filesystem>
|
|
||||||
#include <wrap/io_trimesh/export_obj.h>
|
|
||||||
#include <wrap/io_trimesh/export_ply.h>
|
|
||||||
#include <wrap/io_trimesh/import.h>
|
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
|
||||||
#include <polyscope/surface_mesh.h>
|
|
||||||
#endif
|
|
||||||
class PFace;
|
|
||||||
class PVertex;
|
|
||||||
class PEdge;
|
|
||||||
|
|
||||||
struct PUsedTypes : public vcg::UsedTypes<vcg::Use<PVertex>::AsVertexType,
|
|
||||||
vcg::Use<PFace>::AsFaceType,
|
|
||||||
vcg::Use<PEdge>::AsEdgeType>
|
|
||||||
{};
|
|
||||||
|
|
||||||
class PVertex : public vcg::Vertex<PUsedTypes,
|
|
||||||
vcg::vertex::Coord3d,
|
|
||||||
vcg::vertex::Normal3d,
|
|
||||||
vcg::vertex::Mark,
|
|
||||||
vcg::vertex::Qualityf,
|
|
||||||
vcg::vertex::BitFlags,
|
|
||||||
vcg::vertex::VFAdj,
|
|
||||||
vcg::vertex::VEAdj>
|
|
||||||
{};
|
|
||||||
class PEdge : public vcg::Edge<PUsedTypes,
|
|
||||||
vcg::edge::VertexRef,
|
|
||||||
vcg::edge::BitFlags,
|
|
||||||
vcg::edge::EEAdj,
|
|
||||||
vcg::edge::EFAdj,
|
|
||||||
vcg::edge::VEAdj,
|
|
||||||
vcg::edge::EVAdj>
|
|
||||||
{};
|
|
||||||
|
|
||||||
class PFace : public vcg::Face<PUsedTypes,
|
|
||||||
vcg::face::PolyInfo // this is necessary if you use component in
|
|
||||||
// vcg/simplex/face/component_polygon.h
|
|
||||||
// It says "this class is a polygon and the memory for its components
|
|
||||||
// (e.g. pointer to its vertices will be allocated dynamically")
|
|
||||||
,
|
|
||||||
// vcg::face::FHAdj,
|
|
||||||
vcg::face::PVFAdj,
|
|
||||||
vcg::face::PFEAdj,
|
|
||||||
vcg::face::PFVAdj,
|
|
||||||
vcg::face::PVFAdj,
|
|
||||||
// vcg::face::PVFAdj,
|
|
||||||
vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj )
|
|
||||||
,
|
|
||||||
vcg::face::BitFlags // bit flags
|
|
||||||
,
|
|
||||||
vcg::face::Qualityf // quality
|
|
||||||
,
|
|
||||||
vcg::face::Normal3f // normal
|
|
||||||
,
|
|
||||||
vcg::face::Color4b>
|
|
||||||
{};
|
|
||||||
|
|
||||||
class VCGPolyMesh
|
|
||||||
: public vcg::tri::TriMesh<std::vector<PVertex>, std::vector<PFace>, std::vector<PEdge>>,
|
|
||||||
public Mesh
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool load(const std::filesystem::__cxx11::path &meshFilePath) override
|
|
||||||
{
|
|
||||||
int mask;
|
|
||||||
vcg::tri::io::Importer<VCGPolyMesh>::LoadMask(meshFilePath.c_str(), mask);
|
|
||||||
int error = vcg::tri::io::Importer<VCGPolyMesh>::Open(*this, meshFilePath.c_str(), mask);
|
|
||||||
if (error != 0) {
|
|
||||||
std::cerr << "Could not load polygonal mesh:" << meshFilePath << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::FaceFace(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::VertexEdge(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::VertexFace(*this);
|
|
||||||
vcg::tri::UpdateNormal<VCGPolyMesh>::PerVertexNormalized(*this);
|
|
||||||
vcg::tri::Clean<VCGPolyMesh>::RemoveUnreferencedVertex(*this);
|
|
||||||
//finally remove valence 1 vertices on the border
|
|
||||||
// vcg::PolygonalAlgorithm<PolyMeshType>::RemoveValence2Vertices(dual);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// // vcg::tri::io::ImporterOBJ<VCGPolyMesh>::Open();
|
|
||||||
// // unsigned int mask = 0;
|
|
||||||
// // mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTCOORD;
|
|
||||||
// // mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTNORMAL;
|
|
||||||
// // mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTCOLOR;
|
|
||||||
// // mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_EDGEINDEX;
|
|
||||||
// // mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_FACEINDEX;
|
|
||||||
// // if (nanoply::NanoPlyWrapper<VCGPolyMesh>::LoadModel(
|
|
||||||
// // std::filesystem::absolute(filename).c_str(), *this, mask) !=
|
|
||||||
// // 0) {
|
|
||||||
// // std::cout << "Could not load tri mesh" << std::endl;
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
Eigen::MatrixX3d getVertices() const
|
|
||||||
{
|
|
||||||
Eigen::MatrixX3d vertices(VN(), 3);
|
|
||||||
for (size_t vi = 0; vi < VN(); vi++) {
|
|
||||||
VCGPolyMesh::CoordType vertexCoordinates = vert[vi].cP();
|
|
||||||
vertices.row(vi) = vertexCoordinates.ToEigenVector<Eigen::Vector3d>();
|
|
||||||
}
|
|
||||||
return vertices;
|
|
||||||
}
|
|
||||||
std::vector<std::vector<int>> getFaces() const
|
|
||||||
{
|
|
||||||
std::vector<std::vector<int>> faces(FN());
|
|
||||||
for (const VCGPolyMesh::FaceType &f : this->face) {
|
|
||||||
const int fi = vcg::tri::Index<VCGPolyMesh>(*this, f);
|
|
||||||
for (size_t vi = 0; vi < f.VN(); vi++) {
|
|
||||||
const size_t viGlobal = vcg::tri::Index<VCGPolyMesh>(*this, f.cV(vi));
|
|
||||||
faces[fi].push_back(viGlobal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return faces;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bool load(const std::filesystem::__cxx11::path &meshFilePath)
|
|
||||||
// {
|
|
||||||
// const std::string extension = ".ply";
|
|
||||||
// std::filesystem::path filePath = meshFilePath;
|
|
||||||
// assert(std::filesystem::path(filePath).extension().string() == extension);
|
|
||||||
// unsigned int mask = 0;
|
|
||||||
// mask |= vcg::tri::io::Mask::IOM_VERTCOORD;
|
|
||||||
// mask |= vcg::tri::io::Mask::IOM_VERTNORMAL;
|
|
||||||
// mask |= vcg::tri::io::Mask::IOM_FACEINDEX;
|
|
||||||
// mask |= vcg::tri::io::Mask::IOM_FACECOLOR;
|
|
||||||
// if (vcg::tri::io::Importer<VCGPolyMesh>::Open(*this, filePath.c_str()) != 0) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// label = meshFilePath.filename();
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
bool save(const std::filesystem::__cxx11::path &meshFilePath = std::filesystem::path()) override
|
|
||||||
{
|
|
||||||
if (meshFilePath.extension() == ".obj") {
|
|
||||||
return saveOBJ(meshFilePath);
|
|
||||||
} else if (meshFilePath.extension() == ".ply") {
|
|
||||||
return savePLY(meshFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool saveOBJ(const std::filesystem::path &objFilePath = std::filesystem::path())
|
|
||||||
{
|
|
||||||
const std::string extension = ".obj";
|
|
||||||
std::filesystem::path filePath = objFilePath;
|
|
||||||
if (filePath.empty()) {
|
|
||||||
filePath = std::filesystem::current_path().append(getLabel() + extension).string();
|
|
||||||
} else if (std::filesystem::is_directory(std::filesystem::path(objFilePath))) {
|
|
||||||
filePath = std::filesystem::path(objFilePath).append(getLabel() + extension).string();
|
|
||||||
}
|
|
||||||
assert(std::filesystem::path(filePath).extension().string() == extension);
|
|
||||||
unsigned int mask = 0;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_VERTCOORD;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_VERTNORMAL;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_FACEINDEX;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_FACECOLOR;
|
|
||||||
if (vcg::tri::io::ExporterOBJ<VCGPolyMesh>::Save(*this, filePath.string().c_str(), mask) != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool savePLY(const std::filesystem::path &objFilePath = std::filesystem::path())
|
|
||||||
{
|
|
||||||
const std::string extension = ".ply";
|
|
||||||
std::filesystem::path filePath = objFilePath;
|
|
||||||
if (filePath.empty()) {
|
|
||||||
filePath = std::filesystem::current_path().append(getLabel() + extension).string();
|
|
||||||
} else if (std::filesystem::is_directory(std::filesystem::path(objFilePath))) {
|
|
||||||
filePath = std::filesystem::path(objFilePath).append(getLabel() + extension).string();
|
|
||||||
}
|
|
||||||
assert(std::filesystem::path(filePath).extension().string() == extension);
|
|
||||||
unsigned int mask = 0;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_VERTCOORD;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_VERTNORMAL;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_FACEINDEX;
|
|
||||||
mask |= vcg::tri::io::Mask::IOM_FACECOLOR;
|
|
||||||
if (vcg::tri::io::ExporterPLY<VCGPolyMesh>::Save(*this, filePath.string().c_str(), mask, false) != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
|
||||||
polyscope::SurfaceMesh *registerForDrawing(
|
|
||||||
const std::optional<std::array<double, 3>> &desiredColor = std::nullopt,
|
|
||||||
const bool &shouldEnable = true)
|
|
||||||
{
|
|
||||||
auto vertices = getVertices();
|
|
||||||
auto faces = getFaces();
|
|
||||||
PolyscopeInterface::init();
|
|
||||||
|
|
||||||
polyscope::SurfaceMesh *polyscopeHandle_mesh = polyscope::registerSurfaceMesh(label,
|
|
||||||
vertices,
|
|
||||||
faces);
|
|
||||||
|
|
||||||
const double drawingRadius = 0.002;
|
|
||||||
polyscopeHandle_mesh->setEnabled(shouldEnable);
|
|
||||||
polyscopeHandle_mesh->setEdgeWidth(drawingRadius);
|
|
||||||
|
|
||||||
if (desiredColor.has_value()) {
|
|
||||||
const glm::vec3 desiredColor_glm(desiredColor.value()[0],
|
|
||||||
desiredColor.value()[1],
|
|
||||||
desiredColor.value()[2]);
|
|
||||||
polyscopeHandle_mesh->setSurfaceColor(desiredColor_glm);
|
|
||||||
}
|
|
||||||
|
|
||||||
return polyscopeHandle_mesh;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
void moveToCenter()
|
|
||||||
{
|
|
||||||
CoordType centerOfMass(0, 0, 0);
|
|
||||||
|
|
||||||
for (int vi = 0; vi < VN(); vi++) {
|
|
||||||
centerOfMass += vert[vi].cP();
|
|
||||||
}
|
|
||||||
centerOfMass /= VN();
|
|
||||||
vcg::tri::UpdatePosition<VCGPolyMesh>::Translate(*this, -centerOfMass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns the average distance from the center of each edge to the center of its face over the whole mesh
|
|
||||||
* */
|
|
||||||
double getAverageFaceRadius() const
|
|
||||||
{
|
|
||||||
double averageFaceRadius = 0;
|
|
||||||
for (int fi = 0; fi < FN(); fi++) {
|
|
||||||
const VCGPolyMesh::FaceType &f = face[fi];
|
|
||||||
CoordType centerOfFace(0, 0, 0);
|
|
||||||
for (int vi = 0; vi < f.VN(); vi++) {
|
|
||||||
centerOfFace = centerOfFace + f.cP(vi);
|
|
||||||
}
|
|
||||||
centerOfFace /= f.VN();
|
|
||||||
|
|
||||||
double faceRadius = 0;
|
|
||||||
// for (int face_ei = 0; face_ei < f.EN(); face_ei++) {
|
|
||||||
// std::cout << "fi:" << getIndex(f) << std::endl;
|
|
||||||
// auto vps = f.FVp(0);
|
|
||||||
// auto vpe = vps;
|
|
||||||
for (int i = 0; i < f.VN(); i++) {
|
|
||||||
faceRadius += vcg::Distance(centerOfFace, (f.cP0(i) + f.cP1(i)) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }
|
|
||||||
const int faceEdges = f.VN(); //NOTE: When does this not hold?
|
|
||||||
faceRadius /= faceEdges;
|
|
||||||
averageFaceRadius += faceRadius;
|
|
||||||
}
|
|
||||||
averageFaceRadius /= FN();
|
|
||||||
return averageFaceRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool copy(VCGPolyMesh ©From)
|
|
||||||
{
|
|
||||||
vcg::tri::Append<VCGPolyMesh, VCGPolyMesh>::MeshCopy(*this, copyFrom);
|
|
||||||
label = copyFrom.getLabel();
|
|
||||||
// eigenEdges = mesh.getEigenEdges();
|
|
||||||
// if (eigenEdges.rows() == 0) {
|
|
||||||
// getEdges(eigenEdges);
|
|
||||||
// }
|
|
||||||
// eigenVertices = mesh.getEigenVertices();
|
|
||||||
// if (eigenVertices.rows() == 0) {
|
|
||||||
// getVertices();
|
|
||||||
// }
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::VertexEdge(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::VertexFace(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::FaceFace(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::AllocateEdge(*this);
|
|
||||||
vcg::tri::UpdateTopology<VCGPolyMesh>::EdgeEdge(*this);
|
|
||||||
// vcg::tri::UpdateTopology<VCGPolyMesh>::VertexFace(*this);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
VCGPolyMesh(VCGPolyMesh ©From) { copy(copyFrom); }
|
|
||||||
VCGPolyMesh() {}
|
|
||||||
template<typename MeshElement>
|
|
||||||
size_t getIndex(const MeshElement &meshElement) const
|
|
||||||
{
|
|
||||||
return vcg::tri::Index<VCGPolyMesh>(*this, meshElement);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using ConstVCGPolyMesh = VCGPolyMesh;
|
|
||||||
|
|
||||||
#endif // POLYMESH_HPP
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -2,102 +2,106 @@
|
||||||
#define REDUCEDMODELEVALUATOR_HPP
|
#define REDUCEDMODELEVALUATOR_HPP
|
||||||
|
|
||||||
#include "reducedmodeloptimizer_structs.hpp"
|
#include "reducedmodeloptimizer_structs.hpp"
|
||||||
|
#include "utilities.hpp"
|
||||||
|
|
||||||
class ReducedModelEvaluator
|
class ReducedModelEvaluator {
|
||||||
{
|
public:
|
||||||
public:
|
enum CSVExportingDirection { Vertical = 0, Horizontal };
|
||||||
enum CSVExportingDirection { Vertical = 0, Horizontal };
|
enum CSVExportingData {
|
||||||
enum CSVExportingData {
|
raw_drm2Reduced = 0,
|
||||||
raw_drm2Reduced = 0,
|
norm_drm2Reduced,
|
||||||
norm_drm2Reduced,
|
raw_and_norm_drm2Reduced,
|
||||||
raw_and_norm_drm2Reduced,
|
NumberOfDataTypes
|
||||||
NumberOfDataTypes
|
};
|
||||||
};
|
inline static std::array<std::string, NumberOfDataTypes>
|
||||||
inline static std::array<std::string, NumberOfDataTypes>
|
csvExportingDataStrings{"raw_drm2Reduced", "norm_drm2Reduced",
|
||||||
csvExportingDataStrings{"raw_drm2Reduced", "norm_drm2Reduced", "raw_and_norm_drm2Reduced"};
|
"raw_and_norm_drm2Reduced"};
|
||||||
struct Settings
|
struct Settings {
|
||||||
{
|
CSVExportingDirection exportingDirection{Horizontal};
|
||||||
CSVExportingDirection exportingDirection{Horizontal};
|
CSVExportingData exportingData{norm_drm2Reduced};
|
||||||
CSVExportingData exportingData{norm_drm2Reduced};
|
bool shouldWriteHeader{true};
|
||||||
bool shouldWriteHeader{true};
|
std::string resultsLabel;
|
||||||
std::string resultsLabel;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
inline static constexpr int NumberOfEvaluationScenarios{22};
|
inline static constexpr int NumberOfEvaluationScenarios{22};
|
||||||
struct Results
|
struct Results {
|
||||||
{
|
std::array<double, NumberOfEvaluationScenarios> distances_drm2reduced;
|
||||||
std::array<double, NumberOfEvaluationScenarios> distances_drm2reduced;
|
std::array<double, NumberOfEvaluationScenarios>
|
||||||
std::array<double, NumberOfEvaluationScenarios> distances_normalizedDrm2reduced;
|
distances_normalizedDrm2reduced;
|
||||||
std::array<std::string, NumberOfEvaluationScenarios> evaluationScenarioLabels;
|
std::array<std::string, NumberOfEvaluationScenarios>
|
||||||
};
|
evaluationScenarioLabels;
|
||||||
ReducedModelEvaluator();
|
};
|
||||||
Results evaluateReducedModel(
|
ReducedModelEvaluator();
|
||||||
ReducedModelOptimization::Results &optimizationResult,
|
Results evaluateReducedModel(
|
||||||
const std::filesystem::path &scenariosDirectoryPath,
|
ReducedModelOptimization::Results& optimizationResult,
|
||||||
// const std::filesystem::path &reducedPatternFilePath,
|
const std::filesystem::path& scenariosDirectoryPath,
|
||||||
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath);
|
// const std::filesystem::path &reducedPatternFilePath,
|
||||||
Results evaluateReducedModel(ReducedModelOptimization::Results &optimizationResult);
|
const std::filesystem::path& fullPatternTessellatedResultsDirectoryPath);
|
||||||
static void printResultsVertically(const ReducedModelEvaluator::Results &evaluationResults,
|
Results evaluateReducedModel(
|
||||||
csvFile &csvOutput);
|
ReducedModelOptimization::Results& optimizationResult);
|
||||||
static void printResults(const ReducedModelEvaluator::Results &evaluationResults,
|
static void printResultsVertically(
|
||||||
const std::string &resultsLabel);
|
const ReducedModelEvaluator::Results& evaluationResults,
|
||||||
|
csvFile& csvOutput);
|
||||||
|
static void printResults(
|
||||||
|
const ReducedModelEvaluator::Results& evaluationResults,
|
||||||
|
const std::string& resultsLabel);
|
||||||
|
|
||||||
inline static std::array<std::string, NumberOfEvaluationScenarios> scenariosTestSetLabels{
|
inline static std::array<std::string, NumberOfEvaluationScenarios>
|
||||||
"22Hex_randomBending0",
|
scenariosTestSetLabels{
|
||||||
"22Hex_randomBending1",
|
"22Hex_randomBending0", "22Hex_randomBending1",
|
||||||
"22Hex_randomBending2",
|
"22Hex_randomBending2",
|
||||||
// "22Hex_randomBending3",
|
// "22Hex_randomBending3",
|
||||||
"22Hex_randomBending4",
|
"22Hex_randomBending4", "22Hex_randomBending5",
|
||||||
"22Hex_randomBending5",
|
// "22Hex_randomBending6",
|
||||||
// "22Hex_randomBending6",
|
// "22Hex_randomBending7",
|
||||||
// "22Hex_randomBending7",
|
"22Hex_randomBending8", "22Hex_randomBending9",
|
||||||
"22Hex_randomBending8",
|
"22Hex_randomBending10", "22Hex_randomBending11",
|
||||||
"22Hex_randomBending9",
|
"22Hex_randomBending12",
|
||||||
"22Hex_randomBending10",
|
// "22Hex_randomBending13",
|
||||||
"22Hex_randomBending11",
|
// "22Hex_randomBending14",
|
||||||
"22Hex_randomBending12",
|
// "22Hex_randomBending15",
|
||||||
// "22Hex_randomBending13",
|
"22Hex_randomBending16", "22Hex_randomBending17",
|
||||||
// "22Hex_randomBending14",
|
"22Hex_randomBending18", "22Hex_randomBending19",
|
||||||
// "22Hex_randomBending15",
|
// "22Hex_randomBending20",
|
||||||
"22Hex_randomBending16",
|
"22Hex_bending_0.005N", "22Hex_bending_0.01N", "22Hex_bending_0.03N",
|
||||||
"22Hex_randomBending17",
|
// "22Hex_bending_0.05N",
|
||||||
"22Hex_randomBending18",
|
"22Hex_pullOppositeVerts_0.05N", "22Hex_pullOppositeVerts_0.1N",
|
||||||
"22Hex_randomBending19",
|
// "22Hex_pullOppositeVerts_0.3N",
|
||||||
// "22Hex_randomBending20",
|
//#ifdef POLYSCOPE_DEFINED
|
||||||
"22Hex_bending_0.005N",
|
// "22Hex_shear_2N",
|
||||||
"22Hex_bending_0.01N",
|
// "22Hex_shear_5N",
|
||||||
"22Hex_bending_0.03N",
|
// "22Hex_axial_10N",
|
||||||
// "22Hex_bending_0.05N",
|
// "22Hex_axial_20N",
|
||||||
"22Hex_pullOppositeVerts_0.05N",
|
//#else
|
||||||
"22Hex_pullOppositeVerts_0.1N",
|
// "notUsed_22Hex_shear_2N",
|
||||||
// "22Hex_pullOppositeVerts_0.3N",
|
// "notUsed_22Hex_shear_5N",
|
||||||
//#ifdef POLYSCOPE_DEFINED
|
// "notUsed_22Hex_axial_10N",
|
||||||
// "22Hex_shear_2N",
|
// "notUsed_22Hex_axial_20N",
|
||||||
// "22Hex_shear_5N",
|
//#endif
|
||||||
// "22Hex_axial_10N",
|
"22Hex_cylinder_0.05N", "22Hex_cylinder_0.1N", "22Hex_s_0.05N",
|
||||||
// "22Hex_axial_20N",
|
// "22Hex_s_0.1N"
|
||||||
//#else
|
};
|
||||||
// "notUsed_22Hex_shear_2N",
|
static void printResultsHorizontally(const Results& evaluationResults,
|
||||||
// "notUsed_22Hex_shear_5N",
|
csvFile& csvOutput);
|
||||||
// "notUsed_22Hex_axial_10N",
|
static void printResults(const Results& evaluationResults,
|
||||||
// "notUsed_22Hex_axial_20N",
|
const Settings& settings,
|
||||||
//#endif
|
csvFile& csvOutput);
|
||||||
"22Hex_cylinder_0.05N",
|
static void printHeader(const Settings& settings, csvFile& csvOutput);
|
||||||
"22Hex_cylinder_0.1N",
|
// static double evaluateOptimizationSettings(
|
||||||
"22Hex_s_0.05N",
|
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||||
// "22Hex_s_0.1N"
|
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||||
};
|
// std::vector<ReducedModelEvaluator::Results>
|
||||||
static void printResultsHorizontally(const Results &evaluationResults, csvFile &csvOutput);
|
// &patternEvaluationResults);
|
||||||
static void printResults(const Results &evaluationResults,
|
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
||||||
const Settings &settings,
|
ReducedModelOptimization::Colors::RGBColor color_tesselatedPatterns{
|
||||||
csvFile &csvOutput);
|
24.0 / 255, 23.0 / 255, 23.0 / 255};
|
||||||
static void printHeader(const Settings &settings, csvFile &csvOutput);
|
ReducedModelOptimization::Colors::RGBColor color_tesselatedReducedModels{
|
||||||
// static double evaluateOptimizationSettings(
|
67.0 / 255, 160.00 / 255, 232.0 / 255};
|
||||||
// const ReducedModelOptimization::Settings &optimizationSettings,
|
ReducedModelOptimization::Colors::RGBColor color_tileIntoSurface{
|
||||||
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
222 / 255.0, 235 / 255.0, 255 / 255.0};
|
||||||
// std::vector<ReducedModelEvaluator::Results> &patternEvaluationResults);
|
ReducedModelOptimization::Colors::RGBColor interfaceNodes_color{
|
||||||
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
63.0 / 255, 85.0 / 255, 42.0 / 255};
|
||||||
inline static constexpr char *tileIntoSurfaceFileContent = R"~(OFF
|
inline static constexpr char* tileIntoSurfaceFileContent = R"~(OFF
|
||||||
46 66 0
|
46 66 0
|
||||||
-0.0745923 0.03573945 0
|
-0.0745923 0.03573945 0
|
||||||
-0.07464622 0.02191801 0
|
-0.07464622 0.02191801 0
|
||||||
|
|
@ -214,4 +218,4 @@ public:
|
||||||
)~";
|
)~";
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REDUCEDMODELEVALUATOR_HPP
|
#endif // REDUCEDMODELEVALUATOR_HPP
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,18 +1,17 @@
|
||||||
#ifndef REDUCEDMODELOPTIMIZER_HPP
|
#ifndef REDUCEDMODELOPTIMIZER_HPP
|
||||||
#define REDUCEDMODELOPTIMIZER_HPP
|
#define REDUCEDMODELOPTIMIZER_HPP
|
||||||
|
|
||||||
#include "chronoseulersimulationmodel.hpp"
|
//#include "csvfile.hpp"
|
||||||
#include "csvfile.hpp"
|
|
||||||
#include "drmsimulationmodel.hpp"
|
#include "drmsimulationmodel.hpp"
|
||||||
#include "edgemesh.hpp"
|
#include "edgemesh.hpp"
|
||||||
#include "linearsimulationmodel.hpp"
|
#include "linearsimulationmodel.hpp"
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
#include "matplot/matplot.h"
|
#include "matplot/matplot.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <Eigen/Dense>
|
||||||
#include "reducedmodel.hpp"
|
#include "reducedmodel.hpp"
|
||||||
#include "reducedmodeloptimizer_structs.hpp"
|
#include "reducedmodeloptimizer_structs.hpp"
|
||||||
#include "simulationmesh.hpp"
|
#include "simulationmesh.hpp"
|
||||||
#include <Eigen/Dense>
|
|
||||||
#ifdef DLIB_DEFINED
|
#ifdef DLIB_DEFINED
|
||||||
#include <dlib/global_optimization.h>
|
#include <dlib/global_optimization.h>
|
||||||
#include <dlib/optimization.h>
|
#include <dlib/optimization.h>
|
||||||
|
|
@ -20,348 +19,384 @@
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
#include "polyscope/color_management.h"
|
#include "polyscope/color_management.h"
|
||||||
#endif // POLYSCOPE_DEFINED
|
#endif // POLYSCOPE_DEFINED
|
||||||
using FullPatternVertexIndex = VertexIndex;
|
using PatternVertexIndex = VertexIndex;
|
||||||
using ReducedPatternVertexIndex = VertexIndex;
|
using ReducedModelVertexIndex = VertexIndex;
|
||||||
|
|
||||||
class ReducedModelOptimizer
|
class ReducedModelOptimizer {
|
||||||
{
|
public:
|
||||||
public:
|
struct OptimizationState {
|
||||||
struct OptimizationState
|
std::vector<SimulationResults> fullPatternResults;
|
||||||
{
|
std::vector<double> translationalDisplacementNormalizationValues;
|
||||||
std::vector<SimulationResults> fullPatternResults;
|
std::vector<double> rotationalDisplacementNormalizationValues;
|
||||||
std::vector<double> translationalDisplacementNormalizationValues;
|
std::vector<std::shared_ptr<SimulationJob>> pSimulationJobs_pattern;
|
||||||
std::vector<double> rotationalDisplacementNormalizationValues;
|
std::vector<std::shared_ptr<SimulationJob>> simulationJobs_reducedModel;
|
||||||
std::vector<std::shared_ptr<SimulationJob>> fullPatternSimulationJobs;
|
std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>
|
||||||
std::vector<std::shared_ptr<SimulationJob>> reducedPatternSimulationJobs;
|
reducedToFullInterfaceViMap;
|
||||||
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>
|
||||||
reducedToFullInterfaceViMap;
|
fullPatternOppositeInterfaceViPairs;
|
||||||
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
matplot::line_handle gPlotHandle;
|
||||||
fullPatternOppositeInterfaceViPairs;
|
std::vector<size_t> objectiveValueHistory_iteration;
|
||||||
matplot::line_handle gPlotHandle;
|
std::vector<double> objectiveValueHistory;
|
||||||
std::vector<size_t> objectiveValueHistory_iteration;
|
std::vector<double> plotColors;
|
||||||
std::vector<double> objectiveValueHistory;
|
std::array<double,
|
||||||
std::vector<double> plotColors;
|
ReducedModelOptimization::OptimizationParameterIndex::
|
||||||
std::array<double,
|
NumberOfOptimizationVariables>
|
||||||
ReducedModelOptimization::OptimizationParameterIndex::NumberOfOptimizationVariables>
|
parametersInitialValue;
|
||||||
parametersInitialValue;
|
std::array<double,
|
||||||
std::array<double,
|
ReducedModelOptimization::OptimizationParameterIndex::
|
||||||
ReducedModelOptimization::OptimizationParameterIndex::NumberOfOptimizationVariables>
|
NumberOfOptimizationVariables>
|
||||||
optimizationInitialValue;
|
optimizationInitialValue;
|
||||||
std::vector<int> simulationScenarioIndices;
|
std::vector<int> simulationScenarioIndices;
|
||||||
double minY{DBL_MAX};
|
double minY{DBL_MAX};
|
||||||
std::vector<double> minX;
|
std::vector<double> minX;
|
||||||
int numOfSimulationCrashes{false};
|
int numOfSimulationCrashes{false};
|
||||||
int numberOfFunctionCalls{0};
|
int numberOfFunctionCalls{0};
|
||||||
//Variables for finding the full pattern simulation forces
|
// Variables for finding the full pattern simulation forces
|
||||||
std::shared_ptr<SimulationMesh> pFullPatternSimulationMesh;
|
std::shared_ptr<SimulationEdgeMesh> pFullPatternSimulationEdgeMesh;
|
||||||
std::array<std::function<void(const double &newValue,
|
std::array<std::function<void(const double& newValue,
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>,
|
std::shared_ptr<SimulationEdgeMesh>&
|
||||||
7>
|
pReducedPatternSimulationEdgeMesh)>,
|
||||||
functions_updateReducedPatternParameter;
|
7>
|
||||||
std::vector<double> xMin;
|
functions_updateReducedPatternParameter;
|
||||||
std::vector<double> xMax;
|
std::vector<double> xMin;
|
||||||
std::vector<double> scenarioWeights;
|
std::vector<double> xMax;
|
||||||
std::vector<ReducedModelOptimization::Settings::ObjectiveWeights> objectiveWeights;
|
std::vector<double> scenarioWeights;
|
||||||
};
|
std::vector<ReducedModelOptimization::Settings::ObjectiveWeights>
|
||||||
|
objectiveWeights;
|
||||||
|
std::string simulationModelLabel_reducedModel;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OptimizationState optimizationState;
|
OptimizationState optimizationState;
|
||||||
vcg::Triangle3<double> baseTriangle;
|
vcg::Triangle3<double> baseTriangle;
|
||||||
std::function<void(const double &,
|
std::function<void(
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>> &,
|
const double&,
|
||||||
SimulationJob &)>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&,
|
||||||
constructScenarioFunction;
|
SimulationJob&)>
|
||||||
std::shared_ptr<SimulationMesh> m_pReducedModelSimulationMesh;
|
constructScenarioFunction;
|
||||||
std::shared_ptr<SimulationMesh> m_pFullPatternSimulationMesh;
|
std::shared_ptr<SimulationEdgeMesh> m_pReducedModelSimulationEdgeMesh;
|
||||||
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
std::shared_ptr<SimulationEdgeMesh> m_pSimulationEdgeMesh_pattern;
|
||||||
m_fullToReducedInterfaceViMap;
|
std::unordered_map<PatternVertexIndex, ReducedModelVertexIndex>
|
||||||
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
m_fullToReducedInterfaceViMap;
|
||||||
m_fullPatternOppositeInterfaceViPairs;
|
std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>
|
||||||
std::unordered_map<size_t, size_t> nodeToSlot;
|
m_fullPatternOppositeInterfaceViPairs;
|
||||||
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
std::unordered_map<size_t, size_t> nodeToSlot;
|
||||||
std::string optimizationNotes;
|
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
||||||
std::array<std::function<void(
|
std::string optimizationNotes;
|
||||||
const double &,
|
std::array<
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>> &,
|
std::function<void(
|
||||||
SimulationJob &)>,
|
const double&,
|
||||||
ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&,
|
||||||
constructBaseScenarioFunctions;
|
SimulationJob&)>,
|
||||||
std::vector<bool> scenarioIsSymmetrical;
|
ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
int fullPatternNumberOfEdges;
|
constructBaseScenarioFunctions;
|
||||||
constexpr static double youngsModulus{1 * 1e9};
|
std::vector<bool> scenarioIsSymmetrical;
|
||||||
constexpr static double defaultBeamWidth{0.002};
|
int fullPatternNumberOfEdges;
|
||||||
constexpr static double defaultBeamHeight{0.002};
|
std::string fullPatternLabel;
|
||||||
std::string fullPatternLabel;
|
// ReducedModelOptimization::Settings optimizationSettings;
|
||||||
// ReducedModelOptimization::Settings optimizationSettings;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct FunctionEvaluation
|
struct FunctionEvaluation {
|
||||||
{
|
FunctionEvaluation() = default;
|
||||||
FunctionEvaluation() = default;
|
FunctionEvaluation(const std::vector<double>& x, double y) : x(x), y(y) {}
|
||||||
FunctionEvaluation(const std::vector<double> &x, double y) : x(x), y(y) {}
|
|
||||||
|
|
||||||
std::vector<double> x;
|
std::vector<double> x;
|
||||||
double y = std::numeric_limits<double>::quiet_NaN();
|
double y = std::numeric_limits<double>::quiet_NaN();
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct ParameterLabels
|
// struct ParameterLabels
|
||||||
// {
|
// {
|
||||||
// inline const static std::string E = {"E"};
|
// inline const static std::string E = {"E"};
|
||||||
// inline const static std::string A = {"A"};
|
// inline const static std::string A = {"A"};
|
||||||
// inline const static std::string I2 ={"I2"};
|
// inline const static std::string I2 ={"I2"};
|
||||||
// inline const static std::string I3 ={"I3"};
|
// inline const static std::string I3 ={"I3"};
|
||||||
// inline const static std::string J = {"J"};
|
// inline const static std::string J = {"J"};
|
||||||
// inline const static std::string th= {"Theta"};
|
// inline const static std::string th= {"Theta"};
|
||||||
// inline const static std::string R = {"R"};
|
// inline const static std::string R = {"R"};
|
||||||
// };
|
// };
|
||||||
// inline constexpr static ParameterLabels parameterLabels();
|
// inline constexpr static ParameterLabels parameterLabels();
|
||||||
|
|
||||||
inline static std::array<std::string, ReducedModelOptimization::NumberOfOptimizationVariables>
|
inline static std::array<
|
||||||
parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"};
|
std::string,
|
||||||
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
ReducedModelOptimization::NumberOfOptimizationVariables>
|
||||||
simulationScenariosResolution = {12, 12, 22, 22, 22, 22};
|
parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"};
|
||||||
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
constexpr static std::
|
||||||
baseScenarioWeights = {1, 1, 2, 2, 2};
|
array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
inline static int totalNumberOfSimulationScenarios
|
simulationScenariosResolution = {12, 12, 22, 22, 22, 22};
|
||||||
= std::accumulate(simulationScenariosResolution.begin(),
|
// simulationScenariosResolution = {2, 2, 2, 22, 22, 22};
|
||||||
simulationScenariosResolution.end(),
|
constexpr static std::
|
||||||
0);
|
array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
inline static int fanSize{6};
|
baseScenarioWeights = {1, 1, 2, 2, 2};
|
||||||
inline static double initialHexagonSize{0.3};
|
inline static int totalNumberOfSimulationScenarios =
|
||||||
int interfaceNodeIndex;
|
std::accumulate(simulationScenariosResolution.begin(),
|
||||||
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
simulationScenariosResolution.end(),
|
||||||
|
0);
|
||||||
|
inline static int fanCardinality{6};
|
||||||
|
inline static double initialValue_R{0.3};
|
||||||
|
inline static double initialValue_theta{0};
|
||||||
|
int interfaceNodeIndex;
|
||||||
|
double operator()(const Eigen::VectorXd& x, Eigen::VectorXd&) const;
|
||||||
|
|
||||||
ReducedModelOptimizer();
|
ReducedModelOptimizer();
|
||||||
static void computeReducedModelSimulationJob(
|
static void computeReducedModelSimulationJob(
|
||||||
const SimulationJob &simulationJobOfFullModel,
|
const SimulationJob& simulationJobOfFullModel,
|
||||||
const std::unordered_map<size_t, size_t> &fullToReducedMap,
|
const std::unordered_map<size_t, size_t>& fullToReducedMap,
|
||||||
SimulationJob &simulationJobOfReducedModel);
|
SimulationJob& simulationJobOfReducedModel);
|
||||||
|
|
||||||
SimulationJob getReducedSimulationJob(const SimulationJob &fullModelSimulationJob);
|
SimulationJob getReducedSimulationJob(
|
||||||
|
const SimulationJob& fullModelSimulationJob);
|
||||||
|
|
||||||
static void runSimulation(const std::string &filename, std::vector<double> &x);
|
static void runSimulation(const std::string& filename,
|
||||||
|
std::vector<double>& x);
|
||||||
|
|
||||||
static std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
static std::vector<std::shared_ptr<SimulationJob>>
|
||||||
const std::shared_ptr<SimulationMesh> &pMesh,
|
createFullPatternSimulationJobs(
|
||||||
const std::unordered_map<size_t, size_t> &fullPatternOppositeInterfaceViMap);
|
const std::shared_ptr<SimulationEdgeMesh>& pMesh,
|
||||||
|
const std::unordered_map<size_t, size_t>&
|
||||||
|
fullPatternOppositeInterfaceViMap);
|
||||||
|
|
||||||
static void createSimulationMeshes(
|
static void createSimulationEdgeMeshes(
|
||||||
PatternGeometry &pattern,
|
PatternGeometry& pattern,
|
||||||
PatternGeometry &reducedModel,
|
PatternGeometry& reducedModel,
|
||||||
const RectangularBeamDimensions &beamDimensions,
|
const ReducedModelOptimization::Settings& optimizationSettings,
|
||||||
std::shared_ptr<SimulationMesh> &pFullPatternSimulationMesh,
|
std::shared_ptr<SimulationEdgeMesh>& pFullPatternSimulationEdgeMesh,
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh);
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh);
|
||||||
void computeMaps(const std::unordered_map<size_t, std::unordered_set<size_t>> &slotToNode,
|
void computeMaps(
|
||||||
PatternGeometry &fullPattern,
|
const std::unordered_map<size_t, std::unordered_set<size_t>>& slotToNode,
|
||||||
ReducedModel &reducedPattern,
|
PatternGeometry& fullPattern,
|
||||||
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
ReducedModel& reducedPattern,
|
||||||
&reducedToFullInterfaceViMap,
|
std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
reducedToFullInterfaceViMap,
|
||||||
&fullToReducedInterfaceViMap,
|
std::unordered_map<PatternVertexIndex, ReducedModelVertexIndex>&
|
||||||
std::vector<std::pair<FullPatternVertexIndex, ReducedPatternVertexIndex>>
|
fullToReducedInterfaceViMap,
|
||||||
&fullPatternOppositeInterfaceViMap);
|
std::vector<std::pair<PatternVertexIndex, ReducedModelVertexIndex>>&
|
||||||
static void visualizeResults(
|
fullPatternOppositeInterfaceViMap);
|
||||||
const std::vector<std::shared_ptr<SimulationJob>> &fullPatternSimulationJobs,
|
static void visualizeResults(
|
||||||
const std::vector<std::shared_ptr<SimulationJob>> &reducedPatternSimulationJobs,
|
const std::vector<std::shared_ptr<SimulationJob>>&
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios,
|
fullPatternSimulationJobs,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::vector<std::shared_ptr<SimulationJob>>&
|
||||||
&reducedToFullInterfaceViMap);
|
reducedPatternSimulationJobs,
|
||||||
static void registerResultsForDrawing(
|
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||||
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob,
|
simulationScenarios,
|
||||||
const std::shared_ptr<SimulationJob> &pReducedPatternSimulationJob,
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
reducedToFullInterfaceViMap);
|
||||||
&reducedToFullInterfaceViMap);
|
static void registerResultsForDrawing(
|
||||||
|
const std::shared_ptr<SimulationJob>& pFullPatternSimulationJob,
|
||||||
|
const std::shared_ptr<SimulationJob>& pReducedPatternSimulationJob,
|
||||||
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
|
reducedToFullInterfaceViMap);
|
||||||
|
|
||||||
static double computeRawTranslationalError(
|
static double computeRawTranslationalError(
|
||||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
const std::vector<Vector6d>& fullPatternDisplacements,
|
||||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
const std::vector<Vector6d>& reducedPatternDisplacements,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
&reducedToFullInterfaceViMap);
|
reducedToFullInterfaceViMap);
|
||||||
|
|
||||||
static double computeDisplacementError(
|
static double computeDisplacementError(
|
||||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
const std::vector<Vector6d>& fullPatternDisplacements,
|
||||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
const std::vector<Vector6d>& reducedPatternDisplacements,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
&reducedToFullInterfaceViMap,
|
reducedToFullInterfaceViMap,
|
||||||
const double &normalizationFactor);
|
const double& normalizationFactor);
|
||||||
|
|
||||||
static double computeRawRotationalError(
|
static double computeRawRotationalError(
|
||||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_fullPattern,
|
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_fullPattern,
|
||||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_reducedPattern,
|
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_reducedPattern,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
&reducedToFullInterfaceViMap);
|
reducedToFullInterfaceViMap);
|
||||||
|
|
||||||
static double computeRotationalError(const std::vector<Eigen::Quaterniond> &rotatedQuaternion_fullPattern,
|
static double computeRotationalError(
|
||||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_reducedPattern,
|
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_fullPattern,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_reducedPattern,
|
||||||
&reducedToFullInterfaceViMap,
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
const double &normalizationFactor);
|
reducedToFullInterfaceViMap,
|
||||||
static double computeError(
|
const double& normalizationFactor);
|
||||||
const SimulationResults &simulationResults_fullPattern,
|
static double computeError(
|
||||||
const SimulationResults &simulationResults_reducedPattern,
|
const SimulationResults& simulationResults_fullPattern,
|
||||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
const SimulationResults& simulationResults_reducedPattern,
|
||||||
&reducedToFullInterfaceViMap,
|
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||||
const double &normalizationFactor_translationalDisplacement,
|
reducedToFullInterfaceViMap,
|
||||||
const double &normalizationFactor_rotationalDisplacement,
|
const double& normalizationFactor_translationalDisplacement,
|
||||||
const double &scenarioWeight,
|
const double& normalizationFactor_rotationalDisplacement,
|
||||||
const ReducedModelOptimization::Settings::ObjectiveWeights &objectiveWeights);
|
const double& scenarioWeight,
|
||||||
static void constructAxialSimulationScenario(
|
const ReducedModelOptimization::Settings::ObjectiveWeights&
|
||||||
const double &forceMagnitude,
|
objectiveWeights);
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
static void constructAxialSimulationScenario(
|
||||||
&oppositeInterfaceViPairs,
|
const double& forceMagnitude,
|
||||||
SimulationJob &job);
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
|
oppositeInterfaceViPairs,
|
||||||
|
SimulationJob& job);
|
||||||
|
|
||||||
static void constructShearSimulationScenario(
|
static void constructShearSimulationScenario(
|
||||||
const double &forceMagnitude,
|
const double& forceMagnitude,
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
&oppositeInterfaceViPairs,
|
oppositeInterfaceViPairs,
|
||||||
SimulationJob &job);
|
SimulationJob& job);
|
||||||
|
|
||||||
static void constructBendingSimulationScenario(
|
static void constructBendingSimulationScenario(
|
||||||
const double &forceMagnitude,
|
const double& forceMagnitude,
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
&oppositeInterfaceViPairs,
|
oppositeInterfaceViPairs,
|
||||||
SimulationJob &job);
|
SimulationJob& job);
|
||||||
|
|
||||||
static void constructDomeSimulationScenario(
|
static void constructDomeSimulationScenario(
|
||||||
const double &forceMagnitude,
|
const double& forceMagnitude,
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
&oppositeInterfaceViPairs,
|
oppositeInterfaceViPairs,
|
||||||
SimulationJob &job);
|
SimulationJob& job);
|
||||||
|
|
||||||
static void constructSaddleSimulationScenario(
|
static void constructSaddleSimulationScenario(
|
||||||
const double &forceMagnitude,
|
const double& forceMagnitude,
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
&oppositeInterfaceViPairs,
|
oppositeInterfaceViPairs,
|
||||||
SimulationJob &job);
|
SimulationJob& job);
|
||||||
static void constructSSimulationScenario(
|
static void constructSSimulationScenario(
|
||||||
const double &forceMagnitude,
|
const double& forceMagnitude,
|
||||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||||
&oppositeInterfaceViPairs,
|
oppositeInterfaceViPairs,
|
||||||
SimulationJob &job);
|
SimulationJob& job);
|
||||||
static std::function<void(const std::vector<double> &x,
|
static std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const std::vector<double>& x,
|
||||||
function_updateReducedPattern;
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
static std::function<void(const double &newE,
|
function_updateReducedPattern;
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
static std::function<void(
|
||||||
function_updateReducedPattern_material_E;
|
const double& newE,
|
||||||
static std::function<void(const double &newA,
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
function_updateReducedPattern_material_E;
|
||||||
function_updateReducedPattern_material_A;
|
static std::function<void(
|
||||||
static std::function<void(const double &newI,
|
const double& newA,
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
function_updateReducedPattern_material_I;
|
function_updateReducedPattern_material_A;
|
||||||
static std::function<void(const double &newI2,
|
static std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newI,
|
||||||
function_updateReducedPattern_material_I2;
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
static std::function<void(const double &newI3,
|
function_updateReducedPattern_material_I;
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
static std::function<void(
|
||||||
function_updateReducedPattern_material_I3;
|
const double& newI2,
|
||||||
static std::function<void(const double &newJ,
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
function_updateReducedPattern_material_I2;
|
||||||
function_updateReducedPattern_material_J;
|
static std::function<void(
|
||||||
static double objective(const std::vector<double> &x);
|
const double& newI3,
|
||||||
void initializeUpdateReducedPatternFunctions();
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
// static double objective(const double &xValue);
|
function_updateReducedPattern_material_I3;
|
||||||
|
static std::function<void(
|
||||||
|
const double& newJ,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
|
function_updateReducedPattern_material_J;
|
||||||
|
static double objective(const std::vector<double>& x);
|
||||||
|
void initializeUpdateReducedPatternFunctions();
|
||||||
|
// static double objective(const double &xValue);
|
||||||
|
|
||||||
ReducedModelOptimization::Results optimize(
|
ReducedModelOptimization::Results optimize(
|
||||||
ConstPatternGeometry &fullPattern,
|
ConstPatternGeometry& fullPattern,
|
||||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||||
|
|
||||||
void optimize(ConstPatternGeometry &fullPattern,
|
void optimize(ConstPatternGeometry& fullPattern,
|
||||||
ReducedModelOptimization::Settings &optimizationSettings,
|
ReducedModelOptimization::Settings& optimizationSettings,
|
||||||
ReducedModelOptimization::Results &optimizationResults);
|
ReducedModelOptimization::Results& optimizationResults);
|
||||||
static double objective(const std::vector<double> &x,
|
static double objective(
|
||||||
ReducedModelOptimizer::OptimizationState &optimizationState);
|
const std::vector<double>& x,
|
||||||
|
ReducedModelOptimizer::OptimizationState& optimizationState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void optimize(
|
void optimize(
|
||||||
ReducedModelOptimization::Settings &optimizationSettings,
|
ReducedModelOptimization::Settings& optimizationSettings,
|
||||||
ReducedModelOptimization::Results &results,
|
ReducedModelOptimization::Results& results,
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios
|
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||||
= std::vector<ReducedModelOptimization::BaseSimulationScenario>(
|
simulationScenarios =
|
||||||
{ReducedModelOptimization::Axial,
|
std::vector<ReducedModelOptimization::BaseSimulationScenario>(
|
||||||
ReducedModelOptimization::Shear,
|
{ReducedModelOptimization::Axial,
|
||||||
ReducedModelOptimization::Bending,
|
ReducedModelOptimization::Shear,
|
||||||
ReducedModelOptimization::Dome,
|
ReducedModelOptimization::Bending,
|
||||||
ReducedModelOptimization::Saddle,
|
ReducedModelOptimization::Dome,
|
||||||
ReducedModelOptimization::S}));
|
ReducedModelOptimization::Saddle,
|
||||||
|
ReducedModelOptimization::S}));
|
||||||
|
|
||||||
void initializePatterns(PatternGeometry &fullPattern,
|
void initializePatterns(
|
||||||
ReducedModel &reducedModel,
|
PatternGeometry& fullPattern,
|
||||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
ReducedModel& reducedModel,
|
||||||
static void computeDesiredReducedModelDisplacements(
|
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||||
const SimulationResults &fullModelResults,
|
static void computeDesiredReducedModelDisplacements(
|
||||||
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
const SimulationResults& fullModelResults,
|
||||||
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
const std::unordered_map<size_t, size_t>& displacementsReducedToFullMap,
|
||||||
void runOptimization(const ReducedModelOptimization::Settings &settings,
|
Eigen::MatrixX3d& optimalDisplacementsOfReducedModel);
|
||||||
ReducedModelOptimization::Results &results);
|
void runOptimization(const ReducedModelOptimization::Settings& settings,
|
||||||
void computeMaps(PatternGeometry &fullModel, ReducedModel &reducedModel);
|
ReducedModelOptimization::Results& results);
|
||||||
void createSimulationMeshes(PatternGeometry &fullModel,
|
void computeMaps(PatternGeometry& fullModel, ReducedModel& reducedModel);
|
||||||
PatternGeometry &reducedModel,
|
void createSimulationEdgeMeshes(
|
||||||
const RectangularBeamDimensions &beamDimensions);
|
PatternGeometry& fullModel,
|
||||||
void initializeOptimizationParameters(
|
PatternGeometry& reducedModel,
|
||||||
const std::shared_ptr<SimulationMesh> &mesh,
|
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||||
const std::array<ReducedModelOptimization::xRange,
|
void initializeOptimizationParameters(
|
||||||
ReducedModelOptimization::NumberOfOptimizationVariables>
|
const std::shared_ptr<SimulationEdgeMesh>& mesh,
|
||||||
&optimizationParamters);
|
const std::array<ReducedModelOptimization::xRange,
|
||||||
|
ReducedModelOptimization::NumberOfOptimizationVariables>&
|
||||||
|
optimizationParamters);
|
||||||
|
|
||||||
ChronosEulerSimulationModel patternSimulator;
|
void computeObjectiveValueNormalizationFactors(
|
||||||
LinearSimulationModel reducedModelSimulator;
|
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||||
void computeObjectiveValueNormalizationFactors(
|
|
||||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
|
||||||
|
|
||||||
void getResults(const FunctionEvaluation &optimalObjective,
|
void getResults(const FunctionEvaluation& optimalObjective,
|
||||||
const ReducedModelOptimization::Settings &settings,
|
const ReducedModelOptimization::Settings& settings,
|
||||||
ReducedModelOptimization::Results &results);
|
ReducedModelOptimization::Results& results);
|
||||||
double computeFullPatternMaxSimulationForce(
|
double computeFullPatternMaxSimulationForce(
|
||||||
const ReducedModelOptimization::BaseSimulationScenario &scenario) const;
|
const ReducedModelOptimization::BaseSimulationScenario& scenario) const;
|
||||||
|
|
||||||
#ifdef DLIB_DEFINED
|
#ifdef DLIB_DEFINED
|
||||||
static double objective(const dlib::matrix<double, 0, 1> &x);
|
static double objective(const dlib::matrix<double, 0, 1>& x);
|
||||||
#endif
|
#endif
|
||||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
computeFullPatternMaxSimulationForces(
|
computeFullPatternMaxSimulationForces(
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>
|
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||||
&desiredBaseSimulationScenario) const;
|
desiredBaseSimulationScenario) const;
|
||||||
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
||||||
const std::shared_ptr<SimulationMesh> &pMesh,
|
const std::shared_ptr<SimulationEdgeMesh>& pMesh,
|
||||||
const std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
const std::array<
|
||||||
&baseScenarioMaxForceMagnitudes) const;
|
double,
|
||||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
ReducedModelOptimization::NumberOfBaseSimulationScenarios>&
|
||||||
getFullPatternMaxSimulationForces(
|
baseScenarioMaxForceMagnitudes) const;
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>
|
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
&desiredBaseSimulationScenarioIndices,
|
getFullPatternMaxSimulationForces(
|
||||||
const std::filesystem::path &intermediateResultsDirectoryPath,
|
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||||
const bool &recomputeForceMagnitudes);
|
desiredBaseSimulationScenarioIndices,
|
||||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
const std::filesystem::path& intermediateResultsDirectoryPath,
|
||||||
getFullPatternMaxSimulationForces();
|
const bool& recomputeForceMagnitudes);
|
||||||
void computeScenarioWeights(
|
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &baseSimulationScenarios,
|
getFullPatternMaxSimulationForces();
|
||||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
void computeScenarioWeights(
|
||||||
|
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||||
|
baseSimulationScenarios,
|
||||||
|
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||||
};
|
};
|
||||||
inline std::function<void(const double &newE,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newE,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_E;
|
ReducedModelOptimizer::function_updateReducedPattern_material_E;
|
||||||
inline std::function<void(const double &newA,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newA,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_A;
|
ReducedModelOptimizer::function_updateReducedPattern_material_A;
|
||||||
inline std::function<void(const double &newI,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newI,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_I;
|
ReducedModelOptimizer::function_updateReducedPattern_material_I;
|
||||||
inline std::function<void(const double &newI2,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newI2,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_I2;
|
ReducedModelOptimizer::function_updateReducedPattern_material_I2;
|
||||||
inline std::function<void(const double &newI3,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newI3,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_I3;
|
ReducedModelOptimizer::function_updateReducedPattern_material_I3;
|
||||||
inline std::function<void(const double &newJ,
|
inline std::function<void(
|
||||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
const double& newJ,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern_material_J;
|
ReducedModelOptimizer::function_updateReducedPattern_material_J;
|
||||||
inline std::function<void(const std::vector<double> &x, std::shared_ptr<SimulationMesh> &m)>
|
inline std::function<void(const std::vector<double>& x,
|
||||||
|
std::shared_ptr<SimulationEdgeMesh>& m)>
|
||||||
ReducedModelOptimizer::function_updateReducedPattern;
|
ReducedModelOptimizer::function_updateReducedPattern;
|
||||||
|
|
||||||
extern ReducedModelOptimizer::OptimizationState global;
|
extern ReducedModelOptimizer::OptimizationState global;
|
||||||
|
|
||||||
#endif // REDUCEDMODELOPTIMIZER_HPP
|
#endif // REDUCEDMODELOPTIMIZER_HPP
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,100 +1,103 @@
|
||||||
#ifndef FLATPATTERNGEOMETRY_HPP
|
#ifndef FLATPATTERNGEOMETRY_HPP
|
||||||
#define FLATPATTERNGEOMETRY_HPP
|
#define FLATPATTERNGEOMETRY_HPP
|
||||||
#include "edgemesh.hpp"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "vcgtrimesh.hpp"
|
#include "edgemesh.hpp"
|
||||||
#include "polymesh.hpp"
|
#include "polymesh.hpp"
|
||||||
|
#include "vcgtrimesh.hpp"
|
||||||
|
|
||||||
class PatternGeometry;
|
class PatternGeometry;
|
||||||
using ConstPatternGeometry = PatternGeometry;
|
using ConstPatternGeometry = PatternGeometry;
|
||||||
|
|
||||||
class PatternGeometry : public VCGEdgeMesh
|
class PatternGeometry : public VCGEdgeMesh {
|
||||||
{
|
private:
|
||||||
private:
|
size_t computeTiledValence(
|
||||||
size_t
|
const size_t& nodeIndex,
|
||||||
computeTiledValence(const size_t &nodeIndex,
|
const std::vector<size_t>& numberOfNodesPerSlot) const;
|
||||||
const std::vector<size_t> &numberOfNodesPerSlot) const;
|
size_t getNodeValence(const size_t& nodeIndex) const;
|
||||||
size_t getNodeValence(const size_t &nodeIndex) const;
|
size_t getNodeSlot(const size_t& nodeIndex) const;
|
||||||
size_t getNodeSlot(const size_t &nodeIndex) const;
|
|
||||||
|
|
||||||
void addNormals();
|
void addNormals();
|
||||||
double baseTriangleHeight;
|
double baseTriangleHeight;
|
||||||
|
|
||||||
inline static size_t fanSize{6};
|
inline static size_t fanSize{6};
|
||||||
std::vector<VCGEdgeMesh::CoordType> vertices;
|
std::vector<VCGEdgeMesh::CoordType> vertices;
|
||||||
const double triangleEdgeSize{1}; // radius edge
|
const double triangleEdgeSize{1}; // radius edge
|
||||||
std::unordered_map<size_t, size_t> nodeToSlotMap;
|
std::unordered_map<size_t, size_t> nodeToSlotMap;
|
||||||
std::unordered_map<size_t, size_t> correspondingNode;
|
std::unordered_map<size_t, size_t> correspondingNode;
|
||||||
std::unordered_map<size_t, size_t> nodeTiledValence;
|
std::unordered_map<size_t, size_t> nodeTiledValence;
|
||||||
vcg::Triangle3<double> baseTriangle;
|
vcg::Triangle3<double> baseTriangle;
|
||||||
|
|
||||||
void
|
void constructCorrespondingNodeMap(
|
||||||
constructCorrespondingNodeMap(const std::vector<size_t> &numberOfNodesPerSlot);
|
const std::vector<size_t>& numberOfNodesPerSlot);
|
||||||
|
|
||||||
void constructNodeToTiledValenceMap(const std::vector<size_t> &numberOfNodesPerSlot);
|
void constructNodeToTiledValenceMap(
|
||||||
|
const std::vector<size_t>& numberOfNodesPerSlot);
|
||||||
|
|
||||||
std::vector<VectorType> getEdgeVectorsWithVertexAsOrigin(std::vector<EdgePointer> &edgePointers,
|
std::vector<VectorType> getEdgeVectorsWithVertexAsOrigin(
|
||||||
const int &vi);
|
std::vector<EdgePointer>& edgePointers,
|
||||||
|
const int& vi);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline static VectorType DefaultNormal{0.0, 0.0, 1.0};
|
inline static VectorType DefaultNormal{0.0, 0.0, 1.0};
|
||||||
PatternGeometry();
|
PatternGeometry();
|
||||||
/*The following function should be a copy constructor with
|
/*The following function should be a copy constructor with
|
||||||
* a const argument but this is impossible due to the
|
* a const argument but this is impossible due to the
|
||||||
* vcglib interface.
|
* vcglib interface.
|
||||||
* */
|
* */
|
||||||
PatternGeometry(PatternGeometry &other);
|
PatternGeometry(PatternGeometry& other);
|
||||||
bool load(const std::filesystem::path &meshFilePath) override;
|
bool load(const std::filesystem::path& meshFilePath) override;
|
||||||
void add(const std::vector<vcg::Point3d> &vertices);
|
void add(const std::vector<vcg::Point3d>& vertices);
|
||||||
void add(const std::vector<vcg::Point2i> &edges);
|
void add(const std::vector<vcg::Point2i>& edges);
|
||||||
void add(const std::vector<vcg::Point3d> &vertices, const std::vector<vcg::Point2i> &edges);
|
void add(const std::vector<vcg::Point3d>& vertices,
|
||||||
void add(const std::vector<size_t> &numberOfNodesPerSlot, const std::vector<vcg::Point2i> &edges);
|
const std::vector<vcg::Point2i>& edges);
|
||||||
|
void add(const std::vector<size_t>& numberOfNodesPerSlot,
|
||||||
|
const std::vector<vcg::Point2i>& edges);
|
||||||
static std::vector<vcg::Point3d> constructVertexVector(
|
static std::vector<vcg::Point3d> constructVertexVector(
|
||||||
const std::vector<size_t> &numberOfNodesPerSlot,
|
const std::vector<size_t>& numberOfNodesPerSlot,
|
||||||
const size_t &fanSize,
|
const size_t& fanSize,
|
||||||
const double &triangleEdgeSize);
|
const double& triangleEdgeSize);
|
||||||
bool hasDanglingEdges(const std::vector<size_t> &numberOfNodesPerSlot);
|
bool hasDanglingEdges(const std::vector<size_t>& numberOfNodesPerSlot);
|
||||||
bool hasValenceGreaterThan(const std::vector<size_t> &numberOfNodesPerSlot,
|
bool hasValenceGreaterThan(const std::vector<size_t>& numberOfNodesPerSlot,
|
||||||
const size_t &valenceThreshold);
|
const size_t& valenceThreshold);
|
||||||
std::vector<vcg::Point3d> computeVertices() const;
|
std::vector<vcg::Point3d> computeVertices() const;
|
||||||
static PatternGeometry createFan(PatternGeometry &pattern);
|
static PatternGeometry createFan(PatternGeometry& pattern);
|
||||||
static PatternGeometry createTile(PatternGeometry &pattern);
|
static PatternGeometry createTile(PatternGeometry& pattern);
|
||||||
double getTriangleEdgeSize() const;
|
double getTriangleEdgeSize() const;
|
||||||
bool hasUntiledDanglingEdges();
|
bool hasUntiledDanglingEdges();
|
||||||
std::unordered_map<size_t, std::unordered_set<size_t>> getIntersectingEdges(
|
std::unordered_map<size_t, std::unordered_set<size_t>> getIntersectingEdges(
|
||||||
size_t &numberOfIntersectingEdgePairs) const;
|
size_t& numberOfIntersectingEdgePairs) const;
|
||||||
|
|
||||||
static size_t binomialCoefficient(size_t n, size_t m)
|
static size_t binomialCoefficient(size_t n, size_t m) {
|
||||||
{
|
assert(n >= m);
|
||||||
assert(n >= m);
|
return tgamma(n + 1) / (tgamma(m + 1) * tgamma(n - m + 1));
|
||||||
return tgamma(n + 1) / (tgamma(m + 1) * tgamma(n - m + 1));
|
|
||||||
}
|
}
|
||||||
bool isFullyConnectedWhenFanned();
|
bool isFullyConnectedWhenFanned();
|
||||||
|
|
||||||
bool hasIntersectingEdges(
|
bool hasIntersectingEdges(
|
||||||
const std::string &patternBinaryRepresentation,
|
const std::string& patternBinaryRepresentation,
|
||||||
const std::unordered_map<size_t, std::unordered_set<size_t>>
|
const std::unordered_map<size_t, std::unordered_set<size_t>>&
|
||||||
&intersectingEdges);
|
intersectingEdges);
|
||||||
bool isPatternValid();
|
bool isPatternValid();
|
||||||
size_t getFanSize() const;
|
size_t getFanSize() const;
|
||||||
void add(const std::vector<vcg::Point2d> &vertices,
|
void add(const std::vector<vcg::Point2d>& vertices,
|
||||||
const std::vector<vcg::Point2i> &edges);
|
const std::vector<vcg::Point2i>& edges);
|
||||||
|
|
||||||
PatternGeometry(const std::vector<size_t> &numberOfNodesPerSlot,
|
PatternGeometry(const std::vector<size_t>& numberOfNodesPerSlot,
|
||||||
const std::vector<vcg::Point2i> &edges);
|
const std::vector<vcg::Point2i>& edges);
|
||||||
PatternGeometry(const std::filesystem::path &patternFilePath, bool addNormalsIfAbsent = true);
|
PatternGeometry(const std::filesystem::path& patternFilePath,
|
||||||
|
bool addNormalsIfAbsent = true);
|
||||||
|
|
||||||
bool createHoneycombAtom();
|
bool createHoneycombAtom();
|
||||||
void copy(PatternGeometry ©From);
|
void copy(PatternGeometry& copyFrom);
|
||||||
|
|
||||||
void tilePattern(VCGEdgeMesh &pattern,
|
void tilePattern(VCGEdgeMesh& pattern,
|
||||||
VCGPolyMesh &tileInto,
|
VCGPolyMesh& tileInto,
|
||||||
const int &interfaceNodeIndex,
|
const int& interfaceNodeIndex,
|
||||||
const bool &shouldDeleteDanglingEdges);
|
const bool& shouldDeleteDanglingEdges);
|
||||||
|
|
||||||
void scale(const double &desiredBaseTriangleCentralEdgeSize);
|
void scale(const double& desiredBaseTriangleCentralEdgeSize);
|
||||||
|
|
||||||
double getBaseTriangleHeight() const;
|
double getBaseTriangleHeight() const;
|
||||||
vcg::Triangle3<double> computeBaseTriangle() const;
|
vcg::Triangle3<double> computeBaseTriangle() const;
|
||||||
|
|
@ -102,35 +105,44 @@ private:
|
||||||
double computeBaseTriangleHeight() const;
|
double computeBaseTriangleHeight() const;
|
||||||
void updateBaseTriangleHeight();
|
void updateBaseTriangleHeight();
|
||||||
|
|
||||||
// PatternGeometry(const std::vector<vcg::Point2d> &vertices, const std::vector<vcg::Point2i> &edges);
|
// PatternGeometry(const std::vector<vcg::Point2d> &vertices, const
|
||||||
// static std::shared_ptr<PatternGeometry> tilePattern(
|
// std::vector<vcg::Point2i> &edges); static std::shared_ptr<PatternGeometry>
|
||||||
|
// tilePattern(
|
||||||
// std::vector<PatternGeometry> &pattern,
|
// std::vector<PatternGeometry> &pattern,
|
||||||
// const std::vector<int> &connectToNeighborsVi,
|
// const std::vector<int> &connectToNeighborsVi,
|
||||||
// const VCGPolyMesh &tileInto,
|
// const VCGPolyMesh &tileInto,
|
||||||
// std::vector<int> &tileIntoEdgesToTiledVi,
|
// std::vector<int> &tileIntoEdgesToTiledVi,
|
||||||
// std::vector<std::vector<size_t>> &perPatternEdges);
|
// std::vector<std::vector<size_t>> &perPatternEdges);
|
||||||
virtual void createFan(/*const std::vector<int> &connectToNeighborsVi = std::vector<int>(),*/
|
virtual void createFan(/*const std::vector<int> &connectToNeighborsVi =
|
||||||
const size_t &fanSize = 6);
|
std::vector<int>(),*/
|
||||||
int interfaceNodeIndex{3}; //TODO: Fix this. This should be automatically computed
|
const size_t& fanSize = 6);
|
||||||
bool hasAngleSmallerThanThreshold(const std::vector<size_t> &numberOfNodesPerSlot,
|
int interfaceNodeIndex{
|
||||||
const double &angleThreshold_degrees);
|
3}; // TODO: Fix this. This should be automatically computed
|
||||||
|
bool hasAngleSmallerThanThreshold(
|
||||||
|
const std::vector<size_t>& numberOfNodesPerSlot,
|
||||||
|
const double& angleThreshold_degrees,
|
||||||
|
const bool shouldBreak = false);
|
||||||
vcg::Triangle3<double> getBaseTriangle() const;
|
vcg::Triangle3<double> getBaseTriangle() const;
|
||||||
static std::shared_ptr<PatternGeometry> tilePattern(PatternGeometry &pattern,
|
|
||||||
const std::vector<int> &connectToNeighborsVi,
|
|
||||||
const VCGPolyMesh &tileInto,
|
|
||||||
std::vector<int> &tileIntoEdgesToTiledVi);
|
|
||||||
static std::shared_ptr<PatternGeometry> tilePattern(
|
static std::shared_ptr<PatternGeometry> tilePattern(
|
||||||
std::vector<ConstPatternGeometry> &patterns,
|
PatternGeometry& pattern,
|
||||||
const std::vector<int> &connectToNeighborsVi,
|
const std::vector<int>& connectToNeighborsVi,
|
||||||
const VCGPolyMesh &tileInto,
|
const VCGPolyMesh& tileInto,
|
||||||
const std::vector<int> &perSurfaceFacePatternIndices,
|
std::vector<int>& tileIntoEdgesToTiledVi);
|
||||||
std::vector<size_t> &tileIntoEdgesToTiledVi,
|
static std::shared_ptr<PatternGeometry> tilePattern(
|
||||||
std::vector<std::vector<size_t>> &perPatternIndexTiledPatternEdgeIndex);
|
std::vector<ConstPatternGeometry>& patterns,
|
||||||
std::unordered_set<VertexIndex> getInterfaceNodes(const std::vector<size_t> &numberOfNodesPerSlot);
|
const std::vector<int>& connectToNeighborsVi,
|
||||||
bool isInterfaceConnected(const std::unordered_set<VertexIndex> &interfaceNodes);
|
const VCGPolyMesh& tileInto,
|
||||||
|
const std::vector<int>& perSurfaceFacePatternIndices,
|
||||||
|
std::vector<size_t>& tileIntoEdgesToTiledVi,
|
||||||
|
std::vector<std::vector<size_t>>& perPatternIndexTiledPatternEdgeIndex);
|
||||||
|
std::unordered_set<VertexIndex> getInterfaceNodes(
|
||||||
|
const std::vector<size_t>& numberOfNodesPerSlot);
|
||||||
|
bool isInterfaceConnected(
|
||||||
|
const std::unordered_set<VertexIndex>& interfaceNodes);
|
||||||
void deleteDanglingVertices() override;
|
void deleteDanglingVertices() override;
|
||||||
void deleteDanglingVertices(
|
void deleteDanglingVertices(
|
||||||
vcg::tri::Allocator<VCGEdgeMesh>::PointerUpdater<VertexPointer> &pu) override;
|
vcg::tri::Allocator<VCGEdgeMesh>::PointerUpdater<VertexPointer>& pu)
|
||||||
|
override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLATPATTERNGEOMETRY_HPP
|
#endif // FLATPATTERNGEOMETRY_HPP
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,7 @@ bool VCGTriMesh::save(const std::string plyFilename)
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
|
|
||||||
polyscope::SurfaceMesh *VCGTriMesh::registerForDrawing(
|
polyscope::SurfaceMesh *VCGTriMesh::registerForDrawing(const std::optional<std::array<float, 3> > &desiredColor, const bool &shouldEnable) const
|
||||||
const std::optional<std::array<double, 3>> &desiredColor, const bool &shouldEnable) const
|
|
||||||
{
|
{
|
||||||
auto vertices = getVertices();
|
auto vertices = getVertices();
|
||||||
auto faces = getFaces();
|
auto faces = getFaces();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef VCGTRIMESH_HPP
|
#ifndef VCGTRIMESH_HPP
|
||||||
#define VCGTRIMESH_HPP
|
#define VCGTRIMESH_HPP
|
||||||
#include "mesh.hpp"
|
|
||||||
#include <vcg/complex/complex.h>
|
#include <vcg/complex/complex.h>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include "mesh.hpp"
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
#include <polyscope/surface_mesh.h>
|
#include <polyscope/surface_mesh.h>
|
||||||
|
|
@ -22,40 +22,42 @@ class VCGTriMeshVertex : public vcg::Vertex<VCGTriMeshUsedTypes,
|
||||||
vcg::vertex::Color4b,
|
vcg::vertex::Color4b,
|
||||||
vcg::vertex::VFAdj,
|
vcg::vertex::VFAdj,
|
||||||
vcg::vertex::Qualityd,
|
vcg::vertex::Qualityd,
|
||||||
vcg::vertex::VEAdj>
|
vcg::vertex::VEAdj> {};
|
||||||
{};
|
class VCGTriMeshFace : public vcg::Face<VCGTriMeshUsedTypes,
|
||||||
class VCGTriMeshFace
|
vcg::face::FFAdj,
|
||||||
: public vcg::Face<VCGTriMeshUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj,
|
vcg::face::VFAdj,
|
||||||
vcg::face::VertexRef, vcg::face::BitFlags,
|
vcg::face::VertexRef,
|
||||||
vcg::face::Normal3d> {};
|
vcg::face::BitFlags,
|
||||||
class VCGTriMeshEdge : public vcg::Edge<VCGTriMeshUsedTypes, vcg::edge::VertexRef, vcg::edge::VEAdj>
|
vcg::face::Normal3d> {};
|
||||||
{};
|
class VCGTriMeshEdge : public vcg::Edge<VCGTriMeshUsedTypes,
|
||||||
|
vcg::edge::VertexRef,
|
||||||
|
vcg::edge::VEAdj> {};
|
||||||
|
|
||||||
class VCGTriMesh : public vcg::tri::TriMesh<std::vector<VCGTriMeshVertex>,
|
class VCGTriMesh : public vcg::tri::TriMesh<std::vector<VCGTriMeshVertex>,
|
||||||
std::vector<VCGTriMeshFace>,
|
std::vector<VCGTriMeshFace>,
|
||||||
std::vector<VCGTriMeshEdge>>,
|
std::vector<VCGTriMeshEdge>>,
|
||||||
public Mesh
|
public Mesh {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
VCGTriMesh();
|
VCGTriMesh();
|
||||||
VCGTriMesh(const std::string &filename);
|
VCGTriMesh(const std::string& filename);
|
||||||
bool load(const std::filesystem::path &meshFilePath) override;
|
bool load(const std::filesystem::path& meshFilePath) override;
|
||||||
bool load(std::istringstream &offInputStream);
|
bool load(std::istringstream& offInputStream);
|
||||||
Eigen::MatrixX3d getVertices() const;
|
Eigen::MatrixX3d getVertices() const;
|
||||||
Eigen::MatrixX3i getFaces() const;
|
Eigen::MatrixX3i getFaces() const;
|
||||||
bool save(const std::string plyFilename);
|
bool save(const std::string plyFilename);
|
||||||
template <typename MeshElement> size_t getIndex(const MeshElement &element) {
|
template <typename MeshElement>
|
||||||
|
size_t getIndex(const MeshElement& element) {
|
||||||
return vcg::tri::Index<VCGTriMesh>(*this, element);
|
return vcg::tri::Index<VCGTriMesh>(*this, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef POLYSCOPE_DEFINED
|
#ifdef POLYSCOPE_DEFINED
|
||||||
polyscope::SurfaceMesh *registerForDrawing(
|
polyscope::SurfaceMesh* registerForDrawing(
|
||||||
const std::optional<std::array<double, 3>> &desiredColor = std::nullopt,
|
const std::optional<std::array<float, 3>>& desiredColor = std::nullopt,
|
||||||
const bool &shouldEnable = true) const;
|
const bool& shouldEnable = true) const;
|
||||||
#endif
|
#endif
|
||||||
Eigen::MatrixX2i getEdges() const;
|
Eigen::MatrixX2i getEdges() const;
|
||||||
void updateEigenEdgeAndVertices();
|
void updateEigenEdgeAndVertices();
|
||||||
void moveToCenter();
|
void moveToCenter();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VCGTRIMESH_HPP
|
#endif // VCGTRIMESH_HPP
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue