Skip to content

Conversation

@ma-sadeghi
Copy link
Member

@ma-sadeghi ma-sadeghi commented Dec 16, 2021

Closes #2207.

Here's a working example:

import numpy as np
import openpnm as op
import matplotlib.pyplot as plt

Nx = 101
shape = [Nx, 1, 1]
spacing = 1/Nx * 5
net = op.network.Cubic(shape=shape, spacing=spacing)
air = op.phases.Air(network=net)
air["throat.diffusive_conductance"] = spacing * np.ones(net.Nt)
net["pore.volume"] = spacing**3

# Set up transient Fickian diffusion algorithm
tfd = op.algorithms.TransientFickianDiffusion(network=net, phase=air)
tfd.set_value_BC(net.pores("left"), 0)
tfd.set_value_BC(net.pores("right"), 0)

# Define a pulse signal
def pulse(t, y):
    if 0 <= t <= 0.05:
        y[net.Np//2] = 1.0

# Add the pulse signal to the algorithm as a callback
tfd.set_callback(pulse)

# Solve the transient algorithm
c0 = np.zeros(tfd.Np)
tspan = [0, 0.4]
sol = tfd.run(x0=c0, tspan=tspan)

# Plot c vs. time
tout = np.linspace(tspan[0], tspan[1], 10)
fig, ax = plt.subplots()
for i, t in enumerate(tout):
    ax.plot(sol(t), label=f"{t:.2f} (s)")
ax.legend()
ax.set_title("Dissipation of a pulse signal , c(x=0,L) = 0")
ax.set_xlabel("distance (m)")
ax.set_ylabel("concentration (mol/m$^3$)")

@codecov
Copy link

codecov bot commented Dec 16, 2021

Codecov Report

Merging #2254 (f5264f5) into dev (31f6b26) will decrease coverage by 0.0%.
The diff coverage is 88.8%.

Additional details and impacted files
@@           Coverage Diff           @@
##             dev   #2254     +/-   ##
=======================================
- Coverage   89.8%   89.8%   -0.1%     
=======================================
  Files        145     145             
  Lines       8405    8414      +9     
=======================================
+ Hits        7555    7563      +8     
- Misses       850     851      +1     

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.

Add a apply_callbacks method to the Transient solver

3 participants