BrookStreamFactory.cpp 9.69 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman, Mark Friedrichs                                    *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

32
#include <sstream>
Mark Friedrichs's avatar
Mark Friedrichs committed
33
34
#include "OpenMMException.h"
#include "BrookStreamFactory.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
35
#include "BrookStreamImpl.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
36
37
38

using namespace OpenMM;

39
40
41
42
const std::string BrookStreamFactory::AtomPositions              = "atomPositions";
const std::string BrookStreamFactory::AtomVelocities             = "atomVelocities";
const std::string BrookStreamFactory::AtomForces                 = "atomForces";

Mark Friedrichs's avatar
Mark Friedrichs committed
43
const double DefaultDangleValue                                  = 1.0e+38;
44
45
46
47
48
49
50
51
/** 
 * BrookStreamFactory constructor
 * 
 * @return BrookStreamFactory
 */

BrookStreamFactory::BrookStreamFactory( void ){

Mark Friedrichs's avatar
Mark Friedrichs committed
52
// ---------------------------------------------------------------------------------------
53

Mark Friedrichs's avatar
Mark Friedrichs committed
54
   //static const std::string methodName      = "BrookStreamFactory::BrookStreamFactory";
55

Mark Friedrichs's avatar
Mark Friedrichs committed
56
// ---------------------------------------------------------------------------------------
57

Mark Friedrichs's avatar
Mark Friedrichs committed
58
	_defaultDangleValue                      = 1.0e+38;
Mark Friedrichs's avatar
Mark Friedrichs committed
59
60
61
	_defaultAtomStreamWidth                  = DefaultStreamAtomWidth;
   _defaultStreamRandomNumberWidth          = DefaultStreamRandomNumberWidth;
   _defaultStreamRandomNumberSize           = DefaultStreamRandomNumberSize;
62
63
64
65
66
67
68
69
70
71
72
73

}

/** 
 * BrookStreamFactory destructor
 * 
 */

BrookStreamFactory::~BrookStreamFactory( void ){
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
74
75
76
 * Get atom stream width
 * 
 * @return atomStreamWidth
77
 *
Mark Friedrichs's avatar
Mark Friedrichs committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 */

int BrookStreamFactory::getDefaultAtomStreamWidth( void ) const {

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamFactory::getDefaultAtomStreamWidth";

// ---------------------------------------------------------------------------------------

   return _defaultAtomStreamWidth;
}

/** 
 * Set atom stream width
93
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
94
95
96
97
98
99
 * @param atomStreamWidth  atom stream width
 *
 * @return DefaultReturnValue
 *
 * @throw OpenMMException if atomStreamWidth < 1
 *
100
101
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
102
103
104
105
106
int BrookStreamFactory::setDefaultAtomStreamWidth( int atomStreamWidth ){

// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookStreamFactory::setDefaultAtomStreamWidth";
107

Mark Friedrichs's avatar
Mark Friedrichs committed
108
109
110
111
112
113
114
115
116
// ---------------------------------------------------------------------------------------

   // validate atom stream width

   if( atomStreamWidth < 1 ){
      std::stringstream message;
      message << methodName << " atomStreamWidth=" << atomStreamWidth << " is less than 1.";
      throw OpenMMException( message.str() );
      return ErrorReturnValue;
117
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
118
119
120
121
122

   _defaultAtomStreamWidth = atomStreamWidth;

   return DefaultReturnValue;

123
124
125
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
 * Get randomNumber stream width
 * 
 * @return randomNumberStreamWidth
 *
 */

int BrookStreamFactory::getDefaultRandomNumberStreamWidth( void ) const {

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamFactory::getDefaultRandomNumberStreamWidth";

// ---------------------------------------------------------------------------------------

   return _defaultStreamRandomNumberWidth;
}

/** 
 * Set randomNumber stream width
 * 
 * @param randomNumberStreamWidth  randomNumber stream width
 *
 * @return DefaultReturnValue
 *
 * @throw OpenMMException if randomNumberStreamWidth < 1
 *
 */

int BrookStreamFactory::setDefaultRandomNumberStreamWidth( int randomNumberStreamWidth ){

// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookStreamFactory::setDefaultRandomNumberStreamWidth";

// ---------------------------------------------------------------------------------------

   // validate randomNumber stream width

   if( randomNumberStreamWidth < 1 ){
      std::stringstream message;
      message << methodName << " randomNumberStreamWidth=" << randomNumberStreamWidth << " is less than 1.";
      throw OpenMMException( message.str() );
      return ErrorReturnValue;
   }

   _defaultStreamRandomNumberWidth = randomNumberStreamWidth;

   return DefaultReturnValue;

}

/*
 * Get randomNumber stream size
 * 
 * @return randomNumberStreamSize
 *
 */

int BrookStreamFactory::getDefaultRandomNumberStreamSize( void ) const {

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamFactory::getDefaultRandomNumberStreamSize";

// ---------------------------------------------------------------------------------------

   return _defaultStreamRandomNumberSize;
}

/** 
 * Set randomNumber stream size
 * 
 * @param randomNumberStreamSize  randomNumber stream size
 *
 * @return DefaultReturnValue
 *
 * @throw OpenMMException if randomNumberStreamSize < 1
 *
 */

int BrookStreamFactory::setDefaultRandomNumberStreamSize( int randomNumberStreamSize ){

// ---------------------------------------------------------------------------------------

   static const std::string methodName      = "BrookStreamFactory::setDefaultRandomNumberStreamSize";

// ---------------------------------------------------------------------------------------

   // validate randomNumber stream size

   if( randomNumberStreamSize < 1 ){
      std::stringstream message;
      message << methodName << " randomNumberStreamSize=" << randomNumberStreamSize << " is less than 1.";
      throw OpenMMException( message.str() );
      return ErrorReturnValue;
   }

   _defaultStreamRandomNumberSize = randomNumberStreamSize;

   return DefaultReturnValue;

}

/** 
 * Get default dangle value
231
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
232
233
 * @return default dangle value
 *
234
235
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
236
237
238
239
240
double BrookStreamFactory::getDefaultDangleValue( void ) const {

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamFactory::getDefaultDangleValue";
241

Mark Friedrichs's avatar
Mark Friedrichs committed
242
// ---------------------------------------------------------------------------------------
243

Mark Friedrichs's avatar
Mark Friedrichs committed
244
   return _defaultDangleValue;
245
246
247
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
248
 * Set default dangle value
249
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
250
251
252
253
 * @param DefaultDangleValue default dangle value
 *
 * @return DefaultReturnValue
 *
254
255
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
256
257
258
259
260
261
262
263
264
265
266
int BrookStreamFactory::setDefaultDangleValue( double defaultDangleValue ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamFactory::setDefaultDangleValue";

// ---------------------------------------------------------------------------------------

   _defaultDangleValue = defaultDangleValue;

   return DefaultReturnValue;
267
268
269
270

}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
271
 * Create StreamInternal
272
273
274
275
276
 *
 * @param name     stream name
 * @param size     stream size
 * @param type     data type (float, float2, ...)
 * @param platform platform reference
Mark Friedrichs's avatar
Mark Friedrichs committed
277
 * @param context  context (currently ignored)
278
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
279
 * @return StreamInternal
280
281
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
282
283
StreamImpl* BrookStreamFactory::createStreamImpl( std::string name, int size, Stream::DataType type,
                                                  const Platform& platform, OpenMMContextImpl& context ) const {
284
285
286

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
287
   //static const std::string methodName      = "BrookStreamFactory::createStreamImpl";
288
289
290
291

// ---------------------------------------------------------------------------------------


Mark Friedrichs's avatar
Mark Friedrichs committed
292
   // stream width hould be based on name & value set in platform; for now only atom stream types
293

Mark Friedrichs's avatar
Mark Friedrichs committed
294
   int streamWidth = getDefaultAtomStreamWidth();
295

Mark Friedrichs's avatar
Mark Friedrichs committed
296
   return new BrookStreamImpl( name, size, streamWidth, type, platform );
297

Mark Friedrichs's avatar
Mark Friedrichs committed
298
}