1 /*     CalculiX - A 3-dimensional finite element program                 */
2 /*              Copyright (C) 1998-2021 Guido Dhondt                     */
3 
4 /*     This program is free software; you can redistribute it and/or     */
5 /*     modify it under the terms of the GNU General Public License as    */
6 /*     published by the Free Software Foundation(version 2);    */
7 /*                                                                       */
8 
9 /*     This program is distributed in the hope that it will be useful,   */
10 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */
11 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
12 /*     GNU General Public License for more details.                      */
13 
14 /*     You should have received a copy of the GNU General Public License */
15 /*     along with this program; if not, write to the Free Software       */
16 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
17 
18 #include <stdlib.h>
19 #include <math.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <time.h>
23 #include "CalculiX.h"
24 #include "mortar.h"
25 /**
26  *  sort unsorted sparse matrix au
27 
28  * Author: Saskia Sitzmann
29  *
30  *  [in,out] au		matrix values
31  *  [in,out] mast1	column numbers
32  *  [in,out] irow	row numbers
33  *  [out] jq 		column pointer to irow
34  *  [in,out] nzs	number of non-zero values in au
35  *  [in,out] ndim	dimention of matrix au ndim x ndim
36 **/
37 
matrixsort(double * au,ITG * mast1,ITG * irow,ITG * jq,ITG * nzs,ITG * ndim)38 void matrixsort(double *au,ITG *mast1,ITG *irow,ITG *jq,
39 		ITG *nzs,ITG *ndim){
40 
41   ITG  i,j,k,kflag,numb;
42 
43   /* Sort mast1, irow and au;
44      Outcome: the values in field au are sorted, column by
45      column; sorting is also done within the columns */
46 
47   /* general sort */
48 
49   kflag=2;
50   FORTRAN(isortiid,(mast1,irow,au,nzs,&kflag));
51 
52   /*  determine jq
53       jq(i): first element in field au belonging to column i  */
54 
55   j=0;
56   for(i=0;i<*ndim;i++){
57     if(j==*nzs){
58       for(k=i;k<*ndim;k++)
59 	jq[k]=*nzs+1;
60       break;
61     }
62 
63     if(mast1[j]!=i+1){
64       jq[i]=j+1;
65       continue;
66     }
67 
68     jq[i]=j+1;
69 
70     while(1){
71       j++;
72       if(j==*nzs) break;
73       if(mast1[j]!=i+1) break;
74     }
75   }
76 
77   jq[*ndim]=*nzs+1;
78 
79   /* Sorting within the columns */
80 
81   for (i=0;i<*ndim;i++){
82     if(jq[i+1]-jq[i]>0){
83       numb=jq[i+1]-jq[i];
84       FORTRAN(isortid,(&irow[jq[i]-1],&au[jq[i]-1],&numb,&kflag));
85     }
86   }
87 
88   return;
89 }
90