fprotais / hexsmoothing

Hexahedral smoothing codes done during my Ph.D.
GNU General Public License v3.0
5 stars 2 forks source link

Use/guide/tutorial of hexsmoothing #1

Closed otaolafranc closed 10 months ago

otaolafranc commented 11 months ago

Hello, I would love to use this smoothing algorithms in my hexahedral meshes, would it be possible to provide some guidance on how to use them? thanks in advance

fprotais commented 11 months ago

Hi there, Just to be sure that this code is actually what you would want to use: what is your use case?

There are 3 classic cases:

The two last type are usually quite application dependent, and usually requires good tuning to get good performance with good meshes. May code may help, but with poor performance. I would consider that some research still required there too.

otaolafranc commented 11 months ago

Hello françois, I have created structured meshes using salome and geometries pre cutted in blocks manually in CAD to create the structured mesh that respects the boundary and edge features of the CAD model. that being said, as the blocks are created manually in CAD, there is no 'smoothing' or 'optimization' of them (at least for the moment). I would like to improve the mesh quality inside of the mesh without modifying the external quad mesh (as it respects the CAD already and would like to keep this)

fprotais commented 11 months ago

I can help with that!

In lib/standard_smoother.h, you can use the smooth_hex_mesh function. The arguments are:

If you are encounter bad/strange results, there might some tuning issues. Let me know.

Warning: the code does not behave well if you have anisotropic hexes, but small modification could help.

otaolafranc commented 11 months ago

thanks for your help! just to be clear the workflow would be:

git clone https://github.com/fprotais/hexsmoothing.git
cd hexsmoothing/lib
standard_smoother.h $PATHMesh/mesh $PATHMesh/locksFile 10 True

no? if so, I have other small questions (if I might). In salome I can export the mesh in different formats, .unv, .med and I can also import it into gmsh where I could export in .vtk, or .msh. ideally to lastly import it to OpenFOAM mesh file format (https://github.com/nschloe/meshio/issues/660) . is there any way to easily make the required format and the locksFile? in my case the locksFile would be all the boundary points set to true true true, and the rest to false false false? this will output a new file? or modify the existing one? also, how many number of iterations would you recommend from experience? lastly, is it possible to run it in parallel? to improve performance in big meshes

fprotais commented 11 months ago

My explanation was on the wrong level. Apologies! This code is C++ code that needs compiling, and more than that, it does not contain a standalone executable, it is supposed to be used by a C++ executable.

If you are not familiar with C++, it does make using it a bit more tricky, but nothing out of reach. I'll try to set up something that does what you want.

Just to look cool, I will respond with additional questions: Do you work on Linux or Windows? You'll have to compile the code, so it is important for me to guide you. What is a big mesh? To my experience, the code was surprisingly efficient. For less than millions elements, it is still usable. It could run in parallel, but it is mostly dependent on OS.

And finally an answer: number of iterations is quite dependent of your situation, Mesh almost there, only needs a last tweak: 50 iteration is plenty. Mesh is very bad, or needs large inner movement, then more iter (Quality is ok, but elements need to move a long to ideal position). Note that it is a global optimization, convergence will usually be significantly better than iterative smoother.

otaolafranc commented 11 months ago

I am not familiar with C++ nevertheless I have already compiled some C++ codes but when the steps where clear (and the dependencies where there...) I have also tried to compile others that I havent succed....

fprotais commented 11 months ago

New commit is in! I did not manage to fully test it, but it should do it. To compile, you should do the following:

git clone https://github.com/fprotais/hexsmoothing
cd hexsmoothing
mkdir build
cd build
cmake ..
make -j

You need recent enough CMake & compiler, but on your linux it should do. It should catch openMP as well (parrallel stuff) Now to run, this should do: OMP_NUM_THREADS=1 ./innerSmoother mesh.vtk output.vtk 50 You should start with 1 thread, and you can check later that more speed-up things. Note that for smaller mesh, that may not be the case. The 50 is the number of iter, you can play with that. Regarding file types, the two you can use are medit (.mesh files) and vtk. Both are supported by meshio. There might some funny business because of elements numbering. There are easy fix to those.

Let me know if you run into any issue, or if it works, I love smoothed mesh images :)

otaolafranc commented 11 months ago

Hello francois, thanks for the reactivity! I will have a look and if any issues will come back here to make a post. I will test with some dummy meshes to ensure the workflow and then test with more specific ones. merci beaucoup ^^

otaolafranc commented 11 months ago

New commit is in! I did not manage to fully test it, but it should do it. To compile, you should do the following:

git clone https://github.com/fprotais/hexsmoothing
cd hexsmoothing
mkdir build
cd build
cmake ..
make -j

You need recent enough CMake & compiler, but on your linux it should do. It should catch openMP as well (parrallel stuff) Now to run, this should do: OMP_NUM_THREADS=1 ./innerSmoother mesh.vtk output.vtk 50 You should start with 1 thread, and you can check later that more speed-up things. Note that for smaller mesh, that may not be the case. The 50 is the number of iter, you can play with that. Regarding file types, the two you can use are medit (.mesh files) and vtk. Both are supported by meshio. There might some funny business because of elements numbering. There are easy fix to those.

Let me know if you run into any issue, or if it works, I love smoothed mesh images :)

hello again, I am having an error while doing the compilation see the log attached file: log.txt

edit: i re did the cmake .. and make -j and looks like this time worked (y) I can confirm that it works like charm! I am still having an issue, with the converter of gmsh of vtk I am loosing the information of the surfaces groups (patches/physical groups/2D groups) (https://gitlab.onelab.info/gmsh/gmsh/-/issues/2540) I will give a try tomorrow to go thought meshio instead of gmsh
by any chance do you think that it would be possible to add support to the polyMesh format in the future? one of my main issues that I will have in the future (as a bottle neck) will be the number of exporting/importing/re exporting/importing of the meshes as this a lot of times takes more time than the meshing itself. specially that even if meshio exports in a newer version of vtk that supports the grouping feature, I am not 100% sure that OpenFOAM will correctly import it. EDIT2: also the parallel setting does not look like it is working image

and lastly, I tried with an already good quality mesh and the smoother stoped at first iteration:

OMP_NUM_THREADS=8 ./innerSmoother ../../../Desktop/test.vtk output.vtk 500
Nb verts: 155200
Nb hexes: 143748
Nb iter planned: 500
Now smoothing:
==== Running Elliptic smoother 3d. ====
total vol = 191635
iteration #0
E: 2.00279 eps: 0.001 detmin: 6.48889e-09 ninv: 0
Line search failed
 E : 2.00279  --->  2.00275
iteration #1
E: 2.00275 eps: 0.001 detmin: 3.18108e-09 ninv: 0
Line search failed
 E : 2.00275  --->  2.00275
E: 2.00275 detmin: 3.18108e-09 ninv: 0
Done
Done.

[Uploading test.vtk.tar.gz…]()

fprotais commented 11 months ago

Nice to hear that you fixed it! Regarding parallel, it is a bit of black magic how it works, and I am not sure if they are real gains. If it is really slow, we can discuss that. I think the best solution would be to partition the mesh and smooth each independently.

Regarding PolyMesh format, I am not currently developing this code, only loosely maintaining it, so no plan to add it. It is something you could discuss with the guys from LIHPC-Computational-Geometry. The same way, you could code your own parser in my code, I don't know how hard PolyMesh is to read. Note that even if meshio supports keeping patch data, my code don't when rewriting the model, meaning you probably have to code something there :)

Your last example is a bit worrying, "Line search failed" is never a good sign. Could you share the model? You uploading seems to not have worked.

otaolafranc commented 11 months ago

I think the best solution would be to partition the mesh and smooth each independently. Regarding PolyMesh format, I am not currently developing this code, only loosely maintaining it, so no plan to add it. It is something you could discuss with the guys from LIHPC-Computational-Geometry. The same way, you could code your own parser in my code, I don't know how hard PolyMesh is to read. Note that even if meshio supports keeping patch data, my code don't when rewriting the model, meaning you probably have to code something there :)

I think the key here would be add polyMesh format as the mesh is already divided in different processors. sadly I am not so sure how I could implement it myself....

Your last example is a bit worrying, "Line search failed" is never a good sign. Could you share the model? You uploading seems to not have worked.

here you have the file, my bad, i hit comment before it finished of uploading it. test.vtk.tar.gz

fprotais commented 10 months ago

I don't know how you are using your files. But it will require low level manipulation. The commit that I added for you to access the code was pretty straight forward: read the mesh, transfer the mesh in my data structure, and then call my code. See bin/innerSmoothing.cpp You will have to do something similar.

here you have the file, my bad, i hit comment before it finished of uploading it.

Thanks, if I find time, I'll try to look at why it is stopping.

otaolafranc commented 10 months ago

Thanks, if I find time, I'll try to look at why it is stopping.

thanks, the other meshes I tried after, was giving me the same error :/

otaolafranc commented 10 months ago

Hello @fprotais me again, so I find the issue I was having with my meshes, it was an scaling issue, the meshes were really small..... once I scaled them up the error of "Line search failed" disappeared. saddly the quality didnt improved a lot...between the input and output mesh, even after 5000 iterations nevertheless it is doing only 2? or the 2 are the outer iterations and the inner are the 5000?

Nb verts: 32172 Nb hexes: 29560 Nb iter planned: 5000 Now smoothing: ==== Running Elliptic smoother 3d. ==== total vol = 39396 iteration #0 E: 3.94235 eps: 0.001 detmin: 3.50757 ninv: 0 reached maxiter E : 3.94235 ---> 3.59573 iteration #1 E: 3.59573 eps: 0.001 detmin: 1.49393 ninv: 0 reached maxiter E : 3.59573 ---> 3.59572 iteration #2 E: 3.59572 eps: 0.001 detmin: 1.49439 ninv: 0 (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= 1e-14 E : 3.59572 ---> 3.59572 E: 3.59572 detmin: 1.49441 ninv: 0 Done Done.

I am missing something or is it normal? (in any case I post the mesh intput and output) mesh.tar.gz

fprotais commented 10 months ago

Nice to hear you found a solution! It seems that it has converged:

(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= 1e-14

And looking at the results, it looks to have done its job! Remember that we are locking boundaries, so all changes will happen inside the model, slicing is required to see them. As per my first comment, smoothing the boundary will greatly increase the complexity of algorithm required.

otaolafranc commented 10 months ago

Hello again, thanks for all your help, I knew that it is only internal, and I was looking at that with a slice, but I just realized that there was a block that was not exported in the original mesh, making a 'hole' inside of the mesh which fixed almost everything....now that this was solved the difference is by a lot better. still the external faces fixed complexifies the global quality ( as from the other side it will still look as in the left side from the photo with the internal cut) but still, it is a great tool :D, again thanks a lot for sharing it and also for helping the setup thanks a lot!

image

otaolafranc commented 10 months ago

Thanks for your help again @fprotais ! small question, is there anyway to use it to smooth the surface by giving surfaces where to move or lines/edges (obviously discritized?) as the boundary cells are still quite bad :/

fprotais commented 10 months ago

What I available here probably won't give great result for your needs. Short answer: smoothing both surface and volume is pain, I never managed to have a robust code doing that.

Long answer: Using my smoother both on surface and volume is a pain, and I did not manage something robust that was giving good results every time on CAD geometries. Because you have well define CAD surface, you could first smooth boundaries in parametric space, and then the volume, but sometimes volumetric information is important to get good results. Note that CAD-type geometries are tricky: matching between hexes and CAD must be very well defined, otherwise you fall in annoying local minima, and get bad meshes.

Sadly, I am not aware of easy to use open-source software that provide good solution to that.

otaolafranc commented 10 months ago

Thanks for your time, the thing is that my meshes are created using salome, where they are attached to a CAD object, what I mean is that it works like in gmsh, where you have a CAD model (step) which you discretize the edges of the cad with nodes/edges, and then the surfaces by nodes/edges/faces and then from that it creates the volume cells. So what I would like to do is 'move nodes' over edges or surfaces of the CAD....insight on this?

fprotais commented 10 months ago

I could recommend algorithm that I would see fit, but no existing software. I know that guys from LIHPC-Computational-Geometry have similar problems, and have their own hexmeshing through blocks software. They have smoothing tools tailored for that, but I don't know how to use them.