Message Boards Message Boards

GROUPS:

Thermochemical analysis: linking Mathematica and CEA

Posted 9 months ago
561 Views
|
0 Replies
|
1 Total Likes
|

Hello,
I wanto to share a useful way to perfom thermochemical analysis by linking Mathematica and CEA (Chemical Equilibrium Algoritm), a NASA software.
Using CEA is relatively simple:
1) by using a text editor you write an appropriate text file for an appropriate problem, for example a combustion problem:

problem o/f = 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1,
hp p,atm=200, t,c=3000
react
fuel=JP-5 moles=1 t,k=298.15
fuel=JP-4 moles=1 t,k=298.15
fuel=RP-1 moles=1 t,k=298.15
oxid=Air moles=1 t,k=300
output
plot p t rho h m cp gam son Ar CO2 N2 O2
end

2) Then you save the file with the extension .inp, and run the FCEA2 (.exe) application by writing the input file without any extension. The application will generate two files: .out and .plt. The .out is a general report file and .plt is the data file that contains the calculated quantities indicated in the "plot" section of the input file, for example pressure (p), temperature (t), density (rho) etc...

This process can be automated using Mathematica, in particular the Run[ ] function, so you can generate a database, performing interpolation etc...

We can do this, for example this simple way:
1) write a function to generate the input file; for combustion we have:

CEACombustion = StringJoin[{
     {"problem" <> " " <> ("O/f" /. #)}, {"\n"},
     {"ProblemType" /. #}, {"\n"},
     {"react"}, {"\n"},
     {"AddReactProperties" /. #}, {"\n"},
     {"output"}, {"\n"},
     {"Output" /. #}, {"\n"},
     {"end"}, {"\n"} 
     }] &;

2) Apply this function to a list of parameters to generate the actual file:

InputFile = CEACombustion[{
     "O/f" -> "o/f =0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1,",
     "ProblemType" -> "hp p,atm=200, t,c=3000",
     "AddReactProperties" -> {"fuel=JP-5  moles=1  t,k=298.15", "\n", 
       "fuel=JP-4  moles=1  t,k=298.15", "\n", 
       "fuel=RP-1  moles=1  t,k=298.15", "\n", 
       "oxid=Air moles=1  t,k=300"},
     "Output" -> "plot p t rho h m cp gam son Ar CO2 N2 O2"
     }];

3) Export the file ( in the same directory of FCEA2 ):

Export["CombustionProblem.inp",InputFile,"Text"];

4) Now run FCEA2 (in windows):

Run["@echo CombustionProblem|FCEA2"];

5) Import the .plt file and perform computation on the data...

  PLTfile = Import["CombustionProblem.plt","Table"];

Obviously you can create multiple input files for example for different reagent temperature values ​​etc ...
You can find CEA here CEAsite
Gianluca

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract