4#include "feddlib/core/FEDDCore.hpp"
7#ifndef FEDD_TIMER_START
8#define FEDD_TIMER_START(A,S) Teuchos::RCP<Teuchos::TimeMonitor> A = Teuchos::rcp(new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer(std::string("FEDD") + std::string(S))));
11#ifndef FEDD_TIMER_STOP
12#define FEDD_TIMER_STOP(A) A.reset();
18template<
class ForwardIt,
class GO>
19ForwardIt uniqueWithCombines(ForwardIt first, ForwardIt last, std::vector<std::vector<GO> >& combines)
25 ForwardIt firstForDistance = first;
26 ForwardIt result = first;
27 combines[ distance( firstForDistance, result ) ].push_back( (GO) distance( firstForDistance, first ) );
28 while (++first != last) {
29 if (!(*result == *first) && ++result != first) {
30 *result = std::move(*first);
32 combines[ distance( firstForDistance, result ) ].push_back( (GO) distance( firstForDistance, first ) );
35 combines[ distance( firstForDistance, result ) ].push_back( (GO) distance( firstForDistance, first ) );
42std::vector<T> sort_from_ref(
43 std::vector<T>
const& in,
44 std::vector<int>
const& reference
46 std::vector<T> ret(in.size());
48 int const size = in.size();
49 for (
int i = 0; i < size; ++i)
50 ret[i] = in[reference[i]];
56std::vector<T> sort_from_ref(
57 std::vector<T>
const& in,
58 std::vector<long long>
const& reference
60 std::vector<T> ret(in.size());
62 int const size = in.size();
63 for (
long long i = 0; i < size; ++i)
64 ret[i] = in[reference[i]];
71void sort2byFirst( std::vector<std::vector<T> >& in, std::vector<T>& in2 )
74 std::vector<int> index(in.size(), 0);
75 for (
int i = 0 ; i != index.size() ; i++)
78 std::sort(index.begin(), index.end(),
79 [&](
const int& a,
const int& b) {
83 in = sort_from_ref( in, index );
84 in2 = sort_from_ref( in2, index );
88template <
typename T,
class GO>
89void make_unique( std::vector<std::vector<T> >& in, vec2D_GO_Type& combinedElements, std::vector<GO>& globaIDs )
92 std::vector<int> index(in.size(), 0);
93 for (
int i = 0 ; i != index.size() ; i++)
96 std::sort(index.begin(), index.end(),
97 [&](
const int& a,
const int& b) {
101 in = sort_from_ref( in, index );
102 globaIDs = sort_from_ref( globaIDs, index );
105 std::vector<int> index(in.size(), 0);
106 for (
int i = 0 ; i != index.size() ; i++)
109 combinedElements.resize( in.size() );
111 auto it = uniqueWithCombines( in.begin(), in.end(), combinedElements );
113 in.resize( distance( in.begin(), it ) );
114 combinedElements.resize( in.size() );
119void make_unique( std::vector<std::vector<T> >& in )
122 std::vector<int> index(in.size(), 0);
123 for (
int i = 0 ; i != index.size() ; i++)
126 std::sort(index.begin(), index.end(),
127 [&](
const int& a,
const int& b) {
128 return in[a] < in[b];
131 in = sort_from_ref( in, index );
135 auto it = std::unique( in.begin(), in.end() );
137 in.resize( distance( in.begin(), it ) );
142void make_unique( std::vector<std::vector<T> >& in, vec2D_GO_Type& combinedElements )
145 std::vector<int> index(in.size(), 0);
146 for (
int i = 0 ; i != index.size() ; i++)
149 std::sort(index.begin(), index.end(),
150 [&](
const int& a,
const int& b) {
151 return in[a] < in[b];
154 in = sort_from_ref( in, index );
158 std::vector<int> index(in.size(), 0);
159 for (
int i = 0 ; i != index.size() ; i++)
162 combinedElements.resize( in.size() );
164 auto it = uniqueWithCombines( in.begin(), in.end(), combinedElements );
166 in.resize( distance( in.begin(), it ) );
168 combinedElements.resize( in.size() );
173std::vector<T> operator+(
const std::vector<T>& a,
const std::vector<T>& b)
175 assert(a.size() == b.size());
177 std::vector<T> result;
178 result.reserve(a.size());
180 std::transform(a.begin(), a.end(), b.begin(),
181 std::back_inserter(result), std::plus<T>());
186std::vector<T> operator-(
const std::vector<T>& a,
const std::vector<T>& b)
188 assert(a.size() == b.size());
190 std::vector<T> result;
191 result.reserve(a.size());
193 std::transform(a.begin(), a.end(), b.begin(),
194 std::back_inserter(result), std::minus<T>());
199void make_unique( std::vector<T>& in )
201 std::sort( in.begin(), in.end() );
202 auto it = unique( in.begin(), in.end() );
203 in.erase( it, in.end() );
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5