CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Getting coarse mesh from a finer initial mesh (https://www.cfd-online.com/Forums/openfoam-programming-development/159489-getting-coarse-mesh-finer-initial-mesh.html)

chriss85 September 16, 2015 11:16

Getting coarse mesh from a finer initial mesh
 
I have some calculations which are very expensive, so I would like to run them on a coarser mesh with reduced accuracy compared to the rest of the solver. I've looked around in the source code and the forums but I couldn't find any proper method to generate a coarse mesh yet. Does anyone know of such a function in OpenFOAM or a usable strategy one could use to implement something like this?

There are some overlaps in the GAMG code however GAMG only creates the lduMesh and not the fvMesh objects it seems. Since fvMesh inherits from lduMesh, I'm not sure if we can construct an fvMesh from it.

Dynamic meshes have support for refining but not coarsening, so they aren't a real option either (because control over the main mesh is desired; creating it as a refinement causes problems with cell count and small features).

Another thing is the faceAgglomerate tool used in view factor radiation modelling to agglomerate faces on the boundaries. This would possibly be helpful to me already, but I would prefer coarsening the whole mesh for a presumably better accuracy/performance rating.

I find it quite surprising that such a relatively common task hasn't been covered before. Am I missing anything?

chriss85 September 17, 2015 12:38

I have settled with using the pairPatchAgglomeration class to generate a coarser boundary mesh. I would've preferred a coarser mesh instead of only a coarse boundary because I would expect better accuracy at the same computation time but this is likely good enough for me right now. pairPatchAgglomeration can be a bit difficult to make it work properly if you want to coarsen by a larger factor but using a higher number of mergeLevels helped me. Before I had wrong values when interpolating back to the fine mesh. I didn't explicitly check the values on the coarse mesh though.

A_Pete April 1, 2016 08:28

Hey chriss85,

did you manage to generate a whole coarse fvMesh from your original fine mesh?

I am looking for ways to do the same thing. I want to use a coarser mesh for just a few operations inside of the code, which originates from the mesh I use for my simulation.

chriss85 April 1, 2016 09:57

I have settled with another method. In my case I needed to calculate an integral over the volume. What I did was to use a Monte-Carlo based integration scheme, picking random cells for the integral and weighting them appropriately.

A_Pete April 1, 2016 11:03

Ah ok. Thanks anyways for answering this quickly.

I have to evaluate if a lagrangian particle does hit a wall, but can not loop over the original cells, since the particles may hit a wall but be located way outside of it.

I will now try to replace the cells with bigger geometrical objects near the walls, which are checked whether particles are inside them and hitting the walls.

In your case, maybe you can use cellZones as well to integrate over a certain volume? This could be costly though.

chriss85 April 4, 2016 04:51

cellZones won't really help since I need the complete volume. I can get rid of some cells based on a threshold criterium though. For your case, how about using an octree structure? This might be very helpful. I think there may be some function to find the cell in which a point lies though.

A_Pete April 4, 2016 08:15

Thank you. Yes, we thought about an octree structure as well. But we still need to reduce the mesh to a coarser one near the considered surface.

shang May 4, 2017 13:25

pairPatchAgglomeration for coarser mesh
 
Quote:

Originally Posted by chriss85 (Post 564459)
I have settled with using the pairPatchAgglomeration class to generate a coarser boundary mesh. I would've preferred a coarser mesh instead of only a coarse boundary because I would expect better accuracy at the same computation time but this is likely good enough for me right now. pairPatchAgglomeration can be a bit difficult to make it work properly if you want to coarsen by a larger factor but using a higher number of mergeLevels helped me. Before I had wrong values when interpolating back to the fine mesh. I didn't explicitly check the values on the coarse mesh though.

Hi Chriss85,

Would you mind sharing how did you use pairPatchAgglomeration class to generate a coarser boundary mesh. I want to do the same but can't figure out how. Many thanks.

Kind regards,
Yeru

chriss85 May 5, 2017 05:15

I don't actually use it now because it didn't give me the results I wanted but I can paste a few lines of code.

Code:

//In Header:
#include "pairPatchAgglomeration.H"
#include "PatchToPatchInterpolation.H"
autoPtr<pairPatchAgglomeration> AgglomeratedPatch_;
autoPtr<PatchToPatchInterpolation<bPatch, polyPatch> > P2PIPtr_;

//In constructor
AgglomeratedPatch_.set(new pairPatchAgglomeration(patch().patch(), dict, false));
AgglomeratedPatch_().agglomerate();
if(patch().size() > 0)
    Pout << "Agglomerated patch " << patch().name() << " from " << patch().size() << " to " << AgglomeratedPatch_().patchLevel(AgglomeratedPatch_().size() - 1).size() << " faces." << endl;

P2PIPtr_.reset
(
    new PatchToPatchInterpolation<bPatch,polyPatch>
    (
        AgglomeratedPatch_().patchLevel(AgglomeratedPatch_().size() - 1),
        patch().patch(),
        intersection::FULL_RAY,
        intersection::VECTOR
    )
);

//Get coarse fields and face centres
surfaceField = vectorField(AgglomeratedPatch_().patchLevel(AgglomeratedPatch_().size() - 1).size());
faceCentres = vectorField(AgglomeratedPatch_().patchLevel(AgglomeratedPatch_().size() - 1).faceCentres());
Info << "Agglomerating surface with " << AgglomeratedPatch_().patchLevel(AgglomeratedPatch_().size() - 1).size() << " / " << patch().size() << "faces" << endl;

//Interpolate back on fine mesh
fvPatchVectorField::operator=(P2PIPtr_().faceInterpolate<vector>(surfaceField)());
AgglomeratedPatch_().prolongField(*this, coarse, 0);

Keep in mind that this is not used in my code anymore so it may not be completely correct.

shang May 8, 2017 15:07

Thanks Chris, I will try that out. Regards, Yeru


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