00001
00002
00003
00004
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 ShearModulus<EvalT, Traits>::
00017 ShearModulus(Teuchos::ParameterList& p) :
00018 shearModulus(p.get<std::string>("QP Variable Name"),
00019 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout"))
00020 {
00021 Teuchos::ParameterList* shmd_list =
00022 p.get<Teuchos::ParameterList*>("Parameter List");
00023
00024 Teuchos::RCP<PHX::DataLayout> vector_dl =
00025 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
00026 std::vector<PHX::DataLayout::size_type> dims;
00027 vector_dl->dimensions(dims);
00028 numQPs = dims[1];
00029 numDims = dims[2];
00030
00031 Teuchos::RCP<ParamLib> paramLib =
00032 p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);
00033
00034 std::string type = shmd_list->get("Shear Modulus Type", "Constant");
00035 if (type == "Constant") {
00036 is_constant = true;
00037 constant_value = shmd_list->get("Value", 1.0);
00038
00039
00040 new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
00041 "Shear Modulus", 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>(*shmd_list));
00052 int num_KL = exp_rf_kl->stochasticDimension();
00053
00054
00055 rv.resize(num_KL);
00056 for (int i=0; i<num_KL; i++) {
00057 std::string ss = Albany::strint("Shear Modulus KL Random Variable",i);
00058 new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib);
00059 rv[i] = shmd_list->get(ss, 0.0);
00060 }
00061 }
00062 else {
00063 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00064 "Invalid shear modulus type " << type);
00065 }
00066
00067 if ( p.isType<std::string>("QP Temperature Name") ) {
00068 Teuchos::RCP<PHX::DataLayout> scalar_dl =
00069 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
00070 PHX::MDField<ScalarT,Cell,QuadPoint>
00071 tmp(p.get<std::string>("QP Temperature Name"), scalar_dl);
00072 Temperature = tmp;
00073 this->addDependentField(Temperature);
00074 isThermoElastic = true;
00075 dmudT_value = shmd_list->get("dmudT Value", 0.0);
00076 refTemp = p.get<RealType>("Reference Temperature", 0.0);
00077 new Sacado::ParameterRegistration<EvalT, SPL_Traits>(
00078 "dmudT Value", this, paramLib);
00079 }
00080 else {
00081 isThermoElastic=false;
00082 dmudT_value=0.0;
00083 }
00084
00085 this->addEvaluatedField(shearModulus);
00086 this->setName("Shear Modulus"+PHX::TypeString<EvalT>::value);
00087 }
00088
00089
00090 template<typename EvalT, typename Traits>
00091 void ShearModulus<EvalT, Traits>::
00092 postRegistrationSetup(typename Traits::SetupData d,
00093 PHX::FieldManager<Traits>& fm)
00094 {
00095 this->utils.setFieldData(shearModulus,fm);
00096 if (!is_constant) this->utils.setFieldData(coordVec,fm);
00097 if (isThermoElastic) this->utils.setFieldData(Temperature,fm);
00098 }
00099
00100
00101 template<typename EvalT, typename Traits>
00102 void ShearModulus<EvalT, Traits>::
00103 evaluateFields(typename Traits::EvalData workset)
00104 {
00105 std::size_t numCells = workset.numCells;
00106
00107 if (is_constant) {
00108 for (std::size_t cell=0; cell < numCells; ++cell) {
00109 for (std::size_t qp=0; qp < numQPs; ++qp) {
00110 shearModulus(cell,qp) = constant_value;
00111 }
00112 }
00113 }
00114 else {
00115 for (std::size_t cell=0; cell < numCells; ++cell) {
00116 for (std::size_t qp=0; qp < numQPs; ++qp) {
00117 Teuchos::Array<MeshScalarT> point(numDims);
00118 for (std::size_t i=0; i<numDims; i++)
00119 point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i));
00120 shearModulus(cell,qp) = exp_rf_kl->evaluate(point, rv);
00121 }
00122 }
00123 }
00124 if (isThermoElastic) {
00125 for (std::size_t cell=0; cell < numCells; ++cell) {
00126 for (std::size_t qp=0; qp < numQPs; ++qp) {
00127 shearModulus(cell,qp) -= dmudT_value * (Temperature(cell,qp) - refTemp);
00128 }
00129 }
00130 }
00131 }
00132
00133
00134 template<typename EvalT,typename Traits>
00135 typename ShearModulus<EvalT,Traits>::ScalarT&
00136 ShearModulus<EvalT,Traits>::getValue(const std::string &n)
00137 {
00138 if (n == "Shear Modulus")
00139 return constant_value;
00140 else if (n == "dmudT Value")
00141 return dmudT_value;
00142 for (int i=0; i<rv.size(); i++) {
00143 if (n == Albany::strint("Shear Modulus KL Random Variable",i))
00144 return rv[i];
00145 }
00146 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00147 std::endl <<
00148 "Error! Logic error in getting paramter " << n
00149 << " in ShearModulus::getValue()" << std::endl);
00150 return constant_value;
00151 }
00152
00153
00154
00155 }
00156