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 31 : CoupledValueFunctionFreeEnergy::validParams() 17 : { 18 31 : InputParameters params = DerivativeFunctionMaterialBase::validParams(); 19 31 : params.addClassDescription("Compute a free energy from a lookup function"); 20 62 : params.addRequiredParam<FunctionName>("free_energy_function", 21 : "Coupled function to evaluate with values from v"); 22 62 : params.addRequiredParam<std::vector<FunctionName>>( 23 : "chemical_potential_functions", "Coupled function to evaluate with values from v"); 24 62 : 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 31 : params.set<unsigned int>("derivative_order") = 2; 28 31 : return params; 29 0 : } 30 : 31 24 : CoupledValueFunctionFreeEnergy::CoupledValueFunctionFreeEnergy(const InputParameters & parameters) 32 : : DerivativeFunctionMaterialBase(parameters), 33 24 : _free_energy_function( 34 48 : isParamValid("free_energy_function") ? &getFunction("free_energy_function") : nullptr), 35 48 : _chemical_potential_names(getParam<std::vector<FunctionName>>("chemical_potential_functions")), 36 48 : _chemical_potential_functions(_nargs) 37 : { 38 24 : 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 120 : for (unsigned int i = 0; i < _nargs; ++i) 45 96 : _chemical_potential_functions[i] = &getFunctionByName(_chemical_potential_names[i]); 46 24 : } 47 : 48 : void 49 24 : CoupledValueFunctionFreeEnergy::initialSetup() 50 : { 51 24 : 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 24 : } 56 : 57 : void 58 41400 : CoupledValueFunctionFreeEnergy::computeProperties() 59 : { 60 207000 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 61 : { 62 : // set function arguments to coupled variables 63 : Point p; 64 : Real t = 0; 65 662400 : for (unsigned int i = 0; i < 3 && i < _nargs; ++i) 66 496800 : p(i) = (*_args[i])[_qp]; 67 165600 : if (_nargs == 4) 68 165600 : t = (*_args[3])[_qp]; 69 : 70 : // set function value 71 165600 : if (_prop_F && _free_energy_function) 72 165600 : (*_prop_F)[_qp] = _free_energy_function->value(t, p); 73 : 74 828000 : for (unsigned int i = 0; i < _nargs; ++i) 75 : { 76 : // set first derivatives 77 662400 : if (_prop_dF[i]) 78 662400 : (*_prop_dF[i])[_qp] = _chemical_potential_functions[i]->value(t, p); 79 : 80 : // second derivatives via grad 81 662400 : auto grad = _chemical_potential_functions[i]->gradient(t, p); 82 1656000 : for (unsigned int j = i; j < 3 && j < _nargs; ++j) 83 993600 : if (_prop_d2F[i][j]) 84 993600 : (*_prop_d2F[i][j])[_qp] = grad(j); 85 : 86 : // second derivative via time derivative 87 662400 : if (_nargs == 4 && _prop_d2F[i][3]) 88 662400 : (*_prop_d2F[i][3])[_qp] = _chemical_potential_functions[i]->timeDerivative(t, p); 89 : } 90 : } 91 41400 : }