MoDeNa-EUProject/MoDeNa

Implement index set inputs to backward mapping model

Closed this issue · 15 comments

japaf commented

I prepared a test example in my branch gasmix. Initializing the model would be success for now. To run the example do:

cd applications/PUfoam/foamAging
cp example_inputs/inputs.in .
./build
./initModels

Background info:
We are trying to initialize backward mapping model (foamConductivity). It takes composition created by index set as input and uses it (actually the substitute model is using it, but that seems to be working).

The most relevant file is the foamConductivity.py. I think at least two things are needed. First, InitialPoints strategy needs to understand index set inputs. And second, we need a way to query the index set input in the ExactTask.

@strategies & indexSets: Yes, there will be work to do.

@querying indexSets: That's already in place. Please have a look into examples/multicomponentDiffusion/src/fullerEtAlDiffusionTest.C and let me know whether this is good enough. In addition, modena_model_t holds a reference to modena_function_t which we could make accessible through the interface if needed.

Henrik

japaf commented

@querying indexSets: I thought that this part would be easier. I didn't test it because it crashes before it gets to the ExactTask, but I thought something like this would work to obtain the composition for one specie:

xCO2 = self['point']['x[CO2]']

I can access the index set, so I can remove some of the hardcoding later on.

I think we should be in business now.

japaf commented

Very good, I can initialize the model without problem. I updated the macroscopic code. It runs OK until the composition is out of range. It produces following error:

Traceback (most recent call last):
  File "/home/pavel/lib/python2.7/site-packages/modena/SurrogateModel.py", line 867, in exceptionOutOfBounds
    for k, v in self.inputs.iteritems()
  File "/home/pavel/lib/python2.7/site-packages/modena/SurrogateModel.py", line 867, in <dictcomp>
    for k, v in self.inputs.iteritems()
TypeError: list indices must be integers, not NoneType
Error in python catched in 364 of /home/pavel/github/MoDeNa/src/src/model.c
/home/pavel/lib/modena/libmodena.so.1(modena_print_backtrace+0x1f) [0x7f94e8ce9472]
/home/pavel/lib/modena/libmodena.so.1(write_outside_point+0x11d) [0x7f94e8cea664]
/home/pavel/lib/modena/libmodena.so.1(modena_model_call+0x13b) [0x7f94e8cea800]
/home/pavel/github/MoDeNa/applications/PUfoam/Models/foamAging/src/degas(__conductivity_MOD_equcond+0xa8f) [0x42e49f]
/home/pavel/github/MoDeNa/applications/PUfoam/Models/foamAging/src/degas() [0x457c53]
/home/pavel/github/MoDeNa/applications/PUfoam/Models/foamAging/src/degas(_start+0) [0x40411d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f94e810bec5]
/home/pavel/github/MoDeNa/applications/PUfoam/Models/foamAging/src/degas() [0x404146]

I'll submit pull request with my changes.

japaf commented

To clarify, you need to do ./build again and running ./workflow without error is a success.

I got workflow to work this morning. Please merge with 0fcd8d3 and let me know.

japaf commented

Sorry, the workflow you were working with was preliminary stopped just to test gasMixtureConductivity. If you merge #54 the workflow is fixed and calls the foamConductivity. It produces above error when foamConductivity is out of range.

I am on d07393 and degas bombs out in physicalProperties.f90 line 166:
if (diffModel(1)==1) then
do2Modena = modena_model_new (&
c_char_"diffusivityPol[A=O2]"//c_null_char);
do2Inputs = modena_inputs_new (do2Modena);

diffusivityPol[A=O2] is not initialised and the framework cannot auto-initialise since the error handling is missing.

japaf commented

My bad, could you please uncomment line 43 of initModels (import diffusivity). I had the models in my database and I forgot that it was not initializing.

Okay, now it runs for me with 1395d49.

I noticed a problem.

point = {fstrut: 0.583852, x[CyP]: 0.108186, x[Air]: 0.614148, eps: 0.879917, x[CO2]: 0.0240317, T: 276.642, dcell: 0.000503307}

The framework samples randomly and is aware of complex constraints and as you can see sum(x) != 1.

You need rephrase the parameter space such that it can be bounded by min/max. One route is to specify two species and calculate the third. However, x1, x2 = [0; 1] does not ensure sum(x1+x2) < 1. It's therefore possible that you need to pass concentrations + rho.

japaf commented

Hi Henrik,
Now it indeed refits the model when it is out of range. It runs for a very long time but eventually fails with:

tend   25.553240740740740      days
 x[Air] =   0.92676537436200446     
return code = 200
Model out-of-bounds, executing outOfBoundsStrategy.
2015-12-10 13:58:03,856 INFO Task completed: {{modena.Strategy.BackwardMappingScriptTask}} 
2015-12-10 13:58:03,901 INFO Rocket finished
2015-12-10 13:58:03,903 INFO Created new dir /home/pavel/github/MoDeNa/applications/PUfoam/foamAging/launcher_2015-12-10-12-58-03-903130
2015-12-10 13:58:03,903 INFO Launching Rocket
2015-12-10 13:58:03,934 INFO RUNNING fw_id: 40 in directory: /home/pavel/github/MoDeNa/applications/PUfoam/foamAging/launcher_2015-12-10-12-58-03-903130
2015-12-10 13:58:03,934 INFO Task started: {{foamConductivity.foamConductivity.FoamConductivityExactTask}}.
Performing exact simulation (microscopic code recipe)
point = {fstrut: 0.580843, x[CyP]: 0.0499413, x[Air]: 1.11212, eps: 0.836273, x[CO2]: 0.0110876, T: 273.759, dcell: 0.000487015}
Substituted model out-of-bounds, executing outOfBoundsStrategy.

Some explanation:

  • I added writing out the value of x[Air] with which the surrogate model is called (the line x[Air] = 0.92676537436200446)
  • At the time max value of x[Air] is 0.9175463820274484 (I looked to my database), so the outOfBoundsStrategy is executed, but the new point, which is chosen is x[Air]: 1.11212.
  • The substituted model on last line refers to gasMixtureConductivity, which is forward mapping, and thus nothing can be done.
  • After this the code goes to infinite loop of errors and I have to delete the models from database to be able to start it again.
  • This is probably new bug that is not connected to sum(x) != 1.
  • If you want I can artificially speed-up the microscopic code for testing purposes.

@sum(x) != 1:

  • If by rho you mean total concentration, I am not sure that would help. It would just mean that I would have to normalize the composition in slightly different manner.
  • Naturally, I could accept non-normalized molar fractions and just normalize them at the beginning of the surrogate model. The problem with that is that I would most likely extend the validity region of the surrogate model more than I should. I will have to think about it more.

@speed-up: Please ;-)

japaf commented

The code in 1bd46a4 on my gasmix branch should be fast.

All merged into nextRelease.

japaf commented

It works for me so am I am closing it. I'll create new issue for sum(x) != 1 if need be.