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

How to write IOField variable particle position

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Display Modes
Old   June 5, 2013, 11:35
Post How to write IOField variable particle position
  #1
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hello,

I am using the solid particle library and have looked at solidParticleFoam. I saw 'positions', 'd' and 'U' in the directory of 'lagragian/defaultCloud' in the tutorial case. I am dealing with thousands of particles, just wondering how could I generate the 'positions' file for the particles?

I think the particle position belongs to IOField<vector>, but how can I determine the positions and write them into a file using OpenFOAM? Any suggestions would be really appreciated.

Thanks a lot in advance.

Best Wishes,
Sophie
sophie_l is offline   Reply With Quote

Old   June 12, 2013, 08:25
Default
  #2
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hello,
To the question above, I defined

Quote:
List<vector> initPositions(n);
where n is the number of particles. Now I want to write it to the file 'positions'. I tried to use the code below.
Quote:
std::fstream positions;
positions.open("positions",std::ios:ut);
However, the file header generated is different from the standard OpenFOAM data file and hence cannot be read in by OpenFOAM.

Here is the file header I generated. On the 3rd to 6th line, '\\' is supposed to be the right format, however only '\' is generated. On the line 'location 0;', "" is not allowed to be in the output.


Quote:
/*--------------------------------*- C++ -*----------------------------------*
| ========= | |
| \ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \ / O peration | Version: 1.7.1 |
| \ / A nd | Web: http://www.OpenFOAM.org |
| \/ M anipulation | |
*---------------------------------------------------------------------------//
FoamFile
{
version 2.0;
format ascii;
class Cloud<solidParticle>;
location 0;
object positions;
}
Does anyone know how to generate a correct file header? Any suggestions are really appreciated.
sophie_l is offline   Reply With Quote

Old   June 13, 2013, 05:52
Default
  #3
Amp
New Member
 
Arun Appadurai
Join Date: Apr 2010
Posts: 7
Rep Power: 6
Amp is on a distinguished road
Hi Sophie,
I'm stuck at the same problem too.As a quick workaround, I'm planning to use excel to generate a csv file of positions and copy-paste it onto the existing positions file.Not sure if it will work but hope it helps!

Arun
Amp is offline   Reply With Quote

Old   June 13, 2013, 07:13
Default
  #4
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hi Arun,

I think it should work. But I am thinking to take this practice as the first step to dig into the code. I think it is worth trying to work out the values of the position vector and use Cloud<solidParticle> to call the standard write function. However, I'm in a mess doing this. Have you got some ideas on this?

best,
Sophie
sophie_l is offline   Reply With Quote

Old   June 13, 2013, 07:40
Default
  #5
Amp
New Member
 
Arun Appadurai
Join Date: Apr 2010
Posts: 7
Rep Power: 6
Amp is on a distinguished road
Hi Sophie,

This is going to be my next thing to do, after I get the csv file import working. I see you've got a head start in this. May be you have checked this thread
Output file with OpenFOAM header?



Amp is offline   Reply With Quote

Old   June 13, 2013, 08:27
Default
  #6
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hi Arun,

I just looked at it and it's pretty useful to me. Thank you!

Actually I've thought to modify IOobjectWriteHeader.C, but just being afraid it will have global impact on all the others. Another concern is that in the file 'positions', we have to write both the position vector and the corresponding cell number on the same line.
sophie_l is offline   Reply With Quote

Old   June 13, 2013, 14:39
Default
  #7
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,548
Rep Power: 23
ngj will become famous soon enoughngj will become famous soon enough
Hi Sophie,

I would do something along the following lines. Also note that I have chosen vectorField instead of List<vector>:

Code:
label n = 100;
vectorField initPositions(n, vector::zero);

forAll(initPositions, pointi )
{
    // Set the initial positions
    initPosition[pointi] = <something>
}

IOField<vector> writePositions
(
    IOobject
    (  
        "<name required by model, e.g. positions>",
        "<path, e.g. mesh.time().constant() or mesh.time().timeName()>",
       mesh,
       IOobject::NO_READ,
       IOobject::NO_WRITE
    ),
    initPosition
);

writePosition.write();
If it turns out that the positions are rather an IOField<point>, then merely consequently change vector to point in the above code snippet.

Kind regards

Niels
ngj is online now   Reply With Quote

Old   June 13, 2013, 18:15
Default
  #8
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hi Niels,

Thanks a lot! The code snippet works well. However, the file 'positions' is supposed to be of the format below
Quote:
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7.1 |
| \\ / A nd | Web: http://www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class Cloud<solidParticle>;
location "0";
object positions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
4000
(
( 0.106 0.002 0.002) 0
( 0.103 0.002 0.002) 0
( 0.106 0.001 0.002) 0
whose class is Cloud<solidParticle> and the particle position vector is followed by the corresponding cell number on the same line. (It is ok to set the initial cell number to be all 0, though.) I reckon the IOPosition.C and IOPosition.H are the code to help write positions at each time step once it starts running. But I haven't figured out how to get them work for me to generate the input file 'positions'. Could you shed some lights on this please?

Thank you in advance,
Sophie
sophie_l is offline   Reply With Quote

Old   June 14, 2013, 02:01
Default
  #9
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Rotterdam, The Netherlands
Posts: 1,548
Rep Power: 23
ngj will become famous soon enoughngj will become famous soon enough
Good morning Sophie,

I see the problem. I do not have a "correct" solution right now, however the following utility, which I wrote some time ago might be helpful:

http://sourceforge.net/p/openfoam-ex...veParameters.C

Especially the part where the header is written, since I also needed to do everything by hand:

Code:
    // Write the OF banner
    wOut.writeBanner( os );
            
    // Write the file information. Class name is not correct when
    // using wOut.writeHeader( os ); hence manual entries
    os << "FoamFile" << nl;
    os << token::BEGIN_BLOCK << incrIndent << nl;
    os << indent << "version" << tab << IOstream::currentVersion << token::END_STATEMENT << nl;
    os << indent << "format" << tab << "ascii;" << nl;
    os << indent << "class" << tab << "dictionary;" << nl;
    os << indent << "object" << tab << "waveProperties;" << nl;
    os << decrIndent << indent << token::END_BLOCK << nl;

    // Write the divider
    wOut.writeDivider( os );
    os << nl;
After that you merely write all the positions, which could e.g. be done like:

Code:
os << initPositions.size() << nl << "(" << endl;

forAll( initPositions, pointi )
    os << initPositions[pointi] << " " or tab  << processorNumber[pointi] << endl;

os << ");" << nl << endl;
Kind regards

Niels
HakikiCanakkaleli likes this.
ngj is online now   Reply With Quote

Old   June 14, 2013, 13:06
Default
  #10
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 43
Rep Power: 4
sophie_l is on a distinguished road
Hi Niels,

It works perfectly! Thanks!

Sophie
sophie_l is offline   Reply With Quote

Reply

Tags
iofield, particle, position, write to file

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
dispersion model with lagragian particle tracking model for incompressible flows eelcovv OpenFOAM Running, Solving & CFD 47 November 17, 2014 17:03
OpenFoam-1.6-ext Allwmake compilation error - one last barrier Pat84 OpenFOAM Installation 15 July 25, 2012 22:49
how to know position of particle in PTK areriko CFX 0 November 19, 2007 22:19
Particle position Neser CFX 0 March 7, 2005 13:11
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 21:09


All times are GMT -4. The time now is 10:29.