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 "AddICAction.h" 11 : #include "FEProblem.h" 12 : #include "MooseTypes.h" 13 : #include "MooseUtils.h" 14 : 15 : registerMooseAction("MooseApp", AddICAction, "add_ic"); 16 : 17 : InputParameters 18 9177 : AddICAction::validParams() 19 : { 20 9177 : InputParameters params = MooseObjectAction::validParams(); 21 : 22 : // This is to help with input file validation. When ICs are created with 23 : // this action, they are nested underneath a variable in the input file - so 24 : // we implicitly already know the variable name from this nesting and users 25 : // don't need to specify it for us with the parameter. So we say here that 26 : // the variable param is provided by the action. 27 18354 : params.set<std::vector<std::string>>("_object_params_set_by_action") = {"variable"}; 28 : 29 9177 : return params; 30 18354 : } 31 : 32 8770 : AddICAction::AddICAction(const InputParameters & params) : MooseObjectAction(params) {} 33 : 34 : void 35 8696 : AddICAction::act() 36 : { 37 8696 : std::vector<std::string> elements; 38 8696 : MooseUtils::tokenize<std::string>(_pars.blockFullpath(), elements); 39 : 40 : // The variable name will be the second to last element in the path name 41 8696 : std::string & var_name = elements[elements.size() - 2]; 42 8696 : _moose_object_pars.set<VariableName>("variable") = var_name; 43 8696 : const auto & var = _problem->getVariable(0, var_name); 44 : 45 8696 : if (var.isFV()) 46 0 : mooseError( 47 : "Finite volume variables do not support an [InitialCondition] subblock, please use a " 48 : "separate [FVICs] block with all your finite volume initial conditions in your input " 49 : "file."); 50 : else 51 8696 : _problem->addInitialCondition(_type, var_name, _moose_object_pars); 52 8692 : }