CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Using Octave/MatLab functions to set border conditions?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Logan Page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 1, 2011, 08:30
Default Using Octave/MatLab functions to set border conditions?
  #1
New Member
 
Join Date: Jun 2011
Posts: 12
Rep Power: 14
homerun4711 is on a distinguished road
Hello!

I have a question and hope that you can help me.

My company is searching for a software to calculate heat flux
through a concrete wall of a tower due to solar radiation.
(will be 2D-model in the first case)

We were doing one such calculation before using Autodesk Multiphysics (Algor).
But since there is no possibility to automate data in- and output and do other scripting stuff
we have to switch to another software or I will go crazy because of all that repetitive GUI clicking

While searching for different software packages to compare
OpenFOAM caught my eye, because it looks quite complete and is open source.

In our problem the solar radiation and ambient temperature are used as border conditions
and we have Octave/MatLab functions that return these values.

Is it possible and easy to use these returned values as input for OpenFOAM?

Pseudo-code maybe would be
-----
include "octave.h" or
include "matlab.h"
border_condition_wall(time) = MATLABFUNCTION.solarirradiation(time, date, weather, airmass)
-----

Kind regards,
Walter
homerun4711 is offline   Reply With Quote

Old   June 1, 2011, 09:38
Default
  #2
Member
 
alexey2petrov's Avatar
 
Alexey
Join Date: Feb 2010
Posts: 33
Blog Entries: 1
Rep Power: 17
alexey2petrov is on a distinguished road
Hi Walter!

Quote:
Originally Posted by homerun4711 View Post
we have to switch to another software or I will go crazy because of all that repetitive GUI clicking
Might be pythonFlu - "a Python wrapping for OpenFOAM C++ API" - could suite you even better?

First, pythonFlu initially comes with the automation capabilities you are looking for (you can easily bind corresponding pythonFlu based code with your specific application, look).

Second, Python has a lot of libraries that could easily satisfy all your "Matlab / Octave like" needs (NumPy and SciPy, for example).

And, might be, the third, there is a living example who uses pythonFlu in the way you are interested in.

Best regards,
Alexey
alexey2petrov is offline   Reply With Quote

Old   June 2, 2011, 04:02
Default
  #3
New Member
 
Join Date: Jun 2011
Posts: 12
Rep Power: 14
homerun4711 is on a distinguished road
Hi!

Thanks for your answer. pythonFlu looks quite interesting. I also read a presentation about pyFoam. What is the difference between the two?

But since I usually write C++ code I would rather use it instead of Python to glue OpenFOAM to Octave/MatLab. Has someone of you ever done this and can show me a small piece of code how this could be done?

Kind regards,
Walter
homerun4711 is offline   Reply With Quote

Old   June 2, 2011, 09:42
Default
  #4
Member
 
alexey2petrov's Avatar
 
Alexey
Join Date: Feb 2010
Posts: 33
Blog Entries: 1
Rep Power: 17
alexey2petrov is on a distinguished road
Hi Walter,

Quote:
Originally Posted by homerun4711 View Post
pythonFlu looks quite interesting. I also read a presentation about PyFoam. What is the difference between the two?
Well, I will try demonstrate their difference on the following examples.

You said, that Octave so suitable for you, that you are going to invest your time and energy for embedding it into the target C++ solver.
Now, imagine, that the OpenFOAM solver itself could be written completely in Octave. Would you still like to implement your solver in C++?
And this is the pythonFlu case - "solver as any other user specific code could be written and communicated directly in Python without any loss in clarity and performance"

Also, imagine, you need to add some automation features in your OpenFOAM calculation environment. Something like, parameter variation, conditional running and so on. As we know, Octave will come first in your mind (you are going to use it at any case). Ok, then you decide to implement such stuff through Octave - that is PyFoam case. I mean, that you still have two different beasts - C++, for solver implementation and Python, for its automation.

Quote:
Originally Posted by homerun4711 View Post
But since I usually write C++ code I would rather use it instead of Python to glue OpenFOAM to Octave/MatLab. Has someone of you ever done this and can show me a small piece of code how this could be done?
I have googled a little bit and find something you might be looking for -"GNU Octave for C++: How to start?"

By the way, while I were trying to find out the proper answer on your last question I have bumped on the list of the existing Octave front-ends, namely Perl, Tcl and Java. I started to wonder, why there is no Python among them? Actually, I have found Pytave, but it seems has been abandoned long ago (the latest modifications were done at 2008). So, I started to wonder once again, why?! The answer was actually straightforward -
Existing NumPy and SciPy libraries cover all aspects of Octave functionality and made it no sense to invent any Python Octave front-end at all
So, if you would like to use something as flexible as Octave, but are going to base your solver implementation on OpenFOAM ... you know the right solution

Best regards,
Alexey

Last edited by alexey2petrov; June 2, 2011 at 10:11.
alexey2petrov is offline   Reply With Quote

Old   June 2, 2011, 18:26
Default
  #5
New Member
 
Join Date: Jun 2011
Posts: 12
Rep Power: 14
homerun4711 is on a distinguished road
Hi!

Thanks for the explanation, I get the difference now

pythonFlu seems to be a good solution for some situations,
but I am still not convinced...
And since we need this in our company for important calculations
I would rather stick to the well-known and mature OpenFOAM
and our working Octave-functions.

Well, until now there is no answer from people that could give some lines
of C++ code showing how difficult or easy it is to glue OpenFOAM to MatLab
or Octave. Maybe my question is not clear enough...

I need to set transient border conditions, and in the end I do not
care about how these are set, I just do not want to do it manually
And I do not want to completly rewrite a solver until implementing
transient border conditions is a really really easy job. Is it?

My idea was just to call a MatLab-function from a C++ program,
which is quite an easy job to do. But is it easy to put the
returned values into into the solver? Or is this not
possible at all?

I read about the possibility to use

---
type timeVaryingUniformFixedValue;
timeDataFileName "inlet.dat";
---

to use transient border conditions. Well, this seems to be quite easy.
So I got an idea and please tell me if this is completly nonsense:

I have to set border conditions on the outside of a 2D-circle.
This simulates sunshine onto the tower. The circle has to be
discretized. So I will subdivide it into 1° pieces. Each of
this subdividions will receive different and transient border
conditions.

To achieve this I will use Octave and OpenFOAM separatly.
An Octave function will write the mesh-file using for-loops creating
the 360 Physical Surfaces and assign their names, e.g. Face001 - Face360.
I am not familiar with blockMesh's file format, but thinking of gmsh's
syntax seems this is quite an easy job.

And the Octave function calls the sun-position-function and writes the
results to 360 different text files,e.g."Face001.dat" that are called
by that are called by using

---
type timeVaryingUniformFixedValue;
timeDataFileName "Face001.dat";
....
type timeVaryingUniformFixedValue;
timeDataFileName "Face002.dat";
---

and so on...

Well, I need a second opinion - does this sound like complete nonsense???
Or is it easier to glue OpenFOAM to MatLab/Octave directly?

Kind regards,
Walter
homerun4711 is offline   Reply With Quote

Old   June 4, 2011, 08:57
Default
  #6
Member
 
Logan Page
Join Date: Sep 2010
Posts: 38
Rep Power: 15
Logan Page is on a distinguished road
Hi

Im not sure if this will help at all, but here goes.

My programming skills in anything other than octave is limited at best, and thus I've opted to use octave scripts to do the following for me:

1) update gmsh geometry file
2) call gmsh to create mesh
3) call convert mesh to OpenFOAM
4) update velocity boundary conditions
5) call OpenFOAM to solve case
6) read cost function value/s into optimisation script
7) optimise geometry variables
8) loop from 1

This doesnt really "glue" octave and OpenFOAM together, but rather uses OpenFOAM as a tool inside octave. I wont even begin to claim that this is a good way to do things, but its the best I could come up with.
Ladan.s likes this.
Logan Page is offline   Reply With Quote

Old   June 5, 2011, 02:38
Default
  #7
New Member
 
Join Date: Jun 2011
Posts: 12
Rep Power: 14
homerun4711 is on a distinguished road
Hi!

This sounds quite good from my point of view since it looks
like you used octave to script all the way from automated mesh
creation to solving the case.
And since for my case I need about 360 faces to form a circle,
each of them having different BCs, scripting sounds great.

So, if you do not mind, I would really like to see some scripts
you wrote

Kind regards,
Walter
homerun4711 is offline   Reply With Quote

Old   June 5, 2011, 07:26
Default
  #8
Member
 
Logan Page
Join Date: Sep 2010
Posts: 38
Rep Power: 15
Logan Page is on a distinguished road
Hi Walter

No problem. Send me your email address and we can discuss further.

Regards
Logan
Logan Page is offline   Reply With Quote

Old   June 5, 2011, 16:47
Default
  #9
Senior Member
 
Elvis
Join Date: Mar 2009
Location: Sindelfingen, Germany
Posts: 620
Blog Entries: 6
Rep Power: 24
elvis will become famous soon enough
If you want to do optimisation many consulting companies (ICON, Engys, etc.) use DAKOTA http://dakota.sandia.gov/software.html

Read the post by Paolo Geremia http://www.extend-project.de/compone...=6&start=6#187
(to read you have to register)

Last edited by elvis; June 7, 2011 at 02:23.
elvis is offline   Reply With Quote

Old   June 5, 2011, 16:59
Default
  #10
Member
 
Logan Page
Join Date: Sep 2010
Posts: 38
Rep Power: 15
Logan Page is on a distinguished road
Thanks for the info. It is useful to know.

For now I will be sticking to an optimisation algorithm developed at the university (DYNAMIC-Q), If I dont come right I'll look at this as an alternative.

Regards
Logan Page is offline   Reply With Quote

Old   June 20, 2011, 06:29
Default
  #11
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Quote:
Originally Posted by Logan Page View Post
Hi

Im not sure if this will help at all, but here goes.

My programming skills in anything other than octave is limited at best, and thus I've opted to use octave scripts to do the following for me:

1) update gmsh geometry file
2) call gmsh to create mesh
3) call convert mesh to OpenFOAM
4) update velocity boundary conditions
5) call OpenFOAM to solve case
6) read cost function value/s into optimisation script
7) optimise geometry variables
8) loop from 1

This doesnt really "glue" octave and OpenFOAM together, but rather uses OpenFOAM as a tool inside octave. I wont even begin to claim that this is a good way to do things, but its the best I could come up with.
Walter,

Of course you can do that easier with pythonFlu !
Cheers

Francois
francois is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot set boundary conditions in Pointwise filipwa Pointwise & Gridgen 5 November 29, 2010 16:11
Cannot set boundary conditions in Poitwise filipwa Pointwise & Gridgen 0 November 10, 2010 05:20
How to set the inflow conditions of turbulent BL? CFDer Main CFD Forum 2 March 8, 2006 09:05
Level set & distance functions Renato. Main CFD Forum 7 February 7, 2006 06:46
A problem about setting boundary conditions lyang Main CFD Forum 0 September 19, 1999 18:29


All times are GMT -4. The time now is 21:08.