Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output to separate files #75

Merged
merged 24 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0269572
patch for mpich send buffr
haykh Jul 29, 2024
35ebe53
initial commit: modification to shock pgen to run magnetized shocks
LudwigBoess Aug 3, 2024
5132360
fix misunderstanding in setup
LudwigBoess Sep 5, 2024
cdfd285
fix sign error
LudwigBoess Sep 11, 2024
e24078c
fix sign error
LudwigBoess Sep 11, 2024
37871f9
Merge branch 'pgen/magnetized_shock' of https://github.com/entity-too…
LudwigBoess Sep 11, 2024
0fc366c
Added comment for `InitFields`
LudwigBoess Sep 11, 2024
c3b1018
fix signs (again)
LudwigBoess Sep 23, 2024
d666d1e
removed redundant parameter and added comments
LudwigBoess Sep 23, 2024
0b65f55
added atmosphere bc to enforce initial magnetic field config at the b…
LudwigBoess Oct 2, 2024
96a295c
patch for mpich send buffr
haykh Jul 29, 2024
2344629
initial commit: modification to shock pgen to run magnetized shocks
LudwigBoess Aug 3, 2024
a5f3485
fix misunderstanding in setup
LudwigBoess Sep 5, 2024
6eb034f
fix sign error
LudwigBoess Sep 11, 2024
9d1b39b
Added comment for `InitFields`
LudwigBoess Sep 11, 2024
037c705
fix signs (again)
LudwigBoess Sep 23, 2024
a613d0a
removed redundant parameter and added comments
LudwigBoess Sep 23, 2024
31a7d5b
added atmosphere bc to enforce initial magnetic field config at the b…
LudwigBoess Oct 2, 2024
4f6ad9d
Merge branch 'pgen/magnetized_shock' of github.com:entity-toolkit/ent…
haykh Nov 5, 2024
78412c8
changed FieldBC to FIXED
haykh Nov 5, 2024
9834995
FIXED bc + ATM
haykh Nov 5, 2024
833f038
multifile output
haykh Nov 6, 2024
7c940f7
0 particle case in timers
haykh Nov 12, 2024
f2be35a
Merge branch '1.2.0rc' into dev/sepfiles
haykh Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ venv/
# CMake testing files
Testing/

tags
.clangd
.schema.json
*_old/
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ if(${DEBUG} STREQUAL "OFF")
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "CMake build type")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DNDEBUG -Wno-unused-local-typedefs -Wno-unknown-cuda-version"
)
else()
set(CMAKE_BUILD_TYPE
Debug
Expand All @@ -64,8 +66,6 @@ else()
"${CMAKE_CXX_FLAGS} -DDEBUG -Wall -Wextra -Wno-unknown-pragmas")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")

# options
set(precisions
"single" "double"
Expand Down
10 changes: 7 additions & 3 deletions input.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
# Boundary conditions for fields:
# @required
# @type: 1/2/3-size array of string tuples, each of size 1 or 2
# @valid: "PERIODIC", "ABSORB", "ATMOSPHERE", "CUSTOM", "HORIZON"
# @valid: "PERIODIC", "ABSORB", "FIXED", "ATMOSPHERE", "CUSTOM", "HORIZON"
# @example: [["CUSTOM", "ABSORB"]] (for 2D spherical [[rmin, rmax]])
# @note: When periodic in any of the directions, you should only set one value [..., ["PERIODIC"], ...]
# @note: In spherical, bondaries in theta/phi are set automatically (only specify bc @ [rmin, rmax]) [["ATMOSPHERE", "ABSORB"]]
# @note: When periodic in any of the directions, you should only set one value: [..., ["PERIODIC"], ...]
# @note: In spherical, bondaries in theta/phi are set automatically (only specify bc @ [rmin, rmax]): [["ATMOSPHERE", "ABSORB"]]
# @note: In GR, the horizon boundary is set automatically (only specify bc @ rmax): [["ABSORB"]]
fields = ""
# Boundary conditions for fields:
Expand Down Expand Up @@ -319,6 +319,10 @@
# @default: -1.0 (disabled)
# @note: When `interval_time` < 0, the output is controlled by `interval`, otherwise by `interval_time`
interval_time = ""
# Whether to output each timestep into separate files:
# @type: bool
# @default: true
separate_files = ""

[output.fields]
# Toggle for the field output:
Expand Down
77 changes: 74 additions & 3 deletions setups/srpic/shock/pgen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "global.h"

#include "arch/traits.h"
#include "utils/error.h"
#include "utils/numeric.h"

#include "archetypes/energy_dist.h"
#include "archetypes/particle_injector.h"
Expand All @@ -14,6 +16,53 @@
namespace user {
using namespace ntt;

template <Dimension D>
struct InitFields {
/*
Sets up magnetic and electric field components for the simulation.
Must satisfy E = -v x B for Lorentz Force to be zero.

@param bmag: magnetic field scaling
@param btheta: magnetic field polar angle
@param bphi: magnetic field azimuthal angle
@param drift_ux: drift velocity in the x direction
*/
InitFields(real_t bmag, real_t btheta, real_t bphi, real_t drift_ux)
: Bmag { bmag * static_cast<real_t>(convert::deg2rad) }
, Btheta { btheta * static_cast<real_t>(convert::deg2rad) }
, Bphi { bphi * static_cast<real_t>(convert::deg2rad) }
, Vx { drift_ux } {}

// magnetic field components
Inline auto bx1(const coord_t<D>&) const -> real_t {
return Bmag * math::cos(Btheta);
}

Inline auto bx2(const coord_t<D>&) const -> real_t {
return Bmag * math::sin(Btheta) * math::sin(Bphi);
}

Inline auto bx3(const coord_t<D>&) const -> real_t {
return Bmag * math::sin(Btheta) * math::cos(Bphi);
}

// electric field components
Inline auto ex1(const coord_t<D>&) const -> real_t {
return ZERO;
}

Inline auto ex2(const coord_t<D>&) const -> real_t {
return -Vx * Bmag * math::sin(Btheta) * math::cos(Bphi);
}

Inline auto ex3(const coord_t<D>&) const -> real_t {
return Vx * Bmag * math::sin(Btheta) * math::sin(Bphi);
}

private:
const real_t Btheta, Bphi, Vx, Bmag;
};

template <SimEngine::type S, class M>
struct PGen : public arch::ProblemGenerator<S, M> {
// compatibility traits for the problem generator
Expand All @@ -30,20 +79,42 @@ namespace user {

const real_t drift_ux, temperature;

const real_t Btheta, Bphi, Bmag;
InitFields<D> init_flds;

inline PGen(const SimulationParams& p, const Metadomain<S, M>& m)
: arch::ProblemGenerator<S, M>(p)
: arch::ProblemGenerator<S, M> { p }
, drift_ux { p.template get<real_t>("setup.drift_ux") }
, temperature { p.template get<real_t>("setup.temperature") } {}
, temperature { p.template get<real_t>("setup.temperature") }
, Bmag { p.template get<real_t>("setup.Bmag", ZERO) }
, Btheta { p.template get<real_t>("setup.Btheta", ZERO) }
, Bphi { p.template get<real_t>("setup.Bphi", ZERO) }
, init_flds { Bmag, Btheta, Bphi, drift_ux } {}

inline PGen() {}

auto FixField(const em& comp) const -> real_t {
if (comp == em::ex2) {
return init_flds.ex2({ ZERO });
} else if (comp == em::ex3) {
return init_flds.ex3({ ZERO });
} else if (comp == em::bx1) {
return init_flds.bx1({ ZERO });
} else {
raise::Error("Other components should not be requested when BC is in X",
HERE);
return ZERO;
}
}

inline void InitPrtls(Domain<S, M>& local_domain) {
const auto energy_dist = arch::Maxwellian<S, M>(local_domain.mesh.metric,
local_domain.random_pool,
temperature,
-drift_ux,
in::x1);
const auto injector = arch::UniformInjector<S, M, arch::Maxwellian>(

const auto injector = arch::UniformInjector<S, M, arch::Maxwellian>(
energy_dist,
{ 1, 2 });
arch::InjectUniform<S, M, arch::UniformInjector<S, M, arch::Maxwellian>>(
Expand Down
4 changes: 2 additions & 2 deletions setups/srpic/shock/shock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import matplotlib as mpl

data = nt2r.Data("shock-03.h5")
data = nt2r.Data("shock.h5")


def frame(ti, f):
Expand Down Expand Up @@ -55,7 +55,7 @@ def frame(ti, f):
axs = [fig.add_subplot(gs[i]) for i in range(len(quantities))]

for ax, q in zip(axs, quantities):
q["compute"](f).coarsen(x=2, y=2).mean().plot(
q["compute"](f.isel(t=ti)).plot(
ax=ax,
cmap=q["cmap"],
norm=q["norm"],
Expand Down
5 changes: 4 additions & 1 deletion setups/srpic/shock/shock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
metric = "minkowski"

[grid.boundaries]
fields = [["CONDUCTOR", "ABSORB"], ["PERIODIC"]]
fields = [["FIXED", "ABSORB"], ["PERIODIC"]]
particles = [["REFLECT", "ABSORB"], ["PERIODIC"]]

[scales]
Expand Down Expand Up @@ -42,6 +42,9 @@
[setup]
drift_ux = 0.1
temperature = 1e-3
Bmag = 1.0
Btheta = 0.0
Bphi = 0.0

[output]
interval_time = 0.1
Expand Down
Loading