Skip to content

Add metadata to component objects#596

Open
cmacmackin wants to merge 5 commits into
masterfrom
cmacmackin/component_metadata
Open

Add metadata to component objects#596
cmacmackin wants to merge 5 commits into
masterfrom
cmacmackin/component_metadata

Conversation

@cmacmackin

@cmacmackin cmacmackin commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Purpose

It could be difficult to produce meaningful error messages, because component names are not consistently stored and their type information is not available at runtime. This PR provide a standard interface for this metadata.

Change Summary

The name of the component object is now a mandatory parameter for the Component base class. This gets stored in a private variable and can be accessed using the public objectName() method.

The component type names were a bit more complicated, as it is useful to have these available both statically and dynamically. Components are now expected to provide a static constexpr auto type component which can be converted to a string. This is used by the RegisterComponent helper type to set the type-name associated with the component class (as opposed to passing it to the constructor manually). Additionally, all Component classes must implement the virtual function typeName().

For most sub-classes, this is done using the CRTP. Rather than inheriting directly from Component they inherit from template<typname T> NamedComponent. The secondary NamedComponent class was required so that method implementations for the Component base class can still be put in a separate file from the header. Note that the reaction classes create many components from the same (possibly templated) class and therefore don't use NamedComponent. Instead they use custom logic to set the static constant and define the virtual method.

A formatter has been defined for Component objects, which makes use of the objectName() and typeName() methods. By default, this prints names with the format objname (typename), or just typename if these two names are the same.

Validation

New unit tests were written for the objectName() method and the formatter, which confirms that these work as intended.

Additionally, a unit test was added which instantiates all component type registered with the factory and confirms that typeName() returns the same name as used to create them with the factory. Note that this is the first time there has been any test that many of these components can be constructed at all.

AI Assistance

No AI tools were used.

Documentation

The developer documentation has been updated to reflect the new requirements when writing a component class. I will leave it up to reviewers to advise whether they think any additional details would be beneficial.

Review Notes

This work was originally done on top of #428, but I've spun it off so it can be merged earlier.

@cmacmackin cmacmackin force-pushed the cmacmackin/component_metadata branch from 7a2c0df to 1e3cccb Compare June 29, 2026 16:24
Not completed for all components, which have dummy-data in the
meantime.
As a nice side-effect, this also adds tests for instantiating all Components.
@cmacmackin cmacmackin force-pushed the cmacmackin/component_metadata branch from 7c130ff to 27e6af8 Compare June 29, 2026 17:09
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.80165% with 476 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.98%. Comparing base (d66b56c) to head (27e6af8).

Files with missing lines Patch % Lines
include/fixed_fraction_radiation.hxx 0.00% 157 Missing ⚠️
src/sheath_boundary_simple.cxx 20.53% 89 Missing ⚠️
include/detachment_controller.hxx 73.52% 27 Missing ⚠️
src/binormal_stpm.cxx 33.33% 20 Missing ⚠️
include/temperature_feedback.hxx 63.46% 19 Missing ⚠️
src/electromagnetic.cxx 38.70% 19 Missing ⚠️
include/simple_pump.hxx 0.00% 18 Missing ⚠️
include/upstream_density_feedback.hxx 14.28% 18 Missing ⚠️
src/temperature_feedback.cxx 0.00% 17 Missing ⚠️
src/anomalous_diffusion.cxx 39.13% 14 Missing ⚠️
... and 24 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #596      +/-   ##
==========================================
+ Coverage   49.09%   52.98%   +3.88%     
==========================================
  Files          96       97       +1     
  Lines       10037    10078      +41     
  Branches     1452     1463      +11     
==========================================
+ Hits         4928     5340     +412     
+ Misses       4604     4215     -389     
- Partials      505      523      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@cmacmackin

Copy link
Copy Markdown
Collaborator Author

Irritatingly, the coverage test is failing because prek and clang-format went and totally rewrote a few files. The changes were only to formatting, but they are showing up as untested.

@cmacmackin

Copy link
Copy Markdown
Collaborator Author

@ZedThree I know you're busy but I thought you might be a good person to review this, as it involves some messing around with templates and meta-programming.

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.

1 participant