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