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))
211 MY_ERROR(
"Species Ar not supported");
216 if (error) {
MY_ERROR(
"Unable to create a ComputeArguments object."); }
219 int numberOfComputeArgumentNames;
221 &numberOfComputeArgumentNames);
222 for (
int i = 0; i < numberOfComputeArgumentNames; ++i)
232 if (error)
MY_ERROR(
"unable to get ComputeArgument SupportStatus");
234 std::cout <<
"ComputeArgument Name \"" << computeArgumentName.
ToString()
236 <<
" is of type \"" << dataType.
ToString() <<
"\"" 237 <<
" and has supportStatus \"" << supportStatus.
ToString() <<
"\"" 246 MY_ERROR(
"unsupported required ComputeArgument");
257 MY_ERROR(
"energy or forces not available");
263 int numberOfComputeCallbackNames;
265 &numberOfComputeCallbackNames);
266 for (
int i = 0; i < numberOfComputeCallbackNames; ++i)
274 std::cout <<
"ComputeCallback Name \"" << computeCallbackName.
ToString()
276 <<
" has supportStatus \"" << supportStatus.
ToString() <<
"\"" 282 MY_ERROR(
"unsupported required ComputeCallback");
286 int numberOfParameters;
288 for (
int i = 0; i < numberOfParameters; ++i)
291 std::string
const * strName;
292 std::string
const * strDesc;
295 i, &dataType, &extent, &strName, &strDesc);
296 std::cout <<
"Parameter No. " << i <<
" has" << std::endl
297 <<
" data type : \"" << dataType.
ToString() <<
"\"" << std::endl
298 <<
" extent : " << extent << std::endl
299 <<
" name : " << *strName << std::endl
300 <<
" description : " << *strDesc << std::endl;
307 if (error) {
MY_ERROR(
"Unable to get Extension present/required."); }
312 &supportedExtensions);
313 if (error) {
MY_ERROR(
"Error returned from KIM::Model::Extension()."); }
314 std::cout <<
"Model Supports " 316 <<
" Extensions:" << std::endl;
319 std::cout <<
" spportedExtensionID[" << std::setw(2) << i <<
"] = \"" 321 <<
"which has required = " 332 (
int *) &numberOfParticles_cluster)
335 particleSpecies_cluster_model)
338 particleContributing_cluster_model)
345 (
double *) forces_cluster);
346 if (error)
MY_ERROR(
"KIM_API_set_data");
352 if (error)
MY_ERROR(
"set_call_back");
355 int const * modelWillNotRequestNeighborsOfNoncontributingParticles;
357 &number_of_neighbor_lists,
358 &cutoff_cluster_model,
359 &modelWillNotRequestNeighborsOfNoncontributingParticles);
360 std::cout <<
"Model has influence distance of : " 361 << influence_distance_cluster_model << std::endl;
362 std::cout <<
"Model has numberOfNeighborLists : " << number_of_neighbor_lists
364 for (
int i = 0; i < number_of_neighbor_lists; ++i)
367 <<
"Neighbor list " << i <<
" has cutoff " 368 << cutoff_cluster_model[i]
370 "modelWillNotRequestNeighborsOfNoncontributingParticles " 371 << modelWillNotRequestNeighborsOfNoncontributingParticles[i]
375 if (number_of_neighbor_lists != 1)
MY_ERROR(
"too many neighbor lists");
378 int isSpeciesSupported;
382 &(particleSpecies_cluster_model[0]));
383 if (error)
MY_ERROR(
"get_species_code");
385 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
388 particleContributing_cluster_model[i] = 1;
400 std::ios oldState(NULL);
401 oldState.copyfmt(std::cout);
402 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
403 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
404 std::cout <<
"---------------------------------------------------------------" 405 "-----------------\n";
406 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
411 numberOfParticles_cluster,
412 &(coords_cluster[0][0]),
413 *cutoff_cluster_model,
418 &energy_cluster_model);
420 if (numberOfParameters > 0)
422 int index = numberOfParameters / 2;
424 std::string
const * name;
427 index, &dataType, NULL, &name, NULL);
428 if (error) {
MY_ERROR(
"Cannot get parameter metadata."); }
435 error = kim_cluster_model->
GetParameter(index, 0, &value);
436 if (error) {
MY_ERROR(
"Cannot get parameter value."); }
438 error = kim_cluster_model->
SetParameter(index, 0, value);
439 if (error) {
MY_ERROR(
"Cannot set parameter value."); }
441 if (error) {
MY_ERROR(
"Model ClearThenRefresh returned error."); }
443 std::cout << std::endl
444 <<
"Updated parameter \"" << *name <<
"\" to value " << value
448 &influence_distance_cluster_model);
450 &number_of_neighbor_lists,
451 &cutoff_cluster_model,
452 &modelWillNotRequestNeighborsOfNoncontributingParticles);
457 numberOfParticles_cluster,
458 &(coords_cluster[0][0]),
459 *cutoff_cluster_model,
464 &energy_cluster_model);
473 ".",
"This_IsTheNewModelName");
474 if (error) {
MY_ERROR(
"WriteParameterizedModel returned an error."); }
480 if (error) {
MY_ERROR(
"Unable to destroy compute arguments"); }
490 std::cout.copyfmt(oldState);
495 double const MaxSpacing,
496 double const SpacingIncr,
497 int const numberOfParticles_cluster,
498 double *
const coords_cluster,
503 double *
const forces_cluster,
504 double *
const energy_cluster_model)
506 double const cutpad = 0.75;
508 std::cout << std::setw(20) <<
"Energy" << std::setw(20) <<
"Force Norm" 509 << std::setw(20) <<
"Lattice Spacing" << std::endl;
510 for (
double CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing;
511 CurrentSpacing += SpacingIncr)
520 int error = kim_cluster_model->
Compute(computeArguments);
524 double force_norm = 0.0;
525 for (
int i = 0; i <
DIM * numberOfParticles_cluster; ++i)
527 force_norm += forces_cluster[i] * forces_cluster[i];
529 force_norm = sqrt(force_norm);
532 std::cout << std::setw(20) << *energy_cluster_model << std::setw(20)
533 << force_norm << std::setw(20) << CurrentSpacing << std::endl;
540 double FCCshifts[4][
DIM];
550 FCCshifts[0][0] = 0.0;
551 FCCshifts[0][1] = 0.0;
552 FCCshifts[0][2] = 0.0;
553 FCCshifts[1][0] = 0.5 * FCCspacing;
554 FCCshifts[1][1] = 0.5 * FCCspacing;
555 FCCshifts[1][2] = 0.0;
556 FCCshifts[2][0] = 0.5 * FCCspacing;
557 FCCshifts[2][1] = 0.0;
558 FCCshifts[2][2] = 0.5 * FCCspacing;
559 FCCshifts[3][0] = 0.0;
560 FCCshifts[3][1] = 0.5 * FCCspacing;
561 FCCshifts[3][2] = 0.5 * FCCspacing;
564 for (i = 0; i < nCellsPerSide; ++i)
566 latVec[0] = ((double) i) * FCCspacing;
567 for (j = 0; j < nCellsPerSide; ++j)
569 latVec[1] = ((double) j) * FCCspacing;
570 for (k = 0; k < nCellsPerSide; ++k)
572 latVec[2] = ((double) k) * FCCspacing;
573 for (m = 0; m < 4; ++
m)
575 for (n = 0; n <
DIM; ++n)
577 coords[a * DIM + n] = latVec[n] + FCCshifts[
m][n];
585 latVec[1] = ((double) i) * FCCspacing;
586 latVec[2] = ((double) j) * FCCspacing;
587 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
589 for (n = 0; n <
DIM; ++n)
591 coords[a * DIM + n] = latVec[n] + FCCshifts[3][n];
595 latVec[0] = ((double) i) * FCCspacing;
597 latVec[2] = ((double) j) * FCCspacing;
598 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
600 for (n = 0; n <
DIM; ++n)
602 coords[a * DIM + n] = latVec[n] + FCCshifts[2][n];
606 latVec[0] = ((double) i) * FCCspacing;
607 latVec[1] = ((double) j) * FCCspacing;
609 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
611 for (n = 0; n <
DIM; ++n)
613 coords[a * DIM + n] = latVec[n] + FCCshifts[1][n];
618 latVec[0] = ((double) i) * FCCspacing;
621 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
624 latVec[1] = ((double) i) * FCCspacing;
626 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
630 latVec[2] = ((double) i) * FCCspacing;
631 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
635 for (n = 0; n <
DIM; ++n)
663 cutoff2 = cutoff * cutoff;
671 for (k = 0; k <
DIM; ++k)
673 dx[k] = coords[j * DIM + k] - coords[i * DIM + k];
679 if ((half && i < j) || (!half && i != j))
688 (*nl).NNeighbors[i] = a;
695 int const numberOfNeighborLists,
696 double const *
const cutoffs,
697 int const neighborListIndex,
698 int const particleNumber,
699 int *
const numberOfNeighbors,
700 int const **
const neighborsOfParticle)
707 if ((numberOfNeighborLists != 1) || (cutoffs[0] > nl->
cutoff))
return error;
709 if (neighborListIndex != 0)
return error;
712 *numberOfNeighbors = 0;
714 if ((particleNumber >= numberOfParticles)
715 || (particleNumber < 0))
717 MY_WARNING(
"Invalid part ID in get_cluster_neigh");
722 *numberOfNeighbors = (*nl).NNeighbors[particleNumber];
726 = &((*nl).neighborList[(particleNumber) *numberOfParticles]);
int SetArgumentPointer(ComputeArgumentName const computeArgumentName, int const *const ptr)
Set the data pointer for a ComputeArgumentName.
ModelRoutineName const WriteParameterizedModel
The standard WriteParameterizedModel routine.
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 TemperatureUnit's supported by the KIM API.
SpeciesName const Ar
The standard Argon species.
An Extensible Enumeration for the TimeUnit's supported by the KIM API.
int WriteParameterizedModel(std::string const &path, std::string const &modelName) const
Call the Model's MODEL_ROUTINE_NAME::WriteParameterizedModel routine.
An Extensible Enumeration for the ModelRoutineName's supported by the KIM API.
int GetComputeCallbackName(int const index, ComputeCallbackName *const computeCallbackName)
Get the identity of each defined standard ComputeCallbackName.
std::string const & ToString() const
Converts the object to a string.
Contains the enumeration constants and the discovery routines for the ModelRoutineName Extensible Enu...
TimeUnit const ps
The standard picosecond unit of time.
ModelRoutineName const Extension
The standard Extension routine.
ModelRoutineName const Create
The standard Create routine.
#define KIM_SUPPORTED_EXTENSIONS_ID
ComputeArgumentName const coordinates
The standard coordinates argument.
void GetNumberOfComputeCallbackNames(int *const numberOfComputeCallbackNames)
Get the number of standard ComputeCallbackName's defined by the KIM API.
ModelRoutineName const Destroy
The standard Destroy routine.
char supportedExtensionID[KIM_MAX_NUMBER_OF_EXTENSIONS][KIM_MAX_EXTENSION_ID_LENGTH]
The unique extension ID's of each supported extension.
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.
ChargeUnit const e
The standard electron unit of charge.
void GetNumberOfComputeArgumentNames(int *const numberOfComputeArgumentNames)
Get the number of standard ComputeArgumentName's defined by the KIM API.
void GetNeighborListPointers(int *const numberOfNeighborLists, double const **const cutoffs, int const **const modelWillNotRequestNeighborsOfNoncontributingParticles) const
Get the Model's neighbor list information.
std::string const & ToString() const
Converts the object to a string.
An Extensible Enumeration for the DataType's supported by the KIM API.
int ComputeArgumentsCreate(ComputeArguments **const computeArguments) const
Create a new ComputeArguments object for the Model object.
ComputeCallbackName const GetNeighborList
The standard GetNeighborList callback.
An Extensible Enumeration for the ComputeCallbackName's supported by the KIM API. ...
SupportStatus const required
The standard required status.
An Extensible Enumeration for the LengthUnit's supported by the KIM API.
int Compute(ComputeArguments const *const computeArguments) const
Call the Model's MODEL_ROUTINE_NAME::Compute routine.
void() Function(void)
Generic function type.
int SetParameter(int const parameterIndex, int const arrayIndex, int const parameterValue)
Set a parameter value for the Model.
void GetInfluenceDistance(double *const influenceDistance) const
Get the Model's influence distance.
int Extension(std::string const &extensionID, void *const extensionStructure)
Call the Model's MODEL_ROUTINE_NAME::Extension routine.
An Extensible Enumeration for the SupportStatus's supported by the KIM API.
ComputeArgumentName const particleContributing
The standard particleContributing argument.
int GetCallbackSupportStatus(ComputeCallbackName const computeCallbackName, SupportStatus *const supportStatus) const
Get the SupportStatus of a ComputeCallbackName.
ComputeArgumentName const partialEnergy
The standard partialEnergy argument.
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)
ModelRoutineName const Refresh
The standard Refresh routine.
Provides the primary interface to a KIM API Model object and is meant to be used by simulators...
std::string const & ToString() const
Converts the object to a string.
std::string const & ToString() const
Converts the object to a string.
void create_FCC_cluster(double FCCspacing, int nCellsPerSide, double *coords)
ModelRoutineName const ComputeArgumentsCreate
The standard ComputeArgumentsCreate routine.
ModelRoutineName const ComputeArgumentsDestroy
The standard ComputeArgumentsDestroy routine.
LengthUnit const m
The standard meter unit of length.
static void Destroy(Model **const model)
Destroy a previously Model::Create'd object.
std::string const & ToString() const
Converts the object to a string.
An Extensible Enumeration for the EnergyUnit's supported by the KIM API.
LanguageName const cpp
The standard cpp language.
ModelRoutineName const Compute
The standard Compute routine.
int numberOfSupportedExtensions
The number of extensions supported by the Model.
int GetArgumentSupportStatus(ComputeArgumentName const computeArgumentName, SupportStatus *const supportStatus) const
Get the SupportStatus of a ComputeArgumentName.
int supportedExtensionRequired[KIM_MAX_NUMBER_OF_EXTENSIONS]
LengthUnit const A
The standard angstrom unit of length.
DataType const Double
The standard Double data type.
The only standard extension defined by the KIM API.
ComputeArgumentName const partialForces
The standard partialForces argument.
std::string const & ToString() const
Converts the object to a string.
std::string const & ToString() const
Converts the object to a string.
An Extensible Enumeration for the ComputeArgumentName's supported by the KIM API. ...
Provides the primary interface to a KIM API ComputeArguments object and is meant to be used by simula...
void GetNumberOfParameters(int *const numberOfParameters) const
Get the number of parameter arrays provided by the Model.
EnergyUnit const eV
The standard electronvolt unit of energy.
ComputeArgumentName const particleSpeciesCodes
The standard particleSpeciesCodes argument.
An Extensible Enumeration for the ChargeUnit's supported by the KIM API.
ComputeArgumentName const numberOfParticles
The standard numberOfParticles argument.
int GetParameter(int const parameterIndex, int const arrayIndex, int *const parameterValue) const
Get a parameter value from the Model.
int GetModelRoutineName(int const index, ModelRoutineName *const modelRoutineName)
Get the identity of each defined standard ModelRoutineName.
int GetSpeciesSupportAndCode(SpeciesName const speciesName, int *const speciesIsSupported, int *const code) const
Get the Model's support and code for the requested SpeciesName.
int ComputeArgumentsDestroy(ComputeArguments **const computeArguments) const
Destroy a previously Model::ComputeArgumentsCreate'd object.
#define MY_WARNING(message)
int SetCallbackPointer(ComputeCallbackName const computeCallbackName, LanguageName const languageName, Function *const fptr, void *const dataObject)
Set the function pointer for a ComputeCallbackName.
int IsRoutinePresent(ModelRoutineName const modelRoutineName, int *const present, int *const required) const
Determine presence and required status of the given ModelRoutineName.
#define MY_ERROR(message)
Numbering const zeroBased
The standard zeroBased numbering.
std::string const & ToString() const
Converts the object to a string.
std::string const & ToString() const
Converts the object to a string.
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)
int GetComputeArgumentDataType(ComputeArgumentName const computeArgumentName, DataType *const dataType)
Get the DataType of each defined standard ComputeArgumentName.
int GetComputeArgumentName(int const index, ComputeArgumentName *const computeArgumentName)
Get the identity of each defined standard ComputeArgumentName.
LogVerbosity const error
The standard error verbosity.
void GetNumberOfModelRoutineNames(int *const numberOfModelRoutineNames)
Get the number of standard ModelRoutineName's defined by the KIM API.
int ClearThenRefresh()
Clear influence distance and neighbor list pointers and refresh Model object after parameter changes...
void fcc_cluster_neighborlist(int half, int numberOfParticles, double *coords, double cutoff, NeighList *nl)
SupportStatus const optional
The standard optional status.
TemperatureUnit const K
The standard Kelvin unit of temperature.