Giter Site home page Giter Site logo

haranjackson / pypde Goto Github PK

View Code? Open in Web Editor NEW
50.0 4.0 9.0 1.58 MB

A Python library for solving any system of hyperbolic or parabolic Partial Differential Equations. The PDEs can have stiff source terms and non-conservative components.

License: GNU Affero General Public License v3.0

CMake 0.04% C++ 98.42% C 0.92% Python 0.62%
partial-differential-equations pdes ader weno weno-schemes finite-volume finite-volume-methods euler-equations navier-stokes-equations godunov-peshkov-romenski

pypde's People

Contributors

haranjackson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pypde's Issues

Scalar field becomes filled with NaN s

Hi,
I'm trying to solve the Swift-Hohenbeg model's PDE as such:

l = 3
k_c = 0.5

grid = pde.CartesianGrid([[0, 100], [0, 100]], [100, 100])
field = pde.ScalarField.random_normal(grid, mean=10)

storage = pde.MemoryStorage()
eq = pde.PDE({"u": f"u -{l}*u**3 -laplace(laplace(u)) -{k_c**4}*u - 2*{k_c**2}*laplace(u)"})
result = eq.solve(field, t_range=100, dt=1e-2, tracker=["progress", storage.tracker(1)])
result.plot()

But for many values of l and k_c, The final result becomes a scalar field filled with NaN.

The current values causes this error.
Thanks

2D Navie-Stokes example code produces an error

TypingError Traceback (most recent call last)
Cell In [12], line 6
2 from numpy import linspace
4 from pypde import pde_solver
----> 6 out = pde_solver(u,
7 tf,
8 L,
9 F=F,
10 cfl=0.9,
11 order=2,
12 boundaryTypes='periodic')
14 x = linspace(0, L[0], nx)
15 y = linspace(0, L[1], ny)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/pypde/solvers.py:200, in pde_solver(Q0, tf, L, F, B, S, boundaryTypes, cfl, order, ndt, flux, stiff, nThreads)
196 secondOrder = nargs(F) == 3
198 print('compiling functions...')
--> 200 _F, _B, _S = generate_cfuncs(F, B, S, ndim, V)
202 solver = create_solver()
204 ret = zeros(ndt * Q0.size)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/pypde/cfuncs.py:37, in generate_cfuncs(F, B, S, ndim, V)
33 nBargs = nargs(B)
35 Fsig, Bsig, Ssig = generate_signatures(nFargs, nBargs)
---> 37 Fjit = njit(Fsig)(F)
38 Bjit = njit(Bsig)(B)
39 Sjit = njit(Ssig)(S)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/decorators.py:219, in _jit..wrapper(func)
217 with typeinfer.register_dispatcher(disp):
218 for sig in sigs:
--> 219 disp.compile(sig)
220 disp.disable_compile()
221 return disp

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/dispatcher.py:965, in Dispatcher.compile(self, sig)
963 with ev.trigger_event("numba:compile", data=ev_details):
964 try:
--> 965 cres = self._compiler.compile(args, return_type)
966 except errors.ForceLiteralArg as e:
967 def folded(args, kws):

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/dispatcher.py:129, in _FunctionCompiler.compile(self, args, return_type)
127 return retval
128 else:
--> 129 raise retval

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/dispatcher.py:139, in _FunctionCompiler._compile_cached(self, args, return_type)
136 pass
138 try:
--> 139 retval = self._compile_core(args, return_type)
140 except errors.TypingError as e:
141 self._failed_cache[key] = e

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/dispatcher.py:152, in _FunctionCompiler._compile_core(self, args, return_type)
149 flags = self._customize_flags(flags)
151 impl = self._get_implementation(args, {})
--> 152 cres = compiler.compile_extra(self.targetdescr.typing_context,
153 self.targetdescr.target_context,
154 impl,
155 args=args, return_type=return_type,
156 flags=flags, locals=self.locals,
157 pipeline_class=self.pipeline_class)
158 # Check typing error if object mode is used
159 if cres.typing_error is not None and not flags.enable_pyobject:

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler.py:716, in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
692 """Compiler entry point
693
694 Parameter
(...)
712 compiler pipeline
713 """
714 pipeline = pipeline_class(typingctx, targetctx, library,
715 args, return_type, flags, locals)
--> 716 return pipeline.compile_extra(func)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler.py:452, in CompilerBase.compile_extra(self, func)
450 self.state.lifted = ()
451 self.state.lifted_from = None
--> 452 return self._compile_bytecode()

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler.py:520, in CompilerBase._compile_bytecode(self)
516 """
517 Populate and run pipeline for bytecode input
518 """
519 assert self.state.func_ir is None
--> 520 return self._compile_core()

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler.py:499, in CompilerBase._compile_core(self)
497 self.state.status.fail_reason = e
498 if is_final_pipeline:
--> 499 raise e
500 else:
501 raise CompilerError("All available pipelines exhausted")

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler.py:486, in CompilerBase._compile_core(self)
484 res = None
485 try:
--> 486 pm.run(self.state)
487 if self.state.cr is not None:
488 break

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler_machinery.py:368, in PassManager.run(self, state)
365 msg = "Failed in %s mode pipeline (step: %s)" %
366 (self.pipeline_name, pass_desc)
367 patched_exception = self._patch_error(msg, e)
--> 368 raise patched_exception

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
354 pass_inst = _pass_registry.get(pss).pass_inst
355 if isinstance(pass_inst, CompilerPass):
--> 356 self._runPass(idx, pass_inst, state)
357 else:
358 raise BaseException("Legacy pass in use")

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.call.._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
309 mutated |= check(pss.run_initialization, internal_state)
310 with SimpleTimer() as pass_time:
--> 311 mutated |= check(pss.run_pass, internal_state)
312 with SimpleTimer() as finalize_time:
313 mutated |= check(pss.run_finalizer, internal_state)

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass..check(func, compiler_state)
272 def check(func, compiler_state):
--> 273 mangled = func(compiler_state)
274 if mangled not in (True, False):
275 msg = ("CompilerPass implementations should return True/False. "
276 "CompilerPass with name '%s' did not.")

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/typed_passes.py:105, in BaseTypeInference.run_pass(self, state)
99 """
100 Type inference and legalization
101 """
102 with fallback_context(state, 'Function "%s" failed type inference'
103 % (state.func_id.func_name,)):
104 # Type inference
--> 105 typemap, return_type, calltypes, errs = type_inference_stage(
106 state.typingctx,
107 state.targetctx,
108 state.func_ir,
109 state.args,
110 state.return_type,
111 state.locals,
112 raise_errors=self._raise_errors)
113 state.typemap = typemap
114 # save errors in case of partial typing

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/typed_passes.py:83, in type_inference_stage(typingctx, targetctx, interp, args, return_type, locals, raise_errors)
81 infer.build_constraint()
82 # return errors in case of partial typing
---> 83 errs = infer.propagate(raise_errors=raise_errors)
84 typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)
86 # Output all Numba warnings

File ~/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/typeinfer.py:1086, in TypeInferer.propagate(self, raise_errors)
1083 force_lit_args = [e for e in errors
1084 if isinstance(e, ForceLiteralArg)]
1085 if not force_lit_args:
-> 1086 raise errors[0]
1087 else:
1088 raise reduce(operator.or_, force_lit_args)

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function dot at 0x7faf3c155940>) found for signature:

dot(array(float64, 1d, C), array(float64, 1d, C))

There are 4 candidate implementations:

  • Of which 4 did not match due to:
    Overload in function '_OverloadWrapper._build..ol_generated': File: numba/core/overload_glue.py: Line 129.
    With argument(s): '(array(float64, 1d, C), array(float64, 1d, C))':
    Rejected as the implementation raised a specific error:
    LoweringError: Failed in nopython mode pipeline (step: native lowering)
    scipy 0.16+ is required for linear algebra

File "", line 3:

During: lowering "$8call_function.3 = call $2load_global.0(a, b, func=$2load_global.0, args=[Var(a, :3), Var(b, :3)], kws=(), vararg=None, varkwarg=None, target=None)" at (3)
raised from /home/valentin/anaconda3/envs/pdesolve/lib/python3.8/site-packages/numba/core/errors.py:837

During: resolving callee type: Function(<function dot at 0x7faf3c155940>)
During: typing of call at /tmp/ipykernel_14609/274012429.py (16)

File "../../tmp/ipykernel_14609/274012429.py", line 16:

During: resolving callee type: type(CPUDispatcher(<function pressure at 0x7faf13aac670>))
During: typing of call at /tmp/ipykernel_14609/274012429.py (34)

During: resolving callee type: type(CPUDispatcher(<function pressure at 0x7faf13aac670>))
During: typing of call at /tmp/ipykernel_14609/274012429.py (34)

File "../../tmp/ipykernel_14609/274012429.py", line 34:

matplotlib broke compatibility with get_cmap in new release (3.9)

matplotlib broke compatibility with get_cmap in new release (3.9)

When executing the base example on a newly installed version of py-pde:

import pde

grid = pde.UnitGrid([32,32])
state = pde.ScalarField.random_uniform(grid, -1, 1)

eq = pde.DiffusionPDE(diffusivity=0.1)
result = eq.solve(state, t_range=1, dt=0.01)
result.plot()

I receive the following traceback, which was subsequently solved by performing the command pip install --force-reinstall "matplotlib==3.8.3", which downgrades matplotlib to 3.8.3.

Other packages seem to be having the same issue (atarashansky/SAMap#148).

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File ~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:21
     [20](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:20) try:
---> [21](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:21)     from matplotlib.colormaps import get_cmap
     [22](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:22) except ImportError:

ModuleNotFoundError: No module named 'matplotlib.colormaps'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
Cell In[3], [line 1](vscode-notebook-cell:?execution_count=3&line=1)
----> [1](vscode-notebook-cell:?execution_count=3&line=1) import pde
      [3](vscode-notebook-cell:?execution_count=3&line=3) grid = pde.UnitGrid
      [4](vscode-notebook-cell:?execution_count=3&line=4) state = pde.ScalarField.random_uniform(grid)

File ~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:28
     [25](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:25) del Config  # clean name space
     [27](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:27) # import all other modules that should occupy the main name space
---> [28](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:28) from .fields import *  # @UnusedWildImport
     [29](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:29) from .grids import *  # @UnusedWildImport
     [30](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/__init__.py:30) from .pdes import *  # @UnusedWildImport

File ~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:26
      [1](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:1) """
      [2](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:2) Defines fields, which contain the actual data stored on a discrete grid.
      [3](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:3) 
   (...)
     [22](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:22) .. codeauthor:: David Zwicker <[email protected]>
     [23](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:23) """
     [25](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:25) from .base import FieldBase
---> [26](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:26) from .collection import FieldCollection
     [27](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:27) from .scalar import ScalarField
     [28](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/__init__.py:28) from .tensorial import Tensor2Field

File ~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:23
     [21](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:21)     from matplotlib.colormaps import get_cmap
     [22](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:22) except ImportError:
---> [23](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:23)     from matplotlib.cm import get_cmap
     [25](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:25) from ..grids.base import GridBase
     [26](https://file+.vscode-resource.vscode-cdn.net/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/~/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/pde/fields/collection.py:26) from ..tools.docstrings import fill_in_docstring

ImportError: cannot import name 'get_cmap' from 'matplotlib.cm' (/Users/tmroyal/Documents/composition/opuses2024/coding_projects/pde_play/.venv/lib/python3.11/site-packages/matplotlib/cm.py)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.