New BC with differential equation
Hi everyone,
I'm new to OpenFoam, I need your help. I need to make a new boundary condition and I am using codedFixedValue. Unfortunately I can't solve it. it is a differential equation like this: d(P − R1*Q)/dt +(1/R2*C) *(P(t=0) − R1*Q) =Q*C P and Q are respectively the pressure and the flow rate in the same outlet where I want to apply the equation. R1, C, R2 are constants. Would anyone be kind to help me? So far I have managed to implement the constants, the average flow rate in the outlet and the time read, but I have stuck on the derivative. :( Another question: the pressure I enter must already be divided by density or does OpenFoam do it? |
can no one help me? I just need some ideas for the derivative
|
Quote:
Hi, I am also trying to implement a custom boundary condition (for the first time), so we may be able to help each other. Can you show me the code you have so far? Quote:
That depends on the solver. p_rgh = p - rho*gh |
Hi, the code I have so far is in this post. But now I need to be able to implement the derivative.
https://www.cfd-online.com/Forums/op...tml#post773341 |
Quote:
I think you are a more advanced user than I am. Hopefully, this post will help you with the derivative: https://www.cfd-online.com/Forums/op...tml#post328925 |
Thank you for the link. What do you have to do? Maybe I can help you
|
Yes! It was just what I needed! Thank you
|
Thank you very much for your helps and guides.
|
|
Hello Rohit,
May I assume that the tortuosity field (u) is already defined in the entire domain as part of your problem? I'm guessing also that the e unit vector is constant and set on the boundary condition, Is that right? In such case you may want to adapt the following code to your needs: Code:
inlet |
Quote:
Hello Carlos, Thanks a lot for this code, it helps me a lot. I still have to do a few things before I can run a simulation, but I will let you know if everything works. You were right in both your assumptions - the tortuosity field is already defined in the entire domain, and the unit vector is a constant that only appears in the boundary condition. Could you please help me understand your code a bit better? I didn't fully understand the lines Code:
// Set the equation on each face of the patch what does the ()[facei] do? do we not need to specify somewhere that the expression should evaluate to zero? Also, how do you know which libraries to include in codeOptions? I hope these questions are not stupid or too basic. |
No stupid questions at all! It can be quite frustrating to understand these kind of things (I've been there), even now I'm just trying to make myself comfortable with how the code works, so maybe my explanation is not quite exact. If any of you can improve this explanation do not hesitate in letting me know!
Code:
scalarField& field = *this; Quote:
Let me explain this a little more. forAll is not a function nor a method. It's a macro. Typically macros are writer in upper letters to avoid confusion, but smart developers of OF consider it is more readable this way. The macro is defined as: Code:
#define forAll(list, i) \ Code:
for (Foam::label facei=0; facei<(field).size(); facei++) Quote:
I've compressed all these step by chaining them together, but what is really going on can be written as follows: Code:
// Get the temporal object nf Quote:
I hope that helps you understand what is going on! |
Quote:
Thank you for your reply. It was just detailed enough for me to understand and to help me to navigate through the source code. I have one last question. Should I not somehow specify that the expression has to evaluate to zero at the surfaces? Or is that what the code already means? I also have a comment that might help other beginners like me. The operator () has been redefined in OpenFOAM. Not knowing this was confusing for me in the beginning. Link: https://cpp.openfoam.org/v7/classFoa...81a2dd93376d82 |
Glad to know it helped to you! Concerning the other questions you have:
Quote:
So the class is a GeometricField object, particularized with a set components in a template. The first one is the type of data contained in the field (vector in this case), the second (fvPatchField) is related with the boundary conditions and how to treat them, and the last one is the way it stores the information. volMesh stores the information in the cell centers, in contrast surfaceMesh stores them in the face centers and pointMesh does it in the vertices. The fvPatchField is read from the boundary condition definition. When you define a boundary condition the file has this form: Code:
dimensions [0 2 -2 0 0 0 0]; Quote:
It is a good point to remark these doubts as for sure more people are struggling with the same issues. I hope my answers serve you, let me know if is it still unclear to you! |
Quote:
Hello! Thank you for the explanation about GeometricField objects - it helps me understand better what OpenFOAM is doing. I think you misunderstood what I am trying to implement. I don't want to set the value of the field at the boundaries to zero. I want the expression to evaluate to zero at the boundaries. So the tortuosity or u should not be zero at the boundaries. I would like OpenFOAM to assign a value to u such that the expression becomes zero at the boundaries. Is this even possible? |
Ok, now I'm getting you. Sorry, I totally missed the point. In such a case what you want is to change u in the boundaries, so the field validate your condition. Right?
I've been thinking about it and I think you need further information. Let me explain: In this case you need to work with a boundary condition in u (tortuosity field) which is the one related to the condition. You can set a gradient into this field, but your condition does not totally define the expected value, only part of its information. What you're asking to is that, when subtracted to the resultant vector is perpendicular to . But there are infinite number of vectors that can fulfill that request! https://i.ibb.co/QFh601x/condition-visualized.png You can add a corrector term to other expression to ensure that this condition is satisfied, but you need further definition on this gradient. Also you need to take into account that the relevant information to OpenFoam is the value of the gradient projected on the line connecting the face center and the cell center. This is the factor that will affect the rest of your field. If you figure out a way to define it, then it can be implemented. |
Quote:
Yes, that's true! I didn't think about that. Thank you! We are still trying to understand the problem (the equations to be solved and the BCs), so it is very much possible that something is missing or even wrong. Do you by any chance have an example of a BC in which the value inscribed on the field was somehow determined by OpenFOAM? I am very curious to see what the implementation would look like. |
Thinking about it, the condition can be applied if the normal is pointing to the cell center. If you're working with simple meshes there's a good chance that this is the case. If you have a big incidence of non-orthogonality then this approach could lead to some numerical errors, but maybe these error can be assumed. You can try this approach as a first approximation and see is it fits your results.
I've been recently working through the book "The Finite Volume Method in Computational Fluid Dynamics", there is a chapter which tell you how OpenFoam deals with the non-orthogonality and some strategies to reduce the errorr. The book is openly available, so feel free to take a look on it! |
Hello, I was finally able to run a simulation with the code that you sent me, and I got the following error:
Code:
--> FOAM FATAL ERROR: Do you know what might be the cause of the error? |
All times are GMT -4. The time now is 07:57. |