1
// Copyright (C) 2004-2008 Johan Jansson and Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
5
// Last changed: 2008-12-11
10
#include <dolfin/dolfin_log.h>
11
#include <dolfin/dolfin_math.h>
12
#include <dolfin/parameters.h>
13
#include <dolfin/MultiAdaptivity.h>
14
#include <dolfin/Partition.h>
16
using namespace dolfin;
18
//-----------------------------------------------------------------------------
19
Partition::Partition(uint N) : indices(N)
21
// Get parameter for threshold
22
threshold = dolfin_get("ODE partitioning threshold");
25
for (uint i = 0; i < N; i++)
28
//-----------------------------------------------------------------------------
29
Partition::~Partition()
33
//-----------------------------------------------------------------------------
34
dolfin::uint Partition::size() const
36
return indices.size();
38
//-----------------------------------------------------------------------------
39
dolfin::uint Partition::index(uint i) const
41
dolfin_assert(i < indices.size());
44
//-----------------------------------------------------------------------------
45
real Partition::update(uint offset, uint& end, MultiAdaptivity& adaptivity,
48
// Compute time steps for partition. We partition the components into two
49
// groups, one group with k < Kpivot and one with k >= Kpivot.
51
// Compute time step for partitioning
52
real Kpivot = threshold * maximum(offset, adaptivity);
54
// Comparison operator
55
Less less(Kpivot, adaptivity);
57
// Partition using std::partition
58
Array<uint>::iterator start = indices.begin();
59
std::advance(start, offset);
60
Array<uint>::iterator middle = std::partition(start, indices.end(), less);
62
// Compute pivot index
63
end = std::distance(indices.begin(), middle);
65
// Modify time step to the smallest k such that k >= Kpivot.
66
Kpivot = minimum(offset, end, adaptivity);
68
// Modify time step so K is a multiple of Kpivot
69
//Kpivot = K / ceil(K / Kpivot);
72
for (uint i = offset; i < end ; i++)
74
uint index = indices[i];
75
cout << "i = " << index << ": " << adaptivity.timestep(index)
76
<< " --> " << Kpivot << endl;
82
//-----------------------------------------------------------------------------
83
void Partition::debug(uint offset, uint end) const
87
for (uint i = 0; i < indices.size(); i++)
89
if ( i == offset || i == end )
92
cout << " " << indices[i];
97
//-----------------------------------------------------------------------------
98
real Partition::maximum(uint offset, MultiAdaptivity& adaptivity) const
102
for (uint i = offset; i < indices.size(); i++)
103
K = std::max(adaptivity.timestep(indices[i]), K);
107
//-----------------------------------------------------------------------------
108
real Partition::minimum(uint offset, uint end,
109
MultiAdaptivity& adaptivity) const
111
real k = adaptivity.timestep(indices[offset]);
113
for (uint i = offset + 1; i < end; i++)
114
k = std::min(adaptivity.timestep(indices[i]), k);
118
//-----------------------------------------------------------------------------
119
Partition::Less::Less(real& K, MultiAdaptivity& adaptivity)
120
: K(K), adaptivity(adaptivity)
124
//-----------------------------------------------------------------------------
125
bool Partition::Less::operator()(uint index) const
127
return adaptivity.timestep(index) >= K;
129
//-----------------------------------------------------------------------------