LCOV - code coverage report
Current view: top level - src/kernels - SLKKSMultiPhaseBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 43 50 86.0 %
Date: 2025-09-04 07:55:36 Functions: 2 2 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 "SLKKSMultiPhaseBase.h"
      11             : 
      12             : InputParameters
      13         120 : SLKKSMultiPhaseBase::validParams()
      14             : {
      15         120 :   auto params = Kernel::validParams();
      16         240 :   params.addRequiredCoupledVar("cs", "Array of sublattice concentrations phase for all phases");
      17         240 :   params.addCoupledVar("eta", "Order parameters for all phases");
      18         240 :   params.addRequiredParam<std::vector<unsigned int>>("ns", "Number of sublattices in each phase");
      19         240 :   params.addRequiredParam<std::vector<Real>>("as", "Sublattice site fractions n all phases");
      20         240 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      21             :       "h_names", "Switching Function Materials for all phases");
      22         120 :   return params;
      23           0 : }
      24             : 
      25             : // Phase interpolation func
      26          63 : SLKKSMultiPhaseBase::SLKKSMultiPhaseBase(const InputParameters & parameters)
      27             :   : DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>(parameters),
      28          63 :     _ncs(coupledComponents("cs")),
      29          63 :     _cs(_ncs),
      30          63 :     _cs_map(getParameterJvarMap("cs")),
      31         126 :     _ns(getParam<std::vector<unsigned int>>("ns")),
      32          63 :     _neta(coupledComponents("eta")),
      33          63 :     _eta_names(_neta),
      34          63 :     _eta_map(getParameterJvarMap("eta")),
      35         126 :     _a_cs(getParam<std::vector<Real>>("as")),
      36         189 :     _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")),
      37          63 :     _nh(_h_names.size()),
      38          63 :     _phase(_ncs),
      39          63 :     _c(coupledValue("c")),
      40         126 :     _c_var(coupled("c"))
      41             : {
      42             :   // consistent number of phases?
      43          63 :   if (_ns.size() != _nh)
      44           0 :     paramError("ns",
      45             :                "Need to pass in as many switching functions (parameter `h_names`) as size of "
      46             :                "number of sublattices in each phase (parameter `ns`)");
      47             : 
      48             :   // sum up ns numbers
      49             :   unsigned int nssum = 0;
      50         189 :   for (auto i : _ns)
      51             :   {
      52         126 :     if (i == 0)
      53           0 :       paramError("ns", "All sublattice counts must be larger than zero");
      54         126 :     nssum += i;
      55             :   }
      56             : 
      57          63 :   if (nssum != _ncs)
      58           0 :     paramError("ns", "Numbers need to sum up to the number of passed in cs variables");
      59          63 :   if (_ncs == 0)
      60           0 :     paramError("cs", "Need to supply at least 1 phase sublattice concentration");
      61             : 
      62             :   // get order parameter names
      63         189 :   for (std::size_t i = 0; i < _neta; ++i)
      64         252 :     _eta_names[i] = coupledName("eta", i);
      65             : 
      66             :   // Load concentration variables into the arrays
      67         315 :   for (std::size_t i = 0; i < _ncs; ++i)
      68         252 :     _cs[i] = &coupledValue("cs", i);
      69             : 
      70             :   // normalize sublattice counts within each phase
      71             :   std::size_t k = 0;
      72         189 :   for (std::size_t i = 0; i < _nh; ++i)
      73             :   {
      74             :     // sum site counts
      75         126 :     Real sum = _a_cs[k];
      76         252 :     for (unsigned int j = 1; j < _ns[i]; ++j)
      77         126 :       sum += _a_cs[j + k];
      78         126 :     if (sum <= 0)
      79           0 :       paramError("as", "Sum of sublattice site counts in each phase must be larger than zero");
      80             : 
      81             :     // normalize
      82         378 :     for (unsigned int j = 0; j < _ns[i]; ++j)
      83             :     {
      84         252 :       _a_cs[j + k] /= sum;
      85             : 
      86             :       // remember phase index
      87         252 :       _phase[j + k] = i;
      88             :     }
      89             : 
      90             :     // next phase
      91         126 :     k += _ns[i];
      92             :   }
      93             : 
      94             :   // consistency checks
      95          63 :   if (k != _ncs)
      96           0 :     mooseError("Internal error");
      97          63 : }

Generated by: LCOV version 1.14