-
Notifications
You must be signed in to change notification settings - Fork 18
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
Failing to read real numbers in the xml files in certain regional configurations #124
Comments
Hi @ecasglez, Thanks for reporting this! It's not something we've run into yet. I'm trying to figure out how tied to QT this problem is vs. it being something we can configure in OpenMC's Python API. Does the following work for you in the same environment? $ python -c "import openmc; openmc.Materials.from_xml()" |
Actually, scratch that. The plotter no longer reads XML files using the Python interface. It reads them using the I'll take a look at how to set the locale for the application via QT. |
Can you try this branch of the plotter out to see if it fixes this problem, @ecasglez? |
I think it is still happening. I am not sure if I missed something. You can reproduce it with the test input of this repository:
I will try your changes again later. |
Hrmm that's not causing an error for me.. I'll try to reproduce this another way maybe. |
This should be fixed by openmc-dev/openmc#2574. @ecasglez if you're able to try out the |
It is still happening. When I run openmc-plotter it is using the right develop openmc:
However, if I just run openmc it runs well. I will have a deeper loop on Friday. |
Thanks for trying this again @ecasglez. I was thinking yesterday that it's strange for it to work with the executable but not the plotter as both OpenMC initializations should be relying on the same compiled library. A couple of questions:
|
First, I removed the folder of my previous openmc installation which was /opt/openmc_0.13 and I also typed:
Then I compiled from sources the develop branch following the instructions here but swiching to the develop branch before compilation typing:
It is actually getting the develop branch since it is writing I think QT is somehow forcing the decimal numbers to follow my regional configuration. When running openmc standalone I think no QT libraries are loaded, so there is no problem when reading the numbers. |
Thanks for specifying! That all sounds good to me. Always good to double-check though. A sound theory about the QT libraries. Not something we've encountered before. I'll try to dig into it further soon. When you tried the experimental plotter branch linked above, you reinstalled the plotter in a similar manner? |
Ok. I found it! It is related to this issue in the pugixml parser: zeux/pugixml#469. I am not sure if they are going to fix this in the upstring xml parser. In the mean time, the following patch for OpenMC solves it. I've tried it in the develop branch of OpenMC. diff --git a/src/initialize.cpp b/src/initialize.cpp
index d667f4b03..a8990d7b5 100644
--- a/src/initialize.cpp
+++ b/src/initialize.cpp
@@ -43,6 +43,14 @@ int openmc_init(int argc, char* argv[], const void* intracomm)
{
using namespace openmc;
+ // This fixes parsing the xml files when running openmc-plotter in regions
+ // where the decimal separator is , insted of .
+ // This is an issue of the upstream xml parser pugixml.
+ // See https://github.com/zeux/pugixml/issues/469
+ if (std::setlocale(LC_ALL, "C") == NULL) {
+ fatal_error("Cannot set local to C.");
+ }
+
#ifdef OPENMC_MPI
// Check if intracomm was passed
MPI_Comm comm; |
Nice detective work and I'm glad it's working for you. Would you be up for submitting a PR for this? |
My xml files contain real numbers written using "." as decimal separator, which is the standard when dealing with programming lenguages.
However, my QT installation is configured to use "," as decimal separator, which is the default when using Spanish regional configuration. When I run openmc-plotter I get this error:
But the density of my material 100 is positive: 0.9965 g/cm3. Since the plotter is trying to read that number using Spanish locales, it stops at the "." and reads only the 0, showing that error.
In order to make it run, I have to execute openmc-plotter like this:
This way the numeric format is forced to be the en_US one, that is, using "." as decimal separator.
I tested it on Kubuntu 22.04. The xml files were created in the same machine using Spyder and Openmc, and they were written with "." automatically.
This only affects openmc-plotter, running openmc with those xml files works well without any change.
Openmc-plotter should be forced to always read files using en_US configuration.
The text was updated successfully, but these errors were encountered: