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 "DiffusionFV.h" 11 : #include "MooseUtils.h" 12 : 13 : // Register the actions for the objects actually used 14 : registerMooseAction("MooseApp", DiffusionFV, "add_fv_kernel"); 15 : registerMooseAction("MooseApp", DiffusionFV, "add_fv_bc"); 16 : registerMooseAction("MooseApp", DiffusionFV, "add_variable"); 17 : registerDiffusionPhysicsBaseTasks("MooseApp", DiffusionFV); 18 : 19 : InputParameters 20 315 : DiffusionFV::validParams() 21 : { 22 315 : InputParameters params = DiffusionPhysicsBase::validParams(); 23 315 : params.addClassDescription("Add diffusion physics discretized with cell-centered finite volume"); 24 : // No kernel implemented in the framework for a material property diffusivity 25 315 : params.suppressParameter<MaterialPropertyName>("diffusivity_matprop"); 26 315 : params.addRequiredParam<MooseFunctorName>("diffusivity_functor", 27 : "Functor specifying the diffusivity"); 28 : 29 945 : params.addParam<unsigned short>( 30 630 : "ghost_layers", 2, "Number of ghosting layers for distributed memory parallel calculations"); 31 315 : params.addParamNamesToGroup("ghost_layers", "Advanced"); 32 315 : return params; 33 0 : } 34 : 35 112 : DiffusionFV::DiffusionFV(const InputParameters & parameters) 36 112 : : PhysicsBase(parameters), PhysicsComponentInterface(parameters), DiffusionPhysicsBase(parameters) 37 : { 38 112 : } 39 : 40 : void 41 96 : DiffusionFV::initializePhysicsAdditional() 42 : { 43 96 : getProblem().needFV(); 44 96 : } 45 : 46 : void 47 92 : DiffusionFV::addFVKernels() 48 : { 49 : // Diffusion term 50 : { 51 92 : const std::string kernel_type = "FVDiffusion"; 52 92 : InputParameters params = getFactory().getValidParams(kernel_type); 53 92 : assignBlocks(params, _blocks); 54 92 : params.set<NonlinearVariableName>("variable") = _var_name; 55 92 : params.set<MooseFunctorName>("coeff") = getParam<MooseFunctorName>("diffusivity_functor"); 56 92 : getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_diffusion", params); 57 92 : } 58 : // Source term 59 92 : if (isParamValid("source_functor")) 60 : { 61 : // Select the kernel type based on the user parameters 62 92 : std::string kernel_type; 63 : 64 92 : const auto & source = getParam<MooseFunctorName>("source_functor"); 65 92 : if (MooseUtils::parsesToReal(source) || getProblem().hasFunction(source) || 66 92 : getProblem().hasPostprocessorValueByName(source)) 67 92 : kernel_type = "FVBodyForce"; 68 0 : else if (getProblem().hasVariable(source)) 69 0 : kernel_type = "FVCoupledForce"; 70 : else 71 0 : paramError("source_functor", 72 : "No kernel defined for a source term in FV for the type used for '", 73 : source, 74 : "'"); 75 : 76 92 : InputParameters params = getFactory().getValidParams(kernel_type); 77 92 : params.set<NonlinearVariableName>("variable") = _var_name; 78 92 : assignBlocks(params, _blocks); 79 : 80 : // Transfer the source and coefficient parameter from the Physics to the kernel 81 92 : const auto coef = getParam<Real>("source_coef"); 82 92 : if (MooseUtils::parsesToReal(source)) 83 92 : params.set<Real>("value") = MooseUtils::convert<Real>(source) * coef; 84 0 : else if (getProblem().hasFunction(source)) 85 : { 86 0 : params.set<Real>("value") = coef; 87 0 : params.set<FunctionName>("function") = source; 88 : } 89 0 : else if (getProblem().hasPostprocessorValueByName(source)) 90 : { 91 0 : params.set<Real>("value") = coef; 92 0 : params.set<PostprocessorName>("postprocessor") = source; 93 : } 94 : else 95 : { 96 0 : params.set<Real>("coef") = coef; 97 0 : params.set<MooseFunctorName>("v") = {source}; 98 : } 99 : 100 92 : getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_source", params); 101 92 : } 102 : // Time derivative 103 92 : if (shouldCreateTimeDerivative(_var_name, _blocks, false)) 104 : { 105 12 : const std::string kernel_type = "FVTimeKernel"; 106 12 : InputParameters params = getFactory().getValidParams(kernel_type); 107 12 : params.set<NonlinearVariableName>("variable") = _var_name; 108 12 : assignBlocks(params, _blocks); 109 12 : getProblem().addFVKernel(kernel_type, prefix() + _var_name + "_time", params); 110 12 : } 111 92 : } 112 : 113 : void 114 92 : DiffusionFV::addFVBCs() 115 : { 116 92 : if (isParamValid("neumann_boundaries")) 117 : { 118 92 : const auto & boundary_fluxes = getParam<std::vector<MooseFunctorName>>("boundary_fluxes"); 119 140 : for (const auto i : index_range(_neumann_boundaries)) 120 : { 121 48 : const auto & bc_flux = boundary_fluxes[i]; 122 : // Select the boundary type based on the user parameters and what we know to be most efficient 123 48 : std::string bc_type = ""; 124 48 : if (MooseUtils::parsesToReal(bc_flux)) 125 12 : bc_type = "FVNeumannBC"; 126 36 : else if (getProblem().hasFunction(bc_flux)) 127 12 : bc_type = "FVFunctionNeumannBC"; 128 : else 129 24 : bc_type = "FVFunctorNeumannBC"; 130 : 131 48 : InputParameters params = getFactory().getValidParams(bc_type); 132 48 : params.set<NonlinearVariableName>("variable") = _var_name; 133 96 : params.set<std::vector<BoundaryName>>("boundary") = {_neumann_boundaries[i]}; 134 : 135 : // Set the boundary condition parameter for the specific boundary condition type used 136 48 : if (MooseUtils::parsesToReal(bc_flux)) 137 12 : params.set<Real>("value") = MooseUtils::convert<Real>(bc_flux); 138 36 : else if (getProblem().hasFunction(bc_flux)) 139 12 : params.set<FunctionName>("function") = bc_flux; 140 : else 141 24 : params.set<MooseFunctorName>("functor") = bc_flux; 142 : 143 96 : getProblem().addFVBC( 144 96 : bc_type, prefix() + _var_name + "_neumann_bc_" + _neumann_boundaries[i], params); 145 48 : } 146 : } 147 : 148 92 : if (isParamValid("dirichlet_boundaries")) 149 : { 150 92 : const auto & boundary_values = getParam<std::vector<MooseFunctorName>>("boundary_values"); 151 276 : for (const auto i : index_range(_dirichlet_boundaries)) 152 : { 153 184 : const auto & bc_value = boundary_values[i]; 154 : // Select the boundary type based on the user parameters and what we know to be most efficient 155 184 : std::string bc_type = ""; 156 184 : if (MooseUtils::parsesToReal(bc_value)) 157 148 : bc_type = "FVDirichletBC"; 158 36 : else if (getProblem().hasFunction(bc_value)) 159 12 : bc_type = "FVFunctionDirichletBC"; 160 : else 161 24 : bc_type = "FVADFunctorDirichletBC"; 162 : 163 184 : InputParameters params = getFactory().getValidParams(bc_type); 164 184 : params.set<NonlinearVariableName>("variable") = _var_name; 165 368 : params.set<std::vector<BoundaryName>>("boundary") = {_dirichlet_boundaries[i]}; 166 : 167 : // Set the boundary condition parameter for the specific boundary condition type used 168 184 : if (MooseUtils::parsesToReal(bc_value)) 169 148 : params.set<Real>("value") = MooseUtils::convert<Real>(bc_value); 170 36 : else if (getProblem().hasFunction(bc_value)) 171 12 : params.set<FunctionName>("function") = bc_value; 172 : else 173 24 : params.set<MooseFunctorName>("functor") = bc_value; 174 : 175 368 : getProblem().addFVBC( 176 368 : bc_type, prefix() + _var_name + "_dirichlet_bc_" + _dirichlet_boundaries[i], params); 177 184 : } 178 : } 179 324 : } 180 : 181 : void 182 96 : DiffusionFV::addSolverVariables() 183 : { 184 96 : if (!shouldCreateVariable(_var_name, _blocks, true)) 185 : { 186 0 : reportPotentiallyMissedParameters({"system_names"}, "MooseVariableFVReal"); 187 0 : return; 188 : } 189 : 190 96 : const std::string variable_type = "MooseVariableFVReal"; 191 96 : InputParameters params = getFactory().getValidParams(variable_type); 192 96 : assignBlocks(params, _blocks); 193 96 : params.set<SolverSystemName>("solver_sys") = getSolverSystem(_var_name); 194 96 : getProblem().addVariable(variable_type, _var_name, params); 195 96 : } 196 : 197 : InputParameters 198 280 : DiffusionFV::getAdditionalRMParams() const 199 : { 200 : const auto necessary_layers = 201 280 : std::max(getParam<unsigned short>("ghost_layers"), (unsigned short)2); 202 : 203 : // Just an object that has a ghost_layers parameter 204 280 : const std::string kernel_type = "FVDiffusion"; 205 280 : InputParameters params = getFactory().getValidParams(kernel_type); 206 280 : params.template set<unsigned short>("ghost_layers") = necessary_layers; 207 : 208 560 : return params; 209 280 : }