23 "This user object calculates the stress divergence for a given set of displacement "
24 "variables and assembles the contribution into the residual vector.");
27 "The displacements variables whose function space will be used to define the test "
30 "The name of the NEML2 variable to use as the stress.");
31 params.
addRequiredParam<std::string>(
"residual",
"The tag for the residual");
37 _residual(dynamic_cast<
libMesh::PetscVector<Real> *>(&_sys.system().add_vector(
38 getParam<
std::string>(
"residual"), false,
libMesh::ParallelType::GHOSTED))),
39 _stress(_constitutive.getOutput(getParam<
std::string>(
"stress"))),
40 _disp_vars(getParam<
std::vector<NonlinearVariableName>>(
"displacements")),
41 _ndisp(_disp_vars.size())
43 mooseAssert(
_residual,
"Failed to cast residual to PetscVector<Real>");
46 mooseError(
"TorchStressDivergence requires 1 to 3 displacement variables, got ",
60 torch::InferenceMode guard;
61 using at::indexing::Slice;
69 auto dphi = at::stack({dphix, dphiy, dphiz}, 3);
74 auto re_qp = (dphi * stress).sum(-1);
78 auto re = (re_qp * JxWxT).sum(2);
81 for (
auto i : make_range(
_ndisp))
83 auto re_i = re.select(-1, i).contiguous().cpu();
registerMooseObject("SolidMechanicsApp", TorchStressDivergence)
void mooseError(Args &&... args) const
const at::Tensor & JxWxT() const
const std::vector< dof_id_type > & getGlobalDofMap(const std::string &var_name)
const at::Tensor & getPhiGradient(const std::string &var_name)
TorchFEInterpolation & _fe
TorchAssembly & _assembly
const NEML2ModelExecutor & _constitutive
static InputParameters validParams()
const at::Tensor * _grad_test_x
test function gradients
const std::vector< NonlinearVariableName > _disp_vars
Displacement variables.
const at::Tensor * _grad_test_z
static InputParameters validParams()
const int64_t _ndisp
the number of displacement variables
void forward() override
calculate residual contribution corresponding to the weak form $\phi_{i,J} P_{iJ}$
libMesh::PetscVector< Real > * _residual
The residual vector.
const at::Tensor * _grad_test_y
const at::Tensor & _stress
stress (a NEML2 model output, 6-component Mandel)
TorchStressDivergence(const InputParameters ¶meters)
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices) override
virtual void close() override
at::Tensor mandelToFull(const at::Tensor &mandel)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...