Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
BilinearWeakForm.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_BilinearWeakForm_H_
9#define model_BilinearWeakForm_H_
10
11#include <chrono>
12#include <vector>
13
14#include <Eigen/Sparse>
15
16#include <TrialBase.h>
17#include <LinearWeakForm.h>
18#include <TerminalColors.h>
19#include <BilinearForm.h>
20
22#include <BilinearWeakSum.h>
23
24namespace model
25{
26
27 template <typename _BilinearFormType,typename _IntegrationDomainType>
28 struct BilinearWeakForm : public BilinearWeakExpression<BilinearWeakForm<_BilinearFormType,_IntegrationDomainType> >
29 {
30
31 typedef _BilinearFormType BilinearFormType;
32 typedef _IntegrationDomainType IntegrationDomainType;
34 typedef typename BilinearFormType::TrialFunctionType TrialFunctionType;
35 typedef typename BilinearFormType::TestExpressionType TestExpressionType;
36 typedef typename BilinearFormType::TrialExpressionType TrialExpressionType;
37 typedef typename TrialFunctionType::ElementType ElementType;
38 typedef typename IntegrationDomainType::QuadratureType QuadratureType;
39 typedef typename QuadratureType::VectorDim AbscissaType;
40
45
46 typedef Eigen::Matrix<double,dofPerElement,dofPerElement> ElementMatrixType;
47
48 const std::shared_ptr<BilinearFormType> bilinearForm;
49
51 BilinearWeakForm(std::shared_ptr<BilinearFormType> f,const IntegrationDomainType& dom) : bilinearForm(std::move(f)), domain(dom)
52 {
53 if(!bilinearForm)
54 {
55 throw std::invalid_argument("Null FEM form.");
56 }
57 domain.validateSpace(field().fe());
58 }
59
60
61
62
63 std::vector<Eigen::Triplet<double> > globalTriplets() const
64 {
65 domain.validateSpace(field().fe());
66 std::vector<Eigen::Triplet<double> > glbtrip;
67 glbtrip.reserve(dofPerElement*dofPerElement*field().elementSize());
68
69 for (size_t k=0;k<domain.size();++k)
70 {
71 const ElementType& ele(domain.element(k));
72 ElementMatrixType ke(ElementMatrixType::Zero());
73 QuadratureType::integrate(this,ke,&BilinearWeakFormType::elementAssemblyKernel<AbscissaType>,ele);
74
75 for (int i=0;i<dofPerElement;++i)
76 {
77 for (int j=0;j<dofPerElement;++j)
78 {
79 if(ke(i,j)!=0.0)
80 {
81 const size_t nodeID_I(i/dofPerNode);
82 const size_t nodeDof_I(i%dofPerNode);
83 const size_t gI= ele.node(nodeID_I).gID*dofPerNode+nodeDof_I;
84
85 const size_t nodeID_J(j/dofPerNode);
86 const size_t nodeDof_J(j%dofPerNode);
87 const size_t gJ=ele.node(nodeID_J).gID*dofPerNode+nodeDof_J;
88
89 glbtrip.emplace_back(gI,gJ,ke(i,j));
90 }
91 }
92 }
93 }
94 return glbtrip;
95 }
96
97 template <typename AbscissaType>
99 {
100 const Eigen::Matrix<double,dim+1,1> bary(BarycentricTraits<dim>::x2l(a));
101
102 return (*bilinearForm)(ele,bary)*ele.absJ(bary);
103 }
104
105 const auto& field() const
106 {
107 return bilinearForm->field();
108 }
109
110 };
111
112 template<class T1,class T2,class FE,int D,int Q,template<short unsigned int,size_t> class Rule>
113 auto operator*(const std::shared_ptr<BilinearForm<T1,T2>>& f,const IntegrationDomain<FE,D,Q,Rule>& dom)
114 {
115 return std::make_shared<BilinearWeakForm<BilinearForm<T1,T2>,IntegrationDomain<FE,D,Q,Rule>>>(f,dom);
116 }
117
118}
119#endif
function int_R syms a b c u real f
Definition int_R.m:4
a
Definition int_R.m:14
auto operator*(const std::shared_ptr< BilinearForm< T1, T2 > > &f, const IntegrationDomain< FE, D, Q, Rule > &dom)
static VectorHigherDimD x2l(const VectorDimD &X)
Eigen::Matrix< double, dofPerElement, dofPerElement > ElementMatrixType
ElementMatrixType elementAssemblyKernel(const AbscissaType &a, const ElementType &ele) const
BilinearWeakForm(std::shared_ptr< BilinearFormType > f, const IntegrationDomainType &dom)
const auto & field() const
BilinearWeakForm< BilinearFormType, IntegrationDomainType > BilinearWeakFormType
std::vector< Eigen::Triplet< double > > globalTriplets() const
int j
int k
int i