spmatrix.h

Go to the documentation of this file.
00001 #ifndef __SPMATRIX_H__
00002 #define __SPMATRIX_H__
00003 
00004 /*
00005  *  EXPORTS for sparse matrix routines.
00006  *
00007  *  Author:                     Advising professor:
00008  *      Kenneth S. Kundert          Alberto Sangiovanni-Vincentelli
00009  *      UC Berkeley
00010  *
00011  *  This file contains definitions that are useful to the calling
00012  *  program.  In particular, this file contains error keyword
00013  *  definitions, some macro functions that are used to quickly enter
00014  *  data into the matrix and the type definition of a data structure
00015  *  that acts as a template for entering admittances into the matrix.
00016  *  Also included is the type definitions for the various functions
00017  *  available to the user.
00018  */
00019 
00020 
00021 /*
00022  *  Revision and copyright information.
00023  *
00024  *  Copyright (c) 1985,86,87,88
00025  *  by Kenneth S. Kundert and the University of California.
00026  *
00027  *  Permission to use, copy, modify, and distribute this software and
00028  *  its documentation for any purpose and without fee is hereby granted,
00029  *  provided that the copyright notices appear in all copies and
00030  *  supporting documentation and that the authors and the University of
00031  *  California are properly credited.  The authors and the University of
00032  *  California make no representations as to the suitability of this
00033  *  software for any purpose.  It is provided `as is', without express
00034  *  or implied warranty.
00035  *
00036  */
00037 
00038 
00039 
00040 
00041 #ifndef  spOKAY
00042 
00043 /*
00044  *  IMPORTS
00045  *
00046  *  >>> Import descriptions:
00047  *  spConfig.h
00048  *      Macros that customize the sparse matrix routines.
00049  */
00050 
00051 #include "spConfig.h"
00052 
00053 
00054 
00055 
00056 
00057 
00058 /*
00059  *  ERROR KEYWORDS
00060  *
00061  *  The actual numbers used in the error codes are not sacred, they can be
00062  *  changed under the condition that the codes for the nonfatal errors are
00063  *  less than the code for spFATAL and similarly the codes for the fatal
00064  *  errors are greater than that for spFATAL.
00065  *
00066  *  >>> Error descriptions:
00067  *  spOKAY
00068  *      No error has occurred.
00069  *  spSMALL_PIVOT
00070  *      When reordering the matrix, no element was found which satisfies the
00071  *      absolute threshold criteria.  The largest element in the matrix was
00072  *      chosen as pivot.  Non-fatal.
00073  *  spZERO_DIAG
00074  *      Fatal error.  A zero was encountered on the diagonal the matrix.  This
00075  *      does not necessarily imply that the matrix is singular.  When this
00076  *      error occurs, the matrix should be reconstructed and factored using
00077  *      spOrderAndFactor().
00078  *  spSINGULAR
00079  *      Fatal error.  Matrix is singular, so no unique solution exists.
00080  *  spNO_MEMORY
00081  *      Fatal error.  Indicates that not enough memory is available to handle
00082  *      the matrix.
00083  *  spPANIC
00084  *      Fatal error indicating that the routines are not prepared to
00085  *      handle the matrix that has been requested.  This may occur when
00086  *      the matrix is specified to be real and the routines are not
00087  *      compiled for real matrices, or when the matrix is specified to
00088  *      be complex and the routines are not compiled to handle complex
00089  *      matrices.
00090  *  spFATAL
00091  *      Not an error flag, but rather the dividing line between fatal errors
00092  *      and warnings.
00093  */
00094 
00095 /* Begin error macros. */
00096 #define  spOKAY                 0
00097 #define  spSMALL_PIVOT          1
00098 #define  spZERO_DIAG            2
00099 #define  spSINGULAR             3
00100 #define  spNO_MEMORY            4
00101 #define  spPANIC                5
00102 
00103 #define  spFATAL                2
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 /*
00112  *  KEYWORD DEFINITIONS
00113  *
00114  *  Here we define what precision arithmetic Sparse will use.  Double
00115  *  precision is suggested as being most appropriate for circuit
00116  *  simulation and for C.  However, it is possible to change spREAL
00117  *  to a float for single precision arithmetic.  Note that in C, single
00118  *  precision arithmetic is often slower than double precision.  Sparse
00119  *  internally refers to spREALs as RealNumbers.
00120  *
00121  *  Some C compilers, notably the old VMS compiler, do not handle the keyword
00122  *  "void" correctly.  If this is true for your compiler, remove the
00123  *  comment delimiters from the redefinition of void to int below.
00124  */
00125 
00126 #define  spREAL double
00127 /* #define  void    int   */
00128 
00129 
00130 
00131 
00132 
00133 /*
00134  *  PARTITION TYPES
00135  *
00136  *  When factoring a previously ordered matrix using spFactor(), Sparse
00137  *  operates on a row-at-a-time basis.  For speed, on each step, the row
00138  *  being updated is copied into a full vector and the operations are
00139  *  performed on that vector.  This can be done one of two ways, either
00140  *  using direct addressing or indirect addressing.  Direct addressing
00141  *  is fastest when the matrix is relatively dense and indirect addressing
00142  *  is quite sparse.  The user can select which partitioning mode is used.
00143  *  The following keywords are passed to spPartition() and indicate that
00144  *  Sparse should use only direct addressing, only indirect addressing, or
00145  *  that it should choose the best mode on a row-by-row basis.  The time
00146  *  required to choose a partition is of the same order of the cost to factor
00147  *  the matrix.
00148  *
00149  *  If you plan to factor a large number of matrices with the same structure,
00150  *  it is best to let Sparse choose the partition.  Otherwise, you should
00151  *  choose the partition based on the predicted density of the matrix.
00152  */
00153 
00154 /* Begin partition keywords. */
00155 
00156 #define spDEFAULT_PARTITION     0
00157 #define spDIRECT_PARTITION      1
00158 #define spINDIRECT_PARTITION    2
00159 #define spAUTO_PARTITION        3
00160 
00161 
00162 
00163 
00164 
00165 /*
00166  *  MACRO FUNCTION DEFINITIONS
00167  *
00168  *  >>> Macro descriptions:
00169  *  spADD_REAL_ELEMENT
00170  *      Macro function that adds data to a real element in the matrix by a
00171  *      pointer.
00172  *  spADD_IMAG_ELEMENT
00173  *      Macro function that adds data to a imaginary element in the matrix by
00174  *      a pointer.
00175  *  spADD_COMPLEX_ELEMENT
00176  *      Macro function that adds data to a complex element in the matrix by a
00177  *      pointer.
00178  *  spADD_REAL_QUAD
00179  *      Macro function that adds data to each of the four real matrix elements
00180  *      specified by the given template.
00181  *  spADD_IMAG_QUAD
00182  *      Macro function that adds data to each of the four imaginary matrix
00183  *      elements specified by the given template.
00184  *  spADD_COMPLEX_QUAD
00185  *      Macro function that adds data to each of the four complex matrix
00186  *      elements specified by the given template.
00187  */
00188 
00189 /* Begin Macros. */
00190 #define  spADD_REAL_ELEMENT(element,real)       *(element) += real
00191 
00192 #define  spADD_IMAG_ELEMENT(element,imag)       *(element+1) += imag
00193 
00194 #define  spADD_COMPLEX_ELEMENT(element,real,imag)       \
00195 {   *(element) += real;                                 \
00196     *(element+1) += imag;                               \
00197 }
00198 
00199 #define  spADD_REAL_QUAD(template,real)         \
00200 {   *((template).Element1) += real;             \
00201     *((template).Element2) += real;             \
00202     *((template).Element3Negated) -= real;      \
00203     *((template).Element4Negated) -= real;      \
00204 }
00205 
00206 #define  spADD_IMAG_QUAD(template,imag)         \
00207 {   *((template).Element1+1) += imag;           \
00208     *((template).Element2+1) += imag;           \
00209     *((template).Element3Negated+1) -= imag;    \
00210     *((template).Element4Negated+1) -= imag;    \
00211 }
00212 
00213 #define  spADD_COMPLEX_QUAD(template,real,imag) \
00214 {   *((template).Element1) += real;             \
00215     *((template).Element2) += real;             \
00216     *((template).Element3Negated) -= real;      \
00217     *((template).Element4Negated) -= real;      \
00218     *((template).Element1+1) += imag;           \
00219     *((template).Element2+1) += imag;           \
00220     *((template).Element3Negated+1) -= imag;    \
00221     *((template).Element4Negated+1) -= imag;    \
00222 }
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 /*
00231  *   TYPE DEFINITION FOR COMPONENT TEMPLATE
00232  *
00233  *   This data structure is used to hold pointers to four related elements in
00234  *   matrix.  It is used in conjunction with the routines
00235  *       spGetAdmittance
00236  *       spGetQuad
00237  *       spGetOnes
00238  *   These routines stuff the structure which is later used by the spADD_QUAD
00239  *   macro functions above.  It is also possible for the user to collect four
00240  *   pointers returned by spGetElement and stuff them into the template.
00241  *   The spADD_QUAD routines stuff data into the matrix in locations specified
00242  *   by Element1 and Element2 without changing the data.  The data is negated
00243  *   before being placed in Element3 and Element4.
00244  */
00245 
00246 /* Begin `spTemplate'. */
00247 struct  spTemplate
00248 {   spREAL    *Element1       ;
00249     spREAL    *Element2       ;
00250     spREAL    *Element3Negated;
00251     spREAL    *Element4Negated;
00252 };
00253 
00254 
00255 
00256 
00257 
00258 /*
00259  *   FUNCTION TYPE DEFINITIONS
00260  *
00261  *   The type of every user accessible function is declared here.
00262  */
00263 
00264 /* Begin function declarations. */
00265 
00266 #ifdef __STDC__
00267 
00268 /* For compilers that understand function prototypes. */
00269 
00270 extern  void     spClear( char* );
00271 extern  spREAL   spCondition( char*, spREAL, int* );
00272 extern  char    *spCreate( int, int, int* );
00273 extern  void     spDeleteRowAndCol( char*, int, int );
00274 extern  void     spDestroy( char* );
00275 extern  int      spElementCount( char* );
00276 extern  int      spError( char* );
00277 extern  int      spFactor( char* );
00278 extern  int      spFileMatrix( char*, char*, char*, int, int, int );
00279 extern  int      spFileStats( char*, char*, char* );
00280 extern  int      spFillinCount( char* );
00281 extern  int      spGetAdmittance( char*, int, int, struct spTemplate* );
00282 extern  spREAL  *spGetElement( char*, int, int );
00283 extern  char    *spGetInitInfo( spREAL* );
00284 extern  int      spGetOnes( char*, int, int, int, struct spTemplate* );
00285 extern  int      spGetQuad( char*, int, int, int, int, struct spTemplate* );
00286 extern  int      spGetSize( char*, int );
00287 extern  int      spInitialize( char*, int (*)() );
00288 extern  void     spInstallInitInfo( spREAL*, char* );
00289 extern  spREAL   spLargestElement( char* );
00290 extern  void     spMNA_Preorder( char* );
00291 extern  spREAL   spNorm( char* );
00292 extern  int      spOrderAndFactor( char*, spREAL[], spREAL, spREAL, int );
00293 extern  void     spPartition( char*, int );
00294 extern  void     spPrint( char*, int, int, int );
00295 extern  spREAL   spPseudoCondition( char* );
00296 extern  spREAL   spRoundoff( char*, spREAL );
00297 extern  void     spScale( char*, spREAL[], spREAL[] );
00298 extern  void     spSetComplex( char* );
00299 extern  void     spSetReal( char* );
00300 extern  void     spStripFills( char* );
00301 extern  void     spWhereSingular( char*, int*, int* );
00302 
00303 /* Functions with argument lists that are dependent on options. */
00304 
00305 #if spCOMPLEX
00306 extern  void     spDeterminant ( char*, int*, spREAL*, spREAL* );
00307 #else /* NOT spCOMPLEX */
00308 extern  void     spDeterminant ( char*, int*, spREAL* );
00309 #endif /* NOT spCOMPLEX */
00310 #if spCOMPLEX && spSEPARATED_COMPLEX_VECTORS
00311 extern  int      spFileVector( char*, char* , spREAL[], spREAL[]);
00312 extern  void     spMultiply( char*, spREAL[], spREAL[], spREAL[], spREAL[] );
00313 extern  void     spMultTransposed(char*,spREAL[],spREAL[],spREAL[],spREAL[]);
00314 extern  void     spSolve( char*, spREAL[], spREAL[], spREAL[], spREAL[] );
00315 extern  void     spSolveTransposed(char*,spREAL[],spREAL[],spREAL[],spREAL[]);
00316 #else /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
00317 extern  int      spFileVector( char*, char* , spREAL[] );
00318 extern  void     spMultiply( char*, spREAL[], spREAL[] );
00319 extern  void     spMultTransposed( char*, spREAL[], spREAL[] );
00320 extern  void     spSolve( char*, spREAL[], spREAL[] );
00321 extern  void     spSolveTransposed( char*, spREAL[], spREAL[] );
00322 #endif /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
00323 
00324 #else /* NOT defined(__STDC__) */
00325 
00326 /* For compilers that do not understand function prototypes. */
00327 
00328 extern  void     spClear();
00329 extern  spREAL   spCondition();
00330 extern  char    *spCreate();
00331 extern  void     spDeleteRowAndCol();
00332 extern  void     spDestroy();
00333 extern  void     spDeterminant ();
00334 extern  int      spElementCount();
00335 extern  int      spError();
00336 extern  int      spFactor();
00337 extern  int      spFileMatrix();
00338 extern  int      spFileStats();
00339 extern  int      spFileVector();
00340 extern  int      spFillinCount();
00341 extern  int      spGetAdmittance();
00342 extern  spREAL  *spGetElement();
00343 extern  char    *spGetInitInfo();
00344 extern  int      spGetOnes();
00345 extern  int      spGetQuad();
00346 extern  int      spGetSize();
00347 extern  int      spInitialize();
00348 extern  void     spInstallInitInfo();
00349 extern  spREAL   spLargestElement();
00350 extern  void     spMNA_Preorder();
00351 extern  void     spMultiply();
00352 extern  void     spMultTransposed();
00353 extern  spREAL   spNorm();
00354 extern  int      spOrderAndFactor();
00355 extern  void     spPartition();
00356 extern  void     spPrint();
00357 extern  spREAL   spPseudoCondition();
00358 extern  spREAL   spRoundoff();
00359 extern  void     spScale();
00360 extern  void     spSetComplex();
00361 extern  void     spSetReal();
00362 extern  void     spSolve();
00363 extern  void     spSolveTransposed();
00364 extern  void     spStripFills();
00365 extern  void     spWhereSingular();
00366 #endif /* defined(__STDC__) */
00367 
00368 #endif  /* spOKAY */
00369 
00370 #endif /*  __SPMATRIX_H__ */

Generated on Sun Mar 4 15:04:00 2007 for Scilab [trunk] by  doxygen 1.5.1