LCOV - code coverage report
Current view: top level - src/ics - PolycrystalRandomIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 15 21 71.4 %
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 "PolycrystalRandomIC.h"
      11             : #include "MooseRandom.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", PolycrystalRandomIC);
      14             : 
      15             : InputParameters
      16         192 : PolycrystalRandomIC::validParams()
      17             : {
      18         192 :   InputParameters params = RandomICBase::validParams();
      19         192 :   params.addClassDescription("Random initial condition for a polycrystalline material");
      20         384 :   params.addRequiredParam<unsigned int>("op_num", "Number of order parameters");
      21         384 :   params.addRequiredParam<unsigned int>("op_index", "The index for the current order parameter");
      22         384 :   params.addRequiredParam<unsigned int>("random_type", "Type of random grain structure");
      23         192 :   return params;
      24           0 : }
      25             : 
      26         102 : PolycrystalRandomIC::PolycrystalRandomIC(const InputParameters & parameters)
      27             :   : RandomICBase(parameters),
      28         102 :     _op_num(getParam<unsigned int>("op_num")),
      29         204 :     _op_index(getParam<unsigned int>("op_index")),
      30         306 :     _random_type(getParam<unsigned int>("random_type"))
      31             : {
      32         102 : }
      33             : 
      34             : Real
      35        1040 : PolycrystalRandomIC::value(const Point &)
      36             : {
      37        1040 :   Real val = generateRandom();
      38             : 
      39        1040 :   switch (_random_type)
      40             :   {
      41             :     case 0: // Continuously random
      42             :       return val;
      43             : 
      44           0 :     case 1: // Discretely random
      45             :     {
      46           0 :       unsigned int rndind = _op_num * val;
      47             : 
      48           0 :       if (rndind == _op_index)
      49             :         return 1.0;
      50             :       else
      51           0 :         return 0.0;
      52             :     }
      53             :   }
      54             : 
      55           0 :   paramError("random_type", "Bad type passed in PolycrystalRandomIC");
      56             : }

Generated by: LCOV version 1.14