Skip to content

Conversation

@sunt05
Copy link

@sunt05 sunt05 commented Dec 16, 2025

Summary

This PR implements GH#360 - enabling multiple building archetypes in STEBBS.

Completed Phases

  • Phase 1: Made nbtypes dynamic in Fortran

    • Changed from compile-time PARAMETER to runtime variable
    • Added nbtypes_max=10 as upper bound
  • Phase 2a: Updated Fortran types for multi-archetype arrays

    • Added building_archetypes(:) allocatable array to SUEWS_SITE
    • Added sfr_bldg_arch(:) for archetype surface fractions
    • Updated allocation/deallocation routines
  • Phase 2b: Added archetype initialisation loop in driver

    • Loop variable and initialisation in suews_ctrl_driver.f95
  • Phase 3: Updated Python/Pydantic data model

    • Added sfr field to ArchetypeProperties
    • Added building_archetypes dict field to SiteProperties
    • Added validator for sfr sum == 1.0 and max 10 archetypes
    • Added effective_archetypes property and nbtypes property
  • Phase 4: Extended DataFrame bridge for multi-archetype

    • Added indexed serialisation methods (to_df_state_indexed, from_df_state_indexed)
    • Store nbtypes and archetype_names in DataFrame
  • Phase 5: Added per-archetype output variables

    • Added STEBBS_ARCHETYPE output group
    • Added generate_archetype_variables() function for dynamic variable generation
  • Phase 6: Created tests and fixtures

    • 19 tests covering data model, validation, serialisation, output variables

Remaining Work (Future PRs)

  • Fortran STEBBS physics loop with per-archetype calculations
  • Area-weighted aggregation using DOT_PRODUCT pattern
  • Integration tests with actual STEBBS simulations

Design Decisions

  • Max archetypes: 10 (dynamically scalable via allocatable arrays)
  • Per-archetype outputs: Opt-in via STEBBS_ARCHETYPE output group
  • Output naming: {variable}_{archetype_name} format (e.g., Tair_ind_residential)
  • Aggregation: Area-weighted using DOT_PRODUCT(flux_array, sfr_array) pattern

YAML Configuration Example

# Multi-archetype format
building_archetypes:
  residential:
    sfr: 0.6  # Surface fraction
    stebbs_Height: 8.5
    FootprintArea: 45.0
  commercial:
    sfr: 0.4
    stebbs_Height: 25.0
    FootprintArea: 500.0

# Single archetype (backwards compatible)
building_archetype:
  stebbs_Height: 10.0

Test plan

  • All smoke tests pass (9/9)
  • Multi-archetype unit tests pass (19/19)
  • Backwards compatibility with single archetype

🤖 Generated with Claude Code

@github-actions
Copy link

Preview Deployed

Content Preview URL
Site https://suews.io/preview/pr-1036/
Docs https://suews.io/preview/pr-1036/docs/

Note

This preview is ephemeral. It will be lost when:

  • Another PR with site/ or docs/ changes is pushed
  • Changes are merged to master
  • A manual workflow dispatch runs

To restore, push any commit to this PR.

sunt05 and others added 3 commits December 16, 2025 19:04
Phase 1 & 2a of GH#360 implementation:

- Change nbtypes from compile-time PARAMETER to runtime variable
- Add nbtypes_max=10 as upper bound for archetype count
- Add building_archetypes allocatable array to SUEWS_SITE type
- Add sfr_bldg_arch for archetype surface fractions
- Update allocation/deallocation routines

This provides the foundational data structures for multi-archetype
support while maintaining backwards compatibility with single-archetype
configurations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2b (partial):

- Add loop to copy single archetype to all building_archetypes array slots
- Add loop to initialise all building archetypes via gen_building
- Add i_arch loop variable declaration

The physics still uses buildings(1) for calculations. Full loop and
aggregation will be implemented when Python multi-archetype config
is ready.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 3-6 of multi-archetype implementation:

- Add `sfr` field to ArchetypeProperties for surface fraction
- Add `building_archetypes` dict field to SiteProperties for named archetypes
- Add validator for sfr sum == 1.0 and max 10 archetypes
- Add `effective_archetypes` property and `nbtypes` property
- Add indexed DataFrame serialisation (to_df_state_indexed, from_df_state_indexed)
- Add STEBBS_ARCHETYPE output group for per-archetype variables
- Add generate_archetype_variables() function for dynamic variable generation
- Add comprehensive test suite (19 tests)

YAML config example:
```yaml
building_archetypes:
  residential:
    sfr: 0.6
    stebbs_Height: 8.5
  commercial:
    sfr: 0.4
    stebbs_Height: 25.0
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use modern type hints (dict instead of Dict)
- Fix unused loop variables with .values() iteration
- Use direct assignment instead of object.__setattr__
- Simplify control flow with elif
- Use iterable unpacking for list concatenation
- Use next(iter()) instead of list slice
- Remove unused numpy/pandas imports in tests
- Fix regex patterns with raw strings
- Sort imports with ruff

All smoke tests and multi-archetype tests pass (33/33).
@sunt05
Copy link
Author

sunt05 commented Dec 16, 2025

Hi @yiqing1021, please take a look at this and see whether the prototype aligns with our expectations.

…#360)

Add .sort_index(axis=1) after DataFrame creation to ensure MultiIndex
columns are lexicographically sorted before access. This eliminates
"indexing past lexsort depth" warnings when accessing DataFrame cells.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sunt05 sunt05 marked this pull request as ready for review December 17, 2025 10:16
@yiqing1021
Copy link

Hi Ting,

Thanks for adding the new STEBBS features — the prototype looks good and the approach is reasonable.

A few points I think we should plan to address in future work:

1. yaml inputs for multiple archetypes.
Although the building_archetypes array is set up to store multiple archetypes, the YAML currently provides only a single set of archetype inputs, which is then passed into SUEWS_cal_multitsteps(). We’ll likely need to extend the YAML structure so each archetype can be defined and ingested explicitly.

2. aggregated output.
If we configure STEBBS outputgroup to produce outputs aggregated across archetypes, we’ll probably need additional logic to perform that aggregation downstream. Also, some variables (e.g., wall/roof surface temperatures) are currently stored in the type file for STEBBS–SS coupling; we may need to adjust how these are stored so the aggregated outputs can be passed cleanly into other modules.

@sunt05
Copy link
Author

sunt05 commented Dec 17, 2025

Thanks for the review, Yiqing.

Re: YAML inputs for multiple archetypes

Agreed - the infrastructure is in place but YAML schema needs extending. The Pydantic model already supports building_archetypes: dict[str, ArchetypeProperties], so it's mainly a case of adding the YAML parsing layer.

Re: aggregated output

Just to clarify - the PR already provides per-archetype outputs (e.g., Tair_ind_residential, Qload_heating_commercial). Your point is about whether we also need aggregated (weighted-average) outputs for users who want a single representative value, correct?

For STEBBS-SS coupling, the current design stores per-archetype surface temperatures. If SS needs a single aggregated value, we'd compute the weighted average at the coupling interface. This keeps maximum flexibility internally.

Shall we merge this first and create follow-up issues to track the remaining work?

@sunt05
Copy link
Author

sunt05 commented Dec 17, 2025

To clarify scope: this PR establishes the infrastructure (data model, Fortran arrays, initialisation loop), while the actual per-archetype calculations and output generation are follow-up work.

Proposal: let's expand #360 with sub-issues to track the full feature:

  1. Infrastructure for multiple archetypes (this PR)
  2. YAML schema extension for multi-archetype input
  3. Per-archetype STEBBS calculations and output

We can link this PR to close sub-issue 1, then work through the others. Thoughts? @yiqing1021

@yiqing1021
Copy link

Yes, I agree to merge this infrastructure for multi-archetype. Also we need to let @MatthewPaskin know this change because he designed the STEBBS structure.

@MatthewPaskin
Copy link

This looks good to me @yiqing1021 @sunt05 , however, where is the fraction for each archetype coming in? This has not previously been a parameter for STEBBS (YL correct me if I am wrong). There is however, the surface area and certain datasets contain the count of the archetype. I think a discussion may need to be had with Denise, Stefan and Sue with regarding how STEBBS aggregates across the different archetypes.

@sunt05 sunt05 added the 4-needs-discussion Agenda item for weekly catch-up meeting label Dec 17, 2025
@sunt05
Copy link
Author

sunt05 commented Dec 17, 2025

Thanks both @yiqing1021 @MatthewPaskin - let's leave this open for now.

Good point about the fraction parameter, Matthew. The sfr field in this PR is a placeholder that we haven't fully thought through yet - it could represent surface area fraction, building count weighting, or something derived from external datasets. This needs discussion.

From a maintenance perspective, STEBBS is becoming a substantial component of SUEWS. Before we proceed further, I'd like to have a clearer picture of how STEBBS should integrate as an organic component - particularly around:

  • Input structure (how archetypes are defined/sourced)
  • Aggregation logic (how outputs combine across archetypes)
  • Module coupling (STEBBS-SS interface)

Let's leave this to our next SUEWS catch-up.

@sunt05 sunt05 marked this pull request as draft December 17, 2025 15:56
@yiqing1021
Copy link

Thanks for these useful consideration, @MatthewPaskin ! This PR introduce a parameter “sfr_bldg_arch” for the aggregation, but currently not used. You are right, we should discuss how to do the aggregation of archetypes, but that likely sits outside SUEWS/STEBBS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4-needs-discussion Agenda item for weekly catch-up meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants