Skip to content

Commit bfa0ef9

Browse files
authored
Merge pull request #31232 from aprilnovak/clearer-err
Add better name collision checks.
2 parents 5ee6976 + 87dca2f commit bfa0ef9

5 files changed

Lines changed: 64 additions & 114 deletions

File tree

framework/src/problems/FEProblemBase.C

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,9 +4239,9 @@ FEProblemBase::addPostprocessor(const std::string & pp_name,
42394239
{
42404240
// Check for name collision
42414241
if (hasUserObject(name))
4242-
mooseError("A UserObject with the name \"",
4243-
name,
4244-
"\" already exists. You may not add a Postprocessor by the same name.");
4242+
mooseError("A ",
4243+
getUserObjectBase(name).typeAndName(),
4244+
" already exists. You may not add a Postprocessor by the same name.");
42454245

42464246
addUserObject(pp_name, name, parameters);
42474247
}
@@ -4253,9 +4253,9 @@ FEProblemBase::addVectorPostprocessor(const std::string & pp_name,
42534253
{
42544254
// Check for name collision
42554255
if (hasUserObject(name))
4256-
mooseError("A UserObject with the name \"",
4257-
name,
4258-
"\" already exists. You may not add a VectorPostprocessor by the same name.");
4256+
mooseError("A ",
4257+
getUserObjectBase(name).typeAndName(),
4258+
" already exists. You may not add a VectorPostprocessor by the same name.");
42594259

42604260
addUserObject(pp_name, name, parameters);
42614261
}
@@ -4267,8 +4267,9 @@ FEProblemBase::addReporter(const std::string & type,
42674267
{
42684268
// Check for name collision
42694269
if (hasUserObject(name))
4270-
mooseError(std::string("A UserObject with the name \"") + name +
4271-
"\" already exists. You may not add a Reporter by the same name.");
4270+
mooseError("A ",
4271+
getUserObjectBase(name).typeAndName(),
4272+
" already exists. You may not add a Reporter by the same name.");
42724273

42734274
addUserObject(type, name, parameters);
42744275
}

test/tests/misc/check_error/tests

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@
712712
[uo_pps_name_collision_test]
713713
type = 'RunException'
714714
input = 'uo_pps_name_collision_test.i'
715-
expect_err = 'A UserObject with the name "\w+" already exists'
715+
expect_err = 'A MTUserObject "\w+" already exists'
716716

717717
requirement = 'The system shall report an error when a UserObject and a Postprocessor are added with the same names.'
718718
issues = '#1405'
@@ -721,12 +721,21 @@
721721
[uo_vector_pps_name_collision_test]
722722
type = 'RunException'
723723
input = 'uo_vector_pps_name_collision_test.i'
724-
expect_err = 'A UserObject with the name "\w+" already exists'
724+
expect_err = 'A MTUserObject "\w+" already exists'
725725

726726
requirement = 'The system shall report and error when a UserObject and a VectorPostprocessor are added with the same names.'
727727
issues = '#1405'
728728
[]
729729

730+
[uo_reporter_name_collision_test]
731+
type = 'RunException'
732+
input = 'uo_reporter_name_collision_test.i'
733+
expect_err = 'A MTUserObject "\w+" already exists'
734+
735+
requirement = 'The system shall report an error when a UserObject and a Reporter are added with the same names.'
736+
issues = '#31231'
737+
[]
738+
730739
[wrong_object_test]
731740
type = 'RunException'
732741
input = 'wrong_moose_object_test.i'
Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,30 @@
11
[Mesh]
22
type = GeneratedMesh
3-
dim = 2
3+
dim = 1
44
xmin = 0
55
xmax = 1
6-
ymin = 0
7-
ymax = 1
86
nx = 5
9-
ny = 5
10-
elem_type = QUAD4
7+
[]
8+
9+
[Problem]
10+
type = FEProblem
11+
solve = false
1112
[]
1213

1314
[UserObjects]
14-
[./ud]
15+
[ud]
1516
type = MTUserObject
1617
scalar = 2
1718
vector = '9 7 5'
18-
[../]
19-
[]
20-
21-
[Functions]
22-
[./forcing_fn]
23-
type = ParsedFunction
24-
expression = -2
25-
[../]
26-
27-
[./exact_fn]
28-
type = ParsedFunction
29-
expression = x*x
30-
[../]
31-
[]
32-
33-
[Variables]
34-
[./u]
35-
family = LAGRANGE
36-
order = FIRST
37-
[../]
38-
[]
39-
40-
[Kernels]
41-
[./diff]
42-
type = Diffusion
43-
variable = u
44-
[../]
45-
[./ffn]
46-
type = UserObjectKernel
47-
variable = u
48-
user_object = ud
4919
[]
5020
[]
5121

52-
[BCs]
53-
[./all]
54-
type = FunctionDirichletBC
55-
variable = u
56-
function = exact_fn
57-
boundary = '0 1 2 3'
58-
[../]
59-
[]
60-
6122
[Executioner]
6223
type = Steady
63-
solve_type = 'PJFNK'
6424
[]
6525

6626
[Postprocessors]
67-
[./ud]
27+
[ud]
6828
type = NumDOFs
6929
[]
7030
[]
71-
72-
[Outputs]
73-
execute_on = 'timestep_end'
74-
file_base = out
75-
[]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[Mesh]
2+
type = GeneratedMesh
3+
dim = 1
4+
xmin = 0
5+
xmax = 1
6+
nx = 5
7+
[]
8+
9+
[Problem]
10+
type = FEProblem
11+
solve = false
12+
[]
13+
14+
[UserObjects]
15+
[ud]
16+
type = MTUserObject
17+
scalar = 2
18+
vector = '9 7 5'
19+
[]
20+
[]
21+
22+
[Executioner]
23+
type = Steady
24+
[]
25+
26+
[Reporters]
27+
[ud]
28+
type = ConstantReporter
29+
[]
30+
[]
Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,31 @@
11
[Mesh]
22
type = GeneratedMesh
3-
dim = 2
3+
dim = 1
44
xmin = 0
55
xmax = 1
6-
ymin = 0
7-
ymax = 1
86
nx = 5
9-
ny = 5
10-
elem_type = QUAD4
117
[]
128

139
[UserObjects]
14-
[./ud]
10+
[ud]
1511
type = MTUserObject
1612
scalar = 2
1713
vector = '9 7 5'
18-
[../]
19-
[]
20-
21-
[Functions]
22-
[./forcing_fn]
23-
type = ParsedFunction
24-
expression = -2
25-
[../]
26-
27-
[./exact_fn]
28-
type = ParsedFunction
29-
expression = x*x
30-
[../]
31-
[]
32-
33-
[Variables]
34-
[./u]
35-
family = LAGRANGE
36-
order = FIRST
37-
[../]
38-
[]
39-
40-
[Kernels]
41-
[./diff]
42-
type = Diffusion
43-
variable = u
44-
[../]
45-
[./ffn]
46-
type = UserObjectKernel
47-
variable = u
48-
user_object = ud
4914
[]
5015
[]
5116

52-
[BCs]
53-
[./all]
54-
type = FunctionDirichletBC
55-
variable = u
56-
function = exact_fn
57-
boundary = '0 1 2 3'
58-
[../]
17+
[Problem]
18+
type = FEProblem
19+
solve = false
5920
[]
6021

6122
[Executioner]
6223
type = Steady
63-
solve_type = 'PJFNK'
6424
[]
6525

6626
[VectorPostprocessors]
67-
[./ud]
27+
[ud]
6828
type = ConstantVectorPostprocessor
6929
value = 1
7030
[]
7131
[]
72-
73-
[Outputs]
74-
execute_on = 'timestep_end'
75-
file_base = out
76-
[]

0 commit comments

Comments
 (0)