LCOV - code coverage report
Current view: top level - src/ics - BoundingBoxIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 40 42 95.2 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "BoundingBoxIC.h"
      11             : #include "libmesh/point.h"
      12             : 
      13             : registerMooseObject("MooseApp", BoundingBoxIC);
      14             : 
      15             : InputParameters
      16       14499 : BoundingBoxIC::validParams()
      17             : {
      18       14499 :   InputParameters params = InitialConditionTempl<Real>::validParams();
      19       14499 :   params.addRequiredParam<Real>("x1", "The x coordinate of the lower left-hand corner of the box");
      20       14499 :   params.addRequiredParam<Real>("y1", "The y coordinate of the lower left-hand corner of the box");
      21       14499 :   params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
      22             : 
      23       14499 :   params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
      24       14499 :   params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
      25       14499 :   params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
      26             : 
      27       14499 :   params.addParam<Real>("inside", 0.0, "The value of the variable inside the box");
      28       14499 :   params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
      29             : 
      30       43497 :   params.addParam<Real>(
      31       28998 :       "int_width", 0.0, "The width of the diffuse interface. Set to 0 for sharp interface.");
      32             : 
      33       14499 :   params.addClassDescription("BoundingBoxIC allows setting the initial condition of a value inside "
      34             :                              "and outside of a specified box. The box is aligned with the x, y, z "
      35             :                              "axes");
      36             : 
      37       14499 :   return params;
      38           0 : }
      39             : 
      40         120 : BoundingBoxIC::BoundingBoxIC(const InputParameters & parameters)
      41             :   : InitialCondition(parameters),
      42         120 :     _x1(getParam<Real>("x1")),
      43         120 :     _y1(getParam<Real>("y1")),
      44         120 :     _z1(getParam<Real>("z1")),
      45         120 :     _x2(getParam<Real>("x2")),
      46         120 :     _y2(getParam<Real>("y2")),
      47         120 :     _z2(getParam<Real>("z2")),
      48         120 :     _inside(getParam<Real>("inside")),
      49         120 :     _outside(getParam<Real>("outside")),
      50         120 :     _bottom_left(_x1, _y1, _z1),
      51         120 :     _top_right(_x2, _y2, _z2),
      52         240 :     _int_width(getParam<Real>("int_width"))
      53             : {
      54         120 : }
      55             : 
      56             : Real
      57      116840 : BoundingBoxIC::value(const Point & p)
      58             : {
      59      116840 :   if (_int_width < 0.0)
      60           0 :     mooseError("'int_width' should be non-negative");
      61             : 
      62      116840 :   if (_int_width == 0.0)
      63             :   {
      64      244352 :     for (const auto i : make_range(Moose::dim))
      65      198832 :       if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
      66       54936 :         return _outside;
      67             : 
      68       45520 :     return _inside;
      69             :   }
      70             :   else
      71             :   {
      72       16384 :     Real f_in = 1.0;
      73       65536 :     for (const auto i : make_range(Moose::dim))
      74       49152 :       if (_bottom_left(i) != _top_right(i))
      75       32768 :         f_in *= 0.5 * (std::tanh(2.0 * (p(i) - _bottom_left(i)) / _int_width) -
      76       32768 :                        std::tanh(2.0 * (p(i) - _top_right(i)) / _int_width));
      77             : 
      78       16384 :     return _outside + (_inside - _outside) * f_in;
      79             :   }
      80             : }

Generated by: LCOV version 1.14