Skip to content
Snippets Groups Projects
Commit 8ec22431 authored by Matti Pellika's avatar Matti Pellika
Browse files

Actually added the files mentioned in previous commit just now.

Also added an example file celldriver.cpp and transformer.geo
in /utils/misc
parent 3000d2c8
Branches
Tags
No related merge requests found
File added
function [P, L, U] = kbihnf(A)
% [P, L, U] = kbihnf(A)
%
% Computes the integer Hermite normal form L such that
%
% P*A = L*U
%
% Uses external Kannan-Bachem implementation
% Copyright (C) 3.11.2003 Saku Suuriniemi TUT/CEM
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% Saku Suuriniemi, TUT/Electromagetics
% P.O.Box 692, FIN-33101 Tampere, Finland
% saku.suuriniemi@tut.fi
[i,j,v] = find(A);
fid = fopen('hnf_temp.crd', 'w');
fprintf(fid, '%g %g %g\n', size(A,1), size(A,2), length(i));
if ~isempty(v)
fprintf(fid, '%g %g %g\n', [i'; j'; v']);
end
fclose(fid);
system ("./compute_normal_form -Hl hnf_temp.crd");
load hnf_temp.left;
P = zeros(hnf_temp(1,1), hnf_temp(1,2));
for i = 2:size(hnf_temp,1)
P(hnf_temp(i,1), hnf_temp(i,2)) = hnf_temp(i,3);
end
load hnf_temp.can;
L = zeros(hnf_temp(1,1), hnf_temp(1,2));
for i = 2:size(hnf_temp,1)
L(hnf_temp(i,1), hnf_temp(i,2)) = hnf_temp(i,3);
end
load hnf_temp.right;
U = zeros(hnf_temp(1,1), hnf_temp(1,2));
for i = 2:size(hnf_temp,1)
U(hnf_temp(i,1), hnf_temp(i,2)) = hnf_temp(i,3);
end
function [U, S, V] = kbisnf(A)
% [U, S, V] = kbisnf(A)
%
% Computes the integer Smith normal form S such that
%
% A = U*S*V
%
% Uses external Kannan-Bachem implementation
% Copyright (C) 4.11.2003 Saku Suuriniemi TUT/CEM
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
% Saku Suuriniemi, TUT/Electromagetics
% P.O.Box 692, FIN-33101 Tampere, Finland
% saku.suuriniemi@tut.fi
[i,j,v] = find(A);
fid = fopen('snf_temp.crd', 'w');
fprintf(fid, '%g %g %g\n', size(A,1), size(A,2), length(i));
if ~isempty(v)
fprintf(fid, '%g %g %g\n', [i'; j'; v']);
end
fclose(fid);
system ('./compute_normal_form -S snf_temp.crd');
load snf_temp.left;
U = zeros(snf_temp(1,1), snf_temp(1,2));
for i = 2:size(snf_temp,1)
U(snf_temp(i,1), snf_temp(i,2)) = snf_temp(i,3);
end
load snf_temp.can;
S = zeros(snf_temp(1,1), snf_temp(1,2));
for i = 2:size(snf_temp,1)
S(snf_temp(i,1), snf_temp(i,2)) = snf_temp(i,3);
end
load snf_temp.right;
V = zeros(snf_temp(1,1), snf_temp(1,2));
for i = 2:size(snf_temp,1)
V(snf_temp(i,1), snf_temp(i,2)) = snf_temp(i,3);
end
This diff is collapsed.
-----------
KBIPack 1.0
-----------
This is an ANSI C-implementation of Kannan-Bachem algorithms for Hermite
and Smith normal forms for integer matrices. I wrote it to be the core of
an integer homology group solver. You are welcome to improve this package,
but I am unfortunately unable to invest much more time to it myself. The
license is GNU GPL (see below).
The algorithms are Kannan - Bachem algorithms with improvement by Chou and
Collins. The Smith normal form routine expects a large number of unit
invariant factors (this occurs in my application) and takes advantage of
them as they appear.
References:
-----------
[1] Ravindran Kannan, Achim Bachem:
"Polynomial algorithms for computing the Smith and Hermite normal
forms of an integer matrix",
SIAM J. Comput., vol. 8, no. 5, pp. 499-507, 1979.
[2] Tsu-Wu J.Chou, George E. Collins:
"Algorithms for the solution of systems of linear Diophantine equations",
SIAM J. Comput., vol. 11, no. 4, pp. 687-708, 1982.
[3] GMP homepage http://www.swox.com/gmp/
[4] GNU gmp page http://www.gnu.org/software/gmp/
Technicalities:
---------------
The package relies on GNU multiple precision library gmp to represent large
integers. You must have gmp installed before you compile.
It should run smoothly on UNIX systems with working standard I/O, and
in Cygwin (http://www.cygwin.com/).
You can use this package in at least three ways:
1) You can call the functions bkihnf and bkisnf in respective .m-files
from MatLab or Octave. Note that the numbers in the results may be too
large to be exactly read back by them.
2) You can use the executable "compute normal form" just like any command.
Use the -h flag to get info.
3) You can use just the core routines from your own application.
Contents:
---------
bkihnf.m Integer Hermite normal form for Octave/MatLab
bkisnf.m Integer Smith normal form for Octave/MatLab
compute_normal_form.c A main program for a comand-line version
gmp_blas.c Low-level routines for integer arrays
gmp_blas.h
gmp_matrix.c Integer matrix type
gmp_matrix.h
gmp_matrix_io.c I/O for integer matrices
gmp_matrix_io.h
gmp_normal_form.c The core computation routine
gmp_normal_form.h
LICENCE The GNU General Public License version 2
Makefile A rudimentary Makefile (just type "make")
README This file
Installation:
-------------
First install gmp (http://www.swox.com/gmp/ or a binary package).
If you use gcc, just type "make". If not, alter the Makefile as necessary.
Licensing:
----------
Copyright (C) 2005 Saku Suuriniemi
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Saku Suuriniemi, TUT/Electromagetics
P.O.Box 692, FIN-33101 Tampere, Finland
saku.suuriniemi@tut.fi
http://www.em.tut.fi/Eng/
Background:
-----------
The package is a part of my PhD project, so if you find this package useful
and wish to refer to my thesis (also available on my homepage), here is the
BiBTeX entry:
@phdthesis{Suuriniemi:PhD2004,
author="Saku Suuriniemi",
school="Tampere University of Technology",
title="Homological computations in electromagnetic modeling",
address="Tampere",
year=2004,
isbn="952-15-1237-7"
}
Thanks:
-------
Thanks are due to Chistophe Geuzaine for testing and comments.
// configure, compile and install Gmsh as a library with
//
// ./configure --disable-gui --disable-netgen --disable-chaco
// --disable-metis --disable-tetgen --prefix=/usr/local/
// make install-lib
//
// Then compile this driver with "g++ kaka.cpp -lGmsh -llapack -lblas -lgmp"
#include <stdio.h>
#include <gmsh/Gmsh.h>
#include <gmsh/GModel.h>
#include <gmsh/MElement.h>
#include <gmsh/CellComplex.h>
int main(int argc, char **argv)
{
GmshInitialize(argc, argv);
GModel *m = new GModel();
m->readGEO("transformer.geo");
m->mesh(3);
m->writeMSH("transformer.msh");
printf("This model has: %d GRegions, %d GFaces, %d GEdges and %d GVertices. \n" , m->getNumRegions(), m->getNumFaces(), m->getNumEdges(), m->getNumVertices());
std::vector<GEntity*> domain;
std::vector<GEntity*> subdomain;
// whole model
for(GModel::riter rit = m->firstRegion(); rit != m->lastRegion(); rit++){
GEntity *r = *rit;
domain.push_back(r);
}
// the ports
GModel::fiter sub = m->firstFace();
GEntity *s = *sub;
subdomain.push_back(s);
s = *(++sub);
subdomain.push_back(s);
s =*(++sub);
subdomain.push_back(s);
s= *(++sub);
subdomain.push_back(s);
CellComplex complex = CellComplex(domain, subdomain);
printf("Cell complex of this model has: %d volumes, %d faces, %d edges and %d vertices\n",
complex.getSize(3), complex.getSize(2), complex.getSize(1), complex.getSize(0));
complex.reduceComplex();
complex.writeComplexMSH("reduced_complex.msh");
complex.coreduceComplex();
complex.writeComplexMSH("coreduced_complex.msh");
delete m;
GmshFinalize();
}
// Gmsh project created on Thu Mar 26 10:01:45 2009
m=0.5;
Point(newp) = {0, 0, 0, m};
Point(newp) = {10, 0, 0, m};
Point(newp) = {10, 10, 0, m};
Point(newp) = {0, 10, 0, m};
Point(newp) = {4, 4, 0, m};
Point(newp) = {6, 4, 0, m};
Point(newp) = {6, 6, 0, m};
Point(newp) = {4, 6, 0, m};
Point(newp) = {2, 0, 0, m};
Point(newp) = {8, 0, 0, m};
Point(newp) = {2, 10, 0, m};
Point(newp) = {8, 10, 0, m};
Point(newp) = {0, 0, 1, m};
Point(newp) = {10, 0, 1, m};
Point(newp) = {10, 10, 1, m};
Point(newp) = {0, 10, 1, m};
Point(newp) = {4, 4, 1, m};
Point(newp) = {6, 4, 1, m};
Point(newp) = {6, 6, 1, m};
Point(newp) = {4, 6, 1, m};
Point(newp) = {2, 0, 1, m};
Point(newp) = {8, 0, 1, m};
Point(newp) = {2, 10, 1, m};
Point(newp) = {8, 10, 1, m};
Line(1) = {16, 23};
Line(2) = {23, 11};
Line(3) = {11, 4};
Line(4) = {4, 16};
Line(5) = {24, 12};
Line(6) = {12, 3};
Line(7) = {3, 15};
Line(8) = {15, 24};
Line(9) = {10, 2};
Line(10) = {2, 14};
Line(11) = {14, 22};
Line(12) = {22, 10};
Line(13) = {21, 9};
Line(14) = {9, 1};
Line(15) = {1, 13};
Line(16) = {13, 21};
Line Loop(17) = {3, 4, 1, 2};
Ruled Surface(18) = {17};
Line Loop(19) = {6, 7, 8, 5};
Ruled Surface(20) = {19};
Line Loop(21) = {9, 10, 11, 12};
Ruled Surface(22) = {21};
Line Loop(23) = {14, 15, 16, 13};
Ruled Surface(24) = {23};
Line(25) = {16, 13};
Line(26) = {1, 4};
Line(27) = {11, 12};
Line(28) = {24, 23};
Line(29) = {21, 22};
Line(30) = {10, 9};
Line(31) = {2, 3};
Line(32) = {15, 14};
Line(33) = {20, 19};
Line(34) = {19, 18};
Line(35) = {18, 17};
Line(36) = {17, 20};
Line(37) = {8, 7};
Line(38) = {7, 6};
Line(39) = {6, 18};
Line(40) = {5, 6};
Line(41) = {5, 8};
Line(42) = {20, 8};
Line(43) = {17, 5};
Line(44) = {19, 7};
Line Loop(45) = {27, -5, 28, 2};
Ruled Surface(46) = {45};
Line Loop(47) = {25, -15, 26, 4};
Ruled Surface(48) = {47};
Line Loop(49) = {29, 12, 30, -13};
Ruled Surface(50) = {49};
Line Loop(51) = {32, -10, 31, 7};
Ruled Surface(52) = {51};
Line Loop(53) = {41, -42, -36, 43};
Ruled Surface(54) = {53};
Line Loop(55) = {35, 43, 40, 39};
Ruled Surface(56) = {55};
Line Loop(57) = {34, -39, -38, -44};
Ruled Surface(58) = {57};
Line Loop(59) = {33, 44, -37, -42};
Ruled Surface(60) = {59};
Line Loop(61) = {28, -1, 25, 16, 29, -11, -32, 8};
Line Loop(62) = {33, 34, 35, 36};
Ruled Surface(63) = {61, 62};
Line Loop(64) = {3, -26, -14, -30, 9, 31, -6, -27};
Line Loop(65) = {37, 38, -40, 41};
Ruled Surface(66) = {64, 65};
Surface Loop(67) = {63, 46, 66, 18, 48, 24, 50, 22, 52, 20, 54, 60, 58, 56};
Volume(68) = {67};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment