kim-api  2.1.2+v2.1.2.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
LennardJones612.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) 2015, Regents of the University of Minnesota.
23 // All rights reserved.
24 //
25 // Contributors:
26 // Ryan S. Elliott
27 // Andrew Akerson
28 //
29 
30 
31 #include <cmath>
32 #include <cstdlib>
33 #include <cstring>
34 #include <fstream>
35 #include <iostream>
36 
37 #include "LennardJones612.hpp"
39 
40 
41 //==============================================================================
42 //
43 // This is the standard interface to KIM Model Drivers
44 //
45 //==============================================================================
46 
47 //******************************************************************************
48 extern "C" {
49 int model_driver_create(KIM::ModelDriverCreate * const modelDriverCreate,
50  KIM::LengthUnit const requestedLengthUnit,
51  KIM::EnergyUnit const requestedEnergyUnit,
52  KIM::ChargeUnit const requestedChargeUnit,
53  KIM::TemperatureUnit const requestedTemperatureUnit,
54  KIM::TimeUnit const requestedTimeUnit)
55 {
56  int ier;
57 
58  // read input files, convert units if needed, compute
59  // interpolation coefficients, set cutoff, and publish parameters
60  LennardJones612 * const modelObject
61  = new LennardJones612(modelDriverCreate,
62  requestedLengthUnit,
63  requestedEnergyUnit,
64  requestedChargeUnit,
65  requestedTemperatureUnit,
66  requestedTimeUnit,
67  &ier);
68  if (ier)
69  {
70  // constructor already reported the error
71  delete modelObject;
72  return ier;
73  }
74 
75  // register pointer to LennardJones612 object in KIM object
76  modelDriverCreate->SetModelBufferPointer(static_cast<void *>(modelObject));
77 
78  // everything is good
79  ier = false;
80  return ier;
81 }
82 } // extern "C"
83 
84 //==============================================================================
85 //
86 // Implementation of LennardJones612 public wrapper functions
87 //
88 //==============================================================================
89 
90 //******************************************************************************
92  KIM::ModelDriverCreate * const modelDriverCreate,
93  KIM::LengthUnit const requestedLengthUnit,
94  KIM::EnergyUnit const requestedEnergyUnit,
95  KIM::ChargeUnit const requestedChargeUnit,
96  KIM::TemperatureUnit const requestedTemperatureUnit,
97  KIM::TimeUnit const requestedTimeUnit,
98  int * const ier)
99 {
100  implementation_ = new LennardJones612Implementation(modelDriverCreate,
101  requestedLengthUnit,
102  requestedEnergyUnit,
103  requestedChargeUnit,
104  requestedTemperatureUnit,
105  requestedTimeUnit,
106  ier);
107 }
108 
109 //******************************************************************************
110 LennardJones612::~LennardJones612() { delete implementation_; }
111 
112 //******************************************************************************
113 // static member function
115 {
116  LennardJones612 * modelObject;
117  modelDestroy->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
118 
119  if (modelObject != NULL)
120  {
121  // delete object itself
122  delete modelObject;
123  }
124 
125  // everything is good
126  return false;
127 }
128 
129 //******************************************************************************
130 // static member function
132 {
133  LennardJones612 * modelObject;
134  modelRefresh->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
135 
136  return modelObject->implementation_->Refresh(modelRefresh);
137 }
138 
139 //******************************************************************************
140 // static member function
142  KIM::ModelCompute const * const modelCompute,
143  KIM::ModelComputeArguments const * const modelComputeArguments)
144 {
145  LennardJones612 * modelObject;
146  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
147 
148  return modelObject->implementation_->Compute(modelCompute,
149  modelComputeArguments);
150 }
151 
152 //******************************************************************************
153 // static member function
155  KIM::ModelCompute const * const modelCompute,
156  KIM::ModelComputeArgumentsCreate * const modelComputeArgumentsCreate)
157 {
158  LennardJones612 * modelObject;
159  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
160 
161  return modelObject->implementation_->ComputeArgumentsCreate(
162  modelComputeArgumentsCreate);
163 }
164 
165 //******************************************************************************
166 // static member function
168  KIM::ModelCompute const * const modelCompute,
169  KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy)
170 {
171  LennardJones612 * modelObject;
172  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
173 
174  return modelObject->implementation_->ComputeArgumentsDestroy(
175  modelComputeArgumentsDestroy);
176 }
int ComputeArgumentsCreate(KIM::ModelComputeArgumentsCreate *const modelComputeArgumentsCreate) const
Provides the interface to a KIM API Model object for use by models within their MODEL_ROUTINE_NAME::R...
An Extensible Enumeration for the TemperatureUnit&#39;s supported by the KIM API.
static int Refresh(KIM::ModelRefresh *const modelRefresh)
An Extensible Enumeration for the TimeUnit&#39;s supported by the KIM API.
void GetModelBufferPointer(void **const ptr) const
Get the Model&#39;s buffer pointer within the Model object.
void SetModelBufferPointer(void *const ptr)
Set the Model&#39;s buffer pointer within the Model object.
An Extensible Enumeration for the LengthUnit&#39;s supported by the KIM API.
LennardJones612(KIM::ModelDriverCreate *const modelDriverCreate, KIM::LengthUnit const requestedLengthUnit, KIM::EnergyUnit const requestedEnergyUnit, KIM::ChargeUnit const requestedChargeUnit, KIM::TemperatureUnit const requestedTemperatureUnit, KIM::TimeUnit const requestedTimeUnit, int *const ier)
Provides the interface to a KIM API Model object for use by models within their MODEL_ROUTINE_NAME::D...
Provides the interface to a KIM API Model object for use by models within their MODEL_ROUTINE_NAME::C...
static int ComputeArgumentsCreate(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArgumentsCreate *const modelComputeArgumentsCreate)
Provides the interface to a KIM API Model object for use by models within their MODEL_ROUTINE_NAME::C...
Provides the interface to a KIM API ComputeArguments object for use by models within their MODEL_ROUT...
static int Destroy(KIM::ModelDestroy *const modelDestroy)
An Extensible Enumeration for the EnergyUnit&#39;s supported by the KIM API.
int Refresh(KIM::ModelRefresh *const modelRefresh)
Provides the interface to a KIM API ComputeArguments object for use by models within their MODEL_ROUT...
void GetModelBufferPointer(void **const ptr) const
Get the Model&#39;s buffer pointer within the Model object.
int ComputeArgumentsDestroy(KIM::ModelComputeArgumentsDestroy *const modelComputeArgumentsDestroy) const
static int ComputeArgumentsDestroy(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArgumentsDestroy *const modelComputeArgumentsDestroy)
Provides the interface to a KIM API ComputeArguments object for use by models within their MODEL_ROUT...
An Extensible Enumeration for the ChargeUnit&#39;s supported by the KIM API.
void GetModelBufferPointer(void **const ptr) const
Get the Model&#39;s buffer pointer within the Model object.
int Compute(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArguments const *const modelComputeArguments)
static int Compute(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArguments const *const modelComputeArguments)
int model_driver_create(KIM::ModelDriverCreate *const modelDriverCreate, KIM::LengthUnit const requestedLengthUnit, KIM::EnergyUnit const requestedEnergyUnit, KIM::ChargeUnit const requestedChargeUnit, KIM::TemperatureUnit const requestedTemperatureUnit, KIM::TimeUnit const requestedTimeUnit)