KIM API V2
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 {
51  KIM::ModelDriverCreate * const modelDriverCreate,
52  KIM::LengthUnit const requestedLengthUnit,
53  KIM::EnergyUnit const requestedEnergyUnit,
54  KIM::ChargeUnit const requestedChargeUnit,
55  KIM::TemperatureUnit const requestedTemperatureUnit,
56  KIM::TimeUnit const requestedTimeUnit)
57 {
58  int ier;
59 
60  // read input files, convert units if needed, compute
61  // interpolation coefficients, set cutoff, and publish parameters
62  LennardJones612* const modelObject
63  = new LennardJones612(modelDriverCreate,
64  requestedLengthUnit,
65  requestedEnergyUnit,
66  requestedChargeUnit,
67  requestedTemperatureUnit,
68  requestedTimeUnit,
69  &ier);
70  if (ier)
71  {
72  // constructor already reported the error
73  delete modelObject;
74  return ier;
75  }
76 
77  // register pointer to LennardJones612 object in KIM object
78  modelDriverCreate->SetModelBufferPointer(static_cast<void*>(modelObject));
79 
80  // everything is good
81  ier = false;
82  return ier;
83 }
84 } // extern "C"
85 
86 //==============================================================================
87 //
88 // Implementation of LennardJones612 public wrapper functions
89 //
90 //==============================================================================
91 
92 //******************************************************************************
94  KIM::ModelDriverCreate * const modelDriverCreate,
95  KIM::LengthUnit const requestedLengthUnit,
96  KIM::EnergyUnit const requestedEnergyUnit,
97  KIM::ChargeUnit const requestedChargeUnit,
98  KIM::TemperatureUnit const requestedTemperatureUnit,
99  KIM::TimeUnit const requestedTimeUnit,
100  int* const ier)
101 {
102  implementation_ = new LennardJones612Implementation(
103  modelDriverCreate,
104  requestedLengthUnit,
105  requestedEnergyUnit,
106  requestedChargeUnit,
107  requestedTemperatureUnit,
108  requestedTimeUnit,
109  ier);
110 }
111 
112 //******************************************************************************
114 {
115  delete implementation_;
116 }
117 
118 //******************************************************************************
119 // static member function
121 {
122  LennardJones612 * modelObject;
123  modelDestroy->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
124 
125  if (modelObject != NULL)
126  {
127  // delete object itself
128  delete modelObject;
129  }
130 
131  // everything is good
132  return false;
133 }
134 
135 //******************************************************************************
136 // static member function
138  KIM::ModelRefresh * const modelRefresh)
139 {
140  LennardJones612 * modelObject;
141  modelRefresh->GetModelBufferPointer(
142  reinterpret_cast<void**>(&modelObject));
143 
144  return modelObject->implementation_->Refresh(modelRefresh);
145 }
146 
147 //******************************************************************************
148 // static member function
150  KIM::ModelCompute const * const modelCompute,
151  KIM::ModelComputeArguments const * const modelComputeArguments)
152 {
153  LennardJones612 * modelObject;
154  modelCompute->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
155 
156  return modelObject->implementation_->Compute(modelCompute,
157  modelComputeArguments);
158 }
159 
160 //******************************************************************************
161 // static member function
163  KIM::ModelCompute const * const modelCompute,
164  KIM::ModelComputeArgumentsCreate * const modelComputeArgumentsCreate)
165 {
166  LennardJones612 * modelObject;
167  modelCompute->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
168 
169  return modelObject->implementation_
170  ->ComputeArgumentsCreate(modelComputeArgumentsCreate);
171 }
172 
173 //******************************************************************************
174 // static member function
176  KIM::ModelCompute const * const modelCompute,
177  KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy)
178 {
179  LennardJones612 * modelObject;
180  modelCompute->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
181 
182  return modelObject->implementation_
183  ->ComputeArgumentsDestroy(modelComputeArgumentsDestroy);
184 }
int ComputeArgumentsCreate(KIM::ModelComputeArgumentsCreate *const modelComputeArgumentsCreate) const
static int Refresh(KIM::ModelRefresh *const modelRefresh)
void GetModelBufferPointer(void **const ptr) const
void SetModelBufferPointer(void *const ptr)
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)
static int ComputeArgumentsCreate(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArgumentsCreate *const modelComputeArgumentsCreate)
static int Destroy(KIM::ModelDestroy *const modelDestroy)
int Refresh(KIM::ModelRefresh *const modelRefresh)
void GetModelBufferPointer(void **const ptr) const
int ComputeArgumentsDestroy(KIM::ModelComputeArgumentsDestroy *const modelComputeArgumentsDestroy) const
static int ComputeArgumentsDestroy(KIM::ModelCompute const *const modelCompute, KIM::ModelComputeArgumentsDestroy *const modelComputeArgumentsDestroy)
void GetModelBufferPointer(void **const ptr) const
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)