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 "CalculiX.h"
23 #include "mortar.h"
24 
25 /**  inserts a new nonzero matrix position into the sparse matrix data structure
26  *
27  *  [in,out] irowp	field saving the row numbers
28  *  [in,out] mast1p	field saving the column numbers
29  *  [in] i1   		row number (FORTRAN convention)
30  *  [in] i2   		column number (FORTRAN convention)
31  *  [in,out] ifree	position of next free space in row,imast1,bd
32  *  [in,out] nzs_		size of row,imast1,bd
33  *  [in] contribution	value to be saved in bd
34  *  [in,out] bdp		values of sparse matrix
35 **/
36 
insertas(ITG ** irowp,ITG ** mast1p,ITG * i1,ITG * i2,ITG * ifree,ITG * nzs_,double * contribution,double ** bdp)37 void insertas(ITG **irowp, ITG **mast1p, ITG *i1,ITG *i2, ITG *ifree,
38 	      ITG *nzs_, double *contribution, double **bdp){
39 
40   /*   inserts a new nonzero matrix position into the data structure
41        the structure is not assumed to be symmetric
42        i1: row number (FORTRAN convention)
43        i2: column number (FORTRAN convention) */
44 
45     ITG idof1,idof2,*irow=NULL,*mast1=NULL,nzs_old,i;
46     double *bd=NULL;
47 
48     irow=*irowp;
49     mast1=*mast1p;
50     bd=*bdp;
51 
52     idof1 = *i1;
53     idof2 = *i2;
54 
55     if(*ifree>*nzs_){
56 	nzs_old=*nzs_;
57 	*nzs_=(ITG)(1.5**nzs_+1);
58 	RENEW(irow,ITG,*nzs_);
59 	for(i=nzs_old;i<*nzs_;i++){irow[i]=0;}
60 	RENEW(mast1,ITG,*nzs_);
61 	for(i=nzs_old;i<*nzs_;i++){mast1[i]=0;}
62 	RENEW(bd,double,*nzs_);
63 	for(i=nzs_old;i<*nzs_;i++){bd[i]=0.;}
64     }
65     mast1[*ifree-1]=idof2;
66     irow[*ifree-1]=idof1;
67     bd[*ifree-1]=*contribution;
68     ++*ifree;
69 
70     *irowp=irow;
71     *mast1p=mast1;
72     *bdp=bd;
73 
74     return;
75 
76 }
77