Intrepid
Intrepid_HGRAD_TRI_Cn_FEMDef.hpp
1 #ifndef INTREPID_HGRAD_TRI_CN_FEMDEF_HPP
2 #define INTREPID_HGRAD_TRI_CN_FEMDEF_HPP
3 // @HEADER
4 // ************************************************************************
5 //
6 // Intrepid Package
7 // Copyright (2007) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
40 // Denis Ridzal (dridzal@sandia.gov), or
41 // Kara Peterson (kjpeter@sandia.gov)
42 //
43 // ************************************************************************
44 // @HEADER
45 
51 namespace Intrepid {
52 
53  template<class Scalar, class ArrayScalar>
55  const EPointType pointType ):
56  Phis( n ),
57  V((n+1)*(n+2)/2,(n+1)*(n+2)/2),
58  Vinv((n+1)*(n+2)/2,(n+1)*(n+2)/2),
59  latticePts( (n+1)*(n+2)/2 , 2 )
60  {
61  const int N = (n+1)*(n+2)/2;
62  this -> basisCardinality_ = N;
63  this -> basisDegree_ = n;
64  this -> basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<3> >() );
65  this -> basisType_ = BASIS_FEM_FIAT;
66  this -> basisCoordinates_ = COORDINATES_CARTESIAN;
67  this -> basisTagsAreSet_ = false;
68 
69  // construct lattice
70 
71  shards::CellTopology myTri_3( shards::getCellTopologyData< shards::Triangle<3> >() );
72  PointTools::getLattice<Scalar,FieldContainer<Scalar> >( latticePts ,
73  myTri_3 ,
74  n ,
75  0 ,
76  pointType );
77 
78 
79  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
80  // so we transpose on copy below.
81 
82  Phis.getValues( V , latticePts , OPERATOR_VALUE );
83 
84  // now I need to copy V into a Teuchos array to do the inversion
85  Teuchos::SerialDenseMatrix<int,Scalar> Vsdm(N,N);
86  for (int i=0;i<N;i++) {
87  for (int j=0;j<N;j++) {
88  Vsdm(i,j) = V(i,j);
89  }
90  }
91 
92  // invert the matrix
93  Teuchos::SerialDenseSolver<int,Scalar> solver;
94  solver.setMatrix( rcp( &Vsdm , false ) );
95  solver.invert( );
96 
97  // now I need to copy the inverse into Vinv
98  for (int i=0;i<N;i++) {
99  for (int j=0;j<N;j++) {
100  Vinv(i,j) = Vsdm(j,i);
101  }
102  }
103 
104  }
105 
106 
107  template<class Scalar, class ArrayScalar>
109 
110  // Basis-dependent initializations
111  int tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
112  int posScDim = 0; // position in the tag, counting from 0, of the subcell dim
113  int posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
114  int posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
115 
116  // An array with local DoF tags assigned to the basis functions, in the order of their local enumeration
117 
118  int *tags = new int[ tagSize * this->getCardinality() ];
119  int *tag_cur = tags;
120  const int degree = this->getDegree();
121 
122  // BEGIN DOF ALONG BOTTOM EDGE
123 
124  // the first dof is on vertex 0
125  tag_cur[0] = 0; tag_cur[1] = 0; tag_cur[2] = 0; tag_cur[3] = 1;
126  tag_cur += tagSize;
127 
128  // next degree-1 dof are on edge 0
129  for (int i=1;i<degree;i++) {
130  tag_cur[0] = 1; tag_cur[1] = 0; tag_cur[2] = i-1; tag_cur[3] = degree-1;
131  tag_cur += tagSize;
132  }
133 
134  // last dof is on vertex 1
135  tag_cur[0] = 0; tag_cur[1] = 1; tag_cur[2] = 0; tag_cur[3] = 1;
136  tag_cur += tagSize;
137 
138  // END DOF ALONG BOTTOM EDGE
139 
140  int num_internal_dof = PointTools::getLatticeSize( this->getBaseCellTopology() ,
141  this->getDegree() ,
142  1 );
143 
144  int internal_dof_cur = 0;
145 
146  // BEGIN DOF ALONG INTERNAL HORIZONTAL LINES
147  for (int i=1;i<degree;i++) {
148  // first dof along line is on edge #2
149  tag_cur[0] = 1; tag_cur[1] = 2; tag_cur[2] = i-1; tag_cur[3] = degree-1;
150  tag_cur += tagSize;
151 
152  // next dof are internal
153  for (int j=1;j<degree-i;j++) {
154  tag_cur[0] = 2; tag_cur[1] = 0; tag_cur[2] = internal_dof_cur; tag_cur[3] = num_internal_dof;
155  internal_dof_cur++;
156  tag_cur += tagSize;
157  }
158 
159  // last dof along line is on edge 1
160  tag_cur[0] = 1; tag_cur[1] = 1; tag_cur[2] = i-1; tag_cur[3] = degree-1;
161  tag_cur += tagSize;
162 
163  }
164  // END DOF ALONG INTERNAL HORIZONTAL LINES
165 
166  // LAST DOF IS ON VERTEX 2
167  tag_cur[0] = 0; tag_cur[1] = 2; tag_cur[2] = 0; tag_cur[3] = 1;
168  // END LAST DOF
169 
170 
172  this -> ordinalToTag_,
173  tags,
174  this -> basisCardinality_,
175  tagSize,
176  posScDim,
177  posScOrd,
178  posDfOrd);
179 
180  delete []tags;
181 
182  }
183 
184 
185 
186  template<class Scalar, class ArrayScalar>
188  const ArrayScalar & inputPoints,
189  const EOperator operatorType) const {
190 
191  // Verify arguments
192 #ifdef HAVE_INTREPID_DEBUG
193  Intrepid::getValues_HGRAD_Args<Scalar, ArrayScalar>(outputValues,
194  inputPoints,
195  operatorType,
196  this -> getBaseCellTopology(),
197  this -> getCardinality() );
198 #endif
199  const int numPts = inputPoints.dimension(0);
200  const int numBf = this->getCardinality();
201 
202  try {
203  switch (operatorType) {
204  case OPERATOR_VALUE:
205  {
206  FieldContainer<Scalar> phisCur( numBf , numPts );
207  Phis.getValues( phisCur , inputPoints , operatorType );
208  for (int i=0;i<outputValues.dimension(0);i++) {
209  for (int j=0;j<outputValues.dimension(1);j++) {
210  outputValues(i,j) = 0.0;
211  for (int k=0;k<this->getCardinality();k++) {
212  outputValues(i,j) += this->Vinv(k,i) * phisCur(k,j);
213  }
214  }
215  }
216  }
217  break;
218  case OPERATOR_GRAD:
219  case OPERATOR_D1:
220  case OPERATOR_D2:
221  case OPERATOR_D3:
222  case OPERATOR_D4:
223  case OPERATOR_D5:
224  case OPERATOR_D6:
225  case OPERATOR_D7:
226  case OPERATOR_D8:
227  case OPERATOR_D9:
228  case OPERATOR_D10:
229  {
230  const int dkcard =
231  (operatorType == OPERATOR_GRAD)? getDkCardinality(OPERATOR_D1,2): getDkCardinality(operatorType,2);
232 
233  FieldContainer<Scalar> phisCur( numBf , numPts , dkcard );
234  Phis.getValues( phisCur , inputPoints , operatorType );
235 
236  for (int i=0;i<outputValues.dimension(0);i++) {
237  for (int j=0;j<outputValues.dimension(1);j++) {
238  for (int k=0;k<outputValues.dimension(2);k++) {
239  outputValues(i,j,k) = 0.0;
240  for (int l=0;l<this->getCardinality();l++) {
241  outputValues(i,j,k) += this->Vinv(l,i) * phisCur(l,j,k);
242  }
243  }
244  }
245  }
246  }
247  break;
248  case OPERATOR_CURL: // only works in 2d. first component is -d/dy, second is d/dx
249  {
250  FieldContainer<Scalar> phisCur( numBf , numPts , getDkCardinality( OPERATOR_D1 , 2 ) );
251  Phis.getValues( phisCur , inputPoints , OPERATOR_D1 );
252 
253  for (int i=0;i<outputValues.dimension(0);i++) {
254  for (int j=0;j<outputValues.dimension(1);j++) {
255  outputValues(i,j,0) = 0.0;
256  outputValues(i,j,1) = 0.0;
257  for (int k=0;k<this->getCardinality();k++) {
258  outputValues(i,j,0) = this->Vinv(k,i) * phisCur(k,j,1);
259  }
260  for (int k=0;k<this->getCardinality();k++) {
261  outputValues(i,j,1) -= this->Vinv(k,i) * phisCur(k,j,0);
262  }
263  }
264  }
265  }
266  break;
267  default:
268  TEUCHOS_TEST_FOR_EXCEPTION( true , std::invalid_argument,
269  ">>> ERROR (Basis_HGRAD_TRI_Cn_FEM): Operator type not implemented");
270  break;
271  }
272  }
273  catch (std::invalid_argument &exception){
274  TEUCHOS_TEST_FOR_EXCEPTION( true , std::invalid_argument,
275  ">>> ERROR (Basis_HGRAD_TRI_Cn_FEM): Operator type not implemented");
276  }
277 
278  }
279 
280 
281 
282  template<class Scalar, class ArrayScalar>
284  const ArrayScalar & inputPoints,
285  const ArrayScalar & cellVertices,
286  const EOperator operatorType) const {
287  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::logic_error,
288  ">>> ERROR (Basis_HGRAD_TRI_Cn_FEM): FEM Basis calling an FVD member function");
289  }
290 
291 
292 }// namespace Intrepid
293 #endif
virtual int getCardinality() const
Returns cardinality of the basis.
FieldContainer< Scalar > latticePts
stores the points at which degrees of freedom are located.
EBasis basisType_
Type of the basis.
void setOrdinalTagData(std::vector< std::vector< std::vector< int > > > &tagToOrdinal, std::vector< std::vector< int > > &ordinalToTag, const int *tags, const int basisCard, const int tagSize, const int posScDim, const int posScOrd, const int posDfOrd)
Fills ordinalToTag_ and tagToOrdinal_ by basis-specific tag data.
Basis_HGRAD_TRI_Cn_FEM(const int n, const EPointType pointType)
Constructor.
bool basisTagsAreSet_
"true" if tagToOrdinal_ and ordinalToTag_ have been initialized
EOperator
Enumeration of primitive operators available in Intrepid. Primitive operators act on reconstructed fu...
ECoordinates basisCoordinates_
The coordinate system for which the basis is defined.
FieldContainer< Scalar > V
The Vandermonde matrix with V_{ij} = phi_i(x_j), where x_j is the j_th point in the lattice...
FieldContainer< Scalar > Vinv
The inverse of V. The columns of Vinv express the Lagrange basis in terms of the orthogonal basis...
shards::CellTopology basisCellTopology_
Base topology of the cells for which the basis is defined. See the Shards package http://trilinos...
int getDkCardinality(const EOperator operatorType, const int spaceDim)
Returns cardinality of Dk, i.e., the number of all derivatives of order k.
virtual int getDegree() const
Returns the degree of the basis.
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Triangle cell.
EPointType
Enumeration of types of point distributions in Intrepid.
virtual const shards::CellTopology getBaseCellTopology() const
Returns the base cell topology for which the basis is defined. See Shards documentation http://trilin...
virtual void initializeTags()
Initializes tagToOrdinal_ and ordinalToTag_ lookup arrays.
Basis_HGRAD_TRI_Cn_FEM_ORTH< Scalar, FieldContainer< Scalar > > Phis
The orthogonal basis on triangles, out of which the nodal basis is constructed.
int basisDegree_
Degree of the largest complete polynomial space that can be represented by the basis.
std::vector< std::vector< std::vector< int > > > tagToOrdinal_
DoF tag to ordinal lookup table.
int basisCardinality_
Cardinality of the basis, i.e., the number of basis functions/degrees-of-freedom. ...
std::vector< std::vector< int > > ordinalToTag_
DoF ordinal to tag lookup table.
static int getLatticeSize(const shards::CellTopology &cellType, const int order, const int offset=0)
Computes the number of points in a lattice of a given order on a simplex (currently disabled for othe...