8#ifndef particle_in_cell_h
9#define particle_in_cell_h
25 template<std::
floating_po
int T>
27 n_branch_node<7, T, false>,
37 std::string
s =
"apply_u";
62 const size_t size = x.size();
64 size ==
rand.size() &&
69 "Expected all arguments to have the same length.");
71 for (
size_t j = 0;
j < size;
j++) {
77 if constexpr (std::same_as<T, float>) {
118 n_branch_node<7, T,
false>, 7> ({x,
i,
rand,
mof,
tbnu_e_dt,
A,
B},
168 if (!pre_funcs.contains(
"apply_u")) {
169 pre_funcs.insert(
"apply_u");
171 jit::add_type<T> (stream);
172 stream <<
" apply_u(const ";
173 jit::add_type<T> (stream);
174 stream <<
" x, const uint8_t i, uint32_t rand, const ";
175 jit::add_type<T> (stream);
176 stream <<
" mof, const ";
177 jit::add_type<T> (stream);
178 stream <<
" tbnu_e_dt, const ";
179 jit::add_type<T> (stream);
180 stream <<
" A, const ";
181 jit::add_type<T> (stream);
182 stream <<
" B) {" << std::endl
184 jit::add_type<T> (stream);
185 stream <<
" temp_x = x;" << std::endl
186 <<
" for (uint8_t j = 0; j < i; j++, rand >>= 1) {" << std::endl
188 jit::add_type<T> (stream);
189 stream <<
" E0 = mof*temp_x;" << std::endl
190 <<
" const uint8_t rm = 4*(rand & 1) - 2;" << std::endl
192 jit::add_type<T> (stream);
193 stream <<
" C = rm*sqrt(tbnu_e_dt*E0);" << std::endl
194 <<
" temp_x = (E0*A + B + C)/mof;" << std::endl
196 <<
" return temp_x;" << std::endl
202 b->compile_preamble(stream, registers,
230 if (registers.find(
this) == registers.end()) {
241 jit::add_type<T> (stream);
242 stream <<
" " << registers[
this] <<
" = apply_u("
243 << registers[x.get()] <<
", "
244 << registers[
i.get()] <<
", ";
245 stream << registers[
rand.get()] <<
", "
246 << registers[
mof.get()] <<
", "
248 << registers[
A.get()] <<
", "
249 << registers[
B.get()] <<
")";
263 if (
this == x.get()) {
271 for (
size_t i = 1;
i < 7 &&
temp;
i++) {
283 std::cout <<
"\\apply_u{\\left(";
289 std::cout <<
"\\right)}";
319 if (registers.find(
this) == registers.end()) {
321 registers[
this] =
name;
322 stream <<
" " <<
name
323 <<
" [label = \"apply_u\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
326 auto temp =
b->to_vizgraph(stream, registers);
327 stream <<
" " <<
name <<
" -- " << registers[
temp.get()] <<
";" << std::endl;
349 template<std::
floating_po
int T>
357 auto temp = std::make_shared<apply_u_node<T>> (x,
i,
rand,
mof,
360 for (
size_t i =
temp->get_hash();
370#if defined(__clang__) || defined(__GNUC__)
373 assert(
false &&
"Should never reach.");
378 template<std::
floating_po
int T>
389 template<std::
floating_po
int T>
391 return std::dynamic_pointer_cast<apply_u_node<T>> (x);
399 template<std::
floating_po
int T>
401 n_branch_node<4, T, false>,
411 std::string
s =
"apply_xi";
430 const size_t size = x.size();
432 size ==
rand.size() &&
434 "Expected all arguments to have the same length.");
436 for (
size_t j = 0;
j < size;
j++) {
439 if constexpr (std::same_as<T, float>) {
521 if (!pre_funcs.contains(
"apply_xi")) {
522 pre_funcs.insert(
"apply_xi");
524 jit::add_type<T> (stream);
525 stream <<
" apply_xi(const ";
526 jit::add_type<T> (stream);
527 stream <<
" x, const uint8_t i, uint32_t rand, const ";
528 jit::add_type<T> (stream);
529 stream <<
" nu_D_dt) {" << std::endl
531 jit::add_type<T> (stream);
532 stream <<
" temp_x = x;" << std::endl
533 <<
" for (uint8_t j = 0; j < i; j++, rand >>= 1) {" << std::endl
535 jit::add_type<T> (stream);
536 stream <<
" A = -temp_x*nu_D_dt;" << std::endl
537 <<
" const uint8_t rm = 2*(rand & 1) - 1;" << std::endl
539 jit::add_type<T> (stream);
540 stream <<
" C = rm*sqrt((1 - temp_x*temp_x)*nu_D_dt);" << std::endl
541 <<
" temp_x += A + C;" << std::endl
543 <<
" return temp_x;" << std::endl
549 b->compile_preamble(stream, registers,
577 if (registers.find(
this) == registers.end()) {
585 jit::add_type<T> (stream);
586 stream <<
" " << registers[
this] <<
" = apply_xi("
587 << registers[x.get()] <<
", "
588 << registers[
i.get()] <<
", ";
589 stream << registers[
rand.get()] <<
", "
590 << registers[
nu_D_dt.get()] <<
")";
604 if (
this == x.get()) {
612 for (
size_t i = 1;
i < 4 &&
temp;
i++) {
624 std::cout <<
"\\apply_xi{\\left(";
630 std::cout <<
"\\right)}";
657 if (registers.find(
this) == registers.end()) {
659 registers[
this] =
name;
660 stream <<
" " <<
name
661 <<
" [label = \"apply_xi\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
664 auto temp =
b->to_vizgraph(stream, registers);
665 stream <<
" " <<
name <<
" -- " << registers[
temp.get()] <<
";" << std::endl;
684 template<std::
floating_po
int T>
689 auto temp = std::make_shared<apply_xi_node<T>> (x,
i,
rand,
692 for (
size_t i =
temp->get_hash();
702#if defined(__clang__) || defined(__GNUC__)
705 assert(
false &&
"Should never reach.");
710 template<std::
floating_po
int T>
721 template<std::
floating_po
int T>
723 return std::dynamic_pointer_cast<apply_xi_node<T>> (x);
730 template<std::
floating_po
int T>
731 constexpr T
c =
static_cast<T
> (299792458.0);
733 template<std::
floating_po
int T>
734 constexpr T
epsilon0 =
static_cast<T
> (8.8541878188E-12);
736 template<std::
floating_po
int T>
737 constexpr T
q =
static_cast<T
> (1.602176634E-19);
739 template<std::
floating_po
int T>
742 template<std::
floating_po
int T>
743 constexpr T
m_atomic =
static_cast<T
> (1.66053906892E-27);
745 template<std::
floating_po
int T>
748 template<std::
floating_po
int T>
749 constexpr T
kb =
static_cast<T
> (1.380649E-23);
756 template<std::
floating_po
int T>
765 T make_m(
const std::vector<T> &ion_masses) {
766 T total_m =
static_cast<T
> (0);
767 for (
const T &mass : ion_masses) {
770 return total_m/ion_masses.size();
779 T make_q(
const std::vector<uint8_t> &ion_zs) {
780 T total_q =
static_cast<T
> (0);
781 for (
const uint8_t &z : ion_zs) {
782 total_q += z*pic::q<T>;
784 return total_q/ion_zs.size();
817 const std::vector<uint8_t> &ion_zs,
819 m(make_m(ion_masses)),
q(make_q(ion_zs)),
ne(
ne),
837 template<std::
floating_po
int T>
872 a0(std::numbers::pi_v<T>*(r2*r2 - r1*r1)/(norms.l*norms.l)),
884 template<std::
floating_po
int T>
915 const size_t num_ions,
920 x(
graph::variable<T> (num_ions,
"x")),
922 v_perp(
graph::variable<T> (num_ions,
"v_{\\perp}")),
944 return get_x()->size();
953 return get_x()->data();
1013 const std::string tag) {
1037 template<std::
floating_po
int T>
1050 template<
size_t I=0>
1053 const size_t iterations=0)
const {
1054 auto low = iterations ? build_y_index<I> (x -
dx, scale, iterations - 1) :
1057 auto high = iterations ? build_y_index<I> (x +
dx, scale, iterations - 1) :
1060 const T center_w =
static_cast<T
> (0.5);
1061 const T side_w =
static_cast<T
> (0.25);
1064 return (1 - scale)*
center + scale*b;
1075 std::array<graph::shared_leaf<T>, 4>
y;
1103 }),
xmin(x_min/norms.l),
xmax(x_max/norms.l),
1136 template<
size_t I=0, offset O=center>
1139 if constexpr (O ==
low) {
1140 return build_y_index<I> (x -
dx, params.
smoothing,
1142 }
else if constexpr (O ==
center) {
1143 return build_y_index<I> (x, params.
smoothing,
1146 return build_y_index<I> (x +
dx, params.
smoothing,
1161 template<
size_t I=0, offset O=center>
1165 if constexpr (O ==
low) {
1171 }
else if constexpr (O ==
center) {
1200 return {sum_low, sum, sum_high};
1219 template<
size_t I=0>
1249 auto xnorm1 =
static_cast<T
> (1.5) + (x_off -
dx)/
dx;
1250 auto xnorm2 = x_off/
dx;
1251 auto xnorm3 =
static_cast<T
> (1.5) - (x_off +
dx)/
dx;
1253 auto w0 =
static_cast<T
> (0.5)*xnorm1*xnorm1;
1254 auto w1 =
static_cast<T
> (0.75) - xnorm2*xnorm2;
1255 auto w2 =
static_cast<T
> (0.5)*xnorm3*xnorm3;
1257 return {w0, w1, w2};
1273 return weights[0]*ymesh0 + weights[1]*ymesh1 + weights[2]*ymesh2;
1286 template<std::
floating_po
int T>
1306 template<std::
floating_po
int T>
1340 template<std::
floating_po
int T, model M>
1347 auto mass_ratio =
static_cast<T
> (2)*mass_a/mass_b*gb;
1348 auto nu = nuab0/xab;
1349 if constexpr (M == model::hinton) {
1350 return nu*(mass_ratio - erfp_xab/xab);
1352 return nu*mass_ratio;
1371 template<std::
floating_po
int T, model M>
1380 const T dt = params.
dt*norms.
t;
1382 const T mass_b = ion_b.
mass*norms.
m;
1383 const uint8_t zb2 = ion_b.
z*ion_b.
z;
1392 auto tb =
static_cast<T
> (0.5)*(tpara + tperp)*norms.
te*kb<T>/q<T>;
1398 total_density = total_density + nb;
1399 total_flux = total_flux + nv;
1401 return build_common_collision<T, M> (ion_a, norms, uxb, tb, nb, mass_b,
1419 template<std::
floating_po
int T, model M>
1427 const T dt = params.
dt*norms.
t;
1429 const T mass_b = m_electron<T>;
1430 const uint8_t zb2 = 1;
1432 auto nb = total_density;
1437 auto uxb = total_flux/total_density;
1439 return build_common_collision<T, M> (ion_a, norms, uxb, tb, nb, mass_b,
1459 template<std::
floating_po
int T, model M>
1469 const T mass_a = ion_a.
mass*norms.
m;
1470 const uint8_t za2 = ion_a.
z*ion_a.
z;
1473 auto wxa = ion_a.
v_para*norms.
v - uxb;
1474 auto wya = ion_a.
v_perp*norms.
v;
1480 auto wtb =
graph::sqrt(
static_cast<T
> (2)*q<T>*tb/mass_b);
1481 auto xab = sphere[0]/wtb;
1484 auto erfp_xab = erf_xab->df(xab);
1485 auto erfpp_xab = erfp_xab->df(xab);
1487 auto gb = (erf_xab - xab*erfp_xab)/(
static_cast<T
> (2)*xab*xab);
1489 auto nuab0 = nb*q<T>*q<T>*q<T>*q<T>*
static_cast<T
> (za2*zb2)*logA
1490 / (
static_cast<T
> (2)*std::numbers::pi_v<T>*mass_a*mass_a*epsilon0<T>*epsilon0<T>*wtb*wtb*wtb);
1493 auto nu_e_dt = build_colision_rate<T, M> (xab, mass_a, mass_b, gb, nuab0, erfp_xab)*dt;
1494 auto steps =
graph::min(nu_e_dt*2.5,
static_cast<T
> (32));
1496 nu_e_dt = nu_e_dt*steps;
1498 auto E_nuE_d_nu_E_dE =
static_cast<T
> (0.5)*((
static_cast<T
> (3.0)*(xab*erfp_xab - erf_xab) - xab*xab*erfpp_xab)/(erf_xab - xab*erfp_xab));
1500 const T mof = mass_a/(
static_cast<T
> (2)*q<T>);
1501 auto A =
static_cast<T
> (1) -
static_cast<T
> (2)*nu_e_dt;
1502 auto tbnu_e_df = tb*nu_e_dt;
1503 auto B =
static_cast<T
> (2)*tbnu_e_df*(
static_cast<T
> (1.5) + E_nuE_d_nu_E_dE);
1510 auto nu_D_dt = nuab0*(erf_xab - gb)/(xab*xab*xab)*dt;
1511 steps =
graph::min(nu_D_dt,
static_cast<T
> (32));
1512 nu_D_dt = nu_D_dt/steps;
1517 sphere[1] =
graph::if_(sphere[1]*sphere[1] >
static_cast<T
> (1),
1523 return {(cart[0] + uxb)/norms.
v, cart[1]/norms.
v};
1538 template<std::
floating_po
int T>
1548 static_cast<T
> (2)*std::numbers::pi_v<T>,
1559 static_cast<T
> (2)*std::numbers::pi_v<T>,
1570 auto vperp =
graph::sqrt(vperp1*vperp1 + vperp2*vperp2);
1572 return {position_dist, vpara/norms.
v, vperp/norms.
v};
1590 template<std::
floating_po
int T>
1602 auto reinject_vpara =
graph::if_(is_outside ||
1605 auto reinject_vperp =
graph::if_(is_outside ||
1608 return {reinject_x, reinject_vpara, reinject_vperp};
1621 template<std::
floating_po
int T>
1625 return (x*x*(norms.
l*norms.
l) +
static_cast<T
> (0.5))*params.
b0;
1642 template<std::floating_point T,
size_t I=0,
1649 auto y =
mesh.template build_y_index<I, O> (x, params);
1656 return static_cast<T
> (
ion.
z)*y*cf*sf;
1673 template<std::floating_point T,
size_t I=0,
1680 auto y =
mesh.template build_dydx_index<I, O> (x, params);
1687 return static_cast<T
> (
ion.
z)*y*cf*sf;
1699 template<std::
floating_po
int T>
1723 auto n0 = build_density<T, 0, O> (x,
ion,
mesh, norms, params);
1724 auto n1 = build_density<T, 1, O> (x,
ion,
mesh, norms, params);
1725 auto n2 = build_density<T, 2, O> (x,
ion,
mesh, norms, params);
1726 auto n3 = build_density<T, 3, O> (x,
ion,
mesh, norms, params);
1728 auto dn0dx = build_density_gradient<T, 0, O> (x,
ion,
mesh, norms, params);
1729 auto dn1dx = build_density_gradient<T, 1, O> (x,
ion,
mesh, norms, params);
1730 auto dn2dx = build_density_gradient<T, 2, O> (x,
ion,
mesh, norms, params);
1731 auto dn3dx = build_density_gradient<T, 3, O> (x,
ion,
mesh, norms, params);
1733 auto n = (n0 + n1 + n2 + n3)/
static_cast<T
> (4);
1734 auto dndx = (dn0dx + dn1dx + dn2dx + dn3dx)/
static_cast<T
> (4);
1737 const T scale = norms.
q/q<T>;
1738 auto pressure = te*n*scale;
1755 template<std::
floating_po
int T>
1763 auto ymesh0 = build_electric_efield<T, ::pic::mesh<T>::low> (x,
ion,
mesh, norms, params);
1764 auto ymesh1 = build_electric_efield<T, ::pic::mesh<T>::center> (x,
ion,
mesh, norms, params);
1765 auto ymesh2 = build_electric_efield<T, ::pic::mesh<T>::high> (x,
ion,
mesh, norms, params);
1767 return weights[0]*ymesh0 + weights[1]*ymesh1 + weights[2]*ymesh2;
1782 template<std::
floating_po
int T>
1788 auto bfield = build_magnetic_field<T> (z[0], norms, params);
1789 auto efield = build_interpolate_efield<T> (z[0],
ion,
mesh, norms, params);
1790 auto temp = 0.5*z[2]*z[1]*bfield->df(z[0])/bfield;
1809 template<std::
floating_po
int T>
1816 std::array<graph::shared_leaf<T>, 3> dZ1(build_F_expressions<T> (Z1,
ion,
mesh, norms, params));
1819 std::array<graph::shared_leaf<T>, 3> Z2{
1820 Z1[0] + dZ1[0]/
static_cast<T
> (2),
1821 Z1[1] + dZ1[1]/
static_cast<T
> (2),
1822 Z1[2] + dZ1[2]/
static_cast<T
> (2)
1824 std::array<graph::shared_leaf<T>, 3> dZ2(build_F_expressions<T> (Z2,
ion,
mesh, norms, params));
1827 std::array<graph::shared_leaf<T>, 3> Z3{
1828 Z1[0] + dZ2[0]/
static_cast<T
> (2),
1829 Z1[1] + dZ2[1]/
static_cast<T
> (2),
1830 Z1[2] + dZ2[2]/
static_cast<T
> (2)
1832 std::array<graph::shared_leaf<T>, 3> dZ3(build_F_expressions<T> (Z3,
ion,
mesh, norms, params));
1835 std::array<graph::shared_leaf<T>, 3> Z4{
1840 std::array<graph::shared_leaf<T>, 3> dZ4(build_F_expressions<T> (Z4,
ion,
mesh, norms, params));
1844 Z1[0] + (dZ1[0] +
static_cast<T
> (2)*(dZ2[0] + dZ3[0]) + dZ4[0])/
static_cast<T
> (6),
1845 Z1[1] + (dZ1[1] +
static_cast<T
> (2)*(dZ2[1] + dZ3[1]) + dZ4[1])/
static_cast<T
> (6),
1846 Z1[2] + (dZ1[2] +
static_cast<T
> (2)*(dZ2[2] + dZ3[2]) + dZ4[2])/
static_cast<T
> (6)
Class representing a generic buffer.
Definition backend.hpp:29
U Collision node.
Definition particle_in_cell.hpp:28
virtual shared_leaf< T > remove_pseudo()
Remove pseudo variable nodes.
Definition particle_in_cell.hpp:297
virtual shared_leaf< T > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition particle_in_cell.hpp:226
virtual shared_leaf< T > reduce()
Reduce the apply_u(x, i, rand, mof, tbnu_e_dt, A, B).
Definition particle_in_cell.hpp:144
virtual backend::buffer< T > evaluate()
Evaluate the results of the applying the u operator.
Definition particle_in_cell.hpp:126
virtual shared_leaf< T > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition particle_in_cell.hpp:317
apply_u_node(shared_leaf< T > x, shared_leaf< T > i, shared_leaf< T > rand, shared_leaf< T > mof, shared_leaf< T > tbnu_e_dt, shared_leaf< T > A, shared_leaf< T > B)
Construct an apply_u_node.
Definition particle_in_cell.hpp:110
virtual void to_latex() const
Convert the node to latex.
Definition particle_in_cell.hpp:282
virtual bool is_match(shared_leaf< T > x)
Query if the nodes match.
Definition particle_in_cell.hpp:262
virtual void compile_preamble(std::ostringstream &stream, jit::register_map ®isters, jit::visiter_map &visited, jit::register_usage &usage, jit::texture1d_list &textures1d, jit::texture2d_list &textures2d, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition particle_in_cell.hpp:160
Xi Collision node.
Definition particle_in_cell.hpp:402
virtual void to_latex() const
Convert the node to latex.
Definition particle_in_cell.hpp:623
virtual shared_leaf< T > reduce()
Reduce the apply_zi(x, i, rand, nu_D_dt).
Definition particle_in_cell.hpp:497
virtual shared_leaf< T > remove_pseudo()
Remove pseudo variable nodes.
Definition particle_in_cell.hpp:638
apply_xi_node(shared_leaf< T > x, shared_leaf< T > i, shared_leaf< T > rand, shared_leaf< T > nu_D_dt)
Construct an apply_xi_node.
Definition particle_in_cell.hpp:469
virtual void compile_preamble(std::ostringstream &stream, jit::register_map ®isters, jit::visiter_map &visited, jit::register_usage &usage, jit::texture1d_list &textures1d, jit::texture2d_list &textures2d, jit::preamble_map &pre_funcs, int &avail_const_mem)
Compile preamble.
Definition particle_in_cell.hpp:513
virtual bool is_match(shared_leaf< T > x)
Query if the nodes match.
Definition particle_in_cell.hpp:603
virtual shared_leaf< T > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)
Compile the node.
Definition particle_in_cell.hpp:573
virtual backend::buffer< T > evaluate()
Evaluate the results of the applying the xi operator.
Definition particle_in_cell.hpp:482
virtual shared_leaf< T > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition particle_in_cell.hpp:655
Class representing a node leaf.
Definition node.hpp:371
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
End a line in the kernel source.
Definition node.hpp:653
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:633
Class representing a N branch node.
Definition node.hpp:1571
std::array< shared_leaf< T, SAFE_MATH >, N > branches
Branches of the tree.
Definition node.hpp:1574
Nodes without derivatives.
Definition node.hpp:1713
Class representing a netcdf dataset.
Definition output.hpp:166
void create_variable(const result_file &result, const std::string &name, graph::shared_leaf< T, SAFE_MATH > &node, jit::context< T, SAFE_MATH > &context)
Create a variable.
Definition output.hpp:260
Class representing a netcdf based output file.
Definition output.hpp:32
Characteristic factors.
Definition particle_in_cell.hpp:757
const T bfield
Magnetic field;.
Definition particle_in_cell.hpp:807
const T m
Mass.
Definition particle_in_cell.hpp:789
const T ne
Electron density.
Definition particle_in_cell.hpp:793
const T v
Velocity.
Definition particle_in_cell.hpp:801
const T wpe
Plasma Frequency.
Definition particle_in_cell.hpp:795
const T l
Length.
Definition particle_in_cell.hpp:799
T get_volume() const
Get the characteristic volume.
Definition particle_in_cell.hpp:829
const T te
Electron temperature;.
Definition particle_in_cell.hpp:803
const T efield
Electric field;.
Definition particle_in_cell.hpp:805
const T t
Time.
Definition particle_in_cell.hpp:797
const T q
Charge.
Definition particle_in_cell.hpp:791
characteristics(const std::vector< T > &ion_masses, const std::vector< uint8_t > &ion_zs, const T ne)
Construct the characteristics.
Definition particle_in_cell.hpp:816
ion class.
Definition particle_in_cell.hpp:885
graph::shared_variable< T > get_v_para() const
Get x case as variable.
Definition particle_in_cell.hpp:961
const uint8_t z
Atomic number.
Definition particle_in_cell.hpp:888
graph::shared_leaf< T > v_perp
Normalized Perpendicular velocity.
Definition particle_in_cell.hpp:898
graph::shared_leaf< T > build_profile(std::function< graph::shared_leaf< T >(graph::shared_leaf< T >)> func) const
Build a profile.
Definition particle_in_cell.hpp:1027
graph::shared_variable< T > get_x() const
Get x case as variable.
Definition particle_in_cell.hpp:934
graph::shared_leaf< T > x
Normalized Position.
Definition particle_in_cell.hpp:894
T * v_para_data() const
Get the data for the parallel velocity.
Definition particle_in_cell.hpp:970
size_t size() const
Get the number of computational ions.
Definition particle_in_cell.hpp:943
T * v_perp_data() const
Get the data for the perpendicular velocity.
Definition particle_in_cell.hpp:988
void define_variables(const output::result_file &file, output::data_set< T > &data, workflow::manager< T > &work, const std::string tag)
Define variables.
Definition particle_in_cell.hpp:1010
const T mass
Particle mass.
Definition particle_in_cell.hpp:892
const T num_real
Number of real particles.
Definition particle_in_cell.hpp:902
graph::shared_variable< T > get_v_perp() const
Get x case as variable.
Definition particle_in_cell.hpp:979
T * x_data() const
Get the data for x.
Definition particle_in_cell.hpp:952
T super_to_real() const
Conversion factor from super particles to real particles.
Definition particle_in_cell.hpp:997
ion(const T mass, const uint8_t z, const size_t num_ions, const T num_real, const characteristics< T > &norms)
Construct an ion object.
Definition particle_in_cell.hpp:913
graph::shared_leaf< T > v_para
Normalized Parallel velocity.
Definition particle_in_cell.hpp:896
const T charge
Charge.
Definition particle_in_cell.hpp:890
std::array< graph::shared_leaf< T >, 3 > weights
Mesh Weights.
Definition particle_in_cell.hpp:900
Mesh class.
Definition particle_in_cell.hpp:1038
graph::shared_leaf< T > build_i_index(graph::shared_leaf< T > x) const
Build i index.
Definition particle_in_cell.hpp:1122
graph::shared_leaf< T > build_y_index(graph::shared_leaf< T > x, const parameters< T > ¶ms) const
Build y index.
Definition particle_in_cell.hpp:1137
offset
Mesh point.
Definition particle_in_cell.hpp:1077
@ high
Higher index.
Definition particle_in_cell.hpp:1083
@ center
Center index.
Definition particle_in_cell.hpp:1081
@ low
Lower index.
Definition particle_in_cell.hpp:1079
graph::shared_leaf< T > build_x_index(graph::shared_leaf< T > x) const
Build x index.
Definition particle_in_cell.hpp:1112
std::array< graph::shared_leaf< T >, 3 > build_mesh_solve(const ion< T > &ion) const
Build mesh accumulation.
Definition particle_in_cell.hpp:1192
const T xmax
Max x.
Definition particle_in_cell.hpp:1071
T * data() const
Get the number of computational ions.
Definition particle_in_cell.hpp:1220
graph::shared_leaf< T > build_dydx_index(graph::shared_leaf< T > x, const parameters< T > ¶ms) const
Build dy/dx index.
Definition particle_in_cell.hpp:1162
void define_variables(const output::result_file &file, output::data_set< T > &data, workflow::manager< T > &work)
Define variables.
Definition particle_in_cell.hpp:1232
std::array< graph::shared_leaf< T >, 4 > y
Mesh y values.
Definition particle_in_cell.hpp:1075
graph::shared_leaf< T > build_interpolation(graph::shared_leaf< T > x) const
Build interpolation expression.
Definition particle_in_cell.hpp:1266
mesh(const T x_min, const T x_max, const size_t num, const characteristics< T > &norms)
Construct a mesh object.
Definition particle_in_cell.hpp:1094
std::array< graph::shared_leaf< T >, 3 > build_weights(graph::shared_leaf< T > x) const
Build interpolation weights.
Definition particle_in_cell.hpp:1247
const T dx
Dx.
Definition particle_in_cell.hpp:1073
const T xmin
Min x.
Definition particle_in_cell.hpp:1069
size_t size() const
Get the number of computational ions.
Definition particle_in_cell.hpp:1208
Parameter Class.
Definition particle_in_cell.hpp:838
const T a0
Geometry.
Definition particle_in_cell.hpp:843
parameters(const T b0, const T r1, const T r2, const size_t filter_iterations, const T smoothing, const T dt, const T t_para, const T t_perp, const characteristics< T > &norms)
Construct a parameters object.
Definition particle_in_cell.hpp:866
const T b0
Initial magnetic field.
Definition particle_in_cell.hpp:841
const T t_para
Parallel temperature.
Definition particle_in_cell.hpp:851
const T dt
Time step.
Definition particle_in_cell.hpp:849
const size_t filter_iterations
Filter Iterations.
Definition particle_in_cell.hpp:845
const T t_perp
Perpendicular temperature.
Definition particle_in_cell.hpp:853
const T smoothing
Smoothing parameters.
Definition particle_in_cell.hpp:847
Class representing a workflow manager.
Definition workflow.hpp:400
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:722
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
Name space for graph nodes.
Definition arithmetic.hpp:13
shared_leaf< T > apply_u(shared_leaf< T > x, shared_leaf< T > i, shared_leaf< T > rand, shared_leaf< T > mof, shared_leaf< T > tbnu_e_dt, shared_leaf< T > A, shared_leaf< T > B)
Build apply_u node.
Definition particle_in_cell.hpp:350
shared_leaf< T, SAFE_MATH > log(shared_leaf< T, SAFE_MATH > x)
Define log convenience function.
Definition math.hpp:797
shared_leaf< T, SAFE_MATH > isnan(shared_leaf< T, SAFE_MATH > arg)
Build isnan node from the argument leaves.
Definition logical.hpp:326
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1154
shared_leaf< T > apply_xi(shared_leaf< T > x, shared_leaf< T > i, shared_leaf< T > rand, shared_leaf< T > nu_D_dt)
Build apply_xi node.
Definition particle_in_cell.hpp:685
std::shared_ptr< variable_node< T, SAFE_MATH > > shared_variable
Convenience type alias for shared variable nodes.
Definition node.hpp:2146
std::shared_ptr< apply_xi_node< T > > shared_apply_xi
Convenience type alias for shared sqrt nodes.
Definition particle_in_cell.hpp:711
shared_leaf< T, SAFE_MATH > atomic_accumulate_1D(shared_leaf< T, SAFE_MATH > v, shared_leaf< T, SAFE_MATH > i, shared_leaf< T, SAFE_MATH > x)
Define atomic_accumulate_1D convenience function.
Definition piecewise.hpp:2362
shared_apply_xi< T > apply_xi_cast(shared_leaf< T > x)
Cast to a apply_u node.
Definition particle_in_cell.hpp:722
shared_leaf< T, SAFE_MATH > index_1D(shared_leaf< T, SAFE_MATH > v, shared_leaf< T, SAFE_MATH > x)
Define index_1D convenience function.
Definition piecewise.hpp:1712
shared_leaf< T, SAFE_MATH > erf(shared_leaf< T, SAFE_MATH > x)
Define erf convenience function.
Definition math.hpp:1649
shared_leaf< T, SAFE_MATH > copysign(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r)
Build copysign node.
Definition math.hpp:2532
shared_apply_u< T > apply_u_cast(shared_leaf< T > x)
Cast to a apply_u node.
Definition particle_in_cell.hpp:390
std::shared_ptr< random_state_node< T, SAFE_MATH > > shared_random_state
Convenience type alias for shared sqrt nodes.
Definition random.hpp:269
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:2169
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1186
shared_leaf< T, SAFE_MATH > if_(shared_leaf< T, SAFE_MATH > c, shared_leaf< T, SAFE_MATH > t, shared_leaf< T, SAFE_MATH > f)
Build an if node from a condition and two leaves.
Definition logical.hpp:2963
shared_leaf< T, SAFE_MATH > constant(const backend::buffer< T > &d)
Construct a constant.
Definition node.hpp:1111
shared_leaf< T, SAFE_MATH > sin(shared_leaf< T, SAFE_MATH > x)
Define sine convenience function.
Definition trigonometry.hpp:225
shared_leaf< T, SAFE_MATH > sqrt(shared_leaf< T, SAFE_MATH > x)
Define sqrt convenience function.
Definition math.hpp:297
shared_leaf< T, SAFE_MATH > min(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r)
Build a max node from a condition and two leaves.
Definition logical.hpp:3266
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
shared_leaf< T, SAFE_MATH > isinf(shared_leaf< T, SAFE_MATH > arg)
Build not node from the argument leaves.
Definition logical.hpp:157
shared_leaf< T, SAFE_MATH > cos(shared_leaf< T, SAFE_MATH > x)
Define cosine convenience function.
Definition trigonometry.hpp:479
shared_leaf< T, SAFE_MATH > hypot(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r)
Build hypot node.
Definition math.hpp:2222
shared_leaf< T, SAFE_MATH > argument(shared_leaf< T, SAFE_MATH > x, const T scale, const T offset, const size_t length)
Define argument convenience function.
Definition piecewise.hpp:308
std::shared_ptr< apply_u_node< T > > shared_apply_u
Convenience type alias for shared sqrt nodes.
Definition particle_in_cell.hpp:379
std::unordered_set< void * > visiter_map
Type alias for listing visited nodes.
Definition register.hpp:263
std::string format_to_string(const T value)
Convert a value to a string while avoiding locale.
Definition register.hpp:213
std::unordered_map< void *, size_t > register_usage
Type alias for counting register usage.
Definition register.hpp:261
std::unordered_set< std::string > preamble_map
Type alias for preamble defined functions.
Definition register.hpp:269
std::unordered_map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:259
std::unordered_map< void *, std::array< size_t, 2 > > texture2d_list
Type alias for indexing 2D textures.
Definition register.hpp:267
std::unordered_map< void *, size_t > texture1d_list
Type alias for indexing 1D textures.
Definition register.hpp:265
std::string to_string(const char prefix, const NODE *pointer)
Convert a graph::leaf_node pointer to a string.
Definition register.hpp:247
graph::shared_leaf< T > build_interpolate_efield(graph::shared_leaf< T > x, const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build interpolation expression.
Definition particle_in_cell.hpp:1756
constexpr T kb
Boltzman constant.
Definition particle_in_cell.hpp:749
graph::shared_leaf< T > build_magnetic_field(graph::shared_leaf< T > x, const characteristics< T > &norms, const parameters< T > ¶ms)
Build a magnetic field.
Definition particle_in_cell.hpp:1622
std::array< graph::shared_leaf< T >, 2 > build_ion_electron_collision(const ion< T > &ion_a, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms, graph::shared_leaf< T > total_density, graph::shared_leaf< T > total_flux, const graph::shared_random_state< T > state)
Build ion electron collision.
Definition particle_in_cell.hpp:1420
std::array< graph::shared_leaf< T >, 2 > build_common_collision(const ion< T > &ion_a, const characteristics< T > &norms, graph::shared_leaf< T > uxb, graph::shared_leaf< T > tb, graph::shared_leaf< T > nb, const T mass_b, const uint8_t zb2, const T dt, const graph::shared_random_state< T > state)
Build common collisions graphs for all species.
Definition particle_in_cell.hpp:1460
constexpr T epsilon0
Vacuum permitivity F/m.
Definition particle_in_cell.hpp:734
std::array< graph::shared_leaf< T >, 3 > build_F_expressions(const std::array< graph::shared_leaf< T >, 3 > z, const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build F expressions.
Definition particle_in_cell.hpp:1783
graph::shared_leaf< T > build_colision_rate(graph::shared_leaf< T > xab, const T mass_a, const T mass_b, graph::shared_leaf< T > gb, graph::shared_leaf< T > nuab0, graph::shared_leaf< T > erfp_xab)
Calculate ν_{E}.
Definition particle_in_cell.hpp:1341
std::array< graph::shared_leaf< T >, 3 > cartesian_to_sphereical(graph::shared_leaf< T > x, graph::shared_leaf< T > y)
Convert from cartesian to sphereical coordinates.
Definition particle_in_cell.hpp:1287
constexpr T q
Fundamental charge coulombs.
Definition particle_in_cell.hpp:737
graph::shared_leaf< T > build_density(graph::shared_leaf< T > x, const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build expressions for the density.
Definition particle_in_cell.hpp:1644
graph::shared_leaf< T > build_electron_temperature(graph::shared_leaf< T > x, const characteristics< T > &norms)
Build Expressions for Electron temperature.
Definition particle_in_cell.hpp:1700
std::array< graph::shared_leaf< T >, 3 > build_rk4_step(const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build Runga Kutta step update.
Definition particle_in_cell.hpp:1810
std::array< graph::shared_leaf< T >, 2 > sphereical_to_cartesian(graph::shared_leaf< T > w, graph::shared_leaf< T > xi, graph::shared_leaf< T > sinphi)
Convert from sphereical to cartesian coordinates.
Definition particle_in_cell.hpp:1307
constexpr T m_atomic
Atomic mass.
Definition particle_in_cell.hpp:743
std::array< graph::shared_leaf< T >, 2 > build_ion_ion_collision(const ion< T > &ion_a, const ion< T > &ion_b, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms, graph::shared_leaf< T > total_density, graph::shared_leaf< T > total_flux, const graph::shared_random_state< T > state)
Build ion ion collision.
Definition particle_in_cell.hpp:1372
model
Model for coulomb scattering operators.
Definition particle_in_cell.hpp:1319
@ hinton
From Hinton 1983 EQ 92 and T.S. Chen 1988 EQ 50.
Definition particle_in_cell.hpp:1321
@ chen
From T.S. Chen 1988 Report EQ 57 commonly used for NBI.
Definition particle_in_cell.hpp:1323
std::array< graph::shared_leaf< T >, 3 > build_initialization(const pic::ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms, const graph::shared_random_state< T > state)
Build initialization.
Definition particle_in_cell.hpp:1539
std::array< graph::shared_leaf< T >, 3 > build_reinjection(const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms, const graph::shared_random_state< T > state)
Build reinjected expressions.
Definition particle_in_cell.hpp:1591
graph::shared_leaf< T > build_electric_efield(graph::shared_leaf< T > x, const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build expressions for the electric field.
Definition particle_in_cell.hpp:1718
constexpr T c
Speed of light m/s.
Definition particle_in_cell.hpp:731
constexpr T m_hydrogen
Hydrogen mass kg.
Definition particle_in_cell.hpp:740
constexpr T m_electron
Electron mass kg.
Definition particle_in_cell.hpp:746
graph::shared_leaf< T > build_density_gradient(graph::shared_leaf< T > x, const ion< T > &ion, const mesh< T > &mesh, const characteristics< T > &norms, const parameters< T > ¶ms)
Build expressions for the density gradient.
Definition particle_in_cell.hpp:1675
Random constants and distributions.
Classes to manage workflows,.