/usr/include/dolfin/mesh/LocalMeshValueCollection.h is in libdolfin-dev 1.4.0+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | // Copyright (C) 2008-2012 Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Modified by Anders Logg, 2008-2009.
//
// First added: 2008-11-28
// Last changed: 2011-03-25
//
// Modified by Anders Logg, 2008-2009.
// Modified by Kent-Andre Mardal, 2011.
#ifndef __LOCAL_MESH_VALUE_COLLECTION_H
#define __LOCAL_MESH_VALUE_COLLECTION_H
#include <map>
#include <utility>
#include <vector>
#include <dolfin/common/MPI.h>
#include <dolfin/log/log.h>
namespace dolfin
{
template <typename T> class MeshValueCollection;
/// This class stores mesh data on a local processor corresponding
/// to a portion of a MeshValueCollection.
template <typename T>
class LocalMeshValueCollection
{
public:
/// Create local mesh data for given LocalMeshValueCollection
LocalMeshValueCollection(const MeshValueCollection<T>& values,
std::size_t dim);
/// Destructor
~LocalMeshValueCollection() {}
/// Return dimension of cell entity
std::size_t dim () const
{ return _dim; }
/// Return data
const std::vector<std::pair<std::pair<std::size_t,
std::size_t>, T> >& values() const
{ return _values; }
private:
// Topological dimension
const std::size_t _dim;
// MeshValueCollection values (cell_index, local_index), value))
std::vector<std::pair<std::pair<std::size_t, std::size_t>, T> > _values;
// MPI communicator
MPI_Comm _mpi_comm;
};
//---------------------------------------------------------------------------
// Implementation of LocalMeshValueCollection
//---------------------------------------------------------------------------
template <typename T>
LocalMeshValueCollection<T>::LocalMeshValueCollection(const MeshValueCollection<T>& values,
std::size_t dim)
: _dim(dim), _mpi_comm(MPI_COMM_WORLD)
{
// Prepare data
std::vector<std::vector<std::size_t> > send_indices;
std::vector<std::vector<T> > send_v;
// Extract data on main process and split among processes
if (MPI::is_broadcaster(_mpi_comm))
{
// Get number of processes
const std::size_t num_processes = MPI::size(_mpi_comm);
send_indices.resize(num_processes);
send_v.resize(num_processes);
const std::map<std::pair<std::size_t, std::size_t>, T>& vals
= values.values();
for (std::size_t p = 0; p < num_processes; p++)
{
const std::pair<std::size_t, std::size_t> local_range
= MPI::local_range(_mpi_comm, p, vals.size());
typename std::map<std::pair<std::size_t,
std::size_t>, T>::const_iterator it = vals.begin();
std::advance(it, local_range.first);
for (std::size_t i = local_range.first; i < local_range.second; ++i)
{
send_indices[p].push_back(it->first.first);
send_indices[p].push_back(it->first.second);
send_v[p].push_back(it->second);
std::advance(it, 1);
}
}
}
// Scatter data
std::vector<std::size_t> indices;
std::vector<T> v;
MPI::scatter(_mpi_comm, send_indices, indices);
MPI::scatter(_mpi_comm, send_v, v);
dolfin_assert(2*v.size() == indices.size());
// Unpack
for (std::size_t i = 0; i < v.size(); ++i)
{
const std::size_t cell_index = indices[2*i];
const std::size_t local_entity_index = indices[2*i + 1];
const T value = v[i];
_values.push_back(std::make_pair(std::make_pair(cell_index,
local_entity_index),
value));
}
}
//---------------------------------------------------------------------------
}
#endif
|