Skip to content

Commit

Permalink
Adjust tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Jan 13, 2024
1 parent 10a492d commit 00ac312
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
10 changes: 5 additions & 5 deletions arbor/include/arbor/cable_cell_param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct ARB_SYMBOL_VISIBLE init_membrane_potential {
init_membrane_potential() = default;
init_membrane_potential(const U::quantity& m, iexpr scale=1):
value(m.value_as(U::mV)), scale{scale} {
if (!std::isnan(value)) throw std::domain_error{"Value must be finite and in [mV]."};
if (std::isnan(value)) throw std::domain_error{"Value must be finite and in [mV]."};
}
};

Expand Down Expand Up @@ -461,13 +461,13 @@ struct ARB_SYMBOL_VISIBLE cable_cell_global_properties {

auto &ion_data = default_parameters.ion_data[ion_name];
ion_data.init_int_concentration = init_iconc.value_as(U::mM);
if (std::isnan(*ion_data.init_int_concentration)) throw cable_cell_error("init_int_concentration must be finite and convertible to mM");
if (std::isnan(*ion_data.init_int_concentration)) throw std::domain_error("init_int_concentration must be finite and convertible to mM");
ion_data.init_ext_concentration = init_econc.value_as(U::mM);
if (std::isnan(*ion_data.init_ext_concentration)) throw cable_cell_error("init_ext_concentration must be finite and convertible to mM");
if (std::isnan(*ion_data.init_ext_concentration)) throw std::domain_error("init_ext_concentration must be finite and convertible to mM");
ion_data.init_reversal_potential = init_revpot.value_as(U::mV);
if (std::isnan(*ion_data.init_reversal_potential)) throw cable_cell_error("init_reversal_potential must be finite and convertible to mV");
if (std::isnan(*ion_data.init_reversal_potential)) throw std::domain_error("init_reversal_potential must be finite and convertible to mV");
ion_data.diffusivity = diffusivity.value_as(U::m2/U::s);
if (std::isnan(*ion_data.diffusivity) || *ion_data.diffusivity < 0) throw cable_cell_error("diffusivity must be positive, finite, and convertible to m2/s");
if (std::isnan(*ion_data.diffusivity) || *ion_data.diffusivity < 0) throw std::domain_error("diffusivity must be positive, finite, and convertible to m2/s");
}

void add_ion(const std::string& ion_name,
Expand Down
2 changes: 1 addition & 1 deletion example/diffusion/diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct linear: public recipe {
linear(double ext, double dx, double Xi, double beta): l{ext}, d{dx}, i{Xi}, b{beta} {
gprop.default_parameters = neuron_parameter_defaults;
gprop.default_parameters.discretization = cv_policy_max_extent{d};
gprop.add_ion("bla", 1, 23, 42, 0, b);
gprop.add_ion("bla", 1, 23*U::mM, 42*U::mM, 0*U::mV, b*U::m2/U::s);
}

cell_size_type num_cells() const override { return 1; }
Expand Down
7 changes: 4 additions & 3 deletions test/simple_recipes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#include <arbor/cable_cell.hpp>
#include <arbor/cable_cell_param.hpp>
#include <arbor/recipe.hpp>
#include <arbor/units.hpp>
#include <arbor/util/unique_any.hpp>


#include "util/rangeutil.hpp"

namespace arb {

namespace U = units;

// Common functionality: maintain an unordered map of probe data
// per gid, built with `add_probe()`.

Expand Down Expand Up @@ -48,7 +49,7 @@ class simple_recipe_base: public recipe {
}

void add_ion(const std::string& ion_name, int charge, double init_iconc, double init_econc, double init_revpot) {
cell_gprop_.add_ion(ion_name, charge, init_iconc, init_econc, init_revpot);
cell_gprop_.add_ion(ion_name, charge, init_iconc*U::mM, init_econc*U::mM, init_revpot*U::mV);
}

void nernst_ion(const std::string& ion_name) {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,27 @@ TEST(diffusion, setting_diffusivity) {
// BAD: Trying to use a diffusive ion, but b=0.
{
R r;
r.gprop.add_ion("bla", 1, 23, 42, 0, 0);
r.gprop.add_ion("bla", 1, 23*U::mM, 42*U::mM, 0*U::mV, 0*U::m2/U::s);
EXPECT_THROW(simulation(r).run(1*arb::units::ms, 1*arb::units::ms), illegal_diffusive_mechanism);
}
// BAD: Trying to use a partially diffusive ion
{
R r;
r.gprop.add_ion("bla", 1, 23, 42, 0, 0);
r.gprop.add_ion("bla", 1, 23*U::mM, 42*U::mM, 0*U::mV, 0*U::m2/U::s);
r.dec.paint("(tag 1)"_reg, ion_diffusivity{"bla", 13*U::m.pow(2)/U::s});
EXPECT_THROW(simulation(r).run(1*arb::units::ms, 1*arb::units::ms), cable_cell_error);
}
// OK: Using the global default
{
R r;
r.gprop.add_ion("bla", 1, 23, 42, 0, 8);
r.gprop.add_ion("bla", 1, 23*U::mM, 42*U::mM, 0*U::mV, 8*U::m2/U::s);
r.dec.paint("(tag 1)"_reg, ion_diffusivity{"bla", 13*U::m.pow(2)/U::s});
EXPECT_NO_THROW(simulation(r).run(1*arb::units::ms, 1*arb::units::ms));
}
// OK: Using the cell default
{
R r;
r.gprop.add_ion("bla", 1, 23, 42, 0, 0);
r.gprop.add_ion("bla", 1, 23*U::mM, 42*U::mM, 0*U::mV, 0*U::m2/U::s);
r.dec.set_default(ion_diffusivity{"bla", 8*U::m.pow(2)/U::s});
r.dec.paint("(tag 1)"_reg, ion_diffusivity{"bla", 13*U::m.pow(2)/U::s});
EXPECT_NO_THROW(simulation(r).run(1*arb::units::ms, 1*arb::units::ms));
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_fvm_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,9 @@ TEST(fvm_layout, revpot) {
gprop.catalogue = make_unit_test_catalogue();

gprop.ion_species = {{"a", 1}, {"b", 2}, {"c", 3}};
gprop.add_ion("a", 1, 10., 0, 0);
gprop.add_ion("b", 2, 30., 0, 0);
gprop.add_ion("c", 3, 50., 0, 0);
gprop.add_ion("a", 1, 10.*U::mM, 0*U::mM, 0*U::mV);
gprop.add_ion("b", 2, 30.*U::mM, 0*U::mM, 0*U::mV);
gprop.add_ion("c", 3, 50.*U::mM, 0*U::mM, 0*U::mV);

gprop.default_parameters.reversal_potential_method["a"] = "write_eX/a";
mechanism_desc write_eb_ec = "write_multiple_eX/x=b,y=c";
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_fvm_lowered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../common_cells.hpp"
#include "../simple_recipes.hpp"


using namespace std::string_literals;
using namespace arborio::literals;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ cable_cell custom_cell(cell_size_type num_detectors, cell_size_type num_synapses
// Add a num_detectors detectors to the cell.
for (auto i: util::make_span(num_detectors)) {
decorations.place(arb::mlocation{0,(double)i/num_detectors},
arb::threshold_detector{10*arb::units::ms}, "detector"+std::to_string(i));
arb::threshold_detector{10*arb::units::mV}, "detector"+std::to_string(i));
}

// Add a num_synapses synapses to the cell.
Expand Down

0 comments on commit 00ac312

Please sign in to comment.