Skip to content

Instantly share code, notes, and snippets.

@kaizu
Last active August 29, 2015 14:03
Show Gist options
  • Save kaizu/00e480fb3285b1296485 to your computer and use it in GitHub Desktop.
Save kaizu/00e480fb3285b1296485 to your computer and use it in GitHub Desktop.
diff --git a/ecell4/bd/functions3d.cpp b/ecell4/bd/functions3d.cpp
index f2a94c7..a1a4692 100644
--- a/ecell4/bd/functions3d.cpp
+++ b/ecell4/bd/functions3d.cpp
@@ -64,11 +64,11 @@ Real Igbd_r_3d(Real r, Real sigma, Real t, Real D)
const Real sigmasq(sigma * sigma);
const Real sigmacb(sigmasq * sigma);
- const Real rcb(gsl_pow_3(r));
+ const Real rcb(gsl_pow_int(r, 3));
const Real rsigma(r * sigma);
- const Real rps_sq(gsl_pow_2(r + sigma)), rms_sq(gsl_pow_2(r - sigma));
+ const Real rps_sq(gsl_pow_int(r + sigma, 2)), rms_sq(gsl_pow_int(r - sigma, 2));
const Real term1(-2 * sqrtDt / sqrtPi);
const Real term2(std::exp(-sigmasq / Dt) * (sigmasq - Dt2));
@@ -98,8 +98,11 @@ Real random_ipv_length_3d(
const Real ptot(Igbd_3d(sigma, t, D));
Igbd_r_3d_params params = {sigma, t, D, rng.uniform(0, 1) * ptot};
- gsl_function F = {
- reinterpret_cast<typeof(F.function)>(&Igbd_r_3d_F), &params};
+ gsl_function F;
+ F.function = reinterpret_cast<double (__cdecl *)(double,void *)>(&Igbd_r_3d_F);
+ F.params = &params;
+ // gsl_function F = {
+ // reinterpret_cast<typeof(F.function)>(&Igbd_r_3d_F), &params };
Real low(sigma), high(sigma + 10 * std::sqrt(6 * D * t));
diff --git a/ecell4/bd/functions3d.hpp b/ecell4/bd/functions3d.hpp
index 30dbf36..2dabcbd 100644
--- a/ecell4/bd/functions3d.hpp
+++ b/ecell4/bd/functions3d.hpp
@@ -5,12 +5,24 @@
#include <ecell4/core/Position3.hpp>
#include <ecell4/core/RandomNumberGenerator.hpp>
+#include <boost/math/special_functions/erf.hpp>
+
namespace ecell4
{
namespace bd
{
+inline Real erf(const Real& x)
+{
+ return boost::math::erf(x);
+}
+
+inline Real erfc(const Real& x)
+{
+ return boost::math::erfc(x);
+}
+
/**
* $\int_0^\infty r^2dr\,g\left(r,\Delta t\right),$
* where $g\left(r,\Delta t\right)$ is a probability that a pair, which is
diff --git a/ecell4/core/CMakeLists.txt b/ecell4/core/CMakeLists.txt
index 6b9f052..8593313 100644
--- a/ecell4/core/CMakeLists.txt
+++ b/ecell4/core/CMakeLists.txt
@@ -28,8 +28,13 @@ find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
# set(HAVE_BOOST_REGEX ${Boost_FOUND})
+#find_library(GSL_LIBRARIES gsl)
+#find_library(GSL_CBLAS_LIBRARIES gslcblas)
+
+#set(CMAKE_FIND_LIBRARY_PREFIXES "")
+#set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
find_library(GSL_LIBRARIES gsl)
-find_library(GSL_CBLAS_LIBRARIES gslcblas)
+find_library(GSL_CBLAS_LIBRARIES cblas)
include(CheckIncludeFileCXX)
# set(CMAKE_REQUIRED_INCLUDES "/usr/include")
@@ -51,7 +56,9 @@ configure_file(
${PROJECT_SOURCE_DIR}/ecell4/core/config.h.in
${PROJECT_BINARY_DIR}/ecell4/core/config.h)
-add_library(ecell4-core SHARED
+#add_library(ecell4-core SHARED
+# ${CPP_FILES} ${HPP_FILES} "${PROJECT_BINARY_DIR}/ecell4/core/config.h")
+add_library(ecell4-core
${CPP_FILES} ${HPP_FILES} "${PROJECT_BINARY_DIR}/ecell4/core/config.h")
target_link_libraries(ecell4-core
${HDF5_LIBRARIES} ${Boost_LIBRARIES} ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES})
diff --git a/ecell4/core/CompartmentSpace.cpp b/ecell4/core/CompartmentSpace.cpp
index 730f76b..8d94462 100644
--- a/ecell4/core/CompartmentSpace.cpp
+++ b/ecell4/core/CompartmentSpace.cpp
@@ -8,6 +8,11 @@
namespace ecell4
{
+Real cbrt(const Real& x)
+{
+ return pow(x, 1.0 / 3);
+}
+
const Real CompartmentSpaceVectorImpl::volume() const
{
return volume_;
diff --git a/ecell4/core/CompartmentSpace.hpp b/ecell4/core/CompartmentSpace.hpp
index 20476a9..67c0ae1 100644
--- a/ecell4/core/CompartmentSpace.hpp
+++ b/ecell4/core/CompartmentSpace.hpp
@@ -12,6 +12,8 @@
namespace ecell4
{
+Real cbrt(const Real& x);
+
class CompartmentSpace
: public Space
{
diff --git a/ecell4/core/DynamicPriorityQueue.hpp b/ecell4/core/DynamicPriorityQueue.hpp
index cb6558f..eb50da2 100644
--- a/ecell4/core/DynamicPriorityQueue.hpp
+++ b/ecell4/core/DynamicPriorityQueue.hpp
@@ -97,8 +97,9 @@ public:
typename index_map::const_iterator i(index_map_.find(id));
if (i == index_map_.end())
{
- throw std::out_of_range((boost::format("%s: Key not found (%s)") % __PRETTY_FUNCTION__ % boost::lexical_cast<std::string>(id)).str());
- }
+ throw std::out_of_range((boost::format("%s: Key not found (%s)") % __FUNCTION__ % boost::lexical_cast<std::string>(id)).str());
+ // throw std::out_of_range((boost::format("%s: Key not found (%s)") % __PRETTY_FUNCTION__ % boost::lexical_cast<std::string>(id)).str());
+ }
return (*i).second;
}
diff --git a/ecell4/core/EventScheduler.hpp b/ecell4/core/EventScheduler.hpp
index 7836e56..f4785c7 100644
--- a/ecell4/core/EventScheduler.hpp
+++ b/ecell4/core/EventScheduler.hpp
@@ -65,10 +65,10 @@ protected:
public:
- typedef typename EventPriorityQueue::size_type size_type;
- typedef typename EventPriorityQueue::identifier_type identifier_type;
- typedef typename EventPriorityQueue::value_type value_type;
- typedef boost::iterator_range<typename EventPriorityQueue::const_iterator>
+ typedef EventPriorityQueue::size_type size_type;
+ typedef EventPriorityQueue::identifier_type identifier_type;
+ typedef EventPriorityQueue::value_type value_type;
+ typedef boost::iterator_range<EventPriorityQueue::const_iterator>
events_range;
public:
diff --git a/ecell4/core/Journal.cpp b/ecell4/core/Journal.cpp
index 8b3f56e..cc9c898 100644
--- a/ecell4/core/Journal.cpp
+++ b/ecell4/core/Journal.cpp
@@ -38,7 +38,7 @@ void Journal::logv(enum level lv, char const* format, va_list ap)
return;
char buf[1024];
- std::vsnprintf(buf, sizeof(buf), format, ap);
+ vsnprintf(buf, sizeof(buf), format, ap);
std::fprintf(stderr, "%s: %-8s ", name_.c_str(), stringize_error_level(lv));
std::fwrite(buf, sizeof(char), std::strlen(buf), stderr);
diff --git a/ecell4/core/LatticeSpace.cpp b/ecell4/core/LatticeSpace.cpp
index 95eaf4a..e3e8b03 100644
--- a/ecell4/core/LatticeSpace.cpp
+++ b/ecell4/core/LatticeSpace.cpp
@@ -2,9 +2,17 @@
#include "VacantType.hpp"
#include "LatticeSpace.hpp"
+#include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
+
+
namespace ecell4
{
+Real rint(const Real& x)
+{
+ return boost::numeric::interval_lib::detail::rint(x);
+}
+
LatticeSpace::LatticeSpace(const Position3& edge_lengths,
const Real& voxel_radius, const bool is_periodic) :
voxel_radius_(voxel_radius), edge_lengths_(edge_lengths), t_(0),
@@ -29,9 +37,9 @@ LatticeSpace::~LatticeSpace()
*/
void LatticeSpace::set_lattice_properties(const bool is_periodic)
{
- HCP_L = voxel_radius_/sqrt(3);
+ HCP_L = voxel_radius_/sqrt(3.0);
HCP_X = voxel_radius_*sqrt(8.0/3); //Lx
- HCP_Y = voxel_radius_*sqrt(3); //Ly
+ HCP_Y = voxel_radius_*sqrt(3.0); //Ly
const Real lengthX = edge_lengths_[0];
const Real lengthY = edge_lengths_[1];
@@ -183,7 +191,7 @@ LatticeSpace::get_voxel(const ParticleID& pid) const
for (spmap::const_iterator i(spmap_.begin()); i != spmap_.end(); ++i)
{
const MolecularType& mt((*i).second);
- typename MolecularType::container_type::const_iterator j(mt.find(pid));
+ MolecularType::container_type::const_iterator j(mt.find(pid));
if (j != mt.end())
{
const coordinate_type coord(private2coord((*j).first));
@@ -384,7 +392,7 @@ bool LatticeSpace::remove_voxel(const ParticleID& pid)
for (spmap::iterator i(spmap_.begin()); i != spmap_.end(); ++i)
{
MolecularType& mt((*i).second);
- typename MolecularType::container_type::const_iterator j(mt.find(pid));
+ MolecularType::container_type::const_iterator j(mt.find(pid));
if (j != mt.end())
{
const private_coordinate_type coord((*j).first);
diff --git a/ecell4/core/LatticeSpace.hpp b/ecell4/core/LatticeSpace.hpp
index 3bf1c25..de6a698 100644
--- a/ecell4/core/LatticeSpace.hpp
+++ b/ecell4/core/LatticeSpace.hpp
@@ -17,6 +17,8 @@ namespace ecell4
class MolecularTypeBase;
class MolecularType;
+Real rint(const Real& x);
+
class LatticeSpace
: public Space
{
diff --git a/ecell4/core/ParticleSpace.cpp b/ecell4/core/ParticleSpace.cpp
index 3f37f48..e052699 100644
--- a/ecell4/core/ParticleSpace.cpp
+++ b/ecell4/core/ParticleSpace.cpp
@@ -102,8 +102,9 @@ std::vector<std::pair<std::pair<ParticleID, Particle>, Real> >
ParticleSpaceVectorImpl::list_particles_within_radius(
const Position3& pos, const Real& radius) const
{
- const Real rsq(gsl_pow_2(radius));
- std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
+ // const Real rsq(gsl_pow_2(radius));
+ const Real rsq(gsl_pow_int(radius, 2));
+ std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
for (particle_container_type::const_iterator i(particles_.begin());
i != particles_.end(); ++i)
@@ -122,8 +123,9 @@ std::vector<std::pair<std::pair<ParticleID, Particle>, Real> >
ParticleSpaceVectorImpl::list_particles_within_radius(
const Position3& pos, const Real& radius, const ParticleID& ignore) const
{
- const Real rsq(gsl_pow_2(radius));
- std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
+ // const Real rsq(gsl_pow_2(radius));
+ const Real rsq(gsl_pow_int(radius, 2));
+ std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
for (particle_container_type::const_iterator i(particles_.begin());
i != particles_.end(); ++i)
@@ -146,8 +148,9 @@ ParticleSpaceVectorImpl::list_particles_within_radius(
const Position3& pos, const Real& radius,
const ParticleID& ignore1, const ParticleID& ignore2) const
{
- const Real rsq(gsl_pow_2(radius));
- std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
+ const Real rsq(gsl_pow_int(radius, 2));
+ // const Real rsq(gsl_pow_2(radius));
+ std::vector<std::pair<std::pair<ParticleID, Particle>, Real> > retval;
for (particle_container_type::const_iterator i(particles_.begin());
i != particles_.end(); ++i)
diff --git a/ecell4/core/ParticleSpace.hpp b/ecell4/core/ParticleSpace.hpp
index d63a428..f1c04b5 100644
--- a/ecell4/core/ParticleSpace.hpp
+++ b/ecell4/core/ParticleSpace.hpp
@@ -221,16 +221,19 @@ public:
if (diff > half)
{
- retval += gsl_pow_2(diff - edge_length);
- }
+ retval += gsl_pow_int(diff - edge_length, 2);
+ // retval += gsl_pow_2(diff - edge_length);
+ }
else if (diff < -half)
{
- retval += gsl_pow_2(diff + edge_length);
- }
+ retval += gsl_pow_int(diff + edge_length, 2);
+ // retval += gsl_pow_2(diff + edge_length);
+ }
else
{
- retval += gsl_pow_2(diff);
- }
+ retval += gsl_pow_int(diff, 2);
+ // retval += gsl_pow_2(diff);
+ }
}
return retval;
}
diff --git a/ecell4/core/Position3.hpp b/ecell4/core/Position3.hpp
index f722a1d..d99e8ee 100644
--- a/ecell4/core/Position3.hpp
+++ b/ecell4/core/Position3.hpp
@@ -148,7 +148,8 @@ inline Position3 cross_product(const Position3& p1, const Position3& p2)
inline Position3::value_type length_sq(const Position3& r)
{
- return gsl_pow_2(r[0]) + gsl_pow_2(r[1]) + gsl_pow_2(r[2]);
+ // return gsl_pow_2(r[0]) + gsl_pow_2(r[1]) + gsl_pow_2(r[2]);
+ return gsl_pow_int(r[0], 2) + gsl_pow_int(r[1], 2) + gsl_pow_int(r[2], 2);
}
inline Position3::value_type length(const Position3& r)
diff --git a/ecell4/core/UnitSpecies.cpp b/ecell4/core/UnitSpecies.cpp
index 1042a83..0498217 100644
--- a/ecell4/core/UnitSpecies.cpp
+++ b/ecell4/core/UnitSpecies.cpp
@@ -3,11 +3,14 @@
#include "config.h"
-#if defined(HAVE_BOOST_REGEX)
-#include <boost/regex.hpp>
-#else
-#include <regex.h>
-#endif /* HAVE_BOOST_REGEX */
+//#if defined(HAVE_BOOST_REGEX)
+//#include <boost/regex.hpp>
+//#else
+//#include <regex.h>
+//#endif /* HAVE_BOOST_REGEX */
+
+#define HAVE_BOOST_REGEX
+#include <regex>
#include "UnitSpecies.hpp"
@@ -30,18 +33,20 @@ void UnitSpecies::deserialize(const UnitSpecies::serial_type& serial)
}
#if defined(HAVE_BOOST_REGEX)
- boost::regex r1(
+ using namespace std::tr1;
+
+ regex r1(
"^\\s*(\\w+)\\s*(\\(\\s*([\\w\\s\\^=,]*)\\))?\\s*$");
- boost::smatch results1;
- if (boost::regex_match(serial, results1, r1))
+ smatch results1;
+ if (regex_match(serial, results1, r1))
{
name_ = std::string(results1.str(1).c_str());
if (results1.str(3).size() > 0)
{
- boost::regex r2(
+ regex r2(
"\\s*(\\w+)(\\s*=\\s*(\\w+))?(\\s*\\^\\s*(\\w+))?\\s*");
// boost::match_results<std::string::const_iterator> results2;
- boost::smatch results2;
+ smatch results2;
std::vector<std::string> sites;
boost::split(
sites, static_cast<const std::string>(results1.str(3)),
@@ -50,7 +55,7 @@ void UnitSpecies::deserialize(const UnitSpecies::serial_type& serial)
for (std::vector<std::string>::const_iterator i(sites.begin());
i != sites.end(); ++i)
{
- if (boost::regex_match(*i, results2, r2))
+ if (regex_match(*i, results2, r2))
{
if (results2.str(3).size() > 0)
{
diff --git a/ecell4/core/types.hpp b/ecell4/core/types.hpp
index d869ab4..9643cae 100644
--- a/ecell4/core/types.hpp
+++ b/ecell4/core/types.hpp
@@ -2,8 +2,11 @@
#define __ECELL4_TYPES_HPP
#include <stdint.h>
+
+#define _USE_MATH_DEFINES
#include <math.h>
+
namespace ecell4
{
diff --git a/ecell4/ode/ODEWorld.hpp b/ecell4/ode/ODEWorld.hpp
index bf3c93d..7203a9e 100644
--- a/ecell4/ode/ODEWorld.hpp
+++ b/ecell4/ode/ODEWorld.hpp
@@ -3,7 +3,8 @@
#include <ecell4/core/Species.hpp>
#include <ecell4/core/Position3.hpp>
-#include <ecell4/core/Space.hpp>
+// #include <ecell4/core/Space.hpp>
+#include <ecell4/core/CompartmentSpace.hpp>
#include <ecell4/core/NetworkModel.hpp>
#include <ecell4/core/CompartmentSpaceHDF5Writer.hpp>
diff --git a/python/setup.py b/python/setup.py
index 307cbdf..c7e76c2 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -37,7 +37,7 @@ class run_tests(Command):
test_runner = unittest.TextTestRunner()
test_runner.run(suite)
-with_cpp_shared_libraries = True
+with_cpp_shared_libraries = False
if with_cpp_shared_libraries:
ext_modules = [
Extension("ecell4.core", sources=["lib/ecell4/core.pyx"],
@@ -57,26 +57,32 @@ if with_cpp_shared_libraries:
]
else:
dependent_libs = [
- 'gsl', 'gslcblas', 'm', 'hdf5_hl_cpp', 'hdf5_cpp', 'hdf5_hl', 'hdf5']
+ 'gsl', 'cblas', 'hdf5_hl_cpp_D', 'hdf5_cpp_D', 'hdf5_hl_D', 'hdf5_D']
+ # 'gsl', 'cblas', 'm', 'hdf5_hl_cpp', 'hdf5_cpp', 'hdf5_hl', 'hdf5']
core_src = glob.glob("../ecell4/core/*.cpp")
ext_modules = [
Extension("ecell4.core", sources=["lib/ecell4/core.pyx"] + core_src,
+ extra_compile_args=["/EHsc", "/w"],
include_dirs=[".", ".."], libraries=dependent_libs, language="c++"),
Extension("ecell4.gillespie",
sources=["lib/ecell4/gillespie.pyx"]
+ glob.glob("../ecell4/gillespie/*.cpp") + core_src,
+ extra_compile_args=["/EHsc", "/w"],
libraries=dependent_libs, include_dirs=[".", ".."], language="c++"),
Extension("ecell4.bd",
sources=["lib/ecell4/bd.pyx"]
+ glob.glob("../ecell4/bd/*.cpp") + core_src,
+ extra_compile_args=["/EHsc", "/w"],
libraries=dependent_libs, include_dirs=[".", ".."], language="c++"),
Extension("ecell4.ode",
sources=["lib/ecell4/ode.pyx"]
+ glob.glob("../ecell4/ode/*.cpp") + core_src,
+ extra_compile_args=["/EHsc", "/w"],
libraries=dependent_libs, include_dirs=[".", ".."], language="c++"),
Extension("ecell4.lattice",
sources=["lib/ecell4/lattice.pyx"]
+ glob.glob("../ecell4/lattice/*.cpp") + core_src,
+ extra_compile_args=["/EHsc", "/w"],
libraries=dependent_libs, include_dirs=[".", ".."], language="c++"),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment