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

INTERPOLATEXY format entry for the Xold and Yold

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 23, 2006, 06:54
Default Hello, I have read several
  #1
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Hello,

I have read several interpolateXY (the engineValve example, ...) but I could'nt find
out hown to use interpolateXY, i.e, what is the format input read by interpolate.
I struggled in trying to find out some
information in graph applications but unusefully as my C++ knowledge is almost "null".

What is the correct format declaration for
the entry values in interpolateXY?

Thanks if you can help.

Anne
anne is offline   Reply With Quote

Old   June 23, 2006, 14:02
Default The function signature is:
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
The function signature is:

template<class>
Field<type> interpolateXY
(
const scalarField& xNew,
const scalarField& xOld,
const Field<type>& yOld
);


or

template<class>
Type interpolateXY
(
const scalar x,
const scalarField& xOld,
const Field<type>& yOld
);


Therefore, for new x value you can give it a scalar or a scalar field, for old y you give it a field of whatever you are interpolating (scalar, vector, tensor) and you get back either a single value (second function) or a whole field (first function) of the same thing. You should be able to read this from the function signature...

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   June 26, 2006, 03:16
Default Thank You Hrv, Actually wha
  #3
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Thank You Hrv,

Actually what is not clear for me is
the format for the interpolate function.
Should I write the input data in a similar way
to a volvelocity field read by
OpenFoam but specifying that is is a Field or Scalar interpolateXY and thus write by columns:
(
xnew, xold, yold
)

Must they have the same number of points or
not? (i.e xnew and xold the same number of data?).

There are perhaps evident questions nut I
really struggle with c++ format.

Thank you for your help,
Anne
anne is offline   Reply With Quote

Old   June 26, 2006, 06:40
Default Hello Anne, Let's think abo
  #4
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Hello Anne,

Let's think about it: the idea of interpolation is that you give me an x-y graph and based on this I read off some values from the graph and return them. We have 2 functions: one which reads off values one at a time and another which will read lots of values together (see function signatures above).

So, the "old graph" is given by xold and yold, where xold is the abscissa and yold is the data (ordinate). Now, the function takes xnew (that would be the points you are interested in) and returns the data read off the graph for the new points.

Therefore, xnew can be any size you like and you will get the data (call it ynew - the return value of the function) with the same number of entries as xnew. Additionally, the type of ynew is the same as the type of yold, so if you have a graph of scalars you get scalars, for a graph of vectors you get the vectors etc.

Clear?

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   June 26, 2006, 06:56
Default Hello Hrv, what you told me
  #5
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Hello Hrv,

what you told me is clear.
The problem I have is that I don't know how to
make read the graph file.

In engineValve, the declaration is as follows:

const graph& liftProfile

and thus a call to interpolate.


However, I don't find out where the graph file has to be put (in the 0 time directory ?), and also how to declare the name graph file.
It is a very basic problem (I know) but I have been trying to find an example but I didn't.
So the main problem I have is how to declare correctly my graph file so that the data be read.

I feel sorry to bother you with so basical sttuf, but I always work with the very simple
f77 and c++ is
a hard stuff for me. But I recognize, that
c++ is a very powerfull programmation languange
and I am quite impressed by the code structure.


Thanks again

Anne
anne is offline   Reply With Quote

Old   June 26, 2006, 07:31
Default Aha. It is really up to you w
  #6
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Aha. It is really up to you where you put the file. To skip the "complex things", here's how I read valve lift in the engineValve (adjusted for your needs). The constructor (a function that makes the graph) we will use is defined in the library (OpenFOAM-1.3/src/OpenFOAM/graph/graph.H):

//- Construct from Istream given title and labels
graph
(
const string& title,
const string& xName,
const string& yName,
Istream& is
);


This says: give me 3 strings (name of graph, label of x-axis and label of y-axis) and a stream of x-y data and I will make a graph for you.

The stream can be created in many ways. Probably the easiest one is from a file - I will give you a very simple example and you can adjust it to your needs:

IFstream if("myFile");

This creates a stream called if by opening a file called myFile in the CURRENT DIRECTORY. If you want to open (say) a file myFile in the constant directory of the case, you would do:

IFstream if(runTime.path()/runTime.constant()/"myFile");

Here, I am assuming that runTime is the name of your Time (database) class, as it is in the top-level code.

The format of myFile would be straight x-y with some brackets around it:

(
0 0.001112360000000003
2 0.001325159999999999
4 0.001549999999999994
6 0.001784680000000005
8 0.002027220000000005
10 0.002275840000000002
)


We can now create the graph:

graph myGraph
(
"HrvsGraph",
"x",
"lift",
if
);


Clear?

You can now do the interpolation like this: say, we are reading out a single value for myX:

scalar myY = interpolateXY
(
myX,
myGraph.x(),
myGraph.y()
);


Still clear?

You should, of course, adjust any of the above to your needs and use more sensible names :-)

Enjoy,

Hrv
JackW, superkelle and parthigcar like this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   June 26, 2006, 07:57
Default Dear Hrv, That is exactly t
  #7
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Dear Hrv,

That is exactly the information I wanted from you.

So I think that I will now be able to do my interpolation ...

I thank you a lot,

Anne
anne is offline   Reply With Quote

Old   June 27, 2006, 04:32
Default Hello Hrv, Thanks to you I
  #8
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Hello Hrv,

Thanks to you I have now my interpolation
running.

However I still have a question more ...:

I use the interpolation to get an inlet profile
from experimental data and I do the following:

-----------------------------------------------------
Info<< "Interpolation injector inlet" <<endl;

label inletPatchID=mesh.boundaryMesh().findPatchID("inje ctor_inl");
vectorField& UIN= U.boundaryField()[inletPatchID];
volVectorField centres = U.mesh().C();

vectorField& centresbc = centres.boundaryField()[inletPatchID];
scalarField ybc =centresbc.component(vector::Y);
scalarField zbc =centresbc.component(vector::X);

scalarField rbc =pow(ybc,2)+pow(zbc,2);

# include "createGraphIN.H"
scalarField rbc2=sqrt(rbc);

scalarField vzexp=interpolateXY
(
rbc2,
exp.x(),
exp.y()
);


UIN=vzexp*vector(0,0,1);

----------------------------------------------
Apparently I have, when I visualize the velocity contours with paraFoam a correct inlet profile.

I would like you just to confirm that I really applied the interpolated profile by doing so.
I ask you this because I read quite a lot on the forum about this king of stuff and in one
of the discussion the creation of a new
PrimitivePatch or PatchtoPatchinterpolation was apparently necessary (or something like that)???

Thanks you

Anne
anne is offline   Reply With Quote

Old   June 28, 2006, 12:59
Default A few minor things: label
  #9
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
A few minor things:

label inletPatchID=mesh.boundaryMesh().findPatchID("inje ctor_inl");

After you do this, you should check that the label is not -1: if you mis-spelled the name, the patch will not be found and the function returns -1. If you carro on, the code will probably core dump, so it's nicer to check.

volVectorField centres = U.mesh().C();

This should be:

const volVectorField& centres = U.mesh().C();

Currently, you are making a copy, which is not necessary. Also:

const vectorField& centresbc = centres.boundaryField()[inletPatchID];

The rest is OK - you may consider using the patch normal instead of vector(0,0,1); to make it more general, but it does not matter.

Have a look at the file to see if the field is correctly set up.

Have fun,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   June 29, 2006, 03:25
Default Dear Hrv, Thanks a lot for
  #10
Member
 
anne dejoan
Join Date: Mar 2009
Location: madrid, spain
Posts: 66
Rep Power: 17
anne is on a distinguished road
Dear Hrv,

Thanks a lot for your suggestions.

I will add the checking label.

You write that I can use the patch normal instead of vector(0,0,1) ... Well, I don't know the variable name of the patch normal and how to declare it , but I think I can find it in the forum or Dioxygen ...

Thanks again

Anne
anne is offline   Reply With Quote

Old   June 29, 2006, 06:49
Default Try: U.mesh().boundary().nf
  #11
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Try:

U.mesh().boundary()[inletPatchID].nf();

The function is defined in fvPatch.H in the finiteVolume library:

//- Return face normals
virtual const vectorField& nf() const;

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 3, 2006, 04:36
Default Hello, I just read these po
  #12
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Hello,

I just read these posts with great interest and still have some minor questions. I apologize if they are so "easy" but I don't find an answer in the message board:

1. When using interpolateXY must we always use a graph object to read the data file from which we want to make the interpolation ? Is there a way to use IFstream, read the data in this file and put them in 2 scalarField (one for the x coordinate and the other for the y coordinate) ?

2.Perhaps the second question is linked to the first one. I have tried the procedure described in this thread and I'm able to test the interpolation for one scalar. Now I have created a scalarField an want to make the interpolation on this scalar field, but I'm not able to write the new x scalar and y scalar field in a file using OFstream. Yes I know it's realy basic ... I have tried this:

/ Reading data file
IFstream fichierProfil(runTime.constant()/"profil.dat");
Info << "Reading file profil.dat " << endl;

graph myGraph
(
"FrancoisGraph",
"x",
"y",
fichierProfil
);

// Interpolation

scalarField xNew;
scalarField yNew = interpolateXY
(
xNew,
myGraph.x(),
myGraph.y()
);


// Writing interpolated data to a new file

OFstream fichierProfilInterpole (runTime.constant()/"profilNew.dat");
Info << "Writing interpolated data" << endl;
fichierProfilInterpole << xNew << yNew << endl;

And I the new file profilNew.dat I only have :

0()0()

Any idea ?
Thank's a lot

Francois
francois is offline   Reply With Quote

Old   July 3, 2006, 04:51
Default Hello you need to change some
  #13
New Member
 
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17
aurelia is on a distinguished road
Hello
you need to change some file to use the append option of OFstream: see the last post of Hrvoje in

http://www.cfd-online.com/cgi-bin/Op...=5899#POST5899

Aurelia
aurelia is offline   Reply With Quote

Old   July 3, 2006, 04:54
Default sorry it was not the good link
  #14
New Member
 
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17
aurelia is on a distinguished road
sorry it was not the good link
you will find the new OFstream file if you search for "OFstream app"
aurelia is offline   Reply With Quote

Old   July 3, 2006, 05:13
Default Thank's aurelia but I don' wan
  #15
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Thank's aurelia but I don' want to make an append to an old file but only write some xy data to a new file.

I'm sorry but I send the wrong code ...
Well always think twice before posting !!!

So the new scalarField is defined by:

scalarField xNew=myGraph.x()+0.001 ;

And in the the new file I have:
6(0.001 2.001 4.001 6.001 8.001 10.001)6(0.00111247 0.00132527 0.00155012 0.0017848 0.00202734 0.00227584)

The interpolation works but the format of the file is strange for me. What about the 6 before the x and y values ?
francois is offline   Reply With Quote

Old   July 3, 2006, 05:28
Default Hi Francois, The 6 before o
  #16
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Hi Francois,

The 6 before open bracket tells you that the length of the list is 6 (that's all). You have written out 2 scalar fields so I do not see any problem with the write out. If you want to have x-y pairs in the file, you should make a graph first and then write it out.

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 3, 2006, 07:54
Default Thank's a lot Hrv ! You're so
  #17
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Thank's a lot Hrv ! You're so helpfull

It's what I'm trying to do but I have problems with the format of the graph:

fileName fichierProfilInterpole (runTime.constant()/"profilNew.dat");
Info << "Ecriture dans le fichier" << endl;

graph myNewGraph
(
"FrancoisGraph",
"xNew",
"yNew",
xNew,
yNew
);
myNewGraph.write(fichierProfilInterpole,raw);

I tried raw, ascii but always have a message like:

raw was not declared in this scope

I'm looking in OpenFOAM/OpenFOAM-1.3/src/OpenFOAM/graph/ for the available format but can't find them ...

Anyway thanx for your help
Francois
francois is offline   Reply With Quote

Old   July 3, 2006, 11:56
Default Try "raw" in quotes and tell m
  #18
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
Try "raw" in quotes and tell me what happened.

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 3, 2006, 17:10
Default Thank's Hrv it works I thi
  #19
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Thank's Hrv it works

I think that all is in:

void graph::write(Ostream& os, const word& format)

I forget that the format was of type word, so it explains the quotes no ?

I will try to find a way to remove the .xy extention of the filename.

Thank's it realy helps me
Francois
francois is offline   Reply With Quote

Old   July 3, 2006, 17:22
Default I just find the tips use:
  #20
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
I just find the tips

use:

OFstream fichierProfilInterpole (runTime.constant()/"profilNew.dat");

instead of:

fileName fichierProfilInterpole (runTime.constant()/"profilNew.dat");

The last command will add the .xy extension to the fileName when using "raw" format ...

I think it's in graph.C:

void graph::write(Ostream& os, const word& format) const
{
writer::New(format)().write(*this, os);
}


void graph::write(const fileName& fName, const word& format) const
{
autoPtr<writer> graphWriter(writer::New(format));

OFstream graphFile(fName + '.' + graphWriter().ext());
francois 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
FluxRequired entry msrinath80 OpenFOAM Running, Solving & CFD 4 May 1, 2015 11:30
Entry point lucian OpenFOAM Pre-Processing 1 March 13, 2007 04:04
table entry carno Siemens 1 May 28, 2005 11:29
entry, dump losses Babu FLUENT 0 February 25, 2005 02:59


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