LCOV - code coverage report
Current view: top level - src/ics - MultiBoundingBoxIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 32 35 91.4 %
Date: 2025-09-04 07:55:36 Functions: 4 4 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 "MultiBoundingBoxIC.h"
      11             : #include "MooseMesh.h"
      12             : #include "FEProblemBase.h"
      13             : 
      14             : registerMooseObject("PhaseFieldApp", MultiBoundingBoxIC);
      15             : 
      16             : namespace
      17             : {
      18             : // Convenience function for sizing a vector to "n" given a vector with size 1 or "n"
      19             : std::vector<Real>
      20         234 : sizeVector(std::vector<Real> v, std::size_t size)
      21             : {
      22         234 :   if (v.size() == 1)
      23         198 :     return std::vector<Real>(size, v[0]);
      24             :   else
      25             :     return v;
      26             : }
      27             : }
      28             : 
      29             : InputParameters
      30         444 : MultiBoundingBoxIC::validParams()
      31             : {
      32         444 :   InputParameters params = InitialCondition::validParams();
      33         444 :   params.addClassDescription("Specify variable values inside and outside a list of box shaped "
      34             :                              "axis-aligned regions defined by pairs of opposing corners");
      35         888 :   params.addRequiredParam<std::vector<Point>>("corners", "The corner coordinates boxes");
      36         888 :   params.addRequiredParam<std::vector<Point>>(
      37             :       "opposite_corners", "The coordinates of the opposite corners of the boxes");
      38         888 :   params.addRequiredParam<std::vector<Real>>("inside",
      39             :                                              "The value of the variable inside each box "
      40             :                                              "(one value per box or a single value for "
      41             :                                              "all boxes)");
      42         888 :   params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
      43             : 
      44         444 :   params.addClassDescription("Allows setting the initial condition of a value of a field inside "
      45             :                              "and outside multiple bounding boxes.");
      46         444 :   return params;
      47           0 : }
      48             : 
      49         234 : MultiBoundingBoxIC::MultiBoundingBoxIC(const InputParameters & parameters)
      50             :   : InitialCondition(parameters),
      51         234 :     _c1(getParam<std::vector<Point>>("corners")),
      52         702 :     _c2(getParam<std::vector<Point>>("opposite_corners")),
      53         234 :     _nbox(_c1.size()),
      54         234 :     _dim(_fe_problem.mesh().dimension()),
      55         468 :     _inside(sizeVector(getParam<std::vector<Real>>("inside"), _nbox)),
      56         702 :     _outside(getParam<Real>("outside"))
      57             : {
      58             :   // make sure inputs are the same length
      59         234 :   if (_c2.size() != _nbox || _inside.size() != _nbox)
      60           0 :     mooseError("vector inputs must all be the same size");
      61         234 : }
      62             : 
      63             : Real
      64     1324128 : MultiBoundingBoxIC::value(const Point & p)
      65             : {
      66     1324128 :   Real value = _outside;
      67             : 
      68     3642078 :   for (unsigned int b = 0; b < _nbox; ++b)
      69             :   {
      70     2626416 :     if ((_c1[b](0) < _c2[b](0) && p(0) >= _c1[b](0) && p(0) <= _c2[b](0)) ||
      71       94296 :         (_c1[b](0) >= _c2[b](0) && p(0) <= _c1[b](0) && p(0) >= _c2[b](0)))
      72      806460 :       if (_dim <= 1 || (_c1[b](1) < _c2[b](1) && p(1) >= _c1[b](1) && p(1) <= _c2[b](1)) ||
      73       14040 :           (_c1[b](1) >= _c2[b](1) && p(1) <= _c1[b](1) && p(1) >= _c2[b](1)))
      74      341364 :         if (_dim <= 2 || (_c1[b](2) < _c2[b](2) && p(2) >= _c1[b](2) && p(2) <= _c2[b](2)) ||
      75           0 :             (_c1[b](2) >= _c2[b](2) && p(2) <= _c1[b](2) && p(2) >= _c2[b](2)))
      76             :         {
      77      308466 :           value = _inside[b];
      78      308466 :           break;
      79             :         }
      80             :   }
      81             : 
      82     1324128 :   return value;
      83             : }

Generated by: LCOV version 1.14