zwicker-group / py-pde

Python package for solving partial differential equations using finite differences.
https://py-pde.readthedocs.io
MIT License
402 stars 51 forks source link

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

Closed iamlll closed 1 year ago

iamlll commented 1 year ago

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 https://github.com/zwicker-group/py-pde/discussions/366

Originally posted by **louis10643** February 21, 2023 Hi, Is it possible to solve transient anisotropic heat transfer equation using py-pde? ![image](https://user-images.githubusercontent.com/29681897/220331481-332a4c34-59bf-4cb9-b6f3-bdbc435375d5.png) where kx, ky, kz are all different. I tried to use diffusion module but its D only takes constant as parameter.
david-zwicker commented 1 year ago

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

iamlll commented 1 year ago

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')
david-zwicker commented 1 year ago

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?

iamlll commented 1 year ago

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}}

david-zwicker commented 1 year ago

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.

iamlll commented 1 year ago

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?

david-zwicker commented 1 year ago

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

iamlll commented 1 year ago

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'

david-zwicker commented 1 year ago

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