00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009
00010 #include <Intrepid_MiniTensor.h>
00011
00012 #include <typeinfo>
00013
00014 namespace LCM {
00015
00016
00017 template<typename EvalT, typename Traits>
00018 Kinematics<EvalT, Traits>::
00019 Kinematics(Teuchos::ParameterList& p,
00020 const Teuchos::RCP<Albany::Layouts>& dl) :
00021 grad_u_ (p.get<std::string>("Gradient QP Variable Name"),dl->qp_tensor),
00022 weights_ (p.get<std::string>("Weights Name"),dl->qp_scalar),
00023 def_grad_ (p.get<std::string>("DefGrad Name"),dl->qp_tensor),
00024 j_ (p.get<std::string>("DetDefGrad Name"),dl->qp_scalar),
00025 weighted_average_(p.get<bool>("Weighted Volume Average J", false)),
00026 alpha_(p.get<RealType>("Average J Stabilization Parameter", 0.0)),
00027 needs_vel_grad_(false),
00028 needs_strain_(false)
00029 {
00030 if ( p.isType<bool>("Velocity Gradient Flag") )
00031 needs_vel_grad_ = p.get<bool>("Velocity Gradient Flag");
00032 if ( p.isType<std::string>("Strain Name") ) {
00033 needs_strain_ = true;
00034 PHX::MDField<ScalarT,Cell,QuadPoint,Dim,Dim>
00035 tmp(p.get<std::string>("Strain Name"),dl->qp_tensor);
00036 strain_ = tmp;
00037 this->addEvaluatedField(strain_);
00038 }
00039
00040 std::vector<PHX::DataLayout::size_type> dims;
00041 dl->qp_tensor->dimensions(dims);
00042 num_pts_ = dims[1];
00043 num_dims_ = dims[2];
00044
00045 this->addDependentField(grad_u_);
00046 this->addDependentField(weights_);
00047
00048 this->addEvaluatedField(def_grad_);
00049 this->addEvaluatedField(j_);
00050
00051 if (needs_vel_grad_) {
00052 PHX::MDField<ScalarT,Cell,QuadPoint,Dim,Dim>
00053 tmp(p.get<std::string>("Velocity Gradient Name"),dl->qp_tensor);
00054 vel_grad_ = tmp;
00055 this->addEvaluatedField(vel_grad_);
00056 }
00057
00058 this->setName("Kinematics"+PHX::TypeString<EvalT>::value);
00059
00060 }
00061
00062
00063 template<typename EvalT, typename Traits>
00064 void Kinematics<EvalT, Traits>::
00065 postRegistrationSetup(typename Traits::SetupData d,
00066 PHX::FieldManager<Traits>& fm)
00067 {
00068 this->utils.setFieldData(weights_,fm);
00069 this->utils.setFieldData(def_grad_,fm);
00070 this->utils.setFieldData(j_,fm);
00071 this->utils.setFieldData(grad_u_,fm);
00072 if (needs_strain_) this->utils.setFieldData(strain_,fm);
00073 if (needs_vel_grad_) this->utils.setFieldData(vel_grad_,fm);
00074 }
00075
00076
00077 template<typename EvalT, typename Traits>
00078 void Kinematics<EvalT, Traits>::
00079 evaluateFields(typename Traits::EvalData workset)
00080 {
00081 Intrepid::Tensor<ScalarT> F(num_dims_), strain(num_dims_), gradu(num_dims_);
00082 Intrepid::Tensor<ScalarT> I(Intrepid::eye<ScalarT>(num_dims_));
00083
00084
00085 for (std::size_t cell(0); cell < workset.numCells; ++cell) {
00086 for (std::size_t pt(0); pt < num_pts_; ++pt) {
00087 gradu.fill( &grad_u_(cell,pt,0,0) );
00088 F = I + gradu;
00089 j_(cell,pt) = Intrepid::det(F);
00090 for (std::size_t i(0); i < num_dims_; ++i) {
00091 for (std::size_t j(0); j < num_dims_; ++j) {
00092 def_grad_(cell,pt,i,j) = F(i,j);
00093 }
00094 }
00095 }
00096 }
00097
00098 if (weighted_average_) {
00099 ScalarT jbar, weighted_jbar, volume;
00100 for (std::size_t cell(0); cell < workset.numCells; ++cell) {
00101 jbar = 0.0;
00102 volume = 0.0;
00103 for (std::size_t pt(0); pt < num_pts_; ++pt) {
00104 jbar += weights_(cell,pt) * std::log( j_(cell,pt) );
00105 volume += weights_(cell,pt);
00106 }
00107 jbar /= volume;
00108
00109 for (std::size_t pt(0); pt < num_pts_; ++pt) {
00110 weighted_jbar =
00111 std::exp( (1-alpha_) * jbar + alpha_ * std::log( j_(cell,pt) ) );
00112 F.fill( &def_grad_(cell,pt,0,0) );
00113 F = F*std::pow( (weighted_jbar/j_(cell,pt)), 1./3. );
00114 j_(cell,pt) = weighted_jbar;
00115 for (std::size_t i(0); i < num_dims_; ++i) {
00116 for (std::size_t j(0); j < num_dims_; ++j) {
00117 def_grad_(cell,pt,i,j) = F(i,j);
00118 }
00119 }
00120 }
00121 }
00122 }
00123
00124 if (needs_strain_) {
00125 for (std::size_t cell(0); cell < workset.numCells; ++cell) {
00126 for (std::size_t pt(0); pt < num_pts_; ++pt) {
00127 gradu.fill( &grad_u_(cell,pt,0,0) );
00128 strain = 0.5 * (gradu + Intrepid::transpose(gradu));
00129 for (std::size_t i(0); i < num_dims_; ++i) {
00130 for (std::size_t j(0); j < num_dims_; ++j) {
00131 strain_(cell,pt,i,j) = strain(i,j);
00132 }
00133 }
00134 }
00135 }
00136 }
00137 }
00138
00139 }