Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return electric_field_enabled option to ionflow #221

Open
AndreySchadel opened this issue Jan 9, 2025 · 2 comments
Open

Return electric_field_enabled option to ionflow #221

AndreySchadel opened this issue Jan 9, 2025 · 2 comments
Labels
feature-request New feature request

Comments

@AndreySchadel
Copy link

Abstract

Greeting developers! I've been working on version 2.6.0 because option "electric_field_enabled" was available. It was quite important to correct reproduce the ion concentration in flames where the concentration of electrons and cations were the same.

Motivation

However, I tried to update to Ubuntu 24.04 and when i tried to install cantera 2.6.0. I was unable to do it due to the errors produced by Cython in Python 3.12. I looked through the source code and found lines of code written below.

Is it possible to toggle back this feature?

Possible Solutions

`size_t Flow1D::getSolvingStage() const
{
throw NotImplementedError("Flow1D::getSolvingStage",
"Not used by '{}' objects.", type());
}

void Flow1D::setSolvingStage(const size_t stage)
{
throw NotImplementedError("Flow1D::setSolvingStage",
"Not used by '{}' objects.", type());
}

void Flow1D::solveElectricField(size_t j)
{
throw NotImplementedError("Flow1D::solveElectricField",
"Not used by '{}' objects.", type());
}

void Flow1D::fixElectricField(size_t j)
{
throw NotImplementedError("Flow1D::fixElectricField",
"Not used by '{}' objects.", type());
}

bool Flow1D::doElectricField(size_t j) const
{
throw NotImplementedError("Flow1D::doElectricField",
"Not used by '{}' objects.", type());
}`

References

https://github.com/Cantera/cantera/tree/3.1/src/oneD/Flow1D.cpp

@AndreySchadel AndreySchadel added the feature-request New feature request label Jan 9, 2025
@speth
Copy link
Member

speth commented Jan 9, 2025

Hi Andrey,

All the capabilities for solving the electric field are still in place, but have been modified a bit in Cantera 3.0 and later, such that the IonFlow class is used automatically whenever the ionized-gas transport model is selected. This was done in Cantera/cantera#1514. See ion_free_flame.py for an example.

@AndreySchadel
Copy link
Author

AndreySchadel commented Jan 11, 2025

image
The above image is done by Cantera 3.1.0:
Result_phi_0.8_ion_cantera_3,1,0.csv

from pathlib import Path
import cantera as ct
from numpy import genfromtxt


p = ct.one_atm
tburner = 368.0
reactants = 'CH4:0.06, O2:0.15, Ar:0.79'  # premixed gas composition
width = 0.01 # m 
loglevel = 1  # amount of diagnostic output (0 to 5)
refine_grid = True  # 'True' to enable refinement

gas = ct.Solution(r'/home/andreyubuntu24/Canteradev/Mechanism/MECHANISM - MarioDeRenzo/reducedS26R134_0.yaml')
gas.TPX = tburner, p, reactants
mdot = 0.19  # kg/m^2/s

f = ct.BurnerFlame(gas, width=width)
f.burner.mdot = mdot
zloc, tvalues = genfromtxt('/home/andreyubuntu24/Canteradev/Repository/CH4_flame/temp.txt', delimiter=',', comments='#').T
zloc /= max(zloc)
f.flame.set_fixed_temp_profile(zloc, tvalues)
f.set_refine_criteria(ratio=2.0, slope=0.2, curve=0.4, prune=0.01)
f.set_initial_guess()
f.set_profile('H', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('OH', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('CH3', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('O', [0.0, 0.05, 1.0], [0.0, 0.0001, 0.0])
f.energy_enabled = False
f.show()

f.solve(loglevel, auto=True)
f.solve(loglevel=loglevel, stage=2)

if "native" in ct.hdf_support():
    output = Path() / "Result_phi_0.8_ion.h5"
else:
    output = Path() / "Result_phi_0.8_ion.yaml"
output.unlink(missing_ok=True)

f.save(output, name="ion", description="solution with ionic transport")

f.save('/home/andreyubuntu24/Canteradev/Repository/CH4_flame/Result_phi_0.8_ion_cantera_3,1,0.csv', basis="mole", overwrite=True)         

image
The above image is done by Cantera 2.6.0 with option "electric_field_enabled":
Result_phi_0.8_ion_cantera_2,6,0.txt

import cantera as ct
import numpy as np

p = ct.one_atm
tburner = 368.0
reactants = 'CH4:0.06, O2:0.15, Ar:0.79'  # premixed gas composition
width = 0.01 # m 
loglevel = 1  # amount of diagnostic output (0 to 5)
refine_grid = True  # 'True' to enable refinement

gas = ct.Solution(r'/home/andreywslubuntu/Canteradev/Mechanism/MECHANISM - MarioDeRenzo/reducedS26R134_0.yaml')
gas.TPX = tburner, p, reactants
mdot = 0.19  # kg/m^2/s

f = ct.BurnerFlame(gas, width=width)
f.burner.mdot = mdot
zloc, tvalues = np.genfromtxt('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/temp.txt', delimiter=',', comments='#').T
zloc /= max(zloc)
f.flame.set_fixed_temp_profile(zloc, tvalues)
f.set_refine_criteria(ratio=3.0, slope=0.3, curve=1)
f.set_initial_guess()
f.set_profile('H', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('OH', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('CH3', [0.0, 0.05, 1.0], [0.0, 0.001, 0.0])
f.set_profile('O', [0.0, 0.05, 1.0], [0.0, 0.0001, 0.0])
f.show_solution()
f.energy_enabled = False

f.transport_model = 'Mix'
f.solve(loglevel, refine_grid)
f.save('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/Result_phi_0.8_cantera_2,6,0.xml', 'Mix', 'solution with Mix transport')
f.write_csv('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/Result_phi_0.8_mix_cantera_2,6,0.txt', quiet=False)

g = ct.IonBurnerFlame(gas, width=width)
g.burner.mdot = mdot
g.flame.set_fixed_temp_profile(zloc, tvalues)
g.set_initial_guess()
g.restore('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/Result_phi_0.8_cantera_2,6,0.xml', 'Mix')
g.transport_model = 'Ion'
g.show_solution()
g.energy_enabled = False
g.electric_field_enabled = True
g.set_refine_criteria(ratio=2.0, slope=0.2, curve=0.4, prune=0.01)
g.solve(loglevel, refine_grid)
g.save('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/Result_phi_0.8_cantera_2,6,0.xml', 'Ion', 'solution with Ion transport')

g.write_csv('/home/andreywslubuntu/Canteradev/Repository/CH4_flame/Result_phi_0.8_ion_cantera_2,6,0.txt', quiet=False)

I tried to reproduce the same behaviour. However failed to because this option is not presented there. I believe stage 2 doesn't activate as it should be. The number of positive and negative charged particles are the same but doesn't reproduce the real behaviour. Although both algorithms use the same mechanism.

reducedS26R134_0.txt
This is the mechanism for instance. Change the format from TXT to Yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature request
Projects
None yet
Development

No branches or pull requests

2 participants