diff --git a/framework/doc/content/source/markers/ReporterPointMarker.md b/framework/doc/content/source/markers/ReporterPointMarker.md new file mode 100644 index 000000000000..306338c57bc1 --- /dev/null +++ b/framework/doc/content/source/markers/ReporterPointMarker.md @@ -0,0 +1,19 @@ +# ReporterPointMarker + +!syntax description /Adaptivity/Markers/ReporterPointMarker + +## Description + +The `ReporterPointMarker` is a stand-alone marker that marks all +elements containing points defined by coordinates given in a `Reporter`. + + +## Example Input Syntax + +!listing test/tests/markers/reporter_point_marker/point_marker_test.i block=Adaptivity + +!syntax parameters /Adaptivity/Markers/ReporterPointMarker + +!syntax inputs /Adaptivity/Markers/ReporterPointMarker + +!syntax children /Adaptivity/Markers/ReporterPointMarker diff --git a/framework/include/markers/ReporterPointMarker.h b/framework/include/markers/ReporterPointMarker.h new file mode 100644 index 000000000000..88b4a45a81a3 --- /dev/null +++ b/framework/include/markers/ReporterPointMarker.h @@ -0,0 +1,42 @@ +//* 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 + +#pragma once + +#include "Marker.h" +#include "ReporterInterface.h" + +/** + * Marks all elements near a given boundary for refinement/coarsening + */ +class ReporterPointMarker : public Marker, public ReporterInterface +{ +public: + static InputParameters validParams(); + ReporterPointMarker(const InputParameters & parameters); + virtual void timestepSetup() override; + +protected: + virtual MarkerValue computeElementMarker() override; + + /// marker value to give elements containing a point + const MarkerValue _inside; + /// marker for elements not containing points + const MarkerValue _empty; + /// x coordinate + const std::vector & _x_coord; + /// y coordinate + const std::vector & _y_coord; + ///z coordinate + const std::vector & _z_coord; + /// Pointer to PointLocatorBase object + std::unique_ptr _pl; + /// list of sort uniqued elements containing points + std::set _point_elems; +}; diff --git a/framework/src/markers/ReporterPointMarker.C b/framework/src/markers/ReporterPointMarker.C new file mode 100644 index 000000000000..9affffbf9e5b --- /dev/null +++ b/framework/src/markers/ReporterPointMarker.C @@ -0,0 +1,70 @@ +//* 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 "ReporterPointMarker.h" + +registerMooseObject("MooseApp", ReporterPointMarker); + +InputParameters +ReporterPointMarker::validParams() +{ + InputParameters params = Marker::validParams(); + params.addClassDescription("Marks the region inside or empty if it contains a reporter defined " + "point for refinement or coarsening."); + params.addRequiredParam("x_coord_name", "reporter x-coordinate name"); + params.addRequiredParam("y_coord_name", "reporter y-coordinate name"); + params.addRequiredParam("z_coord_name", "reporter z-coordinate name"); + MooseEnum marker_states = Marker::markerStates(); + params.addRequiredParam( + "inside", marker_states, "How to mark elements containing a point"); + params.addRequiredParam( + "empty", marker_states, "How to mark elements not containing a point"); + return params; +} + +ReporterPointMarker::ReporterPointMarker(const InputParameters & parameters) + : Marker(parameters), + ReporterInterface(this), + _inside(parameters.get("inside").getEnum()), + _empty(parameters.get("empty").getEnum()), + _x_coord(getReporterValue>("x_coord_name", REPORTER_MODE_REPLICATED)), + _y_coord(getReporterValue>("y_coord_name", REPORTER_MODE_REPLICATED)), + _z_coord(getReporterValue>("z_coord_name", REPORTER_MODE_REPLICATED)) +{ +} + +void +ReporterPointMarker::timestepSetup() +{ + if (_x_coord.size() != _y_coord.size() || _x_coord.size() != _z_coord.size()) + mooseError("The coordinate vectors are a different size. \n", + " x_coord size = ", + _x_coord.size(), + "; y_coord size = ", + _y_coord.size(), + "; z_coord size = ", + _z_coord.size()); + + _pl = _fe_problem.mesh().getPointLocator(); + _pl->enable_out_of_mesh_mode(); + _point_elems.clear(); + for (std::size_t i = 0; i < _x_coord.size(); ++i) + { + Point pt(_x_coord[i], _y_coord[i], _z_coord[i]); + const auto elem = (*_pl)(pt); + if (elem) + _point_elems.insert(elem->id()); + } +} + +Marker::MarkerValue +ReporterPointMarker::computeElementMarker() +{ + return (_point_elems.count(_current_elem->id()) ? _inside : _empty); +} diff --git a/test/tests/markers/box_marker/gold/box_marker_test_out.e b/test/tests/markers/box_marker/gold/box_marker_test_out.e index 01bd73f6a171..e0a2634599f0 100644 Binary files a/test/tests/markers/box_marker/gold/box_marker_test_out.e and b/test/tests/markers/box_marker/gold/box_marker_test_out.e differ diff --git a/test/tests/markers/reporter_point_marker/gold/point_marker_test_out.e b/test/tests/markers/reporter_point_marker/gold/point_marker_test_out.e new file mode 120000 index 000000000000..e31ffa47fc82 --- /dev/null +++ b/test/tests/markers/reporter_point_marker/gold/point_marker_test_out.e @@ -0,0 +1 @@ +../../box_marker/gold/box_marker_test_out.e \ No newline at end of file diff --git a/test/tests/markers/reporter_point_marker/point_marker_test.i b/test/tests/markers/reporter_point_marker/point_marker_test.i new file mode 100644 index 000000000000..ca2269e1f119 --- /dev/null +++ b/test/tests/markers/reporter_point_marker/point_marker_test.i @@ -0,0 +1,62 @@ +[Mesh] + type = GeneratedMesh + dim = 2 + nx = 10 + ny = 10 + nz = 0 + zmax = 0 + elem_type = QUAD4 +[] + +[Problem] + solve = false +[] + +[Executioner] + type = Steady +[] + +[Reporters] + [coords] + type=ConstantReporter + real_vector_names = 'x y z' + real_vector_values = '.31 .41 .51 .31 .41 .51 .31 .41 .51 .8; + .31 .31 .31 .41 .41 .41 .51 .51 .51 .8; + 0 0 0 0 0 0 0 0 0 1;' + outputs=none + [] + [bad_coords] + type=ConstantReporter + real_vector_names = 'x y z' + real_vector_values = '.31 .41 .51; + .31 .31 .31 .41 .41 .41 .51 .51; + 0 0 0 0 0 0 0 0 0 1;' + outputs=none + [] +[] + +[Adaptivity] + [Markers] + inactive = 'bad_coord' + [box] + type = ReporterPointMarker + x_coord_name = coords/x + y_coord_name = coords/y + z_coord_name = coords/z + inside = refine + empty = do_nothing + [] + [bad_coord] + type = ReporterPointMarker + x_coord_name = bad_coords/x + y_coord_name = bad_coords/y + z_coord_name = bad_coords/z + inside = refine + empty = do_nothing + [] + [] +[] + +[Outputs] + exodus=true +[] diff --git a/test/tests/markers/reporter_point_marker/tests b/test/tests/markers/reporter_point_marker/tests new file mode 100644 index 000000000000..64c52c7b6408 --- /dev/null +++ b/test/tests/markers/reporter_point_marker/tests @@ -0,0 +1,20 @@ +[Tests] + group = 'Reporter Point Marker' + design = "/Markers/index.md /ReporterPointMarker.md" + issues = '#18886' + [mark_only] + type = 'Exodiff' + input = 'point_marker_test.i' + exodiff = 'point_marker_test_out.e' + scale_refine = 2 + requirement = "The adaptivity system shall create an auxiliary field variable that marks " + "elements containing the points from the reporter for refinement." + [] + [wrong_size_error] + type = 'RunException' + input = 'point_marker_test.i' + cli_args = 'Adaptivity/Markers/inactive=box' + expect_err = "The coordinate vectors are a different size." + requirement = "The point marker shall report an error if the input arrays are not the same size" + [] +[]