Reference
Main functions
time_march(p, cycles=None)
Run the actual simulation(s) as defined in the input json file p
.
Source code in HGD/main.py
Operators
empty_nearby(nu, p)
Identifies empty spaces adjacent to each point in a grid based on a given solid fraction matrix.
Parameters: - nu (numpy.ndarray): A 2D array representing the solid fraction at each point in the grid. - p (object): An object containing simulation parameters, not used in this function but included for consistency with the interface.
Returns: - numpy.ndarray: A boolean array where True indicates an empty space adjacent to the corresponding point in the input grid.
This function applies a maximum filter with a cross-shaped kernel to the solid fraction matrix 'nu'. The kernel is defined to consider the four cardinal directions (up, down, left, right) adjacent to each point. The maximum filter operation identifies the maximum solid fraction value in the neighborhood defined by the kernel for each point. Points where the maximum solid fraction in their neighborhood is 0 are considered adjacent to an empty space, and the function returns a boolean array marking these points as True.
Source code in HGD/operators.py
get_average(s, loc=None)
Calculate the mean size over the microstructural co-ordinate.
Source code in HGD/operators.py
get_depth(nu, p, debug=False)
Calculate the depth array based on the top indices and y-coordinates.
nu : array-like An array or list of values used to determine the top indices. p : object An object containing the attributes 'nx', 'ny', and 'y'. 'nx' and 'ny' are the dimensions of the grid, and 'y' is an array of y-coordinates.
numpy.ndarray A 2D array of shape (p.nx, p.ny) representing the depth values.
Source code in HGD/operators.py
get_hyperbolic_average(s, loc=None)
Calculate the hyperbolic mean size over the microstructural co-ordinate.
Source code in HGD/operators.py
get_solid_fraction(s, loc=None)
Calculate solid fraction of a single physical in a 3D array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
ndarray
|
a 3D numpy array |
required |
loc
|
list | None
|
Either None or a list of two integers. |
None
|
Returns:
Type | Description |
---|---|
float
|
The fraction of the solid phase in s at (i, j) as a float. |
Source code in HGD/operators.py
get_top(nu, p, nu_lim=0)
Determine the top void in each column of a 2D array.
Parameters:
nu (ndarray): A 2D numpy array where each element indicates the presence (0) or absence (non-zero) of a void.
p (object): An object with attributes nx
(number of columns) and ny
(number of rows).
ndarray: A 1D numpy array of integers where each element represents the row index of the top void in the corresponding column.
If a column has no voids, the value will be p.ny - 1
.
Source code in HGD/operators.py
locally_solid(s, i, j, p)
Determines if a given point in the simulation grid is locally solid based on the solid fraction threshold.
Parameters: - s (object): The simulation state, containing the grid and relevant data. - i (int): The row index of the point in the grid. - j (int): The column index of the point in the grid. - p (object): An object containing simulation parameters, including the critical solid fraction threshold (nu_cs).
Returns: - bool: True if the solid fraction at the given point is greater than or equal to the critical solid fraction threshold (nu_cs), indicating the point is locally solid. False otherwise.
This function calculates the solid fraction at the specified point (i, j) in the simulation grid. It then compares this value to the critical solid fraction threshold (nu_cs) defined in the parameter object p. If the solid fraction at the point is greater than or equal to nu_cs, the function returns True, indicating the point is considered locally solid. Otherwise, it returns False.
Source code in HGD/operators.py
stable_slope(s, i, j, dest, p)
Determines if the slope between two points is stable based on the solid fraction difference.
Parameters: - s (object): The simulation state, containing the grid and relevant data. - i (int): The current row index in the grid. - j (int): The current column index in the grid. - dest (int): The destination row index for comparison. - p (object): An object containing simulation parameters, including the delta_limit.
- bool: True if the difference in solid fraction between the current point and the destination point is less than or equal to the delta_limit, indicating a stable slope. False otherwise.
This function calculates the solid fraction at the current point (i, j) and at a destination point (dest, j), then compares the difference in solid fraction to a threshold (delta_limit) defined in the parameter object p. If the difference is less than or equal to the threshold, the function returns True, indicating the slope is stable. Otherwise, it returns False.
Source code in HGD/operators.py
stable_slope_fast(s, d, p, chi=None, potential_free_surface=None)
Determines the stability of slopes based on the solid fraction.
Parameters:
s (numpy.ndarray): A 3D array representing the solid fraction in the system.
d (int): The direction in which to roll the array (shift axis).
p (object): An object containing the parameter delta_limit
which is used to determine stability.
Returns:
numpy.ndarray: A 3D boolean array where True
indicates stable slopes and False
indicates unstable slopes.
Source code in HGD/operators.py
stable_slope_gradient(s, dir, p, debug=False)
Determines the stability of slopes based on the solid fraction.
Parameters:
s (numpy.ndarray): A 3D array representing the solid fraction in the system.
dir (int): The direction in which to roll the array (shift axis).
p (object): An object containing the parameter delta_limit
which is used to determine stability.
Returns:
numpy.ndarray: A 3D boolean array where True
indicates stable slopes and False
indicates unstable slopes.
Source code in HGD/operators.py
stable_slope_stress(s, p, last_swap, debug=False)
Determines the stability of slopes based on the stress.
Parameters:
s (numpy.ndarray): A 3D array representing the solid fraction in the system.
p (object): An object containing the parameter delta_limit
which is used to determine stability.
last_swap (numpy.ndarray): A 3D array representing the last swap in the system.
Returns:
numpy.ndarray: A 3D boolean array where True
indicates stable slopes and False
indicates unstable slopes.
Source code in HGD/operators.py
Boundary conditions
close_voids(p, s, u, v, c, T, last_swap, chi, sigma, outlet)
Not implemented. Do not use.
Source code in HGD/boundary.py
update(p, state)
Add voids to the system. This function is called at each time step. Loop through all functions defined here and call them if they are in the list of boundary methods.
Source code in HGD/boundary.py
Initial conditions
IC(p)
Sets up the initial value of the grain size and/or void distribution everywhere.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
Parameters class. In particular, the |
required |
Returns:
Type | Description |
---|---|
The array of grain sizes. Values of |
Source code in HGD/initial.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
inclination(p, s)
This function is used when the bottom of silo is to be constructed with certain angle with horizontal. The variable used is form_angle which is by default set to 0 in defaults.json5
Source code in HGD/initial.py
Output
array_to_png_buffer(array, colormap, vmin=None, vmax=None)
Convert a NumPy array to a PNG image buffer using a colormap.
Parameters: array (numpy.ndarray): The input array with shape (height, width). colormap (function): A function that maps array values to RGB tuples.
Returns: io.BytesIO: A buffer containing the PNG image.
Source code in HGD/plotter.py
plot_h(s, p)
Show the relative 'height' of the grains in each cell. Used for diagnostic purposes only, otherwise not that useful.
Source code in HGD/plotter.py
plot_permeability(s, p)
Calculate and save the permeability of the domain at time t.
Source code in HGD/plotter.py
replace_strings(text, replacements)
Replaces substrings in a given text based on a dictionary of replacements.
Parameters: - text (str): The original string in which substrings will be replaced. - replacements (dict): A dictionary where keys are substrings to be replaced and values are the new substrings.
Returns: - str: The modified string with all specified replacements applied.
This function iterates over the key-value pairs in the replacements dictionary. For each pair, it replaces all occurrences of the key (old substring) in the text with the corresponding value (new substring). The function returns the modified text after all replacements have been made.
Source code in HGD/plotter.py
Parameters
dict_to_class
A convenience class to store the information from the parameters dictionary. Used because I prefer using p.variable to p['variable'].
Source code in HGD/params.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
resource_path(relative_path)
Get the absolute path to the resource, works for both development and PyInstaller bundle.
Source code in HGD/params.py
Stresses
solve_tridiagonal(a, b, c, d)
Solves a tridiagonal system using the Thomas algorithm. a: subdiagonal (length n-1) b: main diagonal (length n) c: superdiagonal (length n-1) d: right-hand side (length n)
Source code in HGD/stress.py
Thermal
update_temperature(s, T, p)
Used for modelling the diffusion of heat into the body. Still not functional. Do not use.