NEURON
spmatrix.h
Go to the documentation of this file.
1 /*
2  * EXPORTS for sparse matrix routines.
3  *
4  * Author: Advising professor:
5  * Kenneth S. Kundert Alberto Sangiovanni-Vincentelli
6  * UC Berkeley
7  *
8  * This file contains definitions that are useful to the calling
9  * program. In particular, this file contains error keyword
10  * definitions, some macro functions that are used to quickly enter
11  * data into the matrix and the type definition of a data structure
12  * that acts as a template for entering admittances into the matrix.
13  * Also included is the type definitions for the various functions
14  * available to the user.
15  */
16 
17 
18 /*
19  * Revision and copyright information.
20  *
21  * Copyright (c) 1985,86,87,88
22  * by Kenneth S. Kundert and the University of California.
23  *
24  * Permission to use, copy, modify, and distribute this software and
25  * its documentation for any purpose and without fee is hereby granted,
26  * provided that the copyright notices appear in all copies and
27  * supporting documentation and that the authors and the University of
28  * California are properly credited. The authors and the University of
29  * California make no representations as to the suitability of this
30  * software for any purpose. It is provided `as is', without express
31  * or implied warranty.
32  *
33  * $Date: 2003-02-11 19:36:05 +0100 (Tue, 11 Feb 2003) $
34  * $Revision: 3 $
35  */
36 
37 
38 
39 
40 #ifndef spOKAY
41 
42 /*
43  * IMPORTS
44  *
45  * >>> Import descriptions:
46  * spConfig.h
47  * Macros that customize the sparse matrix routines.
48  */
49 
50 #include "spconfig.h"
51 
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 
58 
59 /*
60  * ERROR KEYWORDS
61  *
62  * The actual numbers used in the error codes are not sacred, they can be
63  * changed under the condition that the codes for the nonfatal errors are
64  * less than the code for spFATAL and similarly the codes for the fatal
65  * errors are greater than that for spFATAL.
66  *
67  * >>> Error descriptions:
68  * spOKAY
69  * No error has occurred.
70  * spSMALL_PIVOT
71  * When reordering the matrix, no element was found which satisfies the
72  * absolute threshold criteria. The largest element in the matrix was
73  * chosen as pivot. Non-fatal.
74  * spZERO_DIAG
75  * Fatal error. A zero was encountered on the diagonal the matrix. This
76  * does not necessarily imply that the matrix is singular. When this
77  * error occurs, the matrix should be reconstructed and factored using
78  * spOrderAndFactor().
79  * spSINGULAR
80  * Fatal error. Matrix is singular, so no unique solution exists.
81  * spNO_MEMORY
82  * Fatal error. Indicates that not enough memory is available to handle
83  * the matrix.
84  * spPANIC
85  * Fatal error indicating that the routines are not prepared to
86  * handle the matrix that has been requested. This may occur when
87  * the matrix is specified to be real and the routines are not
88  * compiled for real matrices, or when the matrix is specified to
89  * be complex and the routines are not compiled to handle complex
90  * matrices.
91  * spFATAL
92  * Not an error flag, but rather the dividing line between fatal errors
93  * and warnings.
94  */
95 
96 /* Begin error macros. */
97 #define spOKAY 0
98 #define spSMALL_PIVOT 1
99 #define spZERO_DIAG 2
100 #define spSINGULAR 3
101 #define spNO_MEMORY 4
102 #define spPANIC 5
103 
104 #define spFATAL 2
105 
106 
107 
108 
109 
110 
111 
112 /*
113  * KEYWORD DEFINITIONS
114  *
115  * Here we define what precision arithmetic Sparse will use. Double
116  * precision is suggested as being most appropriate for circuit
117  * simulation and for C. However, it is possible to change spREAL
118  * to a float for single precision arithmetic. Note that in C, single
119  * precision arithmetic is often slower than double precision. Sparse
120  * internally refers to spREALs as RealNumbers.
121  *
122  * Some C compilers, notably the old VMS compiler, do not handle the keyword
123  * "void" correctly. If this is true for your compiler, remove the
124  * comment delimiters from the redefinition of void to int below.
125  */
126 
127 #define spREAL double
128 /* #define void int */
129 
130 
131 
132 
133 
134 /*
135  * PARTITION TYPES
136  *
137  * When factoring a previously ordered matrix using spFactor(), Sparse
138  * operates on a row-at-a-time basis. For speed, on each step, the row
139  * being updated is copied into a full vector and the operations are
140  * performed on that vector. This can be done one of two ways, either
141  * using direct addressing or indirect addressing. Direct addressing
142  * is fastest when the matrix is relatively dense and indirect addressing
143  * is quite sparse. The user can select which partitioning mode is used.
144  * The following keywords are passed to spPartition() and indicate that
145  * Sparse should use only direct addressing, only indirect addressing, or
146  * that it should choose the best mode on a row-by-row basis. The time
147  * required to choose a partition is of the same order of the cost to factor
148  * the matrix.
149  *
150  * If you plan to factor a large number of matrices with the same structure,
151  * it is best to let Sparse choose the partition. Otherwise, you should
152  * choose the partition based on the predicted density of the matrix.
153  */
154 
155 /* Begin partition keywords. */
156 
157 #define spDEFAULT_PARTITION 0
158 #define spDIRECT_PARTITION 1
159 #define spINDIRECT_PARTITION 2
160 #define spAUTO_PARTITION 3
161 
162 
163 
164 
165 
166 /*
167  * MACRO FUNCTION DEFINITIONS
168  *
169  * >>> Macro descriptions:
170  * spADD_REAL_ELEMENT
171  * Macro function that adds data to a real element in the matrix by a
172  * pointer.
173  * spADD_IMAG_ELEMENT
174  * Macro function that adds data to a imaginary element in the matrix by
175  * a pointer.
176  * spADD_COMPLEX_ELEMENT
177  * Macro function that adds data to a complex element in the matrix by a
178  * pointer.
179  * spADD_REAL_QUAD
180  * Macro function that adds data to each of the four real matrix elements
181  * specified by the given template.
182  * spADD_IMAG_QUAD
183  * Macro function that adds data to each of the four imaginary matrix
184  * elements specified by the given template.
185  * spADD_COMPLEX_QUAD
186  * Macro function that adds data to each of the four complex matrix
187  * elements specified by the given template.
188  */
189 
190 /* Begin Macros. */
191 #define spADD_REAL_ELEMENT(element,real) *(element) += real
192 
193 #define spADD_IMAG_ELEMENT(element,imag) *(element+1) += imag
194 
195 #define spADD_COMPLEX_ELEMENT(element,real,imag) \
196 { *(element) += real; \
197  *(element+1) += imag; \
198 }
199 
200 #define spADD_REAL_QUAD(template,real) \
201 { *((template).Element1) += real; \
202  *((template).Element2) += real; \
203  *((template).Element3Negated) -= real; \
204  *((template).Element4Negated) -= real; \
205 }
206 
207 #define spADD_IMAG_QUAD(template,imag) \
208 { *((template).Element1+1) += imag; \
209  *((template).Element2+1) += imag; \
210  *((template).Element3Negated+1) -= imag; \
211  *((template).Element4Negated+1) -= imag; \
212 }
213 
214 #define spADD_COMPLEX_QUAD(template,real,imag) \
215 { *((template).Element1) += real; \
216  *((template).Element2) += real; \
217  *((template).Element3Negated) -= real; \
218  *((template).Element4Negated) -= real; \
219  *((template).Element1+1) += imag; \
220  *((template).Element2+1) += imag; \
221  *((template).Element3Negated+1) -= imag; \
222  *((template).Element4Negated+1) -= imag; \
223 }
224 
225 
226 
227 
228 
229 
230 
231 /*
232  * TYPE DEFINITION FOR COMPONENT TEMPLATE
233  *
234  * This data structure is used to hold pointers to four related elements in
235  * matrix. It is used in conjunction with the routines
236  * spGetAdmittance
237  * spGetQuad
238  * spGetOnes
239  * These routines stuff the structure which is later used by the spADD_QUAD
240  * macro functions above. It is also possible for the user to collect four
241  * pointers returned by spGetElement and stuff them into the template.
242  * The spADD_QUAD routines stuff data into the matrix in locations specified
243  * by Element1 and Element2 without changing the data. The data is negated
244  * before being placed in Element3 and Element4.
245  */
246 
247 /* Begin `spTemplate'. */
253 };
254 
255 
256 
257 
258 
259 /*
260  * FUNCTION TYPE DEFINITIONS
261  *
262  * The type of every user accessible function is declared here.
263  */
264 
265 /* Begin function declarations. */
266 
267 #if defined(__STDC__) || defined(__cplusplus)
268 
269 /* For compilers that understand function prototypes. */
270 
271 extern void spClear( char* );
272 extern spREAL spCondition( char*, spREAL, int* );
273 extern char *spCreate( int, int, int* );
274 extern void spDeleteRowAndCol( char*, int, int );
275 extern void spDestroy( char* );
276 extern int spElementCount( char* );
277 extern int spError( char* );
278 extern int spFactor( char* );
279 extern int spFileMatrix( char*, char*, char*, int, int, int );
280 extern int spFileStats( char*, char*, char* );
281 extern int spFillinCount( char* );
282 extern int spGetAdmittance( char*, int, int, struct spTemplate* );
283 extern spREAL *spGetElement( char*, int, int );
284 extern char *spGetInitInfo( spREAL* );
285 extern int spGetOnes( char*, int, int, int, struct spTemplate* );
286 extern int spGetQuad( char*, int, int, int, int, struct spTemplate* );
287 extern int spGetSize( char*, int );
288 extern int spInitialize( char*, int (*)() );
289 extern void spInstallInitInfo( spREAL*, char* );
290 extern spREAL spLargestElement( char* );
291 extern void spMNA_Preorder( char* );
292 extern spREAL spNorm( char* );
293 extern int spOrderAndFactor( char*, spREAL[], spREAL, spREAL, int );
294 extern void spPartition( char*, int );
295 extern void spPrint( char*, int, int, int );
296 extern spREAL spPseudoCondition( char* );
297 extern spREAL spRoundoff( char*, spREAL );
298 extern void spScale( char*, spREAL[], spREAL[] );
299 extern void spSetComplex( char* );
300 extern void spSetReal( char* );
301 extern void spStripFills( char* );
302 extern void spWhereSingular( char*, int*, int* );
303 
304 /* Functions with argument lists that are dependent on options. */
305 
306 #if spCOMPLEX
307 extern void spDeterminant ( char*, int*, spREAL*, spREAL* );
308 #else /* NOT spCOMPLEX */
309 extern void spDeterminant ( char*, int*, spREAL* );
310 #endif /* NOT spCOMPLEX */
311 #if spCOMPLEX && spSEPARATED_COMPLEX_VECTORS
312 extern int spFileVector( char*, char* , spREAL[], spREAL[]);
313 extern void spMultiply( char*, spREAL[], spREAL[], spREAL[], spREAL[] );
314 extern void spMultTransposed(char*,spREAL[],spREAL[],spREAL[],spREAL[]);
315 extern void spSolve( char*, spREAL[], spREAL[], spREAL[], spREAL[] );
316 extern void spSolveTransposed(char*,spREAL[],spREAL[],spREAL[],spREAL[]);
317 #else /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
318 extern int spFileVector( char*, char* , spREAL[] );
319 extern void spMultiply( char*, spREAL[], spREAL[] );
320 extern void spMultTransposed( char*, spREAL[], spREAL[] );
321 extern void spSolve( char*, spREAL[], spREAL[] );
322 extern void spSolveTransposed( char*, spREAL[], spREAL[] );
323 #endif /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
324 
325 #else /* NOT defined(__STDC__) */
326 
327 /* For compilers that do not understand function prototypes. */
328 
329 extern void spClear();
330 extern spREAL spCondition();
331 extern char *spCreate();
332 extern void spDeleteRowAndCol();
333 extern void spDestroy();
334 extern void spDeterminant ();
335 extern int spElementCount();
336 extern int spError();
337 extern int spFactor();
338 extern int spFileMatrix();
339 extern int spFileStats();
340 extern int spFileVector();
341 extern int spFillinCount();
342 extern int spGetAdmittance();
343 extern spREAL *spGetElement(char*, int, int);
344 extern char *spGetInitInfo();
345 extern int spGetOnes();
346 extern int spGetQuad();
347 extern int spGetSize();
348 extern int spInitialize();
349 extern void spInstallInitInfo();
350 extern spREAL spLargestElement();
351 extern void spMNA_Preorder();
352 extern void spMultiply();
353 extern void spMultTransposed();
354 extern spREAL spNorm();
355 extern int spOrderAndFactor();
356 extern void spPartition();
357 extern void spPrint();
358 extern spREAL spPseudoCondition();
359 extern spREAL spRoundoff();
360 extern void spScale();
361 extern void spSetComplex();
362 extern void spSetReal();
363 extern void spSolve();
364 extern void spSolveTransposed();
365 extern void spStripFills();
366 extern void spWhereSingular();
367 #endif /* defined(__STDC__) */
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif /* spOKAY */
int spError()
int spFileVector()
spREAL spCondition()
void spMultTransposed()
void spPrint()
int spGetOnes()
int spFileMatrix()
spREAL spRoundoff()
int spElementCount()
void spStripFills()
spREAL * spGetElement(char *, int, int)
Definition: spbuild.c:195
int spInitialize()
void spInstallInitInfo()
int spGetAdmittance()
void spSetReal()
void spScale()
spREAL spNorm()
int spGetQuad()
void spDeterminant()
void spDeleteRowAndCol()
spREAL * Element4Negated
Definition: spmatrix.h:252
int spFillinCount()
void spMultiply()
#define spREAL
Definition: spmatrix.h:127
int spFactor()
int spGetSize()
void spClear()
void spPartition()
spREAL spPseudoCondition()
void spSolveTransposed()
void spSetComplex()
int spOrderAndFactor()
spREAL spLargestElement()
spREAL * Element1
Definition: spmatrix.h:249
char * spCreate()
void spDestroy()
int spFileStats()
spREAL * Element3Negated
Definition: spmatrix.h:251
void spWhereSingular()
spREAL * Element2
Definition: spmatrix.h:250
void spSolve()
void spMNA_Preorder()
char * spGetInitInfo()