www.mooseframework.org
ImageSubdomain.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
11 #include <cmath>
12 
13 // MOOSE includes
14 #include "ImageSubdomain.h"
15 #include "MooseMesh.h"
16 
17 #include "libmesh/elem.h"
18 
20 
21 template <>
24 {
26  params.addClassDescription("Samples an image at the coordinates of each element centroid using "
27  "the resulting value as each element's subdomain ID");
28  params += validParams<ImageSampler>();
29  return params;
30 }
31 
33  : MeshModifier(parameters), ImageSampler(parameters)
34 {
35 }
36 
37 void
39 {
40  // Check that we have access to the mesh
41  if (!_mesh_ptr)
42  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
43 
44  // Initialize the ImageSampler
46 
47  // Reference the the libMesh::MeshBase
48  MeshBase & mesh = _mesh_ptr->getMesh();
49 
50  // Loop over the elements and sample the image at the element centroid and use the value for the
51  // subdomain id
52  for (auto & elem : mesh.active_element_ptr_range())
53  {
54  SubdomainID id = static_cast<SubdomainID>(round(sample(elem->centroid())));
55  elem->subdomain_id() = id;
56  }
57 }
InputParameters validParams< ImageSampler >()
Definition: ImageSampler.C:19
virtual void setupImageSampler(MooseMesh &mesh)
Perform initialization of image data.
Definition: ImageSampler.C:75
Real round(Real x)
Definition: MathUtils.h:22
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
MeshModifier for defining a Subdomains based on Image data.
registerMooseObject("MooseApp", ImageSubdomain)
subdomain_id_type SubdomainID
A helper class for reading and sampling images using VTK.
Definition: ImageSampler.h:51
InputParameters validParams< ImageSubdomain >()
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
ImageSubdomain(const InputParameters &parameters)
Class constructor.
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...
virtual Real sample(const Point &p)
Return the pixel value for the given point.
Definition: ImageSampler.C:214
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15