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 b1dddc0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 0 additions & 2 deletions framework/include/base/ComputeUserObjectsThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class ComputeUserObjectsThread : public ThreadedElementLoop<ConstElemRange>
const NumericVector<Number>& _soln;
std::vector<UserObjectWarehouse> & _user_objects;
UserObjectWarehouse::GROUP _group;

const std::vector<unsigned int> & _user_object_shape_variables;
};

#endif //COMPUTEUSEROBJECTSTHREAD_H
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
14 changes: 8 additions & 6 deletions framework/src/base/ComputeUserObjectsThread.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ ComputeUserObjectsThread::ComputeUserObjectsThread(FEProblem & problem, SystemBa
ThreadedElementLoop<ConstElemRange>(problem, sys),
_soln(in_soln),
_user_objects(user_objects),
_group(group),
_user_object_shape_variables(_fe_problem.assembly(_tid).userObjectShapeVariables())
_group(group)
{
}

Expand All @@ -37,8 +36,7 @@ ComputeUserObjectsThread::ComputeUserObjectsThread(ComputeUserObjectsThread & x,
ThreadedElementLoop<ConstElemRange>(x._fe_problem, x._system),
_soln(x._soln),
_user_objects(x._user_objects),
_group(x._group),
_user_object_shape_variables(x._user_object_shape_variables)
_group(x._group)
{
}

Expand Down Expand Up @@ -170,8 +168,12 @@ 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())
{
const std::vector<unsigned int> & user_object_shape_variables = _fe_problem.assembly(_tid).userObjectShapeVariables();
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 b1dddc0

Please sign in to comment.