awsteiner / o2scl

Object-oriented Scientific Computing Library
https://awsteiner.org/code/o2scl
GNU General Public License v3.0
35 stars 14 forks source link

Using multidimensional interpolation #2

Closed slizovskiy closed 4 years ago

slizovskiy commented 8 years ago

Dear Andrew, Could you extend the documentation by providing a simple example for multidimensional interpolation on a regular grid, please. In particular, how to enter and allocate space for tensor elements and how to save/load them. I suppose, this is done in the third-party libraries, but a basic example will be very helpful anyway. Would the interpolation work a bit outside the domain (as extrapolation)? This could have been a useful feature. Thank you! Sergey

awsteiner commented 8 years ago

You are correct, there is no good tensor example, so I will work on it and get back to you as soon as I can. In the mean time, you may find src/base/tensor_ts.cpp helpful. However, I should warn you, O2scl includes only a very basic scheme for grid-based interpolation in higher dimensions in the tensor_grid class, but I don't recommend it's use for anything other than linear interpolation. (The classes interpm_neigh and interpm_idw work best on data which is not specified on a grid.) What rank tensor do you have?

Oh and I forgot: extrapolation is essentially always supported in O2scl for all of the interpolation methods.

slizovskiy commented 8 years ago

Thank you for your reply! I have 6 D interpolation with around 1000000 sample points on a regular grid. There is a more sophisticated Bspline library called "splinter", BUT it takes enormous time even for linear BSpline. That's why I need a good FAST implementation of linear interpolation or some inverse square interpolation. Hope that your library will be helpful, but an example would be very helpful. Best wishes, Sergey

slizovskiy commented 8 years ago

Thank you for referring to tensor_ts.cpp! I will try to write my example myself and will hopefully share it here.

awsteiner commented 8 years ago

Ok. Check out https://github.com/awsteiner/o2scl/blob/master/examples/ex_tensor.cpp . I try to make my classes agnostic with regard to the base vector type, so tensor_grid::interp_linear() always works. However, tensor_grid::interpolate() only works if the base vector types are from ublas.

slizovskiy commented 8 years ago

That is a helpful example! Are there any save/load methods in tensor_grid class? I have read from the manual that you use HDF library for that. Is it hard to make a simple example that would save/load the tensor_grid with http://web.utk.edu/~asteine1/o2scl/html/classo2scl__hdf_1_1hdf__file.html functions?

awsteiner commented 8 years ago

The file ex_tensor.cpp now demonstrates this as well (the I/O functions are at the bottom of hdf_io.h). Note however that HDF5 I/O only works if the tensor is built upon std::vector types, since ublas vectors are not (so far as I know) guaranteed to be contiguous in memory.

slizovskiy commented 8 years ago

Thank you! This is really helpful!

The file ex_tensor.cpp now demonstrates this as well (the I/O functions are at the bottom of hdf_io.h). Note however that HDF5 I/O only works if the tensor is built upon std::vector types, since ublas vectors are not (so far as I know) guaranteed to be contiguous in memory.

— Reply to this email directly or view it on GitHub https://github.com/awsteiner/o2scl/issues/2#issuecomment-163739386.

slizovskiy commented 8 years ago

Dear Andrew, a useful improvement for the future could be the functions to integrate and differentiate on the (possibly non-equally spaced) tensor grid. This is not easy in general, but, at least the linear interpolation can be easily integrated.

slizovskiy commented 8 years ago

Dear Andrew, I have attempted to use tensor_grid template class with complex field and this resulted in an error. Is it hard to make it work for complex? At least, the linear interpolation should be straightforward. Best wishes, Sergey

On 09/12/15 15:20, Andrew W. Steiner wrote:

You are correct, there is no good tensor example, so I will work on it and get back to you as soon as I can. In the mean time, you may find src/base/tensor_ts.cpp helpful. However, I should warn you, O_2 scl includes only a very basic scheme for grid-based interpolation in higher dimensions in the tensor_grid class, but I don't recommend it's use for anything other than linear interpolation. (The classes interpm_neigh and interpm_idw work best on data which is not specified on a grid.) What rank tensor do you have?

— Reply to this email directly or view it on GitHub https://github.com/awsteiner/o2scl/issues/2#issuecomment-163287526.

awsteiner commented 8 years ago

I'm not sure....let me try this later this week.

ny2292000 commented 4 years ago

Dear Andrew,

I am facing the problem of calculating the proton fraction of a neutron star where Gravitation is irrelevant (zero pressure).

Can your work be applied to that scenario? https://arxiv.org/pdf/1303.4662.pdf

By the way, I also had trouble in the make all for o2scl on ubuntu 18.04

Marco

awsteiner commented 4 years ago

Marco,

 1) I'd prefer you create a new issue rather than commenting on an unrelated issue. No need to repeat this comment, but I just note this for next time. 

 2) It's not clear exactly what you mean by "Gravitation is irrelevant". The proton fraction can be computed at any density and that calculation does not include any effect of gravity (using e.g. the calc_eos() function in the nstar_cold class). However, the phrase "proton fraction of a neutron star" implies you're thinking about a neutron star where ignoring gravity is a poor approximation. In any case, check out https://neutronstars.utk.edu/code/o2scl/eos/html/cnstar.html and see if that helps.

Take care, Andrew