• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

FaceAverage_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 #include "Teuchos_TestForException.hpp"
00007 #include "Phalanx_DataLayout.hpp"
00008 
00009 #include "Intrepid_FunctionSpaceTools.hpp"
00010 #include "Intrepid_RealSpaceTools.hpp"
00011 
00012 #include <typeinfo>
00013 
00014 namespace LCM {
00015 
00016 template<typename EvalT, typename Traits>
00017 FaceAverage<EvalT, Traits>::
00018 FaceAverage(const Teuchos::ParameterList& p) :
00019   coordinates(p.get<std::string>("Coordinate Vector Name"),
00020     p.get<Teuchos::RCP<PHX::DataLayout> >("Vertex Vector Data Layout")),
00021   projected(p.get<std::string>("Projected Field Name"),
00022     p.get<Teuchos::RCP<PHX::DataLayout> >("Node Vector Data Layout")),
00023   cubature(p.get<Teuchos::RCP<Intrepid::Cubature<RealType> > >("Face Cubature")),
00024   intrepidBasis(p.get<Teuchos::RCP<Intrepid::Basis
00025     <RealType, Intrepid::FieldContainer<RealType> > > >("Face Intrepid Basis")),
00026   cellType(p.get<Teuchos::RCP<shards::CellTopology> >("Cell Type")),
00027   faceAve(p.get<std::string>("Face Average Name"),
00028     p.get<Teuchos::RCP<PHX::DataLayout> >("Face Vector Data Layout")),
00029   temp(p.get<std::string>("Temp Name"),
00030           p.get<Teuchos::RCP<PHX::DataLayout> >("Cell Scalar Data Layout"))
00031 {
00032     this->addDependentField(coordinates);
00033     this->addDependentField(projected);
00034     this->addEvaluatedField(faceAve);
00035 
00036     this->addEvaluatedField(temp); // temp for testing
00037 
00038     // Get Dimensions
00039     Teuchos::RCP<PHX::DataLayout> vec_dl =
00040       p.get<Teuchos::RCP<PHX::DataLayout> >("Node Vector Data Layout");
00041     std::vector<PHX::DataLayout::size_type> dims;
00042     vec_dl->dimensions(dims);
00043 
00044     worksetSize = dims[0];
00045     numNodes    = dims[1];
00046     numComp     = dims[2];
00047 
00048     /* As the vector length for this problem is not equal to the number
00049      * of spatial dimensions (as in the normal mechanics problems), we
00050      * get the spatial dimension from the coordinate vector.
00051      */
00052     Teuchos::RCP<PHX::DataLayout> vertex_dl =
00053       p.get<Teuchos::RCP<PHX::DataLayout> >("Vertex Vector Data Layout");
00054     vertex_dl->dimensions(dims);
00055     numDims = dims[2];
00056 
00057     // The number of quadrature points for the face
00058     numQPs = cubature->getNumPoints();
00059 
00060     numFaces = cellType->getFaceCount();
00061     faceDim = numDims - 1; // see note below for an explanation why this may be suboptimal
00062 
00063     /*  Get the number of face nodes from the cellType object.
00064      *  Note: Assumes that the face rank is one less than the
00065      *  spatial rank of the system. Will be incorrect if lower rank
00066      *  elements are embedded in a higher order problem(e.g. plate
00067      *  elements in a 3D problem).
00068      *  It might be better to replace this with a call to the topology
00069      *  of the cell face itself with
00070      *  numFaceNodes = sides->getCellTopology->num_nodes
00071      */
00072     numFaceNodes = cellType->getNodeCount(numDims-1,0);
00073 
00074     // Need the local ordering of the nodes on the faces
00075     sides = cellType->getCellTopologyData()->side;
00076 
00077     // Get the quadrature weights and basis functions
00078     refPoints.resize(numQPs,faceDim);
00079     refWeights.resize(numQPs);
00080     refValues.resize(numFaceNodes,numQPs);
00081 
00082     cubature->getCubature(refPoints,refWeights);
00083     intrepidBasis->getValues(refValues, refPoints, Intrepid::OPERATOR_VALUE);
00084 
00085 
00086     this->setName("FaceAverage"+PHX::TypeString<EvalT>::value);
00087 
00088 }
00089 
00090 template<typename EvalT, typename Traits>
00091 void FaceAverage<EvalT,Traits>::
00092 postRegistrationSetup(typename Traits::SetupData d,
00093         PHX::FieldManager<Traits>& fm)
00094 {
00095     this->utils.setFieldData(coordinates,fm);
00096     this->utils.setFieldData(projected, fm);
00097     this->utils.setFieldData(faceAve, fm);
00098 
00099     this->utils.setFieldData(temp,fm);  // temp for testing
00100 
00101 }
00102 
00103 template<typename EvalT, typename Traits>
00104 void FaceAverage<EvalT,Traits>::
00105 evaluateFields(typename Traits::EvalData workset)
00106 {
00107 
00108 
00109     // test output of the side ordering
00110     /*
00111     for (std::size_t i=0; i < cellType->getSideCount(); ++i){
00112       cout << "Side " << i << ":" << std::endl;
00113       for (std::size_t j=0; j < 4; ++j){
00114          cout << sides[i].node[j] << ",";
00115       }
00116       cout << std::endl;
00117     }
00118     */
00119 
00120     for (std::size_t cell=0; cell < workset.numCells; ++cell)
00121     {
00122       for (std::size_t face=0; face<numFaces; ++face)
00123       {
00124         for (std::size_t comp=0; comp<numComp; ++comp)
00125         {
00126           faceAve(cell,face,comp) = 0.0;
00127           double area = 0.0;
00128 
00129           for (std::size_t qp=0; qp<numQPs; ++qp)
00130           {
00131             area += refWeights(qp);
00132 
00133             for (std::size_t np=0; np<numFaceNodes; ++np)
00134             {
00135               // map from the local face node numbering to the local
00136               // element node numbering
00137               int node = sides[face].node[np];
00138               faceAve(cell,face,comp) += refValues(np,qp)*projected(cell,node,comp)*refWeights(qp);
00139               // A more naive averaging scheme
00140               //faceAve(cell,face,i) += projected(cell,node,i);
00141             }  // node
00142           }  // quadrature point
00143 
00144           faceAve(cell,face,comp) = faceAve(cell,face,comp) / area;
00145           // A more naive averaging scheme
00146           //faceAve(cell,face,i) = faceAve(cell,face,i)/static_cast<ScalarT>(numFaceNodes);
00147 
00148           // For debug purposes
00149           //cout << "Face Average (cell,face): (" << cell << "," << face << "): "
00150           //                    << faceAve(cell,face,comp) << std::endl;
00151         } // vector component
00152       } // face
00153 
00154       // temp variable to trick the code into running the evaluator
00155       temp(cell) = cell;
00156     } // cell
00157 }
00158 
00159 } // namespace LCM
00160 

Generated on Wed Mar 26 2014 18:36:38 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1