diff --git a/framework/doc/content/source/meshmodifiers/MoveNodesToSphere.md b/framework/doc/content/source/meshmodifiers/MoveNodesToSphere.md new file mode 100644 index 000000000000..fe3568181f01 --- /dev/null +++ b/framework/doc/content/source/meshmodifiers/MoveNodesToSphere.md @@ -0,0 +1,17 @@ +# MoveNodesToSphere + +!syntax description /UserObjects/MoveNodesToSphere + +Moves all nodes from the supplied [!param](/UserObjects/MoveNodesToSphere/boundary) or [!param](/UserObjects/MoveNodesToSphere/block) +to the surface of the sphere specified by the [!param](/UserObjects/MoveNodesToSphere/center) and +[!param](/UserObjects/MoveNodesToSphere/radius) parameters. + +This is performed by default during adaptivity to allow adaptive refinement of curved geometries. +It can also be performed using regular execution schedules specified by the [!param](/UserObjects/MoveNodesToSphere/execute_on) +parameter. + +!syntax parameters /UserObjects/MoveNodesToSphere + +!syntax inputs /UserObjects/MoveNodesToSphere + +!syntax children /UserObjects/MoveNodesToSphere diff --git a/framework/doc/content/source/userobjects/GeometrySphere.md b/framework/doc/content/source/userobjects/GeometrySphere.md deleted file mode 100644 index d358d95a99bb..000000000000 --- a/framework/doc/content/source/userobjects/GeometrySphere.md +++ /dev/null @@ -1,13 +0,0 @@ -# GeometrySphere - -!syntax description /UserObjects/GeometrySphere - -Whenever the mesh changes all nodes on the supplied `boundary` are snapped to the -surface of the sphere specified by `center` and `radius`. This allows adaptive -refinement of curved geometries. - -!syntax parameters /UserObjects/GeometrySphere - -!syntax inputs /UserObjects/GeometrySphere - -!syntax children /UserObjects/GeometrySphere diff --git a/framework/include/userobjects/GeometryBase.h b/framework/include/meshmodifiers/MoveNodesToGeometryModifierBase.h similarity index 64% rename from framework/include/userobjects/GeometryBase.h rename to framework/include/meshmodifiers/MoveNodesToGeometryModifierBase.h index 47311f6ec823..6e247fff05a7 100644 --- a/framework/include/userobjects/GeometryBase.h +++ b/framework/include/meshmodifiers/MoveNodesToGeometryModifierBase.h @@ -12,15 +12,15 @@ #include "GeneralUserObject.h" /** - * Base class for userobjects that snap nodes to a defined geometry when - * adaptivity happens. + * Base class for mesh modifiers that snap nodes to a defined geometry either when executed + * or when mesh adaptivity happens */ -class GeometryBase : public GeneralUserObject +class MoveNodesToGeometryModifierBase : public GeneralUserObject { public: static InputParameters validParams(); - GeometryBase(const InputParameters & parameters); + MoveNodesToGeometryModifierBase(const InputParameters & parameters); virtual void initialize() final; virtual void execute() final; @@ -29,6 +29,9 @@ class GeometryBase : public GeneralUserObject virtual void meshChanged() final; protected: + /// Snap all nodes from the specified block or boundary restriction to the derived-class-defined geometry + void snapNodes(); + /** * Override this method in derived classes to implement a specific geometry. * The method takes a writable reference to a node. Set the position of the @@ -39,9 +42,9 @@ class GeometryBase : public GeneralUserObject /// Reference to the current simulation mesh MooseMesh & _mesh; - /// List of boundaries (or node sets) that will be snapped to a geometry + /// List of boundaries (or node sets) from which nodes will be snapped to a geometry const std::vector _boundary_ids; - /// List of blocks (likely lower D blocks) that will be snapped to a geometry + /// List of blocks (likely lower D blocks) from which nodes will be snapped to a geometry const std::vector _subdomain_ids; }; diff --git a/framework/include/userobjects/GeometrySphere.h b/framework/include/meshmodifiers/MoveNodesToSphere.h similarity index 66% rename from framework/include/userobjects/GeometrySphere.h rename to framework/include/meshmodifiers/MoveNodesToSphere.h index 31685d7b09b2..79196d9894eb 100644 --- a/framework/include/userobjects/GeometrySphere.h +++ b/framework/include/meshmodifiers/MoveNodesToSphere.h @@ -9,21 +9,23 @@ #pragma once -#include "GeometryBase.h" +#include "MoveNodesToGeometryModifierBase.h" /** * Snaps the selected nodes to the surface of a sphere (or circular disk in 2D) */ -class GeometrySphere : public GeometryBase +class MoveNodesToSphere : public MoveNodesToGeometryModifierBase { public: static InputParameters validParams(); - GeometrySphere(const InputParameters & parameters); + MoveNodesToSphere(const InputParameters & parameters); protected: - virtual void snapNode(Node & node); + virtual void snapNode(Node & node) override; + /// Center of the sphere const Point _center; + /// Radius of the sphere const Real _radius; }; diff --git a/framework/src/userobjects/GeometryBase.C b/framework/src/meshmodifiers/MoveNodesToGeometryModifierBase.C similarity index 77% rename from framework/src/userobjects/GeometryBase.C rename to framework/src/meshmodifiers/MoveNodesToGeometryModifierBase.C index f9c4b50e2058..c1876102abec 100644 --- a/framework/src/userobjects/GeometryBase.C +++ b/framework/src/meshmodifiers/MoveNodesToGeometryModifierBase.C @@ -7,12 +7,12 @@ //* Licensed under LGPL 2.1, please see LICENSE for details //* https://www.gnu.org/licenses/lgpl-2.1.html -#include "GeometryBase.h" +#include "MoveNodesToGeometryModifierBase.h" #include "MooseMesh.h" #include "libmesh/mesh_base.h" InputParameters -GeometryBase::validParams() +MoveNodesToGeometryModifierBase::validParams() { InputParameters params = GeneralUserObject::validParams(); params.addClassDescription( @@ -21,10 +21,14 @@ GeometryBase::validParams() "boundary", {}, "List of boundaries whose nodes are snapped to a given geometry"); params.addParam>( "block", {}, "List of blocks whose nodes are snapped to a given geometry"); + + // By default don't execute + params.set("execute_on") = "NONE"; + return params; } -GeometryBase::GeometryBase(const InputParameters & parameters) +MoveNodesToGeometryModifierBase::MoveNodesToGeometryModifierBase(const InputParameters & parameters) : GeneralUserObject(parameters), _mesh(_subproblem.mesh()), _boundary_ids(_mesh.getBoundaryIDs(getParam>("boundary"))), @@ -33,22 +37,29 @@ GeometryBase::GeometryBase(const InputParameters & parameters) } void -GeometryBase::initialize() +MoveNodesToGeometryModifierBase::initialize() +{ +} + +void +MoveNodesToGeometryModifierBase::execute() { + snapNodes(); } void -GeometryBase::execute() +MoveNodesToGeometryModifierBase::finalize() { } void -GeometryBase::finalize() +MoveNodesToGeometryModifierBase::meshChanged() { + snapNodes(); } void -GeometryBase::meshChanged() +MoveNodesToGeometryModifierBase::snapNodes() { auto & mesh = _mesh.getMesh(); diff --git a/framework/src/meshmodifiers/MoveNodesToSphere.C b/framework/src/meshmodifiers/MoveNodesToSphere.C new file mode 100644 index 000000000000..870d07cedadc --- /dev/null +++ b/framework/src/meshmodifiers/MoveNodesToSphere.C @@ -0,0 +1,39 @@ +//* This file is part of the MOOSE framework +//* https://www.mooseframework.org +//* +//* All rights reserved, see COPYRIGHT for full restrictions +//* https://github.com/idaholab/moose/blob/master/COPYRIGHT +//* +//* Licensed under LGPL 2.1, please see LICENSE for details +//* https://www.gnu.org/licenses/lgpl-2.1.html + +#include "MoveNodesToSphere.h" + +registerMooseObject("MooseApp", MoveNodesToSphere); +registerMooseObjectRenamed("MooseApp", GeometrySphere, "06/30/2025 24:00", MoveNodesToSphere); + +InputParameters +MoveNodesToSphere::validParams() +{ + InputParameters params = MoveNodesToGeometryModifierBase::validParams(); + params.addClassDescription( + "Snap nodes to the surface of a sphere either during adaptivity or on execution"); + params.addParam("center", "Sphere center"); + params.addParam("radius", "Sphere radius"); + return params; +} + +MoveNodesToSphere::MoveNodesToSphere(const InputParameters & parameters) + : MoveNodesToGeometryModifierBase(parameters), + _center(getParam("center")), + _radius(getParam("radius")) +{ +} + +void +MoveNodesToSphere::snapNode(Node & node) +{ + const Point o = node - _center; + const Real r = o.norm(); + node = o * _radius / r + _center; +} diff --git a/framework/src/userobjects/GeometrySphere.C b/framework/src/userobjects/GeometrySphere.C deleted file mode 100644 index 203a5432a1b1..000000000000 --- a/framework/src/userobjects/GeometrySphere.C +++ /dev/null @@ -1,35 +0,0 @@ -//* This file is part of the MOOSE framework -//* https://www.mooseframework.org -//* -//* All rights reserved, see COPYRIGHT for full restrictions -//* https://github.com/idaholab/moose/blob/master/COPYRIGHT -//* -//* Licensed under LGPL 2.1, please see LICENSE for details -//* https://www.gnu.org/licenses/lgpl-2.1.html - -#include "GeometrySphere.h" - -registerMooseObject("MooseApp", GeometrySphere); - -InputParameters -GeometrySphere::validParams() -{ - InputParameters params = GeometryBase::validParams(); - params.addClassDescription("Snap nodes to the surface of a sphere on adaptivity"); - params.addParam("center", "Sphere center"); - params.addParam("radius", "Sphere radius"); - return params; -} - -GeometrySphere::GeometrySphere(const InputParameters & parameters) - : GeometryBase(parameters), _center(getParam("center")), _radius(getParam("radius")) -{ -} - -void -GeometrySphere::snapNode(Node & node) -{ - const Point o = node - _center; - const Real r = o.norm(); - node = o * _radius / r + _center; -} diff --git a/test/tests/userobjects/geometry_snap/block.i b/test/tests/meshmodifiers/move_nodes_to_sphere/block.i similarity index 100% rename from test/tests/userobjects/geometry_snap/block.i rename to test/tests/meshmodifiers/move_nodes_to_sphere/block.i diff --git a/test/tests/userobjects/geometry_snap/geometrysphere.i b/test/tests/meshmodifiers/move_nodes_to_sphere/geometrysphere.i similarity index 100% rename from test/tests/userobjects/geometry_snap/geometrysphere.i rename to test/tests/meshmodifiers/move_nodes_to_sphere/geometrysphere.i diff --git a/test/tests/userobjects/geometry_snap/gold/block_out.e-s004 b/test/tests/meshmodifiers/move_nodes_to_sphere/gold/block_out.e-s004 similarity index 100% rename from test/tests/userobjects/geometry_snap/gold/block_out.e-s004 rename to test/tests/meshmodifiers/move_nodes_to_sphere/gold/block_out.e-s004 diff --git a/test/tests/userobjects/geometry_snap/gold/geometrysphere_out.e-s004 b/test/tests/meshmodifiers/move_nodes_to_sphere/gold/geometrysphere_out.e-s004 similarity index 100% rename from test/tests/userobjects/geometry_snap/gold/geometrysphere_out.e-s004 rename to test/tests/meshmodifiers/move_nodes_to_sphere/gold/geometrysphere_out.e-s004 diff --git a/test/tests/userobjects/geometry_snap/tests b/test/tests/meshmodifiers/move_nodes_to_sphere/tests similarity index 95% rename from test/tests/userobjects/geometry_snap/tests rename to test/tests/meshmodifiers/move_nodes_to_sphere/tests index f0f26ecfbf5d..887c8aa0def9 100644 --- a/test/tests/userobjects/geometry_snap/tests +++ b/test/tests/meshmodifiers/move_nodes_to_sphere/tests @@ -1,5 +1,5 @@ [Tests] - design = 'GeometrySphere.md' + design = 'MoveNodesToSphere.md' [geometrysphere] type = 'Exodiff' input = 'geometrysphere.i'