"wrappers/vscode:/vscode.git/clone" did not exist on "2504cf1ac4ad1a815ce1464a2562eb1b108315e9"
BrookStreamImpl.cpp 8.91 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
3
4
5
6
7
8
/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
9
10
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Authors: Mark Friedrichs, Mike Houston                                     *
Mark Friedrichs's avatar
Mark Friedrichs committed
11
12
 * Contributors:                                                              *
 *                                                                            *
13
14
15
16
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
Mark Friedrichs's avatar
Mark Friedrichs committed
17
 *                                                                            *
18
19
20
21
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
Mark Friedrichs's avatar
Mark Friedrichs committed
22
 *                                                                            *
23
24
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
Mark Friedrichs's avatar
Mark Friedrichs committed
25
26
 * -------------------------------------------------------------------------- */

27
#include "openmm/OpenMMException.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
28
29
#include "BrookStreamImpl.h"

30
31
#include <sstream>

Mark Friedrichs's avatar
Mark Friedrichs committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
using namespace OpenMM;
using namespace std;

/** 
 * BrookStreamImpl constructor
 *
 * @param name        stream name
 * @param size        stream size
 * @param streamWidth stream width
 * @param type        StreamImpl data type (float, float2, ...)
 * @param platform    platform reference
 * 
 */

BrookStreamImpl::BrookStreamImpl( const std::string& name, int size, int streamWidth, Stream::DataType type, const Platform& platform ) :
                                  StreamImpl( name, size, type, platform ){

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

   static const std::string methodName      = "BrookStreamImpl::BrookStreamImpl";

// ---------------------------------------------------------------------------------------
   
   int isFloat;
   BrookStreamInternal::DataType internalType = getTypeMap( type, &isFloat );

   if( isFloat == 1 || isFloat == 2 ){
      double dangleValue = 0.0;
      _brookStreamInternal = new BrookFloatStreamInternal(  name, size, streamWidth, internalType, dangleValue );
   } else if( isFloat == 0 ){
      int dangleValue = 0;
      _brookStreamInternal = new BrookIntStreamInternal(    name, size, streamWidth, internalType, dangleValue );
   } else {
      std::stringstream message;
      message << methodName << " type=" << type << " for stream=" << name << " is invalid.";
      throw OpenMMException( message.str() );
   }   

}

/** 
 * BrookStreamImpl destructor
 *
 */
BrookStreamImpl::~BrookStreamImpl( ){

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

   //static const std::string methodName      = "BrookStreamImpl::~BrookStreamImpl";

// ---------------------------------------------------------------------------------------
   
}

/** 
 * BrookStreamImpl constructor
 *
 * @param type        StreamImpl data type (float, float2, ...)
 * @param isFloat     on output = 1 if float
 *                                2 if double
 *                                0 if integer
 *
 * @return BrookStreamInternal::DataType mapping to Stream::DataType type
 *         if no match, return BrookStreamInternal::Unknown
 * 
 */

BrookStreamInternal::DataType BrookStreamImpl::getTypeMap( Stream::DataType type, int* isFloat ) const { 

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

   // static const std::string methodName      = "BrookStreamImpl::getTypeMap";

// ---------------------------------------------------------------------------------------
   
   *isFloat = 0;
   BrookStreamInternal::DataType internalType = BrookStreamInternal::Unknown;

   switch ( type ){

      case Stream::Float:

         internalType = BrookStreamInternal::Float;
         *isFloat      = 1;
         break;

      case Stream::Float2:

         internalType = BrookStreamInternal::Float2;
         *isFloat      = 1;
         break;

      case Stream::Float3:

         internalType = BrookStreamInternal::Float3;
         *isFloat      = 1;
         break;

      case Stream::Float4:

         internalType = BrookStreamInternal::Float4;
         *isFloat      = 1;
         break;

      case Stream::Double:

         internalType = BrookStreamInternal::Double;
         *isFloat      = 2;
         break;

      case Stream::Double2:

         internalType = BrookStreamInternal::Double2;
         *isFloat      = 2;
         break;

      case Stream::Double3:

         internalType = BrookStreamInternal::Double3;
         *isFloat      = 2;
         break;

      case Stream::Double4:

         internalType = BrookStreamInternal::Double4;
         *isFloat      = 2;
         break;

      case Stream::Integer:

         internalType = BrookStreamInternal::Integer;
         *isFloat      = 0;
         break;

      case Stream::Integer2:

         internalType = BrookStreamInternal::Integer2;
         *isFloat      = 0;
         break;

      case Stream::Integer3:

         internalType = BrookStreamInternal::Integer3;
         *isFloat      = 0;
         break;

      case Stream::Integer4:

         internalType = BrookStreamInternal::Integer4;
         *isFloat      = 0;
         break;
   }

   return internalType;
}

/** 
 * Get width
 * 
 * @return width
 */

int BrookStreamImpl::getWidth( void ) const {
   return _brookStreamInternal->getWidth();
}

/** 
 * Get stream width
 * 
 * @return stream width
 */

int BrookStreamImpl::getStreamWidth( void ) const {
   return _brookStreamInternal->getStreamWidth();
}

/** 
 * Get stream height
 * 
 * @return stream height
 */

int BrookStreamImpl::getStreamHeight( void ) const {
   return _brookStreamInternal->getStreamHeight();
}

/** 
 * Get stream size
 * 
 * @return stream size
 */

int BrookStreamImpl::getStreamSize( void ) const {
   return _brookStreamInternal->getStreamSize();
}

/** 
 * Copy the contents of an array into this stream.
 * 
 * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
 * and to contain elements of the correct data type for this stream.  If the stream has a compound data type, all
 * the values should be packed into a single array: all the values for the first element, followed by all the values
 * for the next element, etc.
 */
void BrookStreamImpl::loadFromArray( const void* array ){
   return _brookStreamInternal->loadFromArray( array );
}
  
/** 
 * Copy the contents of this stream into an array.
 * 
 * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
 * and to contain elements of the correct data type for this stream.  If the stream has a compound data type, all
 * the values should be packed into a single array: all the values for the first element, followed by all the values
 * for the next element, etc.
 */
void BrookStreamImpl::saveToArray( void* array ){
   return _brookStreamInternal->saveToArray( array );
}
  
/** 
 * Set every element of this stream to the same value.
 * 
 * @param a pointer to the value.  It is assumed to be of the correct data type for this stream.
 */
void BrookStreamImpl::fillWithValue( void* value ){
   return _brookStreamInternal->fillWithValue( value );
}

Mark Friedrichs's avatar
Mark Friedrichs committed
261
262
263
264
265
/** 
 * Set every element of this stream to the same value.
 * 
 * @return data array
 */
Mark Friedrichs's avatar
Mark Friedrichs committed
266
void* BrookStreamImpl::getData( void ){
Mark Friedrichs's avatar
Mark Friedrichs committed
267
268
269
   return _brookStreamInternal->getData( );
}

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
270
271
272
273
274
275
276
277
278
279
280
/** 
 * Set every element of this stream to the same value.
 *
 * @param readFromBoard if set, read data from board 
 *
 * @return data array
 */
void* BrookStreamImpl::getData( int readFromBoard ){
   return _brookStreamInternal->getData( readFromBoard );
}

Mark Friedrichs's avatar
Mark Friedrichs committed
281
282
283
284
285
286
287
288
289
290
/** 
 * Get Brook stream
 * 
 * @return Brook stream reference
 */

brook::stream& BrookStreamImpl::getBrookStream( void ){
   return _brookStreamInternal->getBrookStream( );
}

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
291
292
293
294
295
296
/** 
 * Get Brook stream impl 
 * 
 * @return Brook stream impl
 */

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
297
BrookStreamInternal* BrookStreamImpl::getBrookStreamInternal( void ) const {
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
298
299
   return _brookStreamInternal;
}