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

coupling OpenFOAM with other programs

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 26, 2009, 11:30
Default coupling OpenFOAM with other programs
  #1
New Member
 
Martin Tek
Join Date: May 2009
Posts: 7
Rep Power: 16
Martin123 is on a distinguished road
Hi,

I am Martin and new to OpenFOAM. I want to solve the Laplace-Equation
grad(k(x)*grad u(x))=0 with OpenFOAM and interconnect k(x) with data coming from outside.

Is there any possibility to read in and write out dynamically on run-time the k(x) values into a VolScalarField (I'd guess) ? And to access maybe the nearest node for a given coordinate? Or at least to iterate over all nodes, get the coordinates and get/set k(x)?

Any help is appreciated.

Martin
Martin123 is offline   Reply With Quote

Old   May 28, 2009, 21:02
Default
  #2
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18
henrik is on a distinguished road
Dear Martin,

the bottom line is that you can do anything because you have the source code. If you have the source code for the other code, then merging the two codes into a single executable is easier & faster than file IO while avoiding syncronisation problems. However, this is major surgery and you need to know what you are doing. Concerning your questions:

@reading

I would simply create a (temporary) field from an IOobject. Look at any createField.H and place the code inside of the time loop.

However, field.read() should work, too.

@writing:

field.write();

@finding cell numbers:

Code:
vector pos;
label cellI = mesh.findCell(pos);
Info << field[cellI] << endl;
@iterate cell centers:

Code:
forAll(mesh.C(), cellI)
{
    vector pos;
    if ( mag(mesh.C()[cellI] - pos) < SMALL)
    {
        field[cellI] = newValue;
    }
}
Hope this helps.

Henrik
henrik is offline   Reply With Quote

Old   June 2, 2009, 05:26
Default
  #3
New Member
 
Martin Tek
Join Date: May 2009
Posts: 7
Rep Power: 16
Martin123 is on a distinguished road
Dear Henrik,

thank you very much for you help, this is exactly what I was looking for.

I followed your suggestion and created and temporary field during the runtime-loop; unfortunately, OF claims that it cannot read my temporary field

volScalarField epsilon
(
IOobject
(
"epsilon",
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
mesh
);

cannot open file

file: /home/dw9203/projects/ofoprj/cavity/0.005/epsilon at line 0.

From function regIOobject::readStream(const word&)
in file db/regIOobject/regIOobjectRead.C at line 66.

FOAM exiting



But it should however not read from disk, I want to specify the field values during run-time. Could you enlighten this?
Martin123 is offline   Reply With Quote

Old   June 3, 2009, 18:13
Default
  #4
New Member
 
Martin Tek
Join Date: May 2009
Posts: 7
Rep Power: 16
Martin123 is on a distinguished road
Thanks, now it works setting values on run-time. A different constructor for volscalarfield made it and I can set now values during run-time. Great!
Martin123 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
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25
OpenFOAM Debian packaging current status problems and TODOs oseen OpenFOAM Installation 9 August 26, 2007 13:50
OpenFOAM Training and Workshop Zagreb 2628Jan2006 hjasak OpenFOAM 1 February 2, 2006 21:07


All times are GMT -4. The time now is 02:15.