www.mooseframework.org
ImageSubdomain.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // provides round, not std::round (see http://www.cplusplus.com/reference/cmath/round/)
16 #include <cmath>
17 
18 // MOOSE includes
19 #include "ImageSubdomain.h"
20 #include "MooseMesh.h"
21 
22 template <>
25 {
27  params.addClassDescription("Samples an image at the coordinates of each element centroid using "
28  "the resulting value as each element's subdomain ID");
29  params += validParams<ImageSampler>();
30  return params;
31 }
32 
34  : MeshModifier(parameters), ImageSampler(parameters)
35 {
36 }
37 
38 void
40 {
41  // Check that we have access to the mesh
42  if (!_mesh_ptr)
43  mooseError("_mesh_ptr must be initialized before calling SubdomainBoundingBox::modify()");
44 
45  // Initialize the ImageSampler
47 
48  // Reference the the libMesh::MeshBase
49  MeshBase & mesh = _mesh_ptr->getMesh();
50 
51  // Loop over the elements and sample the image at the element centroid and use the value for the
52  // subdomain id
53  for (auto & elem : mesh.active_element_ptr_range())
54  {
55  SubdomainID id = static_cast<SubdomainID>(round(sample(elem->centroid())));
56  elem->subdomain_id() = id;
57  }
58 }
InputParameters validParams< ImageSampler >()
Definition: ImageSampler.C:24
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
virtual void setupImageSampler(MooseMesh &mesh)
Perform initialization of image data.
Definition: ImageSampler.C:80
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:31
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:74
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
A helper class for reading and sampling images using VTK.
Definition: ImageSampler.h:57
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:219
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:20