Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* Swift, a Fourier spectral solver for MOOSE */ 4 : /* */ 5 : /* Copyright 2024 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #include "NEML2TensorBuffer.h" 10 : 11 : registerMooseObject("SwiftApp", VectorTensor); 12 : registerMooseObject("SwiftApp", SR2Tensor); 13 : 14 : template <typename T> 15 : InputParameters 16 0 : NEML2TensorBuffer<T>::validParams() 17 : { 18 : InputParameters params = TensorBuffer<T>::validParams(); 19 : if constexpr (std::is_same_v<T, torch::Tensor>) 20 0 : params.addClassDescription("This tensor type requires Swift to be built woth NEML2."); 21 0 : return params; 22 0 : } 23 : 24 : template <typename T> 25 0 : NEML2TensorBuffer<T>::NEML2TensorBuffer(const InputParameters & parameters) 26 0 : : TensorBuffer<T>(parameters) 27 : { 28 : if constexpr (std::is_same_v<T, torch::Tensor>) 29 0 : mooseError("This tensor type requires Swift to be built woth NEML2."); 30 : 31 : mooseInfoRepeated("Instantiating NEML2 tensor class ", libMesh::demangle(typeid(T).name())); 32 0 : } 33 : 34 : template <typename T> 35 : void 36 0 : NEML2TensorBuffer<T>::init() 37 : { 38 : // TODO 39 0 : } 40 : 41 : template <typename T> 42 : void 43 0 : NEML2TensorBuffer<T>::makeCPUCopy() 44 : { 45 : if constexpr (std::is_same_v<T, torch::Tensor>) 46 0 : mooseError("This tensor type requires Swift to be built woth NEML2."); 47 : else 48 : { 49 : if (!_u.defined()) 50 : return; 51 : 52 : if (_cpu_copy_requested) 53 : { 54 : if (_u.is_cpu()) 55 : _u_cpu = T(_u.clone().contiguous(), _u.batch_dim()); 56 : else 57 : _u_cpu = T(_u.cpu().contiguous(), _u.batch_dim()); 58 : } 59 : } 60 : } 61 : 62 : #ifdef NEML2_ENABLED 63 : template class NEML2TensorBuffer<neml2::Vec>; 64 : template class NEML2TensorBuffer<neml2::SR2>; 65 : #else 66 : template class NEML2TensorBuffer<torch::Tensor>; 67 : #endif