OpenFOAM coupling with matlab
1 Attachment(s)
Hello,
I am working on a Sloshing tank 2d simulation problem. Initially, I have used linear motion for simulation and successfully simulated the programme. The next task I am assigned is with two-way coupling with Matlab. I followed a reference work: http://www.tfd.chalmers.se/~hani/kur...D3D_Report.pdf Using this file I have created a matlabPipe.so file which calls Matlab engine.h The basic idea is to extract sloshing force from OpenFOAM at each time step and give these input values to Matlab and the Matlab calculates the displacement using numerical integration and returns back the value to Open foam in terms of displacement (amplitude) values. The description is also given in the flowchart. I understood that the Matlab engine works with a pointer which are 1. Get the pointer 2. Evaluate the pointer 3. Put the pointer 1. Get the pointer. To get the pointer I looked into my SloshingTank2D contolDict file where I used probes function to obtain pressure. This function creates a P file postprocessing folder. Code:
functions 2. Evaluate the pointer: I have my Matlab interpolation code in .m file format in which utility file I can connect it. 3. Put the pointer: The solidBodyMotionFunction provides a utility where the solid body motion can be read from text file. Can I modify tabulated6DoFMotion utility function such that the Matlab writes the files at each time step and FoamSolver reads the file at each time step? I have looked into the tabulated6DoFMotion.H file and tabulated6DoFMotion.C file in which line I should provide the pointer such that Code:
#include "tabulated6DoFMotion.H" |
Hi,
- Would the following help? - https://www.precice.org/ - https://www.openfoam.com/documentati...alCoupled.html |
Quote:
I dont find a good reason for coupling at all! Why don't you just re-implement whatever you are doing in matlab into an OpenFOAM class/library? Coupling codes is certainly more "difficult", from a programming standpoint, specially when you have to interface with commercial codes (MATLAB). BTW, using file pipes as means of coupling data-intensive codes is rather inefficient, slow, prone to IO errors, and you might run with caching/memory issues along the way. What is better to do in this cases is to program a DRIVER, a third program that interact directly with the codes you want to couple. One example of that is preCICE. |
I Thank HPE and Santiago for taking their precious time and reverting back.
I have seen the src files relating to 'spring', 'mass', 'damper' systems, which I can attach to my sloshingTank and run my simulations. But my goal is to derive the equation of motion flutter derivatives using Matlab which I guess would be difficult to frame in OpenFOAM. To do this I am trying to couple the two systems with the basic equation of motion as my first step. With HPE's advice, I am looking into the preCICE. Also, I have one more query. Instead of Matlab can I use Python script as I have seen OpenFOAM env supports pyFOAM. If so how can I add my class/library files in OpenFOAM using python? For example: Here in my case, I have my probes function which calculates pressure to should be taken by python/Matlab and return the values to OpenFOAM in dynamic library dictionary files. If there is some possibility it would be really helpful if someone shares the manual/URL using pyFOAM.:) |
Quote:
https://github.com/muzuka/MassSpringSystem Or you can implement it directly, for instance: http://www.tfd.chalmers.se/~hani/kur...FoamReport.pdf In any case, its just an additional set of ODEs solved over the surface of your airfoil, calculating displacements and rotations: https://perso.limsi.fr/olm/archives/flutter.pdf Which lays in the very reasons as to why OpenFOAM exists. Anyway, you decide whether it's worth to implement it there, or not. Note that your code will be inevitably slowed down by the blocked communications caused by the preCICE driver. If you are doing toy simulations it may not be a problem though... In any case it'd be nice to see the implementation of such coupling. Quote:
|
Hi,
- For data transfer from OpenFOAM, I suggest Ofpp, which is a bliss in my opinion in comparison to PyFoam. Hope this helps. |
All times are GMT -4. The time now is 13:11. |