Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 443f00a
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Tue Mar 29 13:34:30 2022 +0700

    Minor changes in figure spacing

commit 581bec6
Author: stefaniagl <stefgluhova@gmail.com>
Date:   Tue Mar 29 00:03:24 2022 +0700

    Bessel 0 (adda-team#315)

    Tests and examples for Bessel beams:
    - test using equivalent command line strings `tests/equiv/bb_equiv.py`
    - simple examples `examples/bessel`
    - scripts to reproduce 4 figures in a recent paper (submitted)

    Fixes a bug in TML type of Bessel beams.

commit d7e6169
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Mon Feb 21 23:35:49 2022 +0700

    Makes the test for inconsistencies in the input shape format more sensitive. Detects extra number present in a line for ADDA formats (both single- and multi-domain). The formats themselves are now defines instead of static strings.

commit 887a63c
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Mon Feb 21 14:48:46 2022 +0700

    - All math constants are now given to 35 significant digits (was 32 in most places)
    - This includes the LDR constants (for which a separate calculation procedure was performed)
    - Improves a few related comments

commit a993a91
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Tue Feb 15 10:21:53 2022 +0700

    - renames find_adda.sh into find_adda (and sets executable flag)
    - this script now returns ADDA path to stdout, hence does not need to be sourced (was a bad idea due to potential variables collision)
    - updates all calling scripts

commit c8ea4ed
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Mon Jan 31 14:52:02 2022 +0700

    minor formatting changes

commit a6be5f4
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Mon Jan 31 14:31:10 2022 +0700

    - adds a special script to locate ADDA binaries (to be used by various examples).
    - updates existing examples in `examples/papers/2021_WKBr/` and `misc/near_field/` accordingly
    - other minor changes to `examples/papers/2021_WKBr/calc.sh`

commit 2896575
Author: inzhevatkin <51568160+inzhevatkin@users.noreply.github.com>
Date:   Sun Jan 30 11:40:56 2022 +0700

    WKBr scripts (adda-team#311)

    * Adds scripts to reproduce Figs.15 and 16 from paper (Inzhevatkin & Yurkin, 2022)
    * Includes general-purpose scripts to generate internal field in a sphere in the framework of the WKBr approximation (two modifications).
    * Also includes interface with Mie-theory calculations.

    Co-authored-by: Maxim Yurkin <yurkin@gmail.com>

commit 6c0b401
Merge: 49e6c23 deebdbf
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Tue Jan 11 19:11:38 2022 +0700

    Merge branch 'master' of github.com:adda-team/adda

commit 49e6c23
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Tue Jan 11 19:09:51 2022 +0700

    Updates extracting of gcc version in Makefile to be compatible with all possible configurations of gcc.

commit deebdbf
Author: stefaniagl <stefgluhova@gmail.com>
Date:   Fri Jan 7 17:44:39 2022 +0700

    Changes in tests (adda-team#310)

    - updates ignores in `comp2exec` so that all tests pass (after recent adda-team#304)
    - adds -beam_center to various lines in test suites

    * Corrections in `GenerateB.c`:
    - removes redundant EOL in multi-line beam descriptions
    - fixes incorrect calculation of incident plane wave for grazing incidence in surface mode (when prop_z is on the order of 1e-16). For that the code was completely rewritten to specifically calculate potentially small quantities (e.g., expm1 instead of exp and rcp1=rc+1 instead of rc).
    - removes duplicate initialization of `prIncRefl`
    - mentions `vorticity` in instructions for adding new beam
    - in several places (when accounting for `beam_center`) `LinComb()` was replaced by `vSubtr()`.

    * Other changes:
    - adds functions `imExpM1()` and `cExpM1()` to `cmplx.h`
    - definitions of `prIncRelf` and `prIncTran` are now semi-global (only in `GenerateB.c` and `param.c`)
    - updates copyright year in `param.c`

    Co-authored-by: Maxim Yurkin <yurkin@gmail.com>

commit 6a9ec2e
Author: Maxim Yurkin <yurkin@gmail.com>
Date:   Mon Jan 3 00:02:33 2022 +0700

    adds ignoring of errors when getting commit hash (i.e. when compiling from downloaded source code, not from git repository)
  • Loading branch information
stefaniagl committed Mar 29, 2022
1 parent 62be280 commit 753f790
Show file tree
Hide file tree
Showing 58 changed files with 2,851 additions and 105 deletions.
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Various examples of using ADDA. Mostly these are tutorial examples, which illustrate certain features of ADDA and should not consume too much computational time. The only exception is subfolder `papers/`, which additionally aims to reproduce specific published simulations (thus, may require a large cluster). All examples are designed to be run out of the box assuming that compiled binaries are available (either by default compilation or pre-compiled for Windows). Some only run ADDA with proper command lines, others - also plot or post-process the obtained results. See further details inside corresponding folders:
* `bessel/` – examples involving excitation by Bessel beams (will be added after #209)
* `bessel/` – examples involving excitation by Bessel beams
* `eels/` – examples involving excitation by a fast electron (will be added after #155)
* `papers/` – examples reproducing published results
* `find_adda.sh` - common script to locate ADDA binaries and set corresponding environmenal variables
2 changes: 2 additions & 0 deletions examples/bessel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/option*/
/saved/
8 changes: 6 additions & 2 deletions examples/bessel/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
This python code "bb_examples" represents the comparison of scattering intensities calculated with DDA (ADDA code)
for the scattering of Bessel beam of 2 options by choice (option_1 and option_2).
The python code `bb_examples.py` performs the comparison of scattering intensities calculated with ADDA for two different Bessel beams. By default, they are LE and LM beams of order 2 scattered by a wavelength-sized sphere, but it can be easily modified inside the script.

Other folders (produced by the script):
* `option_1/` - contains raw ADDA results (log file, mueller matrix, incident field, and cross sections by default) for the 1st command line option
* `option_2/` - the same for the 2nd option
* `saved/` - final figures in PDF format
63 changes: 40 additions & 23 deletions examples/bessel/bb_examples.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'''
# This code represents the comparison of scattering intensities calculated with DDA (ADDA code)
# for the scattering of Bessel beam of 2 options by choice (option_1 and option_2).
# This code compares the scattering intensities calculated with the DDA (ADDA code)
# for the scattering of two different Bessel beams (option_1 and option_2) by a sphere.
'''

import os, re, math
import matplotlib.pyplot as plt
from matplotlib import rc
from PIL import Image


# path to adda executable
Expand All @@ -17,15 +16,39 @@
# define here different parameters for 2 options (see ADDA manual)
run_options = [' -beam besselLE 2 15', # option 1
' -beam besselLM 2 15'] # option 2


# =============================================================================
# Bessel beams in ADDA:
#
# besselCS <order> <angle>
# -Bessel beam with circularly symmetric energy density.
# besselCSp <order> <angle>
# -Alternative Bessel beam with circularly symmetric energy density.
# besselM <order> <angle> <ReMex> <ReMey> <ReMmx> <ReMmy> [<ImMex> <ImMey> <ImMmx> <ImMmy>]
# -Generalized Bessel beam. The beam is defined by 2x2 matrix M:
# (Mex, Mey, Mmx, Mmy). Real parts of these four elements are obligatory,
# while imaginary parts are optional (zero, by default).
# besselLE <order> <angle>
# -Bessel beam with linearly polarized electric field.
# besselLM <order> <angle>
# -Bessel beam with linearly polarized magnetic field.
# besselTEL <order> <angle>
# -Linear component of the TE Bessel beam.
# besselTML <order> <angle>
# -Linear component of the TM Bessel beam.
#
# Order is integer (of any sign) and the half-cone angle (in degrees)
# is measured from the z-axis.
# =============================================================================


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# data generation (run of ADDA code)
def adda_run(mode): # option 1 or 2
def adda_run(mode): # option 1 or 2

# cmd line generation (see ADDA manual)

# common parameters for 2 options
cmdline = adda_exec
cmdline += ' -grid 16' # particle discretization
Expand All @@ -35,10 +58,8 @@ def adda_run(mode): # option 1 or 2
cmdline += ' -dir option_' + str(mode) # save path
cmdline += run_options[mode-1]
print(cmdline)

os.system(cmdline)

return 0

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -53,7 +74,7 @@ def extractData(mode):
theta = dat[17:-1:17]
s11 = dat[18:-1:17]
s12 = dat[19:-1:17]

with open(path + '/' + str(files[files.index('IncBeam-Y')])) as f:
fileF = f.read()
f.close()
Expand All @@ -62,7 +83,7 @@ def extractData(mode):
yd = dat[11:-1:10]
zd = dat[12:-1:10]
ed = dat[13:-1:10]

theta = [float(th) for th in theta]
s11 = [float(s) for s in s11]
s12 = [float(s) for s in s12]
Expand All @@ -77,7 +98,7 @@ def extractData(mode):
xd = [xd[i] for i in zslice]
yd = [yd[i] for i in zslice]
ed = [ed[i] for i in zslice]

return theta,i_per,i_par,xd,yd,ed,minz

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -112,28 +133,24 @@ def plotData(xv1,yv1,xv2,yv2,flag):
print(sum(dev)/len(dev))
print('RMS, %:')
print(math.sqrt(sum(dev2)/len(xv2)*100))

return 0


# Visualisation of the amplitude of the incident electric field almost in the middle
# of the particle (z = distance to the closest dipole along z axis)
# of the particle (the nearest to the center xy-plane of dipoles is used, its z-coordinate is shown on the plot)
def plotField(xd,yd,ed,z0,mode):
ax.set_title('OPTION '+str(mode)+'\nAmplitude of the incident field \n(z = '+str(round(z0,2))+')');
ax.set_title(r'OPTION '+str(mode)+':\n '+run_options[mode-1]+'\nIntensity profile of $|E_{inc}|^2$\n(z = '+str(round(z0,2))+')');
ax.scatter(xd, yd, ed, c=ed, cmap='viridis', linewidth=0.5);
#ax.plot_trisurf(xd, yd, ed,cmap='viridis', edgecolor='none');
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))

return 0

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

adda_run(1)
adda_run(2)

theta_1,iper_1,ipar_1,xd_1,yd_1,ed_1,z0_1 = extractData(1) # extraction of ADDA results for option 1
theta_2,iper_2,ipar_2,xd_2,yd_2,ed_2,z0_2 = extractData(2) # extraction of ADDA results for option 2

Expand Down Expand Up @@ -161,5 +178,5 @@ def plotField(xd,yd,ed,z0,mode):
os.makedirs('saved', exist_ok=True)

plt.savefig('saved/results.pdf', bbox_inches='tight')

plt.show()
56 changes: 56 additions & 0 deletions examples/find_adda
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# Copyright (C) ADDA contributors
# GNU General Public License version 3

# Finds adda binary and returns its path to stdout. If the variable ADDA_SEQ, ADDA_MPI, or ADDA_OCL is already defined,
# returns its value, but first tests that the file exist. Otherwise, first checks if the binary is directly available
# (on the PATH), then looks at the corresponding compilation folder, and finally (on Windows only) looks for precompiled
# binary in win64/

# A single optional argument is the mode (seq, mpi, or ocl), which binary to search. 'seq' is the default one.
# The script must not be moved from this folder (searches for a few places relative to its position),
# but can be executed from anywhere.

# The minimal test example is the following (note the test for exit value)
#ADDA_SEQ=$(./find_adda)
#if [ $? -ne 0 ]; then
# exit 1
#fi

mode=${1:-seq}

# We do not add .exe for Windows, since all Bash interpreters for Windows seem to work fine without it
if [ $mode == "seq" ]; then
var=ADDA_SEQ
bin=adda
elif [ $mode == "mpi" ]; then
var=ADDA_MPI
bin=adda_mpi
elif [ $mode == "ocl" ]; then
var=ADDA_OCL
bin=adda_ocl
else
echo "ERROR: unkwnown mode '$mode'" >&2
exit 1
fi

if [ -z "${!var}" ]; then
# Locates root path for ADDA (relative to script's location), https://stackoverflow.com/a/246128/2633728
top=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../" &> /dev/null && pwd)
if command -v $bin &> /dev/null; then
path="$bin"
elif [ -f "$top/src/$mode/$bin" ]; then
path="$top/src/$mode/$bin"
elif [[ ("$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" || "$OSTYPE" == "win64" ) && -f "$top/win64/$bin" ]]; then
path="$top/win64/$bin"
else
echo "ERROR: No $bin binary found (and variable $var is not defined)" >&2
exit 1
fi
elif [ ! -f "${!var}" ]; then
echo "ERROR: No $bin binary found (path given by $var='${!var}' does not exist)" >&2
exit 1
else
path="${!var}"
fi
echo "$path"
5 changes: 5 additions & 0 deletions examples/papers/2021_WKBr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*/__pycache__
/*/*.dat
/Mie_solution/work/*
/run*
/ExpCount
8 changes: 8 additions & 0 deletions examples/papers/2021_WKBr/Mie_solution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The script `exact-script.sh` calculates the exact internal electric field using either [`Bhfield`](https://scattport.org/index.php/light-scattering-software/mie-type-codes/list/521-bhfield) or [`Scattnlay`](https://github.com/ovidiopr/scattnlay) (to be obtained separately). The `toADDA.py` script changes Bhfield / Scattnlay grid so that it matches the ADDA one.

After setting the required parameters and paths to scripts, execute:
```
sh exact-script.sh
python toADDA.py
```
The scripts can also accept parameters through the command line - see the comments inside.
34 changes: 34 additions & 0 deletions examples/papers/2021_WKBr/Mie_solution/exact-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# The script calculates the exact internal electric field using either Bhfield or Scattnlay.
# You need to obtain the required executables (Bhfield or Scattnlay) separately and specify the path to the corresponding
# executables below (or copy them in work/ subfolder)

# SET YOUR PARAMETERS (either here or in command line):
size=${1:-10}
m=${2:-1.1}
grid=${3:-16}
type=${4:-scattnlay} # program type: [bhfield, scattnlay]

# SET YOUR PATHS:
# Path to the working folder (for temporary files, only for bhfield) and for placing output (both must exist)
workpath="$(pwd)/work"
outpath="$(pwd)"
# Executables (with full path) to be used for actual computation
BHFIELD="$workpath/bhfield-std"
# The name of the executable can also be fieldnlay or fieldnlay-mp, depending on installation.
# We tested on the Scattnlay version dated June 7, 2021.
FIELDNLAY="$workpath/fieldnlay-dp"

# Calculating the required variables:
# simple workaround for float computations using awk
calc() { awk "BEGIN{print $*}"; }
radius=$(calc $size/2)
rb=$(calc $radius - $radius/$grid)
lb=-$rb;
if [ "$type" == "bhfield" ]; then
cd $workpath
"$BHFIELD" 6.28318530718 $radius $radius $grid $lb $rb $grid $lb $rb $grid $lb $rb other 0 1 $m 0 $m 0
cp V_0Ereim.dat "$outpath/bhfield-$size-$m-$grid.dat"
elif [ "$type" == "scattnlay" ]; then
"$FIELDNLAY" -l 1 $radius $m 0 -p $lb $rb $grid $lb $rb $grid $lb $rb $grid > "$outpath/scattnlay-$size-$m-$grid.dat"
fi
Loading

0 comments on commit 753f790

Please sign in to comment.