Chi-Tech
RCCLogicalVolume.cc
Go to the documentation of this file.
1#include "RCCLogicalVolume.h"
2
3#include "ChiObjectFactory.h"
4
5namespace chi_mesh
6{
7
9
11{
13
14 params.SetDocGroup("LuaLogicVolumes");
15
16 params.AddOptionalParameter("r", 1.0, "Radius of the sphere.");
17 params.AddOptionalParameter("x0", 0.0, "X-coordinate of the volume base");
18 params.AddOptionalParameter("y0", 0.0, "Y-coordinate of the volume base");
19 params.AddOptionalParameter("z0", 0.0, "Z-coordinate of the volume base");
21 "vx", 0.0, "X-component of the volume extrusion vector");
23 "vy", 0.0, "Y-component of the volume extrusion vector");
25 "vz", 1.0, "Z-component of the volume extrusion vector");
26
27 return params;
28}
29
31 : LogicalVolume(params),
32 r_(params.GetParamValue<double>("r")),
33 x0_(params.GetParamValue<double>("x0")),
34 y0_(params.GetParamValue<double>("y0")),
35 z0_(params.GetParamValue<double>("z0")),
36 vx_(params.GetParamValue<double>("vx")),
37 vy_(params.GetParamValue<double>("vy")),
38 vz_(params.GetParamValue<double>("vz"))
39{
40}
41
43{
44 typedef chi_mesh::Vector3 Vec3;
45
46 const auto& pr = point; // reference point
47 const Vec3 p0(x0_, y0_, z0_); // cylinder root
48 const Vec3 cyl_dir_vec(vx_, vy_, vz_); // cylinder direction vector
49 const Vec3 k_hat(0.0, 0.0, 1.0); // k_hat
50
51 const Vec3 p0r = pr - p0;
52 const Vec3 cyl_unit_dir = cyl_dir_vec.Normalized(); // aka cud
53 const double cyl_length = cyl_dir_vec.Norm();
54
55 //====================================== Check if point is within
56 // normal extents
57 const double p0r_dot_cud = p0r.Dot(cyl_unit_dir);
58 if (p0r_dot_cud < 0.0 or p0r_dot_cud > cyl_length) return false;
59
60 //====================================== Building rotation matrix
61 // This rotation matrix must be such that,
62 // when a coordinate system is rotated with it,
63 // the new normal vector points along the
64 Vec3 binorm;
65 Vec3 tangent;
66 if (std::abs(cyl_dir_vec.Dot(k_hat) / cyl_dir_vec.Norm()) > (1.0 - 1.0e-12))
67 {
68 binorm = Vec3(0.0, 1.0, 0.0);
69 tangent = Vec3(1.0, 0.0, 0.0);
70 }
71 else
72 {
73 binorm = k_hat.Cross(cyl_dir_vec);
74 binorm = binorm / binorm.Norm();
75 tangent = binorm.Cross(cyl_dir_vec);
76 tangent = tangent / tangent.Norm();
77 }
78
79 //====================================== Project p0r onto the binorm and
80 // tangent
81 const Vec3 p0r_projected(p0r.Dot(tangent), p0r.Dot(binorm), 0.0);
82
83 //====================================== Determine if point is within
84 //cylinder
85 if (p0r_projected.NormSquare() <= r_ * r_) return true;
86 else
87 return false;
88}
89
90} // namespace chi_mesh
void SetDocGroup(const std::string &doc_group)
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
static chi::InputParameters GetInputParameters()
Definition: LogicalVolume.cc:6
bool Inside(const chi_mesh::Vector3 &point) const override
static chi::InputParameters GetInputParameters()
RCCLogicalVolume(const chi::InputParameters &params)
RegisterChiObject(chi_mesh, BooleanLogicalVolume)