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 as fpp
import sys
app = fpp.Environment(["myapp"],config=fpp.localRepository(""))
Results
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)in 1 import feelpp as fpp 2 import sys ----> 3 app = fpp.Environment(["myapp"],config=fpp.localRepository("")) AttributeError: module 'feelpp' has no attribute 'Environment'
print("pid:",app.worldComm().localRank() )
print("isMasterRank:",app.isMasterRank() )
print("is parallel: ",app.isParallel() )
Results
--------------------------------------------------------------------------- NameError Traceback (most recent call last)in ----> 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=fpp.download( "github:{repo:feelpp,path:README.adoc}", worldComm=app.worldCommPtr() )[0]
print("downloaded Feel++ README.adoc from Github: ",readme)
Results
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)in ----> 1 readme=fpp.download( "github:{repo:feelpp,path:README.adoc}", worldComm=app.worldCommPtr() )[0] 2 3 print("downloaded Feel++ README.adoc from Github: ",readme) AttributeError: module 'feelpp' has no attribute 'download'
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=fpp.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
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)in ----> 1 acsv=fpp.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=",") 4 df.columns = df.columns.str.replace(' ', '') 5 print(df.head()) AttributeError: module 'feelpp' has no attribute 'download'
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()