Commit 90f31a68 authored by Christopher Bruns's avatar Christopher Bruns
Browse files

Many changes to build OpenMM on Windows:

1) Added DLL export macros to many classes; enough to get tests to compile
2) Cosmetic changes to reduce warnings in Visual Studio:
   a) change many "for (int i ="... to "for (size_t i ="... to avoid unsigned mismatch warnings
   b) included many explicit static_cast<OpenMMReal>() casts to document places where double->float conversion warnings occur
parent 3353081f
......@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */
#include "KernelImpl.h"
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -54,7 +55,7 @@ namespace OpenMM {
* </pre>
*/
class Kernel {
class OPENMM_EXPORT Kernel {
public:
Kernel();
Kernel(const Kernel& copy);
......
......@@ -35,6 +35,7 @@
#include "Platform.h"
#include <string>
#include <cassert>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -44,7 +45,7 @@ namespace OpenMM {
* will in turn subclass it and provide concrete implementations of the execute() method.
*/
class KernelImpl {
class OPENMM_EXPORT KernelImpl {
public:
/**
* Create a KernelImpl.
......
......@@ -35,6 +35,7 @@
#include "Stream.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -60,7 +61,7 @@ class StreamFactory;
* You can then call createKernel() and createStream() to construct particular kernels and streams as needed.
*/
class Platform {
class OPENMM_EXPORT Platform {
public:
virtual ~Platform();
/**
......@@ -168,9 +169,23 @@ public:
*/
static Platform& findPlatform(std::vector<std::string> kernelNames);
private:
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, StreamFactory*> streamFactories;
static std::vector<Platform*> platforms;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
} // namespace OpenMM
......
......@@ -33,10 +33,11 @@
* -------------------------------------------------------------------------- */
#include <string>
#include "internal/windowsExport.h"
namespace OpenMM {
class StreamImpl;
class OPENMM_EXPORT StreamImpl;
/**
* A Stream encapsulates a particular implementation of a stream of data elements. A Stream has three
......
......@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -42,7 +43,7 @@ namespace OpenMM {
* StreamImpls as needed.
*/
class StreamFactory {
class OPENMM_EXPORT StreamFactory {
public:
/**
* Create a StreamImpl.
......
......@@ -34,6 +34,7 @@
#include "Force.h"
#include <string>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -41,7 +42,7 @@ namespace OpenMM {
* This class uses the Andersen method to maintain constant temperature.
*/
class AndersenThermostat : public Force {
class OPENMM_EXPORT AndersenThermostat : public Force {
public:
/**
* This is the name of the parameter which stores the current temperature of the
......
......@@ -34,6 +34,7 @@
#include "Integrator.h"
#include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using Brownian dynamics.
*/
class BrownianIntegrator : public Integrator {
class OPENMM_EXPORT BrownianIntegrator : public Integrator {
public:
/**
* Create a BrownianIntegrator.
......
......@@ -34,6 +34,7 @@
#include "Force.h"
#include <string>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -42,7 +43,7 @@ namespace OpenMM {
* center of mass momentum, then adjusts the individual atom velocities to make it zero.
*/
class CMMotionRemover : public Force {
class OPENMM_EXPORT CMMotionRemover : public Force {
public:
/**
* Create a CMMotionRemover.
......
......@@ -32,6 +32,8 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "internal/windowsExport.h"
namespace OpenMM {
class ForceImpl;
......@@ -51,7 +53,7 @@ class ForceImpl;
* </ul>
*/
class Force {
class OPENMM_EXPORT Force {
public:
Force() {}
virtual ~Force() {
......
......@@ -34,6 +34,7 @@
#include "Force.h"
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -41,7 +42,7 @@ namespace OpenMM {
* This class implements an implicit solvation force using the GBSA-OBC model.
*/
class GBSAOBCForceField : public Force {
class OPENMM_EXPORT GBSAOBCForceField : public Force {
public:
/*
* Create a GBSAOBCForceField.
......@@ -102,7 +103,21 @@ protected:
private:
class AtomInfo;
double solventDielectric, soluteDielectric;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<AtomInfo> atoms;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class GBSAOBCForceField::AtomInfo {
......
......@@ -35,6 +35,7 @@
#include "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -49,7 +50,7 @@ class OpenMMContextImpl;
* is specified by passing the Integrator as an argument to the constructor of the OpenMMContext.
*/
class Integrator {
class OPENMM_EXPORT Integrator {
public:
virtual ~Integrator() {
}
......
......@@ -34,6 +34,7 @@
#include "Integrator.h"
#include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using Langevin dynamics.
*/
class LangevinIntegrator : public Integrator {
class OPENMM_EXPORT LangevinIntegrator : public Integrator {
public:
/**
* Create a LangevinIntegrator.
......
......@@ -37,6 +37,7 @@
#include "System.h"
#include <string>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -60,7 +61,7 @@ class Platform;
* atom and the current energy of the System.
*/
class OpenMMContext {
class OPENMM_EXPORT OpenMMContext {
public:
/**
* Construct a new OpenMMContext in which to run a simulation.
......
......@@ -35,6 +35,7 @@
#include "Force.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -48,7 +49,7 @@ namespace OpenMM {
* method to set the force field parameters for each one.
*/
class StandardMMForceField : public Force {
class OPENMM_EXPORT StandardMMForceField : public Force {
public:
/**
* Create a StandardMMForceField.
......@@ -216,11 +217,25 @@ private:
class AngleInfo;
class PeriodicTorsionInfo;
class RBTorsionInfo;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<AtomInfo> atoms;
std::vector<BondInfo> bonds;
std::vector<AngleInfo> angles;
std::vector<PeriodicTorsionInfo> periodicTorsions;
std::vector<RBTorsionInfo> rbTorsions;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class StandardMMForceField::AtomInfo {
......
......@@ -35,6 +35,7 @@
#include "Vec3.h"
#include <map>
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -49,7 +50,7 @@ namespace OpenMM {
* when the State was created), it will throw an exception.
*/
class State {
class OPENMM_EXPORT State {
public:
/**
* This is an enumeration of the types of data which may be stored in a State. When you create
......@@ -87,6 +88,15 @@ public:
private:
friend class OpenMMContext;
State(double time, int numAtoms, DataType types);
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<Vec3>& updPositions();
std::vector<Vec3>& updVelocities();
std::vector<Vec3>& updForces();
......@@ -98,6 +108,10 @@ private:
std::vector<Vec3> velocities;
std::vector<Vec3> forces;
std::map<std::string, double> parameters;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
......
......@@ -33,10 +33,11 @@
* -------------------------------------------------------------------------- */
#include <vector>
#include "internal/windowsExport.h"
namespace OpenMM {
class Force;
class OPENMM_EXPORT Force;
/**
* This class represents a molecular system. The definition of a System involves
......@@ -53,7 +54,7 @@ class Force;
* stores a list of Force objects that determine the motion of the atoms.
*/
class System {
class OPENMM_EXPORT System {
public:
/**
* Create a new System.
......@@ -134,9 +135,23 @@ public:
}
private:
class ConstraintInfo;
std::vector<double> masses;
// Retarded visual studio compiler complains about being unable to
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
#endif
std::vector<double> masses;
std::vector<ConstraintInfo> constraints;
std::vector<Force*> forces;
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};
class System::ConstraintInfo {
......
......@@ -34,6 +34,7 @@
#include "Integrator.h"
#include "Kernel.h"
#include "internal/windowsExport.h"
namespace OpenMM {
......@@ -41,7 +42,7 @@ namespace OpenMM {
* This is an Integrator which simulates a System using the leap-frog Verlet algorithm.
*/
class VerletIntegrator : public Integrator {
class OPENMM_EXPORT VerletIntegrator : public Integrator {
public:
/**
* Create a VerletIntegrator.
......
#ifndef OPENMM_WINDOWSEXPORT_H_
#define OPENMM_WINDOWSEXPORT_H_
/*
* Shared libraries are messy in Visual Studio. We have to distinguish three
* cases:
* (1) this header is being used to build the SimTKcommon shared library (dllexport)
* (2) this header is being used by a *client* of the SimTKcommon shared
* library (dllimport)
* (3) we are building the SimTKcommon static library, or the client is
* being compiled with the expectation of linking with the
* SimTKcommon static library (nothing special needed)
* In the CMake script for building this library, we define one of the symbols
* SimTK_SimTKCOMMON_BUILDING_{SHARED|STATIC}_LIBRARY
* Client code normally has no special symbol defined, in which case we'll
* assume it wants to use the shared library. However, if the client defines
* the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so
* that the client code can be linked with static libraries. Note that
* the client symbol is not library dependent, while the library symbols
* affect only the SimTKcommon library, meaning that other libraries can
* be clients of this one. However, we are assuming all-static or all-shared.
*/
#ifdef _MSC_VER
#if defined(OPENMM_BUILDING_SHARED_LIBRARY)
#define OPENMM_EXPORT __declspec(dllexport)
#elif defined(OPENMM_BUILDING_STATIC_LIBRARY) || defined(OPENMM_USE_STATIC_LIBRARIES)
#define OPENMM_EXPORT
#else
#define OPENMM_EXPORT __declspec(dllimport) // i.e., a client of a shared library
#endif
#else
#define OPENMM_EXPORT // Linux, Mac
#endif
#endif // OPENMM_WINDOWSEXPORT_H_
......@@ -45,7 +45,11 @@ using std::vector;
using std::string;
OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform) :
owner(owner), system(system), integrator(integrator), platform(platform), platformData(NULL) {
owner(owner), system(system),
integrator(integrator), platform(platform),
platformData(NULL),
time(0)
{
vector<string> kernelNames;
kernelNames.push_back(CalcKineticEnergyKernel::Name());
for (int i = 0; i < system.getNumForces(); ++i) {
......@@ -69,10 +73,10 @@ OpenMMContextImpl::OpenMMContextImpl(OpenMMContext& owner, System& system, Integ
velocities.fillWithValue(&zero);
kineticEnergyKernel = platform->createKernel(CalcKineticEnergyKernel::Name(), *this);
vector<double> masses(system.getNumAtoms());
for (int i = 0; i < masses.size(); ++i)
for (size_t i = 0; i < masses.size(); ++i)
masses[i] = system.getAtomMass(i);
dynamic_cast<CalcKineticEnergyKernel&>(kineticEnergyKernel.getImpl()).initialize(masses);
for (int i = 0; i < forceImpls.size(); ++i)
for (size_t i = 0; i < forceImpls.size(); ++i)
forceImpls[i]->initialize(*this);
integrator.initialize(*this);
}
......
......@@ -69,8 +69,8 @@ const map<string, double>& State::getParameters() const {
return parameters;
}
State::State(double time, int numAtoms, DataType types) : types(types), time(time), ke(0), pe(0),
positions(types&Positions == 0 ? 0 : numAtoms), velocities(types&Velocities== 0 ? 0 : numAtoms),
forces(types&Forces== 0 ? 0 : numAtoms) {
positions( (types & Positions) == 0 ? 0 : numAtoms), velocities( (types & Velocities) == 0 ? 0 : numAtoms),
forces( (types & Forces) == 0 ? 0 : numAtoms) {
}
vector<Vec3>& State::updPositions() {
return positions;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment