CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > 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 Search this Thread Display Modes
Old   June 5, 2013, 10:35
Post How to write IOField variable particle position
  #1
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 51
Rep Power: 10
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, 07:25
Default
  #2
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 51
Rep Power: 10
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, 04:52
Default
  #3
Amp
New Member
 
Arun Appadurai
Join Date: Apr 2010
Posts: 8
Rep Power: 13
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, 06:13
Default
  #4
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 51
Rep Power: 10
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, 06:40
Default
  #5
Amp
New Member
 
Arun Appadurai
Join Date: Apr 2010
Posts: 8
Rep Power: 13
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
http://www.cfd-online.com/Forums/openfoam-post-processing/66619-output-file-openfoam-header.html . ?



Amp is offline   Reply With Quote

Old   June 13, 2013, 07:27
Default
  #6
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 51
Rep Power: 10
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, 13:39
Default
  #7
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,872
Rep Power: 34
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 offline   Reply With Quote

Old   June 13, 2013, 17:15
Default
  #8
Member
 
Join Date: Nov 2012
Location: Liverpool, UK
Posts: 51
Rep Power: 10
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, 01:01
Default
  #9
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Deltares, Delft, The Netherlands
Posts: 1,872
Rep Power: 34
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 offline   Reply With Quote

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

It works perfectly! Thanks!

Sophie
sophie_l is offline   Reply With Quote

Old   January 13, 2016, 19:26
Default Particle tracking
  #11
Member
 
HM
Join Date: Apr 2015
Posts: 30
Rep Power: 8
hojjat.m is on a distinguished road
Hello everyone,
I have been stuck to a problem with particle tracking. In openfoam, all the solvers are designed to inject particles from a certain location for all time steps. But I want to inject particles form different cells, at each time step.
Lets say we have a temperature field calculated at each time step. I want to inject particles at each time step from cells with certain temperature (e.g. T=200K). Can anyone help me with this.

Thanks in advance.
hojjat.m is offline   Reply With Quote

Old   December 11, 2017, 12:05
Default
  #12
New Member
 
Sandip Wadekar
Join Date: Oct 2014
Posts: 17
Rep Power: 8
wadekar is on a distinguished road
Hello Foamer

I am using OF2.2.x
I have similar problem when reading file lagrangian/sprayCloud/positions, because this file contains position vector, cell id and having header class "Cloud<basicSprayParcel>"

Example:
Quote:
FoamFile
{
version 2.0;
format ascii;
class Cloud<basicSprayParcel>;
location "0.0005";
object positions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
4000
(
( 0.106 0.002 0.002) 1510
( 0.103 0.002 0.002) 1512
Actually, i am trying to read the file like this:
Quote:
IOobject fieldpos
(
"positions",
runTime.timeName(),
"lagrangian/sprayCloud",
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE
);

IOField<vector> pos(fieldpos);
Problem: i am changing the header class, and removing cell id from the file 'positions' through script then its working perfectly. But, when i use the paraview then i can't any particle in the domain.

Posible solution:
1. Is there any way to read the file 'lagrangian/sprayCloud/positions' when cell id is also present there ?
2. Is there any way to create the separate file that contains only particle position ?

Please suggest any of the possible solution.
Thanks in advance.
wadekar is offline   Reply With Quote

Old   June 15, 2019, 05:25
Default
  #13
hzw
New Member
 
Join Date: May 2014
Posts: 5
Rep Power: 8
hzw is on a distinguished road
Quote:
Originally Posted by wadekar View Post
Hello Foamer

I am using OF2.2.x
I have similar problem when reading file lagrangian/sprayCloud/positions, because this file contains position vector, cell id and having header class "Cloud<basicSprayParcel>"

Example:


Actually, i am trying to read the file like this:


Problem: i am changing the header class, and removing cell id from the file 'positions' through script then its working perfectly. But, when i use the paraview then i can't any particle in the domain.

Posible solution:
1. Is there any way to read the file 'lagrangian/sprayCloud/positions' when cell id is also present there ?
2. Is there any way to create the separate file that contains only particle position ?

Please suggest any of the possible solution.
Thanks in advance.

Dear wadekar,

Have you found any solution to this problem you proposed? I am also very interested in this question. How can we index the particles to the cells they are in?
hzw is offline   Reply With Quote

Reply

Tags
iofield, particle, position, write to file

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
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 54 April 10, 2018 09:36
OpenFoam-1.6-ext Allwmake compilation error - one last barrier Pat84 OpenFOAM Installation 15 July 25, 2012 21:49
how to know position of particle in PTK areriko CFX 0 November 19, 2007 21:19
Particle position Neser CFX 0 March 7, 2005 12:11
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09


All times are GMT -4. The time now is 04:51.