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 #include "Albany_Layouts.hpp"
00014
00015
00016
00017
00018 namespace FELIX {
00019
00020 const double pi = 3.1415926535897932385;
00021
00022
00023 template<typename EvalT, typename Traits>
00024 ViscosityFO<EvalT, Traits>::
00025 ViscosityFO(const Teuchos::ParameterList& p,
00026 const Teuchos::RCP<Albany::Layouts>& dl) :
00027 Ugrad (p.get<std::string> ("Gradient QP Variable Name"), dl->qp_vecgradient),
00028 mu (p.get<std::string> ("FELIX Viscosity QP Variable Name"), dl->qp_scalar),
00029 temperature(p.get<std::string> ("Temperature Name"), dl->cell_scalar2),
00030 flowFactorA(p.get<std::string> ("Flow Factor Name"), dl->cell_scalar2),
00031 homotopyParam (1.0),
00032 A(1.0),
00033 n(3.0),
00034 flowRate_type(UNIFORM)
00035 {
00036 Teuchos::ParameterList* visc_list =
00037 p.get<Teuchos::ParameterList*>("Parameter List");
00038
00039 std::string viscType = visc_list->get("Type", "Constant");
00040 std::string flowRateType = visc_list->get("Flow Rate Type", "Uniform");
00041 homotopyParam = visc_list->get("Glen's Law Homotopy Parameter", 0.2);
00042 A = visc_list->get("Glen's Law A", 1.0);
00043 n = visc_list->get("Glen's Law n", 3.0);
00044
00045 Teuchos::RCP<Teuchos::FancyOStream> out(Teuchos::VerboseObjectBase::getDefaultOStream());
00046 if (viscType == "Constant"){
00047 #ifdef OUTPUT_TO_SCREEN
00048 *out << "Constant viscosity!" << std::endl;
00049 #endif
00050 visc_type = CONSTANT;
00051 }
00052 else if (viscType == "ExpTrig") {
00053 #ifdef OUTPUT_TO_SCREEN
00054 *out << "Exp trig viscosity!" << std::endl;
00055 #endif
00056 visc_type = EXPTRIG;
00057 }
00058 else if (viscType == "Glen's Law"){
00059 visc_type = GLENSLAW;
00060 #ifdef OUTPUT_TO_SCREEN
00061 *out << "Glen's law viscosity!" << std::endl;
00062 #endif
00063 if (flowRateType == "Uniform")
00064 {
00065 flowRate_type = UNIFORM;
00066 #ifdef OUTPUT_TO_SCREEN
00067 *out << "Uniform Flow Rate A: " << A << std::endl;
00068 #endif
00069 }
00070 else if (flowRateType == "From File")
00071 {
00072 flowRate_type = FROMFILE;
00073 this->addDependentField(flowFactorA);
00074 #ifdef OUTPUT_TO_SCREEN
00075 *out << "Flow Rate read in from file (exodus or ascii)" << std::endl;
00076 #endif
00077 }
00078 else if (flowRateType == "Temperature Based")
00079 {
00080 flowRate_type = TEMPERATUREBASED;
00081 this->addDependentField(temperature);
00082 #ifdef OUTPUT_TO_SCREEN
00083 *out << "Flow Rate computed using Temperature field" << std::endl;
00084 #endif
00085 }
00086 #ifdef OUTPUT_TO_SCREEN
00087 *out << "n: " << n << std::endl;
00088 #endif
00089 }
00090 coordVec = PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>(
00091 p.get<std::string>("Coordinate Vector Name"),dl->qp_gradient);
00092
00093 this->addDependentField(Ugrad);
00094 this->addDependentField(coordVec);
00095 this->addEvaluatedField(mu);
00096
00097 std::vector<PHX::DataLayout::size_type> dims;
00098 dl->qp_gradient->dimensions(dims);
00099 numQPs = dims[1];
00100 numDims = dims[2];
00101
00102 Teuchos::RCP<ParamLib> paramLib = p.get< Teuchos::RCP<ParamLib> >("Parameter Library");
00103
00104 new Sacado::ParameterRegistration<EvalT, SPL_Traits>("Glen's Law Homotopy Parameter", this, paramLib);
00105
00106 this->setName("ViscosityFO"+PHX::TypeString<EvalT>::value);
00107 }
00108
00109
00110 template<typename EvalT, typename Traits>
00111 void ViscosityFO<EvalT, Traits>::
00112 postRegistrationSetup(typename Traits::SetupData d,
00113 PHX::FieldManager<Traits>& fm)
00114 {
00115 this->utils.setFieldData(Ugrad,fm);
00116 this->utils.setFieldData(mu,fm);
00117 this->utils.setFieldData(coordVec,fm);
00118 if (flowRate_type == TEMPERATUREBASED)
00119 this->utils.setFieldData(temperature,fm);
00120 if (flowRate_type == FROMFILE)
00121 this->utils.setFieldData(flowFactorA,fm);
00122 }
00123
00124
00125 template<typename EvalT,typename Traits>
00126 typename ViscosityFO<EvalT,Traits>::ScalarT&
00127 ViscosityFO<EvalT,Traits>::getValue(const std::string &n)
00128 {
00129 return homotopyParam;
00130 }
00131
00132
00133 template<typename EvalT, typename Traits>
00134 void ViscosityFO<EvalT, Traits>::
00135 evaluateFields(typename Traits::EvalData workset)
00136 {
00137 double a = 1.0;
00138 switch (visc_type) {
00139 case CONSTANT:
00140 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00141 for (std::size_t qp=0; qp < numQPs; ++qp)
00142 mu(cell,qp) = 1.0;
00143 }
00144 break;
00145 case EXPTRIG:
00146 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00147 for (std::size_t qp=0; qp < numQPs; ++qp) {
00148 MeshScalarT x = coordVec(cell,qp,0);
00149 MeshScalarT y2pi = 2.0*pi*coordVec(cell,qp,1);
00150 MeshScalarT muargt = (a*a + 4.0*pi*pi - 2.0*pi*a)*sin(y2pi)*sin(y2pi) + 1.0/4.0*(2.0*pi+a)*(2.0*pi+a)*cos(y2pi)*cos(y2pi);
00151 muargt = sqrt(muargt)*exp(a*x);
00152 mu(cell,qp) = 1.0/2.0*pow(A, -1.0/n)*pow(muargt, 1.0/n - 1.0);
00153 }
00154 }
00155 break;
00156 case GLENSLAW:
00157 std::vector<ScalarT> flowFactorVec;
00158 flowFactorVec.resize(workset.numCells);
00159 switch (flowRate_type) {
00160 case UNIFORM:
00161 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00162 flowFactorVec[cell] = 1.0/2.0*pow(A, -1.0/n);
00163 break;
00164 case TEMPERATUREBASED:
00165 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00166 flowFactorVec[cell] = 1.0/2.0*pow(flowRate(temperature(cell)), -1.0/n);
00167 break;
00168 case FROMFILE:
00169 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00170 flowFactorVec[cell] = 1.0/2.0*pow(flowFactorA(cell), -1.0/n);
00171 break;
00172 }
00173 double power = 0.5*(1.0/n - 1.0);
00174 if (homotopyParam == 0.0) {
00175 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00176 for (std::size_t qp=0; qp < numQPs; ++qp) {
00177 mu(cell,qp) = flowFactorVec[cell];
00178 }
00179 }
00180 }
00181 else {
00182 ScalarT ff = pow(10.0, -10.0*homotopyParam);
00183 ScalarT epsilonEqpSq = 0.0;
00184 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00185 for (std::size_t qp=0; qp < numQPs; ++qp) {
00186
00187 ScalarT& u00 = Ugrad(cell,qp,0,0);
00188 ScalarT& u11 = Ugrad(cell,qp,1,1);
00189 epsilonEqpSq = u00*u00 + u11*u11 + u00*u11;
00190 epsilonEqpSq += 0.25*(Ugrad(cell,qp,0,1) + Ugrad(cell,qp,1,0))*(Ugrad(cell,qp,0,1) + Ugrad(cell,qp,1,0));
00191 for (int dim = 2; dim < numDims; ++dim)
00192 epsilonEqpSq += 0.25*(Ugrad(cell,qp,0,dim)*Ugrad(cell,qp,0,dim) + Ugrad(cell,qp,1,dim)*Ugrad(cell,qp,1,dim) );
00193 epsilonEqpSq += ff;
00194 mu(cell,qp) = flowFactorVec[cell]*pow(epsilonEqpSq, power);
00195 }
00196 }
00197 }
00198 break;
00199 }
00200 }
00201 }