Skip to content

Conversation

@Xiangyu-Hu
Copy link
Owner

This pull request refactors the initialization and registration of discrete variables throughout the codebase, centralizing initialization logic within the DiscreteVariable class and removing redundant initialization functions from other classes. The changes simplify variable creation, improve maintainability, and ensure consistent default initialization, especially for matrix types.

Key changes include:

Centralization and Simplification of Discrete Variable Initialization

  • Added new constructors to the DiscreteVariable class to support initialization with a default value, an initialization function, or by copying from another variable, moving all initialization logic into this class.
  • Removed the initializeVariable functions from both BaseParticles and BaseCellLinkedList, as their logic is now handled by the new DiscreteVariable constructors. [1] [2] F99d5537L93R93, [3]

Updates to Variable Registration Methods

  • Updated all variable registration and addition methods in BaseParticles and BaseCellLinkedList to directly forward initialization arguments to the new DiscreteVariable constructors, removing manual initialization steps. [1] [2] [3]

Improved Zero Initialization for Matrix Types

  • Specialized the ZeroData struct to correctly handle zero initialization for Eigen matrix types, ensuring matrices are initialized with zeros by default.

Code Cleanup

  • Removed now-unnecessary code paths that checked for null data pointers and performed late initialization, as all variables are now properly initialized at construction.

These changes collectively make variable management more robust and easier to maintain, while reducing code duplication and potential errors from inconsistent initialization.

@Xiangyu-Hu Xiangyu-Hu requested a review from Lisu-lisa November 25, 2025 21:48
@Xiangyu-Hu Xiangyu-Hu merged commit a3517f4 into master Nov 27, 2025
15 of 16 checks passed
@Xiangyu-Hu Xiangyu-Hu deleted the xiangyu/discrete_variable_initialization branch November 27, 2025 16:50
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.

3 participants