zwicker-group / py-pde

Python package for solving partial differential equations using finite differences.

Home Page:https://py-pde.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to solve transient anisotropic heat transfer equation using py-pde?

iamlll opened this issue · comments

commented

Hello,

I am trying to simulate a similar sort of equation as was discussed previously (see below). The equation I'm interested in also requires unidirectional derivative operators d/dx, d/dy, and d/dz. An simplified snippet of code I used to define my equations is
expr = {'x': f'{A}*d_dx(d_dy(y)) + [isotropic terms]', 'y': f'{A}*d_dx(d_dy(x)) + [isotropic terms]'}, based on Example 2.12.
eq = pde.PDE(expr)
This formulation worked several weeks ago, but now somehow I am now getting NameError messages (in _lambdifygenerated) that "d_dx is not defined" when I try to solve the resulting system of equations using
result = eq.solve(state,t_range=tmax,dt=1E-2,tracker=writer.tracker(dt))
The simulation runs without any issue if I set A = 0.
Do you have any idea what might be causing this? I am quite new to using your package, so any suggestions or advice would be much appreciated!

Discussed in #366

Originally posted by louis10643 February 21, 2023
Hi,

Is it possible to solve transient anisotropic heat transfer equation using py-pde?
image

where kx, ky, kz are all different.

I tried to use diffusion module but its D only takes constant as parameter.

Could you please post a complete minimal example that reproduces the error? This would help us to locate the error!

commented

For sure, sorry about that!

def MWE():
    L = 10; resolution = 2;
    np.random.seed(0)
    grid = pde.CartesianGrid([[-int(L/2), int(L/2)], [-int(L/2),int(L/2)]], [int(resolution*L), int(resolution*L)], periodic=True)
    B = 0.1; A = 1

    bins = np.linspace(-L/2,L/2,int(resolution*L))

    expr = {
        'xx': f'{B}*d_dx(xx) + {A}',
    }
    x = pde.ScalarField.random_uniform(grid,label='xx') - 0.5

    eq = pde.PDE(expr,bc="auto_periodic_neumann")
    state = pde.FieldCollection([x])
    storage = pde.MemoryStorage()
    result = eq.solve(state,t_range=tmax,dt=1E-2,tracker=storage.tracker(0.1))
    state.plot()
    result.plot()
    print('done')

The problem runs without issues on my computer, so I suspect that you setup might be compromised. Could you post the output of running pde.environment() here?

commented

OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
{'package version': '0.16.7', 'python version': '3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:38:11) \n[Clang 14.0.6 ]', 'platform': 'darwin', 'config': {'numba.debug': False, 'numba.fastmath': True, 'numba.parallel': True, 'numba.parallel_threshold': 65536}, 'mandatory packages': {'matplotlib': '3.4.2', 'numba': '0.54.1', 'numpy': '1.20.3', 'scipy': '1.7.0', 'sympy': '1.9'}, 'matplotlib environment': {'backend': 'MacOSX', 'plotting context': 'BasicPlottingContext'}, 'optional packages': {'h5py': '3.8.0', 'napari': 'not available', 'pandas': '1.3.0', 'pyfftw': 'not available', 'tqdm': '4.62.3'}, 'numba environment': {'version': '0.54.1', 'parallel': True, 'fastmath': True, 'debug': False, 'using_svml': False, 'threading_layer': 'omp', 'omp_num_threads': None, 'mkl_num_threads': None, 'num_threads': 8, 'num_threads_default': 8, 'cuda_available': False, 'roc_available': False}}

The output shows that you use the very outdated version 0.16.7 of the py-pde package. The current version is 0.28.0, so you should simply update and see whether the error disappears.

commented

That worked, thank you so much! Although now the pde.environment() command no longer works and returns a FileNotFound error. Was this function deprecated in the newest version of py-pde?

This is strange – can you post the exact traceback (the full error message)?

commented

pde.environment()
Traceback (most recent call last):
File "", line 1, in
File "/opt/homebrew/Caskroom/miniforge/base/envs/bread/lib/python3.9/site-packages/pde/tools/config.py", line 273, in environment
packages_min = packages_from_requirements(PACKAGE_PATH / "requirements.txt")
File "/opt/homebrew/Caskroom/miniforge/base/envs/bread/lib/python3.9/site-packages/pde/tools/config.py", line 237, in packages_from_requirements
with open(requirements_file) as fp:
FileNotFoundError: [Errno 2] No such file or directory: '/opt/homebrew/Caskroom/miniforge/base/envs/bread/lib/python3.9/site-packages/requirements.txt'

Thanks for the report! I opened this as the new issue #399 since this is an unrelated problem.