36 #include "KIM_API_C.h" 37 #include "KIM_API_status.h" 39 #define NAMESTRLEN 128 41 #define FCCSPACING 5.260 43 #define NCELLSPERSIDE 2 44 #define NCLUSTERPARTS (4*(NCELLSPERSIDE*NCELLSPERSIDE*NCELLSPERSIDE) + \ 45 6*(NCELLSPERSIDE*NCELLSPERSIDE) \ 46 + 3*(NCELLSPERSIDE) + 1) 48 #define REPORT_ERROR(LN, FL, MSG, STAT) { \ 49 KIM_API_report_error(LN, FL, MSG, STAT); \ 63 double cutoff, NeighList* nl);
66 int* numnei,
int** nei1part,
double** Rij);
78 double CurrentSpacing;
86 void* pkim_cluster_model;
89 int numberOfSpecies = 1;
90 int particleSpeciesShapeCluster[1];
92 int coordinatesShapeCluster[2];
94 NeighList nl_cluster_model;
96 double cutoff_cluster_model;
97 double energy_cluster_model;
100 char testkimfile[] =
"descriptor.kim";
104 printf(
"Please enter valid KIM Model name: \n");
105 status = scanf(
"%s", modelname);
108 REPORT_ERROR(__LINE__, __FILE__,
"Unable to read model name",
113 status = KIM_API_file_init(&pkim_cluster_model, testkimfile, modelname);
114 if (KIM_STATUS_OK > status)
115 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_file_init()",status);
118 coordinatesShapeCluster[0] = numberOfParticles_cluster;
119 coordinatesShapeCluster[1] = 3;
121 KIM_API_set_shape(pkim_cluster_model,
"particleSpecies", particleSpeciesShapeCluster, 1, &status);
122 if (KIM_STATUS_OK > status)
123 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_shape",status);
124 KIM_API_set_shape(pkim_cluster_model,
"coordinates", coordinatesShapeCluster, 2, &status);
125 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_shape",status);
126 KIM_API_setm_data(pkim_cluster_model, &status, 8*4,
127 "numberOfParticles", 1, &numberOfParticles_cluster, 1,
128 "numberOfSpecies", 1, &numberOfSpecies, 1,
129 "particleSpecies", numberOfParticles_cluster, &particleSpecies_cluster_model, 1,
130 "coordinates",
DIM*numberOfParticles_cluster, coords_cluster, 1,
131 "neighObject", 1, &nl_cluster_model, 1,
132 "cutoff", 1, &cutoff_cluster_model, 1,
133 "energy", 1, &energy_cluster_model, 1,
134 "forces",
DIM*numberOfParticles_cluster, forces_cluster, 1);
135 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_setm_data",status);
136 status = KIM_API_set_method(pkim_cluster_model,
"get_neigh", 1, (func_ptr) &
get_cluster_neigh);
137 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_method",status);
140 status = KIM_API_model_init(pkim_cluster_model);
141 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_model_init", status);
144 particleSpecies_cluster_model[0] = KIM_API_get_species_code(pkim_cluster_model,
"Ar", &status);
145 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"get_species_code", status);
147 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
151 nl_cluster_model.NNeighbors = (
int*) malloc(
NCLUSTERPARTS*
sizeof(
int));
152 if (NULL==nl_cluster_model.NNeighbors)
REPORT_ERROR(__LINE__, __FILE__,
"malloc unsuccessful", -1);
155 if (NULL==nl_cluster_model.neighborList)
REPORT_ERROR(__LINE__, __FILE__,
"malloc unsuccessful", -1);
158 printf(
"This is Test : ex_test_Ar_fcc_cluster\n");
159 printf(
"--------------------------------------------------------------------------------\n");
160 printf(
"Results for KIM Model : %s\n", modelname);
162 printf(
"%20s, %20s, %20s\n",
"Energy",
"Force Norm",
"Lattice Spacing");
163 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
169 (cutoff_cluster_model + cutpad), &nl_cluster_model);
172 status = KIM_API_model_compute(pkim_cluster_model);
173 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"compute", status);
177 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
179 force_norm += forces_cluster[i]*forces_cluster[i];
181 force_norm = sqrt(force_norm);
184 printf(
"%20.10e, %20.10e, %20.10e\n",
185 energy_cluster_model,
191 free(nl_cluster_model.NNeighbors);
192 free(nl_cluster_model.neighborList);
195 status = KIM_API_model_destroy(pkim_cluster_model);
196 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"destroy", status);
199 KIM_API_free(&pkim_cluster_model, &status);
200 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"free", status);
209 double FCCshifts[4][
DIM];
219 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
220 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
221 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
222 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
225 for (i = 0; i < nCellsPerSide; ++i)
227 latVec[0] = ((double) i)*FCCspacing;
228 for (j = 0; j < nCellsPerSide; ++j)
230 latVec[1] = ((double) j)*FCCspacing;
231 for (k = 0; k < nCellsPerSide; ++k)
233 latVec[2] = ((double) k)*FCCspacing;
234 for (
m = 0;
m < 4; ++
m)
236 for (n = 0; n <
DIM; ++n)
238 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
246 latVec[1] = ((double) i)*FCCspacing;
247 latVec[2] = ((double) j)*FCCspacing;
248 for (n = 0; n <
DIM; ++n)
250 coords[a*
DIM + n] = latVec[n];
253 for (n = 0; n <
DIM; ++n)
255 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
259 latVec[0] = ((double) i)*FCCspacing;
261 latVec[2] = ((double) j)*FCCspacing;
262 for (n = 0; n <
DIM; ++n)
264 coords[a*
DIM + n] = latVec[n];
267 for (n = 0; n <
DIM; ++n)
269 coords[a*
DIM + n] = latVec[n] + FCCshifts[2][n];
273 latVec[0] = ((double) i)*FCCspacing;
274 latVec[1] = ((double) j)*FCCspacing;
276 for (n = 0; n <
DIM; ++n)
278 coords[a*
DIM + n] = latVec[n];
281 for (n = 0; n <
DIM; ++n)
283 coords[a*
DIM + n] = latVec[n] + FCCshifts[1][n];
288 latVec[0] = ((double) i)*FCCspacing;
291 for (n = 0; n <
DIM; ++n)
293 coords[a*
DIM + n] = latVec[n];
297 latVec[1] = ((double) i)*FCCspacing;
299 for (n = 0; n <
DIM; ++n)
301 coords[a*
DIM + n] = latVec[n];
306 latVec[2] = ((double) i)*FCCspacing;
307 for (n = 0; n <
DIM; ++n)
309 coords[a*
DIM + n] = latVec[n];
314 for (n = 0; n <
DIM; ++n)
325 double cutoff, NeighList* nl)
337 cutoff2 = cutoff*cutoff;
345 for (k = 0; k <
DIM; ++k)
347 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
353 if ((half && i < j) || (!half && i != j))
362 (*nl).NNeighbors[i] = a;
369 int* numnei,
int** nei1part,
double** Rij)
372 intptr_t* pkim = *((intptr_t**) kimmdl);
383 if (KIM_STATUS_OK > status)
385 KIM_API_report_error(__LINE__, __FILE__,
"get_data", status);
389 nl = (NeighList*) KIM_API_get_data(pkim,
"neighObject", &status);
390 if (KIM_STATUS_OK > status)
392 KIM_API_report_error(__LINE__, __FILE__,
"get_data", status);
401 (*nl).iteratorId = -1;
402 return KIM_STATUS_NEIGH_ITER_INIT_OK;
404 else if (1 == *request)
409 return KIM_STATUS_NEIGH_ITER_PAST_END;
413 partToReturn = (*nl).iteratorId;
418 KIM_API_report_error(__LINE__, __FILE__,
"Invalid request in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_REQUEST);
419 return KIM_STATUS_NEIGH_INVALID_REQUEST;
426 KIM_API_report_error(__LINE__, __FILE__,
"Invalid part ID in get_cluster_neigh", KIM_STATUS_PARTICLE_INVALID_ID);
427 return KIM_STATUS_PARTICLE_INVALID_ID;
431 partToReturn = *request;
436 KIM_API_report_error(__LINE__, __FILE__,
"Invalid mode in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_MODE);
437 return KIM_STATUS_NEIGH_INVALID_MODE;
441 *part = partToReturn;
444 *numnei = (*nl).NNeighbors[*part];
452 return KIM_STATUS_OK;
#define REPORT_ERROR(LN, FL, MSG, STAT)
int get_cluster_neigh(void *kimmdl, int *mode, int *request, int *part, int *numnei, int **nei1part, double **Rij)
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)
ComputeArgumentName const numberOfParticles
void fcc_cluster_neighborlist(int half, int numberOfParticles, double *coords, double cutoff, NeighList *nl)