An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An...

41
Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example An openFuelCell tutorial Henrik Grimler 2017-11-22 Henrik Grimler An openFuelCell tutorial 2017-11-22 1 / 27

Transcript of An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An...

Page 1: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

An openFuelCell tutorial

Henrik Grimler

2017-11-22

Henrik Grimler An openFuelCell tutorial 2017-11-22 1 / 27

Page 2: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

What is a fuel cell?

Converts chemical energy to electrical energy (+ heat, + products)

Chemical energy stored in a fuel

Fuel + oxidant − > electricity + heat + products

Hydrogen often used as fuel

Air or pure oxygen often used as oxidant

Henrik Grimler An openFuelCell tutorial 2017-11-22 2 / 27

Page 3: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

What is a fuel cell?

Converts chemical energy to electrical energy (+ heat, + products)

Chemical energy stored in a fuel

Fuel + oxidant − > electricity + heat + products

Hydrogen often used as fuel

Air or pure oxygen often used as oxidant

Henrik Grimler An openFuelCell tutorial 2017-11-22 2 / 27

Page 4: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

What is a fuel cell?

Converts chemical energy to electrical energy (+ heat, + products)

Chemical energy stored in a fuel

Fuel + oxidant − > electricity + heat + products

Hydrogen often used as fuel

Air or pure oxygen often used as oxidant

Henrik Grimler An openFuelCell tutorial 2017-11-22 2 / 27

Page 5: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

What is a fuel cell?

Converts chemical energy to electrical energy (+ heat, + products)

Chemical energy stored in a fuel

Fuel + oxidant − > electricity + heat + products

Hydrogen often used as fuel

Air or pure oxygen often used as oxidant

Henrik Grimler An openFuelCell tutorial 2017-11-22 2 / 27

Page 6: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

What is a fuel cell?

Converts chemical energy to electrical energy (+ heat, + products)

Chemical energy stored in a fuel

Fuel + oxidant − > electricity + heat + products

Hydrogen often used as fuel

Air or pure oxygen often used as oxidant

Henrik Grimler An openFuelCell tutorial 2017-11-22 2 / 27

Page 7: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Fuel cell basics

Overall reaction:2 H2 + O2 −−→ 2 H2OHalf cell reactions:

2H2 −−→ 4H+ + 4 e− Anode

O2 + 4H+ + 4 e− −−→ 2H2O Cathode

2H2 +O2 −−→ 2H2O

Henrik Grimler An openFuelCell tutorial 2017-11-22 3 / 27

Page 8: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Illustration of fuel cell

H2 O2

H2O

H+

Anode

Membrane

Cathode

Henrik Grimler An openFuelCell tutorial 2017-11-22 4 / 27

Page 9: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Different types of fuel cells

high-temperature (HT) and low-temperature (LT) fuel cells

polymer electrolyte membrane fuel cell (PEMFC)

solid oxide fuel cell (SOFC), H2 and CO as fuel

molten carbonate fuel cell (MCFC), H2, CO and CO2 as fuel

For LT fuel cell, efficiency up to 65%.

For HT fuel cell, efficiency more than 80% (thanks to useable heat)

Henrik Grimler An openFuelCell tutorial 2017-11-22 5 / 27

Page 10: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Different types of fuel cells

HT and LT fuel cells

PEMFC

SOFC, H2 and CO as fuel

MCFC, H2, CO and CO2 as fuel

For LT fuel cell, efficiency up to 65%.

For HT fuel cell, efficiency more than 80% (thanks to useable heat)

Henrik Grimler An openFuelCell tutorial 2017-11-22 5 / 27

Page 11: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Different types of fuel cells

HT and LT fuel cells

PEMFC

SOFC, H2 and CO as fuel

MCFC, H2, CO and CO2 as fuel

For LT fuel cell, efficiency up to 65%.

For HT fuel cell, efficiency more than 80% (thanks to useable heat)

Henrik Grimler An openFuelCell tutorial 2017-11-22 5 / 27

Page 12: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Different types of fuel cells

HT and LT fuel cells

PEMFC

SOFC, H2 and CO as fuel

MCFC, H2, CO and CO2 as fuel

For LT fuel cell, efficiency up to 65%.

For HT fuel cell, efficiency more than 80% (thanks to useable heat)

Henrik Grimler An openFuelCell tutorial 2017-11-22 5 / 27

Page 13: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Different types of fuel cells

HT and LT fuel cells

PEMFC

SOFC, H2 and CO as fuel

MCFC, H2, CO and CO2 as fuel

For LT fuel cell, efficiency up to 65%.

For HT fuel cell, efficiency more than 80% (thanks to useable heat)

Henrik Grimler An openFuelCell tutorial 2017-11-22 5 / 27

Page 14: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Why fuel cells?

Transit into a sustainable (hydrogen)-society with renewable energysources need fuel cells!

Hydrogen is an energy carrierEnergy can be stored efficient (long term) as compressed hydrogenHydrogen is also widely used in the industryUnderstanding fuel cells is very important, modeling needed!

H2

Usage

H2O

Sun

Henrik Grimler An openFuelCell tutorial 2017-11-22 6 / 27

Page 15: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Why fuel cells?

Transit into a sustainable (hydrogen)-society with renewable energysources need fuel cells!Hydrogen is an energy carrier

Energy can be stored efficient (long term) as compressed hydrogenHydrogen is also widely used in the industryUnderstanding fuel cells is very important, modeling needed!

H2

Usage

H2O

Sun

Henrik Grimler An openFuelCell tutorial 2017-11-22 6 / 27

Page 16: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Why fuel cells?

Transit into a sustainable (hydrogen)-society with renewable energysources need fuel cells!Hydrogen is an energy carrierEnergy can be stored efficient (long term) as compressed hydrogen

Hydrogen is also widely used in the industryUnderstanding fuel cells is very important, modeling needed!

H2

Usage

H2O

Sun

Henrik Grimler An openFuelCell tutorial 2017-11-22 6 / 27

Page 17: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Why fuel cells?

Transit into a sustainable (hydrogen)-society with renewable energysources need fuel cells!Hydrogen is an energy carrierEnergy can be stored efficient (long term) as compressed hydrogenHydrogen is also widely used in the industry

Understanding fuel cells is very important, modeling needed!

H2

Usage

H2O

Sun

Henrik Grimler An openFuelCell tutorial 2017-11-22 6 / 27

Page 18: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Why fuel cells?

Transit into a sustainable (hydrogen)-society with renewable energysources need fuel cells!Hydrogen is an energy carrierEnergy can be stored efficient (long term) as compressed hydrogenHydrogen is also widely used in the industryUnderstanding fuel cells is very important, modeling needed!

H2

Usage

H2O

Sun

Henrik Grimler An openFuelCell tutorial 2017-11-22 6 / 27

Page 19: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

History of openFuelCell

Developed as joint project between Forschungszentrum Jlich, NationalResearch Council Canada, Queens University/Royal Military CollegeFuel Cell Research Centre, and Wikki Ltd.

Originally targeting SOFC, later extended to include HT-PEMFC

Henrik Grimler An openFuelCell tutorial 2017-11-22 7 / 27

Page 20: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Acquiring the openFuelCell code

Acquiring the openFuelCell code

To avoid creating a set of files that will be available online but neverupgraded, the files has not been supplied and so must be acquired throughgit.The changes to the source code is supplied in a patch(OF1706+_Grimler.patch )

Henrik Grimler An openFuelCell tutorial 2017-11-22 8 / 27

Page 21: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Acquiring the openFuelCell code

Aquiring the openFuelCell code

Execute these steps from a suitable directory (for example $FOAM_RUN)

# sou r c e the e t c / ba sh r c f i l eOF1706+run # to cd to $FOAM RUN

# c l on e the code :g i t c l o n e g i t : / / g i t . code . s f . ne t /p/ o p e n f u e l c e l l / g i t o p e n f u e l c e l lcd o p e n f u e l c e l lg i t c h e c k o u t V3

Henrik Grimler An openFuelCell tutorial 2017-11-22 9 / 27

Page 22: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

openFuelCell code structure

The openFuelCell code structure

Code is divided into two subfolders, appSrc and libSrc

libSrc contains classes that are in many cases slightly modifiedversions of classes in $FOAM_SRC

appSrc contain the solver files

The main code is appSrc/sofcFoam.C

Henrik Grimler An openFuelCell tutorial 2017-11-22 10 / 27

Page 23: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Meshes and submeshes

Meshes and submeshes

There are in total 5 meshes used

cell

air

electrolyte

fuel

interconnects

Henrik Grimler An openFuelCell tutorial 2017-11-22 11 / 27

Page 24: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Walkthrough of sofcFoam.C

Walkthrough of sofcFoam.C

Header crediting authors/∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗\

========= |\\ / F i e l d | OpenFOAM : The Open Source CFD Toolbox\\ / O p e r a t i o n |\\ / A nd |\\/ M a n i p u l a t i o n |

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−L i c e n s e

Thi s f i l e i s p a r t o f OpenFOAM .

OpenFOAM i s f r e e s o f t w a r e ; you can r e d i s t r i b u t e i t and / o r modi fy i tunder th e terms o f t he GNU G e n e r a l P u b l i c L i c e n s e as p u b l i s h e d by t heF r e e S o f t w a r e Foundat ion ; e i t h e r v e r s i o n 2 o f t he L i c e n s e , o r ( at youro p t i o n ) any l a t e r v e r s i o n .

OpenFOAM i s d i s t r i b u t e d i n the hope t h a t i t w i l l be u s e f u l , but WITHOUTANY WARRANTY; w i t h o u t even t he i m p l i e d w a r r a n t y o f MERCHANTABILITY o rFITNESS FOR A PARTICULAR PURPOSE . See th e GNU G e n e r a l P u b l i c L i c e n s ef o r more d e t a i l s .

You s h o u l d have r e c e i v e d a copy o f th e GNU G e n e r a l P u b l i c L i c e n s ea l o n g w i t h OpenFOAM ; i f not , w r i t e to th e F r e e S o f t w a r e Foundat ion ,I n c . , 51 F r a n k l i n St , F i f t h F l o o r , Boston , MA 02110−1301 USA

A p p l i c a t i o nsofcFoam

D e s c r i p t i o nSteady s o l v e r f o r th e i d e a l i s e d f u e l c e l l model under p r o j e c t work f o rNRC Canada , Feb/2007−

Deve loped byH r v o j e Jasak ( h . j a s a k @ w i k k i . co . uk )Steven B e a l e ( s . b e a l e @ f z− j u e l i c h . de )Dong Hyup Jeon ( DongHyup . Jeon@nrc−c n r c . gc . ca )Helmut Roth ( helmut . roth@nrc−c n r c . gc . ca )Hae−won Choi ( haewon1972@gmail . com )

\∗−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−∗/

Henrik Grimler An openFuelCell tutorial 2017-11-22 12 / 27

Page 25: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Walkthrough of sofcFoam.C

Walkthrough of sofcFoam.C

#i n c l u d e <i o s t r e a m>#i n c l u d e <s t d i o . h>#i n c l u d e <iomanip>

#i n c l u d e ”fvCFD .H”#i n c l u d e ” atomicWeights .H”#i n c l u d e ” p h y s i c a l C o n s t a n t s .H”#i n c l u d e ” s p e c i e .H”#i n c l u d e ” s p e c i e s T a b l e .H”#i n c l u d e ” s o f c S p e c i e .H”

#i n c l u d e ” p a t c h T o P a t c h I n t e r p o l a t i o n .H”#i n c l u d e ” c o n t i n u i t y E r r s .H”#i n c l u d e ” i n i t C o n t i n u i t y E r r s .H”#i n c l u d e ” f i x e d G r a d i e n t F v P a t c h F i e l d s .H”#i n c l u d e ” smearPatchToMesh .H”

#i n c l u d e ” d i f f u s i v i t y M o d e l s .H”/∗ #i n c l u d e ” porousZones .H” D e l e t e d SBB ∗/#i n c l u d e ” p o r o u s Z o n e L i s t .H”// Added SBB#i n c l u d e ” polyToddYoung .H”#i n c l u d e ” R i d d e r s R o o t .H”// added SBB ( p r e v i o u s l y )#i n c l u d e ” t e s t F u n c t i o n .H”// added SBB ( p r e v i o u s l y )

// ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ //

Henrik Grimler An openFuelCell tutorial 2017-11-22 13 / 27

Page 26: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Walkthrough of sofcFoam.C

Walkthrough of sofcFoam.C

i n t main ( i n t argc , c h a r ∗ a r g v [ ] ){# i n c l u d e ” s e t R o o t C a s e .H”# i n c l u d e ” c r e a t e T i m e .H”

// Complete c e l l components# i n c l u d e ” createMesh .H”# i n c l u d e ” r e a d C e l l P r o p e r t i e s .H”# i n c l u d e ” c r e a t e C e l l F i e l d s .H”

// I n t e r c o n n e c t 0 components# i n c l u d e ” c r e a t e I n t e r c o n n e c t M e s h .H”

// Air−r e l a t e d components# i n c l u d e ” c r e a t e A i r M e s h .H”# i n c l u d e ” r e a d A i r P r o p e r t i e s .H”# i n c l u d e ” c r e a t e A i r F i e l d s .H”# i n c l u d e ” c r e a t e A i r S p e c i e s .H”

// E l e c t r o l y t e components# i n c l u d e ” c r e a t e E l e c t r o l y t e M e s h .H”# i n c l u d e ” r e a d E l e c t r o l y t e P r o p e r t i e s .H”# i n c l u d e ” r e a d A c t i v a t i o n P a r a m e t e r s .H”// Added SBB# i n c l u d e ” c r e a t e E l e c t r o l y t e F i e l d s .H”

// Fuel−r e l a t e d components# i n c l u d e ” c r e a t e F u e l M e s h .H”# i n c l u d e ” r e a d F u e l P r o p e r t i e s .H”# i n c l u d e ” c r e a t e F u e l F i e l d s .H”# i n c l u d e ” c r e a t e F u e l S p e c i e s .H”

# i n c l u d e ” r e a d I n t e r c o n n e c t P r o p e r t i e s .H”

# i n c l u d e ” r e a d R x n P r o p e r t i e s .H”

# i n c l u d e ” s e t G l o b a l P a t c h I d s .H”

// c a l c u l a t e e l e c t r o l y e t h i c k n e s s , hE# i n c l u d e ” e l e c t r o l y t e T h i c k n e s s .H”

// Cathode & Anode i n t e r p o l a t i o n# i n c l u d e ” c r e a t e P a t c h T o P a t c h I n t e r p o l a t i o n .H”

// Gas d i f f u s i v i t y models# i n c l u d e ” c r e a t e D i f f u s i v i t y M o d e l s .H”

# i n c l u d e ” v a r I n i t .H” // Added Qing , 2 5 . 0 6 . 2 0 1 4

// ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ //

Henrik Grimler An openFuelCell tutorial 2017-11-22 14 / 27

Page 27: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Walkthrough of sofcFoam.C

Walkthrough of sofcFoam.C

I n f o<< ”\ n S t a r t i n g t ime l o o p \n” << e n d l ;

b o o l f i r s t T i m e = t r u e ;

f o r ( runTime++; ! runTime . end ( ) ; runTime++){

I n f o<< ”Time = ” << runTime . timeName ( ) << n l << e n d l ;

#i n c l u d e ” mapFromCell .H”// map g l o b a l T to f l u i d r e g i o n s

# i n c l u d e ” r h o A i r .H”#

i n c l u d e ” r h o F u e l .H”

# i n c l u d e ” muAir .H”# i n c l u d e ” muFuel .H”

// F o l l o w i n g l i n e s added SBB# i n c l u d e ” n uA i r .H”# i n c l u d e ” nuFue l .H”

// End l i n e s added SBB# i n c l u d e ” k A i r .H”# i n c l u d e ” k F u e l .H”

#i n c l u d e ” s o l v e F u e l .H”

#i n c l u d e ” s o l v e A i r .H”

#i n c l u d e ” ReynoldsNumber .H”

#i n c l u d e ” d i f f u s i v i t y A i r .H”

#i n c l u d e ” d i f f u s i v i t y F u e l .H”

#i n c l u d e ” Yfue lEqn .H”

#i n c l u d e ” YairEqn .H”

#i n c l u d e ” s o l v e E l e c t r o c h e m i s t r y .H”

#i n c l u d e ” mapToCell .H”

#i n c l u d e ” s o l v e E n e r g y .H”

runTime . w r i t e ( ) ;

i f ( f i r s t T i m e ){

f i r s t T i m e = f a l s e ;}

I n f o<< ” Execut ionTime = ”<< runTime . e lapsedCpuTime ( )<< ” s \n\n” << e n d l ;

}

I n f o<< ”End\n” << e n d l ;r e t u r n ( 0 ) ;

}

Henrik Grimler An openFuelCell tutorial 2017-11-22 15 / 27

Page 28: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Intended changes to the code

Intended to implement physical constants (Cp, H, S) lookup &calculation from CHEMKIN database file.

Discovered that this had basically already been done, code which doespretty much the exact same thing has been added

Tried to simplify code instead (but did not manage to finish it)

Henrik Grimler An openFuelCell tutorial 2017-11-22 16 / 27

Page 29: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Duplicate code in openFuelCell

Much of the openFuelCell code is basically duplicate code

appSrc/diffusivityFuel.H

appSrc/kFuel.H

appSrc/muFuel.H

appSrc/nuFuel.H

appSrc/rhoFuel.H

appSrc/solveFuel.H

basically identical with

appSrc/diffusivityAir.H

appSrc/kAir.H

appSrc/muAir.H

appSrc/nuAir.H

appSrc/rhoAir.H

appSrc/solveAir.HHenrik Grimler An openFuelCell tutorial 2017-11-22 17 / 27

Page 30: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Duplicate code in openFuelCell

Solving on anode done in the same way as on cathode

Code for solving on the submeshes could be (roughly) cut in half

Today 64 files in appSrc

Henrik Grimler An openFuelCell tutorial 2017-11-22 18 / 27

Page 31: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

Summary of OF1706+ Grimler.patch

Three type of changes required

Way to access internalField/boundaryField changed

API of PSTREAM module changed

Some files has been moved in the $FOAM_SRCtree,-I$(FOAM_SRC)/.. need to be changed accordingly

Henrik Grimler An openFuelCell tutorial 2017-11-22 19 / 27

Page 32: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

internal/boundaryField changes

Changed so that the ref of the internal and boundaryFields can moreeasily be accessed1

internalField − > primitiveFieldRef in many places

boundaryField − > boundaryFieldRef in many places

1https://bugs.openfoam.org/view.php?id=1938Henrik Grimler An openFuelCell tutorial 2017-11-22 20 / 27

Page 33: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

internal/boundaryField changes

Changed so that the ref of the internal and boundaryFields can moreeasily be accessed1

internalField − > primitiveFieldRef in many places

boundaryField − > boundaryFieldRef in many places

1https://bugs.openfoam.org/view.php?id=1938Henrik Grimler An openFuelCell tutorial 2017-11-22 20 / 27

Page 34: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

internal/boundaryField changes

Changed so that the ref of the internal and boundaryFields can moreeasily be accessed1

internalField − > primitiveFieldRef in many places

boundaryField − > boundaryFieldRef in many places

1https://bugs.openfoam.org/view.php?id=1938Henrik Grimler An openFuelCell tutorial 2017-11-22 20 / 27

Page 35: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

Pstream changes

Pstream::blocking needs to be replaced withPstream::commsTypes::blocking on 8 placesThis change took place in commit1e6c9a0a541554c119035e671389b699432cea33 in the OpenFOAM-devtree.

Henrik Grimler An openFuelCell tutorial 2017-11-22 21 / 27

Page 36: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Porting the code to OpenFOAM-v1706+ (and OpenFOAM-5.x)

Applying the patch

To apply the patch, execute

git apply OF1706+_Grimler.patch

when standing at the root of the openFuelCell file tree.

Henrik Grimler An openFuelCell tutorial 2017-11-22 22 / 27

Page 37: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Running quickTest – parallel mode

To run the quickTest case, first go to the run/quickTest directory

The run cases are run with the help of Makefiles

Cases are setup for either single run or parallel run

parallel run is default

make all executes

make mesh

make parprep

make run

make reconstruct

make view

Henrik Grimler An openFuelCell tutorial 2017-11-22 23 / 27

Page 38: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Running quickTest – parallel mode

make mesh generates the mesh files from blockMeshDict

make parprep deconstructs the mesh so that it can be solved inparallel

make run does the actual solving

make reconstruct reconstructs the mesh so that we can look at theresults

make view generates the VTK files

Now, the results can be viewed with paraview!

Henrik Grimler An openFuelCell tutorial 2017-11-22 24 / 27

Page 39: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Running quickTest – single mode

To run the simulation in single mode, do instead

make mesh

make srun

make view

And again, the results can be viewed with paraview!

Henrik Grimler An openFuelCell tutorial 2017-11-22 25 / 27

Page 40: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

Results...

paraview VTK/quickTest_120.vtk

(How can I specify multiply files to open in paraview from CL?)

Henrik Grimler An openFuelCell tutorial 2017-11-22 26 / 27

Page 41: An openFuelCell tutorial - tfd.chalmers.sehani/kurser/OS_CFD_2017/HenrikGrimler/... · An openFuelCell tutorial ... Air or pure oxygen often used as oxidant ... Energy can be stored

Introduction to fuel cells Introduction to openFuelCell My changes Running the quickTest openFuelCell example

The end

Fuel cells rock!

Henrik Grimler An openFuelCell tutorial 2017-11-22 27 / 27