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

PHAL_HeatEqResid_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 
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009 
00010 #include "Intrepid_FunctionSpaceTools.hpp"
00011 
00012 namespace PHAL {
00013 
00014 //**********************************************************************
00015 template<typename EvalT, typename Traits>
00016 HeatEqResid<EvalT, Traits>::
00017 HeatEqResid(const Teuchos::ParameterList& p) :
00018   wBF         (p.get<std::string>                   ("Weighted BF Name"),
00019          p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Scalar Data Layout") ),
00020   Temperature (p.get<std::string>                   ("QP Variable Name"),
00021          p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00022   Tdot        (p.get<std::string>                   ("QP Time Derivative Variable Name"),
00023          p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00024   ThermalCond (p.get<std::string>                   ("Thermal Conductivity Name"),
00025          p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00026   wGradBF     (p.get<std::string>                   ("Weighted Gradient BF Name"),
00027          p.get<Teuchos::RCP<PHX::DataLayout> >("Node QP Vector Data Layout") ),
00028   TGrad       (p.get<std::string>                   ("Gradient QP Variable Name"),
00029          p.get<Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout") ),
00030   Source      (p.get<std::string>                   ("Source Name"),
00031          p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00032   TResidual   (p.get<std::string>                   ("Residual Name"),
00033          p.get<Teuchos::RCP<PHX::DataLayout> >("Node Scalar Data Layout") ),
00034   haveSource  (p.get<bool>("Have Source")),
00035   haveConvection(false),
00036   haveAbsorption  (p.get<bool>("Have Absorption")),
00037   haverhoCp(false)
00038 {
00039 
00040   if (p.isType<bool>("Disable Transient"))
00041     enableTransient = !p.get<bool>("Disable Transient");
00042   else enableTransient = true;
00043 
00044   this->addDependentField(wBF);
00045   this->addDependentField(Temperature);
00046   this->addDependentField(ThermalCond);
00047   if (enableTransient) this->addDependentField(Tdot);
00048   this->addDependentField(TGrad);
00049   this->addDependentField(wGradBF);
00050   if (haveSource) this->addDependentField(Source);
00051   if (haveAbsorption) {
00052     Absorption = PHX::MDField<ScalarT,Cell,QuadPoint>(
00053   p.get<std::string>("Absorption Name"),
00054   p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"));
00055     this->addDependentField(Absorption);
00056   }
00057   this->addEvaluatedField(TResidual);
00058 
00059   Teuchos::RCP<PHX::DataLayout> vector_dl =
00060     p.get< Teuchos::RCP<PHX::DataLayout> >("Node QP Vector Data Layout");
00061   std::vector<PHX::DataLayout::size_type> dims;
00062   vector_dl->dimensions(dims);
00063   worksetSize = dims[0];
00064   numNodes = dims[1];
00065   numQPs  = dims[2];
00066   numDims = dims[3];
00067 
00068 
00069   // Allocate workspace
00070   flux.resize(dims[0], numQPs, numDims);
00071 
00072   if (haveAbsorption)  aterm.resize(dims[0], numQPs);
00073 
00074   convectionVels = Teuchos::getArrayFromStringParameter<double> (p,
00075                            "Convection Velocity", numDims, false);
00076   if (p.isType<std::string>("Convection Velocity")) {
00077     convectionVels = Teuchos::getArrayFromStringParameter<double> (p,
00078                              "Convection Velocity", numDims, false);
00079   }
00080   if (convectionVels.size()>0) {
00081     haveConvection = true;
00082     if (p.isType<bool>("Have Rho Cp"))
00083       haverhoCp = p.get<bool>("Have Rho Cp");
00084     if (haverhoCp) {
00085       PHX::MDField<ScalarT,Cell,QuadPoint> tmp(p.get<std::string>("Rho Cp Name"),
00086             p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"));
00087       rhoCp = tmp;
00088       this->addDependentField(rhoCp);
00089     }
00090   }
00091 
00092   this->setName("HeatEqResid"+PHX::TypeString<EvalT>::value);
00093 }
00094 
00095 //**********************************************************************
00096 template<typename EvalT, typename Traits>
00097 void HeatEqResid<EvalT, Traits>::
00098 postRegistrationSetup(typename Traits::SetupData d,
00099                       PHX::FieldManager<Traits>& fm)
00100 {
00101   this->utils.setFieldData(wBF,fm);
00102   this->utils.setFieldData(Temperature,fm);
00103   this->utils.setFieldData(ThermalCond,fm);
00104   this->utils.setFieldData(TGrad,fm);
00105   this->utils.setFieldData(wGradBF,fm);
00106   if (haveSource)  this->utils.setFieldData(Source,fm);
00107   if (enableTransient) this->utils.setFieldData(Tdot,fm);
00108 
00109   if (haveAbsorption)  this->utils.setFieldData(Absorption,fm);
00110 
00111   if (haveConvection && haverhoCp)  this->utils.setFieldData(rhoCp,fm);
00112 
00113   this->utils.setFieldData(TResidual,fm);
00114 }
00115 
00116 //**********************************************************************
00117 template<typename EvalT, typename Traits>
00118 void HeatEqResid<EvalT, Traits>::
00119 evaluateFields(typename Traits::EvalData workset)
00120 {
00121 
00122 // workset.print(std::cout);
00123 
00124   typedef Intrepid::FunctionSpaceTools FST;
00125 
00126   FST::scalarMultiplyDataData<ScalarT> (flux, ThermalCond, TGrad);
00127 
00128   FST::integrate<ScalarT>(TResidual, flux, wGradBF, Intrepid::COMP_CPP, false); // "false" overwrites
00129 
00130   if (haveSource) {
00131     for (int i=0; i<Source.size(); i++) Source[i] *= -1.0;
00132     FST::integrate<ScalarT>(TResidual, Source, wBF, Intrepid::COMP_CPP, true); // "true" sums into
00133   }
00134 
00135   if (workset.transientTerms && enableTransient) 
00136     FST::integrate<ScalarT>(TResidual, Tdot, wBF, Intrepid::COMP_CPP, true); // "true" sums into
00137 
00138   if (haveConvection)  {
00139     Intrepid::FieldContainer<ScalarT> convection(worksetSize, numQPs);
00140 
00141     for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00142       for (std::size_t qp=0; qp < numQPs; ++qp) {
00143         convection(cell,qp) = 0.0;
00144         for (std::size_t i=0; i < numDims; ++i) {
00145           if (haverhoCp)
00146             convection(cell,qp) += rhoCp(cell,qp) * convectionVels[i] * TGrad(cell,qp,i);
00147           else
00148             convection(cell,qp) += convectionVels[i] * TGrad(cell,qp,i);
00149         }
00150       }
00151     }
00152 
00153     FST::integrate<ScalarT>(TResidual, convection, wBF, Intrepid::COMP_CPP, true); // "true" sums into
00154   }
00155 
00156 
00157   if (haveAbsorption) {
00158     FST::scalarMultiplyDataData<ScalarT> (aterm, Absorption, Temperature);
00159     FST::integrate<ScalarT>(TResidual, aterm, wBF, Intrepid::COMP_CPP, true); 
00160   }
00161 
00162 //TResidual.print(std::cout, true);
00163 
00164 }
00165 
00166 //**********************************************************************
00167 }
00168 

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