|
[Sponsors] |
August 11, 2020, 03:57 |
Custom von Neumann boundary condition
|
#1 |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Hello,
I am trying to implement the following boundary condition in OpenFOAM: where,
Code:
FSI { type groovyBC; value uniform 0; valueExpression "0"; fractionExpression "0"; //0..Neumann, 1..Dirichlet //Neumann with value equal to e_vec*normalvector variables "e_dot_n=vector(1,0,0) & normal()/mag(normal());"; gradientExpression "e_dot_n"; } I wasn't able to install Swak4FOAM with OpenFOAM 8, and in general I would learn to know how to code a boundary condition by myself. I found some tutorials for Dirichlet boundary conditions. Could someone please help me with implementing this BC? Thanks in advance! |
|
August 11, 2020, 05:24 |
|
#2 |
New Member
Jesper R. K. Qwist
Join Date: Dec 2017
Posts: 22
Rep Power: 8 |
Hi,
Search for programming course by Pavanakumar Mohanamuraly or look in the book by Moukalled about OpenFOAM. You can find what need in these references. https://pavanakumar.github.io/compre...am/of_tut.html https://www.amazon.com/Finite-Method.../dp/3319168738 Good luck, Jesper |
|
August 12, 2020, 04:02 |
|
#3 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Quote:
Hello Jesper, Thank you for the references. I already have the book by Moukalled. Starting from page 747, the book explains how to define a custom boundary condition. In my case, I do not want the whole patch to have the same constant gradient. The value on each face in the patch is dependent on the orientation of the face, and I do not know how to implement this. The tutorials by Pavanakumar do not cover custom boundary conditions at all. |
||
August 12, 2020, 14:21 |
|
#4 |
Senior Member
Gerry Kan
Join Date: May 2016
Posts: 347
Rep Power: 10 |
Dear Rojit:
At the risk of telling you something you might already know ... If you have to introduce your own gradient, may I suggest using the fixedGradient boundary condition as reference (FOAMHOME/src/finiteVolume/fields/fvPatchFields/basic/fixedGradient). The member functions responsible for altering the gradients are located in either evaluate() or updateCoeffs(). fixedGradientFvPatchField is inherited from fvPatchField, which in turn is inherited from fvPatch. In fvPatch there is a variable nf, which returns the face normal vector of each surface belonging to the same patch. I assume your gradient is fixed, only the dot product needs changing. In that case you only need to calculate the direction cosine and multiply it with your gradient magnitude. Here is a call graph of fvPatch, as well as the declaration of fixedGradient for reference. Again if this is something you know already please accept my apologies for the repetition. Hope that helps, Gerry. |
|
October 29, 2020, 07:22 |
|
#5 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Quote:
Hello Gerry, sorry for the late reply. Thank you for your suggestions, and for the very good summary on what/where to look at to modify boundary conditions in OpenFOAM. I think what you mentioned with modifying fixedGradient is the easy approach if the gradient is fixed. Unfortunately, I need to apply this boundary condition on a curved surface and hence the angle between the vectors will be different for each cell. |
||
October 29, 2020, 07:27 |
|
#6 |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
It took some time, but I managed to implement the boundary condition. And I get the same results I did with Swak4Foam. I will post my code here with as many details as possible in the comments in case it will help someone else.
Code:
FSI //name of patch { type codedMixed; // Constructs a new boundary condition on-the-fly. // This boundary condition (BC) is derived from the 'mixed' BC and is a // Robin BC, which a linear blend of 'fixedValue' (Dirichlet) and // 'gradient' (von Neumann) BCs. The blending is specified using the // 'valueFraction' entry according to the equation given at: // https://www.openfoam.com/documentation/guides/latest/doc/guide-bcs-mixed.html // Header file: https://cpp.openfoam.org/v7/codedMixedFvPatchField_8H_source.html refValue uniform 0; refGradient uniform 0; valueFraction uniform 0; //1 - pure Neumann, 0 - pure Dirichlet name customBC; //The name of the dynamically created BC code #{ // Explanation: // Our starting position (this pointer) is a fvsPatchField, so we // have to use the methods made available by this class. // patch () returns an fvPatch object, which contains all the // geometrical information about the patch, such as the surface // normals // The method nf() does not return a vector field, but a // 'tmp<vectorField>' object which points to the relevant // information, but are not themselves the information we need. // The normals can be obtained by using the () operator (redefined // in OpenFOAM) // Get the reference of the mesh const fvMesh& mesh = patch().boundaryMesh().mesh(); // Set the unit vector const vector e(1, 0, 0); // Get the temporal object nf const tmp<vectorField> tmpNf = patch().nf(); // Get the vector field associated with the location specified by // tmpNf const vectorField& nf_p = tmpNf(); // Note that the () operator has been redefined in OpenFOAM. We use // this operator to get the vector field that we need. // Link: https://cpp.openfoam.org/v7/classFoam_1_1tmp.html#afdc36f6a5716b29a5d81a2dd93376d82 volVectorField e_feld ( IOobject ( "e_feld", db().time().timePath(), db(), IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedVector ( "e0", dimensionSet(0, 0, 0, 0, 0, 0, 0), e ) ); // Get a reference of the vector field in current patch const vectorField& e_feld_p = e_feld.boundaryField()[patch().index()]; // Setting the gradient field for the boundary condition this->refGrad() = e_feld_p & nf_p; #}; codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude #}; } Last edited by RGS; October 29, 2020 at 18:00. |
|
October 29, 2020, 09:48 |
|
#7 |
Senior Member
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 15 |
Quote:
|
|
October 29, 2020, 10:26 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
Quote:
Code:
FSI { type codedMixed; name customBC; refValue uniform 0; refGradient uniform 0; valueFraction uniform 0; code #{ // Set gradient field for the boundary condition this->refGrad() = vector(1,0,0) & patch().nf(); #}; codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; } https://www.openfoam.com/documentati...d.html#details |
||
October 30, 2020, 04:26 |
|
#9 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Quote:
Thank you for simplifying my code. I did not know that it can be written in one line! And yes, I know that I created an entire volume field to get some information about a patch, but I did not know how else I can do it. I am still quite a novice OpenFOAM user and I think I make mistakes like this very often. The simplified code you posted is also much easier to understand. Regarding OpenFOAM from ESI - I came across this feature (and some others) last week and I spoke to my boss about shifting to the ESI distribution. Unfortunately I do not get to decide which version of OpenFOAM we use. But thank you for mentioning it. |
||
October 30, 2020, 04:29 |
|
#10 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Quote:
I don't know how to implement this with the fixedGradient BC. The patch is a curved surface, and so each cell face has a normal pointing in a different direction. Maybe it is possible to implement it using a dictionary? Or maybe I am missing something that should be very obvious, because Gerry also suggested using fixedGradient. |
||
October 30, 2020, 18:11 |
|
#11 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
Quote:
Original OpenFOAM author(s)? |
||
November 1, 2020, 08:20 |
|
#12 | |
Member
Rohit George Sebastian
Join Date: May 2017
Posts: 41
Rep Power: 8 |
Quote:
I saw your post in Linkedin a few days back. I just didn't realise that you were the author of the post. Thank you for sharing a link to the thread. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Table bounds warnings at: END OF TIME STEP | CFXer | CFX | 4 | July 16, 2020 23:44 |
My radial inflow turbine | Abo Anas | CFX | 27 | May 11, 2018 01:44 |
several fields modified by single boundary condition | schröder | OpenFOAM Programming & Development | 3 | April 21, 2015 05:09 |
Question about heat transfer coefficient setting for CFX | Anna Tian | CFX | 1 | June 16, 2013 06:28 |
CFX fails to calculate a diffuser pipe flow | shenying0710 | CFX | 7 | March 26, 2013 04:13 |