27#include "DGtal/math/linalg/EigenSupport.h"
28#include "DGtal/dec/DiscreteExteriorCalculus.h"
29#include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
32#include "DGtal/io/boards/Board2D.h"
33#include "DGtal/base/Common.h"
34#include "DGtal/helpers/StdDefs.h"
36#include "boost/version.hpp"
42#if BOOST_VERSION >= 105000
43#define TEST_HARDCODED_ORDER
53 typedef std::list<Calculus::SCell>
SCells;
58 const Calculus::KSpace kspace;
60 for (
int kk=20; kk>0; kk--) cells.push_back( kspace.sCell(
Point(0,kk), kk%2 != 0 ? Calculus::KSpace::NEG : Calculus::KSpace::POS) );
61 for (
int kk=0; kk<10; kk++) cells.push_back( kspace.sCell(
Point(kk,0)) );
62 for (
int kk=0; kk<10; kk++) cells.push_back( kspace.sCell(
Point(10,kk)) );
63 cells.push_back( kspace.sCell(
Point(10,10)) );
64 cells.push_back( kspace.sCell(
Point(9,10), Calculus::KSpace::NEG) );
65 for (
int kk=10; kk<20; kk++) cells.push_back( kspace.sCell(
Point(8,kk)) );
66 for (
int kk=8; kk<12; kk++) cells.push_back( kspace.sCell(
Point(kk,20)) );
67 for (
int kk=20; kk>0; kk--) cells.push_back( kspace.sCell(
Point(12,kk), kk%2 != 0 ? Calculus::KSpace::NEG : Calculus::KSpace::POS) );
68 cells.push_back( kspace.sCell(
Point(12,0)) );
77 for (SCells::const_iterator ci=cells.begin(), ce=cells.end(); ci!=ce; ci++) calculus.insertSCell( *ci );
78 calculus.updateIndexes();
84 Calculus::Cell dirac_cell = calculus.myKSpace.uCell(
Point(10,4));
85 Calculus::PrimalForm0 dirac = Calculus::PrimalForm0::dirac(calculus, dirac_cell);
87 trace.
info() <<
"dirac_cell_index=" << calculus.getCellIndex(dirac_cell) << endl;
94 board.
saveSVG(
"linear_structure_neumann_dirac.svg");
100 trace.
beginBlock(
"solving problem with neumann border condition using sparse qr solver");
103 const Calculus::PrimalIdentity0 laplace = calculus.laplace<
PRIMAL>();
105 trace.
info() <<
"laplace = " << laplace << endl;
107 const Calculus::PrimalIdentity0 reorder = calculus.reorder<0,
PRIMAL>(cells.begin(), cells.end());
108 const Calculus::PrimalIdentity0 laplace_ordered = reorder * laplace * reorder.transpose();
109 trace.
info() << Eigen::MatrixXd(laplace_ordered.myContainer) << endl;
117 Calculus::PrimalForm0 solved_solution = solver.
solve(dirac);
119 Calculus::PrimalForm0 solved_solution_ordered = reorder * solved_solution;
121 Calculus::PrimalForm0 analytic_solution(calculus);
123 const Calculus::Index dirac_position = 17;
124 const Calculus::Index length = analytic_solution.length();
125 for (Calculus::Index kk=0; kk<length; kk++)
127 Calculus::Scalar alpha = 1. * (kk)/dirac_position * (kk+1.)/(dirac_position+1.);
128 if (kk>dirac_position)
130 alpha = 1. * (length-kk)/dirac_position * (length-kk-1.)/(dirac_position+1);
131 alpha -= 1. * (length-dirac_position)/dirac_position * (length-dirac_position-1.)/(dirac_position+1);
134 analytic_solution.myContainer(kk) = alpha;
138 const double shift = solved_solution_ordered.myContainer[0]-analytic_solution.myContainer[0];
139 for (Calculus::Index index=0; index<solved_solution_ordered.length(); index++) solved_solution_ordered.myContainer[index] -= shift;
140 solved_solution_ordered.myContainer /= solved_solution_ordered.myContainer.maxCoeff();
142 trace.
info() << solver.isValid() <<
" " << solver.myLinearAlgebraSolver.info() << endl;
145 std::ofstream handle(
"linear_structure_neumann.dat");
146 for (Calculus::Index kk=0; kk<analytic_solution.length(); kk++)
148 handle << solved_solution_ordered.myContainer(kk) <<
" " << analytic_solution.myContainer(kk) << endl;
152 const double error = (solved_solution_ordered-analytic_solution).myContainer.array().abs().maxCoeff();
153 trace.
info() <<
"error=" << error << endl;
154 FATAL_ERROR( error < 1e-5 );
160 board << solved_solution;
161 board.
saveSVG(
"linear_structure_neumann_solution.svg");
165 Calculus::PrimalForm1 solved_solution_gradient = calculus.derivative<0,
PRIMAL>() * solved_solution;
169 board << solved_solution_gradient;
170 board <<
CustomStyle(
"VectorField",
new VectorFieldStyle2D(1));
171 board << calculus.
sharp(solved_solution_gradient);
172 board.saveSVG(
"linear_structure_neumann_solution_gradient.svg");
178 trace.
beginBlock(
"creating dec problem with dirichlet border condition");
181 calculus.insertSCell( calculus.myKSpace.sCell(
Point(13,0)) );
182 calculus.insertSCell( calculus.myKSpace.sCell(
Point(1,20), Calculus::KSpace::NEG) );
183 calculus.updateIndexes();
186 dirac = Calculus::PrimalForm0::dirac(calculus, dirac_cell);
188 trace.
info() <<
"dirac_cell_index=" << calculus.getCellIndex(dirac_cell) << endl;
195 board.
saveSVG(
"linear_structure_dirichlet_dirac.svg");
201 trace.
beginBlock(
"solving problem with dirichlet border condition using sparse qr solver");
204 const Calculus::PrimalIdentity0 laplace = calculus.laplace<
PRIMAL>();
206 trace.
info() <<
"laplace = " << laplace << endl;
208 const Calculus::PrimalIdentity0 reorder = calculus.reorder<0,
PRIMAL>(cells.begin(), cells.end());
209 const Calculus::PrimalIdentity0 laplace_ordered = reorder * laplace * reorder.transpose();
210 trace.
info() << Eigen::MatrixXd(laplace_ordered.myContainer) << endl;
218 Calculus::PrimalForm0 solved_solution = solver.
solve(dirac);
220 solved_solution.
myContainer.array() /= solved_solution.myContainer.maxCoeff();
221 Calculus::PrimalForm0 solved_solution_ordered = reorder * solved_solution;
223 Calculus::PrimalForm0 analytic_solution(calculus);
225 const Calculus::Index dirac_position = 17;
226 const Calculus::Index length = analytic_solution.length();
227 for (Calculus::Index kk=0; kk<length; kk++)
229 Calculus::Scalar alpha = (kk+1.)/(dirac_position+1.);
230 if (kk>dirac_position)
232 alpha = 1. - (kk-dirac_position)/(1.*length-dirac_position);
234 analytic_solution.myContainer(kk) = alpha;
238 const double shift = solved_solution_ordered.myContainer[0]-analytic_solution.myContainer[0];
239 for (Calculus::Index index=0; index<solved_solution_ordered.length(); index++) solved_solution_ordered.myContainer[index] -= shift;
240 solved_solution_ordered.myContainer /= solved_solution_ordered.myContainer.maxCoeff();
242 trace.
info() << solver.isValid() <<
" " << solver.myLinearAlgebraSolver.info() << endl;
245 std::ofstream handle(
"linear_structure_dirichlet.dat");
246 for (Calculus::Index kk=0; kk<analytic_solution.length(); kk++)
248 handle << solved_solution_ordered.myContainer(kk) <<
" " << analytic_solution.myContainer(kk) << endl;
252 const double error = (solved_solution_ordered-analytic_solution).myContainer.array().abs().maxCoeff();
253 trace.
info() <<
"error=" << error << endl;
254 FATAL_ERROR( error < 1e-5 );
260 board << solved_solution;
261 board.
saveSVG(
"linear_structure_dirichlet_solution.svg");
265 Calculus::PrimalForm1 solved_solution_gradient = calculus.derivative<0,
PRIMAL>() * solved_solution;
270 board << solved_solution_gradient;
271 board << calculus.
sharp(solved_solution_gradient);
272 board.saveSVG(
"linear_structure_dirichlet_solution_gradient.svg");
280template <
typename Operator>
283 trace.
info() << name << endl << op << endl << Eigen::MatrixXd(op.myContainer) << endl;
296 for (
int kk=-8; kk<10; kk++) calculus.insertSCell( calculus.myKSpace.sCell(
Point(-8,kk), kk%2 == 0 ? Calculus::KSpace::POS : Calculus::KSpace::NEG) );
297 for (
int kk=-8; kk<10; kk++) calculus.insertSCell( calculus.myKSpace.sCell(
Point(kk,10), kk%2 == 0 ? Calculus::KSpace::POS : Calculus::KSpace::NEG) );
298 for (
int kk=10; kk>-8; kk--) calculus.insertSCell( calculus.myKSpace.sCell(
Point(10,kk)) );
299 for (
int kk=10; kk>-8; kk--) calculus.insertSCell( calculus.myKSpace.sCell(
Point(kk,-8)) );
300 calculus.updateIndexes();
307 board.
saveSVG(
"ring_structure.svg");
310 const Calculus::PrimalDerivative0 d0 = calculus.derivative<0,
PRIMAL>();
313 const Calculus::PrimalHodge0 h0 = calculus.hodge<0,
PRIMAL>();
316 const Calculus::DualDerivative0 d0p = calculus.derivative<0,
DUAL>();
319 const Calculus::PrimalHodge1 h1 = calculus.hodge<1,
PRIMAL>();
322 const Calculus::PrimalIdentity0 laplace = calculus.laplace<
PRIMAL>();
325 const int laplace_size = calculus.kFormLength(0,
PRIMAL);
326 const Eigen::MatrixXd laplace_dense(laplace.myContainer);
328 for (
int ii=0; ii<laplace_size; ii++)
329 FATAL_ERROR( laplace_dense(ii,ii) == 2 );
331 FATAL_ERROR( laplace_dense.array().rowwise().sum().abs().sum() == 0 );
332 FATAL_ERROR( laplace_dense.transpose() == laplace_dense );
350 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(0,0,0)) );
351 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(2,0,0)) );
354 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(0,1,0), Calculus::KSpace::POS) );
355 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(0,0,1), Calculus::KSpace::POS) );
356 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(1,0,0), Calculus::KSpace::POS) );
357 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(2,1,0), Calculus::KSpace::NEG) );
358 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(2,0,1), Calculus::KSpace::NEG) );
361 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(0,1,1), Calculus::KSpace::NEG) );
362 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(1,0,1), Calculus::KSpace::POS) );
363 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(2,1,1), Calculus::KSpace::POS) );
364 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(1,1,0), Calculus::KSpace::NEG) );
367 calculus.insertSCell( calculus.myKSpace.sCell(
Z3i::Point(1,1,1)) );
369 calculus.updateIndexes();
377 const Calculus::PrimalDerivative0 d0 = calculus.derivative<0,
PRIMAL>();
378 const Calculus::DualDerivative2 d2p = calculus.derivative<2,
DUAL>();
382#if defined(TEST_HARDCODED_ORDER)
383 Eigen::MatrixXd d0_th(5, 2);
391 FATAL_ERROR( Eigen::MatrixXd(d0.myContainer) == d0_th );
393 FATAL_ERROR( Eigen::MatrixXd(d2p.transpose().myContainer) == Eigen::MatrixXd(d0.myContainer) );
397 const Calculus::PrimalDerivative1 d1 = calculus.derivative<1,
PRIMAL>();
398 const Calculus::DualDerivative1 d1p = calculus.derivative<1,
DUAL>();
402#if defined(TEST_HARDCODED_ORDER)
403 Eigen::MatrixXd d1_th(4, 5);
410 FATAL_ERROR( Eigen::MatrixXd(d1.myContainer) == d1_th );
412 FATAL_ERROR( Eigen::MatrixXd(d1p.transpose().myContainer) == Eigen::MatrixXd(d1.myContainer) );
416 const Calculus::PrimalDerivative2 d2 = calculus.derivative<2,
PRIMAL>();
417 const Calculus::DualDerivative0 d0p = calculus.derivative<0,
DUAL>();
421#if defined(TEST_HARDCODED_ORDER)
422 Eigen::MatrixXd d2_th(1, 4);
423 d2_th << -1, -1, -1, -1;
425 FATAL_ERROR( Eigen::MatrixXd(d2.myContainer) == d2_th );
427 FATAL_ERROR( Eigen::MatrixXd(d0p.transpose().myContainer) == Eigen::MatrixXd(d2.myContainer) );
458 Calculus primal_calculus;
463 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(2,2)) );
464 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(4,2)) );
465 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(2,4)) );
466 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(4,4)) );
467 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(2,6)) );
468 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(4,6)) );
470 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(1,2)) );
473 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,2), Calculus::KSpace::NEG) );
474 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,2), Calculus::KSpace::POS) );
475 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(2,3), Calculus::KSpace::NEG) );
476 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(4,3), Calculus::KSpace::POS) );
477 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,4), Calculus::KSpace::NEG) );
478 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(2,5), Calculus::KSpace::POS) );
479 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(4,5), Calculus::KSpace::NEG) );
480 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,6), Calculus::KSpace::POS) );
482 primal_calculus.eraseCell( primal_calculus.myKSpace.uCell(
Point(1,2)) );
485 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,3)) );
486 primal_calculus.insertSCell( primal_calculus.myKSpace.sCell(
Point(3,5)) );
488 primal_calculus.updateIndexes();
492 for (Calculus::ConstIterator iter_property=primal_calculus.begin(), iter_property_end=primal_calculus.end(); iter_property!=iter_property_end; iter_property++)
494 const Calculus::Cell cell = iter_property->first;
495 const Calculus::Property
property = iter_property->second;
496 const Dimension dim = primal_calculus.myKSpace.uDim(cell);
497 const Calculus::SCell signed_cell = primal_calculus.myKSpace.signs(cell, property.flipped ? Calculus::KSpace::NEG : Calculus::KSpace::POS);
499 ASSERT( signed_cell == primal_calculus.getSCell(
dim,
PRIMAL, property.index) );
503 <<
" " << signed_cell
504 <<
" " <<
property.primal_size
505 <<
" " <<
property.dual_size
506 <<
" " <<
property.index
507 <<
" " << (
property.flipped ?
"negative" :
"positive")
514 Calculus dual_calculus;
519 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(7,3)) );
520 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(9,3)) );
521 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(7,5)) );
522 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(9,5)) );
523 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(7,7)) );
524 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(9,7)) );
526 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(6,3)) );
529 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,3), Calculus::KSpace::NEG) );
530 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,3), Calculus::KSpace::POS) );
531 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(7,4), Calculus::KSpace::POS) );
532 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(9,4), Calculus::KSpace::NEG) );
533 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,5), Calculus::KSpace::NEG) );
534 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(7,6), Calculus::KSpace::NEG) );
535 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(9,6), Calculus::KSpace::POS) );
536 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,7), Calculus::KSpace::POS) );
538 dual_calculus.eraseCell( dual_calculus.myKSpace.uCell(
Point(6,3)) );
541 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,4)) );
542 dual_calculus.insertSCell( dual_calculus.myKSpace.sCell(
Point(8,6)) );
544 dual_calculus.updateIndexes();
548 for (Calculus::ConstIterator iter_property=dual_calculus.begin(), iter_property_end=dual_calculus.end(); iter_property!=iter_property_end; iter_property++)
550 const Calculus::Cell cell = iter_property->first;
551 const Calculus::Property
property = iter_property->second;
552 const Dimension dim = dual_calculus.myKSpace.uDim(cell);
553 const Calculus::SCell signed_cell = dual_calculus.myKSpace.signs(cell, property.flipped ? Calculus::KSpace::NEG : Calculus::KSpace::POS);
555 ASSERT( signed_cell == dual_calculus.getSCell(
dim,
PRIMAL, property.index) );
559 <<
" " << signed_cell
560 <<
" " <<
property.primal_size
561 <<
" " <<
property.dual_size
562 <<
" " <<
property.index
563 <<
" " << (
property.flipped ?
"negative" :
"positive")
572 board << primal_calculus;
573 board << dual_calculus;
574 board.
saveSVG(
"operators_structure.svg");
579 const Calculus::PrimalDerivative0 primal_d0 = primal_calculus.derivative<0,
PRIMAL>();
580 const Calculus::DualDerivative0 dual_d0p = dual_calculus.derivative<0,
DUAL>();
585#if defined(TEST_HARDCODED_ORDER)
586 Eigen::MatrixXd d0_th(7, 6);
595 FATAL_ERROR( Eigen::MatrixXd(primal_d0.myContainer) == d0_th );
597 Eigen::MatrixXd d0p_th(7, 6);
606 FATAL_ERROR( Eigen::MatrixXd(dual_d0p.myContainer) == d0p_th );
610 const Calculus::PrimalDerivative1 primal_d1 = primal_calculus.derivative<1,
PRIMAL>();
611 const Calculus::DualDerivative1 dual_d1p = dual_calculus.derivative<1,
DUAL>();
616#if defined(TEST_HARDCODED_ORDER)
617 Eigen::MatrixXd d1_th(2, 7);
620 0, 0, -1, -1, 0, -1, -1;
621 FATAL_ERROR( Eigen::MatrixXd(primal_d1.myContainer) == d1_th );
623 Eigen::MatrixXd d1p_th(2, 7);
625 -1, -1, -1, 0, 0, -1, 0,
627 FATAL_ERROR( Eigen::MatrixXd(dual_d1p.myContainer) == d1p_th );
635 FATAL_ERROR( Eigen::MatrixXd((primal_d1*primal_d0).myContainer) == Eigen::MatrixXd::Zero(2,6) );
636 FATAL_ERROR( Eigen::MatrixXd((dual_d1p*dual_d0p).myContainer) == Eigen::MatrixXd::Zero(2,6) );
639 const Calculus::PrimalHodge0 primal_h0 = primal_calculus.hodge<0,
PRIMAL>();
640 const Calculus::DualHodge0 dual_h0p = dual_calculus.hodge<0,
DUAL>();
641 const Calculus::DualHodge2 primal_h2p = primal_calculus.hodge<2,
DUAL>();
642 const Calculus::PrimalHodge2 dual_h2 = dual_calculus.hodge<2,
PRIMAL>();
649 FATAL_ERROR( Eigen::MatrixXd(primal_h0.myContainer) == Eigen::MatrixXd::Identity(6,6) );
650 FATAL_ERROR( Eigen::MatrixXd(dual_h0p.myContainer) == Eigen::MatrixXd::Identity(6,6) );
651 FATAL_ERROR( Eigen::MatrixXd(primal_h2p.myContainer) == Eigen::MatrixXd::Identity(6,6) );
652 FATAL_ERROR( Eigen::MatrixXd(dual_h2.myContainer) == Eigen::MatrixXd::Identity(6,6) );
655 const Calculus::PrimalHodge2 primal_h2 = primal_calculus.hodge<2,
PRIMAL>();
656 const Calculus::DualHodge2 dual_h2p = dual_calculus.hodge<2,
DUAL>();
657 const Calculus::DualHodge0 primal_h0p = primal_calculus.hodge<0,
DUAL>();
658 const Calculus::PrimalHodge0 dual_h0 = dual_calculus.hodge<0,
PRIMAL>();
665 FATAL_ERROR( Eigen::MatrixXd(primal_h2.myContainer) == Eigen::MatrixXd::Identity(2,2) );
666 FATAL_ERROR( Eigen::MatrixXd(dual_h2p.myContainer) == Eigen::MatrixXd::Identity(2,2) );
667 FATAL_ERROR( Eigen::MatrixXd(primal_h0p.myContainer) == Eigen::MatrixXd::Identity(2,2) );
668 FATAL_ERROR( Eigen::MatrixXd(dual_h0.myContainer) == Eigen::MatrixXd::Identity(2,2) );
671 const Calculus::DualDerivative0 primal_d0p = primal_calculus.derivative<0,
DUAL>();
672 const Calculus::PrimalDerivative0 dual_d0 = dual_calculus.derivative<0,
PRIMAL>();
677#if defined(TEST_HARDCODED_ORDER)
678 Eigen::MatrixXd d0p_th_transpose(2, 7);
681 0, 0, -1, -1, 0, -1, -1;
682 FATAL_ERROR( Eigen::MatrixXd(primal_d0p.myContainer) == d0p_th_transpose.transpose() );
684 Eigen::MatrixXd minus_d0_th_transpose(2, 7);
685 minus_d0_th_transpose <<
686 -1, -1, -1, 0, 0, -1, 0,
688 FATAL_ERROR( Eigen::MatrixXd(dual_d0.myContainer) == -minus_d0_th_transpose.transpose() );
692 const Calculus::DualDerivative1 primal_d1p = primal_calculus.derivative<1,
DUAL>();
693 const Calculus::PrimalDerivative1 dual_d1 = dual_calculus.derivative<1,
PRIMAL>();
698#if defined(TEST_HARDCODED_ORDER)
699 Eigen::MatrixXd minus_d1p_th_transpose(7, 6);
700 minus_d1p_th_transpose <<
708 FATAL_ERROR( Eigen::MatrixXd(primal_d1p.myContainer) == -minus_d1p_th_transpose.transpose() );
710 Eigen::MatrixXd d1_th_transpose(7, 6);
719 FATAL_ERROR( Eigen::MatrixXd(dual_d1.myContainer) == d1_th_transpose.transpose() );
723 const Calculus::PrimalHodge1 primal_h1 = primal_calculus.hodge<1,
PRIMAL>();
724 const Calculus::DualHodge1 dual_h1p = dual_calculus.hodge<1,
DUAL>();
725 const Calculus::DualHodge1 primal_h1p = primal_calculus.hodge<1,
DUAL>();
726 const Calculus::PrimalHodge1 dual_h1 = dual_calculus.hodge<1,
PRIMAL>();
733 FATAL_ERROR( Eigen::MatrixXd(primal_h1.myContainer) == Eigen::MatrixXd::Identity(7,7) );
734 FATAL_ERROR( Eigen::MatrixXd(dual_h1p.myContainer) == -Eigen::MatrixXd::Identity(7,7) );
735 FATAL_ERROR( Eigen::MatrixXd((primal_h1p*primal_h1).myContainer) == -Eigen::MatrixXd::Identity(7,7) );
736 FATAL_ERROR( Eigen::MatrixXd((dual_h1*dual_h1p).myContainer) == -Eigen::MatrixXd::Identity(7,7) );
737 FATAL_ERROR( Eigen::MatrixXd((primal_h1*primal_h1p).myContainer) == -Eigen::MatrixXd::Identity(7,7) );
738 FATAL_ERROR( Eigen::MatrixXd((dual_h1p*dual_h1).myContainer) == -Eigen::MatrixXd::Identity(7,7) );
759 Calculus::PrimalForm1::Container dx_container(7);
760 dx_container << -1, 0, 0, -1, 0, 1, 0;
761 const Calculus::PrimalForm1 primal_dx(primal_calculus, dx_container);
762 const Calculus::PrimalVectorField primal_dx_field = primal_calculus.sharp(primal_dx);
764 Calculus::PrimalForm1::Container dxp_container(7);
765 dxp_container << 1, -1, 0, 0, 1, 0, 0;
766 const Calculus::DualForm1 dual_dx(dual_calculus, dxp_container);
767 const Calculus::DualVectorField dual_dx_field = dual_calculus.sharp(dual_dx);
772 board << primal_calculus;
773 board << primal_dx << primal_dx_field;
774 board << dual_calculus;
775 board << dual_dx << dual_dx_field;
776 board.
saveSVG(
"operators_sharp_dx_primal.svg");
779#if defined(TEST_HARDCODED_ORDER)
780 FATAL_ERROR( primal_dx_field.myCoordinates.col(0) == Eigen::VectorXd::Ones(6) );
781 FATAL_ERROR( primal_dx_field.myCoordinates.col(1) == Eigen::VectorXd::Zero(6) );
782 FATAL_ERROR( dual_dx_field.myCoordinates.col(0) == Eigen::VectorXd::Ones(6) );
783 FATAL_ERROR( dual_dx_field.myCoordinates.col(1) == Eigen::VectorXd::Zero(6) );
788 Calculus::PrimalForm1::Container dy_container(7);
789 dy_container << 0, 1, 1, 0, -1, 0, -1;
790 const Calculus::PrimalForm1 primal_dy(primal_calculus, dy_container);
791 const Calculus::PrimalVectorField primal_dy_field = primal_calculus.sharp(primal_dy);
793 Calculus::PrimalForm1::Container dyp_container(7);
794 dyp_container << 0, 0, 1, 1, 0, -1, -1;
795 const Calculus::DualForm1 dual_dy(dual_calculus, dyp_container);
796 const Calculus::DualVectorField dual_dy_field = dual_calculus.sharp(dual_dy);
801 board << primal_calculus;
802 board << primal_dy << primal_dy_field;
803 board << dual_calculus;
804 board << dual_dy << dual_dy_field;
805 board.
saveSVG(
"operators_sharp_dy_primal.svg");
808#if defined(TEST_HARDCODED_ORDER)
809 FATAL_ERROR( primal_dy_field.myCoordinates.col(0) == Eigen::VectorXd::Zero(6) );
810 FATAL_ERROR( primal_dy_field.myCoordinates.col(1) == Eigen::VectorXd::Ones(6) );
811 FATAL_ERROR( dual_dy_field.myCoordinates.col(0) == Eigen::VectorXd::Zero(6) );
812 FATAL_ERROR( dual_dy_field.myCoordinates.col(1) == Eigen::VectorXd::Ones(6) );
824 Calculus::DualForm1::Container dx_container(7);
825 dx_container << 0, -1, -1, 0, 1, 0, 1;
826 const Calculus::DualForm1 primal_dx(primal_calculus, dx_container);
827 const Calculus::DualVectorField primal_dx_field = primal_calculus.sharp(primal_dx);
829 Calculus::DualForm1::Container dxp_container(7);
830 dxp_container << 0, 0, 1, 1, 0, -1, -1;
831 const Calculus::PrimalForm1 dual_dx(dual_calculus, dxp_container);
832 const Calculus::PrimalVectorField dual_dx_field = dual_calculus.sharp(dual_dx);
837 board << primal_calculus;
838 board << primal_dx << primal_dx_field;
839 board << dual_calculus;
840 board << dual_dx << dual_dx_field;
841 board.
saveSVG(
"operators_sharp_dx_dual.svg");
844#if defined(TEST_HARDCODED_ORDER)
845 FATAL_ERROR( primal_dx_field.myCoordinates.col(0) == Eigen::VectorXd::Ones(2) );
846 FATAL_ERROR( primal_dx_field.myCoordinates.col(1) == Eigen::VectorXd::Zero(2) );
847 FATAL_ERROR( dual_dx_field.myCoordinates.col(0) == Eigen::VectorXd::Ones(2) );
848 FATAL_ERROR( dual_dx_field.myCoordinates.col(1) == Eigen::VectorXd::Zero(2) );
853 Calculus::DualForm1::Container dy_container(7);
854 dy_container << -1, 0, 0, -1, 0 , 1, 0;
855 const Calculus::DualForm1 primal_dy(primal_calculus, dy_container);
856 const Calculus::DualVectorField primal_dy_field = primal_calculus.sharp(primal_dy);
858 Calculus::DualForm1::Container dyp_container(7);
859 dyp_container << -1, 1, 0, 0, -1, 0, 0;
860 const Calculus::PrimalForm1 dual_dy(dual_calculus, dyp_container);
861 const Calculus::PrimalVectorField dual_dy_field = dual_calculus.sharp(dual_dy);
866 board << primal_calculus;
867 board << primal_dy << primal_dy_field;
868 board << dual_calculus;
869 board << dual_dy << dual_dy_field;
870 board.
saveSVG(
"operators_sharp_dy_dual.svg");
873#if defined(TEST_HARDCODED_ORDER)
874 FATAL_ERROR( primal_dy_field.myCoordinates.col(0) == Eigen::VectorXd::Zero(2) );
875 FATAL_ERROR( primal_dy_field.myCoordinates.col(1) == Eigen::VectorXd::Ones(2) );
876 FATAL_ERROR( dual_dy_field.myCoordinates.col(0) == Eigen::VectorXd::Zero(2) );
877 FATAL_ERROR( dual_dy_field.myCoordinates.col(1) == Eigen::VectorXd::Ones(2) );
892 Calculus::PrimalVectorField::Coordinates dx_coords(6,2);
893 dx_coords.col(0) = Eigen::VectorXd::Ones(6);
894 dx_coords.col(1) = Eigen::VectorXd::Zero(6);
896 Calculus::PrimalVectorField::Coordinates dy_coords(6,2);
897 dy_coords.col(0) = Eigen::VectorXd::Zero(6);
898 dy_coords.col(1) = Eigen::VectorXd::Ones(6);
900 const Calculus::PrimalVectorField primal_dx_field(primal_calculus, dx_coords);
901 const Calculus::PrimalForm1 primal_dx = primal_calculus.flat(primal_dx_field);
902 const Calculus::DualVectorField dual_dx_field(dual_calculus, dx_coords);
903 const Calculus::DualForm1 dual_dx = dual_calculus.flat(dual_dx_field);
908 board << primal_calculus;
909 board << primal_dx << primal_dx_field;
910 board << dual_calculus;
911 board << dual_dx << dual_dx_field;
912 board.
saveSVG(
"operators_flat_dx_primal.svg");
915 const Calculus::PrimalVectorField primal_dy_field(primal_calculus, dy_coords);
916 const Calculus::PrimalForm1 primal_dy = primal_calculus.flat(primal_dy_field);
917 const Calculus::DualVectorField dual_dy_field(dual_calculus, dy_coords);
918 const Calculus::DualForm1 dual_dy = dual_calculus.flat(dual_dy_field);
923 board << primal_calculus;
924 board << primal_dy << primal_dy_field;
925 board << dual_calculus;
926 board << dual_dy << dual_dy_field;
927 board.
saveSVG(
"operators_flat_dy_primal.svg");
930#if defined(TEST_HARDCODED_ORDER)
931 Calculus::PrimalForm1::Container dx_container(7);
932 dx_container << -1, 0, 0, -1, 0, 1, 0;
933 Calculus::PrimalForm1::Container dxp_container(7);
934 dxp_container << 1, -1, 0, 0, 1, 0, 0;
935 FATAL_ERROR( primal_dx.myContainer == dx_container );
936 FATAL_ERROR( dual_dx.myContainer == dxp_container );
938 Calculus::PrimalForm1::Container dy_container(7);
939 dy_container << 0, 1, 1, 0, -1, 0, -1;
940 Calculus::PrimalForm1::Container dyp_container(7);
941 dyp_container << 0, 0, 1, 1, 0, -1, -1;
942 FATAL_ERROR( primal_dy.myContainer == dy_container );
943 FATAL_ERROR( dual_dy.myContainer == dyp_container );
953 Calculus::PrimalVectorField::Coordinates dx_coords(2,2);
954 dx_coords.col(0) = Eigen::VectorXd::Ones(2);
955 dx_coords.col(1) = Eigen::VectorXd::Zero(2);
957 Calculus::PrimalVectorField::Coordinates dy_coords(2,2);
958 dy_coords.col(0) = Eigen::VectorXd::Zero(2);
959 dy_coords.col(1) = Eigen::VectorXd::Ones(2);
961 const Calculus::DualVectorField primal_dx_field(primal_calculus, dx_coords);
962 const Calculus::DualForm1 primal_dx = primal_calculus.flat(primal_dx_field);
963 const Calculus::PrimalVectorField dual_dx_field(dual_calculus, dx_coords);
964 const Calculus::PrimalForm1 dual_dx = dual_calculus.flat(dual_dx_field);
969 board << primal_calculus;
970 board << primal_dx << primal_dx_field;
971 board << dual_calculus;
972 board << dual_dx << dual_dx_field;
973 board.
saveSVG(
"operators_flat_dx_dual.svg");
976 const Calculus::DualVectorField primal_dy_field(primal_calculus, dy_coords);
977 const Calculus::DualForm1 primal_dy = primal_calculus.flat(primal_dy_field);
978 const Calculus::PrimalVectorField dual_dy_field(dual_calculus, dy_coords);
979 const Calculus::PrimalForm1 dual_dy = dual_calculus.flat(dual_dy_field);
984 board << primal_calculus;
985 board << primal_dy << primal_dy_field;
986 board << dual_calculus;
987 board << dual_dy << dual_dy_field;
988 board.
saveSVG(
"operators_flat_dy_dual.svg");
991#if defined(TEST_HARDCODED_ORDER)
992 Calculus::PrimalForm1::Container dx_container(7);
993 dx_container << 0, -1, -1, 0, 1, 0, 1;
994 Calculus::PrimalForm1::Container dxp_container(7);
995 dxp_container << 0, 0, 1, 1, 0, -1, -1;
996 FATAL_ERROR( primal_dx.myContainer == dx_container );
997 FATAL_ERROR( dual_dx.myContainer == dxp_container );
999 Calculus::PrimalForm1::Container dy_container(7);
1000 dy_container << -1, 0, 0, -1, 0, 1, 0;
1001 Calculus::PrimalForm1::Container dyp_container(7);
1002 dyp_container << -1, 1, 0, 0, -1, 0, 0;
1003 FATAL_ERROR( primal_dy.myContainer == dy_container );
1004 FATAL_ERROR( dual_dy.myContainer == dyp_container );
1018#if !defined(TEST_HARDCODED_ORDER)
1019 trace.
warning() <<
"hardcoded order tests are NOT performed" << endl;
1025#if !defined(TEST_HARDCODED_ORDER)
1026 trace.
warning() <<
"hardcoded order tests are NOT performed" << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: This wraps a linear algebra solver around a discrete exterior calculus.
SolutionKForm solve(const InputKForm &input_kform) const
DiscreteExteriorCalculusSolver & compute(const Operator &linear_operator)
Aim: DiscreteExteriorCalculus represents a calculus in the dec package. This is the main structure in...
void initKSpace(ConstAlias< TDomain > domain)
DenseMatrix sharp(const Face f) const
void beginBlock(const std::string &keyword="")
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Eigen::SparseQR< SparseMatrix, Eigen::COLAMDOrdering< SparseMatrix::Index > > SolverSparseQR
void test_linear_structure()
void display_operator_info(const std::string &name, const Operator &op)
void test_manual_operators_2d()
void test_manual_operators_3d()