chombo-discharge
Loading...
Searching...
No Matches
CD_DischargeInceptionStepperImplem.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022-2026 SINTEF Energy Research
3 * SPDX-FileCopyrightText: 2022-2026 NTNU
4 * SPDX-FileCopyrightText: 2022-2026 Fanny Skirbekk
5 *
6 * SPDX-License-Identifier: GPL-3.0-or-later
7 */
8
16
17#ifndef CD_DISCHARGEINCEPTIONSTEPPERIMPLEM_H
18#define CD_DISCHARGEINCEPTIONSTEPPERIMPLEM_H
19
20// Std includes
21#include <iostream>
22#include <fstream>
23
24// Chombo includes
25#include <CH_Timer.H>
26
27// Our includes
28#include <CD_Units.H>
29#include <CD_OpenMP.H>
30#include <CD_ParticleLoops.H>
33#include <CD_PolyUtils.H>
34#include <CD_NamespaceHeader.H>
35
36using namespace Physics::DischargeInception;
37
38template <typename P, typename F, typename C>
40{
41 CH_TIME("DischargeInceptionStepper::DischargeInceptionStepper");
42 if (m_verbosity > 5) {
43 pout() << "DischargeInceptionStepper::DischargeInceptionStepper" << endl;
44 }
45
46 // Default settings.
47 m_verbosity = -1;
53 m_profile = false;
54 m_debug = false;
55 m_fullIntegration = false;
56 m_evaluateTownsend = false;
57 m_relativeDeltaU = 1 + 0.05;
58 m_deltaK = 1.0;
59 m_maxKLimit = 15.0;
60
61 this->parseOptions();
62
63 m_rho = [](const RealVect x) -> Real {
64 return 0.0;
65 };
66
67 m_sigma = [](const RealVect x) -> Real {
68 return 0.0;
69 };
70
71 m_alpha = [](const Real E, const RealVect x) -> Real {
72 return 0.0;
73 };
74
75 m_eta = [](const Real E, const RealVect x) -> Real {
76 return 0.0;
77 };
78
79 m_voltageCurve = [](const Real a_time) -> Real {
80 return 1.0;
81 };
82
83 m_backgroundRate = [](const Real E, const RealVect x) -> Real {
84 return 0.0;
85 };
86
87 m_detachmentRate = [](const Real E, const RealVect x) -> Real {
88 return 0.0;
89 };
90
91 m_fieldEmission = [](const Real E, const RealVect x) -> Real {
92 return 0.0;
93 };
94
95 m_secondaryEmission = [](const Real E, const RealVect x) -> Real {
96 return 0.0;
97 };
98
99 m_initialIonDensity = [](const RealVect x) -> Real {
100 return 0.0;
101 };
102
103 m_ionMobility = [](const Real E) -> Real {
104 return 0.0;
105 };
106
107 m_ionDiffusion = [](const Real E) -> Real {
108 return 0.0;
109 };
110}
111
112template <typename P, typename F, typename C>
114{
115 CH_TIME("DischargeInceptionStepper::~DischargeInceptionStepper");
116 if (m_verbosity > 5) {
117 pout() << "DischargeInceptionStepper::~DischargeInceptionStepper" << endl;
118 }
119}
120
121template <typename P, typename F, typename C>
122void
124{
125 CH_TIME("DischargeInceptionStepper::setupSolvers");
126 if (m_verbosity > 5) {
127 pout() << "DischargeInceptionStepper::setupSolvers" << endl;
128 }
129
130 // Always solve for the field using a voltage of one (and then scale up/down later on)
131 auto voltage = [](const Real a_time) -> Real {
132 return 1.0;
133 };
134
135 // Instantiate the field solver.
136 m_fieldSolver = RefCountedPtr<FieldSolver>(new F());
137 m_fieldSolver->setVerbosity(m_verbosity);
138 m_fieldSolver->parseOptions();
139 m_fieldSolver->setAmr(m_amr);
140 m_fieldSolver->setComputationalGeometry(m_computationalGeometry);
141 m_fieldSolver->setVoltage(voltage);
142 m_fieldSolver->setRealm(m_realm);
143 m_fieldSolver->setTime(0, 0.0, 0.0);
144
145 // Instantiate the tracer particle solver.
146 m_tracerParticleSolver = RefCountedPtr<TracerParticleSolver<P>>(new TracerParticleSolver<P>());
147 m_tracerParticleSolver->parseOptions();
149 m_tracerParticleSolver->setComputationalGeometry(m_computationalGeometry);
152 m_tracerParticleSolver->setTime(0, 0.0, 0.0);
153 m_tracerParticleSolver->setName("Tracer particle solver");
154 m_tracerParticleSolver->setVolumeScale(true);
155 m_tracerParticleSolver->setDeposition(DepositionType::NGP);
156
157 // Instantiate the ion solver.
158 m_ionSolver = RefCountedPtr<CdrSolver>(new C());
159
160 m_ionSolver->parseOptions();
161 m_ionSolver->setPhase(m_phase);
162 m_ionSolver->setAmr(m_amr);
163 m_ionSolver->setComputationalGeometry(m_computationalGeometry);
164 m_ionSolver->setRealm(m_realm);
165
166 auto species = RefCountedPtr<CdrSpecies>(new DischargeInceptionSpecies(m_initialIonDensity, true, true));
167
168 m_ionSolver->setSpecies(species);
169}
170
171template <typename P, typename F, typename C>
172void
174{
175 CH_TIME("DischargeInceptionStepper::allocate");
176 if (m_verbosity > 5) {
177 pout() << "DischargeInceptionStepper::allocate" << endl;
178 }
179
180 m_fieldSolver->allocate();
181 m_tracerParticleSolver->allocate();
182 m_ionSolver->allocate();
183
184 // Needed for all modes.
185 m_amr->allocate(m_potential, m_realm, 1);
186 m_amr->allocate(m_potentialHomo, m_realm, 1);
187 m_amr->allocate(m_potentialInho, m_realm, 1);
188
189 m_amr->allocate(m_electricField, m_realm, SpaceDim);
190 m_amr->allocate(m_electricFieldHomo, m_realm, SpaceDim);
191 m_amr->allocate(m_electricFieldInho, m_realm, SpaceDim);
192
193 m_amr->allocate(m_gradAlpha, m_realm, m_phase, SpaceDim);
194
197
198 switch (m_mode) {
199 case Mode::Stationary: {
206
213
214 break;
215 }
216 case Mode::Transient: {
219 m_amr->allocate(m_emissionRate, m_realm, m_phase, 1);
221 m_amr->allocate(m_detachment, m_realm, m_phase, 1);
222
228
229 break;
230 }
231 default: {
232 break;
233 }
234 }
235}
236
237template <typename P, typename F, typename C>
238void
240{
241 CH_TIME("DischargeInceptionStepper::initialData");
242 if (m_verbosity > 5) {
243 pout() << "DischargeInceptionStepper::initialData" << endl;
244 }
245
246 this->solvePoisson();
247}
248
249template <typename P, typename F, typename C>
250void
252{
253 CH_TIME("DischargeInceptionStepper::solvePoisson");
254 if (m_verbosity > 5) {
255 pout() << "DischargeInceptionStepper::solvePoisson" << endl;
256 }
257
258 // Solve for the inhomogeneous part
259 m_fieldSolver->setRho(m_rho);
260 m_fieldSolver->setSigma(m_sigma);
261 m_fieldSolver->setVoltage([](const Real& a_time) {
262 return 0.0;
263 });
264
265 // Solve using our m_potentialInho as an initial guess.
267 const bool convergedInho = m_fieldSolver->solve(m_fieldSolver->getPotential(),
268 m_fieldSolver->getRho(),
269 m_fieldSolver->getSigma(),
270 false);
271
272 if (!convergedInho) {
273 MayDay::Warning("DischargeInceptionStepper::solvePoisson -- could not solve the inhomogeneous Poisson equation. ");
274 }
275
277 DataOps::copy(m_electricFieldInho, m_fieldSolver->getElectricField());
278
279 // Solve for the homogeneous part
280 m_fieldSolver->setRho([](const RealVect& a_pos) {
281 return 0.0;
282 });
283 m_fieldSolver->setSigma([](const RealVect& a_pos) {
284 return 0.0;
285 });
286 m_fieldSolver->setVoltage([](const Real& a_time) {
287 return 1.0;
288 });
289
291 const bool convergedHomo = m_fieldSolver->solve(m_fieldSolver->getPotential(),
292 m_fieldSolver->getRho(),
293 m_fieldSolver->getSigma(),
294 false);
295
296 if (!convergedHomo) {
297 MayDay::Warning("DischargeInceptionStepper::solvePoisson -- could not solve the homogeneous Poisson equation. ");
298 }
299
301 DataOps::copy(m_electricFieldHomo, m_fieldSolver->getElectricField());
302
303 // Alias the field to send to the cell tagger
305
306 if (m_debug) {
307
308 // Do a dummy check if the homogeneous and inhomogeneous solutions with a potential of one, and check that the
309 // difference is "sufficiently small"
310 const Real testVoltage = 1.0;
311 const Real errorThresh = 1.E-6;
312
313 // This is the sum of the two potentials
317
318 // Do a true solution with a test voltage and space/surface charge.
319 auto voltage = [V = testVoltage](const Real& a_time) {
320 return V;
321 };
322
323 DataOps::copy(m_fieldSolver->getPotential(), m_potential);
324
325 m_fieldSolver->setRho(m_rho);
326 m_fieldSolver->setSigma(m_sigma);
327 m_fieldSolver->setVoltage(voltage);
328 m_fieldSolver->solve(m_fieldSolver->getPotential(), m_fieldSolver->getRho(), m_fieldSolver->getSigma(), false);
329
330 // Do the difference between the two potentials and figure out the max error. It should be < 1.E-6 * testVoltage
331 DataOps::incr(m_potential, m_fieldSolver->getPotential(), -1.0);
332
333 EBAMRCellData phiGas = m_amr->alias(phase::gas, m_potential);
334
335 Real max;
336 Real min;
337
338 DataOps::getMaxMin(max, min, phiGas, 0, m_amr->getMultiCutVofIterator(m_realm, m_phase));
339
340 if (std::max(std::abs(max), std::abs(min)) > errorThresh * testVoltage) {
341 MayDay::Error("DischargeInceptionStepper::solvePoisson - debug test failed. Check your BCs!");
342 }
343 }
344}
345
346template <typename P, typename F, typename C>
347void
349{
350 CH_TIME("DischargeInceptionStepper::registerRealms");
351 if (m_verbosity > 5) {
352 pout() << "DischargeInceptionStepper::registerRealms" << endl;
353 }
354
355 m_amr->registerRealm(m_realm);
356}
357
358template <typename P, typename F, typename C>
359void
361{
362 CH_TIME("DischargeInceptionStepper::registerOperators");
363 if (m_verbosity > 5) {
364 pout() << "DischargeInceptionStepper::registerOperators" << endl;
365 }
366
367 m_fieldSolver->registerOperators();
368 m_tracerParticleSolver->registerOperators();
369 m_ionSolver->registerOperators();
370}
371
372template <typename P, typename F, typename C>
373void
375{
376 CH_TIME("DischargeInceptionStepper::parseOptions");
377
378 this->parseVerbosity();
379 this->parseMode();
380 this->parseVoltages();
381 this->parseOutput();
382 this->parsePlotVariables();
385}
386
387template <typename P, typename F, typename C>
388void
390{
391 CH_TIME("DischargeInceptionStepper::parseRuntimeOptions");
392 if (m_verbosity > 5) {
393 pout() << "DischargeInceptionStepper::parseRuntimeOptions" << endl;
394 }
395
396 this->parseVerbosity();
397 this->parsePlotVariables();
400}
401
402template <typename P, typename F, typename C>
403void
405{
406 CH_TIME("DischargeInceptionStepper::parseVerbosity");
407 if (m_verbosity > 5) {
408 pout() << "DischargeInceptionStepper::parseVerbosity" << endl;
409 }
410
411 ParmParse pp("DischargeInceptionStepper");
412 pp.get("verbosity", m_verbosity);
413 pp.get("profile", m_profile);
414 pp.query("debug", m_debug);
415}
416
417template <typename P, typename F, typename C>
418void
420{
421 CH_TIME("DischargeInceptionStepper::parseMode");
422 if (m_verbosity > 5) {
423 pout() << "DischargeInceptionStepper::parseMode" << endl;
424 }
425
426 ParmParse pp("DischargeInceptionStepper");
427
428 std::string str;
429
430 pp.get("mode", str);
431 if (str == "stationary") {
433 }
434 else if (str == "transient") {
436 }
437 else {
438 MayDay::Error("Expected 'none', 'stationary', or 'transient' for 'DischargeInceptionStepper.mode'");
439 }
440}
441
442template <typename P, typename F, typename C>
443void
445{
446 CH_TIME("DischargeInceptionStepper::parseVoltages");
447 if (m_verbosity > 5) {
448 pout() << "DischargeInceptionStepper::parseVoltages" << endl;
449 }
450
451 ParmParse pp("DischargeInceptionStepper");
452
453 pp.get("rel_step_dU", m_relativeDeltaU);
454 pp.get("step_dK", m_deltaK);
455 pp.get("limit_max_K", m_maxKLimit);
456 pp.get("K_inception", m_inceptionK);
457 pp.get("eval_townsend", m_evaluateTownsend);
458
460}
461
462template <typename P, typename F, typename C>
463void
465{
466 CH_TIME("DischargeInceptionStepper::parseOutput");
467 if (m_verbosity > 5) {
468 pout() << "DischargeInceptionStepper::parseOutput" << endl;
469 }
470
471 ParmParse pp("DischargeInceptionStepper");
472
473 pp.get("output_file", m_outputFile);
474}
475
476template <typename P, typename F, typename C>
477void
479{
480 CH_TIME("DischargeInceptionStepper::parseInceptionAlgorithm");
481 if (m_verbosity > 5) {
482 pout() << "DischargeInceptionStepper::parseInceptionAlgorithm" << endl;
483 }
484
485 ParmParse pp("DischargeInceptionStepper");
486
487 std::string str;
488
489 // Get the inception algorithm
490 pp.get("full_integration", m_fullIntegration);
491 pp.get("inception_alg", str);
492 if (str == "euler") {
494 }
495 else if (str == "trapz") {
497 }
498 else {
499 MayDay::Error("Expected 'euler' or 'trapz' for 'DischargeInceptionStepper.inception_alg'");
500 }
501
502 pp.get("min_phys_dx", m_minPhysDx);
503 pp.get("max_phys_dx", m_maxPhysDx);
504 pp.get("min_grid_dx", m_minGridDx);
505 pp.get("max_grid_dx", m_maxGridDx);
506 pp.get("alpha_dx", m_alphaDx);
507 pp.get("grad_alpha_dx", m_gradAlphaDx);
508 pp.get("townsend_grid_dx", m_townsendGridDx);
509
510 if (m_minPhysDx <= 0.0) {
511 MayDay::Abort("DischargeInceptionStepper.min_phys_dx must be > 0.0");
512 }
513 if (m_maxPhysDx <= 0.0) {
514 MayDay::Abort("DischargeInceptionStepper.max_phys_dx must be > 0.0");
515 }
516 if (m_minGridDx <= 0.0) {
517 MayDay::Abort("DischargeInceptionStepper.min_grid_dx must be > 0.0");
518 }
519 if (m_maxGridDx <= 0.0) {
520 MayDay::Abort("DischargeInceptionStepper.max_grid_dx must be > 0.0");
521 }
522 if (m_alphaDx <= 0.0) {
523 MayDay::Abort("DischargeInceptionStepper.alpha_dx must be > 0.0");
524 }
525 if (m_gradAlphaDx <= 0.0) {
526 MayDay::Abort("DischargeInceptionStepper.grad_alpha_dx must be > 0.0");
527 }
528 if (m_townsendGridDx <= 0.0) {
529 MayDay::Abort("DischargeInceptionStepper.townsend_grid_dx must be > 0.0");
530 }
531}
532
533template <typename P, typename F, typename C>
534void
536{
537 CH_TIME("DischargeInceptionStepper::parseTransportAlgorithm");
538 if (m_verbosity > 5) {
539 pout() << "DischargeInceptionStepper::parseTransportAlgorithm" << endl;
540 }
541
542 ParmParse pp("DischargeInceptionStepper");
543
544 std::string str;
545
546 pp.get("transport_alg", str);
547 pp.get("ion_transport", m_ionTransport);
548 pp.get("cfl", m_cfl);
549 pp.get("first_dt", m_firstDt);
550 pp.get("min_dt", m_minDt);
551 pp.get("max_dt", m_maxDt);
552 pp.get("max_dt_growth", m_maxDtGrowth);
553 pp.get("voltage_eps", m_epsVoltage);
554
555 CH_assert(m_minDt >= 0.0);
556 CH_assert(m_maxDt >= 0.0);
557 CH_assert(m_firstDt > 0.0);
558
559 if (str == "euler") {
561 }
562 else if (str == "heun") {
564 }
565 else if (str == "imex") {
567 }
568 else {
569 MayDay::Error("Expected 'euler', 'heun', or 'imex' for 'DischargeInceptionStepper.transport_alg'");
570 }
571}
572
573template <typename P, typename F, typename C>
574void
576{
577 CH_TIME("DischargeInceptionStepper::parsePlotVariables");
578 if (m_verbosity > 5) {
579 pout() << "DischargeInceptionStepper::parsePlotVariables" << endl;
580 }
581
582 m_plotField = false;
583 m_plotPoisson = false;
584 m_plotTracer = false;
585 m_plotNegativeIons = false;
589 m_plotDetachment = false;
590 m_plotFieldEmission = false;
591 m_plotAlpha = false;
592 m_plotEta = false;
593 m_plotTownsend = false;
594
595 ParmParse pp("DischargeInceptionStepper");
596
597 // Get plot variables.
598 const int num = pp.countval("plt_vars");
599 if (num > 0) {
600 Vector<std::string> plotVars(num);
601 pp.getarr("plt_vars", plotVars, 0, num);
602
603 for (int i = 0; i < num; i++) {
604 if (plotVars[i] == "field") {
605 m_plotField = true;
606 }
607 else if (plotVars[i] == "poisson") {
608 m_plotPoisson = true;
609 }
610 else if (plotVars[i] == "tracer") {
611 m_plotTracer = true;
612 }
613 else if (plotVars[i] == "ions") {
614 m_plotNegativeIons = true;
615 }
616 else if (plotVars[i] == "K") {
618 }
619 else if (plotVars[i] == "Uinc") {
621 }
622 else if (plotVars[i] == "bg_rate") {
624 }
625 else if (plotVars[i] == "detachment") {
626 m_plotDetachment = true;
627 }
628 else if (plotVars[i] == "emission") {
629 m_plotFieldEmission = true;
630 }
631 else if (plotVars[i] == "alpha") {
632 m_plotAlpha = true;
633 }
634 else if (plotVars[i] == "eta") {
635 m_plotEta = true;
636 }
637 else if (plotVars[i] == "T") {
638 m_plotTownsend = true;
639 }
640 }
641 }
642}
643
644#ifdef CH_USE_HDF5
645template <typename P, typename F, typename C>
646void
647DischargeInceptionStepper<P, F, C>::writeCheckpointData(HDF5Handle& a_handle, const int a_lvl) const
648{
649 CH_TIME("DischargeInceptionStepper::writeCheckpointData");
650 if (m_verbosity > 5) {
651 pout() << "DischargeInceptionStepper::writeCheckpointData" << endl;
652 }
653}
654#endif
655
656#ifdef CH_USE_HDF5
657template <typename P, typename F, typename C>
658void
659DischargeInceptionStepper<P, F, C>::readCheckpointData(HDF5Handle& a_handle, const int a_lvl)
660{
661 CH_TIME("DischargeInceptionStepper::readCheckpointData");
662 if (m_verbosity > 5) {
663 pout() << "DischargeInceptionStepper::readCheckpointData" << endl;
664 }
665
666 MayDay::Error("DischargeInceptionStepper::readCheckpointData -- restart not supported. Use Driver.restart=0");
667}
668#endif
669
670template <typename P, typename F, typename C>
671int
673{
674 CH_TIME("DischargeInceptionStepper::getNumberOfPlotVariables");
675 if (m_verbosity > 5) {
676 pout() << "DischargeInceptionStepper::getNumberOfPlotVariables" << endl;
677 }
678
679 int ncomp = 0;
680
681 if (m_plotPoisson) {
682 ncomp += m_fieldSolver->getNumberOfPlotVariables();
683 }
684 if (m_plotTracer) {
685 ncomp += m_tracerParticleSolver->getNumberOfPlotVariables();
686 }
687 if (m_plotNegativeIons) {
688 ncomp += m_ionSolver->getNumberOfPlotVariables();
689 }
690
691 switch (m_mode) {
692 case Mode::Stationary: {
693
694 if (m_plotField) {
695 // Electric potential for each voltage
696 ncomp += 2 * m_voltageSweeps.size();
697
698 // Electric field magnitude
699 ncomp += 2 * m_voltageSweeps.size();
700
701 // All the electric field components
702 ncomp += 2 * SpaceDim * m_voltageSweeps.size();
703
704 // Surface and space charge densities
705 ncomp += 2;
706 }
707
708 // K-values
710 ncomp += 2 * m_voltageSweeps.size();
711 }
712
713 // Inception voltage.
715 ncomp += 6;
716 }
717
718 // Background ionization rates
720 ncomp += m_voltageSweeps.size();
721 }
722
723 // Detachment rates
724 if (m_plotDetachment) {
725 ncomp += m_voltageSweeps.size();
726 }
727
728 // Field emission rates
730 ncomp += 2 * m_voltageSweeps.size();
731 }
732
733 // Plotting alpha
734 if (m_plotAlpha) {
735 ncomp += m_voltageSweeps.size();
736 }
737
738 // Plotting eta
739 if (m_plotEta) {
740 ncomp += m_voltageSweeps.size();
741 }
742
743 // When plotting both, add the effective ionization coefficient
744 if (m_plotAlpha && m_plotEta) {
745 ncomp += m_voltageSweeps.size();
746 }
747
748 // Plotting gamma coefficient
749 if (m_plotTownsend) {
750 ncomp += 2 * m_voltageSweeps.size();
751 }
752
753 break;
754 }
755 case Mode::Transient: {
756
757 if (m_plotField) {
758
759 // Potential
760 ncomp += 1;
761
762 // Field magnitude
763 ncomp += 1;
764
765 // Field components
766 ncomp += SpaceDim;
767
768 // Space and surface charge
769 ncomp += 2;
770 }
771
773 ncomp += 1;
774 }
775 if (m_plotTownsend) {
776 ncomp += 1;
777 }
779 ncomp += 1;
780 }
781 if (m_plotDetachment) {
782 ncomp += 1;
783 }
785 ncomp += 1;
786 }
787 if (m_plotAlpha) {
788 ncomp += 1;
789 }
790 if (m_plotEta) {
791 ncomp += 1;
792 }
793 if (m_plotAlpha && m_plotEta) {
794 ncomp += 1;
795 }
796
797 break;
798 }
799 default: {
800 break;
801 }
802 }
803
804 return ncomp;
805}
806
807template <typename P, typename F, typename C>
808Vector<std::string>
810{
811 CH_TIME("DischargeInceptionStepper::getPlotVariableNames");
812 if (m_verbosity > 5) {
813 pout() << "DischargeInceptionStepper::getPlotVariableNames" << endl;
814 }
815
816 Vector<std::string> plotVars;
817
818 if (m_plotPoisson) {
819 Vector<std::string> poissonVars = m_fieldSolver->getPlotVariableNames();
820 for (int i = 0; i < poissonVars.size(); i++) {
821 poissonVars[i] = "Poisson/" + poissonVars[i];
822 }
823 plotVars.append(poissonVars);
824 }
825
826 if (m_plotTracer) {
827 Vector<std::string> tracerVars = m_tracerParticleSolver->getPlotVariableNames();
828 for (int i = 0; i < tracerVars.size(); i++) {
829 tracerVars[i] = "Tracer/" + tracerVars[i];
830 }
831 plotVars.append(tracerVars);
832 }
833
834 if (m_plotNegativeIons) {
835 Vector<std::string> cdrVars = m_ionSolver->getPlotVariableNames();
836 for (int i = 0; i < cdrVars.size(); i++) {
837 cdrVars[i] = "CDR/" + cdrVars[i];
838 }
839 plotVars.append(cdrVars);
840 }
841
842 switch (m_mode) {
843 case Mode::Stationary: {
844 plotVars.append(this->getStationaryPlotVariableNames());
845
846 break;
847 }
848 case Mode::Transient: {
849 plotVars.append(this->getTransientPlotVariableNames());
850
851 break;
852 }
853 default: {
854 MayDay::Error("DischargeInceptionStepper::getPlotVariableNames - logic bust");
855
856 break;
857 }
858 }
859
860 return plotVars;
861}
862
863template <typename P, typename F, typename C>
864Vector<std::string>
866{
867 CH_TIME("DischargeInceptionStepper::getStationaryPlotVariableNames");
868 if (m_verbosity > 5) {
869 pout() << "DischargeInceptionStepper::getStationaryPlotVariableNames" << endl;
870 }
871
872 Vector<std::string> plotVars;
873
874 const std::string prefix = "DischargeInceptionStepper/";
875
876 // Always plotted.
877 if (m_plotField) {
878 for (const Real& V : m_voltageSweeps) {
879 plotVars.push_back(prefix + "Potential/+/ V = +" + std::to_string(V));
880 plotVars.push_back(prefix + "Potential/-/ V = -" + std::to_string(V));
881 }
882
883 for (const Real& V : m_voltageSweeps) {
884 plotVars.push_back(prefix + "E/+/ V = +" + std::to_string(V));
885 plotVars.push_back(prefix + "x-E/+/ V= +" + std::to_string(V));
886 plotVars.push_back(prefix + "y-E/+/ V= +" + std::to_string(V));
887 if (SpaceDim == 3) {
888 plotVars.push_back(prefix + "z-E/+/ V= +" + std::to_string(V));
889 }
890
891 plotVars.push_back(prefix + "E/-/ V = -" + std::to_string(V));
892 plotVars.push_back(prefix + "x-E/-/ V = -" + std::to_string(V));
893 plotVars.push_back(prefix + "y-E/-/ V = -" + std::to_string(V));
894 if (SpaceDim == 3) {
895 plotVars.push_back(prefix + "z-E/-/ V= -" + std::to_string(V));
896 }
897 }
898
899 // Surface charge
900 plotVars.push_back(prefix + "Space charge density");
901 plotVars.push_back(prefix + "Surface charge density");
902 }
903
905 plotVars.push_back(prefix + "Minimum inception voltage +");
906 plotVars.push_back(prefix + "Minimum inception voltage -");
907 plotVars.push_back(prefix + "Streamer inception voltage +");
908 plotVars.push_back(prefix + "Streamer inception voltage -");
909 plotVars.push_back(prefix + "Townsend inception voltage +");
910 plotVars.push_back(prefix + "Townsend inception voltage -");
911 }
912
914 std::string varName;
915
916 for (const Real& V : m_voltageSweeps) {
917 varName = prefix + "K-value/+/ V = +" + std::to_string(V);
918 plotVars.push_back(varName);
919 }
920
921 for (const Real& V : m_voltageSweeps) {
922 varName = prefix + "K-value/-/ V = -" + std::to_string(V);
923 plotVars.push_back(varName);
924 }
925 }
926
927 // Secondary emission coefficient for initiatory ions
928 if (m_plotTownsend) {
929 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
930 const std::string varName = prefix + "T-value/+/ V = +" + std::to_string(m_voltageSweeps[i]);
931
932 plotVars.push_back(varName);
933 }
934
935 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
936 const std::string varName = prefix + "T-value/-/ V = -" + std::to_string(m_voltageSweeps[i]);
937
938 plotVars.push_back(varName);
939 }
940 }
941
942 // Write the background ionization rates
944 std::string varName;
945
946 for (const Real& V : m_voltageSweeps) {
947 varName = prefix + "Background ionization rate/ V = " + std::to_string(V);
948 plotVars.push_back(varName);
949 }
950 }
951
952 // Write detachment rates
953 if (m_plotDetachment) {
954 std::string varName;
955
956 for (const Real& V : m_voltageSweeps) {
957 varName = prefix + "Detachment rate/ V = " + std::to_string(V);
958 plotVars.push_back(varName);
959 }
960 }
961
962 // Write field emission rates
964 std::string varName;
965
966 for (const Real& V : m_voltageSweeps) {
967 varName = prefix + "Field emission rate/+/ V = +" + std::to_string(V);
968 plotVars.push_back(varName);
969 }
970
971 for (const Real& V : m_voltageSweeps) {
972 varName = prefix + "Field emission rate/-/ V = -" + std::to_string(V);
973 plotVars.push_back(varName);
974 }
975 }
976
977 // Alpha value
978 if (m_plotAlpha) {
979 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
980
981 const std::string varName = prefix + "Alpha coefficient/ V = " + std::to_string(m_voltageSweeps[i]);
982
983 plotVars.push_back(varName);
984 }
985 }
986
987 // Eta
988 if (m_plotEta) {
989 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
990 const std::string varName = prefix + "Eta coefficient/ V = " + std::to_string(m_voltageSweeps[i]);
991
992 plotVars.push_back(varName);
993 }
994 }
995
996 // Effective alpha coefficient
997 if (m_plotAlpha && m_plotEta) {
998 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
999 const std::string varName = prefix + "Alpha_eff/ V = " + std::to_string(m_voltageSweeps[i]);
1000
1001 plotVars.push_back(varName);
1002 }
1003 }
1004
1005 return plotVars;
1006}
1007
1008template <typename P, typename F, typename C>
1009Vector<std::string>
1011{
1012 CH_TIME("DischargeInceptionStepper::getTransientPlotVariableNames");
1013 if (m_verbosity > 5) {
1014 pout() << "DischargeInceptionStepper::getTransientPlotVariableNames" << endl;
1015 }
1016
1017 Vector<std::string> plotVars;
1018
1019 if (m_plotField) {
1020 // Add potential and electric field to output
1021 plotVars.push_back("Electric potential");
1022 plotVars.push_back("E");
1023 plotVars.push_back("x-E");
1024 plotVars.push_back("y-E");
1025 if (SpaceDim == 3) {
1026 plotVars.push_back("z-E");
1027 }
1028
1029 // Space and surface charge
1030 plotVars.push_back("Space charge density");
1031 plotVars.push_back("Surface charge density");
1032 }
1033
1035 plotVars.push_back("Inception integral");
1036 }
1037
1038 if (m_plotTownsend) {
1039 plotVars.push_back("Townsend criterion");
1040 }
1041
1043 plotVars.push_back("Background rate");
1044 }
1045
1046 if (m_plotDetachment) {
1047 plotVars.push_back("Detachment rate");
1048 }
1049
1050 if (m_plotFieldEmission) {
1051 plotVars.push_back("Field emission");
1052 }
1053
1054 if (m_plotAlpha) {
1055 plotVars.push_back("Townsend alpha coefficient");
1056 }
1057
1058 if (m_plotEta) {
1059 plotVars.push_back("Townsend eta coefficient");
1060 }
1061
1062 if (m_plotAlpha && m_plotEta) {
1063 plotVars.push_back("Effective Townsend coefficient");
1064 }
1065
1066 for (int i = 0; i < plotVars.size(); i++) {
1067 plotVars[i] = "DischargeInceptionStepper/" + plotVars[i];
1068 }
1069
1070 return plotVars;
1071}
1072
1073template <typename P, typename F, typename C>
1074void
1076 int& a_icomp,
1077 const std::string& a_outputRealm,
1078 const int a_level) const
1079{
1080 CH_TIME("DischargeInceptionStepper::writePlotData");
1081 if (m_verbosity > 5) {
1082 pout() << "DischargeInceptionStepper::writePlotData" << endl;
1083 }
1084
1085 if (m_plotPoisson) {
1086 m_fieldSolver->writePlotData(a_output, a_icomp, a_outputRealm, a_level);
1087 }
1088
1089 if (m_plotTracer) {
1090 m_tracerParticleSolver->writePlotData(a_output, a_icomp, a_outputRealm, a_level);
1091 }
1092
1093 if (m_plotNegativeIons) {
1094 m_ionSolver->writePlotData(a_output, a_icomp, a_outputRealm, a_level);
1095 }
1096
1097 // Write internal data -- this differs between the 'stationary' and 'transient' modes
1098 switch (m_mode) {
1099 case Mode::Stationary: {
1100 this->writePlotDataStationary(a_output, a_icomp, a_outputRealm, a_level);
1101
1102 break;
1103 }
1104 case Mode::Transient:
1105 this->writePlotDataTransient(a_output, a_icomp, a_outputRealm, a_level);
1106
1107 break;
1108 default: {
1109 MayDay::Error("DischargeInceptionStepper::writePlotData - logic bust");
1110
1111 break;
1112 }
1113 }
1114}
1115
1116template <typename P, typename F, typename C>
1117void
1119 int& a_icomp,
1120 const std::string& a_outputRealm,
1121 const int a_level) const noexcept
1122{
1123 CH_TIME("DischargeInceptionStepper::writePlotDataStationary");
1124 if (m_verbosity > 5) {
1125 pout() << "DischargeInceptionStepper::writePlotDataStationary" << endl;
1126 }
1127
1128 const std::string prefix = "DischargeInceptionStepper/";
1129
1130 if (m_plotField) {
1131 MFAMRCellData scratch;
1132 EBAMRIVData scratchSurf;
1133
1134 m_amr->allocate(scratch, m_realm, 1);
1135 m_amr->allocate(scratchSurf, m_realm, phase::gas, 1);
1136
1137 for (const auto& V : m_voltageSweeps) {
1138
1139 // Potential for positive applied voltage
1143 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_potential, phase::gas, a_outputRealm, a_level, true);
1144
1145 // Potential for negative applied voltage
1149 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_potential, phase::gas, a_outputRealm, a_level, true);
1150 }
1151
1152 for (const auto& V : m_voltageSweeps) {
1153 // Field magnitude for positive applied field
1158 DataOps::squareRoot(scratch,
1159 m_amr->getMultiCutVofIterator(m_realm, phase::gas),
1160 m_amr->getMultiCutVofIterator(m_realm, phase::solid));
1161 m_fieldSolver->writeMultifluidData(a_output, a_icomp, scratch, phase::gas, a_outputRealm, a_level, true);
1162 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_electricField, phase::gas, a_outputRealm, a_level, true);
1163
1164 // Field magnitude for positive applied field
1169 DataOps::squareRoot(scratch,
1170 m_amr->getMultiCutVofIterator(m_realm, phase::gas),
1171 m_amr->getMultiCutVofIterator(m_realm, phase::solid));
1172 m_fieldSolver->writeMultifluidData(a_output, a_icomp, scratch, phase::gas, a_outputRealm, a_level, true);
1173 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_electricField, phase::gas, a_outputRealm, a_level, true);
1174 }
1175
1176 // Write the space charge density
1177 DataOps::setValue(scratch,
1178 m_rho,
1179 m_amr->getProbLo(),
1180 m_amr->getDx(),
1181 0,
1182 m_amr->getVofIterator(m_realm, phase::gas),
1183 m_amr->getVofIterator(m_realm, phase::solid));
1184 m_amr->arithmeticAverage(scratch, m_realm);
1185 m_amr->interpGhostPwl(scratch, m_realm);
1186 m_fieldSolver->writeMultifluidData(a_output, a_icomp, scratch, phase::gas, a_outputRealm, a_level, true);
1187
1188 DataOps::setValue(scratchSurf,
1189 m_sigma,
1190 m_amr->getProbLo(),
1191 m_amr->getDx(),
1192 0,
1193 m_amr->getVofIterator(m_realm, phase::gas));
1194 m_fieldSolver->writeSurfaceData(a_output, a_icomp, *scratchSurf[a_level], a_outputRealm, a_level);
1195 }
1196
1198 this->writeData(a_output, a_icomp, m_inceptionVoltagePlus, a_outputRealm, a_level, false, true);
1199 this->writeData(a_output, a_icomp, m_inceptionVoltageMinu, a_outputRealm, a_level, false, true);
1200 this->writeData(a_output, a_icomp, m_streamerInceptionVoltagePlus, a_outputRealm, a_level, false, true);
1201 this->writeData(a_output, a_icomp, m_streamerInceptionVoltageMinu, a_outputRealm, a_level, false, true);
1202 this->writeData(a_output, a_icomp, m_townsendInceptionVoltagePlus, a_outputRealm, a_level, false, true);
1203 this->writeData(a_output, a_icomp, m_townsendInceptionVoltageMinu, a_outputRealm, a_level, false, true);
1204 }
1205
1206 const int numVoltages = m_voltageSweeps.size();
1207
1209 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1210 this->writeData(a_output, a_icomp, m_inceptionIntegralPlus[i], a_outputRealm, a_level, false, true);
1211 }
1212 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1213 this->writeData(a_output, a_icomp, m_inceptionIntegralMinu[i], a_outputRealm, a_level, false, true);
1214 }
1215 }
1216
1217 if (m_plotTownsend) {
1218 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1219 this->writeData(a_output, a_icomp, m_townsendCriterionPlus[i], a_outputRealm, a_level, false, true);
1220 }
1221
1222 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1223 this->writeData(a_output, a_icomp, m_townsendCriterionMinu[i], a_outputRealm, a_level, false, true);
1224 }
1225 }
1226
1228 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1229 this->writeData(a_output, a_icomp, m_backgroundIonizationStationary[i], a_outputRealm, a_level, false, true);
1230 }
1231 }
1232
1233 if (m_plotDetachment) {
1234 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1235 this->writeData(a_output, a_icomp, m_detachmentStationary[i], a_outputRealm, a_level, false, true);
1236 }
1237 }
1238
1239 if (m_plotFieldEmission) {
1240 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1241 this->writeData(a_output, a_icomp, m_emissionRatesPlus[i], a_outputRealm, a_level, false, true);
1242 }
1243 for (int i = 0; i < m_voltageSweeps.size(); i++) {
1244 this->writeData(a_output, a_icomp, m_emissionRatesMinu[i], a_outputRealm, a_level, false, true);
1245 }
1246 }
1247
1248 if (m_plotAlpha) {
1249 LevelData<EBCellFAB> alpha;
1250 LevelData<EBCellFAB> alphaCoar;
1251
1252 m_amr->allocate(alpha, m_realm, m_phase, a_level, 1);
1253 if (a_level > 0) {
1254 m_amr->allocate(alphaCoar, m_realm, m_phase, a_level - 1, 1);
1255 }
1256
1257 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
1258 this->evaluateFunction(alpha, m_voltageSweeps[i], m_alpha, a_level);
1259 if (a_level > 0) {
1260 this->evaluateFunction(alphaCoar, m_voltageSweeps[i], m_alpha, a_level - 1);
1261 m_amr->interpGhost(alpha, alphaCoar, a_level, m_realm, m_phase);
1262 }
1263 else {
1264 alpha.exchange();
1265 }
1266
1267 m_amr->copyData(a_output, alpha, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1268
1269 a_icomp++;
1270 }
1271 }
1272
1273 if (m_plotEta) {
1274 LevelData<EBCellFAB> eta;
1275 LevelData<EBCellFAB> etaCoar;
1276
1277 m_amr->allocate(eta, m_realm, m_phase, a_level, 1);
1278 if (a_level > 0) {
1279 m_amr->allocate(etaCoar, m_realm, m_phase, a_level - 1, 1);
1280 }
1281
1282 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
1283 this->evaluateFunction(eta, m_voltageSweeps[i], m_eta, a_level);
1284 if (a_level > 0) {
1285 this->evaluateFunction(etaCoar, m_voltageSweeps[i], m_eta, a_level - 1);
1286 m_amr->interpGhost(eta, etaCoar, a_level, m_realm, m_phase);
1287 }
1288 else {
1289 eta.exchange();
1290 }
1291
1292 m_amr->copyData(a_output, eta, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1293
1294 a_icomp++;
1295 }
1296 }
1297
1298 if (m_plotAlpha && m_plotEta) {
1299 LevelData<EBCellFAB> alphaEff;
1300 LevelData<EBCellFAB> alphaEffCoar;
1301
1302 m_amr->allocate(alphaEff, m_realm, m_phase, a_level, 1);
1303 if (a_level > 0) {
1304 m_amr->allocate(alphaEffCoar, m_realm, m_phase, a_level - 1, 1);
1305 }
1306
1307 auto alphaFunc = [alpha = this->m_alpha, eta = this->m_eta](const Real E, const RealVect x) -> Real {
1308 return alpha(E, x) - eta(E, x);
1309 };
1310
1311 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
1312 this->evaluateFunction(alphaEff, m_voltageSweeps[i], alphaFunc, a_level);
1313 if (a_level > 0) {
1314 this->evaluateFunction(alphaEffCoar, m_voltageSweeps[i], alphaFunc, a_level - 1);
1315 m_amr->interpGhost(alphaEff, alphaEffCoar, a_level, m_realm, m_phase);
1316 }
1317 else {
1318 alphaEff.exchange();
1319 }
1320
1321 // Do a copy, but note that this does not include ghost cells across the CF interface since
1322 // we are only computing for a single grid level.
1323 m_amr->copyData(a_output, alphaEff, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1324
1325 a_icomp++;
1326 }
1327 }
1328}
1329
1330template <typename P, typename F, typename C>
1331void
1333 int& a_icomp,
1334 const std::string& a_outputRealm,
1335 const int a_level) const noexcept
1336{
1337 CH_TIME("DischargeInceptionStepper::writePlotDataTransient");
1338 if (m_verbosity > 5) {
1339 pout() << "DischargeInceptionStepper::writePlotDataTransient" << endl;
1340 }
1341
1342 CH_assert(a_level >= 0);
1343 CH_assert(a_level <= m_amr->getFinestLevel());
1344
1345 // Add potential and electric field to output. Note that we need to scale appropriately.
1346 if (m_plotField) {
1347
1348 // Holds the field magnitude
1349 MFAMRCellData scratch;
1350 EBAMRIVData scratchSurf;
1351
1352 m_amr->allocate(scratch, m_realm, 1);
1353 m_amr->allocate(scratchSurf, m_realm, phase::gas, 1);
1354
1356 DataOps::squareRoot(scratch,
1357 m_amr->getMultiCutVofIterator(m_realm, phase::gas),
1358 m_amr->getMultiCutVofIterator(m_realm, phase::solid));
1359 m_amr->arithmeticAverage(scratch, m_realm);
1360 m_amr->interpGhostPwl(scratch, m_realm);
1361
1362 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_potential, phase::gas, a_outputRealm, a_level, true);
1363 m_fieldSolver->writeMultifluidData(a_output, a_icomp, scratch, phase::gas, a_outputRealm, a_level, true);
1364 m_fieldSolver->writeMultifluidData(a_output, a_icomp, m_electricField, phase::gas, a_outputRealm, a_level, true);
1365
1366 // Write the space charge density
1367 DataOps::setValue(scratch,
1368 m_rho,
1369 m_amr->getProbLo(),
1370 m_amr->getDx(),
1371 0,
1372 m_amr->getVofIterator(m_realm, phase::gas),
1373 m_amr->getVofIterator(m_realm, phase::solid));
1374 m_amr->arithmeticAverage(scratch, m_realm);
1375 m_amr->interpGhostPwl(scratch, m_realm);
1376 m_fieldSolver->writeMultifluidData(a_output, a_icomp, scratch, phase::gas, a_outputRealm, a_level, true);
1377
1378 DataOps::setValue(scratchSurf,
1379 m_sigma,
1380 m_amr->getProbLo(),
1381 m_amr->getDx(),
1382 0,
1383 m_amr->getVofIterator(m_realm, phase::gas));
1384 m_fieldSolver->writeSurfaceData(a_output, a_icomp, *scratchSurf[a_level], a_outputRealm, a_level);
1385 }
1386
1388 this->writeData(a_output, a_icomp, m_inceptionIntegral, a_outputRealm, a_level, false, true);
1389 }
1390
1391 if (m_plotTownsend) {
1392 this->writeData(a_output, a_icomp, m_townsendCriterion, a_outputRealm, a_level, false, true);
1393 }
1394
1396 LevelData<EBCellFAB> bgIonization;
1397 m_amr->allocate(bgIonization, m_realm, m_phase, a_level, 1);
1398
1399 this->evaluateFunction(bgIonization, m_voltageCurve(m_time), m_backgroundRate, a_level);
1400
1401 // Do a copy, but note that this does not include ghost cells across the CF interface since
1402 // we are only computing for a single grid level.
1403 m_amr
1404 ->copyData(a_output, bgIonization, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1405
1406 a_icomp++;
1407 }
1408
1409 if (m_plotDetachment) {
1410 LevelData<EBCellFAB> detachRate;
1411 LevelData<EBCellFAB> detachRateCoar;
1412
1413 m_amr->allocate(detachRate, m_realm, m_phase, a_level, 1);
1414 if (a_level > 0) {
1415 m_amr->allocate(detachRateCoar, m_realm, m_phase, a_level - 1, 1);
1416 }
1417
1418 this->evaluateFunction(detachRate, m_voltageCurve(m_time), m_detachmentRate, a_level);
1419 if (a_level > 0) {
1420 this->evaluateFunction(detachRateCoar, m_voltageCurve(m_time), m_detachmentRate, a_level - 1);
1421 m_amr->interpGhost(detachRate, detachRateCoar, a_level, m_realm, m_phase);
1422 }
1423
1424 m_amr->copyData(a_output, detachRate, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1425
1426 a_icomp++;
1427 }
1428
1429 if (m_plotFieldEmission) {
1430 this->writeData(a_output, a_icomp, m_emissionRate, a_outputRealm, a_level, false, false);
1431 }
1432
1433 if (m_plotAlpha) {
1434 LevelData<EBCellFAB> alpha;
1435 LevelData<EBCellFAB> alphaCoar;
1436
1437 m_amr->allocate(alpha, m_realm, m_phase, a_level, 1);
1438 if (a_level > 0) {
1439 m_amr->allocate(alphaCoar, m_realm, m_phase, a_level - 1, 1);
1440 }
1441
1442 this->evaluateFunction(alpha, m_voltageCurve(m_time), m_alpha, a_level);
1443 if (a_level > 0) {
1444 this->evaluateFunction(alphaCoar, m_voltageCurve(m_time), m_alpha, a_level - 1);
1445 m_amr->interpGhost(alpha, alphaCoar, a_level, m_realm, m_phase);
1446 }
1447 else {
1448 alpha.exchange();
1449 }
1450
1451 // Do a copy, but note that this does not include ghost cells across the CF interface since
1452 // we are only computing for a single grid level.
1453 m_amr->copyData(a_output, alpha, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1454
1455 a_icomp++;
1456 }
1457
1458 if (m_plotEta) {
1459 LevelData<EBCellFAB> eta;
1460 LevelData<EBCellFAB> etaCoar;
1461
1462 m_amr->allocate(eta, m_realm, m_phase, a_level, 1);
1463 if (a_level > 0) {
1464 m_amr->allocate(etaCoar, m_realm, m_phase, a_level - 1, 1);
1465 }
1466
1467 this->evaluateFunction(eta, m_voltageCurve(m_time), m_eta, a_level);
1468 if (a_level > 0) {
1469 this->evaluateFunction(etaCoar, m_voltageCurve(m_time), m_eta, a_level - 1);
1470 m_amr->interpGhost(eta, etaCoar, a_level, m_realm, m_phase);
1471 }
1472 else {
1473 eta.exchange();
1474 }
1475
1476 // Do a copy, but note that this does not include ghost cells across the CF interface since
1477 // we are only computing for a single grid level.
1478 m_amr->copyData(a_output, eta, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1479
1480 a_icomp++;
1481 }
1482
1483 if (m_plotAlpha && m_plotEta) {
1484 LevelData<EBCellFAB> alphaEff;
1485 LevelData<EBCellFAB> alphaEffCoar;
1486
1487 m_amr->allocate(alphaEff, m_realm, m_phase, a_level, 1);
1488 if (a_level > 0) {
1489 m_amr->allocate(alphaEffCoar, m_realm, m_phase, a_level - 1, 1);
1490 }
1491
1492 auto alphaFunc = [alpha = this->m_alpha, eta = this->m_eta](const Real E, const RealVect x) -> Real {
1493 return alpha(E, x) - eta(E, x);
1494 };
1495
1496 this->evaluateFunction(alphaEff, m_voltageCurve(m_time), alphaFunc, a_level);
1497 if (a_level > 0) {
1498 this->evaluateFunction(alphaEffCoar, m_voltageCurve(m_time), alphaFunc, a_level - 1);
1499 m_amr->interpGhost(alphaEff, alphaEffCoar, a_level, m_realm, m_phase);
1500 }
1501 else {
1502 alphaEff.exchange();
1503 }
1504
1505 // Do a copy, but note that this does not include ghost cells across the CF interface since
1506 // we are only computing for a single grid level.
1507 m_amr->copyData(a_output, alphaEff, a_level, a_outputRealm, m_realm, Interval(a_icomp, a_icomp), Interval(0, 0));
1508
1509 a_icomp++;
1510 }
1511}
1512
1513template <typename P, typename F, typename C>
1514Real
1516{
1517 CH_TIME("DischargeInceptionStepper::computeDt");
1518 if (m_verbosity > 5) {
1519 pout() << "DischargeInceptionStepper::computeDt" << endl;
1520 }
1521
1522 Real dt = std::numeric_limits<Real>::max();
1523
1524 if (m_mode == Mode::Transient) {
1525
1526 // Compute time step from ion solver.
1528
1529 // Restrict by ion solver
1530 if (m_ionTransport) {
1531 Real ionDt = std::numeric_limits<Real>::infinity();
1532
1533 // Euler and Heun extrapolate to the faces without transverse terms, so their advective time step is the unsplit
1534 // bound dx/sum(|v_d|) of CdrSolver, not the CTU bound that CdrCTU::computeAdvectionDt returns. With diffusion,
1535 // computeAdvectionDiffusionDt already uses the unsplit bound.
1536 const Real unsplitDt = (m_ionSolver->isMobile() && !m_ionSolver->isDiffusive())
1537 ? m_ionSolver->CdrSolver::computeAdvectionDt()
1538 : m_ionSolver->computeAdvectionDiffusionDt();
1539
1540 switch (m_transportAlgorithm) {
1542 ionDt = m_cfl * unsplitDt;
1543
1544 break;
1545 }
1547 ionDt = m_cfl * unsplitDt;
1548
1549 break;
1550 }
1552 ionDt = m_cfl * m_ionSolver->computeAdvectionDt();
1553
1554 break;
1555 }
1556 default: {
1557 MayDay::Error("DischargeInceptionStepper::computDt -- logic bust");
1558
1559 break;
1560 }
1561 }
1562
1563 if (ionDt < dt) {
1564 dt = ionDt;
1566 }
1567 }
1568
1569 // Restrict by voltage curve.
1570 Real curveDt = std::numeric_limits<Real>::max();
1571 if (m_timeStep == 0) {
1572 curveDt = m_firstDt;
1573 }
1574 else {
1575 const Real preU = m_voltageCurve(m_time - m_dt);
1576 const Real curU = m_voltageCurve(m_time);
1577 const Real dVdt = std::abs(curU - preU) / dt;
1578
1579 if (dVdt > std::numeric_limits<Real>::epsilon()) {
1580 curveDt = m_epsVoltage * std::abs(curU) / dVdt;
1581 }
1582
1583 // Do not grow too fast.
1584 curveDt = std::min(m_dt * (1.0 + m_maxDtGrowth), curveDt);
1585 curveDt = std::max(m_dt * (1.0 - m_maxDtGrowth), curveDt);
1586 }
1587
1588 if (curveDt < dt) {
1589 dt = curveDt;
1591 }
1592
1593 // Restrict by hardcaps
1594 if (dt > m_maxDt) {
1595 dt = m_maxDt;
1597 }
1598
1599 if (dt < m_minDt) {
1600 dt = m_minDt;
1602 }
1603 }
1604
1605 return dt;
1606}
1607
1608template <typename P, typename F, typename C>
1609Real
1611{
1612 CH_TIME("DischargeInceptionStepper::advance");
1613 if (m_verbosity > 5) {
1614 pout() << "DischargeInceptionStepper::advance" << endl;
1615 }
1616
1617 if (m_mode == Mode::Transient) {
1618 Timer timer("DischargeInceptionStepper::advance");
1619
1620 const Real curTime = m_time + a_dt;
1621 const Real curVoltage = m_voltageCurve(curTime);
1622
1623 // Compute the electric potential and field at the current time step -- these are used in the output routines
1627
1628 m_amr->arithmeticAverage(m_potential, m_realm);
1629 m_amr->interpGhostPwl(m_potential, m_realm);
1630
1634
1635 m_amr->arithmeticAverage(m_electricField, m_realm);
1636 m_amr->interpGhostPwl(m_electricField, m_realm);
1637
1638 // Move the negative ions -- still want this for the time step.
1639 timer.startEvent("Ion advance");
1640 if (m_ionTransport) {
1641 this->computeIonVelocity(curVoltage);
1642 this->computeIonDiffusion(curVoltage);
1643 this->advanceIons(a_dt);
1644 }
1645 timer.stopEvent("Ion advance");
1646
1647 // Seed new particles and compute the inception integral.
1648 timer.startEvent("Inception integral");
1649 this->seedIonizationParticles(curVoltage);
1650 this->computeInceptionIntegralTransient(curVoltage);
1651 timer.stopEvent("Inception integral");
1652
1653 if (m_evaluateTownsend) {
1654 timer.startEvent("Townsend criterion");
1655 this->seedIonizationParticles(curVoltage);
1656 this->computeTownsendCriterionTransient(curVoltage);
1657 timer.stopEvent("Townsend criterion");
1658 }
1659
1660 // Compute the critical volume, critical area, the ionization volume and the electron appearance rate.
1661 timer.startEvent("Compute Vcr");
1662 const Real Vcr = this->computeCriticalVolumeTransient();
1663 const Real Acr = this->computeCriticalAreaTransient();
1664 const Real Vion = this->computeIonizationVolumeTransient(curVoltage);
1665 const Real Rdot = this->computeRdot(curVoltage);
1666 timer.stopEvent("Compute Vcr");
1667
1668 m_criticalVolume.emplace_back(curTime, Vcr);
1669 m_criticalArea.emplace_back(curTime, Acr);
1670 m_ionizationVolumeTransient.emplace_back(curTime, Vion);
1671 m_Rdot.emplace_back(curTime, Rdot);
1672
1673 // Compute the inception probability using the trapezoidal rule.
1674 if (m_Rdot.size() >= 2) {
1675 Real p = 0.0;
1676
1677 for (size_t i = 0; i < m_Rdot.size() - 1; i++) {
1678 const Real dt = m_Rdot[i + 1].first - m_Rdot[i].first;
1679
1680 p += 0.5 * dt * (m_Rdot[i + 1].second + m_Rdot[i].second);
1681 }
1682
1683 m_inceptionProbability.emplace_back(curTime, 1.0 - exp(-p));
1684 }
1685
1686 // Get the maximum K and T values
1687 timer.startEvent("Get max/min K");
1688 Real maxK = -std::numeric_limits<Real>::max();
1689 Real minK = +std::numeric_limits<Real>::max();
1690
1691 Real maxT = -std::numeric_limits<Real>::max();
1692 Real minT = +std::numeric_limits<Real>::max();
1693
1694 DataOps::getMaxMin(maxK, minK, m_inceptionIntegral, 0, m_amr->getMultiCutVofIterator(m_realm, m_phase));
1695 DataOps::getMaxMin(maxT, minT, m_townsendCriterion, 0, m_amr->getMultiCutVofIterator(m_realm, m_phase));
1696
1697 if (!m_fullIntegration) {
1698 maxK = std::min(maxK, m_inceptionK);
1699 maxT = std::min(maxT, 1.0);
1700 }
1701 m_maxK.emplace_back(m_time + a_dt, maxK);
1702 m_maxT.emplace_back(m_time + a_dt, maxT);
1703 timer.stopEvent("Get max/min K");
1704
1705 timer.startEvent("Write report");
1706 this->writeReportTransient();
1707 timer.stopEvent("Write report");
1708
1709 if (m_profile) {
1710 timer.eventReport(pout(), false);
1711 }
1712 }
1713 else {
1714 MayDay::Error("DischargeInceptionStepper::advance -- must have 'DischargeInceptionStepper.mode = transient'");
1715 }
1716
1717 return a_dt;
1718}
1719
1720template <typename P, typename F, typename C>
1721void
1723{
1724 CH_TIME("DischargeInceptionStepper::advanceIons");
1725 if (m_verbosity > 5) {
1726 pout() << "DischargeInceptionStepper::advanceIons" << endl;
1727 }
1728
1729 EBAMRCellData& phi = m_ionSolver->getPhi();
1730
1731 // Use an outflow BC for transport. Note that extrapolateAdvectiveFluxToEB computes
1732 // -n.(phi * v). Since we compute phi^(k+1) = phi^k - dt*sum(fluxes) this means that a negative
1733 // flux is an incoming flux.
1734 EBAMRIVData& ebFlux = m_ionSolver->getEbFlux();
1735 m_ionSolver->extrapolateAdvectiveFluxToEB(ebFlux);
1736 DataOps::floor(ebFlux, 0.0, m_amr->getVofIterator(m_realm, m_phase));
1737
1738 switch (m_transportAlgorithm) {
1740 EBAMRCellData divJ;
1741 m_amr->allocate(divJ, m_realm, m_phase, 1.0);
1742
1743 m_ionSolver->computeDivJ(divJ, phi, 0.0, a_dt, false, true, false);
1744
1745 DataOps::incr(phi, divJ, -a_dt);
1746
1747 break;
1748 }
1750 // Transient storage
1751 EBAMRCellData yp;
1752 EBAMRCellData k1;
1753 EBAMRCellData k2;
1754
1755 m_amr->allocate(yp, m_realm, m_phase, 1);
1756 m_amr->allocate(k1, m_realm, m_phase, 1);
1757 m_amr->allocate(k2, m_realm, m_phase, 1);
1758
1759 // Compute k1 coefficient
1760 m_ionSolver->computeDivJ(k1, phi, 0.0, a_dt, false, true, false);
1761 DataOps::copy(yp, phi);
1762 DataOps::incr(yp, k1, -a_dt);
1763
1764 // Compute k2 coefficient and final state
1765 m_ionSolver->computeDivJ(k2, yp, 0.0, a_dt, false, true, false);
1766 DataOps::incr(phi, k1, -0.5 * a_dt);
1767 DataOps::incr(phi, k2, -0.5 * a_dt);
1768
1769 break;
1770 }
1772 const bool addEbFlux = true;
1773 const bool addDomainFlux = true;
1774
1775 // Transient storage
1776 EBAMRCellData k1;
1777 EBAMRCellData k2;
1778
1779 m_amr->allocate(k1, m_realm, m_phase, 1);
1780 m_amr->allocate(k2, m_realm, m_phase, 1);
1781
1782 m_ionSolver->computeDivF(k1, phi, a_dt, a_dt, false, true, true);
1783
1784 DataOps::kappaScale(k1, m_amr->getVofIterator(m_realm, m_phase));
1785 DataOps::scale(k1, -1.0);
1786
1787 // Use k1 as the old solution.
1788 DataOps::copy(k2, phi);
1789
1790 // Do the Euler solve.
1791 m_ionSolver->advanceCrankNicholson(phi, k2, k1, a_dt);
1792
1793 break;
1794 }
1795 default: {
1796 MayDay::Error("DischargeInceptionStepper::advanceIons -- logic bust");
1797 }
1798 }
1799
1800 DataOps::floor(phi, 0.0, m_amr->getVofIterator(m_realm, m_phase));
1801
1802 m_amr->average(phi, m_realm, m_phase, Average::Conservative);
1803 m_amr->interpGhost(phi, m_realm, m_phase);
1804}
1805
1806template <typename P, typename F, typename C>
1807void
1808DischargeInceptionStepper<P, F, C>::synchronizeSolverTimes(const int a_step, const Real a_time, const Real a_dt)
1809{
1810 CH_TIME("DischargeInceptionStepper::synchronizeSolverTimes");
1811 if (m_verbosity > 5) {
1812 pout() << "DischargeInceptionStepper::synchronizeSolverTimes" << endl;
1813 }
1814
1815 m_timeStep = a_step;
1816 m_time = a_time;
1817 m_dt = a_dt;
1818
1819 m_fieldSolver->setTime(a_step, a_time, a_dt);
1820 m_tracerParticleSolver->setTime(a_step, a_time, a_dt);
1821 m_ionSolver->setTime(a_step, a_time, a_dt);
1822}
1823
1824template <typename P, typename F, typename C>
1825void
1827{
1828 CH_TIME("DischargeInceptionStepper::printStepReport");
1829#ifndef NDEBUG
1830 if (m_verbosity > 5) {
1831 pout() << "DischargeInceptionStepper::printStepReport" << endl;
1832 }
1833#endif
1834
1835 std::string timeStepMessage;
1836 switch (m_timeStepRestriction) {
1838 timeStepMessage = "Unknown";
1839
1840 break;
1841 }
1843 timeStepMessage = "CFL";
1844
1845 break;
1846 }
1848 timeStepMessage = "Voltage curve";
1849
1850 break;
1851 }
1853 timeStepMessage = "Min hardcap";
1854
1855 break;
1856 }
1858 timeStepMessage = "Max hardcap";
1859
1860 break;
1861 }
1862 default: {
1863 MayDay::Warning("DischargeInceptionStepper::printStepReport - logic bust");
1864
1865 break;
1866 }
1867 }
1868
1869 // clang-format off
1870 pout() << " ** Voltage = " << m_voltageCurve(m_time) << endl;
1871 pout() << " ** Crit. volume = " << m_criticalVolume.back().second << endl;
1872 pout() << " ** Inception probability = " << m_inceptionProbability.back().second << endl;
1873 pout() << " ** Time step restriction = " << "'" << timeStepMessage << "'" << endl;
1874 // clang-format on
1875}
1876
1877template <typename P, typename F, typename C>
1878void
1879DischargeInceptionStepper<P, F, C>::preRegrid(const int a_lmin, const int a_oldFinestLevel)
1880{
1881 CH_TIME("DischargeInceptionStepper::preRegrid");
1882 if (m_verbosity > 5) {
1883 pout() << "DischargeInceptionStepper::preRegrid" << endl;
1884 }
1885
1886 m_fieldSolver->preRegrid(a_lmin, a_oldFinestLevel);
1887 m_tracerParticleSolver->preRegrid(a_lmin, a_oldFinestLevel);
1888 m_ionSolver->preRegrid(a_lmin, a_oldFinestLevel);
1889
1890 m_amr->allocate(m_scratchHomo, m_realm, 1);
1891 m_amr->allocate(m_scratchInho, m_realm, 1);
1892
1895}
1896
1897template <typename P, typename F, typename C>
1898void
1899DischargeInceptionStepper<P, F, C>::regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
1900{
1901 CH_TIME("DischargeInceptionStepper::regrid");
1902 if (m_verbosity > 5) {
1903 pout() << "DischargeInceptionStepper::regrid" << endl;
1904 }
1905
1906 // Regrid tracer particles and field
1907 m_fieldSolver->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
1908 m_tracerParticleSolver->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
1909 m_ionSolver->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
1910
1911 // Regrid electric field and potentials
1912 m_amr->reallocate(m_potential, a_lmin);
1913 m_amr->reallocate(m_potentialHomo, a_lmin);
1914 m_amr->reallocate(m_potentialInho, a_lmin);
1915
1916 m_amr->reallocate(m_electricField, a_lmin);
1917 m_amr->reallocate(m_electricFieldHomo, a_lmin);
1918 m_amr->reallocate(m_electricFieldInho, a_lmin);
1919
1920 m_amr->reallocate(m_gradAlpha, m_phase, a_lmin);
1921
1922 const EBCoarseToFineInterp::Type interpType = EBCoarseToFineInterp::ConservativeMinMod;
1923
1924 m_amr->interpToNewGrids(m_potentialHomo, m_scratchHomo, a_lmin, a_oldFinestLevel, a_newFinestLevel, interpType);
1925 m_amr->interpToNewGrids(m_potentialInho, m_scratchInho, a_lmin, a_oldFinestLevel, a_newFinestLevel, interpType);
1926
1927 switch (m_mode) {
1928 case Mode::Stationary: {
1929 m_amr->reallocate(m_inceptionVoltagePlus, m_phase, a_lmin);
1930 m_amr->reallocate(m_inceptionVoltageMinu, m_phase, a_lmin);
1931 m_amr->reallocate(m_streamerInceptionVoltagePlus, m_phase, a_lmin);
1932 m_amr->reallocate(m_streamerInceptionVoltageMinu, m_phase, a_lmin);
1933 m_amr->reallocate(m_townsendInceptionVoltagePlus, m_phase, a_lmin);
1934 m_amr->reallocate(m_townsendInceptionVoltageMinu, m_phase, a_lmin);
1935
1936 break;
1937 }
1938 case Mode::Transient: {
1939 m_amr->reallocate(m_inceptionIntegral, m_phase, a_lmin);
1940 m_amr->reallocate(m_townsendCriterion, m_phase, a_lmin);
1941 m_amr->reallocate(m_emissionRate, m_phase, a_lmin);
1942 m_amr->reallocate(m_backgroundIonization, m_phase, a_lmin);
1943 m_amr->reallocate(m_detachment, m_phase, a_lmin);
1944
1945 break;
1946 }
1947 default: {
1948 break;
1949 }
1950 }
1951
1952 // Solve for the inhomogeneous and homogeneous Poisson fields again
1953 this->solvePoisson();
1954
1955 // Re-compute the ion velocity and diffusion coefficients
1958}
1959
1960template <typename P, typename F, typename C>
1961void
1963{
1964 CH_TIME("DischargeInceptionStepper::postRegrid");
1965 if (m_verbosity > 5) {
1966 pout() << "DischargeInceptionStepper::postRegrid" << endl;
1967 }
1968
1969 m_scratchHomo.clear();
1970 m_scratchInho.clear();
1971}
1972
1973template <typename P, typename F, typename C>
1974void
1975DischargeInceptionStepper<P, F, C>::setVoltageCurve(const std::function<Real(const Real& E)>& a_voltageCurve) noexcept
1976{
1977 CH_TIME("DischargeInceptionStepper::setVoltageCurve");
1978 if (m_verbosity > 5) {
1979 pout() << "DischargeInceptionStepper::setVoltageCurve" << endl;
1980 }
1981
1982 m_voltageCurve = a_voltageCurve;
1983}
1984
1985template <typename P, typename F, typename C>
1986void
1987DischargeInceptionStepper<P, F, C>::setRho(const std::function<Real(const RealVect& x)>& a_rho) noexcept
1988{
1989 CH_TIME("DischargeInceptionStepper::setRho");
1990 if (m_verbosity > 5) {
1991 pout() << "DischargeInceptionStepper::setRho" << endl;
1992 }
1993
1994 m_rho = a_rho;
1995}
1996
1997template <typename P, typename F, typename C>
1998void
1999DischargeInceptionStepper<P, F, C>::setSigma(const std::function<Real(const RealVect& x)>& a_sigma) noexcept
2000{
2001 CH_TIME("DischargeInceptionStepper::setSigma");
2002 if (m_verbosity > 5) {
2003 pout() << "DischargeInceptionStepper::setSigma" << endl;
2004 }
2005
2006 m_sigma = a_sigma;
2007}
2008
2009template <typename P, typename F, typename C>
2010void
2011DischargeInceptionStepper<P, F, C>::setIonDensity(const std::function<Real(const RealVect x)>& a_density) noexcept
2012{
2013 CH_TIME("DischargeInceptionStepper::setIonDensity");
2014 if (m_verbosity > 5) {
2015 pout() << "DischargeInceptionStepper::setIonDensity" << endl;
2016 }
2017
2018 m_initialIonDensity = a_density;
2019}
2020
2021template <typename P, typename F, typename C>
2022void
2023DischargeInceptionStepper<P, F, C>::setIonMobility(const std::function<Real(const Real x)>& a_mobility) noexcept
2024{
2025 CH_TIME("DischargeInceptionStepper::setIonMobility");
2026 if (m_verbosity > 5) {
2027 pout() << "DischargeInceptionStepper::setIonMobility" << endl;
2028 }
2029
2030 m_ionMobility = a_mobility;
2031}
2032
2033template <typename P, typename F, typename C>
2034void
2035DischargeInceptionStepper<P, F, C>::setIonDiffusion(const std::function<Real(const Real x)>& a_diffCo) noexcept
2036{
2037 CH_TIME("DischargeInceptionStepper::setIonDiffusion");
2038 if (m_verbosity > 5) {
2039 pout() << "DischargeInceptionStepper::setIonDiffusion" << endl;
2040 }
2041
2042 m_ionDiffusion = a_diffCo;
2043}
2044
2045template <typename P, typename F, typename C>
2046void
2048 const std::function<Real(const Real& E, const RealVect& x)>& a_alpha) noexcept
2049{
2050 CH_TIME("DischargeInceptionStepper::setAlpha");
2051 if (m_verbosity > 5) {
2052 pout() << "DischargeInceptionStepper::setAlpha" << endl;
2053 }
2054
2055 m_alpha = a_alpha;
2056}
2057
2058template <typename P, typename F, typename C>
2059void
2060DischargeInceptionStepper<P, F, C>::setEta(const std::function<Real(const Real& E, const RealVect& x)>& a_eta) noexcept
2061{
2062 CH_TIME("DischargeInceptionStepper::setEta");
2063 if (m_verbosity > 5) {
2064 pout() << "DischargeInceptionStepper::setEta" << endl;
2065 }
2066
2067 m_eta = a_eta;
2068}
2069
2070template <typename P, typename F, typename C>
2071const std::function<Real(const Real& E, const RealVect& x)>&
2073{
2074 return m_alpha;
2075}
2076
2077template <typename P, typename F, typename C>
2078const std::function<Real(const Real& E, const RealVect& x)>&
2080{
2081 return m_eta;
2082}
2083
2084template <typename P, typename F, typename C>
2085void
2087 const std::function<Real(const Real& E, const RealVect& x)>& a_backgroundRate) noexcept
2088{
2089 CH_TIME("DischargeInceptionStepper::setBackgroundRate");
2090 if (m_verbosity > 5) {
2091 pout() << "DischargeInceptionStepper::setBackgroundRate" << endl;
2092 }
2093
2094 m_backgroundRate = a_backgroundRate;
2095}
2096
2097template <typename P, typename F, typename C>
2098void
2100 const std::function<Real(const Real& E, const RealVect& x)>& a_detachmentRate) noexcept
2101{
2102 CH_TIME("DischargeInceptionStepper::setDetachmentRate");
2103 if (m_verbosity > 5) {
2104 pout() << "DischargeInceptionStepper::setDetachmentRate" << endl;
2105 }
2106
2107 m_detachmentRate = a_detachmentRate;
2108}
2109
2110template <typename P, typename F, typename C>
2111void
2113 const std::function<Real(const Real& E, const RealVect& x)>& a_currentDensity) noexcept
2114{
2115 CH_TIME("DischargeInceptionStepper::setFieldEmission");
2116 if (m_verbosity > 5) {
2117 pout() << "DischargeInceptionStepper::setFieldEmission" << endl;
2118 }
2119
2120 m_fieldEmission = a_currentDensity;
2121}
2122
2123template <typename P, typename F, typename C>
2124void
2126 const std::function<Real(const Real& E, const RealVect& x)>& a_coefficient) noexcept
2127{
2128 CH_TIME("DischargeInceptionStepper::setSecondaryEmission");
2129 if (m_verbosity > 5) {
2130 pout() << "DischargeInceptionStepper::setSecondaryEmission" << endl;
2131 }
2132
2133 m_secondaryEmission = a_coefficient;
2134}
2135
2136template <typename P, typename F, typename C>
2137Mode
2139{
2140 return m_mode;
2141}
2142
2143template <typename P, typename F, typename C>
2144void
2146{
2147 CH_TIME("DischargeInceptionStepper::seedUniformParticles");
2148 if (m_verbosity > 5) {
2149 pout() << "DischargeInceptionStepper::seedUniformParticles" << endl;
2150 }
2151
2152 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
2153 amrParticles.clearParticles();
2154
2155 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2156 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2157 const DataIterator& dit = dbl.dataIterator();
2158 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
2159
2160 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
2161
2162 const Real dx = m_amr->getDx()[lvl];
2163
2164 auto& levelParticles = amrParticles[lvl];
2165
2166 const int nbox = dit.size();
2167
2168#pragma omp parallel for schedule(runtime)
2169 for (int mybox = 0; mybox < nbox; mybox++) {
2170 const DataIndex& din = dit[mybox];
2171
2172 const EBISBox& ebisbox = ebisl[din];
2173 const BaseFab<bool>& validCells = validCellsLD[din];
2174
2175 ParticleSoA<P>& leaf = levelParticles[din];
2176
2177 auto regularKernel = [&](const IntVect& iv) -> void {
2178 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
2179 leaf.append(m_amr->getProbLo() + (0.5 * RealVect::Unit + RealVect(iv)) * dx, 0.0);
2180 }
2181 };
2182
2183 auto irregularKernel = [&](const VolIndex& vof) -> void {
2184 if (validCells(vof.gridIndex())) {
2185 leaf.append(m_amr->getProbLo() + Location::position(Location::Cell::Centroid, vof, ebisbox, dx), 0.0);
2186 }
2187 };
2188
2189 // Execute kernels over appropriate regions. Not vectorizable: per-cell append. Multi-cut N/A:
2190 // regular uses cell-CENTER, irregular uses CENTROID position.
2191 const Box cellBox = dbl[din];
2192 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
2193
2194 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
2195 BoxLoops::loop(vofit, irregularKernel);
2196
2197 // Back up the initial position into the rewind column (weight was set to zero on append).
2198 const double* const pos[SpaceDim] = {
2199 D_DECL(leaf.positionColumn(0), leaf.positionColumn(1), leaf.positionColumn(2))};
2200 double* const x0[SpaceDim] = {
2201 D_DECL(leaf.template column<&P::x0_x>(), leaf.template column<&P::x0_y>(), leaf.template column<&P::x0_z>())};
2202 ParticleLoops::loop(leaf, [&](const std::size_t i) {
2203 for (int dir = 0; dir < SpaceDim; dir++) {
2204 x0[dir][i] = pos[dir][i];
2205 }
2206 });
2207 }
2208 }
2209
2210 // Remove particles inside the EB.
2211 m_amr->removeCoveredParticlesIF(amrParticles, m_phase, 0.0);
2212
2213 amrParticles.remap();
2214}
2215
2216template <typename P, typename F, typename C>
2217void
2219{
2220 CH_TIME("DischargeInceptionStepper::seedIonizationParticles");
2221 if (m_verbosity > 5) {
2222 pout() << "DischargeInceptionStepper::seedIonizationParticles" << endl;
2223 }
2224
2225 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
2226 amrParticles.clearParticles();
2227
2228 // Scratch storages
2229 EBAMRCellData scratch;
2230 EBAMRCellData alphaMesh;
2231
2232 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
2233 m_amr->allocate(alphaMesh, m_realm, m_phase, 1);
2234
2235 this->superposition(scratch, a_voltage);
2236
2237 DataOps::setValue(alphaMesh, 0.0);
2238
2239 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2240 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2241 const DataIterator& dit = dbl.dataIterator();
2242 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
2243
2244 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
2245
2246 const Real dx = m_amr->getDx()[lvl];
2247 const RealVect probLo = m_amr->getProbLo();
2248
2249 auto& levelParticles = amrParticles[lvl];
2250
2251 const int nbox = dit.size();
2252
2253#pragma omp parallel for schedule(runtime)
2254 for (int mybox = 0; mybox < nbox; mybox++) {
2255 const DataIndex& din = dit[mybox];
2256
2257 const EBISBox& ebisbox = ebisl[din];
2258 const BaseFab<bool>& validCells = validCellsLD[din];
2259
2260 ParticleSoA<P>& leaf = levelParticles[din];
2261
2262 const EBCellFAB& electricField = (*scratch[lvl])[din];
2263 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
2264
2265 EBCellFAB& alpha = (*alphaMesh[lvl])[din];
2266 FArrayBox& alphaReg = alpha.getFArrayBox();
2267
2268 if (!ebisbox.isAllCovered()) {
2269
2270 auto regularKernel = [&](const IntVect& iv) -> void {
2271 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
2272
2273 const RealVect x = probLo + dx * (0.5 * RealVect::Unit + RealVect(iv));
2274 const RealVect EE = RealVect(
2275 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
2276
2277 const Real E = EE.vectorLength();
2278 const Real curAlpha = m_alpha(E, x);
2279 const Real curEta = m_eta(E, x);
2280
2281 if (curAlpha > curEta) {
2282 leaf.append(x, 0.0);
2283
2284 alphaReg(iv, 0) = curAlpha - curEta;
2285 }
2286 }
2287 };
2288
2289 auto irregularKernel = [&](const VolIndex& vof) -> void {
2290 const IntVect iv = vof.gridIndex();
2291
2292 if (validCells(iv, 0) && ebisbox.isIrregular(iv)) {
2293 const RealVect x = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
2294 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
2295 const Real E = EE.vectorLength();
2296
2297 const Real curAlpha = m_alpha(E, x);
2298 const Real curEta = m_eta(E, x);
2299
2300 if (curAlpha > curEta) {
2301 leaf.append(x, 0.0);
2302
2303 alpha(vof, 0) = curAlpha - curEta;
2304 }
2305 }
2306 };
2307
2308 // Execute kernels over appropriate regions. Not vectorizable: m_alpha/m_eta std::function
2309 // coefficients per cell + per-particle append + data-dependent branch. Multi-cut N/A (center vs centroid).
2310 const Box cellBox = dbl[din];
2311 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
2312
2313 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
2314 BoxLoops::loop(vofit, irregularKernel);
2315 }
2316
2317 // Back up the initial position into the rewind column (weight + grad-alpha columns are already
2318 // zero from the default-payload append).
2319 const double* const pos[SpaceDim] = {
2320 D_DECL(leaf.positionColumn(0), leaf.positionColumn(1), leaf.positionColumn(2))};
2321 double* const x0[SpaceDim] = {
2322 D_DECL(leaf.template column<&P::x0_x>(), leaf.template column<&P::x0_y>(), leaf.template column<&P::x0_z>())};
2323 ParticleLoops::loop(leaf, [&](const std::size_t i) {
2324 for (int dir = 0; dir < SpaceDim; dir++) {
2325 x0[dir][i] = pos[dir][i];
2326 }
2327 });
2328 }
2329 }
2330
2331 // Update ghost cells
2332 m_amr->arithmeticAverage(alphaMesh, m_realm, m_phase);
2333 m_amr->interpGhost(alphaMesh, m_realm, m_phase);
2334
2335 // Compute gradient
2336 m_amr->computeGradient(m_gradAlpha, alphaMesh, m_realm, m_phase);
2337
2338 // Update ghost cells in the gradient
2339 m_amr->arithmeticAverage(m_gradAlpha, m_realm, m_phase);
2340 m_amr->interpGhost(m_gradAlpha, m_realm, m_phase);
2341 m_amr->interpToCentroids(m_gradAlpha, m_realm, m_phase);
2342}
2343
2344template <typename P, typename F, typename C>
2345void
2347{
2348 CH_TIME("DischargeInceptionStepper::postInitialize");
2349 if (m_verbosity > 5) {
2350 pout() << "DischargeInceptionStepper::postInitialize" << endl;
2351 }
2352
2353 // Initialize the negative ion solver
2354 m_ionSolver->initialData();
2357
2358 switch (m_mode) {
2359 case Mode::Stationary: {
2366
2367 // Compute background ionization and field emission on the mesh. Mostly for plotting.
2370 }
2371
2372 if (m_plotDetachment) {
2374 }
2375
2376 if (m_plotFieldEmission) {
2378 }
2379
2380 this->writeReportStationary();
2381
2382 break;
2383 }
2384 case Mode::Transient: {
2385
2386 // Seed tracer particles and set velocity
2389
2390 // Evaluate the Townsend criterion if the user asks for it.
2391 if (m_evaluateTownsend) {
2394 }
2395
2396 // Get the maximum K and T values
2397 Real maxK = -std::numeric_limits<Real>::max();
2398 Real minK = +std::numeric_limits<Real>::max();
2399
2400 Real maxT = -std::numeric_limits<Real>::max();
2401 Real minT = +std::numeric_limits<Real>::max();
2402
2403 DataOps::getMaxMin(maxK, minK, m_inceptionIntegral, 0, m_amr->getMultiCutVofIterator(m_realm, m_phase));
2404 DataOps::getMaxMin(maxT, minT, m_townsendCriterion, 0, m_amr->getMultiCutVofIterator(m_realm, m_phase));
2405 if (!m_fullIntegration) {
2406 maxK = std::min(maxK, m_inceptionK);
2407 maxT = std::min(maxT, 1.0);
2408 }
2409
2410 m_Rdot.emplace_back(m_time, this->computeRdot(m_voltageCurve(m_time)));
2412 m_criticalArea.emplace_back(m_time, this->computeCriticalAreaTransient());
2414 m_inceptionProbability.emplace_back(m_time, 0.0);
2415 m_maxK.emplace_back(m_time, maxK);
2416 m_maxT.emplace_back(m_time, maxT);
2417
2418 break;
2419 }
2420 default: {
2421 break;
2422 }
2423 }
2424}
2425
2426template <typename P, typename F, typename C>
2427void
2429{
2430 CH_TIME("DischargeInceptionStepper::interpolateGradAlphaToParticles");
2431 if (m_verbosity > 5) {
2432 pout() << "DischargeInceptionStepper::interpolateGradAlphaToParticles" << endl;
2433 }
2434
2435 // Interpolate onto the particle weight structure
2436 m_amr->interpolateParticles<D_DECL(&P::ga_x, &P::ga_y, &P::ga_z)>(m_tracerParticleSolver->getParticles(),
2437 m_realm,
2438 m_phase,
2440 m_tracerParticleSolver->getInterpolationType(),
2441 true);
2442}
2443
2444template <typename P, typename F, typename C>
2445void
2447 const Real a_voltage) noexcept
2448{
2449 CH_TIME("DischargeInceptionStepper::computeInceptionIntegral");
2450 if (m_verbosity > 5) {
2451 pout() << "DischargeInceptionStepper::computeInceptionIntegral" << endl;
2452 }
2453
2454 // TLDR: For this integration we compute the value of the inception integral
2455 //
2456 // K = int alpha_eff(E)dl
2457 //
2458 // The integration runs from the start position of the particle and along a field line until either the
2459 // particle leaves the domain or alpha < 0.0.
2460 //
2461 // For the Euler rule we get
2462 //
2463 // T += alpha_eff(E(x)) * dx
2464 //
2465 // For the trapezoidal rule we get
2466 //
2467 // T += 0.5 * dx * [alpha_eff(E(x)) + alpha_eff(E(x+dx))]
2468
2469 // Reset the particles used for field line integration
2470 this->seedIonizationParticles(a_voltage);
2471 this->resetTracerParticles();
2472
2473 // Switch between algorithms.
2474 switch (m_inceptionAlgorithm) {
2476 this->inceptionIntegrateEuler(a_voltage);
2477
2478 break;
2479 }
2481 this->inceptionIntegrateTrapezoidal(a_voltage);
2482
2483 break;
2484 }
2485 default: {
2486 MayDay::Error("DischargeInceptionStepper::computeInceptionIntegral -- logic bust");
2487
2488 break;
2489 }
2490 }
2491
2492 // Deposit the particles on the mesh and get the max/min values.
2493 m_tracerParticleSolver->deposit(a_inceptionIntegral);
2494
2495 m_amr->conservativeAverage(a_inceptionIntegral, m_realm, m_phase);
2496 m_amr->interpGhost(a_inceptionIntegral, m_realm, m_phase);
2497}
2498
2499template <typename P, typename F, typename C>
2500void
2502{
2503 CH_TIME("DischargeInceptionStepper::computeInceptionIntegralStationary");
2504 if (m_verbosity > 5) {
2505 pout() << "DischargeInceptionStepper::computeInceptionIntegralStationary" << endl;
2506 }
2507
2508 constexpr int maxIter = 50;
2509
2510 // Get the maximum field (in the gas phase) with the electrodes at 1V
2511 Real maxField = 0.0;
2512 Real minField = 0.0;
2513
2514 EBAMRCellData gasField = m_amr->alias(phase::gas, m_electricField);
2515
2516 this->superposition(gasField, 1.0);
2517
2518 DataOps::getMaxMinNorm(maxField, minField, gasField, m_amr->getMultiCutVofIterator(m_realm, m_phase));
2519
2520 // Compute the critical field and the minimum possible inception voltage.
2521 const Real Ecrit = this->getCriticalField();
2522
2523 Real curVoltage = m_relativeDeltaU * Ecrit / maxField;
2524 Real curMaxK = 0.0;
2525 int curIter = 0;
2526
2527 m_inceptionIntegralPlus.resize(0);
2528 m_inceptionIntegralMinu.resize(0);
2529
2530 // We use K1, K2, U2, U1 to extrapolate to a next voltage.
2531 Real K1 = 0.0;
2532 Real K2 = 0.0;
2533 Real U1 = Ecrit / maxField;
2534 Real U2 = curVoltage;
2535
2536 while (curMaxK < m_maxKLimit && curIter < maxIter) {
2537 EBAMRCellData Kplus;
2538 EBAMRCellData Kminu;
2539
2540 m_amr->allocate(Kplus, m_realm, m_phase, 1);
2541 m_amr->allocate(Kminu, m_realm, m_phase, 1);
2542
2543 DataOps::setValue(Kplus, 0.0);
2544 DataOps::setValue(Kminu, 0.0);
2545
2546 m_inceptionIntegralPlus.push_back(Kplus);
2547 m_inceptionIntegralMinu.push_back(Kminu);
2548
2549 this->computeInceptionIntegral(Kplus, +curVoltage);
2550 this->computeInceptionIntegral(Kminu, -curVoltage);
2551
2552 // Get the max and min values of K.
2553 Real maxKPlus = -std::numeric_limits<Real>::max();
2554 Real maxKMinu = -std::numeric_limits<Real>::max();
2555
2556 RealVect maxKPlusPos = RealVect::Zero;
2557 RealVect maxKMinuPos = RealVect::Zero;
2558
2559 this->getMaxValueAndLocation(maxKPlus, maxKPlusPos, Kplus);
2560 this->getMaxValueAndLocation(maxKMinu, maxKMinuPos, Kminu);
2561
2562 // Populate the relevant data containers.
2563 m_KPlusValues.emplace_back(std::make_tuple(curVoltage, maxKPlus, maxKPlusPos));
2564 m_KMinuValues.emplace_back(std::make_tuple(curVoltage, maxKMinu, maxKMinuPos));
2565
2566 curMaxK = std::max(maxKPlus, maxKMinu);
2567
2568 // Figure out the next voltage. User linear extrapolation near the first point and log-linear otherwise.
2569 K2 = curMaxK;
2570 U2 = curVoltage;
2571
2572 Real nextVoltage;
2573 if (K1 <= 0.0) {
2574 const Real dKdU = (K2 - K1) / (U2 - U1);
2575
2576 nextVoltage = U1 + ((K2 - K1) + m_deltaK) / dKdU;
2577 }
2578 else {
2579 const Real dKdU = std::log(K2 / K1) / (U2 - U1);
2580
2581 nextVoltage = U1 + std::log((K2 + m_deltaK) / K1) / dKdU;
2582 }
2583
2584 K1 = K2;
2585 U1 = U2;
2586
2587 // Step to next voltage.
2588 curVoltage = std::min(nextVoltage, curVoltage * m_relativeDeltaU);
2589 curIter = curIter + 1;
2590
2591 if (!m_fullIntegration && (std::abs(curMaxK - m_inceptionK) <= 1E-3)) {
2592 break;
2593 }
2594 }
2595
2596 // Populate the voltage sweep table
2597 m_voltageSweeps.resize(0);
2598 for (int i = 0; i < m_KPlusValues.size(); i++) {
2599 m_voltageSweeps.push_back(std::get<0>(m_KPlusValues[i]));
2600 }
2601}
2602
2603template <typename P, typename F, typename C>
2604void
2606{
2607 CH_TIME("DischargeInceptionStepper::computeInceptionIntegralTransient");
2608 if (m_verbosity > 5) {
2609 pout() << "DischargeInceptionStepper::computeInceptionIntegralTransient" << endl;
2610 }
2611
2612 // Compute K-value on each particle using specified algorithm.
2613 switch (m_inceptionAlgorithm) {
2615 this->inceptionIntegrateEuler(a_voltage);
2616
2617 break;
2618 }
2620 this->inceptionIntegrateTrapezoidal(a_voltage);
2621
2622 break;
2623 }
2624 default: {
2625 MayDay::Error("DischargeInceptionStepper::computeInceptionIntegralTransient - logic bust");
2626
2627 break;
2628 }
2629 }
2630
2631 // Deposit the particles onto m_inceptionIntegral
2633
2634 m_amr->conservativeAverage(m_inceptionIntegral, m_realm, m_phase);
2635 m_amr->interpGhost(m_inceptionIntegral, m_realm, m_phase);
2636}
2637
2638template <typename P, typename F, typename C>
2639void
2641{
2642 CH_TIME("DischargeInceptionStepper::inceptionIntegrateEuler");
2643 if (m_verbosity > 5) {
2644 pout() << "DischargeInceptionStepper::inceptionIntegrateEuler" << endl;
2645 }
2646
2647 const RealVect probLo = m_amr->getProbLo();
2648 const RealVect probHi = m_amr->getProbHi();
2649
2650 // Allocate a data holder for holding the processed particles. This
2651 // will be faster because then we only have to iterate through the
2652 // particles that are actually still moving.
2653 ParticleContainer<P> amrProcessedParticles;
2654 m_amr->allocate(amrProcessedParticles, m_realm);
2655
2656 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
2657
2658 m_tracerParticleSolver->remap();
2659
2660 size_t particlesBefore = 0;
2661
2662 if (m_debug) {
2663 particlesBefore = amrParticles.getNumberOfValidParticlesGlobal();
2664 }
2665
2666 // Allocate something that holds the velocity of the electrons
2667 EBAMRCellData scratch;
2668 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
2669 this->superposition(scratch, a_voltage);
2670 DataOps::scale(scratch, -1.0);
2671
2672 m_tracerParticleSolver->setVelocity(scratch);
2673 m_tracerParticleSolver->interpolateVelocities();
2674
2675 while (amrParticles.getNumberOfValidParticlesGlobal() > 0) {
2676
2678
2679 // Euler integration.
2680 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2681 const Real dx = m_amr->getDx()[lvl];
2682
2683 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2684 const DataIterator& dit = dbl.dataIterator();
2685
2686 const int nbox = dit.size();
2687
2688#pragma omp parallel for schedule(runtime)
2689 for (int mybox = 0; mybox < nbox; mybox++) {
2690 const DataIndex& din = dit[mybox];
2691
2692 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
2693 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
2694
2695 // Column pointers are captured once: remove() is an in-place swap-pop and setting positions/weights
2696 // is in-place, so these stay valid across the loop (only processedLeaf grows, internally).
2697 double* const w = solverLeaf.weightColumn();
2698 double* const pos[SpaceDim] = {
2699 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
2700 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
2701 solverLeaf.template column<&P::v_y>(),
2702 solverLeaf.template column<&P::v_z>())};
2703 const ParticleReal* const ga[SpaceDim] = {D_DECL(solverLeaf.template column<&P::ga_x>(),
2704 solverLeaf.template column<&P::ga_y>(),
2705 solverLeaf.template column<&P::ga_z>())};
2706
2707 std::size_t i = 0;
2708 while (i < solverLeaf.size()) {
2709 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
2710 const RealVect vec(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
2711 const Real v = vec.vectorLength();
2712 const Real E = v;
2713 const Real alpha = m_alpha(E, x);
2714 const Real eta = m_eta(E, x);
2715 const Real alphaEff = alpha - eta;
2716 const Real tol = 1E-10;
2717 const Real gradAlpha = tol + RealVect(D_DECL(ga[0][i], ga[1][i], ga[2][i])).vectorLength();
2718
2719 // Select a step size equal to the avalanche length, but never exceed the physical and grid hardcaps
2720 Real deltaX;
2721 deltaX = std::min(m_alphaDx / (tol + std::abs(alphaEff)), m_gradAlphaDx * std::abs(alphaEff / gradAlpha));
2722 deltaX = std::max(deltaX, m_minGridDx * dx);
2723 deltaX = std::min(deltaX, m_maxGridDx * dx);
2724 deltaX = std::min(deltaX, m_maxPhysDx);
2725 deltaX = std::max(deltaX, m_minPhysDx);
2726
2727 const Real dt = deltaX / v;
2728 const RealVect newPos = x + dt * vec;
2729 const Real delta = (newPos - x).vectorLength();
2730
2731 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
2732 const bool insideEB = this->particleInsideEB(newPos);
2733
2734 Real s = 0.0;
2735
2736 if (alphaEff < 0.0) {
2737 processedLeaf.appendParticle(solverLeaf, i);
2738 solverLeaf.remove(i);
2739 }
2740 else if (insideEB) {
2741 // If the particle struck the EB or domain we finish off the integration with a partial step
2742 const RefCountedPtr<BaseIF>& impFunc = m_amr->getBaseImplicitFunction(m_phase);
2743
2744 if (ParticleOps::ebIntersectionBisect(impFunc, x, newPos, m_minGridDx * dx, s)) {
2745 w[i] = w[i] + s * delta * alphaEff;
2746 }
2747
2748 processedLeaf.appendParticle(solverLeaf, i);
2749 solverLeaf.remove(i);
2750 }
2751 else if (outsideDomain) {
2752 if (ParticleOps::domainIntersection(x, newPos, m_amr->getProbLo(), m_amr->getProbHi(), s)) {
2753 w[i] = w[i] + s * delta * alphaEff;
2754 }
2755
2756 processedLeaf.appendParticle(solverLeaf, i);
2757 solverLeaf.remove(i);
2758 }
2759 else {
2760 for (int dir = 0; dir < SpaceDim; dir++) {
2761 pos[dir][i] = newPos[dir];
2762 }
2763 w[i] = w[i] + deltaX * alphaEff;
2764
2765 i++;
2766 }
2767 }
2768
2769 // Transfer particles that completed their integration.
2770 if (!m_fullIntegration) {
2771 std::size_t j = 0;
2772 while (j < solverLeaf.size()) {
2773 if (w[j] >= m_inceptionK) {
2774 processedLeaf.appendParticle(solverLeaf, j);
2775 solverLeaf.remove(j);
2776 }
2777 else {
2778 j++;
2779 }
2780 }
2781 }
2782 }
2783 }
2784
2785 // Update velocities.
2786 m_tracerParticleSolver->remap();
2787 m_tracerParticleSolver->interpolateVelocities();
2788 }
2789
2790 ParticleOps::copyDestructive(amrParticles, amrProcessedParticles);
2791
2792 // Truncate the weights if we didn't run full integration
2793 if (!m_fullIntegration) {
2794 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2795 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2796 const DataIterator& dit = dbl.dataIterator();
2797
2798 const int nbox = dit.size();
2799
2800#pragma omp parallel for schedule(runtime)
2801 for (int mybox = 0; mybox < nbox; mybox++) {
2802 const DataIndex& din = dit[mybox];
2803
2804 ParticleSoA<P>& leaf = amrParticles[lvl][din];
2805
2806 double* const w = leaf.weightColumn();
2807
2808 ParticleLoops::loop(leaf, [&](const std::size_t i) {
2809 w[i] = std::min(m_inceptionK, w[i]);
2810 });
2811 }
2812 }
2813 }
2814
2815 this->rewindTracerParticles();
2816
2817 size_t particlesAfter = 0;
2818
2819 if (m_debug) {
2820 particlesAfter = amrParticles.getNumberOfValidParticlesGlobal();
2821 }
2822
2823 if (particlesBefore != particlesAfter) {
2824 MayDay::Warning("DischargeInceptionStepper::inceptionIntegrateEuler - lost/gained particles!");
2825 }
2826}
2827
2828template <typename P, typename F, typename C>
2829void
2831{
2832 CH_TIME("DischargeInceptionStepper::inceptionIntegrateTrapezoidal");
2833 if (m_verbosity > 5) {
2834 pout() << "DischargeInceptionStepper::inceptionIntegrateTrapezoidal" << endl;
2835 }
2836
2837 // TLDR: We move the particle using Heun's method.
2838 //
2839 // p^(k+1) = p^k + 0.5 * dt * [v(p^k) + v(p^l)]
2840 //
2841 // where p^l = p^k + dt * v(p^k). We will set dt = d/|v(p^k)|. Once we have the
2842 // particle endpoints we can compute the contribution to the inception integral
2843 // by using the trapezoidal (quadrature) rule
2844 //
2845 // T += 0.5 * dx * [alpha_eff(E(p^k)) + alpha_eff(E(p^(k+1)))],
2846 //
2847 // where dx = |p^(k+1) - p^k|.
2848
2849 const RealVect probLo = m_amr->getProbLo();
2850 const RealVect probHi = m_amr->getProbHi();
2851
2852 // Allocate a data holder for holding the processed particles. This
2853 // will be faster because then we only have to iterate through the
2854 // particles that are actually still moving.
2855 ParticleContainer<P> amrProcessedParticles;
2856 m_amr->allocate(amrProcessedParticles, m_realm);
2857
2858 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
2859
2860 m_tracerParticleSolver->remap();
2861
2862 size_t particlesBefore = 0;
2863
2864 if (m_debug) {
2865 particlesBefore = amrParticles.getNumberOfValidParticlesGlobal();
2866 }
2867
2868 // Allocate something that holds the velocity of the electrons
2869 EBAMRCellData scratch;
2870 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
2871 this->superposition(scratch, a_voltage);
2872 DataOps::scale(scratch, -1.0);
2873
2874 m_tracerParticleSolver->setVelocity(scratch);
2875 m_tracerParticleSolver->interpolateVelocities();
2876
2877 while (amrParticles.getNumberOfValidParticlesGlobal() > 0) {
2878
2880
2881 // Euler stage.
2882 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2883 const Real dx = m_amr->getDx()[lvl];
2884
2885 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2886 const DataIterator& dit = dbl.dataIterator();
2887
2888 const int nbox = dit.size();
2889
2890#pragma omp parallel for schedule(runtime)
2891 for (int mybox = 0; mybox < nbox; mybox++) {
2892 const DataIndex& din = dit[mybox];
2893
2894 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
2895 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
2896
2897 double* const w = solverLeaf.weightColumn();
2898 double* const pos[SpaceDim] = {
2899 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
2900 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
2901 solverLeaf.template column<&P::v_y>(),
2902 solverLeaf.template column<&P::v_z>())};
2903 const ParticleReal* const ga[SpaceDim] = {D_DECL(solverLeaf.template column<&P::ga_x>(),
2904 solverLeaf.template column<&P::ga_y>(),
2905 solverLeaf.template column<&P::ga_z>())};
2906 ParticleReal* const vk[SpaceDim] = {D_DECL(solverLeaf.template column<&P::vk_x>(),
2907 solverLeaf.template column<&P::vk_y>(),
2908 solverLeaf.template column<&P::vk_z>())};
2909 ParticleReal* const alphaEffCol = solverLeaf.template column<&P::alphaEff>();
2910 ParticleReal* const dtCol = solverLeaf.template column<&P::dtStep>();
2911
2912 std::size_t i = 0;
2913 while (i < solverLeaf.size()) {
2914 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
2915 const RealVect vec(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
2916 const Real v = vec.vectorLength();
2917 const Real E = v;
2918 const Real alpha = m_alpha(E, x);
2919 const Real eta = m_eta(E, x);
2920 const Real alphaEff = alpha - eta;
2921 const Real tol = 1E-10;
2922 const Real gradAlpha = tol + RealVect(D_DECL(ga[0][i], ga[1][i], ga[2][i])).vectorLength();
2923
2924 // Select a step size equal to the avalanche length, but never exceed the physical and grid hardcaps
2925 Real deltaX;
2926 deltaX = std::min(m_alphaDx / (tol + std::abs(alphaEff)), m_gradAlphaDx * std::abs(alphaEff / gradAlpha));
2927 deltaX = std::max(deltaX, m_minGridDx * dx);
2928 deltaX = std::min(deltaX, m_maxGridDx * dx);
2929 deltaX = std::min(deltaX, m_maxPhysDx);
2930 deltaX = std::max(deltaX, m_minPhysDx);
2931
2932 const Real dt = deltaX / v;
2933 const RealVect newPos = x + dt * vec;
2934 const Real delta = (newPos - x).vectorLength();
2935
2936 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
2937 const bool insideEB = this->particleInsideEB(newPos);
2938
2939 // If particle hit the EB or domain we finish off with a partial Euler step
2940 Real s = 0.0;
2941
2942 if (alphaEff < 0.0) {
2943 processedLeaf.appendParticle(solverLeaf, i);
2944 solverLeaf.remove(i);
2945 }
2946 else if (insideEB) {
2947 const RefCountedPtr<BaseIF>& impFunc = m_amr->getBaseImplicitFunction(m_phase);
2948
2949 if (ParticleOps::ebIntersectionBisect(impFunc, x, newPos, m_minGridDx * dx, s)) {
2950 w[i] = w[i] + s * delta * alphaEff;
2951 }
2952
2953 processedLeaf.appendParticle(solverLeaf, i);
2954 solverLeaf.remove(i);
2955 }
2956 else if (outsideDomain) {
2957 if (ParticleOps::domainIntersection(x, newPos, m_amr->getProbLo(), m_amr->getProbHi(), s)) {
2958 w[i] = w[i] + s * delta * alphaEff;
2959 }
2960
2961 processedLeaf.appendParticle(solverLeaf, i);
2962 solverLeaf.remove(i);
2963 }
2964 else {
2965 // Do an Euler step, storing alpha(p^k), v(p^k), and the time step size.
2966 alphaEffCol[i] = alphaEff;
2967 dtCol[i] = dt;
2968 for (int dir = 0; dir < SpaceDim; dir++) {
2969 vk[dir][i] = vec[dir];
2970 pos[dir][i] = newPos[dir];
2971 }
2972
2973 i++;
2974 }
2975 }
2976 }
2977 }
2978
2979 // Remap and update velocities.
2980 m_tracerParticleSolver->remap();
2981 m_tracerParticleSolver->interpolateVelocities();
2982
2983 // Second stage.
2984 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
2985 const Real dx = m_amr->getDx()[lvl];
2986
2987 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
2988 const DataIterator& dit = dbl.dataIterator();
2989
2990 const int nbox = dit.size();
2991
2992#pragma omp parallel for schedule(runtime)
2993 for (int mybox = 0; mybox < nbox; mybox++) {
2994 const DataIndex& din = dit[mybox];
2995
2996 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
2997 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
2998
2999 double* const w = solverLeaf.weightColumn();
3000 double* const pos[SpaceDim] = {
3001 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
3002 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
3003 solverLeaf.template column<&P::v_y>(),
3004 solverLeaf.template column<&P::v_z>())};
3005 const ParticleReal* const vk[SpaceDim] = {D_DECL(solverLeaf.template column<&P::vk_x>(),
3006 solverLeaf.template column<&P::vk_y>(),
3007 solverLeaf.template column<&P::vk_z>())};
3008 const ParticleReal* const alphaEffCol = solverLeaf.template column<&P::alphaEff>();
3009 const ParticleReal* const dtCol = solverLeaf.template column<&P::dtStep>();
3010
3011 std::size_t i = 0;
3012 while (i < solverLeaf.size()) {
3013 const Real dt = dtCol[i];
3014 const RealVect vkv(D_DECL(vk[0][i], vk[1][i], vk[2][i]));
3015 const RealVect vk1(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
3016 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
3017 const Real E = vk1.vectorLength();
3018
3019 // Note the weird subtraction since the position was updated to p^k + dt * v^k.
3020 const RealVect oldPos = x - dt * vkv;
3021 const RealVect newPos = oldPos + 0.5 * dt * (vkv + vk1);
3022
3023 // Compute new alpha.
3024 const Real alphak = alphaEffCol[i];
3025 const Real alphak1 = m_alpha(E, x) - m_eta(E, x);
3026 const Real delta = (newPos - oldPos).vectorLength();
3027
3028 // Stop integration for particles that move into regions alpha < 0.0,
3029 // inside the EB or outside of the domain.
3030 const bool negativeAlpha = (alphak + alphak1) < 0.0;
3031 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
3032 const bool insideEB = this->particleInsideEB(newPos);
3033
3034 // If the particle wound up inside the EB we finish off the integration with a partial Euler step
3035 Real s = 0.0;
3036
3037 if (negativeAlpha) {
3038 processedLeaf.appendParticle(solverLeaf, i);
3039 solverLeaf.remove(i);
3040 }
3041 else if (insideEB) {
3042 const RefCountedPtr<BaseIF>& impFunc = m_amr->getBaseImplicitFunction(m_phase);
3043
3044 if (ParticleOps::ebIntersectionBisect(impFunc, oldPos, newPos, m_minGridDx * dx, s)) {
3045 w[i] = w[i] + s * delta * alphak;
3046 }
3047
3048 processedLeaf.appendParticle(solverLeaf, i);
3049 solverLeaf.remove(i);
3050 }
3051 else if (outsideDomain) {
3052 if (ParticleOps::domainIntersection(oldPos, newPos, m_amr->getProbLo(), m_amr->getProbHi(), s)) {
3053 w[i] = w[i] + s * delta * alphak;
3054 }
3055
3056 processedLeaf.appendParticle(solverLeaf, i);
3057 solverLeaf.remove(i);
3058 }
3059 else {
3060 for (int dir = 0; dir < SpaceDim; dir++) {
3061 pos[dir][i] = newPos[dir];
3062 }
3063 w[i] = w[i] + 0.5 * delta * (alphak + alphak1);
3064
3065 i++;
3066 }
3067 }
3068
3069 // Transfer particles that completed their integration (if we're doing partial integration)
3070 if (!m_fullIntegration) {
3071 std::size_t j = 0;
3072 while (j < solverLeaf.size()) {
3073 if (w[j] >= m_inceptionK) {
3074 processedLeaf.appendParticle(solverLeaf, j);
3075 solverLeaf.remove(j);
3076 }
3077 else {
3078 j++;
3079 }
3080 }
3081 }
3082 }
3083 }
3084
3085 // Remap and update velocities.
3086 m_tracerParticleSolver->remap();
3087 m_tracerParticleSolver->interpolateVelocities();
3088 }
3089
3090 // Copy processed particles over to the solver particles.
3091 ParticleOps::copyDestructive(amrParticles, amrProcessedParticles);
3092
3093 // Truncate the weights if we didn't run full integration
3094 if (!m_fullIntegration) {
3095 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3096 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3097 const DataIterator& dit = dbl.dataIterator();
3098
3099 const int nbox = dit.size();
3100
3101#pragma omp parallel for schedule(runtime)
3102 for (int mybox = 0; mybox < nbox; mybox++) {
3103 const DataIndex& din = dit[mybox];
3104
3105 ParticleSoA<P>& leaf = amrParticles[lvl][din];
3106
3107 double* const w = leaf.weightColumn();
3108
3109 ParticleLoops::loop(leaf, [&](const std::size_t i) {
3110 w[i] = std::min(m_inceptionK, w[i]);
3111 });
3112 }
3113 }
3114 }
3115
3116 this->rewindTracerParticles();
3117}
3118
3119template <typename P, typename F, typename C>
3120void
3122{
3123 CH_TIME("DischargeInceptionStepper::computeTownsendCriterionStationary");
3124 if (m_verbosity > 5) {
3125 pout() << "DischargeInceptionStepper::computeTownsendCriterionStationary" << endl;
3126 }
3127
3128 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
3129
3130 m_townsendCriterionPlus.resize(0);
3131 m_townsendCriterionMinu.resize(0);
3132
3133 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
3134 const Real voltage = m_voltageSweeps[i];
3135
3136 const EBAMRCellData KPlus = m_inceptionIntegralPlus[i];
3137 const EBAMRCellData KMinu = m_inceptionIntegralMinu[i];
3138
3139 EBAMRCellData townsendCriterionPlus;
3140 EBAMRCellData townsendCriterionMinu;
3141
3142 EBAMRCellData expKPlus;
3143 EBAMRCellData expKMinu;
3144
3145 m_amr->allocate(townsendCriterionPlus, m_realm, m_phase, 1);
3146 m_amr->allocate(townsendCriterionMinu, m_realm, m_phase, 1);
3147
3148 m_amr->allocate(expKPlus, m_realm, m_phase, 1);
3149 m_amr->allocate(expKMinu, m_realm, m_phase, 1);
3150
3151 DataOps::setValue(townsendCriterionPlus, 0.0);
3152 DataOps::setValue(townsendCriterionMinu, 0.0);
3153
3154 DataOps::setValue(expKPlus, 0.0);
3155 DataOps::setValue(expKMinu, 0.0);
3156
3157 Real maxTPlus = 0.0;
3158 Real maxTMinu = 0.0;
3159
3160 RealVect maxTPlusPos = RealVect::Zero;
3161 RealVect maxTMinuPos = RealVect::Zero;
3162
3163 if (m_evaluateTownsend) {
3164
3165 // Positive polarity.
3166 this->resetTracerParticles();
3167
3168 switch (m_inceptionAlgorithm) {
3170 this->townsendTrackEuler(voltage);
3171
3172 break;
3173 }
3175 this->townsendTrackTrapezoidal(voltage);
3176
3177 break;
3178 }
3179 default: {
3180 MayDay::Error("DischargeInceptionStepper::computeTownsendCriterionStationary -- logic bust");
3181
3182 break;
3183 }
3184 }
3185
3186 m_tracerParticleSolver->deposit(townsendCriterionPlus);
3187
3188 m_amr->conservativeAverage(townsendCriterionPlus, m_realm, m_phase);
3189 m_amr->interpGhost(townsendCriterionPlus, m_realm, m_phase);
3190
3191 // Negative polarity.
3192 this->resetTracerParticles();
3193
3194 switch (m_inceptionAlgorithm) {
3196 this->townsendTrackEuler(-voltage);
3197
3198 break;
3199 }
3201 this->townsendTrackTrapezoidal(-voltage);
3202
3203 break;
3204 }
3205 default: {
3206 MayDay::Error("DischargeInceptionStepper::computeTownsendCriterionStationary -- logic bust");
3207
3208 break;
3209 }
3210 }
3211
3212 m_tracerParticleSolver->deposit(townsendCriterionMinu);
3213
3214 m_amr->conservativeAverage(townsendCriterionMinu, m_realm, m_phase);
3215 m_amr->interpGhost(townsendCriterionMinu, m_realm, m_phase);
3216
3217 // For turning K into exp(K) - 1
3218 auto exponentiate = [](const Real x) -> Real {
3219 return x > 0.0 ? exp(x) - 1 : 0.0;
3220 };
3221
3222 DataOps::copy(expKPlus, KPlus);
3223 DataOps::copy(expKMinu, KMinu);
3224
3225 DataOps::compute(expKPlus, exponentiate, m_amr->getMultiCutVofIterator(m_realm, m_phase));
3226 DataOps::compute(expKMinu, exponentiate, m_amr->getMultiCutVofIterator(m_realm, m_phase));
3227
3228 DataOps::multiply(townsendCriterionPlus, expKPlus);
3229 DataOps::multiply(townsendCriterionMinu, expKMinu);
3230
3231 this->getMaxValueAndLocation(maxTPlus, maxTPlusPos, townsendCriterionPlus);
3232 this->getMaxValueAndLocation(maxTMinu, maxTMinuPos, townsendCriterionMinu);
3233
3234 // If we're not doing full integration we truncate the Townsend value to 1.
3235 if (!m_fullIntegration) {
3236 auto truncate = [](const Real x) -> Real {
3237 return std::min(x, 1.0);
3238 };
3239
3240 DataOps::compute(townsendCriterionPlus, truncate, m_amr->getMultiCutVofIterator(m_realm, m_phase));
3241 DataOps::compute(townsendCriterionMinu, truncate, m_amr->getMultiCutVofIterator(m_realm, m_phase));
3242 }
3243 }
3244
3245 m_townsendCriterionPlus.push_back(townsendCriterionPlus);
3246 m_townsendCriterionMinu.push_back(townsendCriterionMinu);
3247
3248 m_TPlusValues.emplace_back(std::make_tuple(voltage, maxTPlus, maxTPlusPos));
3249 m_TMinuValues.emplace_back(std::make_tuple(voltage, maxTMinu, maxTMinuPos));
3250 }
3251}
3252
3253template <typename P, typename F, typename C>
3254void
3256{
3257 CH_TIME("DischargeInceptionStepper::computeTownsendCriterionTransient");
3258 if (m_verbosity > 5) {
3259 pout() << "DischargeInceptionStepper::computeTownsendCriterionTransient" << endl;
3260 }
3261
3262 // Compute T-value on each particle using specified algorithm.
3263 switch (m_inceptionAlgorithm) {
3265 this->townsendTrackEuler(a_voltage);
3266
3267 break;
3268 }
3270 this->townsendTrackTrapezoidal(a_voltage);
3271
3272 break;
3273 }
3274 default: {
3275 MayDay::Error("DischargeInceptionStepper::computeTownsendCriterionTransient - logic bust");
3276
3277 break;
3278 }
3279 }
3280
3281 // Compute gamma
3282 EBAMRCellData gamma;
3283 m_amr->allocate(gamma, m_realm, m_phase, 1);
3284 DataOps::setValue(gamma, 0.0);
3285 m_tracerParticleSolver->deposit(gamma);
3286
3287 // Turn K into exp(K)-1
3288 auto exponentiate = [](const Real x) -> Real {
3289 return x > 0.0 ? exp(x) - 1 : 0.0;
3290 };
3292 DataOps::compute(m_townsendCriterion, exponentiate, m_amr->getMultiCutVofIterator(m_realm, m_phase));
3294
3295 // If we're running without full integration we truncate the Townsend value to 1.
3296 if (!m_fullIntegration) {
3299 [](const Real x) {
3300 return std::min(x, 1.0);
3301 },
3302 m_amr->getMultiCutVofIterator(m_realm, m_phase));
3303 }
3304
3305 m_amr->conservativeAverage(m_townsendCriterion, m_realm, m_phase);
3306 m_amr->interpGhost(m_townsendCriterion, m_realm, m_phase);
3307}
3308
3309template <typename P, typename F, typename C>
3310void
3312{
3313 CH_TIME("DischargeInceptionStepper::townsendTrackEuler");
3314 if (m_verbosity > 5) {
3315 pout() << "DischargeInceptionStepper::townsendTrackEuler" << endl;
3316 }
3317 const RealVect probLo = m_amr->getProbLo();
3318 const RealVect probHi = m_amr->getProbHi();
3319
3320 // Allocate a data holder for holding the processed particles. This
3321 // will be faster because then we only have to iterate through the
3322 // particles that are actually still moving.
3323 ParticleContainer<P> amrProcessedParticles;
3324 m_amr->allocate(amrProcessedParticles, m_realm);
3325
3326 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
3327
3328 m_tracerParticleSolver->remap();
3329
3330 size_t particlesBefore = 0;
3331
3332 if (m_debug) {
3333 particlesBefore = amrParticles.getNumberOfValidParticlesGlobal();
3334 }
3335
3336 // Allocate something that holds the velocity of the ions
3337 EBAMRCellData scratch;
3338 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
3339 this->superposition(scratch, a_voltage);
3340
3341 m_tracerParticleSolver->setVelocity(scratch);
3342 m_tracerParticleSolver->interpolateVelocities();
3343
3344 while (amrParticles.getNumberOfValidParticlesGlobal() > 0) {
3345
3346 // Euler integration.
3347 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3348 const Real dx = m_amr->getDx()[lvl];
3349
3350 // Integrate particles until they leave alpha > 0 or strike a cathode surface.
3351 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3352 const DataIterator& dit = dbl.dataIterator();
3353
3354 const int nbox = dit.size();
3355
3356#pragma omp parallel for schedule(runtime)
3357 for (int mybox = 0; mybox < nbox; mybox++) {
3358 const DataIndex& din = dit[mybox];
3359
3360 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
3361 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
3362
3363 double* const w = solverLeaf.weightColumn();
3364 double* const pos[SpaceDim] = {
3365 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
3366 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
3367 solverLeaf.template column<&P::v_y>(),
3368 solverLeaf.template column<&P::v_z>())};
3369
3370 std::size_t i = 0;
3371 while (i < solverLeaf.size()) {
3372 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
3373 const RealVect vec(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
3374 const Real v = vec.vectorLength();
3375 const Real E = v;
3376 const Real deltaX = m_townsendGridDx * dx;
3377 const Real dt = deltaX / v;
3378 const RealVect newPos = x + dt * vec;
3379
3380 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
3381 const bool insideEB = this->particleInsideEB(newPos);
3382
3383 // Stop integration if avalanche phase is over
3384 const Real alpha = m_alpha(E, x);
3385 const Real eta = m_eta(E, x);
3386 const Real alphaEff = alpha - eta;
3387 const bool negativeAlpha = alphaEff <= 0.0;
3388
3389 w[i] = 0.0;
3390
3391 if (insideEB) {
3392 w[i] = m_secondaryEmission(E, x);
3393
3394 processedLeaf.appendParticle(solverLeaf, i);
3395 solverLeaf.remove(i);
3396 }
3397 else if (outsideDomain || negativeAlpha) {
3398 processedLeaf.appendParticle(solverLeaf, i);
3399 solverLeaf.remove(i);
3400 }
3401 else {
3402 for (int dir = 0; dir < SpaceDim; dir++) {
3403 pos[dir][i] = newPos[dir];
3404 }
3405
3406 i++;
3407 }
3408 }
3409 }
3410 }
3411
3412 // Update velocities.
3413 m_tracerParticleSolver->remap();
3414 m_tracerParticleSolver->interpolateVelocities();
3415 }
3416
3417 ParticleOps::copyDestructive(amrParticles, amrProcessedParticles);
3418
3419 this->rewindTracerParticles();
3420
3421 size_t particlesAfter = 0;
3422
3423 if (m_debug) {
3424 particlesAfter = amrParticles.getNumberOfValidParticlesGlobal();
3425 }
3426
3427 if (particlesBefore != particlesAfter) {
3428 MayDay::Warning("DischargeInceptionStepper::townsendTrackEuler - lost/gained particles!");
3429 }
3430}
3431
3432template <typename P, typename F, typename C>
3433void
3435{
3436 CH_TIME("DischargeInceptionStepper::townsendTrackTrapezoidal");
3437 if (m_verbosity > 5) {
3438 pout() << "DischargeInceptionStepper::townsendTrackTrapezoidal" << endl;
3439 }
3440
3441 // TLDR: We move the particle using Heun's method.
3442 //
3443 // p^(k+1) = p^k + 0.5 * dt * [v(p^k) + v(p^l)]
3444 //
3445 // where p^l = p^k + dt * v(p^k). We will set dt = d/|v(p^k)|.
3446
3447 const RealVect probLo = m_amr->getProbLo();
3448 const RealVect probHi = m_amr->getProbHi();
3449
3450 // Allocate a data holder for holding the processed particles. This
3451 // will be faster because then we only have to iterate through the
3452 // particles that are actually still moving.
3453 ParticleContainer<P> amrProcessedParticles;
3454 m_amr->allocate(amrProcessedParticles, m_realm);
3455
3456 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
3457
3458 m_tracerParticleSolver->remap();
3459
3460 size_t particlesBefore = 0;
3461
3462 if (m_debug) {
3463 particlesBefore = amrParticles.getNumberOfValidParticlesGlobal();
3464 }
3465
3466 // Allocate something that holds the velocity of the ions
3467 EBAMRCellData scratch;
3468 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
3469 this->superposition(scratch, a_voltage);
3470
3471 m_tracerParticleSolver->setVelocity(scratch);
3472 m_tracerParticleSolver->interpolateVelocities();
3473
3474 while (amrParticles.getNumberOfValidParticlesGlobal() > 0) {
3475
3476 // Euler stage.
3477 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3478 const Real dx = m_amr->getDx()[lvl];
3479
3480 // First stage
3481 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3482 const DataIterator& dit = dbl.dataIterator();
3483
3484 const int nbox = dit.size();
3485
3486#pragma omp parallel for schedule(runtime)
3487 for (int mybox = 0; mybox < nbox; mybox++) {
3488 const DataIndex& din = dit[mybox];
3489
3490 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
3491 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
3492
3493 double* const w = solverLeaf.weightColumn();
3494 double* const pos[SpaceDim] = {
3495 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
3496 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
3497 solverLeaf.template column<&P::v_y>(),
3498 solverLeaf.template column<&P::v_z>())};
3499 ParticleReal* const vk[SpaceDim] = {D_DECL(solverLeaf.template column<&P::vk_x>(),
3500 solverLeaf.template column<&P::vk_y>(),
3501 solverLeaf.template column<&P::vk_z>())};
3502 ParticleReal* const alphaEffCol = solverLeaf.template column<&P::alphaEff>();
3503 ParticleReal* const dtCol = solverLeaf.template column<&P::dtStep>();
3504
3505 std::size_t i = 0;
3506 while (i < solverLeaf.size()) {
3507 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
3508 const RealVect vec(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
3509 const Real v = vec.vectorLength();
3510 const Real E = v;
3511 const Real alpha = m_alpha(E, x);
3512 const Real eta = m_eta(E, x);
3513 const Real alphaEff = alpha - eta;
3514
3515 // Compute a time step that we will use for the integration.
3516 const Real deltaX = m_townsendGridDx * dx;
3517 const Real dt = deltaX / v;
3518 const RealVect newPos = x + vec * dt;
3519
3520 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
3521 const bool insideEB = this->particleInsideEB(newPos);
3522
3523 if (insideEB) {
3524 w[i] = m_secondaryEmission(E, x);
3525
3526 processedLeaf.appendParticle(solverLeaf, i);
3527 solverLeaf.remove(i);
3528 }
3529 else if (alphaEff < 0.0) {
3530 processedLeaf.appendParticle(solverLeaf, i);
3531 solverLeaf.remove(i);
3532 }
3533 else if (outsideDomain) {
3534 processedLeaf.appendParticle(solverLeaf, i);
3535 solverLeaf.remove(i);
3536 }
3537 else {
3538 // Do an Euler step, storing alpha(p^k), v(p^k), and the time step size.
3539 alphaEffCol[i] = alphaEff;
3540 dtCol[i] = dt;
3541 for (int dir = 0; dir < SpaceDim; dir++) {
3542 vk[dir][i] = vec[dir];
3543 pos[dir][i] = newPos[dir];
3544 }
3545
3546 i++;
3547 }
3548 }
3549 }
3550 }
3551
3552 // Remap and update velocities.
3553 m_tracerParticleSolver->remap();
3554 m_tracerParticleSolver->interpolateVelocities();
3555
3556 // Second stage.
3557 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3558 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3559 const DataIterator& dit = dbl.dataIterator();
3560
3561 const int nbox = dit.size();
3562
3563#pragma omp parallel for schedule(runtime)
3564 for (int mybox = 0; mybox < nbox; mybox++) {
3565 const DataIndex& din = dit[mybox];
3566
3567 ParticleSoA<P>& solverLeaf = amrParticles[lvl][din];
3568 ParticleSoA<P>& processedLeaf = amrProcessedParticles[lvl][din];
3569
3570 double* const w = solverLeaf.weightColumn();
3571 double* const pos[SpaceDim] = {
3572 D_DECL(solverLeaf.positionColumn(0), solverLeaf.positionColumn(1), solverLeaf.positionColumn(2))};
3573 const ParticleReal* const vel[SpaceDim] = {D_DECL(solverLeaf.template column<&P::v_x>(),
3574 solverLeaf.template column<&P::v_y>(),
3575 solverLeaf.template column<&P::v_z>())};
3576 const ParticleReal* const vk[SpaceDim] = {D_DECL(solverLeaf.template column<&P::vk_x>(),
3577 solverLeaf.template column<&P::vk_y>(),
3578 solverLeaf.template column<&P::vk_z>())};
3579 const ParticleReal* const alphaEffCol = solverLeaf.template column<&P::alphaEff>();
3580 const ParticleReal* const dtCol = solverLeaf.template column<&P::dtStep>();
3581
3582 std::size_t i = 0;
3583 while (i < solverLeaf.size()) {
3584 const Real dt = dtCol[i];
3585 const RealVect vkv(D_DECL(vk[0][i], vk[1][i], vk[2][i]));
3586 const RealVect vk1(D_DECL(vel[0][i], vel[1][i], vel[2][i]));
3587 const RealVect x(D_DECL(pos[0][i], pos[1][i], pos[2][i]));
3588 const Real E = vk1.vectorLength();
3589
3590 // Note the weird subtraction since the position was updated to p^k + dt * v^k.
3591 const RealVect oldPos = x - dt * vkv;
3592 const RealVect newPos = x + 0.5 * dt * (vk1 - vkv);
3593
3594 // Compute new alpha.
3595 const Real alphak = alphaEffCol[i];
3596 const Real alphak1 = m_alpha(E, x) - m_eta(E, x);
3597
3598 // Stop integration for particles that move into regions alpha < 0.0,
3599 // inside the EB or outside of the domain.
3600 const bool negativeAlpha = (alphak + alphak1) < 0.0;
3601 const bool outsideDomain = this->particleOutsideGrid(newPos, probLo, probHi);
3602 const bool insideEB = this->particleInsideEB(newPos);
3603
3604 // (negativeAlpha is computed but, as in the original, only outsideDomain/insideEB stop the track.)
3605 (void)negativeAlpha;
3606
3607 if (insideEB) {
3608 w[i] = m_secondaryEmission(E, oldPos);
3609
3610 processedLeaf.appendParticle(solverLeaf, i);
3611 solverLeaf.remove(i);
3612 }
3613 else if (outsideDomain) {
3614 processedLeaf.appendParticle(solverLeaf, i);
3615 solverLeaf.remove(i);
3616 }
3617 else {
3618 for (int dir = 0; dir < SpaceDim; dir++) {
3619 pos[dir][i] = newPos[dir];
3620 }
3621
3622 i++;
3623 }
3624 }
3625 }
3626 }
3627
3628 // Remap and update velocities.
3629 m_tracerParticleSolver->remap();
3630 m_tracerParticleSolver->interpolateVelocities();
3631 }
3632
3633 // Copy processed particles over to the solver particles.
3634 ParticleOps::copyDestructive(amrParticles, amrProcessedParticles);
3635
3636 this->rewindTracerParticles();
3637
3638 size_t particlesAfter = 0;
3639
3640 if (m_debug) {
3641 particlesAfter = amrParticles.getNumberOfValidParticlesGlobal();
3642 }
3643
3644 if (particlesBefore != particlesAfter) {
3645 MayDay::Warning("DischargeInceptionStepper::townsendTrackTrapezoidal - lost/gained particles!");
3646 }
3647}
3648
3649template <typename P, typename F, typename C>
3650Real
3651DischargeInceptionStepper<P, F, C>::computeRdot(const Real& a_voltage) const noexcept
3652{
3653 CH_TIME("DischargeInceptionStepper::computeRdot");
3654 if (m_verbosity > 5) {
3655 pout() << "DischargeInceptionStepper::computeRdot" << endl;
3656 }
3657
3658 Real Rdot = 0.0;
3659
3660 // TLDR: We are computing the integral of done/dt * (1-eta/alpha) over the critical volume and integral(j/e * dS) over
3661 // the "critical surface"
3662 const RealVect probLo = m_amr->getProbLo();
3663
3664 // Compute the electric field at the input voltage
3665 EBAMRCellData scratch;
3666 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
3667 this->superposition(scratch, a_voltage);
3668
3669 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3670 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3671 const DataIterator& dit = dbl.dataIterator();
3672 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
3673 const Real dx = m_amr->getDx()[lvl];
3674
3675 const Real vol = std::pow(dx, SpaceDim);
3676 const Real area = std::pow(dx, SpaceDim - 1);
3677
3678 const int nbox = dit.size();
3679
3680#pragma omp parallel for schedule(runtime) reduction(+ : Rdot)
3681 for (int mybox = 0; mybox < nbox; mybox++) {
3682 const DataIndex& din = dit[mybox];
3683
3684 const EBISBox& ebisbox = ebisl[din];
3685 const BaseFab<bool>& validCells = (*m_amr->getValidCells(m_realm)[lvl])[din];
3686
3687 const EBCellFAB& electricField = (*scratch[lvl])[din];
3688 const EBCellFAB& inceptionIntegral = (*m_inceptionIntegral[lvl])[din];
3689 const EBCellFAB& fieldEmission = (*m_emissionRate[lvl])[din];
3690 const EBCellFAB& ionDensity = (*m_ionSolver->getPhi()[lvl])[din];
3691
3692 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
3693 const FArrayBox& inceptionIntegralReg = inceptionIntegral.getFArrayBox();
3694 const FArrayBox& ionDensityReg = ionDensity.getFArrayBox();
3695
3696 // Add contribution from background ionization in regular cells.
3697 auto regularKernel = [&](const IntVect& iv) -> void {
3698 if (ebisbox.isRegular(iv) && validCells(iv, 0)) {
3699 if (inceptionIntegralReg(iv, 0) >= m_inceptionK) {
3700 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
3701 const RealVect EE = RealVect(
3702 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
3703 const Real E = EE.vectorLength();
3704
3705 const Real alpha = m_alpha(E, pos);
3706 const Real eta = m_eta(E, pos);
3707 const Real k = m_detachmentRate(E, pos);
3708 const Real dndt = m_backgroundRate(E, pos) + k * ionDensityReg(iv, 0);
3709
3710 CH_assert(alpha >= eta);
3711
3712 Rdot += dndt * (1.0 - eta / alpha) * vol;
3713 }
3714 }
3715 };
3716
3717 // Add contribution from background ionization and field emission in cut-cells.
3718 auto irregularKernel = [&](const VolIndex& vof) -> void {
3719 const IntVect iv = vof.gridIndex();
3720 if (ebisbox.isIrregular(iv) && validCells(iv, 0)) {
3721 if (inceptionIntegral(vof, 0) >= m_inceptionK) {
3722 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
3723 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
3724 const Real E = EE.vectorLength();
3725
3726 const Real kappa = ebisbox.volFrac(vof);
3727 const Real areaFrac = ebisbox.bndryArea(vof);
3728 const Real alpha = m_alpha(E, pos);
3729 const Real eta = m_eta(E, pos);
3730 const Real k = m_detachmentRate(E, pos);
3731 const Real j = m_fieldEmission(E, pos);
3732 const Real dndt = m_backgroundRate(E, pos) + k * ionDensity(vof, 0);
3733
3734 Rdot += dndt * (1.0 - eta / alpha) * kappa * vol;
3735 Rdot += j / Units::Qe * areaFrac * area;
3736 }
3737 }
3738 };
3739
3740 // Run the kernels. Not vectorizable: FP sum reduction (Rdot) + multiple std::function coefficients
3741 // (m_alpha/m_eta/m_detachmentRate/m_fieldEmission/m_backgroundRate) + data-dependent branch.
3742 Box cellBox = dbl[din];
3743 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
3744
3745 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
3746 BoxLoops::loop(vofit, irregularKernel);
3747 }
3748 }
3749
3750 return ParallelOps::sum(Rdot);
3751}
3752
3753template <typename P, typename F, typename C>
3754void
3756{
3757 CH_TIME("DischargeInceptionStepper::rewindTracerParticles");
3758 if (m_verbosity > 5) {
3759 pout() << "DischargeInceptionStepper::rewindTracerParticles" << endl;
3760 }
3761
3762 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
3763
3764 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3765 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3766 const DataIterator& dit = dbl.dataIterator();
3767
3768 const int nbox = dit.size();
3769
3770#pragma omp parallel for schedule(runtime)
3771 for (int mybox = 0; mybox < nbox; mybox++) {
3772 const DataIndex& din = dit[mybox];
3773
3774 ParticleSoA<P>& leaf = amrParticles[lvl][din];
3775
3776 double* const pos[SpaceDim] = {D_DECL(leaf.positionColumn(0), leaf.positionColumn(1), leaf.positionColumn(2))};
3777 const double* const x0[SpaceDim] = {
3778 D_DECL(leaf.template column<&P::x0_x>(), leaf.template column<&P::x0_y>(), leaf.template column<&P::x0_z>())};
3779
3780 ParticleLoops::loop(leaf, [&](const std::size_t i) {
3781 for (int dir = 0; dir < SpaceDim; dir++) {
3782 pos[dir][i] = x0[dir][i]; // rewind to the snapshot position
3783 }
3784 });
3785 }
3786 }
3787
3788 amrParticles.remap();
3789}
3790
3791template <typename P, typename F, typename C>
3792void
3794{
3795 CH_TIME("DischargeInceptionStepper::resetTracerParticles");
3796 if (m_verbosity > 5) {
3797 pout() << "DischargeInceptionStepper::resetTracerParticles" << endl;
3798 }
3799
3800 ParticleContainer<P>& amrParticles = m_tracerParticleSolver->getParticles();
3801
3802 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3803 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3804 const DataIterator& dit = dbl.dataIterator();
3805
3806 const int nbox = dit.size();
3807
3808#pragma omp parallel for schedule(runtime)
3809 for (int mybox = 0; mybox < nbox; mybox++) {
3810 const DataIndex& din = dit[mybox];
3811
3812 ParticleSoA<P>& leaf = amrParticles[lvl][din];
3813
3814 double* const w = leaf.weightColumn();
3815
3816 ParticleLoops::loop(leaf, [&](const std::size_t i) {
3817 w[i] = 0.0;
3818 });
3819 }
3820 }
3821}
3822
3823template <typename P, typename F, typename C>
3824void
3826{
3827 CH_TIME("DischargeInceptionStepper::computeBackgroundIonizationStationary");
3828 if (m_verbosity > 5) {
3829 pout() << "DischargeInceptionStepper::computeBackgroundIonizationStationary" << endl;
3830 }
3831
3832 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
3833 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
3834 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
3835
3837
3838 // Holds the electric field
3839 EBAMRCellData scratch;
3840 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
3841
3842 // Solve ionization volume for each voltage
3843 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
3844 const Real voltage = m_voltageSweeps[i];
3845
3846 // Compute the electric field into the scratch storage
3847 this->superposition(scratch, voltage);
3848
3849 EBAMRCellData backgroundRate;
3850
3851 m_amr->allocate(backgroundRate, m_realm, m_phase, 1);
3852
3853 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3854 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3855 const DataIterator& dit = dbl.dataIterator();
3856 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
3857 const Real dx = m_amr->getDx()[lvl];
3858 const RealVect probLo = m_amr->getProbLo();
3859
3860 const int nbox = dit.size();
3861
3862#pragma omp parallel for schedule(runtime)
3863 for (int mybox = 0; mybox < nbox; mybox++) {
3864 const DataIndex& din = dit[mybox];
3865
3866 const EBISBox& ebisbox = ebisl[din];
3867
3868 EBCellFAB& bgIonization = (*backgroundRate[lvl])[din];
3869 FArrayBox& bgIonizationReg = bgIonization.getFArrayBox();
3870
3871 const EBCellFAB& electricField = (*scratch[lvl])[din];
3872 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
3873
3874 auto regularKernel = [&](const IntVect& iv) -> void {
3875 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
3876 const RealVect EE = RealVect(
3877 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
3878 const Real E = EE.vectorLength();
3879
3880 bgIonizationReg(iv, 0) = m_backgroundRate(E, pos);
3881 };
3882
3883 auto irregularKernel = [&](const VolIndex& vof) -> void {
3884 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
3885 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
3886 const Real E = EE.vectorLength();
3887
3888 bgIonization(vof, 0) = m_backgroundRate(E, pos);
3889 };
3890
3891 // Execute kernels. Not vectorizable: m_backgroundRate std::function coefficient evaluated per cell.
3892 // (Representative of the stationary coefficient computes -- detachment/field-emission/evaluateFunction/
3893 // ion mobility/ion diffusion all share this std::function-per-cell structure.)
3894 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
3895
3896 BoxLoops::loop<D_DECL(1, 1, 1)>(dbl[din], regularKernel);
3897 BoxLoops::loop(vofit, irregularKernel);
3898 }
3899 }
3900
3901 m_backgroundIonizationStationary.push_back(backgroundRate);
3902 }
3903}
3904
3905template <typename P, typename F, typename C>
3906void
3908{
3909 CH_TIME("DischargeInceptionStepper::computeDetachmentStationary");
3910 if (m_verbosity > 5) {
3911 pout() << "DischargeInceptionStepper::computeDetachmentStationary" << endl;
3912 }
3913
3914 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
3915 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
3916 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
3917
3918 m_detachmentStationary.resize(0);
3919
3920 // Holds the electric field
3921 EBAMRCellData scratch;
3922 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
3923
3924 // Solve ionization volume for each voltage
3925 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
3926 const Real voltage = m_voltageSweeps[i];
3927
3928 // Compute the electric field into the scratch storage
3929 this->superposition(scratch, voltage);
3930
3931 EBAMRCellData detachmentRate;
3932
3933 m_amr->allocate(detachmentRate, m_realm, m_phase, 1);
3934
3935 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
3936 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
3937 const DataIterator& dit = dbl.dataIterator();
3938 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
3939 const Real dx = m_amr->getDx()[lvl];
3940 const RealVect probLo = m_amr->getProbLo();
3941
3942 const int nbox = dit.size();
3943
3944#pragma omp parallel for schedule(runtime)
3945 for (int mybox = 0; mybox < nbox; mybox++) {
3946 const DataIndex& din = dit[mybox];
3947
3948 const EBISBox& ebisbox = ebisl[din];
3949
3950 EBCellFAB& detachment = (*detachmentRate[lvl])[din];
3951 FArrayBox& detachmentReg = detachment.getFArrayBox();
3952
3953 const EBCellFAB& ionDensity = (*m_ionSolver->getPhi()[lvl])[din];
3954 const EBCellFAB& electricField = (*scratch[lvl])[din];
3955
3956 const FArrayBox& ionDensityReg = ionDensity.getFArrayBox();
3957 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
3958
3959 auto regularKernel = [&](const IntVect& iv) -> void {
3960 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
3961 const RealVect EE = RealVect(
3962 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
3963 const Real E = EE.vectorLength();
3964 const Real phi = ionDensityReg(iv, 0);
3965
3966 detachmentReg(iv, 0) = m_detachmentRate(E, pos) * phi;
3967 };
3968
3969 auto irregularKernel = [&](const VolIndex& vof) -> void {
3970 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
3971 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
3972 const Real E = EE.vectorLength();
3973 const Real phi = ionDensity(vof, 0);
3974
3975 detachment(vof, 0) = m_detachmentRate(E, pos) * phi;
3976 };
3977
3978 // Execute kernels
3979 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
3980
3981 BoxLoops::loop<D_DECL(1, 1, 1)>(dbl[din], regularKernel);
3982 BoxLoops::loop(vofit, irregularKernel);
3983 }
3984 }
3985
3986 m_amr->conservativeAverage(detachmentRate, m_realm, m_phase);
3987 m_amr->interpGhost(detachmentRate, m_realm, m_phase);
3988
3989 m_detachmentStationary.push_back(detachmentRate);
3990 }
3991}
3992
3993template <typename P, typename F, typename C>
3994void
3996{
3997 CH_TIME("DischargeInceptionStepper::computeFieldEmissionStationary");
3998 if (m_verbosity > 5) {
3999 pout() << "DischargeInceptionStepper::computeFieldEmissionStationary" << endl;
4000 }
4001
4002 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
4003 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
4004 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
4005
4006 m_emissionRatesPlus.resize(0);
4007 m_emissionRatesMinu.resize(0);
4008
4009 const int numVoltages = m_inceptionIntegralPlus.size();
4010
4011 // Holds the electric field
4012 EBAMRCellData scratchPlus;
4013 EBAMRCellData scratchMinu;
4014
4015 m_amr->allocate(scratchPlus, m_realm, m_phase, SpaceDim);
4016 m_amr->allocate(scratchMinu, m_realm, m_phase, SpaceDim);
4017
4018 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
4019 const Real voltage = m_voltageSweeps[i];
4020
4021 // Compute the electric field into the scratch storage
4022 this->superposition(scratchPlus, +voltage);
4023 this->superposition(scratchMinu, -voltage);
4024
4025 EBAMRCellData emissionRatesPlus;
4026 EBAMRCellData emissionRatesMinu;
4027
4028 m_amr->allocate(emissionRatesPlus, m_realm, m_phase, 1);
4029 m_amr->allocate(emissionRatesMinu, m_realm, m_phase, 1);
4030
4031 DataOps::setValue(emissionRatesPlus, 0.0);
4032 DataOps::setValue(emissionRatesMinu, 0.0);
4033
4034 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
4035 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4036 const DataIterator& dit = dbl.dataIterator();
4037 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4038 const Real& dx = m_amr->getDx()[lvl];
4039 const RealVect probLo = m_amr->getProbLo();
4040
4041 const int nbox = dit.size();
4042
4043#pragma omp parallel for schedule(runtime)
4044 for (int mybox = 0; mybox < nbox; mybox++) {
4045 const DataIndex& din = dit[mybox];
4046
4047 const EBISBox& ebisbox = ebisl[din];
4048
4049 // Here, emissionPlus is when we have the standard voltage (V = 1) and
4050 // emissionMinu is when the voltage is reverted.
4051 EBCellFAB& emissionPlus = (*emissionRatesPlus[lvl])[din];
4052 EBCellFAB& emissionMinu = (*emissionRatesMinu[lvl])[din];
4053
4054 emissionPlus.setVal(0.0);
4055 emissionMinu.setVal(0.0);
4056
4057 const EBCellFAB& electricFieldPlus = (*scratchPlus[lvl])[din];
4058 const EBCellFAB& electricFieldMinu = (*scratchMinu[lvl])[din];
4059
4060 auto irregularKernel = [&](const VolIndex& vof) -> void {
4061 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
4062
4063 const RealVect Eplus = RealVect(
4064 D_DECL(electricFieldPlus(vof, 0), electricFieldPlus(vof, 1), electricFieldPlus(vof, 2)));
4065 const RealVect Eminu = RealVect(
4066 D_DECL(electricFieldMinu(vof, 0), electricFieldMinu(vof, 1), electricFieldMinu(vof, 2)));
4067
4068 const Real normalEplus = Eplus.dotProduct(ebisbox.normal(vof));
4069 const Real normalEminu = Eminu.dotProduct(ebisbox.normal(vof));
4070
4071 emissionPlus(vof, 0) = 0.0;
4072 emissionMinu(vof, 0) = 0.0;
4073
4074 if (normalEplus < 0.0) {
4075 emissionPlus(vof, 0) = m_fieldEmission(Eplus.vectorLength(), pos);
4076 }
4077 if (normalEminu < 0.0) {
4078 emissionMinu(vof, 0) = m_fieldEmission(Eminu.vectorLength(), pos);
4079 }
4080 };
4081
4082 // Execute kernels
4083 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4084 BoxLoops::loop(vofit, irregularKernel);
4085 }
4086 }
4087
4088 m_emissionRatesPlus.push_back(emissionRatesPlus);
4089 m_emissionRatesMinu.push_back(emissionRatesMinu);
4090 }
4091}
4092
4093template <typename P, typename F, typename C>
4094void
4096 const Real& a_voltage) const noexcept
4097{
4098 CH_TIME("DischargeInceptionStepper::computeFieldEmission");
4099 if (m_verbosity > 5) {
4100 pout() << "DischargeInceptionStepper::computeFieldEmission" << endl;
4101 }
4102
4103 CH_assert(a_emissionRate[0]->nComp() == 1);
4104
4105 const RealVect probLo = m_amr->getProbLo();
4106
4107 // Compute the electric field into the scratch storage
4108 EBAMRCellData scratch;
4109 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
4110 this->superposition(scratch, a_voltage);
4111
4112 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
4113 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4114 const DataIterator& dit = dbl.dataIterator();
4115 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4116 const Real dx = m_amr->getDx()[lvl];
4117
4118 const int nbox = dit.size();
4119
4120#pragma omp parallel for schedule(runtime)
4121 for (int mybox = 0; mybox < nbox; mybox++) {
4122 const DataIndex& din = dit[mybox];
4123
4124 const EBISBox& ebisbox = ebisl[din];
4125
4126 // Here, emissionPlus is when we have the standard voltage (V = 1) and
4127 // emissionMinu is when the voltage is reverted.
4128 EBCellFAB& emission = (*a_emissionRate[lvl])[din];
4129
4130 emission.setVal(0.0);
4131
4132 const EBCellFAB& electricField = (*scratch[lvl])[din];
4133 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
4134
4135 auto irregularKernel = [&](const VolIndex& vof) -> void {
4136 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
4137 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
4138 const Real E = EE.vectorLength();
4139
4140 if (EE.dotProduct(ebisbox.normal(vof)) > 0.0) {
4141 emission(vof, 0) = m_fieldEmission(E, pos);
4142 }
4143 };
4144
4145 // Execute kernels
4146 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4147 BoxLoops::loop(vofit, irregularKernel);
4148 }
4149 }
4150}
4151
4152template <typename P, typename F, typename C>
4153void
4155 EBAMRCellData& a_data,
4156 const Real& a_voltage,
4157 const std::function<Real(const Real E, const RealVect x)>& a_func) const noexcept
4158{
4159 CH_TIME("DischargeInceptionStepper::evaluateFunction");
4160 if (m_verbosity > 5) {
4161 pout() << "DischargeInceptionStepper::evaluateFunction" << endl;
4162 }
4163
4164 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
4165 this->evaluateFunction(*a_data[lvl], a_voltage, a_func, lvl);
4166 }
4167}
4168
4169template <typename P, typename F, typename C>
4170void
4172 const Real& a_voltage,
4173 const std::function<Real(const Real E, const RealVect x)>& a_func,
4174 const int a_level) const noexcept
4175{
4176 CH_TIME("DischargeInceptionStepper::evaluateFunction(level)");
4177 if (m_verbosity > 5) {
4178 pout() << "DischargeInceptionStepper::evaluateFunction(level)" << endl;
4179 }
4180
4181 CH_assert(a_level >= 0);
4182 CH_assert(a_level <= m_amr->getFinestLevel());
4183
4184 // Compute the electric field
4185 EBAMRCellData scratch;
4186 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
4187 this->superposition(scratch, a_voltage);
4188
4189 const RealVect probLo = m_amr->getProbLo();
4190
4191 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[a_level];
4192 const DataIterator& dit = dbl.dataIterator();
4193 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[a_level];
4194 const Real dx = m_amr->getDx()[a_level];
4195
4196 const int nbox = dit.size();
4197
4198#pragma omp parallel for schedule(runtime)
4199 for (int mybox = 0; mybox < nbox; mybox++) {
4200 const DataIndex& din = dit[mybox];
4201
4202 const EBISBox& ebisbox = ebisl[din];
4203
4204 // Here, emissionPlus is when we have the standard voltage (V = 1) and
4205 // emissionMinu is when the voltage is reverted.
4206 EBCellFAB& data = a_data[din];
4207 FArrayBox& dataReg = data.getFArrayBox();
4208
4209 data.setVal(0.0);
4210
4211 const EBCellFAB& electricField = (*scratch[a_level])[din];
4212 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
4213
4214 auto regularKernel = [&](const IntVect& iv) -> void {
4215 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
4216 const RealVect EE = RealVect(D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
4217 const Real E = EE.vectorLength();
4218
4219 dataReg(iv, 0) = a_func(E, pos);
4220 };
4221
4222 auto irregularKernel = [&](const VolIndex& vof) -> void {
4223 const RealVect pos = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
4224 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
4225 const Real E = EE.vectorLength();
4226
4227 data(vof, 0) = a_func(E, pos);
4228 };
4229
4230 // Execute kernels
4231 Box cellBox = dbl[din];
4232 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[a_level])[din];
4233
4234 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4235 BoxLoops::loop(vofit, irregularKernel);
4236 }
4237}
4238
4239template <typename P, typename F, typename C>
4240void
4242{
4243 CH_TIME("DischargeInceptionStepper::computeInceptionVoltageVolume");
4244 if (m_verbosity > 5) {
4245 pout() << "DischargeInceptionStepper::computeInceptionVoltageVolume" << endl;
4246 }
4247
4248 // TLDR: This routine runs through all the K-values in each cell and estimates the
4249 // inception voltage using linear interpolation.
4250
4251 CH_assert(m_mode == Mode::Stationary);
4252
4253 if (m_inceptionIntegralPlus.size() < 2) {
4254 DataOps::setValue(m_inceptionVoltagePlus, std::numeric_limits<Real>::quiet_NaN());
4255 DataOps::setValue(m_inceptionVoltageMinu, std::numeric_limits<Real>::quiet_NaN());
4256
4257 MayDay::Warning("DischargeInceptionStepper::computeInceptionVoltageVolume -- not enough voltages for estimating "
4258 "inception voltage");
4259 }
4260 else {
4261 constexpr int comp = 0;
4262
4263 // Function which interpolates the inception voltage if possible. Used in the kernels. This one does interpolation.
4264 auto calcUincInterp = [Kinc = this->m_inceptionK,
4265 &V = this->m_voltageSweeps](const std::vector<Real>& K,
4266 const std::vector<Real>& T) -> std::array<Real, 3> {
4267 Real streamerInc = std::numeric_limits<Real>::quiet_NaN();
4268 Real townsendInc = std::numeric_limits<Real>::quiet_NaN();
4269
4270 bool foundInception = false;
4271
4272 // Streamer criterion
4273 for (size_t i = 0; i < K.size() - 1; i++) {
4274 if (K[i] <= Kinc && K[i + 1] > Kinc) {
4275 streamerInc = V[i] + (Kinc - K[i]) * (V[i + 1] - V[i]) / (K[i + 1] - K[i]);
4276
4277 break;
4278 }
4279 else if (K[i] == Kinc) {
4280 streamerInc = V[i];
4281
4282 break;
4283 }
4284 }
4285
4286 // Townsend criterion
4287 for (size_t i = 0; i < T.size() - 1; i++) {
4288 if (T[i] <= 1.0 && T[i + 1] > 1) {
4289 townsendInc = V[i] + (1.0 - T[i]) * (V[i + 1] - V[i]) / (T[i + 1] - T[i]);
4290
4291 break;
4292 }
4293 else if (T[i] == 1.0) {
4294 townsendInc = V[i];
4295
4296 break;
4297 }
4298 }
4299
4300 Real Uinc;
4301
4302 if (std::isnan(streamerInc) && std::isnan(townsendInc)) {
4303 Uinc = std::numeric_limits<Real>::quiet_NaN();
4304 }
4305 else if (std::isnan(streamerInc) && !std::isnan(townsendInc)) {
4306 Uinc = townsendInc;
4307 }
4308 else if (!std::isnan(streamerInc) && std::isnan(townsendInc)) {
4309 Uinc = streamerInc;
4310 }
4311 else {
4312 Uinc = std::min(streamerInc, townsendInc);
4313 }
4314
4315 return std::array<Real, 3>{Uinc, streamerInc, townsendInc};
4316 };
4317
4318 // Same functionality as above, but without interpolation.
4319 auto calcUincNoInterp = [Kinc = this->m_inceptionK,
4320 &V = this->m_voltageSweeps](const std::vector<Real>& K,
4321 const std::vector<Real>& T) -> std::array<Real, 3> {
4322 Real streamerInc = std::numeric_limits<Real>::quiet_NaN();
4323 Real townsendInc = std::numeric_limits<Real>::quiet_NaN();
4324
4325 // Streamer criterion
4326 for (size_t i = 0; i < K.size() - 1; i++) {
4327 if (K[i] <= Kinc && K[i + 1] >= Kinc) {
4328 streamerInc = V[i];
4329
4330 break;
4331 }
4332 }
4333
4334 // Townsend criterion
4335 for (size_t i = 0; i < T.size() - 1; i++) {
4336 if (T[i] <= 1.0 && T[i + 1] >= 1) {
4337 townsendInc = V[i];
4338
4339 break;
4340 }
4341 }
4342
4343 Real Uinc;
4344
4345 if (std::isnan(streamerInc) && std::isnan(townsendInc)) {
4346 Uinc = std::numeric_limits<Real>::quiet_NaN();
4347 }
4348 else if (std::isnan(streamerInc) && !std::isnan(townsendInc)) {
4349 Uinc = townsendInc;
4350 }
4351 else if (!std::isnan(streamerInc) && std::isnan(townsendInc)) {
4352 Uinc = streamerInc;
4353 }
4354 else {
4355 Uinc = std::min(streamerInc, townsendInc);
4356 }
4357
4358 return std::array<Real, 3>{Uinc, streamerInc, townsendInc};
4359 };
4360
4361 // Iterate through m_inceptionIntegral data and calculate the inception voltage.
4362 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4363 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4364 const DataIterator& dit = dbl.dataIterator();
4365
4366 const int nbox = dit.size();
4367
4368#pragma omp parallel for schedule(runtime)
4369 for (int mybox = 0; mybox < nbox; mybox++) {
4370 const DataIndex& din = dit[mybox];
4371
4372 EBCellFAB& inceptionVoltagePlus = (*m_inceptionVoltagePlus[lvl])[din];
4373 EBCellFAB& inceptionVoltageMinu = (*m_inceptionVoltageMinu[lvl])[din];
4374 EBCellFAB& streamerInceptionVoltagePlus = (*m_streamerInceptionVoltagePlus[lvl])[din];
4375 EBCellFAB& streamerInceptionVoltageMinu = (*m_streamerInceptionVoltageMinu[lvl])[din];
4376 EBCellFAB& townsendInceptionVoltagePlus = (*m_townsendInceptionVoltagePlus[lvl])[din];
4377 EBCellFAB& townsendInceptionVoltageMinu = (*m_townsendInceptionVoltageMinu[lvl])[din];
4378
4379 FArrayBox& inceptionVoltagePlusReg = inceptionVoltagePlus.getFArrayBox();
4380 FArrayBox& inceptionVoltageMinuReg = inceptionVoltageMinu.getFArrayBox();
4381 FArrayBox& streamerInceptionVoltagePlusReg = streamerInceptionVoltagePlus.getFArrayBox();
4382 FArrayBox& streamerInceptionVoltageMinuReg = streamerInceptionVoltageMinu.getFArrayBox();
4383 FArrayBox& townsendInceptionVoltagePlusReg = townsendInceptionVoltagePlus.getFArrayBox();
4384 FArrayBox& townsendInceptionVoltageMinuReg = townsendInceptionVoltageMinu.getFArrayBox();
4385
4386 // Pack the inception integral and townsend criterions into workable vectors.
4387 Vector<const EBCellFAB*> inceptionIntegralPlus;
4388 Vector<const EBCellFAB*> inceptionIntegralMinu;
4389 Vector<const EBCellFAB*> townsendCriterionPlus;
4390 Vector<const EBCellFAB*> townsendCriterionMinu;
4391
4392 Vector<const FArrayBox*> inceptionIntegralPlusReg;
4393 Vector<const FArrayBox*> inceptionIntegralMinuReg;
4394 Vector<const FArrayBox*> townsendCriterionPlusReg;
4395 Vector<const FArrayBox*> townsendCriterionMinuReg;
4396
4397 for (int i = 0; i < m_voltageSweeps.size(); i++) {
4398 inceptionIntegralPlus.push_back(&(*(m_inceptionIntegralPlus[i])[lvl])[din]);
4399 inceptionIntegralMinu.push_back(&(*(m_inceptionIntegralMinu[i])[lvl])[din]);
4400 townsendCriterionPlus.push_back(&(*(m_townsendCriterionPlus[i])[lvl])[din]);
4401 townsendCriterionMinu.push_back(&(*(m_townsendCriterionMinu[i])[lvl])[din]);
4402
4403 inceptionIntegralPlusReg.push_back(&(inceptionIntegralPlus.back()->getFArrayBox()));
4404 inceptionIntegralMinuReg.push_back(&(inceptionIntegralMinu.back()->getFArrayBox()));
4405 townsendCriterionPlusReg.push_back(&(townsendCriterionPlus.back()->getFArrayBox()));
4406 townsendCriterionMinuReg.push_back(&(townsendCriterionMinu.back()->getFArrayBox()));
4407 }
4408
4409 // Regular kernel.
4410 auto regularKernel = [&](const IntVect& iv) -> void {
4411 std::vector<Real> Kplus;
4412 std::vector<Real> Kminu;
4413
4414 std::vector<Real> Tplus;
4415 std::vector<Real> Tminu;
4416
4417 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
4418 Kplus.emplace_back((*inceptionIntegralPlusReg[i])(iv, 0));
4419 Kminu.emplace_back((*inceptionIntegralMinuReg[i])(iv, 0));
4420
4421 Tplus.emplace_back((*townsendCriterionPlusReg[i])(iv, 0));
4422 Tminu.emplace_back((*townsendCriterionMinuReg[i])(iv, 0));
4423 }
4424
4425 std::array<Real, 3> inceptionVoltagesPlus;
4426 std::array<Real, 3> inceptionVoltagesMinu;
4427
4428 if (m_fullIntegration) {
4429 inceptionVoltagesPlus = calcUincInterp(Kplus, Tplus);
4430 inceptionVoltagesMinu = calcUincInterp(Kminu, Tminu);
4431 }
4432 else {
4433 inceptionVoltagesPlus = calcUincNoInterp(Kplus, Tplus);
4434 inceptionVoltagesMinu = calcUincNoInterp(Kminu, Tminu);
4435 }
4436
4437 inceptionVoltagePlusReg(iv, comp) = std::get<0>(inceptionVoltagesPlus);
4438 inceptionVoltageMinuReg(iv, comp) = std::get<0>(inceptionVoltagesMinu);
4439
4440 streamerInceptionVoltagePlusReg(iv, comp) = std::get<1>(inceptionVoltagesPlus);
4441 streamerInceptionVoltageMinuReg(iv, comp) = std::get<1>(inceptionVoltagesMinu);
4442
4443 townsendInceptionVoltagePlusReg(iv, comp) = std::get<2>(inceptionVoltagesPlus);
4444 townsendInceptionVoltageMinuReg(iv, comp) = std::get<2>(inceptionVoltagesMinu);
4445 };
4446
4447 // Irregular kernel.
4448 auto irregularKernel = [&](const VolIndex& vof) -> void {
4449 std::vector<Real> Kplus;
4450 std::vector<Real> Kminu;
4451
4452 std::vector<Real> Tplus;
4453 std::vector<Real> Tminu;
4454
4455 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
4456 Kplus.emplace_back((*inceptionIntegralPlus[i])(vof, 0));
4457 Kminu.emplace_back((*inceptionIntegralMinu[i])(vof, 0));
4458
4459 Tplus.emplace_back((*townsendCriterionPlus[i])(vof, 0));
4460 Tminu.emplace_back((*townsendCriterionMinu[i])(vof, 0));
4461 }
4462
4463 std::array<Real, 3> inceptionVoltagesPlus;
4464 std::array<Real, 3> inceptionVoltagesMinu;
4465
4466 if (m_fullIntegration) {
4467 inceptionVoltagesPlus = calcUincInterp(Kplus, Tplus);
4468 inceptionVoltagesMinu = calcUincInterp(Kminu, Tminu);
4469 }
4470 else {
4471 inceptionVoltagesPlus = calcUincNoInterp(Kplus, Tplus);
4472 inceptionVoltagesMinu = calcUincNoInterp(Kminu, Tminu);
4473 }
4474
4475 inceptionVoltagePlus(vof, comp) = std::get<0>(inceptionVoltagesPlus);
4476 inceptionVoltageMinu(vof, comp) = std::get<0>(inceptionVoltagesMinu);
4477
4478 streamerInceptionVoltagePlus(vof, comp) = std::get<1>(inceptionVoltagesPlus);
4479 streamerInceptionVoltageMinu(vof, comp) = std::get<1>(inceptionVoltagesMinu);
4480
4481 townsendInceptionVoltagePlus(vof, comp) = std::get<2>(inceptionVoltagesPlus);
4482 townsendInceptionVoltageMinu(vof, comp) = std::get<2>(inceptionVoltagesMinu);
4483 };
4484
4485 // Kernel regions.
4486 const Box& cellBox = dbl[din];
4487 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4488
4489 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4490 BoxLoops::loop(vofit, irregularKernel);
4491 }
4492 }
4493
4494 // Coarsen data.
4495 m_amr->conservativeAverage(m_inceptionVoltagePlus, m_realm, m_phase);
4497 }
4498}
4499
4500template <typename P, typename F, typename C>
4501std::pair<Real, RealVect>
4503{
4504 CH_TIME("DischargeInceptionStepper::computeMinimumInceptionVoltage");
4505 if (m_verbosity > 5) {
4506 pout() << "DischargeInceptionStepper::computeMinimumInceptionVoltage" << endl;
4507 }
4508
4509 const RealVect probLo = m_amr->getProbLo();
4510
4511 std::pair<Real, RealVect> UxInc;
4512
4513 UxInc.first = std::numeric_limits<Real>::max();
4514 UxInc.second = RealVect::Zero;
4515
4516 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
4517 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4518 const DataIterator& dit = dbl.dataIterator();
4519 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4520 const Real& dx = m_amr->getDx()[lvl];
4521
4522 const int nbox = dit.size();
4523
4524#pragma omp parallel for schedule(runtime) reduction(pairmin : UxInc)
4525 for (int mybox = 0; mybox < nbox; mybox++) {
4526 const DataIndex& din = dit[mybox];
4527
4528 const BaseFab<bool>& validCells = (*m_amr->getValidCells(m_realm)[lvl])[din];
4529 const EBISBox& ebisBox = ebisl[din];
4530
4531 const EBCellFAB& voltage = (*a_Uinc[lvl])[din];
4532 const FArrayBox& voltageReg = voltage.getFArrayBox();
4533
4534 auto regularKernel = [&](const IntVect& iv) -> void {
4535 if (validCells(iv, 0) && ebisBox.isRegular(iv)) {
4536 const Real& U = voltageReg(iv, 0);
4537 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
4538
4539 if (!(std::isnan(U))) {
4540 if (std::abs(U) < UxInc.first) {
4541 UxInc.first = std::abs(U);
4542 UxInc.second = pos;
4543 }
4544 }
4545 }
4546 };
4547
4548 auto irregularKernel = [&](const VolIndex& vof) -> void {
4549 const IntVect iv = vof.gridIndex();
4550 if (validCells(iv, 0) && ebisBox.isIrregular(iv)) {
4551 const Real& U = voltage(vof, 0);
4552 const RealVect centroid = ebisBox.centroid(vof);
4553 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv) + centroid) * dx;
4554
4555 if (!(std::isnan(U))) {
4556 if (std::abs(U) < UxInc.first) {
4557 UxInc.first = std::abs(U);
4558 UxInc.second = pos;
4559 }
4560 }
4561 }
4562 };
4563
4564 Box cellBox = dbl[din];
4565 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4566
4567 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4568 BoxLoops::loop(vofit, irregularKernel);
4569 }
4570 }
4571
4572 return ParallelOps::min(UxInc.first, UxInc.second);
4573}
4574
4575template <typename P, typename F, typename C>
4576void
4578{
4579 CH_TIME("DischargeInceptionStepper::computeCriticalVolumeStationary");
4580 if (m_verbosity > 5) {
4581 pout() << "DischargeInceptionStepper::computeCriticalVolumeStationary" << endl;
4582 }
4583
4584 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
4585 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
4586 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
4587
4588 m_criticalVolumePlus.resize(0);
4589 m_criticalVolumeMinu.resize(0);
4590
4591 const int numVoltages = m_inceptionIntegralPlus.size();
4592
4593 // Solve critical volume of K values for each voltage
4594 for (size_t i = 0; i < numVoltages; i++) {
4595 Real criticalVolumePlus = 0.0;
4596 Real criticalVolumeMinu = 0.0;
4597
4598 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4599 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4600 const DataIterator& dit = dbl.dataIterator();
4601 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4602
4603 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4604
4605 const Real dx = m_amr->getDx()[lvl];
4606
4607 const int nbox = dit.size();
4608
4609#pragma omp parallel for schedule(runtime) reduction(+ : criticalVolumePlus, criticalVolumeMinu)
4610 for (int mybox = 0; mybox < nbox; mybox++) {
4611 const DataIndex& din = dit[mybox];
4612
4613 const EBISBox& ebisbox = ebisl[din];
4614 const BaseFab<bool>& validCells = validCellsLD[din];
4615
4616 const EBCellFAB& inceptionIntegralPlus = (*(m_inceptionIntegralPlus[i])[lvl])[din];
4617 const EBCellFAB& inceptionIntegralMinu = (*(m_inceptionIntegralMinu[i])[lvl])[din];
4618
4619 const FArrayBox& inceptionIntegralPlusReg = inceptionIntegralPlus.getFArrayBox();
4620 const FArrayBox& inceptionIntegralMinuReg = inceptionIntegralMinu.getFArrayBox();
4621
4622 const EBCellFAB& townsendCritPlus = (*(m_townsendCriterionPlus[i])[lvl])[din];
4623 const EBCellFAB& townsendCritMinu = (*(m_townsendCriterionMinu[i])[lvl])[din];
4624
4625 const FArrayBox& townsendCritPlusReg = townsendCritPlus.getFArrayBox();
4626 const FArrayBox& townsendCritMinuReg = townsendCritMinu.getFArrayBox();
4627
4628 auto regularKernel = [&](const IntVect& iv) -> void {
4629 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
4630 if (inceptionIntegralPlusReg(iv, 0) >= m_inceptionK || townsendCritPlusReg(iv, 0) >= 1.0) {
4631 criticalVolumePlus += std::pow(dx, SpaceDim);
4632 }
4633 if (inceptionIntegralMinuReg(iv, 0) >= m_inceptionK || townsendCritMinuReg(iv, 0) >= 1.0) {
4634 criticalVolumeMinu += std::pow(dx, SpaceDim);
4635 }
4636 }
4637 };
4638
4639 auto irregularKernel = [&](const VolIndex& vof) -> void {
4640 if (validCells(vof.gridIndex())) {
4641 const Real kappa = ebisbox.volFrac(vof);
4642
4643 if (inceptionIntegralPlus(vof, 0) >= m_inceptionK || townsendCritPlus(vof, 0) >= 1.0) {
4644 criticalVolumePlus += kappa * std::pow(dx, SpaceDim);
4645 }
4646 if (inceptionIntegralMinu(vof, 0) >= m_inceptionK || townsendCritMinu(vof, 0) >= 1.0) {
4647 criticalVolumeMinu += kappa * std::pow(dx, SpaceDim);
4648 }
4649 }
4650 };
4651
4652 // Kernel regions.
4653 const Box cellBox = dbl[din];
4654 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4655
4656 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4657 BoxLoops::loop(vofit, irregularKernel);
4658 }
4659 }
4660
4661 m_criticalVolumePlus.push_back(ParallelOps::sum(criticalVolumePlus));
4662 m_criticalVolumeMinu.push_back(ParallelOps::sum(criticalVolumeMinu));
4663 }
4664}
4665
4666template <typename P, typename F, typename C>
4667Real
4669{
4670 CH_TIME("DischargeInceptionStepper::computeCriticalVolumeTransient");
4671 if (m_verbosity > 5) {
4672 pout() << "DischargeInceptionStepper::computeCriticalVolumeTransient" << endl;
4673 }
4674
4675 Real Vcr = 0.0;
4676
4677 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4678 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4679 const DataIterator& dit = dbl.dataIterator();
4680 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4681
4682 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4683
4684 const Real dx = m_amr->getDx()[lvl];
4685 const Real vol = std::pow(dx, SpaceDim);
4686
4687 const int nbox = dit.size();
4688
4689#pragma omp parallel for schedule(runtime) reduction(+ : Vcr)
4690 for (int mybox = 0; mybox < nbox; mybox++) {
4691 const DataIndex& din = dit[mybox];
4692
4693 const EBISBox& ebisbox = ebisl[din];
4694 const BaseFab<bool>& validCells = validCellsLD[din];
4695
4696 const EBCellFAB& inceptionIntegral = (*m_inceptionIntegral[lvl])[din];
4697 const FArrayBox& inceptionIntegralReg = inceptionIntegral.getFArrayBox();
4698
4699 const EBCellFAB& townsendCriterion = (*m_townsendCriterion[lvl])[din];
4700 const FArrayBox& townsendCriterionReg = townsendCriterion.getFArrayBox();
4701
4702 auto regularKernel = [&](const IntVect& iv) -> void {
4703 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
4704 if (inceptionIntegralReg(iv, 0) >= m_inceptionK || townsendCriterionReg(iv, 0) >= 1.0) {
4705 Vcr += vol;
4706 }
4707 }
4708 };
4709
4710 auto irregularKernel = [&](const VolIndex& vof) -> void {
4711 if (validCells(vof.gridIndex())) {
4712 if (inceptionIntegral(vof, 0) >= m_inceptionK || townsendCriterion(vof, 0) >= 1.0) {
4713 Vcr += ebisbox.volFrac(vof) * vol;
4714 }
4715 }
4716 };
4717
4718 // Kernel regions.
4719 const Box cellBox = dbl[din];
4720 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4721
4722 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4723 BoxLoops::loop(vofit, irregularKernel);
4724 }
4725 }
4726
4727 return ParallelOps::sum(Vcr);
4728}
4729
4730template <typename P, typename F, typename C>
4731void
4733{
4734 CH_TIME("DischargeInceptionStepper::computeCriticalAreaStationary");
4735 if (m_verbosity > 5) {
4736 pout() << "DischargeInceptionStepper::computeCriticalAreaStationary" << endl;
4737 }
4738
4739 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
4740 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
4741 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
4742
4743 m_criticalAreaPlus.resize(0);
4744 m_criticalAreaMinu.resize(0);
4745
4746 const int numVoltages = m_inceptionIntegralPlus.size();
4747
4748 // Solve critical area of K values for each voltage
4749 for (size_t i = 0; i < numVoltages; i++) {
4750 Real criticalAreaPlus = 0.0;
4751 Real criticalAreaMinu = 0.0;
4752
4753 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4754 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4755 const DataIterator& dit = dbl.dataIterator();
4756 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4757
4758 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4759
4760 const Real dx = m_amr->getDx()[lvl];
4761
4762 const int nbox = dit.size();
4763
4764#pragma omp parallel for schedule(runtime) reduction(+ : criticalAreaPlus, criticalAreaMinu)
4765 for (int mybox = 0; mybox < nbox; mybox++) {
4766 const DataIndex& din = dit[mybox];
4767
4768 const EBISBox& ebisbox = ebisl[din];
4769 const BaseFab<bool>& validCells = validCellsLD[din];
4770
4771 const EBCellFAB& inceptionIntegralPlus = (*(m_inceptionIntegralPlus[i])[lvl])[din];
4772 const EBCellFAB& inceptionIntegralMinu = (*(m_inceptionIntegralMinu[i])[lvl])[din];
4773
4774 const EBCellFAB& townsendCriterionPlus = (*(m_townsendCriterionPlus[i])[lvl])[din];
4775 const EBCellFAB& townsendCriterionMinu = (*(m_townsendCriterionMinu[i])[lvl])[din];
4776
4777 auto irregularKernel = [&](const VolIndex& vof) -> void {
4778 if (validCells(vof.gridIndex())) {
4779 const Real boundaryArea = ebisbox.bndryArea(vof);
4780
4781 if (inceptionIntegralPlus(vof, 0) >= m_inceptionK || townsendCriterionPlus(vof, 0) >= 1.0) {
4782 criticalAreaPlus += boundaryArea * std::pow(dx, SpaceDim - 1);
4783 }
4784 if (inceptionIntegralMinu(vof, 0) >= m_inceptionK || townsendCriterionMinu(vof, 0) >= 1.0) {
4785 criticalAreaMinu += boundaryArea * std::pow(dx, SpaceDim - 1);
4786 }
4787 }
4788 };
4789
4790 // Kernel regions.
4791 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4792
4793 BoxLoops::loop(vofit, irregularKernel);
4794 }
4795 }
4796
4797 m_criticalAreaPlus.push_back(ParallelOps::sum(criticalAreaPlus));
4798 m_criticalAreaMinu.push_back(ParallelOps::sum(criticalAreaMinu));
4799 }
4800}
4801
4802template <typename P, typename F, typename C>
4803Real
4805{
4806 CH_TIME("DischargeInceptionStepper::computeCriticalAreaTransient");
4807 if (m_verbosity > 5) {
4808 pout() << "DischargeInceptionStepper::computeCriticalAreaTransient" << endl;
4809 }
4810
4811 Real Acr = 0.0;
4812
4813 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4814 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4815 const DataIterator& dit = dbl.dataIterator();
4816 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4817
4818 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4819
4820 const Real dx = m_amr->getDx()[lvl];
4821 const Real area = std::pow(dx, SpaceDim - 1);
4822
4823 const int nbox = dit.size();
4824
4825#pragma omp parallel for schedule(runtime) reduction(+ : Acr)
4826 for (int mybox = 0; mybox < nbox; mybox++) {
4827 const DataIndex& din = dit[mybox];
4828
4829 const EBISBox& ebisbox = ebisl[din];
4830 const BaseFab<bool>& validCells = validCellsLD[din];
4831
4832 const EBCellFAB& inceptionIntegral = (*m_inceptionIntegral[lvl])[din];
4833 const EBCellFAB& townsendCriterion = (*m_townsendCriterion[lvl])[din];
4834
4835 auto irregularKernel = [&](const VolIndex& vof) -> void {
4836 if (validCells(vof.gridIndex())) {
4837 if (inceptionIntegral(vof, 0) >= m_inceptionK || townsendCriterion(vof, 0) >= 1.0) {
4838 Acr += ebisbox.bndryArea(vof) * area;
4839 }
4840 }
4841 };
4842
4843 // Kernel regions.
4844 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4845
4846 BoxLoops::loop(vofit, irregularKernel);
4847 }
4848 }
4849
4850 return ParallelOps::sum(Acr);
4851}
4852
4853template <typename P, typename F, typename C>
4854void
4856{
4857 CH_TIME("DischargeInceptionStepper::computeIonizationVolumeStationary");
4858 if (m_verbosity > 5) {
4859 pout() << "DischargeInceptionStepper::computeIonizationVolumeStationary" << endl;
4860 }
4861
4862 CH_assert(m_inceptionIntegralPlus.size() == m_inceptionIntegralMinu.size());
4863 CH_assert(m_inceptionIntegralPlus.size() == m_KPlusValues.size());
4864 CH_assert(m_inceptionIntegralMinu.size() == m_KMinuValues.size());
4865
4866 m_ionizationVolume.resize(0);
4867
4868 const int numVoltages = m_inceptionIntegralPlus.size();
4869
4870 // Storage something that holds the electric filed
4871 EBAMRCellData scratch;
4872 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
4873
4874 // Solve ionization volume for each voltage
4875 for (size_t i = 0; i < m_voltageSweeps.size(); i++) {
4876 const Real voltage = m_voltageSweeps[i];
4877
4878 Real ionizationVolume = 0.0;
4879
4880 this->superposition(scratch, voltage);
4881
4882 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4883 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4884 const DataIterator& dit = dbl.dataIterator();
4885 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4886
4887 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4888
4889 const Real dx = m_amr->getDx()[lvl];
4890 const RealVect probLo = m_amr->getProbLo();
4891
4892 const int nbox = dit.size();
4893
4894#pragma omp parallel for schedule(runtime) reduction(+ : ionizationVolume)
4895 for (int mybox = 0; mybox < nbox; mybox++) {
4896 const DataIndex& din = dit[mybox];
4897
4898 const EBISBox& ebisbox = ebisl[din];
4899 const BaseFab<bool>& validCells = validCellsLD[din];
4900
4901 const EBCellFAB& electricField = (*scratch[lvl])[din];
4902 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
4903
4904 auto regularKernel = [&](const IntVect& iv) -> void {
4905 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
4906 const RealVect x = probLo + dx * (0.5 * RealVect::Unit + RealVect(iv));
4907 const RealVect EE = RealVect(
4908 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
4909 const Real E = EE.vectorLength();
4910
4911 const Real alpha = m_alpha(E, x);
4912 const Real eta = m_eta(E, x);
4913
4914 if (alpha >= eta) {
4915 ionizationVolume += std::pow(dx, SpaceDim);
4916 }
4917 }
4918 };
4919
4920 auto irregularKernel = [&](const VolIndex& vof) -> void {
4921 if (validCells(vof.gridIndex())) {
4922
4923 const RealVect x = probLo + Location::position(Location::Cell::Center, vof, ebisbox, dx);
4924 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
4925 const Real E = EE.vectorLength();
4926
4927 const Real alpha = m_alpha(E, x);
4928 const Real eta = m_eta(E, x);
4929
4930 const Real kappa = ebisbox.volFrac(vof);
4931
4932 if (alpha >= eta) {
4933 ionizationVolume += kappa * std::pow(dx, SpaceDim);
4934 }
4935 }
4936 };
4937
4938 // Kernel regions.
4939 const Box cellBox = dbl[din];
4940 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
4941
4942 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
4943 BoxLoops::loop(vofit, irregularKernel);
4944 }
4945 }
4946
4947 m_ionizationVolume.push_back(ParallelOps::sum(ionizationVolume));
4948 }
4949}
4950
4951template <typename P, typename F, typename C>
4952Real
4954{
4955 CH_TIME("DischargeInceptionStepper::computeIonizationVolumeTransient");
4956 if (m_verbosity > 5) {
4957 pout() << "DischargeInceptionStepper::computeIonizationVolumeTransient" << endl;
4958 }
4959
4960 Real Vion = 0.0;
4961
4962 // Calculate electric field
4963 EBAMRCellData scratch;
4964 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
4965 this->superposition(scratch, a_voltage);
4966
4967 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); ++lvl) {
4968 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
4969 const DataIterator& dit = dbl.dataIterator();
4970 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
4971
4972 const LevelData<BaseFab<bool>>& validCellsLD = *m_amr->getValidCells(m_realm)[lvl];
4973
4974 const Real dx = m_amr->getDx()[lvl];
4975 const Real vol = std::pow(dx, SpaceDim);
4976 const RealVect probLo = m_amr->getProbLo();
4977
4978 const int nbox = dit.size();
4979
4980#pragma omp parallel for schedule(runtime) reduction(+ : Vion)
4981 for (int mybox = 0; mybox < nbox; mybox++) {
4982 const DataIndex& din = dit[mybox];
4983
4984 const EBISBox& ebisbox = ebisl[din];
4985 const BaseFab<bool>& validCells = validCellsLD[din];
4986
4987 const EBCellFAB& electricField = (*scratch[lvl])[din];
4988 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
4989
4990 auto regularKernel = [&](const IntVect& iv) -> void {
4991 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
4992
4993 const RealVect x = probLo + dx * (0.5 * RealVect::Unit + RealVect(iv));
4994 const RealVect EE = RealVect(
4995 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
4996 const Real E = EE.vectorLength();
4997
4998 const Real alpha = m_alpha(E, x);
4999 const Real eta = m_eta(E, x);
5000 if (alpha >= eta) {
5001 Vion += vol;
5002 }
5003 }
5004 };
5005
5006 auto irregularKernel = [&](const VolIndex& vof) -> void {
5007 if (validCells(vof.gridIndex())) {
5008
5009 const RealVect x = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
5010 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
5011 const Real E = EE.vectorLength();
5012
5013 const Real alpha = m_alpha(E, x);
5014 const Real eta = m_eta(E, x);
5015 if (alpha >= eta) {
5016 Vion += ebisbox.volFrac(vof) * vol;
5017 }
5018 }
5019 };
5020
5021 // Kernel regions.
5022 const Box cellBox = dbl[din];
5023 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
5024
5025 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
5026 BoxLoops::loop(vofit, irregularKernel);
5027 }
5028 }
5029
5030 return ParallelOps::sum(Vion);
5031}
5032
5033template <typename P, typename F, typename C>
5034void
5036{
5037 CH_TIME("DischargeInceptionStepper::writeReportStationary");
5038 if (m_verbosity > 5) {
5039 pout() << "DischargeInceptionStepper::writeReportStationary" << endl;
5040 }
5041
5042 const auto UIncPlus = this->computeMinimumInceptionVoltage(m_inceptionVoltagePlus);
5043 const auto UIncMinu = this->computeMinimumInceptionVoltage(m_inceptionVoltageMinu);
5044
5045 const auto streamerUIncPlus = this->computeMinimumInceptionVoltage(m_streamerInceptionVoltagePlus);
5046 const auto streamerUIncMinu = this->computeMinimumInceptionVoltage(m_streamerInceptionVoltageMinu);
5047
5048 const auto townsendUIncPlus = this->computeMinimumInceptionVoltage(m_townsendInceptionVoltagePlus);
5049 const auto townsendUIncMinu = this->computeMinimumInceptionVoltage(m_townsendInceptionVoltageMinu);
5050
5051#ifdef CH_MPI
5052 if (procID() == 0) {
5053#endif
5054
5055 std::ofstream output(m_outputFile, std::ofstream::out);
5056
5057 const int ww = (SpaceDim == 2) ? 24 : 36;
5058
5059 const std::string lineBreak = "# " + std::string(178 + 4 * ww, '=');
5060
5061 // clang-format off
5062 output << lineBreak << "\n";
5063 if (std::isnan(UIncPlus.first) || std::isnan(UIncMinu.first)) {
5064 output << "# Could not compute inception voltage\n";
5065 }
5066 else {
5068 output << "# Minimum inception voltage(+) = " << UIncPlus.first << ",\t x = " << UIncPlus.second << "\n";
5069 output << "# Minimum inception voltage(-) = " << UIncMinu.first << ",\t x = " << UIncMinu.second << "\n";
5070 output << "# \n";
5071 output << "# Streamer inception voltage(+) = " << streamerUIncPlus.first << ",\t x = " << streamerUIncPlus.second << "\n";
5072 output << "# Streamer inception voltage(-) = " << streamerUIncMinu.first << ",\t x = " << streamerUIncMinu.second << "\n";
5073 output << "# \n";
5074 output << "# Townsend inception voltage(+) = " << townsendUIncPlus.first << ",\t x = " << townsendUIncPlus.second << "\n";
5075 output << "# Townsend inception voltage(-) = " << townsendUIncMinu.first << ",\t x = " << townsendUIncMinu.second << "\n";
5076 }
5077 else{
5078 output << "# Minimum inception voltage(+) >= " << UIncPlus.first << ",\t x = " << UIncPlus.second << "\n";
5079 output << "# Minimum inception voltage(-) >= " << UIncMinu.first << ",\t x = " << UIncMinu.second << "\n";
5080 output << "# \n";
5081 output << "# Streamer inception voltage(+) >= " << streamerUIncPlus.first << ",\t x = " << streamerUIncPlus.second << "\n";
5082 output << "# Streamer inception voltage(-) >= " << streamerUIncMinu.first << ",\t x = " << streamerUIncMinu.second << "\n";
5083 output << "# \n";
5084 output << "# Townsend inception voltage(+) >= " << townsendUIncPlus.first << ",\t x = " << townsendUIncPlus.second << "\n";
5085 output << "# Townsend inception voltage(-) >= " << townsendUIncMinu.first << ",\t x = " << townsendUIncMinu.second << "\n";
5086 }
5087 }
5088
5089 output << lineBreak << "\n";
5090 output << left << setw(15) << setfill(' ') << "# +/- Voltage";
5091 output << left << setw(15) << setfill(' ') << "Max K(+)";
5092 output << left << setw(15) << setfill(' ') << "Max K(-)";
5093 output << left << setw(ww) << setfill(' ') << "Pos. max K(+)";
5094 output << left << setw(ww) << setfill(' ') << "Pos. max K(-)";
5095 output << left << setw(20) << setfill(' ') << "Max T(+)";
5096 output << left << setw(20) << setfill(' ') << "Max T(-)";
5097 output << left << setw(ww) << setfill(' ') << "Pos. max T(+)";
5098 output << left << setw(ww) << setfill(' ') << "Pos. max T(-)";
5099 output << left << setw(20) << setfill(' ') << "Crit. vol(+)";
5100 output << left << setw(20) << setfill(' ') << "Crit. vol(-)";
5101 output << left << setw(20) << setfill(' ') << "Crit. area(+)";
5102 output << left << setw(20) << setfill(' ') << "Crit. area(-)";
5103 output << left << setw(20) << setfill(' ') << "Ionization vol." << "\n";
5104 output << lineBreak << "\n";
5105
5106 auto RealVectToString = [=](const RealVect x) -> std::string {
5107 std::string ret = "(";
5108 for (int dir = 0; dir < SpaceDim; dir++) {
5109 ret += std::to_string(x[dir]);
5110 if(dir < SpaceDim -1) {
5111 ret += ", ";
5112 }
5113 }
5114
5115 ret += ")";
5116
5117 return ret;
5118 };
5119
5120 for (int i = 0; i < m_voltageSweeps.size(); i++) {
5121 output << left << setw(15) << setfill(' ') << m_voltageSweeps[i];
5122 output << left << setw(15) << setfill(' ') << std::get<1>(m_KPlusValues[i]);
5123 output << left << setw(15) << setfill(' ') << std::get<1>(m_KMinuValues[i]);
5124 output << left << setw(ww) << setfill(' ') << RealVectToString(std::get<2>(m_KPlusValues[i]));
5125 output << left << setw(ww) << setfill(' ') << RealVectToString(std::get<2>(m_KMinuValues[i]));
5126 output << left << setw(20) << setfill(' ') << std::get<1>(m_TPlusValues[i]);
5127 output << left << setw(20) << setfill(' ') << std::get<1>(m_TMinuValues[i]);
5128 output << left << setw(ww) << setfill(' ') << RealVectToString(std::get<2>(m_TPlusValues[i]));
5129 output << left << setw(ww) << setfill(' ') << RealVectToString(std::get<2>(m_TMinuValues[i]));
5130 output << left << setw(20) << setfill(' ') << m_criticalVolumePlus[i];
5131 output << left << setw(20) << setfill(' ') << m_criticalVolumeMinu[i];
5132 output << left << setw(20) << setfill(' ') << m_criticalAreaPlus[i];
5133 output << left << setw(20) << setfill(' ') << m_criticalAreaMinu[i];
5134 output << left << setw(20) << setfill(' ') << m_ionizationVolume[i];
5135 output << endl;
5136 }
5137 output << lineBreak << "\n";
5138 // clang-format on
5139#ifdef CH_MPI
5140 }
5141#endif
5142}
5143
5144template <typename P, typename F, typename C>
5145void
5147{
5148 CH_TIME("DischargeInceptionStepper::writeReportTransient");
5149 if (m_verbosity > 5) {
5150 pout() << "DischargeInceptionStepper::writeReportTransient" << endl;
5151 }
5152
5153#ifdef CH_MPI
5154 if (procID() == 0) {
5155#endif
5156 std::ofstream output(m_outputFile, std::ofstream::out);
5157
5158 output << std::left << std::setw(15) << setfill(' ') << "# Time t";
5159 output << std::left << std::setw(15) << setfill(' ') << "V(t)";
5160 output << std::left << std::setw(15) << setfill(' ') << "max K(t)";
5161 output << std::left << std::setw(15) << setfill(' ') << "max T(t)";
5162 output << std::left << std::setw(15) << setfill(' ') << "Vcr(t)";
5163 output << std::left << std::setw(15) << setfill(' ') << "Acr(t)";
5164 output << std::left << std::setw(15) << setfill(' ') << "Vion(t)";
5165 output << std::left << std::setw(15) << setfill(' ') << "lambda(t)";
5166 output << std::left << std::setw(15) << setfill(' ') << "P(t)";
5167 output << std::left << std::setw(15) << setfill(' ') << "dP(t, t+dt)";
5168 output << std::left << std::setw(15) << setfill(' ') << "Time lag";
5169 output << "\n";
5170
5171 // Compute dP(t, t+dt)
5172 std::vector<Real> dProb;
5173 for (size_t i = 0; i < m_Rdot.size() - 1; i++) {
5174 const Real t = m_Rdot[i].first;
5175 const Real dt = m_Rdot[i + 1].first - m_Rdot[i].first;
5176 const Real prob = m_inceptionProbability[i].second;
5177 const Real Rdot = m_Rdot[i].second;
5178
5179 dProb.emplace_back((1.0 - prob) * Rdot * dt);
5180 }
5181 dProb.emplace_back(0.0);
5182
5183 // Compute the average waiting time.
5184 std::vector<Real> tau(m_Rdot.size(), 0.0);
5185 for (size_t i = 0; i < m_Rdot.size() - 1; i++) {
5186 const Real t1 = m_Rdot[i].first;
5187 const Real t2 = m_Rdot[i + 1].first;
5188 const Real dt = t2 - t1;
5189 const Real prob = m_inceptionProbability[i].second;
5190 const Real lambda = m_Rdot[i].second;
5191
5192 tau[i + 1] = tau[i] + t1 * (1 - prob) * lambda * dt;
5193 }
5194 for (int i = 0; i < tau.size(); i++) {
5195 const Real prob = m_inceptionProbability[i].second;
5196
5197 tau[i] = prob > 0.0 ? tau[i] / prob : std::numeric_limits<Real>::infinity();
5198 }
5199
5200 for (size_t i = 0; i < m_Rdot.size(); i++) {
5201 const Real time = m_Rdot[i].first;
5202
5203 output << std::left << std::setw(15) << time;
5204 output << std::left << std::setw(15) << m_voltageCurve(time);
5205 output << std::left << std::setw(15) << m_maxK[i].second;
5206 output << std::left << std::setw(15) << m_maxT[i].second;
5207 output << std::left << std::setw(15) << m_criticalVolume[i].second;
5208 output << std::left << std::setw(15) << m_criticalArea[i].second;
5209 output << std::left << std::setw(15) << m_ionizationVolumeTransient[i].second;
5210 output << std::left << std::setw(15) << m_Rdot[i].second;
5211 output << std::left << std::setw(15) << m_inceptionProbability[i].second;
5212 output << std::left << std::setw(15) << dProb[i];
5213 output << std::left << std::setw(15) << tau[i];
5214 output << "\n";
5215 }
5216
5217 output.close();
5218
5219#ifdef CH_MPI
5220 }
5221#endif
5222}
5223
5224template <typename P, typename F, typename C>
5225bool
5227 const RealVect& a_probLo,
5228 const RealVect& a_probHi) const noexcept
5229{
5230#ifndef NDEBUG
5231 CH_TIME("DischargeInceptionStepper::particleOutsideGrid");
5232 if (m_verbosity > 5) {
5233 pout() << "DischargeInceptionStepper::particleOutsideGrid" << endl;
5234 }
5235#endif
5236
5237 bool isOutside = false;
5238
5239 for (int dir = 0; dir < SpaceDim; dir++) {
5240 if (a_pos[dir] <= a_probLo[dir] || a_pos[dir] >= a_probHi[dir]) {
5241 isOutside = true;
5242 }
5243 }
5244
5245 return isOutside;
5246}
5247
5248template <typename P, typename F, typename C>
5249bool
5250DischargeInceptionStepper<P, F, C>::particleInsideEB(const RealVect& a_pos) const noexcept
5251{
5252#ifndef NDEBUG
5253 CH_TIME("DischargeInceptionStepper::particleInsideEB");
5254 if (m_verbosity > 5) {
5255 pout() << "DischargeInceptionStepper::particleInsideEB" << endl;
5256 }
5257#endif
5258
5259 const RefCountedPtr<BaseIF>& implicitFunction = m_amr->getBaseImplicitFunction(m_phase);
5260
5261 return (implicitFunction->value(a_pos) >= 0.0) ? true : false;
5262}
5263
5264template <typename P, typename F, typename C>
5265void
5267{
5268 CH_TIME("DischargeInceptionStepper::computeIonVelocity");
5269 if (m_verbosity > 5) {
5270 pout() << "DischargeInceptionStepper::computeIonVelocity" << endl;
5271 }
5272
5273 CH_assert(!(m_ionSolver.isNull()));
5274 CH_assert(m_ionSolver->isMobile());
5275
5276 EBAMRCellData& vel = m_ionSolver->getCellCenteredVelocity();
5277
5278 // Compute electric field at the input voltage and set v = -E
5279 this->superposition(vel, a_voltage);
5280 DataOps::scale(vel, -1.0);
5281
5282 // Allocate mesh data that holds mu and compute it on the mesh.
5283 EBAMRCellData mu;
5284 m_amr->allocate(mu, m_realm, m_phase, 1);
5285
5286 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
5287 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
5288 const DataIterator& dit = dbl.dataIterator();
5289
5290 const int nbox = dit.size();
5291
5292#pragma omp parallel for schedule(runtime)
5293 for (int mybox = 0; mybox < nbox; mybox++) {
5294 const DataIndex& din = dit[mybox];
5295
5296 const EBCellFAB& v = (*vel[lvl])[din];
5297 const FArrayBox& vReg = v.getFArrayBox();
5298
5299 EBCellFAB& MU = (*mu[lvl])[din];
5300 FArrayBox& MUREG = MU.getFArrayBox();
5301
5302 auto regularKernel = [&](const IntVect& iv) -> void {
5303 const RealVect EE = RealVect(D_DECL(vReg(iv, 0), vReg(iv, 1), vReg(iv, 2)));
5304 const Real E = EE.vectorLength();
5305
5306 MUREG(iv, 0) = m_ionMobility(E);
5307 };
5308
5309 auto irregularKernel = [&](const VolIndex& vof) -> void {
5310 const RealVect EE = RealVect(D_DECL(v(vof, 0), v(vof, 1), v(vof, 2)));
5311 const Real E = EE.vectorLength();
5312
5313 MU(vof, 0) = m_ionMobility(E);
5314 };
5315
5316 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
5317 Box cellBox = dbl[din];
5318
5319 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
5320 BoxLoops::loop(vofit, irregularKernel);
5321 }
5322 }
5323
5324 DataOps::multiplyScalar(vel, mu);
5325
5326 m_amr->arithmeticAverage(vel, m_realm, m_phase);
5327 m_amr->interpGhostPwl(vel, m_realm, m_phase);
5328}
5329
5330template <typename P, typename F, typename C>
5331void
5333{
5334 CH_TIME("DischargeInceptionStepper::computeIonDiffusion");
5335 if (m_verbosity > 5) {
5336 pout() << "DischargeInceptionStepper::computeIonDiffusion" << endl;
5337 }
5338
5339 CH_assert(!(m_ionSolver.isNull()));
5340 CH_assert(m_ionSolver->isMobile());
5341
5342 // Compute the electric field at the input voltage.
5343 EBAMRCellData scratch;
5344 m_amr->allocate(scratch, m_realm, m_phase, SpaceDim);
5345 this->superposition(scratch, a_voltage);
5346
5347 // Compute the diffusion coefficient on cell centers.
5348 EBAMRCellData diffCoCell;
5349 m_amr->allocate(diffCoCell, m_realm, m_phase, 1);
5350
5351 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
5352 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
5353 const DataIterator& dit = dbl.dataIterator();
5354
5355 const int nbox = dit.size();
5356
5357#pragma omp parallel for schedule(runtime)
5358 for (int mybox = 0; mybox < nbox; mybox++) {
5359 const DataIndex& din = dit[mybox];
5360
5361 const EBCellFAB& electricField = (*scratch[lvl])[din];
5362 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
5363
5364 EBCellFAB& dCo = (*diffCoCell[lvl])[din];
5365 FArrayBox& dCoReg = dCo.getFArrayBox();
5366
5367 auto regularKernel = [&](const IntVect& iv) -> void {
5368 const RealVect EE = RealVect(D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
5369 const Real E = EE.vectorLength();
5370
5371 dCoReg(iv, 0) = m_ionDiffusion(E);
5372 };
5373
5374 auto irregularKernel = [&](const VolIndex& vof) -> void {
5375 const RealVect EE = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
5376 const Real E = EE.vectorLength();
5377
5378 dCo(vof, 0) = m_ionDiffusion(E);
5379 };
5380
5381 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
5382 Box cellBox = dbl[din];
5383
5384 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
5385 BoxLoops::loop(vofit, irregularKernel);
5386 }
5387 }
5388
5389 // Coarsen and update ghost cells
5390 m_amr->arithmeticAverage(diffCoCell, m_realm, m_phase);
5391 m_amr->interpGhostPwl(diffCoCell, m_realm, m_phase);
5392
5393 // Fetch from solver and average to grid faces.
5394 EBAMRFluxData& diffCoFace = m_ionSolver->getFaceCenteredDiffusionCoefficient();
5395 EBAMRIVData& diffCoEB = m_ionSolver->getEbCenteredDiffusionCoefficient();
5396
5397 DataOps::setValue(diffCoFace, 0.0);
5398 DataOps::setValue(diffCoEB, 0.0); // Neumann BC.
5399
5400 DataOps::averageCellToFace(diffCoFace,
5401 diffCoCell,
5402 m_amr->getDomains(),
5403 1,
5404 Interval(0, 0),
5405 Interval(0, 0),
5406 Average::Arithmetic,
5407 m_amr->getFaceIteratorWithTangentialGhosts(m_realm, m_phase));
5408}
5409
5410template <typename P, typename F, typename C>
5411void
5413 const MFAMRCellData& a_inhomogeneousField,
5414 const MFAMRCellData& a_homogeneousField,
5415 const Real a_voltage) const noexcept
5416{
5417 CH_TIME("DischargeInceptionStepper::superposition(full)");
5418
5419 const EBAMRCellData homogeneousField = m_amr->alias(phase::gas, a_homogeneousField);
5420 const EBAMRCellData inhomogeneousField = m_amr->alias(phase::gas, a_inhomogeneousField);
5421
5422 DataOps::setValue(a_sumField, 0.0);
5423 DataOps::incr(a_sumField, homogeneousField, a_voltage);
5424 DataOps::incr(a_sumField, inhomogeneousField, 1.0);
5425
5426 m_amr->arithmeticAverage(a_sumField, m_realm, m_phase);
5427 m_amr->interpGhostPwl(a_sumField, m_realm, m_phase);
5428 // m_amr->interpToCentroids(a_sumField, m_realm, m_phase);
5429}
5430
5431template <typename P, typename F, typename C>
5432void
5433DischargeInceptionStepper<P, F, C>::superposition(EBAMRCellData& a_sumField, const Real a_voltage) const noexcept
5434{
5435 CH_TIME("DischargeInceptionStepper::superposition(short)");
5436
5437 this->superposition(a_sumField, m_electricFieldInho, m_electricFieldHomo, a_voltage);
5438}
5439
5440template <typename P, typename F, typename C>
5441void
5443 RealVect& a_maxPos,
5444 const EBAMRCellData& a_data) const noexcept
5445{
5446 CH_TIME("DischargeInceptionStepper::getMaxValueAndLocation");
5447 if (m_verbosity > 5) {
5448 pout() << "DischargeInceptionStepper::getMaxValueAndLocation" << endl;
5449 }
5450
5451 // Local (val, pos) accumulator so the OpenMP box loop can use a custom pairmax reduction -- writing the
5452 // shared a_maxVal/a_maxPos directly from the kernels would be a data race across threads.
5453 std::pair<Real, RealVect> maxValAndPos;
5454 maxValAndPos.first = -std::numeric_limits<Real>::max();
5455 maxValAndPos.second = RealVect::Zero;
5456
5457 for (int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
5458 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
5459 const DataIterator& dit = dbl.dataIterator();
5460 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
5461 const Real dx = m_amr->getDx()[lvl];
5462 const RealVect probLo = m_amr->getProbLo();
5463
5464 const LevelData<BaseFab<bool>>& validCellsLD = (*m_amr->getValidCells(m_realm)[lvl]);
5465
5466 const int nbox = dit.size();
5467
5468#pragma omp parallel for schedule(runtime) reduction(pairmax : maxValAndPos)
5469 for (int mybox = 0; mybox < nbox; mybox++) {
5470 const DataIndex& din = dit[mybox];
5471 const Box& cellbox = dbl[din];
5472 const EBISBox& ebisbox = ebisl[din];
5473
5474 const EBCellFAB& data = (*a_data[lvl])[din];
5475 const FArrayBox& dataReg = data.getFArrayBox();
5476 const BaseFab<bool>& validCells = validCellsLD[din];
5477
5478 CH_assert(data.nComp() == 1);
5479
5480 // Not vectorizable: max+argmax reduction with a data-dependent branch.
5481 auto regularKernel = [&](const IntVect& iv) -> void {
5482 if (validCells(iv, 0) && ebisbox.isRegular(iv)) {
5483 if (dataReg(iv, 0) > maxValAndPos.first) {
5484 maxValAndPos.first = dataReg(iv, 0);
5485 maxValAndPos.second = probLo + (RealVect(iv) + 0.5 * RealVect::Unit) * dx;
5486 }
5487 }
5488 };
5489
5490 auto irregularKernel = [&](const VolIndex& vof) -> void {
5491 if (validCells(vof.gridIndex(), 0) && ebisbox.isIrregular(vof.gridIndex())) {
5492 if (data(vof, 0) > maxValAndPos.first) {
5493 maxValAndPos.first = data(vof, 0);
5494 maxValAndPos.second = probLo + Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
5495 }
5496 }
5497 };
5498
5499 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
5500
5501 BoxLoops::loop<D_DECL(1, 1, 1)>(cellbox, regularKernel);
5502 BoxLoops::loop(vofit, irregularKernel);
5503 }
5504 }
5505
5506 const std::pair<Real, RealVect> globalMaxValAndPos = ParallelOps::max(maxValAndPos.first, maxValAndPos.second);
5507
5508 a_maxVal = globalMaxValAndPos.first;
5509 a_maxPos = globalMaxValAndPos.second;
5510}
5511
5512template <typename P, typename F, typename C>
5513void
5515 int& a_comp,
5516 const EBAMRCellData& a_data,
5517 const std::string a_outputRealm,
5518 const int a_level,
5519 const bool a_interpToCentroids,
5520 const bool a_interpGhost) const noexcept
5521{
5522 CH_TIMERS("DischargeInceptionStepper::writeData");
5523 CH_TIMER("DischargeInceptionStepper::writeData::allocate", t1);
5524 CH_TIMER("DischargeInceptionStepper::writeData::local_copy", t2);
5525 CH_TIMER("DischargeInceptionStepper::writeData::interp_ghost", t3);
5526 CH_TIMER("DischargeInceptionStepper::writeData::interp_centroid", t4);
5527 CH_TIMER("DischargeInceptionStepper::writeData::final_copy", t5);
5528 if (m_verbosity > 5) {
5529 pout() << "DischargeInceptionStepper::writeData" << endl;
5530 }
5531
5532 // Number of components we are working with.
5533 const int numComp = a_data[a_level]->nComp();
5534
5535 // Component ranges that we copy to/from.
5536 const Interval srcInterv(0, numComp - 1);
5537 const Interval dstInterv(a_comp, a_comp + numComp - 1);
5538
5539 CH_START(t1);
5540 LevelData<EBCellFAB> scratch;
5541 m_amr->allocate(scratch, m_realm, m_phase, a_level, numComp);
5542 CH_STOP(t1);
5543
5544 CH_START(t2);
5545 m_amr->copyData(scratch, *a_data[a_level], a_level, m_realm, m_realm);
5546 CH_STOP(t2);
5547
5548 // Interpolate ghost cells
5549 CH_START(t3);
5550 if (a_level > 0 && a_interpGhost) {
5551 m_amr->interpGhost(scratch, *a_data[a_level - 1], a_level, m_realm, m_phase);
5552 }
5553 CH_STOP(t3);
5554
5555 CH_START(t4);
5556 if (a_interpToCentroids) {
5557 m_amr->interpToCentroids(scratch, m_realm, m_phase, a_level);
5558 }
5559 CH_STOP(t4);
5560
5561 DataOps::setCoveredValue(scratch, *m_amr->getCoveredCells(m_realm, m_phase)[a_level], 0.0);
5562
5563 CH_START(t5);
5564 m_amr->copyData(a_output, scratch, a_level, a_outputRealm, m_realm, dstInterv, srcInterv);
5565 CH_STOP(t5);
5566
5567 a_comp += numComp;
5568}
5569
5570template <typename P, typename F, typename C>
5571const EBAMRCellData*
5573{
5574 CH_TIMERS("DischargeInceptionStepper::getElectricField");
5575
5576 return &m_homogeneousFieldGas;
5577}
5578
5579template <typename P, typename F, typename C>
5580Real
5582{
5583 CH_TIME("DischargeInceptionStepper::getCriticalField");
5584 if (m_verbosity > 5) {
5585 pout() << "DischargeInceptionStepper::getCriticalField" << endl;
5586 }
5587
5588 Real Emin = -10.0;
5589 Real Emax = +10.0;
5590
5591 // Quick lambda for the effective Townsend ionization coefficient. Note that we solve for the exponent.
5592 auto alpha = [this](const Real E) -> Real {
5593 return m_alpha(std::pow(10.0, E), RealVect::Zero) - m_eta(std::pow(10.0, E), RealVect::Zero);
5594 };
5595
5596 const Real p = PolyUtils::brentSolve(Emin, Emax, alpha);
5597
5598 return std::pow(10.0, p);
5599}
5600
5601#include <CD_NamespaceFooter.H>
5602
5603#endif
Declaration of the Physics::DischargeInception::DischargeInceptionSpecies CDR species.
Declaration of the Physics::DischargeInception::DischargeInceptionStepper TimeStepper.
Mode
Solver mode: stationary (voltage sweep) or transient (time-dependent).
Definition CD_DischargeInceptionStepper.H:56
@ Stationary
Stationary mode: solve for inception voltage over a voltage sweep.
Definition CD_DischargeInceptionStepper.H:57
@ Transient
Transient mode: time-dependent simulation with a voltage curve.
Definition CD_DischargeInceptionStepper.H:58
@ MinHardcap
Minimum hard-cap on the time step.
Definition CD_DischargeInceptionStepper.H:69
@ MaxHardcap
Maximum hard-cap on the time step.
Definition CD_DischargeInceptionStepper.H:70
@ Unknown
Restriction not yet determined.
Definition CD_DischargeInceptionStepper.H:66
@ CDR
CFL condition on the negative ion transport.
Definition CD_DischargeInceptionStepper.H:67
@ VoltageCurve
Relative change in applied voltage.
Definition CD_DischargeInceptionStepper.H:68
@ Euler
Explicit forward Euler step.
Definition CD_DischargeInceptionStepper.H:47
@ Heun
Heun's method (explicit second-order Runge-Kutta).
Definition CD_DischargeInceptionStepper.H:48
@ ImExCTU
Implicit-explicit corner-transport-upwind scheme.
Definition CD_DischargeInceptionStepper.H:49
@ Euler
Forward Euler integration along particle trajectories.
Definition CD_DischargeInceptionStepper.H:38
@ Trapezoidal
Trapezoidal (second-order) integration along particle trajectories.
Definition CD_DischargeInceptionStepper.H:39
Declaration of various useful OpenMP-related utilities.
Declaration of a namespace for SIMD-decorated loops over SoA particles.
CD_PARTICLE_REAL ParticleReal
Floating-point type a user may use for payload columns.
Definition CD_ParticleSoA.H:156
Agglomeration of some useful algebraic/polynomial routines.
Declaration of various useful units.
static void scale(MFAMRCellData &a_lhs, const Real &a_scale) noexcept
Scale data by factor.
Definition CD_DataOps.cpp:2564
static void floor(EBAMRCellData &a_lhs, const Real a_value, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Floor values in data holder. This sets all values below a_value to a_value.
Definition CD_DataOps.cpp:1526
static void getMaxMin(Real &max, Real &min, EBAMRCellData &a_data, const int a_comp, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Get maximum and minimum value of specified component.
Definition CD_DataOps.cpp:1772
static void getMaxMinNorm(Real &a_max, Real &a_min, EBAMRCellData &data, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Get maximum and minimum value of normed data.
Definition CD_DataOps.cpp:1940
static void multiply(EBAMRCellData &a_lhs, const EBAMRCellData &a_rhs)
Multiply data holder by another data holder.
Definition CD_DataOps.cpp:2307
static void incr(MFAMRCellData &a_lhs, const MFAMRCellData &a_rhs, const Real a_scale) noexcept
Function which increments data in the form a_lhs = a_lhs + a_rhs*a_scale for all components.
Definition CD_DataOps.cpp:881
static void kappaScale(EBAMRCellData &a_data, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter) noexcept
Scale data by volume fraction.
Definition CD_DataOps.cpp:2203
static void setValue(LevelData< MFInterfaceFAB< T > > &a_lhs, const T &a_value)
Set value in an MFInterfaceFAB data holder.
Definition CD_DataOpsImplem.H:24
static void dotProduct(MFAMRCellData &a_result, const MFAMRCellData &a_data1, const MFAMRCellData &a_data2)
Compote the cell-wise dot product between two data holders.
Definition CD_DataOps.cpp:538
static void squareRoot(EBAMRFluxData &a_lhs, Vector< RefCountedPtr< LayoutData< std::array< FaceIterator, SpaceDim > > > > &a_faceIter)
Compute the square root of the input data.
Definition CD_DataOps.cpp:3445
static void setCoveredValue(EBAMRCellData &a_lhs, const EBAMRCellData &a_coveredMask, const int a_comp, const Real a_value)
Set value in covered cells. Does specified component.
Definition CD_DataOps.cpp:2716
static void compute(EBAMRCellData &a_data, const std::function< Real(const Real a_cellValue)> &a_func, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter) noexcept
Compute a new value given the old cell value.
Definition CD_DataOps.cpp:483
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1262
static void averageCellToFace(EBAMRFluxData &a_faceData, const EBAMRCellData &a_cellData, const Vector< ProblemDomain > &a_domains, Vector< RefCountedPtr< LayoutData< std::array< FaceIterator, SpaceDim > > > > &a_faceIter)
Average all components of the cell-centered data to faces (arithmetic, no tangential ghost faces).
Definition CD_DataOps.cpp:149
static void multiplyScalar(EBAMRCellData &a_lhs, const EBAMRCellData &a_rhs)
Multiply data holder by another data holder.
Definition CD_DataOps.cpp:2402
Type
Type of interpolation methods supported. PWC = Piecewise constant, ignoring the embedded boundary....
Definition CD_EBCoarseToFineInterp.H:43
AMR-hierarchy container of computational particles, stored per patch in Struct-of-Arrays form.
Definition CD_ParticleContainer.H:123
void clearParticles()
Drop all valid particles on every level (keeps each leaf's arena capacity).
Definition CD_ParticleContainer.H:447
unsigned long long getNumberOfValidParticlesGlobal() const
Number of valid particles across all ranks.
Definition CD_ParticleContainer.H:548
void remap()
Redistribute every valid particle to the patch/level/rank that owns its cell.
Definition CD_ParticleContainerImplem.H:502
static bool ebIntersectionBisect(const RefCountedPtr< BaseIF > &a_impFunc, const RealVect &a_oldPos, const RealVect &a_newPos, const Real &a_bisectStep, Real &a_s)
Compute the intersection point between a particle path and an implicit function using a bisection alg...
Definition CD_ParticleOpsImplem.H:175
static void copyDestructive(ParticleContainer< P, Traits > &a_dst, ParticleContainer< P, Traits > &a_src) noexcept
Move all particles from a_src into a_dst (per leaf), emptying a_src. SoA overload.
Definition CD_ParticleOpsImplem.H:278
static bool domainIntersection(const RealVect &a_oldPos, const RealVect &a_newPos, const RealVect &a_probLo, const RealVect &a_probHi, Real &a_s)
Compute the intersection point between a particle path and a domain side.
Definition CD_ParticleOpsImplem.H:126
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
void append(const RealVect &a_position, const double a_weight)
Append one particle with a default-constructed payload.
Definition CD_ParticleSoA.H:962
double * weightColumn() noexcept
Raw weight column (double*).
Definition CD_ParticleSoA.H:1167
std::size_t size() const noexcept
Number of particles currently stored.
Definition CD_ParticleSoA.H:882
double * positionColumn(const int a_dir) noexcept
Raw position component column dir (double*, for SIMD kernels).
Definition CD_ParticleSoA.H:1144
void remove(const std::size_t a_index) noexcept
Remove particle i using swap-and-pop (O(1), does NOT preserve order).
Definition CD_ParticleSoA.H:1040
void appendParticle(const ParticleSoA &a_src, const std::size_t a_index)
Append a single particle (all columns, incl. id/rank) copied from another container.
Definition CD_ParticleSoAImplem.H:172
CdrSpecies subclass for use with DischargeInceptionStepper.
Definition CD_DischargeInceptionSpecies.H:30
TimeStepper for evaluating the streamer inception criterion in static or transient electric fields.
Definition CD_DischargeInceptionStepper.H:95
virtual const std::function< Real(const Real &E, const RealVect &x)> & getAlpha() const noexcept
Get ionization coefficient.
Definition CD_DischargeInceptionStepperImplem.H:2072
void parseRuntimeOptions() override
Parse runtime options.
Definition CD_DischargeInceptionStepperImplem.H:389
Vector< EBAMRCellData > m_townsendCriterionPlus
Townsend criterion for starting positive ions.
Definition CD_DischargeInceptionStepper.H:551
RefCountedPtr< FieldSolver > m_fieldSolver
Field solver.
Definition CD_DischargeInceptionStepper.H:453
std::function< Real(const Real &E, const RealVect &x)> m_secondaryEmission
Secondary emission coefficient.
Definition CD_DischargeInceptionStepper.H:989
TimeStepRestriction m_timeStepRestriction
Time step restriction.
Definition CD_DischargeInceptionStepper.H:443
virtual const EBAMRCellData * getElectricField() const noexcept
Get the electric field.
Definition CD_DischargeInceptionStepperImplem.H:5572
RefCountedPtr< TracerParticleSolver< P > > m_tracerParticleSolver
Tracer particle solver.
Definition CD_DischargeInceptionStepper.H:448
void parseMode() noexcept
Parse simulation mode.
Definition CD_DischargeInceptionStepperImplem.H:419
EBAMRCellData m_townsendInceptionVoltageMinu
Computed Townsend inception voltage.
Definition CD_DischargeInceptionStepper.H:599
EBAMRCellData m_detachment
Detachment factor.
Definition CD_DischargeInceptionStepper.H:611
void computeIonVelocity(const Real &a_voltage) noexcept
Set the negative ion velocity. Note.
Definition CD_DischargeInceptionStepperImplem.H:5266
std::vector< std::tuple< Real, Real, RealVect > > m_TPlusValues
Max T value for every voltage.
Definition CD_DischargeInceptionStepper.H:640
virtual void setIonMobility(const std::function< Real(const Real E)> &a_mobility) noexcept
Set the negative ion mobility (field-dependent).
Definition CD_DischargeInceptionStepperImplem.H:2023
bool m_plotPoisson
Plot Poisson solver or not.
Definition CD_DischargeInceptionStepper.H:859
bool m_plotTownsend
Plot the Townsend-criterion for initiatory ions.
Definition CD_DischargeInceptionStepper.H:909
std::function< Real(const RealVect &x)> m_sigma
Surface charge distribution.
Definition CD_DischargeInceptionStepper.H:944
Real m_gradAlphaDx
Space step size relative to alpha/|grad(alpha)|.
Definition CD_DischargeInceptionStepper.H:819
MFAMRCellData m_potentialInho
Electric potential with charges.
Definition CD_DischargeInceptionStepper.H:473
virtual void writeReportStationary() const noexcept
Print report to the terminal.
Definition CD_DischargeInceptionStepperImplem.H:5035
MFAMRCellData m_electricField
Electric field.
Definition CD_DischargeInceptionStepper.H:488
virtual Real advance(const Real a_dt) override
Advancement method. Swaps between various kernels.
Definition CD_DischargeInceptionStepperImplem.H:1610
std::vector< std::pair< Real, Real > > m_criticalArea
Critical area at various time instances.
Definition CD_DischargeInceptionStepper.H:731
Vector< EBAMRCellData > m_inceptionIntegralPlus
Inception integral values.
Definition CD_DischargeInceptionStepper.H:515
virtual void townsendTrackTrapezoidal(const Real &a_voltage) noexcept
Track particles (positive ions) using a trapezoidal rule and check if the collide with a cathode.
Definition CD_DischargeInceptionStepperImplem.H:3434
virtual void seedUniformParticles() noexcept
Distribute particles in every grid cell.
Definition CD_DischargeInceptionStepperImplem.H:2145
virtual void resetTracerParticles() noexcept
Reset particles.
Definition CD_DischargeInceptionStepperImplem.H:3793
virtual void setIonDensity(const std::function< Real(const RealVect x)> &a_density) noexcept
Set the negative ion density.
Definition CD_DischargeInceptionStepperImplem.H:2011
virtual void computeCriticalVolumeStationary() noexcept
Compute the critical volume of the K values for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4577
virtual void writePlotDataStationary(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string &a_outputRealm, const int a_level) const noexcept
Write plot data for the 'stationary' mode.
Definition CD_DischargeInceptionStepperImplem.H:1118
virtual void postRegrid() override
Perform post-regrid operations.
Definition CD_DischargeInceptionStepperImplem.H:1962
std::function< Real(const Real &E)> m_ionMobility
Negative ion mobility.
Definition CD_DischargeInceptionStepper.H:954
virtual void inceptionIntegrateTrapezoidal(const Real &a_voltage) noexcept
K integral: Add integration parts after particles move.
Definition CD_DischargeInceptionStepperImplem.H:2830
virtual void setBackgroundRate(const std::function< Real(const Real &E, const RealVect &x)> &a_backgroundRate) noexcept
Set the background ionization rate (e.g. from cosmic radiation etc).
Definition CD_DischargeInceptionStepperImplem.H:2086
EBAMRCellData m_gradAlpha
Calculated version of alpha/(|grad(alpha)|) on the mesh.
Definition CD_DischargeInceptionStepper.H:622
Real m_maxKLimit
Maximum K-value that is calculated in stationary mode.
Definition CD_DischargeInceptionStepper.H:754
std::function< Real(const Real &E, const RealVect &x)> m_eta
Attachment coefficient.
Definition CD_DischargeInceptionStepper.H:969
void computeIonDiffusion(const Real &a_voltage) noexcept
Set the negative ion diffusion coefficient.
Definition CD_DischargeInceptionStepperImplem.H:5332
virtual std::pair< Real, RealVect > computeMinimumInceptionVoltage(const EBAMRCellData &a_Uinc) const noexcept
Compute the minimum inception voltage and the starting electron position.
Definition CD_DischargeInceptionStepperImplem.H:4502
Real m_alphaDx
Space step size relative to 1/alpha.
Definition CD_DischargeInceptionStepper.H:809
virtual void computeTownsendCriterionStationary() noexcept
Solve for the Townsend criterion for each particle in each voltage.
Definition CD_DischargeInceptionStepperImplem.H:3121
virtual void synchronizeSolverTimes(const int a_step, const Real a_time, const Real a_dt) override
Synchronize solver times and time steps.
Definition CD_DischargeInceptionStepperImplem.H:1808
virtual void inceptionIntegrateEuler(const Real &a_voltage) noexcept
Integrate the inception integral using the Euler rule.
Definition CD_DischargeInceptionStepperImplem.H:2640
std::function< Real(const RealVect &x)> m_rho
Space charge distribution.
Definition CD_DischargeInceptionStepper.H:939
std::vector< Real > m_ionizationVolume
Ionization volumes for each voltage.
Definition CD_DischargeInceptionStepper.H:688
std::function< Real(const RealVect &x)> m_initialIonDensity
Negative ion density.
Definition CD_DischargeInceptionStepper.H:949
virtual void computeInceptionVoltageVolume() noexcept
Interpolate between K values to find voltage giving K_inception and store values in m_inceptionVoltag...
Definition CD_DischargeInceptionStepperImplem.H:4241
Real m_epsVoltage
Permitted relative deviation in V(t) when computing voltage-curve based time steps.
Definition CD_DischargeInceptionStepper.H:779
EBAMRCellData m_homogeneousFieldGas
Gas-phase homogeneous field.
Definition CD_DischargeInceptionStepper.H:503
bool m_fullIntegration
Use full reconstruction of critical volume or not.
Definition CD_DischargeInceptionStepper.H:844
std::vector< std::pair< Real, Real > > m_maxK
Max K value for every time step.
Definition CD_DischargeInceptionStepper.H:652
std::string m_realm
Realm where the solver lives.
Definition CD_DischargeInceptionStepper.H:919
virtual Real computeIonizationVolumeTransient(const Real &a_voltage) const noexcept
Compute the ionization volume for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4953
virtual void computeFieldEmission(EBAMRCellData &a_emissionRate, const Real &a_voltage) const noexcept
Compute field emission rates.
Definition CD_DischargeInceptionStepperImplem.H:4095
std::vector< Real > m_criticalAreaPlus
Critical area of K values for each voltage.
Definition CD_DischargeInceptionStepper.H:676
virtual int getNumberOfPlotVariables() const override
Get the number of plot variables for this time stepper.
Definition CD_DischargeInceptionStepperImplem.H:672
virtual Real computeCriticalVolumeTransient() const noexcept
Compute the critical volume of the K values for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4668
Real m_maxPhysDx
Maximum spatial step (physical dimensions).
Definition CD_DischargeInceptionStepper.H:794
void registerOperators() override
Register operators.
Definition CD_DischargeInceptionStepperImplem.H:360
virtual void getMaxValueAndLocation(Real &a_maxVal, RealVect &a_maxPos, const EBAMRCellData &a_data) const noexcept
Get the maximum value and location corresponding to the maximum value in the input data holder.
Definition CD_DischargeInceptionStepperImplem.H:5442
EBAMRCellData m_townsendInceptionVoltagePlus
Computed Townsend inception voltage.
Definition CD_DischargeInceptionStepper.H:593
Vector< EBAMRCellData > m_inceptionIntegralMinu
Inception integral values.
Definition CD_DischargeInceptionStepper.H:521
virtual void evaluateFunction(EBAMRCellData &a_data, const Real &a_voltage, const std::function< Real(const Real E, const RealVect x)> &a_func) const noexcept
Evaluate a function f = f(E, x) in a volume.
Definition CD_DischargeInceptionStepperImplem.H:4154
std::vector< Real > m_voltageSweeps
Voltage sweeps.
Definition CD_DischargeInceptionStepper.H:706
MFAMRCellData m_scratchInho
Scratch storage used during regrids.
Definition CD_DischargeInceptionStepper.H:483
bool m_profile
Profile calculation or not.
Definition CD_DischargeInceptionStepper.H:829
std::function< Real(const Real &E)> m_ionDiffusion
Negative ion diffusion coefficient.
Definition CD_DischargeInceptionStepper.H:959
Real m_relativeDeltaU
Maximum relative voltage increase.
Definition CD_DischargeInceptionStepper.H:743
std::function< Real(const Real &E, const RealVect &x)> m_fieldEmission
Field emission current.
Definition CD_DischargeInceptionStepper.H:984
TransportAlgorithm m_transportAlgorithm
Transport algorithm for advancing negative ions in the transient mode.
Definition CD_DischargeInceptionStepper.H:438
void allocate() override
Allocate storage for solvers and time stepper.
Definition CD_DischargeInceptionStepperImplem.H:173
Real m_minPhysDx
Minimum spatial step (physical dimensions).
Definition CD_DischargeInceptionStepper.H:789
Vector< EBAMRCellData > m_detachmentStationary
Detachment rates.
Definition CD_DischargeInceptionStepper.H:533
EBAMRCellData m_emissionRate
Field emission rates.
Definition CD_DischargeInceptionStepper.H:563
virtual Vector< std::string > getTransientPlotVariableNames() const noexcept
Get plot variable names for transient mode.
Definition CD_DischargeInceptionStepperImplem.H:1010
virtual Mode getMode() const noexcept
Get the solver mode.
Definition CD_DischargeInceptionStepperImplem.H:2138
void parseInceptionAlgorithm() noexcept
Parse the inception algorithm.
Definition CD_DischargeInceptionStepperImplem.H:478
virtual ~DischargeInceptionStepper()
Destructor.
Definition CD_DischargeInceptionStepperImplem.H:113
Real m_firstDt
First time step.
Definition CD_DischargeInceptionStepper.H:764
bool m_plotInceptionIntegral
If true, plot the K-values.
Definition CD_DischargeInceptionStepper.H:874
void solvePoisson() noexcept
Solve the Poisson equation.
Definition CD_DischargeInceptionStepperImplem.H:251
virtual void setAlpha(const std::function< Real(const Real &E, const RealVect &x)> &a_alpha) noexcept
Set the ionization coefficient.
Definition CD_DischargeInceptionStepperImplem.H:2047
EBAMRCellData m_inceptionVoltageMinu
Computed inception voltage.
Definition CD_DischargeInceptionStepper.H:575
Vector< EBAMRCellData > m_emissionRatesPlus
Field emission rates.
Definition CD_DischargeInceptionStepper.H:539
MFAMRCellData m_potential
Electric potential.
Definition CD_DischargeInceptionStepper.H:463
bool m_plotDetachment
If true, plot electron detachment rate, i.e. done/dt due to detachment from negative ions.
Definition CD_DischargeInceptionStepper.H:889
Real m_minGridDx
Minimum spatial step (relative to grid resolution).
Definition CD_DischargeInceptionStepper.H:799
virtual void computeInceptionIntegral(EBAMRCellData &a_inceptionIntegral, const Real a_voltage) noexcept
Compute the inception integral for the input voltage.
Definition CD_DischargeInceptionStepperImplem.H:2446
Mode m_mode
Mode.
Definition CD_DischargeInceptionStepper.H:428
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override
Time stepper regrid method.
Definition CD_DischargeInceptionStepperImplem.H:1899
MFAMRCellData m_electricFieldHomo
Electric field without space/surface charge and V = 1 on live electrodes.
Definition CD_DischargeInceptionStepper.H:493
bool m_plotTracer
Plot tracer particle solver or not.
Definition CD_DischargeInceptionStepper.H:864
Real m_deltaK
Maximum targeted increase in K-value.
Definition CD_DischargeInceptionStepper.H:749
bool particleOutsideGrid(const RealVect &a_pos, const RealVect &a_probLo, const RealVect &a_probHi) const noexcept
Check if particle is outside grid boundaries.
Definition CD_DischargeInceptionStepperImplem.H:5226
virtual void writeReportTransient() const noexcept
Print report to the terminal.
Definition CD_DischargeInceptionStepperImplem.H:5146
virtual void rewindTracerParticles() noexcept
Move particles back to their original position.
Definition CD_DischargeInceptionStepperImplem.H:3755
virtual void townsendTrackEuler(const Real &a_voltage) noexcept
Track particles (positive ions) using an Euler rule and check if the collide with a cathode.
Definition CD_DischargeInceptionStepperImplem.H:3311
EBAMRCellData m_streamerInceptionVoltageMinu
Computed streamer inception voltage.
Definition CD_DischargeInceptionStepper.H:587
void superposition(EBAMRCellData &a_sumField, const MFAMRCellData &a_inhomogeneousField, const MFAMRCellData &a_homogeneousField, const Real a_voltage) const noexcept
Calculate the total electric field = inhomogeneous + V * homogeneous.
Definition CD_DischargeInceptionStepperImplem.H:5412
std::vector< std::pair< Real, Real > > m_Rdot
Integral factor for cumulative integration.
Definition CD_DischargeInceptionStepper.H:713
void parseOptions()
Parse options.
Definition CD_DischargeInceptionStepperImplem.H:374
std::vector< std::pair< Real, Real > > m_ionizationVolumeTransient
Ionization volume at various time instances.
Definition CD_DischargeInceptionStepper.H:737
void setupSolvers() override
Instantiate the tracer particle solver.
Definition CD_DischargeInceptionStepperImplem.H:123
std::vector< Real > m_criticalVolumePlus
Critical volumes of K values for each voltage.
Definition CD_DischargeInceptionStepper.H:664
MFAMRCellData m_scratchHomo
Scratch storage used during regrids.
Definition CD_DischargeInceptionStepper.H:478
virtual void setEta(const std::function< Real(const Real &E, const RealVect &x)> &a_eta) noexcept
Set the attachment coefficient.
Definition CD_DischargeInceptionStepperImplem.H:2060
Vector< EBAMRCellData > m_backgroundIonizationStationary
Background ionization rates.
Definition CD_DischargeInceptionStepper.H:527
bool m_plotFieldEmission
If true, plot the field emission.
Definition CD_DischargeInceptionStepper.H:894
IntegrationAlgorithm m_inceptionAlgorithm
Integration algorithm for K-value.
Definition CD_DischargeInceptionStepper.H:433
std::function< Real(const Real &E, const RealVect &x)> m_backgroundRate
Background ionization rate expression.
Definition CD_DischargeInceptionStepper.H:979
EBAMRCellData m_streamerInceptionVoltagePlus
Computed streamer inception voltage.
Definition CD_DischargeInceptionStepper.H:581
virtual Vector< std::string > getStationaryPlotVariableNames() const noexcept
Get plot variable names for stationary mode.
Definition CD_DischargeInceptionStepperImplem.H:865
bool m_plotInceptionVoltage
If true, plot the inception voltage.
Definition CD_DischargeInceptionStepper.H:879
std::string m_outputFile
File name prefix for HDF5 plot output.
Definition CD_DischargeInceptionStepper.H:929
EBAMRCellData m_inceptionVoltagePlus
Computed inception voltage.
Definition CD_DischargeInceptionStepper.H:569
std::function< Real(const Real &E, const RealVect &x)> m_detachmentRate
Detachment probability for negative ion.
Definition CD_DischargeInceptionStepper.H:974
Real m_townsendGridDx
Space step size used for ion tracking.
Definition CD_DischargeInceptionStepper.H:814
virtual void setDetachmentRate(const std::function< Real(const Real &E, const RealVect &x)> &a_detachmentRate) noexcept
Set the detachment rate for negative ions.
Definition CD_DischargeInceptionStepperImplem.H:2099
virtual void computeTownsendCriterionTransient(const Real &a_voltage) noexcept
Solve for the Townsend criterion for each particle in each voltage.
Definition CD_DischargeInceptionStepperImplem.H:3255
virtual void computeIonizationVolumeStationary() noexcept
Compute the ionization volume for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4855
std::function< Real(const Real a_time)> m_voltageCurve
Time-dependent voltage.
Definition CD_DischargeInceptionStepper.H:914
Vector< EBAMRCellData > m_townsendCriterionMinu
Townsend criterion for starting negative ions (electrons arriving at anode).
Definition CD_DischargeInceptionStepper.H:557
virtual void writePlotDataTransient(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string &a_outputRealm, const int a_level) const noexcept
Write plot data for the 'transient' mode.
Definition CD_DischargeInceptionStepperImplem.H:1332
phase::which_phase m_phase
Phase (gas/solid) where the solver lives.
Definition CD_DischargeInceptionStepper.H:934
virtual void computeFieldEmissionStationary() noexcept
Compute field emission rates.
Definition CD_DischargeInceptionStepperImplem.H:3995
void parseOutput() noexcept
Parse output settings.
Definition CD_DischargeInceptionStepperImplem.H:464
std::function< Real(const Real &E, const RealVect &x)> m_alpha
Ionization coefficient.
Definition CD_DischargeInceptionStepper.H:964
MFAMRCellData m_potentialHomo
Electric potential without charges.
Definition CD_DischargeInceptionStepper.H:468
EBAMRCellData m_inceptionIntegral
Inception integral values.
Definition CD_DischargeInceptionStepper.H:509
bool m_plotEta
If true, plot eta.
Definition CD_DischargeInceptionStepper.H:904
Vector< EBAMRCellData > m_emissionRatesMinu
Field emission rates.
Definition CD_DischargeInceptionStepper.H:545
bool m_debug
Debug or not.
Definition CD_DischargeInceptionStepper.H:834
virtual void computeInceptionIntegralStationary() noexcept
Solve streamer inception integral for each particle in each voltage and store K values in m_inception...
Definition CD_DischargeInceptionStepperImplem.H:2501
virtual Real computeCriticalAreaTransient() const noexcept
Compute the critical area of the K values for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4804
Real m_maxGridDx
Maximum spatial step (relative to grid resolution).
Definition CD_DischargeInceptionStepper.H:804
virtual Real getCriticalField() const noexcept
Get the breakdown field.
Definition CD_DischargeInceptionStepperImplem.H:5581
virtual Vector< std::string > getPlotVariableNames() const override
Get plot variable names.
Definition CD_DischargeInceptionStepperImplem.H:809
Real m_maxDt
Maximum permitted time step.
Definition CD_DischargeInceptionStepper.H:769
virtual void computeDetachmentStationary() noexcept
Compute the detachment ionization rate for all voltages.
Definition CD_DischargeInceptionStepperImplem.H:3907
bool m_plotField
Plot field.
Definition CD_DischargeInceptionStepper.H:854
virtual void writeData(LevelData< EBCellFAB > &a_output, int &a_comp, const EBAMRCellData &a_data, const std::string a_outputRealm, const int a_level, const bool a_interpToCentroids, const bool a_interpGhost) const noexcept
Write data to output. Convenience function used for IO.
Definition CD_DischargeInceptionStepperImplem.H:5514
void parseVoltages() noexcept
Parse voltage levels.
Definition CD_DischargeInceptionStepperImplem.H:444
EBAMRCellData m_backgroundIonization
Background ionization.
Definition CD_DischargeInceptionStepper.H:617
virtual void interpolateGradAlphaToParticles() noexcept
Interpolate alpha/|grad(alpha)| onto some scratch particle storage.
Definition CD_DischargeInceptionStepperImplem.H:2428
std::vector< std::tuple< Real, Real, RealVect > > m_KPlusValues
Max K value for every voltage.
Definition CD_DischargeInceptionStepper.H:628
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string &a_outputRealm, const int a_level) const override
Write plot data to output holder.
Definition CD_DischargeInceptionStepperImplem.H:1075
std::vector< std::tuple< Real, Real, RealVect > > m_KMinuValues
Max K value for every voltage.
Definition CD_DischargeInceptionStepper.H:634
bool m_plotAlpha
If true, plot alpha.
Definition CD_DischargeInceptionStepper.H:899
virtual void setIonDiffusion(const std::function< Real(const Real E)> &a_diffCo) noexcept
Set the negative ion diffusion coefficient (field-dependent).
Definition CD_DischargeInceptionStepperImplem.H:2035
void postInitialize() override
Perform any post-initialization steps.
Definition CD_DischargeInceptionStepperImplem.H:2346
bool particleInsideEB(const RealVect &a_pos) const noexcept
Check if particle is inside electrode.
Definition CD_DischargeInceptionStepperImplem.H:5250
virtual void setSigma(const std::function< Real(const RealVect &x)> &a_sigma) noexcept
Set surface charge distribution.
Definition CD_DischargeInceptionStepperImplem.H:1999
EBAMRCellData m_townsendCriterion
Townsend criterion.
Definition CD_DischargeInceptionStepper.H:605
void parseTransportAlgorithm() noexcept
Parse the transport algorithm.
Definition CD_DischargeInceptionStepperImplem.H:535
bool m_ionTransport
Ion transport on/off.
Definition CD_DischargeInceptionStepper.H:849
virtual void seedIonizationParticles(const Real a_voltage) noexcept
Add particles to every cell where alpha - eta > 0.0.
Definition CD_DischargeInceptionStepperImplem.H:2218
DischargeInceptionStepper()
Default constructor.
Definition CD_DischargeInceptionStepperImplem.H:39
bool m_plotNegativeIons
Plot negative ions or not.
Definition CD_DischargeInceptionStepper.H:869
MFAMRCellData m_electricFieldInho
Electric field with space/surface charge and V = 0 on all electrodes.
Definition CD_DischargeInceptionStepper.H:498
Real m_cfl
CFL-step for negative ions.
Definition CD_DischargeInceptionStepper.H:759
std::vector< Real > m_criticalAreaMinu
Critical area of K values for each voltage.
Definition CD_DischargeInceptionStepper.H:682
void parsePlotVariables() noexcept
Parse plot variables.
Definition CD_DischargeInceptionStepperImplem.H:575
void initialData() override
Fill problem with initial data.
Definition CD_DischargeInceptionStepperImplem.H:239
virtual const std::function< Real(const Real &E, const RealVect &x)> & getEta() const noexcept
Get attachment coefficient.
Definition CD_DischargeInceptionStepperImplem.H:2079
RefCountedPtr< CdrSolver > m_ionSolver
Negative ion solver.
Definition CD_DischargeInceptionStepper.H:458
virtual void setSecondaryEmission(const std::function< Real(const Real &E, const RealVect &x)> &a_coeff) noexcept
Set the secondary emission coefficient.
Definition CD_DischargeInceptionStepperImplem.H:2125
virtual Real computeDt() override
Compute a time step to be used by Driver.
Definition CD_DischargeInceptionStepperImplem.H:1515
std::vector< std::pair< Real, Real > > m_criticalVolume
Critical volume at various time instances.
Definition CD_DischargeInceptionStepper.H:725
virtual void preRegrid(const int a_lmin, const int a_oldFinestLevel) override
Perform pre-regrid operations.
Definition CD_DischargeInceptionStepperImplem.H:1879
virtual void printStepReport() override
Print a step report. Used in transient simulations.
Definition CD_DischargeInceptionStepperImplem.H:1826
virtual void setRho(const std::function< Real(const RealVect &x)> &a_rho) noexcept
Set space charge distribution.
Definition CD_DischargeInceptionStepperImplem.H:1987
void parseVerbosity() noexcept
Parse class verbosity.
Definition CD_DischargeInceptionStepperImplem.H:404
bool m_evaluateTownsend
Evaluate secondary emission.
Definition CD_DischargeInceptionStepper.H:839
Real m_minDt
Minimum permitted time step.
Definition CD_DischargeInceptionStepper.H:774
bool m_plotBackgroundIonization
If true, plot the background ionization rates.
Definition CD_DischargeInceptionStepper.H:884
void registerRealms() override
Register realms. Primal is the only realm we need.
Definition CD_DischargeInceptionStepperImplem.H:348
Real m_inceptionK
Inception criteria (read from input).
Definition CD_DischargeInceptionStepper.H:824
virtual void computeBackgroundIonizationStationary() noexcept
Compute the background ionization rate for all voltages.
Definition CD_DischargeInceptionStepperImplem.H:3825
virtual void computeInceptionIntegralTransient(const Real &a_voltage) noexcept
Solve streamer inception integral.
Definition CD_DischargeInceptionStepperImplem.H:2605
virtual void setVoltageCurve(const std::function< Real(const Real &a_time)> &a_voltageCurve) noexcept
Set the voltage curve (used for transient mode).
Definition CD_DischargeInceptionStepperImplem.H:1975
virtual void computeCriticalAreaStationary() noexcept
Compute the critical area of the K values for each voltage.
Definition CD_DischargeInceptionStepperImplem.H:4732
virtual void advanceIons(const Real a_dt) noexcept
Advance negative ions.
Definition CD_DischargeInceptionStepperImplem.H:1722
std::vector< std::pair< Real, Real > > m_inceptionProbability
Cumulative probability of breakdown by time t.
Definition CD_DischargeInceptionStepper.H:719
std::vector< std::pair< Real, Real > > m_maxT
Max Townsend value for every time step.
Definition CD_DischargeInceptionStepper.H:658
virtual Real computeRdot(const Real &a_voltage) const noexcept
Compute integral_Vcr(done/dt * (1 - eta/alpha) dV).
Definition CD_DischargeInceptionStepperImplem.H:3651
virtual void setFieldEmission(const std::function< Real(const Real &E, const RealVect &x)> &a_currentDensity) noexcept
Set the field emission current.
Definition CD_DischargeInceptionStepperImplem.H:2112
std::vector< std::tuple< Real, Real, RealVect > > m_TMinuValues
Max T value for every voltage.
Definition CD_DischargeInceptionStepper.H:646
std::vector< Real > m_criticalVolumeMinu
Critical volumes of K values for each voltage.
Definition CD_DischargeInceptionStepper.H:670
Real m_maxDtGrowth
Maximum permitted time step growth.
Definition CD_DischargeInceptionStepper.H:784
static const std::string Primal
Identifier for perimal realm.
Definition CD_Realm.H:44
Real m_time
TIme.
Definition CD_TimeStepper.H:353
int m_verbosity
Class verbosity.
Definition CD_TimeStepper.H:343
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Computational geometry.
Definition CD_TimeStepper.H:375
int m_timeStep
Time step.
Definition CD_TimeStepper.H:348
Real m_dt
Previous time step size.
Definition CD_TimeStepper.H:358
RefCountedPtr< AmrMesh > m_amr
AmrMesh.
Definition CD_TimeStepper.H:370
Class which is used for run-time monitoring of events.
Definition CD_Timer.H:32
void startEvent(const std::string &a_event) noexcept
Start an event.
Definition CD_TimerImplem.H:60
void eventReport(std::ostream &a_outputStream, const bool a_localReportOnly=false) const noexcept
Print all timed events to cout.
Definition CD_TimerImplem.H:170
void stopEvent(const std::string &a_event) noexcept
Stop an event.
Definition CD_TimerImplem.H:89
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:39
ALWAYS_INLINE void loop(const Box &a_computeBox, Functor &&kernel)
Launch a C++ kernel over a regular grid with compile-time per-dimension strides.
Definition CD_BoxLoopsImplem.H:39
RealVect position(Location::Cell a_location, const VolIndex &a_vof, const EBISBox &a_ebisbox, const Real &a_dx)
Compute the position (ignoring the "origin) of a Vof.
Definition CD_LocationImplem.H:21
Real max(const Real &a_input) noexcept
Get the maximum of the input, reduced over MPI ranks (in the Chombo communicator).
Definition CD_ParallelOpsImplem.H:177
Real min(const Real &a_input) noexcept
Get the minimum of the input, reduced over MPI ranks (in the Chombo communicator).
Definition CD_ParallelOpsImplem.H:59
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:354
ALWAYS_INLINE void loop(const ParticleSoA< P, Traits > &a_soa, Functor &&a_kernel)
Launch a kernel over every particle in a ParticleSoA, decorating the loop with CD_PRAGMA_SIMD.
Definition CD_ParticleLoops.H:87
Real brentSolve(const Real a_point1, const Real a_point2, const std::function< Real(const Real x)> &a_func) noexcept
Compute the root of a function between two points. This is a 1D problem.
Definition CD_PolyUtils.cpp:169
constexpr Real Qe
Elementary charge.
Definition CD_Units.H:35
@ solid
Solid (dielectric) phase.
Definition CD_MultiFluidIndexSpace.H:40
@ gas
Gas phase.
Definition CD_MultiFluidIndexSpace.H:39