CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] groovyBC 2D lookup (https://www.cfd-online.com/Forums/openfoam-community-contributions/159764-groovybc-2d-lookup.html)

ecbmxer September 22, 2015 12:05

groovyBC 2D lookup
 
Has anyone managed to implement a 2D lookup table in groovyBC? I know there was some discussion regarding this, but I haven't seen anything in a while.

Basically I have a bunch of heat flux data as a function of two dimensions. I want to take this and implement it as a BC, shifting it in one dimension at each timestep (so it basically is translating). This appears to be a tough thing to do without writing my own BC.

If there is any other utility that could do this, please let me know.

Thanks!

ecbmxer September 24, 2015 10:21

I just wanted to post an update. I was able to implement a 2D lookup table using the native OpenFOAM coded boundary condition and the existing interpolation2DTable class.

This is what the temperature BC looks like for my patch "inner". Note, I am using "codedMixed" so I can set the gradient rather than the value.

inner
{
type codedMixed;
refValue uniform 300;
refGradient uniform 0;
valueFraction uniform 0;
redirectType lookupHeatFluxBC;

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

code
#{

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

// Example lookup values
scalar lookupVal1 = 10;
scalar lookupVal2 = 20;

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

#};

}

tableData.dat looks like:
Note that you have to repeat the "y" values in each row.


(
( x1 ( (y1 val11) (y2 val12) (y3 val13) .....(ym val1m) ) )
( x2 ( (y1 val21) (y2 val22) (y3 val23) .....(ym val2m) ) )
.
.
(xn ( (y1 valn1) ..................................(ym valnm) ) )
);


If I start to use this functionality more, I'll look into creating a proper new BC vs using the coded BC. But for now, this was the easiest way I could get it up and running. It ends up being a bit slow if you want to lookup values at each coordinate value on the boundary (which I do). You can only pass a scalar to the lookup2DTable, so you have to use nested loops in order to lookup at each point. It would be nice if a whole scalarField could be directly passed in (assuming that would even be faster...maybe it wouldn't).

-Clint


All times are GMT -4. The time now is 02:42.