Skip to content

Commit ce35970

Browse files
committed
✨ nppc as output
1 parent a06250d commit ce35970

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/definitions.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ namespace ntt {
150150
J, // Current density
151151
T, // Particle distribution moments
152152
Rho, // Particle density
153-
N // Particle number density
153+
N, // Particle number density
154+
Nppc // Raw number of particles per each cell
154155
};
155156

156157
inline auto StringizeFieldID(const FieldID& id) -> std::string {
@@ -167,6 +168,8 @@ namespace ntt {
167168
return "Rho";
168169
case FieldID::N:
169170
return "N";
171+
case FieldID::Nppc:
172+
return "Nppc";
170173
default:
171174
return "UNKNOWN";
172175
}

src/framework/io/output.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ namespace ntt {
118118
const auto id = FieldID::Rho;
119119
auto species = InterpretInputField_getspecies(fld);
120120
return InterpretInputField_helper(id, { {} }, species);
121+
} else if (fld.find("Nppc") == 0) {
122+
const auto id = FieldID::Nppc;
123+
auto species = InterpretInputField_getspecies(fld);
124+
return InterpretInputField_helper(id, { {} }, species);
121125
} else if (fld.find("N") == 0) {
122126
const auto id = FieldID::N;
123127
auto species = InterpretInputField_getspecies(fld);
@@ -214,7 +218,13 @@ namespace ntt {
214218
}
215219
} else {
216220
for (std::size_t i { 0 }; i < comp.size(); ++i) {
217-
mblock.ComputeMoments(params, m_id, comp[i], species, i % 3, params.outputMomSmooth());
221+
// no smoothing for FieldID::Nppc
222+
mblock.ComputeMoments(params,
223+
m_id,
224+
comp[i],
225+
species,
226+
i % 3,
227+
m_id == FieldID::Nppc ? 0 : params.outputMomSmooth());
218228
PutField<D, 3>(io, writer, name(i), mblock.buff, i % 3);
219229
}
220230
}

src/framework/meshblock/meshblock.cpp

+20-12
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ namespace ntt {
8282
std::vector<Content> A = { this->buff_content[buff_ind] };
8383
AssertEmptyContent(A);
8484
std::size_t ni1 = this->Ni1(), ni2 = this->Ni2(), ni3 = this->Ni3();
85-
real_t weight = (1.0 / params.ppc0()) / math::pow(2.0 * smooth + 1.0, static_cast<int>(D));
85+
real_t weight = ONE / math::pow(2.0 * smooth + 1.0, static_cast<int>(D));
86+
if (field != FieldID::Nppc) {
87+
weight /= params.ppc0();
88+
}
8689
if constexpr (D == Dim1) {
8790
Kokkos::deep_copy(Kokkos::subview(this->buff, Kokkos::ALL(), (int)buff_ind), ZERO);
8891
} else if constexpr (D == Dim2) {
@@ -131,7 +134,7 @@ namespace ntt {
131134
real_t contrib { ZERO };
132135
if (field == FieldID::Rho) {
133136
contrib = ((mass == ZERO) ? ONE : mass);
134-
} else if (field == FieldID::N) {
137+
} else if ((field == FieldID::N) || (field == FieldID::Nppc)) {
135138
contrib = ONE;
136139
} else if (field == FieldID::T) {
137140
real_t energy { ((mass == ZERO) ? get_photon_Energy_SR(species, p)
@@ -149,9 +152,11 @@ namespace ntt {
149152
}
150153
}
151154
}
155+
if (fieldID != FieldID::Nppc) {
156+
contrib *= this_metric.min_cell_volume() / this_metric.sqrt_det_h({ x1 });
157+
}
152158
for (int i1_ = i1_min; i1_ <= i1_max; ++i1_) {
153-
buff_access(i1_, buff_ind) += contrib * weight * this_metric.min_cell_volume()
154-
/ this_metric.sqrt_det_h({ x1 });
159+
buff_access(i1_, buff_ind) += contrib * weight;
155160
}
156161
}
157162
});
@@ -171,7 +176,7 @@ namespace ntt {
171176
real_t contrib { ZERO };
172177
if (field == FieldID::Rho) {
173178
contrib = ((mass == ZERO) ? ONE : mass);
174-
} else if (field == FieldID::N) {
179+
} else if ((field == FieldID::N) || (field == FieldID::Nppc)) {
175180
contrib = ONE;
176181
} else if (field == FieldID::T) {
177182
real_t energy { ((mass == ZERO) ? get_photon_Energy_SR(species, p)
@@ -204,11 +209,12 @@ namespace ntt {
204209
}
205210
#endif
206211
}
212+
if (fieldID != FieldID::Nppc) {
213+
contrib *= this_metric.min_cell_volume() / this_metric.sqrt_det_h({ x1, x2 });
214+
}
207215
for (int i2_ = i2_min; i2_ <= i2_max; ++i2_) {
208216
for (int i1_ = i1_min; i1_ <= i1_max; ++i1_) {
209-
buff_access(i1_, i2_, buff_ind) += contrib * weight
210-
* this_metric.min_cell_volume()
211-
/ this_metric.sqrt_det_h({ x1, x2 });
217+
buff_access(i1_, i2_, buff_ind) += contrib * weight;
212218
}
213219
}
214220
}
@@ -233,7 +239,7 @@ namespace ntt {
233239
real_t contrib { ZERO };
234240
if (field == FieldID::Rho) {
235241
contrib = ((mass == ZERO) ? ONE : mass);
236-
} else if (field == FieldID::N) {
242+
} else if ((field == FieldID::N) || (field == FieldID::Nppc)) {
237243
contrib = ONE;
238244
} else if (field == FieldID::T) {
239245
real_t energy { ((mass == ZERO) ? get_photon_Energy_SR(species, p)
@@ -264,12 +270,14 @@ namespace ntt {
264270
}
265271
#endif
266272
}
273+
if (fieldID != FieldID::Nppc) {
274+
contrib
275+
*= this_metric.min_cell_volume() / this_metric.sqrt_det_h({ x1, x2, x3 });
276+
}
267277
for (int i3_ = i3_min; i3_ <= i3_max; ++i3_) {
268278
for (int i2_ = i2_min; i2_ <= i2_max; ++i2_) {
269279
for (int i1_ = i1_min; i1_ <= i1_max; ++i1_) {
270-
buff_access(i1_, i2_, i3_, buff_ind)
271-
+= contrib * weight * this_metric.min_cell_volume()
272-
/ this_metric.sqrt_det_h({ x1, x2, x3 });
280+
buff_access(i1_, i2_, i3_, buff_ind) += contrib * weight;
273281
}
274282
}
275283
}

0 commit comments

Comments
 (0)