PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
fracture.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include "fracture.h"
12#include "util/io.h"
13#include "util/parallelUtil.h"
14#include <taskflow/taskflow/taskflow.hpp>
15#include <taskflow/taskflow/algorithm/for_each.hpp>
16
17
19
20geometry::Fracture::Fracture(const std::vector<util::Point> *nodes,
21 const std::vector<std::vector<std::size_t>> *neighbor_list) {
22
23 std::size_t n = nodes->size();
24 d_fracture.resize(n);
25
26 tf::Executor executor(util::parallel::getNThreads());
27 tf::Taskflow taskflow;
28
29 taskflow.for_each_index(
30 (std::size_t) 0, n, (std::size_t) 1, [this, &nodes, &neighbor_list, n](std::size_t i) {
31 // get neighborlist of node i if neighborlist is provided
32 std::vector<size_t> neighs;
33 if (neighbor_list != nullptr)
34 neighs = (*neighbor_list)[i];
35
36 // compute number of neighbors
37 size_t ns = n;
38 if (!neighs.empty())
39 ns = neighs.size();
40
41 size_t s = ns / 8;
42 if (s * 8 < ns)
43 s++;
44 d_fracture[i] = std::vector<uint8_t>(s, uint8_t(0));
45 }
46 ); // for_each
47
48 executor.run(taskflow).get();
49}
50
51void geometry::Fracture::setBondState(const std::size_t &i, const std::size_t &j,
52 const bool &state) {
53
54 // to set i^th bit as true of integer a,
55 // a |= 1UL << (i % 8)
56
57 // to set i^th bit as false of integer a,
58 // a &= ~(1UL << (i % 8))
59
60 state ? (d_fracture[i][j / 8] |= 1UL << (j % 8))
61 : (d_fracture[i][j / 8] &= ~(1UL << (j % 8)));
62}
63
64bool geometry::Fracture::getBondState(const size_t &i, const size_t &j) const {
65
66 auto bond = d_fracture[i][j / 8];
67 return bond >> (j % 8) & 1UL;
68}
69
70const std::vector<uint8_t> &geometry::Fracture::getBonds(const std::size_t &i)
71const {
72 return d_fracture[i];
73}
74std::vector<uint8_t> &geometry::Fracture::getBonds(const std::size_t &i) {
75 return d_fracture[i];
76}
77
78std::string geometry::Fracture::printStr(int nt, int lvl) const {
79
80 auto tabS = util::io::getTabS(nt);
81 std::ostringstream oss;
82 oss << tabS << "------- Fracture --------" << std::endl << std::endl;
83 oss << tabS << "Num of outer fracture data = " << d_fracture.size() <<
84 std::endl;
85 oss << tabS << std::endl;
86
87 return oss.str();
88}
void setBondState(const std::size_t &i, const std::size_t &j, const bool &state)
Sets the bond state.
Definition fracture.cpp:51
const std::vector< uint8_t > & getBonds(const std::size_t &i) const
Returns the list of bonds of node i.
Definition fracture.cpp:70
Fracture()
Constructor.
Definition fracture.cpp:18
bool getBondState(const std::size_t &i, const std::size_t &j) const
Read bond state.
Definition fracture.cpp:64
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition fracture.cpp:78
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
unsigned int getNThreads()
Get number of threads to be used by taskflow.