CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

How to describe the movement of a piston?

Register Blogs Community New Posts Updated Threads Search

Like Tree12Likes
  • 1 Post By aerosayan
  • 1 Post By aerosayan
  • 1 Post By FMDenaro
  • 2 Post By aerosayan
  • 2 Post By FMDenaro
  • 2 Post By aerosayan
  • 1 Post By Harlotte
  • 1 Post By aerosayan
  • 1 Post By aerosayan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2021, 09:25
Smile How to describe the movement of a piston?
  #1
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Hello everyone,
I am currently working on my masters thesis which is about writing a code in Matlab to describe the simulation of a gas exchange in an hydrogen combustion engine.
I am at the beginning of my studies and I am using lid driven cavity as an example to write the code. But I found some questions:How do I describe the movement of the piston in the code written in matlab? And what are the main equations I have to use to describe the gas (NS equation, convection-diffusion equation)? When I use the NS equation to describe the flow of the gas, I find it difficult to describe the convective diffusion equation at the same time?
I would be very grateful if you could give me some advice
Harlotte is offline   Reply With Quote

Old   October 20, 2021, 10:21
Default
  #2
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
This is a complicated question, as your research topic is advanced.


I'm giving a very brief answer. It's not very detailed, so ask if you have more queries.


In my opinion, matlab may be slow if you have a very computationally intensive code. You would have to use vectorization and Intel's MKL library in matlab to get good performance.I say this, because if your code uses the basic do/for loops in matlab, it would be slow.


If the code isn't computationally intensive, you can use matlab without any issue.


(EDIT : Forgot to answer your question before. A moving piston is basically a boundary condition that you can apply to your mesh. For example. it would be something as, the lid of your lid driven cavity moving down instead of sideways. The boundary condition on the lid would prevent any mass to go out of the domain, and it will push the mass inward and compress it. You would need to model the force with which the piston moves down, and the force of compressed gases that work to push it up. The net force will determine the final direction of movement.)



For a moving boundary simulation (as the piston essentially changes the domain volume completely), you have different options available to represent such a system.


  1. You could use adaptive meshing (preferably quadtree or octree based meshing) such that the engine volume is remeshed as the piston traverses up and down. This will possibly be the simplest option (if you use commercial codes), and even commercial codes like OpenFOAM and ANSYS can use this kind of meshing to represent the moving piston and the moving boundary.
  2. Another option would be to use overset meshing, but honestly it may not be worth your effort as quadtree or octree meshing works well enough. One advantage of using overset meshing with structured grids can be that you can write your solvers to work only on structured grids, so your solver development efforts become easier. However, creating the structured grids become a little bit difficult, and adaptive meshing becomes a little bit difficult (if you already don't know what you're doing).
Regarding representing the convective and diffusive equations...


I'm not too experienced to answer this questions. Almost all of discretization in CFD comes down to using Taylor series expansion equations to convert your PDE/ODE into a linear equation. I have only solved inviscid compressible NS equations, so it's a little bit different from your use case. You would need a pressure-velocity coupling using SIMPLE, SIMPLER or such other algorithms. You would also need a staggered grid, but that might be easier for you as you're already modifying a lid-driven cavity code.
Harlotte likes this.
aerosayan is offline   Reply With Quote

Old   October 20, 2021, 10:31
Default
  #3
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Since I don't do research in IC engine, so my answers were somewhat speculative. If you truly need the best answer, I would highly recommend you to search for CFD papers for modelling IC engines and papers on writing CFD codes for modelling IC engines. Find a good paper, study how they do it, then based on that, you can implement your code.

All of your research problems have already been solved by someone else. Just follow their work as inspiration
Harlotte likes this.
aerosayan is offline   Reply With Quote

Old   October 20, 2021, 12:31
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by Harlotte View Post
Hello everyone,
I am currently working on my masters thesis which is about writing a code in Matlab to describe the simulation of a gas exchange in an hydrogen combustion engine.
I am at the beginning of my studies and I am using lid driven cavity as an example to write the code. But I found some questions:How do I describe the movement of the piston in the code written in matlab? And what are the main equations I have to use to describe the gas (NS equation, convection-diffusion equation)? When I use the NS equation to describe the flow of the gas, I find it difficult to describe the convective diffusion equation at the same time?
I would be very grateful if you could give me some advice

1) the lid driven cavity is a good test-case to develop and testing a simple CFD code but it is for incompressible flows. In your case you have compression and expansion, therefore you need to solve the compressible form of the equations.
2) The movement of a piston can be either prescribed or consequent to the flow dynamics, what is your case?
3) The modern trend of the CFD code is to use the immersed boundary method. Thins, You have the moving boundary on a fixed background grid. Several approaches can be adopted and you will find a lot of literature.

4) Whan do you mean for "I find it difficult to describe the convective diffusion equation at the same time"
aerosayan likes this.
FMDenaro is offline   Reply With Quote

Old   October 25, 2021, 03:02
Smile
  #5
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
Since I don't do research in IC engine, so my answers were somewhat speculative. If you truly need the best answer, I would highly recommend you to search for CFD papers for modelling IC engines and papers on writing CFD codes for modelling IC engines. Find a good paper, study how they do it, then based on that, you can implement your code.

All of your research problems have already been solved by someone else. Just follow their work as inspiration
Thank you very much for your advice, it has been very inspiring for me. I will read more CFD papers for modelling IC engines and papers on writing CFD codes for modelling IC engines. I hope this will be useful for me.
Harlotte is offline   Reply With Quote

Old   October 25, 2021, 03:11
Smile
  #6
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
1) the lid driven cavity is a good test-case to develop and testing a simple CFD code but it is for incompressible flows. In your case you have compression and expansion, therefore you need to solve the compressible form of the equations.
2) The movement of a piston can be either prescribed or consequent to the flow dynamics, what is your case?
3) The modern trend of the CFD code is to use the immersed boundary method. Thins, You have the moving boundary on a fixed background grid. Several approaches can be adopted and you will find a lot of literature.

4) Whan do you mean for "I find it difficult to describe the convective diffusion equation at the same time"
First of all thank you very much for the advice! Regarding the motion of the piston, my idea is to specify a fixed velocity that moves with time. When I was looking at the lid driven cavity example it used the NS equation but did not discretize the convective diffusion equation. I am still learning CFD, is the convective diffusion equation already included in the NS equation? So no discretization is needed?
Harlotte is offline   Reply With Quote

Old   October 25, 2021, 22:41
Default
  #7
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by Harlotte View Post
First of all thank you very much for the advice! Regarding the motion of the piston, my idea is to specify a fixed velocity that moves with time. When I was looking at the lid driven cavity example it used the NS equation but did not discretize the convective diffusion equation. I am still learning CFD, is the convective diffusion equation already included in the NS equation? So no discretization is needed?
The convection and diffusion, are physical transport phenomenons that happen. Fluid flow happens to be due to the combination of both. So, automatically NS equations contain the convection and diffusion terms. So, to solve the NS equations, you need to discretize them.

Did you write simple 1D, 2D solvers for convection and diffusion before?

I just had a recent discussion here on how much majority of the students have difficulty understanding CFD because they have never been taught to develop the simpler solvers.
aerosayan is offline   Reply With Quote

Old   October 26, 2021, 01:15
Smile
  #8
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
The convection and diffusion, are physical transport phenomenons that happen. Fluid flow happens to be due to the combination of both. So, automatically NS equations contain the convection and diffusion terms. So, to solve the NS equations, you need to discretize them.

Did you write simple 1D, 2D solvers for convection and diffusion before?

I just had a recent discussion here on how much majority of the students have difficulty understanding CFD because they have never been taught to develop the simpler solvers.
I have not written solvers for convective diffusion equations before.
Yes, understanding CFD is also difficult for me, I had not studied it before, but I need to complete the Master's thesis. Can you give me some advice for my situation?
I appreciate your help.
Harlotte is offline   Reply With Quote

Old   October 26, 2021, 08:07
Default
  #9
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by Harlotte View Post
I have not written solvers for convective diffusion equations before.
Yes, understanding CFD is also difficult for me, I had not studied it before, but I need to complete the Master's thesis. Can you give me some advice for my situation?
I appreciate your help.
How much time do you have left? Master's thesis generally take 2 years in India. I'm not sure how long it takes in other countries.

Honestly, if you have less than 1.5 years of time left, it might be better to use commerical codes like ANSYS or OpenFOAM or SU2 to do your research instead of developing a solver yourself.

I don't mean to be discouraging, and CFD is easy to learn once we know the basics, but learning the basics take some time. That can be done easily in 2 month, if you have a guided learning path.

But since your research topic is in combustion CFD, and you mean to write your own solver, it becomes much more challenging. Combustion CFD requires you to know the basics of CFD + advanced combustion models.

Learning advanced combustion models might take 7 or more months if your guiding professor is an expert in combustion CFD. If you plant to learn on your own, it would take a few years.

Only take this opportunity if your professor is also an expert in combustion CFD. Otherwise he/she won't be able to guide you or correct your mistakes.

however I don't mean to be discouraging. You could do your research that you want. However anyone would highly recommend you to use commerical CFD solvers like ANSYS/COMSOL etc. instead of writing your own code.
FMDenaro and Harlotte like this.
aerosayan is offline   Reply With Quote

Old   October 26, 2021, 08:22
Default
  #10
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by Harlotte View Post
I have not written solvers for convective diffusion equations before.
Yes, understanding CFD is also difficult for me, I had not studied it before, but I need to complete the Master's thesis. Can you give me some advice for my situation?
I appreciate your help.

Generally, a CFD student does practice first with simple exercises like those in the book of Ferziger, Peric and Street. Only after some months he can approach the methods for solving NSE.



That while assuming he has already a good background in fluid mechanics.

What is your present educational background?
aerosayan and Harlotte like this.
FMDenaro is offline   Reply With Quote

Old   October 26, 2021, 08:34
Default
  #11
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
Generally, a CFD student does practice first with simple exercises like those in the book of Ferziger, Peric and Street. Only after some months he can approach the methods for solving NSE.



That while assuming he has already a good background in fluid mechanics.

What is your present educational background?
In my opinion, Professor Lorena Barba's course 12 steps to NS equations is more approachable by students : https://lorenabarba.com/blog/cfd-pyt...navier-stokes/

However, @Harlotte would be best prepared to complete their combustion CFD solver in 2 years *only and only if* their guiding professor has also written combustion CFD solvers before.

I could be wrong, but that's the most probable outcome.
FMDenaro and Harlotte like this.
aerosayan is offline   Reply With Quote

Old   October 26, 2021, 08:46
Smile
  #12
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
How much time do you have left? Master's thesis generally take 2 years in India. I'm not sure how long it takes in other countries.

Honestly, if you have less than 1.5 years of time left, it might be better to use commerical codes like ANSYS or OpenFOAM or SU2 to do your research instead of developing a solver yourself.

I don't mean to be discouraging, and CFD is easy to learn once we know the basics, but learning the basics take some time. That can be done easily in 2 month, if you have a guided learning path.

But since your research topic is in combustion CFD, and you mean to write your own solver, it becomes much more challenging. Combustion CFD requires you to know the basics of CFD + advanced combustion models.

Learning advanced combustion models might take 7 or more months if your guiding professor is an expert in combustion CFD. If you plant to learn on your own, it would take a few years.

Only take this opportunity if your professor is also an expert in combustion CFD. Otherwise he/she won't be able to guide you or correct your mistakes.

however I don't mean to be discouraging. You could do your research that you want. However anyone would highly recommend you to use commerical CFD solvers like ANSYS/COMSOL etc. instead of writing your own code.
Thank you very much for the advice you have given me.
I am a current master in Germany and the Master's theses take 8 months in Germany. My supervisor asked me to write a simple solver in Matlab. This solver should at least include the intake and exhaust ports, but the Ignition can be ignored in this model(I think that the combustion can be ignored). In this way, is it possible to simplify this solver?
aerosayan likes this.
Harlotte is offline   Reply With Quote

Old   October 26, 2021, 09:00
Smile
  #13
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
In my opinion, Professor Lorena Barba's course 12 steps to NS equations is more approachable by students : https://lorenabarba.com/blog/cfd-pyt...navier-stokes/

However, @Harlotte would be best prepared to complete their combustion CFD solver in 2 years *only and only if* their guiding professor has also written combustion CFD solvers before.

I could be wrong, but that's the most probable outcome.
I've been watching Tanmay's videos to learn recently:https://www.youtube.com/watch?v=VwGF...7xbmJISRWA0xYS. Even though he talks about incompressible fluids, it's still inspiring to me. But if I want to complete my solver, I find it's not enough...
Harlotte is offline   Reply With Quote

Old   October 26, 2021, 09:06
Smile
  #14
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
Generally, a CFD student does practice first with simple exercises like those in the book of Ferziger, Peric and Street. Only after some months he can approach the methods for solving NSE.



That while assuming he has already a good background in fluid mechanics.

What is your present educational background?

I had no basic knowledge of CFD before that and I had also not tried to write some CFD code before. I just learn CFD by myself t in the last two months.
Harlotte is offline   Reply With Quote

Old   October 26, 2021, 12:50
Default
  #15
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by Harlotte View Post
Thank you very much for the advice you have given me.
I am a current master in Germany and the Master's theses take 8 months in Germany. My supervisor asked me to write a simple solver in Matlab. This solver should at least include the intake and exhaust ports, but the Ignition can be ignored in this model(I think that the combustion can be ignored). In this way, is it possible to simplify this solver?
If intake and exhaust is only to be modelled and the combustion isn't required, then it can be done.

Although you need more restrictions. Is it 2D or 3D? What is the geometry of the combustion chamber? Will this geometry changed and will you need to use your code for analysing multiple different geometries? Will the Piston move? How much accuracy in results do you require? Do you need to simulate the full cycle, or can you just simulate parts of the cycle, like gas expansion or compression? What's going to be entering into the camber? Is it only air, or air+fuel mixture?

Try to come up with the more restrictions, so the solver is simple. Clarify it with your professor, and ensure that's enough for the project.

Never complicate things.
Harlotte likes this.
aerosayan is offline   Reply With Quote

Old   October 26, 2021, 22:44
Smile
  #16
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
If intake and exhaust is only to be modelled and the combustion isn't required, then it can be done.

Although you need more restrictions. Is it 2D or 3D? What is the geometry of the combustion chamber? Will this geometry changed and will you need to use your code for analysing multiple different geometries? Will the Piston move? How much accuracy in results do you require? Do you need to simulate the full cycle, or can you just simulate parts of the cycle, like gas expansion or compression? What's going to be entering into the camber? Is it only air, or air+fuel mixture?

Try to come up with the more restrictions, so the solver is simple. Clarify it with your professor, and ensure that's enough for the project.

Never complicate things.
Thank you very much for your help! At the moment it is a 2D model that is needed. Cylindrical geometry is enough. I don't need to analyse multiple geometries. The piston will move, the piston will move down when the air enters and afterwards the compression of the gas will take place. I am simulating a mixture of air and hydrogen. I still need to check with my supervisor for accuracy and for the part of the simulation cycle.

Thanks again for the advice you gave me, it helps me a lot!
Harlotte is offline   Reply With Quote

Old   October 27, 2021, 13:46
Default
  #17
Senior Member
 
Sayan Bhattacharjee
Join Date: Mar 2020
Posts: 495
Rep Power: 8
aerosayan is on a distinguished road
Quote:
Originally Posted by Harlotte View Post
Thank you very much for your help! At the moment it is a 2D model that is needed. Cylindrical geometry is enough. I don't need to analyse multiple geometries. The piston will move, the piston will move down when the air enters and afterwards the compression of the gas will take place. I am simulating a mixture of air and hydrogen. I still need to check with my supervisor for accuracy and for the part of the simulation cycle.

Thanks again for the advice you gave me, it helps me a lot!
All right, based on the restrictions and requirements, this is possible. It's basically a NS solver without any extra fancy things. You can probably get away with using a structured grid, and if the piston is moving, set how much it will move at every timestep. If it moves 1 mm every timestep, then you can just make a structured grid with 0.5 mm (or less) cell width and height.


Look up old CFD papers on simulating piston engines. They are simpler to understand and replicate.
Harlotte likes this.
aerosayan is offline   Reply With Quote

Old   October 27, 2021, 21:38
Smile
  #18
New Member
 
Gao Shangya
Join Date: Oct 2021
Posts: 18
Rep Power: 4
Harlotte is on a distinguished road
Quote:
Originally Posted by aerosayan View Post
All right, based on the restrictions and requirements, this is possible. It's basically a NS solver without any extra fancy things. You can probably get away with using a structured grid, and if the piston is moving, set how much it will move at every timestep. If it moves 1 mm every timestep, then you can just make a structured grid with 0.5 mm (or less) cell width and height.


Look up old CFD papers on simulating piston engines. They are simpler to understand and replicate.
Ok, thank you very much for the suggestion! It inspires me a lot.
Harlotte is offline   Reply With Quote

Reply

Tags
engine cylinder head, matlab codes for cfd


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF piston movement problem Dozer_94 Fluent UDF and Scheme Programming 2 December 26, 2016 09:56
Simple piston movement in cylinder- fluid models arun1994 CFX 4 July 8, 2016 02:54
Movement of piston in a cylinder with fluent? Whitworth ANSYS 5 March 3, 2015 23:50
Simple piston movement simulation ReVl27 FLUENT 1 February 20, 2015 08:28
UDF for Piston movement Harish FLUENT 2 July 23, 2004 06:13


All times are GMT -4. The time now is 16:52.