https://mooseframework.inl.gov
Loading...
Searching...
No Matches
OrientedBoxInterface.C
Go to the documentation of this file.
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
11
12// MOOSE includes
13#include "InputParameters.h"
14#include "MooseError.h"
15
16#include <memory>
17
20{
21
23 params.addRequiredParam<Point>("center",
24 "The center (many people spell this 'center') of the box.");
25 params.addRequiredParam<Real>("width", "The width of the box");
26 params.addRequiredParam<Real>("length", "The length of the box");
27 params.addRequiredParam<Real>("height", "The height of the box");
28 params.addRequiredParam<RealVectorValue>("width_direction",
29 "The direction along which the width is oriented.");
30 params.addRequiredParam<RealVectorValue>("length_direction",
31 "The direction along which the length is oriented (must "
32 "be perpendicular to width_direction).");
33 return params;
34}
35
37 : _center(parameters.get<Point>("center"))
38{
39 const std::string & name = parameters.getObjectName();
40
41 // Define the bounding box
42 Real xmax = 0.5 * parameters.get<Real>("width");
43 Real ymax = 0.5 * parameters.get<Real>("length");
44 Real zmax = 0.5 * parameters.get<Real>("height");
45
46 Point bottom_left(-xmax, -ymax, -zmax);
47 Point top_right(xmax, ymax, zmax);
48
49 _bounding_box = std::make_unique<libMesh::BoundingBox>(bottom_left, top_right);
50
51 /*
52 * now create the rotation matrix that rotates the oriented
53 * box's width direction to "x", its length direction to "y"
54 * and its height direction to "z"
55 */
56 RealVectorValue w = parameters.get<RealVectorValue>("width_direction");
57 RealVectorValue l = parameters.get<RealVectorValue>("length_direction");
58
59 /*
60 * Normalize the width and length directions in readiness for
61 * insertion into the rotation matrix
62 */
63 Real len = w.norm();
64 if (len == 0.0)
65 mooseError("Length of width_direction vector is zero in ", name);
66 w /= len;
67
68 len = l.norm();
69 if (len == 0.0)
70 mooseError("Length of length_direction vector is zero in ", name);
71 l /= len;
72
73 if (w * l > 1E-10)
74 mooseError("width_direction and length_direction are not perpendicular in ", name);
75
76 // The rotation matrix!
77 _rot_matrix = std::make_unique<RealTensorValue>(w, l, w.cross(l));
78}
79
80bool
82{
83 // Translate the point to the origin, and then rotate
84 return _bounding_box->contains_point((*_rot_matrix) * (point - _center));
85}
InputParameters emptyInputParameters()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const std::string & getObjectName() const
OrientedBoxInterface(const InputParameters &parameters)
std::unique_ptr< libMesh::BoundingBox > _bounding_box
The bounding box used to test if the point is contained within.
std::unique_ptr< RealTensorValue > _rot_matrix
Rotation matrix for transforming the bounding box.
Point _center
Center of the defined bounding box.
bool containsPoint(const Point &point)
Test if the supplied point is within the defined oriented bounding box.
static InputParameters validParams()
Class constructor.