Code Monkey home page Code Monkey logo

blobmodel's Introduction

blobmodel

Python version Pypi codecov Tests Checked with mypy Code style: black License: MIT Documentation Status

This package provides realizations of advecting and dissipating blobs in up to two dimensions.

All blob parameters can be choosen freely, and multiple blob shapes are implemented. Originally, the model is developed for studying the scrape-off layer of fusion experiments, but it can be applicable to many 1d or 2d systems. See the blobmodel documentation for further details.

Examples for one and two dimensions are shown below:

1D 2D
Density evolution Density evolution

Installation

The package is published to PyPI and can be installed with

pip install blobmodel

If you want the development version you must first clone the repo to your local machine, then install the project in development mode:

git clone https://github.com/uit-cosmo/blobmodel.git
cd blobmodel
python -m pip install -e .

Usage

Create a grid on which the blobs are discretized using the Model class. The make_realization() method computes the output as an xarray dataset which can also be written out as a netcdf file if the argument file_name is specified. A simple example is shown below:

from blobmodel import Model, show_model

bm = Model(Nx=200, Ny=100, Lx=10, Ly=10, dt=0.1, T=20, blob_shape='gauss',num_blobs=100)

ds = bm.make_realization(file_name="example.nc")

The data can be shown as an animation using the show_model function:

show_model(ds)

You can specify the blob parameters with a BlobFactory class. The DefaultBlobFactory class has some of the most common distribution functions implemented. An example would look like this:

from blobmodel import Model, DefaultBlobFactory

# use DefaultBlobFactory to define distribution functions of random variables
bf = DefaultBlobFactory(A_dist="exp", wx_dist="uniform", vx_dist="deg", vy_dist="normal")

# pass on bf when creating the Model
tmp = Model(
    Nx=100,
    Ny=1,
    Lx=10,
    Ly=0,
    dt=1,
    T=1000,
    blob_shape="exp",
    t_drain=2,
    periodic_y=False,
    num_blobs=10000,
    blob_factory=bf,
)

Alternatively, you can specify all blob parameters exactly as you want by writing your own class which inherits from BlobFactory. See examples/custom_blobfactory.py as an example or take a look at the blobmodel documentation.

Contributing

Feel free to raise issues about anything. Contributions through pull requests are also very welcome. Please take a look at our Contributor guide for further details.

blobmodel's People

Contributors

auroradh avatar ema109 avatar gregordecristoforo avatar leanderkirkeland avatar sajidah-ahmed avatar sosnowsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

blobmodel's Issues

Blob throws TypeError

I think the following code should run

`
blob_sp = Blob(
blob_id=0,
blob_shape=BlobShapeImpl("gauss"),
amplitude=1,
width_prop=1,
width_perp=1,
velocity_x=1,
velocity_y=1,
pos_x=0,
pos_y=6,
t_init=0,
t_drain=10**100)

x = 0
y = 0
times = np.arange(1, 5, 0.01)

mesh_x, mesh_y, mesh_t = np.meshgrid(x, y, times)
blob_values = blob_sp.discretize_blob(
x=mesh_x, y=mesh_y, t=mesh_t, periodic_y=True, Ly=10)
`

However, it Throws TypeError. It can be fixed by adding .astype(float) on the drain function of Blob, but I am not sure why it throws here and not in the regular use case.

Add user defined geometry.

I have a use case where I want to have closely spaced probes, but I don't want these to cover all the domain, as that would slow down the simulation drastically. Therefore, I propose adding the possibility of user defined grids. As it is now, the only possible grid will cover the simulation domain uniformly, the change will allow the user to specify any grid (in my use case, that would be a grid containing a few close points, and otherwise empty).

Some reqs missing

When cloning and pip installing the requirements I get the following missing modules for examples/analyse_output.py.

ModuleNotFoundError: No module named 'netCDF4'
ModuleNotFoundError: No module named 'scipy'

Not sure if this is expected

tilted blobs

Implement tilted blob propagation so that blob front is perpendicular to the propagation direction.

Maybe specify v_total and angle for each blob instead of v_x and v_y

add potential as variable

Add potential as variable to the model so that consistent density n and potential phi can be written out.

Can be used for ExB velocity estimations

Encapsulate geometry

This is just a design issue.
Grid initialization and possibly also boundary conditions should be relegated to its own class. This will improve encapsulation and flexibility. This is in line with the single-responsibility principle https://en.wikipedia.org/wiki/Single-responsibility_principle

Helper classes should also be implemented to preserved ease of use: default simulations can now be implemented in three lines of user code and should still be so after the refactor.

Encapsulate stochasticity

This is just a design issue.
Stochasticity -all random variables- should be relegated to its own class. This will improve encapsulation and flexibility. This is in line with the single-responsibility principle https://en.wikipedia.org/wiki/Single-responsibility_principle

Helper classes should also be implemented to preserved ease of use: default simulations can now be implemented in three lines of user code and should still be so after the refactor.

make t_drain a function of x

Cmod data does not show constant t_drain in the SOL. In order to use this module to reproduce profiles t_drain must be therefore a function of x

write out fields with blob labels

This model should be used to create data to train a convolutional neural network (CNN). For this, the blob labels must be available.

add example for 1D model

Provide an example for the 1D case in the README, and provide an animation function for the 1D case.

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.