Exemplo n.º 1
0
void SpaceHelper<BasisFunctionType>::getGlobalDofNormals_defaultImplementation(
    const GridView &view,
    const std::vector<std::vector<LocalDof>> &global2localDofs,
    std::vector<Point3D<CoordinateType>> &normals) {
  const int gridDim = view.dim();
  const int globalDofCount_ = global2localDofs.size();
  const int worldDim = view.dimWorld();
  normals.resize(globalDofCount_);

  const IndexSet &indexSet = view.indexSet();
  int elementCount = view.entityCount(0);

  arma::Mat<CoordinateType> elementNormals(worldDim, elementCount);
  std::unique_ptr<EntityIterator<0>> it = view.entityIterator<0>();
  arma::Col<CoordinateType> center(gridDim);
  // Note: we assume here that elements are flat and so the position at which
  // the normal is calculated does not matter.
  center.fill(0.5);
  arma::Col<CoordinateType> normal;
  while (!it->finished()) {
    const Entity<0> &e = it->entity();
    int index = indexSet.entityIndex(e);
    e.geometry().getNormals(center, normal);

    for (int dim = 0; dim < worldDim; ++dim)
      elementNormals(dim, index) = normal(dim);
    it->next();
  }

  if (gridDim == 1)
    for (size_t g = 0; g < globalDofCount_; ++g) {
      const std::vector<LocalDof> &ldofs = acc(global2localDofs, g);
      normals[g].x = 0.;
      normals[g].y = 0.;
      for (size_t l = 0; l < ldofs.size(); ++l) {
        normals[g].x += elementNormals(0, acc(ldofs, l).entityIndex);
        normals[g].y += elementNormals(1, acc(ldofs, l).entityIndex);
      }
      normals[g].x /= ldofs.size();
      normals[g].y /= ldofs.size();
    }
  else // gridDim == 2
    for (size_t g = 0; g < globalDofCount_; ++g) {
      const std::vector<LocalDof> &ldofs = acc(global2localDofs, g);
      normals[g].x = 0.;
      normals[g].y = 0.;
      normals[g].z = 0.;
      for (size_t l = 0; l < ldofs.size(); ++l) {
        normals[g].x += elementNormals(0, acc(ldofs, l).entityIndex);
        normals[g].y += elementNormals(1, acc(ldofs, l).entityIndex);
        normals[g].z += elementNormals(2, acc(ldofs, l).entityIndex);
      }
      normals[g].x /= ldofs.size();
      normals[g].y /= ldofs.size();
      normals[g].z /= ldofs.size();
    }
}
void PiecewiseLinearDiscontinuousScalarSpaceBarycentric<BasisFunctionType>::getGlobalDofNormals(
        std::vector<Point3D<CoordinateType> >& normals) const
{
    const int gridDim = this->domainDimension();
    const int globalDofCount_ = globalDofCount();
    const int worldDim = this->grid()->dimWorld();
    normals.resize(globalDofCount_);

    const IndexSet& indexSet = this->gridView().indexSet();
    int elementCount = this->gridView().entityCount(0);

    arma::Mat<CoordinateType> elementNormals(worldDim, elementCount);
    std::auto_ptr<EntityIterator<0> > it = this->gridView().template entityIterator<0>();
    arma::Col<CoordinateType> center(gridDim);
    center.fill(0.5);
    arma::Col<CoordinateType> normal;
    while (!it->finished()) {
        const Entity<0>& e = it->entity();
        int index = indexSet.entityIndex(e);
        e.geometry().getNormals(center, normal);

        for (int dim = 0; dim < worldDim; ++dim)
            elementNormals(dim, index) = normal(dim);
        it->next();
    }

    if (gridDim == 1)
        for (size_t g = 0; g < globalDofCount_; ++g) {
            normals[g].x = 0.;
            normals[g].y = 0.;
            for (size_t l = 0; l < m_global2localDofs[g].size(); ++l) {
                normals[g].x += elementNormals(0, m_global2localDofs[g][l].entityIndex);
                normals[g].y += elementNormals(1, m_global2localDofs[g][l].entityIndex);
            }
            normals[g].x /= m_global2localDofs[g].size();
            normals[g].y /= m_global2localDofs[g].size();
        }
    else // gridDim == 2
        for (size_t g = 0; g < globalDofCount_; ++g) {
            normals[g].x = 0.;
            normals[g].y = 0.;
            for (size_t l = 0; l < m_global2localDofs[g].size(); ++l) {
                normals[g].x += elementNormals(0, m_global2localDofs[g][l].entityIndex);
                normals[g].y += elementNormals(1, m_global2localDofs[g][l].entityIndex);
                normals[g].z += elementNormals(2, m_global2localDofs[g][l].entityIndex);
            }
            normals[g].x /= m_global2localDofs[g].size();
            normals[g].y /= m_global2localDofs[g].size();
            normals[g].z /= m_global2localDofs[g].size();
        }
}
void PiecewiseConstantDiscontinuousScalarSpaceBarycentric<BasisFunctionType>::
    getFlatLocalDofNormals(std::vector<Point3D<CoordinateType>> &normals)
    const {
  const int gridDim = this->domainDimension();
  const int worldDim = this->grid()->dimWorld();
  normals.resize(m_flatLocal2localDofs.size());

  const IndexSet &indexSet = this->gridView().indexSet();
  int elementCount = this->gridView().entityCount(0);

  arma::Mat<CoordinateType> elementNormals(worldDim, elementCount);
  std::unique_ptr<EntityIterator<0>> it =
      this->gridView().template entityIterator<0>();
  arma::Col<CoordinateType> center(gridDim);
  center.fill(0.5);
  arma::Col<CoordinateType> normal;
  while (!it->finished()) {
    const Entity<0> &e = it->entity();
    int index = indexSet.entityIndex(e);
    e.geometry().getNormals(center, normal);

    for (int dim = 0; dim < worldDim; ++dim)
      elementNormals(dim, index) = normal(dim);
    it->next();
  }

  if (gridDim == 1)
    for (size_t f = 0; f < m_flatLocal2localDofs.size(); ++f) {
      int elementIndex = m_flatLocal2localDofs[f].entityIndex;
      normals[f].x = elementNormals(0, elementIndex);
      normals[f].y = elementNormals(1, elementIndex);
      normals[f].z = 0.;
    }
  else // gridDim == 2
    for (size_t f = 0; f < m_flatLocal2localDofs.size(); ++f) {
      int elementIndex = m_flatLocal2localDofs[f].entityIndex;
      normals[f].x = elementNormals(0, elementIndex);
      normals[f].y = elementNormals(1, elementIndex);
      normals[f].z = elementNormals(2, elementIndex);
    }
}