root/src/insert.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. insert

   1 /*     CalculiX - A 3-dimensional finite element program                 */
   2 /*              Copyright (C) 1998-2015 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 
  24 void insert(ITG *ipointer, ITG **irowp, ITG **nextp, ITG *i1,
  25             ITG *i2, ITG *ifree, ITG *nzs_){
  26 
  27   /*   inserts a new nonzero matrix position into the data structure 
  28        in FORTRAN notation: 
  29        - ipointer(i) points to a position in field irow containing
  30          the row number of a nonzero position in column i; 
  31          next(ipointer(i)) points a position in field irow containing
  32          the row number of another nonzero position in column i, and
  33          so on until no nonzero positions in column i are left; for 
  34          the position j in field irow containing the momentarily last
  35          nonzero number in column i we have next(j)=0 
  36 
  37        notice that in C the positions start at 0 and not at 1 as in 
  38        FORTRAN; the present routine is written in FORTRAN convention */
  39 
  40   ITG idof1,idof2,istart,*irow=NULL,*next=NULL;
  41 
  42   irow=*irowp;
  43   next=*nextp;
  44 
  45   if(*i1<*i2){
  46     idof1=*i1;
  47     idof2=*i2;
  48   }
  49   else{
  50     idof1=*i2;
  51     idof2=*i1;
  52   }
  53 
  54   if(ipointer[idof2-1]==0){
  55     ++*ifree;
  56     if(*ifree>*nzs_){
  57       *nzs_=(ITG)(1.1**nzs_);
  58       RENEW(irow,ITG,*nzs_);
  59       RENEW(next,ITG,*nzs_);
  60     }
  61     ipointer[idof2-1]=*ifree;
  62     irow[*ifree-1]=idof1;
  63     next[*ifree-1]=0;
  64   }
  65   else{
  66     istart=ipointer[idof2-1];
  67     while(1){
  68       if(irow[istart-1]==idof1) break;
  69       if(next[istart-1]==0){
  70         ++*ifree;
  71         if(*ifree>*nzs_){
  72           *nzs_=(ITG)(1.1**nzs_);
  73           RENEW(irow,ITG,*nzs_);
  74           RENEW(next,ITG,*nzs_);
  75         }
  76         next[istart-1]=*ifree;
  77         irow[*ifree-1]=idof1;
  78         next[*ifree-1]=0;
  79         break;
  80       }
  81       else{
  82         istart=next[istart-1];
  83       }
  84     }
  85   }
  86 
  87   *irowp=irow;
  88   *nextp=next;
  89   
  90   return;
  91 
  92 }

/* [<][>][^][v][top][bottom][index][help] */