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; \ 83 double cutoff, NeighList* nl);
86 int const numberOfCutoffs,
double const *
const cutoffs,
87 int const neighborListIndex,
int const particleNumber,
88 int *
const numberOfNeighbors,
89 int const **
const neighborsOfParticle);
101 double CurrentSpacing;
102 double cutpad = 0.75;
110 int numberOfSpecies = 1;
113 NeighList nl_cluster_model;
115 double influence_distance_cluster_model;
116 int number_of_cutoffs;
117 double const * cutoff_cluster_model;
118 double energy_cluster_model;
121 std::string modelname;
124 printf(
"Please enter valid KIM Model name: \n");
125 std::cin >> modelname;
130 int requestedUnitsAccepted;
138 &requestedUnitsAccepted,
146 if (!requestedUnitsAccepted)
148 MY_ERROR(
"Must Adapt to model units");
158 kim_cluster_model->
GetUnits(&lengthUnit, &energyUnit, &chargeUnit,
159 &temperatureUnit, &timeUnit);
161 std::cout <<
"LengthUnit is \"" << lengthUnit.
String() <<
"\"" << std::endl
162 <<
"EnergyUnit is \"" << energyUnit.
String() <<
"\"" << std::endl
163 <<
"ChargeUnit is \"" << chargeUnit.
String() <<
"\"" << std::endl
164 <<
"TemperatureUnit is \"" << temperatureUnit.
String()
166 <<
"TimeUnit is \"" << timeUnit.
String() <<
"\"" << std::endl;
169 int speciesIsSupported;
173 if ((
error) || (!speciesIsSupported))
175 MY_ERROR(
"Species Ar not supported");
182 MY_ERROR(
"Unable to create a ComputeArguments object.");
186 int numberOfComputeArgumentNames;
188 &numberOfComputeArgumentNames);
189 for (
int i=0; i<numberOfComputeArgumentNames; ++i)
196 computeArgumentName, &dataType);
200 MY_ERROR(
"unable to get ComputeArgument SupportStatus");
202 std::cout <<
"ComputeArgument Name \"" 203 << computeArgumentName.
String() <<
"\"" 205 << dataType.
String() <<
"\"" 206 <<
" and has supportStatus \"" 207 << supportStatus.
String() <<
"\"" 217 MY_ERROR(
"unsupported required ComputeArgument");
230 MY_ERROR(
"energy or forces not available");
236 int numberOfComputeCallbackNames;
238 &numberOfComputeCallbackNames);
239 for (
int i=0; i<numberOfComputeCallbackNames; ++i)
247 std::cout <<
"ComputeCallback Name \"" 248 << computeCallbackName.
String() <<
"\"" 249 <<
" has supportStatus \"" 250 << supportStatus.
String() <<
"\"" 256 MY_ERROR(
"unsupported required ComputeCallback");
260 int numberOfParameters;
262 for (
int i=0; i<numberOfParameters; ++i)
265 std::string
const * str;
268 i, &dataType, &extent, &str);
269 std::cout <<
"Parameter No. " << i
270 <<
" has data type \"" << dataType.
String() <<
"\"" 271 <<
" with extent " << extent
272 <<
" and description : " << *str << std::endl;
278 particleSpecies_cluster_model[0] = kim_cluster_model.get_species_code(
"Ar", &
error);
281 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
287 if (NULL==nl_cluster_model.NNeighbors)
MY_ERROR(
"new unsuccessful");
290 if (NULL==nl_cluster_model.neighborList)
MY_ERROR(
"new unsuccessful");
293 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
294 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
295 std::cout <<
"--------------------------------------------------------------------------------\n";
296 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
298 std::cout << std::setw(20) <<
"Energy" 299 << std::setw(20) <<
"Force Norm" 300 << std::setw(20) <<
"Lattice Spacing" 302 for (CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing; CurrentSpacing += SpacingIncr)
308 (*cutoff_cluster_model + cutpad), &nl_cluster_model);
311 error = kim_cluster_model.model_compute();
316 for (i=0; i <
DIM*numberOfParticles_cluster; ++i)
318 force_norm += forces_cluster[i]*forces_cluster[i];
320 force_norm = sqrt(force_norm);
323 std::cout << std::setw(20) << energy_cluster_model
324 << std::setw(20) << force_norm
325 << std::setw(20) << CurrentSpacing
331 error = kim_cluster_model.model_destroy();
335 delete [] nl_cluster_model.NNeighbors;
336 delete [] nl_cluster_model.neighborList;
345 double FCCshifts[4][
DIM];
355 FCCshifts[0][0] = 0.0; FCCshifts[0][1] = 0.0; FCCshifts[0][2] = 0.0;
356 FCCshifts[1][0] = 0.5*FCCspacing; FCCshifts[1][1] = 0.5*FCCspacing; FCCshifts[1][2] = 0.0;
357 FCCshifts[2][0] = 0.5*FCCspacing; FCCshifts[2][1] = 0.0; FCCshifts[2][2] = 0.5*FCCspacing;
358 FCCshifts[3][0] = 0.0; FCCshifts[3][1] = 0.5*FCCspacing; FCCshifts[3][2] = 0.5*FCCspacing;
361 for (i = 0; i < nCellsPerSide; ++i)
363 latVec[0] = ((double) i)*FCCspacing;
364 for (j = 0; j < nCellsPerSide; ++j)
366 latVec[1] = ((double) j)*FCCspacing;
367 for (k = 0; k < nCellsPerSide; ++k)
369 latVec[2] = ((double) k)*FCCspacing;
370 for (
m = 0;
m < 4; ++
m)
372 for (n = 0; n <
DIM; ++n)
374 coords[a*
DIM + n] = latVec[n] + FCCshifts[
m][n];
382 latVec[1] = ((double) i)*FCCspacing;
383 latVec[2] = ((double) j)*FCCspacing;
384 for (n = 0; n <
DIM; ++n)
386 coords[a*
DIM + n] = latVec[n];
389 for (n = 0; n <
DIM; ++n)
391 coords[a*
DIM + n] = latVec[n] + FCCshifts[3][n];
395 latVec[0] = ((double) i)*FCCspacing;
397 latVec[2] = ((double) j)*FCCspacing;
398 for (n = 0; n <
DIM; ++n)
400 coords[a*
DIM + n] = latVec[n];
403 for (n = 0; n <
DIM; ++n)
405 coords[a*
DIM + n] = latVec[n] + FCCshifts[2][n];
409 latVec[0] = ((double) i)*FCCspacing;
410 latVec[1] = ((double) j)*FCCspacing;
412 for (n = 0; n <
DIM; ++n)
414 coords[a*
DIM + n] = latVec[n];
417 for (n = 0; n <
DIM; ++n)
419 coords[a*
DIM + n] = latVec[n] + FCCshifts[1][n];
424 latVec[0] = ((double) i)*FCCspacing;
427 for (n = 0; n <
DIM; ++n)
429 coords[a*
DIM + n] = latVec[n];
433 latVec[1] = ((double) i)*FCCspacing;
435 for (n = 0; n <
DIM; ++n)
437 coords[a*
DIM + n] = latVec[n];
442 latVec[2] = ((double) i)*FCCspacing;
443 for (n = 0; n <
DIM; ++n)
445 coords[a*
DIM + n] = latVec[n];
450 for (n = 0; n <
DIM; ++n)
461 double cutoff, NeighList* nl)
475 cutoff2 = cutoff*cutoff;
483 for (k = 0; k <
DIM; ++k)
485 dx[k] = coords[j*
DIM + k] - coords[i*
DIM + k];
491 if ((half && i < j) || (!half && i != j))
500 (*nl).NNeighbors[i] = a;
507 int const numberOfCutoffs,
double const *
const cutoffs,
508 int const neighborListIndex,
int const particleNumber,
509 int *
const numberOfNeighbors,
510 int const **
const neighborsOfParticle)
514 NeighList* nl = (NeighList*) dataObject;
517 if ((numberOfCutoffs != 1) || (cutoffs[0] > nl->cutoff))
return error;
519 if (neighborListIndex != 0)
return error;
522 *numberOfNeighbors = 0;
526 MY_WARNING(
"Invalid part ID in get_cluster_neigh");
531 *numberOfNeighbors = (*nl).NNeighbors[particleNumber];
534 *neighborsOfParticle = &((*nl).neighborList[(particleNumber)*
numberOfParticles]);
#define MY_WARNING(message)
std::string const & String() const
static int Create(Numbering const numbering, LengthUnit const requestedLengthUnit, EnergyUnit const requestedEnergyUnit, ChargeUnit const requestedChargeUnit, TemperatureUnit const requestedTemperatureUnit, TimeUnit const requestedTimeUnit, std::string const &modelName, int *const requestedUnitsAccepted, Model **const model)
void GetUnits(LengthUnit *const lengthUnit, EnergyUnit *const energyUnit, ChargeUnit *const chargeUnit, TemperatureUnit *const temperatureUnit, TimeUnit *const timeUnit) const
std::string const & String() const
std::string const & String() const
int GetComputeCallbackName(int const index, ComputeCallbackName *const computeCallbackName)
std::string const & String() const
void GetNumberOfComputeCallbackNames(int *const numberOfComputeCallbackNames)
std::string const & String() const
void GetNumberOfComputeArgumentNames(int *const numberOfComputeArgumentNames)
int get_cluster_neigh(void *kimmdl, int *mode, int *request, int *part, int *numnei, int **nei1part, double **Rij)
int ComputeArgumentsCreate(ComputeArguments **const computeArguments) const
SupportStatus const required
std::string const & String() const
int GetCallbackSupportStatus(ComputeCallbackName const computeCallbackName, SupportStatus *const supportStatus) const
ComputeArgumentName const partialEnergy
int GetArgumentSupportStatus(ComputeArgumentName const computeArgumentName, SupportStatus *const supportStatus) const
void fcc_cluster_neighborlist(int half, int numberOfParticles, double *coords, double cutoff, NeighList *nl)
ComputeArgumentName const partialForces
std::string const & String() const
std::string const & String() const
void GetNumberOfParameters(int *const numberOfParameters) const
std::string const & String() const
ComputeArgumentName const numberOfParticles
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)
#define MY_ERROR(message)
int GetSpeciesSupportAndCode(SpeciesName const speciesName, int *const speciesIsSupported, int *const code) const
Numbering const zeroBased
int GetParameterDataTypeExtentAndDescription(int const index, DataType *const dataType, int *extent, std::string const **const description) const
int GetComputeArgumentDataType(ComputeArgumentName const computeArgumentName, DataType *const dataType)
int GetComputeArgumentName(int const index, ComputeArgumentName *const computeArgumentName)
SupportStatus const optional