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 Porosity<EvalT, Traits>::
00018 Porosity(Teuchos::ParameterList& p,
00019 const Teuchos::RCP<Albany::Layouts>& dl) :
00020 porosity(p.get<std::string>("Porosity Name"),dl->qp_scalar),
00021 is_constant(true),
00022 isCompressibleSolidPhase(false),
00023 isCompressibleFluidPhase(false),
00024 isPoroElastic(false),
00025 hasStrain(false),
00026 hasJ(false),
00027 hasTemp(false)
00028 {
00029 Teuchos::ParameterList* porosity_list =
00030 p.get<Teuchos::ParameterList*>("Parameter List");
00031
00032 std::vector<PHX::DataLayout::size_type> dims;
00033 dl->qp_vector->dimensions(dims);
00034 numQPs = dims[1];
00035 numDims = dims[2];
00036
00037 Teuchos::RCP<ParamLib> paramLib =
00038 p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);
00039
00040 std::string type = porosity_list->get("Porosity Type", "Constant");
00041 if (type == "Constant") {
00042 is_constant = true;
00043
00044 constant_value = porosity_list->get("Value", 0.0);
00045
00046 new Sacado::ParameterRegistration<EvalT, SPL_Traits>
00047 ("Porosity", this, paramLib);
00048 }
00049 else if (type == "Truncated KL Expansion") {
00050 is_constant = false;
00051 PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>
00052 fx(p.get<std::string>("QP Coordinate Vector Name"), dl->qp_vector);
00053 coordVec = fx;
00054 this->addDependentField(coordVec);
00055
00056 exp_rf_kl =
00057 Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<MeshScalarT>
00058 (*porosity_list));
00059 int num_KL = exp_rf_kl->stochasticDimension();
00060
00061
00062 rv.resize(num_KL);
00063 for (int i=0; i<num_KL; i++) {
00064 std::string ss = Albany::strint("Porosity KL Random Variable",i);
00065 new Sacado::ParameterRegistration<EvalT, SPL_Traits>
00066 (ss, this, paramLib);
00067 rv[i] = porosity_list->get(ss, 0.0);
00068 }
00069 }
00070 else {
00071 TEUCHOS_TEST_FOR_EXCEPTION(true,
00072 Teuchos::Exceptions::InvalidParameter,
00073 "Invalid porosity type " << type);
00074 }
00075
00076
00077
00078 if ( p.isType<std::string>("Strain Name") ) {
00079
00080
00081
00082
00083
00084
00085
00086
00087 hasStrain = true;
00088
00089 PHX::MDField<ScalarT,Cell,QuadPoint,Dim, Dim>
00090 ts(p.get<std::string>("Strain Name"), dl->qp_tensor);
00091 strain = ts;
00092 this->addDependentField(strain);
00093
00094 isCompressibleSolidPhase = true;
00095 isCompressibleFluidPhase = true;
00096 isPoroElastic = true;
00097 initialPorosityValue =
00098 porosity_list->get("Initial Porosity Value", 0.0);
00099 new Sacado::ParameterRegistration<EvalT, SPL_Traits>
00100 ("Initial Porosity Value", this, paramLib);
00101 }
00102 else if ( p.isType<std::string>("DetDefGrad Name") ) {
00103 hasJ = true;
00104 PHX::MDField<ScalarT,Cell,QuadPoint>
00105 tj(p.get<std::string>("DetDefGrad Name"), dl->qp_scalar);
00106 J = tj;
00107 this->addDependentField(J);
00108 isPoroElastic = true;
00109 initialPorosityValue =
00110 porosity_list->get("Initial Porosity Value", 0.0);
00111 new Sacado::ParameterRegistration<EvalT, SPL_Traits>
00112 ("Initial Porosity Value", this, paramLib);
00113 }
00114 else {
00115
00116 isPoroElastic=false;
00117 initialPorosityValue=0.0;
00118 }
00119
00120 if ( p.isType<std::string>("Biot Coefficient Name") ) {
00121 PHX::MDField<ScalarT,Cell,QuadPoint>
00122 btp(p.get<std::string>("Biot Coefficient Name"), dl->qp_scalar);
00123 biotCoefficient = btp;
00124 isCompressibleSolidPhase = true;
00125 isCompressibleFluidPhase = true;
00126 isPoroElastic = true;
00127 this->addDependentField(biotCoefficient);
00128 }
00129
00130 if ( p.isType<std::string>("QP Pore Pressure Name") ) {
00131 PHX::MDField<ScalarT,Cell,QuadPoint>
00132 ppn(p.get<std::string>("QP Pore Pressure Name"), dl->qp_scalar);
00133 porePressure = ppn;
00134 isCompressibleSolidPhase = true;
00135 isCompressibleFluidPhase = true;
00136 isPoroElastic = true;
00137 this->addDependentField(porePressure);
00138
00139
00140 GrainBulkModulus =
00141 porosity_list->get("Grain Bulk Modulus Value", 10.0e12);
00142 new Sacado::ParameterRegistration<EvalT, SPL_Traits>
00143 ("Grain Bulk Modulus Value", this, paramLib);
00144 }
00145
00146 if ( p.isType<std::string>("QP Temperature Name") ) {
00147 PHX::MDField<ScalarT,Cell,QuadPoint>
00148 ppn(p.get<std::string>("QP Temperature Name"), dl->qp_scalar);
00149 Temperature = ppn;
00150 this->addDependentField(Temperature);
00151
00152
00153
00154 if ( p.isType<std::string>("Skeleton Thermal Expansion Name") ) {
00155 PHX::MDField<ScalarT,Cell,QuadPoint>
00156 skte(p.get<std::string>("Skeleton Thermal Expansion Name"), dl->qp_scalar);
00157 skeletonThermalExpansion = skte;
00158 this->addDependentField(skeletonThermalExpansion);
00159
00160
00161 if ( p.isType<std::string>("Reference Temperature Name") ) {
00162 PHX::MDField<ScalarT,Cell,QuadPoint>
00163 reftemp(p.get<std::string>("Reference Temperature Name"), dl->qp_scalar);
00164 refTemperature = reftemp;
00165 hasTemp = true;
00166 this->addDependentField(refTemperature);
00167
00168 }
00169 }
00170 }
00171
00172
00173 this->addEvaluatedField(porosity);
00174 this->setName("Porosity"+PHX::TypeString<EvalT>::value);
00175 }
00176
00177
00178 template<typename EvalT, typename Traits>
00179 void Porosity<EvalT, Traits>::
00180 postRegistrationSetup(typename Traits::SetupData d,
00181 PHX::FieldManager<Traits>& fm)
00182 {
00183 this->utils.setFieldData(porosity,fm);
00184 if (!is_constant) this->utils.setFieldData(coordVec,fm);
00185 if (isPoroElastic && hasStrain) this->utils.setFieldData(strain,fm);
00186 if (isPoroElastic && hasJ) this->utils.setFieldData(J,fm);
00187 if (isPoroElastic && hasTemp) this->utils.setFieldData(Temperature,fm);
00188 if (isPoroElastic && hasTemp) this->utils.setFieldData(refTemperature,fm);
00189 if (isPoroElastic && hasTemp) this->utils.setFieldData(skeletonThermalExpansion,fm);
00190 if (isCompressibleSolidPhase) this->utils.setFieldData(biotCoefficient,fm);
00191 if (isCompressibleFluidPhase) this->utils.setFieldData(porePressure,fm);
00192
00193 }
00194
00195
00196 template<typename EvalT, typename Traits>
00197 void Porosity<EvalT, Traits>::
00198 evaluateFields(typename Traits::EvalData workset)
00199 {
00200 std::size_t numCells = workset.numCells;
00201
00202 ScalarT temp;
00203
00204 if (is_constant) {
00205 for (std::size_t cell=0; cell < numCells; ++cell) {
00206 for (std::size_t qp=0; qp < numQPs; ++qp) {
00207 porosity(cell,qp) = constant_value;
00208 }
00209 }
00210 }
00211 else {
00212 for (std::size_t cell=0; cell < numCells; ++cell) {
00213 for (std::size_t qp=0; qp < numQPs; ++qp) {
00214 Teuchos::Array<MeshScalarT> point(numDims);
00215 for (std::size_t i=0; i<numDims; i++)
00216 point[i] = Sacado::ScalarValue<MeshScalarT>::eval(coordVec(cell,qp,i));
00217 porosity(cell,qp) = exp_rf_kl->evaluate(point, rv);
00218 }
00219 }
00220 }
00221
00222
00223 if ((isPoroElastic) && (isCompressibleSolidPhase) && (isCompressibleFluidPhase)) {
00224
00225
00226 if ( hasStrain ) {
00227 for (std::size_t cell=0; cell < numCells; ++cell) {
00228 for (std::size_t qp=0; qp < numQPs; ++qp) {
00229
00230
00231 porosity(cell,qp) = initialPorosityValue;
00232
00233 Teuchos::Array<MeshScalarT> point(numDims);
00234
00235 for (std::size_t i=0; i<numDims; i++) {
00236 porosity(cell,qp) = initialPorosityValue + biotCoefficient(cell,qp)*strain(cell,qp,i,i)
00237 + porePressure(cell,qp)
00238 *(biotCoefficient(cell,qp)-initialPorosityValue)/GrainBulkModulus;
00239 }
00240
00241 if ( porosity(cell,qp) < 0 ) {
00242 std::cout << "negative porosity detected. Error! \n";
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 }
00254 }
00255 } else if ( hasJ )
00256 for (std::size_t cell=0; cell < numCells; ++cell) {
00257 for (std::size_t qp=0; qp < numQPs; ++qp) {
00258 if (hasTemp == false){
00259 porosity(cell,qp) = initialPorosityValue*std::exp(
00260 GrainBulkModulus/(porePressure(cell,qp) + GrainBulkModulus)*
00261 biotCoefficient(cell,qp)*std::log(J(cell,qp)) +
00262 biotCoefficient(cell,qp)/(porePressure(cell,qp) + GrainBulkModulus)*
00263 porePressure(cell,qp));
00264 } else{
00265 temp = 1.0 + porePressure(cell,qp)/GrainBulkModulus
00266 - 3.0*skeletonThermalExpansion(cell,qp)*
00267 (Temperature(cell,qp)-refTemperature(cell,qp));
00268
00269 porosity(cell,qp) = initialPorosityValue*std::exp(
00270 biotCoefficient(cell,qp)*std::log(J(cell,qp)) +
00271 biotCoefficient(cell,qp)/GrainBulkModulus*porePressure(cell,qp)-
00272 3.0*J(cell,qp)*skeletonThermalExpansion(cell,qp)*
00273 (Temperature(cell,qp)-refTemperature(cell,qp))/temp);
00274 }
00275
00276
00277
00278 if ( porosity(cell,qp) < 0 ) {
00279 std::cout << "negative porosity detected. Error! \n";
00280 }
00281
00282 }
00283 }
00284 } else {
00285 for (std::size_t cell=0; cell < numCells; ++cell) {
00286 for (std::size_t qp=0; qp < numQPs; ++qp) {
00287 porosity(cell,qp) = initialPorosityValue;
00288
00289
00290
00291
00292
00293
00294
00295
00296 }
00297 }
00298 }
00299 }
00300
00301
00302 template<typename EvalT,typename Traits>
00303 typename Porosity<EvalT,Traits>::ScalarT&
00304 Porosity<EvalT,Traits>::getValue(const std::string &n)
00305 {
00306 if (n == "Porosity")
00307 return constant_value;
00308 else if (n == "Initial Porosity Value")
00309 return initialPorosityValue;
00310 else if (n == "Grain Bulk Modulus Value")
00311 return GrainBulkModulus;
00312 for (int i=0; i<rv.size(); i++) {
00313 if (n == Albany::strint("Porosity KL Random Variable",i))
00314 return rv[i];
00315 }
00316 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00317 std::endl <<
00318 "Error! Logic error in getting parameter " << n
00319 << " in Porosity::getValue()" << std::endl);
00320 return constant_value;
00321 }
00322
00323
00324 }
00325