-
Notifications
You must be signed in to change notification settings - Fork 46
Monte Carlo Method for Displacement Dynamic #1647
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
base: main
Are you sure you want to change the base?
Changes from all commits
8f7f437
6cb90ef
ecc44b2
d9cb6f9
0490971
76c7d45
3582bd8
2e9bacf
91c2705
3b5cb31
6a1bd13
6106384
43d1078
4c78097
4f10f47
715f02d
34b666e
422d166
3d346a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,16 +427,19 @@ def flag_out_of_column(self): | |
self.attributes.sanitize() | ||
|
||
def calculate_displacement( | ||
self, *, displacement, courant, cell_origin, position_in_cell, n_substeps | ||
self, *, displacement, courant, cell_origin, cell_id, position_in_cell, n_substeps, enable_monte_carlo | ||
): | ||
for dim in range(len(self.environment.mesh.grid)): | ||
self.backend.calculate_displacement( | ||
dim=dim, | ||
displacement=displacement, | ||
courant=courant[dim], | ||
cell_origin=cell_origin, | ||
cell_id=cell_id, | ||
position_in_cell=position_in_cell, | ||
n_substeps=n_substeps, | ||
enable_monte_carlo=enable_monte_carlo, | ||
rng=self.Random(1,1).generator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function slowly starts being too complex. There are at least two flags used in a little bit confusing way (if flag1 and flag2 and after that if flag1 and not flag2). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the displacement calculation, the Random generator is instantiated with a hardcoded seed (seed=1) for each backend call |
||
) | ||
|
||
def isotopic_fractionation(self, heavy_isotopes: tuple): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
""" | ||
basic explicit-in-space Euler scheme | ||
""" | ||
|
||
import numpy as np | ||
|
||
class ExplicitInSpace: # pylint: disable=too-few-public-methods | ||
def __init__(self, _): | ||
pass | ||
|
||
@staticmethod | ||
def displacement(_, position_in_cell, c_l, c_r): | ||
return c_l * (1 - position_in_cell) + c_r * position_in_cell | ||
def displacement(_, position_in_cell, cell_id, c_l, c_r, enable_monte_carlo, u01): | ||
return ( | ||
position_in_cell | ||
+ ( | ||
np.floor( | ||
np.abs(max(c_l, c_r)) | ||
) | ||
* np.sign( | ||
np.abs(max(c_l, c_r)) | ||
/ max(c_l, c_r) | ||
) | ||
) | ||
+ ( | ||
np.abs(max(c_l, c_r)) > u01 | ||
) | ||
* np.sign( | ||
np.abs(max(c_l, c_r)) | ||
/ max(c_l, c_r) | ||
) | ||
) if enable_monte_carlo else ( | ||
c_l | ||
* (1 - position_in_cell) | ||
+ c_r * position_in_cell | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
""" | ||
eqs. 14-16 in [Arabas et al. 2015](https://doi.org/10.5194/gmd-8-1677-2015) | ||
""" | ||
|
||
import numpy as np | ||
|
||
class ImplicitInSpace: # pylint: disable=too-few-public-methods | ||
def __init__(self, _): | ||
pass | ||
|
||
@staticmethod | ||
def displacement(_, position_in_cell, c_l, c_r): | ||
return (c_l * (1 - position_in_cell) + c_r * position_in_cell) / (1 - c_r + c_l) | ||
def displacement(_, position_in_cell, cell_id, c_l, c_r, enable_monte_carlo, u01): | ||
return ( | ||
position_in_cell | ||
+ ( | ||
np.floor( | ||
np.abs(max(c_l, c_r)) | ||
) | ||
* np.sign( | ||
np.abs(max(c_l, c_r)) | ||
/ max(c_l, c_r) | ||
) | ||
) | ||
+ ( | ||
np.abs(max(c_l, c_r)) > u01 | ||
) | ||
* np.sign( | ||
np.abs(max(c_l, c_r)) | ||
/ max(c_l, c_r) | ||
) | ||
) if enable_monte_carlo else ( | ||
( | ||
c_l | ||
* (1 - position_in_cell) | ||
+ c_r | ||
* position_in_cell | ||
) | ||
/ ( | ||
1 | ||
- c_r | ||
+ c_l | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From above to variables names it is not obvious what they represent. Maybe delta_time and delta_altitude (if z is altitude) would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable naming
Thank you for the proposed update concerning the naming of the certain variables!
I agree that clarity in variable naming is important, for both maintainability and readability of the code. In this case, however, the names
dt
anddt_over_dz
are intentionally kept concise and consistent with standard nomenclature widely used in numerical methods and literature.With that being said, we can consider adding a short inline comment to clarify their meaning if that would help in understanding the functionality.