CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Coding a new boundary condition

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By olesen
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 7, 2021, 06:38
Default Coding a new boundary condition
  #1
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
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();
}
But I believe this can also be achieved with:


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();
}
Which version is more correct in OpenFOAM? overloading the == operator, or change directly the values of the field?
Shibi is offline   Reply With Quote

Old   November 7, 2021, 10:32
Default
  #2
Member
 
s1291's Avatar
 
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9
s1291 is on a distinguished road
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
s1291 is offline   Reply With Quote

Old   November 7, 2021, 11:14
Default
  #3
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Quote:
Originally Posted by s1291 View Post
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

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?
Shibi is offline   Reply With Quote

Old   November 7, 2021, 15:28
Default
  #4
Member
 
s1291's Avatar
 
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9
s1291 is on a distinguished road
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 ==
s1291 is offline   Reply With Quote

Old   November 8, 2021, 06:45
Default
  #5
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Quote:
Originally Posted by s1291 View Post
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 ==



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?
Shibi is offline   Reply With Quote

Old   November 8, 2021, 12:10
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by s1291 View Post
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 ==
Careful. That discussion about == vs = pertains to GeometricFields, not to plain Fields!


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.
s1291 likes this.
olesen is offline   Reply With Quote

Old   November 8, 2021, 12:43
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Shibi View Post
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();
}
Which version is more correct in OpenFOAM? overloading the == operator, or change directly the values of the field?

If you are setting up the fields, there is no reason not to set them directly, like in your second code snippet.
s1291 likes this.
olesen is offline   Reply With Quote

Old   November 8, 2021, 13:14
Default
  #8
Member
 
s1291's Avatar
 
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9
s1291 is on a distinguished road
Quote:
Originally Posted by olesen View Post
Careful. That discussion about == vs = pertains to GeometricFields, not to plain Fields!


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.
Dear Mark,

Thank you very much for your clarification.
s1291 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 01:21.