https://mooseframework.inl.gov
QuadraturePointsPositions.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 #include "libmesh/quadrature_gauss.h"
12 #include "SetupQuadratureAction.h"
13 
14 using namespace libMesh;
15 
17 
20 {
22  params.addClassDescription("Positions of element quadrature points.");
24 
25  params.addParam<MooseEnum>("quadrature_type",
27  "Type of the quadrature rule");
28  params.addParam<MooseEnum>("quadrature_order",
30  "Order of the volumetric quadrature. If unspecified, defaults to the "
31  "local element default order. This is not the problem default, which "
32  "is based on the order of the variables in the system.");
33 
34  // Element centroids could be sorted by XYZ or by id. Default to not sorting
35  params.set<bool>("auto_sort") = false;
36  // Gathered locally, should be broadcast on every process
37  params.set<bool>("auto_broadcast") = true;
38 
39  return params;
40 }
41 
43  : Positions(parameters),
44  BlockRestrictable(this),
45  _mesh(_fe_problem.mesh()),
46  _q_type(Moose::stringToEnum<QuadratureType>(getParam<MooseEnum>("quadrature_type"))),
47  _q_order(Moose::stringToEnum<Order>(getParam<MooseEnum>("quadrature_order")))
48 {
49  // Mesh is ready at construction
50  initialize();
51  // Trigger synchronization as the initialization is distributed
52  finalize();
53 }
54 
55 void
57 {
59 
60  // By default, initialize should be called on meshChanged()
61  // Gathering of positions is local, reporter system makes sure to make it global
62  if (blockRestricted())
63  {
64  _positions_2d.resize(numBlocks());
65  unsigned int b_index = 0;
66  for (const auto & sub_id : blockIDs())
67  {
68  for (const auto & elem : _mesh.getMesh().active_local_subdomain_elements_ptr_range(sub_id))
69  {
70  // Get a quadrature going of the requested type and order
71  const FEFamily mapping_family = FEMap::map_fe_type(*elem);
72  const FEType fe_type(elem->default_order(), mapping_family);
73  std::unique_ptr<FEBase> fe = FEBase::build(elem->dim(), fe_type);
74  const auto q_order =
75  (_q_order == INVALID_ORDER) ? fe_type.default_quadrature_order() : _q_order;
76  auto qrule = QBase::build(_q_type, elem->dim(), q_order);
77  fe->attach_quadrature_rule(qrule.get());
78  const auto & q_points = fe->get_xyz();
79  fe->reinit(elem);
80 
81  for (const auto & q : q_points)
82  {
83  _positions.emplace_back(q);
84  _positions_2d[b_index].emplace_back(q);
85  }
86  }
87  b_index += 1;
88  }
89  }
90  else
91  {
93  for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
94  {
95  // Get a quadrature going on the element
96  const FEFamily mapping_family = FEMap::map_fe_type(*elem);
97  const FEType fe_type(elem->default_order(), mapping_family);
98  std::unique_ptr<FEBase> fe = FEBase::build(elem->dim(), fe_type);
99  const auto q_order =
100  (_q_order == INVALID_ORDER) ? fe_type.default_quadrature_order() : _q_order;
101  auto qrule = QBase::build(_q_type, elem->dim(), q_order);
102  fe->attach_quadrature_rule(qrule.get());
103  const auto & q_points = fe->get_xyz();
104  fe->reinit(elem);
105 
106  for (const auto & q : q_points)
107  _positions.emplace_back(q);
108  }
109  }
110  _initialized = true;
111 }
std::unique_ptr< FEGenericBase< Real > > build(const unsigned int dim, const FEType &fet)
static MooseEnum getQuadratureOrderEnum()
Return the potential selections for the order of the quadrature, with an &#39;auto&#39; default.
libMesh::Order _q_order
Order of the quadrature.
Order
virtual void initialize() override
In charge of computing / loading the positions.
unsigned int numBlocks() const
Return the number of blocks for this object.
static InputParameters validParams()
Definition: Positions.C:15
void clearPositions()
Clear all positions vectors.
Definition: Positions.C:154
Positions objects are under the hood Reporters.
Definition: Positions.h:20
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Positions of all the quadrature points.
T stringToEnum(const std::string &s)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
QuadratureType
QuadraturePointsPositions(const InputParameters &parameters)
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition: Positions.h:116
static InputParameters validParams()
static MooseEnum getQuadratureTypesEnum()
Return the possible selections for the type of the quadrature.
std::vector< std::vector< Point > > _positions_2d
2D storage for all the positions
Definition: Positions.h:95
dof_id_type n_active_local_elem() const
libMesh::QuadratureType _q_type
Type of the quadrature.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition: Positions.h:92
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
MooseMesh & _mesh
Reference to the mesh.
INVALID_ORDER
static InputParameters validParams()
virtual SimpleRange< element_iterator > active_local_subdomain_elements_ptr_range(subdomain_id_type sid)=0
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition: Positions.C:220
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...
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...
registerMooseObject("MooseApp", QuadraturePointsPositions)
FEFamily