kim-api  2.2.1+v2.2.1.GNU.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 "LennardJones612.hpp"
33 #include <cstddef>
34 
35 
36 //==============================================================================
37 //
38 // This is the standard interface to KIM Model Drivers
39 //
40 //==============================================================================
41 
42 //******************************************************************************
43 extern "C" {
44 int model_driver_create(KIM::ModelDriverCreate * const modelDriverCreate,
45  KIM::LengthUnit const requestedLengthUnit,
46  KIM::EnergyUnit const requestedEnergyUnit,
47  KIM::ChargeUnit const requestedChargeUnit,
48  KIM::TemperatureUnit const requestedTemperatureUnit,
49  KIM::TimeUnit const requestedTimeUnit)
50 {
51  int ier;
52 
53  // read input files, convert units if needed, compute
54  // interpolation coefficients, set cutoff, and publish parameters
55  LennardJones612 * const modelObject
56  = new LennardJones612(modelDriverCreate,
57  requestedLengthUnit,
58  requestedEnergyUnit,
59  requestedChargeUnit,
60  requestedTemperatureUnit,
61  requestedTimeUnit,
62  &ier);
63  if (ier)
64  {
65  // constructor already reported the error
66  delete modelObject;
67  return ier;
68  }
69 
70  // register pointer to LennardJones612 object in KIM object
71  modelDriverCreate->SetModelBufferPointer(static_cast<void *>(modelObject));
72 
73  // everything is good
74  ier = false;
75  return ier;
76 }
77 } // extern "C"
78 
79 //==============================================================================
80 //
81 // Implementation of LennardJones612 public wrapper functions
82 //
83 //==============================================================================
84 
85 //******************************************************************************
87  KIM::ModelDriverCreate * const modelDriverCreate,
88  KIM::LengthUnit const requestedLengthUnit,
89  KIM::EnergyUnit const requestedEnergyUnit,
90  KIM::ChargeUnit const requestedChargeUnit,
91  KIM::TemperatureUnit const requestedTemperatureUnit,
92  KIM::TimeUnit const requestedTimeUnit,
93  int * const ier)
94 {
95  implementation_ = new LennardJones612Implementation(modelDriverCreate,
96  requestedLengthUnit,
97  requestedEnergyUnit,
98  requestedChargeUnit,
99  requestedTemperatureUnit,
100  requestedTimeUnit,
101  ier);
102 }
103 
104 //******************************************************************************
105 LennardJones612::~LennardJones612() { delete implementation_; }
106 
107 //******************************************************************************
108 // static member function
110 {
111  LennardJones612 * modelObject;
112  modelDestroy->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
113 
114  if (modelObject != NULL)
115  {
116  // delete object itself
117  delete modelObject;
118  }
119 
120  // everything is good
121  return false;
122 }
123 
124 //******************************************************************************
125 // static member function
127 {
128  LennardJones612 * modelObject;
129  modelRefresh->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
130 
131  return modelObject->implementation_->Refresh(modelRefresh);
132 }
133 
134 //******************************************************************************
135 // static member function
137  KIM::ModelCompute const * const modelCompute,
138  KIM::ModelComputeArguments const * const modelComputeArguments)
139 {
140  LennardJones612 * modelObject;
141  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
142 
143  return modelObject->implementation_->Compute(modelCompute,
144  modelComputeArguments);
145 }
146 
147 //******************************************************************************
148 // static member function
150  KIM::ModelCompute const * const modelCompute,
151  KIM::ModelComputeArgumentsCreate * const modelComputeArgumentsCreate)
152 {
153  LennardJones612 * modelObject;
154  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
155 
156  return modelObject->implementation_->ComputeArgumentsCreate(
157  modelComputeArgumentsCreate);
158 }
159 
160 //******************************************************************************
161 // static member function
163  KIM::ModelCompute const * const modelCompute,
164  KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy)
165 {
166  LennardJones612 * modelObject;
167  modelCompute->GetModelBufferPointer(reinterpret_cast<void **>(&modelObject));
168 
169  return modelObject->implementation_->ComputeArgumentsDestroy(
170  modelComputeArgumentsDestroy);
171 }
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)