Skip to content

Commit

Permalink
Merge pull request #28681 from GiudGiud/PR_block_adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud authored Sep 28, 2024
2 parents bfd4591 + a8982c8 commit 22c0a2d
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 4 deletions.
2 changes: 1 addition & 1 deletion framework/doc/content/source/kernels/ADMatBodyForce.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BodyForce
# ADMatBodyForce

## Description

Expand Down
2 changes: 2 additions & 0 deletions framework/include/loops/UpdateErrorVectorsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class UpdateErrorVectorsThread : public ThreadedElementLoop<ConstElemRange>
void join(const UpdateErrorVectorsThread & /*y*/);

protected:
/// Map from indicators to error vectors (markers solution vector)
const std::map<std::string, std::unique_ptr<ErrorVector>> & _indicator_field_to_error_vector;
AuxiliarySystem & _aux_sys;
unsigned int _system_number;
Adaptivity & _adaptivity;
NumericVector<Number> & _solution;

/// Map from indicator variable number to error vectors (markers solution vector)
std::map<unsigned int, ErrorVector *> _indicator_field_number_to_error_vector;
};
14 changes: 11 additions & 3 deletions framework/src/loops/UpdateErrorVectorsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ UpdateErrorVectorsThread::onElement(const Elem * elem)
unsigned int var_num = it.first;
ErrorVector & ev = *(it.second);

dof_id_type dof_number = elem->dof_number(_system_number, var_num, 0);
Real value = _solution(dof_number);
ev[elem->id()] = value;
// Must obey the block restriction of the indicator (error vector is global)
// we have to check here because the loop is over all indicators, and other indicators
// might have larger block restrictions.
if (_aux_sys.getVariable(_tid, var_num).hasBlocks(elem->subdomain_id()))
{
dof_id_type dof_number = elem->dof_number(_system_number, var_num, 0);
Real value = _solution(dof_number);
ev[elem->id()] = value;
}
else
ev[elem->id()] = 0;
}
}

Expand Down
4 changes: 4 additions & 0 deletions framework/src/markers/IndicatorMarker.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ IndicatorMarker::validParams()
IndicatorMarker::IndicatorMarker(const InputParameters & parameters)
: Marker(parameters), _error_vector(getErrorVector(parameters.get<IndicatorName>("indicator")))
{
if (!_subproblem.getVariable(0, getParam<IndicatorName>("indicator")).hasBlocks(blockIDs()))
mooseWarning("The block restriction of the marker is larger than the block restriction of its "
"indicator. Blocks on which the indicator is not active will not be marked, and "
"therefore will not be refined or coarsened");
}
Binary file not shown.
87 changes: 87 additions & 0 deletions test/tests/adaptivity/block_restriction/test.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[Mesh]
[box]
type = GeneratedMeshGenerator
dim = 3
nx = 3
ny = 3
nz = 3
xmin = 0
xmax = 1
ymin = 0
ymax = 1
zmin = 0
zmax = 1
[]
[box1]
type = SubdomainBoundingBoxGenerator
input = box
block_id = 1
bottom_left = '0 0.5 0'
top_right = '1 1 1'
[]
[]

[Variables]
[u]
[]
[]

[Kernels]
[diff]
type = Diffusion
variable = u
[]
[source]
type = BodyForce
variable = u
function = '(x-0.5) * (x-0.5) * (x-0.5)'
[]
[]

[BCs]
[archor_x]
type = DirichletBC
boundary = 'bottom'
variable = u
value = 0
[]
[]

[Adaptivity]
marker = errorfrac
max_h_level = 2
[Indicators]
[error]
type = GradientJumpIndicator
variable = u
block = '0'
[]
[]
[Markers]
[errorfrac]
type = ErrorFractionMarker
refine = 0.5
indicator = error
block = '0'
[]
[]
[]

[Executioner]
type = Transient

end_time = 200
dt = 100

solve_type = 'PJFNK'

nl_abs_tol = 1E-5
nl_max_its = 400

l_tol = 1E-8
l_max_its = 200
[]

[Outputs]
exodus = true
[]
17 changes: 17 additions & 0 deletions test/tests/adaptivity/block_restriction/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Tests]
design = 'syntax/Adaptivity/index.md'
issues = '#14531'
[block]
type = Exodiff
input = 'test.i'
exodiff = 'test_out.e-s002'
requirement = 'The system shall be able to use block-restricted indicators for adaptivity.'
[]
[mismatch]
type = RunException
input = test.i
cli_args = 'Adaptivity/Markers/errorfrac/block="0 1"'
expect_err = 'The block restriction of the marker is larger than the block restriction of its indicator.'
requirement = 'The system shall emit a warning if the block restriction of the marker is larger than that of its indicator.'
[]
[]

0 comments on commit 22c0a2d

Please sign in to comment.