-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathneutrals.cxx
155 lines (129 loc) · 5.34 KB
/
neutrals.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "neutrals.hxx"
#include "bout/constants.hxx"
#include "cross_section.hxx"
#include "git_version.hxx"
#include "interpolation.hxx"
#include "neutrals_diffusion.hxx"
#include "neutrals_none.hxx"
#include "neutrals_parallel.hxx"
#include "unit.hxx"
#include <difops.hxx>
Neutrals::Neutrals(Solver *solver, Mesh *mesh, CrossSection *cs, Options *options)
: dump_more(false), n(nullptr), n_stag(nullptr), Te(nullptr), Ti(nullptr),
Ui(nullptr), Ue(nullptr), phi(nullptr), unit(nullptr), mu(1850), solver(solver),
mesh(mesh), hydrogen(cs), options(options) {
output.write("************************************"
"**********************************\n");
output.write("\tNeutrals-API Version %s\n", NEUTRALS_GIT_SHA1);
output.write("************************************"
"**********************************\n");
}
void Neutrals::init() {
OPTION(options, vort_source_fac, 1.0);
}
Neutrals::~Neutrals() { delete hydrogen; };
void Neutrals::setPlasmaDensity(const Field3D &n_) { n = &n_; }
void Neutrals::setElectronTemperature(const Field3D &Te_) { Te = &Te_; }
void Neutrals::setIonTemperature(const Field3D &Ti_) { Ti = &Ti_; }
void Neutrals::setIonVelocity(const Field3D &U_) { Ui = &U_; }
void Neutrals::setElectronVelocity(const Field3D &U_) { Ue = &U_; }
void Neutrals::setPlasmaDensityStag(const Field3D &n_stag_) { n_stag = &n_stag_; }
void Neutrals::scaleSource(BoutReal fac) { ; }
const CrossSection *Neutrals::getCrossSection() const { return hydrogen; }
void Neutrals::dumpRates(Datafile &dump) {
SAVE_REPEAT(gamma_CX);
SAVE_REPEAT(gamma_rec);
SAVE_REPEAT(gamma_ion);
}
void Neutrals::dumpMore(Datafile &dump) {
dumpRates(dump);
dump_more = true;
ionVelocitySource = new Field3D;
densitySource = new Field3D();
;
electronTemperatureSource = new Field3D;
dump.add(*ionVelocitySource, "ionVelocitySource", true);
dump.add(*densitySource, "densitySource", true);
dump.add(*electronTemperatureSource, "electronTemperatureSource", true);
}
void Neutrals::updateMore() {
if (dump_more) {
*ionVelocitySource = getIonVelocitySource();
*densitySource = getDensitySource();
*electronTemperatureSource = getElectronTemperatureSource();
}
}
void Neutrals::setUnit(const Unit &unit_) { unit = &unit_; }
void Neutrals::setPotential(const Field3D &phi_) { phi = &phi_; }
/*const Field3D &Neutrals::getCXRate() const { return gamma_CX; }
const Field3D &Neutrals::getRecombinationRate() const { return gamma_rec; }
const Field3D &Neutrals::getIonisationRate() const { return gamma_ion; }
*/
// Friction term between neutrals and ions
Field3D Neutrals::getIonVelocitySource() const {
ASSERT2(Ui != nullptr);
Field3D tmp = gamma_CX + gamma_ion;
tmp /= *n; // getCXOverN()+getIonOverN();
return -(*Ui) * (interp_to(tmp, Ui->getLocation()));
}
Field3D Neutrals::getElectronVelocitySource() const {
ASSERT2(Ue != nullptr);
Field3D tmp = gamma_ion / (*n);
return -(*Ue) * (interp_to(tmp, Ue->getLocation()));
}
Field3D Neutrals::getDensitySource() const { return gamma_ion - gamma_rec; }
Field3D Neutrals::getElectronTemperatureSource() const {
ASSERT2(Ue != nullptr);
ASSERT2(Te != nullptr);
ASSERT2(mu > 0);
Field3D rec_over_n = gamma_rec / (*n);
Field3D ion_over_n = gamma_ion / (*n);
Field3D result = rec_over_n * interp_to(SQ(*Ue), Te->getLocation()) / (3. * mu);
// We do not need this term, as we are asking for a change in temperature.
// The particles that go, change the pressure, but also the density
// - while keeping the temperature constant.
// result += (*Te) * (rec_over_n );
// Ionized particles have the temperature of the background gas.
// Thus they contribute the temperature difference times the rates
// over n (i.e. relative importance)
result += (-(*Te)) * ion_over_n;
// Charge exchange cooles the plasma as well
result += (-(*Te)) * gamma_CX / (*n);
result += -(1.09 * (*Te) - 13.6 * SI::qe / unit->getTemperature()) * rec_over_n -
30 * SI::qe / unit->getTemperature() * ion_over_n;
return result;
}
Field3D Neutrals::getVorticitySource() const {
ASSERT2(phi != nullptr);
auto tmp = -Delp2(*phi) * (gamma_CX + gamma_ion) -
Grad_perp(*phi) * Grad_perp(gamma_CX + gamma_ion);
if (vort_source_fac != 1.) {
tmp *= vort_source_fac;
}
return tmp;
}
std::unique_ptr<Neutrals> NeutralsFactory::create(Solver *solver, Mesh *mesh,
Options *options) {
std::string type;
std::unique_ptr<Neutrals> ret;
OPTION(options, type, "NotSet");
CrossSection *cs = CrossSectionFactory::create(options);
if (type == "diffusion") {
ret = std::unique_ptr<Neutrals>(new DiffusionNeutrals(solver, mesh, cs, options));
} else if (type == "parallel") {
ret = std::unique_ptr<Neutrals>(new ParallelNeutrals(solver, mesh, cs, options));
} else if (type == "none") {
ret = std::unique_ptr<Neutrals>(new NoNeutrals(solver, mesh, cs, options));
} else {
delete cs;
throw BoutException("unknow neutrals model '%s'", type.c_str());
}
ret->type = type;
output.write("************************************"
"**********************************\n");
return ret;
}
std::unique_ptr<Neutrals> NeutralsFactory::create(Solver *solver, Mesh *mesh,
std::string options) {
return create(solver, mesh, Options::getRoot()->getSection(options));
}