CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Dynamic Arrays in OF 1.6 (https://www.cfd-online.com/Forums/openfoam/80475-dynamic-arrays-1-6-a.html)

mturcios777 September 27, 2010 13:49

Dynamic Arrays in OF 1.6 [SOLVED]
 
Hello everyone,

I am having trouble with a custom post-processor. I want to be able to read in a tab separated file from memory and refer to its values (look-up table essentially). Since the size of the file may change, I was thinking of using dynamic arrays, and was able to write the code for it to work in a program on its own.

The problem I run into is when I try run the program in FOAM. I've included all the necessary header files, and the program compiles just fine. When I run it and I need to allocate space, I get the following errors:

new cannot satisfy memory request.
This does not necessarily mean you have run out of virtual memory.
It could be due to a stack violation caused by e.g. bad use of pointers or an out of date shared library

My table isn't very big, which is why I'm going the array route. Has anyone run into this before. Barring that, how could I implement this type of functionality with the built in foam libraries?

mturcios777 September 28, 2010 13:09

Ok, figured it out. Easiest way to do this is with the interpolationTable library.


Code:

fileName myFile = someDict.lookup("file.ext");

interpolationTable<scalar> myTab(myFile);

file.ext has the usual structure:

Code:

N
(
  (x1 y1)
  (x2 y2)
  ...
  (xN yN)
)

Now whenever I want to interpolate:

Code:

scalar yiVar = myTab(xi);
returns the corresponding y value interpolated from the entries of myTab.
For future reference, I'm going to see if I can do something similar for multidimensional interpolation. Out of curiosity, what is the best way to indicate that I've solved my problem so people browsing the forum for this answer can find it faster?


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