Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit f2120d3

Browse files
authored
CORENRN_ENABLE_LEGACY_UNITS default OFF (#408)
* CORENRN_ENABLE_LEGACY_UNITS default OFF - Consistency of units selection for NEURON and CoreNEURON checked - Modern units comes from copy of nrnunits-modern.h eion.cpp nrn_nernst and nrn_ghk computes according to the units selection. * Changed CORENRN_LegacyFR to CORENRN_ENABLE_LEGACY_UNITS * inlined chk_nrnunit_consist * mod2c_core built in ${CMAKE_BINARY_DIR}/bin * update mod2c * Update ring data to version 1.3 * set MOD2C_ENABLE_LEGACY_UNITS from CORENRN_ENABLE_LEGACY_UNITS * Fix compilation issue for GPU build - use set_property with APPEND so that previous flags are not overridden
1 parent 93557ec commit f2120d3

File tree

27 files changed

+94
-17
lines changed

27 files changed

+94
-17
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ option(CORENRN_ENABLE_CUDA_UNIFIED_MEMORY "Enable CUDA unified memory support" O
8686
option(CORENRN_ENABLE_UNIT_TESTS "Enable unit tests execution" ON)
8787
option(CORENRN_ENABLE_GPU "Enable GPU support using OpenACC" OFF)
8888
option(CORENRN_ENABLE_SHARED "Enable shared library build" ON)
89+
option(CORENRN_ENABLE_LEGACY_UNITS "Enable legacy FARADAY, R, etc" OFF)
8990

9091
set(CORENRN_NMODL_DIR
9192
""
@@ -240,6 +241,13 @@ if(CORENRN_ENABLE_REPORTING)
240241
include_directories(${sonatareport_INCLUDE_DIR})
241242
endif()
242243

244+
if(CORENRN_ENABLE_LEGACY_UNITS)
245+
set(CORENRN_USE_LEGACY_UNITS 1)
246+
else()
247+
set(CORENRN_USE_LEGACY_UNITS 0)
248+
endif()
249+
set(MOD2C_ENABLE_LEGACY_UNITS ${CORENRN_ENABLE_LEGACY_UNITS} CACHE BOOL "" FORCE)
250+
243251
if(MINGW)
244252
add_definitions("-DMINGW")
245253
endif()
@@ -275,7 +283,7 @@ if(CORENRN_ENABLE_NMODL)
275283
separate_arguments(NMODL_EXTRA_FLAGS_LIST UNIX_COMMAND "${CORENRN_NMODL_FLAGS}")
276284
else()
277285
include(AddMod2cSubmodule)
278-
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/external/mod2c/src/mod2c_core/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
286+
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
279287
set(CORENRN_NMODL_INCLUDE ${CMAKE_BINARY_DIR}/include)
280288
endif()
281289

@@ -398,6 +406,7 @@ if(cmake_generator_tolower MATCHES "makefile")
398406
message(STATUS " INC | ${MPI_C_INCLUDE_PATH}")
399407
endif()
400408
message(STATUS "OpenMP | ${CORENRN_ENABLE_OPENMP}")
409+
message(STATUS "Use legacy units | ${CORENRN_ENABLE_LEGACY_UNITS}")
401410
message(STATUS "NMODL | ${CORENRN_ENABLE_NMODL}")
402411
if(CORENRN_ENABLE_NMODL)
403412
message(STATUS " PATH | ${CORENRN_NMODL_BINARY}")

coreneuron/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ set(NMODL_UNITS_FILE "${CMAKE_BINARY_DIR}/share/mod2c/nrnunits.lib")
5656
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/mechanism/mech/modfile
5757
DESTINATION ${CMAKE_BINARY_DIR}/share)
5858

59+
# eion.cpp depends on CORENRN_USE_LEGACY_UNITS
60+
set(LegacyFR_FILES mechanism/eion.cpp apps/main1.cpp io/global_vars.cpp)
61+
set_source_files_properties(${LegacyFR_FILES} PROPERTIES COMPILE_FLAGS
62+
"-DCORENRN_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS}")
63+
5964
# =============================================================================
6065
# coreneuron GPU library
6166
# =============================================================================
@@ -100,6 +105,17 @@ else()
100105
set(link_cudacoreneuron "")
101106
endif()
102107

108+
# =============================================================================
109+
# eion.cpp depends on CORENRN_USE_LEGACY_UNITS
110+
# =============================================================================
111+
set(LegacyFR_FILES
112+
${CMAKE_CURRENT_SOURCE_DIR}/mechanism/eion.cpp
113+
${CMAKE_CURRENT_SOURCE_DIR}/apps/main1.cpp
114+
${CMAKE_CURRENT_SOURCE_DIR}/io/global_vars.cpp)
115+
116+
set_property(SOURCE ${LegacyFR_FILES} APPEND PROPERTY COMPILE_OPTIONS
117+
"-DCORENRN_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS}")
118+
103119
# =============================================================================
104120
# run KINDERIV_PYTHON_SCRIPT to generate _kinderiv.h
105121
# =============================================================================

coreneuron/apps/main1.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ const char* corenrn_version() {
7070
return coreneuron::bbcore_write_version;
7171
}
7272

73+
// the CORENRN_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
74+
bool corenrn_units_use_legacy() {
75+
return CORENRN_USE_LEGACY_UNITS;
76+
}
77+
7378
void (*nrn2core_part2_clean_)();
7479

7580
#ifdef ISPC_INTEROP

coreneuron/io/global_vars.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "coreneuron/mechanism/membfunc.hpp"
1010
#include "coreneuron/utils/nrn_assert.h"
1111
#include "coreneuron/io/nrn2core_direct.h"
12+
#include "coreneuron/utils/nrnoc_aux.hpp"
1213

1314
void* (*nrn2core_get_global_dbl_item_)(void*, const char*& name, int& size, double*& val);
1415
int (*nrn2core_get_global_int_item_)(const char* name);
@@ -121,6 +122,12 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
121122
secondorder = n;
122123
} else if (strcmp(name, "Random123_globalindex") == 0) {
123124
nrnran123_set_globalindex((uint32_t)n);
125+
} else if (strcmp(name, "_nrnunit_use_legacy_") == 0) {
126+
if (n != CORENRN_USE_LEGACY_UNITS) {
127+
hoc_execerror("CORENRN_ENABLE_LEGACY_UNITS not"
128+
" consistent with NEURON value of"
129+
" nrnunit_use_legacy()", NULL);
130+
}
124131
}
125132
}
126133
}

coreneuron/mechanism/eion.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static const char* mechanism[] = {/*just a template*/
8181
void nrn_init_ion(NrnThread*, Memb_list*, int);
8282
void nrn_alloc_ion(double*, Datum*, int);
8383

84-
double nrn_nernst(), nrn_ghk();
8584
static int na_ion, k_ion, ca_ion; /* will get type for these special ions */
8685

8786
int nrn_is_ion(int type) {
@@ -182,8 +181,19 @@ the USEION statement of any model using this ion\n",
182181
}
183182
}
184183

184+
#ifndef CORENRN_USE_LEGACY_UNITS
185+
#define CORENRN_USE_LEGACY_UNITS 0
186+
#endif
187+
188+
#if CORENRN_USE_LEGACY_UNITS == 1
185189
#define FARADAY 96485.309
186-
#define ktf (1000. * 8.3134 * (celsius + 273.15) / FARADAY)
190+
#define gasconstant 8.3134
191+
#else
192+
#include "coreneuron/nrnoc/nrnunits_modern.h"
193+
#define FARADAY _faraday_codata2018
194+
#define gasconstant _gasconstant_codata2018
195+
#endif
196+
#define ktf (1000. * gasconstant * (celsius + 273.15) / FARADAY)
187197

188198
double nrn_nernst(double ci, double co, double z, double celsius) {
189199
/*printf("nrn_nernst %g %g %g\n", ci, co, z);*/

coreneuron/nrnoc/nrnunits_modern.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef nrnunits_modern_h
2+
#define nrnunits_modern_h
3+
4+
/**
5+
NMODL translated MOD files get unit constants typically from
6+
share/lib/nrnunits.lib.in. But there were other source files that
7+
hardcode some of the constants. Here we gather a few modern units into
8+
a single place (but, unfortunately, also in nrnunits.lib.in). Legacy units
9+
cannot be gathered here because they can differ slightly from place to place.
10+
11+
These come from https://physics.nist.gov/cuu/Constants/index.html.
12+
Termed the "2018 CODATA recommended values", they became available
13+
on 20 May 2019 and replace the 2014 CODATA set.
14+
15+
See oc/hoc_init.c, nrnoc/eion.c, nrniv/kschan.h
16+
**/
17+
18+
19+
#define _electron_charge_codata2018 1.602176634e-19 /* coulomb exact*/
20+
#define _avogadro_number_codata2018 6.02214076e+23 /* exact */
21+
#define _boltzmann_codata2018 1.380649e-23 /* joule/K exact */
22+
#define _faraday_codata2018 (_electron_charge_codata2018*_avogadro_number_codata2018) /* 96485.33212... coulomb/mol */
23+
#define _gasconstant_codata2018 (_boltzmann_codata2018*_avogadro_number_codata2018) /* 8.314462618... joule/mol-K */
24+
25+
/* e/k in K/millivolt */
26+
#define _e_over_k_codata2018 (.001*_electron_charge_codata2018/_boltzmann_codata2018) /* 11.604518... K/mV */
27+
28+
#endif /* nrnunits_modern_h */

coreneuron/utils/nrnoc_aux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int v_structure_change;
4040
int diam_changed;
4141
#define MAXERRCOUNT 5
4242
int hoc_errno_count;
43-
const char* bbcore_write_version = "1.2";
43+
const char* bbcore_write_version = "1.3"; // globals.dat has _nrnunit_use_legacy_
4444

4545
char* pnt_name(Point_process* pnt) {
4646
return corenrn.get_memb_func(pnt->_type).sym;

coreneuron/utils/nrnoc_aux.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ extern void hoc_warning(const char*, const char*);
5555

5656
extern double hoc_Exp(double x);
5757

58+
// defined in eion.cpp and this file included in translated mod files.
59+
extern double nrn_nernst(double ci, double co, double z, double celsius);
60+
extern double nrn_ghk(double v, double ci, double co, double z);
61+
5862
} // namespace coreneuron

tests/integration/ring/12_1.dat

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)