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)
|
||||
|
||||
## polyscope
|
||||
#if(NOT TARGET polyscope AND ${USE_POLYSCOPE})
|
||||
if(#[[NOT TARGET polyscope AND]] ${USE_POLYSCOPE})
|
||||
message("Using polyscope")
|
||||
FetchContent_Declare(polyscope
|
||||
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git
|
||||
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_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)
|
||||
#endif()
|
||||
endif()
|
||||
#if(NOT TARGET polyscope AND ${USE_POLYSCOPE})
|
||||
# set(POLYSCOPE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/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)
|
||||
add_compile_definitions(ARMA_DONT_USE_WRAPPER)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC "/home/iason/Coding/Libraries/armadillo/build/libarmadillo.a" #[[blas lapack]])
|
||||
find_package(Armadillo REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${ARMADILLO_LIBRARIES})
|
||||
#find_package(Armadillo REQUIRED)
|
||||
#target_link_libraries(${PROJECT_NAME} PUBLIC ${ARMADILLO_LIBRARIES})
|
||||
|
||||
#if(NOT TARGET ThreedBeamFEA)
|
||||
#FetchContent_Declare(armadillo
|
||||
# GIT_REPOSITORY https://gitlab.com/conradsnicta/armadillo-code.git
|
||||
|
@ -203,7 +205,7 @@ add_compile_definitions(USE_ENSMALLEN)
|
|||
# LINK_FLAGS "${CHRONO_LINKER_FLAGS}")
|
||||
#include_directories(${CHRONO_INCLUDE_DIRS})
|
||||
#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_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")
|
||||
|
@ -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)
|
||||
# add_subdirectory(${TBB_SOURCE_DIR} ${TBB_BINARY_DIR})
|
||||
#link_directories(${TBB_BINARY_DIR})
|
||||
message("Using tbb")
|
||||
FetchContent_Declare(tbb
|
||||
GIT_REPOSITORY https://github.com/wjakob/tbb.git
|
||||
GIT_TAG master
|
||||
)
|
||||
FetchContent_MakeAvailable(tbb)
|
||||
# target_link_libraries(${PROJECT_NAME} PRIVATE tbb_static)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE tbb)
|
||||
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(
|
||||
const std::shared_ptr<const SimulationJob>& pJob,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||
|
@ -120,30 +147,17 @@ void ChronosEulerSimulationModel::parseConstrainedVertices(
|
|||
auto truss = chrono_types::make_shared<ChBody>();
|
||||
truss->SetBodyFixed(true);
|
||||
my_system.Add(truss);
|
||||
const auto& constrainedChronoNode =
|
||||
const std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>& constrainedChronoNode =
|
||||
edgeMeshVertsToChronoNodes[constrainedVi];
|
||||
// Create a constraint at the end of the beam
|
||||
auto constr_a = chrono_types::make_shared<ChLinkMateGeneric>();
|
||||
constr_a->SetConstrainedCoords(
|
||||
auto constraint = chrono_types::make_shared<ChLinkMateGeneric>();
|
||||
constraint->SetConstrainedCoords(
|
||||
constrainedDoF.contains(0), constrainedDoF.contains(1),
|
||||
constrainedDoF.contains(2), constrainedDoF.contains(3),
|
||||
constrainedDoF.contains(4), constrainedDoF.contains(5));
|
||||
constr_a->Initialize(constrainedChronoNode, truss, false,
|
||||
constrainedChronoNode->Frame(),
|
||||
constrainedChronoNode->Frame());
|
||||
// const auto frameNode = constrainedChronoNode->Frame();
|
||||
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;
|
||||
// }
|
||||
constraint->Initialize(constrainedChronoNode, truss, false,
|
||||
constrainedChronoNode->Frame(),
|
||||
constrainedChronoNode->Frame());
|
||||
my_system.Add(constraint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,6 +191,7 @@ SimulationResults ChronosEulerSimulationModel::executeSimulation(
|
|||
// -1));
|
||||
// my_system.SetTimestepperType(chrono::ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED);
|
||||
// parse forces
|
||||
parseForcedDisplacements(pJob, edgeMeshVertsToChronoNodes, my_system);
|
||||
parseForces(mesh_chronos, edgeMeshVertsToChronoNodes,
|
||||
pJob->nodalExternalForces);
|
||||
// parse constrained vertices
|
||||
|
@ -198,20 +213,29 @@ SimulationResults ChronosEulerSimulationModel::executeSimulation(
|
|||
|
||||
auto solver = chrono_types::make_shared<ChSolverMINRES>();
|
||||
my_system.SetSolver(solver);
|
||||
// solver->SetMaxIterations(1e5);
|
||||
// solver->SetTolerance(1e-12);
|
||||
solver->SetMaxIterations(1e5);
|
||||
solver->EnableWarmStart(
|
||||
true); // IMPORTANT for convergence when using EULER_IMPLICIT_LINEARIZED
|
||||
solver->EnableDiagonalPreconditioner(true);
|
||||
my_system.SetSolverForceTolerance(1e-9);
|
||||
solver->SetVerbose(false);
|
||||
// solver->SetTolerance(1e-15);
|
||||
my_system.SetSolverForceTolerance(1e-15);
|
||||
|
||||
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) {
|
||||
simulationResults.converged = my_system.DoStaticLinear();
|
||||
// simulationResults.converged = my_system.DoStaticRelaxing();
|
||||
} else {
|
||||
simulationResults.converged = my_system.DoStaticNonlinear();
|
||||
// simulationResults.converged = my_system.DoStaticRelaxing();
|
||||
}
|
||||
//#endif
|
||||
if (!simulationResults.converged) {
|
||||
std::cerr << "Simulation failed" << std::endl;
|
||||
assert(false);
|
||||
|
|
|
@ -8,39 +8,48 @@ class ChSystemSMC;
|
|||
namespace fea {
|
||||
class ChMesh;
|
||||
class ChNodeFEAxyzrot;
|
||||
} // namespace fea
|
||||
} // namespace chrono
|
||||
} // namespace fea
|
||||
} // namespace chrono
|
||||
|
||||
class ChronosEulerSimulationModel : public SimulationModel
|
||||
{
|
||||
std::shared_ptr<chrono::fea::ChMesh> mesh_chronos;
|
||||
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> edgeMeshVertsToChronoNodes;
|
||||
class ChronosEulerSimulationModel : public SimulationModel {
|
||||
std::shared_ptr<chrono::fea::ChMesh> mesh_chronos;
|
||||
std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>
|
||||
edgeMeshVertsToChronoNodes;
|
||||
|
||||
static void parseConstrainedVertices(
|
||||
const std::shared_ptr<const SimulationJob> &pJob,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> &edgeMeshVertsToChronoNodes,
|
||||
chrono::ChSystemSMC &my_system);
|
||||
static void parseForces(
|
||||
const std::shared_ptr<chrono::fea::ChMesh> &mesh_chronos,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>> &edgeMeshVertsToChronoNodes,
|
||||
const std::unordered_map<VertexIndex, Vector6d> &nodalExternalForces);
|
||||
static void parseConstrainedVertices(
|
||||
const std::shared_ptr<const SimulationJob>& pJob,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||
edgeMeshVertsToChronoNodes,
|
||||
chrono::ChSystemSMC& my_system);
|
||||
static void parseForces(
|
||||
const std::shared_ptr<chrono::fea::ChMesh>& mesh_chronos,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||
edgeMeshVertsToChronoNodes,
|
||||
const std::unordered_map<VertexIndex, Vector6d>& nodalExternalForces);
|
||||
|
||||
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);
|
||||
static void parseForcedDisplacements(
|
||||
const std::shared_ptr<const SimulationJob>& pJob,
|
||||
const std::vector<std::shared_ptr<chrono::fea::ChNodeFEAxyzrot>>&
|
||||
edgeMeshVertsToChronoNodes,
|
||||
chrono::ChSystemSMC& my_system);
|
||||
|
||||
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
|
||||
{
|
||||
enum AnalysisType { Linear = 0, NonLinear };
|
||||
AnalysisType analysisType{NonLinear};
|
||||
};
|
||||
Settings settings;
|
||||
inline const static std::string label{"Chronos_Euler"};
|
||||
|
||||
struct Settings {
|
||||
enum AnalysisType { Linear = 0, NonLinear };
|
||||
AnalysisType analysisType{NonLinear};
|
||||
};
|
||||
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
|
||||
|
||||
#include "reducedmodeloptimizer_structs.hpp"
|
||||
#include "utilities.hpp"
|
||||
|
||||
class ReducedModelEvaluator
|
||||
{
|
||||
public:
|
||||
enum CSVExportingDirection { Vertical = 0, Horizontal };
|
||||
enum CSVExportingData {
|
||||
raw_drm2Reduced = 0,
|
||||
norm_drm2Reduced,
|
||||
raw_and_norm_drm2Reduced,
|
||||
NumberOfDataTypes
|
||||
};
|
||||
inline static std::array<std::string, NumberOfDataTypes>
|
||||
csvExportingDataStrings{"raw_drm2Reduced", "norm_drm2Reduced", "raw_and_norm_drm2Reduced"};
|
||||
struct Settings
|
||||
{
|
||||
CSVExportingDirection exportingDirection{Horizontal};
|
||||
CSVExportingData exportingData{norm_drm2Reduced};
|
||||
bool shouldWriteHeader{true};
|
||||
std::string resultsLabel;
|
||||
};
|
||||
class ReducedModelEvaluator {
|
||||
public:
|
||||
enum CSVExportingDirection { Vertical = 0, Horizontal };
|
||||
enum CSVExportingData {
|
||||
raw_drm2Reduced = 0,
|
||||
norm_drm2Reduced,
|
||||
raw_and_norm_drm2Reduced,
|
||||
NumberOfDataTypes
|
||||
};
|
||||
inline static std::array<std::string, NumberOfDataTypes>
|
||||
csvExportingDataStrings{"raw_drm2Reduced", "norm_drm2Reduced",
|
||||
"raw_and_norm_drm2Reduced"};
|
||||
struct Settings {
|
||||
CSVExportingDirection exportingDirection{Horizontal};
|
||||
CSVExportingData exportingData{norm_drm2Reduced};
|
||||
bool shouldWriteHeader{true};
|
||||
std::string resultsLabel;
|
||||
};
|
||||
|
||||
inline static constexpr int NumberOfEvaluationScenarios{22};
|
||||
struct Results
|
||||
{
|
||||
std::array<double, NumberOfEvaluationScenarios> distances_drm2reduced;
|
||||
std::array<double, NumberOfEvaluationScenarios> distances_normalizedDrm2reduced;
|
||||
std::array<std::string, NumberOfEvaluationScenarios> evaluationScenarioLabels;
|
||||
};
|
||||
ReducedModelEvaluator();
|
||||
Results evaluateReducedModel(
|
||||
ReducedModelOptimization::Results &optimizationResult,
|
||||
const std::filesystem::path &scenariosDirectoryPath,
|
||||
// const std::filesystem::path &reducedPatternFilePath,
|
||||
const std::filesystem::path &fullPatternTessellatedResultsDirectoryPath);
|
||||
Results evaluateReducedModel(ReducedModelOptimization::Results &optimizationResult);
|
||||
static void printResultsVertically(const ReducedModelEvaluator::Results &evaluationResults,
|
||||
csvFile &csvOutput);
|
||||
static void printResults(const ReducedModelEvaluator::Results &evaluationResults,
|
||||
const std::string &resultsLabel);
|
||||
inline static constexpr int NumberOfEvaluationScenarios{22};
|
||||
struct Results {
|
||||
std::array<double, NumberOfEvaluationScenarios> distances_drm2reduced;
|
||||
std::array<double, NumberOfEvaluationScenarios>
|
||||
distances_normalizedDrm2reduced;
|
||||
std::array<std::string, NumberOfEvaluationScenarios>
|
||||
evaluationScenarioLabels;
|
||||
};
|
||||
ReducedModelEvaluator();
|
||||
Results evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult,
|
||||
const std::filesystem::path& scenariosDirectoryPath,
|
||||
// const std::filesystem::path &reducedPatternFilePath,
|
||||
const std::filesystem::path& fullPatternTessellatedResultsDirectoryPath);
|
||||
Results evaluateReducedModel(
|
||||
ReducedModelOptimization::Results& optimizationResult);
|
||||
static void printResultsVertically(
|
||||
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{
|
||||
"22Hex_randomBending0",
|
||||
"22Hex_randomBending1",
|
||||
"22Hex_randomBending2",
|
||||
// "22Hex_randomBending3",
|
||||
"22Hex_randomBending4",
|
||||
"22Hex_randomBending5",
|
||||
// "22Hex_randomBending6",
|
||||
// "22Hex_randomBending7",
|
||||
"22Hex_randomBending8",
|
||||
"22Hex_randomBending9",
|
||||
"22Hex_randomBending10",
|
||||
"22Hex_randomBending11",
|
||||
"22Hex_randomBending12",
|
||||
// "22Hex_randomBending13",
|
||||
// "22Hex_randomBending14",
|
||||
// "22Hex_randomBending15",
|
||||
"22Hex_randomBending16",
|
||||
"22Hex_randomBending17",
|
||||
"22Hex_randomBending18",
|
||||
"22Hex_randomBending19",
|
||||
// "22Hex_randomBending20",
|
||||
"22Hex_bending_0.005N",
|
||||
"22Hex_bending_0.01N",
|
||||
"22Hex_bending_0.03N",
|
||||
// "22Hex_bending_0.05N",
|
||||
"22Hex_pullOppositeVerts_0.05N",
|
||||
"22Hex_pullOppositeVerts_0.1N",
|
||||
// "22Hex_pullOppositeVerts_0.3N",
|
||||
//#ifdef POLYSCOPE_DEFINED
|
||||
// "22Hex_shear_2N",
|
||||
// "22Hex_shear_5N",
|
||||
// "22Hex_axial_10N",
|
||||
// "22Hex_axial_20N",
|
||||
//#else
|
||||
// "notUsed_22Hex_shear_2N",
|
||||
// "notUsed_22Hex_shear_5N",
|
||||
// "notUsed_22Hex_axial_10N",
|
||||
// "notUsed_22Hex_axial_20N",
|
||||
//#endif
|
||||
"22Hex_cylinder_0.05N",
|
||||
"22Hex_cylinder_0.1N",
|
||||
"22Hex_s_0.05N",
|
||||
// "22Hex_s_0.1N"
|
||||
};
|
||||
static void printResultsHorizontally(const Results &evaluationResults, csvFile &csvOutput);
|
||||
static void printResults(const Results &evaluationResults,
|
||||
const Settings &settings,
|
||||
csvFile &csvOutput);
|
||||
static void printHeader(const Settings &settings, csvFile &csvOutput);
|
||||
// static double evaluateOptimizationSettings(
|
||||
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||
// std::vector<ReducedModelEvaluator::Results> &patternEvaluationResults);
|
||||
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
||||
inline static constexpr char *tileIntoSurfaceFileContent = R"~(OFF
|
||||
inline static std::array<std::string, NumberOfEvaluationScenarios>
|
||||
scenariosTestSetLabels{
|
||||
"22Hex_randomBending0", "22Hex_randomBending1",
|
||||
"22Hex_randomBending2",
|
||||
// "22Hex_randomBending3",
|
||||
"22Hex_randomBending4", "22Hex_randomBending5",
|
||||
// "22Hex_randomBending6",
|
||||
// "22Hex_randomBending7",
|
||||
"22Hex_randomBending8", "22Hex_randomBending9",
|
||||
"22Hex_randomBending10", "22Hex_randomBending11",
|
||||
"22Hex_randomBending12",
|
||||
// "22Hex_randomBending13",
|
||||
// "22Hex_randomBending14",
|
||||
// "22Hex_randomBending15",
|
||||
"22Hex_randomBending16", "22Hex_randomBending17",
|
||||
"22Hex_randomBending18", "22Hex_randomBending19",
|
||||
// "22Hex_randomBending20",
|
||||
"22Hex_bending_0.005N", "22Hex_bending_0.01N", "22Hex_bending_0.03N",
|
||||
// "22Hex_bending_0.05N",
|
||||
"22Hex_pullOppositeVerts_0.05N", "22Hex_pullOppositeVerts_0.1N",
|
||||
// "22Hex_pullOppositeVerts_0.3N",
|
||||
//#ifdef POLYSCOPE_DEFINED
|
||||
// "22Hex_shear_2N",
|
||||
// "22Hex_shear_5N",
|
||||
// "22Hex_axial_10N",
|
||||
// "22Hex_axial_20N",
|
||||
//#else
|
||||
// "notUsed_22Hex_shear_2N",
|
||||
// "notUsed_22Hex_shear_5N",
|
||||
// "notUsed_22Hex_axial_10N",
|
||||
// "notUsed_22Hex_axial_20N",
|
||||
//#endif
|
||||
"22Hex_cylinder_0.05N", "22Hex_cylinder_0.1N", "22Hex_s_0.05N",
|
||||
// "22Hex_s_0.1N"
|
||||
};
|
||||
static void printResultsHorizontally(const Results& evaluationResults,
|
||||
csvFile& csvOutput);
|
||||
static void printResults(const Results& evaluationResults,
|
||||
const Settings& settings,
|
||||
csvFile& csvOutput);
|
||||
static void printHeader(const Settings& settings, csvFile& csvOutput);
|
||||
// static double evaluateOptimizationSettings(
|
||||
// const ReducedModelOptimization::Settings &optimizationSettings,
|
||||
// const std::vector<std::shared_ptr<PatternGeometry>> &pPatterns,
|
||||
// std::vector<ReducedModelEvaluator::Results>
|
||||
// &patternEvaluationResults);
|
||||
std::shared_ptr<VCGPolyMesh> pTileIntoSurface;
|
||||
ReducedModelOptimization::Colors::RGBColor color_tesselatedPatterns{
|
||||
24.0 / 255, 23.0 / 255, 23.0 / 255};
|
||||
ReducedModelOptimization::Colors::RGBColor color_tesselatedReducedModels{
|
||||
67.0 / 255, 160.00 / 255, 232.0 / 255};
|
||||
ReducedModelOptimization::Colors::RGBColor color_tileIntoSurface{
|
||||
222 / 255.0, 235 / 255.0, 255 / 255.0};
|
||||
ReducedModelOptimization::Colors::RGBColor interfaceNodes_color{
|
||||
63.0 / 255, 85.0 / 255, 42.0 / 255};
|
||||
inline static constexpr char* tileIntoSurfaceFileContent = R"~(OFF
|
||||
46 66 0
|
||||
-0.0745923 0.03573945 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
|
||||
#define REDUCEDMODELOPTIMIZER_HPP
|
||||
|
||||
#include "chronoseulersimulationmodel.hpp"
|
||||
#include "csvfile.hpp"
|
||||
//#include "csvfile.hpp"
|
||||
#include "drmsimulationmodel.hpp"
|
||||
#include "edgemesh.hpp"
|
||||
#include "linearsimulationmodel.hpp"
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#include "matplot/matplot.h"
|
||||
#endif
|
||||
#include <Eigen/Dense>
|
||||
#include "reducedmodel.hpp"
|
||||
#include "reducedmodeloptimizer_structs.hpp"
|
||||
#include "simulationmesh.hpp"
|
||||
#include <Eigen/Dense>
|
||||
#ifdef DLIB_DEFINED
|
||||
#include <dlib/global_optimization.h>
|
||||
#include <dlib/optimization.h>
|
||||
|
@ -20,348 +19,384 @@
|
|||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#include "polyscope/color_management.h"
|
||||
#endif // POLYSCOPE_DEFINED
|
||||
using FullPatternVertexIndex = VertexIndex;
|
||||
using ReducedPatternVertexIndex = VertexIndex;
|
||||
#endif // POLYSCOPE_DEFINED
|
||||
using PatternVertexIndex = VertexIndex;
|
||||
using ReducedModelVertexIndex = VertexIndex;
|
||||
|
||||
class ReducedModelOptimizer
|
||||
{
|
||||
public:
|
||||
struct OptimizationState
|
||||
{
|
||||
std::vector<SimulationResults> fullPatternResults;
|
||||
std::vector<double> translationalDisplacementNormalizationValues;
|
||||
std::vector<double> rotationalDisplacementNormalizationValues;
|
||||
std::vector<std::shared_ptr<SimulationJob>> fullPatternSimulationJobs;
|
||||
std::vector<std::shared_ptr<SimulationJob>> reducedPatternSimulationJobs;
|
||||
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
reducedToFullInterfaceViMap;
|
||||
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
fullPatternOppositeInterfaceViPairs;
|
||||
matplot::line_handle gPlotHandle;
|
||||
std::vector<size_t> objectiveValueHistory_iteration;
|
||||
std::vector<double> objectiveValueHistory;
|
||||
std::vector<double> plotColors;
|
||||
std::array<double,
|
||||
ReducedModelOptimization::OptimizationParameterIndex::NumberOfOptimizationVariables>
|
||||
parametersInitialValue;
|
||||
std::array<double,
|
||||
ReducedModelOptimization::OptimizationParameterIndex::NumberOfOptimizationVariables>
|
||||
optimizationInitialValue;
|
||||
std::vector<int> simulationScenarioIndices;
|
||||
double minY{DBL_MAX};
|
||||
std::vector<double> minX;
|
||||
int numOfSimulationCrashes{false};
|
||||
int numberOfFunctionCalls{0};
|
||||
//Variables for finding the full pattern simulation forces
|
||||
std::shared_ptr<SimulationMesh> pFullPatternSimulationMesh;
|
||||
std::array<std::function<void(const double &newValue,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>,
|
||||
7>
|
||||
functions_updateReducedPatternParameter;
|
||||
std::vector<double> xMin;
|
||||
std::vector<double> xMax;
|
||||
std::vector<double> scenarioWeights;
|
||||
std::vector<ReducedModelOptimization::Settings::ObjectiveWeights> objectiveWeights;
|
||||
};
|
||||
class ReducedModelOptimizer {
|
||||
public:
|
||||
struct OptimizationState {
|
||||
std::vector<SimulationResults> fullPatternResults;
|
||||
std::vector<double> translationalDisplacementNormalizationValues;
|
||||
std::vector<double> rotationalDisplacementNormalizationValues;
|
||||
std::vector<std::shared_ptr<SimulationJob>> pSimulationJobs_pattern;
|
||||
std::vector<std::shared_ptr<SimulationJob>> simulationJobs_reducedModel;
|
||||
std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>
|
||||
reducedToFullInterfaceViMap;
|
||||
std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>
|
||||
fullPatternOppositeInterfaceViPairs;
|
||||
matplot::line_handle gPlotHandle;
|
||||
std::vector<size_t> objectiveValueHistory_iteration;
|
||||
std::vector<double> objectiveValueHistory;
|
||||
std::vector<double> plotColors;
|
||||
std::array<double,
|
||||
ReducedModelOptimization::OptimizationParameterIndex::
|
||||
NumberOfOptimizationVariables>
|
||||
parametersInitialValue;
|
||||
std::array<double,
|
||||
ReducedModelOptimization::OptimizationParameterIndex::
|
||||
NumberOfOptimizationVariables>
|
||||
optimizationInitialValue;
|
||||
std::vector<int> simulationScenarioIndices;
|
||||
double minY{DBL_MAX};
|
||||
std::vector<double> minX;
|
||||
int numOfSimulationCrashes{false};
|
||||
int numberOfFunctionCalls{0};
|
||||
// Variables for finding the full pattern simulation forces
|
||||
std::shared_ptr<SimulationEdgeMesh> pFullPatternSimulationEdgeMesh;
|
||||
std::array<std::function<void(const double& newValue,
|
||||
std::shared_ptr<SimulationEdgeMesh>&
|
||||
pReducedPatternSimulationEdgeMesh)>,
|
||||
7>
|
||||
functions_updateReducedPatternParameter;
|
||||
std::vector<double> xMin;
|
||||
std::vector<double> xMax;
|
||||
std::vector<double> scenarioWeights;
|
||||
std::vector<ReducedModelOptimization::Settings::ObjectiveWeights>
|
||||
objectiveWeights;
|
||||
std::string simulationModelLabel_reducedModel;
|
||||
};
|
||||
|
||||
private:
|
||||
OptimizationState optimizationState;
|
||||
vcg::Triangle3<double> baseTriangle;
|
||||
std::function<void(const double &,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>> &,
|
||||
SimulationJob &)>
|
||||
constructScenarioFunction;
|
||||
std::shared_ptr<SimulationMesh> m_pReducedModelSimulationMesh;
|
||||
std::shared_ptr<SimulationMesh> m_pFullPatternSimulationMesh;
|
||||
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
||||
m_fullToReducedInterfaceViMap;
|
||||
std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
m_fullPatternOppositeInterfaceViPairs;
|
||||
std::unordered_map<size_t, size_t> nodeToSlot;
|
||||
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
||||
std::string optimizationNotes;
|
||||
std::array<std::function<void(
|
||||
const double &,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>> &,
|
||||
SimulationJob &)>,
|
||||
ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
constructBaseScenarioFunctions;
|
||||
std::vector<bool> scenarioIsSymmetrical;
|
||||
int fullPatternNumberOfEdges;
|
||||
constexpr static double youngsModulus{1 * 1e9};
|
||||
constexpr static double defaultBeamWidth{0.002};
|
||||
constexpr static double defaultBeamHeight{0.002};
|
||||
std::string fullPatternLabel;
|
||||
// ReducedModelOptimization::Settings optimizationSettings;
|
||||
private:
|
||||
OptimizationState optimizationState;
|
||||
vcg::Triangle3<double> baseTriangle;
|
||||
std::function<void(
|
||||
const double&,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&,
|
||||
SimulationJob&)>
|
||||
constructScenarioFunction;
|
||||
std::shared_ptr<SimulationEdgeMesh> m_pReducedModelSimulationEdgeMesh;
|
||||
std::shared_ptr<SimulationEdgeMesh> m_pSimulationEdgeMesh_pattern;
|
||||
std::unordered_map<PatternVertexIndex, ReducedModelVertexIndex>
|
||||
m_fullToReducedInterfaceViMap;
|
||||
std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>
|
||||
m_fullPatternOppositeInterfaceViPairs;
|
||||
std::unordered_map<size_t, size_t> nodeToSlot;
|
||||
std::unordered_map<size_t, std::unordered_set<size_t>> slotToNode;
|
||||
std::string optimizationNotes;
|
||||
std::array<
|
||||
std::function<void(
|
||||
const double&,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&,
|
||||
SimulationJob&)>,
|
||||
ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
constructBaseScenarioFunctions;
|
||||
std::vector<bool> scenarioIsSymmetrical;
|
||||
int fullPatternNumberOfEdges;
|
||||
std::string fullPatternLabel;
|
||||
// ReducedModelOptimization::Settings optimizationSettings;
|
||||
|
||||
public:
|
||||
struct FunctionEvaluation
|
||||
{
|
||||
FunctionEvaluation() = default;
|
||||
FunctionEvaluation(const std::vector<double> &x, double y) : x(x), y(y) {}
|
||||
public:
|
||||
struct FunctionEvaluation {
|
||||
FunctionEvaluation() = default;
|
||||
FunctionEvaluation(const std::vector<double>& x, double y) : x(x), y(y) {}
|
||||
|
||||
std::vector<double> x;
|
||||
double y = std::numeric_limits<double>::quiet_NaN();
|
||||
};
|
||||
std::vector<double> x;
|
||||
double y = std::numeric_limits<double>::quiet_NaN();
|
||||
};
|
||||
|
||||
// struct ParameterLabels
|
||||
// {
|
||||
// inline const static std::string E = {"E"};
|
||||
// inline const static std::string A = {"A"};
|
||||
// inline const static std::string I2 ={"I2"};
|
||||
// inline const static std::string I3 ={"I3"};
|
||||
// inline const static std::string J = {"J"};
|
||||
// inline const static std::string th= {"Theta"};
|
||||
// inline const static std::string R = {"R"};
|
||||
// };
|
||||
// inline constexpr static ParameterLabels parameterLabels();
|
||||
// struct ParameterLabels
|
||||
// {
|
||||
// inline const static std::string E = {"E"};
|
||||
// inline const static std::string A = {"A"};
|
||||
// inline const static std::string I2 ={"I2"};
|
||||
// inline const static std::string I3 ={"I3"};
|
||||
// inline const static std::string J = {"J"};
|
||||
// inline const static std::string th= {"Theta"};
|
||||
// inline const static std::string R = {"R"};
|
||||
// };
|
||||
// inline constexpr static ParameterLabels parameterLabels();
|
||||
|
||||
inline static std::array<std::string, ReducedModelOptimization::NumberOfOptimizationVariables>
|
||||
parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"};
|
||||
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
simulationScenariosResolution = {12, 12, 22, 22, 22, 22};
|
||||
constexpr static std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
baseScenarioWeights = {1, 1, 2, 2, 2};
|
||||
inline static int totalNumberOfSimulationScenarios
|
||||
= std::accumulate(simulationScenariosResolution.begin(),
|
||||
simulationScenariosResolution.end(),
|
||||
0);
|
||||
inline static int fanSize{6};
|
||||
inline static double initialHexagonSize{0.3};
|
||||
int interfaceNodeIndex;
|
||||
double operator()(const Eigen::VectorXd &x, Eigen::VectorXd &) const;
|
||||
inline static std::array<
|
||||
std::string,
|
||||
ReducedModelOptimization::NumberOfOptimizationVariables>
|
||||
parameterLabels = {"E", "A", "I2", "I3", "J", "Theta", "R"};
|
||||
constexpr static std::
|
||||
array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
simulationScenariosResolution = {12, 12, 22, 22, 22, 22};
|
||||
// simulationScenariosResolution = {2, 2, 2, 22, 22, 22};
|
||||
constexpr static std::
|
||||
array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
baseScenarioWeights = {1, 1, 2, 2, 2};
|
||||
inline static int totalNumberOfSimulationScenarios =
|
||||
std::accumulate(simulationScenariosResolution.begin(),
|
||||
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();
|
||||
static void computeReducedModelSimulationJob(
|
||||
const SimulationJob &simulationJobOfFullModel,
|
||||
const std::unordered_map<size_t, size_t> &fullToReducedMap,
|
||||
SimulationJob &simulationJobOfReducedModel);
|
||||
ReducedModelOptimizer();
|
||||
static void computeReducedModelSimulationJob(
|
||||
const SimulationJob& simulationJobOfFullModel,
|
||||
const std::unordered_map<size_t, size_t>& fullToReducedMap,
|
||||
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(
|
||||
const std::shared_ptr<SimulationMesh> &pMesh,
|
||||
const std::unordered_map<size_t, size_t> &fullPatternOppositeInterfaceViMap);
|
||||
static std::vector<std::shared_ptr<SimulationJob>>
|
||||
createFullPatternSimulationJobs(
|
||||
const std::shared_ptr<SimulationEdgeMesh>& pMesh,
|
||||
const std::unordered_map<size_t, size_t>&
|
||||
fullPatternOppositeInterfaceViMap);
|
||||
|
||||
static void createSimulationMeshes(
|
||||
PatternGeometry &pattern,
|
||||
PatternGeometry &reducedModel,
|
||||
const RectangularBeamDimensions &beamDimensions,
|
||||
std::shared_ptr<SimulationMesh> &pFullPatternSimulationMesh,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh);
|
||||
void computeMaps(const std::unordered_map<size_t, std::unordered_set<size_t>> &slotToNode,
|
||||
PatternGeometry &fullPattern,
|
||||
ReducedModel &reducedPattern,
|
||||
std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap,
|
||||
std::unordered_map<FullPatternVertexIndex, ReducedPatternVertexIndex>
|
||||
&fullToReducedInterfaceViMap,
|
||||
std::vector<std::pair<FullPatternVertexIndex, ReducedPatternVertexIndex>>
|
||||
&fullPatternOppositeInterfaceViMap);
|
||||
static void visualizeResults(
|
||||
const std::vector<std::shared_ptr<SimulationJob>> &fullPatternSimulationJobs,
|
||||
const std::vector<std::shared_ptr<SimulationJob>> &reducedPatternSimulationJobs,
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap);
|
||||
static void registerResultsForDrawing(
|
||||
const std::shared_ptr<SimulationJob> &pFullPatternSimulationJob,
|
||||
const std::shared_ptr<SimulationJob> &pReducedPatternSimulationJob,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap);
|
||||
static void createSimulationEdgeMeshes(
|
||||
PatternGeometry& pattern,
|
||||
PatternGeometry& reducedModel,
|
||||
const ReducedModelOptimization::Settings& optimizationSettings,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pFullPatternSimulationEdgeMesh,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh);
|
||||
void computeMaps(
|
||||
const std::unordered_map<size_t, std::unordered_set<size_t>>& slotToNode,
|
||||
PatternGeometry& fullPattern,
|
||||
ReducedModel& reducedPattern,
|
||||
std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap,
|
||||
std::unordered_map<PatternVertexIndex, ReducedModelVertexIndex>&
|
||||
fullToReducedInterfaceViMap,
|
||||
std::vector<std::pair<PatternVertexIndex, ReducedModelVertexIndex>>&
|
||||
fullPatternOppositeInterfaceViMap);
|
||||
static void visualizeResults(
|
||||
const std::vector<std::shared_ptr<SimulationJob>>&
|
||||
fullPatternSimulationJobs,
|
||||
const std::vector<std::shared_ptr<SimulationJob>>&
|
||||
reducedPatternSimulationJobs,
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||
simulationScenarios,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
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(
|
||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap);
|
||||
static double computeRawTranslationalError(
|
||||
const std::vector<Vector6d>& fullPatternDisplacements,
|
||||
const std::vector<Vector6d>& reducedPatternDisplacements,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap);
|
||||
|
||||
static double computeDisplacementError(
|
||||
const std::vector<Vector6d> &fullPatternDisplacements,
|
||||
const std::vector<Vector6d> &reducedPatternDisplacements,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap,
|
||||
const double &normalizationFactor);
|
||||
static double computeDisplacementError(
|
||||
const std::vector<Vector6d>& fullPatternDisplacements,
|
||||
const std::vector<Vector6d>& reducedPatternDisplacements,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap,
|
||||
const double& normalizationFactor);
|
||||
|
||||
static double computeRawRotationalError(
|
||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_fullPattern,
|
||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_reducedPattern,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap);
|
||||
static double computeRawRotationalError(
|
||||
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_fullPattern,
|
||||
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_reducedPattern,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap);
|
||||
|
||||
static double computeRotationalError(const std::vector<Eigen::Quaterniond> &rotatedQuaternion_fullPattern,
|
||||
const std::vector<Eigen::Quaterniond> &rotatedQuaternion_reducedPattern,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap,
|
||||
const double &normalizationFactor);
|
||||
static double computeError(
|
||||
const SimulationResults &simulationResults_fullPattern,
|
||||
const SimulationResults &simulationResults_reducedPattern,
|
||||
const std::unordered_map<ReducedPatternVertexIndex, FullPatternVertexIndex>
|
||||
&reducedToFullInterfaceViMap,
|
||||
const double &normalizationFactor_translationalDisplacement,
|
||||
const double &normalizationFactor_rotationalDisplacement,
|
||||
const double &scenarioWeight,
|
||||
const ReducedModelOptimization::Settings::ObjectiveWeights &objectiveWeights);
|
||||
static void constructAxialSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static double computeRotationalError(
|
||||
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_fullPattern,
|
||||
const std::vector<Eigen::Quaterniond>& rotatedQuaternion_reducedPattern,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap,
|
||||
const double& normalizationFactor);
|
||||
static double computeError(
|
||||
const SimulationResults& simulationResults_fullPattern,
|
||||
const SimulationResults& simulationResults_reducedPattern,
|
||||
const std::unordered_map<ReducedModelVertexIndex, PatternVertexIndex>&
|
||||
reducedToFullInterfaceViMap,
|
||||
const double& normalizationFactor_translationalDisplacement,
|
||||
const double& normalizationFactor_rotationalDisplacement,
|
||||
const double& scenarioWeight,
|
||||
const ReducedModelOptimization::Settings::ObjectiveWeights&
|
||||
objectiveWeights);
|
||||
static void constructAxialSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
|
||||
static void constructShearSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static void constructShearSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
|
||||
static void constructBendingSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static void constructBendingSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
|
||||
static void constructDomeSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static void constructDomeSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
|
||||
static void constructSaddleSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static void constructSSimulationScenario(
|
||||
const double &forceMagnitude,
|
||||
const std::vector<std::pair<FullPatternVertexIndex, FullPatternVertexIndex>>
|
||||
&oppositeInterfaceViPairs,
|
||||
SimulationJob &job);
|
||||
static std::function<void(const std::vector<double> &x,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern;
|
||||
static std::function<void(const double &newE,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_E;
|
||||
static std::function<void(const double &newA,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_A;
|
||||
static std::function<void(const double &newI,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_I;
|
||||
static std::function<void(const double &newI2,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_I2;
|
||||
static std::function<void(const double &newI3,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_I3;
|
||||
static std::function<void(const double &newJ,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
function_updateReducedPattern_material_J;
|
||||
static double objective(const std::vector<double> &x);
|
||||
void initializeUpdateReducedPatternFunctions();
|
||||
// static double objective(const double &xValue);
|
||||
static void constructSaddleSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
static void constructSSimulationScenario(
|
||||
const double& forceMagnitude,
|
||||
const std::vector<std::pair<PatternVertexIndex, PatternVertexIndex>>&
|
||||
oppositeInterfaceViPairs,
|
||||
SimulationJob& job);
|
||||
static std::function<void(
|
||||
const std::vector<double>& x,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
function_updateReducedPattern;
|
||||
static std::function<void(
|
||||
const double& newE,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
function_updateReducedPattern_material_E;
|
||||
static std::function<void(
|
||||
const double& newA,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
function_updateReducedPattern_material_A;
|
||||
static std::function<void(
|
||||
const double& newI,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
function_updateReducedPattern_material_I;
|
||||
static std::function<void(
|
||||
const double& newI2,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
function_updateReducedPattern_material_I2;
|
||||
static std::function<void(
|
||||
const double& newI3,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
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(
|
||||
ConstPatternGeometry &fullPattern,
|
||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
||||
ReducedModelOptimization::Results optimize(
|
||||
ConstPatternGeometry& fullPattern,
|
||||
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||
|
||||
void optimize(ConstPatternGeometry &fullPattern,
|
||||
ReducedModelOptimization::Settings &optimizationSettings,
|
||||
ReducedModelOptimization::Results &optimizationResults);
|
||||
static double objective(const std::vector<double> &x,
|
||||
ReducedModelOptimizer::OptimizationState &optimizationState);
|
||||
void optimize(ConstPatternGeometry& fullPattern,
|
||||
ReducedModelOptimization::Settings& optimizationSettings,
|
||||
ReducedModelOptimization::Results& optimizationResults);
|
||||
static double objective(
|
||||
const std::vector<double>& x,
|
||||
ReducedModelOptimizer::OptimizationState& optimizationState);
|
||||
|
||||
private:
|
||||
void optimize(
|
||||
ReducedModelOptimization::Settings &optimizationSettings,
|
||||
ReducedModelOptimization::Results &results,
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &simulationScenarios
|
||||
= std::vector<ReducedModelOptimization::BaseSimulationScenario>(
|
||||
{ReducedModelOptimization::Axial,
|
||||
ReducedModelOptimization::Shear,
|
||||
ReducedModelOptimization::Bending,
|
||||
ReducedModelOptimization::Dome,
|
||||
ReducedModelOptimization::Saddle,
|
||||
ReducedModelOptimization::S}));
|
||||
private:
|
||||
void optimize(
|
||||
ReducedModelOptimization::Settings& optimizationSettings,
|
||||
ReducedModelOptimization::Results& results,
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||
simulationScenarios =
|
||||
std::vector<ReducedModelOptimization::BaseSimulationScenario>(
|
||||
{ReducedModelOptimization::Axial,
|
||||
ReducedModelOptimization::Shear,
|
||||
ReducedModelOptimization::Bending,
|
||||
ReducedModelOptimization::Dome,
|
||||
ReducedModelOptimization::Saddle,
|
||||
ReducedModelOptimization::S}));
|
||||
|
||||
void initializePatterns(PatternGeometry &fullPattern,
|
||||
ReducedModel &reducedModel,
|
||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
||||
static void computeDesiredReducedModelDisplacements(
|
||||
const SimulationResults &fullModelResults,
|
||||
const std::unordered_map<size_t, size_t> &displacementsReducedToFullMap,
|
||||
Eigen::MatrixX3d &optimalDisplacementsOfReducedModel);
|
||||
void runOptimization(const ReducedModelOptimization::Settings &settings,
|
||||
ReducedModelOptimization::Results &results);
|
||||
void computeMaps(PatternGeometry &fullModel, ReducedModel &reducedModel);
|
||||
void createSimulationMeshes(PatternGeometry &fullModel,
|
||||
PatternGeometry &reducedModel,
|
||||
const RectangularBeamDimensions &beamDimensions);
|
||||
void initializeOptimizationParameters(
|
||||
const std::shared_ptr<SimulationMesh> &mesh,
|
||||
const std::array<ReducedModelOptimization::xRange,
|
||||
ReducedModelOptimization::NumberOfOptimizationVariables>
|
||||
&optimizationParamters);
|
||||
void initializePatterns(
|
||||
PatternGeometry& fullPattern,
|
||||
ReducedModel& reducedModel,
|
||||
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||
static void computeDesiredReducedModelDisplacements(
|
||||
const SimulationResults& fullModelResults,
|
||||
const std::unordered_map<size_t, size_t>& displacementsReducedToFullMap,
|
||||
Eigen::MatrixX3d& optimalDisplacementsOfReducedModel);
|
||||
void runOptimization(const ReducedModelOptimization::Settings& settings,
|
||||
ReducedModelOptimization::Results& results);
|
||||
void computeMaps(PatternGeometry& fullModel, ReducedModel& reducedModel);
|
||||
void createSimulationEdgeMeshes(
|
||||
PatternGeometry& fullModel,
|
||||
PatternGeometry& reducedModel,
|
||||
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||
void initializeOptimizationParameters(
|
||||
const std::shared_ptr<SimulationEdgeMesh>& mesh,
|
||||
const std::array<ReducedModelOptimization::xRange,
|
||||
ReducedModelOptimization::NumberOfOptimizationVariables>&
|
||||
optimizationParamters);
|
||||
|
||||
ChronosEulerSimulationModel patternSimulator;
|
||||
LinearSimulationModel reducedModelSimulator;
|
||||
void computeObjectiveValueNormalizationFactors(
|
||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
||||
void computeObjectiveValueNormalizationFactors(
|
||||
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||
|
||||
void getResults(const FunctionEvaluation &optimalObjective,
|
||||
const ReducedModelOptimization::Settings &settings,
|
||||
ReducedModelOptimization::Results &results);
|
||||
double computeFullPatternMaxSimulationForce(
|
||||
const ReducedModelOptimization::BaseSimulationScenario &scenario) const;
|
||||
void getResults(const FunctionEvaluation& optimalObjective,
|
||||
const ReducedModelOptimization::Settings& settings,
|
||||
ReducedModelOptimization::Results& results);
|
||||
double computeFullPatternMaxSimulationForce(
|
||||
const ReducedModelOptimization::BaseSimulationScenario& scenario) const;
|
||||
|
||||
#ifdef DLIB_DEFINED
|
||||
static double objective(const dlib::matrix<double, 0, 1> &x);
|
||||
static double objective(const dlib::matrix<double, 0, 1>& x);
|
||||
#endif
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
computeFullPatternMaxSimulationForces(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>
|
||||
&desiredBaseSimulationScenario) const;
|
||||
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
||||
const std::shared_ptr<SimulationMesh> &pMesh,
|
||||
const std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
&baseScenarioMaxForceMagnitudes) const;
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
getFullPatternMaxSimulationForces(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>
|
||||
&desiredBaseSimulationScenarioIndices,
|
||||
const std::filesystem::path &intermediateResultsDirectoryPath,
|
||||
const bool &recomputeForceMagnitudes);
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
getFullPatternMaxSimulationForces();
|
||||
void computeScenarioWeights(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario> &baseSimulationScenarios,
|
||||
const ReducedModelOptimization::Settings &optimizationSettings);
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
computeFullPatternMaxSimulationForces(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||
desiredBaseSimulationScenario) const;
|
||||
std::vector<std::shared_ptr<SimulationJob>> createFullPatternSimulationJobs(
|
||||
const std::shared_ptr<SimulationEdgeMesh>& pMesh,
|
||||
const std::array<
|
||||
double,
|
||||
ReducedModelOptimization::NumberOfBaseSimulationScenarios>&
|
||||
baseScenarioMaxForceMagnitudes) const;
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
getFullPatternMaxSimulationForces(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||
desiredBaseSimulationScenarioIndices,
|
||||
const std::filesystem::path& intermediateResultsDirectoryPath,
|
||||
const bool& recomputeForceMagnitudes);
|
||||
std::array<double, ReducedModelOptimization::NumberOfBaseSimulationScenarios>
|
||||
getFullPatternMaxSimulationForces();
|
||||
void computeScenarioWeights(
|
||||
const std::vector<ReducedModelOptimization::BaseSimulationScenario>&
|
||||
baseSimulationScenarios,
|
||||
const ReducedModelOptimization::Settings& optimizationSettings);
|
||||
};
|
||||
inline std::function<void(const double &newE,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newE,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
ReducedModelOptimizer::function_updateReducedPattern_material_E;
|
||||
inline std::function<void(const double &newA,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newA,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
ReducedModelOptimizer::function_updateReducedPattern_material_A;
|
||||
inline std::function<void(const double &newI,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newI,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
ReducedModelOptimizer::function_updateReducedPattern_material_I;
|
||||
inline std::function<void(const double &newI2,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newI2,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
ReducedModelOptimizer::function_updateReducedPattern_material_I2;
|
||||
inline std::function<void(const double &newI3,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newI3,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
ReducedModelOptimizer::function_updateReducedPattern_material_I3;
|
||||
inline std::function<void(const double &newJ,
|
||||
std::shared_ptr<SimulationMesh> &pReducedPatternSimulationMesh)>
|
||||
inline std::function<void(
|
||||
const double& newJ,
|
||||
std::shared_ptr<SimulationEdgeMesh>& pReducedPatternSimulationEdgeMesh)>
|
||||
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;
|
||||
|
||||
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
|
||||
#define FLATPATTERNGEOMETRY_HPP
|
||||
#include "edgemesh.hpp"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include "vcgtrimesh.hpp"
|
||||
#include "edgemesh.hpp"
|
||||
#include "polymesh.hpp"
|
||||
#include "vcgtrimesh.hpp"
|
||||
|
||||
class PatternGeometry;
|
||||
using ConstPatternGeometry = PatternGeometry;
|
||||
|
||||
class PatternGeometry : public VCGEdgeMesh
|
||||
{
|
||||
private:
|
||||
size_t
|
||||
computeTiledValence(const size_t &nodeIndex,
|
||||
const std::vector<size_t> &numberOfNodesPerSlot) const;
|
||||
size_t getNodeValence(const size_t &nodeIndex) const;
|
||||
size_t getNodeSlot(const size_t &nodeIndex) const;
|
||||
class PatternGeometry : public VCGEdgeMesh {
|
||||
private:
|
||||
size_t computeTiledValence(
|
||||
const size_t& nodeIndex,
|
||||
const std::vector<size_t>& numberOfNodesPerSlot) const;
|
||||
size_t getNodeValence(const size_t& nodeIndex) const;
|
||||
size_t getNodeSlot(const size_t& nodeIndex) const;
|
||||
|
||||
void addNormals();
|
||||
double baseTriangleHeight;
|
||||
|
||||
inline static size_t fanSize{6};
|
||||
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> correspondingNode;
|
||||
std::unordered_map<size_t, size_t> nodeTiledValence;
|
||||
vcg::Triangle3<double> baseTriangle;
|
||||
|
||||
void
|
||||
constructCorrespondingNodeMap(const std::vector<size_t> &numberOfNodesPerSlot);
|
||||
void constructCorrespondingNodeMap(
|
||||
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,
|
||||
const int &vi);
|
||||
std::vector<VectorType> getEdgeVectorsWithVertexAsOrigin(
|
||||
std::vector<EdgePointer>& edgePointers,
|
||||
const int& vi);
|
||||
|
||||
public:
|
||||
public:
|
||||
inline static VectorType DefaultNormal{0.0, 0.0, 1.0};
|
||||
PatternGeometry();
|
||||
/*The following function should be a copy constructor with
|
||||
* a const argument but this is impossible due to the
|
||||
* vcglib interface.
|
||||
* */
|
||||
PatternGeometry(PatternGeometry &other);
|
||||
bool load(const std::filesystem::path &meshFilePath) override;
|
||||
void add(const std::vector<vcg::Point3d> &vertices);
|
||||
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<size_t> &numberOfNodesPerSlot, const std::vector<vcg::Point2i> &edges);
|
||||
PatternGeometry(PatternGeometry& other);
|
||||
bool load(const std::filesystem::path& meshFilePath) override;
|
||||
void add(const std::vector<vcg::Point3d>& vertices);
|
||||
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<size_t>& numberOfNodesPerSlot,
|
||||
const std::vector<vcg::Point2i>& edges);
|
||||
static std::vector<vcg::Point3d> constructVertexVector(
|
||||
const std::vector<size_t> &numberOfNodesPerSlot,
|
||||
const size_t &fanSize,
|
||||
const double &triangleEdgeSize);
|
||||
bool hasDanglingEdges(const std::vector<size_t> &numberOfNodesPerSlot);
|
||||
bool hasValenceGreaterThan(const std::vector<size_t> &numberOfNodesPerSlot,
|
||||
const size_t &valenceThreshold);
|
||||
const std::vector<size_t>& numberOfNodesPerSlot,
|
||||
const size_t& fanSize,
|
||||
const double& triangleEdgeSize);
|
||||
bool hasDanglingEdges(const std::vector<size_t>& numberOfNodesPerSlot);
|
||||
bool hasValenceGreaterThan(const std::vector<size_t>& numberOfNodesPerSlot,
|
||||
const size_t& valenceThreshold);
|
||||
std::vector<vcg::Point3d> computeVertices() const;
|
||||
static PatternGeometry createFan(PatternGeometry &pattern);
|
||||
static PatternGeometry createTile(PatternGeometry &pattern);
|
||||
static PatternGeometry createFan(PatternGeometry& pattern);
|
||||
static PatternGeometry createTile(PatternGeometry& pattern);
|
||||
double getTriangleEdgeSize() const;
|
||||
bool hasUntiledDanglingEdges();
|
||||
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)
|
||||
{
|
||||
assert(n >= m);
|
||||
return tgamma(n + 1) / (tgamma(m + 1) * tgamma(n - m + 1));
|
||||
static size_t binomialCoefficient(size_t n, size_t m) {
|
||||
assert(n >= m);
|
||||
return tgamma(n + 1) / (tgamma(m + 1) * tgamma(n - m + 1));
|
||||
}
|
||||
bool isFullyConnectedWhenFanned();
|
||||
|
||||
bool hasIntersectingEdges(
|
||||
const std::string &patternBinaryRepresentation,
|
||||
const std::unordered_map<size_t, std::unordered_set<size_t>>
|
||||
&intersectingEdges);
|
||||
const std::string& patternBinaryRepresentation,
|
||||
const std::unordered_map<size_t, std::unordered_set<size_t>>&
|
||||
intersectingEdges);
|
||||
bool isPatternValid();
|
||||
size_t getFanSize() const;
|
||||
void add(const std::vector<vcg::Point2d> &vertices,
|
||||
const std::vector<vcg::Point2i> &edges);
|
||||
void add(const std::vector<vcg::Point2d>& vertices,
|
||||
const std::vector<vcg::Point2i>& edges);
|
||||
|
||||
PatternGeometry(const std::vector<size_t> &numberOfNodesPerSlot,
|
||||
const std::vector<vcg::Point2i> &edges);
|
||||
PatternGeometry(const std::filesystem::path &patternFilePath, bool addNormalsIfAbsent = true);
|
||||
PatternGeometry(const std::vector<size_t>& numberOfNodesPerSlot,
|
||||
const std::vector<vcg::Point2i>& edges);
|
||||
PatternGeometry(const std::filesystem::path& patternFilePath,
|
||||
bool addNormalsIfAbsent = true);
|
||||
|
||||
bool createHoneycombAtom();
|
||||
void copy(PatternGeometry ©From);
|
||||
void copy(PatternGeometry& copyFrom);
|
||||
|
||||
void tilePattern(VCGEdgeMesh &pattern,
|
||||
VCGPolyMesh &tileInto,
|
||||
const int &interfaceNodeIndex,
|
||||
const bool &shouldDeleteDanglingEdges);
|
||||
void tilePattern(VCGEdgeMesh& pattern,
|
||||
VCGPolyMesh& tileInto,
|
||||
const int& interfaceNodeIndex,
|
||||
const bool& shouldDeleteDanglingEdges);
|
||||
|
||||
void scale(const double &desiredBaseTriangleCentralEdgeSize);
|
||||
void scale(const double& desiredBaseTriangleCentralEdgeSize);
|
||||
|
||||
double getBaseTriangleHeight() const;
|
||||
vcg::Triangle3<double> computeBaseTriangle() const;
|
||||
|
@ -102,35 +105,44 @@ private:
|
|||
double computeBaseTriangleHeight() const;
|
||||
void updateBaseTriangleHeight();
|
||||
|
||||
// PatternGeometry(const std::vector<vcg::Point2d> &vertices, const std::vector<vcg::Point2i> &edges);
|
||||
// static std::shared_ptr<PatternGeometry> tilePattern(
|
||||
// PatternGeometry(const std::vector<vcg::Point2d> &vertices, const
|
||||
// std::vector<vcg::Point2i> &edges); static std::shared_ptr<PatternGeometry>
|
||||
// tilePattern(
|
||||
// std::vector<PatternGeometry> &pattern,
|
||||
// const std::vector<int> &connectToNeighborsVi,
|
||||
// const VCGPolyMesh &tileInto,
|
||||
// std::vector<int> &tileIntoEdgesToTiledVi,
|
||||
// std::vector<std::vector<size_t>> &perPatternEdges);
|
||||
virtual void createFan(/*const std::vector<int> &connectToNeighborsVi = std::vector<int>(),*/
|
||||
const size_t &fanSize = 6);
|
||||
int interfaceNodeIndex{3}; //TODO: Fix this. This should be automatically computed
|
||||
bool hasAngleSmallerThanThreshold(const std::vector<size_t> &numberOfNodesPerSlot,
|
||||
const double &angleThreshold_degrees);
|
||||
virtual void createFan(/*const std::vector<int> &connectToNeighborsVi =
|
||||
std::vector<int>(),*/
|
||||
const size_t& fanSize = 6);
|
||||
int interfaceNodeIndex{
|
||||
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;
|
||||
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(
|
||||
std::vector<ConstPatternGeometry> &patterns,
|
||||
const std::vector<int> &connectToNeighborsVi,
|
||||
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);
|
||||
PatternGeometry& pattern,
|
||||
const std::vector<int>& connectToNeighborsVi,
|
||||
const VCGPolyMesh& tileInto,
|
||||
std::vector<int>& tileIntoEdgesToTiledVi);
|
||||
static std::shared_ptr<PatternGeometry> tilePattern(
|
||||
std::vector<ConstPatternGeometry>& patterns,
|
||||
const std::vector<int>& connectToNeighborsVi,
|
||||
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(
|
||||
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
|
||||
|
||||
polyscope::SurfaceMesh *VCGTriMesh::registerForDrawing(
|
||||
const std::optional<std::array<double, 3>> &desiredColor, const bool &shouldEnable) const
|
||||
polyscope::SurfaceMesh *VCGTriMesh::registerForDrawing(const std::optional<std::array<float, 3> > &desiredColor, const bool &shouldEnable) const
|
||||
{
|
||||
auto vertices = getVertices();
|
||||
auto faces = getFaces();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef VCGTRIMESH_HPP
|
||||
#define VCGTRIMESH_HPP
|
||||
#include "mesh.hpp"
|
||||
#include <vcg/complex/complex.h>
|
||||
#include <optional>
|
||||
#include "mesh.hpp"
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
#include <polyscope/surface_mesh.h>
|
||||
|
@ -22,40 +22,42 @@ class VCGTriMeshVertex : public vcg::Vertex<VCGTriMeshUsedTypes,
|
|||
vcg::vertex::Color4b,
|
||||
vcg::vertex::VFAdj,
|
||||
vcg::vertex::Qualityd,
|
||||
vcg::vertex::VEAdj>
|
||||
{};
|
||||
class VCGTriMeshFace
|
||||
: public vcg::Face<VCGTriMeshUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj,
|
||||
vcg::face::VertexRef, vcg::face::BitFlags,
|
||||
vcg::face::Normal3d> {};
|
||||
class VCGTriMeshEdge : public vcg::Edge<VCGTriMeshUsedTypes, vcg::edge::VertexRef, vcg::edge::VEAdj>
|
||||
{};
|
||||
vcg::vertex::VEAdj> {};
|
||||
class VCGTriMeshFace : public vcg::Face<VCGTriMeshUsedTypes,
|
||||
vcg::face::FFAdj,
|
||||
vcg::face::VFAdj,
|
||||
vcg::face::VertexRef,
|
||||
vcg::face::BitFlags,
|
||||
vcg::face::Normal3d> {};
|
||||
class VCGTriMeshEdge : public vcg::Edge<VCGTriMeshUsedTypes,
|
||||
vcg::edge::VertexRef,
|
||||
vcg::edge::VEAdj> {};
|
||||
|
||||
class VCGTriMesh : public vcg::tri::TriMesh<std::vector<VCGTriMeshVertex>,
|
||||
std::vector<VCGTriMeshFace>,
|
||||
std::vector<VCGTriMeshEdge>>,
|
||||
public Mesh
|
||||
{
|
||||
public:
|
||||
public Mesh {
|
||||
public:
|
||||
VCGTriMesh();
|
||||
VCGTriMesh(const std::string &filename);
|
||||
bool load(const std::filesystem::path &meshFilePath) override;
|
||||
bool load(std::istringstream &offInputStream);
|
||||
VCGTriMesh(const std::string& filename);
|
||||
bool load(const std::filesystem::path& meshFilePath) override;
|
||||
bool load(std::istringstream& offInputStream);
|
||||
Eigen::MatrixX3d getVertices() const;
|
||||
Eigen::MatrixX3i getFaces() const;
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef POLYSCOPE_DEFINED
|
||||
polyscope::SurfaceMesh *registerForDrawing(
|
||||
const std::optional<std::array<double, 3>> &desiredColor = std::nullopt,
|
||||
const bool &shouldEnable = true) const;
|
||||
polyscope::SurfaceMesh* registerForDrawing(
|
||||
const std::optional<std::array<float, 3>>& desiredColor = std::nullopt,
|
||||
const bool& shouldEnable = true) const;
|
||||
#endif
|
||||
Eigen::MatrixX2i getEdges() const;
|
||||
void updateEigenEdgeAndVertices();
|
||||
void moveToCenter();
|
||||
};
|
||||
|
||||
#endif // VCGTRIMESH_HPP
|
||||
#endif // VCGTRIMESH_HPP
|
||||
|
|
Loading…
Reference in New Issue