Skip to content

Commit

Permalink
Add interspecies collision in main sheath simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyBourne committed Jan 24, 2024
1 parent 2d82add commit ad29aa5
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from gysdata import DiskStore
from plot_utils import plot_field1d, plot_field2d
from math_utils import compute_moment, differentiate
from geometryXVx.utils import compute_krook_sink_constant, compute_krook_sink_adaptive, compute_kinetic_source
from geometryXVx.utils import compute_collinter_energy_exchange, compute_temperature


if __name__ == '__main__':
Expand Down Expand Up @@ -47,14 +48,16 @@ if __name__ == '__main__':
particle_flux = compute_moment(fdistribu, 'v_x', moment_order=1)
momentum_flux = compute_moment(fdistribu, 'v_x', moment_order=2)
energy_flux = compute_moment(fdistribu, 'v_x', moment_order=3)
temperature = compute_temperature(density, particle_flux, momentum_flux)

momentum_flux = momentum_flux.chunk({'time': len(momentum_flux['time'])})
dmomentum_flux_dt = differentiate(momentum_flux, 'time')
grad_flux_over_m = differentiate(energy_flux, 'x') / np.sqrt(mass)
force_term = 2*particle_flux*charge/np.sqrt(mass)*electric_field
energy_source = compute_moment(compute_krook_sink_constant(ds), 'v_x', moment_order=2) \
+ compute_moment(compute_krook_sink_adaptive(ds, density), 'v_x', moment_order=2) \
+ compute_moment(compute_kinetic_source(ds), 'v_x', moment_order=2)
+ compute_moment(compute_kinetic_source(ds), 'v_x', moment_order=2) \
+ 2*compute_collinter_energy_exchange(ds, density, temperature)
error = dmomentum_flux_dt + grad_flux_over_m - energy_source - force_term

time_diag = fdistribu.coords['time'].values[args.itime]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from gysdata import DiskStore
from plot_utils import plot_field1d, plot_field2d
from math_utils import compute_moment, differentiate
from geometryXVx.utils import compute_krook_sink_constant, compute_krook_sink_adaptive, compute_kinetic_source
from geometryXVx.utils import compute_collinter_momentum_exchange, compute_temperature


if __name__ == '__main__':
Expand Down Expand Up @@ -47,14 +48,16 @@ if __name__ == '__main__':
density = compute_moment(fdistribu, 'v_x', moment_order=0)
particle_flux = compute_moment(fdistribu, 'v_x', moment_order=1)
momentum_flux = compute_moment(fdistribu, 'v_x', moment_order=2)
temperature = compute_temperature(density, particle_flux, momentum_flux)

particle_flux = particle_flux.chunk({'time': len(particle_flux['time'])})
dgamma_dt = differentiate(particle_flux, 'time')
grad_flux_over_m = differentiate(momentum_flux, 'x') / np.sqrt(mass)
force_term = density*charge/np.sqrt(mass)*electric_field
momentum_source = compute_moment(compute_krook_sink_constant(ds), 'v_x', moment_order=1) \
+ compute_moment(compute_krook_sink_adaptive(ds, density), 'v_x', moment_order=1) \
+ compute_moment(compute_kinetic_source(ds), 'v_x', moment_order=1)
+ compute_moment(compute_kinetic_source(ds), 'v_x', moment_order=1) \
+ compute_collinter_momentum_exchange(ds, density, particle_flux/density, temperature)
error = dgamma_dt + grad_flux_over_m - momentum_source - force_term

time_diag = fdistribu.coords['time'].values[args.itime]
Expand Down
68 changes: 68 additions & 0 deletions post-process/PythonScripts/geometryXVx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import numpy as np
import yaml
import xarray as xr

Expand Down Expand Up @@ -86,3 +87,70 @@ def compute_kinetic_source(diskstore):
print('Info: no kinetic source in simulation:', e)
return xr.zeros_like(diskstore['fdistribu'])


def compute_collinter_collision_frequency(diskstore, density, temperature):
'''Computes the interspecies collision frequency
'''

charges = diskstore['fdistribu_charges']
masses = diskstore['fdistribu_masses']
charges_pow4 = charges**4
collfreq_onespec = diskstore['collinter_nustar0'] * charges_pow4 \
* np.sqrt(masses.sel(species='electrons')/masses) \
/ diskstore['Lx'] * density / np.power(temperature, 1.5)

density_flipped = density.copy()
density_flipped.coords['species'] = density.coords['species'][::-1]
density_ratio = density/density_flipped

temperature_flipped = temperature.copy()
temperature_flipped.coords['species'] = temperature.coords['species'][::-1]
temperature_ratio = temperature/temperature_flipped

charges_ratio = charges/charges.values[::-1]
masses_ratio = masses/masses.values[::-1]

collfreq_bothspecies = collfreq_onespec * np.sqrt(2.) / (charges_ratio * charges_ratio) \
* (1. + masses_ratio) / density_ratio \
/ np.power(1. + masses_ratio/temperature_ratio, 1.5)

return collfreq_bothspecies


def compute_collinter_momentum_exchange(diskstore, density, fluid_velocity, temperature):
'''Computes the interspecies collision operator expression of the
momentum exchange term
'''
try:
collfreq = compute_collinter_collision_frequency(diskstore, density, temperature)
masses = diskstore['fdistribu_masses']
masses_ratio = masses/masses.values[::-1]
fluid_velocity_flipped = fluid_velocity.copy()
fluid_velocity_flipped.coords['species'] = fluid_velocity_flipped.coords['species'][::-1]
momentum_term = -collfreq*density * (fluid_velocity - np.sqrt(masses_ratio) \
* fluid_velocity_flipped)
return momentum_term
except KeyError as e:
print('Info: no inter_species collisions in simulation:', e)
return xr.zeros_like(diskstore['electrostatic_potential'])


def compute_collinter_energy_exchange(diskstore, density, temperature):
'''Computes the interspecies collision operator expression of the
energy exchange term
'''
try:
temperature_flipped = temperature.copy()
temperature_flipped.coords['species'] = temperature_flipped.coords['species'][::-1]

masses = diskstore['fdistribu_masses']
masses_flipped = masses.copy()
masses_flipped.coords['species'] = masses_flipped.coords['species'][::-1]
ma_on_ma_mb = masses/(masses + masses_flipped)
collfreq = compute_collinter_collision_frequency(diskstore, density, temperature)

return -3*collfreq*density*ma_on_ma_mb*(temperature - temperature_flipped)

except KeyError as e:
print('Info: no inter_species collisions in simulation:', e)
return xr.zeros_like(diskstore['electrostatic_potential'])
8 changes: 8 additions & 0 deletions post-process/PythonScripts/gysdata/data_structure_sheath.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ fdistribu_eq:
dimensions: [ *speciesd , *vxd ]
path: { file: 'VOICEXX_initstate.h5', dataset: 'fdistribu_eq' }

collinter_nustar0:
dimensions: [ ]
path: { file: 'VOICEXX_initstate.h5', dataset: 'collinter_nustar0' }

Lx:
dimensions: [ ]
path: { file: 'VOICEXX_initstate.h5', dataset: 'Lx' }

krook_sink_constant_amplitude:
dimensions: [ ]
path: { file: 'VOICEXX_initstate.h5', dataset: 'krook_sink_constant_amplitude' }
Expand Down
4 changes: 4 additions & 0 deletions simulations/geometryXVx/sheath/pdi_out.yml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG(
time_saved : double
nbstep_diag: int
iter_saved : int
Lx : double
MeshX_extents: { type: array, subtype: int64, size: 1 }
MeshX:
type: array
Expand Down Expand Up @@ -36,6 +37,7 @@ constexpr char const* const PDI_CFG = R"PDI_CFG(
subtype: double
size: [ '$fdistribu_eq_extents[0]', '$fdistribu_eq_extents[1]' ]
collintra_nustar0 : double
collinter_nustar0 : double
krook_sink_adaptive_extent : double
krook_sink_adaptive_stiffness : double
Expand Down Expand Up @@ -118,8 +120,10 @@ constexpr char const* const PDI_CFG = R"PDI_CFG(
- Nvx
- MeshX
- MeshVx
- Lx
- nbstep_diag
- collintra_nustar0
- collinter_nustar0
- Nkinspecies
- fdistribu_charges
- fdistribu_masses
Expand Down
1 change: 1 addition & 0 deletions simulations/geometryXVx/sheath/sheath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ int main(int argc, char** argv)
ddc::expose_to_pdi("Nvx", vx_size.value());
ddc::expose_to_pdi("MeshX", meshX_coord);
ddc::expose_to_pdi("MeshVx", meshVx_coord);
ddc::expose_to_pdi("Lx", ddcHelper::total_interval_length(gridx));
ddc::expose_to_pdi("nbstep_diag", nbstep_diag);
ddc::expose_to_pdi("Nkinspecies", nb_kinspecies.value());
ddc::expose_to_pdi("fdistribu_charges", ddc::discrete_space<IDimSp>().charges()[dom_kinsp]);
Expand Down
2 changes: 1 addition & 1 deletion simulations/geometryXVx/sheath/sheath.yaml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ constexpr char const* const params_yaml = R"PARAMS_CFG(Mesh:
temperature: 1.
CollisionsInfo:
enable_inter: false
enable_inter: true
nustar0: 0.1
Algorithm:
Expand Down

0 comments on commit ad29aa5

Please sign in to comment.