NGD6QWRDHWBMQXL2YXZVF3BFQALSII3LH6BMIOFL7VFMGPLHCZEQC
ActiveThorns = "
AMReX
IOUtil
MaxwellToyAMReX
"
$nlevels = 1
$ncells = 32
Cactus::cctk_show_schedule = no
# Cactus::terminate = "iteration"
# Cactus::cctk_itlast = 0
Cactus::terminate = "time"
Cactus::cctk_final_time = 2.0
# AMReX::verbose = yes
AMReX::xmin = -1.0
AMReX::ymin = -1.0
AMReX::zmin = -1.0
AMReX::xmax = +1.0
AMReX::ymax = +1.0
AMReX::zmax = +1.0
AMReX::ncells_x = $ncells
AMReX::ncells_y = $ncells
AMReX::ncells_z = $ncells
AMReX::max_num_levels = $nlevels
AMReX::regrid_every = 16
AMReX::regrid_error_threshold = 0.1
AMReX::dtfac = 0.5
MaxwellToyAMReX::spatial_frequency_x = 0.5
MaxwellToyAMReX::spatial_frequency_y = 0.0
MaxwellToyAMReX::spatial_frequency_z = 0.0
IO::out_dir = $parfile
IO::out_every = $ncells * 2 ** ($nlevels - 1) / 32
Cactus Code Thorn HydroToyAMReX
Author(s) : Erik Schnetter <schnetter@gmail.com>
Maintainer(s): Erik Schnetter <schnetter@gmail.com>
Licence : LGPL
--------------------------------------------------------------------------
1. Purpose
Solve the non-relativistic hydrodynamics equations
# Configuration definitions for thorn HydroToyAMReX
% *======================================================================*
% Cactus Thorn template for ThornGuide documentation
% Author: Ian Kelley
% Date: Sun Jun 02, 2002
% $Header$
%
% Thorn documentation in the latex file doc/documentation.tex
% will be included in ThornGuides built with the Cactus make system.
% The scripts employed by the make system automatically include
% pages about variables, parameters and scheduling parsed from the
% relevant thorn CCL files.
%
% This template contains guidelines which help to assure that your
% documentation will be correctly added to ThornGuides. More
% information is available in the Cactus UsersGuide.
%
% Guidelines:
% - Do not change anything before the line
% % START CACTUS THORNGUIDE",
% except for filling in the title, author, date, etc. fields.
% - Each of these fields should only be on ONE line.
% - Author names should be separated with a \\ or a comma.
% - You can define your own macros, but they must appear after
% the START CACTUS THORNGUIDE line, and must not redefine standard
% latex commands.
% - To avoid name clashes with other thorns, 'labels', 'citations',
% 'references', and 'image' names should conform to the following
% convention:
% ARRANGEMENT_THORN_LABEL
% For example, an image wave.eps in the arrangement CactusWave and
% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps
% - Graphics should only be included using the graphicx package.
% More specifically, with the "\includegraphics" command. Do
% not specify any graphic file extensions in your .tex file. This
% will allow us to create a PDF version of the ThornGuide
% via pdflatex.
% - References should be included with the latex "\bibitem" command.
% - Use \begin{abstract}...\end{abstract} instead of \abstract{...}
% - Do not use \appendix, instead include any appendices you need as
% standard sections.
% - For the benefit of our Perl scripts, and for future extensions,
% please use simple latex.
%
% *======================================================================*
%
% Example of including a graphic image:
% \begin{figure}[ht]
% \begin{center}
% \includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}
% \end{center}
% \caption{Illustration of this and that}
% \label{MyArrangement_MyThorn_MyLabel}
% \end{figure}
%
% Example of using a label:
% \label{MyArrangement_MyThorn_MyLabel}
%
% Example of a citation:
% \cite{MyArrangement_MyThorn_Author99}
%
% Example of including a reference
% \bibitem{MyArrangement_MyThorn_Author99}
% {J. Author, {\em The Title of the Book, Journal, or periodical}, 1 (1999),
% 1--16. {\tt http://www.nowhere.com/}}
%
% *======================================================================*
% If you are using CVS use this line to give version information
% $Header$
\documentclass{article}
% Use the Cactus ThornGuide style file
% (Automatically used from Cactus distribution, if you have a
% thorn without the Cactus Flesh download this from the Cactus
% homepage at www.cactuscode.org)
\usepackage{../../../../doc/latex/cactus}
\begin{document}
% The author of the documentation
\author{Erik Schnetter \textless schnetter@gmail.com\textgreater}
% The title of the document (not necessarily the name of the Thorn)
\title{WaveToyAMReX}
% the date your document was last changed, if your document is in CVS,
% please use:
% \date{$ $Date$ $}
\date{July 10 2019}
\maketitle
% Do not delete next line
% START CACTUS THORNGUIDE
% Add all definitions used in this documentation here
% \def\mydef etc
% Add an abstract for this thorn's documentation
\begin{abstract}
\end{abstract}
% The following sections are suggestive only.
% Remove them or add your own.
\section{Introduction}
\section{Physical System}
\section{Numerical Implementation}
\section{Using This Thorn}
\subsection{Obtaining This Thorn}
\subsection{Basic Usage}
\subsection{Special Behaviour}
\subsection{Interaction With Other Thorns}
\subsection{Examples}
\subsection{Support and Feedback}
\section{History}
\subsection{Thorn Source Code}
\subsection{Thorn Documentation}
\subsection{Acknowledgements}
\begin{thebibliography}{9}
\end{thebibliography}
% Do not delete next line
% END CACTUS THORNGUIDE
\end{document}
# Interface definition for thorn HydroToyAMReX
IMPLEMENTS: HydroToyAMReX
INHERITS: AMReX
USES INCLUDE HEADER: loop.hxx
CCTK_REAL density TYPE=gf TIMELEVELS=2
{
rho
} "Density"
CCTK_REAL momentum TYPE=gf TIMELEVELS=2
{
momx momy momz
} "Momentum"
CCTK_REAL energy TYPE=gf TIMELEVELS=2
{
etot
} "Energy"
# Parameter definitions for thorn HydroToyAMReX
# Schedule definitions for thorn HydroToyAMReX
SCHEDULE HydroToyAMReX_Initialize AT initial
{
LANG: C
} "Set up hydro initial conditions"
SCHEDULE HydroToyAMReX_Evolve AT evol
{
LANG: C
} "Evolve the hydro equations"
#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>
#include <loop.hxx>
#include <cassert>
#include <cmath>
#include <iostream>
namespace HydroToyAMReX {
using namespace std;
constexpr int dim = 3;
////////////////////////////////////////////////////////////////////////////////
extern "C" void HydroToyAMReX_Initialize(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL t = cctk_time;
const CCTK_REAL dt = CCTK_DELTA_TIME;
CCTK_REAL x0[dim], dx[dim];
for (int d = 0; d < dim; ++d) {
x0[d] = CCTK_ORIGIN_SPACE(d);
dx[d] = CCTK_DELTA_SPACE(d);
}
Loop::loop_all(cctkGH, [&](int i, int j, int k, int idx) {
rho[idx] = 1.0;
momx[idx] = 0.0;
momy[idx] = 0.0;
momz[idx] = 0.0;
etot[idx] = 1.0;
});
}
extern "C" void HydroToyAMReX_Evolve(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL dt = CCTK_DELTA_TIME;
const CCTK_REAL dx = CCTK_DELTA_SPACE(0);
const CCTK_REAL dy = CCTK_DELTA_SPACE(1);
const CCTK_REAL dz = CCTK_DELTA_SPACE(2);
constexpr int di = 1;
const int dj = di * cctk_ash[0];
const int dk = dj * cctk_ash[1];
Loop::loop_int(cctkGH, [&](int i, int j, int k, int idx) {
// dt rho + d_i (rho vel^i) = 0
rho[idx] = rho_p[idx] - dt * ((momx_p[idx + di] - momx_p[idx]) / dx +
(momy_p[idx + dj] - momy_p[idx]) / dy +
(momz_p[idx + dk] - momz_p[idx]) / dz);
// // dt mom^i + d_j (mom^i vel^j) = 0
// momx[idx] = momx_p[idx] - dt * (
// momx_p[idx] * momx_p[idx]
// );
CCTK_REAL velx = momx[idx] / rho[idx];
CCTK_REAL vely = momy[idx] / rho[idx];
CCTK_REAL velz = momz[idx] / rho[idx];
});
}
} // namespace HydroToyAMReX
# Main make.code.defn file for thorn WaveToyAMReX
# Source files in this directory
SRCS = hydrotoy.cxx
# Subdirectories containing source files
SUBDIRS =
Cactus Code Thorn MaxwellToyAMReX
Author(s) : Erik Schnetter <schnetter@gmail.com>
Maintainer(s): Erik Schnetter <schnetter@gmail.com>
Licence : LGPL
--------------------------------------------------------------------------
1. Purpose
Solve the Maxwell equations
# Configuration definitions for thorn MaxwellToyAMReX
% *======================================================================*
% Cactus Thorn template for ThornGuide documentation
% Author: Ian Kelley
% Date: Sun Jun 02, 2002
% $Header$
%
% Thorn documentation in the latex file doc/documentation.tex
% will be included in ThornGuides built with the Cactus make system.
% The scripts employed by the make system automatically include
% pages about variables, parameters and scheduling parsed from the
% relevant thorn CCL files.
%
% This template contains guidelines which help to assure that your
% documentation will be correctly added to ThornGuides. More
% information is available in the Cactus UsersGuide.
%
% Guidelines:
% - Do not change anything before the line
% % START CACTUS THORNGUIDE",
% except for filling in the title, author, date, etc. fields.
% - Each of these fields should only be on ONE line.
% - Author names should be separated with a \\ or a comma.
% - You can define your own macros, but they must appear after
% the START CACTUS THORNGUIDE line, and must not redefine standard
% latex commands.
% - To avoid name clashes with other thorns, 'labels', 'citations',
% 'references', and 'image' names should conform to the following
% convention:
% ARRANGEMENT_THORN_LABEL
% For example, an image wave.eps in the arrangement CactusWave and
% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps
% - Graphics should only be included using the graphicx package.
% More specifically, with the "\includegraphics" command. Do
% not specify any graphic file extensions in your .tex file. This
% will allow us to create a PDF version of the ThornGuide
% via pdflatex.
% - References should be included with the latex "\bibitem" command.
% - Use \begin{abstract}...\end{abstract} instead of \abstract{...}
% - Do not use \appendix, instead include any appendices you need as
% standard sections.
% - For the benefit of our Perl scripts, and for future extensions,
% please use simple latex.
%
% *======================================================================*
%
% Example of including a graphic image:
% \begin{figure}[ht]
% \begin{center}
% \includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}
% \end{center}
% \caption{Illustration of this and that}
% \label{MyArrangement_MyThorn_MyLabel}
% \end{figure}
%
% Example of using a label:
% \label{MyArrangement_MyThorn_MyLabel}
%
% Example of a citation:
% \cite{MyArrangement_MyThorn_Author99}
%
% Example of including a reference
% \bibitem{MyArrangement_MyThorn_Author99}
% {J. Author, {\em The Title of the Book, Journal, or periodical}, 1 (1999),
% 1--16. {\tt http://www.nowhere.com/}}
%
% *======================================================================*
% If you are using CVS use this line to give version information
% $Header$
\documentclass{article}
% Use the Cactus ThornGuide style file
% (Automatically used from Cactus distribution, if you have a
% thorn without the Cactus Flesh download this from the Cactus
% homepage at www.cactuscode.org)
\usepackage{../../../../doc/latex/cactus}
\begin{document}
% The author of the documentation
\author{Erik Schnetter \textless schnetter@gmail.com\textgreater}
% The title of the document (not necessarily the name of the Thorn)
\title{WaveToyAMReX}
% the date your document was last changed, if your document is in CVS,
% please use:
% \date{$ $Date$ $}
\date{July 10 2019}
\maketitle
% Do not delete next line
% START CACTUS THORNGUIDE
% Add all definitions used in this documentation here
% \def\mydef etc
% Add an abstract for this thorn's documentation
\begin{abstract}
\end{abstract}
% The following sections are suggestive only.
% Remove them or add your own.
\section{Introduction}
\section{Physical System}
\section{Numerical Implementation}
\section{Using This Thorn}
\subsection{Obtaining This Thorn}
\subsection{Basic Usage}
\subsection{Special Behaviour}
\subsection{Interaction With Other Thorns}
\subsection{Examples}
\subsection{Support and Feedback}
\section{History}
\subsection{Thorn Source Code}
\subsection{Thorn Documentation}
\subsection{Acknowledgements}
\begin{thebibliography}{9}
\end{thebibliography}
% Do not delete next line
% END CACTUS THORNGUIDE
\end{document}
# Interface definition for thorn MaxwellToyAMReX
IMPLEMENTS: MaxwellToyAMReX
INHERITS: AMReX
USES INCLUDE HEADER: loop.hxx
# Wikipedia, <https://en.wikipedia.org/wiki/Maxwell%27s_equations>
CCTK_REAL potential TYPE=gf TIMELEVELS=2
{
# d*dA = mu J A^a,^b_b - A^b,^a_b = mu J^a
# d*A = 0 A^a,a = 0
# -d*(dphi + A,t) = rho/epsilon
# d*dA + dt*(dphi+A,t) = mu J
# *phi,t + d*A = 0 phi,t + A^i,i = 0
phi
ax ay az
} "Electromagnetic potential"
CCTK_REAL field TYPE=gf TIMELEVELS=2
{
# F = dA F_ab = A_a,b - A_b,a
# dF = 0 F_ab,c + F_bc,a + F_ca,b = 0
# d*F = mu J F^ab,a = mu J^b
# E = -dphi - A,t E_i = - phi,i - A_i,t
# B = dA B_ij = A_j,i - A_i,j
# dE + B,t = 0 E_j,i - E_i,j + B_ij,t = 0
# dB = 0 B_jk,i + B_ki,j + B_ijk = 0
# d*E = rho/epsilon E^i,i = rho/epsilon
# d*B - dt*E = mu J - B^ij,i - E^j,t = mu J^j
ex ey ez
bx by bz # B_yz B_zx B_xy
} "Electromagnetic field"
CCTK_REAL current TYPE=gf TIMELEVELS=2
{
rho
jx jy jz
} "Electric charge current"
CCTK_REAL errors TYPE=gf
{
phierr
axerr ayerr azerr
exerr eyerr ezerr
bxerr byerr bzerr
rhoerr
jxerr jyerr jzerr
} "Errors"
# CCTK_REAL constraints TYPE=gf
# {
# dive
# divb
# } "Constraints"
#
# CCTK_REAL poynting TYPE=gf
# {
# sx sy sz
# } "Poynting vector"
#
# CCTK_REAL energy TYPE=gf
# {
# eps
# } "Electromagnetic energy density"
# Parameter definitions for thorn MaxwellToyAMReX
KEYWORD initial_condition "Initial condition"
{
"plane wave" :: ""
} "plane wave"
CCTK_REAL spatial_frequency_x "spatial frequency"
{
*:* :: ""
} 0.5
CCTK_REAL spatial_frequency_y "spatial frequency"
{
*:* :: ""
} 0.5
CCTK_REAL spatial_frequency_z "spatial frequency"
{
*:* :: ""
} 0.5
# Schedule definitions for thorn MaxwellToyAMReX
SCHEDULE MaxwellToyAMReX_Initialize AT initial
{
LANG: C
} "Set up initial conditions for the Maxwell equations"
SCHEDULE MaxwellToyAMReX_EstimateError AT postinitial
{
LANG: C
} "Estimate local error for regridding initial conditions"
SCHEDULE MaxwellToyAMReX_Evolve1 AT evol
{
LANG: C
SYNC: potential field current
} "Evolve the Maxwell equations, step 1"
SCHEDULE MaxwellToyAMReX_Evolve2 AT evol AFTER MaxwellToyAMReX_Evolve1
{
LANG: C
SYNC: potential field current
} "Evolve the Maxwell equations step 2"
# SCHEDULE MaxwellToyAMReX_Constraints AT analysis
# {
# LANG: C
# } "Calculate constraints of the Maxwell equations"
# SCHEDULE MaxwellToyAMReX_Energy AT analysis
# {
# LANG: C
# } "Calculate energy density for the Maxwell equations"
SCHEDULE MaxwellToyAMReX_EstimateError AT poststep
{
LANG: C
} "Estimate local error for regridding during evolution"
SCHEDULE MaxwellToyAMReX_Error AT analysis
{
LANG: C
} "Calculate error for the Maxwell equations"
# Main make.code.defn file for thorn MaxwellToyAMReX
# Source files in this directory
SRCS = maxwelltoy.cxx
# Subdirectories containing source files
SUBDIRS =
#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>
#include <loop.hxx>
#include <cassert>
#include <cmath>
#include <iostream>
namespace MaxwellToyAMReX {
using namespace std;
constexpr int dim = 3;
////////////////////////////////////////////////////////////////////////////////
template <typename T> struct potential {
T phi, ax, ay, az;
potential operator-(const potential &y) const {
const auto &x = *this;
return {.phi = x.phi - y.phi,
.ax = x.ax - y.ax,
.ay = x.ay - y.ay,
.az = x.az - y.az};
}
potential operator/(T a) const {
const auto &x = *this;
return {.phi = x.phi / a, .ax = x.ax / a, .ay = x.ay / a, .az = x.az / a};
}
};
template <typename T> potential<T> plane_wave(T t, T x, T y, T z) {
DECLARE_CCTK_PARAMETERS;
T kx = 2 * M_PI * spatial_frequency_x;
T ky = 2 * M_PI * spatial_frequency_y;
T kz = 2 * M_PI * spatial_frequency_z;
T omega = sqrt(pow(kx, 2) + pow(ky, 2) + pow(kz, 2));
return {.phi = cos(omega * t - kx * x - ky * y - kz * z),
.ax = omega / kx * cos(omega * t - kx * x - ky * y - kz * z),
.ay = 0,
.az = 0};
}
////////////////////////////////////////////////////////////////////////////////
// Derivatives
template <typename T, typename R> auto tderiv(R f(T t, T x, T y, T z), T dt) {
return [=](T t, T x, T y, T z) {
return (f(t + dt / 2, x, y, z) - f(t - dt / 2, x, y, z)) / dt;
};
}
template <typename T, typename R> auto xderiv(R f(T t, T x, T y, T z), T dx) {
return [=](T t, T x, T y, T z) {
return (f(t, x + dx / 2, y, z) - f(t, x - dx / 2, y, z)) / dx;
};
}
template <typename T, typename R> auto yderiv(R f(T t, T x, T y, T z), T dy) {
return [=](T t, T x, T y, T z) {
return (f(t, x, y + dy / 2, z) - f(t, x, y - dy / 2, z)) / dy;
};
}
template <typename T, typename R> auto zderiv(R f(T t, T x, T y, T z), T dz) {
return [=](T t, T x, T y, T z) {
return (f(t, x, y, z + dz / 2) - f(t, x, y, z - dz / 2)) / dz;
};
}
////////////////////////////////////////////////////////////////////////////////
extern "C" void MaxwellToyAMReX_Initialize(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL t = cctk_time;
const CCTK_REAL x0 = CCTK_ORIGIN_SPACE(0);
const CCTK_REAL y0 = CCTK_ORIGIN_SPACE(1);
const CCTK_REAL z0 = CCTK_ORIGIN_SPACE(2);
const CCTK_REAL dt = CCTK_DELTA_TIME;
const CCTK_REAL dx = CCTK_DELTA_SPACE(0);
const CCTK_REAL dy = CCTK_DELTA_SPACE(1);
const CCTK_REAL dz = CCTK_DELTA_SPACE(2);
if (CCTK_EQUALS(initial_condition, "plane wave")) {
Loop::loop_all(cctkGH, [&](int i, int j, int k, int idx) {
CCTK_REAL x = x0 + (cctk_lbnd[0] + i) * dx;
CCTK_REAL y = y0 + (cctk_lbnd[1] + j) * dy;
CCTK_REAL z = z0 + (cctk_lbnd[2] + k) * dz;
phi[idx] = plane_wave(t + dt / 2, x, y, z).phi;
ax[idx] = plane_wave(t, x + dx / 2, y, z).ax;
ay[idx] = plane_wave(t, x, y + dy / 2, z).ay;
az[idx] = plane_wave(t, x, y, z + dz / 2).az;
ex[idx] =
-xderiv(plane_wave<CCTK_REAL>, dx)(t + dt / 2, x + dx / 2, y, z).phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x + dx / 2, y, z).ax;
ey[idx] =
-yderiv(plane_wave<CCTK_REAL>, dy)(t + dt / 2, x, y + dy / 2, z).phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x, y + dy / 2, z).ay;
ez[idx] =
-zderiv(plane_wave<CCTK_REAL>, dz)(t + dt / 2, x, y, z + dz / 2).phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x, y, z + dz / 2).az;
bx[idx] =
yderiv(plane_wave<CCTK_REAL>, dy)(t, x, y + dy / 2, z + dz / 2).az -
zderiv(plane_wave<CCTK_REAL>, dz)(t, x, y + dy / 2, z + dz / 2).ay;
by[idx] =
zderiv(plane_wave<CCTK_REAL>, dz)(t, x + dx / 2, y, z + dz / 2).ax -
xderiv(plane_wave<CCTK_REAL>, dx)(t, x + dx / 2, y, z + dz / 2).az;
bz[idx] =
xderiv(plane_wave<CCTK_REAL>, dx)(t, x, y + dy / 2, z + dz / 2).ay -
yderiv(plane_wave<CCTK_REAL>, dy)(t, x, y + dy / 2, z + dz / 2).ax;
rho[idx] = 0.0;
jx[idx] = 0.0;
jy[idx] = 0.0;
jz[idx] = 0.0;
});
} else {
assert(0);
}
}
extern "C" void MaxwellToyAMReX_Evolve1(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL dt = CCTK_DELTA_TIME;
const CCTK_REAL dx = CCTK_DELTA_SPACE(0);
const CCTK_REAL dy = CCTK_DELTA_SPACE(1);
const CCTK_REAL dz = CCTK_DELTA_SPACE(2);
constexpr int di = 1;
const int dj = di * cctk_ash[0];
const int dk = dj * cctk_ash[1];
Loop::loop_int(cctkGH, [&](int i, int j, int k, int idx) {
jx[idx] = jx_p[idx];
jy[idx] = jy_p[idx];
jz[idx] = jz_p[idx];
bx[idx] = bx_p[idx] + dt * ((ey_p[idx + dk] - ey_p[idx]) / dz -
(ez_p[idx + dj] - ez_p[idx]) / dy);
by[idx] = by_p[idx] + dt * ((ez_p[idx + di] - ez_p[idx]) / dx -
(ex_p[idx + dk] - ex_p[idx]) / dz);
bz[idx] = bz_p[idx] + dt * ((ex_p[idx + dj] - ex_p[idx]) / dy -
(ey_p[idx + di] - ey_p[idx]) / dx);
ax[idx] =
ax_p[idx] - dt * ((phi_p[idx + di] - phi_p[idx]) / dx + ex_p[idx]);
ay[idx] =
ay_p[idx] - dt * ((phi_p[idx + dj] - phi_p[idx]) / dy + ey_p[idx]);
az[idx] =
az_p[idx] - dt * ((phi_p[idx + dk] - phi_p[idx]) / dz + ez_p[idx]);
});
}
extern "C" void MaxwellToyAMReX_Evolve2(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL dt = CCTK_DELTA_TIME;
const CCTK_REAL dx = CCTK_DELTA_SPACE(0);
const CCTK_REAL dy = CCTK_DELTA_SPACE(1);
const CCTK_REAL dz = CCTK_DELTA_SPACE(2);
constexpr int di = 1;
const int dj = di * cctk_ash[0];
const int dk = dj * cctk_ash[1];
Loop::loop_int(cctkGH, [&](int i, int j, int k, int idx) {
rho[idx] = rho_p[idx] - dt * ((jx[idx] - jx[idx - di]) / dx +
(jy[idx] - jy[idx - dj]) / dy +
(jz[idx] - jz[idx - dk]) / dz);
ex[idx] = ex_p[idx] - dt * ((by[idx] - by[idx - dk]) / dz -
(bz[idx] - bz[idx - dj]) / dy + jx[idx]);
ey[idx] = ey_p[idx] - dt * ((bz[idx] - bz[idx - di]) / dx -
(bx[idx] - bx[idx - dk]) / dz + jy[idx]);
ez[idx] = ez_p[idx] - dt * ((bx[idx] - bx[idx - dj]) / dy -
(by[idx] - by[idx - di]) / dx + jz[idx]);
phi[idx] = phi_p[idx] - dt * ((ax[idx] - ax[idx - di]) / dx +
(ay[idx] - ay[idx - dj]) / dy +
(ay[idx] - az[idx - dk]) / dz);
});
}
extern "C" void MaxwellToyAMReX_EstimateError(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
Loop::loop_int(cctkGH,
[&](int i, int j, int k, int idx) { regrid_error[idx] = 0; });
}
extern "C" void MaxwellToyAMReX_Error(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;
const CCTK_REAL t = cctk_time;
const CCTK_REAL x0 = CCTK_ORIGIN_SPACE(0);
const CCTK_REAL y0 = CCTK_ORIGIN_SPACE(1);
const CCTK_REAL z0 = CCTK_ORIGIN_SPACE(2);
const CCTK_REAL dt = CCTK_DELTA_TIME;
const CCTK_REAL dx = CCTK_DELTA_SPACE(0);
const CCTK_REAL dy = CCTK_DELTA_SPACE(1);
const CCTK_REAL dz = CCTK_DELTA_SPACE(2);
if (CCTK_EQUALS(initial_condition, "plane wave")) {
Loop::loop_all(cctkGH, [&](int i, int j, int k, int idx) {
CCTK_REAL x = x0 + (cctk_lbnd[0] + i) * dx;
CCTK_REAL y = y0 + (cctk_lbnd[1] + j) * dy;
CCTK_REAL z = z0 + (cctk_lbnd[2] + k) * dz;
phierr[idx] = phi[idx] - plane_wave(t + dt / 2, x, y, z).phi;
axerr[idx] = ax[idx] - plane_wave(t, x + dx / 2, y, z).ax;
ayerr[idx] = ay[idx] - plane_wave(t, x, y + dy / 2, z).ay;
azerr[idx] = az[idx] - plane_wave(t, x, y, z + dz / 2).az;
exerr[idx] =
ex[idx] -
(-xderiv(plane_wave<CCTK_REAL>, dx)(t + dt / 2, x + dx / 2, y, z)
.phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x + dx / 2, y, z).ax);
eyerr[idx] =
ey[idx] -
(-yderiv(plane_wave<CCTK_REAL>, dy)(t + dt / 2, x, y + dy / 2, z)
.phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x, y + dy / 2, z).ay);
ezerr[idx] =
ez[idx] -
(-zderiv(plane_wave<CCTK_REAL>, dz)(t + dt / 2, x, y, z + dz / 2)
.phi -
tderiv(plane_wave<CCTK_REAL>, dt)(t + dt / 2, x, y, z + dz / 2).az);
bxerr[idx] =
bx[idx] -
(yderiv(plane_wave<CCTK_REAL>, dy)(t, x, y + dy / 2, z + dz / 2).az -
zderiv(plane_wave<CCTK_REAL>, dz)(t, x, y + dy / 2, z + dz / 2).ay);
byerr[idx] =
by[idx] -
(zderiv(plane_wave<CCTK_REAL>, dz)(t, x + dx / 2, y, z + dz / 2).ax -
xderiv(plane_wave<CCTK_REAL>, dx)(t, x + dx / 2, y, z + dz / 2).az);
bzerr[idx] =
bz[idx] -
(xderiv(plane_wave<CCTK_REAL>, dx)(t, x, y + dy / 2, z + dz / 2).ay -
yderiv(plane_wave<CCTK_REAL>, dy)(t, x, y + dy / 2, z + dz / 2).ax);
rhoerr[idx] = 0.0;
jxerr[idx] = 0.0;
jyerr[idx] = 0.0;
jzerr[idx] = 0.0;
});
} else {
assert(0);
}
}
} // namespace MaxwellToyAMReX