https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SetupResidualDebugAction.C
Go to the documentation of this file.
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
11
12// MOOSE includes
13#include "ActionWarehouse.h"
14#include "Factory.h"
15#include "FEProblem.h"
16#include "MooseVariableFE.h"
17#include "NonlinearSystemBase.h"
18#include "Conversion.h"
19#include "AddVariableAction.h"
20#include "libmesh/string_to_enum.h"
21
22registerMooseAction("MooseApp", SetupResidualDebugAction, "setup_residual_debug");
23
26{
28 params.addParam<std::vector<NonlinearVariableName>>(
29 "show_var_residual", {}, "Variables for which residuals will be sent to the output file.");
31 "Adds the necessary objects for computing the residuals for individual variables.");
32 return params;
33}
34
36 : Action(parameters),
37 _show_var_residual(getParam<std::vector<NonlinearVariableName>>("show_var_residual"))
38{
39}
40
41void
43{
44 if (_problem.get() == NULL)
45 return;
46
47 // debug variable residuals
48 for (const auto & var_name : _show_var_residual)
49 {
50 // Get the variable
51 MooseVariableFEBase & var = _problem->getVariable(
53
54 // Turn on variable residual debugging in the system of the variable
55 // TODO: Add linear system support
56 _problem->getNonlinearSystemBase(var.sys().number()).debuggingResiduals(true);
57
58 // add aux-variable
61
62 auto fe_type = var.feType();
63 order = Utility::enum_to_string<Order>(fe_type.order);
64 family = Utility::enum_to_string(fe_type.family);
65
66 InputParameters params = _factory.getValidParams("DebugResidualAux");
67 const std::set<SubdomainID> & subdomains = var.activeSubdomains();
68
69 std::stringstream aux_var_ss;
70 aux_var_ss << "residual_" << var.name();
71 std::string aux_var_name = aux_var_ss.str();
72
73 auto var_params = _factory.getValidParams("MooseVariable");
74 var_params.set<MooseEnum>("family") = family;
75 var_params.set<MooseEnum>("order") = order;
76
77 if (subdomains.empty())
78 _problem->addAuxVariable("MooseVariable", aux_var_name, var_params);
79 else
80 {
81 std::vector<SubdomainName> block_names;
82 block_names.reserve(subdomains.size());
83 for (const SubdomainID & id : subdomains)
84 block_names.push_back(Moose::stringify(id));
85 params.set<std::vector<SubdomainName>>("block") = block_names;
86 var_params.set<std::vector<SubdomainName>>("block") = block_names;
87
88 _problem->addAuxVariable("MooseVariable", aux_var_name, var_params);
89 }
90
91 // add aux-kernel
92 std::stringstream kern_ss;
93 kern_ss << "residual_" << var.name() << "_kernel";
94 std::string kern_name = kern_ss.str();
95
96 params.set<AuxVariableName>("variable") = aux_var_name;
97 params.set<NonlinearVariableName>("debug_variable") = var.name();
98 params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_END};
99 _problem->addAuxKernel("DebugResidualAux", kern_name, params);
100 }
101}
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
registerMooseAction("MooseApp", SetupResidualDebugAction, "setup_residual_debug")
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
static MooseEnum getNonlinearVariableFamilies()
Get the possible variable families.
static MooseEnum getNonlinearVariableOrders()
Get the possible variable orders.
A MultiMooseEnum object to hold "execute_on" flags.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
const libMesh::FEType & feType() const
Get the type of finite element object.
SystemBase & sys()
Get the system this variable is part of.
This class provides an interface for common operations on field variables of both FE and FV types wit...
const std::set< SubdomainID > & activeSubdomains() const
The subdomains the variable is active on.
Factory & _factory
The Factory associated with the MooseApp.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
SetupResidualDebugAction(const InputParameters &parameters)
static InputParameters validParams()
std::vector< NonlinearVariableName > _show_var_residual
unsigned int number() const
Gets the number of this system.
@ VAR_FIELD_STANDARD
Definition MooseTypes.h:777
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
@ VAR_SOLVER
Definition MooseTypes.h:770
std::string enum_to_string(const T e)