damogranlabs / classy_blocks

Python classes for easier creation of OpenFOAM's blockMesh dictionaries.
MIT License
123 stars 37 forks source link

enhancement: structured block array #42

Open bjnieuwboer opened 11 months ago

bjnieuwboer commented 11 months ago

Hi,

I have an idea for an additional functionality in classy blocks: a multiHex object. This is a structured 3d array of blocks. I’ve attached a proof of concept in python. This is not yet linked to classy blocks. It creates the points and blocks and shows how one can interact with these.

The advantage of creating a separate class over having multiple lofts is the ease of selecting and editing the location of the vertices. In this class one can select vertices and blocks based on their location in the blocking structure; i.e. (1,2,3) means the second vertex in x direction, the third vertex in y direction and the fourth vertex in z direction. When selecting this vertex it can be translated or rotated afterwards. Since the hexblocks have an index to the vertices in the multiHex class, all the hexBlocks are updated automatically when the vertex is moved. For a Cartesian mesh this procedure is far easier than the current method in classy blocks of selecting vertices in the mesh by looking at their location within a sphere or box.

The idea is based on blockmeshbuilder: https://github.com/NauticalMile64/blockmeshbuilder/blob/master/blockmeshbuilder/blockstructures/cartesian.py . However, I’ve built the code from scratch and added more features. In the attached file, you can see what the code is currently capable of and what I still would like to add.

My question is: would this be interesting for you to add? If so, I could integrate this code to classy blocks. However, I suppose it would need some final editing by you since you know all the ins and outs of the class blocks framework. What would be your idea to integrate this code to classy blocks. Should this code create multiple loft operations which can be added to the mesh, or should this code be directly added to the mesh class? multiHex.zip

FranzBangar commented 11 months ago

This multi-block idea falls under you other proposal of universal sketches that users will define. Editing is done afterwards (see examples) but finding which vertex by their location in blocking structure is a yet-to-be-done "Finder" object. Will definitely consider. Do you have an example geometry (possibly something real-life-ish, a bit more serious than the attached multiHex) that I can use as a reference and example?

bjnieuwboer commented 11 months ago

You are right, that another way of creating such a multi hex block is via an user defined sketch. For an end user, this would still be more work than defining the block with its x,y,z vertex coordinates. I don’t know what your plans are for the Finder object. I think the ease of finding an index would still be more work than via the proposed indexing method. This method gives the user a different way of designing a mesh. Namely by starting with all the blocks and deleting/editing these.

Some real life examples are • Flow over an inclined plate (modeling using Finite Area or VOF) • Flow in an enlarged duct • Flow in a diffusor • Modeling flow around a body: ◦ Sphere/cylinder ◦ Multiple spheres/cylinders • Flow around buildings • Heat sink

Let me know if you are interested in implementing this and if you would like my help in any way.

FranzBangar commented 11 months ago

If I understand you correctly, you'd like something like this:

array = cb.CartesianArray(point_1, point_2, count_x=3, count_y=3, count_z=3)
array.lofts[1][1][1].points[0].translate(0, 0, 0.1)
array.delete(1, 1, 0)

Apart from "cartesian addressing" and block deletion, is there anything else this array should be capable of?

MHS0027 commented 2 months ago

There is a vertex finder in hexmesh - would you like me to break this code out into stand alone pay file

FranzBangar commented 2 months ago

What do you mean, something like that? https://github.com/damogranlabs/classy_blocks/blob/master/src/classy_blocks/modify/find/geometric.py

MHS0027 commented 2 months ago

This does the find_in_sphere using scipy.spacial kdtree (I used this for duplicate vertex finding in hexmesh) you need to add the positions property to the vertexlist class (copy paste and remove comments)

The find_in_box and find_in_box_center - i have just thrown them together and not tested It uses the sphere find to get list of vertices then checks if each of these are in a box as shown in https://math.stackexchange.com/questions/1472049/check-if-a-point-is-inside-a-rectangular-shaped-area-3d

There may be a better way to do this but i could not find it quickly ( There is a request for this functionality on scipy on github (rectangle-range-query for scipy.spatial.KDTree #7822) but this is from 2017 so I'm not convinced its going to make it into scipy anytime soon)

I apologize for not writing a test for this (my working classy blocks is now buried in a finite element solver and not easy to do one offs - but this was welcome distraction) I am sure you will change this quite a bit before release

and yes if i could remember how to use github i would have created a pull request - but i don't and its too much effort to relearn for 1 file

Regards Malcolm

On Fri, 12 Jul 2024 at 07:08, Nejc Jurkovič @.***> wrote:

What do you mean, something like that? https://github.com/damogranlabs/classy_blocks/blob/master/src/classy_blocks/modify/find/geometric.py

— Reply to this email directly, view it on GitHub https://github.com/damogranlabs/classy_blocks/issues/42#issuecomment-2224821937, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKSK2IXQDUGE6MRZEIAPXTZL5XFNAVCNFSM6AAAAABKXTGEOCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRUHAZDCOJTG4 . You are receiving this because you commented.Message ID: @.***>

FranzBangar commented 2 months ago

...ahem, where is the code?

MHS0027 commented 2 months ago

Sorry

On Mon, 15 Jul 2024 at 08:39, Nejc Jurkovič @.***> wrote:

...ahem, where is the code?

— Reply to this email directly, view it on GitHub https://github.com/damogranlabs/classy_blocks/issues/42#issuecomment-2227873976, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKSK2JSACIGYEX5WZARUXLZMN4EHAVCNFSM6AAAAABKXTGEOCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXHA3TGOJXGY . You are receiving this because you commented.Message ID: @.***>