Skip to content

Commit

Permalink
2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
haykh committed Jun 16, 2024
1 parent e999640 commit 1e50f43
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
!CITATION
!LICENSE
.vscode/*.log
CMakeLists.txt
__pycache__

*.pyc
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, Anatoly Spitkovsky & Hayk Hakobyan
Copyright (c) 2024, Tristan v2 Dev. Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tristan v2.7
# Tristan v2.8

[![DOI](https://zenodo.org/badge/234551890.svg)](https://zenodo.org/badge/latestdoi/234551890)

Expand Down Expand Up @@ -27,6 +27,8 @@ sudo apt libhdf5-openmpi-dev hdf5-tools
### Usage

#### `configure.py` + GNU Make

```shell
# to view all configuration options
python3 configure.py --help
Expand All @@ -38,6 +40,15 @@ make all -j
mpirun -np <NCORES> ./bin/tristan-mp2d -input ../inputs/input.2d_rec
```

#### `CMake` (experimental support)

```shell
# preconfigure the code using
cmake -B build -D user=<USERFILE> -D dim=3 ...
# compile
cmake --build build -j $(nproc)
```

### Docker

Another way to avoid the tedium of installing libraries (especially for local development) is to use [Docker containers](https://docs.docker.com/get-started/). This approach allows to quickly create an isolated linux environment with all the necessary packages already preinstalled (similar to a VM, but much lighter). The best thing is that VSCode can natively attach to a running container, and all the development can be done there (make sure to install the [appropriate extension](https://code.visualstudio.com/docs/remote/containers)).
Expand Down Expand Up @@ -103,23 +114,25 @@ or in the VSCode environment (see the extension list in the `.vscode/settings.js

## Contributors (alphabetical order)

* Fabio Bacchini (University of Colorado Boulder)
* Alexander Chernoglazov (University of Maryland)
* Daniel Groselj (Columbia)
* Hayk Hakobyan (PPPL/Columbia)
* Jens Mahlmann (Princeton)
* Arno Vanthieghem (Princeton)
* Fabio Bacchini (KU Leuven)
* Alexander Chernoglazov (Univ. of Maryland)
* Daniel Groselj (KU Leuven)
* Hayk Hakobyan (Columbia/PPPL)
* Jens Mahlmann (Columbia)
* Arno Vanthieghem (Univ. of Paris)

## Board of trustees

* Prof. Anatoly Spitkovsky (Princeton)
* Prof. Sasha Philippov (University of Maryland)
* Prof. Sasha Philippov (Univ. of Maryland)

## Publications

__@TODO__

## Latest Releases
* `v2.8` __Jun 2024__
* `CMake` support (experimental)
* `v2.6.1` __Aug 2023__
* Fixed a buggy ordering of synchrotron cooling term and particle coordinate update (very minor correction)
* `v2.6` __Jan 2023__
Expand Down
120 changes: 64 additions & 56 deletions src/tools/auxiliary.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module m_aux
#ifdef MPI08
use mpi_f08
#else
include "mpif.h"
#endif
#ifdef HDF5
use hdf5
#endif
use m_globalnamespace
implicit none
real(dprec) :: dseed
Expand All @@ -11,7 +19,7 @@ function spatialDistribution(x_glob, y_glob, z_glob, &
real, intent(in), optional :: dummy1, dummy2, dummy3
end function spatialDistribution
function spatialCloudDistribution(x_glob, y_glob, z_glob, &
dummy1, dummy2, dummy3)
dummy1, dummy2, dummy3)
real :: spatialCloudDistribution
real, intent(in), optional :: x_glob, y_glob, z_glob
real, intent(in), optional :: dummy1, dummy2, dummy3
Expand Down Expand Up @@ -44,24 +52,24 @@ end function spatialCloudDistribution
end type simulation_params

abstract interface
function getFMT(value, w) result(FMT)
implicit none
real, intent(in) :: value
character(len=STR_MAX) :: FMT
integer, intent(in), optional :: w
end function getFMT
end interface
function getFMT(value, w) result(FMT)
implicit none
real, intent(in) :: value
character(len=STR_MAX) :: FMT
integer, intent(in), optional :: w
end function getFMT
end interface

type :: warning
character(len=STR_MAX) :: description
integer :: counter = 0
end type warning
type :: warning
character(len=STR_MAX) :: description
integer :: counter = 0
end type warning

type(warning) :: warnings(100)
type(simulation_params) :: sim_params
type(warning) :: warnings(100)
type(simulation_params) :: sim_params

!--- PRIVATE functions -----------------------------------------!
private :: intToStr, realToStr, int8ToStr, real8ToStr
private :: intToStr, realToStr, int8ToStr, real8ToStr
!...............................................................!
contains
subroutine initializeSimulationParameters()
Expand Down Expand Up @@ -93,7 +101,7 @@ subroutine printDiag(msg, level)
if (present(level)) then
sz = sz + level * 3
do i = 1, level * 3
dummy(i:i) = '.'
dummy(i:i) = '.'
end do
end if
dummy = trim(dummy)//trim(msg)
Expand All @@ -115,8 +123,8 @@ subroutine printWarnings(timestep)
integer :: warnings_global(100)

do w = 1, 100
call MPI_REDUCE(warnings(w) % counter, warnings_global(w), 1, MPI_INTEGER, &
MPI_SUM, root_rnk, MPI_COMM_WORLD, ierr)
call MPI_REDUCE(warnings(w) % counter, warnings_global(w), 1, MPI_INTEGER, &
MPI_SUM, root_rnk, MPI_COMM_WORLD, ierr)
end do

if (mpi_rank .eq. root_rnk) then
Expand All @@ -133,7 +141,7 @@ subroutine printWarnings(timestep)
end if

do w = 1, 100
warnings(w) % counter = 0
warnings(w) % counter = 0
end do
end subroutine printWarnings

Expand Down Expand Up @@ -162,18 +170,18 @@ end function getFMTForReal

function getFMTForRealScientific(value, w) result(FMT)
implicit none
real, intent(in) :: value
character(len=STR_MAX) :: FMT
real, intent(in) :: value
character(len=STR_MAX) :: FMT
integer, intent(in), optional :: w
integer :: w_
character(len=10) :: dummy
integer :: w_
character(len=10) :: dummy
if (.not. present(w)) then
w_ = 10
else
w_ = w
end if
write(dummy, '(I10)') w_
FMT = 'ES' // trim(dummy) // '.3'
write (dummy, '(I10)') w_
FMT = 'ES'//trim(dummy)//'.3'
end function getFMTForRealScientific

subroutine printTimeHeader(tstep)
Expand All @@ -193,7 +201,7 @@ subroutine printTimeHeader(tstep)

write (*, "(1X,A10,I9)", advance='no') "Timestep: ", tstep
do i = 1, 48
write (*, "(A)", advance='no') '.'
write (*, "(A)", advance='no') '.'
end do
print "(A4)", "[OK]"
print "(1X,A71)", "[ROUTINE] [TIME, ms] [MIN / MAX, ms] [FRACTION, %]"
Expand Down Expand Up @@ -332,8 +340,8 @@ logical function arraysAreEqual(array1, array2)
arraysAreEqual = (size(array1) .eq. size(array2))
if (arraysAreEqual) then
do i = 1, size(array1)
arraysAreEqual = (array1(i) .eq. array2(i))
if (.not. arraysAreEqual) exit
arraysAreEqual = (array1(i) .eq. array2(i))
if (.not. arraysAreEqual) exit
end do
end if
end function arraysAreEqual
Expand All @@ -356,7 +364,7 @@ real function random(DSEED)
real :: rnd
rnd = 1.0
do while (rnd .ge. 1.0)
rnd = REAL(randomNum(DSEED))
rnd = REAL(randomNum(DSEED))
end do
random = rnd
return
Expand All @@ -379,9 +387,9 @@ real function poisson(num)
kps = 0
pps = 1
do while (pps .ge. Lps)
kps = kps + 1
ups = random(dseed)
pps = pps * ups
kps = kps + 1
ups = random(dseed)
pps = pps * ups
end do
poisson = kps - 1
return
Expand All @@ -405,19 +413,19 @@ subroutine log_normal(n_bins, lognorm)
allocate (lognorm(n_bins))
sum = 0.0
do i = 1, n_bins
x = random(dseed)
y = random(dseed)
z = sqrt(-2.0 * log(x)) * cos(2.0 * M_PI * y) ! now z has standard normal distribution
z = exp(0.0 + 1.0 * z) ! now z has lognormal distribution with certain sigma=1 and mu=0
lognorm(i) = z
sum = sum + z
x = random(dseed)
y = random(dseed)
z = sqrt(-2.0 * log(x)) * cos(2.0 * M_PI * y) ! now z has standard normal distribution
z = exp(0.0 + 1.0 * z) ! now z has lognormal distribution with certain sigma=1 and mu=0
lognorm(i) = z
sum = sum + z
end do

! this allows having lognorm(max) != 1/
! in this case bins are not fixed in upper limit
lognorm(1) = lognorm(1) / (n_bins + 1.)
do i = 2, n_bins
lognorm(i) = lognorm(i) / (n_bins + 1.) + lognorm(i - 1)
lognorm(i) = lognorm(i) / (n_bins + 1.) + lognorm(i - 1)
end do
! /this allows having lognorm(max) != 1
end subroutine log_normal
Expand All @@ -431,20 +439,20 @@ subroutine lin_normal(n_bins, linnorm)
allocate (linnorm(n_bins))
sum = 0.0
do i = 1, n_bins
x = random(dseed)
linnorm(i) = x
sum = sum + x
x = random(dseed)
linnorm(i) = x
sum = sum + x
end do

! this allows having linnorm(max) != 1/
! in this case bins are not fixed in upper limit
linnorm(1) = linnorm(1) / (n_bins + 1.0)
do i = 2, n_bins
linnorm(i) = linnorm(i) / (n_bins + 1.0) + linnorm(i - 1)
linnorm(i) = linnorm(i) / (n_bins + 1.0) + linnorm(i - 1)
end do

do i = 1, n_bins
linnorm(i) = 2.0 * linnorm(i)
linnorm(i) = 2.0 * linnorm(i)
end do
! /this allows having linnorm(max) != 1
end subroutine lin_normal
Expand Down Expand Up @@ -499,16 +507,16 @@ subroutine rotateRandomlyIn3D(rx, ry, rz, rnd1, rnd2, rnd3)
one_m_cos_phi = (1.0 - cos_phi)

rx = (one_m_cos_phi * ux**2 + cos_phi) * rx_ + &
(one_m_cos_phi * ux * uy - sin_phi * uz) * ry_ + &
(one_m_cos_phi * ux * uz + sin_phi * uy) * rz_
(one_m_cos_phi * ux * uy - sin_phi * uz) * ry_ + &
(one_m_cos_phi * ux * uz + sin_phi * uy) * rz_

ry = (one_m_cos_phi * ux * uy + sin_phi * uz) * rx_ + &
(one_m_cos_phi * uy**2 + cos_phi) * ry_ + &
(one_m_cos_phi * uy * uz - sin_phi * ux) * rz_
(one_m_cos_phi * uy**2 + cos_phi) * ry_ + &
(one_m_cos_phi * uy * uz - sin_phi * ux) * rz_

rz = (one_m_cos_phi * ux * uz - sin_phi * uy) * rx_ + &
(one_m_cos_phi * uy * uz + sin_phi * ux) * ry_ + &
(one_m_cos_phi * uz**2 + cos_phi) * rz_
(one_m_cos_phi * uy * uz + sin_phi * ux) * ry_ + &
(one_m_cos_phi * uz**2 + cos_phi) * rz_
end subroutine rotateRandomlyIn3D

subroutine rotateIn3D(rx, ry, rz, ax, ay, az, ang)
Expand All @@ -530,16 +538,16 @@ subroutine rotateIn3D(rx, ry, rz, ax, ay, az, ang)
one_m_cos_phi = (1.0 - cos_phi)

rx = (one_m_cos_phi * ux**2 + cos_phi) * rx_ + &
(one_m_cos_phi * ux * uy - sin_phi * uz) * ry_ + &
(one_m_cos_phi * ux * uz + sin_phi * uy) * rz_
(one_m_cos_phi * ux * uy - sin_phi * uz) * ry_ + &
(one_m_cos_phi * ux * uz + sin_phi * uy) * rz_

ry = (one_m_cos_phi * ux * uy + sin_phi * uz) * rx_ + &
(one_m_cos_phi * uy**2 + cos_phi) * ry_ + &
(one_m_cos_phi * uy * uz - sin_phi * ux) * rz_
(one_m_cos_phi * uy**2 + cos_phi) * ry_ + &
(one_m_cos_phi * uy * uz - sin_phi * ux) * rz_

rz = (one_m_cos_phi * ux * uz - sin_phi * uy) * rx_ + &
(one_m_cos_phi * uy * uz + sin_phi * ux) * ry_ + &
(one_m_cos_phi * uz**2 + cos_phi) * rz_
(one_m_cos_phi * uy * uz + sin_phi * ux) * ry_ + &
(one_m_cos_phi * uz**2 + cos_phi) * rz_
end subroutine rotateIn3D

end module m_aux

0 comments on commit 1e50f43

Please sign in to comment.