CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to read .dat files into OpenFOAM (http://www.cfd-online.com/Forums/openfoam-programming-development/130465-how-read-dat-files-into-openfoam.html)

manju819 February 26, 2014 11:38

How to read .dat files into OpenFOAM
 
Hiiii,
I want to read data file like .dat into solver and interpolate
for example

SGAS KRG PCOG
0 0 0
0.02 0 0
0.05 0.005 0
0.12 0.025 0
0.2 0.075 0
0.25 0.125 0
0.3 0.19 0
0.4 0.41 0

On searching i found In interFOAM solver reading of data file is there but it is commented
that is

interpolationTable<vector> timeSeriesAcceleration
(
runTime.path()/runTime.caseConstant()/"acceleration.dat"
);

i want to know what is the format of "acceleration.dat".

Thanks & Regards
N.Manjunath,
M-Tech,
IIT Guwahati

wyldckat March 1, 2014 08:56

Greetings Manjunath,

It really depends on the objective on what to do with the loaded data. Is it for:
  1. Using in a function object?
  2. Using in a boundary condition?
  3. For post-processing?
  4. For implementing in a custom (modified) solver?
Best regards,
Bruno

manju819 March 1, 2014 10:46

Hiiii wyldckat
 
Thank you for your reply.


Where KRG = f(SGAS) . I want to interpolate the KRG & SGAS and then use it in my equation.
That is coefficient of 'sw'

volScalarField KRG = f(SGAS) ;

- fvm::ddt(KRG,sw)
==
fvc::laplacian(phik*phiM_o,p)
- fvc::laplacian(KRG*phik*rho_o,gh)
- fvc::Sp(J*n*KRG,p)
+ fvc::Sp(J*n*KRG,pbh)


Thanks & Regards
N.Manjunath Reddy

wyldckat March 1, 2014 11:16

If I'm not mistaken, for the file extension ".dat", OpenFOAM will use it's own data formatting convention. Therefore, for a vector, it should be:
Code:

#SGAS  KRG  PCOG
(0      0      0)
(0.02  0      0)
(0.05  0.005  0)
(0.12  0.025  0)
(0.2    0.075  0)
(0.25  0.125  0)
(0.3    0.19    0)
(0.4    0.41    0)

Mmm... but the problem is that we're dealing with a time based interpolation table and you're asking for a vector table, where the first column is time, so I think it should be:
Code:

#SGAS  KRG  PCOG
(0      (0      0))
(0.02  (0      0))
(0.05  (0.005  0))
(0.12  (0.025  0))
(0.2    (0.075  0))
(0.25 ( 0.125  0))
(0.3    (0.19    0))
(0.4    (0.41    0))

Or:
Code:

#SGAS  KRG  PCOG
0      (0      0)
0.02  (0      0)
0.05  (0.005  0)
0.12  (0.025  0)
0.2    (0.075  0)
0.25 ( 0.125  0)
0.3    (0.19    0)
0.4    (0.41    0)


manju819 March 4, 2014 05:11

Hiiii wyldckat
 
Thank you so much for your reply.

As you told i wrote the .dat file in vector form while reading
OpenFOAM shown this error

--> FOAM FATAL IO ERROR:
incorrect first token, expected <int> or '(', found on line 1 the word '#SGAS'

file: /home/manjunath/OpenFOAM/manjunath-2.2.2/run/tutorials/basic/laplacianFoam/flange/constant/acceleration.dat at line 1.

From function operator>>(Istream&, List<T>&)
in file /opt/openfoam222/src/OpenFOAM/lnInclude/ListIO.C at line 149.


i used laplacianFoam as sample code too run this


Thanks &Regards
N.Manjunath

alexeym March 4, 2014 05:37

Quote:

Originally Posted by manju819 (Post 477877)
--> FOAM FATAL IO ERROR:
incorrect first token, expected <int> or '(', found on line 1 the word '#SGAS'

Maybe you should also use OpenFOAM syntax for comments? I.e. // instead of #

wyldckat March 4, 2014 06:09

Mmm... Try this:
Code:

//SGAS  KRG  PCOG
(
(0      0      0)
(0.02  0      0)
(0.05  0.005  0)
(0.12  0.025  0)
(0.2    0.075  0)
(0.25  0.125  0)
(0.3    0.19    0)
(0.4    0.41    0)
)


ripudaman April 9, 2014 20:07

I have a similar issue where I am trying to import a set of X-Y values. I want to run some explicit calculation in my solver using this field of values. One such implementation is going to be calculating the minimum distance of the XY vaues imported to a chosen point in the Openfoam mesh.

I am stuck at the first step though. I am unable to import the file in my code.

Here is the data I am trying to import:
Quote:

(
(-152.4 -91.44)
(-152.4 91.44)
)
Here is the error message i get:
Code:

--> FOAM FATAL ERROR:
out-of-order value: -152.4 at index 1


    From function Foam::interpolationTable<Type>::checkOrder() const
    in file /opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/interpolationTable.C at line 226.

FOAM exiting

and here is my code snippet :
Code:

interpolationTable<scalar> previousFracTraj(previousFrac);
Can you guide me please?

Thanks.
Ripu

manju819 April 10, 2014 00:59

Hi Ripudaman
 
I overcome d the problem by reading individual X and Y data like given below....



If you want to read the scalarField
create a data file which has a scalarFields
Ex: file name PVTdata

which has a scalarField X

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.2.2 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

X
(
9.342894e-02
4.567101e-02
3.013131e-02
2.219316e-02
1.746954e-02
1.427184e-02
1.205589e-02
1.041777e-02
9.144300e-03
8.184990e-03
7.393980e-03
6.737610e-03
6.221490e-03
5.789520e-03
5.452920e-03
5.172420e-03
4.925580e-03
4.712400e-03
4.532880e-03
4.370190e-03
);

and you can read this Field in create fields

using a IOdict

IOdictionary PVTdata
(
IOobject
(
"PVTdata",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);


scalarField X
(
PVTdata.lookup("X")
);
similarly for Y


Regards
Manjunath

ripudaman April 10, 2014 01:19

Thanks this is very helpful.

manju819 April 10, 2014 03:30

If you have Swak4foam in that " wobbler " case consist similar type of file importing as you mentioned in the previous post....


All times are GMT -4. The time now is 07:47.