NuTo
Numerics Tool
DifferentialOperators.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include "nuto/base/Exception.h"
5 
6 namespace NuTo
7 {
8 
9 namespace Nabla
10 {
11 struct Interface
12 {
13  virtual Eigen::MatrixXd operator()(const Eigen::MatrixXd& dNdX) const = 0;
14 };
15 
17 {
18  Eigen::MatrixXd operator()(const Eigen::MatrixXd& dNdX) const override
19  {
20  return dNdX.transpose();
21  }
22 };
23 
24 struct Strain : Interface
25 {
26  Eigen::MatrixXd operator()(const Eigen::MatrixXd& dNdX) const override
27  {
28  const int dim = dNdX.cols();
29  const int numNodes = dNdX.rows();
30  switch (dim)
31  {
32  case 1:
33  return dNdX.transpose();
34  case 2:
35  {
36  Eigen::MatrixXd B = Eigen::MatrixXd::Zero(3, numNodes * 2);
37  for (int iNode = 0, iColumn = 0; iNode < numNodes; ++iNode, iColumn += 2)
38  {
39  double dNdXx = dNdX(iNode, 0);
40  double dNdXy = dNdX(iNode, 1);
41 
42  B(0, iColumn) = dNdXx;
43  B(1, iColumn + 1) = dNdXy;
44  B(2, iColumn) = dNdXy;
45  B(2, iColumn + 1) = dNdXx;
46  }
47  return B;
48  }
49  case 3:
50  {
51  Eigen::MatrixXd B = Eigen::MatrixXd::Zero(6, numNodes * 3);
52  for (int iNode = 0, iColumn = 0; iNode < numNodes; ++iNode, iColumn += 3)
53  {
54  double dNdXx = dNdX(iNode, 0);
55  double dNdXy = dNdX(iNode, 1);
56  double dNdXz = dNdX(iNode, 2);
57 
58  /* according to Jirásek
59  *
60  * +0 +1 +2
61  * -------------
62  * 0 | dx 0 0 | - e_x
63  * 1 | 0 dy 0 | - e_y
64  * 2 | 0 0 dz | - e_z
65  * 3 | 0 dz dy | - g_yz
66  * 4 | dz 0 dx | - g_xz
67  * 5 | dy dx 0 | - g_xy
68  * -------------
69  */
70 
71 
72  B(0, iColumn) = dNdXx;
73  B(1, iColumn + 1) = dNdXy;
74  B(2, iColumn + 2) = dNdXz;
75 
76  B(3, iColumn + 1) = dNdXz;
77  B(3, iColumn + 2) = dNdXy;
78 
79  B(4, iColumn) = dNdXz;
80  B(4, iColumn + 2) = dNdXx;
81 
82  B(5, iColumn) = dNdXy;
83  B(5, iColumn + 1) = dNdXx;
84  }
85  return B;
86  }
87  default:
88  throw Exception(__PRETTY_FUNCTION__, "c'mon.");
89  }
90  }
91 };
92 } /* B */
93 } /* NuTo */
Definition: DifferentialOperators.h:11
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
virtual Eigen::MatrixXd operator()(const Eigen::MatrixXd &dNdX) const =0
Eigen::MatrixXd operator()(const Eigen::MatrixXd &dNdX) const override
Definition: DifferentialOperators.h:26
Definition: DifferentialOperators.h:16
Definition: Exception.h:6
Definition: DifferentialOperators.h:24
Eigen::MatrixXd operator()(const Eigen::MatrixXd &dNdX) const override
Definition: DifferentialOperators.h:18
constexpr int dim
Definition: ConstraintNodeToElement2D.cpp:24