CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Calculating phi from U read from file (https://www.cfd-online.com/Forums/openfoam/228129-calculating-phi-u-read-file.html)

kauraajn June 20, 2020 20:51

Calculating phi from U read from file
 
Hi,

I have used the incompressible navier stokes equations to compute the velocity field for my domain using a third part solver, and I need to use this velocity to implement a scalar transport solver in openfoam. How should I calculate phi for this application? I have my velocity field in the format required by openfoam on file.

crubio.abujas June 21, 2020 05:04

When you mention you need to implement a scalar transport solver you mean to write the code? Have you tried scalarTransportFoam? You can check in the tutorials how to define the case and it do just that (inside the basic folder).

Basically you define a U Boundary condition with a non-uniform internal with the velocity field you have, and also set the boundary condition properly. The scalar has to be named T for this case, and a diffusion term is defined in constant/transportProperties as DT. With that information it will calculate phi and solve the scalar transport. It sounds pretty much to want you want.

However, if you want to modify the behavior, adding additional scalarFields, renamed or whatever you may check the code of scalarTransient. There are plenty of tutorials out there explaining how to do that. (i.e https://openfoamwiki.net/index.php/H...ure_to_icoFoam).

kauraajn June 21, 2020 05:29

Thanks for your reply crubio.abujas! Yes, I have implemented what you have pointed out using scalarTransportFoam. However, I am having trouble in obtaining the phi field. It seems to be always be set to 0 throughout my domain. I guess my question is: how do I obtain the right phi field from U which I know.

crubio.abujas June 21, 2020 05:54

Quote:

Originally Posted by kauraajn (Post 775360)
Thanks for your reply crubio.abujas! Yes, I have implemented what you have pointed out using scalarTransportFoam. However, I am having trouble in obtaining the phi field. It seems to be always be set to 0 throughout my domain. I guess my question is: how do I obtain the right phi field from U which I know.


It's hard to tell without knowing how your settings file look like. What is 0? the U field? the scalar (lets name it T) T field? or the phi field?

When you define the BC you have to tell two pieces of information, one is the value field inside the domain and other is the treatment on the boundaries. Typically you set the scalar value in a boundary and then let the solver calculate the distribution. Maybe you defined de velocity in that particular patch to be 0, or to point outwards the domain and that is why the scalar is not distributing.

I'm only guessing here, please share more information about the setting of the case for more insight.

kauraajn June 21, 2020 15:10

The phi field is always zero.

I read the internal field for U from a file, and compute U on the boundary using correctBoundaryConditions. I use zeroGradient boundary conditions for U for my inlet and outlet, and no slip conditions on the walls.

I find that even if U is updated, phi does not get updated. How do I tell the solver to update the values of phi based on U?

crubio.abujas June 22, 2020 02:16

So you are coding your own solver, right? In that case it would be useful if you share the code, so it is clearer where something may be wrong instead of me having to guess what you have done.

If you're getting a phi field to visualize means that, at least, you're initiating the field. You probably have created this field using
Code:

#include "createPhi.H"
Quote:

Originally Posted by kauraajn (Post 775407)
I read the internal field for U from a file, and compute U on the boundary using correctBoundaryConditions. I use zeroGradient boundary conditions for U for my inlet and outlet, and no slip conditions on the walls.

When you said you're reading the internal field from a file, I'm guessing that file is not 0/U internalField, right? If you initialize the U field, then initialize the phi field and only after these two initializations you read the external U field, then phi is not being updated with this new information. The scalarTransportFoam solver does not solve for U, so it only calculate the phi field at the initialization.

If that is your case, you can just call createPhi after U is properly set. Or call
Code:

phi = fvc::flux(U);
Whenever that happens.

Again, it's hard to forecast the details and implementation of your solver without seeing the code itself. If the problems persist please share the important bits of the code. It's also important to know your OF version, as the code may be different.

Regars

kauraajn June 22, 2020 06:22

That worked, thanks a lot! Yes, phi was not getting updated because I read U after creating phi.

crubio.abujas June 22, 2020 06:43

Quote:

Originally Posted by kauraajn (Post 775514)
That worked, thanks a lot! Yes, phi was not getting updated because I read U after creating phi.


Glad to know it worked! :D


All times are GMT -4. The time now is 08:01.