Dear Philip,
thanks for your reply! I tried by simplifying the code, but I get the same error lnInclude/Henry.C:132:53: error: passing ‘const Foam::fvPatchField<double>’ as ‘this’ argument of ‘void Foam::fvPatchField<Type>::operator=(const Foam::UList<T>&) [with Type = double]’ discards qualifiers [-fpermissive] IndexTest[0][0].boundaryField()[patchi] = newPatchValues; This is the code: Quote:
Quote:
Simone |
I tried also to copy the code above outside the function, directly in a *.H in the folder reactingTwoPhaseEulerFoam in order to substitute
Quote:
Quote:
error: passing ‘const Foam::fvPatchField<double>’ as ‘this’ argument of ‘void Foam::fvPatchField<Type>::operator=(const Foam::UList<T>&) [with Type = double]’ discards qualifiers [-fpermissive] IndexTest[0][0].boundaryField()[patchi] = newPatchValues; Any idea? Thanks Simone |
Dear Philip,
I have followed your comments on how to update the BC contents with coding in solver. I want to write a Dirichlet BC with nonuniform values for omega at the wall. The omega should be calculated from friction velocity for each cell of the wall (I calculated it from U field). My solver is simpleFoam. I use the method you mentioned below for calculating omega in the simpleFoam solver. I have written my code but the problem is I don't know how can I insert the calculated values in omega field? (BTW I am not experienced in coding in c++) any hints are really appreciated. Many thanks in advance. Amir Quote:
|
Hi Amir,
Can you give your code that you have so far? And where are you inserting this code? Philip |
Quote:
I don't think my code structure is easily understandable. First I calculated the velocity and the distance from the wall for the centre of the cells on the wall. Then, I used the dimensionless van Driest near-wall velocity profile and used an iterative method (Newton-Raphson method) to calculate the friction velocity in each cell face of the wall, and calculated omega at the wall by the method that has been mentioned in Wilcox (2006) for both smooth and rough walls. the problem is I don't know how can I insert the calculated omega into omega field. Because the omega has not been defined in the main solver and it is defined in turbulence models. I simply tried to define a volScalarField for omega in the createFields.H and saving the calculated omega in it, but it seems that the solver does not use it. I started my code exactly after the starting loop of the simpleFoam Code:
while (simple.loop()) Thank you very much for your help in advance, Regards, Amir |
Hi Amir,
The cleanest method would be to write a new boundary condition for omega where you can directly update the boundary values for omega. However, it is possible to do it by adding code to your solver: one way to do it would be to "look up" the omega field from the turbulence model using the objectRegistry (this keeps track of all the significant objects) and then update it using your proposed method (however, this method requires const_cast which is evil: const cast is evil). For example, you could do the following: Code:
while (simple.loop()) Also, you would need to add the following header file at the top of the solver e.g. just under #include "fvCFD.H": Code:
#include "fixedInternalValueFvPatchFields.H" But if you are trying to create an omega wall function boundary condition, I would suggest making a copy of omegaWallFunctionFvPatchScalarField and renaming to myOmegaWallFunctionFvPatchScalarField and then you can edit the code in the updateCoeffs() function. Philip |
Quote:
I have learned a lot from this post and this thread. Actually, I want to use omega on the wall (y=0), and not as a wall function, that is why I have not tried changing the omegaWallFunction. In this case, I should use codedFixedValue instead of fixedInternalValueFvPatchScalarField in your code? Regards, Amir |
Hi Amir,
OK, so if you intend to set the value of omega at the patch faces then I suggest you use the fixedValue patch type (for your patch in 0/omega); then the code becomes more simple: Code:
while (simple.loop()) Philip |
Dear Philip,
Hope you have been monitoring this thread. I try to compile the following code (based on yours) for fixedGradient but I have the following error. I wonder if you could tell what the problem is. I tryed "#include "fixedGradientFvPatchFields.H.H" but it didn't help. Code: Code:
**body of solver is here** Code:
In file included from /data/OpenFoams/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/token.H:46:0, Code:
fixedGradientFvPatchVectorField& PotEpatch = Best regards, Tar |
Hi Tar,
Yep, it seems using boundaryFieldRef is the correct thing to do, e.g. as discussed here link. Philip |
Dear Philip,
Thank you very much for your answer. Your link helped me a lot to understand the reason. Best regards, Tar |
Dear Philip,
Sorry to bother you again. I faced one more problem. My code is following: Code:
label patchID = mesh.boundaryMesh().findPatchID("frontAndBack"); Code:
dynamicBC.H: In function ‘int main(int, char**)’: A also noticed that if I remove [faceI] from this line: Code:
PotEpatch.gradient()[faceI] = PotE; Best regards, Tar |
One more update:
When I tried this Code:
PotEpatch.gradient()[faceI] = PotE.internalField()[faceI]; Best regards, Tar |
Quote:
What are you trying to set as the boundary gradient? It is not clear to me what you are actually trying to do. Philip |
OK, I understand.
Something like the following should work: Code:
if By the way, the following does not make sense: Code:
PotE.internalField()[faceI] |
Quote:
Thank you very much for your advice. It works now and I understood my error and algorithm. I also would like to ask two more questions (hope last questions) if you don't mind: 1. In your suggestion I get uniform boundary condition, but I would like to get nonuniform. I wrote the following code to cope with this problem, it compiles and seems logical but I kindly ask you to take a look (maybe I still have some silly mistakes): Code:
if For instance I would like to realize something like this: = You wrote some information about the tangential part in this post https://www.cfd-online.com/Forums/op...tml#post381068 but to be honest I am not fully sure how to do this. Thanks in advance again. Best regards, Tar |
Your proposed code for applying a spatially varying condition look fine to me.
As regards the tangential gradient at the boundary, OpenFOAM uses the tangential gradient at the closest cell-centre (so-called patch-internal-field) by default i.e. extrapolates tangential gradient from the internal field using a zero gradient approach. it is possible to directly calculate the tangential gradient at the boundary using, for example, the finite area method (you can google this for more information); however, I suggest you try the former method first. An example approach could be: Code:
// Calculate the gradient of PotE everywhere |
Dear Philip,
Thank you for your answer, it helps me a lot. But when I try to compile your code it shows the following error (openFoam 4.1): Code:
dynamicBC.H: In function ‘int main(int, char**)’: Now I will try to do the same for the tangential laplacian. When I get something I will share my results in this topic. Thank you very much for your help again. Best regards, Tar |
Hi Tar,
Removing the "const" in this case will fix it; also, you could use boundaryField instead of boundaryFieldRef for the boundary of gradPotE. Both will act the same. Philip |
All times are GMT -4. The time now is 13:25. |