Line data Source code
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 : #include "CSGSphere.h" 11 : 12 : namespace CSG 13 : { 14 : 15 4 : CSGSphere::CSGSphere(const std::string & name, const Point & center, const Real r) 16 4 : : CSGSurface(name, MooseUtils::prettyCppType<CSGSphere>()), 17 8 : _x0(center(0)), 18 4 : _y0(center(1)), 19 4 : _z0(center(2)), 20 8 : _r(r) 21 : { 22 4 : checkRadius(); 23 4 : } 24 : 25 78 : CSGSphere::CSGSphere(const std::string & name, const Real r) 26 78 : : CSGSurface(name, MooseUtils::prettyCppType<CSGSphere>()), _x0(0.0), _y0(0.0), _z0(0.0), _r(r) 27 : { 28 78 : checkRadius(); 29 78 : } 30 : 31 : std::unordered_map<std::string, Real> 32 188 : CSGSphere::getCoeffs() const 33 : { 34 1128 : std::unordered_map<std::string, Real> coeffs = {{"x0", _x0}, {"y0", _y0}, {"z0", _z0}, {"r", _r}}; 35 188 : return coeffs; 36 188 : } 37 : 38 : Real 39 2 : CSGSphere::evaluateSurfaceEquationAtPoint(const Point & p) const 40 : { 41 : // Compute distance from the sphere center to determine if inside (< r^2) 42 : // or outside (> r^2) the sphere 43 : const Real dist_sq = 44 2 : Utility::pow<2>((p(0) - _x0)) + Utility::pow<2>((p(1) - _y0)) + Utility::pow<2>((p(2) - _z0)); 45 : 46 2 : return dist_sq - Utility::pow<2>(_r); 47 : } 48 : 49 : void 50 82 : CSGSphere::checkRadius() const 51 : { 52 82 : if (_r <= 0.0) 53 2 : mooseError("Radius of sphere must be positive."); 54 80 : } 55 : 56 : } // namespace CSG