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); \ 65 int* numnei,
int** nei1part,
double** Rij);
77 double CurrentSpacing;
85 void* pkim_cluster_model;
88 int numberOfSpecies = 1;
89 int particleSpeciesShapeCluster[1];
91 int coordinatesShapeCluster[2];
95 double cutoff_cluster_model;
96 double energy_cluster_model;
99 char testkimfile[] =
"descriptor.kim";
103 printf(
"Please enter valid KIM Model name: \n");
104 status = scanf(
"%s", modelname);
107 REPORT_ERROR(__LINE__, __FILE__,
"Unable to read model name",
112 status = KIM_API_file_init(&pkim_cluster_model, testkimfile, modelname);
113 if (KIM_STATUS_OK > status)
114 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_file_init()",status);
117 coordinatesShapeCluster[0] = numberOfParticles_cluster;
118 coordinatesShapeCluster[1] = 3;
120 KIM_API_set_shape(pkim_cluster_model,
"particleSpecies", particleSpeciesShapeCluster, 1, &status);
121 if (KIM_STATUS_OK > status)
122 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_shape",status);
123 KIM_API_set_shape(pkim_cluster_model,
"coordinates", coordinatesShapeCluster, 2, &status);
124 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_shape",status);
125 KIM_API_setm_data(pkim_cluster_model, &status, 8*4,
126 "numberOfParticles", 1, &numberOfParticles_cluster, 1,
127 "numberOfSpecies", 1, &numberOfSpecies, 1,
128 "particleSpecies", numberOfParticles_cluster, &particleSpecies_cluster_model, 1,
129 "coordinates",
DIM*numberOfParticles_cluster, coords_cluster, 1,
130 "neighObject", 1, &nl_cluster_model, 1,
131 "cutoff", 1, &cutoff_cluster_model, 1,
132 "energy", 1, &energy_cluster_model, 1,
133 "forces",
DIM*numberOfParticles_cluster, forces_cluster, 1);
134 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_setm_data",status);
135 status = KIM_API_set_method(pkim_cluster_model,
"get_neigh", 1, (func_ptr) &
get_cluster_neigh);
136 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_method",status);
139 status = KIM_API_model_init(pkim_cluster_model);
140 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_model_init", status);
143 particleSpecies_cluster_model[0] = KIM_API_get_species_code(pkim_cluster_model,
"Ar", &status);
144 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"get_species_code", status);
146 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
157 printf(
"This is Test : ex_test_Ar_fcc_cluster\n");
158 printf(
"--------------------------------------------------------------------------------\n");
159 printf(
"Results for KIM Model : %s\n", modelname);
161 printf(
"%20s, %20s, %20s\n",
"Energy",
"Force Norm",
"Lattice Spacing");
162 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
168 (cutoff_cluster_model + cutpad), &nl_cluster_model);
171 status = KIM_API_model_compute(pkim_cluster_model);
172 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"compute", status);
176 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
178 force_norm += forces_cluster[i]*forces_cluster[i];
180 force_norm = sqrt(force_norm);
183 printf(
"%20.10e, %20.10e, %20.10e\n",
184 energy_cluster_model,
194 status = KIM_API_model_destroy(pkim_cluster_model);
195 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"destroy", status);
198 KIM_API_free(&pkim_cluster_model, &status);
199 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"free", status);
208 double FCCshifts[4][
DIM];
218 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
219 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
220 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
221 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
224 for (i = 0; i < nCellsPerSide; ++i)
226 latVec[0] = ((double) i)*FCCspacing;
227 for (j = 0; j < nCellsPerSide; ++j)
229 latVec[1] = ((double) j)*FCCspacing;
230 for (k = 0; k < nCellsPerSide; ++k)
232 latVec[2] = ((double) k)*FCCspacing;
233 for (
m = 0;
m < 4; ++
m)
235 for (n = 0; n <
DIM; ++n)
237 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
245 latVec[1] = ((double) i)*FCCspacing;
246 latVec[2] = ((double) j)*FCCspacing;
247 for (n = 0; n <
DIM; ++n)
249 coords[a*
DIM + n] = latVec[n];
252 for (n = 0; n <
DIM; ++n)
254 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
258 latVec[0] = ((double) i)*FCCspacing;
260 latVec[2] = ((double) j)*FCCspacing;
261 for (n = 0; n <
DIM; ++n)
263 coords[a*
DIM + n] = latVec[n];
266 for (n = 0; n <
DIM; ++n)
268 coords[a*
DIM + n] = latVec[n] + FCCshifts[2][n];
272 latVec[0] = ((double) i)*FCCspacing;
273 latVec[1] = ((double) j)*FCCspacing;
275 for (n = 0; n <
DIM; ++n)
277 coords[a*
DIM + n] = latVec[n];
280 for (n = 0; n <
DIM; ++n)
282 coords[a*
DIM + n] = latVec[n] + FCCshifts[1][n];
287 latVec[0] = ((double) i)*FCCspacing;
290 for (n = 0; n <
DIM; ++n)
292 coords[a*
DIM + n] = latVec[n];
296 latVec[1] = ((double) i)*FCCspacing;
298 for (n = 0; n <
DIM; ++n)
300 coords[a*
DIM + n] = latVec[n];
305 latVec[2] = ((double) i)*FCCspacing;
306 for (n = 0; n <
DIM; ++n)
308 coords[a*
DIM + n] = latVec[n];
313 for (n = 0; n <
DIM; ++n)
344 for (k = 0; k <
DIM; ++k)
346 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
352 if ((half && i < j) || (!half && i != j))
361 (*nl).NNeighbors[i] = a;
368 int* numnei,
int** nei1part,
double** Rij)
371 intptr_t* pkim = *((intptr_t**) kimmdl);
382 if (KIM_STATUS_OK > status)
384 KIM_API_report_error(__LINE__, __FILE__,
"get_data", status);
388 nl = (
NeighList*) KIM_API_get_data(pkim,
"neighObject", &status);
389 if (KIM_STATUS_OK > status)
391 KIM_API_report_error(__LINE__, __FILE__,
"get_data", status);
400 KIM_API_report_error(__LINE__, __FILE__,
"Invalid part ID in get_cluster_neigh", KIM_STATUS_PARTICLE_INVALID_ID);
401 return KIM_STATUS_PARTICLE_INVALID_ID;
405 partToReturn = *request;
410 KIM_API_report_error(__LINE__, __FILE__,
"Invalid mode in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_MODE);
411 return KIM_STATUS_NEIGH_INVALID_MODE;
415 *part = partToReturn;
418 *numnei = (*nl).NNeighbors[*part];
426 return KIM_STATUS_OK;
int get_cluster_neigh(void *kimmdl, int *mode, int *request, int *part, int *numnei, int **nei1part, double **Rij)
#define REPORT_ERROR(LN, FL, MSG, STAT)
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)