epanet-plus 0.0.1__cp313-cp313-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of epanet-plus might be problematic. Click here for more details.
- docs/conf.py +67 -0
- epanet-msx-src/dispersion.h +27 -0
- epanet-msx-src/hash.c +107 -0
- epanet-msx-src/hash.h +28 -0
- epanet-msx-src/include/epanetmsx.h +104 -0
- epanet-msx-src/include/epanetmsx_export.h +42 -0
- epanet-msx-src/mathexpr.c +937 -0
- epanet-msx-src/mathexpr.h +39 -0
- epanet-msx-src/mempool.c +204 -0
- epanet-msx-src/mempool.h +24 -0
- epanet-msx-src/msxchem.c +1285 -0
- epanet-msx-src/msxcompiler.c +368 -0
- epanet-msx-src/msxdict.h +42 -0
- epanet-msx-src/msxdispersion.c +586 -0
- epanet-msx-src/msxerr.c +116 -0
- epanet-msx-src/msxfile.c +260 -0
- epanet-msx-src/msxfuncs.c +175 -0
- epanet-msx-src/msxfuncs.h +35 -0
- epanet-msx-src/msxinp.c +1504 -0
- epanet-msx-src/msxout.c +398 -0
- epanet-msx-src/msxproj.c +791 -0
- epanet-msx-src/msxqual.c +2011 -0
- epanet-msx-src/msxrpt.c +400 -0
- epanet-msx-src/msxtank.c +422 -0
- epanet-msx-src/msxtoolkit.c +1164 -0
- epanet-msx-src/msxtypes.h +551 -0
- epanet-msx-src/msxutils.c +524 -0
- epanet-msx-src/msxutils.h +56 -0
- epanet-msx-src/newton.c +158 -0
- epanet-msx-src/newton.h +34 -0
- epanet-msx-src/rk5.c +287 -0
- epanet-msx-src/rk5.h +39 -0
- epanet-msx-src/ros2.c +293 -0
- epanet-msx-src/ros2.h +35 -0
- epanet-msx-src/smatrix.c +816 -0
- epanet-msx-src/smatrix.h +29 -0
- epanet-src/AUTHORS +60 -0
- epanet-src/LICENSE +21 -0
- epanet-src/enumstxt.h +151 -0
- epanet-src/epanet.c +5937 -0
- epanet-src/epanet2.c +961 -0
- epanet-src/epanet2.def +131 -0
- epanet-src/errors.dat +79 -0
- epanet-src/flowbalance.c +186 -0
- epanet-src/funcs.h +219 -0
- epanet-src/genmmd.c +1000 -0
- epanet-src/hash.c +177 -0
- epanet-src/hash.h +28 -0
- epanet-src/hydcoeffs.c +1303 -0
- epanet-src/hydraul.c +1164 -0
- epanet-src/hydsolver.c +781 -0
- epanet-src/hydstatus.c +442 -0
- epanet-src/include/epanet2.h +466 -0
- epanet-src/include/epanet2_2.h +1962 -0
- epanet-src/include/epanet2_enums.h +518 -0
- epanet-src/inpfile.c +884 -0
- epanet-src/input1.c +672 -0
- epanet-src/input2.c +970 -0
- epanet-src/input3.c +2265 -0
- epanet-src/leakage.c +527 -0
- epanet-src/mempool.c +146 -0
- epanet-src/mempool.h +24 -0
- epanet-src/output.c +853 -0
- epanet-src/project.c +1691 -0
- epanet-src/quality.c +695 -0
- epanet-src/qualreact.c +800 -0
- epanet-src/qualroute.c +696 -0
- epanet-src/report.c +1559 -0
- epanet-src/rules.c +1500 -0
- epanet-src/smatrix.c +871 -0
- epanet-src/text.h +508 -0
- epanet-src/types.h +928 -0
- epanet-src/util/cstr_helper.c +59 -0
- epanet-src/util/cstr_helper.h +38 -0
- epanet-src/util/errormanager.c +92 -0
- epanet-src/util/errormanager.h +39 -0
- epanet-src/util/filemanager.c +212 -0
- epanet-src/util/filemanager.h +81 -0
- epanet-src/validate.c +408 -0
- epanet.cpython-313-x86_64-linux-musl.so +0 -0
- epanet_plus/VERSION +1 -0
- epanet_plus/__init__.py +8 -0
- epanet_plus/epanet_plus.c +118 -0
- epanet_plus/epanet_toolkit.py +2730 -0
- epanet_plus/epanet_wrapper.py +2414 -0
- epanet_plus/include/epanet_plus.h +9 -0
- epanet_plus-0.0.1.dist-info/METADATA +152 -0
- epanet_plus-0.0.1.dist-info/RECORD +105 -0
- epanet_plus-0.0.1.dist-info/WHEEL +5 -0
- epanet_plus-0.0.1.dist-info/licenses/LICENSE +21 -0
- epanet_plus-0.0.1.dist-info/top_level.txt +11 -0
- examples/basic_usage.py +35 -0
- python-extension/ext.c +344 -0
- python-extension/pyepanet.c +2133 -0
- python-extension/pyepanet.h +143 -0
- python-extension/pyepanet2.c +1823 -0
- python-extension/pyepanet2.h +141 -0
- python-extension/pyepanet_plus.c +37 -0
- python-extension/pyepanet_plus.h +4 -0
- python-extension/pyepanetmsx.c +388 -0
- python-extension/pyepanetmsx.h +35 -0
- tests/test_epanet.py +16 -0
- tests/test_epanetmsx.py +36 -0
- tests/test_epyt.py +114 -0
- tests/test_load_inp_from_buffer.py +18 -0
epanet-msx-src/smatrix.c
ADDED
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*******************************************************************
|
|
3
|
+
Modified from:
|
|
4
|
+
|
|
5
|
+
SMATRIX.C -- Sparse matrix routines for EPANET program, VERSION: 2.0.0.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
DATE: 5/8/00
|
|
9
|
+
AUTHOR: L. Rossman
|
|
10
|
+
US EPA - NRMRL
|
|
11
|
+
|
|
12
|
+
This module contains the sparse matrix routines used to solve
|
|
13
|
+
a network's hydraulic equations. The entry points into this
|
|
14
|
+
module are:
|
|
15
|
+
msx_createsparse() -- called from openhyd() in HYDRAUL.C
|
|
16
|
+
msx_freesparse() -- called from closehyd() in HYDRAUL.C
|
|
17
|
+
msx_linsolve() -- called from netsolve() in HYDRAUL.C
|
|
18
|
+
|
|
19
|
+
Createsparse() does the following:
|
|
20
|
+
1. for each node, builds an adjacency list that identifies
|
|
21
|
+
all links connected to the node (see buildlists())
|
|
22
|
+
2. re-orders the network's nodes to minimize the number
|
|
23
|
+
of non-zero entries in the hydraulic solution matrix
|
|
24
|
+
(see reorder())
|
|
25
|
+
3. converts the adjacency lists into a compact scheme
|
|
26
|
+
for storing the non-zero coeffs. in the lower diagonal
|
|
27
|
+
portion of the solution matrix (see storesparse())
|
|
28
|
+
Freesparse() frees the memory used for the sparse matrix.
|
|
29
|
+
Linsolve() solves the linearized system of hydraulic equations.
|
|
30
|
+
|
|
31
|
+
********************************************************************
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include <string.h>
|
|
36
|
+
#include <stdlib.h>
|
|
37
|
+
#include <math.h>
|
|
38
|
+
|
|
39
|
+
#include "hash.h"
|
|
40
|
+
#include "msxtypes.h"
|
|
41
|
+
#include "smatrix.h"
|
|
42
|
+
#include "dispersion.h"
|
|
43
|
+
#define EXTERN extern
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// External variables
|
|
48
|
+
//--------------------
|
|
49
|
+
extern MSXproject MSX; // MSX project data
|
|
50
|
+
#define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
int msx_createsparse()
|
|
56
|
+
/*
|
|
57
|
+
**--------------------------------------------------------------
|
|
58
|
+
** Input: none
|
|
59
|
+
** Output: returns error code
|
|
60
|
+
** Purpose: creates sparse representation of coeff. matrix
|
|
61
|
+
**--------------------------------------------------------------
|
|
62
|
+
*/
|
|
63
|
+
{
|
|
64
|
+
int errcode = 0;
|
|
65
|
+
int njuncs = MSX.Nobjects[NODE] - MSX.Nobjects[TANK];
|
|
66
|
+
|
|
67
|
+
/* Allocate data structures */
|
|
68
|
+
ERRCODE(allocsparse());
|
|
69
|
+
if (errcode) return(errcode);
|
|
70
|
+
|
|
71
|
+
/* Build node-link adjacency lists with parallel links removed. */
|
|
72
|
+
|
|
73
|
+
ERRCODE(buildlists(TRUE)); //TRUE localadjlists in 2.2
|
|
74
|
+
if (!errcode)
|
|
75
|
+
{
|
|
76
|
+
xparalinks(); /* Remove parallel links */
|
|
77
|
+
countdegree(); /* Find degree of each junction */
|
|
78
|
+
} /* (= # of adjacent links) */
|
|
79
|
+
|
|
80
|
+
/* Re-order nodes to minimize number of non-zero coeffs. */
|
|
81
|
+
/* in factorized solution matrix. At same time, adjacency */
|
|
82
|
+
/* list is updated with links representing non-zero coeffs. */
|
|
83
|
+
MSX.Dispersion.Ncoeffs = MSX.Nobjects[LINK];
|
|
84
|
+
ERRCODE(reordernodes());
|
|
85
|
+
|
|
86
|
+
/* Allocate memory for sparse storage of positions of non-zero */
|
|
87
|
+
/* coeffs. and store these positions in vector NZSUB. */
|
|
88
|
+
ERRCODE(storesparse(njuncs));
|
|
89
|
+
|
|
90
|
+
/* Free memory used for adjacency lists and sort */
|
|
91
|
+
/* row indexes in NZSUB to optimize msx_linsolve(). */
|
|
92
|
+
if (!errcode) freelists();
|
|
93
|
+
ERRCODE(ordersparse(njuncs));
|
|
94
|
+
|
|
95
|
+
MSX.Dispersion.Aij = (double*)calloc(MSX.Dispersion.Ncoeffs + 1, sizeof(double));
|
|
96
|
+
MSX.Dispersion.Aii = (double*)calloc(MSX.Nobjects[NODE]+1, sizeof(double));
|
|
97
|
+
MSX.Dispersion.F = (double*)calloc(MSX.Nobjects[NODE]+1, sizeof(double));
|
|
98
|
+
MSX.Dispersion.temp = (double*)calloc(MSX.Nobjects[NODE] + 1, sizeof(double));
|
|
99
|
+
MSX.Dispersion.link = (int*)calloc(MSX.Nobjects[NODE] + 1, sizeof(int));
|
|
100
|
+
MSX.Dispersion.first = (int*)calloc(MSX.Nobjects[NODE] + 1, sizeof(int));
|
|
101
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Aij));
|
|
102
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Aii));
|
|
103
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.F));
|
|
104
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.temp));
|
|
105
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.link));
|
|
106
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.first));
|
|
107
|
+
|
|
108
|
+
// MSX.Dispersion.md = (double*)calloc(MSX.Nobjects[SPECIES] + 1, sizeof(double));
|
|
109
|
+
|
|
110
|
+
MSX.Dispersion.pipeDispersionCoeff = (double*)calloc(MSX.Nobjects[LINK] + 1, sizeof(double));
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.ld));
|
|
115
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.md));
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
dispersion_open();
|
|
119
|
+
|
|
120
|
+
/* Re-build adjacency lists without removing parallel */
|
|
121
|
+
/* links for use in future connectivity checking. */
|
|
122
|
+
ERRCODE(buildlists(FALSE)); //FALSE buildadjlists in 2.2
|
|
123
|
+
|
|
124
|
+
/* Free allocated memory */
|
|
125
|
+
free(MSX.Dispersion.Degree);
|
|
126
|
+
return(errcode);
|
|
127
|
+
} /* End of msx_createsparse */
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
int allocsparse()
|
|
131
|
+
/*
|
|
132
|
+
**--------------------------------------------------------------
|
|
133
|
+
** Input: none
|
|
134
|
+
** Output: returns error code
|
|
135
|
+
** Purpose: allocates memory for indexing the solution matrix
|
|
136
|
+
**--------------------------------------------------------------
|
|
137
|
+
*/
|
|
138
|
+
{
|
|
139
|
+
int errcode = 0;
|
|
140
|
+
int nnodes = MSX.Nobjects[NODE];
|
|
141
|
+
int nlinks = MSX.Nobjects[LINK];
|
|
142
|
+
MSX.Dispersion.Aii = NULL;
|
|
143
|
+
MSX.Dispersion.Aij = NULL;
|
|
144
|
+
MSX.Dispersion.F = NULL;
|
|
145
|
+
MSX.Dispersion.temp = NULL;
|
|
146
|
+
MSX.Dispersion.link = NULL;
|
|
147
|
+
MSX.Dispersion.first = NULL;
|
|
148
|
+
|
|
149
|
+
MSX.Dispersion.Adjlist = (Padjlist *) calloc(nnodes+1, sizeof(Padjlist));
|
|
150
|
+
MSX.Dispersion.Order = (int *) calloc(nnodes+1, sizeof(int));
|
|
151
|
+
MSX.Dispersion.Row = (int *) calloc(nnodes+1, sizeof(int));
|
|
152
|
+
MSX.Dispersion.Ndx = (int *) calloc(nlinks+1, sizeof(int));
|
|
153
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Adjlist));
|
|
154
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Order));
|
|
155
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Row));
|
|
156
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Ndx));
|
|
157
|
+
return(errcode);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
void msx_freesparse()
|
|
162
|
+
/*
|
|
163
|
+
**----------------------------------------------------------------
|
|
164
|
+
** Input: None
|
|
165
|
+
** Output: None
|
|
166
|
+
** Purpose: Frees memory used for sparse matrix storage
|
|
167
|
+
**----------------------------------------------------------------
|
|
168
|
+
*/
|
|
169
|
+
{
|
|
170
|
+
freelists();
|
|
171
|
+
FREE(MSX.Dispersion.Adjlist);
|
|
172
|
+
FREE(MSX.Dispersion.Order);
|
|
173
|
+
FREE(MSX.Dispersion.Row);
|
|
174
|
+
FREE(MSX.Dispersion.Ndx);
|
|
175
|
+
FREE(MSX.Dispersion.XLNZ);
|
|
176
|
+
FREE(MSX.Dispersion.NZSUB);
|
|
177
|
+
FREE(MSX.Dispersion.LNZ);
|
|
178
|
+
FREE(MSX.Dispersion.Aii);
|
|
179
|
+
FREE(MSX.Dispersion.Aij);
|
|
180
|
+
FREE(MSX.Dispersion.F);
|
|
181
|
+
FREE(MSX.Dispersion.link);
|
|
182
|
+
FREE(MSX.Dispersion.first);
|
|
183
|
+
FREE(MSX.Dispersion.temp);
|
|
184
|
+
|
|
185
|
+
FREE(MSX.Dispersion.md);
|
|
186
|
+
|
|
187
|
+
FREE(MSX.Dispersion.pipeDispersionCoeff);
|
|
188
|
+
dispersion_close();
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
} /* End of msx_freesparse */
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
int buildlists(int paraflag)
|
|
197
|
+
/*
|
|
198
|
+
**--------------------------------------------------------------
|
|
199
|
+
** Input: paraflag = TRUE if list marks parallel links
|
|
200
|
+
** Output: returns error code
|
|
201
|
+
** Purpose: builds linked list of links adjacent to each node
|
|
202
|
+
**--------------------------------------------------------------
|
|
203
|
+
*/
|
|
204
|
+
{
|
|
205
|
+
int i,j,k;
|
|
206
|
+
int pmark = 0;
|
|
207
|
+
int errcode = 0;
|
|
208
|
+
int nlinks = MSX.Nobjects[LINK];
|
|
209
|
+
Padjlist alink;
|
|
210
|
+
|
|
211
|
+
freelists();
|
|
212
|
+
MSX.Dispersion.Adjlist = (Padjlist*)calloc(MSX.Nobjects[NODE] + 1, sizeof(Padjlist));
|
|
213
|
+
if (MSX.Dispersion.Adjlist == NULL) return 101;
|
|
214
|
+
for (i = 0; i <= MSX.Nobjects[NODE]; i++)
|
|
215
|
+
MSX.Dispersion.Adjlist[i] = NULL;
|
|
216
|
+
|
|
217
|
+
/* For each link, update adjacency lists of its end nodes */
|
|
218
|
+
for (k=1; k<=nlinks; k++)
|
|
219
|
+
{
|
|
220
|
+
i = MSX.Link[k].n1;
|
|
221
|
+
j = MSX.Link[k].n2;
|
|
222
|
+
if (paraflag) pmark = paralink(i,j,k); /* Parallel link check */
|
|
223
|
+
|
|
224
|
+
/* Include link in start node i's list */
|
|
225
|
+
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
|
|
226
|
+
if (alink == NULL) return(101);
|
|
227
|
+
if (!pmark) alink->node = j;
|
|
228
|
+
else alink->node = 0; /* Parallel link marker */
|
|
229
|
+
alink->link = k;
|
|
230
|
+
alink->next = MSX.Dispersion.Adjlist[i];
|
|
231
|
+
MSX.Dispersion.Adjlist[i] = alink;
|
|
232
|
+
|
|
233
|
+
/* Include link in end node j's list */
|
|
234
|
+
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
|
|
235
|
+
if (alink == NULL) return(101);
|
|
236
|
+
if (!pmark) alink->node = i;
|
|
237
|
+
else alink->node = 0; /* Parallel link marker */
|
|
238
|
+
alink->link = k;
|
|
239
|
+
alink->next = MSX.Dispersion.Adjlist[j];
|
|
240
|
+
MSX.Dispersion.Adjlist[j] = alink;
|
|
241
|
+
}
|
|
242
|
+
if (errcode)freelists();
|
|
243
|
+
return(errcode);
|
|
244
|
+
} /* End of buildlists */
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
int paralink(int i, int j, int k)
|
|
248
|
+
/*
|
|
249
|
+
**--------------------------------------------------------------
|
|
250
|
+
** Input: i = index of start node of link
|
|
251
|
+
** j = index of end node of link
|
|
252
|
+
** k = link index
|
|
253
|
+
** Output: returns 1 if link k parallels another link, else 0
|
|
254
|
+
** Purpose: checks for parallel links between nodes i and j
|
|
255
|
+
**
|
|
256
|
+
**--------------------------------------------------------------
|
|
257
|
+
*/
|
|
258
|
+
{
|
|
259
|
+
Padjlist alink;
|
|
260
|
+
for (alink = MSX.Dispersion.Adjlist[i]; alink != NULL; alink = alink->next)
|
|
261
|
+
{
|
|
262
|
+
if (alink->node == j) /* Link || to k (same end nodes) */
|
|
263
|
+
{
|
|
264
|
+
MSX.Dispersion.Ndx[k] = alink->link; /* Assign Ndx entry to this link */
|
|
265
|
+
return(1);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
MSX.Dispersion.Ndx[k] = k; /* Ndx entry if link not parallel */
|
|
269
|
+
return(0);
|
|
270
|
+
} /* End of paralink */
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
void xparalinks()
|
|
274
|
+
/*
|
|
275
|
+
**--------------------------------------------------------------
|
|
276
|
+
** Input: none
|
|
277
|
+
** Output: none
|
|
278
|
+
** Purpose: removes parallel links from nodal adjacency lists
|
|
279
|
+
**--------------------------------------------------------------
|
|
280
|
+
*/
|
|
281
|
+
{
|
|
282
|
+
int i;
|
|
283
|
+
Padjlist alink, /* Current item in adjacency list */
|
|
284
|
+
blink; /* Previous item in adjacency list */
|
|
285
|
+
int nnodes = MSX.Nobjects[NODE];
|
|
286
|
+
|
|
287
|
+
/* Scan adjacency list of each node */
|
|
288
|
+
for (i=1; i<=nnodes; i++)
|
|
289
|
+
{
|
|
290
|
+
alink = MSX.Dispersion.Adjlist[i]; /* First item in list */
|
|
291
|
+
blink = NULL;
|
|
292
|
+
while (alink != NULL)
|
|
293
|
+
{
|
|
294
|
+
if (alink->node == 0) /* Parallel link marker found */
|
|
295
|
+
{
|
|
296
|
+
if (blink == NULL) /* This holds at start of list */
|
|
297
|
+
{
|
|
298
|
+
MSX.Dispersion.Adjlist[i] = alink->next;
|
|
299
|
+
free(alink); /* Remove item from list */
|
|
300
|
+
alink = MSX.Dispersion.Adjlist[i];
|
|
301
|
+
}
|
|
302
|
+
else /* This holds for interior of list */
|
|
303
|
+
{
|
|
304
|
+
blink->next = alink->next;
|
|
305
|
+
free(alink); /* Remove item from list */
|
|
306
|
+
alink = blink->next;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else
|
|
310
|
+
{
|
|
311
|
+
blink = alink; /* Move to next item in list */
|
|
312
|
+
alink = alink->next;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} /* End of xparalinks */
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
void freelists()
|
|
320
|
+
/*
|
|
321
|
+
**--------------------------------------------------------------
|
|
322
|
+
** Input: none
|
|
323
|
+
** Output: none
|
|
324
|
+
** Purpose: frees memory used for nodal adjacency lists
|
|
325
|
+
**--------------------------------------------------------------
|
|
326
|
+
*/
|
|
327
|
+
{
|
|
328
|
+
int i;
|
|
329
|
+
Padjlist alink;
|
|
330
|
+
int nnodes = MSX.Nobjects[NODE];
|
|
331
|
+
|
|
332
|
+
if (MSX.Dispersion.Adjlist == NULL)
|
|
333
|
+
return;
|
|
334
|
+
for (i=0; i<=nnodes; i++)
|
|
335
|
+
{
|
|
336
|
+
for (alink = MSX.Dispersion.Adjlist[i]; alink != NULL; alink = MSX.Dispersion.Adjlist[i])
|
|
337
|
+
{
|
|
338
|
+
MSX.Dispersion.Adjlist[i] = alink->next;
|
|
339
|
+
free(alink);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
free(MSX.Dispersion.Adjlist);
|
|
343
|
+
MSX.Dispersion.Adjlist = NULL;
|
|
344
|
+
} /* End of freelists */
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
void countdegree()
|
|
348
|
+
/*
|
|
349
|
+
**----------------------------------------------------------------
|
|
350
|
+
** Input: none
|
|
351
|
+
** Output: none
|
|
352
|
+
** Purpose: counts number of nodes directly connected to each node
|
|
353
|
+
**----------------------------------------------------------------
|
|
354
|
+
*/
|
|
355
|
+
{
|
|
356
|
+
int i;
|
|
357
|
+
Padjlist alink;
|
|
358
|
+
|
|
359
|
+
int nnodes = MSX.Nobjects[NODE];
|
|
360
|
+
int njuncs = MSX.Nobjects[NODE]-MSX.Nobjects[TANK];
|
|
361
|
+
int errcode;
|
|
362
|
+
|
|
363
|
+
errcode = 0;
|
|
364
|
+
|
|
365
|
+
MSX.Dispersion.Degree = (int *)calloc(MSX.Nobjects[NODE] + 1, sizeof(int));
|
|
366
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.Degree));
|
|
367
|
+
memset(MSX.Dispersion.Degree,0,(nnodes+1)*sizeof(int));
|
|
368
|
+
|
|
369
|
+
/* NOTE: For purposes of node re-ordering, Tanks (nodes with */
|
|
370
|
+
/* indexes above Njuncs) have zero degree of adjacency. */
|
|
371
|
+
|
|
372
|
+
for (i=1; i<=njuncs; i++)
|
|
373
|
+
for (alink = MSX.Dispersion.Adjlist[i]; alink != NULL; alink = alink->next)
|
|
374
|
+
if (alink->node > 0) MSX.Dispersion.Degree[i]++;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
int reordernodes()
|
|
379
|
+
/*
|
|
380
|
+
**--------------------------------------------------------------
|
|
381
|
+
** Input: none
|
|
382
|
+
** Output: returns 1 if successful, 0 if not
|
|
383
|
+
** Purpose: re-orders nodes to minimize # of non-zeros that
|
|
384
|
+
** will appear in factorized solution matrix
|
|
385
|
+
**--------------------------------------------------------------
|
|
386
|
+
*/
|
|
387
|
+
{
|
|
388
|
+
int k, knode, m, n;
|
|
389
|
+
int nnodes = MSX.Nobjects[NODE];
|
|
390
|
+
int njuncs = MSX.Nobjects[NODE] - MSX.Nobjects[TANK];
|
|
391
|
+
for (k=1; k<=nnodes; k++)
|
|
392
|
+
{
|
|
393
|
+
MSX.Dispersion.Row[k] = k;
|
|
394
|
+
MSX.Dispersion.Order[k] = k;
|
|
395
|
+
}
|
|
396
|
+
n = njuncs;
|
|
397
|
+
for (k=1; k<=n; k++) /* Examine each junction */
|
|
398
|
+
{
|
|
399
|
+
m = mindegree(k,n); /* Node with lowest degree */
|
|
400
|
+
knode = MSX.Dispersion.Order[m]; /* Node's index */
|
|
401
|
+
if (!growlist(knode)) return(101); /* Augment adjacency list */
|
|
402
|
+
MSX.Dispersion.Order[m] = MSX.Dispersion.Order[k]; /* Switch order of nodes */
|
|
403
|
+
MSX.Dispersion.Order[k] = knode;
|
|
404
|
+
MSX.Dispersion.Degree[knode] = 0; /* In-activate node */
|
|
405
|
+
}
|
|
406
|
+
for (k=1; k<=n; k++) /* Assign nodes to rows of */
|
|
407
|
+
MSX.Dispersion.Row[MSX.Dispersion.Order[k]] = k; /* coeff. matrix */
|
|
408
|
+
return(0);
|
|
409
|
+
} /* End of reordernodes */
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
int mindegree(int k, int n)
|
|
413
|
+
/*
|
|
414
|
+
**--------------------------------------------------------------
|
|
415
|
+
** Input: k = first node in list of active nodes
|
|
416
|
+
** n = total number of junction nodes
|
|
417
|
+
** Output: returns node index with fewest direct connections
|
|
418
|
+
** Purpose: finds active node with fewest direct connections
|
|
419
|
+
**--------------------------------------------------------------
|
|
420
|
+
*/
|
|
421
|
+
{
|
|
422
|
+
int i, m;
|
|
423
|
+
int min = n,
|
|
424
|
+
imin = n;
|
|
425
|
+
|
|
426
|
+
for (i=k; i<=n; i++)
|
|
427
|
+
{
|
|
428
|
+
m = MSX.Dispersion.Degree[MSX.Dispersion.Order[i]];
|
|
429
|
+
if (m < min)
|
|
430
|
+
{
|
|
431
|
+
min = m;
|
|
432
|
+
imin = i;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return(imin);
|
|
436
|
+
} /* End of mindegree */
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
int growlist(int knode)
|
|
440
|
+
/*
|
|
441
|
+
**--------------------------------------------------------------
|
|
442
|
+
** Input: knode = node index
|
|
443
|
+
** Output: returns 1 if successful, 0 if not
|
|
444
|
+
** Purpose: creates new entries in knode's adjacency list for
|
|
445
|
+
** all unlinked pairs of active nodes that are
|
|
446
|
+
** adjacent to knode
|
|
447
|
+
**--------------------------------------------------------------
|
|
448
|
+
*/
|
|
449
|
+
{
|
|
450
|
+
int node;
|
|
451
|
+
Padjlist alink;
|
|
452
|
+
|
|
453
|
+
/* Iterate through all nodes connected to knode */
|
|
454
|
+
for (alink = MSX.Dispersion.Adjlist[knode]; alink != NULL; alink = alink -> next)
|
|
455
|
+
{
|
|
456
|
+
node = alink->node; /* End node of connecting link */
|
|
457
|
+
if (MSX.Dispersion.Degree[node] > 0) /* End node is active */
|
|
458
|
+
{
|
|
459
|
+
MSX.Dispersion.Degree[node]--; /* Reduce degree of adjacency */
|
|
460
|
+
if (!newlink(alink)) /* Add to adjacency list */
|
|
461
|
+
return(0);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return(1);
|
|
465
|
+
} /* End of growlist */
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
int newlink(Padjlist alink)
|
|
469
|
+
/*
|
|
470
|
+
**--------------------------------------------------------------
|
|
471
|
+
** Input: alink = element of node's adjacency list
|
|
472
|
+
** Output: returns 1 if successful, 0 if not
|
|
473
|
+
** Purpose: links end of current adjacent link to end nodes of
|
|
474
|
+
** all links that follow it on adjacency list
|
|
475
|
+
**--------------------------------------------------------------
|
|
476
|
+
*/
|
|
477
|
+
{
|
|
478
|
+
int inode, jnode;
|
|
479
|
+
Padjlist blink;
|
|
480
|
+
|
|
481
|
+
/* Scan all entries in adjacency list that follow anode. */
|
|
482
|
+
inode = alink->node; /* End node of connection to anode */
|
|
483
|
+
for (blink = alink->next; blink != NULL; blink = blink->next)
|
|
484
|
+
{
|
|
485
|
+
jnode = blink->node; /* End node of next connection */
|
|
486
|
+
|
|
487
|
+
/* If jnode still active, and inode not connected to jnode, */
|
|
488
|
+
/* then add a new connection between inode and jnode. */
|
|
489
|
+
if (MSX.Dispersion.Degree[jnode] > 0) /* jnode still active */
|
|
490
|
+
{
|
|
491
|
+
if (!linked(inode,jnode)) /* inode not linked to jnode */
|
|
492
|
+
{
|
|
493
|
+
|
|
494
|
+
/* Since new connection represents a non-zero coeff. */
|
|
495
|
+
/* in the solution matrix, update the coeff. count. */
|
|
496
|
+
MSX.Dispersion.Ncoeffs++;
|
|
497
|
+
|
|
498
|
+
/* Update adjacency lists for inode & jnode to */
|
|
499
|
+
/* reflect the new connection. */
|
|
500
|
+
if (!addlink(inode,jnode,MSX.Dispersion.Ncoeffs)) return(0);
|
|
501
|
+
if (!addlink(jnode,inode,MSX.Dispersion.Ncoeffs)) return(0);
|
|
502
|
+
MSX.Dispersion.Degree[inode]++;
|
|
503
|
+
MSX.Dispersion.Degree[jnode]++;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return(1);
|
|
508
|
+
} /* End of newlink */
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
int linked(int i, int j)
|
|
512
|
+
/*
|
|
513
|
+
**--------------------------------------------------------------
|
|
514
|
+
** Input: i = node index
|
|
515
|
+
** j = node index
|
|
516
|
+
** Output: returns 1 if nodes i and j are linked, 0 if not
|
|
517
|
+
** Purpose: checks if nodes i and j are already linked.
|
|
518
|
+
**--------------------------------------------------------------
|
|
519
|
+
*/
|
|
520
|
+
{
|
|
521
|
+
Padjlist alink;
|
|
522
|
+
for (alink = MSX.Dispersion.Adjlist[i]; alink != NULL; alink = alink->next)
|
|
523
|
+
if (alink->node == j) return(1);
|
|
524
|
+
return(0);
|
|
525
|
+
} /* End of linked */
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
int addlink(int i, int j, int n)
|
|
529
|
+
/*
|
|
530
|
+
**--------------------------------------------------------------
|
|
531
|
+
** Input: i = node index
|
|
532
|
+
** j = node index
|
|
533
|
+
** n = link index
|
|
534
|
+
** Output: returns 1 if successful, 0 if not
|
|
535
|
+
** Purpose: augments node i's adjacency list with node j
|
|
536
|
+
**--------------------------------------------------------------
|
|
537
|
+
*/
|
|
538
|
+
{
|
|
539
|
+
Padjlist alink;
|
|
540
|
+
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
|
|
541
|
+
if (alink == NULL) return(0);
|
|
542
|
+
alink->node = j;
|
|
543
|
+
alink->link = n;
|
|
544
|
+
alink->next = MSX.Dispersion.Adjlist[i];
|
|
545
|
+
MSX.Dispersion.Adjlist[i] = alink;
|
|
546
|
+
return(1);
|
|
547
|
+
} /* End of addlink */
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
int storesparse(int n)
|
|
551
|
+
/*
|
|
552
|
+
**--------------------------------------------------------------
|
|
553
|
+
** Input: n = number of rows in solution matrix
|
|
554
|
+
** Output: returns error code
|
|
555
|
+
** Purpose: stores row indexes of non-zeros of each column of
|
|
556
|
+
** lower triangular portion of factorized matrix
|
|
557
|
+
**--------------------------------------------------------------
|
|
558
|
+
*/
|
|
559
|
+
{
|
|
560
|
+
Padjlist alink;
|
|
561
|
+
int i, ii, j, k, l, m;
|
|
562
|
+
int errcode = 0;
|
|
563
|
+
|
|
564
|
+
/* Allocate sparse matrix storage */
|
|
565
|
+
MSX.Dispersion.XLNZ = (int *) calloc(n+2, sizeof(int));
|
|
566
|
+
MSX.Dispersion.NZSUB = (int *) calloc(MSX.Dispersion.Ncoeffs+2, sizeof(int));
|
|
567
|
+
MSX.Dispersion.LNZ = (int *) calloc(MSX.Dispersion.Ncoeffs+2, sizeof(int));
|
|
568
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.XLNZ));
|
|
569
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.NZSUB));
|
|
570
|
+
ERRCODE(MEMCHECK(MSX.Dispersion.LNZ));
|
|
571
|
+
if (errcode) return(errcode);
|
|
572
|
+
|
|
573
|
+
/* Generate row index pointers for each column of matrix */
|
|
574
|
+
k = 0;
|
|
575
|
+
MSX.Dispersion.XLNZ[1] = 1;
|
|
576
|
+
for (i=1; i<=n; i++) /* column */
|
|
577
|
+
{
|
|
578
|
+
m = 0;
|
|
579
|
+
ii = MSX.Dispersion.Order[i];
|
|
580
|
+
for (alink = MSX.Dispersion.Adjlist[ii]; alink != NULL; alink = alink->next)
|
|
581
|
+
{
|
|
582
|
+
j = MSX.Dispersion.Row[alink->node]; /* row */
|
|
583
|
+
l = alink->link;
|
|
584
|
+
if (j > i && j <= n)
|
|
585
|
+
{
|
|
586
|
+
m++;
|
|
587
|
+
k++;
|
|
588
|
+
MSX.Dispersion.NZSUB[k] = j;
|
|
589
|
+
MSX.Dispersion.LNZ[k] = l;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
MSX.Dispersion.XLNZ[i+1] = MSX.Dispersion.XLNZ[i] + m;
|
|
593
|
+
}
|
|
594
|
+
return(errcode);
|
|
595
|
+
} /* End of storesparse */
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
int ordersparse(int n)
|
|
599
|
+
/*
|
|
600
|
+
**--------------------------------------------------------------
|
|
601
|
+
** Input: n = number of rows in solution matrix
|
|
602
|
+
** Output: returns eror code
|
|
603
|
+
** Purpose: puts row indexes in ascending order in NZSUB
|
|
604
|
+
**--------------------------------------------------------------
|
|
605
|
+
*/
|
|
606
|
+
{
|
|
607
|
+
int i, k;
|
|
608
|
+
int *xlnzt, *nzsubt, *lnzt, *nzt;
|
|
609
|
+
int errcode = 0;
|
|
610
|
+
|
|
611
|
+
xlnzt = (int *) calloc(n+2, sizeof(int));
|
|
612
|
+
nzsubt = (int *) calloc(MSX.Dispersion.Ncoeffs+2, sizeof(int));
|
|
613
|
+
lnzt = (int *) calloc(MSX.Dispersion.Ncoeffs+2, sizeof(int));
|
|
614
|
+
nzt = (int *) calloc(n+2, sizeof(int));
|
|
615
|
+
ERRCODE(MEMCHECK(xlnzt));
|
|
616
|
+
ERRCODE(MEMCHECK(nzsubt));
|
|
617
|
+
ERRCODE(MEMCHECK(lnzt));
|
|
618
|
+
ERRCODE(MEMCHECK(nzt));
|
|
619
|
+
if (!errcode)
|
|
620
|
+
{
|
|
621
|
+
|
|
622
|
+
/* Count # non-zeros in each row */
|
|
623
|
+
for (i=1; i<=n; i++) nzt[i] = 0;
|
|
624
|
+
for (i=1; i<=n; i++)
|
|
625
|
+
{
|
|
626
|
+
for (k=MSX.Dispersion.XLNZ[i]; k<MSX.Dispersion.XLNZ[i+1]; k++) nzt[MSX.Dispersion.NZSUB[k]]++;
|
|
627
|
+
}
|
|
628
|
+
xlnzt[1] = 1;
|
|
629
|
+
for (i=1; i<=n; i++) xlnzt[i+1] = xlnzt[i] + nzt[i];
|
|
630
|
+
|
|
631
|
+
/* Transpose matrix twice to order column indexes */
|
|
632
|
+
transpose(n,MSX.Dispersion.XLNZ,MSX.Dispersion.NZSUB,MSX.Dispersion.LNZ,xlnzt,nzsubt,lnzt,nzt);
|
|
633
|
+
transpose(n,xlnzt,nzsubt,lnzt,MSX.Dispersion.XLNZ,MSX.Dispersion.NZSUB,MSX.Dispersion.LNZ,nzt);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/* Reclaim memory */
|
|
637
|
+
free(xlnzt);
|
|
638
|
+
free(nzsubt);
|
|
639
|
+
free(lnzt);
|
|
640
|
+
free(nzt);
|
|
641
|
+
return(errcode);
|
|
642
|
+
} /* End of ordersparse */
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
void transpose(int n, int *il, int *jl, int *xl, int *ilt, int *jlt,
|
|
646
|
+
int *xlt, int *nzt)
|
|
647
|
+
/*
|
|
648
|
+
**---------------------------------------------------------------------
|
|
649
|
+
** Input: n = matrix order
|
|
650
|
+
** il,jl,xl = sparse storage scheme for original matrix
|
|
651
|
+
** nzt = work array
|
|
652
|
+
** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix
|
|
653
|
+
** Purpose: Determines sparse storage scheme for transpose of a matrix
|
|
654
|
+
**---------------------------------------------------------------------
|
|
655
|
+
*/
|
|
656
|
+
{
|
|
657
|
+
int i, j, k, kk;
|
|
658
|
+
|
|
659
|
+
for (i=1; i<=n; i++) nzt[i] = 0;
|
|
660
|
+
for (i=1; i<=n; i++)
|
|
661
|
+
{
|
|
662
|
+
for (k=il[i]; k<il[i+1]; k++)
|
|
663
|
+
{
|
|
664
|
+
j = jl[k];
|
|
665
|
+
kk = ilt[j] + nzt[j];
|
|
666
|
+
jlt[kk] = i;
|
|
667
|
+
xlt[kk] = xl[k];
|
|
668
|
+
nzt[j]++;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
} /* End of transpose */
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
int msx_linsolve(int n, double *Aii, double *Aij, double *B)
|
|
675
|
+
/*
|
|
676
|
+
**--------------------------------------------------------------
|
|
677
|
+
** Input: n = number of equations
|
|
678
|
+
** Aii = diagonal entries of solution matrix
|
|
679
|
+
** Aij = non-zero off-diagonal entries of matrix
|
|
680
|
+
** B = right hand side coeffs.
|
|
681
|
+
** Output: B = solution values
|
|
682
|
+
** returns 0 if solution found, or index of
|
|
683
|
+
** equation causing system to be ill-conditioned
|
|
684
|
+
** Purpose: solves sparse symmetric system of linear
|
|
685
|
+
** equations using Cholesky factorization
|
|
686
|
+
**
|
|
687
|
+
** NOTE: This procedure assumes that the solution matrix has
|
|
688
|
+
** been symbolically factorized with the positions of
|
|
689
|
+
** the lower triangular, off-diagonal, non-zero coeffs.
|
|
690
|
+
** stored in the following integer arrays:
|
|
691
|
+
** XLNZ (start position of each column in NZSUB)
|
|
692
|
+
** NZSUB (row index of each non-zero in each column)
|
|
693
|
+
** LNZ (position of each NZSUB entry in Aij array)
|
|
694
|
+
**
|
|
695
|
+
** This procedure has been adapted from subroutines GSFCT and
|
|
696
|
+
** GSSLV in the book "Computer Solution of Large Sparse
|
|
697
|
+
** Positive Definite Systems" by A. George and J. W-H Liu
|
|
698
|
+
** (Prentice-Hall, 1981).
|
|
699
|
+
**--------------------------------------------------------------
|
|
700
|
+
*/
|
|
701
|
+
{
|
|
702
|
+
|
|
703
|
+
int i, istop, istrt, isub, j, k, kfirst, newk;
|
|
704
|
+
int errcode = 0;
|
|
705
|
+
double bj, diagj, ljk;
|
|
706
|
+
|
|
707
|
+
memset(MSX.Dispersion.temp,0,(n+1)*sizeof(double));
|
|
708
|
+
memset(MSX.Dispersion.link,0,(n+1)*sizeof(int));
|
|
709
|
+
|
|
710
|
+
/* Begin numerical factorization of matrix A into L */
|
|
711
|
+
/* Compute column L(*,j) for j = 1,...n */
|
|
712
|
+
for (j=1; j<=n; j++)
|
|
713
|
+
{
|
|
714
|
+
/* For each column L(*,k) that affects L(*,j): */
|
|
715
|
+
diagj = 0.0;
|
|
716
|
+
newk = MSX.Dispersion.link[j];
|
|
717
|
+
k = newk;
|
|
718
|
+
while (k != 0)
|
|
719
|
+
{
|
|
720
|
+
|
|
721
|
+
/* Outer product modification of L(*,j) by */
|
|
722
|
+
/* L(*,k) starting at first[k] of L(*,k). */
|
|
723
|
+
newk = MSX.Dispersion.link[k];
|
|
724
|
+
kfirst = MSX.Dispersion.first[k];
|
|
725
|
+
ljk = Aij[MSX.Dispersion.LNZ[kfirst]];
|
|
726
|
+
diagj += ljk*ljk;
|
|
727
|
+
istrt = kfirst + 1;
|
|
728
|
+
istop = MSX.Dispersion.XLNZ[k+1] - 1;
|
|
729
|
+
if (istop >= istrt)
|
|
730
|
+
{
|
|
731
|
+
|
|
732
|
+
/* Before modification, update vectors 'first' */
|
|
733
|
+
/* and 'link' for future modification steps. */
|
|
734
|
+
MSX.Dispersion.first[k] = istrt;
|
|
735
|
+
isub = MSX.Dispersion.NZSUB[istrt];
|
|
736
|
+
MSX.Dispersion.link[k] = MSX.Dispersion.link[isub];
|
|
737
|
+
MSX.Dispersion.link[isub] = k;
|
|
738
|
+
|
|
739
|
+
/* The actual mod is saved in vector 'temp'. */
|
|
740
|
+
for (i=istrt; i<=istop; i++)
|
|
741
|
+
{
|
|
742
|
+
isub = MSX.Dispersion.NZSUB[i];
|
|
743
|
+
MSX.Dispersion.temp[isub] += Aij[MSX.Dispersion.LNZ[i]]*ljk;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
k = newk;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/* Apply the modifications accumulated */
|
|
750
|
+
/* in 'temp' to column L(*,j). */
|
|
751
|
+
diagj = Aii[j] - diagj;
|
|
752
|
+
if (diagj <= 0.0) /* Check for ill-conditioning */
|
|
753
|
+
{
|
|
754
|
+
errcode = j;
|
|
755
|
+
return errcode;
|
|
756
|
+
}
|
|
757
|
+
diagj = sqrt(diagj);
|
|
758
|
+
Aii[j] = diagj;
|
|
759
|
+
istrt = MSX.Dispersion.XLNZ[j];
|
|
760
|
+
istop = MSX.Dispersion.XLNZ[j+1] - 1;
|
|
761
|
+
if (istop >= istrt)
|
|
762
|
+
{
|
|
763
|
+
MSX.Dispersion.first[j] = istrt;
|
|
764
|
+
isub = MSX.Dispersion.NZSUB[istrt];
|
|
765
|
+
MSX.Dispersion.link[j] = MSX.Dispersion.link[isub];
|
|
766
|
+
MSX.Dispersion.link[isub] = j;
|
|
767
|
+
for (i=istrt; i<=istop; i++)
|
|
768
|
+
{
|
|
769
|
+
isub = MSX.Dispersion.NZSUB[i];
|
|
770
|
+
bj = (Aij[MSX.Dispersion.LNZ[i]] - MSX.Dispersion.temp[isub])/diagj;
|
|
771
|
+
Aij[MSX.Dispersion.LNZ[i]] = bj;
|
|
772
|
+
MSX.Dispersion.temp[isub] = 0.0;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
} /* next j */
|
|
776
|
+
|
|
777
|
+
/* Foward substitution */
|
|
778
|
+
for (j=1; j<=n; j++)
|
|
779
|
+
{
|
|
780
|
+
bj = B[j]/Aii[j];
|
|
781
|
+
B[j] = bj;
|
|
782
|
+
istrt = MSX.Dispersion.XLNZ[j];
|
|
783
|
+
istop = MSX.Dispersion.XLNZ[j+1] - 1;
|
|
784
|
+
if (istop >= istrt)
|
|
785
|
+
{
|
|
786
|
+
for (i=istrt; i<=istop; i++)
|
|
787
|
+
{
|
|
788
|
+
isub = MSX.Dispersion.NZSUB[i];
|
|
789
|
+
B[isub] -= Aij[MSX.Dispersion.LNZ[i]]*bj;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/* Backward substitution */
|
|
795
|
+
for (j=n; j>=1; j--)
|
|
796
|
+
{
|
|
797
|
+
bj = B[j];
|
|
798
|
+
istrt = MSX.Dispersion.XLNZ[j];
|
|
799
|
+
istop = MSX.Dispersion.XLNZ[j+1] - 1;
|
|
800
|
+
if (istop >= istrt)
|
|
801
|
+
{
|
|
802
|
+
for (i=istrt; i<=istop; i++)
|
|
803
|
+
{
|
|
804
|
+
isub = MSX.Dispersion.NZSUB[i];
|
|
805
|
+
bj -= Aij[MSX.Dispersion.LNZ[i]]*B[isub];
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
B[j] = bj/Aii[j];
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
return(errcode);
|
|
812
|
+
} /* End of msx_linsolve */
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
/************************ END OF SMATRIX.C ************************/
|
|
816
|
+
|