https://mooseframework.inl.gov
Loading...
Searching...
No Matches
TorchAssembly.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#ifdef MOOSE_LIBTORCH_ENABLED
13
14#include <torch/torch.h>
15
16// MOOSE includes
17#include "ElementUserObject.h"
18
22{
23public:
25
27
29 int64_t numElem() const { return _nelem; }
30
32 int64_t numQP() const { return _nqp; }
33
42 const at::Tensor & JxWxT() const { return _JxWxT; }
43
45 bool upToDate() const { return _up_to_date; }
46
48 void invalidate();
49
50 void meshChanged() override { invalidate(); }
51
52 void initialize() override;
53 void execute() override;
54 void finalize() override;
55 void threadJoin(const UserObject &) override;
56
57protected:
59 bool _up_to_date = false;
60
62 int64_t _nelem;
64 int64_t _nqp;
65
68 std::vector<Real> _moose_JxWxT;
69 at::Tensor _JxWxT;
70};
71
72#endif // MOOSE_LIBTORCH_ENABLED
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This user object caches assembly information (JxWxT) from MOOSE as a batched at::Tensor for the Torch...
void threadJoin(const UserObject &) override
Must override.
int64_t _nelem
number of elements on this rank
void invalidate()
Invalidate the cached assembly information.
void meshChanged() override
Called on this object when the mesh changes.
int64_t numQP() const
Number of quadrature points per element.
bool _up_to_date
Whether the current assembly cache is up to date.
void initialize() override
Called before execute() is ever called so that data can be cleared.
void execute() override
Execute method.
const at::Tensor & JxWxT() const
Get the cached JxWxT for each element, each quadrature point.
int64_t _nqp
number of quadrature points per element
bool upToDate() const
Whether the current assembly cache is up to date.
int64_t numElem() const
Number of active elements on this rank.
std::vector< Real > _moose_JxWxT
JxWxT (product of Jacobian determinant, quadrature weight, and coordinate transformation factor) for ...
void finalize() override
Finalize.
static InputParameters validParams()
at::Tensor _JxWxT
Base class for user-specific data.
Definition UserObject.h:20