-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlasma.cpp
More file actions
623 lines (564 loc) · 22.1 KB
/
Copy pathPlasma.cpp
File metadata and controls
623 lines (564 loc) · 22.1 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
/*
Written by: Daniel Duque and Clementine Domine
Last modified on 10 Dec 2019
Definitions for the Plasma class
This file contains a corresponding source file.
*/
#include"Plasma.hpp"
#include<iostream>
#include<fstream>
MacroRing::MacroRing(int r, double z, double aSpeed) : posR(r), posZ(z), speed(aSpeed)
{
}
MacroRing::~MacroRing()
{
}
int MacroRing::getR() const
{
return posR;
}
double MacroRing::getZ() const
{
return posZ;
}
double MacroRing::getSpeed() const
{
return speed;
}
void MacroRing::setZ(double newZ)
{
posZ = newZ;
}
void MacroRing::setSpeed(double newSpeed)
{
speed = newSpeed;
}
void MacroRing::saveState()
{
historyZ.push_back(posZ);
historySpeed.push_back(speed);
}
void MacroRing::reserve(int desired)
{
historyZ.reserve(desired);
historySpeed.reserve(desired);
}
void MacroRing::printPositions(std::ofstream& file) const
{
if (!historyZ.empty())
{
file << posR;
file << ",";
for (unsigned int i = 0; i < historyZ.size() - 1; ++i)
{
file << historyZ[i] << ",";
}
file << historyZ.back() << "\n";
}
}
void MacroRing::printSpeeds(std::ofstream& file) const
{
for (unsigned int i = 0; i < historySpeed.size(); ++i)
{
file << historySpeed[i];
i < historySpeed.size() - 1 ? file << "," : file << "\n";
}
}
/*----------------------------------------------------------------------------------------------------------
Plasma class
----------------------------------------------------------------------------------------------------------*/
Plasma::Plasma(PenningTrap& trap, std::string aName, double aMass, double aCharge)
: refTrap(trap) , name(aName), mass(aMass), charge(aCharge)
{
refTrap.addPlasma(*this);
}
Plasma::~Plasma()
{
//Should remove itself from the plasma, look later into this
}
void Plasma::updateRHS()
{
//The RHS is: (minus) chargeDensity/epsilon
//Performs a First-order weighting (Area weighting)
RHS.setZero(refTrap.Nz * refTrap.Nr + refTrap.Nr);
double hr{ refTrap.hr };
double hz{ refTrap.hz };
for (const MacroRing& aRing : rings)
{
int indexR{ aRing.getR() };
int indexZ{ (int)floor(aRing.getZ() / hz) };
int indexRHS{ (refTrap.Nz + 1) * indexR + indexZ };
double z{ aRing.getZ() - indexZ * hz };//Distance from left grid point to particle
double weightFactor{ z / hz };//Weight going to grid point on the right (number between 0 and 1)
double volume; //Volume of the MacroRing
if (indexR == 0)
{
volume = PI * hz * hr * hr / 4;
}
else
{
volume = hz * hr * 2 * PI * indexR * hr;
}
double specificCharge{aRing.getR() == 0 ? chargeMacro : 8 * chargeMacro * aRing.getR()};
RHS.coeffRef(indexRHS) += -specificCharge * (1 - weightFactor) / (volume * epsilon);//Point to the left
RHS.coeffRef(indexRHS + 1) += -specificCharge* weightFactor / (volume * epsilon);//Point to the right
}
}
void Plasma::solvePoisson()
{
updateRHS();
selfPotential = refTrap.solver.solve(RHS);
}
void Plasma::moveRings(double deltaT)
{
for (unsigned int i = 0; i < rings.size(); )
{
//Leapfrog method
double specificCharge{rings[i].getR() == 0 ? chargeMacro : 8 * chargeMacro * rings[i].getR()};
double specificMass{rings[i].getR() == 0 ? massMacro : 8 * massMacro * rings[i].getR()};
double forceOld{ specificCharge * refTrap.getEField(rings[i].getR(), rings[i].getZ()) };
double vNew{ deltaT * forceOld / specificMass + rings[i].getSpeed() };
double zNew{ deltaT * vNew + rings[i].getZ() };
//remove elements than escape the trap
if (zNew < refTrap.getLength() && zNew > 0)
{
rings[i].setZ(zNew);
rings[i].setSpeed(vNew);
++i;
}
else
{
std::swap(rings[i], rings.back());//check that this std::swap works efficiently as expected
rings.pop_back();
}
}
}
void Plasma::extractSelfPotential(std::string fileName) const
{
Eigen::IOFormat fastFullPrecision(Eigen::FullPrecision, Eigen::DontAlignCols, "", "\n", "", "", "", "");
std::ofstream newFile;
newFile.open(fileName);
newFile << selfPotential.format(fastFullPrecision);
newFile.close();
}
void Plasma::extractPlasmaParameters(std::string fileName) const
{
std::ofstream newFile;
newFile.open(fileName);
newFile << mass << '\n';
newFile << charge << '\n';
newFile << massMacro << '\n';
newFile << chargeMacro;
newFile.close();
}
void Plasma::extractHistory(std::string preName) const
{
std::ofstream newPositions, newSpeeds;
newPositions.open(preName + "Positions" + name + ".csv");
newSpeeds.open(preName + "Speeds" + name + ".csv");
for (const MacroRing& aRing : rings)
{
aRing.printPositions(newPositions);
aRing.printSpeeds(newSpeeds);
}
newPositions.close();
newSpeeds.close();
}
void Plasma::saveState()
{
for (MacroRing& aRing : rings)
{
aRing.saveState();
}
}
void Plasma::reserve(int desired)
{
for (MacroRing& aRing : rings)
{
aRing.reserve(desired);
}
}
void Plasma::loadOneDUniform(int numMacro, double aChargeMacro, double lengthLine, int r)
{
//Creates equally spaced charges at r = 0 along a centred line of length lengthLine
if (lengthLine >= refTrap.getLength() || r >= refTrap.Nr - 1)
{
throw std::logic_error("Length of charge must be less than the length of the trap and r inside the trap");
}
if (aChargeMacro * charge < 0)
{
throw std::logic_error("Charge of MacroRing and the plasma type must have the same sign");
}
chargeMacro = aChargeMacro;
massMacro = mass * chargeMacro / charge;
rings.clear();
rings.reserve(numMacro);
//Divide lengthLine in numMacro + 1 cells, which corresponds to numMacro + 2 points
//Put the particles along the points except for the first and last point
double start{ (refTrap.getLength() - lengthLine) / 2 };
double hz{ lengthLine / (numMacro + 1) };
for (int i = 1; i <= numMacro; ++i)
{
rings.push_back(MacroRing(r, start + i * hz, 0));
}
solvePoisson();
}
void Plasma::loadSingleRing(double aChargeMacro, int r, double Z, double speed)
{
if (Z >= refTrap.getLength() || Z <= 0 || r >= refTrap.Nr - 1)
{
throw std::logic_error("Input r,z is not inside the trap");
}
if (aChargeMacro * charge < 0)
{
throw std::logic_error("Charge of MacroRing and the plasma type must have the same sign");
}
massMacro = mass * chargeMacro/ charge;
rings.clear();
rings.push_back(MacroRing(r, Z, speed));
solvePoisson();
}
std::vector<double> Plasma::getselfpotential11(double Z)
{ std::vector<double> SPE;
for (int i = 0; i < refTrap.Nr-1; ++i)
{ int indexZ{ (int)floor(Z/ refTrap.hz) };
loadSingleRing( -100 * ePos, i, indexZ*refTrap.hz, 0);
double spe= selfPotential(indexZ+(i*(refTrap.Nz+1)));
SPE.push_back(spe);
}
return SPE;
}
std::vector<double> Plasma::getselfpotential12(double Z)
{ std::vector<double> SPE12;
for (int i = 0; i < refTrap.Nr-1; ++i)
{int indexZ{ (int)floor(Z/ refTrap.hz) };
loadSingleRing( -100 * ePos, i, indexZ*refTrap.hz, 0);
double spe= selfPotential((indexZ+1)+(i*(refTrap.Nz+1)));
SPE12.push_back(spe);
}
return SPE12;
}
void Plasma::extractselfpotential11 (std::string fileName, double Z)
{
std::ofstream newFile;
newFile.open(fileName);
std::vector<double> a;
a = getselfpotential11(Z);
for (unsigned int i = 0; i < a.size(); ++i)
{
newFile << a[i];
i < a.size() - 1 ? newFile << "," : newFile << "\n";
}
newFile.close();
}
void Plasma::extractselfpotential12 (std::string fileName, double Z)
{
std::ofstream newFile;
newFile.open(fileName);
std::vector<double> a;
a = getselfpotential12(Z);
for (unsigned int i = 0; i < a.size(); ++i)
{
newFile << a[i];
i < a.size() - 1 ? newFile << "," : newFile << "\n";
}
newFile.close();
}
std::vector<double> Plasma::gettotalpotentialenergy(int r,double Z){
std::vector<double> Potentialenergy;
double ps11 = getselfpotential11(Z)[r];
double ps12 = getselfpotential12(Z)[r];
loadOneDUniform(10000, -100 * ePos, 0.01, 0);
for (const MacroRing& aRing : rings)
{
int indexZ{ (int)floor(aRing.getZ() / refTrap.hz) };
double dz{ aRing.getZ() - indexZ * refTrap.hz };
double weightFactor{ dz / refTrap.hz };
double ps = (pow((1 - weightFactor),2)+pow((weightFactor),2))*ps11+2*((1 - weightFactor)* weightFactor * ps12);
double phiselfleft = selfPotential(indexZ+(r*(refTrap.Nz+1)));
double phiselftright = selfPotential(indexZ+1+(r*(refTrap.Nz+1)));
double phiT= phiselfleft*(1 - weightFactor)+phiselftright*(weightFactor);//Point to the left
double phitrapleft =refTrap.potentialsVector(indexZ+(r*(refTrap.Nz+1)));
double phitrapright =refTrap.potentialsVector(indexZ+1+(r*(refTrap.Nz+1)));
double phiTraptot= phitrapleft*(1 - weightFactor)+phitrapright*(weightFactor);//Point to the left
double specificCharge{r== 0 ? chargeMacro : 8 * chargeMacro * r};
double phireal= specificCharge*(ps);
Potentialenergy.push_back(phireal);
}
return Potentialenergy;
}
void Plasma::extracttotalpotentialenergy(std::string fileName, int r,double Z)
{
std::ofstream newFile;
newFile.open(fileName);
std::vector<double> b;
b = gettotalpotentialenergy(r,Z);
for (unsigned int i = 0; i < b.size(); ++i)
{
newFile << b[i];
i < b.size() - 1 ? newFile << "," : newFile << "\n";
}
newFile.close();
}
void Plasma::estimateDensityProportions()
{
int pointsZ = refTrap.Nz + 1;
int pointsR = refTrap.Nr;
//For each grid point, estimate density from Total Potential
for (int indexR = 0; indexR < pointsR; ++indexR)
{
double phiCentralR{ refTrap.getTotalPhi(indexR, refTrap.lengthTrap / 2) };
for (int indexZ = 0; indexZ < pointsZ; ++indexZ)
{
initialDensity2.coeffRef(pointsZ * indexR + indexZ) = exp(-(charge / (KB * temperature)) * (refTrap.getTotalPhi(indexR, indexZ) - phiCentralR));
}
}
}
void Plasma::fitDensityProportionToProfile( double n, double b)
{
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
double initialDensity2normvalue {0};
for (int indexZ = 0; indexZ < (refTrap.Nz + 1); ++indexZ)
{
//Convert from volume density into flat space density
initialDensity2normvalue += initialDensity2.coeffRef((refTrap.Nz +1)* indexR + indexZ) * refTrap.hz;
}
//this number becomes very big
double Factornorm2 = ((exp(-pow((indexR* refTrap.hr *1000 /b),n))/initialDensity2normvalue));
//This 1000 is because the profile is given in milimeters
for (int indexZ = 0; indexZ < (refTrap.Nz + 1 ); ++indexZ)
{
initialDensity2.coeffRef((refTrap.Nz + 1 )* indexR + indexZ) *= Factornorm2;
}
}
}
void Plasma::normalizeDensityToTotalCharge()
{ double volume ;
double currentCharge{ 0 };
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
//First calculate what the total charge is right now
if (indexR== 0)//Volume of the MacroRing
{
volume = PI * refTrap.hz * refTrap.hr * refTrap.hr / 4;
}
else
{
volume =refTrap.hz * refTrap.hr* 2 * PI * indexR * refTrap.hr;
}
for (int indexZ = 0; indexZ < (refTrap.Nz + 1 ); ++indexZ)
{
currentCharge += (initialDensity2.coeffRef((refTrap.Nz + 1)* indexR + indexZ) * volume);
}
}
//Now multiply every density by the appropriate correction to get the expected total charge
double correction= totalCharge/currentCharge;
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
for (int indexZ = 0; indexZ < refTrap.Nz+1; ++indexZ)
{
initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ) *= correction;
}
}
}
void Plasma::estimateDensityProportions2()
{
int pointsZ = refTrap.Nz + 1;
int pointsR = refTrap.Nr;
//For each grid point, estimate density from Total Potential
for (int indexR = 0; indexR < pointsR; ++indexR)
{
double phiCentralR{ refTrap.getTotalPhi(indexR, refTrap.lengthTrap / 2) };
for (int indexZ = 0; indexZ < pointsZ; ++indexZ)
{
initialDensity4.coeffRef(pointsZ * indexR + indexZ) = exp(-(charge / (KB * temperature)) * (refTrap.getTotalPhi(indexR, indexZ) - phiCentralR));
}
}
}
void Plasma::fitDensityProportionToProfile2( double n, double b)
{
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
double initialDensity4normvalue {0};
for (int indexZ = 0; indexZ < (refTrap.Nz + 1); ++indexZ)
{
//Convert from volume density into flat space density
initialDensity4normvalue += initialDensity4.coeffRef((refTrap.Nz +1)* indexR + indexZ) * refTrap.hz;
}
//this number becomes very big
double Factornorm2 = ((exp(-pow((indexR* refTrap.hr *1000 /b),n))/initialDensity4normvalue));
//This 1000 is because the profile is given in milimeters
for (int indexZ = 0; indexZ < (refTrap.Nz + 1 ); ++indexZ)
{
initialDensity4.coeffRef((refTrap.Nz + 1 )* indexR + indexZ) *= Factornorm2;
}
}
}
void Plasma::normalizeDensityToTotalCharge2()
{ double volume ;
double currentCharge{ 0 };
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
//First calculate what the total charge is right now
if (indexR== 0)//Volume of the MacroRing
{
volume = PI * refTrap.hz * refTrap.hr * refTrap.hr / 4;
}
else
{
volume =refTrap.hz * refTrap.hr* 2 * PI * indexR * refTrap.hr;
}
for (int indexZ = 0; indexZ < (refTrap.Nz + 1 ); ++indexZ)
{
currentCharge += (initialDensity4.coeffRef((refTrap.Nz + 1)* indexR + indexZ) * volume);
}
}
//Now multiply every density by the appropriate correction to get the expected total charge
double correction= totalCharge/currentCharge;
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
for (int indexZ = 0; indexZ < refTrap.Nz+1; ++indexZ)
{
initialDensity4.coeffRef((refTrap.Nz+1)* indexR + indexZ) *= correction;
}
}
}
//the variance is not used to decide th enumber of iteration in the loop
//n0 density at the center, N number of particles , a b and n paramter of the radial fit.
void Plasma::loadProfile( double aTotalcharge, double b, double n,double aTemperature)
{
//Check input makes sense
if (aTemperature <= 0|| n <= 0 || b <= 0)
{
throw std::logic_error("Temperature, shape, and scale all need to be positive");
}
if (aTotalcharge *charge < 0)
{
throw std::logic_error("Total charge and the plasma type charge must have the same sign");
}
temperature = aTemperature;
totalCharge = aTotalcharge;
//Declaration and Initialisation of the variables
double C=0.997;
// Factor for normalisation for th radial profil with n0 in center
initialDensity1.setZero(refTrap.Nz * refTrap.Nr + refTrap.Nr);
initialDensity2.setZero(refTrap.Nz * refTrap.Nr + refTrap.Nr);
initialDensity3.setZero(refTrap.Nz * refTrap.Nr + refTrap.Nr);
//Solve Poisson's equation for the charge density
//Then estimate a thermal equilibrium density from that potential (normalized to totalCharge). Should add a double return here, to get how much it changed
//Tune the obtained density according to the expected profile
//Repeat until it is both self consistent and in agreement with expected profile
//Change this for a do while loop after you have figured out what conditions to impose to decide wether to repeat or not
// Start iteration procedure
var=1e6;
var1=0;
var2=0;
double x2;
double x;
//int numIterations{10000};
//for (int i = 0; i < numIterations; ++i)
do{
//Format the density as the right hand side of Poissons equation
for (int j = 0; j < refTrap.Nz * refTrap.Nr + refTrap.Nr; ++j)
{
initialDensity1.coeffRef(j) = -initialDensity1.coeffRef(j) / epsilon;
}
//Solve Poisson's equation using Denstiy1
selfPotential = refTrap.solver.solve(initialDensity1);
//first estimate the proportions based on thermal equilibrium assumption
estimateDensityProportions();
//Then weight them appropriately to match the given profile
fitDensityProportionToProfile(n, b);
normalizeDensityToTotalCharge();
//Calculate the new estimate as the linear combination of the orginal density1 and the first estimate of the density2
x=0;
x2=0;
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
for (int indexZ = 0; indexZ < refTrap.Nz+1; ++indexZ)
{
x2 += pow((-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ))-initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ),2)*indexR;
x += pow((-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ)),2)+(pow(initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ),2))*indexR;
initialDensity3.coeffRef((refTrap.Nz+1)* indexR + indexZ) =((C)*(-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ)))+(1-C)*initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ);
}
}
var1= x2/x;
for (int j = 0; j < refTrap.Nz * refTrap.Nr + refTrap.Nr; ++j)
{
initialDensity3.coeffRef(j) = -initialDensity3.coeffRef(j) / epsilon;
}
//Solve Poisson's equation using Denstiy1
selfPotential = refTrap.solver.solve(initialDensity3);
estimateDensityProportions2();
//Then weight them appropriately to match the given profile
fitDensityProportionToProfile2(n, b);
normalizeDensityToTotalCharge2();
x=0;
x2=0;
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
for (int indexZ = 0; indexZ < refTrap.Nz+1; ++indexZ)
{
x2 += pow((-epsilon*initialDensity3.coeffRef((refTrap.Nz+1)* indexR + indexZ))-initialDensity4.coeffRef((refTrap.Nz+1)* indexR + indexZ),2)*indexR;
x += pow((-epsilon*initialDensity3.coeffRef((refTrap.Nz+1)* indexR + indexZ)),2)+pow(initialDensity4.coeffRef((refTrap.Nz+1)* indexR + indexZ),2)*indexR;
// initialDensity3.coeffRef((refTrap.Nz+1)* indexR + indexZ) =((C)*(-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ)))
// +(1-C)*initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ);
}
}
var2= x2/x;
if (var2>var1)
{
C=C*0.99999999997;
}
if(var2<var1)
{
C=C*1.0000000003;
}
x=0;
x2=0;
for (int indexR = 0; indexR < refTrap.Nr; ++indexR)
{
for (int indexZ = 0; indexZ < refTrap.Nz+1; ++indexZ)
{
x2 += pow((-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ))-initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ),2)*indexR;
x += pow((-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ)),2)+(pow(initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ),2))*indexR;
initialDensity5.coeffRef((refTrap.Nz+1)* indexR + indexZ) =((C)*(-epsilon*initialDensity1.coeffRef((refTrap.Nz+1)* indexR + indexZ)))+(1-C)*initialDensity2.coeffRef((refTrap.Nz+1)* indexR + indexZ);
}
}
extractInitialDensitybinary("Daniel.dat");
var=x2/x;
for (int j = 0; j < refTrap.Nz * refTrap.Nr + refTrap.Nr; ++j)
{
initialDensity1.coeffRef(j) = initialDensity5.coeffRef(j);
}
} while (var>1e-1);
}
void Plasma::extractInitialDensity(std::string fileName) const
{
Eigen::IOFormat fastFullPrecision(Eigen::FullPrecision, Eigen::DontAlignCols, "", "\n", "", "", "", "");
std::ofstream newFile;
newFile.open(fileName);
newFile << initialDensity5.format(fastFullPrecision);
newFile.close();
}
void Plasma::extractInitialDensitybinary(std::string fileName) const
{
Eigen::IOFormat fastFullPrecision(Eigen::FullPrecision, Eigen::DontAlignCols, "", "\n", "", "", "", "");
std::ofstream newFile(fileName, std::ios::out | std::ios::binary);
if(!newFile)
{
throw std::logic_error( "Cannot open file!");
}
newFile.open(fileName);
for(int i = 0; i < 3; i++)
for (int j = 0; j < refTrap.Nz * refTrap.Nr + refTrap.Nr; ++j)
{
newFile.write((char *) &initialDensity5.coeffRef(j), sizeof(initialDensity5.coeffRef(j))); //not sure what I want to write there
}
newFile.close();
if(!newFile.good())
{
throw std::logic_error("Error occurred at writing time!");
}
}