PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
bMatrix.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 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 "bMatrix.h"
12
13fe::B::B(const std::vector<std::vector<double>> &dNdx, int dim)
14 : d_dim(dim), d_nStrain(dim == 2 ? 3 : (dim == 3 ? 6 : 1)),
15 d_nDof(dim * static_cast<int>(dNdx.size())),
16 d_data(static_cast<size_t>(d_nStrain * d_nDof), 0.) {
17 const int n = static_cast<int>(dNdx.size());
18 for (int a = 0; a < n; a++) {
19 const auto &dN = dNdx[a];
20 const int c = dim * a;
21 auto set = [&](int i, int j, double v) { d_data[i * d_nDof + j] = v; };
22
23 set(0, c, dN[0]);
24 if (dim == 1)
25 continue;
26 set(1, c + 1, dN[1]);
27 if (dim == 2) {
28 set(2, c, 0.5 * dN[1]);
29 set(2, c + 1, 0.5 * dN[0]);
30 continue;
31 }
32 set(2, c + 2, dN[2]);
33 set(3, c + 1, 0.5 * dN[2]);
34 set(3, c + 2, 0.5 * dN[1]);
35 set(4, c, 0.5 * dN[2]);
36 set(4, c + 2, 0.5 * dN[0]);
37 set(5, c, 0.5 * dN[1]);
38 set(5, c + 1, 0.5 * dN[0]);
39 }
40}
int d_nDof
Definition bMatrix.h:40
B(const std::vector< std::vector< double > > &dNdx, int dim)
Definition bMatrix.cpp:13
int dim() const
Definition bMatrix.h:31
std::vector< double > d_data
Definition bMatrix.h:41