|
[Sponsors] |
How to use mesh information in other source file |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 23, 2018, 13:28 |
How to access mesh and user-defined fields in other source file
|
#1 | |||
Senior Member
|
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:
when I compile the codes, the compiler gives: Quote:
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:
Any thoughts, guys? Last edited by TurbJet; January 30, 2018 at 19:03. |
||||
January 25, 2018, 23:43 |
|
#4 |
Senior Member
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12 |
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. |
|
January 30, 2018, 12:40 |
|
#5 | |||
Senior Member
|
Quote:
Quote:
the codes I add: Quote:
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. |
||||
January 30, 2018, 18:02 |
|
#6 | ||
Senior Member
|
I kind of figured out this mesh problem.
I added few sentences in the code: Quote:
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:
Last edited by TurbJet; January 30, 2018 at 19:58. |
|||
January 30, 2018, 19:54 |
|
#7 | ||
Senior Member
|
following the previous procedure, I tried the following:
Quote:
Quote:
|
|||
February 1, 2018, 17:42 |
|
#8 |
Senior Member
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12 |
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(); 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") ); |
|
February 2, 2018, 12:29 |
|
#9 | |
Senior Member
|
Quote:
|
||
February 2, 2018, 12:47 |
|
#10 | ||
Senior Member
|
Quote:
Quote:
|
|||
March 5, 2020, 18:56 |
|
#11 |
New Member
tooran
Join Date: Nov 2016
Posts: 23
Rep Power: 9 |
I created a new viscosity model base on HerschelBulkley model . I want to model the following structure:
If y< 0.048 Then return... Else return.... I am trying to access the points in the mesh inside the the HerschelBulkley class.So I added the following loop on the calcNu() function in HerschelBulkley : forAll (etat, cellI) { etat[cellI]=mrsh.c()[cellI].y(); If (etat[cellI]<0.048) {.... But When I compiled the error appeared : "mesh is not declare in this scope" I solved this error by adding the following lines: const objectRegistry& db(); const volVectorField& U = db().lookupObject<volVectorField>("U"); const fvMesh & mesh = U.mesh(); forAll (etat, cellI) { etat[cellI]=mrsh.c()[cellI].y(); If (etat[cellI]<0.048) {.... Now the libary compiles with out errors,but when I want to run the case with the solver simple foam , the following error appears: Undefined symbol: _ZN4Foam15viscosityModels2dev Could anyone help me? Thanks |
|
February 9, 2022, 07:27 |
|
#12 |
Member
hari charan
Join Date: Sep 2021
Location: India,hyderabad
Posts: 96
Rep Power: 4 |
Hello TurbJet,
I had the same problem can you go through my post . I am sharing the link below. request for a field in object registry failed Thanks in advance. |
|
Tags |
mesh; |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom Thermophysical Properties | wsmith02 | OpenFOAM | 4 | June 1, 2023 14:30 |
[swak4Foam] groovyBC in openFOAM-2.0 for parabolic velocity bc | ofslcm | OpenFOAM Community Contributions | 25 | March 6, 2017 10:03 |
[OpenFOAM.org] 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 |
friction forces icoFoam | ofslcm | OpenFOAM | 3 | April 7, 2012 10:57 |