13 #include "neml2/tensors/functions/stack.h" 14 #include "neml2/tensors/functions/sum.h" 26 "This user object calculates the stress divergence for a given set of displacement " 27 "variables and assemble the contribution into the residual vector.");
30 "The displacements variables whose function space will be used to define the test " 33 "The name of the NEML2 variable to use as the stress.");
34 params.
addRequiredParam<std::string>(
"residual",
"The tag for the residual");
40 _residual(dynamic_cast<PetscVector<
Real> *>(&_sys.system().add_vector(
44 _disp_vars(getParam<
std::vector<NonlinearVariableName>>(
"displacements")),
45 _ndisp(_disp_vars.size())
47 mooseAssert(
_residual,
"Failed to cast residual to PetscVector<Real>");
50 mooseError(
"NEML2StressDivergence requires 1 to 3 displacement variables, got ",
64 torch::InferenceMode guard;
67 auto dphiy =
_ndisp >= 2 ? neml2::Tensor(*
_grad_test_y, 3) : neml2::Tensor::zeros_like(dphix);
68 auto dphiz =
_ndisp >= 3 ? neml2::Tensor(*
_grad_test_z, 3) : neml2::Tensor::zeros_like(dphix);
69 auto dphi = neml2::base_stack({dphix, dphiy, dphiz}, 0);
70 auto stress = neml2::R2(neml2::SR2(
_stress)).dynamic_unsqueeze(-2);
73 auto re_qp = neml2::base_sum(dphi * neml2::Tensor(stress), -1);
78 auto re = neml2::dynamic_sum(re_qp * JxWxT, -1)
79 .base_index({neml2::indexing::Slice(0,
_ndisp)});
84 auto re_i = re.base_index({i}).contiguous().cpu();
const neml2::Tensor & getPhiGradient(const std::string &var_name)
const std::vector< dof_id_type > & getGlobalDofMap(const std::string &var_name)
const neml2::Tensor * _grad_test_y
const std::vector< NonlinearVariableName > _disp_vars
Displacement variables.
const neml2::Tensor * _grad_test_x
test function gradients
void forward() override
calculate residual contribution corresponding to the weak form ${i,J} P_{iJ}$
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
static InputParameters validParams()
const neml2::Tensor & JxWxT() const
NEML2StressDivergence(const InputParameters ¶meters)
const int64_t _ndisp
the number of displacement variables
const neml2::Tensor & _stress
stress
PetscVector< Real > * _residual
The residual vector.
NEML2FEInterpolation & _fe
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
static InputParameters validParams()
void mooseError(Args &&... args) const
registerMooseObject("SolidMechanicsApp", NEML2StressDivergence)
NEML2Assembly & _neml2_assembly
neml2::VariableName parseVariableName(const std::string &)
const neml2::Tensor * _grad_test_z
const NEML2ModelExecutor & _constitutive