-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Plug Flow Reactor MATLAB code for changing are and straight area #701
Plug Flow Reactor MATLAB code for changing are and straight area #701
Conversation
Codecov Report
@@ Coverage Diff @@
## master #701 +/- ##
==========================================
+ Coverage 71.40% 71.57% +0.17%
==========================================
Files 372 372
Lines 43605 44499 +894
==========================================
+ Hits 31134 31849 +715
- Misses 12471 12650 +179
Continue to review full report at Codecov.
|
What is the status of this pull request. Is there any comments? Is there anything that I should look into? |
Hi! Sorry that no one has responded to you. We haven't had the time to review this yet. Thanks for your patience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! Thank you again for this contribution. I have a few concerns broadly about this example, in addition to the specific comments listed below. Please feel free to ask any questions or push back on any suggestion.
- Can you provide a short source/description with the derivation of the equations you're using here, particularly the conservation equations for mass, energy, and species?
- You are using the equilibrated
gas_conv
object passed into all your calls. This results in the composition being essentially fixed and nothing much interesting happening (i.e., this could be solved by frozen composition calculations without an ODE I think). Was this intentional? I tried to change the state to the equilibrated temperature, but the initial composition, but the simulation took a long time and I didn't wait for it to finish. - The files that you're adding here should be placed in the
samples/matlab
folder, please.
Thanks again for your contribution, and please do let me know any questions you have!
General_Plug_Flow_Reactor.m
Outdated
@@ -0,0 +1,75 @@ | |||
% This code snippet is a sample to model a converging nozzle as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for this example should be in the format similar to flame1.m
in the samples/matlab
folder. In other words, something like
% GENERAL_PLUG_FLOW_REACTOR - One line description
%
% Longer description goes here indented by four spaces after the
% comment character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
General_Plug_Flow_Reactor.m
Outdated
in2 = speciesIndex(gas_conv,'N2'); | ||
nsp = nSpecies(gas_conv); | ||
x = zeros(nsp,1); | ||
% Change the below values for different Phi values of methane Combsution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small typo here... "Combsution" -> "combustion"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
General_Plug_Flow_Reactor.m
Outdated
nsp = nSpecies(gas_conv); | ||
x = zeros(nsp,1); | ||
% Change the below values for different Phi values of methane Combsution | ||
x(ich4,1) =0.2899; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make sure the spacing before and after the =
sign is consistent with the rest of the code? Also, can you delete the space at the end of the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
General_Plug_Flow_Reactor.m
Outdated
|
||
%% Converging Section | ||
% The Dimensions and conditions of the reactor are given below | ||
A_in=0.018; % Inlet Area |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if the different quantities were labeled by a comment above the variable, rather than on the same line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
General_Plug_Flow_Reactor.m
Outdated
% k = -1 makes the solver solve for converging area. | ||
% Use k = +1 for diverging area. make sure to change the inlet and exit area for diverging area | ||
% Use k = 0 for constant cross sectional area | ||
k=-1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you automatically set k
based on the relative values for A_in
and A_out
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
PFR_solver_CANTERA.m
Outdated
%---density, temperature and mass fractions variations along a plug flow--- | ||
%-------------------------reactor------------------------------------------ | ||
%-------------------------------------------------------------------------- | ||
F(1)=((1-R/cp_mass(gas))*((rho*vx)^2)*(1/A)*(dAdx) + rho*R*sum(MW.*w.*(h-MW_mix*cp_mass(gas)*T./MW))/(vx*cp_mass(gas)) ) / (P*(1+vx^2/(cp_mass(gas)*T)) - rho*vx^2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to add a variable for the value of cp_mass
to avoid having to calculate it so many times in these two lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should also split this calculation over several lines by defining several variables to hold different pieces of the equation. That will make it easier for people to see how each term is calculated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is easier for me like this to debug. If everything else is approved, I can change this as the last step before you upload it to the main repository
PFR_solver_CANTERA.m
Outdated
if k~=0 | ||
set(gas,'Temperature',T,'Density',rho,'MassFractions',Y); % the gas is set to the corresponding properties during each iteration of the ode loop | ||
else | ||
set(gas,'Temperature',T,'Pressure',P,'MassFractions',Y); % the gas is set to the corresponding properties during each iteration of the ode loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use pressure to set the state when k = 0
? Density should be equally as valid, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I changed it
PFR_solver_CANTERA.m
Outdated
@@ -0,0 +1,43 @@ | |||
function [F] = PFR_solver_CANTERA(x,initial,gas,mdot,A_in,dAdx,k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of naming this function PFR_solver_CANTERA
, can you just name it PFR_solver
? I think you should also be able to include it in the PFR_setup.m
file, at the end of that file. I'm not that familiar with how MATLAB functions are defined though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
PFR_solver_CANTERA.m
Outdated
|
||
if k==1 | ||
A = A_in-k*dAdx*x; | ||
elseif k==-1|k==0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My linter suggests using ||
for this comparison. However, if k = 1
, doesn't this result in the area decreasing anyways? I think you have a logic error here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I fixed it
PFR_solver_CANTERA.m
Outdated
F(2) = (vx*vx/(rho*cp_mass(gas)))*F(1) + vx*vx*(1/A)*(dAdx)/cp_mass(gas) - (1/(vx*rho*cp_mass(gas)))*sum(h.*w.*MW); | ||
|
||
for i = 3:nsp+2 | ||
F(i) = w(i-2)*MW(i-2)/(rho*vx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a for-loop, can you do this calculation all at once, and then add the calculated values into the F
array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@mgashwinkumar Hi 👋 Do you have any questions about the comments that I left here? How to update the code, or anything like that? |
Bryan,
Thanks for reaching out. I didn’t get a chance to review the questions you posted to me. I will do that and upload the revised version soon.
Regards
Ashwin
From: Bryan W. Weber
Sent: Monday, December 2, 2019 9:35 PM
To: Cantera/cantera
Cc: mgashwinkumar; Mention
Subject: Re: [Cantera/cantera] Plug Flow Reactor MATLAB code for changing areand straight area (#701)
@mgashwinkumar Hi 👋 Do you have any questions about the comments that I left here? How to update the code, or anything like that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@mgashwinkumar Hello again! Just wondering when/if you'll have a chance to update this code? Thanks! |
@bryanwweber , I will update the code and try to address your comments in two-three weeks. |
@mgashwinkumar thanks! Let me know if you have any questions, I'm happy to help |
@bryanwweber , Is there a way to retrieve the version that I uploaded earlier for reference? |
@mgashwinkumar You can go to https://github.com/Cantera/cantera/pull/701/files and then click the 3 dots, and then "View File" which will let you see the original version. |
@bryanwweber , I replied to each of your comment individually. I have uploaded the derivations in a pdf along with this comment. I have also uploaded the new files into samples/matlab of my individual repository. Please let me know if you have any other question or concern. |
@mgashwinkumar Thank you! Unfortunately, I can't see any of the changes here. Did you do them on your local computer? If so, you'll need to |
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
code
{mso-style-priority:99;
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
-->Bryan, Yes. I changed it on my local Matlab. I just uploaded it. I didn’t do any git commit. Can you please help with me. Also, if you don’t mind, are you available to meet over zoom sometime tomorrow so that you can show me how to do and I don’t have to bother you every time. Sorry, its just my lack of experience with GitHub. RegardsAshwin From: Bryan W. WeberSent: Monday, June 1, 2020 8:51 PMTo: Cantera/canteraCc: mgashwinkumar; MentionSubject: Re: [Cantera/cantera] Plug Flow Reactor MATLAB code for changing are and straight area (#701) @mgashwinkumar Thank you! Unfortunately, I can't see any of the changes here. Did you do them on your local computer? If so, you'll need to git commit them, and then git push them so they're on GitHub. Let me know if you need any help with that!—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
@mgashwinkumar No problem! Send me an email to the email on my profile and we can set up a meeting. Tomorrow won't work for me, but Wednesday or Thursday will be a little better. |
@mgashwinkumar Wednesday at 10 would work for me. Can you send a separate Zoom invite by email? I don't think it's a good idea to publish meeting codes publicly like this. |
762c776
to
5883fd8
Compare
@mgashwinkumar I made a few more fixes to the files here, let me know if anything seems wrong! https://github.com/Cantera/cantera/pull/701/files |
@bryanwweber , I would like to download the latest version and run it once on my computer to check if everything is fine. Should I download the file from the main cantera repository or the forked copy of mine? |
@mgashwinkumar the forked copy, all the changes got made to those copies |
Hi, @mgashwinkumar -- thanks so much for submitting this PR - I think it will be well-received and useful for many! I made a few small changes, mostly to documentation and variable names in a couple places, but otherwise this should be good to go! |
@bryanwweber , @decaluwe , Thank you very much for your inputs, I have a few comments/questions mentioned below:
|
@bryanwweber , Any updates about the final version and the comment I posted yesterday? |
The reactor can have varying area, and therefore, pressure variation throughout the domain. The example is solved by discretizing the domain into chunks and solving them as a sequence of 0-D reactors.
Renaming solution vector references. Renaming 'init' variable, external and internal to the residual function for greater clarity. External to the ode call, they are renamed 'inlet_soln', since they correspond to the current volume's inlet state. Within the ode call, they are renamed 'soln_vector' since they represent solution at the current location x.
The call to meanMolecularWeight was previously located before the Cantera gas object was set to the current state. This commit fixes that.
2588556
to
e9bd282
Compare
@mgashwinkumar No problem adding the contact info. The YAML file is something new in Cantera 2.5.0, so I wouldn't expect it to work in your environment unless you compiled Cantera yourself fairly recently. Using the CTI version is fine for your local testing, but since this will go out with Cantera 2.5.0, we'd like it to use the new format. Once we release v2.5.0 (sometime this summer), your example will show up on the website! Thanks again for the contribution, I'm just going to wait for the tests to pass before merging it into |
@bryanwweber , Thank you very much for your help. I am happy that I contributed to the combustion community. Please let me know when you publish it online. |
Please fill in the issue number this pull request is fixing:
Fixes #
Changes proposed in this pull request: