Example of vector field manipulation using Discrete Exterior Calculus.
#include <string>
#include "DECExamplesCommon.h"
#include "DGtal/math/linalg/EigenSupport.h"
#include "DGtal/dec/DiscreteExteriorCalculus.h"
#include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
#include "DGtal/dec/DiscreteExteriorCalculusFactory.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/readers/GenericReader.h"
using namespace std;
void usage2d()
{
typedef DiscreteExteriorCalculus<2, 2, EigenLinearAlgebraBackend> Calculus;
typedef DiscreteExteriorCalculusFactory<EigenLinearAlgebraBackend> CalculusFactory;
{
Calculus
calculus = CalculusFactory::createFromDigitalSet(generateRingSet(
domain),
false);
Board2D board;
board.saveSVG("usage_calculus_without_border.svg");
}
Calculus
calculus = CalculusFactory::createFromDigitalSet(generateRingSet(
domain),
true);
{
Board2D board;
board.saveSVG("usage_calculus_with_border.svg");
}
{
Calculus::PrimalForm0 primal_zero_form(
calculus);
{
const Calculus::Scalar& value = Z2i::l2Metric(
calculus.myKSpace.sKCoords(cell),
center)/2;
primal_zero_form.myContainer(index) = value;
}
const Calculus::PrimalForm0 foo = 2 * primal_zero_form + primal_zero_form;
{
Board2D board;
board << primal_zero_form;
board.saveSVG("usage_primal_zero_form.svg");
}
const Calculus::PrimalDerivative0 primal_zero_derivative =
calculus.derivative<0,
PRIMAL>();
const Calculus::PrimalForm1 primal_one_form = primal_zero_derivative * primal_zero_form;
const Calculus::PrimalVectorField primal_vector_field =
calculus.sharp(primal_one_form);
{
Board2D board;
board << primal_one_form;
board << primal_vector_field;
board.saveSVG("usage_primal_one_form.svg");
}
const Calculus::PrimalForm1 flat_sharp_primal_one_form =
calculus.flat(primal_vector_field);
const Calculus::PrimalVectorField sharp_flat_primal_vector_field =
calculus.sharp(flat_sharp_primal_one_form);
{
Board2D board;
board << flat_sharp_primal_one_form;
board << sharp_flat_primal_vector_field;
board.saveSVG("usage_primal_one_form_sharp_flat.svg");
}
const Calculus::PrimalHodge1 primal_one_hodge =
calculus.hodge<1,
PRIMAL>();
const Calculus::DualForm1 dual_one_form = primal_one_hodge * primal_zero_derivative * primal_zero_form;
const Calculus::DualVectorField dual_vector_field =
calculus.sharp(dual_one_form);
{
Board2D board;
board << dual_one_form;
board << dual_vector_field;
board << primal_vector_field;
board.saveSVG("usage_primal_one_form_hodge.svg");
}
}
{
Calculus::DualForm0 dual_zero_form(
calculus);
{
const Calculus::Scalar& value = Z2i::l2Metric(
calculus.myKSpace.sKCoords(cell),
center)/2;
dual_zero_form.myContainer(index) = value;
}
{
Board2D board;
board << dual_zero_form;
board.saveSVG("usage_dual_zero_form.svg");
}
const Calculus::DualDerivative0 dual_zero_derivative =
calculus.derivative<0,
DUAL>();
const Calculus::DualForm1 dual_one_form = dual_zero_derivative * dual_zero_form;
const Calculus::DualVectorField dual_vector_field =
calculus.sharp(dual_one_form);
{
Board2D board;
board << dual_one_form;
board << dual_vector_field;
board.saveSVG("usage_dual_one_form.svg");
}
const Calculus::DualForm1 flat_sharp_dual_one_form =
calculus.flat(dual_vector_field);
const Calculus::DualVectorField sharp_flat_dual_vector_field = -
calculus.sharp(flat_sharp_dual_one_form);
{
Board2D board;
board << flat_sharp_dual_one_form;
board << -sharp_flat_dual_vector_field;
board.saveSVG("usage_dual_one_form_sharp_flat.svg");
}
const Calculus::DualHodge1 dual_one_hodge =
calculus.hodge<1,
DUAL>();
const Calculus::PrimalForm1 primal_one_form = dual_one_hodge * dual_zero_derivative * dual_zero_form;
const Calculus::PrimalVectorField primal_vector_field =
calculus.sharp(primal_one_form);
{
Board2D board;
board << primal_one_form;
board << primal_vector_field;
board << dual_vector_field;
board.saveSVG("usage_dual_one_form_hodge.svg");
}
}
}
{
usage2d();
return 0;
}
void beginBlock(const std::string &keyword="")
Point center(const std::vector< Point > &points)
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain