Initializing Feel++
The core
module provides the basic data structures to
-
setup and run Feel++ application in a parallel environment.
-
handle the command line options
-
download and upload data from and to GitHub and/or Girder
1. Setting up the Feel++ Environment
To set Feel++ environment, we create an environment and set the associated repository for the results.
A Feel++ environment can be created only once.
The repository can be global with respect to $HOME/.feelppconfig
globalroot
setting or local with respect to the current directory.
import feelpp.core as fppc
import sys
app = fppc.Environment(["myapp"],config=fppc.localRepository(""))
Results
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/PETSc.py:3 2 from petsc4py.lib import ImportPETSc # noqa: E402 ----> 3 PETSc = ImportPETSc(ARCH) 4 PETSc._initialize() File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:29, in ImportPETSc(arch) 28 path, arch = getPathArchPETSc(arch) ---> 29 return Import('petsc4py', 'PETSc', path, arch) File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:95, in Import(pkg, name, path, arch) 94 # import extension module from 'path/arch' directory ---> 95 module = import_module(pkg, name, path, arch) 96 module.__arch__ = arch # save arch value File /usr/lib/petsc/lib/python3/dist-packages/petsc4py/lib/__init__.py:73, in Import..import_module(pkg, name, path, arch) 72 sys.modules[fullname] = module ---> 73 spec.loader.exec_module(module) 74 return module File petsc4py/PETSc.pyx:1, in init petsc4py.PETSc() ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject The above exception was the direct cause of the following exception: SystemError Traceback (most recent call last) File :1 ----> 1 import feelpp.core as fppc 2 import sys 3 app = fppc.Environment(["myapp"],config=fppc.localRepository("")) File /usr/lib/python3/dist-packages/feelpp/core/__init__.py:12 10 from ._feelpp import * 11 from ._core import * ---> 12 from ._alg import * 13 from ._mesh import * 14 from ._plot import * SystemError: initialization of _alg raised unreported exception
print("pid:",app.worldComm().localRank() )
print("isMasterRank:",app.isMasterRank() )
print("is parallel: ",app.isParallel() )
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 print("pid:",app.worldComm().localRank() ) 2 print("isMasterRank:",app.isMasterRank() ) 3 print("is parallel: ",app.isParallel() ) NameError: name 'app' is not defined
2. Downloading data
Feel++ can query data on GitHub and Girder.
readme=fppc.download( "github:{repo:feelpp,path:README.adoc}", worldComm=app.worldCommPtr() )[0]
print("downloaded Feel++ README.adoc from Github: ",readme)
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 readme=fppc.download( "github:{repo:feelpp,path:README.adoc}", worldComm=app.worldCommPtr() )[0] 3 print("downloaded Feel++ README.adoc from Github: ",readme) NameError: name 'fppc' is not defined
The code will get the file README.adoc
from the toplevel Feel++ github directory downloaded
A bit more interesting example: the following code will download a csv file from the Feel++ github repository and plot the data using the plotly
library.
acsv=fppc.download( "github:{repo:feelpp,path:toolboxes/fluid/cases/moving_body/gravity/cylinder_under_gravity/curve_comparison.csv}", worldComm=app.worldCommPtr() )[0] (1)
import pandas as pd (2)
df = pd.read_csv(acsv, sep=",") (3)
df.columns = df.columns.str.replace(' ', '')
print(df.head())
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) File:1 ----> 1 acsv=fppc.download( "github:{repo:feelpp,path:toolboxes/fluid/cases/moving_body/gravity/cylinder_under_gravity/curve_comparison.csv}", worldComm=app.worldCommPtr() )[0] # 2 import pandas as pd # 3 df = pd.read_csv(acsv, sep=",") # NameError: name 'fppc' is not defined
1 | download the file curve_comparison.csv from the Feel++ github repository toolboxes/fluid/cases/moving_body/gravity/cylinder_under_gravity/curve_comparison.csv |
2 | use the pandas library to read the csv file |
3 | read the csv file and remove the spaces in the column names |
We can now use plotly to plot the data
import plotly.express as px
fig = px.scatter(df,x="TIME", y="Y_CM", title="y-displacement of the center of mass(CM) of the cylinder",labels={"TIME":"t (s)","Y_CM":r'y-displacement (m)'})
fig.show()