LCOV - code coverage report
Current view: top level - src/interfaces - GravityVectorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose misc: #32971 (54bef8) with base c6cf66 Lines: 26 30 86.7 %
Date: 2026-05-29 20:37:18 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "GravityVectorInterface.h"
      11             : #include "PhysicalConstants.h"
      12             : #include "MooseUtils.h"
      13             : #include "MooseObject.h"
      14             : 
      15             : InputParameters
      16         339 : GravityVectorInterface::validParams()
      17             : {
      18         339 :   InputParameters params = emptyInputParameters();
      19         678 :   params.addParam<Real>("gravity_magnitude",
      20             :                         PhysicalConstants::acceleration_of_gravity,
      21             :                         "Magnitude of the gravitational acceleration [m/s^2]");
      22         678 :   params.addParam<RealVectorValue>(
      23             :       "gravity_direction",
      24             :       "Direction of gravitational acceleration. This will be normalized and multiplied by "
      25             :       "'gravity_magnitude'. This parameter is mutually exclusive with 'gravity_vector'.");
      26         678 :   params.addParam<RealVectorValue>("gravity_vector",
      27             :                                    "Gravitational acceleration vector [m/s^2]. This parameter is "
      28             :                                    "mutually exclusive with 'gravity_direction'.");
      29         339 :   return params;
      30           0 : }
      31             : 
      32         171 : GravityVectorInterface::GravityVectorInterface(const MooseObject * moose_object)
      33             : {
      34         342 :   if (moose_object->isParamValid("gravity_direction"))
      35             :   {
      36         226 :     if (moose_object->isParamValid("gravity_vector"))
      37           1 :       moose_object->paramError(
      38             :           "gravity_direction",
      39             :           "The parameters 'gravity_vector' and 'gravity_direction' are mutually exclusive.");
      40             : 
      41         224 :     _gravity_magnitude = moose_object->getParam<Real>("gravity_magnitude");
      42             : 
      43             :     // Direction is normalized below
      44         224 :     _gravity_direction = moose_object->getParam<RealVectorValue>("gravity_direction");
      45             : 
      46             :     // If gravity is zero, direction is the zero vector (which is initial value)
      47         112 :     if (MooseUtils::absoluteFuzzyEqual(_gravity_direction.norm(), 0.0))
      48             :     {
      49          56 :       if (!MooseUtils::absoluteFuzzyEqual(_gravity_magnitude, 0.0))
      50           0 :         mooseError("If 'gravity_direction' is zero, then 'gravity_magnitude' must also be zero.");
      51             :     }
      52             :     else
      53             :     {
      54             :       // If gravity is zero, direction is the zero vector
      55          56 :       if (MooseUtils::absoluteFuzzyEqual(_gravity_magnitude, 0.0))
      56           0 :         _gravity_direction = RealVectorValue(0, 0, 0);
      57             :       else
      58          56 :         _gravity_direction = _gravity_direction.unit();
      59             :     }
      60             : 
      61         112 :     _gravity_vector = _gravity_magnitude * _gravity_direction;
      62             :   }
      63         116 :   else if (moose_object->isParamValid("gravity_vector"))
      64             :   {
      65         114 :     if (moose_object->isParamSetByUser("gravity_magnitude"))
      66           1 :       moose_object->paramError(
      67             :           "gravity_magnitude",
      68             :           "The parameters 'gravity_vector' and 'gravity_magnitude' are mutually exclusive.");
      69             : 
      70         112 :     _gravity_vector = moose_object->getParam<RealVectorValue>("gravity_vector");
      71          56 :     _gravity_magnitude = _gravity_vector.norm();
      72             : 
      73             :     // If gravity is zero, direction is the zero vector
      74          56 :     if (MooseUtils::absoluteFuzzyEqual(_gravity_magnitude, 0.0))
      75          56 :       _gravity_direction = RealVectorValue(0, 0, 0);
      76             :     else
      77           0 :       _gravity_direction = _gravity_vector / _gravity_magnitude;
      78             :   }
      79             :   else
      80           1 :     moose_object->paramError("gravity_vector",
      81             :                              "Either 'gravity_vector' or 'gravity_direction' must be specified.");
      82         168 : }

Generated by: LCOV version 1.14