-
Notifications
You must be signed in to change notification settings - Fork 1
/
apply.cpp
72 lines (63 loc) · 1.86 KB
/
apply.cpp
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
#include <dolfin/la/GenericMatrix.h>
#include <dolfin/fem/DirichletBC.h>
#include <algorithm>
namespace dolfin
{
struct myclass {
bool operator() (int i,int j) { return (i<j);}
} myobject;
void apply(GenericMatrix& A, const std::vector<dolfin::la_index> &ind0)
{
std::vector<std::size_t> neighbors;
std::vector<double> values;
std::vector<std::size_t> surface_neighbors;
std::vector<dolfin::la_index> zero_row;
std::size_t self_index;
std::vector<std::size_t> ind;
std::vector<std::vector<std::size_t> > allneighbors;
int m;
for (std::size_t i = 0; i < ind0.size(); i++)
ind.push_back(ind0[i]);
std::sort (ind.begin(), ind.end(), myobject );
for (std::size_t i = 0; i < ind.size(); i++)
{
if (ind[i] == ind0[0])
continue;
std::size_t row = ind[i];
A.getrow(row, neighbors, values);
allneighbors.push_back(neighbors);
}
A.zero(ind0.size()-1, ind0.data()+1);
std::size_t count = 0;
for (std::size_t i = 0; i < ind.size(); i++)
{
if (ind[i] == ind0[0])
continue;
std::size_t row = ind[i];
surface_neighbors.clear();
values.clear();
for (std::size_t j = 0; j < allneighbors[count].size(); j++)
{
std::size_t n = allneighbors[count][j];
if (std::binary_search(ind.begin(), ind.end(), n))
{
surface_neighbors.push_back(n);
values.push_back(-1.0);
}
}
for (std::size_t j = 0; j < surface_neighbors.size(); j++)
{
if (surface_neighbors[j] == row)
{
self_index = j;
break;
}
}
std::size_t num_of_neighbors = surface_neighbors.size()-1;
values[self_index] = num_of_neighbors;
A.setrow(row, surface_neighbors, values);
count++;
}
A.apply("insert");
}
}