Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
TrialProd.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_TrialProd_H_
9#define model_TrialProd_H_
10
11#include <utility>
12#include <TypeTraits.h>
13#include <Simplex.h>
14#include <TrialBase.h>
15#include <TrialGrad.h>
16#include <TrialExpressionBase.h>
17#include <Constant.h>
18
19#include <EvalFunction.h>
20#include <memory>
21#include <stdexcept>
22
23namespace model
24{
25
26 template<int rows1,int cols1, int rows2>
28 {
29 static_assert(cols1==rows2,"YOU ARE MULTIPLYING TrialExpressionBaseS WITH DIFFERENT SIZE.");
30 constexpr static int rows=rows1;
31 };
32
33 template<int rows2>
34 struct TrialProdRows<1,1,rows2>
35 {
36 constexpr static int rows=rows2;
37 };
38
39 template<>
40 struct TrialProdRows<1,1,1>
41 {
42 constexpr static int rows=1;
43 };
44
45 template <typename T1, typename T2>
46 struct TrialProd :
47 public TrialExpressionBase<TrialProd<T1,T2> >
48 {
49 typedef typename T2::TrialFunctionType TrialFunctionType;
56 constexpr static int cols=T2::cols;
57
58 typedef Eigen::Matrix<double,rows,dofPerElement> ShapeFunctionMatrixType;
59 typedef Eigen::Matrix<double,rows*dim,dofPerElement> ShapeFunctionGradMatrixType;
60 typedef Eigen::Matrix<double,rows,1> EvalMatrixType;
61
62 const std::shared_ptr<T1> op1;
63 const std::shared_ptr<T2> op2;
64 TrialProd(std::shared_ptr<T1> x, std::shared_ptr<T2> y) :
65 op1(std::move(x)), op2(std::move(y))
66 {
67 if(!op1 || !op2)
68 {
69 throw std::invalid_argument("Null FEM expression operand.");
70 }
71 }
72
74 const BaryType& bary) const
75 {
76 return (*op1)(ele,bary)*op2->sfm(ele,bary);
77 }
78
80 const BaryType& bary) const
81 {
82 const auto t1((*op1)(ele,bary));
83 if constexpr(T1::rows==1 && T1::cols==1)
84 {
85 if constexpr(std::is_arithmetic_v<decltype(t1)>)
86 {
87 return t1*op2->sfmGrad(ele,bary);
88 }
89 else
90 {
91 return t1(0,0)*op2->sfmGrad(ele,bary);
92 }
93 }
94 else
95 {
96 Eigen::Matrix<double,T1::rows*dim,TrialGrad<T2>::rows> t1Ex(Eigen::Matrix<double,T1::rows*dim,TrialGrad<T2>::rows>::Zero());
97 for(int I=0;I<T1::rows;++I)
98 {
99 for(int J=0;J<T1::cols;++J)
100 {
101 for(int d=0;d<dim;++d)
102 {
103 const int i(I*dim+d);
104 const int j(J*dim+d);
105 t1Ex(i,j)=t1(I,J);
106 }
107 }
108 }
109 return t1Ex*op2->sfmGrad(ele,bary);
110 }
111 }
112 const auto& field() const
113 {
114 return op2->field();
115 }
116
117 };
118
119 template<class E,class T, std::enable_if_t<std::is_base_of_v<EvalFunction<E>,E> && std::is_base_of_v<TrialExpressionBase<T>,T>,int> = 0>
120 auto operator*(const std::shared_ptr<E>& e,const std::shared_ptr<T>& t)
121 {
122 return std::make_shared<TrialProd<E,T>>(e,t);
123 }
124 template<class T>
125 auto operator*(double c,const std::shared_ptr<T>& t)
126 {
127 return make_constant(c)*t;
128 }
129 template<int R,int C,class T>
130 auto operator*(const Eigen::Matrix<double,R,C>& c,const std::shared_ptr<T>& t)
131 {
132 return make_constant(c)*t;
133 }
134
135}
136#endif
static constexpr int rows
Definition TrialGrad.h:37
The q vector I
final point of the source segment t
c
Definition int_R.m:15
x
Definition int_R.m:12
auto operator*(const std::shared_ptr< BilinearForm< T1, T2 > > &f, const IntegrationDomain< FE, D, Q, Rule > &dom)
auto make_constant(const Eigen::Matrix< double, rows, cols > &c)
Definition Constant.h:44
Eigen::Matrix< double, rows, 1 > EvalMatrixType
Definition TrialProd.h:60
ShapeFunctionMatrixType sfm(const ElementType &ele, const BaryType &bary) const
Definition TrialProd.h:73
TypeTraits< TrialFunctionType >::BaryType BaryType
Definition TrialProd.h:52
ShapeFunctionGradMatrixType sfmGrad(const ElementType &ele, const BaryType &bary) const
Definition TrialProd.h:79
Eigen::Matrix< double, rows, dofPerElement > ShapeFunctionMatrixType
Definition TrialProd.h:58
const auto & field() const
Definition TrialProd.h:112
TrialBase< TrialFunctionType > TrialBaseType
Definition TrialProd.h:50
Eigen::Matrix< double, rows *dim, dofPerElement > ShapeFunctionGradMatrixType
Definition TrialProd.h:59
const std::shared_ptr< MobileGradType > op2
Definition TrialProd.h:63
const std::shared_ptr< FluxMatrix< dim > > op1
Definition TrialProd.h:62
TypeTraits< TrialFunctionType >::ElementType ElementType
Definition TrialProd.h:51
MobileGradType::TrialFunctionType TrialFunctionType
Definition TrialProd.h:49
TrialProd(std::shared_ptr< T1 > x, std::shared_ptr< T2 > y)
Definition TrialProd.h:64
static constexpr int rows
Definition TrialProd.h:42
static constexpr int rows
Definition TrialProd.h:30
int j
INEXACT REAL t1
int i
int e