CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

Space varying temperature boundary condition

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By crubio.abujas
  • 1 Post By crubio.abujas
  • 1 Post By crubio.abujas

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 19, 2021, 01:44
Default Space varying temperature boundary condition
  #1
Member
 
L S
Join Date: Apr 2016
Posts: 56
Rep Power: 7
silviliril is on a distinguished road
Dear All,

I have been trying to simulate nucleate boiling in OpenFOAM. With present model in phaseChangeHeatFoam the wall constant wall temperature can be applied throughout the wall having fixed value. Which generates a thin vapor layer first and then it breaks into several nucleation sites due to density difference. (See bottom nucleation image file attached below)

Now, What I want to do is, apply random value of wall temperature only at certain provided locations (also randomly chosen locations) in lookup table (see posx image file attached below).

I want the nucleation to start only at certain locations and not from entire wall.

I have tried to write following groovyBC boundary condition for temperature:

Code:
bottom
   {
	type groovyBC;
	valueExpression "data(pos().x)";
	value uniform 373.15;

	/*
	fields
	(
	pos().x T
	);
	*/

	lookuptables
	(
	{
	name data;
	outOfBounds clamp;
	fileName "$FOAM_CASE/temp.dat";
	}
	);
}
The temp.dat file is written as:

Code:
(
	(375 0.0005)
	(378 0.001)
	(377 0.0015)
	(380 0.002)
)
which specified, temperature vs. axial position in x direction data.

This is giving me a warning and a fatal error for the side walls as:

Quote:
--> FOAM Warning :
From function entry::getKeyword(keyType&, Istream&)
in file db/dictionary/entry/entryIO.C at line 78
Reading /home/arupdas/Liril/ONB/Test2DRand/0/T
found on line 50 the punctuation token ')'
expected either } or EOF


--> FOAM FATAL IO ERROR:
Cannot find patchField entry for walls
Is there any mistake I have done in using groovyBC? What will be the correct way to implement the said boundary condition?

Kindly help.
Attached Images
File Type: jpg botom nucleation.JPG (32.8 KB, 12 views)
File Type: jpg posx.JPG (22.9 KB, 8 views)

Last edited by silviliril; July 19, 2021 at 03:07.
silviliril is offline   Reply With Quote

Old   July 20, 2021, 03:44
Default
  #2
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 118
Rep Power: 6
crubio.abujas is on a distinguished road
I haven't used GroovyBC before, but the program is complaining about a missing definition of the walls patch.

Can you share de 0/T file so we can check if there is something missing?
silviliril likes this.
crubio.abujas is offline   Reply With Quote

Old   July 20, 2021, 05:58
Default
  #3
Member
 
L S
Join Date: Apr 2016
Posts: 56
Rep Power: 7
silviliril is on a distinguished road
Thank you for replying.

I have managed to solve the problem. I did some mistake in understanding how lookup table actually works. I have attached the temperature file and .dat file for someone if they face similar issues.

But, I came to know that lookup table feature in groovyBC is only applicable for 1D data. e.g. Position of X axis and corresponding Temperate values.

For, 2D data, we need to user interpolation2DTable feature under codedMixed boundary condition. I need to provide temperature only on certain provided coordinates on heated wall patch.

I have written following boundary condition after reading another post from cfd-online.

Code:
 bottom
   {
	type codedMixed;
	refValue uniform 373.15;
	refGradient uniform 0;
	valueFraction uniform 0;
	redirectType lookupHeatFluxBC;

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

	code
	#{

	// Construct interpolation2DTable 
	fileName fName = "$FOAM_CASE/temp.dat";
	Foam::interpolation2DTable<scalar> lookupTableData(fName);

	// Example lookup values
	scalar lookupVal1 = 0.001;
	scalar lookupVal2 = 374;

	// Set variable gradient field
	// Looks up as-> lookupTableData(row,col) in tableData.dat
	this->refGrad() = lookupTableData(lookupVal1,lookupVal2);

	#};

   }
and lookup table is something like this:
Code:
(
(0.0001	((0.0001 374) (0.0002 375)))
(0.0002	((0.0001 378) (0.0002 376)))
)
where decimal values represents the X and Y coordinates in meters and 374 represents temperature value in Kelvin.

But, I am getting some erratic results, it is not applying the temperature spatially as I asked for, instead it is applying temperature (that too erratic) with time. What can be the issue? Where am I making mistake?
Attached Files
File Type: zip T_Temp.zip (991 Bytes, 3 views)
silviliril is offline   Reply With Quote

Old   July 20, 2021, 12:12
Default
  #4
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 118
Rep Power: 6
crubio.abujas is on a distinguished road
Hi Sabrina,

There are several things in the code you shared that make the code not working as described:
  • From the explanation I've understood that your intention is to set the value of the temperature, not the gradient of temperature. Using a codedMixture boundary condition you are using a hybrid boundary condition, part fixed and part gradient dependent. The weight fraction is the entry valueFraction. In the shated code you are setting it to be 0, which means only consider only the gradient part and ignore the fixed value. So to have the expected behaviour set this value to 1.
  • In the code you are also interpolating along fixed values (x=0.001, y=374) so you're impossing a uniform value on the entire patch, which I think is not the intended behavior.
  • Additionally, you're setting this fixed value to this->refGrad() , which is the value of the gradient, not the value of the fixedValue. So no surprise that you're having unexpected results.
Here is a code that I've tried and you may that do what I think you're trying to achieve. On OF7 this works fine, but on different openfoam versions the code may not work properly.

Code:
    hot
    {
        type            codedMixed;
        value           uniform 373.15;
        refValue        uniform 10;
        refGradient     uniform 0;
        valueFraction   1;   // <--   FixedValue not gradientValue
        redirectType    lookupHeatFluxBC;

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

        code
        #{

            fileName fName("$FOAM_CASE/temp.dat");
            Foam::interpolation2DTable<scalar> lookupTableData(fName);

            const vectorField& centers = this->patch().Cf();

            // Loop acros al the faces conforming the patch
            forAll(centers, facei)
            {
                // Interpolate the value of each of the faces. 
                // In the case I tested x corresponds with z so change this accordingly.
                scalar out = lookupTableData(
                        centers[facei].z(),
                        centers[facei].y()
                );
                // Set the value to refValue instead of refGrad() for each face

                this->refValue()[facei] = out;
            }
        #};

    }
Let me know if this code works for you, or if I missunderstood something.
silviliril likes this.
crubio.abujas is offline   Reply With Quote

Old   July 21, 2021, 02:33
Default
  #5
Member
 
L S
Join Date: Apr 2016
Posts: 56
Rep Power: 7
silviliril is on a distinguished road
This is like miracle. This worked like charm. Thanks for the help.
silviliril is offline   Reply With Quote

Old   August 16, 2021, 04:41
Default
  #6
New Member
 
Joao Coelho
Join Date: Jun 2021
Posts: 6
Rep Power: 2
jcoelho5 is on a distinguished road
Hey, do you know how to adapt this to OF9?

I guess the interpolate2DTable function is no longer present in this version; UniformTable instead. However, I am having a hard time adapting your code to it. Do you have any idea how to do it? My problem is related to how to change the code, and not on the uniform table generation in particular.

I really need to use OF9 since I am using the new feature of using a combination of thermophysical properties that were not compatible in previous versions.

Thank you very much!

Last edited by jcoelho5; August 16, 2021 at 05:26. Reason: add more info
jcoelho5 is offline   Reply With Quote

Old   August 31, 2021, 05:02
Default
  #7
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 118
Rep Power: 6
crubio.abujas is on a distinguished road
Hi Joao,

I've been looking around for some time on how to adapt the code to OF9. It seems that they have introduced a Function2 which is intended to combine all the two dimensional interpolation in one library.

The solution I found is a little bit cumbersome, but it should work.

On the boundary condition use:
Code:
hot
    {
        type            codedFixedValue;
        value           uniform 373.15;
        name          lookupHeatFluxBC;

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

        code
        #{
            const fvMesh& mesh = patch().boundaryMesh().mesh();

            dictionary F2Dict;
            IOobject FDictIO
            (
                "F2Dict", // name of the file
                mesh.time().path(), // path to where the file is
                mesh, // reference to the mesh needed by the constructor
                IOobject::MUST_READ // indicate that reading this dictionary is compulsory
            );
            F2Dict = IOdictionary(FDictIO);

            autoPtr<Function2<scalar>> function_
            (
                Function2<scalar>::New("function", F2Dict)
            );

            const vectorField& centers = this-> patch().Cf();

            forAll(centers, facei)
            {
                (*this)[facei] = function_->value(
                    centers[facei].y(),
                    centers[facei].z()
                );
            }
        #};

    }
With that code the boundary condition will look for a file named F2Dict on the case folder, where the definition of the table must be present.
Notice that I have changed the type of the boundary condition to codedFixedValue instead of codedMixed as it is more suited to the intended purpose. The asignation of the field values is the main significant change.

This file should look like this one:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  7
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "";
    object      F2Dict;
}

/* ------------------------------------------------------------------------- */

function    uniformTable;
low         (-50  0);
high        (230  140);

values      3 3
(
    ( 0 0 0 )
    ( 0 35 140 )
    ( 0 70 280 )
);
Where low and high define the range of the table, the two values following values define the size of the matrix (3x3 in this case) and at last the values. Ensure that the header is present on this file, otherwise the program will complain.

Sadly I didn't find any way to do it directly from a csv file, which would be very much convienient, probably it will be developmed in further versions.

I hope that helps!
crubio.abujas is offline   Reply With Quote

Old   September 3, 2021, 11:38
Default
  #8
New Member
 
Joao Coelho
Join Date: Jun 2021
Posts: 6
Rep Power: 2
jcoelho5 is on a distinguished road
Dear Carlos,

This was perfect! Got it working exactly as I wanted. Thank you very much!!

(tip for people trying to run this in parallel: you should copy the file for each processor's folder)

Everything else, working fine.

I believe if I wanted to use this with the gradient (input would be space varying gradient instead of space varying temperature), we could use codedMixed BC, with valueFraction 0, right?

Thank you again, Carlos.

Best regards.
jcoelho5 is offline   Reply With Quote

Old   September 3, 2021, 12:32
Default
  #9
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 118
Rep Power: 6
crubio.abujas is on a distinguished road
Hi again Joao,

Glad to know the code works properly.

Concerning the parallel issues you mentioned, yes the code reads on the local time. That means that, right now, to run on parallel running the file should be duplicated on each processor. This is an avoidable cumbersome, as the solution is simply change the IOObject to:

Code:
IOobject FDictIO
(
       "F2Dict",
       mesh.time().globalPath(),
       mesh,
       IOobject::MUST_READ
);
That way the code will search on the global path instead. I didn't have in mind the parallel usage, so I didn't check this option.

Concerning the codedMixed, yes it should be possible to switch between the two with minor changes. Take a look to the previous version on the code and let me know if you find any difficulties with it.

Best regards.
jcoelho5 likes this.
crubio.abujas is offline   Reply With Quote

Reply

Tags
codedfixedvalue, groovybc, openfoam, phasechangeheatfoam

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Varying wall temperature boundary condition mj2malik FLUENT 11 January 12, 2018 04:09
2D time varying boundary condition Hillie OpenFOAM Running, Solving & CFD 0 January 22, 2017 22:38
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 08:44
Problem in setting Boundary Condition Madhatter92 CFX 12 January 12, 2016 04:39
Dynamic Temperature Boundary Condition Kshitij FLUENT 0 October 12, 2005 13:40


All times are GMT -4. The time now is 09:33.