Line data Source code
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 : #pragma once 10 : 11 : #include "ThreadedGeneralUserObject.h" 12 : 13 : /** 14 : * User object that computes the shortest distance to one or more surfaces 15 : * defined by function- and/or mesh-based distance strategies. 16 : * 17 : * This object only answers distance queries on demand; it does not store or 18 : * build up any results of its own. Other objects call distanceVector()/ 19 : * trueNormal()/... directly, and there is no per-element work to do, so an 20 : * ElementUserObject's element loop would not be used here. For that reason it 21 : * is a ThreadedGeneralUserObject rather than an element-based user object. 22 : * 23 : * A ThreadedGeneralUserObject is constructed once per thread. Each copy stores 24 : * its own per-thread Function pointers; parsed functions mutate internal state 25 : * during evaluation, so sharing the TID=0 copy across threads can race and 26 : * produce incorrect distances. The per-thread copies avoid that race. 27 : */ 28 : class ShortestDistanceToSurface : public ThreadedGeneralUserObject 29 : { 30 : public: 31 : static InputParameters validParams(); 32 : ShortestDistanceToSurface(const InputParameters & parameters); 33 102 : void initialize() override {} 34 102 : void execute() override {} 35 85 : void finalize() override {} 36 : 37 : // This object answers queries on demand and stores no results, so there is 38 : // nothing to combine across threads. 39 17 : void threadJoin(const UserObject &) override {} 40 : 41 : /// @brief Get the SBMSurfaceMeshBuilder user objects 42 : const std::vector<const Function *> & getDistanceFuncs() const { return _distance_functions; } 43 : 44 : /// Return the closest distance vector from point pt to the boundaries 45 : RealVectorValue distanceVector(const Point & pt) const; 46 : 47 : /// Return the true normal vector at the closest point on the boundaries 48 : RealVectorValue trueNormal(const Point & pt) const; 49 : 50 : /// A distance vector from a point \p pt to a specific surface specified by index \p idx 51 : /// in the 'surfaces' parameter list. 52 : RealVectorValue distanceVectorByIndex(unsigned int idx, const Point & pt) const; 53 : 54 : /// A true normal vector at the projected point of \p pt onto a specific surface specified 55 : /// by index \p idx in the 'surfaces' parameter list. 56 : RealVectorValue trueNormalByIndex(unsigned int idx, const Point & pt) const; 57 : 58 : /// Compute distance vector using a specific distance function 59 : RealVectorValue distanceVectorByFunc(const Point & pt, Real t, const Function * func) const; 60 : 61 : /// Compute true normal using a specific distance function 62 : RealVectorValue trueNormalByFunc(const Point & pt, Real t, const Function * func) const; 63 : 64 : protected: 65 : /// Optional signed-distance function 66 : std::vector<const Function *> _distance_functions; 67 : };