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 external particle fields ohms law hybrid #5275

Open
wants to merge 87 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
8eefb02
Adding RZ implementation of external particle field for Ohms Law Hybr…
clarkse Aug 28, 2024
786a5c9
Adding Cartesian implementation.
clarkse Aug 28, 2024
cb99d2a
Adding 3D implementation of analytical particle fields.
clarkse Aug 29, 2024
d866bda
Fixing up external fields for ohms law hybrid solver in RZ and 3D.
clarkse Sep 5, 2024
f82bb97
Fixing bug that leads to garbage E fields.
clarkse Sep 12, 2024
98fd8af
Fixed issue with external parser in HybridPIC model object
clarkse Sep 15, 2024
5f75428
Rebasing to latest development branch
clarkse Sep 16, 2024
36caed1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2024
f0ad73a
Removing electron pressure calculation. Fixing merge error.
clarkse Sep 18, 2024
c9dea5d
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Sep 18, 2024
1482f8b
Adding grid based split field advance for Hybrid solver to improve pe…
clarkse Sep 24, 2024
ba9678a
Merging new multifab register changes.
clarkse Sep 24, 2024
344a3dd
Merged and refactored external fields to use new MultiFab register in…
clarkse Sep 25, 2024
18ae509
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2024
71116c7
Fixing hybrid multifab wrapper sin PICMI.
clarkse Sep 25, 2024
d8465b1
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Sep 25, 2024
bc127a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2024
8d39c52
Fixing some BC issues.
clarkse Sep 25, 2024
368e8a9
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Sep 25, 2024
a546023
Fixed segfault when accessing edge_lengths MF during loading of analy…
clarkse Sep 26, 2024
ae4fc4e
Merge branch 'development' into add_external_particle_fields_ohms_law…
clarkse Sep 26, 2024
e31b639
Adding checks to make sure Hybrid external field loading is skipped w…
clarkse Sep 26, 2024
2ca7190
Adding appropriate flags to mask embedded boundary properly during ex…
clarkse Sep 30, 2024
f1bcd35
Updating so time varying vector potential A is initialized, then B is…
clarkse Oct 22, 2024
7e4f6d6
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Oct 22, 2024
5158bbd
Merged with development
clarkse Oct 22, 2024
15caad1
Ironing out a few merge issues.
clarkse Oct 22, 2024
821250e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 22, 2024
ce99096
Fixing issues with initialization and boundary conditions.
clarkse Oct 23, 2024
5f0ceab
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Oct 23, 2024
c810af2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
b85f868
Refactored EB logic in Hybrid solver to reduce code redundancy.
clarkse Oct 25, 2024
c4b9417
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2024
1cafe4d
Fixing some CI issues.
clarkse Oct 29, 2024
c73d22c
Adding flags for sometimes unused variables in EB covering calcs.
clarkse Oct 29, 2024
e2730bc
More CI cleanup.
clarkse Oct 30, 2024
aa716ae
Clang-tidy update.
clarkse Oct 30, 2024
eed83ea
Adding nodiscard to EB::Covered::isCovered routine.
clarkse Oct 31, 2024
6bfe0f9
Changing order of attribute list for HIP
clarkse Oct 31, 2024
b724995
Adding ability to add lists of external fields with different timings.
clarkse Nov 6, 2024
859158e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2024
db817c1
Updating boundary covering helper to work when compiling with EB, but…
clarkse Nov 7, 2024
bed12a8
Manually resolving merge
clarkse Nov 7, 2024
5a1e8cc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
6659cdc
Update Python/pywarpx/picmi.py
clarkse Nov 7, 2024
2c0b35f
Update Python/pywarpx/picmi.py
clarkse Nov 7, 2024
e82cccc
Update Source/FieldSolver/FiniteDifferenceSolver/ComputeCurlA.cpp
clarkse Nov 7, 2024
e1180fd
Update Source/FieldSolver/FiniteDifferenceSolver/ComputeCurlA.cpp
clarkse Nov 7, 2024
57df0b2
Update Source/FieldSolver/FiniteDifferenceSolver/ComputeCurlA.cpp
clarkse Nov 7, 2024
dd18deb
Update Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp
clarkse Nov 7, 2024
13ecbce
Update Source/FieldSolver/FiniteDifferenceSolver/HybridPICSolveE.cpp
clarkse Nov 7, 2024
913760c
Redisabling filtering for RZ. Commenting out E field boundary.
clarkse Nov 7, 2024
8d2dc92
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Nov 7, 2024
5083cad
Fixing some bugs in RZ mode.
clarkse Nov 20, 2024
0ee42fc
Adding Generic Multifab wrappers to access runtime allocated multifab…
clarkse Dec 7, 2024
c9e9bd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 7, 2024
d86c411
Adding Holmstrom vacuum handing and updating external fields to inter…
clarkse Jan 30, 2025
315d053
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Jan 30, 2025
0f11b42
Changing evaluation of current to break dependence on standard resist…
clarkse Feb 4, 2025
e55ffdf
Changing Ez calculation for hyper resistivity to allow for z complone…
clarkse Feb 4, 2025
9ba0ac2
Merging development with EB changes.
clarkse Feb 4, 2025
84056ab
Merging latest development branch.
clarkse Feb 5, 2025
8a09559
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2025
b41e717
Adding benchmarks and cleaning up CI test a bit.
clarkse Feb 6, 2025
a0da96e
Fixing some issues with CI tests.
clarkse Feb 6, 2025
d151e96
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2025
ea55f19
More CI changes.
clarkse Feb 6, 2025
9cb9b0b
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Feb 6, 2025
404cdc8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2025
aff8938
Changing description in CI test input file for 3d case.
clarkse Feb 6, 2025
41cf2b1
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Feb 6, 2025
ef83768
Adding usage documentation to Parameters.rst
clarkse Feb 6, 2025
0aa4144
Adding usage documentation, holmstrom vacuum flag, and updated CI tes…
clarkse Feb 6, 2025
8dd2cfb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2025
3ae78aa
Adjusting CI tests and application of external fields in vacuum region.
clarkse Feb 7, 2025
925e065
Merge branch 'add_external_particle_fields_ohms_law_hybrid' of github…
clarkse Feb 7, 2025
e4b285d
Adding check around lookup of external fields to not lookup from regi…
clarkse Feb 7, 2025
066f72a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2025
f49494c
Removing typo.
clarkse Feb 7, 2025
dd6f5d4
Fixed bug in EB maksing for field loading for external fields.
clarkse Feb 7, 2025
4904329
Adding directory prefix for file writing to CI tests.
clarkse Feb 7, 2025
c3f40cf
Fixing typo in CI tests.
clarkse Feb 7, 2025
2081e33
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2025
863b645
Adjusting CI invocation script.
clarkse Feb 7, 2025
55eb2a3
Resetting benchmarks and turning off holmstrom vacuum flag in test. D…
clarkse Feb 7, 2025
cd68984
Updating benchmarks and fixinf clang-tiday issue.
clarkse Feb 10, 2025
aef570f
Cleaning up to pass clang-tidy.
clarkse Feb 11, 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 Python/pywarpx/HybridPICModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .Bucket import Bucket

hybridpicmodel = Bucket("hybrid_pic_model")
external_vector_potential = Bucket("external_vector_potential")
3 changes: 2 additions & 1 deletion Python/pywarpx/WarpX.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .Diagnostics import diagnostics, reduced_diagnostics
from .EB2 import eb2
from .Geometry import geometry
from .HybridPICModel import hybridpicmodel
from .HybridPICModel import external_vector_potential, hybridpicmodel
from .Interpolation import interpolation
from .Lasers import lasers, lasers_list
from .Particles import particles, particles_list
Expand All @@ -46,6 +46,7 @@ def create_argv_list(self, **kw):
argv += amrex.attrlist()
argv += geometry.attrlist()
argv += hybridpicmodel.attrlist()
argv += external_vector_potential.attrlist()
argv += boundary.attrlist()
argv += algo.attrlist()
argv += interpolation.attrlist()
Expand Down
2 changes: 1 addition & 1 deletion Python/pywarpx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .Diagnostics import diagnostics, reduced_diagnostics # noqa
from .EB2 import eb2 # noqa
from .Geometry import geometry # noqa
from .HybridPICModel import hybridpicmodel # noqa
from .HybridPICModel import hybridpicmodel, external_vector_potential # noqa
from .Interpolation import interpolation # noqa
from .Lasers import lasers # noqa
from .LoadThirdParty import load_cupy # noqa
Expand Down
81 changes: 81 additions & 0 deletions Python/pywarpx/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,87 @@ def BzFPExternalWrapper(level=0, include_ghosts=False):
)


def AxHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_A_fp_external",
idir=0,
level=level,
include_ghosts=include_ghosts,
)


def AyHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_A_fp_external",
idir=1,
level=level,
include_ghosts=include_ghosts,
)


def AzHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_A_fp_external",
idir=2,
level=level,
include_ghosts=include_ghosts,
)


def ExHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_E_fp_external",
idir=0,
level=level,
include_ghosts=include_ghosts,
)


def EyHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_E_fp_external",
idir=1,
level=level,
include_ghosts=include_ghosts,
)


def EzHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_E_fp_external",
idir=2,
level=level,
include_ghosts=include_ghosts,
)


def BxHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_B_fp_external",
idir=0,
level=level,
include_ghosts=include_ghosts,
)


def ByHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_B_fp_external",
idir=1,
level=level,
include_ghosts=include_ghosts,
)


def BzHybridExternalWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="hybrid_B_fp_external",
idir=2,
level=level,
include_ghosts=include_ghosts,
)


def JxFPWrapper(level=0, include_ghosts=False):
return _MultiFABWrapper(
mf_name="current_fp", idir=0, level=level, include_ghosts=include_ghosts
Expand Down
55 changes: 55 additions & 0 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,9 @@ class HybridPICSolver(picmistandard.base._ClassWithInit):

Jx/y/z_external_function: str
Function of space and time specifying external (non-plasma) currents.

Ex/y/z_external_function: str
clarkse marked this conversation as resolved.
Show resolved Hide resolved
Function of space and time specifying external (non-plasma) E-fields.
clarkse marked this conversation as resolved.
Show resolved Hide resolved
"""

def __init__(
Expand All @@ -1797,6 +1800,7 @@ def __init__(
Jx_external_function=None,
Jy_external_function=None,
Jz_external_function=None,
A_external=None,
**kw,
):
self.grid = grid
Expand All @@ -1815,6 +1819,25 @@ def __init__(
self.Jy_external_function = Jy_external_function
self.Jz_external_function = Jz_external_function

self.add_external_fields = None

# It is expected that a nested dicitonary will be passed
# into picmi for each field that has different timings
# e.g.
# A_external = {
# '<field_name1>': {
# 'Ax_external_function': ...,
# 'Ax_external_function': ...,
# 'Ax_external_function': ...,
# 'A_time_external_function': ...
# },
# '<field_name2>: {...}'
# }
self.A_external = A_external

if A_external is not None:
self.add_external_fields = True

# Handle keyword arguments used in expressions
self.user_defined_kw = {}
for k in list(kw.keys()):
Expand Down Expand Up @@ -1863,6 +1886,38 @@ def solver_initialize_inputs(self):
self.Jz_external_function, self.mangle_dict
),
)
pywarpx.hybridpicmodel.add_external_fields = self.add_external_fields
pywarpx.external_vector_potential.__setattr__(
"fields",
pywarpx.my_constants.mangle_expression(
list(self.A_external.keys()), self.mangle_dict
),
)
for field_name, field_dict in self.A_external.items():
pywarpx.external_vector_potential.__setattr__(
f"{field_name}.Ax_external_grid_function(x,y,z)",
pywarpx.my_constants.mangle_expression(
field_dict["Ax_external_function"], self.mangle_dict
),
)
pywarpx.external_vector_potential.__setattr__(
f"{field_name}.Ay_external_grid_function(x,y,z)",
pywarpx.my_constants.mangle_expression(
field_dict["Ay_external_function"], self.mangle_dict
),
)
pywarpx.external_vector_potential.__setattr__(
f"{field_name}.Az_external_grid_function(x,y,z)",
pywarpx.my_constants.mangle_expression(
field_dict["Az_external_function"], self.mangle_dict
),
)
pywarpx.external_vector_potential.__setattr__(
f"{field_name}.A_time_external_function(t)",
pywarpx.my_constants.mangle_expression(
field_dict["A_time_external_function"], self.mangle_dict
),
)


class ElectrostaticSolver(picmistandard.PICMI_ElectrostaticSolver):
Expand Down
1 change: 1 addition & 0 deletions Source/EmbeddedBoundary/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ foreach(D IN LISTS WarpX_DIMS)
WarpXFaceExtensions.cpp
WarpXFaceInfoBox.H
Enabled.cpp
Covered.cpp
)
endforeach()
116 changes: 116 additions & 0 deletions Source/EmbeddedBoundary/Covered.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* Copyright 2024 S. Eric Clark (Helion Energy)
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#ifndef WARPX_EB_COVERED_H_
#define WARPX_EB_COVERED_H_


#include "EmbeddedBoundary/Enabled.H"
#include "Fields.H"

# include <AMReX.H>
# include <AMReX_Array.H>
# include <AMReX_Array4.H>
# include <AMReX_Config.H>
# include <AMReX_GpuControl.H>
# include <AMReX_GpuDevice.H>
# include <AMReX_GpuQualifiers.H>
# include <AMReX_MFIter.H>
# include <AMReX_MultiFab.H>
# include <AMReX_REAL.H>
# include <AMReX_SPACE.H>

namespace EB {

AMREX_ENUM(CoverTopology,
none,
face,
edge
);

class Covered
{
public:
amrex::Array4<amrex::Real> lx, ly, lz, Sx, Sy, Sz;

#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
amrex::Dim3 lx_lo, lx_hi, lz_lo, lz_hi;
#endif

Covered (amrex::MFIter &mfi, int lev);

// Can have topology of f or e for 'face' or 'edge'
[[nodiscard]] AMREX_GPU_HOST_DEVICE
bool isCovered (
[[maybe_unused]] const int idir,
[[maybe_unused]] const CoverTopology topology,
[[maybe_unused]] const int i,
[[maybe_unused]] const int j,
[[maybe_unused]] const int k) const noexcept
{
#ifdef AMREX_USE_EB
bool is_covered = false;

switch (idir)
{
case 0:
#ifdef WARPX_DIM_3D
if((topology==CoverTopology::edge and lx(i, j, k)<=0) or (topology==CoverTopology::face and Sx(i, j, k)<=0))
{
is_covered = true;
}
#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
//In XZ and RZ Ex is associated with a x-edge, while Bx is associated with a z-edge
if((topology==CoverTopology::edge and lx(i, j, k)<=0) or (topology==CoverTopology::face and lz(i, j, k)<=0))
{
is_covered = true;
}
#endif
break;

case 1:
#ifdef WARPX_DIM_3D
if((topology==CoverTopology::edge and ly(i, j, k)<=0) or (topology==CoverTopology::face and Sy(i, j, k)<=0))
{
is_covered = true;
}
#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
//In XZ and RZ Ey is associated with a mesh node, so we need to check if the mesh node is covered
if( (topology==CoverTopology::edge and (lx(std::min(i , lx_hi.x), std::min(j , lx_hi.y), k)<=0
|| lx(std::max(i-1, lx_lo.x), std::min(j , lx_hi.y), k)<=0
|| lz(std::min(i , lz_hi.x), std::min(j , lz_hi.y), k)<=0
|| lz(std::min(i , lz_hi.x), std::max(j-1, lz_lo.y), k)<=0)) or
(topology==CoverTopology::face and Sy(i,j,k)<=0))
{
is_covered = true;
}
#endif
break;

case 2:
#ifdef WARPX_DIM_3D
if((topology==CoverTopology::edge and lz(i, j, k)<=0) or (topology==CoverTopology::face and Sz(i, j, k)<=0))
{
is_covered = true;
}
#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
//In XZ and RZ Ez is associated with a z-edge, while Bz is associated with a x-edge
if((topology==CoverTopology::edge and lz(i, j, k)<=0) or (topology==CoverTopology::face and lx(i, j, k)<=0))
{
is_covered = true;
}
#endif
break;
}
return is_covered;
#else
return false;
#endif //AMREX_USE_EB
}
};

} // namespace EB
#endif
51 changes: 51 additions & 0 deletions Source/EmbeddedBoundary/Covered.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright 2024 S. Eric Clark
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "WarpX.H"

#include "EmbeddedBoundary/Covered.H"
#include "EmbeddedBoundary/Enabled.H"
#include "Fields.H"

# include <AMReX.H>
# include <AMReX_Array.H>
# include <AMReX_Array4.H>
# include <AMReX_Loop.H>
# include <AMReX_MFIter.H>
# include <AMReX_MultiFab.H>
# include <AMReX_REAL.H>
# include <AMReX_SPACE.H>

using namespace amrex;
using namespace warpx::fields;

namespace EB {

// Default Constructor
Covered::Covered (amrex::MFIter &mfi, int lev)
{
if (EB::enabled()) {
auto& warpx = WarpX::GetInstance();
auto edge_lengths = warpx.m_fields.get_alldirs(FieldType::edge_lengths, lev);
auto face_areas = warpx.m_fields.get_alldirs(FieldType::face_areas, lev);

lx = edge_lengths[0]->array(mfi);
ly = edge_lengths[1]->array(mfi);
lz = edge_lengths[2]->array(mfi);
Sx = face_areas[0]->array(mfi);
Sy = face_areas[1]->array(mfi);
Sz = face_areas[2]->array(mfi);

#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
lx_lo = amrex::lbound(lx);
lx_hi = amrex::ubound(lx);
lz_lo = amrex::lbound(lz);
lz_hi = amrex::ubound(lz);
#endif
}
}

}
2 changes: 2 additions & 0 deletions Source/EmbeddedBoundary/Make.package
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
CEXE_headers += Enabled.H
CEXE_headers += Covered.H
CEXE_headers += ParticleScraper.H
CEXE_headers += ParticleBoundaryProcess.H
CEXE_headers += DistanceToEB.H
CEXE_headers += WarpXFaceInfoBox.H

CEXE_sources += Enabled.cpp
CEXE_sources += Covered.cpp
CEXE_sources += WarpXInitEB.cpp
CEXE_sources += WarpXFaceExtensions.cpp

Expand Down
1 change: 1 addition & 0 deletions Source/FieldSolver/FiniteDifferenceSolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ foreach(D IN LISTS WarpX_DIMS)
target_sources(lib_${SD}
PRIVATE
ComputeDivE.cpp
ComputeCurlA.cpp
EvolveB.cpp
EvolveBPML.cpp
EvolveE.cpp
Expand Down
Loading
Loading