• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MechanicsResidual_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include <Intrepid_MiniTensor_Mechanics.h>
00008 #include <Teuchos_TestForException.hpp>
00009 #include <Phalanx_DataLayout.hpp>
00010 #include <Sacado_ParameterRegistration.hpp>
00011 
00012 namespace LCM
00013 {
00014 
00015 //------------------------------------------------------------------------------
00016 template<typename EvalT, typename Traits>
00017 MechanicsResidual<EvalT, Traits>::
00018 MechanicsResidual(Teuchos::ParameterList& p,
00019                   const Teuchos::RCP<Albany::Layouts>& dl) :
00020   stress_(p.get<std::string>("Stress Name"), dl->qp_tensor),
00021   w_grad_bf_(p.get<std::string>("Weighted Gradient BF Name"),
00022              dl->node_qp_vector),
00023   w_bf_(p.get<std::string>("Weighted BF Name"), dl->node_qp_scalar),
00024   residual_(p.get<std::string>("Residual Name"), dl->node_vector),
00025   have_body_force_(false),
00026   density_(p.get<RealType>("Density", 1.0))
00027 {
00028   this->addDependentField(stress_);
00029   this->addDependentField(w_grad_bf_);
00030   this->addDependentField(w_bf_);
00031 
00032   this->addEvaluatedField(residual_);
00033 
00034   if (p.isType<bool>("Disable Dynamics"))
00035     enable_dynamics_ = !p.get<bool>("Disable Dynamics");
00036   else enable_dynamics_ = true;
00037 
00038   if (enable_dynamics_) {
00039     PHX::MDField<ScalarT,Cell,QuadPoint,Dim> tmp
00040       (p.get<std::string>("Acceleration Name"), dl->qp_vector);
00041     acceleration_ = tmp;
00042     this->addDependentField(acceleration_);
00043   }
00044 
00045   this->setName("MechanicsResidual" + PHX::TypeString<EvalT>::value);
00046 
00047   if (have_body_force_) {
00048     // grab the pore pressure
00049     PHX::MDField<ScalarT, Cell, QuadPoint, Dim>
00050     tmp(p.get<std::string>("Body Force Name"), dl->qp_vector);
00051     body_force_ = tmp;
00052     this->addDependentField(body_force_);
00053   }
00054 
00055   std::vector<PHX::DataLayout::size_type> dims;
00056   w_grad_bf_.fieldTag().dataLayout().dimensions(dims);
00057   num_nodes_ = dims[1];
00058   num_pts_ = dims[2];
00059   num_dims_ = dims[3];
00060 
00061   Teuchos::RCP<ParamLib> paramLib =
00062       p.get<Teuchos::RCP<ParamLib> >("Parameter Library");
00063 }
00064 
00065 //------------------------------------------------------------------------------
00066 template<typename EvalT, typename Traits>
00067 void MechanicsResidual<EvalT, Traits>::
00068 postRegistrationSetup(typename Traits::SetupData d,
00069     PHX::FieldManager<Traits>& fm)
00070 {
00071   this->utils.setFieldData(stress_, fm);
00072   this->utils.setFieldData(w_grad_bf_, fm);
00073   this->utils.setFieldData(w_bf_, fm);
00074   this->utils.setFieldData(residual_, fm);
00075   if (have_body_force_) {
00076     this->utils.setFieldData(body_force_, fm);
00077   }
00078   if (enable_dynamics_) {
00079     this->utils.setFieldData(acceleration_, fm);
00080   }
00081 }
00082 
00083 //------------------------------------------------------------------------------
00084 template<typename EvalT, typename Traits>
00085 void MechanicsResidual<EvalT, Traits>::
00086 evaluateFields(typename Traits::EvalData workset)
00087 {
00088   //std::cout.precision(15);
00089   // initilize Tensors
00090   // Intrepid::Tensor<ScalarT> F(num_dims_), P(num_dims_), sig(num_dims_);
00091   // Intrepid::Tensor<ScalarT> I(Intrepid::eye<ScalarT>(num_dims_));
00092 
00093   // for large deformation, map Cauchy stress to 1st PK stress
00094   for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00095     for (std::size_t node = 0; node < num_nodes_; ++node) {
00096       for (std::size_t dim = 0; dim < num_dims_; ++dim) {
00097         residual_(cell, node, dim) = 0.0;
00098       }
00099     }
00100     for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00101       for (std::size_t node = 0; node < num_nodes_; ++node) {
00102         for (std::size_t i = 0; i < num_dims_; ++i) {
00103           for (std::size_t j = 0; j < num_dims_; ++j) {
00104             residual_(cell, node, i) +=
00105               stress_(cell, pt, i, j) * w_grad_bf_(cell, node, pt, j);
00106           }
00107         }
00108       }
00109     }
00110   }
00111 
00112   // optional body force
00113   if (have_body_force_) {
00114     for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
00115       for (std::size_t node = 0; node < num_nodes_; ++node) {
00116         for (std::size_t pt = 0; pt < num_pts_; ++pt) {
00117           for (std::size_t dim = 0; dim < num_dims_; ++dim) {
00118             residual_(cell, node, dim) +=
00119                 w_bf_(cell, node, pt) * body_force_(cell, pt, dim);
00120           }
00121         }
00122       }
00123     }
00124   }
00125 
00126   // dynamic term
00127   if (workset.transientTerms && enable_dynamics_) {
00128     for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00129       for (std::size_t node=0; node < num_nodes_; ++node) {
00130         for (std::size_t pt=0; pt < num_pts_; ++pt) {
00131           for (std::size_t dim=0; dim < num_dims_; ++dim) {
00132             residual_(cell,node,dim) += density_ *
00133               acceleration_(cell,pt,dim) * w_bf_(cell,node,pt);
00134           }
00135         }
00136       }
00137     }
00138   }
00139 }
00140 //------------------------------------------------------------------------------
00141 }
00142 

Generated on Wed Mar 26 2014 18:36:40 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1