LCOV - code coverage report
Current view: top level - src/ics - RndSmoothCircleIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 23 27 85.2 %
Date: 2025-09-04 07:55:36 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 "RndSmoothCircleIC.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseMesh.h"
      14             : #include "MooseVariable.h"
      15             : 
      16             : registerMooseObject("PhaseFieldApp", RndSmoothCircleIC);
      17             : 
      18             : InputParameters
      19          16 : RndSmoothCircleIC::validParams()
      20             : {
      21          16 :   InputParameters params = SmoothCircleIC::validParams();
      22          16 :   params.addClassDescription(
      23             :       "Random noise with different min/max inside/outside of a smooth circle");
      24          32 :   params.addRequiredParam<Real>("variation_invalue", "Plus or minus this amount on the invalue");
      25          32 :   params.addRequiredParam<Real>("variation_outvalue", "Plus or minus this amount on the outvalue");
      26          16 :   return params;
      27           0 : }
      28             : 
      29           8 : RndSmoothCircleIC::RndSmoothCircleIC(const InputParameters & parameters)
      30             :   : SmoothCircleIC(parameters),
      31           8 :     _variation_invalue(parameters.get<Real>("variation_invalue")),
      32           8 :     _variation_outvalue(parameters.get<Real>("variation_outvalue"))
      33             : {
      34           8 :   if (_profile == ProfileType::TANH)
      35           0 :     paramError("profile", "Hyperbolic tangent profile is not supported for this IC");
      36           8 : }
      37             : 
      38             : Real
      39       60000 : RndSmoothCircleIC::computeCircleValue(const Point & p, const Point & center, const Real & radius)
      40             : {
      41       60000 :   Point l_center = center;
      42       60000 :   Point l_p = p;
      43       60000 :   if (!_3D_spheres) // Create 3D cylinders instead of spheres
      44             :   {
      45           0 :     l_p(2) = 0.0;
      46           0 :     l_center(2) = 0.0;
      47             :   }
      48             :   // Compute the distance between the current point and the center
      49       60000 :   Real dist = _mesh.minPeriodicDistance(_var.number(), l_p, l_center);
      50             : 
      51             :   // Return value
      52             :   Real value = 0.0;
      53             : 
      54       60000 :   if (dist <= radius - _int_width / 2.0) // Random value inside circle
      55        1152 :     value = _invalue - _variation_invalue + 2.0 * _random.rand(_tid) * _variation_invalue;
      56       58848 :   else if (dist < radius + _int_width / 2.0) // Smooth interface
      57             :   {
      58        3840 :     Real int_pos = (dist - radius + _int_width / 2.0) / _int_width;
      59        3840 :     value = _outvalue + (_invalue - _outvalue) * (1.0 + std::cos(int_pos * libMesh::pi)) / 2.0;
      60             :   }
      61             :   else // Random value outside circle
      62       55008 :     value = _outvalue - _variation_outvalue + 2.0 * _random.rand(_tid) * _variation_outvalue;
      63             : 
      64       60000 :   return value;
      65             : }

Generated by: LCOV version 1.14