|
[Sponsors] |
November 7, 2021, 06:38 |
Coding a new boundary condition
|
#1 |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
Hello,
I would like to code a new fixedValue boundary condition where I assign the value of each face center to the its corresponding x-coordinate. I would like to know what is the correct procedure for implementing the boundary condition within openFoam. Currently, I have: Code:
void Foam::test::updateCoeffs() { if (updated()) { return; } const vectorField& Cf = patch().Cf(); scalarField result (Cf.size(), Zero); forAll(result, faceI) { const scalar x = Cf[faceI].x(); result[faceI] = x; } operator==(result); fixedValueFvPatchScalarField::updateCoeffs(); } Code:
void Foam::test::updateCoeffs() { if (updated()) { return; } const vectorField& Cf = patch().Cf(); scalarField& field = *this; forAll(field, faceI) { const scalar x = Cf[faceI].x(); field[faceI] = x; } fixedValueFvPatchScalarField::updateCoeffs(); } |
|
November 7, 2021, 10:32 |
|
#2 |
Member
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9 |
Do you need to create a new BC just for that? You can use the codedFixedValue BC:
https://www.openfoam.com/documentati...xed-value.html |
|
November 7, 2021, 11:14 |
|
#3 | |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
Quote:
Hi, I am aware of those coded boundaries. But I would like to create a new one for coding practice. If both approaches are valid what is the advantage of overloading the == operator? Isn't it cleaner to just change the value of the field? |
||
November 7, 2021, 15:28 |
|
#4 |
Member
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9 |
In this case, you should use the version with operator==
I think you will find the detailed answer in the following thread post #2: Difference between = and == |
|
November 8, 2021, 06:45 |
|
#5 | |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
Quote:
Thank you for the reply. Just one further comment. You can see in here: https://cfd-training.com/2018/05/07/...dedfixedvalue/ and http://www.wolfdynamics.com/wiki/pro...streamINIT.pdf (I know that they are not official OF sources) That the authors use the approach with *this. Is the == doing anything else apart form assigning the value inside the parenthesis to the field? If not, is it worth having an extra vector on the boundary to just store calculation and afterwards assign it to the field? Isn't this more inefficient? |
||
November 8, 2021, 12:10 |
|
#6 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
For patch fields. Compare the implementation of '==' vs '=': https://develop.openfoam.com/Develop...chField.C#L378 https://develop.openfoam.com/Develop...chField.C#L554 I don't think that you will see any difference in performance or overhead, or its meaning. |
||
November 8, 2021, 12:43 |
|
#7 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
If you are setting up the fields, there is no reason not to set them directly, like in your second code snippet. |
||
November 8, 2021, 13:14 |
|
#8 | |
Member
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9 |
Quote:
Thank you very much for your clarification. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wind turbine simulation | Saturn | CFX | 60 | July 17, 2024 06:45 |
Fatal overflow in linear solver. | iamnotfajar | CFX | 9 | October 28, 2020 05:47 |
Radiation in semi-transparent media with surface-to-surface model? | mpeppels | CFX | 11 | August 22, 2019 08:30 |
Error finding variable "THERMX" | sunilpatil | CFX | 8 | April 26, 2013 08:00 |
External Radiation Boundary Condition for Grid Interface | CFD XUE | FLUENT | 0 | July 9, 2010 03:53 |