示例#1
0
void
MaterialPropertyStorage::initStatefulProps(MaterialData & material_data,
                                           const std::vector<std::shared_ptr<Material>> & mats,
                                           unsigned int n_qpoints,
                                           const Elem & elem,
                                           unsigned int side /* = 0*/)
{
  // NOTE: since materials are storing their computed properties in MaterialData class, we need to
  // juggle the memory between MaterialData and MaterialProperyStorage classes

  initProps(material_data, elem, side, n_qpoints);

  // copy from storage to material data
  swap(material_data, elem, side);
  // run custom init on properties
  for (const auto & mat : mats)
    mat->initStatefulProperties(n_qpoints);

  swapBack(material_data, elem, side);

  if (!hasStatefulProperties())
    return;

  // This second call to initProps covers cases where code in
  // "init[Qp]StatefulProperties" may have called a get/declare for a stateful
  // property affecting the _stateful_prop_id_to_prop_id vector among other
  // things.  This is necessary because a call to
  // getMaterialProperty[Old/Older] can potentially trigger a material to
  // become stateful that previously wasn't.  This needs to go after the
  // swapBack.
  initProps(material_data, elem, side, n_qpoints);

  // Copy the properties to Old and Older as needed
  for (unsigned int i = 0; i < _stateful_prop_id_to_prop_id.size(); ++i)
  {
    auto curr = props(&elem, side)[i];
    auto old = propsOld(&elem, side)[i];
    auto older = propsOlder(&elem, side)[i];
    for (unsigned int qp = 0; qp < n_qpoints; ++qp)
    {
      old->qpCopy(qp, curr, qp);
      if (hasOlderProperties())
        older->qpCopy(qp, curr, qp);
    }
  }
}
void
MaterialPropertyStorage::initStatefulProps(MaterialData & material_data, const std::vector<MooseSharedPointer<Material> > & mats, unsigned int n_qpoints, const Elem & elem, unsigned int side/* = 0*/)
{
  // NOTE: since materials are storing their computed properties in MaterialData class, we need to
  // juggle the memory between MaterialData and MaterialProperyStorage classes

  material_data.size(n_qpoints);

  if (props()[&elem][side].size() == 0) props()[&elem][side].resize(_stateful_prop_id_to_prop_id.size());
  if (propsOld()[&elem][side].size() == 0) propsOld()[&elem][side].resize(_stateful_prop_id_to_prop_id.size());
  if (propsOlder()[&elem][side].size() == 0) propsOlder()[&elem][side].resize(_stateful_prop_id_to_prop_id.size());

  // init properties (allocate memory. etc)
  for (unsigned int i=0; i < _stateful_prop_id_to_prop_id.size(); ++i)
  {
    // duplicate the stateful property in property storage (all three states - we will reuse the allocated memory there)
    // also allocating the right amount of memory, so we do not have to resize, etc.
    if (props()[&elem][side][i] == NULL) props()[&elem][side][i] = material_data.props()[ _stateful_prop_id_to_prop_id[i] ]->init(n_qpoints);
    if (propsOld()[&elem][side][i] == NULL) propsOld()[&elem][side][i] = material_data.propsOld()[ _stateful_prop_id_to_prop_id[i] ]->init(n_qpoints);
    if (hasOlderProperties())
      if (propsOlder()[&elem][side][i] == NULL) propsOlder()[&elem][side][i] = material_data.propsOlder()[ _stateful_prop_id_to_prop_id[i] ]->init(n_qpoints);
  }
  // copy from storage to material data
  swap(material_data, elem, side);
  // run custom init on properties
  for (const auto & mat : mats)
    mat->initStatefulProperties(n_qpoints);
  swapBack(material_data, elem, side);

  // Copy the properties to Old and Older as needed
  if (hasStatefulProperties())
    for (unsigned int i=0; i < _stateful_prop_id_to_prop_id.size(); ++i)
      for (unsigned int qp=0; qp < n_qpoints; ++qp)
      {
        propsOld()[&elem][side][i]->qpCopy(qp, props()[&elem][side][i], qp);
        if (hasOlderProperties())
          propsOlder()[&elem][side][i]->qpCopy(qp, props()[&elem][side][i], qp);
      }
}