Skip to content

Conversation

alexandre2946
Copy link

@alexandre2946 alexandre2946 commented Apr 16, 2025

Replace the LecFicDiffuse_JDD with a new DataFile parser/preprocessor.

The goal of this change is to provide more flexibility in data files, while providing better user feedback when an error occure.
The way it work is by parsing a first time the data file, do some action on it and feed to the interpreters a regular string (similar to the current LecFicDiffuse_JDD procedure).

This parser add the following functionality:

  • One line comment using the '//' syntax.
  • Add #define and #include macros to define constants and include other files in data files (more flexible the Lire_Fichier has #include can be use in a list of initial condition for example).
  • Precompute constant with expressions. Combining this with the #define macro, its possible to do basic math in the data file. Supported functions are sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, ln, log10, sqrt, rand(om), abs, sign, int (convert to int), float (convert to float). max and min are implemented has a binary operator as two variables functions are not implemented. The parser throw error when undefinied result are accounter (like 0-division, function invalid domain, 0^0 undefinied result).
  • Clearer error message with the .data file line underlined in the message.
  • Allow to write expressions using spaces, line feed, tabs… in it).
  • Operators in math expressions are not limited to one character nor required to use the OPERATOR syntax (like LE, GE…). For example, the expressions
                1.4-1.3908*(y]1)*(y[3)
                4*((16/Re)$(0.079/(Re^0.25))$0.003)

becomes

               (1.4 - 1.3908 * (y>=1) * (y<=3))
               (4*((16/Re) max (0.079 / (Re^0.25)) max 0.003))
  • Check expression validity and provide error message for various syntax error (See the Incorrect_syntax reference test for examples).
  • Errors messages are only colored when stdout (resp. stderr) is not redirected to a file to avoid noisy output files. The redirection dependent coloring is provided by the methods in the TextFormatting namespace from TextFormatting.cpp.

Limitations:

  • Expressions required surrounding parenthesis to be correctly parsed (other space separated numeric values with unary ± operator are ambiguous). A small hack is implemented to make most previous non-parenthesis-surrounded expressions still works, but it does not work every time.
  • Names cannot start with '.' so path cannot be written "./my_folder/my_file" (writing just "my_folder/my_file" still works).
    For those reasons, a bunch of reference test cases had to be modified to match this parser syntax.

I've suppress the LecFicDiffuse_JDD and EChaineJDD source code, and added DataFile, DataFileToken and DataFileExpression files.
Some change has also be made to Lire_Fichier to make it work with the new read tracker system. I also add a method to read one single character from an Entree object.
This implementation creates quite a few copy of strings and list, but make it more efficient on those aspects would generate quite a lot of unecessary complexity as data files do not contains millions of tokens.
Tests Incorrect_syntax and Macro have been added to check if the syntax error catching system works and to demonstrate the macro usage.

I've tried to catch all the possible invalid input a user could write, but I'm not 100% sure to have catch them all.

A few examples:
image
image
Capture d’écran du 2025-04-17 00-41-45

@abruneton
Copy link
Member

Hi Alexandre

Thank you very much for this significant work, this is very impressive, and very much appreciated.

As we already briefly discussed during the training session in Saclay, TRUST is a big baby, with a lot of other projects depending on it (including some industrial codes).

We are completely open to discuss major changes like this, but this needs to be coordinated and discussed with the core developpers' team to decide together what is the best approach.

Discussion to follow by PM.
Thanks !

@alexandre2946 alexandre2946 force-pushed the new_data_file_parser branch from 4bea8e3 to 81b7750 Compare June 18, 2025 13:47
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

Successfully merging this pull request may close these issues.

2 participants