-
Notifications
You must be signed in to change notification settings - Fork 3
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
Parsing exception of phaseProperties file #166
Comments
@vpmapelli Thanks! It ended up being necessary to disambiguate between Should be fixed in the current release (v0.4.1). Thanks again for the bug report. |
Thanks for the patch, @gerlero ! Tested again with now with version v0.4.2, but I am still getting an error with this same dictionary. Here is the message error:
Inspecting line number, the error occurs in the following key:
|
Thanks! Interesting. TBH I'm not sure how foamlib should parse this:
Is this supposed to be a dict with a list as a keyword? Or should |
I think that considering "(water and mercury)" as a keyword is more reasonable, as well. This type of syntax is used for defining behavior of pair phases, so I tend to see this as the key for the dictionary. Just to remind, there is also ordered pair configurations, with a syntax "(phase1 in phase2)", but I guess that considering them as a str key should cover this use case, as well. TBH, I would prefer if surfaceTension itself would be a dictionary, but OpenFOAM sees it as a list of pair phase configs, so, not much to do about this matter. |
@vpmapelli Thanks! If a str keyword is reasonable, then I'm hoping #170 fixes it. You're welcome to test the new changes (I'll make a new release as soon as CI passes on that PR). |
FWIW, from foamlib import FoamFile
FoamFile("phaseProperties").as_dict() now outputs:
|
@vpmapelli v0.4.3 is now out. I ended up having to restrict the valid characters in |
It works as expected now! Thank you for this fix. |
FWIW, in #287 I'm experimenting with changing the way we parse these lists of keyword entries, in two ways:
Behavior similar to the previous can be recovered by doing @vpmapelli If you're still using this functionality and want to comment, I'm open to hearing your opinion. I'm not 100% sold on this new way of parsing these, but I'm leaning toward doing the change for v0.8.0 of foamlib. |
@gerlero , thanks for the heads up! Those changes sound reasonable and I would say they are more consistent regarding parsing of entries between parenthesis. If I got it right, some code that would be written as: from foamlib import FoamFile
phase_properties = FoamFile("phaseProperties").as_dict()
print(phase_properties['surfaceTension'][0]['(air and water)']) would turn into: from foamlib import FoamFile
phase_properties = FoamFile("phaseProperties").as_dict()
print(phase_properties['surfaceTension'][0][1]) If that is the case, changing the list-like keyword to a number would have some impact on user-code in favor of library consistency. Is this going to affect all entries of a OpenFOAM dictionary or only lists of keyword entries? As a matter of fact, this is somewhat closer to how PyFoam parses these kind of entries, but I would prefer this kind of parsing, as PyFoam does not create a list of 2-tuples, but a single list of len(2n), where i-th element is a list em 2i-th a dictionary. From the point of view of code layering, I can undestand that replicating PhasePair hashing from OpenFOAM should be implemented by user code from the list parsed form the list-like keyword. But, for my use case, for example, just for some fast case manipulations, I'd say it would not have that much impact. To be fair, I am in no place to give my opinion, since I used this library in an early version for manipulating some simple cases. I am still monitoring, though, some libraries to handle OpenFOAM cases and haven't adopted one definetly yet. But, personally, I actually still prefer the list of dicts parsing as I cannot see a strong positive benefit of this change. But I guess that as a user, I am probably missing something such better consistency on library code or performance-wise issues. |
That's right!
Only lists of keyword entries.
Yeah, I don't like how PyFoam does it either, so I wouldn't go that way. Honestly, I believe PyFoam's way is an accident of how they parse their list entries and not really carefully thought out for this scenario.
Anyway, thanks for chiming in on this one! I'll consider your opinion no matter which way I choose to go. |
Hello, I've tried using this library to manipulate some multiphase cases, but I had some problems. I am sending the minimal case to replicate it.
System: Ubuntu 24.04
Python: 3.10.14
foamlib: 0.4.0
foamversion: OpenFOAM-9
Minimal code to replicate the error:
Error message:
It seems that some structures of this specific files has not been treated by parsing rules. By the message, it seems that this specific line is troublesome
I hope this issue helps to improve the library :)
Let me know if any further piece of information is needed. Thank you.
The text was updated successfully, but these errors were encountered: