CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Accessing the value of a field variable (https://www.cfd-online.com/Forums/openfoam-pre-processing/203296-accessing-value-field-variable.html)

charles4allme June 23, 2018 11:01

Accessing the value of a field variable
 
Hello,

I have looked at the forums and have found solutions but I want to be sure that I am correct. I am trying to access the value of velocity during each time step to calculate losses in a ventilation duct. Here is the form that I have written it in:

Code:

const volVectorField& Uduct = U.db().lookupObject<volVectorField>("U");
Uduct is what I would input into my equation for calculating the duct losses. Is that the right way of setting it up. I appreciate any input.

Thanks

dl6tud June 23, 2018 16:15

Your questions is difficult to understand. From where do you need to access the velocity? In a boundary condition? In the solver itself? In a post-processing tool?

charles4allme June 25, 2018 08:15

HI thanks,


From the solver itself. So what ever value of U in the time step, it looks it up and gets the value. Is that possible?

dl6tud June 25, 2018 08:26

U


only "U"


Info << U << endl;

charles4allme June 25, 2018 15:06

Alright thanks.


Is it possible to use the values at each time step to update the values for the reynolds number. I need the value for the reynolds number to calculate the flow loss. I assumed my earlier code would do that but at the moment all I think it does is take the initial velocity value.


Thanks.

olesen June 25, 2018 17:07

Quote:

Originally Posted by charles4allme (Post 696995)
Hello,

I have looked at the forums and have found solutions but I want to be sure that I am correct. I am trying to access the value of velocity during each time step to calculate losses in a ventilation duct. Here is the form that I have written it in:

Code:

const volVectorField& Uduct = U.db().lookupObject<volVectorField>("U");
Uduct is what I would input into my equation for calculating the duct losses. Is that the right way of setting it up. I appreciate any input.

Thanks

Actually your code snippet makes very little sense (or it suffered from transcription problems).

If we really start with this:
Code:

const volVectorField& Uduct = U.db().lookupObject<volVectorField>("U");
The "U" part is presumably already the velocity field. The "db()" part gets you the objectRegistry used by "U", which means your mesh. From this the "lookupObject" finds the named object of the specified type. Which seems like you've gone once around to come up with a reference to your starting point??

If you want to calculate a Reynolds number or something, having the entire velocity field throughout the volume probably won't help much. It might be more useful to use a sampling plane or a sampling patch combined with an area average to obtain a representative value.
Can't say offhand where you want to proceed from there (how to get a length scale, which rho, mu, etc) - it's not really obvious from your post what data or geometry you have.

/mark

charles4allme June 26, 2018 06:45

1 Attachment(s)
Quote:

Originally Posted by olesen (Post 697188)
Actually your code snippet makes very little sense (or it suffered from transcription problems).

If you want to calculate a Reynolds number or something, having the entire velocity field throughout the volume probably won't help much. It might be more useful to use a sampling plane or a sampling patch combined with an area average to obtain a representative value.
Can't say offhand where you want to proceed from there (how to get a length scale, which rho, mu, etc) - it's not really obvious from your post what data or geometry you have.

/mark

I would go with your suggestion to calculate the Reynolds number. I have all other variables except the length scale on this occassion . I have attached the geometry. Its a simple case of flow through a ventilation duct with an initial velocity of 10m/s. The dimension of the duct is 0.4m x 0.4m x 3m.

Thanks.

Tibo99 June 17, 2020 16:36

What would be the code line to access to the variable field 'k', let say at every cells center of the domain, but from the file fvOptions?

I try to find an example of how to achieve that and I find nothing.

Thank!

Best Regards,


All times are GMT -4. The time now is 18:19.