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 e778993 commit 41f6951
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
3 changes: 3 additions & 0 deletions framework/include/loops/ComputeNodalUserObjectsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ class ComputeNodalUserObjectsThread
const TheWarehouse::Query _query;
AuxiliarySystem & _aux_sys;

/// was the auxiliary system modified through writable variables? If so we need to close the solution.
bool _aux_modified;

static Threads::spin_mutex writable_variable_mutex;
};
3 changes: 3 additions & 0 deletions framework/include/loops/ComputeUserObjectsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class ComputeUserObjectsThread : public ThreadedElementLoop<ConstElemRange>
std::vector<DomainUserObject *> _all_domain_objs;

AuxiliarySystem & _aux_sys;

/// was the auxiliary system modified through writable variables? If so we need to close the solution.
bool _aux_modified;
};

// determine when we need to run user objects based on whether any initial conditions or aux
Expand Down
17 changes: 14 additions & 3 deletions framework/src/loops/ComputeNodalUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ComputeNodalUserObjectsThread::ComputeNodalUserObjectsThread(FEProblemBase & fe_
const TheWarehouse::Query & query)
: ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
_query(query),
_aux_sys(fe_problem.getAuxiliarySystem())
_aux_sys(fe_problem.getAuxiliarySystem()),
_aux_modified(false)
{
}

Expand All @@ -31,11 +32,19 @@ ComputeNodalUserObjectsThread::ComputeNodalUserObjectsThread(ComputeNodalUserObj
Threads::split split)
: ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
_query(x._query),
_aux_sys(x._aux_sys)
_aux_sys(x._aux_sys),
_aux_modified(false)
{
}

ComputeNodalUserObjectsThread::~ComputeNodalUserObjectsThread() {}
ComputeNodalUserObjectsThread::~ComputeNodalUserObjectsThread()
{
if (_aux_modified)
{
_aux_sys.solution().close();
_aux_sys.system().update();
}
}

void
ComputeNodalUserObjectsThread::onNode(ConstNodeRange::const_iterator & node_it)
Expand Down Expand Up @@ -65,6 +74,7 @@ ComputeNodalUserObjectsThread::onNode(ConstNodeRange::const_iterator & node_it)
Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
for (auto * var : uo->getWritableCoupledVariables())
var->insert(_aux_sys.solution());
_aux_modified = true;
}
}
}
Expand Down Expand Up @@ -98,6 +108,7 @@ ComputeNodalUserObjectsThread::onNode(ConstNodeRange::const_iterator & node_it)
Threads::spin_mutex::scoped_lock lock(writable_variable_mutex);
for (auto * var : uo->getWritableCoupledVariables())
var->insert(_aux_sys.solution());
_aux_modified = true;
}

computed.insert(uo);
Expand Down
19 changes: 13 additions & 6 deletions framework/src/loops/ComputeUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ComputeUserObjectsThread::ComputeUserObjectsThread(FEProblemBase & problem,
_query(query),
_query_subdomain(_query),
_query_boundary(_query),
_aux_sys(problem.getAuxiliarySystem())
_aux_sys(problem.getAuxiliarySystem()),
_aux_modified(false)
{
}

Expand All @@ -43,11 +44,19 @@ ComputeUserObjectsThread::ComputeUserObjectsThread(ComputeUserObjectsThread & x,
_query(x._query),
_query_subdomain(x._query_subdomain),
_query_boundary(x._query_boundary),
_aux_sys(x._aux_sys)
_aux_sys(x._aux_sys),
_aux_modified(false)
{
}

ComputeUserObjectsThread::~ComputeUserObjectsThread() {}
ComputeUserObjectsThread::~ComputeUserObjectsThread()
{
if (_aux_modified)
{
_aux_sys.solution().close();
_aux_sys.system().update();
}
}

void
ComputeUserObjectsThread::subdomainChanged()
Expand Down Expand Up @@ -129,9 +138,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 All @@ -140,6 +146,7 @@ ComputeUserObjectsThread::onElement(const Elem * elem)
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
for (auto * var : uo->getWritableCoupledVariables())
var->insert(_aux_sys.solution());
_aux_modified = true;
}
}

Expand Down

0 comments on commit 41f6951

Please sign in to comment.