12#ifdef MOOSE_LIBTORCH_ENABLED
32scatter(
const at::Tensor & v,
const at::Tensor & dof_map)
34 return v.index({dof_map});
43interpolate(
const at::Tensor & elem_dofs,
const at::Tensor & basis)
46 while (ed.dim() < basis.dim())
47 ed = ed.unsqueeze(-1);
48 return (ed * basis).sum(1);
57assemble(
const at::Tensor & scattered,
const at::Tensor & dof_map, int64_t ndof)
59 return at::zeros({ndof}, scattered.options())
60 .scatter_add_(0, dof_map.flatten(), scattered.flatten());
72 const double s2 = std::sqrt(2.0);
73 auto c = [&full](
int i,
int j) {
return full.select(-2, i).select(-1, j); };
74 return at::stack({c(0, 0), c(1, 1), c(2, 2), s2 * c(1, 2), s2 * c(0, 2), s2 * c(0, 1)}, -1);
84 const double is2 = 1.0 / std::sqrt(2.0);
85 auto m = [&mandel](
int k) {
return mandel.select(-1, k); };
86 auto d0 = m(0), d1 = m(1), d2 = m(2);
87 auto o12 = m(3) * is2, o02 = m(4) * is2, o01 = m(5) * is2;
88 auto row0 = at::stack({d0, o01, o02}, -1);
89 auto row1 = at::stack({o01, d1, o12}, -1);
90 auto row2 = at::stack({o02, o12, d2}, -1);
91 return at::stack({row0, row1, row2}, -2);
Small raw-ATen helpers for the batched finite-element assembly used by the Torch FEM kernels.
at::Tensor fullToMandel(const at::Tensor &full)
Convert a full (symmetric) rank-2 tensor to its 6-component Mandel representation,...
at::Tensor scatter(const at::Tensor &v, const at::Tensor &dof_map)
Gather global solution values into element-local DOF values: out[e,a,...] = v[dof_map[e,...
at::Tensor mandelToFull(const at::Tensor &mandel)
Inverse of fullToMandel: expand a 6-component Mandel tensor to a full symmetric (....
at::Tensor assemble(const at::Tensor &scattered, const at::Tensor &dof_map, int64_t ndof)
Scatter-add element-local contributions into a global vector: out[dof_map.flatten()[k]] += scattered....
at::Tensor interpolate(const at::Tensor &elem_dofs, const at::Tensor &basis)
Interpolate element-local DOF values onto quadrature points by contracting over the per-element DOF a...