Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SimplexReader.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, distributed under GNU GPL v2. */
2#include <SimplexReader.h>
3#include <IDreader.h>
4#include <GmshReader.h>
5
6namespace model
7{
8
9 template <int dim> auto SimplexReaderBase<dim>::nodes() const -> const NodeContainerType &
10 {
11 return *this;
12 }
13
14 template <int dim> auto SimplexReaderBase<dim>::nodes() -> NodeContainerType &
15 {
16 return *this;
17 }
18
19 template <int dim> auto SimplexReaderBase<dim>::elements() const -> const ElementContainerType &
20 {
21 return *this;
22 }
23
24 template <int dim> auto SimplexReaderBase<dim>::elements() -> ElementContainerType &
25 {
26 return *this;
27 }
28
29 template <int dim> auto SimplexReaderBase<dim>::clear() -> void
30 {
31 nodes().clear();
32 elements().clear();
33 }
34
36 {
37 return *this;
38 }
39
40 template <int dim> auto SimplexReaderBase<dim>::simplexReader() const -> const SimplexReaderBase<dim> &
41 {
42 return *this;
43 }
44
45 template <int dim>
47 -> const Eigen::Matrix<double, dim, 1> &
48 {
49 // const typename VertexReader<'N',dim+1,double>::const_iterator nIter(nodeReader.find((xID)(0)));
50 const auto nIter(nodes().find((xID)(0)));
51 assert((nIter != nodes().end()) && "MESH VERTEX NOT FOUND IN N/N_x.txt.");
52 return nIter->second;
53 }
54
55 template <int dim> auto SimplexReader<dim>::read(const int &meshID) -> void
56 {
57
58 this->clear();
59 IDreader<1, dim, double> nodeReader("N/N");
60 nodeReader.read(meshID, true);
61 for (const auto &node : nodeReader)
62 {
63 this->nodes().emplace(node.first, Eigen::Map<const Eigen::Matrix<double, dim, 1>>(node.second.data()));
64 }
65 assert(nodeReader.size() == this->nodes().size());
66
67 IDreader<1, dim + 2, size_t> elementReader("T/T");
68 elementReader.read(meshID, true);
69 for (const auto &eIter : elementReader)
70 {
71 std::set<size_t> vertices;
72 for (int d = 0; d < dim + 1; ++d)
73 {
74 vertices.insert(eIter.second[d]);
75 }
76 size_t regionID(eIter.second[dim + 1]);
77 this->elements().emplace(eIter.first, std::make_pair(typename SimplexTraits<dim, dim>::SimplexIDType(vertices), regionID));
78 }
79 // assert(elementReader.size()==this->elements().size());
80 }
81
82 template <int dim>
83 void SimplexReader<dim>::read(const std::string &meshFileName, const Eigen::Matrix<double, dim, dim> &A,
84 const Eigen::Matrix<double, dim, 1> &x0)
85 {
86 this->clear();
87 GmshReader reader(meshFileName, Eigen::Matrix3d::Identity(), Eigen::Vector3d::Zero());
88 for (const auto &node : reader.nodes())
89 {
90 this->nodes().emplace(node.first, A * (node.second.template head<dim>() - x0));
91 }
92 constexpr int linearType = dim == 3 ? 4 : (dim == 2 ? 2 : 1);
93 constexpr int quadraticType = dim == 3 ? 11 : (dim == 2 ? 9 : 8);
94 for (const auto &entry : reader.elements())
95 {
96 const auto &element = entry.second;
97 if (element.type == linearType || element.type == quadraticType)
98 {
99 if (element.nodeIDs.size() < dim + 1 || element.tags.size() < 2)
100 {
101 throw std::runtime_error("Mesh element is missing vertices or region tag");
102 }
103 std::set<size_t> vertices;
104 for (int k = 0; k <= dim; ++k)
105 {
106 vertices.insert(element.nodeIDs[k]);
107 }
108 this->elements().emplace(entry.first, std::make_pair(
109 typename SimplexTraits<dim, dim>::SimplexIDType(vertices), element.tags[1]));
110 }
111 }
112 }
113 template struct SimplexReaderBase<1>;
114 template struct SimplexReaderBase<2>;
115 template struct SimplexReaderBase<3>;
116 template struct SimplexReader<1>;
117 template struct SimplexReader<2>;
118 template struct SimplexReader<3>;
119} // namespace model
const std::map< size_t, Eigen::Vector3d > & nodes() const
const std::map< size_t, GmshElement > & elements() const
A class template.
Definition IDreader.h:55
function infiniteDisplacement syms Ax Ay Az Bx By Bz qx qy qz u L x y z real A
const Eigen::Matrix< double, dim, 1 > & get_P0(const typename SimplexTraits< dim, 0 >::SimplexIDType &xID)
SimplexReaderBase< dim > & simplexReader()
const ElementContainerType & elements() const
const NodeContainerType & nodes() const
void read(const int &meshID)
SimplexID< nVertices > SimplexIDType
int end[2]
int elements
int k
void vertices