1 /********** 2 Copyright 1991 Regents of the University of California. All rights reserved. 3 Author: 1991 David A. Gates, U. C. Berkeley CAD Group 4 **********/ 5 6 #include "ngspice/ngspice.h" 7 #include "ngspice/numglobs.h" 8 #include "ngspice/numenum.h" 9 #include "ngspice/twodev.h" 10 #include "ngspice/twomesh.h" 11 #include "ngspice/spmatrix.h" 12 #include "twoddefs.h" 13 #include "twodext.h" 14 15 void TWOdestroy(TWOdevice * pDevice)16TWOdestroy(TWOdevice *pDevice) 17 { 18 int index, eIndex; 19 TWOelem *pElem; 20 TWOnode *pNode; 21 TWOedge *pEdge; 22 23 if ( !pDevice ) return; 24 25 switch ( pDevice->solverType ) { 26 case SLV_SMSIG: 27 case SLV_BIAS: 28 /* free up memory allocated for the bias solution */ 29 FREE( pDevice->dcSolution ); 30 FREE( pDevice->dcDeltaSolution ); 31 FREE( pDevice->copiedSolution ); 32 FREE( pDevice->rhs ); 33 FREE( pDevice->rhsImag ); 34 spDestroy( pDevice->matrix ); 35 break; 36 case SLV_EQUIL: 37 /* free up the vectors allocated in the equilibrium solution */ 38 FREE( pDevice->dcSolution ); 39 FREE( pDevice->dcDeltaSolution ); 40 FREE( pDevice->copiedSolution ); 41 FREE( pDevice->rhs ); 42 spDestroy( pDevice->matrix ); 43 break; 44 case SLV_NONE: 45 break; 46 default: 47 fprintf( stderr, "Panic: Unknown solver type in TWOdestroy.\n" ); 48 exit( -1 ); 49 break; 50 } 51 52 /* destroy the mesh */ 53 if ( pDevice->elements ) { 54 for ( eIndex = 1; eIndex <= pDevice->numElems; eIndex++ ) { 55 pElem = pDevice->elements[ eIndex ]; 56 for ( index = 0; index <= 3; index++ ) { 57 if ( pElem->evalNodes[ index ] ) { 58 pNode = pElem->pNodes[ index ]; 59 FREE( pNode ); 60 } 61 if ( pElem->evalEdges[ index ] ) { 62 pEdge = pElem->pEdges[ index ]; 63 FREE( pEdge ); 64 } 65 } 66 FREE( pElem ); 67 } 68 FREE( pDevice->elements ); 69 FREE( pDevice->elemArray ); 70 } 71 72 /* destroy the contacts & channels */ 73 /* NOT IMPLEMENTED */ 74 75 FREE( pDevice ); 76 } 77