@@ -9,6 +9,7 @@ ClassicalDiffusion::ClassicalDiffusion(std::string name, Options& alloptions, So
99 Bsq = SQ (bout::globals::mesh->getCoordinates ()->Bxy );
1010
1111 diagnose = options[" diagnose" ].doc (" Output additional diagnostics?" ).withDefault <bool >(false );
12+ custom_D = options[" custom_D" ].doc (" Custom diffusion coefficient override. -1: Off, calculate D normally" ).withDefault <BoutReal>(-1 );
1213}
1314
1415void ClassicalDiffusion::transform (Options &state) {
@@ -35,11 +36,21 @@ void ClassicalDiffusion::transform(Options &state) {
3536 auto & electrons = allspecies[" e" ];
3637 const auto me = get<BoutReal>(electrons[" AA" ]);
3738 const Field3D Ne = GET_VALUE (Field3D, electrons[" density" ]);
38- const Field3D nu_e = floor (GET_VALUE (Field3D, electrons[" collision_frequency" ]), 1e-10 );
3939
4040 // Particle diffusion coefficient. Applied to all charged species
4141 // so that net transport is ambipolar
42- Dn = floor (Ptotal, 1e-5 ) * me * nu_e / (floor (Ne, 1e-5 ) * Bsq);
42+
43+ if (custom_D > 0 ) { // User-set
44+ Dn = custom_D;
45+ } else { // Calculated from collisions
46+ const Field3D nu_e = floor (GET_VALUE (Field3D, electrons[" collision_frequency" ]), 1e-10 );
47+ Dn = floor (Ptotal, 1e-5 ) * me * nu_e / (floor (Ne, 1e-5 ) * Bsq);
48+ }
49+
50+ // Set D to zero in all guard cells
51+ BOUT_FOR (i, Dn.getRegion (" RGN_GUARDS" )) {
52+ Dn[i] = 0.0 ;
53+ }
4354
4455 for (auto & kv : allspecies.getChildren ()) {
4556 Options& species = allspecies[kv.first ]; // Note: Need non-const
@@ -73,8 +84,11 @@ void ClassicalDiffusion::transform(Options &state) {
7384 const auto P = GET_VALUE (Field3D, species[" pressure" ]);
7485 const auto AA = GET_VALUE (BoutReal, species[" AA" ]);
7586
76- const Field3D nu = floor (GET_VALUE (Field3D, species[" collision_frequency" ]), 1e-10 );
77- add (species[" energy_source" ], FV::Div_a_Grad_perp (2 . * floor (P, 1e-5 ) * nu * AA / Bsq, T));
87+ // TODO: Figure out what to do with the below
88+ if (custom_D < 0 ) {
89+ const Field3D nu = floor (GET_VALUE (Field3D, species[" collision_frequency" ]), 1e-10 );
90+ add (species[" energy_source" ], FV::Div_a_Grad_perp (2 . * floor (P, 1e-5 ) * nu * AA / Bsq, T));
91+ }
7892 }
7993 }
8094}
0 commit comments