42 #define NAMESTRLEN 128 44 #define FCCSPACING 5.260 46 #define NCELLSPERSIDE 2 47 #define NCLUSTERPARTS \ 48 (4 * (NCELLSPERSIDE * NCELLSPERSIDE * NCELLSPERSIDE) \ 49 + 6 * (NCELLSPERSIDE * NCELLSPERSIDE) + 3 * (NCELLSPERSIDE) + 1) 51 #define MY_ERROR(message) \ 53 std::cout << "* Error : \"" << message << "\" : " << __LINE__ << ":" \ 54 << __FILE__ << std::endl; \ 58 #define MY_WARNING(message) \ 60 std::cout << "* Warning : \"" << message << "\" : " << __LINE__ << ":" \ 61 << __FILE__ << std::endl; \ 82 int const numberOfNeighborLists,
83 double const *
const cutoffs,
84 int const neighborListIndex,
85 int const particleNumber,
86 int *
const numberOfNeighbors,
87 int const **
const neighborsOfParticle);
92 double const MaxSpacing,
93 double const SpacingIncr,
94 int const numberOfParticles_cluster,
95 double *
const coords_cluster,
100 double *
const forces_cluster,
101 double *
const energy_cluster_model);
110 double const SpacingIncr = 0.025 *
FCCSPACING;
122 double influence_distance_cluster_model;
123 int number_of_neighbor_lists;
124 double const * cutoff_cluster_model;
125 double energy_cluster_model;
128 std::string modelname;
131 printf(
"Please enter valid KIM Model name: \n");
132 std::cin >> modelname;
137 int requestedUnitsAccepted;
145 &requestedUnitsAccepted,
147 if (error) {
MY_ERROR(
"KIM::Model::Create()"); }
150 if (!requestedUnitsAccepted) {
MY_ERROR(
"Must Adapt to model units"); }
153 int numberOfModelRoutineNames;
155 &numberOfModelRoutineNames);
156 for (
int i = 0; i < numberOfModelRoutineNames; ++i)
161 if (error) {
MY_ERROR(
"Unable to get ModelRoutineName."); }
165 modelRoutineName, &present, &required);
166 if (error) {
MY_ERROR(
"Unable to get routine present/required."); }
168 std::cout <<
"Model routine name \"" << modelRoutineName.
ToString()
169 <<
"\" has present = " << present
170 <<
" and required = " << required <<
"." << std::endl;
172 if ((present ==
true) && (required ==
true))
175 if (!((modelRoutineName ==
Create)
179 || (modelRoutineName ==
Destroy)))
182 +
"\" is required by model.");
195 &lengthUnit, &energyUnit, &chargeUnit, &temperatureUnit, &timeUnit);
197 std::cout <<
"LengthUnit is \"" << lengthUnit.ToString() <<
"\"" << std::endl
198 <<
"EnergyUnit is \"" << energyUnit.
ToString() <<
"\"" << std::endl
199 <<
"ChargeUnit is \"" << chargeUnit.
ToString() <<
"\"" << std::endl
200 <<
"TemperatureUnit is \"" << temperatureUnit.
ToString() <<
"\"" 202 <<
"TimeUnit is \"" << timeUnit.
ToString() <<
"\"" << std::endl;
205 int speciesIsSupported;
209 if ((error) || (!speciesIsSupported))
210 {
MY_ERROR(
"Species Ar not supported"); }
214 if (error) {
MY_ERROR(
"Unable to create a ComputeArguments object."); }
217 int numberOfComputeArgumentNames;
219 &numberOfComputeArgumentNames);
220 for (
int i = 0; i < numberOfComputeArgumentNames; ++i)
230 if (error)
MY_ERROR(
"unable to get ComputeArgument SupportStatus");
232 std::cout <<
"ComputeArgument Name \"" << computeArgumentName.
ToString()
234 <<
" is of type \"" << dataType.
ToString() <<
"\"" 235 <<
" and has supportStatus \"" << supportStatus.
ToString() <<
"\"" 243 {
MY_ERROR(
"unsupported required ComputeArgument"); }
252 {
MY_ERROR(
"energy or forces not available"); }
257 int numberOfComputeCallbackNames;
259 &numberOfComputeCallbackNames);
260 for (
int i = 0; i < numberOfComputeCallbackNames; ++i)
268 std::cout <<
"ComputeCallback Name \"" << computeCallbackName.
ToString()
270 <<
" has supportStatus \"" << supportStatus.
ToString() <<
"\"" 275 {
MY_ERROR(
"unsupported required ComputeCallback"); }
278 int numberOfParameters;
280 for (
int i = 0; i < numberOfParameters; ++i)
283 std::string
const * strName;
284 std::string
const * strDesc;
287 i, &dataType, &extent, &strName, &strDesc);
288 std::cout <<
"Parameter No. " << i <<
" has" << std::endl
289 <<
" data type : \"" << dataType.
ToString() <<
"\"" << std::endl
290 <<
" extent : " << extent << std::endl
291 <<
" name : " << *strName << std::endl
292 <<
" description : " << *strDesc << std::endl;
299 if (error) {
MY_ERROR(
"Unable to get Extension present/required."); }
304 &supportedExtensions);
305 if (error) {
MY_ERROR(
"Error returned from KIM::Model::Extension()."); }
306 std::cout <<
"Model Supports " 308 <<
" Extensions:" << std::endl;
311 std::cout <<
" spportedExtensionID[" << std::setw(2) << i <<
"] = \"" 313 <<
"which has required = " 324 (
int *) &numberOfParticles_cluster)
327 particleSpecies_cluster_model)
330 particleContributing_cluster_model)
337 (
double *) forces_cluster);
338 if (error)
MY_ERROR(
"KIM_API_set_data");
344 if (error)
MY_ERROR(
"set_call_back");
347 int const * modelWillNotRequestNeighborsOfNoncontributingParticles;
349 &number_of_neighbor_lists,
350 &cutoff_cluster_model,
351 &modelWillNotRequestNeighborsOfNoncontributingParticles);
352 std::cout <<
"Model has influence distance of : " 353 << influence_distance_cluster_model << std::endl;
354 std::cout <<
"Model has numberOfNeighborLists : " << number_of_neighbor_lists
356 for (
int i = 0; i < number_of_neighbor_lists; ++i)
359 <<
"Neighbor list " << i <<
" has cutoff " 360 << cutoff_cluster_model[i]
362 "modelWillNotRequestNeighborsOfNoncontributingParticles " 363 << modelWillNotRequestNeighborsOfNoncontributingParticles[i]
367 if (number_of_neighbor_lists != 1)
MY_ERROR(
"too many neighbor lists");
370 int isSpeciesSupported;
374 &(particleSpecies_cluster_model[0]));
375 if (error)
MY_ERROR(
"get_species_code");
377 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
380 particleContributing_cluster_model[i] = 1;
392 std::ios oldState(NULL);
393 oldState.copyfmt(std::cout);
394 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
395 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
396 std::cout <<
"---------------------------------------------------------------" 397 "-----------------\n";
398 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
403 numberOfParticles_cluster,
404 &(coords_cluster[0][0]),
405 *cutoff_cluster_model,
410 &energy_cluster_model);
412 if (numberOfParameters > 0)
414 int index = numberOfParameters / 2;
416 std::string
const * name;
419 index, &dataType, NULL, &name, NULL);
420 if (error) {
MY_ERROR(
"Cannot get parameter metadata."); }
425 error = kim_cluster_model->
GetParameter(index, 0, &value);
426 if (error) {
MY_ERROR(
"Cannot get parameter value."); }
428 error = kim_cluster_model->
SetParameter(index, 0, value);
429 if (error) {
MY_ERROR(
"Cannot set parameter value."); }
431 if (error) {
MY_ERROR(
"Model ClearThenRefresh returned error."); }
433 std::cout << std::endl
434 <<
"Updated parameter \"" << *name <<
"\" to value " << value
438 &influence_distance_cluster_model);
440 &number_of_neighbor_lists,
441 &cutoff_cluster_model,
442 &modelWillNotRequestNeighborsOfNoncontributingParticles);
447 numberOfParticles_cluster,
448 &(coords_cluster[0][0]),
449 *cutoff_cluster_model,
454 &energy_cluster_model);
463 ".",
"This_IsTheNewModelName");
464 if (error) {
MY_ERROR(
"WriteParameterizedModel returned an error."); }
470 if (error) {
MY_ERROR(
"Unable to destroy compute arguments"); }
480 std::cout.copyfmt(oldState);
485 double const MaxSpacing,
486 double const SpacingIncr,
487 int const numberOfParticles_cluster,
488 double *
const coords_cluster,
493 double *
const forces_cluster,
494 double *
const energy_cluster_model)
496 double const cutpad = 0.75;
498 std::cout << std::setw(20) <<
"Energy" << std::setw(20) <<
"Force Norm" 499 << std::setw(20) <<
"Lattice Spacing" << std::endl;
500 for (
double CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing;
501 CurrentSpacing += SpacingIncr)
510 int error = kim_cluster_model->
Compute(computeArguments);
514 double force_norm = 0.0;
515 for (
int i = 0; i <
DIM * numberOfParticles_cluster; ++i)
516 { force_norm += forces_cluster[i] * forces_cluster[i]; }
517 force_norm = sqrt(force_norm);
520 std::cout << std::setw(20) << *energy_cluster_model << std::setw(20)
521 << force_norm << std::setw(20) << CurrentSpacing << std::endl;
528 double FCCshifts[4][
DIM];
538 FCCshifts[0][0] = 0.0;
539 FCCshifts[0][1] = 0.0;
540 FCCshifts[0][2] = 0.0;
541 FCCshifts[1][0] = 0.5 * FCCspacing;
542 FCCshifts[1][1] = 0.5 * FCCspacing;
543 FCCshifts[1][2] = 0.0;
544 FCCshifts[2][0] = 0.5 * FCCspacing;
545 FCCshifts[2][1] = 0.0;
546 FCCshifts[2][2] = 0.5 * FCCspacing;
547 FCCshifts[3][0] = 0.0;
548 FCCshifts[3][1] = 0.5 * FCCspacing;
549 FCCshifts[3][2] = 0.5 * FCCspacing;
552 for (i = 0; i < nCellsPerSide; ++i)
554 latVec[0] = ((double) i) * FCCspacing;
555 for (j = 0; j < nCellsPerSide; ++j)
557 latVec[1] = ((double) j) * FCCspacing;
558 for (k = 0; k < nCellsPerSide; ++k)
560 latVec[2] = ((double) k) * FCCspacing;
561 for (m = 0; m < 4; ++
m)
563 for (n = 0; n <
DIM; ++n)
564 { coords[a * DIM + n] = latVec[n] + FCCshifts[
m][n]; }
571 latVec[1] = ((double) i) * FCCspacing;
572 latVec[2] = ((double) j) * FCCspacing;
573 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
575 for (n = 0; n <
DIM; ++n)
576 { coords[a * DIM + n] = latVec[n] + FCCshifts[3][n]; }
579 latVec[0] = ((double) i) * FCCspacing;
581 latVec[2] = ((double) j) * FCCspacing;
582 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
584 for (n = 0; n <
DIM; ++n)
585 { coords[a * DIM + n] = latVec[n] + FCCshifts[2][n]; }
588 latVec[0] = ((double) i) * FCCspacing;
589 latVec[1] = ((double) j) * FCCspacing;
591 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
593 for (n = 0; n <
DIM; ++n)
594 { coords[a * DIM + n] = latVec[n] + FCCshifts[1][n]; }
598 latVec[0] = ((double) i) * FCCspacing;
601 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
604 latVec[1] = ((double) i) * FCCspacing;
606 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
610 latVec[2] = ((double) i) * FCCspacing;
611 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
615 for (n = 0; n <
DIM; ++n)
641 cutoff2 = cutoff * cutoff;
649 for (k = 0; k <
DIM; ++k)
651 dx[k] = coords[j * DIM + k] - coords[i * DIM + k];
657 if ((half && i < j) || (!half && i != j))
666 (*nl).NNeighbors[i] = a;
673 int const numberOfNeighborLists,
674 double const *
const cutoffs,
675 int const neighborListIndex,
676 int const particleNumber,
677 int *
const numberOfNeighbors,
678 int const **
const neighborsOfParticle)
685 if ((numberOfNeighborLists != 1) || (cutoffs[0] > nl->
cutoff))
return error;
687 if (neighborListIndex != 0)
return error;
690 *numberOfNeighbors = 0;
692 if ((particleNumber >= numberOfParticles)
693 || (particleNumber < 0))
695 MY_WARNING(
"Invalid part ID in get_cluster_neigh");
700 *numberOfNeighbors = (*nl).NNeighbors[particleNumber];
704 = &((*nl).neighborList[(particleNumber) *numberOfParticles]);
void GetNumberOfComputeCallbackNames(int *const numberOfComputeCallbackNames)
Get the number of standard ComputeCallbackName's defined by the KIM API.
Numbering const zeroBased
The standard zeroBased numbering.
Provides the primary interface to a KIM API ComputeArguments object and is meant to be used by simula...
Contains the enumeration constants and the discovery routines for the ModelRoutineName Extensible Enu...
std::string const & ToString() const
Converts the object to a string.
void() Function(void)
Generic function type.
TimeUnit const ps
The standard picosecond unit of time.
int numberOfSupportedExtensions
The number of extensions supported by the Model.
EnergyUnit const eV
The standard electronvolt unit of energy.
ComputeCallbackName const GetNeighborList
The standard GetNeighborList callback.
int ClearThenRefresh()
Clear influence distance and neighbor list pointers and refresh Model object after parameter changes...
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)
Create a new KIM API Model object.
void GetUnits(LengthUnit *const lengthUnit, EnergyUnit *const energyUnit, ChargeUnit *const chargeUnit, TemperatureUnit *const temperatureUnit, TimeUnit *const timeUnit) const
Get the Model's base unit values.
An Extensible Enumeration for the ComputeArgumentName's supported by the KIM API. ...
void GetInfluenceDistance(double *const influenceDistance) const
Get the Model's influence distance.
std::string const & ToString() const
Converts the object to a string.
int ComputeArgumentsCreate(ComputeArguments **const computeArguments) const
Create a new ComputeArguments object for the Model object.
void GetNeighborListPointers(int *const numberOfNeighborLists, double const **const cutoffs, int const **const modelWillNotRequestNeighborsOfNoncontributingParticles) const
Get the Model's neighbor list information.
An Extensible Enumeration for the ChargeUnit's supported by the KIM API.
An Extensible Enumeration for the LengthUnit's supported by the KIM API.
SupportStatus const optional
The standard optional status.
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)
TemperatureUnit const K
The standard Kelvin unit of temperature.
std::string const & ToString() const
Converts the object to a string.
int GetCallbackSupportStatus(ComputeCallbackName const computeCallbackName, SupportStatus *const supportStatus) const
Get the SupportStatus of a ComputeCallbackName.
The only standard extension defined by the KIM API.
int get_cluster_neigh(void *const dataObject, int const numberOfNeighborLists, double const *const cutoffs, int const neighborListIndex, int const particleNumber, int *const numberOfNeighbors, int const **const neighborsOfParticle)
An Extensible Enumeration for the EnergyUnit's supported by the KIM API.
#define MY_WARNING(message)
An Extensible Enumeration for the SupportStatus's supported by the KIM API.
int GetArgumentSupportStatus(ComputeArgumentName const computeArgumentName, SupportStatus *const supportStatus) const
Get the SupportStatus of a ComputeArgumentName.
int WriteParameterizedModel(std::string const &path, std::string const &modelName) const
Call the Model's MODEL_ROUTINE_NAME::WriteParameterizedModel routine.
int SetArgumentPointer(ComputeArgumentName const computeArgumentName, int const *const ptr)
Set the data pointer for a ComputeArgumentName.
SpeciesName const Ar
The standard Argon species.
int GetParameter(int const parameterIndex, int const arrayIndex, int *const parameterValue) const
Get a parameter value from the Model.
ModelRoutineName const Destroy
The standard Destroy routine.
void GetNumberOfModelRoutineNames(int *const numberOfModelRoutineNames)
Get the number of standard ModelRoutineName's defined by the KIM API.
std::string const & ToString() const
Converts the object to a string.
ModelRoutineName const Create
The standard Create routine.
LengthUnit const m
The standard meter unit of length.
void compute_loop(double const MinSpacing, double const MaxSpacing, double const SpacingIncr, int const numberOfParticles_cluster, double *const coords_cluster, double const cutoff, NeighList *nl, KIM::Model const *const kim_cluster_model, KIM::ComputeArguments const *const computeArguments, double *const forces_cluster, double *const energy_cluster_model)
ModelRoutineName const Extension
The standard Extension routine.
An Extensible Enumeration for the ComputeCallbackName's supported by the KIM API. ...
std::string const & ToString() const
Converts the object to a string.
An Extensible Enumeration for the ModelRoutineName's supported by the KIM API.
int ComputeArgumentsDestroy(ComputeArguments **const computeArguments) const
Destroy a previously Model::ComputeArgumentsCreate'd object.
static void Destroy(Model **const model)
Destroy a previously Model::Create'd object.
int GetModelRoutineName(int const index, ModelRoutineName *const modelRoutineName)
Get the identity of each defined standard ModelRoutineName.
An Extensible Enumeration for the TimeUnit's supported by the KIM API.
ModelRoutineName const Refresh
The standard Refresh routine.
DataType const Double
The standard Double data type.
ModelRoutineName const ComputeArgumentsDestroy
The standard ComputeArgumentsDestroy routine.
ModelRoutineName const ComputeArgumentsCreate
The standard ComputeArgumentsCreate routine.
void GetNumberOfComputeArgumentNames(int *const numberOfComputeArgumentNames)
Get the number of standard ComputeArgumentName's defined by the KIM API.
ComputeArgumentName const coordinates
The standard coordinates argument.
int GetComputeArgumentName(int const index, ComputeArgumentName *const computeArgumentName)
Get the identity of each defined standard ComputeArgumentName.
LengthUnit const A
The standard angstrom unit of length.
ComputeArgumentName const partialEnergy
The standard partialEnergy argument.
char supportedExtensionID[KIM_MAX_NUMBER_OF_EXTENSIONS][KIM_MAX_EXTENSION_ID_LENGTH]
The unique extension ID's of each supported extension.
ModelRoutineName const Compute
The standard Compute routine.
int SetParameter(int const parameterIndex, int const arrayIndex, int const parameterValue)
Set a parameter value for the Model.
ComputeArgumentName const particleSpeciesCodes
The standard particleSpeciesCodes argument.
ComputeArgumentName const numberOfParticles
The standard numberOfParticles argument.
#define KIM_SUPPORTED_EXTENSIONS_ID
void fcc_cluster_neighborlist(int half, int numberOfParticles, double *coords, double cutoff, NeighList *nl)
void GetNumberOfParameters(int *const numberOfParameters) const
Get the number of parameter arrays provided by the Model.
ModelRoutineName const WriteParameterizedModel
The standard WriteParameterizedModel routine.
Provides the primary interface to a KIM API Model object and is meant to be used by simulators...
LanguageName const cpp
The standard cpp language.
std::string const & ToString() const
Converts the object to a string.
SupportStatus const required
The standard required status.
std::string const & ToString() const
Converts the object to a string.
int supportedExtensionRequired[KIM_MAX_NUMBER_OF_EXTENSIONS]
An Extensible Enumeration for the TemperatureUnit's supported by the KIM API.
LogVerbosity const error
The standard error verbosity.
int GetComputeArgumentDataType(ComputeArgumentName const computeArgumentName, DataType *const dataType)
Get the DataType of each defined standard ComputeArgumentName.
std::string const & ToString() const
Converts the object to a string.
std::string const & ToString() const
Converts the object to a string.
ChargeUnit const e
The standard electron unit of charge.
int GetComputeCallbackName(int const index, ComputeCallbackName *const computeCallbackName)
Get the identity of each defined standard ComputeCallbackName.
An Extensible Enumeration for the DataType's supported by the KIM API.
int GetParameterMetadata(int const parameterIndex, DataType *const dataType, int *const extent, std::string const **const name, std::string const **const description) const
Get the metadata associated with one of the Model's parameter arrays.
int IsRoutinePresent(ModelRoutineName const modelRoutineName, int *const present, int *const required) const
Determine presence and required status of the given ModelRoutineName.
int GetSpeciesSupportAndCode(SpeciesName const speciesName, int *const speciesIsSupported, int *const code) const
Get the Model's support and code for the requested SpeciesName.
ComputeArgumentName const particleContributing
The standard particleContributing argument.
int Extension(std::string const &extensionID, void *const extensionStructure)
Call the Model's MODEL_ROUTINE_NAME::Extension routine.
ComputeArgumentName const partialForces
The standard partialForces argument.
#define MY_ERROR(message)
int SetCallbackPointer(ComputeCallbackName const computeCallbackName, LanguageName const languageName, Function *const fptr, void *const dataObject)
Set the function pointer for a ComputeCallbackName.
int Compute(ComputeArguments const *const computeArguments) const
Call the Model's MODEL_ROUTINE_NAME::Compute routine.