yt-project / yt

Main yt repository
http://yt-project.org
Other
468 stars 280 forks source link

yt code_length unit inconsistent with Ramses unit_l #4787

Open fredt00 opened 9 months ago

fredt00 commented 9 months ago

Bug report

Bug summary I experience the same issue as https://github.com/yt-project/yt/issues/2866: the unit length conversion for a non cosmological simulation is off by a factor of the boxlength.

Code for reproduction

print(ds.arr(1,"code_density").in_cgs().value/ds.parameters['unit_d'])
print(ds.arr(1,"code_length").in_cgs().value/ds.parameters['unit_l'])
print(ds.parameters['boxlen'])

Actual outcome

The length conversion is off by a factor of 150, the value of the box length. However, the density conversion seems to be correct...

1.0
150.0
150.0

I was wondering if anyone had a simple work around for this? I don't think I can just multiply any results with length units by factors of the box length since the density conversion is correct and includes length**3.

Version Information

welcome[bot] commented 9 months ago

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

matthewturk commented 9 months ago

Thanks for bringing this up -- I am sorry we didn't address it before! Perhaps @cphyc can provide some insight?

cphyc commented 9 months ago

I'm happy to help but I'm 200% busy until February 9 and won't have time until then. Most likely, these two lines are the right entry points: https://github.com/yt-project/yt/blob/1e90fd73f165283399dc45d487183a95239196fd/yt/frontends/ramses/data_structures.py#L977 https://github.com/yt-project/yt/blob/1e90fd73f165283399dc45d487183a95239196fd/yt/frontends/ramses/data_structures.py#L1046

The first sets the length_unit, so 1 * length_unit equals the box size. The second sets the size of the box. I wonder if the fix is simply to replace the latter by

        self.domain_right_edge = np.full(3, self.parameters["boxlen"], dtype="float64")

Could you try and let us know if this works? If it does, we'd be happy for you to submit a PR, or I can do it in a couple of weeks.

fredt00 commented 9 months ago

Hi,

Thanks for the quick reply. I tried changing the line you suggested, and this does mean the correct domain_right_edge is returned when loading the data:

yt : [INFO     ] 2024-01-24 16:11:33,248 Parameters: domain_right_edge         = [150. 150. 150.]

However, the ratio code_length/unit_l is still incorrect by a factor of boxlen and I get the same offset in my plots.

I also tried removing the factor of boxlen in line 977 to give:

setdefaultattr(self, "length_unit", self.quan(length_unit , "cm")) 

I'm completely new to both Ramses and yt so I'm not sure if it was logical to do this, but this seems to completely break any plots I make of the gas.