MoDeNa-EUProject / MoDeNa

Software Framework for MOdelling of morphology DEvelopment of micro- and NAnostructures (MoDeNa)
17 stars 19 forks source link

Implement index set inputs to backward mapping model #51

Closed japaf closed 8 years ago

japaf commented 8 years ago

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.

henrus commented 8 years ago

@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 8 years ago

@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.

henrus commented 8 years ago

I think we should be in business now.

japaf commented 8 years ago

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 8 years ago

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

henrus commented 8 years ago

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

japaf commented 8 years ago

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.

henrus commented 8 years ago

I am on d07393 and degas bombs out in physicalProperties.f90 line 166: if (diffModel(1)==1) then do2Modena = modena_model_new (& cchar"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 8 years ago

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.

henrus commented 8 years ago

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 8 years ago

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:

@sum(x) != 1:

henrus commented 8 years ago

@Speed-Up: Please ;-)

japaf commented 8 years ago

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

henrus commented 8 years ago

All merged into nextRelease.

japaf commented 8 years ago

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