Coder Social home page Coder Social logo

sebastiaagramunt / micromagnetics Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4.14 MB

A package for micromagnetism in python

License: MIT License

Makefile 0.04% Python 1.30% Dockerfile 0.02% Jupyter Notebook 98.57% Shell 0.07%
physics-simulation physics magnetism micromagnetics

micromagnetics's People

Contributors

dependabot[bot] avatar sebastiaagramunt avatar

Watchers

 avatar  avatar

micromagnetics's Issues

Refactor Docker related stuff

Current docker files Dockerfile and makefile for docker are based on a previous package version. We now install things on poetry, we may change the images and write proper documentation

Derivatives

Need to implement the derivatives to calculate the exchange energy/field.

def derivative_coefficients(stencil: List[float], deg: int):
    """
    Calculates the coefficients for the numerical derivative
    Inputs:
        deg: int -> the max degree of the derivatives
    Output:
        The coefficients to calculate the derivative at one point. 
    Refs:
        http://web.media.mit.edu/~crtaylor/calculator.html
        https://en.wikipedia.org/wiki/Finite_difference_coefficient
    """

    # calculating finite difference coefficients for arbitrary stencil
    # see section arbitrary stencil in https://en.wikipedia.org/wiki/Finite_difference_coefficient
    N = len(stencil)
    stencil_matrix = np.zeros((N, N), dtype=np.int64)
    for i, j in [(x, y) for x in range(N) for y in range(N)]:
        stencil_matrix[i][j] = pow(stencil[j], i)

    stencil_matrix_inv = np.linalg.inv(stencil_matrix)
    v = np.array(
        [0 if i != deg else np.math.factorial(deg) for i in range(N)], dtype=np.int
    )

    return stencil_matrix_inv.dot(v)

def numeric_derivative(target_fn: Callable, stencil: List[float], a: float, h: float, deg: int):

    """
    Calculate numerical d derivative at point a using points in self.strencil
    Input:
        a: point where we want to calculate the derivative
        h: separation between evaluation points
        deg: degree of the numeric derivative
    """

    coeffs = derivative_coefficients(deg)
    res = 0
    for s, coef in zip(stencil, coeffs):
        res += coef * target_fn(a + s * h) / pow(h, deg)

    return res

Numeric derivative here calculates the derivative of a callable function at at a point a using a stencil. The idea is to adapt this code to calculate the derivative of the magnetisation at the center of a cell i. Initially in a regular grid (also with edges) and then as a general grid with a different stencil.

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.