% $Id: newsletter.tex,v 1.26 2024/10/07 19:08:05 brandenb Exp $
%\documentclass{article}
\documentclass[twocolumn]{article}
\setlength{\textwidth}{170mm}
\setlength{\oddsidemargin}{-7mm}
\setlength{\textheight}{220mm}
\setlength{\topmargin}{-8mm}
\newcommand{\yapjN}[4]{, ``#4,'' {\em Astrophys.\ J.\ }{\bf #2}, #3 (#1).}
\newcommand{\const}{{\rm const}  {}}
\def\half{{\textstyle{1\over2}}}

%\bibliographystyle{apalike}
\bibliographystyle{gGAF} %is checked in (say "make ln")
%\usepackage{bm,natbib,html,wrapfig,graphicx,multicol,color} %,etoollbox}  %setspace,tocloft}
\usepackage{bm,natbib,wrapfig,graphicx,multicol,color} %,etoollbox}  %setspace,tocloft}
\usepackage{hyperref}
\usepackage[anythingbreaks]{breakurl} %AB: is needed
\usepackage{xcolor, soul}
\usepackage{listings}
\usepackage{amssymb}
\usepackage{amsmath}

\graphicspath{{./fig/}{./png/}}
\thispagestyle{empty}
\input ../../jour_def
\newcommand{\Fig}[1]{Figure~\ref{#1}}
\newcommand{\Figs}[2]{Figures~\ref{#1} and \ref{#2}}
\def\red{\textcolor{red}}
\def\blue{\textcolor{blue}}
\newcommand{\yjourN}[5]{:~#1, ``#5,'' {\em #2} {\bf #3}, #4}
\newcommand{\bra}[1]{\langle #1\rangle}
\newcommand{\Eq}[1]{Eq.~(\ref{#1})}
\newcommand{\AAA}{\bm{A}}
\newcommand{\BB}{\bm{B}}
\newcommand{\kk}{\bm{k}}
\newcommand{\xx}{\bm{x}}
\newcommand{\ii}{{\rm i}}
\newcommand{\dd}{{\rm d} {}}
\newcommand{\nab}{{\bm{\nabla}}}
\newcommand{\Cou}{{\mbox{Cou}}}
\def\HM{H_{\rm M}}
\def\EM{E_{\rm M}}
\def\EEM{{\cal E}_{\rm M}}
\def\Pm{\mbox{\rm Pr}_{\rm M}}
\def\Rm{\mbox{\rm Re}_{\rm M}}
\def\Rey{\mbox{\rm Re}}
\def\urms{u_{\rm rms}}
\def\kf{k_{\rm f}}

\title{The {\sc Pencil Code} Newsletter}
\author{Issue 2024/2}
\date{October 7, 2024,~ $ $Revision: 1.26 $ $}
\begin{document}
\maketitle

\renewcommand{\baselinestretch}{-.4}\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1}\normalsize

\section{PCUM 2024 in Barcelona}

The Pencil Code User Meeting (PCUM) of 2024 was well received by all
participants.
We had a number of newcomers who have heard about the code, but haven't
actually used it yet.
They all acknowledged the personal contacts that developed.
This provided help that could not be replaced by any zoom meeting.

An important highlight was the tutorial led by
Jenny Schober (\url{https://jennifer-schober.com/}).
She provided hands-on experience with the code and its basics; see
\url{https://jennifer-schober.com/teaching/pcum2024/} for her material.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Monday}
\end{center}\caption[]{
Monday morning: introduction.
}\label{Monday}\end{figure}

\subsection{15 on-site participants}

When people introduced themselves on Monday morning (\Fig{Monday}),
they also indicated since which year they started using the code.
Out of the 15 on-site participants, there were 5 newcomers to the code.
Most of the other 10 participants started using the code in the last
10 years, and a few others even well before then; see 
\Fig{pusers} for a histogram.
There were also some who have been exposed to the code since earlier
years, but didn't really work with it until opportunities arose to
get help from others either during the tutorials or during some of the
coding sessions.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{pusers}
\end{center}\caption[]{
Number of users versus the year when they started using the code.
}\label{pusers}\end{figure}

\subsection{Mac problems}

Macs used to be the system of choice for many users.
This has changed and new upgrades often result in trouble.
These types of problems are usually unheard of for Linux users.
Fortunately, we had some experts.

Below, we reproduce two recent posts that are intended to help
with MacOS problems.
The instructions by \textit{Deepen Garg} (\url{https://www.dgarg.com/}) are now posted on
\url{http://pencil-code.nordita.org/doc/MacOS/Pencil_Code_MacOS_Writeup.pdf}.
This text is also listed on \url{http://pencil-code.nordita.org/doc.php} and
reproduced below in Sec. \ref{deepen}.

On September 30, Clara Dehman posted the following on our pencil-code-discuss list
(\url{https://groups.google.com/g/pencil-code-discuss/c/iZd8pG5B_DM/m/YEWC6bkUAwAJ}):

I'm reaching out regarding a solution I found for getting MPI to work
properly on my MacBook, which might be helpful for anyone facing similar
issues.

After updating my MacBook to the latest MacOS (Sequoia 15.0) and Xcode
(16.0), I encountered problems running the Pencil Code with multiple
processors due to MPI no longer functioning. I attempted various fixes,
including reverting to the previous Xcode version (15.3), which had
worked before, and uninstalling and reinstalling both Xcode and Homebrew
(which I used to install MPI). However, the problem persisted.

I then decided to use MacPorts instead of Homebrew. While installing
MacPorts, I was prompted to update to the latest version of Xcode
(16.0). Once I did that, installing MPI via MacPorts successfully resolved
the issue.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Tuesday}
\end{center}\caption[]{
Tuesday evening dinner: a great treat!
}\label{Tuesday}\end{figure}

\input{Pencil_Code_MacOS_Writeup.tex}
\label{deepen}

\subsection{Dinners and lunches}

Dinners and lunches provided great opportunities for discussing
problems of scientific interest; see \Figs{Tuesday}{Thursday}.
In the rest of this newsletter, we elaborate on some of the
points that emerged during the meeting.
When the Friday group picture was taken (\Fig{Friday}), some
people had left already, but others continued.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Thursday}
\end{center}\caption[]{
Thursday luncheon: all problems solved.
}\label{Thursday}\end{figure}

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Friday}
\end{center}\caption[]{
Friday group picture: some have left.
}\label{Friday}\end{figure}

%AB: added
\section{Tutorials from ``Bernoulli''}

On an earlier occasion, at the Bernoulli Center at EPFL in Lausanne (\url{https://indico.cern.ch/event/1334236/overview}),
\mbox{Jenny Schober and Alberto Roper Pol presented a} tutorial with hands-on exercises using \textsc{Pencil Code}.
It can be accessed via {Jenny's website} \footnote{\url{https://jennifer-schober.com/teaching/numerical-simulations-of-magnetohydrodynamics-in-the-early-universe}},
where it is protected under the password BernoulliMHD2024.
This course attracted a number of interested users, in particular those interested in MHD and GWs in the early Universe.
You can find a few pictures from the course and the workshop attached!

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Bernoulli}
\end{center}\caption[]{
\textsc{Pencil Code} tutorial at the Bernoulli Center at EPFL in Lausanne.
}\label{Bernoulli}\end{figure}

\section{GPU readiness}

During the PCUM24, Matthias Rheinhardt explained how to include
the Astaroth libraries in the \textsc{Pencil Code} so as to gain
significant speedup though GPU accelerated computing.
His presentation is now also listed on \url{http://pencil-code.nordita.org/doc.php}
and available on \url{http://pencil-code.nordita.org/doc/GPUs/Presentation3.pdf}.

\section{Dispersive and diffusive errors}

In simulations, dispersive errors result from truncation errors in the
spatial discretization, while diffusive errors result from truncation
errors in the temporal discretization.

When someone asks about numerical diffusion of a code, one does
usually not mean the diffusive error of the discretization scheme, but a numerical device
that acts like explicit diffusion in places where it is ``needed'',
e.g., ``slope-limited diffusion".
Below, we review dispersive and diffusive errors.

\subsection{Spatial discretization}

The spatial discretization with the 6th order scheme yields an error that
is proportional to $\delta x^6$, where $\delta x$ is the mesh spacing.
Specifically, we have
\begin{equation}
(f')^\mathrm{6th}_\mathrm{num}=f'+7\times10^{-3}\delta x^6\,f^\mathrm{(vii)};
\label{6thOrder}
\end{equation}
see Eq.~(9.42) of Brandenburg
(2003)\footnote{\url{http://norlx65.nordita.org/~brandenb/Own_Papers/B/2003/Bran_comp03.pdf}}.
For an advection equation of the form
\begin{equation}
\dot{f}=-Uf',
\label{AdvectEqu}
\end{equation}
where $U=\const$ is the advection speed, and $f\propto e^{\ii(kx-\omega t)}$,
we obtain for the dispersion relation
\begin{equation}
-\ii\omega=-\ii k U\left[1-7\times10^{-3}(k\delta x)^6+\ldots\right],
\label{DispRel}
\end{equation}
so $\omega$ is real, the error is dispersive and there is no diffusive error.

A dispersive error corresponds to a phase error, because the phase speed
of a wave, $\omega/k$, amounts no longer to the actual value of $(kU)/k=U$,
but to a smaller value, $(k_\mathrm{eff}U)/k$, where $k_\mathrm{eff}$
is the effective wavenumber, which is a function of $k$ that is no longer
linear at large $k$.
The highest wavenumber is the Nyquist frequency, $k_\mathrm{Ny}=\pi/\delta x$,
which corresponds to a zic-zac function where a wave period is described
by just two points.

At $k=k_\mathrm{Ny}$, the value of $k_\mathrm{eff}$ vanishes for
centered differences, so the error is infinite.
Computing $k_\mathrm{eff}(k)$ is an exercise in the \textsc{Pencil Code} course;
see \url{http://norlx65.nordita.org/~brandenb/teach/PencilCode/keff.html}.
We see from \Eq{DispRel} that the leading correction is proportional to
$(k\delta x)^6$, which is almost $10^3$ at the Nyquist wavenumber,
so $7\times10^{-3}(k\delta x)^6$ exceeds unity.
This shows that there are higher order terms that become important
at and near the Nyquist wavenumber.

\subsection{Diffusive error}

A diffusive error results from the temporal error of the scheme
in an advection equation such as \Eq{AdvectEqu}.
Analogous to \Eq{6thOrder}, the temporal error in the \textsc{Pencil Code}
is in our standard scheme
\begin{equation}
(\dot{f})^\mathrm{3rd}_\mathrm{num}=\dot{f}+\epsilon^\mathrm{(3rd)}\delta t^3\,\dd^4 f/\dd t^4.
\label{3rdOrder}
\end{equation}
where $\epsilon^\mathrm{(3rd)}=0.042$ is a non-dimensional coefficient
quantifying the error of the third order timestepping scheme.
To estimate $\dd^4 f/\dd t^4$, we differentiate \Eq{AdvectEqu} three
times (using $U=\const$).
After the first differentiation, we find $\ddot{f}=-U\dot{f}'=+U^2 f''$,
so we pick up a diffusion-like term.
Differentiating another two times, we obtain
$\dd^4 f/\dd t^4=U^4\dd^4 f/\dd x^4$, corresponding to fourth
order hyperdiffusion.
Inserting this into \Eq{3rdOrder} yields an advection-hyperdiffusion equation,
\begin{equation}
\dot{f}=-Uf'-\kappa_2\,\dd^4 f/\dd x^4,
\label{AdvectHyperDiff}
\end{equation}
with a hyperdiffusion coefficient $\kappa_2=\epsilon^\mathrm{(3rd)}\delta t^3 U^4$.
Already during the PCUM in 2009 in Heidelberg, it was demonstrated that the
advection of the sine wave with wavenumber $k=1$ yields diffusive behavior with
an exponential decay proportional to $e^{-\lambda t}$ at the rate $\lambda=1.06\times10^{-6}$
for 128 mesh points when $U=1$.
This agrees with the value of $\kappa_2 k^4$ obtained from the calculation above.

However, when applying upwinding, both discretizations contribute to both errors, for first order in $t$ and $x$:
\begin{align}
  \dot{f} + U f'= &\frac{U\delta x}{2}(1-\Cou) f'' \\
                                              &+ \frac{U(\delta x)^2}{6} (3 \Cou - 2 \Cou^2 -1) f''' \nonumber
\end{align}
with the Courant number $\Cou=U \delta t/\delta x$.

%AB: added
In general, upwinding can be described as as the
sum of a centered difference scheme and a centered hyperdiffusive term;
see Appendix~B of Dobler et al.\ (2006); see
\url{https://ui.adsabs.harvard.edu/abs/2006ApJ...638..336D/abstract}.
For a sixth-order scheme, this hyperdiffusivity is $|U|\delta x^5/60$.
%AB.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{pcomp}
\end{center}\caption[]{
Demonstration of start-up errors using $w=0.1$ (solid line) and $w=0.01$ (dotted line)
one timestep after the initial time $t_0$ (top)
and after 5 ``revolutions'' through the periodic mesh at $t_1=10\pi$ (bottom).
}\label{pcomp}\end{figure}

\subsection{Artificial viscosity in 2009}

Those who attended the PCUM in 2009 and the years before will remember
Mikaela Sundberg (Professor of Sociology at Stockholm University;
see \url{https://www.su.se/english/profiles/msund-1.183862}),
who studied the sociology of us during the meetings.
But you may not know that she has written several related papers.
Her work may attract new interest in view of related discussions
during the PCUM in Barcelona.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Sundberg12}
\end{center}\caption[]{
Excerpt from Sundberg's 2012 paper\protect\footnotemark.
}\label{Sundberg12}\end{figure}

Her impressions from a discussion of numerical diffusion
are reflected by the excerpt in \Fig{Sundberg12}
\footnotetext{Sundberg 2012,
 \textit{Science, Technology, \& Human Values}, \textbf{37}, 64--87
(\url{https://doi.org/10.1177/0162243910385417})}.
As back then, the community still seems divided.

\subsection{Start-up errors}

Start-up errors result when the initial condition is too sharp such that
its derivatives cannot be represented accurately by the scheme.
In the \textsc{Pencil Code}, advection tests can be done like in
\url{http://norlx65.nordita.org/~brandenb/teach/PencilCode/advection.html}.
A hatwave of the form
\begin{equation}
f=\half[1+\tanh(w^{-1}\cos kx)]
\end{equation}
is invoked through
\begin{verbatim}
&pscalar_init_pars
initlncc='hatwave-x',ampllncc=1e-0,widthcc=.10
\end{verbatim}
In \Fig{pcomp}, we see that $w=0.01$ is clearly too small and yields 
after one timestep sharp spikes in the tail of the flanks.
After five revolutions through the periodic mesh, i.e., at a time of $t=10\pi$ (for $k=U=1$), the profiles
for $w=0.01$ and $w=0.1$ look almost the same, however.
In both cases, we used for the passive scalar diffusivity the value $\kappa=5\times10^{-4}$.
On our mesh with $\delta x=2\pi/128\approx0.05$, this corresponds to $\kappa\approx0.01\,U\delta x$,
which was also the value used in Eq.~(9.42) of Brandenburg (2003) for the sixth-order scheme.


\section{Random tips}

\subsection{Check-in notifications}

Many of us receive check-in notifications after each check-in.
This can be a lot of mail, but normally you would delete it anyway
after having looked at it.
Being aware of the check-in activity can be useful for anybody
doing any changes to the code.
You might, e.g.,  think that a particular \texttt{special} module of yours
should only be of your concern, but this is not true.
Somebody else might need to make  changes to it because of
some compatibility issues, for example.

Check-in notifications are published on
\url{https://groups.google.com/g/pencil-code-commits}
and one can subscribe to this list.
Please email to brandenb@nordita.org.

\subsection{New ``Documentation'' material}

On \url{http://pencil-code.nordita.org/doc.php}, several new links have appeared.
One is by Deepen Garg with Instructions for MacOS installation (Sep 29, 2024).
Another is the GPU acceleration with the \textsc{Pencil Code} using Astaroth by Matthias Rheinhardt (25 Sep 2024).
Finally, we have now a link to the teaching material of Jennifer Schober from the Barcelona User Meeting,
where she explains how to simulate turbulent dynamos with the Pencil Code (Sep 25, 2024).

\section{Next PC User Meeting}

During the PCUM in Barcelona, there was an ad hoc steering
committee meeting to discuss proposals for the next meeting.
The current chair of the Pencil Code Steering Committee will ask
the proposers for more detailed proposals.
The minutes on the meeting will be published on
\url{http://norlx65.nordita.org/~brandenb/pencil-code/PCSC/minutes/}.

%AB: added
\section{Upcoming meetings}

Several meetings may be of interest to the \textsc{Pencil Code} community.
During December 2--4, there is the 19th MHD days in Potsdam; see \url{https://meetings.aip.de/event/1/}.
Furthermore, there will be two programs at Nordita during 2025:
the one on ``Axions in Stockholm'' during June 23 -- July 11 (\url{https://indico.fysik.su.se/event/8808/})
with \textsc{Pencil Code} user Oksana Iarygina as an organizer
and that on ``Numerical simulations of early Universe sources of gravitational waves'' during July 28 -- August 15
(\url{https://indico.fysik.su.se/event/8805/})
with \textsc{Pencil Code} user Alberto Roper Pol as an organizer
Both sites are still restricted though.

%It could also be mentioned that we are organizing a Nordita program next year (July 28-August 15) on "Numerical simulations of early Universe sources of gravitational waves," to be officially announced and distributed soon (see attached screenshot of the private webpage). If people are interested in organizing a working/discussion session focusing on Pencil Code, they can contact me.

\section{Papers since May 2024}

As usual, we look here at new papers that make use of the {\sc Pencil Code}.
Since the last newsletter of May, 3rd, 11 new papers have appeared    
on the arXiv, plus 9 others, some of which had been just preprints and have now been published in a journal.
We list both here, altogether 20.
A browsable ADS list of all {\sc Pencil Code} papers can be found on:
\url{https://ui.adsabs.harvard.edu/public-libraries/iGR7N570Sy6AlhDMQRTe_A}.
If something is missing in those entries, you can also include it yourself in:
\url{https://github.com/pencil-code/pencil-code/blob/master/doc/citations/ref.bib},
or otherwise just email brandenb@nordita.org.
A compiled version of this file is available as
\url{https://github.com/pencil-code/website/blob/master/doc/citations.pdf},
where we also list a total of now 119 code comparison papers in the last
section ``Code comparison \& reference''.
Those are not included in our list below, nor among the now total number
of 722 research papers that use the {\sc Pencil Code}.

\nocite{
2024arXiv240914045V,%Vemareddy "Simulating the formation and eruption of flux rope by magneto-friction model driven by time-dependent electric fields"
2024arXiv240914840K,%Kishore "Strengthening of the f mode due to subsurface magnetic fields in simulations of convection"
2024arXiv240918066H,%Hidalgo+ "Magnetohydrodynamic simulations of A-type stars: Long-term evolution of core dynamo cycles"
2024arXiv240817413B,%Brandenburg+ "Magnetogenesis from axion-SU(2) inflation"
2024arXiv240808819D,%Dehman+Brandenburg "Reality of Inverse Cascading in Neutron Star Crusts"
2024arXiv240807668L,%Lipatnikov "Towards large eddy simulations of premixed turbulent flames without a combustion model}",
2024SoPh..299..115V,%Vashishth "Hysteresis Near the Transition of the Large-Scale Dynamo in the Presence of the Small-Scale Dynamo"
2024PhRvD.110d3515S,%Schober+ "Efficiency of dynamos from autonomous generation of chiral asymmetry"
2024arXiv240718188S,%Maity+ "Evolution of reconnection flux during eruption of magnetic flux ropes"
2024LRCA...10....3K,%Korpi-Lagg+ "Computational approaches to modeling dynamos in galaxies"
2024ApJ...970L..19L,%Lyra+ "Rapid Protoplanet Formation in Vortices: Three-dimensional Local Simulations with Self-gravity"
2024A&A...687A.186B,%Brandenburg+ "Resistively controlled primordial magnetic turbulence decay"
2024arXiv240616230M,%Mtchedlidze+ "Intergalactic medium rotation measure of primordial magnetic fields"
2024arXiv240611798B,%Brandenburg+Banerjee "Turbulent magnetic decay controlled by two conserved quantities"
2024arXiv240608967W,%Warnecke+ "Small-scale and large-scale dynamos in global convection simulations of solar-like stars"
2024arXiv240517197Y,%Yuvraj+ "How ``mixing'' affects propagation and structure of intensely turbulent, lean, hydrogen-air premixed flames"
2024ApJ...966...90S,%Sengupta+ "Length and Velocity Scales in Protoplanetary Disk Turbulence"
2024ApJ...962...86M,%Maity+ "Changes in Photospheric Lorentz Force in Eruptive and Confined Solar Flares"
2024JFM...979A..46S,%Saieed+Hickey "Viscosity-modulated clustering of heated bidispersed particles in a turbulent gas"
2024PComI..4005315W%Wang+ "Particle-resolved numerical simulations of char particle combustion in isotropic turbulence"
%
%2024arXiv240410804E,%Elias-Lopez+ "Vorticity and magnetic dynamo from subsonic expansion waves II: Dependence on magnetic Prandtl number, forcing scale, cooling time"
%2024arXiv240101336H,%Hosking+ "Metastability of stratified magnetohydrostatic equilibria and their relaxation"
%2024arXiv240101965D,%Dwivedi+ "Quasi-two-dimensionality of three-dimensional, magnetically dominated, decaying turbulence"
%2024arXiv240115860Z,%Zhou+Jingade "Correlation times of velocity and kinetic helicity fluctuations in nonhelical hydrodynamic turbulence"
%2024arXiv240410720K,%Kesri+ "Dependence of spicule properties on magnetic field -- results from Magnetohydrodynamics simulations"
%2024arXiv240416096D,%Dey+ "Spinning solar jets explained through the interplay between plasma sheets and vortex columns"
%
% outdated
%2023arXiv231109082K,%Kapyla "Effects of rotation and surface forcing on deep stellar convection zones"
%2023arXiv230705490Z,%Zhu+Shi "Helical and nonhelical (magneto-)Burgers turbulence: I. Compressibility reduction and beyond"
%2023arXiv230300911Y,%Yuvraj "On flame speed enhancement in turbulent premixed hydrogen-air flames during local flame-flame interaction"
%2022arXiv220606566M,%Masada+Sano "Rotational Dependence of Large-scale Dynamo in Strongly-stratified Convection: What Causes It?"
%2022arXiv220509261R,%Roper Pol "Gravitational waves from MHD turbulence at the QCD phase transition as a source for Pulsar Timing Arrays"
%2021arXiv211201193C,%Candelaresi+Del Sordo "Stability of plasmas through magnetic helicity"
%2021arXiv210508287R,%Roper Pol "Gravitational radiation from MHD turbulence in the early universe"
}

\bibliography{ref}
\vspace{5mm}
\hrule
\vspace{2mm}
This {\sc Pencil Code} Newsletter was edited by
Axel Brandenburg {\tt <brandenb@nordita.org>}, Nordita, KTH Royal Institute of Technology and Stockholm University, SE-10691 Stockholm, Sweden;
and Matthias Rheinhardt {\tt <matthias.rheinhardt@aalto.fi>}, Department of Computer Science, Aalto University, PO Box 15400, FI-00076 Aalto, Finland.
See \url{http://www.nordita.org/~brandenb/pencil-code/newsletter} or
\url{https://github.com/pencil-code/website/tree/master/NewsLetters}
for the online version as well as back issues.
For a timeline off the beach of Bogatell on the last day of the PCUM24 in Barcelona; see \Fig{Timeline_Bogatell}.

\begin{figure}[h]\begin{center}
\includegraphics[width=\columnwidth]{Timeline_Bogatell}
\end{center}\caption[]{
Timeline off the beach of Bogatell on the last day of the PCUM24 in Barcelona.
}\label{Timeline_Bogatell}\end{figure}. 

\end{document}
