Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
EvalExpression.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_EvalExpression_H_
9#define model_EvalExpression_H_
10
11#include <utility>
12#include <EvalFunction.h>
13#include <memory>
14#include <stdexcept>
15
16namespace model
17{
18
19 template<typename TrialExpressionType>
20 struct EvalExpression : public EvalFunction<EvalExpression<TrialExpressionType>>
21 {
22 typedef typename TrialExpressionType::TrialFunctionType TrialFunctionType;
23 constexpr static int rows=TrialExpressionType::rows;
24 constexpr static int cols=TrialExpressionType::cols;
25
26 typedef Eigen::Matrix<double,rows,1> EvalMatrixType;
27
32
34
35 const std::shared_ptr<TrialExpressionType> trialExp;
36
37 explicit EvalExpression(std::shared_ptr<TrialExpressionType> te) : trialExp(std::move(te))
38 {
39 if(!trialExp)
40 {
41 throw std::invalid_argument("Null FEM expression operand.");
42 }
43 }
44
46 const BaryType& bary) const
47 {
48 return trialExp->sfm(ele,bary)*field().dofs(ele);
49 }
50
51 EvalMatrixType operator()(const Eigen::Matrix<double,dim,1>& P,
52 const Simplex<dim,dim>* const guess) const
53 {
54 const std::pair<bool,const ElementType*> temp(field().fe().searchWithGuess(P,guess));
55 if(temp.first)
56 {
57 auto bary(temp.second->simplex.pos2bary(P));
58 for(int d=0; d<dim+1; d++)
59 {
60 if(bary(d)<0.0)
61 {
62 bary(d)=0.0;
63 }
64 if(bary(d)>1.0)
65 {
66 bary(d)=1.0;
67 }
68 }
69
70 return trialExp->sfm(*(temp.second),bary)*field().dofs(*(temp.second));
71 }
72 else
73 {
74 std::cout<<"WARNING: EVALUATING EXPRESSION OUTSIDE DOMAIN"<<std::endl;
75 return EvalMatrixType::Zero();
76 }
77 }
78
79 EvalMatrixType operator()(const Eigen::Matrix<double,dim,1>& P) const
80 {
81 return this->operator()(P,field().mesh().simplices().begin()->second.get());
82 }
83
85 {
86 EvalMatrixType temp(EvalMatrixType::Zero());
87 for(const auto& ele : node)
88 {
89 const Eigen::Matrix<double,dim+1,1> bary(ele->simplex.pos2bary(node.P0));
90 temp+=trialExp->sfm(*ele,bary)*field().dofs(*ele);
91 }
92 return temp/node.size();
93 }
94
95 const auto& field() const
96 {
97 return trialExp->field();
98 }
99
100 };
101
102}
103#endif
EvalMatrixType operator()(const NodeType &node) const
Eigen::Matrix< double, rows, 1 > EvalMatrixType
TypeTraits< TrialFunctionType >::BaryType BaryType
EvalMatrixType operator()(const Eigen::Matrix< double, dim, 1 > &P) const
TypeTraits< TrialFunctionType >::ElementType ElementType
TypeTraits< TrialFunctionType >::NodeType NodeType
const auto & field() const
EvalExpression(std::shared_ptr< TrialExpressionType > te)
EvalMatrixType operator()(const Eigen::Matrix< double, dim, 1 > &P, const Simplex< dim, dim > *const guess) const
EvalMatrixType operator()(const ElementType &ele, const BaryType &bary) const
ImmobileTrialFunctionType::TrialFunctionType TrialFunctionType
const std::shared_ptr< ImmobileTrialFunctionType > trialExp
vertex temp