Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
3ee3c7b
Restore support for older-format NetCDF forcings files that have Time…
PhilMiller Dec 26, 2025
407ed3e
Clean up comments and formatting
PhilMiller Dec 26, 2025
e90c79c
Handle more units, with and without a specified reference epoch
PhilMiller Dec 26, 2025
3002d54
Handle different orderings of variable dimensions
PhilMiller Dec 26, 2025
9f61af0
Flesh out API for state saving and restoring, with adjusted use in Bm…
PhilMiller Nov 25, 2025
bb6011d
WIP Wiring all the pieces together
PhilMiller Nov 26, 2025
1f8001b
Add logic and structures for parsing state saving configuration from …
PhilMiller Dec 9, 2025
6b77086
CMakeLists.txt: Remove commented out bits
PhilMiller Dec 10, 2025
d97e4a7
Add File_Per_Unit state saving mechanism
PhilMiller Dec 16, 2025
99803e0
State saving for multi-BMI
idtodd Jan 16, 2026
27256aa
Cold start config structure
idtodd Jan 19, 2026
3588beb
Cold start loading
idtodd Jan 20, 2026
e27f10e
Fix config JSON array parsing
idtodd Jan 20, 2026
d37625e
Less restrictive start and end of run save state
idtodd Jan 21, 2026
96d20d3
Use parent classes for start and end of run states
idtodd Jan 21, 2026
1d7d0b7
Dynamically sized set value option for python BMI adapter
idtodd Jan 27, 2026
200c2b6
Add output suppression flag for UEB
idtodd Jan 30, 2026
a9fb47b
update t-route submodule ref for named logger
cmaynard-ngwpc Jan 5, 2026
fb23619
Dynamic Forcing Engine CAT-ID Data Type (NGWPC-9255) (#109)
idtodd Jan 6, 2026
c9ee3f4
Docker updates for python ewts packages
cmaynard-ngwpc Jan 8, 2026
b732ae6
Update lstm and t-route submodules for ewts package
cmaynard-ngwpc Jan 8, 2026
098c956
update cicd file to use new branches for releases
miguelp1986 Jan 12, 2026
f0add01
Update submod ref for SMP
idtodd Jan 20, 2026
f4fcc78
Fix use-after-free error
idtodd Dec 8, 2025
193c876
Remove explicit interpreter release
idtodd Dec 8, 2025
03fab9e
Ensure bmi_model has not been destroyed
idtodd Dec 8, 2025
b597be4
Remove null check since that should be an error state if null
idtodd Dec 11, 2025
f01bf47
Finalize forcing engine providers on instances clear
idtodd Dec 19, 2025
dda7b63
Release BMI reference
idtodd Dec 22, 2025
8246276
Revert "Release BMI reference"
cmaynard-ngwpc Jan 21, 2026
155712a
Revert "Finalize forcing engine providers on instances clear"
cmaynard-ngwpc Jan 21, 2026
8a9b863
Revert "Remove null check since that should be an error state if null"
cmaynard-ngwpc Jan 21, 2026
fb86c40
Revert "Ensure bmi_model has not been destroyed"
cmaynard-ngwpc Jan 21, 2026
cd5a61b
Revert "Remove explicit interpreter release"
cmaynard-ngwpc Jan 21, 2026
05df353
Revert "Fix use-after-free error"
cmaynard-ngwpc Jan 21, 2026
5661740
Fix use-after-free error
idtodd Dec 8, 2025
98e3fb0
Remove explicit interpreter release
idtodd Dec 8, 2025
7a75de6
Ensure bmi_model has not been destroyed
idtodd Dec 8, 2025
8aa2ccd
Remove null check since that should be an error state if null
idtodd Dec 11, 2025
e173a4e
Finalize forcing engine providers on instances clear
idtodd Dec 19, 2025
38a4844
Release BMI reference
idtodd Dec 22, 2025
dcc24cb
Update tear down method name
idtodd Jan 21, 2026
f67e220
Catch csv file errors and log exceptions initializing formulation
cmaynard-ngwpc Dec 4, 2025
f5795bd
Add check for empty CSV forcing file.
cmaynard-ngwpc Dec 4, 2025
e4d8303
Update submodule references for LASAM, SFT, SMP, CFE, LSTM, Snow17, T…
cmaynard-ngwpc Jan 21, 2026
fce6188
Ensure bmi_model has not been destroyed
idtodd Dec 8, 2025
63556dc
Remove null check since that should be an error state if null
idtodd Dec 11, 2025
adba13c
Finalize forcing engine providers on instances clear
idtodd Dec 19, 2025
b744ee1
Ensure BMIs Destroyed Before Calling MPI_Finalize (#123)
idtodd Jan 23, 2026
3fc428f
Ensure data ownership not passed to python
idtodd Jan 30, 2026
a5d2428
T-Route save stating for hot start
idtodd Feb 4, 2026
6e9a5f0
Global source for serialization message names
idtodd Feb 4, 2026
9e8a3ca
Expand applicable types for get value as double
idtodd Feb 4, 2026
92bebce
C++14 consts
idtodd Feb 4, 2026
d05953a
Expand python typing interface
idtodd Feb 5, 2026
6d5ceef
Prevent multiple hot start config definitions
idtodd Feb 5, 2026
bf027f6
Use Boost for serializing Multi-BMI
idtodd Feb 6, 2026
a1614e0
Add GetValuePtrInt for Fortran Adapter
idtodd Feb 12, 2026
8c56622
Fortran state hackery
idtodd Feb 17, 2026
3dff58c
Add variable name
idtodd Feb 17, 2026
57c3822
Update submodules for testing
idtodd Feb 18, 2026
082383d
Remove explicit pip install call for package nextgen_forcings_ewts
mxkpp Jan 25, 2026
eefea2d
Add new Dockerfile arg to specify the full name of the ngen-forcing b…
mxkpp Feb 1, 2026
4cfa923
updates to cicd and dockerfile
miguelp1986 Feb 5, 2026
18e0f2c
updated cicd file
miguelp1986 Feb 5, 2026
f0a392c
Added unit conversion code to ForcingsEngineLumpedDataProvider which …
sivasankkar Feb 4, 2026
65a113b
updated cicd file
miguelp1986 Feb 11, 2026
bdf27f4
updated cicd file
miguelp1986 Feb 11, 2026
1764311
updated cicd file
miguelp1986 Feb 11, 2026
2121a51
updated cicd file
miguelp1986 Feb 11, 2026
c470849
updated cicd file
miguelp1986 Feb 11, 2026
8dae76d
Ignore git info
peterkronenberg-rtx Feb 9, 2026
45eb0f9
Merge remote-tracking branch 'NOAA-OWP/master' into development
idtodd Feb 12, 2026
60f2ebf
Add logging library for access to Logger.hpp
idtodd Feb 12, 2026
ebc42f8
Update Boost version requirement
idtodd Feb 12, 2026
2a439e1
Fix download URL to Boost 1.86.0
idtodd Feb 12, 2026
e2f414c
fixing boost version in code scan
miguelp1986 Feb 18, 2026
f05800c
fixing boost version in code scan
miguelp1986 Feb 18, 2026
9e342ba
fixing boost version in code scan
miguelp1986 Feb 18, 2026
163c12a
cicd updates
miguelp1986 Feb 18, 2026
bf87b7c
cicd updates
miguelp1986 Feb 18, 2026
e8f63bb
Flesh out API for state saving and restoring, with adjusted use in Bm…
PhilMiller Nov 25, 2025
5b335da
Add logic and structures for parsing state saving configuration from …
PhilMiller Dec 9, 2025
db2f432
State saving for multi-BMI
idtodd Jan 16, 2026
005aa3f
Use Boost for serializing Multi-BMI
idtodd Feb 6, 2026
3189c31
Remove duplicate declaration
idtodd Feb 18, 2026
9a0a329
Remove old state calls
idtodd Feb 18, 2026
245c1c0
Remove old state saving definitions
idtodd Feb 18, 2026
ac0cc30
Update submodule references for bug fixes
idtodd Feb 18, 2026
3f1d396
Update submodules for testing
idtodd Feb 18, 2026
7eee79f
Update submodule for snow17 fix
idtodd Feb 19, 2026
a47604a
Update submodels for bug fixes
idtodd Feb 20, 2026
7cad804
Fortran packages report byte size of data
idtodd Feb 20, 2026
508ab43
Align Fortran state size with sizeof int
idtodd Feb 24, 2026
1f3da20
Update references for bug fixes
idtodd Feb 26, 2026
cd9a84d
Dynamically check Fortran state size for load alignment
idtodd Feb 26, 2026
c8113c3
Update repo references
idtodd Feb 26, 2026
99a5ffa
Fortran reports size in bytes
idtodd Mar 2, 2026
473a31c
Update reference for snow17 fix
idtodd Mar 3, 2026
7d2b1e2
Update Topmodel reference for bug fix
idtodd Mar 5, 2026
a75e5f2
Update reference for Topmodel bug fix
idtodd Mar 5, 2026
af3cfd5
Update Topmodel reference for bug fix
idtodd Mar 9, 2026
c7a97ad
Catch csv file errors and log exceptions initializing formulation
cmaynard-ngwpc Dec 4, 2025
c7250a1
Merge remote-tracking branch 'NOAA-OWP/master' into development
idtodd Feb 12, 2026
5644857
feat(mass_balance): define the bmi mass balance protocol
hellkite500 Sep 16, 2025
ca9651b
test(bmi_protocols): add mock for BMI protocol testing
hellkite500 Sep 16, 2025
c3f78c7
feat(ngen): add mass balance check for all bmi modules during runtime
hellkite500 Sep 17, 2025
38d3475
feat(bmi-protocols)!: v0.2 of the protocols lib using expected semant…
hellkite500 Sep 27, 2025
043d5b8
fix(protocols): better default handling; add missing return
hellkite500 Oct 23, 2025
ad3dc8f
test: point formulation tests to use same protocol mock
hellkite500 Oct 23, 2025
98eb211
fix(mpi): prevent potential deadlock scenario
hellkite500 Feb 4, 2026
31734ae
fix(mpi): better handling of pending communication in remote nexus de…
hellkite500 Feb 4, 2026
d0931cb
Merge resolution from OWP Master
idtodd Feb 20, 2026
01e2fcd
Add topoflow-glacier submodule
jswade-rtx Feb 16, 2026
52bd97b
Update topoflow-glacier branch
jswade-rtx Feb 24, 2026
bae75a8
Update topoflow-glacier submodule to dev merge
jswade-rtx Feb 25, 2026
c11b7fa
Revert changes from OWP
idtodd Feb 25, 2026
8cfd97c
updated cicd file
miguelp1986 Mar 4, 2026
19591f4
Flesh out API for state saving and restoring, with adjusted use in Bm…
PhilMiller Nov 25, 2025
c81f1d4
State saving for multi-BMI
idtodd Jan 16, 2026
1aa0e4d
Cold start loading
idtodd Jan 20, 2026
b7d5957
Use Boost for serializing Multi-BMI
idtodd Feb 6, 2026
7ba868b
Merge remote-tracking branch 'NOAA-OWP/master' into development
idtodd Feb 12, 2026
a7decba
Update submodule references for bug fixes
idtodd Feb 18, 2026
b8a632a
Update submodels for bug fixes
idtodd Feb 20, 2026
2588423
Align Fortran state size with sizeof int
idtodd Feb 24, 2026
d591ce5
Fortran reports size in bytes
idtodd Mar 2, 2026
3559f7e
Fix rebase problems
idtodd Mar 10, 2026
79cacf2
Remove commented old code
idtodd Mar 10, 2026
e075387
Log end of run saving
idtodd Mar 10, 2026
44fc2bb
Fix documentation
idtodd Mar 10, 2026
bda07db
Update submodule pointers for state saving
jswade-rtx Mar 12, 2026
5e42270
Send NGEN's delta time to T-route
idtodd Mar 13, 2026
b2bd692
Resolve merge conflicts
idtodd Mar 13, 2026
465ef8f
Update submodule references to development branches
idtodd Mar 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ add_compile_definitions(NGEN_SHARED_LIB_EXTENSION)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.86.0 REQUIRED)
if(CMAKE_CXX_STANDARD LESS 17)
# requires non-header filesystem for state saving if C++ 11 or lower
find_package(Boost 1.86.0 REQUIRED COMPONENTS system filesystem)
else()
find_package(Boost 1.86.0 REQUIRED)
endif()

# -----------------------------------------------------------------------------
if(NGEN_WITH_SQLITE)
Expand Down Expand Up @@ -318,6 +323,7 @@ add_subdirectory("src/geojson")
add_subdirectory("src/bmi")
add_subdirectory("src/realizations/catchment")
add_subdirectory("src/forcing")
add_subdirectory("src/state_save_restore")
add_subdirectory("src/utilities")
add_subdirectory("src/utilities/mdarray")
add_subdirectory("src/utilities/mdframe")
Expand All @@ -337,7 +343,9 @@ target_link_libraries(ngen
NGen::core_mediator
NGen::logging
NGen::parallel
NGen::state_save_restore
NGen::bmi_protocols
NGen::state_save_restore
)

if(NGEN_WITH_SQLITE)
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ RUN --mount=type=cache,target=/root/.cache/cmake,id=cmake-soilfreezethaw \

RUN --mount=type=cache,target=/root/.cache/cmake,id=cmake-ueb-bmi \
set -eux && \
cmake -B extern/ueb-bmi/cmake_build -S extern/ueb-bmi/ -DBMICXX_INCLUDE_DIRS=/ngen-app/ngen/extern/bmi-cxx/ -DBOOST_ROOT=/opt/boost && \
cmake -B extern/ueb-bmi/cmake_build -S extern/ueb-bmi/ \
-DUEB_SUPPRESS_OUTPUTS=ON -DBMICXX_INCLUDE_DIRS=/ngen-app/ngen/extern/bmi-cxx/ -DBOOST_ROOT=/opt/boost && \
cmake --build extern/ueb-bmi/cmake_build/ && \
find /ngen-app/ngen/extern/ueb-bmi/ -name '*.o' -exec rm -f {} +

Expand Down
109 changes: 109 additions & 0 deletions data/example_state_saving_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"global": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"file_pattern": ".*{{id}}.*.csv",
"path": "./data/forcing/"
}
},
"state_saving": {
"label": "end",
"path": "state_end",
"type": "FilePerUnit",
"when": "EndOfRun"
},
"time": {
"start_time": "2015-12-01 00:00:00",
"end_time": "2015-12-30 23:00:00",
"output_interval": 3600
},
"output_root": "./output_dir/",
"catchments": {
"cat-27": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-27_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
},
"cat-52": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-52_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
},
"cat-67": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-67_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
}
}
}
117 changes: 117 additions & 0 deletions data/example_state_saving_config_multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"global": {
"formulations": [
{
"name": "bmi_multi",
"params": {
"model_type_name": "bmi_multi_noahowp_cfe",
"forcing_file": "",
"init_config": "",
"allow_exceed_end_time": true,
"main_output_variable": "Q_OUT",
"modules": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "bmi_c++_sloth",
"library_file": "./extern/sloth/cmake_build/libslothmodel.so",
"init_config": "/dev/null",
"allow_exceed_end_time": true,
"main_output_variable": "z",
"uses_forcing_file": false,
"model_params": {
"sloth_ice_fraction_schaake(1,double,m,node)": 0.0,
"sloth_ice_fraction_xinanjiang(1,double,1,node)": 0.0,
"sloth_smp(1,double,1,node)": 0.0
}
}
},
{
"name": "bmi_fortran",
"params": {
"model_type_name": "bmi_fortran_noahowp",
"library_file": "./extern/noah-owp-modular/cmake_build/libsurfacebmi",
"forcing_file": "",
"init_config": "./data/bmi/fortran/noah-owp-modular-init-{{id}}.namelist.input",
"allow_exceed_end_time": true,
"main_output_variable": "QINSUR",
"variables_names_map": {
"PRCPNONC": "atmosphere_water__liquid_equivalent_precipitation_rate",
"Q2": "atmosphere_air_water~vapor__relative_saturation",
"SFCTMP": "land_surface_air__temperature",
"UU": "land_surface_wind__x_component_of_velocity",
"VV": "land_surface_wind__y_component_of_velocity",
"LWDN": "land_surface_radiation~incoming~longwave__energy_flux",
"SOLDN": "land_surface_radiation~incoming~shortwave__energy_flux",
"SFCPRS": "land_surface_air__pressure"
},
"uses_forcing_file": false
}
},
{
"name": "bmi_c",
"params": {
"model_type_name": "bmi_c_pet",
"library_file": "./extern/evapotranspiration/evapotranspiration/cmake_build/libpetbmi",
"forcing_file": "",
"init_config": "./data/bmi/c/pet/{{id}}_bmi_config.ini",
"allow_exceed_end_time": true,
"main_output_variable": "water_potential_evaporation_flux",
"registration_function": "register_bmi_pet",
"variables_names_map": {
"water_potential_evaporation_flux": "potential_evapotranspiration"
},
"uses_forcing_file": false
}
},
{
"name": "bmi_c",
"params": {
"model_type_name": "bmi_c_cfe",
"library_file": "./extern/cfe/cmake_build/libcfebmi",
"forcing_file": "",
"init_config": "./data/bmi/c/cfe/{{id}}_bmi_config.ini",
"allow_exceed_end_time": true,
"main_output_variable": "Q_OUT",
"registration_function": "register_bmi_cfe",
"variables_names_map": {
"water_potential_evaporation_flux": "potential_evapotranspiration",
"atmosphere_air_water~vapor__relative_saturation": "SPFH_2maboveground",
"land_surface_air__temperature": "TMP_2maboveground",
"land_surface_wind__x_component_of_velocity": "UGRD_10maboveground",
"land_surface_wind__y_component_of_velocity": "VGRD_10maboveground",
"land_surface_radiation~incoming~longwave__energy_flux": "DLWRF_surface",
"land_surface_radiation~incoming~shortwave__energy_flux": "DSWRF_surface",
"land_surface_air__pressure": "PRES_surface",
"ice_fraction_schaake" : "sloth_ice_fraction_schaake",
"ice_fraction_xinanjiang" : "sloth_ice_fraction_xinanjiang",
"soil_moisture_profile" : "sloth_smp"
},
"uses_forcing_file": false
}
}
],
"uses_forcing_file": false
}
}
],
"forcing": {
"file_pattern": ".*{{id}}.*..csv",
"path": "./data/forcing/",
"provider": "CsvPerFeature"
}
},
"state_saving": [{
"direction": "save",
"label": "end",
"path": "state_end",
"type": "FilePerUnit",
"when": "EndOfRun"
}],
"time": {
"start_time": "2015-12-01 00:00:00",
"end_time": "2015-12-30 23:00:00",
"output_interval": 3600
},
"output_root": "./output_dir/"
}
2 changes: 1 addition & 1 deletion extern/sac-sma/sac-sma
2 changes: 1 addition & 1 deletion extern/sloth
2 changes: 1 addition & 1 deletion extern/snow17
2 changes: 1 addition & 1 deletion extern/ueb-bmi
57 changes: 36 additions & 21 deletions include/bmi/Bmi_Py_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,33 +541,30 @@ namespace models {
int itemSize = GetVarItemsize(name);
std::string py_type = GetVarType(name);
std::string cxx_type = get_analogous_cxx_type(py_type, (size_t) itemSize);

if (cxx_type == "short") {
set_value<short>(name, (short *) src);
} else if (cxx_type == "int") {
set_value<int>(name, (int *) src);
} else if (cxx_type == "long") {
set_value<long>(name, (long *) src);
} else if (cxx_type == "long long") {
//FIXME this gets dicey -- if a python numpy array is of type np.int64 (long long),
//but a c++ int* is passed to this function as src, it will fail in undefined ways...
//the template type overload may be perferred for doing SetValue from framework components
//such as forcing providers...
set_value<long long>(name, (long long *) src);
} else if (cxx_type == "float") {
set_value<float>(name, (float *) src);
} else if (cxx_type == "double") {
set_value<double>(name, (double *) src);
} else if (cxx_type == "long double") {
set_value<long double>(name, (long double *) src);
} else {
// macro for checking type and setting value
#define BMI_PY_SET_VALUE(type) if (cxx_type == #type) {\
this->set_value<type>(name, static_cast<type *>(src)); }
BMI_PY_SET_VALUE(signed char)
else BMI_PY_SET_VALUE(unsigned char)
else BMI_PY_SET_VALUE(short)
else BMI_PY_SET_VALUE(unsigned short)
else BMI_PY_SET_VALUE(int)
else BMI_PY_SET_VALUE(unsigned int)
else BMI_PY_SET_VALUE(long)
else BMI_PY_SET_VALUE(unsigned long)
else BMI_PY_SET_VALUE(long long)
else BMI_PY_SET_VALUE(unsigned long long)
else BMI_PY_SET_VALUE(float)
else BMI_PY_SET_VALUE(double)
else BMI_PY_SET_VALUE(long double)
else {
std::string throw_msg; throw_msg.assign("Bmi_Py_Adapter cannot set values for variable '" + name +
"' that has unrecognized C++ type '" + cxx_type + "'");
LOG(throw_msg, LogLevel::WARNING);
throw std::runtime_error(throw_msg);
}
#undef BMI_PY_SET_VALUE
}

/**
* Set the values of the given BMI variable for the model, sourcing new data from the provided vector.
*
Expand Down Expand Up @@ -597,6 +594,24 @@ namespace models {
}
}

/**
* Set the value of a variable. This version of setting a variable will send an array with the `size` specified instead of checking the BMI for its current size of the variable.
* Ownership of the pointer will remain in C++, so the consuming BMI should not maintain a reference to the values beyond the scope of its `set_value` method.
*
* @param name The name of the BMI variable.
* @param src Pointer to the data that will be sent to the BMI.
* @param size The number of items represented by the pointer.
*/
template <typename T>
void set_value_unchecked(const std::string &name, T *src, size_t size) {
// declare readonly array info with the pointer and size
py::buffer_info info(src, static_cast<py::ssize_t>(size), true);
// create the array with the info and NULL handler so python doesn't take ownership
py::array_t<T> src_array(info, nullptr);
// pass the array to python to read; the BMI should not attempt to maintain a reference beyond the scope of this function to prevent trying to use freed memory
bmi_model->attr("set_value")(name, src_array);
}

/**
* Set values for a model's BMI variable at specified indices.
*
Expand Down
Loading
Loading