CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   mixed boundary condition (https://www.cfd-online.com/Forums/openfoam-pre-processing/225340-mixed-boundary-condition.html)

YannGuyot March 24, 2020 04:33

mixed boundary condition
 
Dear all,


I have a probably newbie question but i can find the answer by myself
I want to implement convective heat transfer using mixed type BC.
After checking on the web i found that it could be somethink like that:
Code:



top
  {
    type            mixed;
    refValue        298;
    refGradient    0;
    valueFraction  1./(1. + 0.6/(1.*deltaCoeffs()));
  }

Unfortunately I am not able to pass properly the expression in valueFraction (the solver seems to take only the "1." in front, so corresponding to dirichlet BC)


So my question is simple (and probably stupid), how to pass an expression in openfoam, (for example fixedValue 273.15+25 instead of 298.15)


Thank you very much for help


Yann

peyman.havaej March 24, 2020 06:10

Dear Yann
you can use groovyBC.

check the openfoamwiki and find more information and the capabilities of groovyBC.

YannGuyot March 24, 2020 06:13

Dear Paymen


I use openfoam7 and it seems that groovyBC is not an option anymore
In the other hand, i tried codedMixed BC typr as the following


Code:

    top
    {
        type            codedMixed;
        refValue        uniform 0;
        refGradient    uniform 0;
        valueFraction  uniform 1;

        name    robin;  // name of generated BC

        code
        #{
            const scalarField& delta = patch().deltaCoeffs();
            this->refValue() = 298;
            this->refGrad() = 0.;
            this->valueFraction() = 1.0/(1+0.6/(1.0*delta));
        #};
    }

Unfortunately it doesnt give ant difference

alexeym March 26, 2020 05:12

Hi,

What solver do you use? What is 0.6 (thermal conductivity? thermal diffusivity? just a random number?)?

YannGuyot March 26, 2020 09:55

hello,

I am using buoyantPimpleFoam, and the parameter corresponds to water thermal conductivity, I just don't know how to get it properly from thermophysical properties, (If you know I will be glad to know too :) )

I also realize that I made a mistake, according to this well made document:

https://foamingtime2.files.wordpress...ction-bc_1.pdf

It should be
Code:


    top
    {
        type            codedMixed;
        refValue        uniform 0;
        refGradient    uniform 0;
        valueFraction  uniform 1;

        name    robin;  // name of generated BC

        code
        #{
            const scalarField& delta = patch().deltaCoeffs();
            this->refValue() = 298;
            this->refGrad() = 0.;
            this->valueFraction() = 1.0/(1+0.6/(1.0/delta));
        #};
    }

This seems to work

alexeym March 26, 2020 10:06

Or

Code:

this->valueFraction() = 1.0/(1+0.6*delta);
You can find a way to lookup kappa in, for example, TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/temperatureCoupledBase/temperatureCoupledBase.C.

YannGuyot March 26, 2020 10:22

Sorry i am newbie, I don't really understand how to lookup variables like in the example

alexeym March 26, 2020 10:34

Since the example is general, it has lots of checks, you can get rid of them for your concrete situation. You have mentioned water, so I assume, you use fluidThermo, so the code for kappa lookup is:

Code:

            typedef compressible::turbulenceModel turbulenceModel;

            word turbName(turbulenceModel::propertiesName);

            if
            (
                mesh.foundObject<turbulenceModel>(turbName)
            )
            {
                const turbulenceModel& turbModel =
                    mesh.lookupObject<turbulenceModel>(turbName);

                return turbModel.kappaEff(patchi);
            }
            else if (mesh.foundObject<fluidThermo>(basicThermo::dictName))
            {
                const fluidThermo& thermo =
                    mesh.lookupObject<fluidThermo>(basicThermo::dictName);

                return thermo.kappa(patchi);
            }

First branch gets kappa value from turbulence model, else branch gets it directly from thermo object (if turbulence model is not available). If you use turbulence model, you can get rid of conditionals and directly use corresponding branch.

In BC you can access mesh object like this, for example:

Code:

const fvMesh& mesh = patch_.boundaryMesh().mesh();

YannGuyot March 26, 2020 11:01

I think i miss something (sorry, i am really bad at c++)


Code:

      code
      #{
          const scalarField& delta = patch().deltaCoeffs();
          const fvMesh& mesh = patch_.boundaryMesh().mesh();
          const fluidThermo& thermo = mesh.lookupObject<fluidThermo>(basicThermo::dictName);
          this->refValue() = 298;
          this->refGrad() = 0;
          this->valueFraction() = 1.0/(1.0+thermo.kappa(patchi)/(1.0/delta));
      #};


alexeym March 26, 2020 11:12

I do not think you have basicThermo in coded BC. You should use codeInclude section to add necessary includes. Something like:

Code:

codeInclude
#{
    #include "fluidThermo.H"
#}


YannGuyot March 26, 2020 11:54

It is asking me a system/codeDict, I never have seen file like this so far.

alexeym March 26, 2020 13:22

It would be easier to figure out a cause of the problem if you post solver/compiler output. "Guess-what-is-wrong" game can take quite a long time.

YannGuyot March 27, 2020 07:43

Sure


Code:

--> FOAM FATAL ERROR:
cannot find file "/home/yann/Projet/system/codeDict"
    From function virtual Foam::autoPtr<Foam::ISstream> Foam::fileOperations::uncollatedFileOperation::readStream(Foam::regIOobject&, const Foam::fileName&, const Foam::word&, bool) const
    in file global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C at line 538.

FOAM exiting


alexeym March 27, 2020 08:20

Could you post final version of the BC? It seems, you have lost semi-colon, since:

Code:

A special form is if the 'code' section is not supplied. In this case
the code gets read from a (runTimeModifiable!) dictionary system/codeDict
which would have a corresponding entry

Basically, it looks for system/codeDict only if there is no inline code section.

YannGuyot March 27, 2020 08:24

Here you go



Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0";
    object      T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 1 0 0 0];

internalField  uniform 283;

boundaryField
{
  top
  {
      type            codedMixed;
      refValue        uniform 0;
      refGradient    uniform 0;
      valueFraction  uniform 1;

      name    robin;  // name of generated BC

      codeInclude
      #{
          #include "fluidThermo.H";
      #}
     
      code
      #{
          const scalarField& delta = patch().deltaCoeffs();
          const fvMesh& mesh = patch_.boundaryMesh().mesh();
          const fluidThermo& thermo = mesh.lookupObject<fluidThermo>(basicThermo::dictName);
          this->refValue() = 298;
          this->refGrad() = 0;
          this->valueFraction() = 1.0/(1.0+thermo.kappa(patchi)/(1.0/delta));
      #};
    }

  ground
  {
      type            zeroGradient;
  }

  sym
  {
      type            zeroGradient;
  }
}


alexeym March 27, 2020 08:31

Semicolon is missing after codeInclude entry (so code entry is eaten by codeInclude). It should be:

Code:

  top
  {
      type            codedMixed;
      refValue        uniform 0;
      refGradient    uniform 0;
      valueFraction  uniform 1;

      name    robin;  // name of generated BC

      codeInclude
      #{
          #include "fluidThermo.H";
      #}; // <-- here
     
      code
      #{
      ...


YannGuyot March 27, 2020 08:37

Of course, thank you so much


PS: j'espere que tout va bien pour toi dans l'est

YannGuyot March 27, 2020 09:33

after adding the semicolon, I have another error:


Code:

Using dynamicCode for patch top on field T at line 26 in "/home/yann/Projet/0/T.boundaryField.top"
Creating new library in "dynamicCode/robin/platforms/linux64GccDPInt32Opt/lib/librobin_53fcadabbc93dcdfc6e8ad4486434b09ccd4ede5.so"
Invoking "wmake -s libso /home/yann/Projet/dynamicCode/robin"
wmake libso /home/yann/Projets/dynamicCode/robin
    ln: ./lnInclude
    wmkdep: mixedFvPatchFieldTemplate.C
could not open file fluidThermo.H for source file mixedFvPatchFieldTemplate.C due to No such file or directory
    Ctoo: mixedFvPatchFieldTemplate.C
/home/yann/Projet/0/T.boundaryField.top:35:25: warning: extra tokens at end of #include directive
/home/yann/Projet/0/T.boundaryField.top:35:10: fatal error: fluidThermo.H: Aucun fichier ou dossier de ce type
compilation terminated.
/opt/openfoam7/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/mixedFvPatchFieldTemplate.o' failed
make: *** [Make/linux64GccDPInt32Opt/mixedFvPatchFieldTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/robin/platforms/linux64GccDPInt32Opt/lib/librobin_53fcadabbc93dcdfc6e8ad4486434b09ccd4ede5.so"


file: /home/yann/Projet/0/T.boundaryField.top from line 26 to line 39.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

FOAM exiting

Any idea?

alexeym March 27, 2020 09:40

The warning is self-explanatory, you do not need ; after #include "fluidThermo.H".

The error is due to missing -I flags. You need to add codeOptions section, there you put -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude:

Code:

codeOptions
#{
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude
#};


YannGuyot March 27, 2020 10:06

Code:

Using dynamicCode for patch top on field T at line 26 in "/home/yann/Projet/0/T.boundaryField.top"
Creating new library in "dynamicCode/robin/platforms/linux64GccDPInt32Opt/lib/librobin_7dab6cfe54673a55a3892dc8057acb21ae82c018.so"
Invoking "wmake -s libso /home/yann/Projet/dynamicCode/robin"
wmake libso /home/yann/Projet/dynamicCode/robin
    ln: ./lnInclude
    wmkdep: mixedFvPatchFieldTemplate.C
could not open file compressibleTransportModel.H for source file mixedFvPatchFieldTemplate.C due to No such file or directory
    Ctoo: mixedFvPatchFieldTemplate.C
In file included from /home/yann/Projet/0/T.boundaryField.top:37:0:
/opt/openfoam7/src/thermophysicalModels/basic/lnInclude/fluidThermo.H:39:10: fatal error: compressibleTransportModel.H: Aucun fichier ou dossier de ce type
 #include "compressibleTransportModel.H"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
/opt/openfoam7/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/mixedFvPatchFieldTemplate.o' failed
make: *** [Make/linux64GccDPInt32Opt/mixedFvPatchFieldTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/robin/platforms/linux64GccDPInt32Opt/lib/librobin_7dab6cfe54673a55a3892dc8057acb21ae82c018.so"


file: /home/yann/Projet/0/T.boundaryField.top from line 26 to line 46.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.


Still not working


All times are GMT -4. The time now is 16:04.