Giter Site home page Giter Site logo

maxibove13 / rheos Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 811 KB

Program aimed to build a block grid simulation domain for later use in a flow simulation in caffa3d LES-CFD and visualize the resulting fields.

Python 27.50% MATLAB 16.71% Fortran 51.80% Jupyter Notebook 3.99%

rheos's Introduction

rheos

Ancient Greek: ρεω (rhéō, "flow")


Everything flows and nothing stand still.

Heraclitus


Program aimed to build a block grid simulation domain for later use in a flow simulation in caffa3d LES-CFD and visualize the resulting fields.


Python where we can, C where we must

Sergey, Larry, Craig


Installation

I. pip

  1. Create a virtual environment (See venv section below) in rheos project root folder.

    i. Create venv

    python3 -m venv .venv
  2. Install necessary dependencies via requirements.txt

    pip install -r requirements.txt
  3. Add your virtual environment to Jupyter (the interactive IDE)

    python -m ipykernel install --user --name=.venv
  4. (Optionally) Install python matlab.engine in order to run matlab functions from python

    i. Open a matlab session and obtain the root path of matlab

    matlabroot

    ii. Go to matlabroot/extern/engines/python

    cd matlabroot/extern/engines/python

    Note that matlabroot means the path to matlab obtained in step i.

    iii. Install matlab.engine

    python setup.py install

II. conda

  1. Install Miniconda in your system.

  2. Create an environment, see this guide.

  3. Check its existence:

    conda info -envs
  4. Activate it:

    conda activate myenv
  5. Deactivate it:

    conda deactivate

Execution

Activate venv

source .venv/bin/activate

Currently thera are only two tasks implemented:

  1. Process already generated *.gin files and visualizing them in a 3D plot using mayavi library.

    i. Run main_pre.py from an IDE or terminal

    ./src/main_pre.py

    ii. Enter your casename.

    iii. Expect a modal window to popup and visualize your grid. ()

  2. Generate the 2D bottom section (the surface) of a grid block.

    i. Open igrid.ipynb in an IPython interactive IDE (Like Jupyter-Lab)

    ii. Follow the steps


Directories


samples

All the simulation cases should have a folder inside this directory.

  • duct11

    Test case. Currently it only contains block grid generating files *.gin

src/pre

Build your own simulation domain with the desired geometry and export it through some files in order to run it in CHAMAN.

  • Modules/Files

    • checkgrd

      Contains functions to read *.grd files containing grid information in binary.

    • makegrid

      Contains a function to execute grid3d.lnx program.

    • checkgrid_matlab

      Contains old MATLAB functions to read *.grd files. (Deprecated)

    • grid3d.lnx

      Program to compute and generate a structure grid block from *.gin ASCII files.

    • grid3d.MB.f

      Source code of grid3d.lnx

src/post

Takes the outputs of CHAMAN as input and generates the desired visualization of the results.


  • Modules

    • mayavi_demo

      Contains a function to test the mayavi library visualizing a fancy 3D function.

    • plotgrids

      Contains functions to plot grids.


The current main entry of this package is the script: src/main_pre.py


General Python recomendations

venv

venv is a python utlity to create virtual environment where all the python files and packages are stored isolated from the rest of your computer. Different projects needs different packages and maybe different versions of those packages and even of python, so it is a good practice to isolate the python environment of your particular project or application.

  1. Install venv in Debian/Ubuntu

    sudo apt-get install -y python3-venv
  2. Create virtual environment

    Usually, the virtual environment goes inside your project/application directory, and inside a folder called .venv

    python3 -m venv <project_dir>/.venv
  3. Activate virtual environment

    When you activate the virtual environment all the python related calls will use the python version and packages installed in your .venv directory.

    source <project_dir>/.venv/bin/activate
  4. Deactivate virtual environment

    deactivate

Dependencies

Display installed dependencies

Activate your virtual environment and type:

pip freeze

That shows a list of your installed dependencies.

Export dependencies to requirements.txt

pip freeze > requirements.txt

Install dependencies given a requirements.txt

A collection of needed dependencies are usually stored in a file called requirements.txt If such a file is present in your project, you can install all the dependencies needed for that project typing:

pip install -r requirements.txt

Jupyter extensions

Fundamentally, JupyterLab is designed as an extensible environment. JuyterLab extensions can customize or enhance any part of JupyterLab. See more here: https://jupyterlab.readthedocs.io/en/stable/user/extensions.html#installing-extensions

  1. List existing extensions

    jupyter labextension list
  2. Install an extension

    jupyter labextension install <my-extension>
  3. Uninstall an extension

    jupyter labextension uninstall <my-extension>
  4. Rebuild Jupyter

    jupyter lab build

Headers

As a convention, python scripts should roughly and generally contain the following (ultimately is up to the programmer):

  1. The interpreter path in order to run the script like an executable with the used encoding below:

    #!/usr/bin/env python3
    # -*- coding: UTF-8 -*-
  2. A Docstring with a brief description of the script/module/function/class:

    """This is a description of this module"""
  3. Some dunder names, that is, especial variables that contains info about the module.

    __author__ = "Maximiliano Bove"
    __email__ = "[email protected]"
    __status__ = "Prototype" # Could also be "Development" and "Production"
    __date__ = "06/21"
  4. All your imports separated by three categories:

    # Built-in
    import os
    import datetime
    
    # Third-party
    import numpy
    
    # Local
    from my_package.my_module import my_function

Python in VS Code

  1. Install the Python extension

  2. Inside your root project directory create a dir called .vscode.

  3. There, create a file called settings.json

  4. Specify in that file your default python interpreter for your current project (In this case I will use the interpreter of the virtual environment):

    {
      // Sets this project .venv Python interpreter
      "python.pythonPath": "/<your_path_to_venv>/.venv/bin/python3"
    }
  5. Specify formatter

    i. Go to the settings.json of your workspace and make sure you have no default formatter:

    {
      "python.formatting.provider": null
    }

    ii. Configure your format document shortcut going to Files > Preferences > Keyboard Shortcuts, and search for 'format'

    iii. Try to format your document using the configured shortcut.

    iv. When asked whether to install a formatter choose pep8 (you can choose whatever you like actually)

Comments, Tips & Reminders

  • The python interpreter has several implementations, the most common one is CPython.

  • Use SymPy to integrate symbolic mathematical expressions.

  • Use ipywidgets. You can create interactive plots and modify any variable

  • You can prevent warnings!

  • MATLAB employs a copy-on-write memory management system, where an array may only be copied to a new memory location when it is modified. In NumPy, slices of arrays are views to the original array. They are like instances, or shortcuts to the original variable, like pointers to the same memory address. So, if you modify that view, the original arrays is modified also. It's the same variable with different name, exactly the same variable. See https://realpython.com/matlab-vs-python/#an-overview-of-basic-array-operations

rheos's People

Contributors

maxibove13 avatar

Stargazers

 avatar

Watchers

 avatar

rheos's Issues

mayavi hangs

When importing mlab module of mayavi most times it hangs the program execution.
A warning related to GTK+ is also displayed.

Request of caffa3d.MBRi

Hi, Can I ask you a question?
Do you have the caffa3d.MBRi package? If you have it, would you mind share it with me?
Thank you so much!
Jin Xie

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.