Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ca4bb07
Added all changes from struphy-with-cupy
max-models Oct 31, 2025
08b903c
Graphs with profiler
max-models Nov 17, 2025
7d4643e
Color by region type
max-models Nov 17, 2025
696ac05
Merge branch 'devel' into clean-struphy-with-cupy
max-models Nov 18, 2025
af7cda6
Formatting
max-models Nov 18, 2025
8abb229
Merge branch 'devel' into clean-struphy-with-cupy
max-models Jan 6, 2026
59af968
Convert result from numpy to cupy
max-models Jan 6, 2026
921303d
Added typehints
max-models Jan 6, 2026
e6fe558
Formatting
max-models Jan 6, 2026
bc7195c
Added missing import of numpy
max-models Jan 8, 2026
752d0a0
Formatting
max-models Jan 8, 2026
7d12aa3
Import from numpy instead of cupy
max-models Jan 8, 2026
8b66de1
Merge remote-tracking branch 'origin/devel' into clean-struphy-with-cupy
Copilot May 5, 2026
917c74f
Updated cupy compatibility
max-models May 5, 2026
a7fc9bc
Merge remote-tracking branch 'origin/devel' into clean-struphy-with-cupy
Copilot Jul 3, 2026
8549b31
Merge branch 'devel' into clean-struphy-with-cupy
max-models Jul 3, 2026
59a288f
Merge branch 'devel' into clean-struphy-with-cupy
max-models Jul 22, 2026
00acf2a
Merge branch 'devel' into clean-struphy-with-cupy
max-models Jul 28, 2026
6c526e3
Updated feectools commit
max-models Jul 28, 2026
89edcb5
Updated feectool commit
max-models Jul 29, 2026
0410e41
Updated feectools commit
max-models Aug 4, 2026
fd27380
Merge branch 'devel' into clean-struphy-with-cupy
max-models Aug 4, 2026
e062600
Fix src/struphy/geometry/transform_kernels.py cunumpy import
max-models Jul 28, 2026
3b8ed93
Bumb dependencies
max-models Aug 5, 2026
6d4abd4
Force usage of numpy where needed
max-models Aug 5, 2026
4d1d72d
Hacky fix of dumping the json when cupy is used instead of numpy
max-models Aug 5, 2026
ca7ef55
Updated feectools commit
max-models Aug 5, 2026
1b9c2c4
Use numpy in kernels so we can compile
max-models Aug 5, 2026
e69d3e9
Updated feectools
max-models Aug 5, 2026
de3b93b
Merge branch 'devel' into clean-struphy-with-cupy
max-models Aug 5, 2026
af8b767
Updated feectools
max-models Aug 5, 2026
ca77ad6
Fix missing linebreak in feectools
max-models Aug 5, 2026
742fd48
Added missing linebreaks
max-models Aug 5, 2026
67dfb06
update feectools
max-models Aug 5, 2026
0363b7e
Pyccelkernel --> PyccelKernel
max-models Aug 5, 2026
e4bcbe9
Fix missing linebreak in feectools
max-models Aug 5, 2026
a8a3d9c
Formatting
max-models Aug 5, 2026
8f7e513
Fix ruff check errors
max-models Aug 5, 2026
2168ff5
Updated feectools
max-models Aug 5, 2026
df5b52e
fix bsplines tests
max-models Aug 6, 2026
76ad44e
TEMPORARY: removed plotting
max-models Aug 6, 2026
125773f
TEMPORARY: Run tests with -xvs
max-models Aug 6, 2026
f3756fb
Updated feectools
max-models Aug 6, 2026
e011f10
Updated feectools
max-models Aug 6, 2026
949c635
Merge branch 'devel' into clean-struphy-with-cupy
max-models Aug 6, 2026
8a0a702
bump feectools version
max-models Aug 6, 2026
1694a2f
Merge branch 'devel' into clean-struphy-with-cupy
max-models Aug 6, 2026
086da57
Use PyccelKernel from cunumpy
max-models Aug 6, 2026
57baea8
Fixed python float error, cunumpy is array_api_compat.numpy which is …
max-models Aug 6, 2026
16cb498
formatting
max-models Aug 6, 2026
c89d5fc
Formatting
max-models Aug 6, 2026
f7ab139
Commented out -xvs from testing
max-models Aug 7, 2026
4896871
Updated feectools to devel-tiny
max-models Aug 7, 2026
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
116 changes: 116 additions & 0 deletions params_LinearMHDDriftkineticCC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# import model, set verbosity
from struphy.models.hybrid import LinearMHDDriftkineticCC

from struphy import main
from struphy.fields_background import equils
from struphy.geometry import domains
from struphy.initial import perturbations
from struphy.io.options import BaseUnits, DerhamOptions, EnvironmentOptions, FieldsBackground, Time
from struphy.kinetic_background import maxwellians
from struphy.pic.utilities import (
BinningPlot,
BoundaryParameters,
KernelDensityPlot,
LoadingParameters,
WeightsParameters,
)
from struphy.topology import grids

# environment options
env = EnvironmentOptions()

# units
base_units = BaseUnits()

# time stepping
time_opts = Time()

# geometry
domain = domains.Cuboid()

# fluid equilibrium (can be used as part of initial conditions)
equil = equils.HomogenSlab()

# grid
grid = grids.TensorProductGrid(Nel=(16, 16, 16))

# derham options
derham_opts = DerhamOptions()

# light-weight model instance
model = LinearMHDDriftkineticCC()

# species parameters
model.mhd.set_phys_params()
model.energetic_ions.set_phys_params()

loading_params = LoadingParameters(ppc=1000)
weights_params = WeightsParameters()
boundary_params = BoundaryParameters()
model.energetic_ions.set_markers(
loading_params=loading_params,
weights_params=weights_params,
boundary_params=boundary_params,
)
model.energetic_ions.set_sorting_boxes()
model.energetic_ions.set_save_data()

# propagator options
model.propagators.push_bxe.options = model.propagators.push_bxe.Options(
b_tilde=model.em_fields.b_field,
)
model.propagators.push_parallel.options = model.propagators.push_parallel.Options(
b_tilde=model.em_fields.b_field,
)
model.propagators.shearalfen_cc5d.options = model.propagators.shearalfen_cc5d.Options(
energetic_ions=model.energetic_ions.var,
)
model.propagators.magnetosonic.options = model.propagators.magnetosonic.Options(
b_field=model.em_fields.b_field,
)
model.propagators.cc5d_density.options = model.propagators.cc5d_density.Options(
energetic_ions=model.energetic_ions.var,
b_tilde=model.em_fields.b_field,
)
model.propagators.cc5d_gradb.options = model.propagators.cc5d_gradb.Options(
b_tilde=model.em_fields.b_field,
)
model.propagators.cc5d_curlb.options = model.propagators.cc5d_curlb.Options(
b_tilde=model.em_fields.b_field,
)

# background, perturbations and initial conditions
model.mhd.velocity.add_background(FieldsBackground())
model.mhd.velocity.add_perturbation(perturbations.TorusModesCos(given_in_basis="v", comp=0))
model.mhd.velocity.add_perturbation(perturbations.TorusModesCos(given_in_basis="v", comp=1))
model.mhd.velocity.add_perturbation(perturbations.TorusModesCos(given_in_basis="v", comp=2))
maxwellian_1 = maxwellians.GyroMaxwellian2D(n=(1.0, None), equil=equil)
maxwellian_2 = maxwellians.GyroMaxwellian2D(n=(0.1, None), equil=equil)
background = maxwellian_1 + maxwellian_2
model.energetic_ions.var.add_background(background)

# if .add_initial_condition is not called, the background is the kinetic initial condition
perturbation = perturbations.TorusModesCos()
maxwellian_1pt = maxwellians.GyroMaxwellian2D(n=(1.0, perturbation), equil=equil)
init = maxwellian_1pt + maxwellian_2
model.energetic_ions.var.add_initial_condition(init)

# optional: exclude variables from saving
# model.energetic_ions.var.save_data = False

if __name__ == "__main__":
# start run
verbose = True

main.run(
model,
params_path=__file__,
env=env,
base_units=base_units,
time_opts=time_opts,
domain=domain,
equil=equil,
grid=grid,
derham_opts=derham_opts,
verbose=verbose,
)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ classifiers = [
]
dependencies = [
"numpy<=2.5.0",
"cunumpy<=0.1.1",
"cunumpy>=0.1.4, <=0.1.5",
"pyccel>=2.2.0, <=2.2.3",
"feectools<=0.1.3",
"feectools<=0.1.8",
"scipy<=1.18.0",
"h5py<=3.16.0",
"matplotlib<=3.11.0",
Expand Down
4 changes: 2 additions & 2 deletions src/struphy/bsplines/bsplines.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ def make_knots(breaks, degree, periodic):

if periodic:
period = breaks[-1] - breaks[0]
T[0:p] = [xi - period for xi in breaks[-p - 1 : -1]]
T[-p:] = [xi + period for xi in breaks[1 : p + 1]]
T[0:p] = xp.asarray([xi - period for xi in breaks[-p - 1 : -1]])
T[-p:] = xp.asarray([xi + period for xi in breaks[1 : p + 1]])
else:
T[0:p] = breaks[0]
T[-p:] = breaks[-1]
Expand Down
4 changes: 1 addition & 3 deletions src/struphy/console/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ def get_python_files(input_type, path=None):

# python_files = [f for f in files if f.endswith(".py") and os.path.isfile(f)]
python_files = [
os.path.join(repopath, f)
for f in files
if (f.endswith(".py") or f.endswith(".ipynb")) and os.path.isfile(os.path.join(repopath, f))
os.path.join(repopath, f) for f in files if f.endswith(".py") and os.path.isfile(os.path.join(repopath, f))
]

if not python_files:
Expand Down
2 changes: 1 addition & 1 deletion src/struphy/console/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def struphy_test(
cmd = [
"pytest",
"--testmon",
"-xvs",
] + list_of_tests

if with_desc:
Expand Down Expand Up @@ -156,7 +157,6 @@ def struphy_test(
"pytest",
"-m",
"single",
"-xvs",
# "--with-mpi",
"--model-name",
group,
Expand Down
25 changes: 12 additions & 13 deletions src/struphy/feec/basis_projection_ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging

import cunumpy as xp
import numpy as np
from cunumpy import PyccelKernel
from feectools.api.settings import PSYDAC_BACKEND_GPYCCEL
from feectools.ddm.mpi import mpi as MPI
from feectools.fem.basic import FemSpace
Expand All @@ -19,7 +21,6 @@
from struphy.polar.basic import PolarDerhamSpace, PolarVector
from struphy.polar.linear_operators import PolarExtractionOperator
from struphy.utils.docstring_converter import auto_convert_docstring
from struphy.utils.pyccel import Pyccelkernel

logger = logging.getLogger("struphy")

Expand Down Expand Up @@ -53,9 +54,7 @@ def __init__(self, derham, domain, **weights):

self._rank = derham.comm.Get_rank() if derham.comm is not None else 0

if xp.any(
[degree == 1 and num_elements > 1 for degree, num_elements in zip(derham.degree, derham.num_elements)]
):
if any([degree == 1 and num_elements > 1 for degree, num_elements in zip(derham.degree, derham.num_elements)]):
logger.warning(
f'WARNING: Class "BasisProjectionOperators" called with degree={derham.degree} (interpolation of piece-wise constants should be avoided).',
)
Expand Down Expand Up @@ -1057,11 +1056,11 @@ def __init__(
if isinstance(V, TensorFemSpace):
self._Vspaces = [V.coeff_space]
self._V1ds = [V.spaces]
self._VNbasis = xp.array([self._V1ds[0][0].nbasis, self._V1ds[0][1].nbasis, self._V1ds[0][2].nbasis])
self._VNbasis = np.array([self._V1ds[0][0].nbasis, self._V1ds[0][1].nbasis, self._V1ds[0][2].nbasis])
else:
self._Vspaces = V.coeff_space
self._V1ds = [comp.spaces for comp in V.spaces]
self._VNbasis = xp.array(
self._VNbasis = np.array(
[
[self._V1ds[0][0].nbasis, self._V1ds[0][1].nbasis, self._V1ds[0][2].nbasis],
[
Expand Down Expand Up @@ -1949,13 +1948,13 @@ def assemble(self, weights=None):

# input vector space (domain), column of block
for j, (Vspace, V1d, loc_weight) in enumerate(zip(_Vspaces, _V1ds, weight_line)):
_starts_in = xp.array(Vspace.starts)
_ends_in = xp.array(Vspace.ends)
_pads_in = xp.array(Vspace.pads)
_starts_in = np.array(Vspace.starts)
_ends_in = np.array(Vspace.ends)
_pads_in = np.array(Vspace.pads)

_starts_out = xp.array(Wspace.starts)
_ends_out = xp.array(Wspace.ends)
_pads_out = xp.array(Wspace.pads)
_starts_out = np.array(Wspace.starts)
_ends_out = np.array(Wspace.ends)
_pads_out = np.array(Wspace.pads)

# use cached information if asked
if self._use_cache:
Expand Down Expand Up @@ -2043,7 +2042,7 @@ def assemble(self, weights=None):
)
dofs_mat = self._dof_mat[i, j]

kernel = Pyccelkernel(
kernel = PyccelKernel(
getattr(
basis_projection_kernels,
"assemble_dofs_for_weighted_basisfuns_" + str(V.ldim) + "d",
Expand Down
4 changes: 2 additions & 2 deletions src/struphy/feec/boundary_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Callable

import cunumpy as xp
from cunumpy import PyccelKernel
from feectools.api.settings import PSYDAC_BACKEND_GPYCCEL
from feectools.linalg.block import BlockLinearOperator, BlockVector
from feectools.linalg.stencil import StencilMatrix, StencilVector
Expand All @@ -11,7 +12,6 @@
from struphy.feec.mass import WeightedMassOperators
from struphy.feec.psydac_derham import Derham, SplineFunction
from struphy.geometry.base import Domain
from struphy.utils.pyccel import Pyccelkernel

logger = logging.getLogger("struphy")

Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(
self._setup_surface_data()

# load assembly kernel
self._assembly_kernel = Pyccelkernel(mass_kernels.surface_kernel_3d_mat)
self._assembly_kernel = PyccelKernel(mass_kernels.surface_kernel_3d_mat)

self.assemble()

Expand Down
10 changes: 5 additions & 5 deletions src/struphy/feec/mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Callable

import cunumpy as xp
from cunumpy import PyccelKernel
from feectools.api.settings import PSYDAC_BACKEND_GPYCCEL
from feectools.ddm.mpi import MockComm
from feectools.ddm.mpi import mpi as MPI
Expand All @@ -26,7 +27,6 @@
from struphy.polar.basic import PolarVector
from struphy.polar.linear_operators import PolarExtractionOperator
from struphy.utils.docstring_converter import auto_convert_docstring, info
from struphy.utils.pyccel import Pyccelkernel
from struphy.utils.utils import __class_with_params_repr_no_defaults__

logger = logging.getLogger("struphy")
Expand Down Expand Up @@ -1856,7 +1856,7 @@ def __init__(

# load assembly kernel
if not self._matrix_free:
self._assembly_kernel = Pyccelkernel(
self._assembly_kernel = PyccelKernel(
getattr(
mass_kernels,
"kernel_" + str(self._V.ldim) + "d_mat",
Expand Down Expand Up @@ -2457,7 +2457,7 @@ def eval_quad(self, W, coeffs, out=None):
assert isinstance(out, (list, tuple))

# load assembly kernel
kernel = Pyccelkernel(getattr(mass_kernels, "kernel_" + str(W.ldim) + "d_eval"))
kernel = PyccelKernel(getattr(mass_kernels, "kernel_" + str(W.ldim) + "d_eval"))

# loop over components
for a, wspace in enumerate(Wspaces):
Expand Down Expand Up @@ -2555,14 +2555,14 @@ def __init__(self, derham, V, W, weights=None, nquads=None):
self._nquads = nquads

self._dtype = V.coeff_space.dtype
self._dot_kernel = Pyccelkernel(
self._dot_kernel = PyccelKernel(
getattr(
mass_kernels,
"kernel_" + str(self._V.ldim) + "d_matrixfree",
),
)

self._diag_kernel = Pyccelkernel(
self._diag_kernel = PyccelKernel(
getattr(
mass_kernels,
"kernel_" + str(self._V.ldim) + "d_diag",
Expand Down
18 changes: 8 additions & 10 deletions src/struphy/feec/preconditioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ def solver(self):
"""KroneckerLinearSolver or BlockDiagonalSolver for exactly inverting the approximate mass matrix self.matrix."""
return self._solver

@property
def domain(self):
"""The domain of the linear operator - an element of Vectorspace"""
return self._space

@property
def codomain(self):
"""The codomain of the linear operator - an element of Vectorspace"""
return self._codomain

@property
def domain(self):
"""The domain of the linear operator - an element of Vectorspace"""
return self._domain

@property
def dtype(self):
return self._dtype
Expand Down Expand Up @@ -750,6 +750,9 @@ def matrix(self):
def solver(self):
"""KroneckerLinearSolver or BlockDiagonalSolver for exactly inverting the approximate mass matrix self.matrix."""
return self._solver

@property
def domain(self):
"""The domain of the linear operator - an element of Vectorspace"""
return self._space

Expand All @@ -758,11 +761,6 @@ def codomain(self):
"""The codomain of the linear operator - an element of Vectorspace"""
return self._codomain

@property
def domain(self):
"""The domain of the linear operator - an element of Vectorspace"""
return self._domain

@property
def dtype(self):
return self._dtype
Expand Down
Loading
Loading