00001 /* @HEADER@ */ 00002 // ************************************************************************ 00003 // 00004 // Sundance 00005 // Copyright 2011 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu) 00038 // 00039 00040 /* @HEADER@ */ 00041 00042 #ifndef SUNDANCE_CELLJACOBIANBATCH_H 00043 #define SUNDANCE_CELLJACOBIANBATCH_H 00044 00045 00046 #include "SundanceDefs.hpp" 00047 #include "SundanceObjectWithVerbosity.hpp" 00048 #include "Teuchos_Array.hpp" 00049 00050 namespace Sundance 00051 { 00052 using namespace Teuchos; 00053 00054 00055 00056 00057 /** 00058 * A CellJacobianBatch is a collection of Jacobian matrices 00059 * for many quadrature 00060 * points distributed over batch of cells. All cells 00061 * must have the same dimension 00062 * and number of quadrature points. Affine cells have constant Jacobians, 00063 * so in that case the quadrature point index can be ignored. 00064 * See the ReferenceCellBase documentation 00065 * for definitions of the coordinate systems used. 00066 * 00067 * <H4> Data layout </H4> 00068 * All Jacobian elements for all points and cells are 00069 * packed into a single vector. 00070 * The length of the vector is 00071 * \f$ N_{cell} \times N_{quad} \times D^2, \f$ where 00072 * \f$D\f$ is the spatial dimension. 00073 * The indices into the vector cycle in the following order 00074 * (from slowest to fastest) 00075 * <ol> 00076 * <li> cell number 00077 * <li> quadrature point number 00078 * <li> physical coordinate direction 00079 * <li> reference coordinate direction 00080 * </ol> 00081 * Thus, the jacobian values for the \f$q\f$-th quadrature point on the 00082 * \f$c\f$-th cell are the \f$D^2\f$ entries following 00083 * the \f$(q + cN_{quad})D^2\f$-th 00084 * element. 00085 * 00086 */ 00087 class CellJacobianBatch 00088 : public ObjectWithClassVerbosity<CellJacobianBatch> 00089 { 00090 public: 00091 /** empty ctor */ 00092 CellJacobianBatch(); 00093 00094 /** get the spatial dimension */ 00095 int spatialDim() const {return spatialDim_;} 00096 00097 /** get the cell dimension */ 00098 int cellDim() const {return cellDim_;} 00099 00100 /** get the number of cells in the batch */ 00101 int numCells() const {return numCells_;} 00102 00103 /** get the number of quad points per cell */ 00104 int numQuadPoints() const {return numQuad_;} 00105 00106 /** resize the batch */ 00107 void resize(int numCells, int numQuad, int spatialDim, int cellDim); 00108 00109 /** resize the batch, using one quadrature point per cell 00110 * (appropriate for affine elements) */ 00111 void resize(int numCells, int spatialDim, int cellDim); 00112 00113 /** Get a pointer to the values at the q-th quadrature 00114 * point on the c-th cell. 00115 * @param c the index of the cell in the batch 00116 * @param q the index of the quadrature point 00117 */ 00118 double* jVals(int c, int q); 00119 00120 /** 00121 * Get a pointer to the start of the c-th Jacobian in the batch. 00122 */ 00123 double* jVals(int c) 00124 {return &(J_[c*jSize_]);} 00125 00126 /** Get a constant pointer to start of c-th Jacobian in the batch */ 00127 const double *jVals(int c) const { return &(J_[c*jSize_]); } 00128 00129 /** */ 00130 double* detJ(int c) 00131 {return &(detJ_[c]);} 00132 00133 /** get the vector of determinant values */ 00134 const Array<double>& detJ() const 00135 {if (!isFactored_ && cellDim()==spatialDim()) factor(); return detJ_;} 00136 00137 /** 00138 * Apply a cell's inverse Jacobian to (possibly) multiple rhs 00139 * stored in column-major order. 00140 */ 00141 void applyInvJ(int cell, int q, double* rhs, 00142 int nRhs, bool trans) const ; 00143 00144 /** 00145 * Apply an affine cell's inverse Jacobian to (possibly) multiple rhs 00146 * stored in column-major order. 00147 */ 00148 void applyInvJ(int cell, double* rhs, 00149 int nRhs, bool trans) const 00150 {applyInvJ(cell, 0, rhs, nRhs, trans);} 00151 00152 /** 00153 * Get the explicit inverse of the Jacobian for the given 00154 * (cell, quad) combination. 00155 */ 00156 void getInvJ(int cell, int quad, Array<double>& invJ) const ; 00157 00158 /** 00159 * Get the explicit inverse of the Jacobian for the given 00160 * affine cell. 00161 */ 00162 void getInvJ(int cell, Array<double>& invJ) const 00163 {getInvJ(cell, 0, invJ);} 00164 00165 00166 /** */ 00167 void print(std::ostream& os) const ; 00168 00169 static double& totalFlops() {static double rtn = 0; return rtn;} 00170 00171 00172 00173 static void addFlops(const double& flops) {totalFlops() += flops;} 00174 00175 private: 00176 00177 void factor() const ; 00178 00179 void computeInverses() const ; 00180 00181 int spatialDim_; 00182 int cellDim_; 00183 int jSize_; 00184 int numCells_; 00185 int numQuad_; 00186 mutable Array<int> iPiv_; 00187 mutable Array<double> J_; 00188 mutable Array<double> detJ_; 00189 mutable Array<double> invJ_; 00190 mutable bool isFactored_; 00191 mutable bool hasInverses_; 00192 mutable bool hasDetJ_; 00193 }; 00194 00195 00196 inline std::ostream& operator<<(std::ostream& os, 00197 const CellJacobianBatch& J) 00198 { 00199 J.print(os); 00200 return os; 00201 } 00202 } 00203 00204 00205 00206 #endif