LCOV - code coverage report
Current view: top level - src/userobjects - NodalDensity.C (source / functions) Hit Total Coverage
Test: idaholab/moose contact: 8601ad Lines: 35 37 94.6 %
Date: 2025-07-18 13:27:36 Functions: 8 8 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 "NodalDensity.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariable.h"
      14             : #include "SystemBase.h"
      15             : 
      16             : #include "libmesh/numeric_vector.h"
      17             : #include "libmesh/quadrature.h"
      18             : 
      19             : registerMooseObject("ContactApp", NodalDensity);
      20             : 
      21             : InputParameters
      22         156 : NodalDensity::validParams()
      23             : {
      24         156 :   InputParameters params = SideIntegralVariableUserObject::validParams();
      25         156 :   params.set<ExecFlagEnum>("execute_on") = EXEC_LINEAR;
      26         156 :   params.addClassDescription("Compute the tributary densities for nodes on a surface");
      27         156 :   return params;
      28           0 : }
      29             : 
      30          84 : NodalDensity::NodalDensity(const InputParameters & parameters)
      31             :   : SideIntegralVariableUserObject(parameters),
      32          84 :     _phi(_variable->phiFace()),
      33          84 :     _system(_variable->sys()),
      34          84 :     _aux_solution(_system.solution()),
      35         168 :     _density(getMaterialProperty<Real>("density"))
      36             : {
      37          84 : }
      38             : 
      39         252 : NodalDensity::~NodalDensity() {}
      40             : 
      41             : void
      42        1968 : NodalDensity::threadJoin(const UserObject & fred)
      43             : {
      44        1968 :   const NodalDensity & na = dynamic_cast<const NodalDensity &>(fred);
      45             : 
      46             :   std::map<const Node *, Real>::const_iterator it = na._node_densities.begin();
      47             :   const std::map<const Node *, Real>::const_iterator it_end = na._node_densities.end();
      48        1968 :   for (; it != it_end; ++it)
      49             :   {
      50           0 :     _node_densities[it->first] += it->second;
      51             :   }
      52        1968 : }
      53             : 
      54             : void
      55       10496 : NodalDensity::initialize()
      56             : {
      57             :   _node_densities.clear();
      58       10496 : }
      59             : 
      60             : void
      61       45112 : NodalDensity::execute()
      62             : {
      63       45112 :   std::vector<Real> node_densities(_phi.size());
      64      225560 :   for (unsigned qp(0); qp < _qrule->n_points(); ++qp)
      65     1624032 :     for (unsigned j(0); j < _phi.size(); ++j)
      66     1443584 :       node_densities[j] += (_phi[j][qp] * _density[qp]);
      67             : 
      68      406008 :   for (unsigned j(0); j < _phi.size(); ++j)
      69             :   {
      70      360896 :     const Real density = node_densities[j];
      71      360896 :     if (density != 0)
      72      180448 :       _node_densities[_current_elem->node_ptr(j)] = density;
      73             :   }
      74       45112 : }
      75             : 
      76             : void
      77        8528 : NodalDensity::finalize()
      78             : {
      79             : 
      80             :   const std::map<const Node *, Real>::iterator it_end = _node_densities.end();
      81      101588 :   for (std::map<const Node *, Real>::iterator it = _node_densities.begin(); it != it_end; ++it)
      82             :   {
      83       93060 :     const Node * const node = it->first;
      84       93060 :     dof_id_type dof = node->dof_number(_system.number(), _variable->number(), 0);
      85       93060 :     _aux_solution.set(dof, it->second);
      86             :   }
      87        8528 :   _aux_solution.close();
      88        8528 : }

Generated by: LCOV version 1.14