LCOV - code coverage report
Current view: top level - src/meshgenerators - ImageSubdomainGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 18 19 94.7 %
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 "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       14385 : ImageSubdomainGenerator::validParams()
      22             : {
      23       14385 :   InputParameters params = MeshGenerator::validParams();
      24       14385 :   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       14385 :   params += MeshBaseImageSampler::validParams();
      27             : 
      28       14385 :   params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
      29             : 
      30       14385 :   return params;
      31           0 : }
      32             : 
      33          60 : ImageSubdomainGenerator::ImageSubdomainGenerator(const InputParameters & parameters)
      34          60 :   : MeshGenerator(parameters), MeshBaseImageSampler(parameters), _input(getMesh("input"))
      35             : {
      36          60 : }
      37             : 
      38             : std::unique_ptr<MeshBase>
      39          54 : ImageSubdomainGenerator::generate()
      40             : {
      41          54 :   std::unique_ptr<MeshBase> mesh = std::move(_input);
      42             : 
      43             :   // Initialize the ImageSampler
      44          54 :   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      635465 :   for (auto & elem : mesh->active_element_ptr_range())
      49             :   {
      50      635411 :     subdomain_id_type id = static_cast<subdomain_id_type>(round(sample(elem->vertex_average())));
      51      635411 :     elem->subdomain_id() = id;
      52          54 :   }
      53             : 
      54         108 :   return dynamic_pointer_cast<MeshBase>(mesh);
      55          54 : }

Generated by: LCOV version 1.14