23#include <taskflow/taskflow/taskflow.hpp>
24#include <taskflow/taskflow/algorithm/for_each.hpp>
27 : d_numNodes(0), d_numElems(0), d_eType(1), d_eNumVertex(0), d_numDofs(0),
28 d_h(0.), d_dim(dim), d_encDataPopulated(false), d_needEncData(false),
32 : d_numNodes(0), d_numElems(0), d_eType(1), d_eNumVertex(0), d_numDofs(0),
33 d_h(deck->d_h), d_dim(deck->d_dim),
34 d_spatialDiscretization(deck->d_spatialDiscretization),
35 d_filename(deck->d_filename), d_encDataPopulated(false),
36 d_needEncData(deck->d_populateElementNodeConnectivity),
44 std::cerr <<
"Error: Spatial discretization type not known. Check input "
46 std::cerr << deck->
printStr() <<
"\n";
51 std::cerr <<
"Error: Check Dimension in input data.\n";
56 std::cerr <<
"Error: Filename for mesh data not specified.\n";
80 std::cerr <<
"Error: Currently only '.csv', '.msg', and '.vtu' "
81 "files are supported for reading mesh.\n";
85 if (d_spatialDiscretization !=
"finite_difference" and file_type == 0) {
87 std::cerr <<
"Error: For discretization = " << d_spatialDiscretization
88 <<
" .vtu or .msh mesh file is required.\n";
94 if (d_spatialDiscretization ==
"finite_difference")
100 else if (file_type == 1) {
102 &d_enc, &d_nec, &d_vol,
false);
103 d_encDataPopulated =
true;
105 else if (file_type == 2) {
121 bool found_volume_data =
false;
127 if (!found_volume_data)
134 if (!is_fd || !found_volume_data) {
137 d_encDataPopulated =
true;
145 d_numNodes = d_nodes.size();
147 d_numDofs = d_numNodes * d_dim;
152 if (d_fix.size() != d_numNodes)
153 d_fix = std::vector<uint8_t>(d_nodes.size(), uint8_t(0));
158 bool compute_vol =
false;
159 if (is_fd and d_vol.empty()) compute_vol =
true;
163 if (d_spatialDiscretization ==
"weak_finite_element")
182 for (
const auto &v : d_vol) {
184 if (v < 0.01 * std::pow(d_h, d_dim)) {
186 std::cerr <<
"Error: Check nodal volume " << v
187 <<
" is less than " << 0.01 * std::pow(d_h, d_dim)
188 <<
", Node = " << counter
189 <<
" at position = " << d_nodes[counter].printStr() <<
"\n"
190 <<
"mesh filename = " << filename <<
"\n"
191 << printStr() <<
"\n";
199 if (d_needEncData and (!d_encDataPopulated or d_enc.empty()))
200 readElementData(d_filename);
205 if (d_encDataPopulated and !d_enc.empty()) {
210 util::io::log(
"Mesh: Reading element-node connectivity data.\n");
221 std::cerr <<
"Error: Currently only '.csv', '.msg', and '.vtu' "
222 "files are supported for reading mesh.\n";
226 if (file_type == 0) {
227 std::cerr <<
"Error: readElementData() requires file to be either "
228 ".vtu or .msh mesh file.\n";
232 if (file_type == 1) {
236 d_encDataPopulated =
true;
239 else if (file_type == 2) {
243 d_encDataPopulated =
true;
263 if (d_nec.size() != d_numNodes || d_enc.empty()) {
264 std::cerr <<
"Error: Can not compute nodal volume for given finite "
265 "element mesh as the element-node connectivity data is "
273 std::cout <<
"\n-------- Node data ----------\n";
275 std::cout <<
"\n-------- Element data ----------\n";
282 d_vol.resize(d_numNodes);
285 tf::Taskflow taskflow;
287 taskflow.for_each_index(
288 (std::size_t) 0, this->d_numNodes, (std::size_t) 1, [
this, quads](std::size_t i) {
291 for (
auto e : this->d_nec[i]) {
293 std::vector<size_t> e_ns = this->getElementConnectivity(e);
297 for (
size_t l = 0; l < e_ns.size(); l++)
302 std::cerr <<
"Error: Check node element connectivity.\n";
307 std::vector<util::Point> e_nodes;
309 e_nodes.emplace_back(this->d_nodes[k]);
312 double vol = quads->
elemSize(e_nodes);
317 std::vector<fe::QuadData> qds = quads->
getQuadDatas(e_nodes);
321 v += qd.d_shapes[loc_i] * factor * qd.d_w;
329 executor.run(taskflow).get();
333 std::vector<double> p1(3,0.);
334 std::vector<double> p2(3,0.);
335 for (
const auto& x : d_nodes) {
350 d_bbox = std::make_pair(p1, p2);
356 if (d_nodes.size() < 2) {
361 guess = (d_nodes[0] - d_nodes[1]).length();
362 for (
size_t i = 0; i < d_nodes.size(); i++)
363 for (
size_t j = 0; j < d_nodes.size(); j++)
365 double val = d_nodes[i].dist(d_nodes[j]);
369 std::cout <<
"Check nodes are too close = "
370 << util::io::printStr<util::Point>({d_nodes[i],
373 std::cout <<
"Distance = " << val <<
", guess = " << guess <<
"\n";
394 flag ? (d_fix[i] |= 1UL << dof) : (d_fix[i] &= ~(1UL << dof));
398 d_enc.shrink_to_fit();
401 d_nec.shrink_to_fit();
407 std::ostringstream oss;
408 oss << tabS <<
"------- Mesh --------" << std::endl << std::endl;
409 oss << tabS <<
"Dimension = " << d_dim << std::endl;
410 oss << tabS <<
"Spatial discretization type = " << d_spatialDiscretization << std::endl;
411 oss << tabS <<
"Mesh size = " << d_h << std::endl;
412 oss << tabS <<
"Num nodes = " << d_numNodes << std::endl;
413 oss << tabS <<
"Num elements = " << d_numElems << std::endl;
414 oss << tabS <<
"Element type = " << d_eType << std::endl;
415 oss << tabS <<
"Num nodes per element = " << d_eNumVertex << std::endl;
416 oss << tabS <<
"Num nodal vol = " << d_vol.size() << std::endl;
417 oss << tabS <<
"Bounding box: " << std::endl;
419 oss << tabS << std::endl;
A base class which provides methods to map points to/from reference element and to compute quadrature...
virtual std::vector< fe::QuadData > getQuadDatas(const std::vector< util::Point > &nodes)=0
Get vector of quadrature data.
virtual double elemSize(const std::vector< util::Point > &nodes)=0
Returns the size of element (length in 1-d, area in 2-d, volume in 3-d element)
std::string d_spatialDiscretization
Tag for spatial discretization type.
bool readElementData(const std::string &filename)
Reads element-node connectivity data from file. This function is meant for cases when mesh was create...
size_t d_dim
Dimension of the mesh.
void computeBBox()
Compute the bounding box
void clearElementData()
Clear element-node connectivity data.
void computeMeshSize()
Compute the mesh size.
Mesh(size_t dim=0)
Constructor.
std::string d_filename
Filename to read mesh data.
void setFixity(const size_t &i, const unsigned int &dof, const bool &flag)
Set the fixity to free (0) or fixed (1)
void computeVol()
Compute the nodal volume.
void createData(const std::string &filename, bool ref_config=false)
Reads mesh data from the file and populates other data.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
A class for mapping and quadrature related operations for bi-linear quadrangle element.
A class for mapping and quadrature related operations for linear tetrahedron element.
A class for mapping and quadrature related operations for linear triangle element.
static int vtk_map_element_to_num_nodes[16]
Map from element type to number of nodes (for vtk)
static const int vtk_type_triangle
Integer flag for triangle element.
static const int vtk_type_quad
Integer flag for quad element.
static const int vtk_type_tetra
Integer flag for tetrahedron element.
void readVtuFileCells(const std::string &filename, size_t dim, size_t &element_type, size_t &num_elem, std::vector< size_t > *enc, std::vector< std::vector< size_t > > *nec)
Reads cell data, i.e. element-node connectivity and node-element connectivity.
void readMshFileCells(const std::string &filename, size_t dim, size_t &element_type, size_t &num_elem, std::vector< size_t > *enc, std::vector< std::vector< size_t > > *nec)
Reads cell data, i.e. element-node connectivity and node-element connectivity.
bool readVtuFilePointData(const std::string &filename, const std::string &tag, std::vector< uint8_t > *data)
Reads data of specified tag from the vtu file.
void readVtuFileNodes(const std::string &filename, size_t dim, std::vector< util::Point > *nodes, bool ref_config=false)
Reads nodal coordinates.
void readCsvFile(const std::string &filename, size_t dim, std::vector< util::Point > *nodes, std::vector< double > *volumes)
Reads mesh data into node file and element file.
void readMshFile(const std::string &filename, size_t dim, std::vector< util::Point > *nodes, size_t &element_type, size_t &num_elem, std::vector< size_t > *enc, std::vector< std::vector< size_t > > *nec, std::vector< double > *volumes, bool is_fd=false)
Reads mesh data into node file and element file.
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
std::string getTabS(int nt)
Returns tab spaces of given size.
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
std::string getExtensionFromFile(std::string const &filename)
Get extension from the filename.
void log(std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
Global method to log the message.
unsigned int getNThreads()
Get number of threads to be used by taskflow.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Structure to read and store mesh related input data.
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.