Sync Jeff Arnold's water allocation/carbon/manure work with dev - #252
Conversation
…ultiple channels within a water allication object.
- Switch transplant data file from "transplant.plt" to "transplant.ops" - Clarify comments for `phuacc` and `pop` in plant data module - Add check for positive `trn_cur` in channel control logic to prevent invalid water allocation loops
Introduces cswat=3 option for three-pool residue decomposition using lignin fractions, with new subroutines for surface/soil residue and tillage mixing. Adds plant data structures for above/below-ground partitioning, tracks C above 300mm and live root fractions, and updates output files accordingly. Expands decision/action system for snow and reservoir irrigation demand. Implements new reservoir release schemes (Doell, Hanazaki, HYPE) with rolling inflow/demand memory. Refactors soil test adjustment for better weighted averaging. Generalizes cswat logic, improves table reader utility, and fixes various bugs and formatting issues.
Introduce new manure database and organic/mineral attribute structures, with file readers for both. Update constituent and salt application logic to use new manure type checks. Refactor transplant and irrigation management output for clarity. Enhance debug build safety with Fortran bounds checking and adjust static linking for GNU compilers. Minor cleanups throughout.
Backup 03312026a
Expanded support for tracking and transferring constituent (nutrient, salt, contaminant) mass in water allocation, canal, and aquifer routines. Refactored data structures for clarity, added new arrays for constituent mass in allocation objects, and updated canal seepage and aquifer loss logic. Improved fertilizer/manure data handling and application, updated file formats, and streamlined soil carbon cycling code. All relevant routines and file readers updated for consistency and clarity. These changes ensure constituent mass is tracked alongside water throughout the system. Refactor water allocation: new POU/POD/POR structure Major overhaul of the water allocation (WALLO) system: - Introduced new Fortran types for Points of Use (POU), Points of Delivery (POD), and Points of Return (POR), replacing the old transfer object structure. - Implemented daily/monthly/yearly/average annual hydrograph and constituent mass tracking for each POU/POD/POR. - Integrated decision tables for dynamic allocation of water rights, duties, and source/return fractions. - Refactored wallo_control, wallo_withdraw, and related routines to use the new structure, with improved logic for withdrawal, delivery, and return. - Updated all relevant modules and input/output routines to support the new format. - Enhanced handling of out-of-basin sources, canals, water towers, and aquifers as PODs, with new fields for limits and losses. - Improved recall file handling and integration. - Updated fertilizer/manure logic to use new manure_om database with explicit C/N/P fractions. - Improved erosion and C-factor calculations and outputs. - Numerous bug fixes, code cleanups, and documentation updates.
Major overhaul of the water allocation (WALO) system: - Replaces legacy wallo (water rights object) structure with modular POU/POD/POR (Point of Use/Delivery/Return) system. - Adds new input files (`point_of_use.wro`, `point_of_deliv.wro`) and updates all read, allocation, and initialization routines. - Refactors main control flow, moving start-of-day logic to `wallo_start_day` and updating all transfer, treatment, and use routines. - Removes legacy wallo routines and output, updating all references and output logic. - Updates constituent and salt irrigation routines to use new structure. - Improves modularity, maintainability, and extensibility of water allocation code.
- Added `pest_tempdecay_module` for temperature-adjusted decay rates. - Updated `pest_decay.f90` to handle temperature effects and metabolites. - Fixed mass leaks in `smp_filter.f90` and `smp_grass_wway.f90`. - Corrected pesticide mixing logic in tillage modules. - Improved pesticide application and root uptake calculations. - Introduced `harvest_sink` and `resistance_n` parameters for pesticide behavior. - Enhanced output tracking with new fields for harvest and plant death. - Updated channel pesticide routing with dynamic partitioning factors. - Addressed double-counting in decay and metabolite formation. - Improved pesticide handling during harvest for sink and non-sink cases. - Added floodplain area (`fp_km2`) to channel morphology outputs. - Fixed unit inconsistencies, improved readability, and removed redundant code.
Refactored and modularized water allocation code to improve readability, maintainability, and scalability. Introduced new data structures (`irrigation_water_transfer`, `pou_irrigation`, `hru_irrigation`) to handle HRU-specific irrigation demands, applied water, runoff, and efficiency. Integrated decision tables (`dtbl_lum`, `dtbl_flo`) for dynamic irrigation demand and allocation rates. Added new subroutines (`wallo_pou_deliv`, `wallo_return`, `water_hru_irr_read`) to manage irrigation and water delivery processes. Updated file handling logic to support new input formats and added checks for file existence. Improved hydrograph outputs and constituent mass calculations to account for irrigation water quality. Fixed bugs in POD/POU handling and minimum storage checks. Optimized array allocation for large-scale simulations. Enhanced documentation and comments for better code understanding.
…and several I/O changes.
…cation-to-dev # Conflicts: # src/mgt_biomix.f90 # src/mgt_newtillmix_cswat0.f90 # src/mgt_newtillmix_cswat1.f90 # src/organic_mineral_mass_module.f90 # src/wallo_transfer.f90 # src/water_allocation_module.f90
doc/VSCode_Codespace.md, jupyter_notebooks/carbon.ipynb, and refdata/Osu_1hru/lum.dtl only carried upstream's typo-fix commit through the merge - no functional change, out of scope for this sync. Keeping the branch focused on the .f90 source changes.
These 63 files under refdata/ (plus carbon.ipynb) had drifted from dev during Jeff's working commits - all deletions/modifications, zero new files, and confirmed absent at the fork point (cb442f7). Looks like an out-of-date or gitignore-affected local checkout got swept up in a broad commit, not intentional changes tied to the water allocation work. Restoring dev's checked-in versions removes that unrelated drift.
Missed by the merge: Jeff's branch independently touched this line elsewhere (recall_db -> recall refactor nearby), so git's auto-merge silently kept his version of the comment, which fixed "substraction" but not "already" on its own. Both instances are in commented-out (dead) code - no functional change.
Jeff's branch had added ignore rules for manure_db.frt, manure_om.frt, and mgt_out.txt, which is why those refdata files showed as deleted - inconsistent now that the earlier refdata restore brought them back as tracked files.
|
Running tests on various datasets before merging. |
PR 252 merge notesfinished checking PR 252. PR head 795d2d9 on dev e05177f.
Recall fixdev (and 62.0.0) can't read a normal recall.rec at all since Jeff's January commit 72206bc; any dataset with recall objects segfaults in command.f90:335. Jeff's fix puts the 61.0.2.11 reader back. Works. Tests (ifx 2026 Release; gfortran 16.2 Release for Osu_1hru and Ames_sub1)
Recall numbers check out: 5927.658 m3/d in, 2163595 m3/yr out (2169523 in the The Wichita files are an older format and lack wtps_wuses.wal, so that crash only says missing wallo inputs segfault instead of erroring. Need a dataset in the current format to test the wallo model itself. Follow-up PRs should address these:
Summary: what needs fixing after the mergeThe merge itself is fine and the recall fix is needed now. The new water allocation code is not usable end to end yet. Two areas stand out; item 9 is a gfortran-only segfault on ordinary projects and should go first; the rest are reader and output fixes (items 1 to 4, 7 and 8 above). Irrigation (item 5). Any POU of type Interbasin transfer, outside sources (item 6 and wallo_start_day). The Test dataset for both: robit_wallo.zip below (wtps_wuses.wal included). Test datasetsInputs only, model outputs stripped, each with a README of what to expect.
|
Author
The substantive work in this PR — 25 commits — is authored by Jeff Arnold (
Jeff.Arnold@agnet.tamu.edu, GitHub@arnoldjjms), from his fork arnoldjjms/swatplus_dev, verifiable directly in the commit history below.What this PR does
Jeff's branch diverged from
devatcb442f7and accumulated 25 commits of feature work:This PR merges that work with the current tip of
dev, so both sides are fully caught up.Bug fixes carried forward from dev
While Jeff's branch was diverged,
devpicked up 12 commits of its own, including four real fixes now included here:phuacc_pwas never initialized for perennials that start a simulation already growing, flooring root depth regardless of declared maturity.days_irrwasn't reset when irrigating from an unlimited source, throwing off subsequent scheduling.mgt_operatn— a schedule whose operations all fall on the same calendar date could cycle forever; capped at one full pass through the schedule.varinitperformance — a daily reset was zeroing an entire all-HRU array instead of just the active HRU's row, an O(N²)-per-day cost on large basins.The remaining 8 of those 12
devcommits were typo/comment-only fixes, also carried forward.Conflicts resolved
6 files had real conflicts between Jeff's rework and the 12 newer
devcommits. In every case Jeff's substantive code was kept as-is;dev's changes were folded in only where they were still-applicable comment/typo fixes on surviving code:mgt_biomix.f90,mgt_newtillmix_cswat0.f90,mgt_newtillmix_cswat1.f90—dev's fix for the >12-plant crash (c917b44) was redundant with a fix Jeff's residue-pool rework had already made the same way; kept Jeff's version (keeping both would double-allocateand crash at runtime).organic_mineral_mass_module.f90— comment-only conflict, tookdev's clearer wording.wallo_transfer.f90— kept Jeff's new POU/POD object model, folded in a typo fix to the comment.water_allocation_module.f90— Jeff's rework deleted an oldoutside_basin_sourcetype in favor of reusing an existing one;devhad only fixed typos inside that now-deleted block. Kept Jeff's design, folded in the one typo fix that still applied.Full writeup with the actual conflict diffs: tugraskan/swatplus_ug#156. Raw conflict view (GitHub's native conflict UI, unresolved) against Jeff's own
main: arnoldjjms/swatplus_dev#9.Scope
refdata/andjupyter_notebooks/carbon.ipynbchanges unrelated to this work (stale local-checkout drift, not new data — verified no new files were added, only deletions/modifications relative todev) were reverted to matchdevexactly, so this PR is scoped to the.f90source changes plus one doc typo fix. Also swept the branch for every misspelling fromdev's "Fix typos" commit to make sure none were silently reintroduced by the merge — found and fixed one (alrready→already, in dead/commented-out lines inres_hydro.f90). Compiles clean with gfortran/CMake: 0 warnings, 0 errors.🤖 Generated with Claude Code