LCOV - code coverage report
Current view: top level - src/ics - PolycrystalRandomIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 15 21 71.4 %
Date: 2026-05-29 20:38:39 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         152 : PolycrystalRandomIC::validParams()
      17             : {
      18         152 :   InputParameters params = RandomICBase::validParams();
      19         152 :   params.addClassDescription("Random initial condition for a polycrystalline material");
      20         304 :   params.addRequiredParam<unsigned int>("op_num", "Number of order parameters");
      21         304 :   params.addRequiredParam<unsigned int>("op_index", "The index for the current order parameter");
      22         304 :   params.addRequiredParam<unsigned int>("random_type", "Type of random grain structure");
      23         152 :   return params;
      24           0 : }
      25             : 
      26          82 : PolycrystalRandomIC::PolycrystalRandomIC(const InputParameters & parameters)
      27             :   : RandomICBase(parameters),
      28          82 :     _op_num(getParam<unsigned int>("op_num")),
      29         164 :     _op_index(getParam<unsigned int>("op_index")),
      30         246 :     _random_type(getParam<unsigned int>("random_type"))
      31             : {
      32          82 : }
      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