LCOV - code coverage report
Current view: top level - src/positions - QuadraturePointsPositions.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 53 54 98.1 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "QuadraturePointsPositions.h"
      11             : #include "libmesh/quadrature_gauss.h"
      12             : #include "SetupQuadratureAction.h"
      13             : 
      14             : using namespace libMesh;
      15             : 
      16             : registerMooseObject("MooseApp", QuadraturePointsPositions);
      17             : 
      18             : InputParameters
      19       14313 : QuadraturePointsPositions::validParams()
      20             : {
      21       14313 :   InputParameters params = Positions::validParams();
      22       14313 :   params.addClassDescription("Positions of element quadrature points.");
      23       14313 :   params += BlockRestrictable::validParams();
      24             : 
      25       42939 :   params.addParam<MooseEnum>("quadrature_type",
      26       28626 :                              SetupQuadratureAction::getQuadratureTypesEnum(),
      27             :                              "Type of the quadrature rule");
      28       42939 :   params.addParam<MooseEnum>("quadrature_order",
      29       28626 :                              SetupQuadratureAction::getQuadratureOrderEnum(),
      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       14313 :   params.set<bool>("auto_sort") = false;
      36             :   // Gathered locally, should be broadcast on every process
      37       14313 :   params.set<bool>("auto_broadcast") = true;
      38             : 
      39       14313 :   return params;
      40           0 : }
      41             : 
      42          24 : QuadraturePointsPositions::QuadraturePointsPositions(const InputParameters & parameters)
      43             :   : Positions(parameters),
      44             :     BlockRestrictable(this),
      45          48 :     _mesh(_fe_problem.mesh()),
      46          24 :     _q_type(Moose::stringToEnum<QuadratureType>(getParam<MooseEnum>("quadrature_type"))),
      47          48 :     _q_order(Moose::stringToEnum<Order>(getParam<MooseEnum>("quadrature_order")))
      48             : {
      49             :   // Mesh is ready at construction
      50          24 :   initialize();
      51             :   // Trigger synchronization as the initialization is distributed
      52          24 :   finalize();
      53          24 : }
      54             : 
      55             : void
      56          24 : QuadraturePointsPositions::initialize()
      57             : {
      58          24 :   clearPositions();
      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          24 :   if (blockRestricted())
      63             :   {
      64          12 :     _positions_2d.resize(numBlocks());
      65          12 :     unsigned int b_index = 0;
      66          24 :     for (const auto & sub_id : blockIDs())
      67             :     {
      68          30 :       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           9 :         const FEFamily mapping_family = FEMap::map_fe_type(*elem);
      72           9 :         const FEType fe_type(elem->default_order(), mapping_family);
      73           9 :         std::unique_ptr<FEBase> fe = FEBase::build(elem->dim(), fe_type);
      74             :         const auto q_order =
      75           9 :             (_q_order == INVALID_ORDER) ? fe_type.default_quadrature_order() : _q_order;
      76           9 :         auto qrule = QBase::build(_q_type, elem->dim(), q_order);
      77           9 :         fe->attach_quadrature_rule(qrule.get());
      78           9 :         const auto & q_points = fe->get_xyz();
      79           9 :         fe->reinit(elem);
      80             : 
      81          81 :         for (const auto & q : q_points)
      82             :         {
      83          72 :           _positions.emplace_back(q);
      84          72 :           _positions_2d[b_index].emplace_back(q);
      85             :         }
      86          21 :       }
      87          12 :       b_index += 1;
      88             :     }
      89             :   }
      90             :   else
      91             :   {
      92          12 :     _positions.resize(_mesh.getMesh().n_active_local_elem());
      93          48 :     for (const auto & elem : _mesh.getMesh().active_local_element_ptr_range())
      94             :     {
      95             :       // Get a quadrature going on the element
      96          18 :       const FEFamily mapping_family = FEMap::map_fe_type(*elem);
      97          18 :       const FEType fe_type(elem->default_order(), mapping_family);
      98          18 :       std::unique_ptr<FEBase> fe = FEBase::build(elem->dim(), fe_type);
      99             :       const auto q_order =
     100          18 :           (_q_order == INVALID_ORDER) ? fe_type.default_quadrature_order() : _q_order;
     101          18 :       auto qrule = QBase::build(_q_type, elem->dim(), q_order);
     102          18 :       fe->attach_quadrature_rule(qrule.get());
     103          18 :       const auto & q_points = fe->get_xyz();
     104          18 :       fe->reinit(elem);
     105             : 
     106         162 :       for (const auto & q : q_points)
     107         144 :         _positions.emplace_back(q);
     108          30 :     }
     109             :   }
     110          24 :   _initialized = true;
     111          24 : }

Generated by: LCOV version 1.14