CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Selecting & Colouring Edges using Scheme (https://www.cfd-online.com/Forums/fluent/204452-selecting-colouring-edges-using-scheme.html)

pcristini July 24, 2018 04:10

Selecting & Colouring Edges using Scheme
 
EDIT: Apologies, I selected the wrong forum when posting, can this be moved please?

I'm trying to automate some of the visualization checks we perform before running a simulation. This includes colour-coding some edges and zones. However I'm having some issues finding/figuring out the functions to call. I'm new to scheme and fluent, so please understand I may be looking at the wrong areas.

First Issue: setting edge colour. The only way I've found to set specific edge colours was to record the journal of the clicks to manually set it. However, this results in sometimes the colour not applying to the edge. Adding a (cx-pause) guarantees that it's applied, however this has an obvious fault. I would have figured the /display/update-scene/display function would be able to set edge colour, as this seems to be the function that emulates the form used to set colours, but it doesn't.

Code:

(define (set_edge_color name_filter edge_r edge_g edge_b edge_t is_edge)
    (let ()       
        (if (not (and (equal? is_edge 1) is_edge))
            (set! is_edge 0)
            (set! is_edge 1))

        (ti-menu-load-string (format #f "/display/surface-mesh '(~a)" name_filter))
        (ti-menu-load-string "/display/views/auto-scale")

        (cx-gui-do cx-activate-item "Ribbon*Frame1*Frame7(Viewing)*Table1*Table3(Graphics)*PushButton4(Compose)")
        (cx-gui-do cx-activate-item "Scene Description*Frame1*List1(Names)")
        (cx-gui-do cx-activate-item "Scene Description*PushButton2(fl_SelectAll)")
        (cx-gui-do cx-activate-item "Scene Description*Frame5(Geometry Attributes)*ButtonBox2*PushButton1(Display)")
        (cx-gui-do cx-set-list-selections "Display Properties*Frame3(Colors)*DropDownList1(Color)" '( 1))
        (cx-gui-do cx-activate-item "Display Properties*Frame3(Colors)*DropDownList1(Color)")

        (display (format #f "Setting red to: ~a\n" edge_r))
        (cx-gui-do cx-set-scale "Display Properties*Frame3(Colors)*Scale2(Red)" edge_r)

        (display (format #f "Setting green to: ~a\n" edge_g))
        (cx-gui-do cx-set-scale "Display Properties*Frame3(Colors)*Scale3(Green)" edge_g)

        (display (format #f "Setting blue to: ~a\n" edge_b))
        (cx-gui-do cx-set-scale "Display Properties*Frame3(Colors)*Scale4(Blue)" edge_b)
       
        (if (not (equal? is_edge 1))
            (cx-gui-do cx-set-scale "Display Properties*Frame3(Colors)*Scale5(Transparency)" edge_t)
        )

        ;STUPID HACK TO GET COLOR TO APPLY
        (if color_pause (cx-pause))
        (cx-gui-do cx-activate-item "Display Properties*PanelButtons*PushButton1(OK)")
        (cx-gui-do cx-activate-item "Display Properties*PanelButtons*PushButton2(Cancel)")

        (cx-gui-do cx-activate-item "Scene Description*PanelButtons*PushButton1(OK)")
        (cx-gui-do cx-activate-item "Scene Description*PanelButtons*PushButton2(Cancel)")
    ))

Second Issue: I have coloured faces based on zone names, and now I want to display all of them. The only method I've found of displaying faces is by calling:
Code:

;display new zone
(display (format #f "Displaying ~a~%" elem))
(ti-menu-load-string (format #f "/display/surface-mesh '(~a)~%" elem ))

;select it                       
(display (format #f "Selecting ~a~%" elem))
(ti-menu-load-string (format #f "/display/update-scene/select-geometry ~a ~a ~a~%"
  "yes"
  elem
  "no"))

;color it
(ti-menu-load-string (format #f "/display/update-scene/display ~a ~a ~a ~a ~a ~a ~a ~a ~a ~a ~a ~a ~a~%"
  "yes"
  "no"
  "yes"
  "no"
  "no"
  "no"
  "no"
  "no"
  "no"
  (list-ref zone_colors 0)
  (list-ref zone_colors 1)
  (list-ref zone_colors 2)
  (list-ref zone_colors 3)
 ))

But this only displays one face at a time. I'm not sure of the format to pass into /display/update-scene/select-geometry to select multiple elements, and /display/surface-mesh (which can accept a list of wildcarded elements, eg. alu_* if my aluminum components are named alu_compressor, etc) will display the edges of the zones, and therefore the actual mesh, not a solid coloured face.

Any input/suggestions would be greatly appreciated!

pcristini July 26, 2018 03:18

In the spirit of not abandoning a thread. I've figured out the solution to one of the issues. After inspecting several functions related to surfaces I finally found the following:

Code:

(cx-store-surface-desc-attr (cx-get-surface surface_id) edge-color|face-color (1 0 0 0))
*italicized values are variables passed in.
The colors are percentages of 255 and in order r g b trans

This can set edge or face color easily enough. Now to figure out how to display faces properly...

AlexanderZ July 26, 2018 03:36

what is ~% in your code? What is functionality of this expression?
Code:

(display (format #f "Displaying ~a~%" elem))
looks like here elem is a list of faces, that you want to choose.
May be you should make a loop to go though the whole list and execute calling function each time?

best regards

pcristini July 26, 2018 04:08

~% just causes a new line to be appended to the displayed string.


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