Skip to content

Commit b72dbb0

Browse files
committed
Current methods and tests in activating inactive blocks
Refs #31903
1 parent 7edd10c commit b72dbb0

File tree

10 files changed

+1467
-0
lines changed

10 files changed

+1467
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "NodalUserObject.h"
13+
14+
namespace libMesh
15+
{
16+
class Elem;
17+
class QBase;
18+
}
19+
20+
class UndisplacedMeshUpdater : public NodalUserObject
21+
{
22+
public:
23+
static InputParameters validParams();
24+
25+
UndisplacedMeshUpdater(const InputParameters & parameters);
26+
27+
virtual void initialize() override {}
28+
virtual void execute() override;
29+
virtual void finalize() override;
30+
virtual void threadJoin(const UserObject &) override {}
31+
32+
protected:
33+
const unsigned int _n_vars;
34+
const std::vector<const VariableValue *> _input_variables;
35+
std::vector<MooseWritableVariable *> _output_variables;
36+
/// Compute the value used in the criterion
37+
virtual Real computeValue();
38+
39+
/// Threshold to modify the element subdomain ID
40+
const Real _threshold;
41+
42+
/// Criterion type
43+
const enum class CriterionType { Below, Equal, Above } _criterion_type;
44+
const VariableValue & _criterion_variable;
45+
};
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#include "UndisplacedMeshUpdater.h"
11+
#include "libmesh/quadrature.h"
12+
13+
registerMooseObject("MooseApp", UndisplacedMeshUpdater);
14+
15+
InputParameters
16+
UndisplacedMeshUpdater::validParams()
17+
{
18+
InputParameters params = NodalUserObject::validParams();
19+
params.addClassDescription("Update nodal values for nodal variables on undisplaced mesh.");
20+
params.addRequiredCoupledVar(
21+
"variables", "Coupled variables that will be modified by the MeshModifier object.");
22+
params.addRequiredParam<Real>("threshold",
23+
"The value above (or below) which to change the element subdomain");
24+
params.addParam<MooseEnum>("criterion_type",
25+
MooseEnum("BELOW EQUAL ABOVE", "ABOVE"),
26+
"Criterion to use for the threshold");
27+
params.addRequiredCoupledVar(
28+
"criterion_variable",
29+
"Coupled variable whose value is used in the criterion of activating the MeshModifier.");
30+
params.registerBase("MeshModifier");
31+
return params;
32+
}
33+
34+
UndisplacedMeshUpdater::UndisplacedMeshUpdater(const InputParameters & parameters)
35+
: NodalUserObject(parameters),
36+
_n_vars(coupledComponents("variables")),
37+
_input_variables(coupledValues("variables")),
38+
_threshold(getParam<Real>("threshold")),
39+
_criterion_type(getParam<MooseEnum>("criterion_type").getEnum<CriterionType>()),
40+
_criterion_variable(coupledValue("criterion_variable"))
41+
{
42+
for (unsigned int i = 0; i < _n_vars; i++)
43+
_output_variables.push_back(&writableVariable("variables", i));
44+
}
45+
46+
void
47+
UndisplacedMeshUpdater::execute()
48+
{
49+
Real criterion = computeValue();
50+
switch (_criterion_type)
51+
{
52+
case CriterionType::Equal:
53+
if (!MooseUtils::absoluteFuzzyEqual(criterion - _threshold, 0))
54+
return;
55+
break;
56+
57+
case CriterionType::Below:
58+
if (criterion >= _threshold)
59+
return;
60+
break;
61+
62+
case CriterionType::Above:
63+
if (criterion <= _threshold)
64+
return;
65+
break;
66+
}
67+
68+
const auto node_id = _current_node->id();
69+
auto & node = _mesh.nodeRef(node_id);
70+
if (node_id == 93)
71+
std::cout << "Modify" << std::endl;
72+
for (unsigned int i = 0; i < _n_vars; i++)
73+
{
74+
if (node_id == 93)
75+
std::cout << "Before(" << i << ") : " << node(i) << " " << (*_input_variables[i])[0]
76+
<< std::endl;
77+
auto current_value = (*_input_variables[i])[0];
78+
node(i) += current_value;
79+
_output_variables[i]->setNodalValue(0.0);
80+
if (node_id == 93)
81+
std::cout << "After(" << i << ") : " << node(i) << " " << (*_input_variables[i])[0]
82+
<< std::endl;
83+
}
84+
}
85+
86+
void
87+
UndisplacedMeshUpdater::finalize()
88+
{
89+
// Reinit mesh, but notequation systems
90+
_fe_problem.meshChanged(
91+
/*intermediate_change=*/true, /*contract_mesh=*/false, /*clean_refinement_flags=*/false);
92+
}
93+
94+
Real
95+
UndisplacedMeshUpdater::computeValue()
96+
{
97+
return _criterion_variable[0];
98+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
[GlobalParams]
2+
order = SECOND
3+
family = LAGRANGE
4+
displacements = 'disp_x disp_y'
5+
large_kinematics = true
6+
use_displaced_mesh = true
7+
[]
8+
9+
[Problem]
10+
type = ReferenceResidualProblem
11+
reference_vector = 'ref'
12+
extra_tag_vectors = 'ref'
13+
material_coverage_check = false
14+
kernel_coverage_check = false
15+
[]
16+
17+
[Mesh]
18+
use_displaced_mesh = true
19+
displacements = 'disp_x disp_y'
20+
[block_B]
21+
type = GeneratedMeshGenerator
22+
dim = 2
23+
xmin = 0
24+
xmax = 1
25+
ymin = 0
26+
ymax = 1
27+
nx = 5
28+
ny = 5
29+
elem_type = QUAD8
30+
boundary_id_offset = 4
31+
subdomain_ids = 2
32+
subdomain_name = B
33+
boundary_name_prefix = b
34+
[]
35+
[]
36+
37+
[Materials]
38+
[elasticity_tensor_B]
39+
type = ComputeElasticityTensor
40+
block = B
41+
fill_method = symmetric_isotropic
42+
C_ijkl = '1 0'
43+
#youngs_modulus = 1 #2.0e11
44+
#poissons_ratio = 0 #0.345
45+
[]
46+
[stress_B]
47+
type = ComputeFiniteStrainElasticStress
48+
block = B
49+
[]
50+
[stress_wrapped_B]
51+
type = ComputeLagrangianWrappedStress
52+
block = B
53+
objective_rate = jaumann
54+
[]
55+
[]
56+
57+
[MeshModifiers]
58+
[nodal_values]
59+
type = UndisplacedMeshUpdater
60+
block = B
61+
execute_on = 'TIMESTEP_END'
62+
variables = 'disp_x disp_y'
63+
threshold = 0.5
64+
criterion_type = 'Above'
65+
criterion_variable = phi
66+
use_displaced_mesh = false
67+
execution_order_group = -1
68+
[]
69+
[]
70+
71+
[Physics]
72+
[SolidMechanics]
73+
[QuasiStatic]
74+
[block_B]
75+
block = B
76+
strain = SMALL
77+
formulation = TOTAL
78+
new_system = true
79+
generate_output = 'stress_xx
80+
stress_yy
81+
stress_xy
82+
stress_zz
83+
strain_xx
84+
strain_yy
85+
strain_xy
86+
strain_zz'
87+
[]
88+
[]
89+
[]
90+
[]
91+
92+
[Variables]
93+
[disp_x]
94+
[]
95+
[disp_y]
96+
[]
97+
[]
98+
99+
[Functions]
100+
[pressure_func]
101+
type = ParsedFunction
102+
expression = 'if (t < 3, .3, 0)'
103+
[]
104+
[]
105+
106+
[AuxVariables]
107+
[phi]
108+
[]
109+
[]
110+
111+
[Kernels]
112+
[diff_x]
113+
type = Diffusion
114+
variable = disp_x
115+
[]
116+
[diff_y]
117+
type = Diffusion
118+
variable = disp_y
119+
[]
120+
[]
121+
122+
[AuxKernels]
123+
[switch_block]
124+
type = ParsedAux
125+
expression = "if(t=3, 1, 0)"
126+
use_xyzt = true
127+
variable = phi
128+
use_displaced_mesh = false
129+
execute_on = 'TIMESTEP_BEGIN'
130+
[]
131+
[]
132+
133+
[BCs]
134+
[no_x]
135+
type = DirichletBC
136+
boundary = 7
137+
value = 0
138+
variable = disp_x
139+
[]
140+
[no_y]
141+
type = DirichletBC
142+
boundary = 4
143+
value = 0
144+
variable = disp_y
145+
[]
146+
[Pressure]
147+
[outer_pressure]
148+
boundary = 5
149+
function = pressure_func
150+
factor = 1
151+
[]
152+
[]
153+
[]
154+
155+
[Preconditioning]
156+
[SMP]
157+
type = SMP
158+
full = true
159+
[]
160+
[]
161+
162+
[Executioner]
163+
type = Transient
164+
solve_type = 'PJFNK'
165+
166+
petsc_options = '-snes_converged_reason -ksp_converged_reason -snes_ksp_ew'
167+
petsc_options_iname = '-pc_type -pc_factor_mat_solver_package -snes_type'
168+
petsc_options_value = 'lu superlu_dist vinewtonrsls'
169+
automatic_scaling = true
170+
compute_scaling_once = false
171+
line_search = 'none'
172+
173+
start_time = 0
174+
dt = 1
175+
end_time = 3 #20
176+
verbose = true
177+
178+
l_max_its = 100
179+
l_tol = 8e-3
180+
nl_max_its = 40
181+
nl_rel_tol = 1e-4
182+
nl_abs_tol = 1e-10
183+
[]
184+
185+
[Outputs]
186+
exodus = true
187+
[]

0 commit comments

Comments
 (0)