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 namespace LCM {
00014
00015
00016 template<typename EvalT, typename Traits>
00017 AssumedStrain<EvalT, Traits>::
00018 AssumedStrain(const Teuchos::ParameterList& p) :
00019 GradU (p.get<std::string> ("Gradient QP Variable Name"),
00020 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00021 weights (p.get<std::string> ("Weights Name"),
00022 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout") ),
00023 defgrad (p.get<std::string> ("DefGrad Name"),
00024 p.get<Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout") ),
00025 assumedStrain (p.get<std::string> ("Assumed Strain 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 avgJ (p.get<bool> ("avgJ Name")),
00030 volavgJ (p.get<bool> ("volavgJ Name")),
00031 weighted_Volume_Averaged_J (p.get<bool> ("weighted_Volume_Averaged_J Name"))
00032 {
00033 Teuchos::RCP<PHX::DataLayout> tensor_dl =
00034 p.get< Teuchos::RCP<PHX::DataLayout> >("QP Tensor Data Layout");
00035
00036 std::vector<PHX::DataLayout::size_type> dims;
00037 tensor_dl->dimensions(dims);
00038 worksetSize = dims[0];
00039 numQPs = dims[1];
00040 numDims = dims[2];
00041
00042 this->addDependentField(GradU);
00043 this->addDependentField(weights);
00044
00045 this->addEvaluatedField(defgrad);
00046 this->addEvaluatedField(assumedStrain);
00047 this->addEvaluatedField(J);
00048
00049 this->setName("Assumed Strain"+PHX::TypeString<EvalT>::value);
00050
00051 }
00052
00053
00054 template<typename EvalT, typename Traits>
00055 void AssumedStrain<EvalT, Traits>::
00056 postRegistrationSetup(typename Traits::SetupData d,
00057 PHX::FieldManager<Traits>& fm)
00058 {
00059 this->utils.setFieldData(weights,fm);
00060 this->utils.setFieldData(assumedStrain,fm);
00061 this->utils.setFieldData(J,fm);
00062 this->utils.setFieldData(GradU,fm);
00063 this->utils.setFieldData(defgrad,fm);
00064 }
00065
00066
00067 template<typename EvalT, typename Traits>
00068 void AssumedStrain<EvalT, Traits>::
00069 evaluateFields(typename Traits::EvalData workset)
00070 {
00071
00072 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00073 {
00074 for (std::size_t qp=0; qp < numQPs; ++qp)
00075 {
00076 for (std::size_t i=0; i < numDims; ++i)
00077 {
00078 for (std::size_t j=0; j < numDims; ++j)
00079 {
00080 defgrad(cell,qp,i,j) = GradU(cell,qp,i,j);
00081 }
00082 defgrad(cell,qp,i,i) += 1.0;
00083 }
00084 }
00085 }
00086
00087 Intrepid::RealSpaceTools<ScalarT>::det(J, defgrad);
00088
00089 if (avgJ)
00090 {
00091 ScalarT Jbar;
00092 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00093 {
00094 Jbar = 0.0;
00095 for (std::size_t qp=0; qp < numQPs; ++qp)
00096 {
00097
00098
00099 Jbar += std::log(J(cell,qp));
00100
00101 }
00102 Jbar /= numQPs;
00103 Jbar = std::exp(Jbar);
00104 for (std::size_t qp=0; qp < numQPs; ++qp)
00105 {
00106 for (std::size_t i=0; i < numDims; ++i)
00107 {
00108 for (std::size_t j=0; j < numDims; ++j)
00109 {
00110 defgrad(cell,qp,i,j) *= std::pow(Jbar/J(cell,qp),1./3.);
00111 }
00112 }
00113 J(cell,qp) = Jbar;
00114 }
00115 }
00116 }
00117 else if (volavgJ)
00118 {
00119 ScalarT Jbar, vol;
00120 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00121 {
00122 Jbar = 0.0;
00123 vol = 0.0;
00124 for (std::size_t qp=0; qp < numQPs; ++qp)
00125 {
00126
00127
00128 Jbar += weights(cell,qp) * std::log( J(cell,qp) );
00129 vol += weights(cell,qp);
00130 }
00131 Jbar /= vol;
00132 Jbar = std::exp(Jbar);
00133 for (std::size_t qp=0; qp < numQPs; ++qp)
00134 {
00135 for (std::size_t i=0; i < numDims; ++i)
00136 {
00137 for (std::size_t j=0; j < numDims; ++j)
00138 {
00139 defgrad(cell,qp,i,j) *= std::pow(Jbar/J(cell,qp),1./3.);
00140 }
00141 }
00142 J(cell,qp) = Jbar;
00143 }
00144 }
00145 }
00146 else if (weighted_Volume_Averaged_J)
00147 {
00148 ScalarT Jbar, wJbar, vol;
00149 ScalarT StabAlpha = 0.5;
00150 for (std::size_t cell=0; cell < workset.numCells; ++cell)
00151 {
00152 Jbar = 0.0;
00153 vol = 0.0;
00154 for (std::size_t qp=0; qp < numQPs; ++qp)
00155 {
00156
00157
00158 Jbar += weights(cell,qp) * std::log( J(cell,qp) );
00159 vol += weights(cell,qp);
00160
00161 }
00162 Jbar /= vol;
00163
00164
00165 for (std::size_t qp=0; qp < numQPs; ++qp)
00166 {
00167 for (std::size_t i=0; i < numDims; ++i)
00168 {
00169 for (std::size_t j=0; j < numDims; ++j)
00170 {
00171 wJbar = std::exp( (1-StabAlpha)*Jbar+
00172 StabAlpha*std::log(J(cell,qp)));
00173
00174 defgrad(cell,qp,i,j) *= std::pow(wJbar /J(cell,qp),1./3.);
00175 }
00176 }
00177 J(cell,qp) = wJbar;
00178 }
00179 }
00180 }
00181
00182
00183
00184
00185 for (std::size_t cell=workset.numCells; cell < worksetSize; ++cell)
00186 for (std::size_t qp=0; qp < numQPs; ++qp)
00187 for (std::size_t i=0; i < numDims; ++i)
00188 defgrad(cell,qp,i,i) = 1.0;
00189
00190
00191
00192 for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00193 for (std::size_t qp=0; qp < numQPs; ++qp) {
00194 for (std::size_t i=0; i < numDims; ++i){
00195 for (std::size_t j=0; j < numDims; ++j){
00196 assumedStrain(cell,qp,i,j) =0.5*(defgrad(cell,qp,i,j) + defgrad(cell,qp,j,i));
00197 if (i==j) assumedStrain(cell,qp,i,j) = assumedStrain(cell,qp,i,j) - 1.0;
00198 }
00199 }
00200 }
00201 }
00202
00203
00204
00205
00206
00207 }
00208
00209
00210 }