Giter VIP home page Giter VIP logo

fastfd's Introduction

FastFD

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)
import fastfd as ffd
ffd.sparse_lib('scipy')

import numpy as np

# Define axes
x = ffd.LinearAxis('x', start = 0, stop = 1, num = 201)
y = ffd.LinearAxis('y', start = 0, stop = 1, num = 201)

# Define scalars
T = ffd.Scalar('T', [x, y], accuracy = 4)

# Define the model
model = 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 conditions
model.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 model
result = 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 current version 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 conduction Transient 1D wave propagation Transient 2D wave propagation

fastfd's People

Contributors

stefanmeili avatar

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.