00001 00049 #include "apbscfg.h" 00050 #include "apbs/vmgrid.h" 00051 00052 VEMBED(rcsid="$Id: vmgrid.c 1552 2010-02-10 17:46:27Z yhuang01 $") 00053 00054 /* /////////////////////////////////////////////////////////////////////////// 00055 // Routine: Vmgrid_ctor 00056 // Author: Nathan Baker 00058 VPUBLIC Vmgrid* Vmgrid_ctor() { 00059 00060 Vmgrid *thee = VNULL; 00061 00062 thee = Vmem_malloc(VNULL, 1, sizeof(Vmgrid)); 00063 VASSERT(thee != VNULL); 00064 VASSERT(Vmgrid_ctor2(thee)); 00065 00066 return thee; 00067 } 00068 00069 /* /////////////////////////////////////////////////////////////////////////// 00070 // Routine: Vmgrid_ctor2 00071 // Author: Nathan Baker 00073 VPUBLIC int Vmgrid_ctor2(Vmgrid *thee) { 00074 00075 int i; 00076 00077 if (thee == VNULL) return 0; 00078 00079 thee->ngrids = 0; 00080 for (i=0; i<VMGRIDMAX; i++) thee->grids[i] = VNULL; 00081 00082 return 1; 00083 } 00084 00085 /* /////////////////////////////////////////////////////////////////////////// 00086 // Routine: Vmgrid_dtor 00087 // Author: Nathan Baker 00089 VPUBLIC void Vmgrid_dtor(Vmgrid **thee) { 00090 00091 if ((*thee) != VNULL) { 00092 Vmgrid_dtor2(*thee); 00093 Vmem_free(VNULL, 1, sizeof(Vmgrid), (void **)thee); 00094 (*thee) = VNULL; 00095 } 00096 } 00097 00098 /* /////////////////////////////////////////////////////////////////////////// 00099 // Routine: Vmgrid_dtor2 00100 // Author: Nathan Baker 00102 VPUBLIC void Vmgrid_dtor2(Vmgrid *thee) { ; } 00103 00104 /* /////////////////////////////////////////////////////////////////////////// 00105 // Routine: Vmgrid_value 00106 // Author: Nathan Baker 00108 VPUBLIC int Vmgrid_value(Vmgrid *thee, double pt[3], double *value) { 00109 00110 int i, rc; 00111 double tvalue; 00112 00113 VASSERT(thee != VNULL); 00114 00115 for (i=0; i<thee->ngrids; i++) { 00116 rc = Vgrid_value(thee->grids[i], pt, &tvalue); 00117 if (rc) { 00118 *value = tvalue; 00119 return 1; 00120 } 00121 } 00122 00123 Vnm_print(2, "Vmgrid_value: Point (%g, %g, %g) not found in \ 00124 hiearchy!\n", pt[0], pt[1], pt[2]); 00125 00126 return 0; 00127 } 00128 00129 /* /////////////////////////////////////////////////////////////////////////// 00130 // Routine: Vmgrid_curvature 00131 // 00132 // Notes: cflag=0 ==> Reduced Maximal Curvature 00133 // cflag=1 ==> Mean Curvature (Laplace) 00134 // cflag=2 ==> Gauss Curvature 00135 // cflag=3 ==> True Maximal Curvature 00136 // 00137 // Authors: Nathan Baker 00139 VPUBLIC int Vmgrid_curvature(Vmgrid *thee, double pt[3], int cflag, 00140 double *value) { 00141 00142 int i, rc; 00143 double tvalue; 00144 00145 VASSERT(thee != VNULL); 00146 00147 for (i=0; i<thee->ngrids; i++) { 00148 rc = Vgrid_curvature(thee->grids[i], pt, cflag, &tvalue); 00149 if (rc) { 00150 *value = tvalue; 00151 return 1; 00152 } 00153 } 00154 00155 Vnm_print(2, "Vmgrid_curvature: Point (%g, %g, %g) not found in \ 00156 hiearchy!\n", pt[0], pt[1], pt[2]); 00157 00158 return 0; 00159 00160 00161 } 00162 00163 /* /////////////////////////////////////////////////////////////////////////// 00164 // Routine: Vmgrid_gradient 00165 // 00166 // Authors: Nathan Baker 00168 VPUBLIC int Vmgrid_gradient(Vmgrid *thee, double pt[3], double grad[3]) { 00169 00170 int i, j, rc; 00171 double tgrad[3]; 00172 00173 VASSERT(thee != VNULL); 00174 00175 for (i=0; i<thee->ngrids; i++) { 00176 rc = Vgrid_gradient(thee->grids[i], pt, tgrad); 00177 if (rc) { 00178 for (j=0; j<3; j++) grad[j] = tgrad[j]; 00179 return 1; 00180 } 00181 } 00182 00183 Vnm_print(2, "Vmgrid_gradient: Point (%g, %g, %g) not found in \ 00184 hiearchy!\n", pt[0], pt[1], pt[2]); 00185 00186 return 0; 00187 00188 00189 } 00190 00191 /* /////////////////////////////////////////////////////////////////////////// 00192 // Routine: Vmgrid_addGrid 00193 // 00194 // Authors: Nathan Baker 00196 VPUBLIC int Vmgrid_addGrid(Vmgrid *thee, Vgrid *grid) { 00197 00198 int i, j, rc; 00199 double tgrad[3]; 00200 00201 VASSERT(thee != VNULL); 00202 00203 if (grid == VNULL) { 00204 Vnm_print(2, "Vmgrid_addGrid: Not adding VNULL grid!\n"); 00205 return 0; 00206 } 00207 00208 if (thee->ngrids >= VMGRIDMAX) { 00209 Vnm_print(2, "Vmgrid_addGrid: Too many grids in hierarchy (max = \ 00210 %d)!\n", VMGRIDMAX); 00211 Vnm_print(2, "Vmgrid_addGrid: Not adding grid!\n"); 00212 return 0; 00213 } 00214 00215 thee->grids[thee->ngrids] = grid; 00216 (thee->ngrids)++; 00217 00218 return 1; 00219 00220 }