Refactored code to compile under visual studio.

This commit is contained in:
iasonmanolas 2021-02-04 14:58:41 +02:00
parent 8f9b5c2c20
commit 2599d47261
12 changed files with 40 additions and 34 deletions

View File

@ -3,6 +3,7 @@
#include <assert.h>
#include <cmath>
#include <iostream>
#include <string>
struct RectangularBeamDimensions {
inline static std::string name{"Rectangular"};

View File

@ -19,7 +19,7 @@ void FormFinder::runUnitTests() {
// const size_t spanGridSize = 11;
// mesh.createSpanGrid(spanGridSize);
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;
fixedVertices[0] = std::unordered_set<DoFType>{0, 1, 2, 3};
fixedVertices[beam.VN() - 1] = std::unordered_set<DoFType>{1, 2};
@ -50,7 +50,7 @@ void FormFinder::runUnitTests() {
simpleBeam_simulationResults.save();
const std::string simpleBeamGroundOfTruthBinaryFilename =
std::filesystem::path(groundOfTruthFolder)
.append("SimpleBeam_displacements.eigenBin");
.append("SimpleBeam_displacements.eigenBin").string();
assert(std::filesystem::exists(
std::filesystem::path(simpleBeamGroundOfTruthBinaryFilename)));
Eigen::MatrixXd simpleBeam_groundOfTruthDisplacements;
@ -211,7 +211,7 @@ void FormFinder::reset() {
history.clear();
constrainedVertices.clear();
rigidSupports.clear();
pMesh.release();
pMesh.reset();
plotYValues.clear();
plotHandle.reset();
checkedForMaximumMoment = false;
@ -219,6 +219,7 @@ void FormFinder::reset() {
externalMomentsNorm = 0;
mSettings.drawingStep = 1;
Dt = mSettings.Dtini;
numOfDampings=0;
}
VectorType FormFinder::computeDisplacementDifferenceDerivative(
@ -793,8 +794,8 @@ void FormFinder::updateResidualForcesOnTheFly(
std::vector<std::pair<int, Vector6d>>(4, {-1, Vector6d()}));
// omp_lock_t writelock;
// omp_init_lock(&writelock);
#pragma omp parallel for schedule(static) num_threads(8)
for (size_t ei = 0; ei < pMesh->EN(); ei++) {
//#pragma omp parallel for //schedule(static) num_threads(8)
for (int ei = 0; ei < pMesh->EN(); ei++) {
const EdgeType &e = pMesh->edge[ei];
const SimulationMesh::VertexType &ev_j = *e.cV(0);
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);
if (mSettings.beVerbose) {
if (mSettings.beVerbose ) {
std::cout << "Executing simulation for mesh with:" << pMesh->VN()
<< " nodes and " << pMesh->EN() << " elements." << std::endl;
}
computeRigidSupports();
if (mSettings.shouldDraw) {
if (mSettings.shouldDraw ) {
initPolyscope();
polyscope::registerCurveNetwork(
meshPolyscopeLabel, pMesh->getEigenVertices(), pMesh->getEigenEdges());
@ -1974,7 +1976,7 @@ mesh->currentTotalPotentialEnergykN*/
} else if (std::isnan(pMesh->currentTotalKineticEnergy)) {
results.converged = false;
} else if (mSettings.beVerbose) {
} else if (mSettings.beVerbose ) {
auto t2 = std::chrono::high_resolution_clock::now();
double simulationDuration =
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();

View File

@ -23,6 +23,14 @@ public:
: fs_(), is_first_(true), separator_(separator), escape_seq_("\""),
special_chars_("\"") {
fs_.exceptions(std::ios::failbit | std::ios::badbit);
if (!std::filesystem::exists(std::filesystem::path("../OptimizationResults")
.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);
}

View File

@ -183,21 +183,11 @@ bool VCGEdgeMesh::loadPly(const std::string plyFilename) {
assert(std::filesystem::exists(usedPath));
this->Clear();
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)) {
std::cerr << "Error: Unable to open " + usedPath << std::endl;
return false;
}
}
getEdges(eigenEdges);
getVertices(eigenVertices);
vcg::tri::UpdateTopology<VCGEdgeMesh>::VertexEdge(*this);

View File

@ -53,7 +53,6 @@ public:
Eigen::MatrixX3d getNormals() const;
bool loadUsingDefaultLoader(const std::string &plyFilename);
bool hasProperty(const std::vector<nanoply::PlyProperty> &v,
const std::string &propertyName);

View File

@ -38,6 +38,12 @@ SimulationMesh::SimulationMesh(VCGEdgeMesh &mesh) {
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) {
vcg::tri::MeshAssert<FlatPattern>::VertexNormalNormalized(pattern);

View File

@ -23,6 +23,7 @@ private:
public:
PerEdgeAttributeHandle<Element> elements;
PerVertexAttributeHandle<Node> nodes;
~SimulationMesh();
SimulationMesh(FlatPattern &pattern);
SimulationMesh(ConstVCGEdgeMesh &edgeMesh);
SimulationMesh(SimulationMesh &elementalMesh);

View File

@ -75,7 +75,7 @@ struct SimulationResultsReporter {
createPlots(simulationResult.history, simulationResultPath.string(),
graphSuffix);
writeStatistics(simulationResult, simulationResultPath);
writeStatistics(simulationResult, simulationResultPath.string());
}
}
static void createPlot(const std::string &xLabel, const std::string &yLabel,

View File

@ -187,16 +187,15 @@ public:
if (json.contains(jsonLabel_constrainedVertices)) {
constrainedVertices =
// auto conV =
std::unordered_map<VertexIndex, std::unordered_set<int>>(
json[jsonLabel_constrainedVertices]);
json[jsonLabel_constrainedVertices].get<std::unordered_map<VertexIndex, std::unordered_set<int>>>();
std::cout << "Loaded constrained vertices. Number of constrained "
"vertices found:"
<< constrainedVertices.size() << std::endl;
}
if (json.contains(jsonLabel_nodalForces)) {
auto f = std::unordered_map<VertexIndex, std::array<double, 6>>(
json[jsonLabel_nodalForces]);
auto f (
json[jsonLabel_nodalForces].get<std::unordered_map<VertexIndex, std::array<double, 6>>>());
for (const auto &forces : f) {
nodalExternalForces[forces.first] = Vector6d(forces.second);
}
@ -221,7 +220,7 @@ public:
std::filesystem::absolute(
std::filesystem::canonical(
std::filesystem::path(pathFolderDirectory)))
.append(pMesh->getLabel() + ".ply");
.append(pMesh->getLabel() + ".ply").string();
returnValue = pMesh->savePly(meshFilename);
nlohmann::json json;
json[jsonLabel_meshFilename] = meshFilename;
@ -238,7 +237,7 @@ public:
std::string jsonFilename(
std::filesystem::path(pathFolderDirectory)
.append(pMesh->getLabel() + "_simScenario.json"));
.append(pMesh->getLabel() + "_simScenario.json").string());
std::ofstream jsonFile(jsonFilename);
jsonFile << json;
std::cout << "Saved simulation job as:" << jsonFilename << std::endl;

View File

@ -130,7 +130,7 @@ void TopologyEnumerator::computeValidPatterns(
if (debugIsOn) {
// Export all valid edges in a ply
patternAllValidEdges.savePly(
std::filesystem::path(resultsPath).append("allValidEdges.ply"));
std::filesystem::path(resultsPath).append("allValidEdges.ply").string());
}
// statistics.numberOfValidEdges = validEdges.size();
@ -357,7 +357,7 @@ std::vector<vcg::Point2i> TopologyEnumerator::getValidEdges(
patternDuplicateEdges, p0, p1);
}
patternDuplicateEdges.savePly(
std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply"));
std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply").string());
}
statistics.numberOfDuplicateEdges = duplicateEdges.size();

View File

@ -156,7 +156,7 @@ private:
const size_t &numberOfDesiredEdges) const;
std::vector<vcg::Point2i>
getValidEdges(const std::vector<size_t> &numberOfNodesPerSlot,
const std::filesystem::__cxx11::path &resultsPath,
const std::filesystem::path &resultsPath,
const FlatPatternGeometry &patternGeometryAllEdges,
const std::vector<vcg::Point2i> &allPossibleEdges);
std::unordered_set<size_t> computeDuplicateEdges();

View File

@ -11,7 +11,7 @@ void VCGTriMesh::loadFromPlyFile(const std::string &filename) {
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_EDGEINDEX;
mask |= nanoply::NanoPlyWrapper<VCGTriMesh>::IO_FACEINDEX;
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;
}
vcg::tri::UpdateTopology<VCGTriMesh>::FaceFace(*this);
@ -57,7 +57,7 @@ bool VCGTriMesh::savePly(const std::string plyFilename) {
VCGTriMesh::VCGTriMesh() {}
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") {
loadFromPlyFile(filename);
} else if (extension == ".obj") {