Skip to content

Fix/non periodic homogenization#24

Open
chemiskyy wants to merge 2 commits intomasterfrom
fix/non_periodic_homogenization
Open

Fix/non periodic homogenization#24
chemiskyy wants to merge 2 commits intomasterfrom
fix/non_periodic_homogenization

Conversation

@chemiskyy
Copy link
Member

This pull request refactors and improves the handling of periodic boundary conditions in fedoo/constraint/periodic_bc.py, focusing on the construction of multi-point constraints (MPCs) based on node distances. The changes enhance code clarity, introduce utility methods for MPC creation and weight calculation, and fix issues with variable assignment and array handling.

Refactoring and Utility Improvements:

  • Added two static utility methods: _mpc_from_2d to streamline the creation of MPC objects from 2D arrays, and _distance_weights to robustly compute normalized distance weights, including special handling for exact matches and edge cases.
  • Replaced repeated in-line logic for generating normalized weights with calls to the new _distance_weights method throughout the MPC construction process. [1] [2] [3] [4] [5] [6] [7] [8]
  • Simplified the creation of list_variables by using [list_disp[i] for _ in range(...)] instead of [list_disp[i] for i in range(...)], avoiding variable shadowing and improving clarity. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Bug Fixes and API Consistency:

  • Changed the access pattern for dic_closest_points_on_boundaries from function-call style to dictionary-style (e.g., ["face_Xm"] instead of ("face_Xm")), ensuring correct data retrieval and preventing runtime errors.
  • Updated the constructor of the periodic BC class to accept and store dic_closest_points_on_boundaries as an optional argument, improving flexibility and future extensibility. [1] [2]

Other Notable Changes:

  • Changed D_xyz from a list to a NumPy array for consistency and to enable efficient array operations.

These changes collectively improve code maintainability, reliability, and performance in the handling of periodic boundary conditions.

Add support for storing dic_closest_points_on_boundaries in __init__ and use it during initialize when not provided. Replace tuple-call dict access with standard dict indexing when constructing face/edge/corner members. Introduce helper methods _distance_weights (robust normalized distance weighting that handles exact matches) and _mpc_from_2d (convert 2D arrays to MPC list-of-arrays), and use them throughout to replace repeated normalization and MPC(...) calls. Convert D_xyz to a NumPy array and fix dtype usage for np.full_like. Improve error handling in initialize with a clear ValueError when non-periodic data is missing and pass d_rve from the dictionary. These changes simplify MPC construction, fix indexing/normalization bugs, and make weight computation more robust.
Forward the dic_closest_points_on_boundaries keyword from get_tangent_stiffness's **kargs** into the PeriodicBC constructor. This allows callers to supply a mapping of closest points on boundaries for periodic boundary conditions when computing the tangent stiffness.
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