Skip to content

Commit f2d814e

Browse files
MohammedAnsyspyansys-ci-bothpohekar
authored
docs: Example on Electrolysis Modeling of Proton Exchange Membrane El… [skip tests] (#4587)
End-to-end PyFluent workflow on Electrolysis Modeling 1. [ANSYS Fluent User's Guide, ANSYS, Inc.](https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/prod_page.html?pn=Fluent&prodver=25.2&lang=en) 2. [Electrolysis Modeling](https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/corp/v252/en/flu_tg/flu_tg_electrolysis.html) The example tries to follow the provided guidelines with #4378 and uses the new API implementation. Thanks. --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Harshal Pohekar <[email protected]>
1 parent 080596b commit f2d814e

File tree

8 files changed

+346
-1
lines changed

8 files changed

+346
-1
lines changed

.github/workflows/execute-examples-weekly.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ jobs:
173173
run: |
174174
python examples/00-fluent/transient_compressible_nozzle_workflow.py
175175
176+
- name: Execute Electrolysis_Modeling_workflow.py
177+
run: |
178+
python examples/00-fluent/Electrolysis_Modeling_workflow.py
179+
180+
176181
# https://github.com/ansys/pyfluent/issues/4157
177182
# - name: Execute conjugate_heat_transfer.py
178183
# run: |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Example on Electrolysis Modeling of Proton Exchange Membrane El… [skip tests]
44.7 KB
Loading
20.6 KB
Loading
17.1 KB
Loading
38.5 KB
Loading

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _stop_fluent_container(gallery_conf, fname):
152152
# path where to save gallery generated examples
153153
"gallery_dirs": ["examples"],
154154
# Pattern to search for example files
155-
"filename_pattern": r"exhaust_system_settings_api\.py|external_compressible_flow\.py|mixing_elbow_settings_api\.py|modeling_cavitation\.py|species_transport\.py|ahmed_body_workflow\.py|brake\.py|DOE_ML\.py|radiation_headlamp\.py|parametric_static_mixer_1\.py|conjugate_heat_transfer\.py|tyler_sofrin_modes\.py|lunar_lander_thermal\.py|modeling_ablation\.py|frozen_rotor_workflow\.py|mixing_tank_workflow\.py|single_battery_cell_workflow\.py|steady_vortex\.py|fsi_1way_workflow\.py|transient_compressible_nozzle_workflow\.py",
155+
"filename_pattern": r"exhaust_system_settings_api\.py|external_compressible_flow\.py|mixing_elbow_settings_api\.py|modeling_cavitation\.py|species_transport\.py|ahmed_body_workflow\.py|brake\.py|DOE_ML\.py|radiation_headlamp\.py|parametric_static_mixer_1\.py|conjugate_heat_transfer\.py|tyler_sofrin_modes\.py|lunar_lander_thermal\.py|modeling_ablation\.py|frozen_rotor_workflow\.py|mixing_tank_workflow\.py|single_battery_cell_workflow\.py|steady_vortex\.py|fsi_1way_workflow\.py|transient_compressible_nozzle_workflow\.py|Electrolysis_Modeling_workflow\.py",
156156
# Do not execute examples
157157
"plot_gallery": False,
158158
# Remove the "Download all examples" button from the top level gallery
Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
""".. _Electrolysis_Modeling:
24+
25+
Electrolysis Modeling
26+
-----------------------
27+
"""
28+
29+
# %%
30+
# Objective
31+
# ---------
32+
#
33+
# This example demonstrates the modeling of a PEM electrolyzer
34+
# using PyFluent. The simulation captures three-dimensional
35+
# multiphase flow involving liquid water and a gas mixture,
36+
# coupled with electrochemical reactions governed by
37+
# Butler–Volmer kinetics. It includes dual potential
38+
# fields representing electronic and ionic conduction,
39+
# along with porous media transport through the catalyst and
40+
# diffusion layers. The workflow employs the electrolysis
41+
# model to simulate hydrogen and oxygen generation at
42+
# the anode and cathode catalyst layers under a total
43+
# cell voltage of 1.73 V. Liquid water enters the anode
44+
# at 333.15 K with a mass flow rate of 0.000404 kg/s.
45+
# The simulation is performed under steady-state conditions,
46+
# initialized with full liquid saturation and a uniform
47+
# temperature field.
48+
49+
# %%
50+
# Problem Description
51+
# -------------------
52+
#
53+
# The 3D domain represents a PEM electrolyzer with an anode,
54+
# membrane, and cathode assembly, including porous and catalyst
55+
# layers, flow channels, and current collectors. Electrochemical
56+
# reactions follow Butler-Volmer kinetics with OER at the anode
57+
# and HER at the cathode. A VOF model captures gas-liquid flow,
58+
# while porous media account for Darcy flow, capillary pressure,
59+
# and contact angle effects. Dual conductivity represents both
60+
# electronic and ionic transport, with osmotic drag modeling
61+
# water transport through the membrane. The cell operates at
62+
# 1.730202 V, with liquid water entering the anode at 333.15 K
63+
# and 0.000404 kg/s.
64+
#
65+
# .. image:: ../../_static/Electrolysis_Modeling.png
66+
# :align: center
67+
# :alt: Schematic of the Electrolyzer Problem.
68+
69+
# %%
70+
# Import modules
71+
# --------------
72+
#
73+
# .. note::
74+
# Importing the following classes offer streamlined access to key solver settings,
75+
# eliminating the need to manually browse through the full settings structure.
76+
77+
import os
78+
79+
import ansys.fluent.core as pyfluent
80+
from ansys.fluent.core import examples
81+
from ansys.fluent.core.solver import (
82+
BoundaryConditions,
83+
Contour,
84+
Controls,
85+
Graphics,
86+
Initialization,
87+
Materials,
88+
Mesh,
89+
RunCalculation,
90+
Setup,
91+
)
92+
93+
# %%
94+
# Launch Fluent session in solver mode
95+
# ------------------------------------
96+
solver = pyfluent.launch_fluent(
97+
precision=pyfluent.Precision.DOUBLE,
98+
mode=pyfluent.FluentMode.SOLVER,
99+
)
100+
101+
# %%
102+
# Download mesh file
103+
# ------------------
104+
105+
mesh_file = examples.download_file(
106+
"electrolysis.msh.h5",
107+
"pyfluent/electrolysis",
108+
save_path=os.getcwd(),
109+
)
110+
111+
solver.settings.file.read_mesh(file_name=mesh_file)
112+
113+
# %%
114+
# Display mesh
115+
# ------------
116+
graphics = Graphics(solver)
117+
mesh = Mesh(solver, new_instance_name="mesh-1")
118+
119+
120+
graphics.picture.x_resolution = 650 # Horizontal resolution for clear visualization
121+
graphics.picture.y_resolution = 450 # Vertical resolution matching typical aspect ratio
122+
123+
all_walls = mesh.surfaces_list.allowed_values()
124+
125+
mesh.surfaces_list = all_walls
126+
mesh.options.edges = True
127+
mesh.display()
128+
129+
graphics.picture.save_picture(file_name="Electrolysis_Modeling_1.png")
130+
131+
# %%
132+
# .. image:: ../../_static/Electrolysis_Modeling_1.png
133+
# :align: center
134+
# :alt: Mesh
135+
136+
# %%
137+
# Enable Electrolysis Model
138+
# -------------------------
139+
setup = Setup(solver)
140+
141+
setup.models.echemistry = {
142+
"potential": True,
143+
"echemistry_enabled": True,
144+
"electrolysis": {
145+
"options": {
146+
"bc_type": "Total voltage",
147+
"tot_voltage": 1.730202, # V
148+
},
149+
"parameters": {
150+
"anode_jref": 1.36e-09, # A/m²
151+
"anode_jea": 181411, # A/m²
152+
"anode_exp": 0, # Concentration exponent
153+
"cathode_jref": 200, # A/m²
154+
"cathode_jea": 24359, # A/m²
155+
"cathode_ex_a": 1, # Anodic transfer coefficient
156+
"cathode_ex_c": 1, # Cathodic transfer coefficient
157+
"open_voltage": 1.1999, # V
158+
},
159+
"anode": {
160+
"anode_cc_zone": {
161+
"anode_cc_zone_list": ["anode_cc"],
162+
"anode_cc_material": "collector-default",
163+
},
164+
"anode_fc_zone": {"anode_fc_zone_list": ["anode_fc"]},
165+
"anode_pl_zone": {
166+
"anode_pl_zone_list": ["anode_pl"],
167+
"anode_pl_material": "porous-default",
168+
"anode_pl_porosity": 0.75, # Porosity of porous layer
169+
"anode_pl_kr": 4.9e-11, # m² Absolute permeability
170+
"anode_pl_angle": 70, # Degrees
171+
},
172+
"anode_cl_zone": {
173+
"anode_cl_zone_list": ["anode_cl"],
174+
"anode_cl_material": "catalyst-default",
175+
"anode_cl_porosity": 0.2, # Catalyst layer porosity
176+
"anode_cl_kr": 4.9e-12, # m² Catalyst layer permeability
177+
"anode_cl_angle": 80, # Degrees
178+
},
179+
},
180+
"electrolyte": {
181+
"mem_zone": {
182+
"mem_zone_list": ["mem"],
183+
"mem_material": "electrolyte-default",
184+
}
185+
},
186+
"cathode": {
187+
"cathode_cc_zone": {
188+
"cathode_cc_zone_list": ["cathode_cc"],
189+
"cathode_cc_material": "collector-default",
190+
},
191+
"cathode_fc_zone": {"cathode_fc_zone_list": ["cathode_fc"]},
192+
"cathode_pl_zone": {
193+
"cathode_pl_zone_list": ["cathode_pl"],
194+
"cathode_pl_material": "porous-default",
195+
"cathode_pl_porosity": 0.75, # Porosity
196+
"cathode_pl_kr": 1e-11, # m² Permeability
197+
},
198+
"cathode_cl_zone": {
199+
"cathode_cl_zone_list": ["cathode_cl"],
200+
"cathode_cl_material": "catalyst-default",
201+
"cathode_cl_porosity": 0.2, # Catalyst layer porosity
202+
"cathode_cl_kr": 2e-12, # m² Permeability
203+
},
204+
},
205+
"electrical_tab": {
206+
"anode_tab": ["anode_tab", "anode_tab.1", "anode_tab.1.1"],
207+
"cathode_tab": ["cathode_tab", "cathode_tab.1", "cathode_tab.1.1"],
208+
},
209+
},
210+
}
211+
212+
# %%
213+
# Define solid materials
214+
# ----------------------
215+
materials = Materials(solver)
216+
217+
# Current collector
218+
materials.solid["collector-default"] = {
219+
"electric_conductivity": {"value": 20000} # S/m
220+
}
221+
222+
# Porous layer
223+
materials.solid["porous-default"] = {"electric_conductivity": {"value": 20000}} # S/m
224+
225+
# Catalyst layer: dual conductivity
226+
materials.solid["catalyst-default"] = {
227+
"electric_conductivity": {"value": 5000}, # S/m Electronic
228+
"dual_electric_conductivity": {"value": 4.5}, # S/m Ionic in catalyst
229+
}
230+
231+
# Membrane: ionic conductivity
232+
materials.solid["electrolyte-default"] = {
233+
"dual_electric_conductivity": {"value": 11} # S/m Proton conductivity
234+
}
235+
236+
# %%
237+
# Boundary conditions
238+
# -------------------
239+
conditions = BoundaryConditions(solver)
240+
241+
# Mixture phase: thermal condition
242+
conditions.mass_flow_inlet["anode_in"] = {
243+
"phase": {"mixture": {"thermal": {"total_temperature": {"value": 333.15}}}} # K
244+
}
245+
246+
# Phase-2 (liquid water): mass flow rate
247+
conditions.mass_flow_inlet["anode_in"] = {
248+
"phase": {"phase-2": {"momentum": {"mass_flow_rate": {"value": 0.000404}}}} # kg/s
249+
}
250+
251+
# %%
252+
# Solution controls
253+
# -----------------
254+
255+
controls = Controls(solver)
256+
257+
controls.under_relaxation = {"mp": 1}
258+
259+
# %%
260+
# Initialize solution
261+
# -------------------
262+
initialize = Initialization(solver)
263+
264+
initialize.initialization_type = "standard"
265+
initialize.defaults = {
266+
"temperature": 333.15, # K
267+
"phase-2-mp": 1, # Initial volume fraction of liquid
268+
}
269+
270+
# %%
271+
# Run calculation
272+
# ---------------
273+
274+
calculation = RunCalculation(solver)
275+
276+
calculation.iterate(iter_count=300)
277+
278+
# %%
279+
# Post-processing
280+
# ---------------
281+
282+
potential_contour = Contour(solver, new_instance_name="potential_contour")
283+
284+
potential_contour.field = "potential"
285+
potential_contour.surfaces_list = ["zmid"]
286+
graphics.views.restore_view(view_name="front")
287+
potential_contour.display()
288+
289+
graphics.views.restore_view(view_name="front")
290+
graphics.picture.save_picture(file_name="Electrolysis_Modeling_2.png")
291+
292+
# %%
293+
# .. image:: ../../_static/Electrolysis_Modeling_2.png
294+
# :align: center
295+
# :alt: Potential Contour
296+
297+
volume_fraction_contour = Contour(solver, new_instance_name="volume_fraction_contour")
298+
299+
volume_fraction_contour.field = "phase-1-vof"
300+
volume_fraction_contour.surfaces_list = ["zmid", "xmid"]
301+
302+
graphics.views.restore_view(view_name="isometric")
303+
volume_fraction_contour.display()
304+
305+
graphics.picture.save_picture(file_name="Electrolysis_Modeling_3.png")
306+
307+
# %%
308+
# .. image:: ../../_static/Electrolysis_Modeling_3.png
309+
# :align: center
310+
# :alt: Volume Fraction Contour
311+
312+
# save case and data file
313+
solver.settings.file.write(file_type="case-data", file_name="electrolysis")
314+
315+
# %%
316+
# Close session
317+
# -------------
318+
solver.exit()
319+
320+
# %%
321+
# Summary
322+
# -------
323+
#
324+
# In this example, we used PyFluent to simulate a complete PEM
325+
# electrolysis process under steady-state conditions. The model
326+
# applies Butler-Volmer electrochemistry with a total cell voltage
327+
# boundary condition and includes dual conductivity in catalyst
328+
# layers, multiphase VOF flow, and porous media transport. Effects
329+
# such as osmotic drag and capillary pressure capture water
330+
# management within the cell. The workflow defines zones, assigns
331+
# materials, sets inlet conditions, and solves for coupled
332+
# electrochemical and flow fields.
333+
334+
# %%
335+
# References:
336+
# -----------
337+
# [1] Electrolysis Modeling, `Ansys Fluent documentation​ <https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/corp/v252/en/flu_tg/flu_tg_electrolysis.html>`_.
338+
339+
# sphinx_gallery_thumbnail_path = '_static/Electrolysis_Modeling.png'

0 commit comments

Comments
 (0)