[meshlib] add append method to mesh series
Allows to append mesh series.
-
Feature description was added to the changelog -
Tests covering your feature were added? -
Any new feature or behaviour change was documented? -
API-breaking changes documented here
Merge request reports
Activity
added workflowin development label
added 12 commits
-
4d115f00...55882677 - 9 commits from branch
ogs/tools:main
- c4800ca8 - parse timesteps from vtui input
- 60a6b5c5 - add append method
- 3a977f2b - fix path variable for append method
Toggle commit list-
4d115f00...55882677 - 9 commits from branch
added Feature label
added 37 commits
-
8b61cb0f...89680d9b - 35 commits from branch
ogs/tools:main
- 791b91a1 - implement extend and merge functions to mesh series
- 583a2396 - add tests for merge and extend
-
8b61cb0f...89680d9b - 35 commits from branch
added workflowplease review label and removed workflowin development label
108 108 ) 109 109 return new_ms 110 110 111 @classmethod 112 def merge( 113 cls, mesh_series1: MeshSeries, mesh_series2: MeshSeries 114 ) -> MeshSeries: 115 "Merge two Mesh Series while keeping all timevalues" 116 ms_list = list(mesh_series1) + list(mesh_series2) 117 ms_timevalues = np.append( 118 mesh_series1.timevalues, mesh_series2.timevalues, axis=0 119 ) 120 ms_timevalues, ms_list = zip( 121 *sorted(zip(ms_timevalues, ms_list, strict=False)), strict=False I'm confused about the strict=False. In from_data there is strict=True, so if the length of timevalues and meshes doesn't match it fails anyway, thus we also use strict=True here and fail early. The line is clever but a but confusing with the double zip. Is the sorting necessary? I wonder what a practical use case would be, where you want to join two meshseries and their timevalues are intersecting?
I think it is not possible that both lengths disagree. The strinct keyword was added automatically, which is why it is set to False. I can set it to True.
Some words on the context. I first wanted to have only an append function, but discussed with @TobiasMeisel that merge might be more general and would make sense in the case of different time discretiztions/outputs. During implementation, I realized that both features needed to have different implementations (because of the sorting for merge and the offset for append), which is why there are 2 methods now. However, I'm not completely convinced of this use case.
That would be good. I don't really see any usecase here even after giving it some thought.
And regarding the extend method: would it make sense, to make the offset a function argument, which the user provides? i.e.
ms1.extend(ms2, offset=ms1.timevalues[-1])
But if this would be done in 99% of the use cases anyway, then I see that we can automate it. Was just some food for thought.
108 108 ) 109 109 return new_ms 110 110 111 @classmethod 112 def merge( 113 cls, mesh_series1: MeshSeries, mesh_series2: MeshSeries 114 ) -> MeshSeries: 115 "Merge two Mesh Series while keeping all timevalues" 116 ms_list = list(mesh_series1) + list(mesh_series2) 117 ms_timevalues = np.append( 118 mesh_series1.timevalues, mesh_series2.timevalues, axis=0 119 ) 120 ms_timevalues, ms_list = zip( 121 *sorted(zip(ms_timevalues, ms_list, strict=False)), strict=False 122 ) 123 return cls.from_data(ms_list, np.array(ms_timevalues)) 131 ) -> MeshSeries: 132 "Extends mesh_series1 with mesh_series2 removing redundant entries" 133 ms1_list = list(mesh_series1) 134 ms2_list = list(mesh_series2) 135 ms1_timevalues = mesh_series1.timevalues 136 ms2_timevalues = mesh_series2.timevalues 137 offset = 0.0 138 if ms2_timevalues[0] < ms1_timevalues[-1]: 139 offset = ms1_timevalues[-1] 140 if ms2_timevalues[0] == 0.0: 141 ms1_timevalues = ms1_timevalues[:-1] 142 ms1_list = ms1_list[:-1] 143 elif np.abs(ms2_timevalues[0] - ms1_timevalues[-1]) < epsilon: 144 ms1_timevalues = ms1_timevalues[:-1] 145 ms1_list = ms1_list[:-1] 146 ms2_timevalues = ms2_timevalues + offset - Comment on lines +137 to +146
138 if ms2_timevalues[0] < ms1_timevalues[-1]: 139 offset = ms1_timevalues[-1] 140 if ms2_timevalues[0] == 0.0: 141 ms1_timevalues = ms1_timevalues[:-1] 142 ms1_list = ms1_list[:-1] 143 elif np.abs(ms2_timevalues[0] - ms1_timevalues[-1]) < epsilon: 144 ms1_timevalues = ms1_timevalues[:-1] 145 ms1_list = ms1_list[:-1] 146 ms2_timevalues = ms2_timevalues + offset 138 delta = ms2_timevalues[0] - ms1_timevalues[-1] 139 offset = 0.0 if delta >= 0 else ms1_timevalues[-1] 140 if ((delta < 0) and (ms2_timevalues[0] == 0.0)) or (np.abs(delta) < epsilon): 141 ms1_timevalues = ms1_timevalues[:-1] 142 ms1_list = ms1_list[:-1] 143 ms2_timevalues = ms2_timevalues + offset