Skip to content

Commit

Permalink
reporter point marker to mark mesh for refinement around points given…
Browse files Browse the repository at this point in the history
… by a reporter. closes idaholab#18886

included Logan and Daniels suggestions
  • Loading branch information
lynnmunday committed Sep 25, 2021
1 parent da6ac53 commit 0665c09
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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
42 changes: 42 additions & 0 deletions 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<Real> & _x_coord;
/// y coordinate
const std::vector<Real> & _y_coord;
///z coordinate
const std::vector<Real> & _z_coord;
/// Pointer to PointLocatorBase object
std::unique_ptr<PointLocatorBase> _pl;
/// list of sort uniqued elements containing points
std::set<dof_id_type> _point_elems;
};
70 changes: 70 additions & 0 deletions 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<ReporterName>("x_coord_name", "reporter x-coordinate name");
params.addRequiredParam<ReporterName>("y_coord_name", "reporter y-coordinate name");
params.addRequiredParam<ReporterName>("z_coord_name", "reporter z-coordinate name");
MooseEnum marker_states = Marker::markerStates();
params.addRequiredParam<MooseEnum>(
"inside", marker_states, "How to mark elements containing a point");
params.addRequiredParam<MooseEnum>(
"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<MooseEnum>("inside").getEnum<MarkerValue>()),
_empty(parameters.get<MooseEnum>("empty").getEnum<MarkerValue>()),
_x_coord(getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)),
_y_coord(getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)),
_z_coord(getReporterValue<std::vector<Real>>("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);
}
Binary file modified test/tests/markers/box_marker/gold/box_marker_test_out.e
Binary file not shown.
62 changes: 62 additions & 0 deletions 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
[]
20 changes: 20 additions & 0 deletions 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"
[]
[]

0 comments on commit 0665c09

Please sign in to comment.