|
[Sponsors] |
March 24, 2021, 12:54 |
|
#81 |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
The newer OpenFOAM versions (I think from v1906 onwards) have a function object named hydrostaticPressure, which should give you ph_rgh.
I haven't tried it yet, but I think it should work. Actually, I prefer to include my own phrghEqn in my version of the solver, to be able to update ph_rgh as the density field changes (hydrostaticPressure will just give you an initial ph_rgh field). |
|
June 12, 2021, 06:57 |
Close Cavity
|
#82 | |
Member
Join Date: Nov 2020
Posts: 53
Rep Power: 5 |
Quote:
What about for a close cavity, like the hot room tutorial in buoyantPimpleFoam. I wanna use a fluid whose density is a function of temperature, not air. However, it blew up if fixedFluxPressure is used as boundaries to all walls. Any idea about this? Mike |
||
June 15, 2021, 03:34 |
|
#83 |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Hi Mike,
I hope you have solved your problems by now. Sorry, I don't have an explanation for the problems you are seeing. They could have many reasons. Have you tried using fixedFluxPressure only on the horizontal walls (i.e. floor and ceiling)? Cheers, Jost |
|
June 16, 2021, 00:28 |
|
#84 | |
Member
Join Date: Nov 2020
Posts: 53
Rep Power: 5 |
Quote:
Still now, I can't find any solution. If all boundaries are fixedFluxPressure, the p_rgh reaches to maxIter even up to 5000 iterations. By manipulating fvSolution, the solver runs with a very unstable velocity and temperature profile, which makes deltaT too small up to 1e-20 just to maintain Courant No = 1. However, if one wall is not set to fixedFluxPressure, I doubt if that condition is physically right. |
||
June 16, 2021, 03:55 |
|
#85 | |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Quote:
Hi Mike, could you upload your case or at least some more info? |
||
June 16, 2021, 04:22 |
|
#86 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Quote:
__________________
Keep foaming, Tobias Holzmann |
||
June 16, 2021, 06:41 |
|
#87 | |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Quote:
Hi Tobi, thanks for picking up this discussion, which I found extremely fruitful! I mean, the ph_rgh field isn't really used in the fireFoam solver either, is it? As far as I understand, the only purpose of the ph_rgh field is to be used in the prghTotalHydrostaticPressure boundary condition. This boundary condition simply uses the boundary value of ph_rgh in a totalPressue BC for p_rgh (essentially ph_rgh provides the nonuniform p0 value for the totalPressue BC). Why do you need to set the boundary value of p_rgh to ph_rgh? Well, this comes from the momentum equation. Total balance (i.e. no flow) demands that the source term are in balance i.e. This is the balance you need to satisfy if you want the flow at your boundary to be driven by convection, not by gravity. ph_rgh is the pressure that satisfies exactly that balance. Thus, prghTotalHydrostaticPressure would be my first candidate for a p_rgh boundary condition at any vertical outlet (in flows with nonuniform density). I think, this would also help in your initial watertank case and certainly in the case you posted here (Correct boundary conditions for p_rgh (special for vertical patches)). (Little side problem: what happens when the density changes over time? That is where the trouble starts...) So how can we use the prghTotalHydrostaticPressure BC in the buoyant* solvers? Using the hydrostaticPressure function object you can get the ph_rgh field not only in fireFoam but also in the buoyant* solvers (or any other solver), which means you can use the prghTotalHydrostaticPressure boundary condition. Apart from giving you ph_rgh, the hydrostaticPressure function object also provides you with an improved initial guess for p and p_rgh, which can help in some cases. So it can be useful, even if you do not intend to use the prghTotalHydrostaticPressure BC. I would say there is no need to use a transient solver first, as you proposed, if you do the hydrostatic initialisation with hydrostaticPressure. Cheers, Jost |
||
June 16, 2021, 07:08 |
|
#88 | |||
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hey,
I never went through the ph_rgh field and boundary condition in detail. However, in OpenFOAM v2012 (ESI version) this field is only used in the fireFoam solver. Easy to check by doing the following: Code:
shorty@solvers: grep -rni -e "ph_rgh" combustion/fireFoam/phrghEqn.H:3: volScalarField& ph_rgh = regIOobject::store combustion/fireFoam/phrghEqn.H:9: "ph_rgh", combustion/fireFoam/phrghEqn.H:21: p = ph_rgh + rho*gh + pRef; combustion/fireFoam/phrghEqn.H:41: constrainPressure(ph_rgh, rho, U, phig, rhof); combustion/fireFoam/phrghEqn.H:43: fvScalarMatrix ph_rghEqn combustion/fireFoam/phrghEqn.H:45: fvm::laplacian(rhof, ph_rgh) == fvc::div(phig) combustion/fireFoam/phrghEqn.H:48: ph_rghEqn.solve(); combustion/fireFoam/phrghEqn.H:50: p = ph_rgh + rho*gh + pRef; combustion/fireFoam/phrghEqn.H:55: << (max(ph_rgh) - min(ph_rgh)).value() << endl; combustion/fireFoam/phrghEqn.H:58: ph_rgh.write(); combustion/fireFoam/phrghEqn.H:60: p_rgh = ph_rgh; Code:
shorty@derived: grep -rni -e 'ph_rgh' prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.H:37: p_rgh = ph_rgh - 0.5 \rho |U|^2 prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.H:43: ph_rgh | Hydrostatic pressure: \f$ \rho g (h - h_{ref}) \f$ [Pa] prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.H:56: ph_rgh | ph_rgh field name | no | ph_rgh prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.H:111: word ph_rghName_; prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:49: ph_rghName_("ph_rgh") prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:65: ph_rghName_(dict.getOrDefault<word>("ph_rgh", "ph_rgh")) prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:82: ph_rghName_(ptf.ph_rghName_) prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:96: ph_rghName_(ptf.ph_rghName_) prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:111: ph_rghName_(ptf.ph_rghName_) prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:127: const scalarField& ph_rghp = prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:128: patch().lookupPatchField<volScalarField, scalar>(ph_rghName_); prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:138: ph_rghp prghTotalHydrostaticPressure/prghTotalHydrostaticPressureFvPatchScalarField.C:155: os.writeEntryIfDifferent<word>("ph_rgh", "ph_rgh", ph_rghName_); Now, it is obvious that this condition can only be used in combination with the fireFoam solver. Why? In the updateCoeffs() function we have the following: Code:
void Foam::prghTotalHydrostaticPressureFvPatchScalarField::updateCoeffs() { if (updated()) { return; } const scalarField& rhop = patch().lookupPatchField<volScalarField, scalar>(rhoName_); const scalarField& ph_rghp = patch().lookupPatchField<volScalarField, scalar>(ph_rghName_); const scalarField& phip = patch().lookupPatchField<surfaceScalarField, scalar>(phiName_); const vectorField& Up = patch().lookupPatchField<volVectorField, vector>(UName_); operator== ( ph_rghp - 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up) ); fixedValueFvPatchScalarField::updateCoeffs(); } We are looking for a volScalarField named ph_rgh (the variable ph_rgh_name does store that string). So far so good ... However, while checking the constructors, we can specify the name of the ph_rhg_name variable to be, e.g., [i}p_rgh[/i] --> does this make sense? Not really because: [code] <patchName> { type prghTotalHydrostaticPressure; ph_rgh p_rgh; value uniform 0; } [code] Will result in the following calculation: Code:
\f[ p_rgh = ph_rgh - 0.5 \rho |U|^2 \f] So if ph_rgh is equal to p_rgh, the p_rgh field gets: p_rgh = p - rho*h*g - 1/2 U^2 rho. However, this has to be analyzed further as it always depends which value we store in the fields. Nevertheless, for the boundary condition it is similar or equal to the prghTotalPressure boundary condition - depending what we specify as value for the ph_rgh condition. To your questions:
Quote:
Quote:
Code:
<patchName> { type prghTotalHydrostaticPressure; ph_rgh p_rgh; value nonuniform (Some List of values); } Quote:
This might be correct. I never made a initialisation by using the hydrstaticPressure function (its a while ago that I investigated in that case). Probably everything that I wrote is a mixture of guessing and knowing :P - Again, I would need to investigate into that topic again. I remember that I was using the mentioned condition but if you don't set your ph_rgh field in the boundary condition to e.g., p_rgh, the solver stops as the default field ph_rgh does not exist in the foam database (only in the fireFoam solver).
__________________
Keep foaming, Tobias Holzmann |
||||
June 16, 2021, 07:55 |
|
#89 |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Hi Tobi,
here (see attached case) is an example of how I would set up an open vertical boundary using the hydrostaticPressure function object and the prghTotalHydrostaticPressure boundary condition in conjunction. The example only works on ESI OpenFOAM v1906 and onward (because of the hydrostaticPressure function object). I have only tested it on v2006. Note, that the hydrostaticPressure function object does actually create the ph_rgh registry object, which the BC does than look up. So you don't have to set the ph_rgh name to p_rgh in the boundary condition settings (I agree that that would not really make any sense). Cheers, Jost |
|
June 16, 2021, 14:00 |
|
#90 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Ahhh now I got it. You use the functionObject function to generate the field ph_rgh during the simulation and it is in the registry. Hence, the boundary condition does have access to the field !
Nice way to use it. Never tested it. Thanks for the case. I will check your case.
__________________
Keep foaming, Tobias Holzmann |
|
June 17, 2021, 03:24 |
|
#91 |
Member
Join Date: Nov 2020
Posts: 53
Rep Power: 5 |
Dear Jost,
I tried to simplify everything first by starting with the hotRoomBoussinesq in the tutorial folder of buoyantPimpleFoam v7 of OpenFoam to make the solution faster. Actually, I wanna model a phase change material in a close cavity which you can see at the constant folder using solidificationMeltingSource in fvOptions. Also, I used icoPolynomial to model the density, thermal conductivity, specific heat, and viscosity. As you can see in the attached file, you can observe that the pressure goes wild, so with p_rgh. This is initiated I believe from that weird result starting at the corner as shown. However, if the density is assumed constant, which is usually the main assumption for solidificationMeltingSource, everything goes fine (though accuracy needs finer mesh and small Courant Number). Moreover, if one wall will stay open, say p_rgh initial condition is set to fixedValue or prghPressure, etc. it will be fine but physically it is not right for me. Thus, I am suspecting that the boundary condition fixedFluxPressure for this case will lead to an erroneous result. Regards, Mike UPDATE: I set turbulenceProperties to laminar and it looks better to me. Last edited by mikulo; June 17, 2021 at 03:40. Reason: Update: set turbulenceProperties to laminar |
|
June 17, 2021, 03:25 |
|
#92 |
Member
Join Date: Nov 2020
Posts: 53
Rep Power: 5 |
Dear Tobi and Jost,
I learned something new from your discussions. Thanks! Regards, Mike |
|
June 28, 2021, 03:56 |
problems with hydrostatic initialization
|
#93 |
Member
Mattia de\' Michieli Vitturi
Join Date: Mar 2009
Posts: 51
Rep Power: 17 |
Hello,
When you use the hydrostatic initialization for ph_rgh equation, please be aware that the pressure profile given by openFOAM could be wrong. It is found by solving an equation with a laplacian, obtained by differentiating the correct equation (dp/dz=rho*g), but the differentiation add other solutions (the original solution plus any linear function of z). For small domains, you will not notice a big difference, but for large domains the error can be large. I've noticed this thing for large domains with air, and I've noticed that in many case it was not possible to find the correct atmospheric profile for pressure. At the end I had to rewrite the solver for the initialization of ph_rgh, in order to solve directly for dp/dz=rho*g. The initial profile I have now seems correct, but I'm still working on how to use it correctly with other solvers in the latest openfoam-dev. Mattia |
|
June 28, 2021, 08:33 |
|
#94 |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Hi Mattia,
Thanks for your input! I am simulating water in a large domain and I was also experiencing some problems with the hydrostatic initialization at first but finally managed to resolve them by experimenting with different boundary conditions. It would be very interesting to hear how you manage to directly solve for dp/dz=rho*g . I did not think this was possible with a Finite Volume approach. Are you sure the pressure obtained by the hydrostatic Poisson equation can differ from the correct solution by any linear function of z? Is this generally the case for the pressure in simulations where the velocity approaches zero (i.e. with no horizontal pressure gradient)? Cheers, Jost |
|
June 28, 2021, 09:04 |
|
#95 | |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Quote:
Hm, my experience is that fully enclosed volumes are always tricky with buoyantPimpleFoam. Maybe switching to "sensibleEnthapy" with "dpdt off" could help. Generally I can see that solving a mass conservation equation for an incompressible fluid with changing density in an enclosed volume may lead to problems (if the density changes and the volume stays constant you cannot be conserving mass). This is probably why you are having less problems with a laminar simulation, less diffusion means less density change i.e. less mass conservation error. Have you considered changing to a compressible equation of state? Cheers, Jost |
||
June 29, 2021, 06:16 |
|
#96 |
Member
Mattia de\' Michieli Vitturi
Join Date: Mar 2009
Posts: 51
Rep Power: 17 |
Hi Jost,
A quick reply to your first question about how to manage directly dp/dz=rho*g. The problem with the solution of this equation is that we don't have the implicit fvm method to discretize gradient terms, so it seems that we cannot discretize implicitely the left-hand side. The trick is to use a constant unitary velocity field U with direction parallel to that the gravity (here z), and note that div(U*p)=dp/dz. Now, for the divergence we have the fvm method, so we can obtain the desired discretization matrix and solve implicitely. The right hand-side, which is also multiplied by U, is computed explicitely (rho is a function of p), so we need to iterate updating the density after each solution of the equation div(U*p)=rho*(g*U). There are two important things when solving the equation. We need to use an upwind scheme for the discretization of the divergence term, and the sign of U has to be chosen accordingly to the location of the patch were we fix a reference pressure for the hydrostatic profile. Once these things are done, with few iterations we have the desired profile. Mattia |
|
July 3, 2021, 07:40 |
|
#97 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Quote:
__________________
Keep foaming, Tobias Holzmann |
||
March 16, 2022, 03:08 |
|
#98 |
Member
Join Date: Nov 2020
Posts: 53
Rep Power: 5 |
Dear Jost,
Until now, still struggling quite a bit. But, yeah, I agree with you. Continuity error is one of the culprit for variable density in an incompressible fluid assumption. I have tried compressible case by providing values on psi, but, the results are not good. Treating expansion/compression might be good for density-based solver. Seems like pressure-based solver with p_rgh would be a big problem. Mike |
|
June 21, 2022, 06:00 |
|
#99 | |
Member
Jost Kemper
Join Date: Apr 2018
Location: Kiel, Germany
Posts: 39
Rep Power: 8 |
Quote:
Hi Mattia, I've finally gotten round to implementing your approach for the hydrostatic pressure. It really runs much faster than my previous approach. It works quite nicely so far, but there is one thing about using the upwind scheme that puzzles me. Imagine a one-dimensional case with an upper (N) and a lower cell (S). We are solving with the Gauss upwind scheme. Then, as far as I can tell, the solution for the pressure in cell S is This does not quite resemble the trapezoidal rule for integration, which would be In my implementation, I get a corresponding error in the value of the hydrostatic pressure. It gets better when I use linearUpwind instead of pure upwind, but the solution is not perfect. Perhaps I misunderstood something about your approach. It would be nice to hear hear if you had the same problem and how you solved it. Thanks a lot so far! Cheers, Jost |
||
June 21, 2022, 06:51 |
|
#100 |
Member
Mattia de\' Michieli Vitturi
Join Date: Mar 2009
Posts: 51
Rep Power: 17 |
Hi Jost,
You're right when you write that the upwind introduce an error in the value of the hydrostatic pressure. In general it is small, but it is there. You may get better results with a quick scheme. Have you already tried? In my latest version of the script for the initialisation of the pressure profile now I use both my solver to get a first profile (with the error you mentioned), and then I use this profile as initial solution of the solver from fireFoam. In this way I get a good hydrostatic profile, which seems to be stable when passed to the main solver. Mattia |
|
|
|