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

How to use mesh information in other source file

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

Like Tree1Likes
  • 1 Post By Taataa

Reply
 
LinkBack Thread Tools Display Modes
Old   January 23, 2018, 13:28
Unhappy How to access mesh and user-defined fields in other source file
  #1
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
Hello to everyone,

Currently I am using MPPICFoam to track particles. Now I have to modify one of its source files, which needs to access the information like mesh and other user-created fields. So how am I gonna do that? How am I gonna access other information outside the source file, in this case mesh, user-created fields? Should I include some headers for the mesh or something else? I tried to include headers like "polyMesh.H" "fvCFD.H", but it did not work out.

I am kind of desperate now. Hope there is someone could help me out here.

Thanks a lot.


PS:
to be more specific. I am doing Lagrangian Particle tracking and using MPPICFoam. Currently I am trying to make some modification to the file Cloud.C. What I am trying to do is to loop over all the mesh and particles, and then check the mesh where the particle is at, see how is the porosity of this mesh; if the porosity of this mesh is 0, delete the particle, otherwise, do nothing.


the codes I add:

Quote:
forAll(mesh.C(), celli)
{
if (( abs(mesh().C()[celli].x() - p.position().x()) < posdiff )
&&( abs(mesh().C()[celli].y() - p.position().y()) < posdiff ))
{
if (abs(porosity[celli]) <= threshold)
{
deleteParticle(p);
}
}
}
where posdiff and threshold are just constants I defined, and porosity is a new field I create; deleteParticle is a member function of Cloud.C; p.position() is to access the coordinates of the particles.


when I compile the codes, the compiler gives:
Quote:
/opt/openfoam4/src/lagrangian/basic/lnInclude/Cloud.C: In member function ‘void Foam::Cloud<ParticleType>::move(TrackData&, Foam::scalar)’:
/opt/openfoam4/src/lagrangian/basic/lnInclude/Cloud.C:309:13: error: ‘mesh’ was not declared in this scope
forAll(mesh.C(), celli)
^
/opt/openfoam4/src/OpenFOAM/lnInclude/UList.H:430:30: note: in definition of macro ‘forAll’
for (Foam::label i=0; i<(list).size(); i++)


UPDATE:

I figured out the mesh problem (for those who might be interested, see my reply below at #6). And I was inspired by this thread:
const volVectorField& U = db().lookupObject<volVectorField>("U") gives runtime error

But I am still not able to access my self-created field "porosity" within this scope, i.e., within this Cloud.C file.

I create the porosity field by add codes in createFields.H, and write another header file to compute the field. Then I include this header file at the beginning of the solver MPPICFoam.

The compiler says the same thing:
Quote:
error: ‘porosity’ was not declared in this scope
if (abs(porosity[celli]) <= threshold)
Anyway, to narrow this down: how am I gonna retrieve self-created field within other source file?

Any thoughts, guys?

Last edited by TurbJet; January 30, 2018 at 19:03.
TurbJet is offline   Reply With Quote

Old   January 23, 2018, 19:41
Default
  #2
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
could someone please answer my question? I am desperate
TurbJet is offline   Reply With Quote

Old   January 24, 2018, 14:19
Default
  #3
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
anyone can help me out?
TurbJet is offline   Reply With Quote

Old   January 25, 2018, 23:43
Default
  #4
Senior Member
 
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 126
Rep Power: 6
Taataa is on a distinguished road
You need to be more specific about your problem if you want help.

Regarding the mesh not declared error you need use it like this:
mesh().C()
in the newer versions of OF.
Tobi likes this.
Taataa is offline   Reply With Quote

Old   January 30, 2018, 12:40
Default
  #5
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
Quote:
Originally Posted by Taataa View Post
You need to be more specific about your problem if you want help.

Regarding the mesh not declared error you need use it like this:
mesh().C()
in the newer versions of OF.
the compiler gives
Quote:
/opt/openfoam4/src/lagrangian/basic/lnInclude/Cloud.C: In member function ‘void Foam::Cloud<ParticleType>::move(TrackData&, Foam::scalar)’:
/opt/openfoam4/src/lagrangian/basic/lnInclude/Cloud.C:309:13: error: ‘mesh’ was not declared in this scope
forAll(mesh.C(), celli)
^
/opt/openfoam4/src/OpenFOAM/lnInclude/UList.H:430:30: note: in definition of macro ‘forAll’
for (Foam::label i=0; i<(list).size(); i++)
I am doing Lagrangian Particle tracking and using MPPICFoam. Currently I am trying to make some modification to the file Cloud.C; the goal I want to achieve is that I want to access the mesh center coordinates to compare with the coordinates of particles.

the codes I add:

Quote:
forAll(mesh.C(), celli)
{
if (( abs(mesh().C()[celli].x() - p.position().x()) < posdiff )
&&( abs(mesh().C()[celli].y() - p.position().y()) < posdiff ))
{
if (abs(porosity[celli]) <= threshold)
{
deleteParticle(p);
}
}
}
where posdiff and threshold are just constants I defined, and porosity is a new field I create; deleteParticle is a member function of Cloud.C; p.position() is to access the coordinates of the particles.

I am not sure, but I think the fvMesh info is just not available within this scope, even if I include the header file "fvMesh.H" into this .C file. And I tried to add the brackets after "mesh" as you suggested, but it still not work.

Now I am thinking about passing mesh as an argument into the member function of Cloud.C, but that needs to modify a chunk of other functions.

So I am running out of thoughts.

Last edited by TurbJet; January 30, 2018 at 16:33.
TurbJet is offline   Reply With Quote

Old   January 30, 2018, 18:02
Default
  #6
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
I kind of figured out this mesh problem.

I added few sentences in the code:

Quote:
const objectRegistry& db();
const volVectorField& U = db().lookupObject<volVectorField>("U");
const fvMesh & mesh = U.mesh();
and the compiling worked out without further warning, even though I am not sure if the codes as a whole would work.

But the remaining question is: how am I gonna make the self-created field "porosity" to be accessible within this context? The compiler says the same thing:

Quote:
error: ‘porosity’ was not declared in this scope
if (abs(porosity[celli]) <= threshold)

Last edited by TurbJet; January 30, 2018 at 19:58.
TurbJet is offline   Reply With Quote

Old   January 30, 2018, 19:54
Default
  #7
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
following the previous procedure, I tried the following:

Quote:
const volScalarField& porosity = db().lookupObject<volScalarField>("porosity");
to include my self-created scalar field "porosity". However, the compiler said:

Quote:
Make/linux64GccDPInt32Opt/modDPMFoam.o: In function `_GLOBAL__sub_I_modDPMFoam.C':
modDPMFoam.C: (.text.startup+0x73) : undefined reference to `db()'
modDPMFoam.C: (.text.startup+0xc5) : undefined reference to `db()'
collect2: error: ld returned 1 exit status
make: *** [/home/ipalab/OpenFOAM/ipalab-4.1/platforms/linux64GccDPInt32Opt/bin/modDPMFoam] Error 1
Seems it has some linking issue. Does anyone know what's wrong with it? Any thoughts?
TurbJet is offline   Reply With Quote

Old   February 1, 2018, 17:42
Default
  #8
Senior Member
 
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 126
Rep Power: 6
Taataa is on a distinguished road
This is the way that I would declare velocity and cell centers:
Code:
const volVectorField& U =  mesh().lookupObject<volVectorField>("U");
const volVectorField& centers = mesh().C();
Regarding the dictionary, here is an example for finding air density in transportProperties:
Code:
const objectRegistry& db = mesh().thisDb();
const dictionary& transportProperties =
    db.lookupObject<IOdictionary>
    (
        "transportProperties"
    );

dictionary alpha2
    (
        transportProperties.subDict("air")
    );
        
dimensionedScalar rhoAir
    (
        "rhoAir",
        dimDensity,
        alpha2.lookup("rho")
    );
You can adjust it based on the dictionary and sub-dictionaries.
Taataa is offline   Reply With Quote

Old   February 2, 2018, 12:29
Default
  #9
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
Quote:
Originally Posted by Taataa View Post
This is the way that I would declare velocity and cell centers:
Code:
const volVectorField& U =  mesh().lookupObject<volVectorField>("U");
const volVectorField& centers = mesh().C();
Regarding the dictionary, here is an example for finding air density in transportProperties:
Code:
const objectRegistry& db = mesh().thisDb();
const dictionary& transportProperties =
    db.lookupObject<IOdictionary>
    (
        "transportProperties"
    );

dictionary alpha2
    (
        transportProperties.subDict("air")
    );
        
dimensionedScalar rhoAir
    (
        "rhoAir",
        dimDensity,
        alpha2.lookup("rho")
    );
You can adjust it based on the dictionary and sub-dictionaries.
actually, I was trying to declare mesh, not velocity.
TurbJet is offline   Reply With Quote

Old   February 2, 2018, 12:47
Default
  #10
Senior Member
 
Join Date: Oct 2017
Posts: 122
Blog Entries: 1
Rep Power: 3
TurbJet is on a distinguished road
Quote:
Originally Posted by Taataa View Post
This is the way that I would declare velocity and cell centers:
Code:
const volVectorField& U =  mesh().lookupObject<volVectorField>("U");
const volVectorField& centers = mesh().C();
Regarding the dictionary, here is an example for finding air density in transportProperties:
Code:
const objectRegistry& db = mesh().thisDb();
const dictionary& transportProperties =
    db.lookupObject<IOdictionary>
    (
        "transportProperties"
    );

dictionary alpha2
    (
        transportProperties.subDict("air")
    );
        
dimensionedScalar rhoAir
    (
        "rhoAir",
        dimDensity,
        alpha2.lookup("rho")
    );
You can adjust it based on the dictionary and sub-dictionaries.
Basically, I did this:

Quote:
const objectRegistry& db();
const volVectorField& U = db().lookupObject<volVectorField>("U");
const fvMesh & mesh = U.mesh();

const volScalarField& porosity = db().lookupObject<volScalarField>("porosity");

IOdictionary porosity
(
IOobject
(
"porosity",
this->db().time().constant(),
this->db(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
)
);
The declaration of U and mesh were a success, but the declare of the self-created field "porosity" was not.
TurbJet is offline   Reply With Quote

Reply

Tags
mesh;

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
[swak4Foam] groovyBC in openFOAM-2.0 for parabolic velocity bc ofslcm OpenFOAM Community Contributions 25 March 6, 2017 10:03
Error creating ParaView-4.1.0 OpenFOAM 2.3.0 tlcoons OpenFOAM Installation 13 April 20, 2016 17:34
what is swap4foam ?? AB08 OpenFOAM 28 February 2, 2016 01:22
Custom Thermophysical Properties wsmith02 OpenFOAM 3 July 27, 2015 05:37
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 10:57


All times are GMT -4. The time now is 23:42.