www.mooseframework.org
SetupResidualDebugAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 // MOOSE includes
18 #include "ActionWarehouse.h"
19 #include "Factory.h"
20 #include "FEProblem.h"
21 #include "MooseVariable.h"
22 #include "NonlinearSystemBase.h"
23 #include "Conversion.h"
24 
25 template <>
28 {
30  params.addParam<std::vector<NonlinearVariableName>>(
31  "show_var_residual", "Variables for which residuals will be sent to the output file");
32  return params;
33 }
34 
36  : Action(parameters),
37  _show_var_residual(getParam<std::vector<NonlinearVariableName>>("show_var_residual"))
38 {
39 }
40 
41 void
43 {
44  if (_problem.get() == NULL)
45  return;
46 
47  _problem->getNonlinearSystemBase().debuggingResiduals(true);
48 
49  // debug variable residuals
50  for (const auto & var_name : _show_var_residual)
51  {
52  // add aux-variable
53  MooseVariable & var = _problem->getVariable(0, var_name);
54  InputParameters params = _factory.getValidParams("DebugResidualAux");
55  const std::set<SubdomainID> & subdomains = var.activeSubdomains();
56 
57  std::stringstream aux_var_ss;
58  aux_var_ss << "residual_" << var.name();
59  std::string aux_var_name = aux_var_ss.str();
60 
61  if (subdomains.empty())
62  _problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE));
63  else
64  {
65  _problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE), &subdomains);
66  std::vector<SubdomainName> block_names;
67  block_names.reserve(subdomains.size());
68  for (const SubdomainID & id : subdomains)
69  block_names.push_back(Moose::stringify(id));
70  params.set<std::vector<SubdomainName>>("block") = block_names;
71  }
72 
73  // add aux-kernel
74  std::stringstream kern_ss;
75  kern_ss << "residual_" << var.name() << "_kernel";
76  std::string kern_name = kern_ss.str();
77 
78  params.set<AuxVariableName>("variable") = aux_var_name;
79  params.set<NonlinearVariableName>("debug_variable") = var.name();
80  params.set<MultiMooseEnum>("execute_on") = "linear timestep_end";
81  _problem->addAuxKernel("DebugResidualAux", kern_name, params);
82  }
83 }
Class for stuff related to variables.
Definition: MooseVariable.h:43
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:26
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:101
Base class for actions.
Definition: Action.h:39
const std::string & name() const
Get the variable name.
SetupResidualDebugAction(InputParameters parameters)
const std::set< SubdomainID > & activeSubdomains() const
std::vector< NonlinearVariableName > _show_var_residual
InputParameters validParams< SetupResidualDebugAction >()
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
virtual void act() override
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:131
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
InputParameters validParams< Action >()
Definition: Action.C:23