Skip to content

Commit a1fa0bb

Browse files
authored
♻️ refactoring eGFRD (#481)
* 🔥 remove unused header file * 🔥 remove unused code, util.hpp * 🔥 remove unused functions * 🔥 remove a header file not included * 🔥 remove a file not included * ♻️ Wrap egfrd in namespace ecell4::egfrd To do that, the previous ecell4::egfrd::EGFRDSimulator and BDSimulator that are aliases of EGFRDSimulator<traits> are renamed as cell4::egfrd::DefaultEGFRDSimulator and DefaultBDSimulator. * ♻️ remove collection_value; use boost::range_value * ♻️ simplify egfrd/abstract_set - remove boost.range dependency - remove unary_function base class that is deprecated in C++11 - remove template struct partial specialization; use function overload - simplify function declaration * ♻️ refactror egfrd/neighbor_filter - remove boost dependency - simplify neighbor_filter implementation * ♻️ remove dependency to egfrd/utils/range * 🔥 remove range_support * ♻️ use unique_ptr to manage memory and remove map_adaptor and map_adaptor_handler * ✏️ fix namespace block end * 👽 update namespace specifier * ♻️ manually expand BOOST_PP_ENUM to reduce code * 🔥 re-remove removed files (mistake while merging) * 🔥 remove unused file * 🔥 re-remove removed file (mistake while merging) * 🔥 remove unused code * 🔥 remove needless include files * 🔥 remove unused code `factorial` is for GreensFunction that are now maintained as an independent library, greens_functions. * 🔥 remove Defs.hpp It has aliases to Real and Integer. However, since the egfrd module is now under the ecell4 namespace, we no longer need those aliases. Other aliseses and macros are currently not used. * 🔥 remove ParticleContainerBase the whole code is commented out * 🔥 remove unused codes * ♻️ reduce code in utils/pair.hpp * 🔥 remove delete_ptr functor * 🔥 remove needless code unassignable_adapter is currently not used * ♻️ further simplify stringize_and_join impl * 🔥 remove utils/fun_wrappers dereference<T> is replaced by lambda. others are not used. * 🔥 remove assoc_container_traits since we switched to C++11, we can always use std::unordered_map. Those meta-functions are no longer required. * ♻️ simplify egfrd/utils/fun_composition impl * ♻️ comment out element_type_of specializations that are currently not used * 🔥 remove unused macro definition * ♻️ avoid macro while defining create_vector * 🔥 remove call_with_size_if_randomly_accessible In the ancient era, the complexity of the size() method of std::list was not constant, it was O(N). The purpose of `call_with_size_if_...` seems that to avoid calling list.size() for the runtime efficiency. It checks whether the container is randomly accessible and call the passed function only if the container is randomly accessible (i.e. not an instance of std::list). After C++11, the complexity of std::list::size is constant. We no longer need to do this meta programing magic. * 🔥 remove unused functions * 🐛 add namespace specifier even inside assert * ♻️ use std::array instead of boost::array * 🔥 remove Transaction * 🔥 remove unused header file * 🔥 remove unused meta function * 🔥 remove unused template parameter * 🔥 remove call_traits; use const& everywhere * 🔥 remove boost/array header * 🔥 remove boost/type_traits and use <type_traits> * 🔥 remove boost::noncopyable and use `= delete` * 🔥 remove boost::enable_if and use std::enable_if * 🔥 replace boost/mpl/bool by <type_traits> * 🔥 remove unused header file * ♻️ use range-based for instead of BOOST_FOREACH * ➖ remove boost::multi_array from linear_algebra * ♻️ use core/exceptions in egfrd * 🔥 remove unused include file * ♻️ update included files * 🔥 remove unused function and file take_neighbor is used in the World::check_overlap through the traits. But now World::check_overlap has different implementation, so we don't need to have the filter function. * 🔥 remove unused functions * ⚡ mark simulator's static constant as constexpr * 🎨 remove extraneous whitespaces * 🔥 remove needless include * 🔥 re-remove removed files When merging the master branch, those files came back. * ♻️ simplify Logger implementation * 🔥 remove generic function that is used only once * ♻️ simplify shell_id_collector * 🚚 abstract_set -> utils/collection_contains * ♻️ simplify function composition remove compose_unary from EGFRDSimulator remove compose_unary rename compose_binary -> fun_composition * 🔥 remove consoleappender.cpp * 🔥 remove static function, use static constant * 🚚 move StructureVisitor to structures * ♻️ use constexpr value instead of static fn * 🔥 remove needless header * 🔥 remove unused include file * 🎨 remove extraneous whitespaces * 🎨 simplify implementation a bit * ♻️ move definition of inline fn to in-line * 🚚 move is_initialized to twofold_container.hpp * ✏️ fix typo in a variable name * ♻️ use static_vector instead of twofold_container * 🔥 remove unused vector funcs; use Real3 * 🎨 improve readability; add braces and aligned * 🚨 add override specifier * Revert "♻️ use static_vector instead of twofold_container" This reverts commit 658a394. Since twofold_container sorts contained variables, it may affect to the result of memberwise_compare and it may change the trajectory. * 🚚 make too short functions inline * 🚧 move polygon-related stuff to free function * 👽 update egfrd/Polygon interface * 🔥 remove unused function * ♻️ use range-based for instead of iterators * 🔥 remove unused member methods * 🚚 move triangle related funcs to FaceTriangle * ➖ use std type_traits instead of boost * ♻️ remove template from Polygon * 🐛 add missing include file * 🔥 remove unused functions * ♻️ use boost::optional for optional value * ♻️ make return value smaller * ♻️ simplify distance from point to triangle * ♻️ make ecell4 polygon interface similar to core * ♻️ add list_faces_within_radius with ignore to egfrd/polygon * ♻️ remove specializations of element_type_of * 🔥 remove FaceTriangle * ♻️ replace egfrd/polygon by core/polygon * 🔥 remove egfrd polygon related code * 🏁 add full namespace specifier * 🐛 fix apply_structure in egfrd World the function is called only when polygon is set. In some edge case, like particle is almost colliding to two or more boundaries in the same time (means particle is on an **edge**), the older code moves the particle through two boundaries at once and the assertion will fail. * 🚚 move geometry stuff to Polygon * ♻️ remove a forwarding function that just expand the parameters * ♻️ remove template parameters from geometry fns * ♻️ unify the format of include guard
1 parent 903efcb commit a1fa0bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+894
-5129
lines changed

ecell4/egfrd/AnalyticalPair.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef ANALYTICAL_PAIR_HPP
2-
#define ANALYTICAL_PAIR_HPP
1+
#ifndef ECELL4_EGFRD_ANALYTICAL_PAIR_HPP
2+
#define ECELL4_EGFRD_ANALYTICAL_PAIR_HPP
33

44
#include <cmath>
5-
#include <boost/array.hpp>
5+
#include <array>
66
#include "Pair.hpp"
77
#include "AnalyticalSingle.hpp"
88

ecell4/egfrd/AnalyticalSingle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef ANALYTICAL_SINGLE_HPP
2-
#define ANALYTICAL_SINGLE_HPP
1+
#ifndef ECELL4_EGFRD_ANALYTICAL_SINGLE_HPP
2+
#define ECELL4_EGFRD_ANALYTICAL_SINGLE_HPP
33

44
#include "Single.hpp"
55

ecell4/egfrd/BDPropagator.hpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BD_PROPAGATOR_HPP
2-
#define BD_PROPAGATOR_HPP
1+
#ifndef ECELL4_EGFRD_BD_PROPAGATOR_HPP
2+
#define ECELL4_EGFRD_BD_PROPAGATOR_HPP
33

44
#include <algorithm>
55
#include <limits>
@@ -9,8 +9,7 @@
99
#include <boost/range/begin.hpp>
1010
#include <boost/range/end.hpp>
1111
#include <boost/range/const_iterator.hpp>
12-
#include <boost/utility/enable_if.hpp>
13-
#include "Defs.hpp"
12+
#include <ecell4/core/types.hpp>
1413
#include "generator.hpp"
1514
#include "exceptions.hpp"
1615
#include "utils/random.hpp"
@@ -71,14 +70,10 @@ class BDPropagator
7170
queue_(), rejected_move_count_(0),
7271
potentials_(potentials)
7372
{
74-
call_with_size_if_randomly_accessible(
75-
boost::bind(&particle_id_vector_type::reserve, &queue_, _1),
76-
particles);
77-
for (typename boost::range_const_iterator<Trange_>::type
78-
i(boost::begin(particles)),
79-
e(boost::end(particles)); i != e; ++i)
73+
queue_.reserve(ecell4::egfrd::size(particles));
74+
for(const auto& p : particles)
8075
{
81-
queue_.push_back(*i);
76+
queue_.push_back(p);
8277
}
8378
shuffle(rng, queue_);
8479
}
@@ -99,7 +94,7 @@ class BDPropagator
9994
if (attempt_reaction(pp))
10095
return true;
10196
}
102-
catch (propagation_error const& reason)
97+
catch (PropagationError const& reason)
10398
{
10499
log_.info("first-order reaction rejected (reason: %s)", reason.what());
105100
++rejected_move_count_;
@@ -147,7 +142,7 @@ class BDPropagator
147142
++rejected_move_count_;
148143
}
149144
}
150-
catch (propagation_error const& reason)
145+
catch (PropagationError const& reason)
151146
{
152147
log_.info("second-order reaction rejected (reason: %s)", reason.what());
153148
++rejected_move_count_;
@@ -163,7 +158,7 @@ class BDPropagator
163158
}
164159
if (vc_)
165160
{
166-
if (!(*vc_)(shape(particle_to_update.second),
161+
if (!(*vc_)(shape(particle_to_update.second),
167162
particle_to_update.first))
168163
{
169164
log_.info("propagation move rejected.");
@@ -219,14 +214,14 @@ class BDPropagator
219214
pp.second.position(), s0.radius, s0.D));
220215
if (!tx_.no_overlap(shape(new_p.second), new_p.first))
221216
{
222-
throw propagation_error("no space");
217+
throw PropagationError("no space");
223218
}
224219

225220
if (vc_)
226221
{
227222
if (!(*vc_)(shape(new_p.second), pp.first))
228223
{
229-
throw propagation_error("no space");
224+
throw PropagationError("no space");
230225
}
231226
}
232227

@@ -258,7 +253,7 @@ class BDPropagator
258253
{
259254
if (--i < 0)
260255
{
261-
throw propagation_error("no space");
256+
throw PropagationError("no space");
262257
}
263258

264259
const Real rnd(rng_.random());
@@ -283,7 +278,7 @@ class BDPropagator
283278
{
284279
if (!(*vc_)(particle_shape_type(np0, s0.radius), pp.first) || !(*vc_)(particle_shape_type(np1, s1.radius), pp.first))
285280
{
286-
throw propagation_error("no space");
281+
throw PropagationError("no space");
287282
}
288283
}
289284

@@ -304,7 +299,7 @@ class BDPropagator
304299
}
305300
break;
306301
default:
307-
throw not_implemented("monomolecular reactions that produce more than two products are not supported");
302+
throw ::ecell4::NotImplemented("monomolecular reactions that produce more than two products are not supported");
308303
}
309304
return true;
310305
}
@@ -336,7 +331,7 @@ class BDPropagator
336331
prob += p;
337332
if (prob >= 1.)
338333
{
339-
throw propagation_error(
334+
throw PropagationError(
340335
"invalid acceptance ratio ("
341336
+ boost::lexical_cast<std::string>(p)
342337
+ ") for reaction rate "
@@ -368,16 +363,16 @@ class BDPropagator
368363
particle_shape_type(new_pos, sp.radius),
369364
pp0.first, pp1.first))
370365
{
371-
throw propagation_error("no space");
366+
throw PropagationError("no space");
372367
}
373368

374369
if (vc_)
375370
{
376371
if (!(*vc_)(
377-
particle_shape_type(new_pos, sp.radius),
372+
particle_shape_type(new_pos, sp.radius),
378373
pp0.first, pp1.first))
379374
{
380-
throw propagation_error("no space");
375+
throw PropagationError("no space");
381376
}
382377
}
383378

@@ -398,7 +393,7 @@ class BDPropagator
398393
remove_particle(pp1.first);
399394
break;
400395
default:
401-
throw not_implemented("bimolecular reactions that produce more than one product are not supported");
396+
throw ::ecell4::NotImplemented("bimolecular reactions that produce more than one product are not supported");
402397
}
403398

404399
return true;

ecell4/egfrd/BDSimulator.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef BD_SIMULATOR_HPP
2-
#define BD_SIMULATOR_HPP
1+
#ifndef ECELL4_EGFRD_BD_SIMULATOR_HPP
2+
#define ECELL4_EGFRD_BD_SIMULATOR_HPP
33

44
#include <algorithm>
55
#include <limits>
6-
#include <boost/foreach.hpp>
76

87
#include "BDPropagator.hpp"
98
#include "World.hpp"
@@ -162,7 +161,7 @@ class BDSimulator: public ParticleSimulator<Ttraits_>
162161
Real determine_dt()
163162
{
164163
Real prob = 0.0;
165-
BOOST_FOREACH(reaction_rule_type const& rr,
164+
for(reaction_rule_type const& rr:
166165
(*base_type::network_rules_).zeroth_order_reaction_rules())
167166
{
168167
prob += rr.k();
@@ -176,7 +175,7 @@ class BDSimulator: public ParticleSimulator<Ttraits_>
176175

177176
Real D_max(0.0), radius_min(std::numeric_limits<Real>::max());
178177

179-
BOOST_FOREACH(molecule_info_type info,
178+
for(molecule_info_type info:
180179
(*base_type::world_).get_molecule_info_range())
181180
{
182181
if (D_max < info.D)
@@ -224,7 +223,7 @@ class BDSimulator: public ParticleSimulator<Ttraits_>
224223
{
225224
attempt_zeroth_order_reaction(dt);
226225
}
227-
catch (no_space const&)
226+
catch (NoSpace const&)
228227
{
229228
LOG_DEBUG(("birth reaction rejected."));
230229
// ++rejected_moves_;
@@ -248,7 +247,7 @@ class BDSimulator: public ParticleSimulator<Ttraits_>
248247
base_type::rng().random() / (dt * (*base_type::world_).volume()));
249248
Real prob = 0.0;
250249

251-
BOOST_FOREACH(reaction_rule_type const& rr, rules)
250+
for(reaction_rule_type const& rr: rules)
252251
{
253252
prob += rr.k();
254253
if (prob > rnd)
@@ -270,7 +269,7 @@ class BDSimulator: public ParticleSimulator<Ttraits_>
270269
if (!(*base_type::world_).no_overlap(new_particle))
271270
{
272271
LOG_INFO(("no space for product particle."));
273-
throw no_space();
272+
throw NoSpace();
274273
}
275274

276275
particle_id_pair pp(

ecell4/egfrd/ConsoleAppender.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

ecell4/egfrd/ConsoleAppender.hpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef CONSOLE_LOGGER_HPP
2-
#define CONSOLE_LOGGER_HPP
3-
4-
#include <string>
5-
1+
#ifndef ECELL4_EGFRD_CONSOLE_LOGGER_HPP
2+
#define ECELL4_EGFRD_CONSOLE_LOGGER_HPP
63
#include "Logger.hpp"
4+
#include <cstdio>
5+
#include <cstring>
76

87
namespace ecell4
98
{
@@ -16,11 +15,22 @@ class ConsoleAppender: public LogAppender
1615
typedef LogAppender base_type;
1716

1817
public:
19-
virtual ~ConsoleAppender();
20-
21-
virtual void flush();
22-
23-
virtual void operator()(enum Logger::level lv, char const* name, char const** chunks);
18+
~ConsoleAppender() override = default;
19+
20+
void flush() override
21+
{
22+
std::fflush(stderr);
23+
}
24+
25+
void operator()(enum Logger::level lv, char const* name, char const** chunks) override
26+
{
27+
std::fprintf(stderr, "%s: %-8s ", name, Logger::stringize_error_level(lv));
28+
for (char const** p = chunks; *p; ++p)
29+
{
30+
std::fwrite(*p, sizeof(char), std::strlen(*p), stderr);
31+
}
32+
std::fputc('\n', stderr);
33+
}
2434
};
2535

2636
} // egfrd

ecell4/egfrd/Defs.hpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

ecell4/egfrd/Domain.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DOMAIN_HPP
2-
#define DOMAIN_HPP
1+
#ifndef ECELL4_EGFRD_DOMAIN_HPP
2+
#define ECELL4_EGFRD_DOMAIN_HPP
33

44
#include <string>
55
#include <cstddef>

ecell4/egfrd/DomainFactory.hpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

ecell4/egfrd/DomainID.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef DOMAIN_ID_HPP
2-
#define DOMAIN_ID_HPP
1+
#ifndef ECELL4_EGFRD_DOMAIN_ID_HPP
2+
#define ECELL4_EGFRD_DOMAIN_ID_HPP
33

44
#include <ostream>
55
#include <functional>

0 commit comments

Comments
 (0)