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

PoissonsRatio_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 <fstream>
00008 #include "Teuchos_TestForException.hpp"
00009 #include "Phalanx_DataLayout.hpp"
00010 #include "Sacado_ParameterRegistration.hpp"
00011 #include "Albany_Utils.hpp"
00012 
00013 namespace LCM {
00014 
00015 template<typename EvalT, typename Traits>
00016 PoissonsRatio<EvalT, Traits>::
00017 PoissonsRatio(Teuchos::ParameterList& p) :
00018   poissonsRatio(p.get<std::string>("QP Variable Name"),
00019       p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"))
00020 {
00021   Teuchos::ParameterList* pr_list = 
00022     p.get<Teuchos::ParameterList*>("Parameter List");
00023   
00024   Teuchos::RCP<ParamLib> paramLib = 
00025     p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);
00026 
00027   Teuchos::RCP<PHX::DataLayout> vector_dl =
00028     p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
00029   std::vector<PHX::DataLayout::size_type> dims;
00030   vector_dl->dimensions(dims);
00031   numQPs  = dims[1];
00032   numDims = dims[2];
00033 
00034   std::string type = pr_list->get("Poissons Ratio Type", "Constant");
00035   if (type == "Constant") {
00036     is_constant = true;
00037     constant_value = pr_list->get("Value", 1.0);
00038 
00039     // Add Poissons Ratio as a Sacado-ized parameter
00040     new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
00041       "Poissons Ratio", this, paramLib);
00042   }
00043   else if (type == "Truncated KL Expansion") {
00044     is_constant = false;
00045     PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>
00046       fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl);
00047     coordVec = fx;
00048     this->addDependentField(coordVec);
00049 
00050     exp_rf_kl = 
00051       Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<MeshScalarT>(*pr_list));
00052     int num_KL = exp_rf_kl->stochasticDimension();
00053 
00054     // Add KL random variables as Sacado-ized parameters
00055     rv.resize(num_KL);
00056     for (int i=0; i<num_KL; i++) {
00057       std::string ss = Albany::strint("Poissons Ratio KL Random Variable",i);
00058       new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib);
00059       rv[i] = pr_list->get(ss, 0.0);
00060     }
00061   }
00062   else {
00063     TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00064              "Invalid Poissons ratio type " << type);
00065   } 
00066 
00067   // Optional dependence on Temperature (nu = nu_ + dnudT * T)
00068   // Switched ON by sending Temperature field in p
00069 
00070   if ( p.isType<std::string>("QP Temperature Name") ) {
00071     Teuchos::RCP<PHX::DataLayout> scalar_dl =
00072       p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
00073     PHX::MDField<ScalarT,Cell,QuadPoint>
00074       tmp(p.get<std::string>("QP Temperature Name"), scalar_dl);
00075     Temperature = tmp;
00076     this->addDependentField(Temperature);
00077     isThermoElastic = true;
00078     dnudT_value = pr_list->get("dnudT Value", 0.0);
00079     refTemp = p.get<RealType>("Reference Temperature", 0.0);
00080     new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
00081                                 "dnudT Value", this, paramLib);
00082   }
00083   else {
00084     isThermoElastic=false;
00085     dnudT_value=0.0;
00086   }
00087 
00088 
00089   this->addEvaluatedField(poissonsRatio);
00090   this->setName("Poissons Ratio"+PHX::TypeString<EvalT>::value);
00091 }
00092 
00093 // **********************************************************************
00094 template<typename EvalT, typename Traits>
00095 void PoissonsRatio<EvalT, Traits>::
00096 postRegistrationSetup(typename Traits::SetupData d,
00097                       PHX::FieldManager<Traits>& fm)
00098 {
00099   this->utils.setFieldData(poissonsRatio,fm);
00100   if (!is_constant) this->utils.setFieldData(coordVec,fm);
00101   if (isThermoElastic) this->utils.setFieldData(Temperature,fm);
00102 }
00103 
00104 // **********************************************************************
00105 template<typename EvalT, typename Traits>
00106 void PoissonsRatio<EvalT, Traits>::
00107 evaluateFields(typename Traits::EvalData workset)
00108 {
00109   std::size_t numCells = workset.numCells;
00110 
00111   if (is_constant) {
00112     for (std::size_t cell=0; cell < numCells; ++cell) {
00113       for (std::size_t qp=0; qp < numQPs; ++qp) {
00114   poissonsRatio(cell,qp) = constant_value;
00115       }
00116     }
00117   }
00118   else {
00119     for (std::size_t cell=0; cell < numCells; ++cell) {
00120       for (std::size_t qp=0; qp < numQPs; ++qp) {
00121   Teuchos::Array<MeshScalarT> point(numDims);
00122   for (std::size_t i=0; i<numDims; i++)
00123     point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i));
00124   poissonsRatio(cell,qp) = exp_rf_kl->evaluate(point, rv);
00125       }
00126     }
00127   }
00128   if (isThermoElastic) {
00129     for (std::size_t cell=0; cell < numCells; ++cell) {
00130       for (std::size_t qp=0; qp < numQPs; ++qp) {
00131         poissonsRatio(cell,qp) += dnudT_value * (Temperature(cell,qp) - refTemp);;
00132       }
00133     }
00134   }
00135 }
00136 
00137 // **********************************************************************
00138 template<typename EvalT,typename Traits>
00139 typename PoissonsRatio<EvalT,Traits>::ScalarT& 
00140 PoissonsRatio<EvalT,Traits>::getValue(const std::string &n)
00141 {
00142   if (n=="Poissons Ratio")
00143     return constant_value;
00144   else if (n == "dnudT Value")
00145     return dnudT_value;
00146   for (int i=0; i<rv.size(); i++) {
00147     if (n == Albany::strint("Poissons Ratio KL Random Variable",i))
00148       return rv[i];
00149   }
00150   TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00151            std::endl <<
00152            "Error! Logic error in getting paramter " << n
00153            << " in PoissonsRatio::getValue()" << std::endl);
00154   return constant_value;
00155 }
00156 
00157 // **********************************************************************
00158 // **********************************************************************
00159 }
00160 

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