kim-api  2.1.4-git+v2.1.3-git-3-g4c859c7f.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
simulator-model-example.cpp
Go to the documentation of this file.
1 //
2 // CDDL HEADER START
3 //
4 // The contents of this file are subject to the terms of the Common Development
5 // and Distribution License Version 1.0 (the "License").
6 //
7 // You can obtain a copy of the license at
8 // http://www.opensource.org/licenses/CDDL-1.0. See the License for the
9 // specific language governing permissions and limitations under the License.
10 //
11 // When distributing Covered Code, include this CDDL HEADER in each file and
12 // include the License file in a prominent location with the name LICENSE.CDDL.
13 // If applicable, add the following below this CDDL HEADER, with the fields
14 // enclosed by brackets "[]" replaced with your own identifying information:
15 //
16 // Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17 //
18 // CDDL HEADER END
19 //
20 
21 //
22 // Copyright (c) 2016--2019, Regents of the University of Minnesota.
23 // All rights reserved.
24 //
25 // Contributors:
26 // Ryan S. Elliott
27 //
28 
29 
30 #include "KIM_SimulatorHeaders.hpp"
31 #include <cstdlib>
32 #include <iomanip>
33 #include <iostream>
34 #include <string>
35 
36 int main()
37 {
40  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", &SM);
41 
42  if (error)
43  {
44  std::cout << "Can't create SM." << std::endl;
45  goto fail;
46  }
47 
48  {
49  std::string const * pSimulatorName;
50  std::string const * pSimulatorVersion;
51  SM->GetSimulatorNameAndVersion(&pSimulatorName, &pSimulatorVersion);
52  std::cout << "Simulator name : " << *pSimulatorName << std::endl
53  << "Simulator version : " << *pSimulatorVersion << std::endl
54  << std::endl;
55  }
56 
57  {
58  int extent;
59  SM->GetNumberOfSupportedSpecies(&extent);
60  std::cout << "SM supports " << extent << " species:" << std::endl;
61  for (int i = 0; i < extent; ++i)
62  {
63  std::string const * pSpecies;
64  error = SM->GetSupportedSpecies(i, &pSpecies);
65  if (error)
66  {
67  std::cout << "Unable to get species." << std::endl;
68  goto fail;
69  }
70  else
71  {
72  std::cout << "\t" << std::setw(2) << i << " " << *pSpecies << std::endl;
73  }
74  }
75  std::cout << std::endl;
76  }
77 
78  {
79  error = SM->AddTemplateMap("atom-type-sym-list", "Pb Pb Au Pb");
80  if (error)
81  {
82  std::cout << "Unable to add template map." << std::endl;
83  goto fail;
84  }
85  SM->CloseTemplateMap();
86  int numberFields;
87  SM->GetNumberOfSimulatorFields(&numberFields);
88  std::cout << "SM has " << std::setw(2) << numberFields
89  << " fields :" << std::endl;
90 
91  for (int i = 0; i < numberFields; ++i)
92  {
93  int extent;
94  std::string const * pFieldName;
95  error = SM->GetSimulatorFieldMetadata(i, &extent, &pFieldName);
96  std::cout << " Field " << std::setw(2) << i << " is " << *pFieldName
97  << " and has " << std::setw(2) << extent
98  << " lines:" << std::endl;
99  for (int j = 0; j < extent; ++j)
100  {
101  std::string const * pFieldLine;
102  error = SM->GetSimulatorFieldLine(i, j, &pFieldLine);
103  if (error)
104  {
105  std::cout << "Unable to get field line." << std::endl;
106  goto fail;
107  }
108  else
109  {
110  std::cout << "\t" << *pFieldLine << std::endl;
111  }
112  }
113  }
114  std::cout << std::endl;
115  }
116 
117  {
118  std::string const * pDirName;
119  SM->GetParameterFileDirectoryName(&pDirName);
120  std::cout << "SM param dir name is " << *pDirName << std::endl;
121 
122  std::string const * pSpecName;
123  SM->GetSpecificationFileName(&pSpecName);
124  std::cout << "SM spec file name is " << *pSpecName << std::endl
125  << std::endl;
126  error
127  = system((std::string("cat ") + *pDirName + "/" + *pSpecName).c_str());
128  std::cout << std::endl;
129 
130  int numberParamFiles;
131  SM->GetNumberOfParameterFiles(&numberParamFiles);
132  std::cout << "SM has " << numberParamFiles
133  << " parameter files:" << std::endl;
134  for (int i = 0; i < numberParamFiles; ++i)
135  {
136  std::string const * pParamFileName;
137  error = SM->GetParameterFileName(i, &pParamFileName);
138  if (error)
139  {
140  std::cout << "Unable to get parameter file name." << std::endl;
141  goto fail;
142  }
143  else
144  {
145  std::cout << "Parameter file " << std::setw(2) << i
146  << " has name : " << *pParamFileName << std::endl;
147  error = system(
148  (std::string("cat ") + *pDirName + "/" + *pParamFileName).c_str());
149  std::cout << std::endl;
150  }
151  }
152  }
153 
155  return false;
156 fail:
158  return true;
159 }
void GetSimulatorNameAndVersion(std::string const **const simulatorName, std::string const **const simulatorVersion) const
Get the SimulatorModel&#39;s simulator name and version.
void GetNumberOfParameterFiles(int *const numberOfParameterFiles) const
Get the number of parameter files provided by the SimulatorModel.
void GetNumberOfSupportedSpecies(int *const numberOfSupportedSpecies) const
Get the number of species supported by the SimulatorModel.
void GetSpecificationFileName(std::string const **const specificationFileName) const
Get the SimulatorModel&#39;s specification file basename (file name without path). The file is located in...
void CloseTemplateMap()
Close the template map and perform template substitutions.
static int Create(std::string const &simulatorModelName, SimulatorModel **const simulatorModel)
Create a new KIM API SimulatorModel object.
void GetParameterFileDirectoryName(std::string const **const directoryName) const
Get absolute path name of the temporary directory where parameter files provided by the simulator mod...
int AddTemplateMap(std::string const &key, std::string const &value)
Add a new key-value entry to the template map.
int GetParameterFileName(int const index, std::string const **const parameterFileName) const
Get the basename (file name without path) of a particular parameter file. The file is located in the ...
Provides the primary interface to a KIM API SimulatorModel object and is meant to be used by simulato...
int GetSupportedSpecies(int const index, std::string const **const speciesName) const
Get a species name supported by the SimulatorModel.
int GetSimulatorFieldMetadata(int const fieldIndex, int *const extent, std::string const **const fieldName) const
Get the metadata for the simulator field of interest.
Collection const system
The standard system Collection.
static void Destroy(SimulatorModel **const simulatorModel)
Destroy a previously SimulatorModel::Create&#39;d object.
int GetSimulatorFieldLine(int const fieldIndex, int const lineIndex, std::string const **const lineValue) const
Get a line for the simulator field of interest with all template substitutions performed (Requires th...
void GetNumberOfSimulatorFields(int *const numberOfSimulatorFields) const
Get the number of simulator fields provided by the SimulatorModel.