LCOV - code coverage report
Current view: top level - src/postprocessors - ReciprocalIntegral.C (source / functions) Hit Total Coverage
Test: idaholab/swift: #92 (25e020) with base b3cd84 Lines: 20 21 95.2 %
Date: 2025-09-10 17:10:32 Functions: 5 5 100.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 "ReciprocalIntegral.h"
      10             : #include "DomainAction.h"
      11             : 
      12             : registerMooseObject("SwiftApp", ReciprocalIntegral);
      13             : 
      14             : InputParameters
      15           8 : ReciprocalIntegral::validParams()
      16             : {
      17           8 :   InputParameters params = TensorPostprocessor::validParams();
      18           8 :   params.addClassDescription("Extract the zero k-vector value (corresponding to the integral).");
      19           8 :   return params;
      20           0 : }
      21             : 
      22           4 : ReciprocalIntegral::ReciprocalIntegral(const InputParameters & parameters)
      23           4 :   : TensorPostprocessor(parameters)
      24             : 
      25             : {
      26           4 : }
      27             : 
      28             : void
      29           4 : ReciprocalIntegral::execute()
      30             : {
      31           4 :   static const at::indexing::TensorIndex zero[3] = {0, 0, 0};
      32             :   // Extract the zero-frequency component at index {0, 0, ..., 0} for arbitrary dimensions
      33             :   torch::Tensor zero_frequency_tensor =
      34           4 :       _u.index(torch::ArrayRef<at::indexing::TensorIndex>(zero, _u.dim()));
      35             : 
      36             :   // Convert to std::complex<double> (TODO: or float!)
      37           4 :   _integral = torch::real(zero_frequency_tensor).item<double>();
      38             : 
      39             :   // divide by number of cells in real space
      40           4 :   const auto & n = _domain.getGridSize();
      41           4 :   _integral /= n[0] * n[1] * n[2];
      42             : 
      43             :   // multiply by domain size
      44             :   const auto & volume = _domain.getVolume();
      45           4 :   mooseInfo(volume);
      46           4 :   _integral *= volume;
      47             : 
      48             :   // for parallelism only the proc owning the global 0 matters...
      49           4 : }
      50             : 
      51             : void
      52           4 : ReciprocalIntegral::finalize()
      53             : {
      54             :   // proc that owns 0 should broadcast it. everyone else listens
      55           4 : }
      56             : 
      57             : PostprocessorValue
      58           4 : ReciprocalIntegral::getValue() const
      59             : {
      60           4 :   return _integral;
      61             : }

Generated by: LCOV version 1.14