https://mooseframework.inl.gov
SetupQuadratureAction.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 
10 #include "SetupQuadratureAction.h"
11 #include "Conversion.h"
12 #include "FEProblem.h"
13 #include "MooseEnum.h"
14 
15 registerMooseAction("MooseApp", SetupQuadratureAction, "setup_quadrature");
16 
19 {
21  params.addClassDescription("Sets the quadrature type for the simulation.");
22  params.addParam<MooseEnum>("type", getQuadratureTypesEnum(), "Type of the quadrature rule");
23  params.addParam<MooseEnum>("order", getQuadratureOrderEnum(), "Order of the quadrature");
24  params.addParam<MooseEnum>(
25  "element_order", getQuadratureOrderEnum(), "Order of the quadrature for elements");
26  params.addParam<MooseEnum>(
27  "side_order", getQuadratureOrderEnum(), "Order of the quadrature for sides");
28  params.addParam<std::vector<SubdomainID>>("custom_blocks",
29  std::vector<SubdomainID>{},
30  "list of blocks to specify custom quadrature order");
31  params.addParam<MultiMooseEnum>(
32  "custom_orders",
34  "list of quadrature orders for the blocks specified in `custom_blocks`");
35  params.addParam<MultiMooseEnum>(
36  "custom_types",
38  "list of quadrature types for the blocks specified in `custom_blocks` "
39  "(must match length of custom_blocks; omit to use global type for all custom blocks)");
40  params.addParam<bool>(
41  "allow_negative_qweights", true, "Whether or not allow negative quadrature weights");
42 
43  return params;
44 }
45 
47  : Action(parameters),
48  _type(Moose::stringToEnum<libMesh::QuadratureType>(getParam<MooseEnum>("type"))),
49  _order(Moose::stringToEnum<Order>(getParam<MooseEnum>("order"))),
50  _element_order(Moose::stringToEnum<Order>(getParam<MooseEnum>("element_order"))),
51  _side_order(Moose::stringToEnum<Order>(getParam<MooseEnum>("side_order"))),
52  _custom_block_orders(getParam<SubdomainID, MooseEnumItem>("custom_blocks", "custom_orders")),
53  _allow_negative_qweights(getParam<bool>("allow_negative_qweights"))
54 {
55  for (const auto & t : getParam<MultiMooseEnum>("custom_types"))
56  _custom_block_types.push_back(Moose::stringToEnum<libMesh::QuadratureType>(std::string(t)));
57 
58  if (!_custom_block_types.empty() && _custom_block_types.size() != _custom_block_orders.size())
59  paramError("custom_types",
60  "Must have the same number of entries as 'custom_blocks' (got ",
61  _custom_block_types.size(),
62  " types for ",
63  _custom_block_orders.size(),
64  " blocks)");
65 }
66 
67 void
69 {
70  if (_problem.get() == nullptr)
71  return;
72 
73  // add default/global quadrature rules
74  _problem->createQRules(
76 
77  // add custom block-specific quadrature rules
78  for (const auto i : index_range(_custom_block_orders))
79  {
80  const auto & [block, order] = _custom_block_orders[i];
81  const auto qtype = (i < _custom_block_types.size()) ? _custom_block_types[i] : _type;
82  _problem->createQRules(qtype,
83  _order,
86  block,
88  }
89 }
Sets the quadrature.
static MooseEnum getQuadratureOrderEnum()
Return the potential selections for the order of the quadrature, with an &#39;auto&#39; default.
Order
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
static MultiMooseEnum getQuadratureOrdersMultiEnum()
A MultiMooseEnum for selecting multiple quadrature orders.
T stringToEnum(const std::string &s)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< std::pair< SubdomainID, MooseEnumItem > > _custom_block_orders
QuadratureType
registerMooseAction("MooseApp", SetupQuadratureAction, "setup_quadrature")
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Order stringToEnum< Order >(const std::string &s)
Definition: Conversion.C:175
Base class for actions.
Definition: Action.h:34
static MooseEnum getQuadratureTypesEnum()
Return the possible selections for the type of the quadrature.
libMesh::QuadratureType _type
static InputParameters validParams()
Definition: Action.C:26
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
static InputParameters validParams()
static MultiMooseEnum getQuadratureTypesMultiEnum()
A MultiMooseEnum for selecting multiple quadrature types (one per custom block)
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
SetupQuadratureAction(const InputParameters &parameters)
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...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:178
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...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
auto index_range(const T &sizable)
std::vector< libMesh::QuadratureType > _custom_block_types
Per-block quadrature types, parallel to _custom_block_orders. Falls back to _type if empty...