LCOV - code coverage report
Current view: top level - src/tensor_computes - LBMIsotropicLaplacian.C (source / functions) Hit Total Coverage
Test: idaholab/swift: #92 (25e020) with base b3cd84 Lines: 0 37 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 "LBMIsotropicLaplacian.h"
      10             : 
      11             : using namespace torch::indexing;
      12             : 
      13             : registerMooseObject("SwiftApp", LBMIsotropicLaplacian);
      14             : 
      15             : InputParameters
      16           0 : LBMIsotropicLaplacian::validParams()
      17             : {
      18           0 :   InputParameters params = LatticeBoltzmannOperator::validParams();
      19           0 :   params.addClassDescription("Compute isotropic Laplacian object.");
      20           0 :   params.addRequiredParam<TensorInputBufferName>("scalar_field",
      21             :                                                  "Scalar field to compute the Laplacian of");
      22             : 
      23           0 :   return params;
      24           0 : }
      25             : 
      26           0 : LBMIsotropicLaplacian::LBMIsotropicLaplacian(const InputParameters & parameters)
      27           0 :   : LBMIsotropicGradient(parameters)
      28             : {
      29           0 :   const unsigned int & dim = _domain.getDim();
      30             : 
      31             :   // Note: if D3Q19 stencil is used, isotropic gradient is NOT going to work,
      32             :   // because D3Q19 is NOT isotropic.
      33             : 
      34           0 :   if (_stencil._q == 19)
      35           0 :     mooseError("Isotropic Laplacian cannot be computed for D3Q19 stencil");
      36             : 
      37           0 :   _kernel = torch::zeros({3, 3}, MooseTensor::floatTensorOptions());
      38             : 
      39           0 :   switch (dim)
      40             :   {
      41           0 :     case 3:
      42           0 :       mooseError("LBMIsotropicLaplacian is not implemented for 3D");
      43             :       break;
      44           0 :     case 2:
      45             :     {
      46             :       _kernel =
      47           0 :           torch::index_select(_stencil._weights, 0, _stencil._reorder_indices).reshape({3, 3});
      48           0 :       _conv_options.bias(torch::Tensor()).stride({1, 1}).padding(0);
      49           0 :       break;
      50             :     }
      51             :   }
      52           0 : }
      53             : 
      54             : void
      55           0 : LBMIsotropicLaplacian::computeBuffer()
      56             : {
      57           0 :   const unsigned int & dim = _domain.getDim();
      58           0 :   torch::Tensor kernel = _kernel.view({1, 1, 3, 3});
      59             : 
      60           0 :   switch (dim)
      61             :   {
      62           0 :     case 3:
      63           0 :       mooseError("LBMIsotropicGradient is not implemented for 3D");
      64             :       break;
      65           0 :     case 2:
      66             :     {
      67           0 :       if (_scalar_field.dim() > 2)
      68           0 :         _scalar_field.squeeze_(-1);
      69             : 
      70           0 :       torch::Tensor input_field = padScalarField();
      71             : 
      72           0 :       input_field = input_field.unsqueeze(0).unsqueeze(0);
      73             : 
      74             :       torch::Tensor isotropic_Laplacian_1 =
      75           0 :           torch::nn::functional::conv2d(input_field, kernel, _conv_options);
      76             : 
      77           0 :       isotropic_Laplacian_1 = 2.0 * isotropic_Laplacian_1.squeeze(0).squeeze(0);
      78             : 
      79             :       auto isotropic_Laplacian_2 =
      80             :           2.0 *
      81           0 :           torch::sum(_scalar_field.unsqueeze(-1) * _stencil._weights.unsqueeze(0).unsqueeze(0), -1);
      82             : 
      83           0 :       _u = (isotropic_Laplacian_1.unsqueeze(-1) - isotropic_Laplacian_2.unsqueeze(-1)) /
      84           0 :            _lb_problem._cs2;
      85             :       break;
      86             :     }
      87             :   }
      88           0 : }

Generated by: LCOV version 1.14