Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
IntegrationDomain.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_IntegrationDomain_H_
9#define model_IntegrationDomain_H_
10
11#include <deque>
12#include <memory>
13#include <stdexcept>
14#include <utility> // std::pair, std::make_pair
15#include <chrono>
16#include <Quadrature.h>
17
18#include <BarycentricTraits.h>
19#include <IntegrationList.h>
20#include <JGNselector.h>
21
22
23namespace model
24{
25 // Domains may be retained independently of the field that uses them.
26 template<class FE>
28 {
29 std::shared_ptr<const FE> owner;
30 const FE* space=nullptr;
31 std::weak_ptr<const int> lifetime;
32 public:
33 void bind(const FE& fe)
34 {
35 if(space && space!=&fe)
36 {
37 throw std::runtime_error("Integration domain belongs to a different FEM space.");
38 }
39 fe.validateMeshLifetime();
40 space=&fe;
41 owner=fe.weak_from_this().lock();
42 lifetime=fe.lifetimeToken();
43 }
44 void validate() const
45 {
46 if(space)
47 {
48 if(lifetime.expired())
49 {
50 throw std::runtime_error("Integration domain outlived its borrowed FEM space.");
51 }
52 space->validateMeshLifetime();
53 }
54 }
55 void validateSpace(const FE& fe) const
56 {
57 validate();
58 if(space && space!=&fe)
59 {
60 throw std::runtime_error("Integration domain belongs to a different FEM space.");
61 }
62 }
63 };
64
65
66
67 /**************************************************************************/
68 /**************************************************************************/
69 template <typename FiniteElementType, int dimMinusDomainDim, int qOrder, template <short unsigned int, size_t> class QuadratureRule>
71 {
72
73 /**********************************************************************/
75 {
76 assert(0 && "IntegrationDomain not implemented");
77 }
78 };
79
80 /**************************************************************************/
81 /**************************************************************************/
82 template <typename FiniteElementType, int qOrder, template <short unsigned int, size_t> class QuadratureRule>
83 struct IntegrationDomain<FiniteElementType,0,qOrder,QuadratureRule> : public FEMDomainOwner<FiniteElementType>, public std::deque<const typename FiniteElementType::ElementType*>
84 {// Volume integration
85 constexpr static int dim=FiniteElementType::dim;
86 constexpr static int domainDim=dim;
88
89 /**********************************************************************/
90 const typename FiniteElementType::ElementType& element(const size_t& k) const
91 {
92 this->validate();
93 return *(this->operator[](k));
94 }
95 };
96
97 /**************************************************************************/
98 /**************************************************************************/
99 template <typename FiniteElementType, int qOrder, template <short unsigned int, size_t> class QuadratureRule>
100 struct IntegrationDomain<FiniteElementType,1,qOrder,QuadratureRule> : public FEMDomainOwner<FiniteElementType>, public std::deque<std::pair<const typename FiniteElementType::ElementType* const,int> >
101 {// Boundary integration
102 constexpr static int dim=FiniteElementType::dim;
103 constexpr static int dimMinusDomainDim=1;
104 constexpr static int domainDim=dim-dimMinusDomainDim;
107 typedef typename FiniteElementType::ElementType ElementType;
109
110 /**********************************************************************/
111 const typename FiniteElementType::ElementType& element(const size_t& k) const
112 {
113 this->validate();
114 return *(this->operator[](k).first);
115 }
116
117 /**********************************************************************/
118 template <typename AnyClass, typename IntegrandType, typename ...Args>
119 void integrate(const AnyClass* const C, IntegrandType &intgrl, IntegrandType (AnyClass::*mfp)(const AbscissaType&,const ElementType&, const int&, const Args&...) const, const Args&...args) const
120 {
121// std::cout<<"Integrating on boundary ("<<this->size()<<" faces) ..."<<std::flush;
122// const auto t0= std::chrono::system_clock::now();
123 for (size_t k=0;k<this->size();++k)
124 {
125 QuadratureType::integrate(C,intgrl,mfp,*(this->operator[](k)).first,this->operator[](k).second,args...);
126 }
127// std::cout<<" done.["<<(std::chrono::duration<double>(std::chrono::system_clock::now()-t0)).count()<<" sec]"<<std::endl;
128 }
129
130// /**********************************************************************/
131// double volumeKernel(const Eigen::Matrix<double,dim-1,1>& a1, const ElementType& ele, const int& boundaryFace) const
132// {
133// const Eigen::Matrix<double,dim,1> b1(BarycentricTraits<dim-1>::x2l(a1));
134// const Eigen::Matrix<double,dim+1,1> bary(face2domainBary(b1,boundaryFace));
135// return JGNselector<1>::jGN(ele.jGN(bary,boundaryFace));
136// }
137
138 /**********************************************************************/
139 double volume() const
140 {
141 double temp=0.0;
142 for(const auto& pair : *this)
143 {
144 temp+=pair.first->simplex.child(pair.second).vol0;
145 }
146// integrate(this,temp,&IntegrationDomainType::volumeKernel);
147 return temp;
148 }
149// /**********************************************************************/
150// template <typename PointType>
151// void integrationList(std::deque<PointType>& deq) const
152// {
153// std::cout<<"populating integration List (size "<<deq.size()<<"->"<<std::flush;
154// const auto t0= std::chrono::system_clock::now();
155// for (int k=0;k<this->size();++k)
156// {
157// const ElementType& ele(*(this->operator[](k).first)); // element ID
158// const int f(this->operator[](k).second); // face ID
159// // ElementVectorType ve(ElementVectorType::Zero());
160// // QuadratureType::integrate(this,ve,&LinearWeakFormType::boundaryAssemblyKernel<AbscissaType>,ele,f);
161// for(unsigned int q=0;q<qOrder;++q)
162// {
163// const Eigen::Matrix<double,dim,1> b1(BarycentricTraits<dim-1>::x2l(QuadratureType::abscissa(q)));
164// const Eigen::Matrix<double,dim+1,1> bary(BarycentricTraits<dim>::face2domainBary(b1,f));
165// deq.emplace_back(ele.position(bary));
166// }
167//
168// }
169// std::cout<<deq.size()<<") ["<<(std::chrono::duration<double>(std::chrono::system_clock::now()-t0)).count()<<" sec]"<<std::endl;
170//
171// }
172
173 /**********************************************************************/
174 template <typename PointType>
179
180 };
181
182
183
184
185} // close namespace
186#endif
void validateSpace(const FE &fe) const
void bind(const FE &fe)
const FiniteElementType::ElementType & element(const size_t &k) const
const FiniteElementType::ElementType & element(const size_t &k) const
void integrate(const AnyClass *const C, IntegrandType &intgrl, IntegrandType(AnyClass::*mfp)(const AbscissaType &, const ElementType &, const int &, const Args &...) const, const Args &...args) const
IntegrationDomain< FiniteElementType, 1, qOrder, QuadratureRule > IntegrationDomainType
IntegrationList< dimMinusDomainDim, PointType > integrationList() const
A static class template for generating quadrature abcsissas and weights for arbitrary-order and Quadr...
Definition Quadrature.h:50
static void integrate(IntegrandType(*fp)(const double &), IntegrandType &intgrl)
Definition Quadrature.h:81
VectorDimTypeSelector< dim, qOrder >::VectorDim VectorDim
Definition Quadrature.h:55
int k
vertex temp
vertex first