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

Add CONDUCTOR boundary #84

Open
wants to merge 76 commits into
base: 1.2.0rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3e1848a
prep for conductor boundaries
LudwigBoess Feb 21, 2025
bacbe24
first stubborn attempt at conductor boundaries (broken)
LudwigBoess Feb 21, 2025
2081a39
first attempt at ConductorBoundaries_kernel
LudwigBoess Feb 21, 2025
b7a863c
bugfix
LudwigBoess Feb 21, 2025
f383e49
first attempt at Kokkos::parallel_for loop (broken)
LudwigBoess Feb 21, 2025
7666918
Ongoing.
jmahlmann Feb 22, 2025
af06544
Ongoing.
jmahlmann Feb 22, 2025
0d3cc1c
Ongoing.
jmahlmann Feb 22, 2025
4a57c38
Ongoing.
jmahlmann Feb 22, 2025
ff5a3ee
Ongoing.
jmahlmann Feb 22, 2025
d6b2b1c
Ongoing.
jmahlmann Feb 22, 2025
f0ed6c7
Ongoing.
jmahlmann Feb 22, 2025
79d3237
Ongoing.
jmahlmann Feb 22, 2025
17b469b
Ongoing.
jmahlmann Feb 22, 2025
e234173
Ongoing.
jmahlmann Feb 22, 2025
de510ea
Ongoing.
jmahlmann Feb 22, 2025
0524d78
Ongoing.
jmahlmann Feb 23, 2025
9d78b9e
Ongoing.
jmahlmann Feb 23, 2025
cec22b0
Ongoing.
jmahlmann Feb 23, 2025
b3754e2
Ongoing.
jmahlmann Feb 23, 2025
83dba37
Ongoing.
jmahlmann Feb 23, 2025
a7ef051
Ongoing.
jmahlmann Feb 23, 2025
d219fc4
Ongoing.
jmahlmann Feb 23, 2025
044ccea
Ongoing.
jmahlmann Feb 23, 2025
2af41d8
Ongoing.
jmahlmann Feb 23, 2025
056c629
Ongoing.
jmahlmann Feb 23, 2025
7d9a1a3
Ongoing.
jmahlmann Feb 23, 2025
d8abf1b
Ongoing.
jmahlmann Feb 26, 2025
a17db62
Ongoing.
jmahlmann Feb 26, 2025
1d109a0
Ongoing.
jmahlmann Feb 27, 2025
bee7530
Ongoing.
jmahlmann Feb 27, 2025
2a269fd
Ongoing.
jmahlmann Feb 27, 2025
49820ff
Ongoing.
jmahlmann Feb 27, 2025
d2167da
first attempt at single particle injection
LudwigBoess Feb 28, 2025
fc3e647
Ongoing.
jmahlmann Feb 28, 2025
83c144f
Ongoing.
jmahlmann Feb 28, 2025
7c7c3f9
Ongoing.
jmahlmann Feb 28, 2025
939369e
Ongoing.
jmahlmann Feb 28, 2025
fa5a38f
Ongoing.
jmahlmann Feb 28, 2025
eeca02d
Ongoing.
jmahlmann Feb 28, 2025
c18840c
Ongoing.
jmahlmann Feb 28, 2025
9085afd
Ongoing.
jmahlmann Feb 28, 2025
87b37be
Ongoing.
jmahlmann Feb 28, 2025
5712e3b
Ongoing.
jmahlmann Feb 28, 2025
af258c6
Ongoing.
jmahlmann Feb 28, 2025
86f0597
Ongoing.
jmahlmann Feb 28, 2025
d0ce7c8
cleanup of conductor BCs
LudwigBoess Mar 3, 2025
0fd05b9
add 3D case and set correct boundary cells to zero
LudwigBoess Mar 3, 2025
425abe5
Ongoing
Mar 4, 2025
cfee51e
Ongoing
Mar 4, 2025
7d317e6
Ongoing
Mar 4, 2025
21d9937
Ongoing
Mar 4, 2025
bd723f3
minor reformatting of conductor BC
haykh Mar 7, 2025
28a02f1
filters adapted for conducting BCs
haykh Mar 7, 2025
b800b61
revert to old pgen for testing
LudwigBoess Mar 8, 2025
2b269f3
enforce B0/E0 at boundary
LudwigBoess Mar 8, 2025
9b23732
filter test fixed
haykh Mar 8, 2025
179fafe
removed extra kokkos flags
haykh Mar 9, 2025
db1a393
Merge branch 'dev/conductor_boundary' of github.com:entity-toolkit/en…
haykh Mar 9, 2025
b6fe114
revert to zero at boundary
LudwigBoess Mar 10, 2025
777d1fb
cleanup of pgen
LudwigBoess Mar 13, 2025
ef5c854
update example parameter file
LudwigBoess Mar 13, 2025
84e047c
revert to cleaner injector for shocktest
LudwigBoess Mar 19, 2025
69d4a0d
implemented new `arch::Piston` spatial distribution to set up shock p…
LudwigBoess Mar 20, 2025
e4d5979
fix inconsistency in return type
LudwigBoess Mar 20, 2025
cbc2021
Added `MovingInjector` (wip)
LudwigBoess Mar 21, 2025
70ea9af
Added `CustomPostStep` for shock pgen to continually inject particles…
LudwigBoess Mar 21, 2025
9727507
bugfix
LudwigBoess Mar 22, 2025
d7d12a3
added start time of injection and explicitly enforce injection region…
LudwigBoess Mar 22, 2025
6cf0dc8
small bugfix
LudwigBoess Mar 22, 2025
22a0479
shock pgen changed
haykh Mar 24, 2025
13da0dd
reduce resolution for faster test
LudwigBoess Mar 24, 2025
54f083f
cleanup and bugfix
LudwigBoess Mar 24, 2025
9f45d04
removed unnecessary parameter
LudwigBoess Mar 24, 2025
aa8b8e7
applied formatting to `MovingInjector`
LudwigBoess Mar 24, 2025
d0fb4ca
first attempt at moving-window injection
LudwigBoess Mar 31, 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
35 changes: 0 additions & 35 deletions cmake/kokkosConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,6 @@ set(Kokkos_ENABLE_OPENMP
${default_KOKKOS_ENABLE_OPENMP}
CACHE BOOL "Enable OpenMP")

# set memory space
if(${Kokkos_ENABLE_CUDA})
add_compile_definitions(CUDA_ENABLED)
set(ACC_MEM_SPACE Kokkos::CudaSpace)
elseif(${Kokkos_ENABLE_HIP})
add_compile_definitions(HIP_ENABLED)
set(ACC_MEM_SPACE Kokkos::HIPSpace)
else()
set(ACC_MEM_SPACE Kokkos::HostSpace)
endif()

set(HOST_MEM_SPACE Kokkos::HostSpace)

# set execution space
if(${Kokkos_ENABLE_CUDA})
set(ACC_EXE_SPACE Kokkos::Cuda)
elseif(${Kokkos_ENABLE_HIP})
set(ACC_EXE_SPACE Kokkos::HIP)
elseif(${Kokkos_ENABLE_OPENMP})
set(ACC_EXE_SPACE Kokkos::OpenMP)
else()
set(ACC_EXE_SPACE Kokkos::Serial)
endif()

if(${Kokkos_ENABLE_OPENMP})
set(HOST_EXE_SPACE Kokkos::OpenMP)
else()
set(HOST_EXE_SPACE Kokkos::Serial)
endif()

add_compile_options("-D AccelExeSpace=${ACC_EXE_SPACE}")
add_compile_options("-D AccelMemSpace=${ACC_MEM_SPACE}")
add_compile_options("-D HostExeSpace=${HOST_EXE_SPACE}")
add_compile_options("-D HostMemSpace=${HOST_MEM_SPACE}")

if(${BUILD_TESTING} STREQUAL "OFF")
set(Kokkos_ENABLE_TESTS
OFF
Expand Down
2 changes: 1 addition & 1 deletion input.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
# Boundary conditions for fields:
# @required
# @type: 1/2/3-size array of string tuples, each of size 1 or 2
# @valid: "PERIODIC", "MATCH", "FIXED", "ATMOSPHERE", "CUSTOM", "HORIZON"
# @valid: "PERIODIC", "MATCH", "FIXED", "ATMOSPHERE", "CUSTOM", "HORIZON", "CONDUCTOR"
# @example: [["CUSTOM", "MATCH"]] (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", "MATCH"]]
Expand Down
10 changes: 5 additions & 5 deletions legacy/tests/kernels-sr.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "wrapper.h"

#include <Kokkos_Core.hpp>

#include <iostream>
#include <stdexcept>

#include "wrapper.h"

#include METRIC_HEADER
#include PGEN_HEADER

#include "particle_macros.h"

#include "kernels/particle_pusher_sr.hpp"

#include "particle_macros.h"

template <typename T>
void put_value(ntt::array_t<T*>& arr, T value, int i) {
auto arr_h = Kokkos::create_mirror_view(arr);
Expand Down Expand Up @@ -221,4 +221,4 @@ auto main(int argc, char* argv[]) -> int {
ntt::GlobalFinalize();

return 0;
}
}
247 changes: 230 additions & 17 deletions setups/srpic/shock/pgen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ namespace user {
using arch::ProblemGenerator<S, M>::C;
using arch::ProblemGenerator<S, M>::params;

const real_t drift_ux, temperature;

const real_t Btheta, Bphi, Bmag;
// gas properties
const real_t drift_ux, temperature, filling_fraction;
// injector properties
const real_t injector_velocity, injection_start, dt;
const int injection_frequency;
// magnetic field properties
real_t Btheta, Bphi, Bmag;
InitFields<D> init_flds;

inline PGen(const SimulationParams& p, const Metadomain<S, M>& m)
Expand All @@ -91,40 +95,249 @@ namespace user {
, 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 } {}
, init_flds { Bmag, Btheta, Bphi, drift_ux }
, filling_fraction { p.template get<real_t>("setup.filling_fraction", 1.0) }
, injector_velocity { p.template get<real_t>("setup.injector_velocity", 1.0) }
, injection_start { p.template get<real_t>("setup.injection_start", 0.0) }
, injection_frequency { p.template get<int>("setup.injection_frequency", 100) }
, dt { p.template get<real_t>("algorithms.timestep.dt") } {}

inline PGen() {}

auto FixFieldsConst(const bc_in&, const em& comp) const
-> std::pair<real_t, bool> {
if (comp == em::ex2) {
return { init_flds.ex2({ ZERO }), true };
auto MatchFields(real_t time) const -> InitFields<D> {
return init_flds;
}

auto ResetFields(const em& comp) const -> real_t {
if (comp == em::ex1) {
return init_flds.ex1({ ZERO });
} else if (comp == em::ex2) {
return init_flds.ex2({ ZERO });
} else if (comp == em::ex3) {
return { init_flds.ex3({ ZERO }), true };
return init_flds.ex3({ ZERO });
} else if (comp == em::bx1) {
return init_flds.bx1({ ZERO });
} else if (comp == em::bx2) {
return init_flds.bx2({ ZERO });
} else if (comp == em::bx3) {
return init_flds.bx3({ ZERO });
} else {
return { ZERO, false };
raise::Error("Invalid component", HERE);
return ZERO;
}
}

auto MatchFields(real_t time) const -> InitFields<D> {
return init_flds;
}

inline void InitPrtls(Domain<S, M>& local_domain) {

// minimum and maximum position of particles
real_t xg_min = local_domain.mesh.extent(in::x1).first;
real_t xg_max = local_domain.mesh.extent(in::x1).first +
filling_fraction * (local_domain.mesh.extent(in::x1).second -
local_domain.mesh.extent(in::x1).first);

// define box to inject into
boundaries_t<real_t> box;
// loop over all dimensions
for (unsigned short d { 0 }; d < static_cast<unsigned short>(M::Dim); ++d) {
// compute the range for the x-direction
if (d == static_cast<unsigned short>(in::x1)) {
box.push_back({ xg_min, xg_max });
} else {
// inject into full range in other directions
box.push_back(Range::All);
}
}

// spatial distribution of the particles
// -> hack to use the uniform distribution in NonUniformInjector
const auto spatial_dist = arch::Piston<S, M>(local_domain.mesh.metric,
xg_min,
xg_max,
in::x1);

// energy distribution of the particles
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::NonUniformInjector<S, M, arch::Maxwellian, arch::Piston>(
energy_dist,
spatial_dist,
{ 1, 2 });
arch::InjectUniform<S, M, arch::UniformInjector<S, M, arch::Maxwellian>>(

arch::InjectNonUniform<S, M, arch::NonUniformInjector<S, M, arch::Maxwellian, arch::Piston>>(
params,
local_domain,
injector,
1.0);
1.0, // target density
false, // no weights
box);
}

void CustomPostStep(std::size_t step, long double time, Domain<S, M>& domain) {

// check if the injector should be active
if (step % injection_frequency != 0) {
return;
}

// initial position of injector
const auto x_init = domain.mesh.extent(in::x1).first +
filling_fraction * (domain.mesh.extent(in::x1).second -
domain.mesh.extent(in::x1).first);

// check if injector is supposed to start moving already
const auto dt_inj = time - injection_start > ZERO ?
time - injection_start : ZERO;

// define box to inject into
boundaries_t<real_t> box;

// loop over all dimension
for (auto d = 0u; d < M::Dim; ++d) {
if (d == 0) {
box.push_back({ x_init + injector_velocity * dt_inj -
drift_ux / math::sqrt(1 + SQR(drift_ux)) * dt -
1.5 * injection_frequency * dt,
x_init + injector_velocity * (dt_inj + dt) });
} else {
box.push_back(Range::All);
}
}

// define indice range to reset fields
boundaries_t<bool> incl_ghosts;
for (auto d = 0; d < M::Dim; ++d) {
incl_ghosts.push_back({ true, true });
}
const auto extent = domain.mesh.ExtentToRange(box, incl_ghosts);
tuple_t<std::size_t, M::Dim> x_min { 0 }, x_max { 0 };
for (auto d = 0; d < M::Dim; ++d) {
x_min[d] = extent[d].first;
x_max[d] = extent[d].second;
}

// reset fields
std::vector<unsigned short> comps = { em::ex1, em::ex2, em::ex3,
em::bx1, em::bx2, em::bx3 };

// loop over all components
for (const auto& comp : comps) {
auto value = ResetFields((em)comp);

if constexpr (M::Dim == Dim::_1D) {
Kokkos::deep_copy(Kokkos::subview(domain.fields.em,
std::make_pair(x_min[0], x_max[0]),
comp),
value);
} else if constexpr (M::Dim == Dim::_2D) {
Kokkos::deep_copy(Kokkos::subview(domain.fields.em,
std::make_pair(x_min[0], x_max[0]),
std::make_pair(x_min[1], x_max[1]),
comp),
value);
} else if constexpr (M::Dim == Dim::_3D) {
Kokkos::deep_copy(Kokkos::subview(domain.fields.em,
std::make_pair(x_min[0], x_max[0]),
std::make_pair(x_min[1], x_max[1]),
std::make_pair(x_min[2], x_max[2]),
comp),
value);
} else {
raise::Error("Invalid dimension", HERE);
}
}

/*
tag particles inside the injection zone as dead
*/

// loop over particle species
for (std::size_t s { 0 }; s < 2; ++s) {

// get particle properties
auto& species = domain.species[s];
auto i1 = species.i1;
auto tag = species.tag;


// tag all particles with x > box[0].first as dead
Kokkos::parallel_for(
"RemoveParticles",
species.rangeActiveParticles(),
Lambda(index_t p) {
// check if the particle is already dead
if (tag(p) == ParticleTag::dead) {
return;
}
// select the x-coordinate index
auto x_i1 = i1(p);
// check if the particle is inside the box of new plasma
if (x_i1 > x_min[0]) {
tag(p) = ParticleTag::dead;
}
}
);
}

/*
Inject piston of fresh plasma
*/

// same maxwell distribution as above
const auto energy_dist = arch::Maxwellian<S, M>(domain.mesh.metric,
domain.random_pool,
temperature,
-drift_ux,
in::x1);
// spatial distribution of the particles
// -> hack to use the uniform distribution in NonUniformInjector
const auto spatial_dist = arch::Piston<S, M>(domain.mesh.metric,
box[0].first,
box[0].second,
in::x1);

// inject piston of fresh plasma
const auto injector = arch::NonUniformInjector<S, M, arch::Maxwellian, arch::Piston>(
energy_dist,
spatial_dist,
{ 1, 2 });

// inject non-uniformly within the defined box
arch::InjectNonUniform<S, M, decltype(injector)>(params,
domain,
injector,
ONE,
false,
box);

/*
I thought this option would be better, but I can't get it to work
*/

// const auto spatial_dist = arch::Replenish<S, M,
// decltype(TargetDensityProfile)>(domain.mesh.metric,
// domain.fields.bckp,
// box,
// TargetDensity,
// 1.0);

// const auto injector = arch::NonUniformInjector<S, M, arch::Maxwellian, arch::Replenish>(
// energy_dist,
// spatial_dist,
// {1, 2});

// const auto injector = arch::MovingInjector<S, M, in::x1> {
// domain.mesh.metric,
// domain.fields.bckp,
// energy_dist,
// box[0].first,
// box[0].second,
// 1.0,
// { 1, 2 }
// };
}
};

Expand Down
Loading