BrookStreamFactory.cpp 6.65 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
59
	_defaultDangleValue                      = 1.0e+38;
	_defaultAtomStreamWidth                  = 32;
60
61
62
63
64
65
66
67
68
69
70
71

}

/** 
 * BrookStreamFactory destructor
 * 
 */

BrookStreamFactory::~BrookStreamFactory( void ){
}

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

int BrookStreamFactory::getDefaultAtomStreamWidth( void ) const {

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

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

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

   return _defaultAtomStreamWidth;
}

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
106
107
108
109
110
111
112
113
114
// ---------------------------------------------------------------------------------------

   // validate atom stream width

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

   _defaultAtomStreamWidth = atomStreamWidth;

   return DefaultReturnValue;

121
122
123
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
124
 * get default dangle value
125
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
126
127
 * @return default dangle value
 *
128
129
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
130
131
132
133
134
double BrookStreamFactory::getDefaultDangleValue( void ) const {

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
136
// ---------------------------------------------------------------------------------------
137

Mark Friedrichs's avatar
Mark Friedrichs committed
138
   return _defaultDangleValue;
139
140
141
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
142
 * Set default dangle value
143
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
144
145
146
147
 * @param DefaultDangleValue default dangle value
 *
 * @return DefaultReturnValue
 *
148
149
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
150
151
152
153
154
155
156
157
158
159
160
int BrookStreamFactory::setDefaultDangleValue( double defaultDangleValue ){

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

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

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

   _defaultDangleValue = defaultDangleValue;

   return DefaultReturnValue;
161
162
163
164

}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
165
 * Create StreamInternal
166
167
168
169
170
 *
 * @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
171
 * @param context  context (currently ignored)
172
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
173
 * @return StreamInternal
174
175
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
176
177
StreamImpl* BrookStreamFactory::createStreamImpl( std::string name, int size, Stream::DataType type,
                                                  const Platform& platform, OpenMMContextImpl& context ) const {
178
179
180

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

Mark Friedrichs's avatar
Mark Friedrichs committed
181
   //static const std::string methodName      = "BrookStreamFactory::createStreamImpl";
182
183
184
185

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


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

Mark Friedrichs's avatar
Mark Friedrichs committed
188
   int streamWidth = getDefaultAtomStreamWidth();
189

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

Mark Friedrichs's avatar
Mark Friedrichs committed
192
}