00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009
00010 #include "Intrepid_FunctionSpaceTools.hpp"
00011 #include "Intrepid_RealSpaceTools.hpp"
00012
00013 #include <typeinfo>
00014
00015 namespace LCM {
00016
00017
00018 template<typename EvalT, typename Traits>
00019 DefGrad<EvalT, Traits>::
00020 DefGrad(const Teuchos::ParameterList& p) :
00021 GradU (p.get<std::string> ("Gradient QP Variable Name"),
00022 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00023 weights (p.get<std::string> ("Weights Name"),
00024 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00025 defgrad (p.get<std::string> ("DefGrad Name"),
00026 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00027 J (p.get<std::string> ("DetDefGrad Name"),
00028 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00029 weightedAverage(false),
00030 alpha(0.05)
00031 {
00032 if ( p.isType<bool>("Weighted Volume Average J") )
00033 weightedAverage = p.get<bool>("Weighted Volume Average J");
00034 if ( p.isType<RealType>("Average J Stabilization Parameter") )
00035 alpha = p.get<RealType>("Average J Stabilization Parameter");
00036
00037 Teuchos::RCP<PHX::DataLayout> tensor_dl =
00038 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout");
00039
00040 std::vector<PHX::DataLayout::size_type> dims;
00041 tensor_dl->dimensions(dims);
00042 worksetSize = dims[0];
00043 numQPs = dims[1];
00044 numDims = dims[2];
00045
00046 this->addDependentField(GradU);
00047 this->addDependentField(weights);
00048
00049 this->addEvaluatedField(defgrad);
00050 this->addEvaluatedField(J);
00051
00052 this->setName("DefGrad"+PHX::TypeString<EvalT>::value);
00053
00054 }
00055
00056
00057 template<typename EvalT, typename Traits>
00058 void DefGrad<EvalT, Traits>::
00059 postRegistrationSetup(typename Traits::SetupData d,
00060 PHX::FieldManager<Traits>& fm)
00061 {
00062 this->utils.setFieldData(weights,fm);
00063 this->utils.setFieldData(defgrad,fm);
00064 this->utils.setFieldData(J,fm);
00065 this->utils.setFieldData(GradU,fm);
00066 }
00067
00068
00069 template<typename EvalT, typename Traits>
00070 void DefGrad<EvalT, Traits>::
00071 evaluateFields(typename Traits::EvalData workset)
00072 {
00073
00074
00075
00076
00077 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00078 {
00079 for (std::size_t qp=0; qp < numQPs; ++qp)
00080 {
00081 for (std::size_t i=0; i < numDims; ++i)
00082 {
00083 for (std::size_t j=0; j < numDims; ++j)
00084 {
00085 defgrad(cell,qp,i,j) = GradU(cell,qp,i,j);
00086 }
00087 defgrad(cell,qp,i,i) += 1.0;
00088 }
00089 }
00090 }
00091
00092
00093
00094 for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell)
00095 for (std::size_t qp=0; qp < numQPs; ++qp)
00096 for (std::size_t i=0; i < numDims; ++i)
00097 defgrad(cell,qp,i,i) = 1.0;
00098
00099 Intrepid::RealSpaceTools<ScalarT>::det(J, defgrad);
00100
00101 if (weightedAverage)
00102 {
00103 ScalarT Jbar, wJbar, vol;
00104 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00105 {
00106 Jbar = 0.0;
00107 vol = 0.0;
00108 for (std::size_t qp=0; qp < numQPs; ++qp)
00109 {
00110 Jbar += weights(cell,qp) * std::log( J(cell,qp) );
00111 vol += weights(cell,qp);
00112 }
00113 Jbar /= vol;
00114
00115
00116 for (std::size_t qp=0; qp < numQPs; ++qp)
00117 {
00118 for (std::size_t i=0; i < numDims; ++i)
00119 {
00120 for (std::size_t j=0; j < numDims; ++j)
00121 {
00122 wJbar = std::exp( (1-alpha) * Jbar + alpha * std::log( J(cell,qp) ) );
00123 defgrad(cell,qp,i,j) *= std::pow( wJbar / J(cell,qp) ,1./3. );
00124 }
00125 }
00126 J(cell,qp) = wJbar;
00127 }
00128 }
00129 }
00130 }
00131
00132
00133 }