Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
BilinearForm.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_BilinearForm_H_
9#define model_BilinearForm_H_
10
11#include <type_traits>
12#include <TrialExpressionBase.h>
13
14#include <TerminalColors.h>
15#include <memory>
16#include <stdexcept>
17
18namespace model
19{
20
21 template <typename T1,typename T2>
23 {
24
25 static_assert(std::is_same<typename T1::TrialFunctionType,typename T2::TrialFunctionType>::value,"YOU ARE CREATING A BilinearForm OF DIFFERENT TrialFunction TYPES.");
26 static_assert(T1::rows==T2::rows,"YOU ARE CREATING A BilinearForm BETWEEN A TrialExpression AND A TestExpression WITH DIFFERENT NUMBER OF ROWS");
27
30
31 typedef typename T2::TrialFunctionType TrialFunctionType;
35
40
41 typedef Eigen::Matrix<double,dofPerElement,dofPerElement> ElementMatrixType;
42
43 const std::shared_ptr<TestExpression<T1>> testExpr;
44 const std::shared_ptr<TrialExpressionType> trialExpr;
45 BilinearForm(std::shared_ptr<TestExpression<T1>> x, std::shared_ptr<T2> y) :
46 testExpr(std::move(x)), trialExpr(std::move(y))
47 {
48 if(!testExpr || !trialExpr)
49 {
50 throw std::invalid_argument("Null FEM expression operand.");
51 }
52 }
53
54 ElementMatrixType operator()(const ElementType& ele, const BaryType& bary) const
55 {
56
57 if(!(testExpr->field().sameField(field())))
58 {
59 throw std::runtime_error("Cannot assemble expressions from different FEM field instances.");
60 }
61 return testExpr->sfm(ele,bary).transpose()*trialExpr->sfm(ele,bary);
62 }
63
64 const auto& field() const
65 {
66 return trialExpr->field();
67 }
68
69 };
70
71 template<class T1,class T2, std::enable_if_t<std::is_base_of_v<TrialExpressionBase<T2>,T2>,int> = 0>
72 auto operator,(const std::shared_ptr<TestExpression<T1>>& t,const std::shared_ptr<T2>& e)
73 {
74 return std::make_shared<BilinearForm<T1,T2>>(t,e);
75 }
76
77}
78#endif
final point of the source segment t
x
Definition int_R.m:12
auto operator,(const std::shared_ptr< TestExpression< T1 > > &t, const std::shared_ptr< T2 > &e)
BilinearForm(std::shared_ptr< TestExpression< T1 > > x, std::shared_ptr< T2 > y)
ElementMatrixType operator()(const ElementType &ele, const BaryType &bary) const
TrialProd< Constant< double, 1, 1 >, MobileFluxType >::TrialFunctionType TrialFunctionType
TestExpression< TrialExpressionType > TestExpressionType
int e