Skip to content

Commit

Permalink
Fix and test user object support (idaholab#22563)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 21, 2023
1 parent c980260 commit e6dcd7e
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 0 deletions.
9 changes: 9 additions & 0 deletions framework/src/loops/ComputeNodalUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ ComputeNodalUserObjectsThread::onNode(ConstNodeRange::const_iterator & node_it)
if (!uo->isUniqueNodeExecute() || computed.count(uo) == 0)
{
uo->execute();

// update the aux solution vector if writable coupled variables are used
if (uo->hasWritableCoupledVariables())
{
Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
for (auto * var : uo->getWritableCoupledVariables())
var->insert(_aux_sys.solution());
}

computed.insert(uo);
}
}
Expand Down
31 changes: 31 additions & 0 deletions test/include/userobjects/MultiUpdateElementalUO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* 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 "ElementUserObject.h"

/**
* Test object for the writableVariable API for nodal values
*/
class MultiUpdateElementalUO : public ElementUserObject
{
public:
static InputParameters validParams();

MultiUpdateElementalUO(const InputParameters & parameters);

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

protected:
MooseVariable & _v;
};
31 changes: 31 additions & 0 deletions test/include/userobjects/MultiUpdateNodalUO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* 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"

/**
* Test object for the writableVariable API for nodal values
*/
class MultiUpdateNodalUO : public NodalUserObject
{
public:
static InputParameters validParams();

MultiUpdateNodalUO(const InputParameters & parameters);

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

protected:
MooseVariable & _v;
};
33 changes: 33 additions & 0 deletions test/src/userobjects/MultiUpdateElementalUO.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* 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 "MultiUpdateElementalUO.h"

registerMooseObject("MooseTestApp", MultiUpdateElementalUO);

InputParameters
MultiUpdateElementalUO::validParams()
{
InputParameters params = ElementUserObject::validParams();
params.addClassDescription("Test object for the writableVariable API for elemental values");
params.addRequiredCoupledVar("v", "Coupled variable that will be written to by the test object.");
return params;
}

MultiUpdateElementalUO::MultiUpdateElementalUO(const InputParameters & parameters)
: ElementUserObject(parameters), _v(writableVariable("v"))
{
}

void
MultiUpdateElementalUO::execute()
{
// it really is a DOF value
_v.setNodalValue(1.23);
}
32 changes: 32 additions & 0 deletions test/src/userobjects/MultiUpdateNodalUO.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* 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 "MultiUpdateNodalUO.h"

registerMooseObject("MooseTestApp", MultiUpdateNodalUO);

InputParameters
MultiUpdateNodalUO::validParams()
{
InputParameters params = NodalUserObject::validParams();
params.addClassDescription("Test object for the writableVariable API for nodal values");
params.addRequiredCoupledVar("v", "Coupled variable that will be written to by the test object.");
return params;
}

MultiUpdateNodalUO::MultiUpdateNodalUO(const InputParameters & parameters)
: NodalUserObject(parameters), _v(writableVariable("v"))
{
}

void
MultiUpdateNodalUO::execute()
{
_v.setNodalValue(1.23);
}
8 changes: 8 additions & 0 deletions test/tests/auxkernels/nodal_aux_var/tests
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
"auxiliary variables within a single AuxKernel object."
[]

[multi_update_elem_family_error]
type = 'RunException'
input = 'multi_update_elem_var_test.i'
cli_args = 'AuxVariables/ten/order=FIRST AuxVariables/ten/family=LAGRANGE'
expect_err = "The AuxKernel 'all' and the variable 'ten' must both either be nodal or elemental."
requirement = "The MOOSE auxiliary system shall check compatibility between primary and writable coupled variables."
[]

[ts_test]
type = 'Exodiff'
input = 'nodal_aux_ts_test.i'
Expand Down
35 changes: 35 additions & 0 deletions test/tests/userobjects/writable_variable/elemental.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[Mesh]
[gen]
type = GeneratedMeshGenerator
dim = 2
nx = 1
ny = 1
[]
[]

[AuxVariables]
[v]
family = MONOMIAL
order = CONSTANT
[]
[]

[UserObjects]
[elemental]
type = MultiUpdateElementalUO
v = v
[]
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions test/tests/userobjects/writable_variable/nodal.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[Mesh]
[gen]
type = GeneratedMeshGenerator
dim = 2
nx = 1
ny = 1
[]
[]

[AuxVariables]
[v]
family = LAGRANGE
order = FIRST
[]
[]

[UserObjects]
[elemental]
type = MultiUpdateNodalUO
v = v
[]
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
12 changes: 12 additions & 0 deletions test/tests/userobjects/writable_variable/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Tests]
[nodal]
type = Exodiff
input = nodal.i
exodiff = nodal_out.e
[]
[elemental]
type = Exodiff
input = elemental.i
exodiff = elemental_out.e
[]
[]

0 comments on commit e6dcd7e

Please sign in to comment.