void Kinematics<EvalT, Traits>::evaluateFields(typename Traits::EvalData workset) { minitensor::Tensor<ScalarT> F(num_dims_), strain(num_dims_), gradu(num_dims_); minitensor::Tensor<ScalarT> I(minitensor::eye<ScalarT>(num_dims_)); // Compute DefGrad tensor from displacement gradient if (!def_grad_rc_) { for (int cell(0); cell < workset.numCells; ++cell) { for (int pt(0); pt < num_pts_; ++pt) { gradu.fill(grad_u_, cell, pt, 0, 0); F = I + gradu; j_(cell, pt) = minitensor::det(F); for (int i(0); i < num_dims_; ++i) { for (int j(0); j < num_dims_; ++j) { def_grad_(cell, pt, i, j) = F(i, j); } } } } } else { bool first = true; for (int cell = 0; cell < workset.numCells; ++cell) { for (int pt = 0; pt < num_pts_; ++pt) { gradu.fill(grad_u_, cell, pt, 0, 0); F = I + gradu; for (int i = 0; i < num_dims_; ++i) for (int j = 0; j < num_dims_; ++j) def_grad_(cell, pt, i, j) = F(i, j); if (first && check_det(workset, cell, pt)) first = false; // F[n,0] = F[n,n-1] F[n-1,0]. def_grad_rc_.multiplyInto<ScalarT>(def_grad_, cell, pt); F.fill(def_grad_, cell, pt, 0, 0); j_(cell, pt) = minitensor::det(F); } } } if (weighted_average_) { ScalarT jbar, weighted_jbar, volume; for (int cell(0); cell < workset.numCells; ++cell) { jbar = 0.0; volume = 0.0; for (int pt(0); pt < num_pts_; ++pt) { jbar += weights_(cell, pt) * j_(cell, pt); volume += weights_(cell, pt); } jbar /= volume; for (int pt(0); pt < num_pts_; ++pt) { weighted_jbar = (1 - alpha_) * jbar + alpha_ * j_(cell, pt); F.fill(def_grad_, cell, pt, 0, 0); const ScalarT p = std::pow((weighted_jbar / j_(cell, pt)), 1. / 3.); F *= p; j_(cell, pt) = weighted_jbar; for (int i(0); i < num_dims_; ++i) { for (int j(0); j < num_dims_; ++j) { def_grad_(cell, pt, i, j) = F(i, j); } } } } } if (needs_strain_) { if (!def_grad_rc_) { for (int cell(0); cell < workset.numCells; ++cell) { for (int pt(0); pt < num_pts_; ++pt) { gradu.fill(grad_u_, cell, pt, 0, 0); strain = 0.5 * (gradu + minitensor::transpose(gradu)); for (int i(0); i < num_dims_; ++i) { for (int j(0); j < num_dims_; ++j) { strain_(cell, pt, i, j) = strain(i, j); } } } } } else { for (int cell = 0; cell < workset.numCells; ++cell) { for (int pt = 0; pt < num_pts_; ++pt) { F.fill(def_grad_, cell, pt, 0, 0); gradu = F - I; // dU/dx[0] = dx[n]/dx[0] - dx[0]/dx[0] = F[n,0] - I. // strain = 1/2 (dU/dx[0] + dU/dx[0]^T). strain = 0.5 * (gradu + minitensor::transpose(gradu)); for (int i = 0; i < num_dims_; ++i) for (int j = 0; j < num_dims_; ++j) strain_(cell, pt, i, j) = strain(i, j); } } } } }
void MechanicsResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { std::cout.precision(15); // initilize Tensors Intrepid::Tensor<ScalarT> F(num_dims_), P(num_dims_), sig(num_dims_); Intrepid::Tensor<ScalarT> I(Intrepid::eye<ScalarT>(num_dims_)); if (have_pore_pressure_) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t pt=0; pt < num_pts_; ++pt) { // Effective Stress theory sig.fill( &stress_(cell,pt,0,0) ); sig -= biot_coeff_(cell,pt) * pore_pressure_(cell,pt) * I; for (std::size_t i=0; i<num_dims_; i++) { for (std::size_t j=0; j<num_dims_; j++) { stress_(cell,pt,i,j) = sig(i,j); } } } } } // initialize residual if(have_strain_){ // for small deformation, use Cauchy stress for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t node=0; node < num_nodes_; ++node) { for (std::size_t dim=0; dim<num_dims_; ++dim) { residual_(cell,node,dim)=0.0; } } for (std::size_t pt=0; pt < num_pts_; ++pt) { //F.fill( &def_grad_(cell,pt,0,0) ); sig.fill( &stress_(cell,pt,0,0) ); for (std::size_t node=0; node < num_nodes_; ++node) { for (std::size_t i=0; i<num_dims_; ++i) { for (std::size_t j=0; j<num_dims_; ++j) { residual_(cell,node,i) += sig(i, j) * w_grad_bf_(cell, node, pt, j); } } } } } } else { // for large deformation, map Cauchy stress to 1st PK stress for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t node=0; node < num_nodes_; ++node) { for (std::size_t dim=0; dim<num_dims_; ++dim) { residual_(cell,node,dim)=0.0; } } for (std::size_t pt=0; pt < num_pts_; ++pt) { F.fill( &def_grad_(cell,pt,0,0) ); sig.fill( &stress_(cell,pt,0,0) ); // map Cauchy stress to 1st PK P = Intrepid::piola(F,sig); for (std::size_t node=0; node < num_nodes_; ++node) { for (std::size_t i=0; i<num_dims_; ++i) { for (std::size_t j=0; j<num_dims_; ++j) { residual_(cell,node,i) += P(i, j) * w_grad_bf_(cell, node, pt, j); } } } } } } // optional body force if (have_body_force_) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t node=0; node < num_nodes_; ++node) { for (std::size_t pt=0; pt < num_pts_; ++pt) { for (std::size_t dim=0; dim<num_dims_; ++dim) { residual_(cell,node,dim) += w_bf_(cell,node,pt) * body_force_(cell,pt,dim); } } } } } }