www.mooseframework.org
OrientedBoxInterface.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 #include "OrientedBoxInterface.h"
16 
17 // MOOSE includes
18 #include "InputParameters.h"
19 #include "MooseError.h"
20 
21 // libMesh incluces
22 
23 template <>
26 {
28  params.addRequiredParam<Point>("center",
29  "The center (many people spell this 'center') of the box.");
30  params.addRequiredParam<Real>("width", "The width of the box");
31  params.addRequiredParam<Real>("length", "The length of the box");
32  params.addRequiredParam<Real>("height", "The height of the box");
33  params.addRequiredParam<RealVectorValue>("width_direction",
34  "The direction along which the width is oriented.");
35  params.addRequiredParam<RealVectorValue>("length_direction",
36  "The direction along which the length is oriented (must "
37  "be perpendicular to width_direction).");
38  return params;
39 }
40 
42  : _center(parameters.get<Point>("center"))
43 {
44  const std::string & name = parameters.get<std::string>("_object_name");
45 
46  // Define the bounding box
47  Real xmax = 0.5 * parameters.get<Real>("width");
48  Real ymax = 0.5 * parameters.get<Real>("length");
49  Real zmax = 0.5 * parameters.get<Real>("height");
50 
51  Point bottom_left(-xmax, -ymax, -zmax);
52  Point top_right(xmax, ymax, zmax);
53 
54  _bounding_box = libmesh_make_unique<BoundingBox>(bottom_left, top_right);
55 
56  /*
57  * now create the rotation matrix that rotates the oriented
58  * box's width direction to "x", its length direction to "y"
59  * and its height direction to "z"
60  */
61  RealVectorValue w = parameters.get<RealVectorValue>("width_direction");
62  RealVectorValue l = parameters.get<RealVectorValue>("length_direction");
63 
64  /*
65  * Normalize the width and length directions in readiness for
66  * insertion into the rotation matrix
67  */
68  Real len = w.norm();
69  if (len == 0.0)
70  mooseError("Length of width_direction vector is zero in ", name);
71  w /= len;
72 
73  len = l.norm();
74  if (len == 0.0)
75  mooseError("Length of length_direction vector is zero in ", name);
76  l /= len;
77 
78  if (w * l > 1E-10)
79  mooseError("width_direction and length_direction are not perpendicular in ", name);
80 
81  // The rotation matrix!
82  _rot_matrix = libmesh_make_unique<RealTensorValue>(w, l, w.cross(l));
83 }
84 
85 bool
87 {
88  // Translate the point to the origin, and then rotate
89  return _bounding_box->contains_point((*_rot_matrix) * (point - _center));
90 }
bool containsPoint(const Point &point)
Test if the supplied point is within the defined oriented bounding box.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
InputParameters validParams< OrientedBoxInterface >()
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Point _center
Center of the defined bounding box.
std::unique_ptr< RealTensorValue > _rot_matrix
Rotation matrix for transforming the bounding box.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
InputParameters emptyInputParameters()
std::unique_ptr< BoundingBox > _bounding_box
The bounding box used to test if the point is contained within.
OrientedBoxInterface(const InputParameters &parameters)
Class constructor.