Merge pull request #803 from blattms/allow-for-multiple-equations

Allow to create the correct communication information for several unknowns.
This commit is contained in:
Atgeirr Flø Rasmussen 2015-05-19 20:32:53 +02:00
commit 32b3aff8ea

View File

@ -1,6 +1,6 @@
/*
Copyright 2014, 2015 Dr. Markus Blatt - HPC-Simulation-Software & Services
Copyright 2014 Statoil ASA
Copyright 2014, 2015 Statoil ASA
Copyright 2015 NTNU
This file is part of the Open Porous Media project (OPM).
@ -28,7 +28,6 @@
#include <exception>
#if HAVE_MPI && HAVE_DUNE_ISTL
#include "mpi.h"
#include <dune/istl/owneroverlapcopy.hh>
#include <dune/common/parallel/interface.hh>
@ -38,6 +37,7 @@
#include <algorithm>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
namespace Opm
@ -112,10 +112,24 @@ public:
/// \brief Copy the information stored to the specified objects.
/// \param[out] indexSet The object to store the index set in.
/// \param[out] remoteIndices The object to store the remote indices information in.
void copyValuesTo(ParallelIndexSet& indexSet, RemoteIndices& remoteIndices) const
void copyValuesTo(ParallelIndexSet& indexSet, RemoteIndices& remoteIndices,
std::size_t local_component_size = 0, std::size_t num_components = 1) const
{
ParallelIndexSet::GlobalIndex global_component_size = local_component_size;
if ( num_components > 1 )
{
ParallelIndexSet::GlobalIndex max_gi = 0;
// component the max global index
for( auto i = indexSet_->begin(), end = indexSet_->end(); i != end; ++i )
{
max_gi = std::max(max_gi, i->global());
}
global_component_size = max_gi+1;
global_component_size = communicator_.max(global_component_size);
}
indexSet.beginResize();
IndexSetInserter<ParallelIndexSet> inserter(indexSet);
IndexSetInserter<ParallelIndexSet> inserter(indexSet, global_component_size,
local_component_size, num_components);
std::for_each(indexSet_->begin(), indexSet_->end(), inserter);
indexSet.endResize();
remoteIndices.rebuild<false>();
@ -317,19 +331,31 @@ private:
{
public:
typedef T ParallelIndexSet;
typedef typename ParallelIndexSet::LocalIndex LocalIndex;
typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
IndexSetInserter(ParallelIndexSet& indexSet)
: indexSet_(&indexSet)
IndexSetInserter(ParallelIndexSet& indexSet, const GlobalIndex& component_size,
std::size_t local_component_size, std::size_t num_components)
: indexSet_(&indexSet), component_size_(component_size),
local_component_size_(local_component_size),
num_components_(num_components)
{}
void operator()(const typename ParallelIndexSet::IndexPair& pair)
{
indexSet_->add(pair.global(), pair.local());
for(std::size_t i = 0; i < num_components_; i++)
indexSet_->add(i * component_size_ + pair.global(),
LocalIndex(i * local_component_size_ + pair.local(),
pair.local().attribute()));
}
private:
ParallelIndexSet* indexSet_;
/// \brief The global number of unknowns per component/equation.
GlobalIndex component_size_;
/// \brief The local number of unknowns per component/equation.
std::size_t local_component_size_;
/// \brief The number of components/equations.
std::size_t num_components_;
};
std::shared_ptr<ParallelIndexSet> indexSet_;
std::shared_ptr<RemoteIndices> remoteIndices_;
Dune::CollectiveCommunication<MPI_Comm> communicator_;