gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
terms.hpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 //
6 // Contributor(s):
7 // Eric Bechet
8 //
9 
10 //#include "terms.h"
11 
12 template<class T2> void LinearTermBase<T2>::get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &vec) const
13 {
14  std::vector<fullVector<T2> > vv;
15  vv.resize(npts);
16  get(ele,npts,GP,vv);
17  int nbFF=vv[0].size();
18  vec.resize(nbFF);
19  vec.setAll(T2());
20  double jac[3][3];
21  for(int i = 0; i < npts; i++)
22  {
23  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
24  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
25  for(int j = 0; j < nbFF; j++)
26  {
27  double contrib = weight * detJ;
28  vec(j) += contrib*vv[i](j);
29  }
30  }
31 }
32 
33 template<class T2> void PlusTerm<T2>::get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const
34 {
35  fullVector<T2> v2;
36  a->get(ele,npts,GP,v);
37  b->get(ele,npts,GP,v2);
38  for (int i=0;i<v2.size();++i) v(i)+=v2(i);
39 }
40 
41 template<class T2> void ScalarTermConstant<T2>::get(MElement *ele, int npts, IntPt *GP, T2 &val) const
42 {
43  double jac[3][3];
44  double eval = 0;
45  for(int i = 0; i < npts; i++)
46  {
47  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
48  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
49  eval += weight * detJ;
50  }
51  val=cst * eval;
52 }
53 
54 template<class T2> void ScalarTermConstant<T2>::get(MElement *ele, int npts, IntPt *GP, std::vector<T2> &vval) const
55 {
56  for(int i = 0; i < npts; i++)
57  {
58  vval[i] = cst;
59  }
60 }
61 
62 template<class T2> void ScalarTermConstant<T2>::get(MVertex *ver, T2 &val) const
63 {
64  val = cst;
65 }
66 
67 template<class T1> void LaplaceTerm<T1, T1>::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const
68 {
69  int nbFF = BilinearTerm<T1, T1>::space1.getNumKeys(ele);
70  double jac[3][3];
71  m.resize(nbFF, nbFF);
72  m.setAll(0.);
73  for(int i = 0; i < npts; i++){
74  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
75  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
76  std::vector<typename TensorialTraits<T1>::GradType> Grads;
77  BilinearTerm<T1, T1>::space1.gradf(ele, u, v, w, Grads);
78  for(int j = 0; j < nbFF; j++)
79  {
80  for(int k = j; k < nbFF; k++)
81  {
82  double contrib = weight * detJ * dot(Grads[j], Grads[k]) * diffusivity;
83  m(j, k) += contrib;
84  if(j != k) m(k, j) += contrib;
85  }
86  }
87  }
88 }
89 
90 template<class T1> void LoadTerm<T1>::get(MElement *ele, int npts, IntPt *GP, fullVector<double> &m) const
91 {
92  if(ele->getParent()) ele = ele->getParent();
93  int nbFF = LinearTerm<T1>::space1.getNumKeys(ele);
94  double jac[3][3];
95  m.resize(nbFF);
96  m.scale(0.);
97  for(int i = 0; i < npts; i++){
98  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
99  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
100  std::vector<typename TensorialTraits<T1>::ValType> Vals;
101  LinearTerm<T1>::space1.f(ele, u, v, w, Vals);
102  SPoint3 p;
103  ele->pnt(u, v, w, p);
104  typename TensorialTraits<T1>::ValType load = (*Load)(p.x(), p.y(), p.z());
105  for(int j = 0; j < nbFF ; ++j)
106  {
107  m(j) += dot(Vals[j], load) * weight * detJ;
108  }
109  }
110 }
111 
113 {
114  return BilinearTermContract<T2>(L1,L2);
115 }
116 
117 template<class T2> void BilinearTermContract<T2>::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const
118 {
119  fullVector<T2> va;
120  fullVector<T2> vb;
121  a->get(ele,npts,GP,va);
122  b->get(ele,npts,GP,vb);
123  m.resize(va.size(), vb.size());
124  m.setAll(0.);
125  for (int i=0;i<va.size();++i)
126  for (int j=0;j<vb.size();++j)
127  m(i,j)=dot(va(i),vb(j));
128 }
129 
130 
131 template<class T2> void BilinearTermContractWithLaw<T2>::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const
132 {
133  BilinearTermBase::get(ele,npts,GP,m);
134 }
135 
136 template<class T2> void BilinearTermContractWithLaw<T2>::get(MElement *ele, int npts, IntPt *GP, std::vector<fullMatrix<double> > &mv) const
137 {
138  std::vector<fullVector<T2> > va(npts);
139  std::vector<fullVector<T2> > vb(npts);
140  std::vector<typename TensorialTraits<T2>::TensProdType> tens(npts);
141  BilinearTermContract<T2>::a->get(ele,npts,GP,va);
142  BilinearTermContract<T2>::b->get(ele,npts,GP,vb);
143  c->get(ele,npts,GP,tens);
144  for (int k=0;k<npts;k++)
145  {
146  mv[k].resize(va[k].size(), vb[k].size());
147  for (int i=0;i<va[k].size();++i)
148  for (int j=0;j<vb[k].size();++j)
149  mv[k](i,j)=dot(va[k](i),tens[k]*vb[k](j));
150  }
151 }
152 
154 {
155  return PlusTerm<T2>(*this,other);
156 }
157 /*
158 template<class T1> void GradTerm<T1>::get(MElement *ele, int npts, IntPt *GP, fullVector<typename TensorialTraits<T1>::GradType > &vec) const
159 {
160  int nbFF = LinearTerm<T1,typename TensorialTraits<T1>::GradType>::space1.getNumKeys(ele);
161  double jac[3][3];
162  vec.resize(nbFF);
163  vec.setAll(typename TensorialTraits<T1>::GradType());
164  for(int i = 0; i < npts; i++)
165  {
166  std::vector<typename TensorialTraits<T1>::GradType> Grads;
167  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
168  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
169  LinearTerm<T1,typename TensorialTraits<T1>::GradType>::space1.gradf(ele, u, v, w, Grads);
170  for(int j = 0; j < nbFF; j++)
171  {
172  double contrib = weight * detJ;
173  vec(j) += contrib*Grads[j];
174  }
175  }
176 }
177 */
178 template<class T1> void GradTerm<T1>::get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<typename TensorialTraits<T1>::GradType > > &vvec) const
179 {
180  int nbFF = LinearTerm<T1,typename TensorialTraits<T1>::GradType>::space1.getNumKeys(ele);
181  for(int i = 0; i < npts; i++)
182  {
183  vvec[i].resize(nbFF);
184  std::vector<typename TensorialTraits<T1>::GradType> Grads;
185  const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2];
186  LinearTerm<T1,typename TensorialTraits<T1>::GradType>::space1.gradf(ele, u, v, w, Grads);
187  for(int j = 0; j < nbFF; j++)
188  {
189  vvec[i](j) = Grads[j];
190  }
191  }
192 }
193 
194 template<class T1> void LagrangeMultiplierTerm<T1>::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const
195 {
196  int nbFF1 = BilinearTerm<T1, double>::space1.getNumKeys(ele); //nbVertices*nbcomp of parent
197  int nbFF2 = BilinearTerm<T1, double>::space2.getNumKeys(ele); //nbVertices of boundary
198  double jac[3][3];
199  m.resize(nbFF1, nbFF2);
200  m.setAll(0.);
201  for(int i = 0; i < npts; i++)
202  {
203  double u = GP[i].pt[0]; double v = GP[i].pt[1]; double w = GP[i].pt[2];
204  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
205  std::vector<typename TensorialTraits<T1>::ValType> Vals;
206  std::vector<TensorialTraits<double>::ValType> ValsT;
207  BilinearTerm<T1,double>::space1.f(ele, u, v, w, Vals);
208  BilinearTerm<T1,double>::space2.f(ele, u, v, w, ValsT);
209  for(int j = 0; j < nbFF1; j++)
210  {
211  for(int k = 0; k < nbFF2; k++)
212  {
213  m(j, k) += dot(Vals[j], _d) * ValsT[k] * weight * detJ;
214  }
215  }
216  }
217 }
218 
219 template<class T1> void LoadTermOnBorder<T1>::get(MElement *ele, int npts, IntPt *GP, fullVector<double> &m) const
220 {
221  int nbFF = LinearTerm<T1>::space1.getNumKeys(ele);
222  double jac[3][3];
223  m.resize(nbFF);
224  m.scale(0.);
225  for(int i = 0; i < npts; i++)
226  {
227  double u = GP[i].pt[0]; double v = GP[i].pt[1]; double w = GP[i].pt[2];
228  const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac);
229  std::vector<typename TensorialTraits<T1>::ValType> Vals;
230  LinearTerm<T1>::space1.f(ele, u, v, w, Vals);
231  if(ele->getTypeForMSH() == MSH_LIN_B || ele->getTypeForMSH() == MSH_TRI_B ||
232  ele->getTypeForMSH() == MSH_POLYG_B)
234  SPoint3 p;
235  ele->pnt(u, v, w, p);
236  typename TensorialTraits<T1>::ValType load = (*Load)(p.x(), p.y(), p.z());
237  for(int j = 0; j < nbFF ; ++j){
238  m(j) += _eqfac * dot(Vals[j], load) * weight * detJ;
239  }
240  }
241 }
BilinearTermContractWithLaw::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix< double > &m) const
Definition: terms.hpp:131
dot
double dot(const SVector3 &a, const SMetric3 &m, const SVector3 &b)
Definition: STensor3.h:71
fullVector
Definition: MElement.h:26
ScalarTermConstant::get
virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const
Definition: terms.hpp:41
MElement::getTypeForMSH
virtual int getTypeForMSH() const
Definition: MElement.h:488
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition: discreteFrechetDistance.cpp:15
MVertex
Definition: MVertex.h:24
fullMatrix::setAll
void setAll(const scalar &m)
Definition: fullMatrix.h:422
SPoint3
Definition: SPoint3.h:14
MElement::getParent
virtual MElement * getParent() const
Definition: MElement.h:231
fullVector::size
int size() const
Definition: fullMatrix.h:69
fullVector::scale
void scale(const scalar s)
Definition: fullMatrix.h:144
fullVector::resize
bool resize(int r, bool resetValue=true)
Definition: fullMatrix.h:103
IntPt::pt
double pt[3]
Definition: GaussIntegration.h:13
BilinearTermContract
Definition: terms.h:103
operator|
BilinearTermContract< T2 > operator|(const LinearTermBase< T2 > &L1, const LinearTermBase< T2 > &L2)
Definition: terms.hpp:112
GradTerm::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector< typename TensorialTraits< T1 >::GradType > &vec) const
Definition: terms.h:220
LoadTermOnBorder::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector< double > &m) const
Definition: terms.hpp:219
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
fullMatrix< double >
IntPt::weight
double weight
Definition: GaussIntegration.h:14
LinearTermBase::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector< T2 > &v) const
Definition: terms.hpp:12
MSH_TRI_B
#define MSH_TRI_B
Definition: GmshDefines.h:147
LaplaceTerm::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix< double > &m) const
Definition: terms.h:245
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
MSH_POLYG_B
#define MSH_POLYG_B
Definition: GmshDefines.h:148
MElement
Definition: MElement.h:30
MSH_LIN_B
#define MSH_LIN_B
Definition: GmshDefines.h:146
MElement::pnt
virtual void pnt(double u, double v, double w, SPoint3 &p) const
Definition: MElement.cpp:1072
LoadTerm::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector< double > &m) const
Definition: terms.hpp:90
BilinearTermContract::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix< double > &m) const
Definition: terms.hpp:117
MElement::movePointFromParentSpaceToElementSpace
virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const
Definition: MElement.cpp:1188
IntPt
Definition: GaussIntegration.h:12
LagrangeMultiplierTerm::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix< double > &m) const
Definition: terms.hpp:194
BilinearTermBase::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix< double > &m) const
Definition: terms.cpp:20
PlusTerm
Definition: terms.h:26
BilinearTerm
Definition: terms.h:159
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
LinearTermBase::operator+
PlusTerm< T2 > operator+(const LinearTermBase< T2 > &other)
Definition: terms.hpp:153
TensorialTraits
Definition: functionSpace.h:22
MElement::getJacobian
virtual double getJacobian(const fullMatrix< double > &gsf, double jac[3][3]) const
Definition: MElement.cpp:868
LinearTermBase
Definition: terms.h:25
fullMatrix::resize
bool resize(int r, int c, bool resetValue=true)
Definition: fullMatrix.h:307
fullVector::setAll
void setAll(const scalar &m)
Definition: fullMatrix.h:158
LinearTerm
Definition: terms.h:203
PlusTerm::get
virtual void get(MElement *ele, int npts, IntPt *GP, fullVector< T2 > &v) const
Definition: terms.hpp:33