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