LCOV - code coverage report
Current view: top level - src/meshgenerators - ImageSubdomainGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 18 19 94.7 %
Date: 2025-08-08 20:01:16 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 "ImageSubdomainGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : 
      13             : #include "libmesh/elem.h"
      14             : 
      15             : // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
      16             : #include <cmath>
      17             : 
      18             : registerMooseObject("MooseApp", ImageSubdomainGenerator);
      19             : 
      20             : InputParameters
      21       14397 : ImageSubdomainGenerator::validParams()
      22             : {
      23       14397 :   InputParameters params = MeshGenerator::validParams();
      24       14397 :   params.addClassDescription("Samples an image at the coordinates of each element centroid, using "
      25             :                              "the resulting pixel color value as each element's subdomain ID");
      26       14397 :   params += MeshBaseImageSampler::validParams();
      27             : 
      28       14397 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      29             : 
      30       14397 :   return params;
      31           0 : }
      32             : 
      33          66 : ImageSubdomainGenerator::ImageSubdomainGenerator(const InputParameters & parameters)
      34          66 :   : MeshGenerator(parameters), MeshBaseImageSampler(parameters), _input(getMesh("input"))
      35             : {
      36          66 : }
      37             : 
      38             : std::unique_ptr<MeshBase>
      39          60 : ImageSubdomainGenerator::generate()
      40             : {
      41          60 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      42             : 
      43             :   // Initialize the ImageSampler
      44          60 :   setupImageSampler(*mesh);
      45             : 
      46             :   // Loop over the elements and sample the image at the element centroid and use the value for the
      47             :   // subdomain id
      48      700707 :   for (auto & elem : mesh->active_element_ptr_range())
      49             :   {
      50      700647 :     subdomain_id_type id = static_cast<subdomain_id_type>(round(sample(elem->vertex_average())));
      51      700647 :     elem->subdomain_id() = id;
      52          60 :   }
      53             : 
      54         120 :   return dynamic_pointer_cast<MeshBase>(mesh);
      55          60 : }

Generated by: LCOV version 1.14