Skip to content

Commit

Permalink
Close solution and update system (idaholab#22563)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 22, 2023
1 parent b9f7a70 commit 17fc40e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions framework/include/interfaces/Coupleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class Coupleable
/**
* Checks whether the object has any writable coupled variables
*/
bool hasWritableCoupledVariables() { return !_writable_coupled_variables[_c_tid].empty(); }
bool hasWritableCoupledVariables() const { return !_writable_coupled_variables[_c_tid].empty(); }

/**
* returns a reference to the set of writable coupled variables
*/
auto & getWritableCoupledVariables() { return _writable_coupled_variables[_c_tid]; }
auto & getWritableCoupledVariables() const { return _writable_coupled_variables[_c_tid]; }

protected:
/**
Expand Down
9 changes: 9 additions & 0 deletions framework/src/interfaces/Coupleable.C
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ Coupleable::writableVariable(const std::string & var_name, unsigned int comp)
"'.");
// if (nuo && !var->isNodal()) is handled by checkVar already

// check block restrictions for compatibility
const auto * br = dynamic_cast<const BlockRestrictable *>(this);
if (!var->hasBlocks(br->blockIDs()))
mooseError("The variable '",
var->name(),
"' must be defined on all blocks '",
_obj->name(),
"' is defined on");

// make sure only one object can access a variable
checkWritableVar(var);

Expand Down
1 change: 1 addition & 0 deletions framework/src/loops/ComputeNodalUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FEProblem.h"
#include "MooseMesh.h"
#include "NodalUserObject.h"
#include "AuxiliarySystem.h"

#include "libmesh/threads.h"

Expand Down
4 changes: 1 addition & 3 deletions framework/src/loops/ComputeUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "FEProblem.h"
#include "MaterialBase.h"
#include "DomainUserObject.h"
#include "AuxiliarySystem.h"

#include "libmesh/numeric_vector.h"

Expand Down Expand Up @@ -129,9 +130,6 @@ ComputeUserObjectsThread::onElement(const Elem * elem)

for (const auto & uo : _element_objs)
{
// for (auto * var : uo->getWritableCoupledVariables())
// var->prepareAux();

uo->execute();

// update the aux solution vector if writable coupled variables are used
Expand Down
20 changes: 20 additions & 0 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -4198,6 +4198,16 @@ FEProblemBase::computeUserObjectsInternal(const ExecFlagType & type,
joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::DomainUserObject));
}

// if any userobject may have written to variables we need to close the aux solution
for (const auto & uo : userobjs)
if (auto euo = dynamic_cast<const ElementUserObject *>(uo);
euo && euo->hasWritableCoupledVariables())
{
_aux->solution().close();
_aux->system().update();
break;
}

// Execute NodalUserObjects
// BISON has an axial reloc elemental user object that has a finalize func that depends on a
// nodal user object's prev value. So we can't initialize this until after elemental objects
Expand All @@ -4211,6 +4221,16 @@ FEProblemBase::computeUserObjectsInternal(const ExecFlagType & type,
joinAndFinalize(query.clone().condition<AttribInterfaces>(Interfaces::NodalUserObject));
}

// if any userobject may have written to variables we need to close the aux solution
for (const auto & uo : nodal)
if (auto nuo = dynamic_cast<const NodalUserObject *>(uo);
nuo && nuo->hasWritableCoupledVariables())
{
_aux->solution().close();
_aux->system().update();
break;
}

// Execute threaded general user objects
for (auto obj : tgobjs)
obj->initialize();
Expand Down

0 comments on commit 17fc40e

Please sign in to comment.