Skip to content

Commit

Permalink
Only initialize shapes for Jacobians (idaholab#5913)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Nov 3, 2015
1 parent a7b61c6 commit 9314dbc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions framework/include/userobject/ShapeElementUserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ InputParameters validParams<ShapeElementUserObject>();

/**
* ElementUserObject class in which the _phi and _grad_phi shape function data
* is available and correctly initialized. This enables the calculation of
* Jacobian matrix contributions inside a UO
* is available and correctly initialized on EXEC_NONLINEAR (the Jacobian calculation).
* This enables the calculation of Jacobian matrix contributions inside a UO.
*
* \warning It is up to the user to ensure _fe_problem.currentlyComputingJacobian()
* returns true before utilizing the shape functions.
*/
class ShapeElementUserObject : public ElementUserObject
{
Expand Down
10 changes: 5 additions & 5 deletions framework/src/base/Assembly.C
Original file line number Diff line number Diff line change
Expand Up @@ -1526,14 +1526,14 @@ Assembly::addCachedJacobianContributions(SparseMatrix<Number> & jacobian)
void
Assembly::registerUserObjectShapeVariable(unsigned int var)
{
std::vector<unsigned int> & vec = _user_object_shape_variables;
std::vector<unsigned int> & reg = _user_object_shape_variables;

// add variable to the vector
vec.push_back(var);
// add variable number to the list of registered variables
reg.push_back(var);

// sort and keep elements unique
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
std::sort(reg.begin(), reg.end());
reg.erase(std::unique(reg.begin(), reg.end()), reg.end());
}

void
Expand Down
5 changes: 3 additions & 2 deletions framework/src/base/ComputeUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ ComputeUserObjectsThread::onElement(const Elem * elem)
_fe_problem.reinitMaterials(_subdomain, _tid);

// Prepare shape functions for ShapeElementUserObjects
for (unsigned int i = 0; i < _user_object_shape_variables.size(); ++i)
_fe_problem.prepareShapes(_user_object_shape_variables[i], _tid);
if (_fe_problem.currentlyComputingJacobian())
for (unsigned int i = 0; i < _user_object_shape_variables.size(); ++i)
_fe_problem.prepareShapes(_user_object_shape_variables[i], _tid);

//Global UserObjects
for (std::vector<ElementUserObject *>::const_iterator UserObject_it = _user_objects[_tid].elementUserObjects(Moose::ANY_BLOCK_ID, _group).begin();
Expand Down
4 changes: 4 additions & 0 deletions framework/src/base/FEProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,9 @@ FEProblem::execute(const ExecFlagType & exec_type)
{
// Set the current flag
_current_execute_on_flag = exec_type;
if (exec_type == EXEC_NONLINEAR)
_currently_computing_jacobian = true;


// Pre-aux UserObjects
Moose::perf_log.push("computeUserObjects()", "Setup");
Expand All @@ -2265,6 +2268,7 @@ FEProblem::execute(const ExecFlagType & exec_type)

// Return the current flag to None
_current_execute_on_flag = EXEC_NONE;
_currently_computing_jacobian = false;
}

void
Expand Down

0 comments on commit 9314dbc

Please sign in to comment.