37 #define NAMESTRLEN 128 39 #define FCCSPACING 5.260 41 #define NCELLSPERSIDE 2 42 #define NCLUSTERPARTS \ 43 (4 * (NCELLSPERSIDE * NCELLSPERSIDE * NCELLSPERSIDE) \ 44 + 6 * (NCELLSPERSIDE * NCELLSPERSIDE) + 3 * (NCELLSPERSIDE) + 1) 46 #define MY_ERROR(message) \ 48 std::cout << "* Error : \"" << message << "\" : " << __LINE__ << ":" \ 49 << __FILE__ << std::endl; \ 53 #define MY_WARNING(message) \ 55 std::cout << "* Warning : \"" << message << "\" : " << __LINE__ << ":" \ 56 << __FILE__ << std::endl; \ 77 int const numberOfNeighborLists,
78 double const *
const cutoffs,
79 int const neighborListIndex,
80 int const particleNumber,
81 int *
const numberOfNeighbors,
82 int const **
const neighborsOfParticle);
87 double const MaxSpacing,
88 double const SpacingIncr,
89 int const numberOfParticles_cluster,
90 double *
const coords_cluster,
95 double *
const forces_cluster,
96 double *
const energy_cluster_model);
105 double const SpacingIncr = 0.025 *
FCCSPACING;
117 double influence_distance_cluster_model;
118 int number_of_neighbor_lists;
119 double const * cutoff_cluster_model;
120 double energy_cluster_model;
123 std::string modelname;
126 printf(
"Please enter valid KIM Model name: \n");
127 std::cin >> modelname;
132 int requestedUnitsAccepted;
140 &requestedUnitsAccepted,
142 if (error) {
MY_ERROR(
"KIM::Model::Create()"); }
145 if (!requestedUnitsAccepted) {
MY_ERROR(
"Must Adapt to model units"); }
148 int numberOfModelRoutineNames;
150 &numberOfModelRoutineNames);
151 for (
int i = 0; i < numberOfModelRoutineNames; ++i)
156 if (error) {
MY_ERROR(
"Unable to get ModelRoutineName."); }
160 modelRoutineName, &present, &required);
161 if (error) {
MY_ERROR(
"Unable to get routine present/required."); }
163 std::cout <<
"Model routine name \"" << modelRoutineName.
ToString()
164 <<
"\" has present = " << present
165 <<
" and required = " << required <<
"." << std::endl;
167 if ((present ==
true) && (required ==
true))
170 if (!((modelRoutineName ==
Create)
174 || (modelRoutineName ==
Destroy)))
177 +
"\" is required by model.");
190 &lengthUnit, &energyUnit, &chargeUnit, &temperatureUnit, &timeUnit);
192 std::cout <<
"LengthUnit is \"" << lengthUnit.ToString() <<
"\"" << std::endl
193 <<
"EnergyUnit is \"" << energyUnit.
ToString() <<
"\"" << std::endl
194 <<
"ChargeUnit is \"" << chargeUnit.
ToString() <<
"\"" << std::endl
195 <<
"TemperatureUnit is \"" << temperatureUnit.
ToString() <<
"\"" 197 <<
"TimeUnit is \"" << timeUnit.
ToString() <<
"\"" << std::endl;
200 int speciesIsSupported;
204 if ((error) || (!speciesIsSupported))
206 MY_ERROR(
"Species Ar not supported");
211 if (error) {
MY_ERROR(
"Unable to create a ComputeArguments object."); }
214 int numberOfComputeArgumentNames;
216 &numberOfComputeArgumentNames);
217 for (
int i = 0; i < numberOfComputeArgumentNames; ++i)
227 if (error)
MY_ERROR(
"unable to get ComputeArgument SupportStatus");
229 std::cout <<
"ComputeArgument Name \"" << computeArgumentName.
ToString()
231 <<
" is of type \"" << dataType.
ToString() <<
"\"" 232 <<
" and has supportStatus \"" << supportStatus.
ToString() <<
"\"" 241 MY_ERROR(
"unsupported required ComputeArgument");
252 MY_ERROR(
"energy or forces not available");
258 int numberOfComputeCallbackNames;
260 &numberOfComputeCallbackNames);
261 for (
int i = 0; i < numberOfComputeCallbackNames; ++i)
269 std::cout <<
"ComputeCallback Name \"" << computeCallbackName.
ToString()
271 <<
" has supportStatus \"" << supportStatus.
ToString() <<
"\"" 277 MY_ERROR(
"unsupported required ComputeCallback");
281 int numberOfParameters;
283 for (
int i = 0; i < numberOfParameters; ++i)
286 std::string
const * strName;
287 std::string
const * strDesc;
290 i, &dataType, &extent, &strName, &strDesc);
291 std::cout <<
"Parameter No. " << i <<
" has" << std::endl
292 <<
" data type : \"" << dataType.
ToString() <<
"\"" << std::endl
293 <<
" extent : " << extent << std::endl
294 <<
" name : " << *strName << std::endl
295 <<
" description : " << *strDesc << std::endl;
302 if (error) {
MY_ERROR(
"Unable to get Extension present/required."); }
307 &supportedExtensions);
308 if (error) {
MY_ERROR(
"Error returned from KIM::Model::Extension()."); }
309 std::cout <<
"Model Supports " 311 <<
" Extensions:" << std::endl;
314 std::cout <<
" spportedExtensionID[" << std::setw(2) << i <<
"] = \"" 316 <<
"which has required = " 327 (
int *) &numberOfParticles_cluster)
330 particleSpecies_cluster_model)
333 particleContributing_cluster_model)
340 (
double *) forces_cluster);
341 if (error)
MY_ERROR(
"KIM_API_set_data");
347 if (error)
MY_ERROR(
"set_call_back");
350 int const * modelWillNotRequestNeighborsOfNoncontributingParticles;
352 &number_of_neighbor_lists,
353 &cutoff_cluster_model,
354 &modelWillNotRequestNeighborsOfNoncontributingParticles);
355 std::cout <<
"Model has influence distance of : " 356 << influence_distance_cluster_model << std::endl;
357 std::cout <<
"Model has numberOfNeighborLists : " << number_of_neighbor_lists
359 for (
int i = 0; i < number_of_neighbor_lists; ++i)
362 <<
"Neighbor list " << i <<
" has cutoff " 363 << cutoff_cluster_model[i]
365 "modelWillNotRequestNeighborsOfNoncontributingParticles " 366 << modelWillNotRequestNeighborsOfNoncontributingParticles[i]
370 if (number_of_neighbor_lists != 1)
MY_ERROR(
"too many neighbor lists");
373 int isSpeciesSupported;
377 &(particleSpecies_cluster_model[0]));
378 if (error)
MY_ERROR(
"get_species_code");
380 particleSpecies_cluster_model[i] = particleSpecies_cluster_model[0];
383 particleContributing_cluster_model[i] = 1;
395 std::ios oldState(NULL);
396 oldState.copyfmt(std::cout);
397 std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(10);
398 std::cout <<
"This is Test : ex_test_Ar_fcc_cluster_cpp\n";
399 std::cout <<
"---------------------------------------------------------------" 400 "-----------------\n";
401 std::cout <<
"Results for KIM Model : " << modelname << std::endl;
406 numberOfParticles_cluster,
407 &(coords_cluster[0][0]),
408 *cutoff_cluster_model,
413 &energy_cluster_model);
415 if (numberOfParameters > 0)
417 int index = numberOfParameters / 2;
419 std::string
const * name;
422 index, &dataType, NULL, &name, NULL);
423 if (error) {
MY_ERROR(
"Cannot get parameter metadata."); }
430 error = kim_cluster_model->
GetParameter(index, 0, &value);
431 if (error) {
MY_ERROR(
"Cannot get parameter value."); }
433 error = kim_cluster_model->
SetParameter(index, 0, value);
434 if (error) {
MY_ERROR(
"Cannot set parameter value."); }
436 if (error) {
MY_ERROR(
"Model ClearThenRefresh returned error."); }
438 std::cout << std::endl
439 <<
"Updated parameter \"" << *name <<
"\" to value " << value
443 &influence_distance_cluster_model);
445 &number_of_neighbor_lists,
446 &cutoff_cluster_model,
447 &modelWillNotRequestNeighborsOfNoncontributingParticles);
452 numberOfParticles_cluster,
453 &(coords_cluster[0][0]),
454 *cutoff_cluster_model,
459 &energy_cluster_model);
468 ".",
"This_IsTheNewModelName");
469 if (error) {
MY_ERROR(
"WriteParameterizedModel returned an error."); }
475 if (error) {
MY_ERROR(
"Unable to destroy compute arguments"); }
485 std::cout.copyfmt(oldState);
490 double const MaxSpacing,
491 double const SpacingIncr,
492 int const numberOfParticles_cluster,
493 double *
const coords_cluster,
498 double *
const forces_cluster,
499 double *
const energy_cluster_model)
501 double const cutpad = 0.75;
503 std::cout << std::setw(20) <<
"Energy" << std::setw(20) <<
"Force Norm" 504 << std::setw(20) <<
"Lattice Spacing" << std::endl;
505 for (
double CurrentSpacing = MinSpacing; CurrentSpacing < MaxSpacing;
506 CurrentSpacing += SpacingIncr)
515 int error = kim_cluster_model->
Compute(computeArguments);
519 double force_norm = 0.0;
520 for (
int i = 0; i <
DIM * numberOfParticles_cluster; ++i)
522 force_norm += forces_cluster[i] * forces_cluster[i];
524 force_norm = sqrt(force_norm);
527 std::cout << std::setw(20) << *energy_cluster_model << std::setw(20)
528 << force_norm << std::setw(20) << CurrentSpacing << std::endl;
535 double FCCshifts[4][
DIM];
545 FCCshifts[0][0] = 0.0;
546 FCCshifts[0][1] = 0.0;
547 FCCshifts[0][2] = 0.0;
548 FCCshifts[1][0] = 0.5 * FCCspacing;
549 FCCshifts[1][1] = 0.5 * FCCspacing;
550 FCCshifts[1][2] = 0.0;
551 FCCshifts[2][0] = 0.5 * FCCspacing;
552 FCCshifts[2][1] = 0.0;
553 FCCshifts[2][2] = 0.5 * FCCspacing;
554 FCCshifts[3][0] = 0.0;
555 FCCshifts[3][1] = 0.5 * FCCspacing;
556 FCCshifts[3][2] = 0.5 * FCCspacing;
559 for (i = 0; i < nCellsPerSide; ++i)
561 latVec[0] = ((double) i) * FCCspacing;
562 for (j = 0; j < nCellsPerSide; ++j)
564 latVec[1] = ((double) j) * FCCspacing;
565 for (k = 0; k < nCellsPerSide; ++k)
567 latVec[2] = ((double) k) * FCCspacing;
568 for (m = 0; m < 4; ++
m)
570 for (n = 0; n <
DIM; ++n)
572 coords[a * DIM + n] = latVec[n] + FCCshifts[
m][n];
580 latVec[1] = ((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)
586 coords[a * DIM + n] = latVec[n] + FCCshifts[3][n];
590 latVec[0] = ((double) i) * FCCspacing;
592 latVec[2] = ((double) j) * FCCspacing;
593 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
595 for (n = 0; n <
DIM; ++n)
597 coords[a * DIM + n] = latVec[n] + FCCshifts[2][n];
601 latVec[0] = ((double) i) * FCCspacing;
602 latVec[1] = ((double) j) * FCCspacing;
604 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
606 for (n = 0; n <
DIM; ++n)
608 coords[a * DIM + n] = latVec[n] + FCCshifts[1][n];
613 latVec[0] = ((double) i) * FCCspacing;
616 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
619 latVec[1] = ((double) i) * FCCspacing;
621 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
625 latVec[2] = ((double) i) * FCCspacing;
626 for (n = 0; n <
DIM; ++n) { coords[a * DIM + n] = latVec[n]; }
630 for (n = 0; n <
DIM; ++n)
658 cutoff2 = cutoff * cutoff;
666 for (k = 0; k <
DIM; ++k)
668 dx[k] = coords[j * DIM + k] - coords[i * DIM + k];
674 if ((half && i < j) || (!half && i != j))
683 (*nl).NNeighbors[i] = a;
690 int const numberOfNeighborLists,
691 double const *
const cutoffs,
692 int const neighborListIndex,
693 int const particleNumber,
694 int *
const numberOfNeighbors,
695 int const **
const neighborsOfParticle)
702 if ((numberOfNeighborLists != 1) || (cutoffs[0] > nl->
cutoff))
return error;
704 if (neighborListIndex != 0)
return error;
707 *numberOfNeighbors = 0;
709 if ((particleNumber >= numberOfParticles)
710 || (particleNumber < 0))
712 MY_WARNING(
"Invalid part ID in get_cluster_neigh");
717 *numberOfNeighbors = (*nl).NNeighbors[particleNumber];
721 = &((*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.