44 #include "KIM_ArgumentName.hpp" 45 #include "KIM_CallbackName.hpp" 49 #define NAMESTRLEN 128 51 #define FCCSPACING 5.260 53 #define NCELLSPERSIDE 2 54 #define NCLUSTERPARTS (4*(NCELLSPERSIDE*NCELLSPERSIDE*NCELLSPERSIDE) + \ 55 6*(NCELLSPERSIDE*NCELLSPERSIDE) \ 56 + 3*(NCELLSPERSIDE) + 1) 58 #define MY_ERROR(message) \ 60 std::cout << "* Error : \"" << message << "\" : " \ 61 << __LINE__ << ":" << __FILE__ << std::endl; \ 65 #define MY_WARNING(message) \ 67 std::cout << "* Error : \"" << message << "\" : " \ 68 << __LINE__ << ":" << __FILE__ << std::endl; \ 84 double cutoff, NeighList* nl);
87 int const numberOfCutoffs,
double const *
const cutoffs,
88 int const neighborListIndex,
int const particleNumber,
89 int *
const numberOfNeighbors,
90 int const **
const neighborsOfParticle);
102 double CurrentSpacing;
103 double cutpad = 0.75;
111 int numberOfSpecies = 1;
114 NeighList nl_cluster_model;
116 double cutoff_cluster_model;
117 double energy_cluster_model;
120 std::string modelname;
123 printf(
"Please enter valid KIM Model name: \n");
124 std::cin >> modelname;
128 KIM_API_model kim_cluster_model;
129 error = kim_cluster_model.string_init(
descriptor(), modelname.c_str());
130 if (KIM_ERROR_OK >
error)
133 kim_cluster_model.setm_data(&
error, 8*4,
134 "numberOfParticles", 1, &numberOfParticles_cluster, 1,
135 "numberOfSpecies", 1, &numberOfSpecies, 1,
136 "particleSpecies", numberOfParticles_cluster, &particleSpecies_cluster_model, 1,
137 "coordinates",
DIM*numberOfParticles_cluster, coords_cluster, 1,
138 "neighObject", 1, &nl_cluster_model, 1,
139 "cutoff", 1, &cutoff_cluster_model, 1,
140 "energy", 1, &energy_cluster_model, 1,
141 "forces",
DIM*numberOfParticles_cluster, forces_cluster, 1);
147 error = kim_cluster_model.model_init();
151 particleSpecies_cluster_model[0] = kim_cluster_model.get_species_code(
"Ar", &
error);
154 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
160 if (NULL==nl_cluster_model.NNeighbors)
MY_ERROR(
"new unsuccessful");
163 if (NULL==nl_cluster_model.neighborList)
MY_ERROR(
"new unsuccessful");
166 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
167 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
168 std::cout <<
"--------------------------------------------------------------------------------\n";
169 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
171 std::cout << std::setw(20) <<
"Energy" 172 << std::setw(20) <<
"Force Norm" 173 << std::setw(20) <<
"Lattice Spacing" 175 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
181 (*cutoff_cluster_model + cutpad), &nl_cluster_model);
184 error = kim_cluster_model.model_compute();
189 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
191 force_norm += forces_cluster[i]*forces_cluster[i];
193 force_norm = sqrt(force_norm);
196 std::cout << std::setw(20) << energy_cluster_model
197 << std::setw(20) << force_norm
198 << std::setw(20) << CurrentSpacing
204 error = kim_cluster_model.model_destroy();
208 delete [] nl_cluster_model.NNeighbors;
209 delete [] nl_cluster_model.neighborList;
218 double FCCshifts[4][
DIM];
228 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
229 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
230 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
231 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
234 for (i = 0; i < nCellsPerSide; ++i)
236 latVec[0] = ((double) i)*FCCspacing;
237 for (j = 0; j < nCellsPerSide; ++j)
239 latVec[1] = ((double) j)*FCCspacing;
240 for (k = 0; k < nCellsPerSide; ++k)
242 latVec[2] = ((double) k)*FCCspacing;
243 for (
m = 0;
m < 4; ++
m)
245 for (n = 0; n <
DIM; ++n)
247 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
255 latVec[1] = ((double) i)*FCCspacing;
256 latVec[2] = ((double) j)*FCCspacing;
257 for (n = 0; n <
DIM; ++n)
259 coords[a*
DIM + n] = latVec[n];
262 for (n = 0; n <
DIM; ++n)
264 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
268 latVec[0] = ((double) i)*FCCspacing;
270 latVec[2] = ((double) j)*FCCspacing;
271 for (n = 0; n <
DIM; ++n)
273 coords[a*
DIM + n] = latVec[n];
276 for (n = 0; n <
DIM; ++n)
278 coords[a*
DIM + n] = latVec[n] + FCCshifts[2][n];
282 latVec[0] = ((double) i)*FCCspacing;
283 latVec[1] = ((double) j)*FCCspacing;
285 for (n = 0; n <
DIM; ++n)
287 coords[a*
DIM + n] = latVec[n];
290 for (n = 0; n <
DIM; ++n)
292 coords[a*
DIM + n] = latVec[n] + FCCshifts[1][n];
297 latVec[0] = ((double) i)*FCCspacing;
300 for (n = 0; n <
DIM; ++n)
302 coords[a*
DIM + n] = latVec[n];
306 latVec[1] = ((double) i)*FCCspacing;
308 for (n = 0; n <
DIM; ++n)
310 coords[a*
DIM + n] = latVec[n];
315 latVec[2] = ((double) i)*FCCspacing;
316 for (n = 0; n <
DIM; ++n)
318 coords[a*
DIM + n] = latVec[n];
323 for (n = 0; n <
DIM; ++n)
334 double cutoff, NeighList* nl)
348 cutoff2 = cutoff*cutoff;
356 for (k = 0; k <
DIM; ++k)
358 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
364 if ((half && i < j) || (!half && i != j))
373 (*nl).NNeighbors[i] = a;
380 int const numberOfCutoffs,
double const *
const cutoffs,
381 int const neighborListIndex,
int const particleNumber,
382 int *
const numberOfNeighbors,
383 int const **
const neighborsOfParticle)
387 NeighList* nl = (NeighList*) dataObject;
390 if ((numberOfCutoffs != 1) || (cutoffs[0] > nl->cutoff))
return error;
392 if (neighborListIndex != 0)
return error;
395 *numberOfNeighbors = 0;
399 MY_WARNING(
"Invalid part ID in get_cluster_neigh");
404 *numberOfNeighbors = (*nl).NNeighbors[particleNumber];
407 *neighborsOfParticle = &((*nl).neighborList[(particleNumber)*
numberOfParticles]);
415 "KIM_API_Version := 1.6.0\n" 417 "Unit_energy := eV\n" 419 "Unit_temperature := K\n" 422 "PARTICLE_SPECIES:\n" 426 "ZeroBasedLists flag\n" 427 "Neigh_LocaAccess flag\n" 428 "NEIGH_PURE_F flag\n" 431 "numberOfParticles integer none []\n" 432 "numberOfSpecies integer none []\n" 433 "particleSpecies integer none [numberOfParticles]\n" 434 "coordinates double length [numberOfParticles,3]\n" 435 "get_neigh method none []\n" 436 "neighObject pointer none []\n" 439 "destroy method none []\n" 440 "compute method none []\n" 441 "reinit method none []\n" 442 "cutoff double length []\n" 443 "energy double energy []\n" 444 "forces double force [numberOfParticles,3]\n";
#define MY_ERROR(message)
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)
#define MY_WARNING(message)
char const *const descriptor()
ComputeArgumentName const numberOfParticles
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)