Changeset 12436
- Timestamp:
- 06/15/12 17:02:02 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/shared
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/shared/Alloc/alloc.cpp
r12011 r12436 84 84 } 85 85 86 87 86 void* xrealloc( void* pv, int size){ 88 87 -
issm/trunk-jpl/src/c/shared/Numerics/GaussPoints.cpp
r12424 r12436 52 52 53 53 // _printf_(true,"Gauss-Legendre recurrence coefficients ngaus=%d\n",ngaus); 54 *pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));55 *pxwgt = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));54 *pxgaus =xNew<IssmPDouble>(ngaus); 55 *pxwgt =xNew<IssmPDouble>(ngaus); 56 56 57 57 /* check to see if Gauss points need to be calculated */ … … 70 70 71 71 /* calculate the Gauss points using recurrence relations */ 72 alpha= (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));73 beta = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));72 alpha=xNew<IssmPDouble>(ngaus); 73 beta =xNew<IssmPDouble>(ngaus); 74 74 75 75 /* calculate the Legendre recurrence coefficients */ … … 84 84 /* calculate the Gauss points */ 85 85 GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta ); 86 x free((void **)&beta);87 x free((void **)&alpha);86 xDelete<IssmPDouble>(beta); 87 xDelete<IssmPDouble>(alpha); 88 88 } 89 89 }/*}}}*/ … … 1150 1150 *pngaus=np[iord-1]; 1151 1151 1152 *pl1 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1153 *pl2 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1154 *pl3 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1155 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1152 *pl1 =xNew<IssmPDouble>(*pngaus); 1153 *pl2 =xNew<IssmPDouble>(*pngaus); 1154 *pl3 =xNew<IssmPDouble>(*pngaus); 1155 *pwgt =xNew<IssmPDouble>(*pngaus); 1156 1156 1157 1157 for (i=0; i<*pngaus; i++) { … … 1168 1168 *pngaus=nigaus*nigaus; 1169 1169 1170 *pl1 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1171 *pl2 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1172 *pl3 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1173 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1170 *pl1 =xNew<IssmPDouble>(*pngaus); 1171 *pl2 =xNew<IssmPDouble>(*pngaus); 1172 *pl3 =xNew<IssmPDouble>(*pngaus); 1173 *pwgt =xNew<IssmPDouble>(*pngaus); 1174 1174 1175 1175 /* get the gauss points in each direction */ … … 1195 1195 } 1196 1196 } 1197 x free((void **)&xwgt );1198 x free((void **)&xgaus);1197 xDelete<IssmPDouble>(xwgt ); 1198 xDelete<IssmPDouble>(xgaus); 1199 1199 } 1200 1200 … … 1410 1410 *pngaus=np[iord-1]; 1411 1411 1412 *pl1 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1413 *pl2 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1414 *pl3 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1415 *pl4 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1416 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1412 *pl1 =xNew<IssmPDouble>(*pngaus); 1413 *pl2 =xNew<IssmPDouble>(*pngaus); 1414 *pl3 =xNew<IssmPDouble>(*pngaus); 1415 *pl4 =xNew<IssmPDouble>(*pngaus); 1416 *pwgt =xNew<IssmPDouble>(*pngaus); 1417 1417 1418 1418 for (i=0; i<*pngaus; i++) { … … 1430 1430 *pngaus=nigaus*nigaus*nigaus; 1431 1431 1432 *pl1 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1433 *pl2 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1434 *pl3 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1435 *pl4 = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1436 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));1432 *pl1 =xNew<IssmPDouble>(*pngaus); 1433 *pl2 =xNew<IssmPDouble>(*pngaus); 1434 *pl3 =xNew<IssmPDouble>(*pngaus); 1435 *pl4 =xNew<IssmPDouble>(*pngaus); 1436 *pwgt =xNew<IssmPDouble>(*pngaus); 1437 1437 1438 1438 /* get the gauss points in each direction */ … … 1467 1467 } 1468 1468 } 1469 x free((void **)&xwgt );1470 x free((void **)&xgaus);1469 xDelete<IssmPDouble>(xwgt ); 1470 xDelete<IssmPDouble>(xgaus); 1471 1471 } 1472 1472 }/*}}}*/ … … 1522 1522 1523 1523 // _printf_(true,"Gauss-Lobatto recurrence coefficients ngaus=%d\n",ngaus); 1524 *pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));1525 *pxwgt = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));1524 *pxgaus =xNew<IssmPDouble>(ngaus); 1525 *pxwgt =xNew<IssmPDouble>(ngaus); 1526 1526 1527 1527 /* check to see if Gauss points need to be calculated */ … … 1539 1539 1540 1540 /* calculate the Gauss points using recurrence relations */ 1541 alpha= (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));1542 beta = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));1541 alpha=xNew<IssmPDouble>(ngaus); 1542 beta =xNew<IssmPDouble>(ngaus); 1543 1543 1544 1544 /* calculate the Legendre recurrence coefficients */ … … 1575 1575 /* calculate the Gauss points */ 1576 1576 GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta ); 1577 x free((void **)&beta );1578 x free((void **)&alpha);1577 xDelete<IssmPDouble>(beta ); 1578 xDelete<IssmPDouble>(alpha); 1579 1579 } 1580 1580 … … 1598 1598 } 1599 1599 1600 work= (IssmPDouble*)xmalloc(n*sizeof(IssmPDouble));1600 work=xNew<IssmPDouble>(n); 1601 1601 1602 1602 zero[0] =alpha[0]; … … 1669 1669 } while (iter < MAX_GAUS_ITER); 1670 1670 if (iter >= MAX_GAUS_ITER) { 1671 x free((void **)&work);1671 xDelete<IssmPDouble>(work); 1672 1672 _error_("%s%i"," Max iterations exceeded for l=",MAX_GAUS_ITER); 1673 1673 } … … 1698 1698 1699 1699 /*Cleanup*/ 1700 x free((void **)&work);1700 xDelete<IssmPDouble>(work); 1701 1701 1702 1702 }/*}}}*/ -
issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp
r12086 r12436 7 7 #include "./trimesh.h" 8 8 #include "../Exceptions/exceptions.h" 9 #include "../Alloc/xNewDelete.h" 9 10 #include "../Alloc/alloc.h" 10 11 #include "../../include/include.h" … … 53 54 current_size=max_number_elements; 54 55 NumGridElements=0; 55 GridElements= (int*)xmalloc(max_number_elements*sizeof(int));56 GridElements=xNew<int>(max_number_elements); 56 57 57 58 for (i=0;i<nel;i++){ … … 81 82 cleanup_and_return: 82 83 if(!noerr){ 83 x free((void**)&GridElements);84 xDelete<int>(GridElements); 84 85 } 85 86 /*Allocate return pointers: */ … … 165 166 166 167 /*Compress riftsegments_uncompressed:*/ 167 riftsegments= (int*)xmalloc(nriftsegs*4*sizeof(int));168 riftsegments=xNew<int>(nriftsegs*4); 168 169 counter=0; 169 170 for (i=0;i<nsegs;i++){ … … 177 178 } 178 179 179 x free((void**)&riftsegments_uncompressed);180 xDelete<int>(riftsegments_uncompressed); 180 181 181 182 /*Assign output pointers: */ … … 202 203 /*Figure out the list of elements that are on the same side of the rift. To do so, we start from one 203 204 * side of the rift and keep rotating in the same direction:*/ 204 GridElementListOnOneSideOfRift= (int*)xmalloc(NumGridElements*sizeof(int));205 GridElementListOnOneSideOfRift=xNew<int>(NumGridElements); 205 206 //bootstrap the GridElementListOnOneSideOfRift by filling elements from riftsegments: */ 206 207 GridElementListOnOneSideOfRift[0]=*(riftsegments+4*segmentnumber+0); /*this one does not belong to the same side, but is just there … … 241 242 242 243 /*Free ressources: */ 243 x free((void**)&GridElements);244 xDelete<int>(GridElements); 244 245 /*Assign output pointers: */ 245 246 *pNumGridElementListOnOneSideOfRift=NumGridElementListOnOneSideOfRift; … … 380 381 381 382 /*input: */ 382 double * segments=NULL;383 double * segmentmarkerlist=NULL;383 double *segments = NULL; 384 double *segmentmarkerlist = NULL; 384 385 int numsegs; 385 386 386 387 /*output: */ 387 int * riftsnumsegs=NULL;388 double** riftssegments=NULL;389 int new_numsegs;390 double * new_segments=NULL;391 double * new_segmentmarkers=NULL;388 int new_numsegs; 389 int *riftsnumsegs = NULL; 390 double **riftssegments = NULL; 391 double *new_segments = NULL; 392 double *new_segmentmarkers = NULL; 392 393 393 394 /*intermediary: */ … … 406 407 /*Allocate new segments: */ 407 408 new_numsegs=counter; 408 new_segments= (double*)xmalloc(new_numsegs*3*sizeof(double));409 new_segmentmarkers= (double*)xmalloc(new_numsegs*sizeof(double));409 new_segments=xNew<double>(new_numsegs*3); 410 new_segmentmarkers=xNew<double>(new_numsegs); 410 411 411 412 /*Copy new segments info : */ … … 422 423 423 424 /*Now deal with rift segments: */ 424 riftsnumsegs= (int*)xmalloc(numrifts*sizeof(int));425 riftssegments= (double**)xmalloc(numrifts*sizeof(double*));425 riftsnumsegs=xNew<int>(numrifts); 426 riftssegments=xNew<double*>(numrifts); 426 427 for (i=0;i<numrifts;i++){ 427 428 /*Figure out how many segments for rift i: */ … … 431 432 } 432 433 riftsnumsegs[i]=counter; 433 riftsegment= (double*)xmalloc(counter*3*sizeof(double));434 riftsegment=xNew<double>(counter*3); 434 435 /*Copy new segments info :*/ 435 436 counter=0; … … 446 447 447 448 /*Free ressources: */ 448 x free((void**)&segments);449 xDelete<double>(segments); 449 450 450 451 /*Assign output pointers: */ … … 465 466 466 467 /*output: */ 467 int * riftsnumpairs=NULL;468 double ** riftspairs=NULL;468 int *riftsnumpairs = NULL; 469 double **riftspairs = NULL; 469 470 470 471 /*intermediary :*/ … … 474 475 int node1,node2,node3,node4; 475 476 476 riftsnumpairs= (int*)xmalloc(numrifts*sizeof(int));477 riftspairs= (double**)xmalloc(numrifts*sizeof(double*));477 riftsnumpairs=xNew<int>(numrifts); 478 riftspairs=xNew<double*>(numrifts); 478 479 for (i=0;i<numrifts;i++){ 479 480 segments=riftssegments[i]; 480 481 numsegs=riftsnumsegments[i]; 481 482 riftsnumpairs[i]=numsegs; 482 pairs= (double*)xmalloc(2*numsegs*sizeof(double));483 pairs=xNew<double>(2*numsegs); 483 484 for (j=0;j<numsegs;j++){ 484 485 *(pairs+2*j+0)=*(segments+3*j+2); //retrieve element to which this segment belongs. … … 500 501 } 501 502 502 503 503 /*Assign output pointers: */ 504 504 *priftsnumpairs=riftsnumpairs; 505 505 *priftspairs=riftspairs; 506 507 506 return noerr; 508 507 }/*}}}*/ … … 522 521 523 522 /*intermediary: */ 524 double * riftsegments=NULL;525 double * riftpairs=NULL;523 double *riftsegments = NULL; 524 double *riftpairs = NULL; 526 525 int node1,node2,node3,node4,temp_node; 527 526 double el2; 528 527 int newnods; //temporary # node counter. 529 528 double xmin,ymin; 530 double * xreal=NULL;531 double * yreal=NULL;532 int * nodes=NULL;533 int * mergingnodes=NULL;529 double *xreal = NULL; 530 double *yreal = NULL; 531 int *nodes = NULL; 532 int *mergingnodes = NULL; 534 533 int max_size; 535 534 int redundant; 536 537 535 538 536 /*Recover input: */ … … 562 560 max_size+=rifts1numsegs[i]; 563 561 } 564 nodes= (int*)xmalloc(max_size*sizeof(int));565 mergingnodes= (int*)xmalloc(max_size*sizeof(int));562 nodes=xNew<int>(max_size); 563 mergingnodes=xNew<int>(max_size); 566 564 567 565 /*Go through the rifts segments, and identify which node we are going to merge with its counterpart on the other side … … 678 676 } 679 677 } 680 x free((void**)&x); x=xreal;681 x free((void**)&y); y=yreal;678 xDelete<double>(x); x=xreal; 679 xDelete<double>(y); y=yreal; 682 680 683 681 /*Assign output pointers:*/ … … 688 686 *psegments=segments; 689 687 *pnumsegs=numsegs; 690 691 688 return noerr; 692 689 }/*}}}*/ … … 716 713 *priftflag=riftflag; 717 714 *pnumrifts=numrifts; 718 719 715 return noerr; 720 716 }/*}}}*/ … … 726 722 727 723 /*intermediary: */ 728 double * riftsegments=NULL;729 double * riftpairs=NULL;724 double *riftsegments = NULL; 725 double *riftpairs = NULL; 730 726 int numsegs; 731 727 732 728 /*ordering and copy: */ 733 int * order=NULL;734 double * riftsegments_copy=NULL;735 double * riftpairs_copy=NULL;729 int *order = NULL; 730 double *riftsegments_copy = NULL; 731 double *riftpairs_copy = NULL; 736 732 737 733 /*node and element manipulation: */ … … 744 740 745 741 /*Allocate byproduct of this routine, riftstips: */ 746 riftstips= (double*)xmalloc(numrifts*2*sizeof(double));742 riftstips=xNew<double>(numrifts*2); 747 743 748 744 /*Go through all rifts: */ … … 754 750 /*Allocate copy of riftsegments and riftpairs, 755 751 *as well as ordering vector: */ 756 riftsegments_copy= (double*)xmalloc(numsegs*3*sizeof(double));757 riftpairs_copy= (double*)xmalloc(numsegs*2*sizeof(double));758 order= (int*)xmalloc(numsegs*sizeof(int));752 riftsegments_copy=xNew<double>(numsegs*3); 753 riftpairs_copy=xNew<double>(numsegs*2); 754 order=xNew<int>(numsegs); 759 755 760 756 /*First find the tips, using the pairs. If a pair of elements has one node in common, this node is a rift tip: */ … … 814 810 *(riftstips+2*i+0)=(double)tip1; 815 811 *(riftstips+2*i+1)=(double)tip2; 816 817 812 818 813 /*We have the two tips for this rift. Go from tip1 to tip2, and figure out the order in which segments are sequential. … … 865 860 } 866 861 867 x free((void**)&order);868 x free((void**)&riftsegments_copy);869 x free((void**)&riftpairs_copy);862 xDelete<int>(order); 863 xDelete<double>(riftsegments_copy); 864 xDelete<double>(riftpairs_copy); 870 865 871 866 } … … 887 882 888 883 /*output: */ 889 double ** riftspenaltypairs=NULL;890 double * riftpenaltypairs=NULL;891 int * riftsnumpenaltypairs=NULL;884 double **riftspenaltypairs = NULL; 885 double *riftpenaltypairs = NULL; 886 int *riftsnumpenaltypairs = NULL; 892 887 893 888 /*intermediary: */ … … 901 896 902 897 /*Allocate: */ 903 riftspenaltypairs= (double**)xmalloc(numrifts*sizeof(double*));904 riftsnumpenaltypairs= (int*)xmalloc(numrifts*sizeof(int));898 riftspenaltypairs=xNew<double*>(numrifts); 899 riftsnumpenaltypairs=xNew<int>(numrifts); 905 900 906 901 for(i=0;i<numrifts;i++){ … … 910 905 911 906 /*allocate riftpenaltypairs, and riftnumpenaltypairs: */ 912 if((numsegs/2-1)!=0)riftpenaltypairs= (double*)xcalloc((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,sizeof(double));907 if((numsegs/2-1)!=0)riftpenaltypairs=xNewInit<double>((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,0.0); 913 908 914 909 /*Go through only one flank of the rifts, not counting the tips: */ … … 1006 1001 riftsnumpenaltypairs[i]=(numsegs/2-1); 1007 1002 } 1008 1009 1010 1003 1011 1004 /*Assign output pointers: */ 1012 1005 *priftspenaltypairs=riftspenaltypairs; 1013 1006 *priftsnumpenaltypairs=riftsnumpenaltypairs; 1014 1015 1007 return noerr; 1016 1008 } … … 1143 1135 *py=y; 1144 1136 *pnods=nods; 1145 1146 1137 return noerr; 1147 1138 }
Note:
See TracChangeset
for help on using the changeset viewer.