Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
LinearWeakAssembler.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_LinearWeakAssembler_H_
9#define model_LinearWeakAssembler_H_
10
11#include <chrono>
12#include <vector>
13
14#include <Eigen/Dense>
15
16#include <Quadrature.h>
17
18#include <TerminalColors.h>
19#include <TrialBase.h>
20
21#include <JGNselector.h>
22
23namespace model
24{
25
26 template<typename LinearWeakFormType, short unsigned int DimMinusDomainDim>
28 {
29
30 const LinearWeakFormType& lwf;
31
32 LinearWeakAssembler(const LinearWeakFormType& lwf_in) :
33 lwf(lwf_in)
34 {
35 assert(0 && "LinearWeakAssembler: DimMinusDomainDim must be 0 or 1.");
36 }
37
38 };
39
40 template<typename LinearWeakFormType>
41 struct LinearWeakAssembler<LinearWeakFormType,0>
42 {
44 typedef typename LinearWeakFormType::LinearFormType LinearFormType;
45 typedef typename LinearWeakFormType::IntegrationDomainType IntegrationDomainType;
46 constexpr static int dim=IntegrationDomainType::dim;
47
48 typedef typename LinearFormType::TrialFunctionType TrialFunctionType;
49
53 typedef Eigen::Matrix<double,dofPerElement,1> ElementVectorType;
54 constexpr static int evalCols=LinearFormType::evalCols;
55 typedef typename IntegrationDomainType::QuadratureType QuadratureType;
56 typedef typename QuadratureType::VectorDim AbscissaType;
57
58 const LinearWeakFormType& lwf;
59
60 LinearWeakAssembler(const LinearWeakFormType& lwf_in) :
61 lwf(lwf_in)
62 {
63
64 }
65
66 Eigen::Matrix<double,Eigen::Dynamic,1> assemble() const
67 {
68
69 const auto t0= std::chrono::system_clock::now();
70
71 Eigen::Matrix<double,Eigen::Dynamic,1> _globalVector(Eigen::Matrix<double,Eigen::Dynamic,1>::Zero(lwf.field().gSize()));
72
73 for (size_t k=0;k<lwf.domain.size();++k)
74 {
75
76 ElementVectorType ve(ElementVectorType::Zero());
77 QuadratureType::integrate(this,ve,&LinearWeakAssemblerType::assemblyKernel,lwf.domain.element(k));
78
79 for (int i=0;i<dofPerElement;++i)
80 {
81 const size_t nodeID_I(i/dofPerNode);
82 const size_t nodeDof_I(i%dofPerNode);
83 const size_t gI= lwf.domain.element(k).node(nodeID_I).gID*dofPerNode+nodeDof_I;
84 _globalVector(gI) += ve(i);
85 }
86 }
87
88 return _globalVector;
89 }
90
92 {
93 const Eigen::Matrix<double,dim+1,1> bary(BarycentricTraits<dim>::x2l(a));
94 return (*lwf.linearForm)(ele,bary)*ele.absJ(bary);
95 }
96
97 };
98
99 template<typename LinearWeakFormType>
100 struct LinearWeakAssembler<LinearWeakFormType,1>
101 {
103 typedef typename LinearWeakFormType::LinearFormType LinearFormType;
104 typedef typename LinearWeakFormType::IntegrationDomainType IntegrationDomainType;
105 constexpr static int dim=IntegrationDomainType::dim;
106
107 typedef typename LinearFormType::TrialFunctionType TrialFunctionType;
108
112 typedef Eigen::Matrix<double,dofPerElement,1> ElementVectorType;
113 constexpr static int evalCols=LinearFormType::evalCols;
114 typedef typename IntegrationDomainType::QuadratureType QuadratureType;
115 typedef typename QuadratureType::VectorDim AbscissaType;
116
117 const LinearWeakFormType& lwf;
118
119 LinearWeakAssembler(const LinearWeakFormType& lwf_in) :
120 lwf(lwf_in)
121 {
122
123 }
124
125 Eigen::Matrix<double,Eigen::Dynamic,1> assemble() const
126 {
127 std::cout<<"Assembling LinearWeakForm on faces ("<<lwf.domain.size()<<" faces) ..."<<std::flush;
128 const auto t0= std::chrono::system_clock::now();
129
130 Eigen::Matrix<double,Eigen::Dynamic,1> _globalVector(Eigen::Matrix<double,Eigen::Dynamic,1>::Zero(lwf.field().gSize()));
131
132 for (size_t k=0;k<lwf.domain.size();++k)
133 {
134 const ElementType& ele(lwf.domain.element(k));
135 const int f(lwf.domain[k].second);
136 ElementVectorType ve(ElementVectorType::Zero());
137 QuadratureType::integrate(this,ve,&LinearWeakAssemblerType::assemblyKernel,ele,f);
138 for (int i=0;i<dofPerElement;++i)
139 {
140 const size_t nodeID_I(i/dofPerNode);
141 const size_t nodeDof_I(i%dofPerNode);
142 const size_t gI= ele.node(nodeID_I).gID*dofPerNode+nodeDof_I;
143 _globalVector(gI) += ve(i);
144 }
145 }
146 std::cout<<" done.["<<(std::chrono::duration<double>(std::chrono::system_clock::now()-t0)).count()<<" sec]"<<std::endl;
147 return _globalVector;
148 }
149
151 const ElementType& ele,
152 const int& boundaryFace) const
153 {
154 const Eigen::Matrix<double,dim,1> b1(BarycentricTraits<dim-1>::x2l(a1));
155 const Eigen::Matrix<double,dim+1,1> bary(BarycentricTraits<dim>::face2domainBary(b1,boundaryFace));
156 return (*lwf.linearForm)(ele,bary)*JGNselector<evalCols>::jGN(ele.jGN(bary,boundaryFace));
157 }
158
159 };
160
161}
162#endif
function int_R syms a b c u real f
Definition int_R.m:4
a
Definition int_R.m:14
size_t InstanceCount< Derived >::count
static VectorHigherDimD x2l(const VectorDimD &X)
static Eigen::Matrix< double, dim+1, 1 > face2domainBary(const Eigen::Matrix< double, dim, 1 > &b1, const int &boundaryFace)
static Eigen::Matrix< double, dim, 1 > jGN(const Eigen::Matrix< double, dim, 1 > &jgn)
Definition JGNselector.h:19
LinearWeakFormType::IntegrationDomainType IntegrationDomainType
Eigen::Matrix< double, dofPerElement, 1 > ElementVectorType
LinearWeakAssembler(const LinearWeakFormType &lwf_in)
ElementVectorType assemblyKernel(const AbscissaType &a, const ElementType &ele) const
LinearWeakAssembler< LinearWeakFormType, 0 > LinearWeakAssemblerType
IntegrationDomainType::QuadratureType QuadratureType
TypeTraits< TrialFunctionType >::ElementType ElementType
Eigen::Matrix< double, Eigen::Dynamic, 1 > assemble() const
TypeTraits< TrialFunctionType >::ElementType ElementType
Eigen::Matrix< double, Eigen::Dynamic, 1 > assemble() const
LinearWeakAssembler< LinearWeakFormType, 1 > LinearWeakAssemblerType
LinearWeakFormType::IntegrationDomainType IntegrationDomainType
IntegrationDomainType::QuadratureType QuadratureType
ElementVectorType assemblyKernel(const AbscissaType &a1, const ElementType &ele, const int &boundaryFace) const
Eigen::Matrix< double, dofPerElement, 1 > ElementVectorType
const LinearWeakFormType & lwf
LinearWeakAssembler(const LinearWeakFormType &lwf_in)
REAL t0
int k
int i