From 973a13bdbb6413aa3f149021f1ece1c7ab3836a4 Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Sun, 22 Sep 2024 08:28:42 -0600 Subject: [PATCH 1/2] Add support for block restriction of indicators, closes #14531 --- .../doc/content/source/kernels/ADMatBodyForce.md | 2 +- framework/include/loops/UpdateErrorVectorsThread.h | 2 ++ framework/src/loops/UpdateErrorVectorsThread.C | 14 +++++++++++--- framework/src/markers/IndicatorMarker.C | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/framework/doc/content/source/kernels/ADMatBodyForce.md b/framework/doc/content/source/kernels/ADMatBodyForce.md index 0f62e4b0dcec..7811c93f771c 100644 --- a/framework/doc/content/source/kernels/ADMatBodyForce.md +++ b/framework/doc/content/source/kernels/ADMatBodyForce.md @@ -1,4 +1,4 @@ -# BodyForce +# ADMatBodyForce ## Description diff --git a/framework/include/loops/UpdateErrorVectorsThread.h b/framework/include/loops/UpdateErrorVectorsThread.h index 605c107b0bb5..8ddafbe52696 100644 --- a/framework/include/loops/UpdateErrorVectorsThread.h +++ b/framework/include/loops/UpdateErrorVectorsThread.h @@ -31,11 +31,13 @@ class UpdateErrorVectorsThread : public ThreadedElementLoop void join(const UpdateErrorVectorsThread & /*y*/); protected: + /// Map from indicators to error vectors (markers solution vector) const std::map> & _indicator_field_to_error_vector; AuxiliarySystem & _aux_sys; unsigned int _system_number; Adaptivity & _adaptivity; NumericVector & _solution; + /// Map from indicator variable number to error vectors (markers solution vector) std::map _indicator_field_number_to_error_vector; }; diff --git a/framework/src/loops/UpdateErrorVectorsThread.C b/framework/src/loops/UpdateErrorVectorsThread.C index 4f1ef02bdbf1..928137d66bb1 100644 --- a/framework/src/loops/UpdateErrorVectorsThread.C +++ b/framework/src/loops/UpdateErrorVectorsThread.C @@ -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; } } diff --git a/framework/src/markers/IndicatorMarker.C b/framework/src/markers/IndicatorMarker.C index 00c592a85984..c4a1b5b6f19e 100644 --- a/framework/src/markers/IndicatorMarker.C +++ b/framework/src/markers/IndicatorMarker.C @@ -21,4 +21,8 @@ IndicatorMarker::validParams() IndicatorMarker::IndicatorMarker(const InputParameters & parameters) : Marker(parameters), _error_vector(getErrorVector(parameters.get("indicator"))) { + if (!_subproblem.getVariable(0, getParam("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"); } From a8982c896e21b3d250fbd059aa91740c2b352231 Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Sun, 22 Sep 2024 08:29:06 -0600 Subject: [PATCH 2/2] Add test for block restriciton of indicators --- .../block_restriction/gold/test_out.e-s002 | Bin 0 -> 21004 bytes .../tests/adaptivity/block_restriction/test.i | 87 ++++++++++++++++++ test/tests/adaptivity/block_restriction/tests | 17 ++++ 3 files changed, 104 insertions(+) create mode 100644 test/tests/adaptivity/block_restriction/gold/test_out.e-s002 create mode 100644 test/tests/adaptivity/block_restriction/test.i create mode 100644 test/tests/adaptivity/block_restriction/tests diff --git a/test/tests/adaptivity/block_restriction/gold/test_out.e-s002 b/test/tests/adaptivity/block_restriction/gold/test_out.e-s002 new file mode 100644 index 0000000000000000000000000000000000000000..7699c63018b2ba8bd7fc7d802ade8174a2a27aeb GIT binary patch literal 21004 zcmeI333QZImdC@Ig#cj(WeJe5$`XkP3RGee5)ovF$QCL|B`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+%WGwem_f-eOUi$X{CGMdk^k<{ui=eZ!ZsAla(`GzVz{lVXglTM#}ts)5poY(}fu_ zZ_uZ0)UI;s3*Wxe?(@%dEbH8{^`pw%?`}Ld?u*W{A76YIsrt%kcQ%@It~^HUwr|~4 zSrA*$a%Af>s+aot`XYZfNwe13VU4Uaa%>~nkLEr3Tg=jPKQ8u)6}xRyn}}VLjUyZ> z^WNHY{7`qt2>ncfqb&xBet4I1 zM~5a444e1jOzCqy1&)#1+(Tb`{j6i??Cp2=ZTdTr&;2AF&Y&d;CQ?nsK5ld<%ve8;#R_eFmG+Pk7(^UFffpXjjFk+CYTQ~N_vqCZpO5c&Rp zUM+Sjhpd$RjwD1&ej^`RF8V{2iB|q?2Uz-h(?ma_Pgluna(JBdn^T>V-;s3Z+@*8xdRP>LRjTL?QcNvoZ{!tFmC$w})UXwna zXyy4%j^y{j6CX-`iL*wFe3*B$^q#H%Df&O8%@O^WN%7)${p^qZd9<|h>vBr+d&5;B z`YlbZJfH6Wjp)DJvDq=Hx%cU_!+w>d_2qw3b!_(f|NjamSN-?xO}{!;e>x7@~ literal 0 HcmV?d00001 diff --git a/test/tests/adaptivity/block_restriction/test.i b/test/tests/adaptivity/block_restriction/test.i new file mode 100644 index 000000000000..d631179614ef --- /dev/null +++ b/test/tests/adaptivity/block_restriction/test.i @@ -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 +[] diff --git a/test/tests/adaptivity/block_restriction/tests b/test/tests/adaptivity/block_restriction/tests new file mode 100644 index 000000000000..67b6c9dc27c1 --- /dev/null +++ b/test/tests/adaptivity/block_restriction/tests @@ -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.' + [] +[]