Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
LinearWeakDiff.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_LinearWeakDiff_H_
9#define model_LinearWeakDiff_H_
10
11#include <type_traits>
13#include <memory>
14#include <stdexcept>
15
16namespace model
17{
18
19 template <typename T1,typename T2>
20 struct LinearWeakDiff : public LinearWeakExpression<LinearWeakDiff<T1,T2> >
21 {
22
23 static_assert(std::is_same<typename T1::TrialFunctionType,typename T2::TrialFunctionType>::value,"YOU ARE SUMMING TrialExpressionBase OF DIFFERENT TRIALFUNCTIONS.");
24 typedef typename T1::TrialFunctionType TrialFunctionType;
25
26 const std::shared_ptr<T1> op1;
27
28 const std::shared_ptr<T2> op2;
29 LinearWeakDiff(std::shared_ptr<T1> x, std::shared_ptr<T2> y) :
30 op1(std::move(x)), op2(std::move(y))
31 {
32 if(!op1 || !op2)
33 {
34 throw std::invalid_argument("Null FEM expression operand.");
35 }
36 }
37
38 Eigen::Matrix<double,Eigen::Dynamic,1> globalVector() const
39 {
40 if(!(op2->field().sameField(field())))
41 {
42 throw std::runtime_error("Cannot assemble expressions from different FEM field instances.");
43 }
44 return op1->globalVector()-op2->globalVector();
45 }
46
47 const auto& field() const
48 {
49 return op1->field();
50 }
51
52 };
53
54 template<class T1,class T2, std::enable_if_t<std::is_base_of_v<LinearWeakExpression<T1>,T1> && std::is_base_of_v<LinearWeakExpression<T2>,T2>,int> = 0>
55 auto operator-(const std::shared_ptr<T1>& x,const std::shared_ptr<T2>& y)
56 {
57 return std::make_shared<LinearWeakDiff<T1,T2>>(x,y);
58 }
59
60}
61#endif
x
Definition int_R.m:12
auto operator-(const std::shared_ptr< T1 > &x, const std::shared_ptr< T2 > &y)
const std::shared_ptr< T2 > op2
LinearWeakDiff(std::shared_ptr< T1 > x, std::shared_ptr< T2 > y)
Eigen::Matrix< double, Eigen::Dynamic, 1 > globalVector() const
const std::shared_ptr< T1 > op1
const auto & field() const
T1::TrialFunctionType TrialFunctionType