Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed example_outputs/flow/PINN_solution_masked.png
Binary file not shown.
Binary file removed example_outputs/flow/bc_colloc_legends.png
Binary file not shown.
Binary file modified example_outputs/flow/bcs_collocs.png
Comment thread
maruti-iitm marked this conversation as resolved.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified example_outputs/flow/numerical_solution.npz
Binary file not shown.
Binary file added example_outputs/flow/numerical_solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example_outputs/flow/numerical_solution_masked.png
Binary file not shown.
Binary file not shown.
Binary file modified example_outputs/flow/pinn_solution.npz
Binary file not shown.
Binary file modified example_outputs/flow/pinn_training.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 23 additions & 65 deletions examples/example_1_50x50_to_model.ipynb

Large diffs are not rendered by default.

34 changes: 19 additions & 15 deletions examples/example_2_100x100_to_model.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/example_3_model_properties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"\n",
"path = os.getcwd()\n",
"\n",
"%matplotlib widget\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
Expand Down
11 changes: 10 additions & 1 deletion examples/example_4_porespy_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"Maruti K. Mudunuru"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install tqdm # For modules that use tdqm loading bars in notebook environments"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand All @@ -37,7 +46,7 @@
"\n",
"path = os.getcwd()\n",
"\n",
"%matplotlib widget\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
Expand Down
14 changes: 12 additions & 2 deletions examples/example_5_vtk_exporting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
"Maruti K. Mudunuru"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install tqdm # For modules that use tdqm loading bars in notebook environments"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -40,9 +49,10 @@
"\n",
"path = os.getcwd()\n",
"\n",
"%matplotlib widget\n",
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2"
"%autoreload 2\n",
"os.makedirs('example_outputs', exist_ok=True) # Ensures output folder exists"
]
},
{
Expand Down
65 changes: 31 additions & 34 deletions examples/example_6_flow_2d_numerical_on_XCT.ipynb

Large diffs are not rendered by default.

136 changes: 75 additions & 61 deletions examples/example_7_flow_2d_pinn_on_XCT.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ numpy
opencv-python
openpnm
porespy
pypardiso
scikit-image
scipy
yapf
svglib
reportlab
reportlab==3.6.13
cairosvg
gstools
jaxlib
Expand Down
164 changes: 36 additions & 128 deletions src/flow/plotting_results.py
Comment thread
maruti-iitm marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -79,63 +79,46 @@ def plot_2d_permeability_seg(X, Y, perm_field, results_dir):
plt.savefig(results_dir + filename, dpi=dpi)


def plot_boundary_conditions(x_b1, y_b1, bc_1, x_b2, y_b2, bc_2, x_b3, y_b3,
bc_3, x_b4, y_b4, bc_4, x_c, y_c, results_dir):
def plot_boundary_conditions(x_b1, y_b1, bc_1, x_b2, y_b2, bc_2,
x_b3, y_b3, bc_3, x_b4, y_b4, bc_4,
x_c, y_c, results_dir):
plt.figure(figsize=(width, height), dpi=dpi)
s = 10
plt.scatter(x_b1,
y_b1,
c=bc_1,
marker='x',
vmin=0,
vmax=2,
label='P[0,y] = 0',
cmap=cm.jet,
s=s)
plt.scatter(x_b2,
y_b2,
c=bc_2,
marker='^',
vmin=0,
vmax=2,
label='P[1,y] = y',
cmap=cm.jet,
s=s)
plt.scatter(x_b3,
y_b3,
c=bc_3,
marker='*',
vmin=0,
vmax=2,
label='$\\partial P/\\partial y[x,0] = 0$',
cmap=cm.jet,
s=s)
plt.scatter(x_b4,
y_b4,
c=bc_4,
marker='o',
vmin=0,
vmax=2,
label='$\\partial P/\\partial y[x,1] = 0$',
cmap=cm.jet,
s=s)
s = 5
plt.scatter(x_c,
y_c,
c='k',
marker='.',
alpha=0.5,
label='Collocation points',
s=s)

# Compute vmin and vmax across all boundary condition values
all_bc_values = np.concatenate([bc_1, bc_2, bc_3, bc_4])
vmin = np.min(all_bc_values)
vmax = np.max(all_bc_values)

s = 3

# Plot the first boundary condition and link it to the colorbar
sc = plt.scatter(x_b1, y_b1, c=bc_1, marker='x', vmin=vmin, vmax=vmax,
label='P[0,y]', cmap=cm.jet, s=s)

# Remaining boundary conditions
plt.scatter(x_b2, y_b2, c=bc_2, marker='^', vmin=vmin, vmax=vmax,
label='P[1,y]', cmap=cm.jet, s=s)
plt.scatter(x_b3, y_b3, c=bc_3, marker='*', vmin=vmin, vmax=vmax,
label='$\\partial P/\\partial y[x,0]$', cmap=cm.jet, s=s)
plt.scatter(x_b4, y_b4, c=bc_4, marker='o', vmin=vmin, vmax=vmax,
label='$\\partial P/\\partial y[x,1]$', cmap=cm.jet, s=s)

# Collocation points
plt.scatter(x_c, y_c, c='k', marker='.', alpha=0.5,
label='Collocation points', s=1)

# Labels and colorbar
plt.xlabel('$X$')
plt.ylabel('$Y$')
cbar = plt.colorbar(mpl.cm.ScalarMappable(norm=mpl.colors.Normalize(
vmin=0, vmax=2),
cmap=cm.jet),
aspect=30)
cbar = plt.colorbar(sc, aspect=30)
cbar.set_label('Pressure (kPa)')

#plt.legend(fontsize=6)
# plt.legend(fontsize=6, loc='best', frameon=True,
# title='Legend', title_fontsize=6)
plt.legend(fontsize=6, loc='upper left', bbox_to_anchor=(0.50, 0.95))
plt.tight_layout()

figure_name = 'bcs_collocs'
plt.savefig(results_dir + figure_name + figure_format,
dpi=dpi,
Expand All @@ -144,53 +127,6 @@ def plot_boundary_conditions(x_b1, y_b1, bc_1, x_b2, y_b2, bc_2, x_b3, y_b3,
plt.show()


def save_legend_as_image(results_dir):
plt.figure(figsize=(width, height), dpi=dpi)
fig, ax = plt.subplots()
handles = [
mlines.Line2D([], [],
color='red',
marker='x',
linestyle='None',
markersize=10,
label='P[0,y] = 0'),
mlines.Line2D([], [],
color='blue',
marker='^',
linestyle='None',
markersize=10,
label='P[1,y] = y'),
mlines.Line2D([], [],
color='green',
marker='*',
linestyle='None',
markersize=10,
label='$\\partial P/\\partial y[x,0] = 0$'),
mlines.Line2D([], [],
color='purple',
marker='o',
linestyle='None',
markersize=10,
label='$\\partial P/\\partial y[x,1] = 0$'),
mlines.Line2D([], [],
color='black',
marker='.',
linestyle='None',
markersize=10,
label='Collocation points')
]
legend = ax.legend(handles=handles,
loc='upper right',
fontsize=fontsize,
fancybox=True)
plt.tight_layout()
ax.axis('off')
fig.canvas.draw()
bbox = legend.get_window_extent().transformed(
fig.dpi_scale_trans.inverted())
filename = 'bc_colloc_legends.png'
fig.savefig(results_dir + filename, dpi=dpi, bbox_inches=bbox)
plt.close()


#%% plot for pinn loss
Expand Down Expand Up @@ -232,6 +168,7 @@ def plot_2d_pressure_distribution(X, Y, pressure, cbar_lebel, title, fig_name,
plt.ylabel('$Y$')
filename = fig_name + '.png'
plt.savefig(results_dir + filename, dpi=dpi)
plt.show()


def plot_pressure_along_x(X, Y, pressure, title, fig_name, results_dir):
Expand Down Expand Up @@ -298,35 +235,6 @@ def plot_2d_pressure_distribution_masked(X, Y, pressure, perm_field,
plt.savefig(results_dir + filename, dpi=dpi)
# Set masked values to zero
pressure_with_zeros = masked_pressure.filled(0)

plt.show()
return pressure_with_zeros


def plot_gradient_field(X, Y, grad_head_x, grad_head_y, fig_title, scale,
results_dir):
plt.figure(figsize=(width, height), dpi=dpi)

# Calculate the magnitude of the gradient vectors
magnitude = np.sqrt(grad_head_x**2 + grad_head_y**2)

# Determine vmin and vmax based on the actual values of grad_head_x and grad_head_y
vmin = min(np.min(grad_head_x), np.min(grad_head_y))
vmax = max(np.max(grad_head_x), np.max(grad_head_y))

# Plot gradient vectors with color range based on actual vmin and vmax
quiver = plt.quiver(X,
Y,
grad_head_x,
grad_head_y,
magnitude,
scale=scale,
cmap='jet')
quiver.set_clim(vmin, vmax) # Set the color range without normalization

plt.colorbar(quiver, label='Gradient magnitude')
plt.title(f'{fig_title}')
plt.xlabel('X (m)')
plt.ylabel('Y (m)')
plt.xlim([X.min(), X.max()])
plt.ylim([Y.min(), Y.max()])
plt.show()
16 changes: 14 additions & 2 deletions src/pore2chip/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def network2svg(
throat_random_debug=False,
no_throats=False,
middle_pores=None,
disconnected=None
): # Boolean to draw perp. lines for throat placement (debugging)
disconnected=None,
throat_vector_thres=None): # Boolean to draw perp. lines for throat placement (debugging)
r"""
Create an SVG file from an OpenPNM network.
The network2svg function converts an OpenPNM network into an SVG image.
Expand Down Expand Up @@ -210,6 +210,18 @@ def network2svg(
pore1_coords = [pore1_x, (-pore1_y) + d2]
pore2_coords = [pore2_x, (-pore2_y) + d2]

# If small throats are vectors
if throat_vector_thres is not None:
if generated_network['throat.diameter'][throat_index] < throat_vector_thres:
design.append(
dr.Line(pore1_coords[0],
pore1_coords[1],
pore2_coords[0],
pore2_coords[1],
stroke='red',
stroke_width=1))
continue

# Distance between the two pores
distance = math.dist(pore1_coords, pore2_coords)

Expand Down
1 change: 1 addition & 0 deletions src/pore2chip/filter_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def filter_single(image,
thresh (int): Threshold value. If not given, then Otsu's threshold is used
gauss (int): Radius of Gaussian Blur. Default is 5
invert (Boolean): Inverts pixel values of image
returnthres (Boolean): Returns the threshold value calculated using Otsu

Returns:
2D numpy array: Filtered image
Expand Down
2 changes: 1 addition & 1 deletion tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Set up the module path (I am in tests folder)
# Modify these lines if the pore2chip package is not in the PYTHONPATH
mod_path = Path("__file__").resolve().parents[2]
mod_path = Path(os.getcwd()).resolve().parent
sys.path.append(os.path.abspath(mod_path))

# Importing specific functions for exporting network data to SVG and DXF formats
Expand Down
4 changes: 0 additions & 4 deletions tests/test_filter_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def main():
ax[2].imshow(filtered2)
ax[3].imshow(filtered3)
plt.show()
plt.waitforbuttonpress() # Wait for a user interaction before closing
plt.close()

### Advanced Tests ###

Expand All @@ -93,8 +91,6 @@ def main():
ax[2].imshow(filtered_stack[1])
ax[3].imshow(filtered_stack[2])
plt.show()
plt.waitforbuttonpress() # Wait for user interaction before closing
plt.close()


if __name__ == "__main__":
Expand Down