{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Manipulate Datafiles\n\nThis snippet loads a datafile and modifies its contents\n\nDownload Input files\n\n* :download:`dipole_2d.data <../../../../../examples/input_files/dipole_2d.data>`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting up\nLoad Datafile into RoxieInputBuilder object\n\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pathlib\nimport tempfile\n\nfrom roxieapi.input.builder import RoxieInputBuilder\n\nfolder = pathlib.Path(\"../input_files\").absolute()\ndatafile = \"dipole_2d.data\"\n\nrib = RoxieInputBuilder.from_datafile(folder / datafile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Change flags and metadata\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "rib.comment = \"Python modified datafile\"\nrib.flags[\"LDEBUG\"] = True\nrib.flags[\"LFORCE2D\"] = True\n\nrib.flags" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check defined Blocks\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "rib.block" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Update alpha angle of block no 4\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Dataframe index 3 corresponds to Block no 4\nrib.block.loc[3, \"alpha\"] = 23.2\n\nrib.block" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate new datafile\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "tmp_dir = pathlib.Path(tempfile.gettempdir())\ntmp_file = tmp_dir / \"temp.data\"\nrib.build(str(tmp_file))\n\nwith open(tmp_file, \"r\") as f:\n print(f.read())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.20" } }, "nbformat": 4, "nbformat_minor": 0 }