38 #include "KIM_API_status.h" 40 #define NAMESTRLEN 128 42 #define FCCSPACING 5.260 44 #define NCELLSPERSIDE 2 45 #define NCLUSTERPARTS (4*(NCELLSPERSIDE*NCELLSPERSIDE*NCELLSPERSIDE) + \ 46 6*(NCELLSPERSIDE*NCELLSPERSIDE) \ 47 + 3*(NCELLSPERSIDE) + 1) 49 #define REPORT_ERROR(LN, FL, MSG, STAT) { \ 50 kim_cluster_model.report_error(LN, FL, MSG, STAT); \ 68 int* numnei,
int** nei1part,
double** Rij);
80 double CurrentSpacing;
89 int numberOfSpecies = 1;
94 double cutoff_cluster_model;
95 double energy_cluster_model;
98 std::string modelname;
101 printf(
"Please enter valid KIM Model name: \n");
102 std::cin >> modelname;
106 KIM_API_model kim_cluster_model;
107 status = kim_cluster_model.string_init(
descriptor(), modelname.c_str());
108 if (KIM_STATUS_OK > status)
109 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_string_init()",status);
111 kim_cluster_model.setm_data(&status, 8*4,
112 "numberOfParticles", 1, &numberOfParticles_cluster, 1,
113 "numberOfSpecies", 1, &numberOfSpecies, 1,
114 "particleSpecies", numberOfParticles_cluster, &particleSpecies_cluster_model, 1,
115 "coordinates",
DIM*numberOfParticles_cluster, coords_cluster, 1,
116 "neighObject", 1, &nl_cluster_model, 1,
117 "cutoff", 1, &cutoff_cluster_model, 1,
118 "energy", 1, &energy_cluster_model, 1,
119 "forces",
DIM*numberOfParticles_cluster, forces_cluster, 1);
120 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_setm_data",status);
121 status = kim_cluster_model.set_method(
"get_neigh", 1, (func_ptr) &
get_cluster_neigh);
122 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_method",status);
125 status = kim_cluster_model.model_init();
126 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_model_init", status);
129 particleSpecies_cluster_model[0] = kim_cluster_model.get_species_code(
"Ar", &status);
130 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"get_species_code", status);
132 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
143 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
144 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
145 std::cout <<
"--------------------------------------------------------------------------------\n";
146 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
148 std::cout << std::setw(20) <<
"Energy" 149 << std::setw(20) <<
"Force Norm" 150 << std::setw(20) <<
"Lattice Spacing" 152 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
158 (cutoff_cluster_model + cutpad), &nl_cluster_model);
161 status = kim_cluster_model.model_compute();
162 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"compute", status);
166 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
168 force_norm += forces_cluster[i]*forces_cluster[i];
170 force_norm = sqrt(force_norm);
173 std::cout << std::setw(20) << energy_cluster_model
174 << std::setw(20) << force_norm
175 << std::setw(20) << CurrentSpacing
181 status = kim_cluster_model.model_destroy();
182 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"destroy", status);
195 double FCCshifts[4][
DIM];
205 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
206 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
207 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
208 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
211 for (i = 0; i < nCellsPerSide; ++i)
213 latVec[0] = ((double) i)*FCCspacing;
214 for (j = 0; j < nCellsPerSide; ++j)
216 latVec[1] = ((double) j)*FCCspacing;
217 for (k = 0; k < nCellsPerSide; ++k)
219 latVec[2] = ((double) k)*FCCspacing;
220 for (
m = 0;
m < 4; ++
m)
222 for (n = 0; n <
DIM; ++n)
224 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
232 latVec[1] = ((double) i)*FCCspacing;
233 latVec[2] = ((double) j)*FCCspacing;
234 for (n = 0; n <
DIM; ++n)
236 coords[a*
DIM + n] = latVec[n];
239 for (n = 0; n <
DIM; ++n)
241 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
245 latVec[0] = ((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[2][n];
259 latVec[0] = ((double) i)*FCCspacing;
260 latVec[1] = ((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[1][n];
274 latVec[0] = ((double) i)*FCCspacing;
277 for (n = 0; n <
DIM; ++n)
279 coords[a*
DIM + n] = latVec[n];
283 latVec[1] = ((double) i)*FCCspacing;
285 for (n = 0; n <
DIM; ++n)
287 coords[a*
DIM + n] = latVec[n];
292 latVec[2] = ((double) i)*FCCspacing;
293 for (n = 0; n <
DIM; ++n)
295 coords[a*
DIM + n] = latVec[n];
300 for (n = 0; n <
DIM; ++n)
331 for (k = 0; k <
DIM; ++k)
333 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
339 if ((half && i < j) || (!half && i != j))
348 (*nl).NNeighbors[i] = a;
355 int* numnei,
int** nei1part,
double** Rij)
358 KIM_API_model * pkim = *(KIM_API_model **) kimmdl;
369 if (KIM_STATUS_OK > status)
371 pkim->report_error(__LINE__, __FILE__,
"get_data", status);
375 nl = (
NeighList*) pkim->get_data(
"neighObject", &status);
376 if (KIM_STATUS_OK > status)
378 pkim->report_error(__LINE__, __FILE__,
"get_data", status);
388 return KIM_STATUS_NEIGH_ITER_INIT_OK;
390 else if (1 == *request)
395 return KIM_STATUS_NEIGH_ITER_PAST_END;
399 partToReturn = (*nl).iteratorId;
404 pkim->report_error(__LINE__, __FILE__,
"Invalid request in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_REQUEST);
405 return KIM_STATUS_NEIGH_INVALID_REQUEST;
412 pkim->report_error(__LINE__, __FILE__,
"Invalid part ID in get_cluster_neigh", KIM_STATUS_PARTICLE_INVALID_ID);
413 return KIM_STATUS_PARTICLE_INVALID_ID;
417 partToReturn = *request;
422 pkim->report_error(__LINE__, __FILE__,
"Invalid mode in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_MODE);
423 return KIM_STATUS_NEIGH_INVALID_MODE;
427 *part = partToReturn;
430 *numnei = (*nl).NNeighbors[*part];
438 return KIM_STATUS_OK;
444 "KIM_API_Version := 1.6.0\n" 446 "Unit_energy := eV\n" 448 "Unit_temperature := K\n" 451 "PARTICLE_SPECIES:\n" 455 "ZeroBasedLists flag\n" 456 "Neigh_BothAccess flag\n" 457 "NEIGH_PURE_F flag\n" 460 "numberOfParticles integer none []\n" 461 "numberOfSpecies integer none []\n" 462 "particleSpecies integer none [numberOfParticles]\n" 463 "coordinates double length [numberOfParticles,3]\n" 464 "get_neigh method none []\n" 465 "neighObject pointer none []\n" 468 "destroy method none []\n" 469 "compute method none []\n" 470 "reinit method none []\n" 471 "cutoff double length []\n" 472 "energy double energy []\n" 473 "forces double force [numberOfParticles,3]\n";
int get_cluster_neigh(void *kimmdl, int *mode, int *request, int *part, int *numnei, int **nei1part, double **Rij)
void fcc_cluster_neighborlist(int half, int numberOfParticles, double *coords, double cutoff, NeighList *nl)
char const *const descriptor()
ComputeArgumentName const numberOfParticles
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)
#define REPORT_ERROR(LN, FL, MSG, STAT)