Skip to content

Commit

Permalink
Remove legacy units support (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu authored Sep 27, 2023
1 parent cda1d1e commit 38b48df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ simulation_stack:
.spack_nmodl:
variables:
SPACK_PACKAGE: nmodl
SPACK_PACKAGE_SPEC: ~legacy-unit+python
SPACK_PACKAGE_SPEC: +python

spack_setup:
extends: .spack_setup_ccache
Expand Down
18 changes: 1 addition & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
# Build options for NMODL
# =============================================================================
option(NMODL_ENABLE_PYTHON_BINDINGS "Enable pybind11 based python bindings" ON)
option(NMODL_ENABLE_LEGACY_UNITS "Use original faraday, R, etc. instead of 2019 nist constants" OFF)
option(NMODL_ENABLE_TESTS "Enable build of tests" ON)
if(NMODL_ENABLE_LEGACY_UNITS)
add_definitions(-DUSE_LEGACY_UNITS)
endif()
set(NMODL_EXTRA_CXX_FLAGS
""
CACHE STRING "Add extra compile flags for NMODL sources")
Expand Down Expand Up @@ -220,21 +216,10 @@ include(${PROJECT_SOURCE_DIR}/src/language/code_generator.cmake)

add_subdirectory(src)

# =============================================================================
# Prepare units database file from nrnunits.lib.in
# =============================================================================
if(NMODL_ENABLE_LEGACY_UNITS)
set(LegacyY "")
set(LegacyN "/")
else()
set(LegacyY "/")
set(LegacyN "")
endif()
configure_file(share/nrnunits.lib.in ${CMAKE_CURRENT_BINARY_DIR}/share/nmodl/nrnunits.lib @ONLY)

# =============================================================================
# Install unit database to share
# =============================================================================
configure_file(share/nrnunits.lib ${CMAKE_CURRENT_BINARY_DIR}/share/nmodl/nrnunits.lib COPYONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/nmodl/nrnunits.lib
DESTINATION ${NMODL_INSTALL_DIR_SUFFIX}share/nmodl)

Expand Down Expand Up @@ -268,7 +253,6 @@ message(STATUS "--------------------+-------------------------------------------
message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS}")
message(STATUS "Build Type | ${CMAKE_BUILD_TYPE}")
message(STATUS "Legacy Units | ${NMODL_ENABLE_LEGACY_UNITS}")
message(STATUS "Python Bindings | ${NMODL_ENABLE_PYTHON_BINDINGS}")
message(STATUS "Flex | ${FLEX_EXECUTABLE}")
message(STATUS "Bison | ${BISON_EXECUTABLE}")
Expand Down
21 changes: 7 additions & 14 deletions share/nrnunits.lib.in → share/nrnunits.lib
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ pi 3.14159265358979323846
c 2.99792458+8 m/sec fuzz
g 9.80665 m/sec2
au 1.49597871+11 m fuzz
@LegacyY@mole 6.022169+23 fuzz
@LegacyN@mole 6.02214076+23 fuzz
mole 6.02214076+23 fuzz
mol 1
/ mol is explicitly defined as a constant
/ with value 1 to avoid "undefined unit"
/ error with mod files that don't define
/ it themselves
@LegacyY@e 1.6021917-19 coul fuzz
@LegacyN@e 1.602176634-19 coul fuzz
e 1.602176634-19 coul fuzz
energy c2
force g
mercury 1.33322+5 kg/m2-sec2
Expand Down Expand Up @@ -399,8 +397,7 @@ ev e-volt
/ faraday 9.652000+04 coul
/ faraday from host: physics.nist.gov
/ path: /PhysRefData/fundconst/html/keywords.html
@LegacyY@faraday 9.6485309+4 coul
@LegacyN@faraday e-mole
faraday e-mole
fathom 6 ft
fermi 1-15 m
fifth 4|5 qt
Expand Down Expand Up @@ -436,8 +433,7 @@ hyl gm force sec2/m
hz /sec
imaginarycubicfoot 1.4 ft3
jeroboam 4|5 gal
@LegacyY@boltzmann 1.38064852-23 joule/K
@LegacyN@boltzmann 1.380649-23 joule/K
boltzmann 1.380649-23 joule/K
k boltzmann
karat 1|24
kcal kilocal
Expand Down Expand Up @@ -506,8 +502,7 @@ quarter 9 in
quartersection 1|4 mi2
quintal 100 kg
quire 25
@LegacyY@gasconstant 8.3144598 joule/K
@LegacyN@gasconstant k-mole
gasconstant k-mole
R gasconstant
rad 100 erg/gm
ream 500
Expand Down Expand Up @@ -581,10 +576,8 @@ tex .001 gram / m
englishell 45 inch
scottishell 37.2 inch
flemishell 27 inch
@LegacyY@planck 6.626-34 joule-sec
@LegacyN@planck 6.62607015-34 joule-sec
@LegacyY@hbar 1.055-34 joule-sec
@LegacyN@hbar planck/two-pi
planck 6.62607015-34 joule-sec
hbar planck/two-pi
electronmass 9.1095-31 kg
protonmass 1.6726-27 kg
neutronmass 1.6606-27 kg
Expand Down
6 changes: 0 additions & 6 deletions src/visitors/units_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ void UnitsVisitor::visit_factor_def(ast::FactorDef& node) {
auto node_unit_name = node.get_node_name();
auto unit1_factor = units_driver.table->get_unit(node_unit_name + "_unit1")->get_factor();
auto unit2_factor = units_driver.table->get_unit(node_unit_name + "_unit2")->get_factor();

#ifdef USE_LEGACY_UNITS
auto unit_factor = stringutils::to_string(unit1_factor / unit2_factor, "{:g}");
#else
auto unit_factor = stringutils::to_string(unit1_factor / unit2_factor, "{:a}");
#endif

auto double_value_ptr = std::make_shared<ast::Double>(ast::Double(unit_factor));
node.set_value(std::move(double_value_ptr));
}
Expand Down

0 comments on commit 38b48df

Please sign in to comment.