forked from bollu/discrete-differential-geometry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddg.cpp
84 lines (69 loc) · 1.67 KB
/
ddg.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
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;
using Mat = int*;
using Vec = int*;
int matvec(Mat m, Vec v) {};
int vecvec(Vec v, Vec w) {};
struct Manifold {
int dim;
// `dim` sizes
vector<int> sizes;
// `dim-1` boundary operators
vector<Mat> boundaries;
};
// A chain on a manifold
struct Chain {
Manifold &m;
int dim; // dimension of the chain
Vec coeffs; // coefficients of cells
Chain (Manifold &m) : m (m), dim(-42), coeffs(nullptr) { };
Chain boundary() {
Chain c(m);
assert(dim >= 1);
c.dim = dim - 1;
matvec(boundaries[c.dim], coeffs, c.coeffs);
c.verify();
return c;
}
void verify() {
assert(dim >= 0);
assert(coeffs);
}
};
struct Form {
Manifold &m;
// dimension of form, ie, what dimension of chain
int dim;
double *v; // valuations of the manifold, at index i
int nintegrate; // number of times this form has been integrated.
Form(const Form &other):m(other.m),
dim(other.dim),
nintegrate(other.nintegrate) {
const int nv = m.sizes[dim];
v = new double[nv];
memcpy(v, other.v, nv * sizeof(double));
}
Form integrate() {
Form fi(*this);
fi.nintegrate++;
fi.dim++;
return fi;
}
};
// evaluate the form on the chain...
// eval c df = eval (boundary c) f
double evaluateForm(Chain c, Form f) {
for(int i = 0; i < f.nintegrate; ++i) {
c = c.boundary();
f.dim -= 1;
}
assert(c.dim == f.dim);
// f has valuations
// c hs coefficients
return vecvec(c.v, f.v);
}
int main() {
}