Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMR for ElementSubdomainModifier #20716

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conda/libmesh/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Do not use jinja templating (A physical change to this file is required to trigger a build)
{% set build = 2 %}
{% set build = 0 %}
{% set strbuild = "build_" + build|string %}
{% set version = "2022.03.28" %}
{% set version = "2022.04.05" %}

package:
name: moose-libmesh
Expand Down
2 changes: 1 addition & 1 deletion conda/mpich/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Any changes made will require additional changes to any item above that.

moose_libmesh:
- moose-libmesh 2022.03.28 build_2
- moose-libmesh 2022.04.05 build_0

SHORT_VTK_NAME:
- 9.1
Expand Down
25 changes: 25 additions & 0 deletions framework/doc/content/source/markers/BoundaryPreservedMarker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# BoundaryPreservedMarker

## Description

This is the same as [ErrorFractionMarker](ErrorFractionMarker.md), which
marks elements for refinement or coarsening based on the fraction of the min/max error
from the supplied indicator while preserving the given boundary.

The motivation is to preserve the boundary geometry during the mesh coarsening.
Any elements that connect with the boundary will be maintained during coarsening.
These elements might be coarsened later if the boundary moves to a different location.

## Example Input File Syntax

!listing test/tests/userobjects/element_subdomain_modifier/adaptivity_moving_boundary.i
block=Adaptivity
link=False

!! Describe and include an example of how to use the BoundaryPreservedMarker object.

!syntax parameters /Adaptivity/Markers/BoundaryPreservedMarker

!syntax inputs /Adaptivity/Markers/BoundaryPreservedMarker

!syntax children /Adaptivity/Markers/BoundaryPreservedMarker
34 changes: 34 additions & 0 deletions framework/include/markers/BoundaryPreservedMarker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//* 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 "ErrorFractionMarker.h"

/*
Do not coarsen any element touching a given boundary in order to preserve the boundary
libMesh will delete all boundaries for the elements to be coarsened.
*/
class BoundaryPreservedMarker : public ErrorFractionMarker
{
public:
static InputParameters validParams();
BoundaryPreservedMarker(const InputParameters & parameters);

protected:
virtual MarkerValue computeElementMarker() override;

// Check whether or not to coarsen the current element
// It is fine to coarsen the current element if it does not touch the given boundary
// Otherwise return false
bool preserveBoundary(const Elem * const & _current_elem);

// Boundary to be preserved during coarsening (AMR)
BoundaryID _preserved_boundary;
};
6 changes: 6 additions & 0 deletions framework/include/userobject/ElementSubdomainModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class ElementSubdomainModifier : public ElementUserObject
// Set old and older solutions to be the same as the current solution
void setOldAndOlderSolutionsForMovedNodes(SystemBase & sys);

// Change the subdomain ID of all ancestor elements
void setAncestorsSubdomainIDs(const SubdomainID & subdomain_id, const dof_id_type & elem_id);

// Elements on the undisplaced mesh whose subdomain IDs have changed
std::vector<const Elem *> _moved_elems;

Expand All @@ -113,4 +116,7 @@ class ElementSubdomainModifier : public ElementUserObject

/// The Id of the moving boundary
BoundaryID _moving_boundary_id;

/// Subdomains between that the moving boundary is
std::set<SubdomainID> _moving_boundary_subdomains;
};
68 changes: 68 additions & 0 deletions framework/src/markers/BoundaryPreservedMarker.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//* 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 "BoundaryPreservedMarker.h"
#include "MooseMeshUtils.h"

#include "libmesh/error_vector.h"

registerMooseObject("MooseApp", BoundaryPreservedMarker);

InputParameters
BoundaryPreservedMarker::validParams()
{
InputParameters params = ErrorFractionMarker::validParams();
params.addRequiredParam<BoundaryName>(
"preserved_boundary",
"The name of the boundary to be preserved. Will try to preserve the boundary during AMR");
params.addClassDescription(
"Marks elements for refinement or coarsening based on the fraction of "
"the min/max error from the supplied indicator, while preserving the given boundary.");
return params;
}

BoundaryPreservedMarker::BoundaryPreservedMarker(const InputParameters & parameters)
: ErrorFractionMarker(parameters)
{
BoundaryName boundary_name = getParam<BoundaryName>("preserved_boundary");
auto boundary_ids = MooseMeshUtils::getBoundaryIDs(_mesh, {boundary_name}, true);
mooseAssert(boundary_ids.size() == 1, "Boundary does not exist");
_preserved_boundary = boundary_ids[0];
}

bool
BoundaryPreservedMarker::preserveBoundary(const Elem * const & _current_elem)
{
auto & elem_side_bnd_ids = _mesh.getMesh().get_boundary_info().get_sideset_map();

// Do not coarsen the elements when they are connected to the preserved boundary
for (const auto & pr : as_range(elem_side_bnd_ids.equal_range(_current_elem)))
if (pr.second.second == _preserved_boundary)
return true;

return false;
}

Marker::MarkerValue
BoundaryPreservedMarker::computeElementMarker()
{
Real error = _error_vector[_current_elem->id()];

if (error > _refine_cutoff)
return REFINE;
else if (error < _coarsen_cutoff)
{
if (preserveBoundary(_current_elem))
return DO_NOTHING;
else
return COARSEN;
}

return DO_NOTHING;
}
Loading