-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Gadget2Particle #10
base: master
Are you sure you want to change the base?
Conversation
- Many routines translated from pynbody to read gadget2 files (format 1 and 2). - Drastically reduced code repetition. TODO: - A config file needed for collect gadget user defined fields and relative units. - StructArray data type (e.g. Float32 of Float64) can't be instantiated at runtime. I think it should be possible, but still I need to find a way. - Rebase with latest modifications upstream
0ab0747
to
db88e90
Compare
Thanks! I will review the code next week (soon after I have updated documentations and release packages of JuliaAstroSim). Before that, AstroIO will release a minor patch to solve some compat problems.
My clumsy solution is to construct a small Lines 285 to 289 in 901d337
I decide to force user to determine what units they are using while reading snapshots, for example, header, data = read_gadget2("snapshot.gadget2", uAstro) where argument header, data = read_gadget2("snapshot.gadget2", uAstro, uGadget2) #! There will be unit conversions
write_gadget2("output.Gadget2", header, data, uGadget2) where |
More elegant way, not having to append! (which was causing a 'type does not have a definite number of fields' error). Also probably more efficient because memory is contiguous from the beginning.
I think I found a better solution by initializing a full-length StructArray and then write the proper The append! was also creating a 'type does not have a definite number of fields' error with the newly defined Now I'm updating the code with the possibility to use other units like you introduced recently. Last step is to make the choice of fields more flexible via a configuration file and probably some metaprogramming in order to create on-demand additional fields in the StructArray. |
Wow! Great idea! As for the conf file, ConfParser.jl should be helpful. I had thought about it once before, however it's hard to make the whole interface user-friendly. My idea is that, users can choose to
|
Ok, thanks. I'll have a look at ConfParser.jl |
Are you pushing to https://github.com/elehcim/AstroIO.jl? Where can I contribute some help? |
Now I have a problem regarding unit conversion which seems to change the datatype. For example: source_units = getuVel(uGadget2);
target_units = getuVel(uAstro);
v = PVector(3.f0, 3.f0, 4.f0, source_units);
println(typeof(uconvert(target_units, v.x)))
Quantity{Float64, 𝐋 𝐓^-1, Unitful.FreeUnits{(Gyr^-1, kpc), 𝐋 𝐓^-1, nothing}} but I'd like it to stay a Float32. I don't know now the solution. Do you think a type stable uconvert for PVector would be a solution? Any idea? I can open an issue in PhysicalParticles |
Yes, I'm pushing there. |
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
because there is no method for `peek(::Stream{DataFormat{:Gadget2}, args...)`
How can I infer the numeric type from a PVector{Quantity{Float32, 𝐋, Unitful.FreeUnits{(kpc,), 𝐋, nothing}}} --> Float32 to be used like: julia> infer_numeric_type(eltype(data.Pos))
Float32 |
For now I'll do: eltype(d.Pos).parameters[1].parameters[1] |
I get a better solution (in the latest master branch of Have fun with it :D julia> using PhysicalParticles
julia> a = PVector(1.0f0, 2.0f0, 3.0f0)
PVector{Float32}(1.0f0, 2.0f0, 3.0f0)
julia> numeric_type(a)
Float32
julia> numeric_type([a])
Float32 |
Merged through #12. (Sorry that I was not familiar with editing PRs before merging. I should have merged this PR first and then commit to master branch)
I have implemented a config file loading procedure in
There is an example of loading Lines 142 to 145 in 1bb9949
How to define blocks from Lines 3 to 7 in 1bb9949
|
I'm also planing to remove SPH fields from |
Hi!
No problem, thanks for merging. I think I'll close this one and open a new one dedicated to the write operations. And also for pushing forward the config file.
Thanks, I'll look into it.
|
I don't think so. But I'm thinking that in It may contain what is there in the gadget2 file (guided by the config file). If we convene to use Let me know what do you think. |
Ah, after commit b655ee3, I think I can continue here. |
Yep. I'm using There are only two restrictions to user-defined particle types for a N-body force solver:
So It's ok to leave |
TODO:
StructArray
data type (e.g.Float32
ofFloat64
) can't be instantiated at runtime. I think it should be possible, but still I need to find a way.I pushed because I saw you're very nicely going forward. I did this work in the past two weeks but newly arrived commitments hindered me to finishing this up. By having it here, you can have a look and probably improve or pick up something for the codebase. I'll try to keep this going in any case.
The main architecture change is the introduction of a
Gadget2Block
type which detects and reads 1D and 3D blocks and knows about the datatype (Float32
,Float64
,Int
) of the data block itself. This uses some routines from pynbody and reduces a lot of code repetition.Then a newly created
Gadget2Particle
struct is added containing fields commonly used in Gadget2 files. This type is then used to load aStructArray
and fill it up with a common file-reading machinery on blocks.