You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When adding 1D2D links more than one time, for example some embedded and some later links, issues arise due to double counting of link ids. I found the issue and propose a solution below.
To Reproduce
within the Link1d2d class in HYDROLIB-core/hydrolib/core/dflowfm/net/models.py, the process function appends new links to exising links. The code below is currently in HYDROLIB:
def _process(self) -> None:
"""
Get links from meshkernel and add to the array with link administration
"""
contacts = self.meshkernel.contacts_get()
self.link1d2d = np.append(
self.link1d2d,
np.stack([contacts.mesh1d_indices, contacts.mesh2d_indices], axis=1),
axis=0,
)
self.link1d2d_contact_type = np.append(
self.link1d2d_contact_type, np.full(contacts.mesh1d_indices.size, 3)
)
self.link1d2d_id = np.append(
self.link1d2d_id,
np.array([f"{n1d:d}_{f2d:d}" for n1d, f2d in self.link1d2d]),
)
self.link1d2d_long_name = np.append(
self.link1d2d_long_name,
np.array([f"{n1d:d}_{f2d:d}" for n1d, f2d in self.link1d2d]),
)
Here, self.link1d2d and self.link1d2d_contact_type are handled correctly. However, self.link1d2d_id and self.link1d2d_long_name take the current entries and apppend the names of all 1d2d link in self.1d2d link. As self.1d2dlink contains both the old and new entries (due to the append earlier), self.link1d2d_id will end up with double entries for all entries that were already present. This leads to errors when writing the DIMR configuration.
A solution would be to change the process function into the following, solving the issue:
def _process(self) -> None:
"""
Get links from meshkernel and add to the array with link administration
"""
contacts = self.meshkernel.contacts_get()
self.link1d2d = np.append(
self.link1d2d,
np.stack([contacts.mesh1d_indices, contacts.mesh2d_indices], axis=1),
axis=0,
)
self.link1d2d_contact_type = np.append(
self.link1d2d_contact_type, np.full(contacts.mesh1d_indices.size, 3)
)
self.link1d2d_id = np.array([f"{n1d:d}_{f2d:d}" for n1d, f2d in self.link1d2d])
self.link1d2d_long_name = np.array([f"{n1d:d}_{f2d:d}" for n1d, f2d in self.link1d2d])
Expected behavior
No double counting and correctly saving the model
The text was updated successfully, but these errors were encountered:
Hi @Kreef, thanks for creating this issue. For the Mesh2d class these type of issues were fixed by aligning directly with the underlying meshkernel class at the end of last year, but we did not get around implementing this for the other hydrolib-core classes. I will link the issue where we plan to do this for future reference: #576
Describe the bug
When adding 1D2D links more than one time, for example some embedded and some later links, issues arise due to double counting of link ids. I found the issue and propose a solution below.
To Reproduce
within the Link1d2d class in HYDROLIB-core/hydrolib/core/dflowfm/net/models.py, the process function appends new links to exising links. The code below is currently in HYDROLIB:
def _process(self) -> None:
"""
Get links from meshkernel and add to the array with link administration
"""
contacts = self.meshkernel.contacts_get()
Here, self.link1d2d and self.link1d2d_contact_type are handled correctly. However, self.link1d2d_id and self.link1d2d_long_name take the current entries and apppend the names of all 1d2d link in self.1d2d link. As self.1d2dlink contains both the old and new entries (due to the append earlier), self.link1d2d_id will end up with double entries for all entries that were already present. This leads to errors when writing the DIMR configuration.
A solution would be to change the process function into the following, solving the issue:
Expected behavior
No double counting and correctly saving the model
The text was updated successfully, but these errors were encountered: