Skip to content

Conversation

@reneangermeyer
Copy link
Contributor

When FloPy writes free-format arrays for unstructured MODFLOW-USG models,
all values are written on a single line (e.g., 65,448 values on one line for
a large model). This makes files unreadable and difficult to diff or inspect.

Groundwater Vistas and other preprocessors write these same arrays with
10 values per line in block format, which is equally valid for MODFLOW but
far more readable.

This PR adds a model.free_format_npl property (values per line) that
controls line wrapping when writing free-format arrays.

Usage

m = flopy.mfusg.MfUsg.load('model.nam', model_ws='path')                                                                                                                      
m.free_format_npl = 10  # 10 values per line                                                                                                                                  
m.write_input()                                                                                                                                                               
                                                                                                                                                                              
Before (default, free_format_npl=None)                                                                                                                                        
                                                                                                                                                                              
INTERNAL 1 (FREE) -1                                                                                                                                                          
0.000000E+00  2.562436E-05  2.562436E-05  2.562436E-05  ...  (65,448 values on one line)                                                                                      
                                                                                                                                                                              
After (free_format_npl=10)                                                                                                                                                    
                                                                                                                                                                              
INTERNAL 1 (FREE) -1                                                                                                                                                          
0.000000E+00  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05                                    
2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05  2.562436E-05                                    
...                                                                                                                                                                           
                                                                                                                                                                              
Changes                                                                                                                                                                       
                                                                                                                                                                              
- mbase.py: add free_format_npl property (default None, no change in behavior)                                                                                                
- util_array.py: override npl in Util2d.string (INTERNAL arrays) and                                                                                                          
Util2d.get_file_entry (EXTERNAL/OPENCLOSE arrays) when property is set

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 72.3%. Comparing base (556c088) to head (cfe64e8).
⚠️ Report is 120 commits behind head on develop.

Files with missing lines Patch % Lines
flopy/utils/util_array.py 83.3% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2696      +/-   ##
===========================================
+ Coverage     55.5%    72.3%   +16.8%     
===========================================
  Files          644      667      +23     
  Lines       124135   130408    +6273     
===========================================
+ Hits         68947    94390   +25443     
+ Misses       55188    36018   -19170     
Files with missing lines Coverage Δ
flopy/mbase.py 70.4% <100.0%> (-2.3%) ⬇️
flopy/mfusg/mfusg.py 78.3% <ø> (+0.8%) ⬆️
flopy/modflow/mf.py 68.2% <ø> (-1.1%) ⬇️
flopy/utils/util_array.py 82.5% <83.3%> (-0.9%) ⬇️

... and 559 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reneangermeyer reneangermeyer marked this pull request as ready for review January 29, 2026 11:34
Copy link
Member

@wpbonelli wpbonelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to me

@wpbonelli wpbonelli added this to the 3.10 milestone Jan 29, 2026
Copy link
Contributor

@jdhughes-dev jdhughes-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, this option will not be visible to anyone who does not know it exists. It could be pulled out as a kwarg and added to the docstring for the kwargs in mbase.

Also, there is no test(s) with evaluation that it is working as intended...although I don't think this is critical.

@reneangermeyer reneangermeyer force-pushed the feature/free-format-npl branch from b67bee4 to 3a60459 Compare January 29, 2026 14:56
flopy/mbase.py Outdated
Number of values per line when writing free-format arrays. When set
(e.g., ``free_format_npl=10``), arrays are written with that many
values per line instead of all values on a single line. This produces
block-format output matching Groundwater Vistas style, improving
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would simplify to

...block-format output, improving...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified!

@reneangermeyer reneangermeyer force-pushed the feature/free-format-npl branch from 3a60459 to 6f76466 Compare January 29, 2026 15:09
@jlarsen-usgs
Copy link
Contributor

@reneangermeyer,
Just as a follow up to increasing the visibility of this option, it'd also make sense to explicitly define this option in the MfUsg class initialization parameters. As it is right now, it's still hidden from the end-user as a keyword argument that's not visible in the child class (MfUsg), even though it's explicitly defined in the parent (BaseModel) class.

… free-format array output

When free_format_npl is set (e.g., model.free_format_npl = 10), free-format
arrays are written with that many values per line instead of all values on a
single line. This produces block-format output matching Groundwater Vistas
style, improving readability for large unstructured models.

Affects both INTERNAL arrays (Util2d.string) and EXTERNAL/OPENCLOSE arrays
(Util2d.get_file_entry). Default is None (no change in behavior).
@reneangermeyer reneangermeyer force-pushed the feature/free-format-npl branch from 6f76466 to cfe64e8 Compare January 29, 2026 21:19
Copy link
Contributor

@jlarsen-usgs jlarsen-usgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the keyword argument to the MfUsg Class. Overall, the changes look good to me.

@wpbonelli wpbonelli merged commit 5e64da8 into modflowpy:develop Jan 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants