LCOV - code coverage report
Current view: top level - src/tensor_computes - GradientTensor.C (source / functions) Hit Total Coverage
Test: idaholab/swift: #92 (25e020) with base b3cd84 Lines: 0 15 0.0 %
Date: 2025-09-10 17:10:32 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          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 "MooseError.h"
      10             : #include "GradientTensor.h"
      11             : #include "SwiftUtils.h"
      12             : #include "TensorProblem.h"
      13             : 
      14             : registerMooseObject("SwiftApp", GradientTensor);
      15             : 
      16             : InputParameters
      17           0 : GradientTensor::validParams()
      18             : {
      19           0 :   InputParameters params = TensorOperator<GradientTensorType>::validParams();
      20             : #ifdef NEML2_ENABLED
      21             :   params.addClassDescription("Gradient of the coupled tensor buffer.");
      22             : #else
      23           0 :   params.addClassDescription("Object requires NEML2.");
      24             : #endif
      25             : 
      26           0 :   params.addParam<TensorInputBufferName>("input", "Input buffer name");
      27           0 :   params.addParam<bool>(
      28           0 :       "input_is_reciprocal", false, "Input buffer is already in reciprocal space");
      29           0 :   return params;
      30           0 : }
      31             : 
      32           0 : GradientTensor::GradientTensor(const InputParameters & parameters)
      33             :   : TensorOperator<GradientTensorType>(parameters),
      34           0 :     _input(getInputBuffer("input")),
      35           0 :     _input_is_reciprocal(getParam<bool>("input_is_reciprocal")),
      36           0 :     _zero(torch::tensor(0.0, MooseTensor::floatTensorOptions()))
      37             : {
      38             : #ifndef NEML2_ENABLED
      39           0 :   mooseError("Object requires NEML2");
      40             : #endif
      41             : }
      42             : 
      43             : void
      44           0 : GradientTensor::computeBuffer()
      45             : {
      46             : #ifdef NEML2_ENABLED
      47             :   auto i_reciprocal_input = (_input_is_reciprocal ? _input : _domain.fft(_input)) * _imaginary;
      48             :   auto grad_x = neml2::Scalar(_domain.ifft(i_reciprocal_input * _i), _dim);
      49             :   auto grad_y = neml2::Scalar(_dim > 1 ? _domain.ifft(i_reciprocal_input * _j) : _zero, _dim);
      50             :   auto grad_z = neml2::Scalar(_dim > 2 ? _domain.ifft(i_reciprocal_input * _k) : _zero, _dim);
      51             :   _u = neml2::Vec::fill(grad_x, grad_y, grad_z);
      52             : #endif
      53           0 : }

Generated by: LCOV version 1.14