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); \ 67 int* numnei,
int** nei1part,
double** Rij);
79 double CurrentSpacing;
88 int numberOfSpecies = 1;
93 double cutoff_cluster_model;
94 double energy_cluster_model;
97 std::string modelname;
100 printf(
"Please enter valid KIM Model name: \n");
101 std::cin >> modelname;
105 KIM_API_model kim_cluster_model;
106 status = kim_cluster_model.string_init(
descriptor(), modelname.c_str());
107 if (KIM_STATUS_OK > status)
108 REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_string_init()",status);
110 kim_cluster_model.setm_data(&status, 8*4,
111 "numberOfParticles", 1, &numberOfParticles_cluster, 1,
112 "numberOfSpecies", 1, &numberOfSpecies, 1,
113 "particleSpecies", numberOfParticles_cluster, &particleSpecies_cluster_model, 1,
114 "coordinates",
DIM*numberOfParticles_cluster, coords_cluster, 1,
115 "neighObject", 1, &nl_cluster_model, 1,
116 "cutoff", 1, &cutoff_cluster_model, 1,
117 "energy", 1, &energy_cluster_model, 1,
118 "forces",
DIM*numberOfParticles_cluster, forces_cluster, 1);
119 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_setm_data",status);
120 status = kim_cluster_model.set_method(
"get_neigh", 1, (func_ptr) &
get_cluster_neigh);
121 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_set_method",status);
124 status = kim_cluster_model.model_init();
125 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"KIM_API_model_init", status);
128 particleSpecies_cluster_model[0] = kim_cluster_model.get_species_code(
"Ar", &status);
129 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"get_species_code", status);
131 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
142 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
143 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
144 std::cout <<
"--------------------------------------------------------------------------------\n";
145 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
147 std::cout << std::setw(20) <<
"Energy" 148 << std::setw(20) <<
"Force Norm" 149 << std::setw(20) <<
"Lattice Spacing" 151 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
157 (cutoff_cluster_model + cutpad), &nl_cluster_model);
160 status = kim_cluster_model.model_compute();
161 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"compute", status);
165 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
167 force_norm += forces_cluster[i]*forces_cluster[i];
169 force_norm = sqrt(force_norm);
172 std::cout << std::setw(20) << energy_cluster_model
173 << std::setw(20) << force_norm
174 << std::setw(20) << CurrentSpacing
180 status = kim_cluster_model.model_destroy();
181 if (KIM_STATUS_OK > status)
REPORT_ERROR(__LINE__, __FILE__,
"destroy", status);
194 double FCCshifts[4][
DIM];
204 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
205 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
206 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
207 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
210 for (i = 0; i < nCellsPerSide; ++i)
212 latVec[0] = ((double) i)*FCCspacing;
213 for (j = 0; j < nCellsPerSide; ++j)
215 latVec[1] = ((double) j)*FCCspacing;
216 for (k = 0; k < nCellsPerSide; ++k)
218 latVec[2] = ((double) k)*FCCspacing;
219 for (
m = 0;
m < 4; ++
m)
221 for (n = 0; n <
DIM; ++n)
223 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
231 latVec[1] = ((double) i)*FCCspacing;
232 latVec[2] = ((double) j)*FCCspacing;
233 for (n = 0; n <
DIM; ++n)
235 coords[a*
DIM + n] = latVec[n];
238 for (n = 0; n <
DIM; ++n)
240 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
244 latVec[0] = ((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[2][n];
258 latVec[0] = ((double) i)*FCCspacing;
259 latVec[1] = ((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[1][n];
273 latVec[0] = ((double) i)*FCCspacing;
276 for (n = 0; n <
DIM; ++n)
278 coords[a*
DIM + n] = latVec[n];
282 latVec[1] = ((double) i)*FCCspacing;
284 for (n = 0; n <
DIM; ++n)
286 coords[a*
DIM + n] = latVec[n];
291 latVec[2] = ((double) i)*FCCspacing;
292 for (n = 0; n <
DIM; ++n)
294 coords[a*
DIM + n] = latVec[n];
299 for (n = 0; n <
DIM; ++n)
330 for (k = 0; k <
DIM; ++k)
332 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
338 if ((half && i < j) || (!half && i != j))
347 (*nl).NNeighbors[i] = a;
354 int* numnei,
int** nei1part,
double** Rij)
357 KIM_API_model * pkim = *(KIM_API_model **) kimmdl;
368 if (KIM_STATUS_OK > status)
370 pkim->report_error(__LINE__, __FILE__,
"get_data", status);
374 nl = (
NeighList*) pkim->get_data(
"neighObject", &status);
375 if (KIM_STATUS_OK > status)
377 pkim->report_error(__LINE__, __FILE__,
"get_data", status);
386 pkim->report_error(__LINE__, __FILE__,
"Invalid part ID in get_cluster_neigh", KIM_STATUS_PARTICLE_INVALID_ID);
387 return KIM_STATUS_PARTICLE_INVALID_ID;
391 partToReturn = *request;
396 pkim->report_error(__LINE__, __FILE__,
"Invalid mode in get_cluster_neigh", KIM_STATUS_NEIGH_INVALID_MODE);
397 return KIM_STATUS_NEIGH_INVALID_MODE;
401 *part = partToReturn;
412 return KIM_STATUS_OK;
418 "KIM_API_Version := 1.6.0\n" 420 "Unit_energy := eV\n" 422 "Unit_temperature := K\n" 425 "PARTICLE_SPECIES:\n" 429 "ZeroBasedLists flag\n" 430 "Neigh_LocaAccess flag\n" 431 "NEIGH_PURE_F flag\n" 434 "numberOfParticles integer none []\n" 435 "numberOfSpecies integer none []\n" 436 "particleSpecies integer none [numberOfParticles]\n" 437 "coordinates double length [numberOfParticles,3]\n" 438 "get_neigh method none []\n" 439 "neighObject pointer none []\n" 442 "destroy method none []\n" 443 "compute method none []\n" 444 "reinit method none []\n" 445 "cutoff double length []\n" 446 "energy double energy []\n" 447 "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)