How to add a body force to a momentum equation
Hello
If I have a constant body force f(fx fy 0) which has a dimension of force/volume/density. I want to add it to the momentum equation, 1) is it possible to use fvOptions in this case? if yes how? don't post links because there no useful info there, I searched the whole internet without success. :mad: 2) if it must involve programming, then where in my code (I mean in the pimple loop) should I put the body force? |
Cant you include this force by using a modified gravity vector?
|
Quote:
|
This depends highly on what you are trying to implement. For example, you can add a body force directly to the momentum equation or you can put the source term to the pressure. For the second one, my former colleague would be better suited for the answer. Thus, let us consider the simple way: Adding the source term to the momentum equation. Here you have at least two options:
a) Modifying the momentum equation inside the code (UEqn.H file). b) Using fvOptions and adding the terms of your needs; e.g., using the <Type>codedSource To a) - The file UEqn.H is located in the solver folder you are using. It is recommended to build a new derivation of the underlying solver (there is a lot of information on the web). The path is $FOAM_SOLVERS/ Adding an arbitrary source term to the momentum of pimpleFoam looks as follows. The common UEqn is: Code:
tmp<fvVectorMatrix> tUEqn Code:
tmp<fvVectorMatrix> tUEqn Code:
const dimensionedVector mySource("mySource", dimensionSet(0,1,-1,0,0,0,0), vector(-4,0,0)); To b) please follow this link and scroll down to the Detailed Description -> Usage https://cpp.openfoam.org/v6/classFoa...21f7bbb656d86d Good luck |
Thank you very much, dear Tobi, for your answer it is very clear. Actually I am trying to simulate the 2D flow over a NACA airfoil but without using the real geometry, instead, I replace it as a source term. (Lift and drag forces projected to x and y directions).
In the UEqn.H, I have a question. Are the following syntaxes the same?: Code:
tmp<fvVectorMatrix> tUEqn Code:
tmp<fvVectorMatrix> tUEqn 2)When using fvOptions, I guess there is something called "vectorCodedSource", right? |
Quote:
A body force is an action exerted on matter essentially by: i) gravity, ii) magnetic fields, iii) electric fields, iv) centrifugal and Coriolis accelerations. From the above, gravity is often taken as constant. As you mention that your force is constant; then I assumed that, whatever this force is, you can add it to gravity. For some solvers, gravity is added at RUNTIME as a vector, that is read from a dictionary. You can check the squareBump example in the OpenFOAM tutorials subdirectory. Thus, your new gravity vector in your input dictionary would look like: Code:
g g [0 1 -2 0 0 0 0] (fx fy -9.81); This approach would avoid programming a new solver. Of course this implies that your solver allows this body force. Finally, I think that Tobi's suggestion is the best approach. |
A few comments,
1. I never saw the modifing gravity vector but this sounds to be a real hack! That's excellent, easy and without headache. The only problem is related to the fact that it acts on the whole domain. 2. Out of the box I would expect that both forumations are the same (related to the question of the equations). One can work with Sp operators to make it more stable but that is not the matter of question. 3. There should be a vectorCodedSource Finally,I really like Martins way because it is actually the same what I mentioned but much easier :) By the way, the units of the source in my example should be wrong :) |
Quote:
Thank you for your answer. but it is not useful in my case, because I have to insert the body force in a specified cellZone only not in the entire domain. |
Greetings to all,
It took me two or three passes through this thread to figure out which side is up... sorry, what I mean is that I wasn't clear if a solution had been reached yet or not. I had to double-check with Evren to know if I should take a better look into this... so I'll write my post as I go along with figuring things out... I'm having a hard time understanding the original request on the type of force to be applied, so... Quote:
Quote:
I got there from the base "fv :: option" class: https://cpp.openfoam.org/v6/classFoa...1_1option.html - from there, we can find more possible "fvOptions" if we click on the "cellSetOption" one: https://cpp.openfoam.org/v6/classFoa...SetOption.html - this is because these are bound to the possibility to select a list of cells to which the "fvOption" is applied to. OK, so the basis for adding a new source term is roughly outlined. Now I have to try and understand the original request: Quote:
OK ok... if I step back, we do have access to the volumes of the cells and possibly access to the density field, so that shouldn't be a problem. But that raises the following question: What volume should be used and which density? What I mean is: should we simply make the calculation the same for each individual cell? And should it be applied to the whole field? Because if this is the case, then it should be simply a matter of:
But if this is not the desired math operation that is meant to be done - for example, if the idea is to impose only a force directly on a patch - then it's a whole other ball game... My last concern is whether this a standard feature that is needed for airfoil studies? Because if it is, that I or Tobi or anyone else can look into creating a definitive fvOption for this and contribute it to the OpenFOAM Foundation, so that it's always available in future versions. Best regards, Bruno |
Hi.
I do not know if this is still relevant but to you but here goes nothing. I am not an expert in this, but you could try using fvOptions as you suggested. The following code is the fvOptions file which should be placed in the constant folder of your case. I am not completely sure about the units and expression for the source, but you can try changing it so that is fits your requirements. Code:
/*--------------------------------*- C++ -*----------------------------------*\ Best regards Mathias |
Quote:
Hey Martin, i am trying to implement coriolis and centrifugal accelerations to a case without changing the solver. Any suggestion how to implement this ? I tried tabulatedAccelerationSource, but keep getting errors no matter what i change. Kind Regards Daniel |
Quote:
You should adopt the approaches proposed by Tomi or Bruno. I do not think there is an easy hack for Coriolis. Good luck! Martin |
Hey Martin,
thanks for your reply. I tried to implement the rotation via FvOptions using the tabulatedAccelerationSource, unfortunatly this did not work for me, I also tried using MRFProperties an i tried to rotate my Mesh with dynamic mesh. None of that worked so back to start i guess... Regards Daniel |
Quote:
I think that writing a new solver (and probably a library) to take into account this force should not be extremely difficult. But of course you need to know some details about OpenFOAM classes. |
Quote:
Can you briefly explain how this is done? I ask because I am trying to add a time-dependent source term cos(omega*t), so I believe I would edit as follows Code:
tmp<fvVectorMatrix> tUEqn Code:
# define omega 3 |
Quote:
Hi Josh, it seems you are using the correct approach. You can access to the current time with runTime.value(). It is not working? |
Quote:
|
Quote:
|
Quote:
Code:
MRF.correctBoundaryVelocity(U); Code:
In file included from bfInterFoam.C:142:0: |
For anyone in the future trying to add a body force, my UEqn.H file looks like this
Code:
MRF.correctBoundaryVelocity(U); I should ask: do I need to do anything to the pEqn.H or is this all that's necessary to add a body force? |
All times are GMT -4. The time now is 02:51. |