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

Issue with Implementing Custom Boundary Condition using codedMixed in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Lorenzo210
  • 1 Post By aliyah.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 2, 2023, 10:19
Default Issue with Implementing Custom Boundary Condition using codedMixed in OpenFOAM
  #1
Member
 
Al
Join Date: May 2019
Posts: 37
Rep Power: 7
aliyah. is on a distinguished road
Hello everyone,

I am currently trying to implement the following custom boundary condition in OpenFOAM:

\left( D_B \frac{d\phi}{dy} \right)_{y=0} = -\left( \frac{D_T dT}{T_\infty} \right)_{y=0}




The boundary condition relates the gradient of a scalar field (phi) at a certain boundary (y=0) with the gradient of temperature. I have decided to use codedMixed for this purpose in the boundary field of phi.

Below is the code I've written, which seems to work up to a point:

Code:
fluid_to_solid
{
    type            codedMixed;
    value           uniform 5e-2;
    name            phitFlux;
    refValue        uniform 5e-2;       
    refGradient     uniform 0;      
    valueFraction   uniform 0;      //1 - Dirictlect ;  0 - Neumann

    codeInclude
#{
	#include "fvCFD.H"
#};

codeOptions
#{
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
  	-I$(LIB_SRC)/finiteVolume/lnInclude \
		-I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/solidThermo/lnInclude 
#};

codeLibs
#{
	-lmeshTools \
	-lfiniteVolume
#};

code
#{
    // Get current patchi
    const label patchi = patch().index();

    // Accessing the temperature field of the current patch
    const volScalarField& TS=db().lookupObject<volScalarField>("T");

    // I am facing issues while trying to compute snGrad for the temperature field
    // When I use snGrad(), I encounter an error. However, removing .snGrad() (like shown below) lets it run without any problem.
    const scalarField& TG = TS.boundaryField()[patchi];  // How can I add .snGrad() here?

    // This is the phi of the current patch, which is not utilized in the code right now
    const scalarField& phip(*this);

    // Constants of the equation
    const scalar C1 = 1;
    const scalar C2 = 2;

    // Here, this->refGrad() represents the left side of the equation concerning phi.
    this->refGrad() = C1*C2*TG;  
}
#};

}
My specific issue arises when trying to calculate the snGrad of the temperature field. When I add .snGrad() to the line const scalarField& TG = TS.boundaryField()[patchi]; (I mean when I write const scalarField& TG = TS.boundaryField()[patchi].snGrad() I receive an error. Without .snGrad(), the code runs without any issues.

Could someone kindly provide insights or corrections on how I can successfully calculate the snGrad for the temperature field in the above context?

Thank you in advance!
aliyah. is offline   Reply With Quote

Old   November 3, 2023, 11:36
Default
  #2
Member
 
Al
Join Date: May 2019
Posts: 37
Rep Power: 7
aliyah. is on a distinguished road
I managed to add snGrad using the following code

Code:
// Access the entire temperature field
const volScalarField& T = db().lookupObject<volScalarField>("T");

// Calculate the surface-normal gradient for the entire temperature field
const surfaceScalarField gradT = fvc::snGrad(T);

// Extract the values at the boundary of interest
const scalarField& gradT_boundary = gradT.boundaryField()[patchi];

// Here, this->refGrad() represents the left side of the equation concerning phi.
this->refGrad() = C1*C2*gradT_boundary;

But there is a problem still when i am running the code, after the first iteration, it gives me core dumped error

Code:
#0  Foam::error::printStack(Foam::Ostream&) at ??:?                                                                                                                                                                                        #1  Foam::sigFpe::sigHandler(int) at ??:?                                                                                                                                                                                                  #2  ? in /lib/x86_64-linux-gnu/libpthread.so.0                                                                                                                                                                                             #3  ? in /lib/x86_64-linux-gnu/libm.so.6                                                                                                                                                                                                   #4  Foam::log(Foam::Field<double>&, Foam::UList<double> const&) at ??:?                                                                                                                                                                    #5  void Foam::log<Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) at ??:?                                    #6  Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::log<Foam::fvPatchField, Foam::volMesh>(Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > const&) at ??:?                   #7  Foam::surfaceTensionModels::temperatureDependent::sigma() const at ??:?                                                                                                                                                                #8  Foam::phaseSystem::surfaceTensionCoeff(Foam::phasePairKey const&) const at ??:?                                                                                                                                                        #9  Foam::phaseSystem::surfaceTensionForce() const at ??:?                                                                                                                                                                                 #10  ? in ~/OpenFOAM/ubuntu-v2006/platforms/linux64GccDPInt32Opt/bin/icoReactingMultiphaseInterFoamPhi2BrounNew2                                                                                                                           #11  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6                                                                                                                                                                                  #12  ? in ~/OpenFOAM/ubuntu-v2006/platforms/linux64GccDPInt32Opt/bin/icoReactingMultiphaseInterFoamPhi2BrounNew2                                                                                                                           Floating point exception (core dumped)
aliyah. is offline   Reply With Quote

Old   November 3, 2023, 12:02
Default
  #3
Member
 
Lorenzo
Join Date: Apr 2020
Location: Italy
Posts: 46
Rep Power: 6
Lorenzo210 is on a distinguished road
Hi aliyah,


It seems that something could be wrong with the surface tension rather than the BC.
Could you please provide the phaseProperties dict of your test case?


I guessed the error is due the surface tension force because of the following lines:


Quote:
#7 Foam::surfaceTensionModels::temperatureDependent:: sigma() const at ??:?

#8 Foam:haseSystem::surfaceTensionCoeff(Foam:hase PairKey const&) const at ??:?

#9 Foam:haseSystem::surfaceTensionForce() const at ??:?

Regards,
Lorenzo
aliyah. likes this.
Lorenzo210 is offline   Reply With Quote

Old   November 5, 2023, 06:51
Default
  #4
Member
 
Al
Join Date: May 2019
Posts: 37
Rep Power: 7
aliyah. is on a distinguished road
Quote:
Originally Posted by Lorenzo210 View Post
Hi aliyah,


It seems that something could be wrong with the surface tension rather than the BC.
Could you please provide the phaseProperties dict of your test case?


I guessed the error is due the surface tension force because of the following lines:





Regards,
Lorenzo
Hello Lorenzo,

Thanks for your tip. You were right. I was using a custom surface tension model and this custom surface tension model had logarithmic terms causing issues. When I used the abovementioned boundary condition, it resulted in negative values for the logarithm. I've now addressed this and things are working better.

Appreciate your help.

Best,
Lorenzo210 likes this.
aliyah. 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
Custom boundary condition in OpenFOAM saurcerer OpenFOAM 0 May 5, 2023 14:24
Question about different kinds of Boundaries and Boundary Conditions granzer Main CFD Forum 17 April 12, 2022 18:27
My radial inflow turbine Abo Anas CFX 27 May 11, 2018 02:44
Wrong flow in ratating domain problem Sanyo CFX 17 August 15, 2015 07:20


All times are GMT -4. The time now is 06:28.