From 3ec23af77456200a128e8f9435be074375cb251d Mon Sep 17 00:00:00 2001 From: MuellerSeb Date: Fri, 5 Jul 2019 15:29:21 +0200 Subject: [PATCH] gli: fix add_polyline bug for given IDs and add swap_axis; msh: add swap_axis --- ogs5py/fileclasses/gli/core.py | 38 +++++++++++++++++++++++++++++++++- ogs5py/fileclasses/msh/core.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/ogs5py/fileclasses/gli/core.py b/ogs5py/fileclasses/gli/core.py index 89dc6a9..f086fa0 100644 --- a/ogs5py/fileclasses/gli/core.py +++ b/ogs5py/fileclasses/gli/core.py @@ -410,6 +410,42 @@ def check(self, verbose=True): """ return check_gli_dict(self.__dict, verbose=verbose) + def swap_axis(self, axis1="y", axis2="z"): + """ + Swap axis of the coordinate system + + Parameters + ---------- + axis1 : :class:`str` or :class:`int`, optional + First selected Axis. + Either in ["x", "y", "z"] or in [0, 1, 2]. Default: "y" + axis2 : :class:`str` or :class:`int`, optional + Second selected Axis. + Either in ["x", "y", "z"] or in [0, 1, 2]. Default: "z" + """ + axis = ["x", "y", "z"] + if axis1 in range(3): + axis1 = axis[axis1] + if axis2 in range(3): + axis2 = axis[axis2] + if axis1 not in axis or axis2 not in axis: + raise ValueError( + "GLI.swap_axis: axis need to be 'x', 'y' or 'z': " + + str(axis1) + + ", " + + str(axis2) + ) + if axis1 == axis2: + raise ValueError( + "GLI.swap_axis: please select distict axis: " + + str(axis1) + + " = " + + str(axis2) + ) + ax1 = axis.index(axis1) + ax2 = axis.index(axis2) + self.POINTS[:, [ax1, ax2]] = self.POINTS[:, [ax2, ax1]] + def rotate( self, angle, @@ -616,7 +652,7 @@ def add_polyline( "POINT_VECTOR": point_vector, } # add by name - if ( + elif ( is_str_array(points) and points.ndim == 1 and points.shape[0] >= 2 diff --git a/ogs5py/fileclasses/msh/core.py b/ogs5py/fileclasses/msh/core.py index 33cd2c9..3310d44 100644 --- a/ogs5py/fileclasses/msh/core.py +++ b/ogs5py/fileclasses/msh/core.py @@ -808,6 +808,42 @@ def check(self, verbose=True): """ return check_mesh_list(self._meshlist, verbose=verbose) + def swap_axis(self, axis1="y", axis2="z"): + """ + Swap axis of the coordinate system + + Parameters + ---------- + axis1 : :class:`str` or :class:`int`, optional + First selected Axis. + Either in ["x", "y", "z"] or in [0, 1, 2]. Default: "y" + axis2 : :class:`str` or :class:`int`, optional + Second selected Axis. + Either in ["x", "y", "z"] or in [0, 1, 2]. Default: "z" + """ + axis = ["x", "y", "z"] + if axis1 in range(3): + axis1 = axis[axis1] + if axis2 in range(3): + axis2 = axis[axis2] + if axis1 not in axis or axis2 not in axis: + raise ValueError( + "MSH.swap_axis: axis need to be 'x', 'y' or 'z': " + + str(axis1) + + ", " + + str(axis2) + ) + if axis1 == axis2: + raise ValueError( + "MSH.swap_axis: please select distict axis: " + + str(axis1) + + " = " + + str(axis2) + ) + ax1 = axis.index(axis1) + ax2 = axis.index(axis2) + self.NODES[:, [ax1, ax2]] = self.NODES[:, [ax2, ax1]] + def rotate( self, angle,