Skip to content

Conversation

@joshcalcino
Copy link
Contributor

Description:
Changes include adding a moddump to add in spheres/ellipses on parabolic/hyperbolic orbits following the flyby prescription (for parabolic) and Dullemond+2019 (hyperbolic). Also the Pineda+2009 streamer model used to fit the streamer in Gupta+, Speedie+ papers.

Components modified:

  • Setup (src/setup)
  • [ x] Main code (src/main)
  • [ x] Moddump utilities (src/utils/moddump)
  • Analysis utilities (src/utils/analysis)
  • Test suite (src/tests)
  • Documentation (docs/)
  • Build/CI (build/ or github actions)

Type of change:

  • Bug fix
  • Physics improvements
  • Better initial conditions
  • Performance improvements
  • Documentation update
  • Better testing
  • Code cleanup / refactor
  • [ x ] Other (please describe)

New injection routines, moddump.

Testing:

Did you run the bots? no

Did you update relevant documentation in the docs directory? no

Did you add comments such that the purpose of the code is understandable? yes

Is there a unit test that could be added for this feature/bug? yes/no

Checked the code compiles and output looks sensible.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joshcalcino, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant new capabilities for simulating astrophysical phenomena, particularly focusing on the injection and manipulation of material. It provides a robust framework for modeling infall scenarios with precise control over initial conditions and orbital dynamics, and integrates a specialized streamer model for specific astrophysical contexts. The changes also include refinements to existing setup routines, a suite of new utility moddumps for various simulation adjustments, and the crucial addition of HDF5 support for dump files, which will improve data management and interoperability within the simulation workflow.

Highlights

  • New Infall Moddump: A new moddump (moddump_infall.f90) has been added to simulate the infall of material (spheres or ellipses) onto a central object, supporting both parabolic and hyperbolic orbital prescriptions. This includes parameters for defining the shape, mass, initial distance, and detailed orbital characteristics such as closest approach, velocity at infinity, and impact parameter.
  • Pineda+2009 Streamer Model Implementation: A new injection routine (inject_streamer_pineda.f90) has been introduced, which implements the Pineda+2009 streamer model. This allows for the injection of material in a stream-like configuration, with configurable parameters for mass injection rate, angular velocity, and geometric properties of the stream.
  • Inclination Support for Keplerian Injection: The existing inject_keplerian.f90 module has been enhanced to include incx, incy, and incz runtime parameters. These parameters enable the injection of particles with specified inclinations about the x, y, and z axes, allowing for tilted Keplerian injection scenarios.
  • Makefile and Setup Integration: The build system (build/Makefile and build/Makefile_setups) has been updated to incorporate new velocity field objects (velfield_fromcubes.o, set_vfield.o) and to define a new streamerdisc setup. This new setup specifically utilizes the inject_streamer_pineda.f90 routine, streamlining the configuration of streamer simulations.
  • Enhanced Sphere and Ellipse Setup: The set_sphere and set_ellipse subroutines in src/setup/set_sphere.f90 have been improved. set_sphere now uses integer(kind=8) for dir and nptot parameters, accommodating larger particle counts. set_ellipse now supports density profiles and origin shifting, offering greater flexibility in defining initial geometries.
  • New Moddump Utilities: Several new moddump utilities have been added to src/utils/moddump, expanding the range of post-processing and setup modifications available. These include tools for setting floor temperatures (moddump_addcsmin_binary.f90), adding spheres of material (moddump_addsphere.f90), adjusting dust fractions (moddump_dustsinkfrac.f90), reorienting and recentering discs (moddump_faceon.f90, moddump_recenter.f90), rescaling simulation units (moddump_rescale.f90), and specific utilities for the GG Tau system (moddump_ggtau.f90) and disc extension (moddump_testhexdisc.f90). The moddump_changemass.f90 utility was also updated to handle dead/accreted particles before mass scaling.
  • HDF5 Dumpfile Support: New utility functions (utils_dumpfiles_hdf5.f90) have been introduced to enable the writing and reading of HDF5 dump files. This significantly enhances data handling capabilities, allowing for more efficient storage and retrieval of simulation headers and particle data, and supporting various physics options and external force types.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant new functionality, including new infall models (Calcino et al. 2024/subm, Pineda streamer model) and various moddump utilities. The changes are extensive and add valuable capabilities. However, my review has identified several critical and high-severity issues, primarily stemming from copy-paste errors, incorrect calculations, and unit mismatches in the new modules. I have also pointed out some medium-severity issues related to code duplication and clarity. Addressing these points will improve the robustness and maintainability of the new code.

n0 = (sqrt(xp(1)**2 + xp(2)**2))/dma
pf = 2*dma
n1 = (xp(2)-y1)/dma
m0 = 2*sqrt(n0-n1-1.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The calculation m0 = 2*sqrt(n0-n1-1.0) could fail with a domain error if n0-n1-1.0 is negative. You should add a check to ensure the argument of sqrt is non-negative before calling it.

x0 = -m0*dma
y0 = dma*(1.0-(x0/pf)**2)
dx = xyzh_add(1, i) - xp(1)
y_prime = 4*dma/x0 *dx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There is a potential for division by zero here if x0 is zero. x0 is calculated from m0, which can be zero. You should add a check to handle the case where x0 is zero to prevent a runtime error.

Comment on lines +166 to +167
dustfrac_tmp = sum(dustfrac)/npartoftype(igas)
dustfrac_tmp = sum(dustfrac(1,:))/npartoftype(igas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The calculation for dustfrac_tmp is performed twice. The first line, dustfrac_tmp = sum(dustfrac)/npartoftype(igas), is incorrect for a 2D array and seems to be a leftover. The second line is also suspicious as sum(dustfrac(1,:)) sums over the entire allocated size of the array, not just the active particles, which could lead to incorrect average values. You should sum only over active particles, for example, sum(dustfrac(1, 1:npart)) / npart if you want the average over all active particles, or sum(dustfrac(1, 1:npartoftype(igas))) / npartoftype(igas) for just gas particles.

       dustfrac_tmp = sum(dustfrac(1,1:npartoftype(igas)))/npartoftype(igas)

Comment on lines 151 to 152
dustfrac_tmp = sum(dustfrac)/npartoftype(igas)
dustfrac_tmp = sum(dustfrac(1,:))/npartoftype(igas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The calculation for dustfrac_tmp is performed twice. The first line, dustfrac_tmp = sum(dustfrac)/npartoftype(igas), is incorrect for a 2D array and seems to be a leftover. The second line is also suspicious as sum(dustfrac(1,:)) sums over the entire allocated size of the array, not just the active particles, which could lead to incorrect average values. You should sum only over active particles, for example, sum(dustfrac(1, 1:npart)) / npart if you want the average over all active particles, or sum(dustfrac(1, 1:npartoftype(igas))) / npartoftype(igas) for just gas particles.

       dustfrac_tmp = sum(dustfrac(1,1:npartoftype(igas)))/npartoftype(igas)

case('sym_stream')
read(valstring,*,iostat=ierr) sym_stream
ngot = ngot + 1
if (sym_stream < 0 .or. sym_stream > 2) call fatal(label,'sym_stream < 0 or > 2 in input options')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The validation for sym_stream only allows values up to 2, but the code in inject_particles handles a value of 3. This will cause a fatal error for a valid option. The check should be updated to allow sym_stream to be 3.

    if (sym_stream < 0 .or. sym_stream > 3) call fatal(label,'sym_stream < 0 or > 3 in input options')

Comment on lines +19 to +20
! - incy : *inclination about the x-axis (degrees)*
! - incz : *inclination about the x-axis (degrees)*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The descriptions for incy and incz appear to be copy-pasted from incx and incorrectly state they are for inclination about the x-axis. They should be updated to refer to the y-axis and z-axis, respectively.

!   - incy        : *inclination about the y-axis (degrees)*
!   - incz        : *inclination about the z-axis (degrees)*

! need a better root finder, so right now r_inj must be r0
!call theta_at_r(r_inj/rc, theta0m, ecc, xi0, theta)
theta = theta0m
phi = phi0m + acos( tan(theta0m) / tan(theta) ) ! Ulrich 1976, eq. (15)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to acos could result in a domain error if abs(tan(theta0m) / tan(theta)) is greater than 1. While theta is currently set to theta0m, the commented-out call to theta_at_r suggests this might change. It would be safer to add a check to prevent runtime errors.

Comment on lines +35 to +43
print "(7(a5,1x,a,1x,f13.7,/))",&
'x','=',xyzmh_ptmass(1,i),&
'y','=',xyzmh_ptmass(2,i),&
'z','=',xyzmh_ptmass(3,i),&
'mass','=',xyzmh_ptmass(4,i),&
'h','=',xyzmh_ptmass(ihsoft,i),&
'hacc','=',xyzmh_ptmass(ihacc,i),&
'Lnuc','=',xyzmh_ptmass(ilum,i),&
'???','=',xyzmh_ptmass(12,i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The print statement for sink properties appears to print the luminosity twice with different labels. xyzmh_ptmass(ilum,i) (where ilum is 12) is printed with the label Lnuc, and xyzmh_ptmass(12,i) is printed with the label ???. This is redundant and confusing. The line for ??? should be removed.

    print "(6(a5,1x,a,1x,f13.7,/))",&
             'x','=',xyzmh_ptmass(1,i),&
             'y','=',xyzmh_ptmass(2,i),&
             'z','=',xyzmh_ptmass(3,i),&
             'mass','=',xyzmh_ptmass(4,i),&
             'h','=',xyzmh_ptmass(ihsoft,i),&
             'hacc','=',xyzmh_ptmass(ihacc,i),&
             'Lnuc','=',xyzmh_ptmass(ilum,i)

Comment on lines +200 to +227
xyzit = xyzi+x0
vxyzt = vxyz+v0

call rotatevec(xyzit,(/1.,0.,0./),incx/180.*pi)
call rotatevec(vxyzt,(/1.,0.,0./),incx/180.*pi)

call rotatevec(xyzit,(/0.,1.,0./),incy/180.*pi)
call rotatevec(vxyzt,(/0.,1.,0./),incy/180.*pi)

call rotatevec(xyzit,(/0.,0.,1./),incz/180.*pi)
call rotatevec(vxyzt,(/0.,0.,1./),incz/180.*pi)

i_part = npart + 1! all particles are new
call add_or_update_particle(igas, xyzi+x0, vxyz+v0, hguess, u, i_part, npart, npartoftype, xyzh, vxyzu)
call add_or_update_particle(igas, xyzit, vxyzt, hguess, u, i_part, npart, npartoftype, xyzh, vxyzu)

xyzit = -xyzi+x0
vxyzt = -vxyz+v0

call rotatevec(xyzit,(/1.,0.,0./),incx/180.*pi)
call rotatevec(vxyzt,(/1.,0.,0./),incx/180.*pi)

call rotatevec(xyzit,(/0.,1.,0./),incy/180.*pi)
call rotatevec(vxyzt,(/0.,1.,0./),incy/180.*pi)

call rotatevec(xyzit,(/0.,0.,1./),incz/180.*pi)
call rotatevec(vxyzt,(/0.,0.,1./),incz/180.*pi)
i_part = npart + 1! all particles are new
call add_or_update_particle(igas, -xyzi+x0, -vxyz+v0, hguess, u, i_part, npart, npartoftype, xyzh, vxyzu)
call add_or_update_particle(igas, xyzit, vxyzt, hguess, u, i_part, npart, npartoftype, xyzh, vxyzu)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The block of code for rotating the particle's position and velocity is duplicated for the positive and negative particle pairs. This duplicated code can be refactored into a helper subroutine to improve maintainability and reduce redundancy. The subroutine would take the position and velocity vectors as arguments and apply the series of rotations.

enddo
xyzmh_ptmass(1:3, 1) = xyzmh_ptmass(1:3, 1) - xyzmh_ptmass(1:3, 1)
!
print*, 'Fuck.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This print statement contains unprofessional language and should be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant