LCOV - code coverage report
Current view: top level - src/ics - PFCFreezingIC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 51 57 89.5 %
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 "PFCFreezingIC.h"
      11             : #include "MooseRandom.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", PFCFreezingIC);
      14             : 
      15             : InputParameters
      16          22 : PFCFreezingIC::validParams()
      17             : {
      18          22 :   InputParameters params = RandomICBase::validParams();
      19          44 :   params.addRequiredParam<Real>("x1",
      20             :                                 "The x coordinate of the lower left-hand corner of the frozen box");
      21          44 :   params.addRequiredParam<Real>("y1",
      22             :                                 "The y coordinate of the lower left-hand corner of the frozen box");
      23          44 :   params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
      24             : 
      25          44 :   params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
      26          44 :   params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
      27          44 :   params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
      28             : 
      29          44 :   params.addParam<Real>("min", 0.0, "Lower bound of the randomly generated values");
      30          44 :   params.addParam<Real>("max", 1.0, "Upper bound of the randomly generated values");
      31          44 :   params.addParam<Real>("inside", 1.0, "Value inside sinusoids");
      32          44 :   params.addParam<Real>("outside", 0.0, "Value outside sinusoids");
      33             : 
      34          44 :   params.addRequiredParam<Real>("lc", "The lattice constant off the crystal structure");
      35             : 
      36          44 :   MooseEnum crystal_structures("FCC BCC");
      37          44 :   params.addParam<MooseEnum>(
      38             :       "crystal_structure", crystal_structures, "The type of crystal structure");
      39             : 
      40          22 :   return params;
      41          22 : }
      42             : 
      43          12 : PFCFreezingIC::PFCFreezingIC(const InputParameters & parameters)
      44             :   : RandomICBase(parameters),
      45          12 :     _x1(getParam<Real>("x1")),
      46          24 :     _y1(getParam<Real>("y1")),
      47          24 :     _z1(getParam<Real>("z1")),
      48          24 :     _x2(getParam<Real>("x2")),
      49          24 :     _y2(getParam<Real>("y2")),
      50          24 :     _z2(getParam<Real>("z2")),
      51          24 :     _lc(getParam<Real>("lc")),
      52          24 :     _crystal_structure(getParam<MooseEnum>("crystal_structure")),
      53          12 :     _bottom_left(_x1, _y1, _z1),
      54          12 :     _top_right(_x2, _y2, _z2),
      55             :     _range(_top_right - _bottom_left),
      56          24 :     _min(getParam<Real>("min")),
      57          24 :     _max(getParam<Real>("max")),
      58          12 :     _val_range(_max - _min),
      59          24 :     _inside(getParam<Real>("inside")),
      60          36 :     _outside(getParam<Real>("outside"))
      61             : {
      62          48 :   for (const auto i : make_range(Moose::dim))
      63          36 :     if (_range(i) < 0.0)
      64           0 :       mooseError("x1, y1 or z1 is not less than x2, y2 or z2");
      65             : 
      66          12 :   if (_range(1) == 0.0)
      67           0 :     _icdim = 1;
      68          12 :   else if (_range(2) < 1.0e-10 * _range(0))
      69          12 :     _icdim = 2;
      70             :   else
      71           0 :     _icdim = 3;
      72          12 : }
      73             : 
      74             : Real
      75      320000 : PFCFreezingIC::value(const Point & p)
      76             : {
      77             :   // If out of bounds, set random value
      78      870848 :   for (const auto i : make_range(Moose::dim))
      79      709024 :     if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
      80      158176 :       return _min + _val_range * generateRandom();
      81             : 
      82             :   // If in bounds, set sinusoid IC to make atoms
      83             :   Real val = 0.0;
      84      161824 :   if (_crystal_structure == "FCC")
      85             :   {
      86             :     // Note: this effectively (and now explicitly) returns 0.0 for FCC.
      87             :     return 0.0;
      88             : 
      89             :     for (unsigned int i = 0; i < _icdim; i++)
      90             :       val += std::cos((2.0 / _lc * p(i)) * libMesh::pi);
      91             :   }
      92             :   else
      93             :   {
      94       71824 :     if (_icdim > 2)
      95             :     {
      96           0 :       for (unsigned int i = 0; i < _icdim; i++)
      97             :         // one mode approximation for initial condition
      98           0 :         val += (std::cos((2.0 / _lc * p(i % 3)) * libMesh::pi) *
      99           0 :                 std::cos((2.0 / _lc * p((i + 1) % 3)) * libMesh::pi)) /
     100             :                4.0; // Doesn't work in 2D
     101             :     }
     102             :     else
     103             :     {
     104      215472 :       for (unsigned int i = 0; i < _icdim; i++)
     105      143648 :         val *= std::cos((2.0 / _lc * p(i)) * libMesh::pi); // 2D IC for 111 plane
     106             : 
     107       71824 :       val = val / 2.0 + 0.5;
     108             :     }
     109             :   }
     110             : 
     111       71824 :   Real amp = _inside - _outside;
     112       71824 :   val = amp * val + _outside;
     113             : 
     114       71824 :   return val;
     115             : }

Generated by: LCOV version 1.14