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(
79  static_cast<void*>(modelObject));
80 
81  // everything is good
82  ier = false;
83  return ier;
84 }
85 }
86 
87 //==============================================================================
88 //
89 // Implementation of LennardJones612 public wrapper functions
90 //
91 //==============================================================================
92 
93 //******************************************************************************
95  KIM::ModelDriverCreate * const modelDriverCreate,
96  KIM::LengthUnit const requestedLengthUnit,
97  KIM::EnergyUnit const requestedEnergyUnit,
98  KIM::ChargeUnit const requestedChargeUnit,
99  KIM::TemperatureUnit const requestedTemperatureUnit,
100  KIM::TimeUnit const requestedTimeUnit,
101  int* const ier)
102 {
103  implementation_ = new LennardJones612Implementation(
104  modelDriverCreate,
105  requestedLengthUnit,
106  requestedEnergyUnit,
107  requestedChargeUnit,
108  requestedTemperatureUnit,
109  requestedTimeUnit,
110  ier);
111 }
112 
113 //******************************************************************************
115 {
116  delete implementation_;
117 }
118 
119 //******************************************************************************
120 // static member function
122 {
123  LennardJones612 * modelObject;
124  modelDestroy->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
125 
126  if (modelObject != NULL)
127  {
128  // delete object itself
129  delete modelObject;
130  }
131 
132  // everything is good
133  return false;
134 }
135 
136 //******************************************************************************
137 // static member function
139  KIM::ModelRefresh * const modelRefresh)
140 {
141  LennardJones612 * modelObject;
142  modelRefresh->GetModelBufferPointer(
143  reinterpret_cast<void**>(&modelObject));
144 
145  return modelObject->implementation_->Refresh(modelRefresh);
146 }
147 
148 //******************************************************************************
149 // static member function
150 int LennardJones612::Compute(KIM::ModelCompute const * const modelCompute)
151 {
152  LennardJones612 * modelObject;
153  modelCompute->GetModelBufferPointer(reinterpret_cast<void**>(&modelObject));
154 
155  return modelObject->implementation_->Compute(modelCompute);
156 }
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 Destroy(KIM::ModelDestroy *const modelDestroy)
int Refresh(KIM::ModelRefresh *const modelRefresh)
static int Compute(KIM::ModelCompute const *const modelCompute)
void GetModelBufferPointer(void **const ptr) const
int Compute(KIM::ModelCompute const *const modelCompute)
void GetModelBufferPointer(void **const ptr) const
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)