Intrepid
Intrepid_HGRAD_TRI_C1_FEMDef.hpp
1#ifndef INTREPID_HGRAD_TRI_C1_FEMDEF_HPP
2#define INTREPID_HGRAD_TRI_C1_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
51namespace Intrepid {
52
53
54template<class Scalar, class ArrayScalar>
56 {
57 this -> basisCardinality_ = 3;
58 this -> basisDegree_ = 1;
59 this -> basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<3> >() );
60 this -> basisType_ = BASIS_FEM_DEFAULT;
61 this -> basisCoordinates_ = COORDINATES_CARTESIAN;
62 this -> basisTagsAreSet_ = false;
63 }
64
65
66
67template<class Scalar, class ArrayScalar>
69
70 // Basis-dependent initializations
71 int tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
72 int posScDim = 0; // position in the tag, counting from 0, of the subcell dim
73 int posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
74 int posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
75
76 // An array with local DoF tags assigned to the basis functions, in the order of their local enumeration
77 int tags[] = { 0, 0, 0, 1,
78 0, 1, 0, 1,
79 0, 2, 0, 1 };
80
81 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
82 Intrepid::setOrdinalTagData(this -> tagToOrdinal_,
83 this -> ordinalToTag_,
84 tags,
85 this -> basisCardinality_,
86 tagSize,
87 posScDim,
88 posScOrd,
89 posDfOrd);
90}
91
92
93
94template<class Scalar, class ArrayScalar>
96 const ArrayScalar & inputPoints,
97 const EOperator operatorType) const {
98
99 // Verify arguments
100#ifdef HAVE_INTREPID_DEBUG
101 Intrepid::getValues_HGRAD_Args<Scalar, ArrayScalar>(outputValues,
102 inputPoints,
103 operatorType,
104 this -> getBaseCellTopology(),
105 this -> getCardinality() );
106#endif
107
108 // Number of evaluation points = dim 0 of inputPoints
109 int dim0 = inputPoints.dimension(0);
110
111 // Temporaries: (x,y) coordinates of the evaluation point
112 Scalar x = 0.0;
113 Scalar y = 0.0;
114
115 switch (operatorType) {
116
117 case OPERATOR_VALUE:
118 for (int i0 = 0; i0 < dim0; i0++) {
119 x = inputPoints(i0, 0);
120 y = inputPoints(i0, 1);
121
122 // outputValues is a rank-2 array with dimensions (basisCardinality_, dim0)
123 outputValues(0, i0) = 1.0 - x - y;
124 outputValues(1, i0) = x;
125 outputValues(2, i0) = y;
126 }
127 break;
128
129 case OPERATOR_GRAD:
130 case OPERATOR_D1:
131 for (int i0 = 0; i0 < dim0; i0++) {
132
133 // outputValues is a rank-3 array with dimensions (basisCardinality_, dim0, spaceDim)
134 outputValues(0, i0, 0) = -1.0;
135 outputValues(0, i0, 1) = -1.0;
136
137 outputValues(1, i0, 0) = 1.0;
138 outputValues(1, i0, 1) = 0.0;
139
140 outputValues(2, i0, 0) = 0.0;
141 outputValues(2, i0, 1) = 1.0;
142 }
143 break;
144
145 case OPERATOR_CURL:
146 for (int i0 = 0; i0 < dim0; i0++) {
147 outputValues(0, i0, 0) = -1.0;
148 outputValues(0, i0, 1) = 1.0;
149
150 outputValues(1, i0, 0) = 0.0;
151 outputValues(1, i0, 1) = -1.0;
152
153 outputValues(2, i0, 0) = 1.0;
154 outputValues(2, i0, 1) = 0.0;
155 }
156 break;
157
158 case OPERATOR_DIV:
159 TEUCHOS_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_DIV), std::invalid_argument,
160 ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): DIV is invalid operator for rank-0 (scalar) fields in 2D.");
161 break;
162
163 case OPERATOR_D2:
164 case OPERATOR_D3:
165 case OPERATOR_D4:
166 case OPERATOR_D5:
167 case OPERATOR_D6:
168 case OPERATOR_D7:
169 case OPERATOR_D8:
170 case OPERATOR_D9:
171 case OPERATOR_D10:
172 {
173 // outputValues is a rank-3 array with dimensions (basisCardinality_, dim0, DkCardinality)
174 int DkCardinality = Intrepid::getDkCardinality(operatorType,
175 this -> basisCellTopology_.getDimension() );
176 for(int dofOrd = 0; dofOrd < this -> basisCardinality_; dofOrd++) {
177 for (int i0 = 0; i0 < dim0; i0++) {
178 for(int dkOrd = 0; dkOrd < DkCardinality; dkOrd++){
179 outputValues(dofOrd, i0, dkOrd) = 0.0;
180 }
181 }
182 }
183 }
184 break;
185
186 default:
187 TEUCHOS_TEST_FOR_EXCEPTION( !( Intrepid::isValidOperator(operatorType) ), std::invalid_argument,
188 ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): Invalid operator type");
189 }
190}
191
192
193
194template<class Scalar, class ArrayScalar>
196 const ArrayScalar & inputPoints,
197 const ArrayScalar & cellVertices,
198 const EOperator operatorType) const {
199 TEUCHOS_TEST_FOR_EXCEPTION( (true), std::logic_error,
200 ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): FEM Basis calling an FVD member function");
201}
202
203template<class Scalar, class ArrayScalar>
205#ifdef HAVE_INTREPID_DEBUG
206 // Verify rank of output array.
207 TEUCHOS_TEST_FOR_EXCEPTION( !(DofCoords.rank() == 2), std::invalid_argument,
208 ">>> ERROR: (Intrepid::Basis_HGRAD_TRI_C1_FEM::getDofCoords) rank = 2 required for DofCoords array");
209 // Verify 0th dimension of output array.
210 TEUCHOS_TEST_FOR_EXCEPTION( !( DofCoords.dimension(0) == this -> basisCardinality_ ), std::invalid_argument,
211 ">>> ERROR: (Intrepid::Basis_HGRAD_TRI_C1_FEM::getDofCoords) mismatch in number of DoF and 0th dimension of DofCoords array");
212 // Verify 1st dimension of output array.
213 TEUCHOS_TEST_FOR_EXCEPTION( !( DofCoords.dimension(1) == (int)(this -> basisCellTopology_.getDimension()) ), std::invalid_argument,
214 ">>> ERROR: (Intrepid::Basis_HGRAD_TRI_C1_FEM::getDofCoords) incorrect reference cell (1st) dimension in DofCoords array");
215#endif
216
217 DofCoords(0,0) = 0.0; DofCoords(0,1) = 0.0;
218 DofCoords(1,0) = 1.0; DofCoords(1,1) = 0.0;
219 DofCoords(2,0) = 0.0; DofCoords(2,1) = 1.0;
220}
221
222
223}// namespace Intrepid
224#endif
int isValidOperator(const EOperator operatorType)
Verifies validity of an operator enum.
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.
int getDkCardinality(const EOperator operatorType, const int spaceDim)
Returns cardinality of Dk, i.e., the number of all derivatives of order k.
void initializeTags()
Initializes tagToOrdinal_ and ordinalToTag_ lookup arrays.
void getDofCoords(ArrayScalar &DofCoords) const
Returns spatial locations (coordinates) of degrees of freedom on a reference Quadrilateral.
void getValues(ArrayScalar &outputValues, const ArrayScalar &inputPoints, const EOperator operatorType) const
Evaluation of a FEM basis on a reference Triangle cell.