Welcome, Guest
Username: Password: Remember me

TOPIC: Unexpected behavior when loading a geometry through the Python API

Unexpected behavior when loading a geometry through the Python API 4 years 3 months ago #36556

  • fviry
  • fviry's Avatar
Hi,

I have a unexpected behavior when loading a very simple geometry with 2 profiles described by a different number of points (4 for the first one, 6 for the second one) through the Python API of Mascaret.

The geometry is the following:
PROFIL Reach_1 UPSTREAM 0.0
-2.5 4.5 B
-2.5 0.5 B
2.5 0.5 B
2.5 4.5 B
PROFIL Reach_1 DOWNSTREAM 500.0
-3.5 5.0 B
-2.5 4.0 B
-2.5 0.0 B
2.5 0.0 B
2.5 4.0 B
3.5 5.0 B

When printing the X and Y values of both profiles, I get the following result:
> Model.CrossSection.X
[[-2.5 -2.5 -2.5  2.5  2.5  2.5]
 [-3.5 -3.5 -2.5 -2.5  2.5  2.5]]
> Model.CrossSection.Y
[[ 14.5   4.5   0.5   0.5   4.5  14.5]
 [ 15.    5.    4.    0.    0.    4. ]]

The first profile (first subarray of each printed array) is good, but what annoys me is that the last point (and also the point added by Mascaret to add a "wall") of the second profile (second subarray of each printed array) has been dropped.

Is it a bad definition of my geometry?
Or am I wrong in my script?

I attached all the files needed to reproduce the problem.
I am using Mascaret V8P2R0 (fishstick branch).

Thanks in advance
Attachments:
The administrator has disabled public write access.

Unexpected behavior when loading a geometry through the Python API 4 years 3 months ago #36569

  • fviry
  • fviry's Avatar
I found my mistake, I did not use the right way the API.

The Model.CrossSection.* variables are not 2D arrays, but a collection of 1D arrays, which is consistent with the fact that cross sections are not always described by the same number of points.

In my old script, I used the method get_var_size as follows:
mascaret.get_var_size('Model.CrossSection.X')		# returns (2, 6, 0)

In my new script, I used the same method but with its second argument, allowing me to select the cross section I want:
mascaret.get_var_size('Model.CrossSection.X', 0)	# returns (2, 6, 0)
mascaret.get_var_size('Model.CrossSection.X', 1)	# returns (2, 8, 0)
Here, the second value of each returned tuple is what I expected.

The new script giving the expected values is attached and gives the following result:
> Model.CrossSection.X
[array([-2.5, -2.5, -2.5,  2.5,  2.5,  2.5]), array([-3.5, -3.5, -2.5, -2.5,  2.5,  2.5,  3.5,  3.5])]
> Model.CrossSection.Y
[array([ 14.5,   4.5,   0.5,   0.5,   4.5,  14.5]), array([ 15.,   5.,   4.,   0.,   0.,   4.,   5.,  15.])]
Attachments:
The administrator has disabled public write access.
Moderators: JFourdrinoy

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.