Example of Discrete Exterior Calculus with Chladni.
#include <sstream>
#include <string>
#include "DGtal/math/linalg/EigenSupport.h"
#include <Eigen/Eigenvalues>
#include "DGtal/dec/DiscreteExteriorCalculus.h"
#include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/math/linalg/EigenSupport.h"
#include "DGtal/dec/DiscreteExteriorCalculus.h"
#include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
using namespace std;
using namespace Eigen;
double standard_deviation(const VectorXd& xx)
{
const double mean = xx.mean();
double accum = 0;
for (int kk=0, kk_max=xx.rows(); kk<kk_max; kk++)
accum += (xx(kk)-mean)*(xx(kk)-mean);
return sqrt(accum)/(xx.size()-1);
}
{
typedef DiscreteExteriorCalculus<2, 2, EigenLinearAlgebraBackend> Calculus;
for (int kk=2; kk<=20; kk++)
for (int kk=3; kk<=20; kk++)
for (int kk=3; kk<20; kk++)
for (int ll=3; ll<20; ll++)
{
if (kk==11 && ll==11) continue;
}
const Calculus::DualIdentity0 laplace =
calculus.laplace<
DUAL>();
trace.
info() <<
"laplace=" << laplace << endl;
{
Board2D board;
board.saveSVG("chladni_calculus.svg");
}
typedef SelfAdjointEigenSolver<MatrixXd> EigenSolverMatrix;
const EigenSolverMatrix eigen_solver(laplace.myContainer);
const VectorXd eigen_values = eigen_solver.eigenvalues();
const MatrixXd eigen_vectors = eigen_solver.eigenvectors();
for (int kk=0; kk<laplace.myContainer.rows(); kk++)
{
Calculus::Scalar eigen_value = eigen_values(kk, 0);
const VectorXd eigen_vector = eigen_vectors.col(kk);
const Calculus::DualForm0 eigen_form = Calculus::DualForm0(
calculus, eigen_vector);
std::stringstream ss;
ss << "chladni_eigen_" << kk << ".svg";
const std::string filename = ss.str();
ss << "chladni_eigen_vector_" << kk << ".svg";
trace.
info() << kk <<
" " << eigen_value <<
" " << sqrt(eigen_value) <<
" " << eigen_vector.minCoeff() <<
" " << eigen_vector.maxCoeff() <<
" " << standard_deviation(eigen_vector) << endl;
Board2D board;
board << CustomStyle("KForm", new KFormStyle2D(eigen_vectors.minCoeff(),eigen_vectors.maxCoeff()));
board << eigen_form;
board.saveSVG(filename.c_str());
}
return 0;
}
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain