00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Teuchos_VerboseObject.hpp"
00009 #include "Phalanx_DataLayout.hpp"
00010 #include "Sacado_ParameterRegistration.hpp"
00011
00012 #include "Intrepid_FunctionSpaceTools.hpp"
00013
00014 namespace FELIX {
00015
00016 const double pi = 3.1415926535897932385;
00017
00018
00019
00020
00021 template<typename EvalT, typename Traits>
00022 Viscosity<EvalT, Traits>::
00023 Viscosity(const Teuchos::ParameterList& p,
00024 const Teuchos::RCP<Albany::Layouts>& dl) :
00025 VGrad (p.get<std::string> ("Velocity Gradient QP Variable Name"), dl->qp_tensor),
00026 mu (p.get<std::string> ("FELIX Viscosity QP Variable Name"), dl->qp_scalar),
00027 homotopyParam (1.0),
00028 A(1.0),
00029 n(3.0)
00030 {
00031 Teuchos::ParameterList* visc_list =
00032 p.get<Teuchos::ParameterList*>("Parameter List");
00033
00034 std::string viscType = visc_list->get("Type", "Constant");
00035 homotopyParam = visc_list->get("Glen's Law Homotopy Parameter", 0.2);
00036 A = visc_list->get("Glen's Law A", 1.0);
00037 n = visc_list->get("Glen's Law n", 3.0);
00038
00039 Teuchos::RCP<Teuchos::FancyOStream> out(Teuchos::VerboseObjectBase::getDefaultOStream());
00040 if (viscType == "Constant"){
00041 *out << "Constant viscosity!" << std::endl;
00042 visc_type = CONSTANT;
00043 }
00044 else if (viscType == "Glen's Law"){
00045 visc_type = GLENSLAW;
00046 *out << "Glen's law viscosity!" << std::endl;
00047 *out << "A: " << A << std::endl;
00048 *out << "n: " << n << std::endl;
00049 }
00050
00051 coordVec = PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>(
00052 p.get<std::string>("Coordinate Vector Name"),dl->qp_gradient);
00053 this->addDependentField(coordVec);
00054
00055 this->addDependentField(VGrad);
00056
00057 this->addEvaluatedField(mu);
00058
00059 std::vector<PHX::DataLayout::size_type> dims;
00060 dl->qp_gradient->dimensions(dims);
00061 numQPs = dims[1];
00062 numDims = dims[2];
00063
00064 Teuchos::RCP<ParamLib> paramLib = p.get< Teuchos::RCP<ParamLib> >("Parameter Library");
00065
00066 new Sacado::ParameterRegistration<EvalT, SPL_Traits>("Glen's Law Homotopy Parameter", this, paramLib);
00067
00068 this->setName("Viscosity"+PHX::TypeString<EvalT>::value);
00069 }
00070
00071
00072 template<typename EvalT, typename Traits>
00073 void Viscosity<EvalT, Traits>::
00074 postRegistrationSetup(typename Traits::SetupData d,
00075 PHX::FieldManager<Traits>& fm)
00076 {
00077 this->utils.setFieldData(VGrad,fm);
00078 this->utils.setFieldData(coordVec,fm);
00079 this->utils.setFieldData(mu,fm);
00080 }
00081
00082
00083 template<typename EvalT,typename Traits>
00084 typename Viscosity<EvalT,Traits>::ScalarT&
00085 Viscosity<EvalT,Traits>::getValue(const std::string &n)
00086 {
00087 return homotopyParam;
00088 }
00089
00090
00091 template<typename EvalT, typename Traits>
00092 void Viscosity<EvalT, Traits>::
00093 evaluateFields(typename Traits::EvalData workset)
00094 {
00095 if (visc_type == CONSTANT){
00096 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00097 for (std::size_t qp=0; qp < numQPs; ++qp) {
00098 mu(cell,qp) = 1.0;
00099 }
00100 }
00101 }
00102 else if (visc_type == GLENSLAW) {
00103 if (homotopyParam == 0.0) {
00104 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00105 for (std::size_t qp=0; qp < numQPs; ++qp) {
00106 mu(cell,qp) = 1.0/2.0*pow(A, -1.0/n);
00107 }
00108 }
00109 }
00110 else {
00111 ScalarT ff = pow(10.0, -10.0*homotopyParam);
00112 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00113 for (std::size_t qp=0; qp < numQPs; ++qp) {
00114
00115 ScalarT epsilonEqp = 0.0;
00116 for (std::size_t k=0; k<numDims; k++) {
00117 for (std::size_t l=0; l<numDims; l++) {
00118 epsilonEqp += 1.0/8.0*(VGrad(cell,qp,k,l) + VGrad(cell,qp,l,k))*(VGrad(cell,qp,k,l) + VGrad(cell,qp,l,k));
00119 }
00120 }
00121 epsilonEqp += ff;
00122 epsilonEqp = sqrt(epsilonEqp);
00123 mu(cell,qp) = 1.0/2.0*pow(A, -1.0/n)*pow(epsilonEqp, 1.0/n-1.0);
00124
00125 }
00126 }
00127 }
00128 }
00129 }
00130 }
00131