CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [Tutorials] Coupling Dakota and OpenFOAM - Tutorial (https://www.cfd-online.com/Forums/openfoam-community-contributions/169972-coupling-dakota-openfoam-tutorial.html)

Tobi April 20, 2016 19:03

Coupling Dakota and OpenFOAM - Tutorial
 
1 Attachment(s)
Dear all,

today I published a tutorial that couples OpenFOAM and Dakota based on the Tesla's One-Way-Valve case that I published last week. The tutorial has a run script that will guide you through each step that is necessary to couple dakota and openfoam.

The target or object function is the ratio between the flux in working and reverse direction of the one-way-valve. Therefore we need a respond function that could be minimized. In that case it is simple (( | 3 - ratio | )). The flux is dependend on the pressure drop that is applied between inlet and outlet and therefore the variable parameter is the pressure at the inlet. The case is working with the gradient based method mentioned by Fletcher & Reeves.

The tutorial should only demonstrate how to combine both software packages, so please do not ask about the meaning of the case (: anyway I think its very clear and understandable.

The case can be found on my homepage www.holzmann-cfd.com

http://www.cfd-online.com/Forums/att...1&d=1461193009

I hope it could help someone. Feedback is always welcomed.

nsf April 30, 2016 08:57

Hi,

Really nice tutorial. Just a week before you posted this I showed OpenFOAM for a group of colleagues and had prepared something similar. If you are interested I can clean up the case and post it here.

I did multidimensional parameter study and set dakota up so it store each run i a separate directory.

I saw this in your your dakota.sh
Code:

    # Remove time directorys (reg expression would be nicer)
    #---------------------------------------------------------------------------
    rm -rf 1* 2* 3* 4* 5* 6* 7* 8* 9*

So I thought I'd show post back and let you know how I would set up the regular expression:

Code:

rm -rf [0-9]*
Now for that to work you would first have to rename the 0.org folder to org0. Other wise one could do this

Code:

rm -rf 0.[0-9]* [1-9]* 0
Best Regards
Nicolas

Tobi May 1, 2016 15:06

Hey Nikolas,

thanks for the replay. The regular expressions are familiar for me but I did not want to do it here due to the fact that (maybe) non-familiar people are using this ;)

I will change it in the new tutorials (:

If you want, you can change your case and I will upload it too (of course within your name). For my Ph.D. I also do multidimension analysis, but the main focus is only in coupling.

Anyway Dakota is very powerful and could be changed to a lot of studies.

nsf May 2, 2016 15:06

1 Attachment(s)
Quote:

Originally Posted by Tobi (Post 597552)
Hey Nikolas,

thanks for the replay. The regular expressions are familiar for me but I did not want to do it here due to the fact that (maybe) non-familiar people are using this ;)

I will change it in the new tutorials (:

If you want, you can change your case and I will upload it too (of course within your name). For my Ph.D. I also do multidimension analysis, but the main focus is only in coupling.

Anyway Dakota is very powerful and could be changed to a lot of studies.

Hi,

I've made some preliminary clean up. In my mind running the case is crystal clear but I've realized that my mind is not the real world so it might not "just work". The case should be attached. You are very welcome to publish it (or throw it in the trash if you don't like it).

Yes, I agree dakota is really powerful. I've seen that it already has a method for Richardson extrapolation. I haven't tried it but perhaps really should.

What I find lacking in dakota though, is a good way to postprocess the results. For an optimization this might not be very important but for a sensitivity study it would be. I'm very new to dakota so if I missed something obvious don't shoot me. The first tool that comes to mind is Excels pivot table.

Best Regards
Nicolas

Tobi May 2, 2016 15:19

Quote:

Originally Posted by nsf (Post 597747)
Hi,

I've made some preliminary clean up. In my mind running the case is crystal clear but I've realized that my mind is not the real world so it might not "just work". The case should be attached. You are very welcome to publish it (or throw it in the trash if you don't like it).

Yes, I agree dakota is really powerful. I've seen that it already has a method for Richardson extrapolation. I haven't tried it but perhaps really should.

What I find lacking in dakota though, is a good way to postprocess the results. For an optimization this might not be very important but for a sensitivity study it would be. I'm very new to dakota so if I missed something obvious don't shoot me. The first tool that comes to mind is Excels pivot table.

Best Regards
Nicolas

Hi Nicolas,

I think each tutorial that can be published in one close place is worth to publish (:
I will definitely upload it with the remark that this is from you and add this to the dakota site of the openfoamwiki.

But it will take a few time. I think the weekend in two weeks is reserved for doing that :)

Many thanks for your share and the open-source thought!

nsf May 3, 2016 14:27

That's sounds great!

Let me know if I should change anything.

Best Regards
Nicolas

Tobi May 9, 2016 15:08

Dear Nicolas,

nice Dakota tutorial but for a beginner a bit hard with all the scripts. Just one question: can you simplify it in a way like I did it? Otherwise I will do it if I find time (:

Thanks for sharing // which FOAM version should be used?

nsf May 9, 2016 16:44

1 Attachment(s)
Hi,

You have a fair point! I had a pre script which only ran once in the templatedir because I thought it more efficient but come to think of it; meshing takes about 1s and running the case takes about 20 s...

I've combined most of the scripts. I now use two, Allrun (for running dakota) and templatecase/runcase which creates the mesh, runs deprepro, runs interFoam and postprocesses. Then there are clean scripts as well.

I've attached the new case Attachment 47349. I've used OpenFOAM-3.0.x. You are more than welcome to add comments of your own.

Best Regards
Nicolas

popstar0426 October 17, 2016 11:13

Dear Nicolas:

Thank you for sharing your case dakota-mulitparamstudy.tar.gz.
I am runing it. However, it is quit slow.
May I run it in parallel?
How do I run it parallel?

I tried to compile dakota in parallel with MPICH2.
I selected "DAKOTA_HAVE_MPI" option in ccmake step.
However, there was an error on the step of "make install".
It seems "DAKOTA_HAVE_MPI" conflicts with "DAKOTA_ENABLE_TESTS".
Because I deselected "DAKOTA_ENABLE_TESTS" and selected "DAKOTA_HAVE_MPI" ON, "make install" step is OK.

Best regards!:)


Quote:

Originally Posted by nsf (Post 597747)
Hi,

I've made some preliminary clean up. In my mind running the case is crystal clear but I've realized that my mind is not the real world so it might not "just work". The case should be attached. You are very welcome to publish it (or throw it in the trash if you don't like it).

Yes, I agree dakota is really powerful. I've seen that it already has a method for Richardson extrapolation. I haven't tried it but perhaps really should.

What I find lacking in dakota though, is a good way to postprocess the results. For an optimization this might not be very important but for a sensitivity study it would be. I'm very new to dakota so if I missed something obvious don't shoot me. The first tool that comes to mind is Excels pivot table.

Best Regards
Nicolas


nsf October 17, 2016 15:49

Quote:

Originally Posted by popstar0426 (Post 621801)
Dear Nicolas:

Thank you for sharing your case dakota-mulitparamstudy.tar.gz.
I am runing it. However, it is quit slow.
May I run it in parallel?
How do I run it parallel?

I tried to compile dakota in parallel with MPICH2.
I selected "DAKOTA_HAVE_MPI" option in ccmake step.
However, there was an error on the step of "make install".
It seems "DAKOTA_HAVE_MPI" conflicts with "DAKOTA_ENABLE_TESTS".
Because I deselected "DAKOTA_ENABLE_TESTS" and selected "DAKOTA_HAVE_MPI" ON, "make install" step is OK.

Best regards!:)

Hi,

I've actually only setup dakota and openfoam once as a proof of concept for colleagues. I've never actually ran it in parallel but here are my guesses.

I don't think you need to compile dakota with mpi for it to run parallel openfoam simulations. You do need mpi support for dakota to run in parallel. Does that make sense?

There are different modes of using dakota. The way I set it up was the simplest way, just have dakota run a script which fires of your simulation and waits for the simulation to finish. It expects the result in a text file on disk. This way dakota has no clue if the script actually ran in serial, parallel or submitted the job to a queue system on a super computer. For this you would have to change the script "dakota-multiparamstudy/templatecase/runcase" accordingly.

The next way is to have dakota fire of the varies permutations of your simulation asynchronously. For a parameter study there is no real need to wait for simulation A to finish before starting simulation B we can just start them simultaneously. I don't think this requires mpi support either. For this case you would have to uncomment line 26 in file "dakota.in".

The only reason, as I understand, to use dakota with mpi is if you couple it with you're own software on code level, i.e. using dakota as a library. You would have to check the manual for this as I have no clue on how to do this.

I haven't tried either of above methods. Please let me know if you give it a try.

Best Regards
Nicolas

lebc August 31, 2017 16:36

Hi guys,

This will probably be out of topic, but as we don't have a Dakota topic, there it goes!

I have already coupled OF4.1 with Dakota 6.5, it is running ok. My problem is: I have to optimize the distribution of source terms over a 2D domain, but Dakota suggests more than one source term located on the same point (by doing this, the source term bugs and duplicates its effects).

One of the restrictions of my problem is the distance between every source term, it has a minimum value, but until now I was not able to implement it.

As an example, for 2 source terms (4 variables)

Quote:

variables
continuous_design = 4
cdv_initial_point 200 200 200 800
cdv_lower_bounds 200 200 200 200
cdv_upper_bounds 800 800 800 800
cdv_descriptor 'x1' 'y1' 'x2' 'y2'
the restriction should be (x1-x2)² + (y1-y2)² > Some value

I have already checked lots of documentations from Dakota, but didn't find it.

Best Regards,
Luis

nsf September 1, 2017 03:54

Quote:

Originally Posted by lebc (Post 662652)
Hi guys,

This will probably be out of topic, but as we don't have a Dakota topic, there it goes!

I have already coupled OF4.1 with Dakota 6.5, it is running ok. My problem is: I have to optimize the distribution of source terms over a 2D domain, but Dakota suggests more than one source term located on the same point (by doing this, the source term bugs and duplicates its effects).

One of the restrictions of my problem is the distance between every source term, it has a minimum value, but until now I was not able to implement it.

As an example, for 2 source terms (4 variables)

the restriction should be (x1-x2)² + (y1-y2)² > Some value

I have already checked lots of documentations from Dakota, but didn't find it.

Best Regards,
Luis

Hi Luis,

I'm glad to hear that someone is using Dakota with OpenFoam. I haven't worked more with Dakota so I'm not really up to speed. But I do remember the Dakota manual mentioning non linear constraints. You could check that out.

There is also a workaround. Just let one of your "pre simulation" scripts check the distances. If it's to close just set whatever metric you are optimizing to a high value. You don't even have to run the simulation!

Good luck
Best regards
Nicolas

lebc September 1, 2017 10:08

Hi Nicolas,

Thank you for the answer!

I using Dakota on my MsC, it has only one week I'm using it (it was actually a surprise that things worked so fast with OpenFoam!)

Some hours after posting this thread I thought something like you suggested, this is probably the fastest workaround, maybe I can write a python script that reads params.in and check the distance before the simulation.

I also saw about the non linear constraints, but I didn't find much information or a way to make something like what I need.

On the next week I'll be testing it, I will post the solution here in case I succeed!

Best Regards,
Luis

lebc September 17, 2017 21:45

Hi Nicolas,

Finally I have followed your suggestion, it works, but not exactly as I wanted to...

As I'm working with a maximization problem, every time the minimum distance is not respected I put 0 for the objective function. The problem of doing this is that it takes a long time for Dakota to find a configuration that respects this outside constrain, and sometimes I end the optimization with just a few individuals on my population (I'm using genetic algorithm - SOGA).

For example, if I set the population = 30, after about 300 evaluations my population have only 3~4 individuals, and maybe I will end up on a local optimum point...

In order to overcome this I thought about using my own initial population that already respected this constraint via a python ode that creates it, but Dakota seems to mess my input file and I can't use this method.

If there is anyone that could help me on any of the mentioned problems I would be really thankful!!!

Regards,
Luis


All times are GMT -4. The time now is 01:23.