CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   How to describe the movement of a piston? (https://www.cfd-online.com/Forums/main/239096-how-describe-movement-piston.html)

Harlotte October 20, 2021 09:25

How to describe the movement of a piston?
 
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 :)

aerosayan October 20, 2021 10:21

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.

aerosayan October 20, 2021 10:31

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 :)

FMDenaro October 20, 2021 12:31

Quote:

Originally Posted by Harlotte (Post 814669)
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"

Harlotte October 25, 2021 03:02

Quote:

Originally Posted by aerosayan (Post 814677)
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 October 25, 2021 03:11

Quote:

Originally Posted by FMDenaro (Post 814686)
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?

aerosayan October 25, 2021 22:41

Quote:

Originally Posted by Harlotte (Post 814984)
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.

Harlotte October 26, 2021 01:15

Quote:

Originally Posted by aerosayan (Post 815072)
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.

aerosayan October 26, 2021 08:07

Quote:

Originally Posted by Harlotte (Post 815077)
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 October 26, 2021 08:22

Quote:

Originally Posted by Harlotte (Post 815077)
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 October 26, 2021 08:34

Quote:

Originally Posted by FMDenaro (Post 815119)
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.

Harlotte October 26, 2021 08:46

Quote:

Originally Posted by aerosayan (Post 815116)
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?

Harlotte October 26, 2021 09:00

Quote:

Originally Posted by aerosayan (Post 815123)
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 October 26, 2021 09:06

Quote:

Originally Posted by FMDenaro (Post 815119)
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.

aerosayan October 26, 2021 12:50

Quote:

Originally Posted by Harlotte (Post 815126)
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 October 26, 2021 22:44

Quote:

Originally Posted by aerosayan (Post 815155)
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!

aerosayan October 27, 2021 13:46

Quote:

Originally Posted by Harlotte (Post 815176)
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 October 27, 2021 21:38

Quote:

Originally Posted by aerosayan (Post 815229)
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.


All times are GMT -4. The time now is 15:47.