Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A library for building finite difference simulations

License

NotificationsYou must be signed in to change notification settings

stefanmeili/FastFD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A finite differences simulation library.

This package lets you quickly build simple numerical simulations.

Features

  • Quickly build finite difference simulations with an arbitrary number of domains, scalars, dimensions and boundary conditions.
  • Concise, clear syntax.
  • Build models for CPU or GPU using Scipy or Cupy sparse libraries.
  • Arbitrary derivative order and approximation accuracy.
  • Partial model updates minimize overheads in iterative solutions.
  • Implicit transient simulation.

Installation

pip install fastfd

Usage

# Import fastfd and select the scipy sparse library (or cupy for GPU support)importfastfdasffdffd.sparse_lib('scipy')importnumpyasnp# Define axesx=ffd.LinearAxis('x',start=0,stop=1,num=201)y=ffd.LinearAxis('y',start=0,stop=1,num=201)# Define scalarsT=ffd.Scalar('T', [x,y],accuracy=4)# Define the modelmodel=ffd.FDModel([T])# Set model governing equations (thermal diffusion)model.update_equations({'Conductivity': ((T.d('x',2)+T.d('y',2)),0),})# Set model boundary conditionsmodel.update_bocos({'Tx=1 adiabatic': (T.i[-1, :],T.d('x')[-1, :],0),'Ty=1 adiabatic': (T.i[:,-1],T.d('y')[:,-1],0),'Tx=0 sinewave': (T.i[0, :],T.i[0, :],100*np.sin(x.coords*2*np.pi)),'Ty=0 sinewave': (T.i[:,0],T.i[:,0],-100*np.sin(y.coords*2*np.pi)),})# Solve the modelresult=model.solve()

Model Solution

GPU

FastFD can be set to use the Cupyx sparse libraries, though support is still a little rough around the edges. The currentversion of Cupy (8.5) only supports a least squares solver ('lsqr') which is much slower than the default 'spsolve'.However, spsolve will be implemented in the upcoming release of Cupy 9.0.

Example Notebooks

See example notebooks here: ./docs/examples for a more detailed explanation of how to use.

Steady state heat conductionTransient 1D wave propagationTransient 2D wave propagation


[8]ページ先頭

©2009-2025 Movatter.jp