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
print("pid:",app.worldComm().localRank() )
print("isMasterRank:",app.isMasterRank() )
print("is parallel: ",app.isParallel() )
Results
pid: 0 isMasterRank: True is parallel: False
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
downloaded Feel++ README.adoc from Github: /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/feelppdb/downloads/README.adoc
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
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) File:3 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=",") # 4 df.columns = df.columns.str.replace(' ', '') 5 print(df.head()) File /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/.venv/lib/python3.12/site-packages/pandas/io/parsers/readers.py:948, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend) 935 kwds_defaults = _refine_defaults_read( 936 dialect, 937 delimiter, (...) 944 dtype_backend=dtype_backend, 945 ) 946 kwds.update(kwds_defaults) --> 948 return _read(filepath_or_buffer, kwds) File /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/.venv/lib/python3.12/site-packages/pandas/io/parsers/readers.py:611, in _read(filepath_or_buffer, kwds) 608 _validate_names(kwds.get("names", None)) 610 # Create the parser. --> 611 parser = TextFileReader(filepath_or_buffer, **kwds) 613 if chunksize or iterator: 614 return parser File /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/.venv/lib/python3.12/site-packages/pandas/io/parsers/readers.py:1448, in TextFileReader.__init__(self, f, engine, **kwds) 1445 self.options["has_index_names"] = kwds["has_index_names"] 1447 self.handles: IOHandles | None = None -> 1448 self._engine = self._make_engine(f, self.engine) File /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/.venv/lib/python3.12/site-packages/pandas/io/parsers/readers.py:1705, in TextFileReader._make_engine(self, f, engine) 1703 if "b" not in mode: 1704 mode += "b" -> 1705 self.handles = get_handle( 1706 f, 1707 mode, 1708 encoding=self.options.get("encoding", None), 1709 compression=self.options.get("compression", None), 1710 memory_map=self.options.get("memory_map", False), 1711 is_text=is_text, 1712 errors=self.options.get("encoding_errors", "strict"), 1713 storage_options=self.options.get("storage_options", None), 1714 ) 1715 assert self.handles is not None 1716 f = self.handles.handle File /scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/.venv/lib/python3.12/site-packages/pandas/io/common.py:863, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options) 858 elif isinstance(handle, str): 859 # Check whether the filename is to be opened in binary mode. 860 # Binary mode does not support 'encoding' and 'newline'. 861 if ioargs.encoding and "b" not in ioargs.mode: 862 # Encoding --> 863 handle = open( 864 handle, 865 ioargs.mode, 866 encoding=ioargs.encoding, 867 errors=errors, 868 newline="", 869 ) 870 else: 871 # Binary mode 872 handle = open(handle, ioargs.mode) FileNotFoundError: [Errno 2] No such file or directory: '/scratch/github-runners/feelpp-actions-runner-0/_work/book.feelpp.org/book.feelpp.org/feelppdb/downloads/curve_comparison.csv'
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()