Refactored code to compile under visual studio.
This commit is contained in:
parent
8f9b5c2c20
commit
2599d47261
1
beam.hpp
1
beam.hpp
|
|
@ -3,6 +3,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
struct RectangularBeamDimensions {
|
struct RectangularBeamDimensions {
|
||||||
inline static std::string name{"Rectangular"};
|
inline static std::string name{"Rectangular"};
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ void FormFinder::runUnitTests() {
|
||||||
// const size_t spanGridSize = 11;
|
// const size_t spanGridSize = 11;
|
||||||
// mesh.createSpanGrid(spanGridSize);
|
// mesh.createSpanGrid(spanGridSize);
|
||||||
beam.loadPly(
|
beam.loadPly(
|
||||||
std::filesystem::path(groundOfTruthFolder).append("simpleBeam.ply"));
|
std::filesystem::path(groundOfTruthFolder).append("simpleBeam.ply").string());
|
||||||
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
std::unordered_map<VertexIndex, std::unordered_set<DoFType>> fixedVertices;
|
||||||
fixedVertices[0] = std::unordered_set<DoFType>{0, 1, 2, 3};
|
fixedVertices[0] = std::unordered_set<DoFType>{0, 1, 2, 3};
|
||||||
fixedVertices[beam.VN() - 1] = std::unordered_set<DoFType>{1, 2};
|
fixedVertices[beam.VN() - 1] = std::unordered_set<DoFType>{1, 2};
|
||||||
|
|
@ -50,7 +50,7 @@ void FormFinder::runUnitTests() {
|
||||||
simpleBeam_simulationResults.save();
|
simpleBeam_simulationResults.save();
|
||||||
const std::string simpleBeamGroundOfTruthBinaryFilename =
|
const std::string simpleBeamGroundOfTruthBinaryFilename =
|
||||||
std::filesystem::path(groundOfTruthFolder)
|
std::filesystem::path(groundOfTruthFolder)
|
||||||
.append("SimpleBeam_displacements.eigenBin");
|
.append("SimpleBeam_displacements.eigenBin").string();
|
||||||
assert(std::filesystem::exists(
|
assert(std::filesystem::exists(
|
||||||
std::filesystem::path(simpleBeamGroundOfTruthBinaryFilename)));
|
std::filesystem::path(simpleBeamGroundOfTruthBinaryFilename)));
|
||||||
Eigen::MatrixXd simpleBeam_groundOfTruthDisplacements;
|
Eigen::MatrixXd simpleBeam_groundOfTruthDisplacements;
|
||||||
|
|
@ -211,7 +211,7 @@ void FormFinder::reset() {
|
||||||
history.clear();
|
history.clear();
|
||||||
constrainedVertices.clear();
|
constrainedVertices.clear();
|
||||||
rigidSupports.clear();
|
rigidSupports.clear();
|
||||||
pMesh.release();
|
pMesh.reset();
|
||||||
plotYValues.clear();
|
plotYValues.clear();
|
||||||
plotHandle.reset();
|
plotHandle.reset();
|
||||||
checkedForMaximumMoment = false;
|
checkedForMaximumMoment = false;
|
||||||
|
|
@ -219,6 +219,7 @@ void FormFinder::reset() {
|
||||||
externalMomentsNorm = 0;
|
externalMomentsNorm = 0;
|
||||||
mSettings.drawingStep = 1;
|
mSettings.drawingStep = 1;
|
||||||
Dt = mSettings.Dtini;
|
Dt = mSettings.Dtini;
|
||||||
|
numOfDampings=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorType FormFinder::computeDisplacementDifferenceDerivative(
|
VectorType FormFinder::computeDisplacementDifferenceDerivative(
|
||||||
|
|
@ -793,8 +794,8 @@ void FormFinder::updateResidualForcesOnTheFly(
|
||||||
std::vector<std::pair<int, Vector6d>>(4, {-1, Vector6d()}));
|
std::vector<std::pair<int, Vector6d>>(4, {-1, Vector6d()}));
|
||||||
// omp_lock_t writelock;
|
// omp_lock_t writelock;
|
||||||
// omp_init_lock(&writelock);
|
// omp_init_lock(&writelock);
|
||||||
#pragma omp parallel for schedule(static) num_threads(8)
|
//#pragma omp parallel for //schedule(static) num_threads(8)
|
||||||
for (size_t ei = 0; ei < pMesh->EN(); ei++) {
|
for (int ei = 0; ei < pMesh->EN(); ei++) {
|
||||||
const EdgeType &e = pMesh->edge[ei];
|
const EdgeType &e = pMesh->edge[ei];
|
||||||
const SimulationMesh::VertexType &ev_j = *e.cV(0);
|
const SimulationMesh::VertexType &ev_j = *e.cV(0);
|
||||||
const SimulationMesh::VertexType &ev_jplus1 = *e.cV(1);
|
const SimulationMesh::VertexType &ev_jplus1 = *e.cV(1);
|
||||||
|
|
@ -1790,14 +1791,15 @@ FormFinder::executeSimulation(const std::shared_ptr<SimulationJob> &pJob,
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
pMesh.reset();
|
||||||
pMesh = std::make_unique<SimulationMesh>(*pJob->pMesh);
|
pMesh = std::make_unique<SimulationMesh>(*pJob->pMesh);
|
||||||
if (mSettings.beVerbose) {
|
if (mSettings.beVerbose ) {
|
||||||
std::cout << "Executing simulation for mesh with:" << pMesh->VN()
|
std::cout << "Executing simulation for mesh with:" << pMesh->VN()
|
||||||
<< " nodes and " << pMesh->EN() << " elements." << std::endl;
|
<< " nodes and " << pMesh->EN() << " elements." << std::endl;
|
||||||
}
|
}
|
||||||
computeRigidSupports();
|
computeRigidSupports();
|
||||||
|
|
||||||
if (mSettings.shouldDraw) {
|
if (mSettings.shouldDraw ) {
|
||||||
initPolyscope();
|
initPolyscope();
|
||||||
polyscope::registerCurveNetwork(
|
polyscope::registerCurveNetwork(
|
||||||
meshPolyscopeLabel, pMesh->getEigenVertices(), pMesh->getEigenEdges());
|
meshPolyscopeLabel, pMesh->getEigenVertices(), pMesh->getEigenEdges());
|
||||||
|
|
@ -1974,7 +1976,7 @@ mesh->currentTotalPotentialEnergykN*/
|
||||||
} else if (std::isnan(pMesh->currentTotalKineticEnergy)) {
|
} else if (std::isnan(pMesh->currentTotalKineticEnergy)) {
|
||||||
results.converged = false;
|
results.converged = false;
|
||||||
|
|
||||||
} else if (mSettings.beVerbose) {
|
} else if (mSettings.beVerbose ) {
|
||||||
auto t2 = std::chrono::high_resolution_clock::now();
|
auto t2 = std::chrono::high_resolution_clock::now();
|
||||||
double simulationDuration =
|
double simulationDuration =
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
|
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
|
||||||
|
|
|
||||||
12
csvfile.hpp
12
csvfile.hpp
|
|
@ -23,8 +23,16 @@ public:
|
||||||
: fs_(), is_first_(true), separator_(separator), escape_seq_("\""),
|
: fs_(), is_first_(true), separator_(separator), escape_seq_("\""),
|
||||||
special_chars_("\"") {
|
special_chars_("\"") {
|
||||||
fs_.exceptions(std::ios::failbit | std::ios::badbit);
|
fs_.exceptions(std::ios::failbit | std::ios::badbit);
|
||||||
overwrite ? fs_.open(filename, std::ios::trunc)
|
if (!std::filesystem::exists(std::filesystem::path("../OptimizationResults")
|
||||||
: fs_.open(filename, std::ios::app);
|
.append("statistics.csv")
|
||||||
|
)) {
|
||||||
|
std::ofstream outfile(std::filesystem::path("../OptimizationResults")
|
||||||
|
.append("statistics.csv")
|
||||||
|
.string());
|
||||||
|
outfile.close();
|
||||||
|
}
|
||||||
|
overwrite ? fs_.open(filename, std::ios::trunc)
|
||||||
|
: fs_.open(filename, std::ios::app);
|
||||||
}
|
}
|
||||||
|
|
||||||
~csvfile() {
|
~csvfile() {
|
||||||
|
|
|
||||||
12
edgemesh.cpp
12
edgemesh.cpp
|
|
@ -183,21 +183,11 @@ bool VCGEdgeMesh::loadPly(const std::string plyFilename) {
|
||||||
assert(std::filesystem::exists(usedPath));
|
assert(std::filesystem::exists(usedPath));
|
||||||
this->Clear();
|
this->Clear();
|
||||||
const bool useDefaultImporter = false;
|
const bool useDefaultImporter = false;
|
||||||
if (useDefaultImporter) {
|
|
||||||
if (!loadUsingDefaultLoader(usedPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
eigenEdgeNormals.resize(EN(), 3);
|
|
||||||
for (int i = 0; i < EN(); i++) {
|
|
||||||
eigenEdgeNormals.row(i) = Eigen::Vector3d(0, 1, 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!loadUsingNanoply(usedPath)) {
|
if (!loadUsingNanoply(usedPath)) {
|
||||||
std::cerr << "Error: Unable to open " + usedPath << std::endl;
|
std::cerr << "Error: Unable to open " + usedPath << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
getEdges(eigenEdges);
|
getEdges(eigenEdges);
|
||||||
getVertices(eigenVertices);
|
getVertices(eigenVertices);
|
||||||
vcg::tri::UpdateTopology<VCGEdgeMesh>::VertexEdge(*this);
|
vcg::tri::UpdateTopology<VCGEdgeMesh>::VertexEdge(*this);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ public:
|
||||||
|
|
||||||
Eigen::MatrixX3d getNormals() const;
|
Eigen::MatrixX3d getNormals() const;
|
||||||
|
|
||||||
bool loadUsingDefaultLoader(const std::string &plyFilename);
|
|
||||||
bool hasProperty(const std::vector<nanoply::PlyProperty> &v,
|
bool hasProperty(const std::vector<nanoply::PlyProperty> &v,
|
||||||
const std::string &propertyName);
|
const std::string &propertyName);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ SimulationMesh::SimulationMesh(VCGEdgeMesh &mesh) {
|
||||||
eigenVertices = mesh.getEigenVertices();
|
eigenVertices = mesh.getEigenVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimulationMesh::~SimulationMesh()
|
||||||
|
{
|
||||||
|
vcg::tri::Allocator<VCGEdgeMesh>::DeletePerEdgeAttribute<Element>(*this, elements);
|
||||||
|
vcg::tri::Allocator<VCGEdgeMesh>::DeletePerVertexAttribute<Node>(*this,nodes);
|
||||||
|
}
|
||||||
|
|
||||||
SimulationMesh::SimulationMesh(FlatPattern &pattern) {
|
SimulationMesh::SimulationMesh(FlatPattern &pattern) {
|
||||||
vcg::tri::MeshAssert<FlatPattern>::VertexNormalNormalized(pattern);
|
vcg::tri::MeshAssert<FlatPattern>::VertexNormalNormalized(pattern);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ private:
|
||||||
public:
|
public:
|
||||||
PerEdgeAttributeHandle<Element> elements;
|
PerEdgeAttributeHandle<Element> elements;
|
||||||
PerVertexAttributeHandle<Node> nodes;
|
PerVertexAttributeHandle<Node> nodes;
|
||||||
|
~SimulationMesh();
|
||||||
SimulationMesh(FlatPattern &pattern);
|
SimulationMesh(FlatPattern &pattern);
|
||||||
SimulationMesh(ConstVCGEdgeMesh &edgeMesh);
|
SimulationMesh(ConstVCGEdgeMesh &edgeMesh);
|
||||||
SimulationMesh(SimulationMesh &elementalMesh);
|
SimulationMesh(SimulationMesh &elementalMesh);
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ struct SimulationResultsReporter {
|
||||||
|
|
||||||
createPlots(simulationResult.history, simulationResultPath.string(),
|
createPlots(simulationResult.history, simulationResultPath.string(),
|
||||||
graphSuffix);
|
graphSuffix);
|
||||||
writeStatistics(simulationResult, simulationResultPath);
|
writeStatistics(simulationResult, simulationResultPath.string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void createPlot(const std::string &xLabel, const std::string &yLabel,
|
static void createPlot(const std::string &xLabel, const std::string &yLabel,
|
||||||
|
|
|
||||||
|
|
@ -187,16 +187,15 @@ public:
|
||||||
if (json.contains(jsonLabel_constrainedVertices)) {
|
if (json.contains(jsonLabel_constrainedVertices)) {
|
||||||
constrainedVertices =
|
constrainedVertices =
|
||||||
// auto conV =
|
// auto conV =
|
||||||
std::unordered_map<VertexIndex, std::unordered_set<int>>(
|
json[jsonLabel_constrainedVertices].get<std::unordered_map<VertexIndex, std::unordered_set<int>>>();
|
||||||
json[jsonLabel_constrainedVertices]);
|
|
||||||
std::cout << "Loaded constrained vertices. Number of constrained "
|
std::cout << "Loaded constrained vertices. Number of constrained "
|
||||||
"vertices found:"
|
"vertices found:"
|
||||||
<< constrainedVertices.size() << std::endl;
|
<< constrainedVertices.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains(jsonLabel_nodalForces)) {
|
if (json.contains(jsonLabel_nodalForces)) {
|
||||||
auto f = std::unordered_map<VertexIndex, std::array<double, 6>>(
|
auto f (
|
||||||
json[jsonLabel_nodalForces]);
|
json[jsonLabel_nodalForces].get<std::unordered_map<VertexIndex, std::array<double, 6>>>());
|
||||||
for (const auto &forces : f) {
|
for (const auto &forces : f) {
|
||||||
nodalExternalForces[forces.first] = Vector6d(forces.second);
|
nodalExternalForces[forces.first] = Vector6d(forces.second);
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +220,7 @@ public:
|
||||||
std::filesystem::absolute(
|
std::filesystem::absolute(
|
||||||
std::filesystem::canonical(
|
std::filesystem::canonical(
|
||||||
std::filesystem::path(pathFolderDirectory)))
|
std::filesystem::path(pathFolderDirectory)))
|
||||||
.append(pMesh->getLabel() + ".ply");
|
.append(pMesh->getLabel() + ".ply").string();
|
||||||
returnValue = pMesh->savePly(meshFilename);
|
returnValue = pMesh->savePly(meshFilename);
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
json[jsonLabel_meshFilename] = meshFilename;
|
json[jsonLabel_meshFilename] = meshFilename;
|
||||||
|
|
@ -238,7 +237,7 @@ public:
|
||||||
|
|
||||||
std::string jsonFilename(
|
std::string jsonFilename(
|
||||||
std::filesystem::path(pathFolderDirectory)
|
std::filesystem::path(pathFolderDirectory)
|
||||||
.append(pMesh->getLabel() + "_simScenario.json"));
|
.append(pMesh->getLabel() + "_simScenario.json").string());
|
||||||
std::ofstream jsonFile(jsonFilename);
|
std::ofstream jsonFile(jsonFilename);
|
||||||
jsonFile << json;
|
jsonFile << json;
|
||||||
std::cout << "Saved simulation job as:" << jsonFilename << std::endl;
|
std::cout << "Saved simulation job as:" << jsonFilename << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ void TopologyEnumerator::computeValidPatterns(
|
||||||
if (debugIsOn) {
|
if (debugIsOn) {
|
||||||
// Export all valid edges in a ply
|
// Export all valid edges in a ply
|
||||||
patternAllValidEdges.savePly(
|
patternAllValidEdges.savePly(
|
||||||
std::filesystem::path(resultsPath).append("allValidEdges.ply"));
|
std::filesystem::path(resultsPath).append("allValidEdges.ply").string());
|
||||||
}
|
}
|
||||||
// statistics.numberOfValidEdges = validEdges.size();
|
// statistics.numberOfValidEdges = validEdges.size();
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ std::vector<vcg::Point2i> TopologyEnumerator::getValidEdges(
|
||||||
patternDuplicateEdges, p0, p1);
|
patternDuplicateEdges, p0, p1);
|
||||||
}
|
}
|
||||||
patternDuplicateEdges.savePly(
|
patternDuplicateEdges.savePly(
|
||||||
std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply"));
|
std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply").string());
|
||||||
}
|
}
|
||||||
statistics.numberOfDuplicateEdges = duplicateEdges.size();
|
statistics.numberOfDuplicateEdges = duplicateEdges.size();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ private:
|
||||||
const size_t &numberOfDesiredEdges) const;
|
const size_t &numberOfDesiredEdges) const;
|
||||||
std::vector<vcg::Point2i>
|
std::vector<vcg::Point2i>
|
||||||
getValidEdges(const std::vector<size_t> &numberOfNodesPerSlot,
|
getValidEdges(const std::vector<size_t> &numberOfNodesPerSlot,
|
||||||
const std::filesystem::__cxx11::path &resultsPath,
|
const std::filesystem::path &resultsPath,
|
||||||
const FlatPatternGeometry &patternGeometryAllEdges,
|
const FlatPatternGeometry &patternGeometryAllEdges,
|
||||||
const std::vector<vcg::Point2i> &allPossibleEdges);
|
const std::vector<vcg::Point2i> &allPossibleEdges);
|
||||||
std::unordered_set<size_t> computeDuplicateEdges();
|
std::unordered_set<size_t> computeDuplicateEdges();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ void VCGTriMesh::loadFromPlyFile(const std::string &filename) {
|
||||||
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_EDGEINDEX;
|
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_EDGEINDEX;
|
||||||
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_FACEINDEX;
|
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_FACEINDEX;
|
||||||
if (nanoply::NanoPlyWrapper<VCGTriMesh>::LoadModel(
|
if (nanoply::NanoPlyWrapper<VCGTriMesh>::LoadModel(
|
||||||
std::filesystem::absolute(filename).c_str(), *this, mask) != 0) {
|
std::filesystem::absolute(filename).string().c_str(), *this, mask) != 0) {
|
||||||
std::cout << "Could not load tri mesh" << std::endl;
|
std::cout << "Could not load tri mesh" << std::endl;
|
||||||
}
|
}
|
||||||
vcg::tri::UpdateTopology<VCGTriMesh>::FaceFace(*this);
|
vcg::tri::UpdateTopology<VCGTriMesh>::FaceFace(*this);
|
||||||
|
|
@ -57,7 +57,7 @@ bool VCGTriMesh::savePly(const std::string plyFilename) {
|
||||||
VCGTriMesh::VCGTriMesh() {}
|
VCGTriMesh::VCGTriMesh() {}
|
||||||
|
|
||||||
VCGTriMesh::VCGTriMesh(const std::string &filename) {
|
VCGTriMesh::VCGTriMesh(const std::string &filename) {
|
||||||
const std::string extension = std::filesystem::path(filename).extension();
|
const std::string extension = std::filesystem::path(filename).extension().string();
|
||||||
if (extension == ".ply") {
|
if (extension == ".ply") {
|
||||||
loadFromPlyFile(filename);
|
loadFromPlyFile(filename);
|
||||||
} else if (extension == ".obj") {
|
} else if (extension == ".obj") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue