MCPcopy Create free account
hub / github.com/avaxman/Directional / main

Function main

tutorial/602_DiscreteExteriorCalculus/main.cpp:18–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17
18int main()
19{
20 directional::readOBJ(TUTORIAL_DATA_PATH "/697224__sf.obj",mesh);
21
22 Eigen::VectorXd z2(mesh.dcel.faces.size());
23 //giving a 2-form of constant (pointwise curl).
24 for (int i=0;i<mesh.dcel.faces.size();i++)
25 z2[i] = mesh.faceAreas(i)*sin(mesh.barycenters(i,0)/40.0)*cos(mesh.barycenters(i,1)/40.0);
26
27 //making it a physical curl quantity
28 z2.array()-=z2.mean();
29
30 Eigen::SparseMatrix<double> d0 = directional::d0_matrix<double>(mesh);
31 Eigen::SparseMatrix<double> d1 = directional::d1_matrix<double>(mesh);
32 Eigen::SparseMatrix<double> hodgeStar, invHodgeStar;
33 directional::hodge_star_1_matrix(mesh, hodgeStar, invHodgeStar);
34 //Eigen::SparseMatrix<double> M2 = directional::face_mass_matrix_2D<double>(mesh, true); //of inverse face areas, since -forms are integrated quantities
35 Eigen::SparseMatrix<double> M1;
36 directional::linear_whitney_mass_matrix(mesh, M1);
37
38 Eigen::SparseMatrix<double> L1 = d0.adjoint()*M1*d0;
39 Eigen::SparseMatrix<double> L2 = d0.adjoint()*hodgeStar*d0;
40 Eigen::SparseMatrix<double> diff = L1-L2;
41
42 double maxAbsValue = 0.0;
43 for (int k = 0; k < diff.outerSize(); ++k)
44 for (Eigen::SparseMatrix<double>::InnerIterator it(diff, k); it; ++it)
45 maxAbsValue = std::max(maxAbsValue, std::abs(it.value()));
46
47 std::cout<<"Exact laplacian identity (should be numerically zero): "<<maxAbsValue<<std::endl;
48 directional::project_exact(d1, hodgeStar, z2, z1Diag, z2Exact, true);
49 std::cout<<"Reproducing the original curl (z2Diag, should be numerically zero): "<<(z2-z2Exact).cwiseAbs().maxCoeff()<<std::endl;
50 directional::project_exact(d1, M1, z2, z1, z2Exact, true);
51 std::cout<<"Reproducing the original curl (z2, should be numerically zero): "<<(z2-z2Exact).cwiseAbs().maxCoeff()<<std::endl;
52 std::cout<<"Difference between z1 and z1Diag (small, not zero): "<<(z1-z1Diag).cwiseAbs().maxCoeff()<<std::endl;
53
54 viewer.init();
55 viewer.set_surface_mesh(mesh);
56 viewer.set_surface_face_data(z2, "Integrated face curl", 0);
57 Eigen::MatrixXd formField = viewer.set_1form(z1,"Coexact field", 0, 0, 1.0, 2, 0.2);
58 Eigen::MatrixXd formFieldDiag = viewer.set_1form(z1Diag,"Coexact field diag", 0, 1, 1.0, 2, 0.2);
59
60 viewer.launch();
61}

Callers

nothing calls this directly

Calls 15

readOBJFunction · 0.85
hodge_star_1_matrixFunction · 0.85
project_exactFunction · 0.85
set_surface_meshMethod · 0.80
set_surface_face_dataMethod · 0.80
set_1formMethod · 0.80
sinFunction · 0.50
cosFunction · 0.50
absFunction · 0.50
sizeMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected