#!/usr/bin/perl -w
#!/usr/local/bin/perl -w
#!/usr/bin/env perl
#
# Read an SQLite database file containing an fea model and compute
# sparse matrix indexing information in preparation for assembling
# the stiffness matrix.
# Albert Danial Nov 15 2003
#
use strict;
use Getopt::Std;
use vars qw ( $opt_l );
use DBI;
use DBD::SQLite 1.00;
getopts('l');

die "$0 [-l] <.db file>

              Determine stiffness matrix indexing data.

              -l  Only show terms for the lower triangle.

" unless @ARGV;

my $db_file       = shift @ARGV;
die "Expecting .db file to have a .db extenstion (got $db_file)\n"
    unless $db_file =~ /\.db$/i;

my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","");

# remap the node connectivity table from seq_no to renumbered node IDs
my $raa_connect = $dbh->selectall_arrayref(
     "select a.new_id id_a, b.new_id id_b from renumbered_nid    a, 
                                               renumbered_nid    b, 
                                               node_connectivity c 
             where a.orig_id=c.nid_a and 
	           b.orig_id=c.nid_b
             order by id_a,id_b");

my $st  = $dbh->disconnect;

foreach my $pair (@{$raa_connect}) {
    next if $opt_l and ($pair->[0] > $pair->[1]);
    printf "% 3d % 3d\n", $pair->[0], -$pair->[1];
}
# use Data::Dumper; print Dumper($raa_connect);
