Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serafin.Write creates a ghosted frame #30

Closed
nicogodet opened this issue Apr 10, 2024 · 4 comments
Closed

Serafin.Write creates a ghosted frame #30

nicogodet opened this issue Apr 10, 2024 · 4 comments

Comments

@nicogodet
Copy link
Contributor

Maillage.zip

Here is 3 files:

  • "input.slf": File created by QGIS after mesh edition
  • "pyteltools_out.slf": output file of below script
  • "FUDAA_export.slf": export of pyteltools_out.slf with 1 timestep sith FUDAA

Python script

from pyteltools.slf import Serafin
with Serafin.Read("input.slf", "fr") as resin:
    resin.read_header()
    output_header = resin.header.copy()
    output_header.title = bytes("MAILLAGE", Serafin.SLF_EIT)
    output_header.empty_variables()
    output_header.add_variable_from_ID("B")
    output_header.add_variable_from_ID("W")
    output_values = np.ones(
        (output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type
    )

with Serafin.Write("pyteltools_out.slf", "fr" "", overwrite=True) as resout:
    resout.write_header(output_header)
    resout.write_entire_frame(output_header, 0.0, output_values)

Note np.ones

"Error" when reading pyteltools_out.slf with FUDAA
image

Frame 0 with 1 everywhere
image

Frame 1 (???) with 0
image

It seems harmless.

If "pyteltools_out.slf" is set as GEOMETRY FILE and computation is run in parallel, partel fails to split the file.

Partel log
partel < partel_T2DGEO.par

 +-------------------------------------------------+
   PARTEL/PARRES: TELEMAC METISOLOGIC PARTITIONER

   REBEKKA KOPMANN & JACEK A. JANKOWSKI (BAW)
                  JEAN-MICHEL HERVOUET (LNHE)
                  CHRISTOPHE DENIS     (SINETICS)
                  YOANN AUDOUIN        (LNHE)
   PARTEL (C) COPYRIGHT 2000-2002
   BUNDESANSTALT FUER WASSERBAU, KARLSRUHE

   METIS 5.0.2 (C) COPYRIGHT 2012
   REGENTS OF THE UNIVERSITY OF MINNESOTA

   BIEF V8P5   (C) COPYRIGHT 2012 EDF
 +-------------------------------------------------+


   MAXIMUM NUMBER OF PARTITIONS:       100000

 +--------------------------------------------------+

 --INPUT FILE NAME <INPUT_NAME>:
 INPUT: T2DGEO
 --INPUT FILE FORMAT <INPFORMAT> [MED,SERAFIN,SERAFIND]:
  INPUT: SERAFIND
 --BOUNDARY CONDITIONS FILE NAME:
 INPUT: T2DCLI
--NUMBER OF PARTITIONS <NPARTS> [2 -100000]:
  INPUT:            2
  PARTITIONING METHOD <PMETHOD>                                                                                     [1 (METIS) OR 2 (SCOTCH)]:
 --INPUT:            1
 --CONTROL SECTIONS FILE NAME (OR RETURN) :
  NO SECTIONS
 --CONTROL ZONES FILE NAME (OR RETURN) :
  NO ZONES
 --WEIR FILE NAME (OR RETURN) :
  NO WEIRS
 --GEOMETRY FILE NAME <INPUT_NAME>:
 INPUT: T2DGEO
 --GEOMETRY FILE FORMAT <GEOFORMAT> [MED,SERAFIN,SERAFIND]:
  INPUT: SERAFIND
 --CONCATENATE FILES <YES-NO>:
 CONCATENATE: NO
 +---- PARTEL: BEGINNING -------------+
 FICHIER:T2DGEO                                                                                                                                                                        


 READ_MESH_INFO: TITLE= MAILLAGE
            NUMBER OF ELEMENTS:    26907
            NUMBER OF POINTS:    13628

            TYPE OF ELEMENT: TRIANGLE
            TYPE OF BND ELEMENT: POINT

            DOUBLE PRECISION FORMAT (R8)


 ONE-LEVEL MESH.
 NDP NODES PER ELEMENT:                    3
 ELEMENT TYPE :                           10
 NPOIN NUMBER OF MESH NODES:           13628
 NELEM NUMBER OF MESH ELEMENTS:        26907

 THE INPUT FILE ASSUMED TO BE 2D
 THERE ARE            1  TIME-DEPENDENT RECORDINGS

 THERE IS     3 ISLAND(S) IN THE DOMAIN

 THERE IS     2 LIQUID BOUNDARIES:

 BOUNDARY    1 :
  BEGINS AT BOUNDARY POINT:      125 , WITH GLOBAL NUMBER:         3
  AND COORDINATES:     350085.9           6247820.
  ENDS AT BOUNDARY POINT:      145 , WITH GLOBAL NUMBER:       319
  AND COORDINATES:     350253.9           6247411.

 BOUNDARY    2 :
  BEGINS AT BOUNDARY POINT:      237 , WITH GLOBAL NUMBER:      1017
  AND COORDINATES:     350444.2           6246046.
  ENDS AT BOUNDARY POINT:        1 , WITH GLOBAL NUMBER:      1218
  AND COORDINATES:     350472.9           6246000.

 THERE IS     5 SOLID BOUNDARIES:

 BOUNDARY    1 :
  BEGINS AT BOUNDARY POINT:        1 , WITH GLOBAL NUMBER:      1218
  AND COORDINATES:     350472.9           6246000.
  ENDS AT BOUNDARY POINT:      125 , WITH GLOBAL NUMBER:         3
  AND COORDINATES:     350085.9           6247820.

 BOUNDARY    2 :
  BEGINS AT BOUNDARY POINT:      145 , WITH GLOBAL NUMBER:       319
  AND COORDINATES:     350253.9           6247411.
  ENDS AT BOUNDARY POINT:      237 , WITH GLOBAL NUMBER:      1017
  AND COORDINATES:     350444.2           6246046.

 BOUNDARY    3 :
  BEGINS AT BOUNDARY POINT:      246 , WITH GLOBAL NUMBER:      1421
  AND COORDINATES:     350485.4           6246302.
  ENDS AT BOUNDARY POINT:      246 , WITH GLOBAL NUMBER:      1421
  AND COORDINATES:     350485.4           6246302.

 BOUNDARY    4 :
  BEGINS AT BOUNDARY POINT:      277 , WITH GLOBAL NUMBER:      3076
  AND COORDINATES:     350505.9           6246295.
  ENDS AT BOUNDARY POINT:      277 , WITH GLOBAL NUMBER:      3076
  AND COORDINATES:     350505.9           6246295.

 BOUNDARY    5 :
  BEGINS AT BOUNDARY POINT:      313 , WITH GLOBAL NUMBER:      6052
  AND COORDINATES:     350524.2           6246299.
  ENDS AT BOUNDARY POINT:      313 , WITH GLOBAL NUMBER:      6052
  AND COORDINATES:     350524.2           6246299.
  THE MESH PARTITIONING STEP STARTS
 BEGIN PARTITIONING WITH METIS
  RUNTIME OF METIS    0.00000000      SECONDS
  THE MESH PARTITIONING STEP HAS FINISHED
 ERROR IN BOUNDARIES J=         236
 WHILE NPTFR_P(I)=           0
 WHILE L=           0



 PLANTE: PROGRAM STOPPED AFTER AN ERROR
 RETURNING EXIT CODE:            2
STOP 1

With "FUDAA_export.slf", partel is OK

@nicogodet nicogodet changed the title Fudaa-PREPRO read 2 timestep while PyTelTools reads 1 Serafin.Write creates a ghosted frame Apr 10, 2024
@lucduron
Copy link
Member

lucduron commented Apr 11, 2024

Hi Nicolas,

The number of frames is not a variable included in the Serafin file, but it is computed from the file size and parameters (single vs double precision). I think Fudaa-PrePro is more permissive: it can open a non-valid file and can fix it.

Indeed, your initial Serafin file input.slf does not seem valid. For example its params are all set to 0.

The file cannot be opened in BlueKenue:

image

image

I added (see 64e8fc8) a method to rebuild params tuple, but it is not sufficient. The file still can not be opened in BlueKenue for example (a problem in the mesh : X/Y/IKLE ?).

I ran this script:

import logging
import matplotlib.pyplot as plt
import numpy as np

from pyteltools.slf import Serafin
from pyteltools.slf.util import logger

logger.setLevel(logging.DEBUG)

with Serafin.Read("input.slf", "fr") as resin:
    resin.read_header()
    print("Initial params", resin.header.params)

    output_header = resin.header.copy()
    # output_header.date = (1900, 1, 1, 0, 0, 0)
    output_header.build_params()
    output_header.title = bytes("MAILLAGE", Serafin.SLF_EIT).ljust(72)
    output_header.empty_variables()
    output_header.add_variable_from_ID("B")
    output_header.add_variable_from_ID("W")
    print("New params", output_header.params)

    output_values = np.ones(
        (output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type
    )

with Serafin.Write("pyteltools_out_2.slf", "fr", overwrite=True) as resout:
    resout.write_header(output_header)
    resout.write_entire_frame(output_header, 0.0, output_values)

plt.triplot(output_header.x, output_header.y, triangles=output_header.ikle - 1)
plt.show()

Its output is:

Reading the input file: "input.slf" of size 595652 bytes
Writing the output file: "pyteltools_out_2.slf"
Initial params (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
New params (1, 0, 0, 0, 0, 0, 0, 26907, 0, 0)

The mesh elements are not optimized for an hydraulic computation code:
image

EDIT: I propably misused triplot (it should be plt.triplot(output_header.x, output_header.y, triangles=output_header.ikle_2d - 1)), the mesh seems OK:
image

Can the attached file be opened with Fudaa-PrePro ?
pyteltools_out_2.zip

@nicogodet
Copy link
Contributor Author

nicogodet commented Apr 11, 2024

Can the attached file be opened with Fudaa-PrePro ?
pyteltools_out_2.zip

It can be opened in both Fudaa and BK but partel still crashes.

I open pyteltools_out_2.slf in FUDAA, export, partel is happy
fudaa_export2.zip

Thank you to look into this.

Indeed, your initial Serafin file input.slf does not seem valid. For example its params are all set to 0.
Most likely caused by lutraconsulting/MDAL#468

@nicogodet
Copy link
Contributor Author

nicogodet commented Apr 11, 2024

Reading the input file: "maillage/pyteltools_out_2.slf" of size 813812 bytes
pyteltools_out_2 params (1, 0, 0, 0, 0, 0, 0, 26907, 0, 0)
pyteltools_out_2 ipobo [0 0 0 ... 0 0 0]
Reading the input file: "maillage/FUDAA_export2.ser" of size 1031988 bytes
The 2D variable name "X" is not known (lang=fr). The complete name will be used as ID
The 2D variable name "Y" is not known (lang=fr). The complete name will be used as ID
FUDAA_export2 params (1, 0, 0, 0, 0, 0, 0, 0, 0, 1)
FUDAA_export2 ipobo [124 123 125 ...   0   0   0]

Indeed IPOBO is wrong

@nicogodet
Copy link
Contributor Author

Adding output_header.build_ipobo() fixes the issue even without output_header.build_params().
Initial issue is not related to PyTelTools then, I'm sorry for the noise

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

No branches or pull requests

2 participants