LCOV - code coverage report
Current view: top level - src/materials - CoupledValueFunctionFreeEnergy.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 38 41 92.7 %
Date: 2025-09-04 07:55:36 Functions: 4 4 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 "CoupledValueFunctionFreeEnergy.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("PhaseFieldApp", CoupledValueFunctionFreeEnergy);
      14             : 
      15             : InputParameters
      16          47 : CoupledValueFunctionFreeEnergy::validParams()
      17             : {
      18          47 :   InputParameters params = DerivativeFunctionMaterialBase::validParams();
      19          47 :   params.addClassDescription("Compute a free energy from a lookup function");
      20          94 :   params.addRequiredParam<FunctionName>("free_energy_function",
      21             :                                         "Coupled function to evaluate with values from v");
      22          94 :   params.addRequiredParam<std::vector<FunctionName>>(
      23             :       "chemical_potential_functions", "Coupled function to evaluate with values from v");
      24          94 :   params.addCoupledVar("v",
      25             :                        "List of up to four coupled variables that are substituted for x,y,z, and t "
      26             :                        "in the coupled function");
      27          47 :   params.set<unsigned int>("derivative_order") = 2;
      28          47 :   return params;
      29           0 : }
      30             : 
      31          36 : CoupledValueFunctionFreeEnergy::CoupledValueFunctionFreeEnergy(const InputParameters & parameters)
      32             :   : DerivativeFunctionMaterialBase(parameters),
      33          36 :     _free_energy_function(
      34          72 :         isParamValid("free_energy_function") ? &getFunction("free_energy_function") : nullptr),
      35          72 :     _chemical_potential_names(getParam<std::vector<FunctionName>>("chemical_potential_functions")),
      36          72 :     _chemical_potential_functions(_nargs)
      37             : {
      38          36 :   if (_chemical_potential_functions.size() != _nargs)
      39           0 :     paramError(
      40             :         "chemical_potential_functions",
      41             :         "Exactly one chemical potential function must be supplied for each coupled variable");
      42             : 
      43             :   // get chemical potential functions
      44         180 :   for (unsigned int i = 0; i < _nargs; ++i)
      45         144 :     _chemical_potential_functions[i] = &getFunctionByName(_chemical_potential_names[i]);
      46          36 : }
      47             : 
      48             : void
      49          36 : CoupledValueFunctionFreeEnergy::initialSetup()
      50             : {
      51          36 :   if (_prop_F && !_free_energy_function)
      52           0 :     paramError("free_energy_function",
      53             :                "The undifferentiated free energy property is requested in the simulation, but no "
      54             :                "function is provided");
      55          36 : }
      56             : 
      57             : void
      58       49200 : CoupledValueFunctionFreeEnergy::computeProperties()
      59             : {
      60      246000 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      61             :   {
      62             :     // set function arguments to coupled variables
      63             :     Point p;
      64             :     Real t = 0;
      65      787200 :     for (unsigned int i = 0; i < 3 && i < _nargs; ++i)
      66      590400 :       p(i) = (*_args[i])[_qp];
      67      196800 :     if (_nargs == 4)
      68      196800 :       t = (*_args[3])[_qp];
      69             : 
      70             :     // set function value
      71      196800 :     if (_prop_F && _free_energy_function)
      72      196800 :       (*_prop_F)[_qp] = _free_energy_function->value(t, p);
      73             : 
      74      984000 :     for (unsigned int i = 0; i < _nargs; ++i)
      75             :     {
      76             :       // set first derivatives
      77      787200 :       if (_prop_dF[i])
      78      787200 :         (*_prop_dF[i])[_qp] = _chemical_potential_functions[i]->value(t, p);
      79             : 
      80             :       // second derivatives via grad
      81      787200 :       auto grad = _chemical_potential_functions[i]->gradient(t, p);
      82     1968000 :       for (unsigned int j = i; j < 3 && j < _nargs; ++j)
      83     1180800 :         if (_prop_d2F[i][j])
      84     1180800 :           (*_prop_d2F[i][j])[_qp] = grad(j);
      85             : 
      86             :       // second derivative via time derivative
      87      787200 :       if (_nargs == 4 && _prop_d2F[i][3])
      88      787200 :         (*_prop_d2F[i][3])[_qp] = _chemical_potential_functions[i]->timeDerivative(t, p);
      89             :     }
      90             :   }
      91       49200 : }

Generated by: LCOV version 1.14