Line data Source code
1 : 2 : /**********************************************************************/ 3 : /* DO NOT MODIFY THIS HEADER */ 4 : /* Swift, a Fourier spectral solver for MOOSE */ 5 : /* */ 6 : /* Copyright 2024 Battelle Energy Alliance, LLC */ 7 : /* ALL RIGHTS RESERVED */ 8 : /**********************************************************************/ 9 : 10 : #include "CreateTensorSolverAction.h" 11 : #include "TensorProblem.h" 12 : #include "TensorSolver.h" 13 : #include "SwiftTypes.h" 14 : 15 : registerMooseAction("SwiftApp", CreateTensorSolverAction, "create_tensor_solver"); 16 : 17 : InputParameters 18 112 : CreateTensorSolverAction::validParams() 19 : { 20 112 : InputParameters params = MooseObjectAction::validParams(); 21 112 : params.addClassDescription("Create a TensorSolver."); 22 112 : return params; 23 0 : } 24 : 25 112 : CreateTensorSolverAction::CreateTensorSolverAction(const InputParameters & parameters) 26 112 : : MooseObjectAction(parameters), DomainInterface(this) 27 : { 28 112 : } 29 : 30 : void 31 110 : CreateTensorSolverAction::act() 32 : { 33 110 : auto tensor_problem = std::dynamic_pointer_cast<TensorProblem>(_problem); 34 110 : if (!tensor_problem) 35 0 : mooseError("A TensorSolver is only supported if the problem class is set to `TensorProblem`"); 36 : 37 : // Add a pointer to the TensorProblem and the Domain 38 110 : _moose_object_pars.addPrivateParam<TensorProblem *>("_tensor_problem", tensor_problem.get()); 39 110 : _moose_object_pars.addPrivateParam<const DomainAction *>("_domain", &_domain); 40 : 41 : // check if a root compute was supplied, otherwise automatically generate one 42 220 : if (!_moose_object_pars.isParamValid("root_compute")) 43 : { 44 82 : mooseInfo("Automatically generating root compute."); 45 : 46 : // get the names of all computes 47 : std::vector<TensorComputeName> compute_names; 48 382 : for (const auto & cmp : tensor_problem->getComputes()) 49 300 : compute_names.push_back(cmp->name()); 50 : 51 : // create ComputeGroup 52 : const auto root_name = "automatic_root_compute"; 53 82 : auto params = _factory.getValidParams("ComputeGroup"); 54 82 : params.set<std::vector<TensorComputeName>>("computes") = compute_names; 55 164 : tensor_problem->addTensorComputeSolve("ComputeGroup", root_name, params); 56 : 57 : // set solver root compute to the generated object 58 82 : _moose_object_pars.set<TensorComputeName>("root_compute") = root_name; 59 82 : } 60 : 61 : // Create the object 62 220 : auto solver = _factory.create<TensorSolver>(_type, "TensorSolver", _moose_object_pars, 0); 63 220 : tensor_problem->setSolver(solver, {}); 64 110 : }