Skip to content

Commit

Permalink
"Gradient descent" convergence to steady-state (#176)
Browse files Browse the repository at this point in the history
* Added ArbitraryDistributionVolumeEmitter

* Updated particle weight calculation

* renamed thermionic_emission test directory to emission

* arbitrary seed from uniform distribution

* Bug fixes and changes to test

* add test for arbitrary seeding

* Changed position sampling, added test

* Removed unused imports and code

* revert traceback printout

* Added comments for binning particle positions

* increased rtol for test

* Allow input of any 2d array, add interpolation of 2d array onto current simulation grid

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated changelog

* update version

* created steady_state_descent.py file

* Added coarsening algorithm

* Added ability to read numpy data and coarsen grid

* Added regression function calculation

* Solve system of equations rather than curve fit

* Use skimage block_reduce

* Hard coded inverse exponential solve

* take mean if exponential equation can't be solved

* Added special cases to use linear regression

* Update docstring

* Added command line arguments

* Modified linear regression logic and added main function

* Added entry point

* Change output file name

* Change output file name

* Fixed interpolate grid

* updated arbitrary distribution emitter test

* Fix interpolation logic

* Changed to take in exact prediction timestep rather than a multiple

* Added ability to specify save directory

* Updated docstrings, removed unneeded files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added gradient descent test, refactored code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Changed test parameters

* Increase rtol of arbitrary seed test by 0.01

* Apply shift in BTD for zmax different than 0 (ECP-WarpX#3091)

* Include shift in t_lab when `zmax` is different than 0

* Revert "Include shift in t_lab when `zmax` is different than 0"

This reverts commit 5f786f2.

* Apply shift in BTD for zmax > 0

* Update mewarpx/mewarpx/utils_store/plasma_density_oracle.py

Co-authored-by: Roelof Groenewald <[email protected]>

* Update changelog

* AMReX: Weekly Update (ECP-WarpX#3095)

* Update version

* Add controller for plasma density oracle

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix miscellaneous issues found with clang tidy (ECP-WarpX#3083)

* fix miscellaneous issues found with clang tidy
* fix miscellaneous issues found with clang tidy
* moved default constructors and destructors to header
* fix issue
* Use default again

* Add a python script to generate timestep duration plots (ECP-WarpX#3036)

* add script to generate timestep duration plots
* disable transparent background
* fix bugs
* fix bug in doc
* Update plot_timestep_duration.rst
* add permissions
* using argparse
* using if __name__ == __main__:
* add page in workflows
* Update Docs/source/usage/workflows.rst
* added missing file
* Formatting

* Apply shift for zmax>0 in old BTD (ECP-WarpX#3094)

* Apply shift for zmax>0 in old BTD
* BTD: also shift t_slice_lab

* Use uniform error message formatting for all the amrex::Abort() calls in WarpX.cpp (ECP-WarpX#2952)

* use WARPX_ALWAYS_ASSERT_WITH_MESSAGE instead of Abort()
* fix bug
* Update Source/WarpX.cpp
* fixed bug
* fixed bug
* Update Source/WarpX.cpp
* Update Source/WarpX.cpp
Co-authored-by: Axel Huebl <[email protected]>

* WIP oracle control

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use queryWithParser to Parse v_particle_pml (ECP-WarpX#3096)

Use queryWithParser, instead of query, to parse v_particle_pml, in order to support functions like sin, cos, sqrt, etc.

* Allow oracle control bins to be overridden

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix Wrong Abort Message for PSATD w/ Time Averaging (ECP-WarpX#3098)

* Doc: Improve Doxygen Links (ECP-WarpX#3099)

* Doc: Improve Doxygen Links

- download also openPMD-api tag files & link them
- improve developer page: clearer links

* Update: .gitignore

* Added command line arguments

* Fix Mirrors for RZ (NullifyMF) (ECP-WarpX#3101)

* Fixed bugs, added info logging

* added ability to modify run_script

* removed unnecessary code

* Cleaned up code

* Fix Breaking Pip 22.1 Logic (ECP-WarpX#3106)

* CI: Fix Windows

Pip's `--no-build-isolation` says we have to have build-deps pre-installed.
But Pip does offer no option to install those from `pyproject.toml`.

* Pip 22.1: in-tree-build default

And dropped the old option with a fatal error... classic.

* Pip no-build isolation: pre-install build tools

not installed in non-isolated builds
- we want isolated builds, because they have a derministic
  path that we can cache with ccache

* fix bug (ECP-WarpX#3110)

* Fix Laser Injection in RZ (ECP-WarpX#3104)

* Add STL files support in pywarpx (ECP-WarpX#3089)

* Added STL files support in pywarpx

* Add new EB bucket

* Added name to file headers

* Fixing year in  file headers

* Checking that stl file and imp function are not both specified

* Renamed EB bucket to EB2

* Adding STL documentation

* Implement suggestions from code review

Co-authored-by: lgiacome <[email protected]>

* Stricter Tolerance for 3D Langmuir Tests (ECP-WarpX#3097)

* CI: HIP with https (ECP-WarpX#3111)

Small update in HIP docs: now supports HTTPS:
https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu

* Add Headers to Input File Written by PICMI (ECP-WarpX#3093)

* Add Headers to Input File Written by PICMI
* Commit Suggestion by @dpgrote
* Add Comment
* Add Empty Line
* Slightly Better Readable with a newline

* Refactored code to be clearer

* AMReX/PICSAR: Weekly Update (ECP-WarpX#3112)

* AMReX: Weekly Update

* PICSAR: Weekly Update

* [pre-commit.ci] pre-commit autoupdate (ECP-WarpX#3113)

updates:
- [github.com/Lucas-C/pre-commit-hooks: v1.1.13 → v1.1.14](Lucas-C/pre-commit-hooks@v1.1.13...v1.1.14)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Use uniform error message formatting in more source files (ECP-WarpX#2964)

* use WARPX_ALWAYS_ASSERT_WITH_MESSAGE instead of Abort()

* fix bug

* Update Source/WarpX.cpp

Co-authored-by: Axel Huebl <[email protected]>

* use more uniform text formatting

* fixed bug

* fixed bug

* using Utils::TextMsg in more files

* fixed bug

* use Utils::TextMsg in more files

* fixed bug

* use Utils::TextMsg in more files

* fixed last merge conflict

* fixed bug

* fix indentation

Co-authored-by: Axel Huebl <[email protected]>

* Avoid resizing ParticleBoundaryBuffer allocation to total particle count (ECP-WarpX#3068)

* Avoid resizing ParticleBoundaryBuffer allocation to total particle count

* Switch atomic increments over to reductions

* Lassen (LLNL): ADIOS2, BLAS++ & LAPACK++ (ECP-WarpX#3071)

* Lassen (LLNL): ADIOS2, BLAS++ & LAPACK++

Document how to install ADIOS2 (for openPMD `.bp`) and
BLAS++/LAPACK++ (for PSATD in RZ) on Lassen at LLNL.

* Update: ADIOS2~SST, BLAS++/LAPACK++ w/ ESSL

* Add workaround for Libfabric bug on Crusher to job script. (ECP-WarpX#3114)

* Add workaround for Libfabric bug on Crusher to job script.

* add known issues section for Crusher

* Update docstrings

* Added test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added documentation about oracle_control

* Updated changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed TOTAL_TIME calculation

* ABLASTR: localIDtoGlobal (ECP-WarpX#3115)

* ABLASTR: localIDtoGlobal

Move the control of `localIDtoGlobal` to ABLASTR for particle IDs.

* WarpX: Use ABLASTR now

* update wheel in docker build

* build image

* change numpy to oldest-supported-numpy for docker

* build image

* Updated formatting and documentation

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Remi Lehe <[email protected]>
Co-authored-by: Roelof Groenewald <[email protected]>
Co-authored-by: Axel Huebl <[email protected]>
Co-authored-by: Luca Fedeli <[email protected]>
Co-authored-by: amadou38 <[email protected]>
Co-authored-by: Edoardo Zoni <[email protected]>
Co-authored-by: David Grote <[email protected]>
Co-authored-by: Lorenzo Giacomel <[email protected]>
Co-authored-by: lgiacome <[email protected]>
Co-authored-by: Phil Miller <[email protected]>
Co-authored-by: Andrew Myers <[email protected]>
Co-authored-by: roelof.groenewald <[email protected]>
  • Loading branch information
14 people authored May 24, 2022
1 parent 50ad568 commit e31338f
Show file tree
Hide file tree
Showing 105 changed files with 1,846 additions and 699 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
which nvcc || echo "nvcc not in PATH!"
git clone https://github.com/AMReX-Codes/amrex.git ../amrex
cd amrex && git checkout --detach 22.05 && cd -
cd amrex && git checkout --detach 843a7dff266273a0f5b7b9f6cc9233a278f41fe1 && cd -
make COMP=gcc QED=FALSE USE_MPI=TRUE USE_GPU=TRUE USE_OMP=FALSE USE_PSATD=TRUE USE_CCACHE=TRUE -j 2
build_nvhpc21-11-nvcc:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/dependencies/hip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
set -eu -o pipefail

# Ref.: https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu
wget -q -O - http://repo.radeon.com/rocm/rocm.gpg.key \
wget -q -O - https://repo.radeon.com/rocm/rocm.gpg.key \
| sudo apt-key add -
echo 'deb [arch=amd64] http://repo.radeon.com/rocm/apt/debian/ ubuntu main' \
echo 'deb [arch=amd64] https://repo.radeon.com/rocm/apt/debian/ ubuntu main' \
| sudo tee /etc/apt/sources.list.d/rocm.list

echo 'export PATH=/opt/rocm/llvm/bin:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin:$PATH' \
| sudo tee -a /etc/profile.d/rocm.sh

# we should not need to export HIP_PATH=/opt/rocm/hip with those installs

sudo apt-get update
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
cmake --build build --config Debug --parallel 2
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install --upgrade cmake
$env:PYWARPX_LIB_DIR="$(Get-Location | Foreach-Object { $_.Path })\build\lib\Debug\"
python3 -m pip install . -vv --no-build-isolation
Expand Down Expand Up @@ -81,6 +82,7 @@ jobs:
cmake --build build --config Release --parallel 2
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install --upgrade cmake
set "PYWARPX_LIB_DIR=%cd%\build\lib\"
python3 -m pip install . -vv --no-build-isolation
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pywarpx.egg-info/
##########
Docs/amrex-doxygen-web.tag.xml
Docs/warpx-doxygen-web.tag.xml
Docs/openpmd-api-doxygen-web.tag.xml
Docs/doxyhtml/
Docs/doxyxml/
Docs/source/_static/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repos:

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.13
rev: v1.1.14
hooks:
- id: remove-tabs
exclude: 'Make.WarpX|Make.package|Makefile|GNUmake'
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ if(WarpX_LIB)
${CMAKE_COMMAND} -E rm -f ${WarpX_BINARY_DIR}/pywarpx*whl
COMMAND
${CMAKE_COMMAND} -E env PYWARPX_LIB_DIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
python3 -m pip wheel -v --no-build-isolation --use-feature=in-tree-build ${WarpX_SOURCE_DIR}
python3 -m pip wheel -v --no-build-isolation ${WarpX_SOURCE_DIR}
WORKING_DIRECTORY
${WarpX_BINARY_DIR}
DEPENDS
Expand Down
3 changes: 2 additions & 1 deletion Docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,8 @@ SKIP_FUNCTION_MACROS = YES
# the path). If a tag file is not located in the directory in which doxygen is
# run, you must also specify the path to the tagfile here.

TAGFILES = amrex-doxygen-web.tag.xml=https://amrex-codes.github.io/amrex/doxygen/
TAGFILES = amrex-doxygen-web.tag.xml=https://amrex-codes.github.io/amrex/doxygen/ \
openpmd-api-doxygen-web.tag.xml=https://openpmd-api.readthedocs.io/en/latest/_static/doxyhtml/

# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
# tag file that is based on the input files it reads. See section "Linking to
Expand Down
4 changes: 3 additions & 1 deletion Docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@
# Tell sphinx what the pygments highlight language should be.
highlight_language = 'cpp'

# Download AMReX Doxygen Tagfile to interlink Doxygen docs
# Download AMReX & openPMD-api Doxygen Tagfile to interlink Doxygen docs
url = 'https://amrex-codes.github.io/amrex/docs_xml/doxygen/amrex-doxygen-web.tag.xml'
urllib.request.urlretrieve(url, '../amrex-doxygen-web.tag.xml')

url = 'https://openpmd-api.readthedocs.io/en/latest/_static/doxyhtml/openpmd-api-doxygen-web.tag.xml'
urllib.request.urlretrieve(url, '../openpmd-api-doxygen-web.tag.xml')

# Build Doxygen
subprocess.call('cd ../; doxygen;'
Expand Down
8 changes: 7 additions & 1 deletion Docs/source/developers/doxygen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ C++ Objects & Functions

We generate the documentation of C++ objects and functions *from our C++ source code* by adding :ref:`Doxygen strings <developers-docs>`.

Our Doxygen C++ API documentation in classic formatting `is located here <../_static/doxyhtml/index.html>`_.
* **WarpX and ABLASTR**: `C++ Doxygen <../_static/doxyhtml/index.html>`__

This documentation dynamically links to objects described in dependencies:

* **AMReX**: `C++ Doxygen <https://amrex-codes.github.io/amrex/doxygen>`__ and `Manual <https://amrex-codes.github.io/amrex/docs_html/>`__
* **openPMD-api**: `C++ Doxygen <https://openpmd-api.readthedocs.io/en/latest/_static/doxyhtml/index.html>`__ and `Manual <https://openpmd-api.readthedocs.io>`__
* **PICSAR-QED**: C++ Doxygen is *TODO*
1 change: 1 addition & 0 deletions Docs/source/install/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ PICMI Python Bindings
.. code-block:: bash
python3 -m pip install -U pip setuptools wheel
python3 -m pip install -U cmake
For PICMI Python bindings, configure WarpX to produce a library and call our ``pip_install`` *CMake target*:

Expand Down
16 changes: 16 additions & 0 deletions Docs/source/install/hpc/crusher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,19 @@ Post-Processing
For post-processing, most users use Python via OLCFs's `Jupyter service <https://jupyter.olcf.ornl.gov>`__ (`Docs <https://docs.olcf.ornl.gov/services_and_applications/jupyter/index.html>`__).

Please follow the same guidance as for :ref:`OLCF Summit post-processing <post-processing-summit>`.

.. _known-crusher-issues:

Known System Issues
-------------------

.. warning::

May 16th, 2022 (OLCFHELP-6888):
There is a caching bug in Libfrabric that causes WarpX simulations to occasionally hang on Crusher on more than 1 node.

As a work-around, please export the following environment variable in your job scripts unti the issue is fixed:

.. code-block:: bash
export FI_MR_CACHE_MAX_COUNT=0 # libfabric disable caching
28 changes: 28 additions & 0 deletions Docs/source/install/hpc/lassen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ We recommend to store the above lines in a file, such as ``$HOME/lassen_warpx.pr
source $HOME/lassen_warpx.profile
And since Lassen does not yet provide a module for them, install ADIOS2, BLAS++ and LAPACK++:

.. code-block:: bash
# c-blosc (I/O compression)
git clone -b v1.21.1 https://github.com/Blosc/c-blosc.git src/c-blosc
rm -rf src/c-blosc-lassen-build
cmake -S src/c-blosc -B src/c-blosc-lassen-build -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF -DDEACTIVATE_AVX2=OFF -DCMAKE_INSTALL_PREFIX=$HOME/sw/lassen/c-blosc-1.21.1
cmake --build src/c-blosc-lassen-build --target install --parallel 16
# ADIOS2
git clone -b v2.7.1 https://github.com/ornladios/ADIOS2.git src/adios2
rm -rf src/adios2-lassen-build
cmake -S src/adios2 -B src/adios2-lassen-build -DADIOS2_USE_Blosc=ON -DADIOS2_USE_Fortran=OFF -DADIOS2_USE_Python=OFF -DADIOS2_USE_SST=OFF -DADIOS2_USE_ZeroMQ=OFF -DCMAKE_INSTALL_PREFIX=$HOME/sw/lassen/adios2-2.7.1
cmake --build src/adios2-lassen-build --target install -j 16
# BLAS++ (for PSATD+RZ)
git clone https://bitbucket.org/icl/blaspp.git src/blaspp
rm -rf src/blaspp-lassen-build
cmake -S src/blaspp -B src/blaspp-lassen-build -Duse_openmp=ON -Dgpu_backend=CUDA -Duse_cmake_find_blas=ON -DBLA_VENDOR=IBMESSL -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=$HOME/sw/lassen/blaspp-master
cmake --build src/blaspp-lassen-build --target install --parallel 16
# LAPACK++ (for PSATD+RZ)
git clone https://bitbucket.org/icl/lapackpp.git src/lapackpp
rm -rf src/lapackpp-lassen-build
CXXFLAGS="-DLAPACK_FORTRAN_ADD_" cmake -S src/lapackpp -B src/lapackpp-lassen-build -Duse_cmake_find_lapack=ON -DBLA_VENDOR=IBMESSL -DCMAKE_CXX_STANDARD=17 -Dbuild_tests=OFF -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON -DCMAKE_INSTALL_PREFIX=$HOME/sw/lassen/lapackpp-master -DLAPACK_LIBRARIES=/usr/lib64/liblapack.so
cmake --build src/lapackpp-lassen-build --target install --parallel 16
Then, ``cd`` into the directory ``$HOME/src/warpx`` and use the following commands to compile:

.. code-block:: bash
Expand Down
1 change: 1 addition & 0 deletions Docs/source/install/hpc/lxplus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Now, ensure Python tooling is up-to-date:
.. code-block:: bash
python3 -m pip install -U pip setuptools wheel
python3 -m pip install -U cmake
Then we compile WarpX as in the previous section (with or without CUDA) adding ``-DWarpX_LIB=ON`` and then we install it into our Python:

Expand Down
3 changes: 3 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ Additional PML parameters
Whether to damp current in PML. Can only be used if particles are propagated in PML,
i.e. if `warpx.pml_has_particles = 1`.

* ``warpx.v_particle_pml`` (`float`; default: 1)
When ``warpx.do_pml_j_damping = 1``, the assumed velocity of the particles to be absorbed in the PML, in units of the speed of light `c`.

* ``warpx.do_pml_dive_cleaning`` (`bool`; default: 1)
Whether to use divergence cleaning for E in the PML region.
The value must match ``warpx.do_pml_divb_cleaning`` (either both false or both true).
Expand Down
1 change: 1 addition & 0 deletions Docs/source/usage/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This section collects typical user workflows and best practices for WarpX.
workflows/parallelization
workflows/debugging
workflows/libensemble
workflows/plot_timestep_duration
workflows/plot_distribution_mapping
workflows/psatd_stencil
workflows/archiving
18 changes: 18 additions & 0 deletions Docs/source/usage/workflows/plot_timestep_duration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. _plot-timestep-duration:

Plot timestep duration
======================
We provide a simple python script to generate plots of the timestep duration
from the stdandard output of WarpX (provided that ``warpx.verbose`` is set to 1):
`plot_timestep_duration.py <../../../../Tools/PostProcessing/plot_timestep_duration.py>`__ .

If the standard output of a simulation has been redirected to a file named ``log_file``,
the script can be used as follows:

::

python plot_timestep_duration.py log_file

The script generates two pictures: ``log_file_ts_duration.png``, which shows the duration
of each timestep in seconds as a function of the timestep number, and ``log_file_ts_cumulative_duration.png``,
which shows the total duration of the simulation as a function of the timestep number.
2 changes: 1 addition & 1 deletion Examples/Tests/Langmuir/analysis_langmuir_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_theoretical_field( field, t ):
fig.tight_layout()
fig.savefig('Langmuir_multi_analysis.png', dpi = 200)

tolerance_rel = 0.15
tolerance_rel = 5e-2

print("error_rel : " + str(error_rel))
print("tolerance_rel: " + str(tolerance_rel))
Expand Down
9 changes: 9 additions & 0 deletions Python/pywarpx/EB2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2022 Lorenzo Giacomel
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

from .Bucket import Bucket

eb2 = Bucket('eb2')
18 changes: 16 additions & 2 deletions Python/pywarpx/WarpX.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2016-2020 Andrew Myers, David Grote, Maxence Thevenet
# Remi Lehe
# Copyright 2016-2022 Andrew Myers, David Grote, Maxence Thevenet
# Remi Lehe, Lorenzo Giacomel
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

import re

from . import Particles
from .Algo import algo
from .Amr import amr
Expand All @@ -13,6 +15,7 @@
from .Collisions import collisions, collisions_list
from .Constants import my_constants
from .Diagnostics import diagnostics
from .EB2 import eb2
from .Geometry import geometry
from .Interpolation import interpolation
from .Langmuirwave import langmuirwave
Expand All @@ -38,6 +41,7 @@ def create_argv_list(self):
argv += langmuirwave.attrlist()
argv += interpolation.attrlist()
argv += psatd.attrlist()
argv += eb2.attrlist()

# --- Search through species_names and add any predefined particle objects in the list.
particles_list_names = [p.instancename for p in particles_list]
Expand Down Expand Up @@ -101,7 +105,17 @@ def write_inputs(self, filename='inputs', **kw):

with open(filename, 'w') as ff:

prefix_old = ''
for arg in argv:
# This prints the name of the input group (prefix) as a header
# before each group to make the input file more human readable
prefix_new = re.split(' |\.', arg)[0]
if prefix_new != prefix_old:
if prefix_old != '':
ff.write('\n')
ff.write(f'# {prefix_new}\n')
prefix_old = prefix_new

ff.write(f'{arg}\n')

warpx = WarpX('warpx')
3 changes: 2 additions & 1 deletion Python/pywarpx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Andrew Myers, David Grote
# Copyright 2016-2022 Andrew Myers, David Grote, Lorenzo Giacomel
#
# This file is part of WarpX.
#
Expand All @@ -10,6 +10,7 @@
from .Collisions import collisions
from .Constants import my_constants
from .Diagnostics import diagnostics
from .EB2 import eb2
from .Geometry import geometry
from .Interpolation import interpolation
from .Langmuirwave import langmuirwave
Expand Down
46 changes: 38 additions & 8 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2018-2020 Andrew Myers, David Grote, Ligia Diana Amorim
# Maxence Thevenet, Remi Lehe, Revathi Jambunathan
# Copyright 2018-2022 Andrew Myers, David Grote, Ligia Diana Amorim
# Maxence Thevenet, Remi Lehe, Revathi Jambunathan, Lorenzo Giacomel
#
#
# This file is part of WarpX.
Expand Down Expand Up @@ -917,21 +917,43 @@ class EmbeddedBoundary(picmistandard.base._ClassWithInit):
"""
Custom class to handle set up of embedded boundaries specific to WarpX.
If embedded boundary initialization is added to picmistandard this can be
changed to inherit that functionality.
changed to inherit that functionality. The geometry can be specified either as
an implicit function or as an STL file (ASCII or binary). In the latter case the
geometry specified in the STL file can be scaled, translated and inverted.
- implicit_function: Analytic expression describing the embedded boundary
- stl_file: STL file path (string), file contains the embedded boundary geometry
- stl_scale: factor by which the STL geometry is scaled (pure number)
- stl_center: vector by which the STL geometry is translated (in meters)
- stl_reverse_normal: if True inverts the orientation of the STL geometry
- potential: Analytic expression defining the potential. Can only be specified
when the solver is electrostatic. Optional, defaults to 0.
Parameters used in the expressions should be given as additional keyword arguments.
"""
def __init__(self, implicit_function, potential=None, **kw):
def __init__(self, implicit_function=None, stl_file=None, stl_scale=None, stl_center=None, stl_reverse_normal=False,
potential=None, **kw):

assert stl_file is None or implicit_function is None, Exception('Only one between implicit_function and '
'stl_file can be specified')

self.implicit_function = implicit_function
self.stl_file = stl_file

if stl_file is None:
assert stl_scale is None, Exception('EB can only be scaled only when using an stl file')
assert stl_center is None, Exception('EB can only be translated only when using an stl file')
assert stl_reverse_normal is False, Exception('EB can only be reversed only when using an stl file')

self.stl_scale = stl_scale
self.stl_center = stl_center
self.stl_reverse_normal = stl_reverse_normal

self.potential = potential

# Handle keyword arguments used in expressions
self.user_defined_kw = {}
for k in list(kw.keys()):
if (re.search(r'\b%s\b'%k, implicit_function) or
(potential is not None and re.search(r'\b%s\b'%k, potential))):
if (implicit_function is not None and re.search(r'\b%s\b'%k, implicit_function) or
(potential is not None and re.search(r'\b%s\b'%k, potential))):
self.user_defined_kw[k] = kw[k]
del kw[k]

Expand All @@ -944,8 +966,16 @@ def initialize_inputs(self, solver):
# defined in my_constants with the same name but different value.
self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw)

expression = pywarpx.my_constants.mangle_expression(self.implicit_function, self.mangle_dict)
pywarpx.warpx.eb_implicit_function = expression
if self.implicit_function is not None:
expression = pywarpx.my_constants.mangle_expression(self.implicit_function, self.mangle_dict)
pywarpx.warpx.eb_implicit_function = expression

if self.stl_file is not None:
pywarpx.eb2.geom_type = "stl"
pywarpx.eb2.stl_file = self.stl_file
pywarpx.eb2.stl_scale = self.stl_scale
pywarpx.eb2.stl_center = self.stl_center
pywarpx.eb2.stl_reverse_normal = self.stl_reverse_normal

if self.potential is not None:
assert isinstance(solver, ElectrostaticSolver), Exception('The potential is only supported with the ElectrostaticSolver')
Expand Down
2 changes: 1 addition & 1 deletion Regression/WarpX-GPU-tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ emailBody = Check https://ccse.lbl.gov/pub/GpuRegressionTesting/WarpX/ for more

[AMReX]
dir = /home/regtester/git/amrex/
branch = 22.05
branch = 843a7dff266273a0f5b7b9f6cc9233a278f41fe1

[source]
dir = /home/regtester/git/WarpX
Expand Down
2 changes: 1 addition & 1 deletion Regression/WarpX-tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ emailBody = Check https://ccse.lbl.gov/pub/RegressionTesting/WarpX/ for more det

[AMReX]
dir = /home/regtester/AMReX_RegTesting/amrex/
branch = 22.05
branch = 843a7dff266273a0f5b7b9f6cc9233a278f41fe1

[source]
dir = /home/regtester/AMReX_RegTesting/warpx
Expand Down
Loading

0 comments on commit e31338f

Please sign in to comment.