CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How to write IOField variable particle position (https://www.cfd-online.com/Forums/openfoam-solving/118844-how-write-iofield-variable-particle-position.html)

sophie_l June 5, 2013 11:35

How to write IOField variable particle position
 
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 June 12, 2013 08:25

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::out);
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.

Amp June 13, 2013 05:52

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

sophie_l June 13, 2013 07:13

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

Amp June 13, 2013 07:40

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 . ?




sophie_l June 13, 2013 08:27

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.

ngj June 13, 2013 14:39

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

sophie_l June 13, 2013 18:15

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

ngj June 14, 2013 02:01

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

sophie_l June 14, 2013 13:06

Hi Niels,

It works perfectly! Thanks!

Sophie

hojjat.m January 13, 2016 20:26

Particle tracking
 
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.

wadekar December 11, 2017 13:05

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.

hzw June 15, 2019 06:25

Quote:

Originally Posted by wadekar (Post 674755)
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?


All times are GMT -4. The time now is 17:38.