Skip to content
Draft
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
45 changes: 45 additions & 0 deletions framework/include/meshmodifiers/UndisplacedMeshUpdater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* 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 "NodalUserObject.h"

namespace libMesh
{
class Elem;
class QBase;
}

class UndisplacedMeshUpdater : public NodalUserObject
{
public:
static InputParameters validParams();

UndisplacedMeshUpdater(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override;
virtual void finalize() override;
virtual void threadJoin(const UserObject &) override {}

protected:
const unsigned int _n_vars;
const std::vector<const VariableValue *> _input_variables;
std::vector<MooseWritableVariable *> _output_variables;
/// Compute the value used in the criterion
virtual Real computeValue();

/// Threshold to modify the element subdomain ID
const Real _threshold;

/// Criterion type
const enum class CriterionType { Below, Equal, Above } _criterion_type;
const VariableValue & _criterion_variable;
};
90 changes: 90 additions & 0 deletions framework/src/meshmodifiers/UndisplacedMeshUpdater.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* 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 "UndisplacedMeshUpdater.h"
#include "libmesh/quadrature.h"

registerMooseObject("MooseApp", UndisplacedMeshUpdater);

InputParameters
UndisplacedMeshUpdater::validParams()
{
InputParameters params = NodalUserObject::validParams();
params.addClassDescription("Update nodal values for nodal variables on undisplaced mesh.");
params.addRequiredCoupledVar(
"variables", "Coupled variables that will be modified by the MeshModifier object.");
params.addRequiredParam<Real>("threshold",
"The value above (or below) which to change the element subdomain");
params.addParam<MooseEnum>("criterion_type",
MooseEnum("BELOW EQUAL ABOVE", "ABOVE"),
"Criterion to use for the threshold");
params.addRequiredCoupledVar(
"criterion_variable",
"Coupled variable whose value is used in the criterion of activating the MeshModifier.");
params.registerBase("MeshModifier");
return params;
}

UndisplacedMeshUpdater::UndisplacedMeshUpdater(const InputParameters & parameters)
: NodalUserObject(parameters),
_n_vars(coupledComponents("variables")),
_input_variables(coupledValues("variables")),
_threshold(getParam<Real>("threshold")),
_criterion_type(getParam<MooseEnum>("criterion_type").getEnum<CriterionType>()),
_criterion_variable(coupledValue("criterion_variable"))
{
for (unsigned int i = 0; i < _n_vars; i++)
_output_variables.push_back(&writableVariable("variables", i));
}

void
UndisplacedMeshUpdater::execute()
{
Real criterion = computeValue();
switch (_criterion_type)
{
case CriterionType::Equal:
if (!MooseUtils::absoluteFuzzyEqual(criterion - _threshold, 0))
return;
break;

case CriterionType::Below:
if (criterion >= _threshold)
return;
break;

case CriterionType::Above:
if (criterion <= _threshold)
return;
break;
}

const auto node_id = _current_node->id();
auto & node = _mesh.nodeRef(node_id);
for (unsigned int i = 0; i < _n_vars; i++)
{
auto current_value = (*_input_variables[i])[0];
node(i) += current_value;
_output_variables[i]->setNodalValue(0.0);
}
}

void
UndisplacedMeshUpdater::finalize()
{
// Reinit mesh, but notequation systems
_fe_problem.meshChanged(
/*intermediate_change=*/true, /*contract_mesh=*/false, /*clean_refinement_flags=*/false);
}

Real
UndisplacedMeshUpdater::computeValue()
{
return _criterion_variable[0];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
[GlobalParams]
order = SECOND
family = LAGRANGE
displacements = 'disp_x disp_y'
large_kinematics = true
use_displaced_mesh = true
[]

[Problem]
type = ReferenceResidualProblem
reference_vector = 'ref'
extra_tag_vectors = 'ref'
material_coverage_check = false
kernel_coverage_check = false
[]

[Mesh]
use_displaced_mesh = true
displacements = 'disp_x disp_y'
[block_B]
type = GeneratedMeshGenerator
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 5
ny = 5
elem_type = QUAD8
boundary_id_offset = 4
subdomain_ids = 2
subdomain_name = B
boundary_name_prefix = b
[]
[]

[Materials]
[elasticity_tensor_B]
type = ComputeElasticityTensor
block = B
fill_method = symmetric_isotropic
C_ijkl = '1 0'
#youngs_modulus = 1 #2.0e11
#poissons_ratio = 0 #0.345
[]
[stress_B]
type = ComputeFiniteStrainElasticStress
block = B
[]
[stress_wrapped_B]
type = ComputeLagrangianWrappedStress
block = B
objective_rate = jaumann
[]
[]

[MeshModifiers]
[nodal_values]
type = UndisplacedMeshUpdater
block = B
execute_on = 'TIMESTEP_END'
variables = 'disp_x disp_y'
threshold = 0.5
criterion_type = 'Above'
criterion_variable = phi
use_displaced_mesh = false
execution_order_group = -1
[]
[]

[Physics]
[SolidMechanics]
[QuasiStatic]
[block_B]
block = B
strain = SMALL
formulation = TOTAL
new_system = true
generate_output = 'stress_xx
stress_yy
stress_xy
stress_zz
strain_xx
strain_yy
strain_xy
strain_zz'
[]
[]
[]
[]

[Variables]
[disp_x]
[]
[disp_y]
[]
[]

[Functions]
[pressure_func]
type = ParsedFunction
expression = 'if (t < 3, .3, 0)'
[]
[]

[AuxVariables]
[phi]
[]
[]

[Kernels]
[diff_x]
type = Diffusion
variable = disp_x
[]
[diff_y]
type = Diffusion
variable = disp_y
[]
[]

[AuxKernels]
[switch_block]
type = ParsedAux
expression = "if(t=3, 1, 0)"
use_xyzt = true
variable = phi
use_displaced_mesh = false
execute_on = 'TIMESTEP_BEGIN'
[]
[]

[BCs]
[no_x]
type = DirichletBC
boundary = 7
value = 0
variable = disp_x
[]
[no_y]
type = DirichletBC
boundary = 4
value = 0
variable = disp_y
[]
[Pressure]
[outer_pressure]
boundary = 5
function = pressure_func
factor = 1
[]
[]
[]

[Preconditioning]
[SMP]
type = SMP
full = true
[]
[]

[Executioner]
type = Transient
solve_type = 'PJFNK'

petsc_options = '-snes_converged_reason -ksp_converged_reason -snes_ksp_ew'
petsc_options_iname = '-pc_type -pc_factor_mat_solver_package -snes_type'
petsc_options_value = 'lu superlu_dist vinewtonrsls'
automatic_scaling = true
compute_scaling_once = false
line_search = 'none'

start_time = 0
dt = 1
end_time = 3 #20
verbose = true

l_max_its = 100
l_tol = 8e-3
nl_max_its = 40
nl_rel_tol = 1e-4
nl_abs_tol = 1e-10
[]

[Outputs]
exodus = true
[]
Loading