Skip to content

Use std::any for DataIO context #32303

Open
dschwen wants to merge 9 commits intoidaholab:nextfrom
dschwen:std_any_32302
Open

Use std::any for DataIO context #32303
dschwen wants to merge 9 commits intoidaholab:nextfrom
dschwen:std_any_32302

Conversation

@dschwen
Copy link
Member

@dschwen dschwen commented Feb 2, 2026

Closes #32302

@moosebuild
Copy link
Contributor

Job Test, step Results summary on 2ee5605 wanted to post the following:

Framework test summary

Compared against e4407b3 in job civet.inl.gov/job/3542080.

No change

Modules test summary

Compared against e4407b3 in job civet.inl.gov/job/3542080.

No change

@moosebuild
Copy link
Contributor

Job Documentation, step Docs: sync website on 2ee5605 wanted to post the following:

View the site here

This comment will be updated on new commits.

@loganharbour
Copy link
Member

No concerns here. I've wanted this for a while. Now to fix...

@dschwen dschwen force-pushed the std_any_32302 branch 4 times, most recently from 0a283cc to 218de34 Compare February 7, 2026 01:28
dschwen and others added 7 commits February 6, 2026 18:28
- Add missing includes (sstream, string, typeindex, libmesh/utility.h)
- Fix AnyPtr -> AnyPointer typos in copy/move constructors/operators
- Fix member variable references (type -> _type_id, ptr -> _ptr)
- Fix initializer list naming (msg_ -> _msg)
- Fix typeinfo(void) -> typeid(void)
- Add missing semicolon after class definition
- Use initializer list in constructor instead of assignment
- Add hasValue() method for checking if pointer is set
- Handle const pointer conversion properly with const_cast

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- TimeIntegrator now properly passes Communicator reference for _solution_sub
  and _solution_old_sub serialization (preserves original restartable behavior)
- Updated DataIO.C unique_ptr<NumericVector> specializations to accept
  Communicator& instead of Communicator*
- Removed catch-all template for raw pointer serialization from DataIO.h
  (eliminates ordering fragility where specializations had to come first)
- Cleaned up LibtorchArtificialNeuralNet old AnyPointer specializations
- Updated test files to use template Context parameter

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Converted dataStore/dataLoad specializations in stochastic_tools module
  from Moose::AnyPointer to templated Context parameter
- Updated GaussianProcess, Standardizer, and SnapshotContainerBase
- Made Eigen::LLT serialization functions template-based
- Removed RestartableModelInterface AnyPointer usage
- Updated phase_field FeatureFloodCount serialization
- Updated navier_stokes FaceCenteredMapFunctor serialization
- Updated xfem GeometricCutUserObject serialization
- Added DataIOContext.h with context type traits and compatibility checks

This completes the transition from AnyPointer to typed Context templates
for all module-level restartable data serialization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Removes the required_load_context and context_compatible_v trait system
from DataIO. The traits were used to provide early compile-time error
messages when wrong context types were passed to container dataLoad
functions, but added complexity without sufficient benefit.

With RestartableData<T, Context> now making context types explicit at
compile-time, the natural template instantiation errors are sufficient
to catch context mismatches.

Changes:
- Deleted framework/include/utils/DataIOContext.h
- Removed all static_assert calls using context_compatible_v
- Removed #include "DataIOContext.h" from DataIO.h
- Cleaned up formatting with clang-format

The type system itself now enforces context correctness.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dschwen dschwen force-pushed the std_any_32302 branch 2 times, most recently from a0714bf to e0b50f7 Compare February 7, 2026 20:21
Completes the conversion of dataStore/dataLoad functions from using
Moose::AnyPointer to templated Context parameters throughout the
codebase. This eliminates all type erasure in the serialization system.

Framework changes:
- MultiApp: Removed AnyPointer handling, kept void* and MultiApp* support
- KokkosMaterialPropertyStorage: Converted to template with MooseMesh* instantiation
- KokkosArray: Added Context template parameter
- LibtorchArtificialNeuralNet: Converted to template
- SolutionInvalidity: Converted declarations to templates

Module changes:
- ray_tracing: Converted Ray dataStore/dataLoad to templates with RayTracingStudy* context
- phase_field: Converted GrainTracker and DiscreteNucleationInserterBase
- stochastic_tools: Converted PolynomialQuadrature and SnapshotContainerBase

Test changes:
- Removed Moose::AnyPointer(...) wrappers from all test call sites
- Tests now pass raw pointers directly (e.g., `this` instead of `Moose::AnyPointer(this)`)

All dataStore/dataLoad functions now use compile-time type-safe Context
parameters with no runtime type erasure.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@moosebuild
Copy link
Contributor

Job Precheck, step Clang format on 5e55ad2 wanted to post the following:

Your code requires style changes.

A patch was auto generated and copied here
You can directly apply the patch by running, in the top level of your repository:

curl -s https://mooseframework.inl.gov/docs/PRs/32303/clang_format/style.patch | git apply -v

Alternatively, with your repository up to date and in the top level of your repository:

git clang-format 1055f6b4261e471330249f148dc2d26b3c0e31bf

Adds explicit template instantiations to fix linker errors for
dataStore/dataLoad functions with various Context types.

Instantiations added for:
- Basic types (Real, Point, VectorValue, TensorValue, DenseMatrix) with
  std::nullptr_t and libMesh::MeshBase* contexts
- ADReal types with std::nullptr_t context
- Elem/Node pointers with libMesh::MeshBase* context
- MaterialPropertyStorage and MaterialProperties with appropriate contexts
- SolutionInvalidity with std::nullptr_t context
- RestartableEquationSystems with MooseMesh* context
- PerfGraph with MooseApp* context
- NumericVector with const Communicator* context
- Test types (RestartableTypesChecker) with appropriate contexts

These instantiations are required because the template functions need
to be explicitly instantiated for each Context type used in the codebase.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

Change dataLoad/dataSave context from void * to std::any

3 participants