Skip to content

Commit

Permalink
Move updateMatPropDependency into MooseObjectWarehouseBase. (idaholab…
Browse files Browse the repository at this point in the history
…#8444)

- Also make material computing threads (e.g. ComputeResidualThread call the
  updateMatPropDependency methods)
- Make sure that we don't mark as having material property dependencies simply
  because we call setActiveMaterialProperties in FEProblemBase/Subproblem
  • Loading branch information
lindsayad committed Feb 2, 2017
1 parent 4d118e2 commit 85d7b46
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 60 deletions.
61 changes: 61 additions & 0 deletions framework/include/base/MooseObjectWarehouseBase.h
Expand Up @@ -115,6 +115,14 @@ class MooseObjectWarehouseBase
void updateBoundaryVariableDependency(BoundaryID id, std::set<MooseVariable *> & needed_moose_vars, THREAD_ID tid = 0) const;
///@}

void updateMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

void updateBlockMatPropDependency(SubdomainID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

void updateBoundaryMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

void updateBoundaryMatPropDependency(BoundaryID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

/**
* Populates a set of covered subdomains and the associated variable names.
*/
Expand Down Expand Up @@ -160,6 +168,9 @@ class MooseObjectWarehouseBase
static void updateVariableDependencyHelper(std::set<MooseVariable *> & needed_moose_vars,
const std::vector<MooseSharedPointer<T> > & objects);

static void updateMatPropDependencyHelper(std::set<unsigned int> & needed_mat_props,
const std::vector<MooseSharedPointer<T> > & objects);

/**
* Calls assert on thread id.
*/
Expand Down Expand Up @@ -539,6 +550,56 @@ MooseObjectWarehouseBase<T>::updateVariableDependencyHelper(std::set<MooseVariab
}
}

template<typename T>
void
MooseObjectWarehouseBase<T>::updateMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
{
if (hasActiveObjects(tid))
updateMatPropDependencyHelper(needed_mat_props, _all_objects[tid]);
}

template<typename T>
void
MooseObjectWarehouseBase<T>::updateBlockMatPropDependency(SubdomainID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
{
if (hasActiveBlockObjects(id, tid))
updateMatPropDependencyHelper(needed_mat_props, getActiveBlockObjects(id, tid));
}


template<typename T>
void
MooseObjectWarehouseBase<T>::updateBoundaryMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid/* = 0*/) const
{
if (hasActiveBoundaryObjects(tid))
{
typename std::map<BoundaryID, std::vector<MooseSharedPointer<T> > >::const_iterator it;
for (it = _active_boundary_objects[tid].begin(); it != _active_boundary_objects[tid].end(); ++it)
updateMatPropDependencyHelper(needed_mat_props, it->second);
}
}


template<typename T>
void
MooseObjectWarehouseBase<T>::updateBoundaryMatPropDependency(BoundaryID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid/* = 0*/) const
{
if (hasActiveBoundaryObjects(id, tid))
updateMatPropDependencyHelper(needed_mat_props, getActiveBoundaryObjects(id, tid));
}


template<typename T>
void
MooseObjectWarehouseBase<T>::updateMatPropDependencyHelper(std::set<unsigned int> & needed_mat_props, const std::vector<MooseSharedPointer<T> > & objects)
{
for (typename std::vector<MooseSharedPointer<T> > ::const_iterator it = objects.begin(); it != objects.end(); ++it)
{
const std::set<unsigned int> & mp_deps = (*it)->getMatPropDependencies();
needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
}
}


template<typename T>
void
Expand Down
2 changes: 1 addition & 1 deletion framework/include/dgkernels/DGKernel.h
Expand Up @@ -54,7 +54,7 @@ class DGKernel :
public FunctionInterface,
public UserObjectInterface,
public NeighborCoupleableMooseVariableDependencyIntermediateInterface,
protected TwoMaterialPropertyInterface,
public TwoMaterialPropertyInterface,
public Restartable,
public ZeroInterface,
public MeshChangedInterface
Expand Down
12 changes: 0 additions & 12 deletions framework/include/materials/MaterialWarehouse.h
Expand Up @@ -51,24 +51,12 @@ class MaterialWarehouse : public MooseObjectWarehouse<Material>
*/
void addObjects(MooseSharedPointer<Material> block, MooseSharedPointer<Material> neighbor, MooseSharedPointer<Material> face, THREAD_ID tid = 0);

void updateMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

void updateBlockMatPropDependency(SubdomainID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

void updateBoundaryMatPropDependency(BoundaryID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid = 0) const;

protected:
/// Stroage for neighbor material objects (Block are stored in the base class)
MooseObjectWarehouse<Material> _neighbor_materials;

/// Stroage for face material objects (Block are stored in the base class)
MooseObjectWarehouse<Material> _face_materials;

/**
* Helper method for updating variable dependency vector
*/
static void updateMatPropDependencyHelper(std::set<unsigned int> & needed_mat_props,
const std::vector<MooseSharedPointer<Material> > & material_objects);
};

#endif // MATERIALWAREHOUSE_H
4 changes: 4 additions & 0 deletions framework/src/base/ComputeElemAuxVarsThread.C
Expand Up @@ -54,6 +54,7 @@ ComputeElemAuxVarsThread::subdomainChanged()
}

std::set<MooseVariable *> needed_moose_vars;
std::set<unsigned int> needed_mat_props;

if (_aux_kernels.hasActiveBlockObjects(_subdomain, _tid))
{
Expand All @@ -62,11 +63,14 @@ ComputeElemAuxVarsThread::subdomainChanged()
{
aux->subdomainSetup();
const std::set<MooseVariable *> & mv_deps = aux->getMooseVariableDependencies();
const std::set<unsigned int> & mp_deps = aux->getMatPropDependencies();
needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
}
}

_fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
_fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
_fe_problem.prepareMaterials(_subdomain, _tid);
}

Expand Down
8 changes: 8 additions & 0 deletions framework/src/base/ComputeJacobianThread.C
Expand Up @@ -167,7 +167,15 @@ ComputeJacobianThread::subdomainChanged()
_dg_kernels.updateBlockVariableDependency(_subdomain, needed_moose_vars, _tid);
_interface_kernels.updateBoundaryVariableDependency(needed_moose_vars, _tid);

// Update material dependencies
std::set<unsigned int> needed_mat_props;
_kernels.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);
_integrated_bcs.updateBoundaryMatPropDependency(needed_mat_props, _tid);
_dg_kernels.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);
_interface_kernels.updateBoundaryMatPropDependency(needed_mat_props, _tid);

_fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
_fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
_fe_problem.prepareMaterials(_subdomain, _tid);
}

Expand Down
8 changes: 8 additions & 0 deletions framework/src/base/ComputeResidualThread.C
Expand Up @@ -69,7 +69,15 @@ ComputeResidualThread::subdomainChanged()
_dg_kernels.updateBlockVariableDependency(_subdomain, needed_moose_vars, _tid);
_interface_kernels.updateBoundaryVariableDependency(needed_moose_vars, _tid);

// Update material dependencies
std::set<unsigned int> needed_mat_props;
_kernels.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);
_integrated_bcs.updateBoundaryMatPropDependency(needed_mat_props, _tid);
_dg_kernels.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);
_interface_kernels.updateBoundaryMatPropDependency(needed_mat_props, _tid);

_fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
_fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
_fe_problem.prepareMaterials(_subdomain, _tid);
}

Expand Down
6 changes: 6 additions & 0 deletions framework/src/base/ComputeUserObjectsThread.C
Expand Up @@ -61,11 +61,17 @@ ComputeUserObjectsThread::subdomainChanged()
_side_user_objects.updateBoundaryVariableDependency(needed_moose_vars, _tid);
_internal_side_user_objects.updateBlockVariableDependency(_subdomain, needed_moose_vars, _tid);

std::set<unsigned int> needed_mat_props;
_elemental_user_objects.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);
_side_user_objects.updateBoundaryMatPropDependency(needed_mat_props, _tid);
_internal_side_user_objects.updateBlockMatPropDependency(_subdomain, needed_mat_props, _tid);

_elemental_user_objects.subdomainSetup(_subdomain, _tid);
_side_user_objects.subdomainSetup(_tid);
_internal_side_user_objects.subdomainSetup(_subdomain, _tid);

_fe_problem.setActiveElementalMooseVariables(needed_moose_vars, _tid);
_fe_problem.setActiveMaterialProperties(needed_mat_props, _tid);
_fe_problem.prepareMaterials(_subdomain, _tid);
}

Expand Down
15 changes: 7 additions & 8 deletions framework/src/base/FEProblemBase.C
Expand Up @@ -2018,11 +2018,10 @@ FEProblemBase::prepareMaterials(SubdomainID blk_id, THREAD_ID tid)
std::set<MooseVariable *> needed_moose_vars;
std::set<unsigned int> needed_mat_props;


if (_all_materials.hasActiveBlockObjects(blk_id, tid))
{
_all_materials.updateVariableDependency(needed_moose_vars, tid);
_all_materials.updateMatPropDependency(needed_mat_props, tid);
_all_materials.updateBlockMatPropDependency(blk_id, needed_mat_props, tid);
}

const std::set<BoundaryID> & ids = _mesh.getSubdomainBoundaryIds(blk_id);
Expand All @@ -2035,18 +2034,18 @@ FEProblemBase::prepareMaterials(SubdomainID blk_id, THREAD_ID tid)
const std::set<MooseVariable *> & current_active_elemental_moose_variables = getActiveElementalMooseVariables(tid);
needed_moose_vars.insert(current_active_elemental_moose_variables.begin(), current_active_elemental_moose_variables.end());

if (!needed_moose_vars.empty())
setActiveElementalMooseVariables(needed_moose_vars, tid);
const std::set<unsigned int> & current_active_material_properties = getActiveMaterialProperties(tid);
needed_mat_props.insert(current_active_material_properties.begin(), current_active_material_properties.end());

if (!needed_mat_props.empty())
setActiveMaterialProperties(needed_mat_props, tid);
setActiveElementalMooseVariables(needed_moose_vars, tid);
setActiveMaterialProperties(needed_mat_props, tid);
}

void
FEProblemBase::reinitMaterials(SubdomainID blk_id, THREAD_ID tid, bool swap_stateful)
{
// if (_all_materials.hasActiveBlockObjects(blk_id, tid))
if (_all_materials.hasActiveBlockObjects(blk_id, tid) && this->hasActiveMaterialProperties(tid))
if (_all_materials.hasActiveBlockObjects(blk_id, tid))
// if (_all_materials.hasActiveBlockObjects(blk_id, tid) && this->hasActiveMaterialProperties(tid))
{
const Elem * & elem = _assembly[tid]->elem();
unsigned int n_points = _assembly[tid]->qRule()->n_points();
Expand Down
14 changes: 10 additions & 4 deletions framework/src/base/SubProblem.C
Expand Up @@ -51,8 +51,11 @@ SubProblem::~SubProblem()
void
SubProblem::setActiveElementalMooseVariables(const std::set<MooseVariable *> & moose_vars, THREAD_ID tid)
{
_has_active_elemental_moose_variables[tid] = 1;
_active_elemental_moose_variables[tid] = moose_vars;
if (!moose_vars.empty())
{
_has_active_elemental_moose_variables[tid] = 1;
_active_elemental_moose_variables[tid] = moose_vars;
}
}

const std::set<MooseVariable *> &
Expand All @@ -77,8 +80,11 @@ SubProblem::clearActiveElementalMooseVariables(THREAD_ID tid)
void
SubProblem::setActiveMaterialProperties(const std::set<unsigned int> & mat_prop_ids, THREAD_ID tid)
{
_has_active_material_property_ids[tid] = 1;
_active_material_property_ids[tid] = mat_prop_ids;
if (!mat_prop_ids.empty())
{
_has_active_material_property_ids[tid] = 1;
_active_material_property_ids[tid] = mat_prop_ids;
}
}

const std::set<unsigned int> &
Expand Down
32 changes: 0 additions & 32 deletions framework/src/materials/MaterialWarehouse.C
Expand Up @@ -104,35 +104,3 @@ MaterialWarehouse::sort(THREAD_ID tid /*=0*/)
_neighbor_materials.sort(tid);
_face_materials.sort(tid);
}


void
MaterialWarehouse::updateMatPropDependency(std::set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
{
if (hasActiveObjects(tid))
updateMatPropDependencyHelper(needed_mat_props, _all_objects[tid]);
}

void
MaterialWarehouse::updateBlockMatPropDependency(SubdomainID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
{
if (hasActiveBlockObjects(id, tid))
updateMatPropDependencyHelper(needed_mat_props, getActiveBlockObjects(id, tid));
}

void
MaterialWarehouse::updateBoundaryMatPropDependency(BoundaryID id, std::set<unsigned int> & needed_mat_props, THREAD_ID tid/* = 0*/) const
{
if (hasActiveBoundaryObjects(id, tid))
updateMatPropDependencyHelper(needed_mat_props, getActiveBoundaryObjects(id, tid));
}

void
MaterialWarehouse::updateMatPropDependencyHelper(std::set<unsigned int> & needed_mat_props, const std::vector<MooseSharedPointer<Material> > & material_objects)
{
for (std::vector<MooseSharedPointer<Material> > ::const_iterator it = material_objects.begin(); it != material_objects.end(); ++it)
{
const std::set<unsigned int> & mp_deps = (*it)->getMatPropDependencies();
needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
}
}
2 changes: 2 additions & 0 deletions test/src/base/MooseTestApp.C
Expand Up @@ -127,6 +127,7 @@
#include "DataStructIC.h"

// Materials
#include "ErrorMaterial.h"
#include "MTMaterial.h"
#include "TypesMaterial.h"
#include "StatefulMaterial.h"
Expand Down Expand Up @@ -426,6 +427,7 @@ MooseTestApp::registerObjects(Factory & factory)

// Materials
registerMaterial(MTMaterial);
registerMaterial(ErrorMaterial);
registerMaterial(TypesMaterial);
registerMaterial(StatefulMaterial);
registerMaterial(SpatialStatefulMaterial);
Expand Down
15 changes: 12 additions & 3 deletions test/tests/materials/material_dependency/material_dependency.i
Expand Up @@ -11,6 +11,11 @@
[]

[Kernels]
# [./diff]
# type = MatDiffusion
# variable = u
# prop_name = 'diff'
# [../]
[./diff]
type = Diffusion
variable = u
Expand All @@ -33,10 +38,14 @@
[]

[Materials]
# [./block]
# type = GenericConstantMaterial
# prop_names = 'diff'
# prop_values = '1'
# block = 0
# [../]
[./block]
type = GenericConstantMaterial
prop_names = 'diff'
prop_values = '1'
type = ErrorMaterial
block = 0
[../]
[]
Expand Down

0 comments on commit 85d7b46

Please sign in to comment.