forked from jpanetta/ElasticRods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossSection.cc
59 lines (47 loc) · 2.04 KB
/
CrossSection.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <nlohmann/json.hpp>
#include <fstream>
#include <algorithm>
#include <string>
#include "CrossSection.hh"
#include <MeshFEM/Geometry.hh>
#include <MeshFEM/Triangulate.h>
#include "cross_sections/I.hh"
#include "cross_sections/L.hh"
#include "cross_sections/Plus.hh"
#include "cross_sections/Ellipse.hh"
#include "cross_sections/Rectangle.hh"
using json = nlohmann::json;
std::unique_ptr<CrossSection> CrossSection::load(const std::string &path) {
std::ifstream inFile(path);
if (!inFile.is_open()) throw std::runtime_error("Couldn't open " + path);
json config;
inFile >> config;
return construct(config.at("type").get<std::string>(),
config.at("young").get<double>(),
config.at("poisson").get<double>(),
config.at("params").get<std::vector<Real>>());
}
std::unique_ptr<CrossSection> CrossSection::construct(std::string type, Real E, Real nu, const std::vector<Real> ¶ms) {
std::transform(type.begin(), type.end(), type.begin(), ::toupper);
std::unique_ptr<CrossSection> c;
if (type == "I") { c = std::make_unique<CrossSections::I >(); }
else if (type == "L") { c = std::make_unique<CrossSections::L >(); }
else if (type == "+") { c = std::make_unique<CrossSections::Plus >(); }
else if (type == "-") { c = std::make_unique<CrossSections::Rectangle>(); }
else if (type == "RECTANGLE") { c = std::make_unique<CrossSections::Rectangle>(); }
else if (type == "ELLIPSE") { c = std::make_unique<CrossSections::Ellipse >(); }
else throw std::runtime_error("Unknown cross-section " + type);
c->E = E;
c->nu = nu;
c->setParams(params);
return c;
}
CrossSection::VRep CrossSection::interior(Real triArea) const {
auto bdry = boundary(true);
BBox<Point2D> bb(bdry.first);
triArea *= bb.volume();
VRep result;
triangulatePSLC(bdry.first, bdry.second, std::vector<Vector2D>(),
result.first, result.second, triArea, "Q");
return result;
}