Version: SMASH-3.1
fields.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2021
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/fields.h"
11 
12 namespace smash {
13 
18  RectangularLattice<std::array<FourVector, 4>> *fields_four_grad_lattice,
19  DensityLattice *jmuB_lat, const LatticeUpdate fields_lat_update,
20  const Potentials &potentials, const double time_step) {
21  // Do not proceed if lattice does not exists/update not required
22  if (fields_lat == nullptr || fields_lat->when_update() != fields_lat_update) {
23  return;
24  }
25  // get the number of nodes on the fields lattice
26  const std::array<int, 3> lattice_n_cells = fields_lat->n_cells();
27  const int number_of_nodes =
28  lattice_n_cells[0] * lattice_n_cells[1] * lattice_n_cells[2];
29 
30  /*
31  * Take the provided FieldsOnLattice lattice, fields_lat, and use the
32  * information about the fields to populate the lattice of A^mu FourVectors at
33  * t0, old_fields.
34  */
35  for (int i = 0; i < number_of_nodes; i++) {
36  old_fields->assign_value(i, ((*fields_lat)[i]).A_mu());
37  }
38 
39  /*
40  * Update the fields lattice
41  */
42  fields_lat->reset();
43 
44  // Get the potential parameters
45  const double rhoB_0 = potentials.saturation_density();
46 
47  // update the fields lattice
48  for (int i = 0; i < number_of_nodes; i++) {
49  // read values off the jmu_B lattice (which holds values at t0 + Delta t)
50  double rhoB_at_i = ((*jmuB_lat)[i]).rho();
51  FourVector jmuB_at_i = ((*jmuB_lat)[i]).jmu_net();
52 
53  double abs_rhoB_at_i = std::abs(rhoB_at_i);
54  // this is to prevent nan expressions
55  if (abs_rhoB_at_i < very_small_double) {
56  abs_rhoB_at_i = very_small_double;
57  }
58 
59  // this needs to be used in order to prevent trying to calculate something
60  // an expression like (-rhoB)^{3.4}
61  const int sgn = rhoB_at_i > 0 ? 1 : -1;
62 
63  // field contributions as obtained in the VDF model
64  double field_contribution = 0.0;
65  for (int j = 0; j < potentials.number_of_terms(); j++) {
66  field_contribution +=
67  sgn * potentials.coeffs()[j] *
68  std::pow(abs_rhoB_at_i / rhoB_0, potentials.powers()[j] - 2.0) /
69  rhoB_0;
70  }
71  FourVector field_at_i = field_contribution * jmuB_at_i;
72 
73  // fill the A_mu lattice
74  ((*fields_lat)[i]).overwrite_A_mu(field_at_i);
75  }
76 
77  /*
78  * Use the updated fields lattice, fields_lat, to populate the lattice of A^mu
79  * FourVectors at t0 + Delta t, new_fields.
80  */
81  for (int i = 0; i < number_of_nodes; i++) {
82  new_fields->assign_value(i, ((*fields_lat)[i]).A_mu());
83  }
84 
85  /*
86  * Compute time derivatives and gradients of all components of A^mu
87  */
88  new_fields->compute_four_gradient_lattice(*old_fields, time_step,
89  *fields_four_grad_lattice);
90 
91  // substitute new derivatives
92  for (int i = 0; i < number_of_nodes; i++) {
93  auto tmp = (*fields_four_grad_lattice)[i];
94  ((*fields_lat)[i]).overwrite_dAmu_dxnu(tmp[0], tmp[1], tmp[2], tmp[3]);
95  }
96 } // void update_fields_lattice()
97 
98 } // namespace smash
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
A class that stores parameters of potentials, calculates potentials and their gradients.
Definition: potentials.h:36
const std::vector< double > & powers() const
Definition: potentials.h:459
const std::vector< double > & coeffs() const
Definition: potentials.h:457
int number_of_terms() const
Definition: potentials.h:461
double saturation_density() const
Definition: potentials.h:455
A container class to hold all the arrays on the lattice and access them.
Definition: lattice.h:47
void reset()
Sets all values on lattice to zeros.
Definition: lattice.h:104
LatticeUpdate when_update() const
Definition: lattice.h:169
void compute_four_gradient_lattice(RectangularLattice< FourVector > &old_lat, double time_step, RectangularLattice< std::array< FourVector, 4 >> &grad_lat) const
Compute a fourgradient on a lattice of FourVectors jmu via the finite difference method.
Definition: lattice.h:418
const std::array< int, 3 > & n_cells() const
Definition: lattice.h:157
void assign_value(int lattice_index, T value)
Overwrite with a template value T at a given node.
Definition: lattice.h:193
int sgn(T val)
Signum function.
Definition: random.h:190
Definition: action.h:24
constexpr double very_small_double
A very small double, used to avoid division by zero.
Definition: constants.h:40
void update_fields_lattice(RectangularLattice< FieldsOnLattice > *fields_lat, RectangularLattice< FourVector > *old_fields, RectangularLattice< FourVector > *new_fields, RectangularLattice< std::array< FourVector, 4 >> *fields_four_grad_lattice, DensityLattice *jmu_B_lat, const LatticeUpdate fields_lat_update, const Potentials &potentials, const double time_step)
Updates the contents on the lattice of FieldsOnLattice type.
Definition: fields.cc:14
LatticeUpdate
Enumerator option for lattice updates.
Definition: lattice.h:36