CfdOf Translating / Moving object workflow

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

Post Reply
chrisv-nz
Posts: 3
Joined: Fri Oct 07, 2022 10:27 pm

CfdOf Translating / Moving object workflow

Post by chrisv-nz »

I've tried to set up Transient analysis using dynamic mesh interface refinement, using a very basic model (attached) but I must be doing something wrong. I've also tried to follow several tutorials on translating / rotating objects (propeller example) but cannot figure out how to make that work in my case.
Attachments
Moving object
Moving object
Translating Object.png (309.72 KiB) Viewed 1254 times
Moving object test.FCStd
Sample model
(27.18 KiB) Downloaded 36 times
Last edited by oliveroxtoby on Sun Oct 09, 2022 1:58 pm, edited 1 time in total.
Reason: Damage limitation after I edited this post in error, intending to reply.
User avatar
oliveroxtoby
Posts: 812
Joined: Fri Dec 23, 2016 9:43 am
Location: South Africa

Re: CfdOf Translating / Moving object workflow

Post by oliveroxtoby »

chrisv-nz wrote: Fri Oct 07, 2022 10:48 pm I've tried to set up Transient analysis using dynamic mesh interface refinement, using a very basic model (attached) but I must be doing something wrong. I've also tried to follow several tutorials on translating / rotating objects (propeller example) but cannot figure out how to make that work in my case.
@chrisv-nz my humble apologies, I accidentally edited (and truncated) your post above instead of replying to it...and I can't seem to find a way to undo the edit. Sorry about that!! My reply was meant to be:

Unfortunately there is no support for moving mesh in CfdOF at the moment. The dynamic mesh refinement is for adaptive refinement of the interface in multiphase cases.
mario52
Veteran
Posts: 4674
Joined: Wed May 16, 2012 2:13 pm

Re: CfdOf Translating / Moving object workflow

Post by mario52 »

Hi

welcome

try:

select the object to move and run the macro

Macro_D_Un_Jour_Move_Object_To_Distance_In_A_Defined_Time

Code: Select all

##Macro_D_Un_Jour_Move_Object_To_Distance_In_A_Defined_Time
##09/10/2022
##Mario52
##https://forum.freecadweb.org/viewtopic.php?f=37&t=72433

import FreeCAD, FreeCADGui
import time
App = FreeCAD
Gui = FreeCADGui

####Configuration Begin
timeTrajet          = 10.0     # secondes
lengthTrajet        = 30000.0  # mm
timeBetween_2_Step  = 0.0      # default=0.0 # secondes # precision depend : machine, memory, loop, code ...
                               # if timeBetween_2_Step is used the object is moved step by step
loopMultiply        = 124      # default=10 (or other) if timeBetween_2_Step is used
                               # if timeBetween_2_Step = 0 search the good number of loop progressif
direction           = 1        # 0 = "x" , 1 = "y" , other = "z"
####Configuration End

try:
    sel = Gui.Selection.getSelection()[0]    # select the object to move
    #FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
    
    stepBySecond = (lengthTrajet / timeTrajet)    # number of step by second
    
    ##### begin measure the time elapsed for a recompute "chrisb"
    timeFn = time.perf_counter # measure real time
    startTime = timeFn()
    #####
    
    if loopMultiply == 0: loopMultiply = 1.0
    try:
        for i in range(int(timeTrajet*loopMultiply)):    # multiply by 10 for 0.1 second
            if direction == 0:    # x
                sel.Placement.Base.x = sel.Placement.Base.x + (stepBySecond/loopMultiply)    # axis x
            elif direction == 1:  # y
                sel.Placement.Base.y = sel.Placement.Base.y + (stepBySecond/loopMultiply)    # axis y
            else:                 # z
                sel.Placement.Base.z = sel.Placement.Base.z + (stepBySecond/loopMultiply)    # axis z
            time.sleep(timeBetween_2_Step)
            Gui.updateGui()                                    # rafraichi lecran
            #print(i,"    ",sel.Placement.Base.y)
    except Exception:
        print("Not good configuration")
    
    ##### end measure the time elapsed for a recompute "chrisb"
    endTime = timeFn()
    elapsed = (endTime - startTime)
    #####
    
    print("________________")
    print('Real Time elapsed  : {:02d}:{:02d}:{:05.3f}'.format(int(elapsed) // 3600, (int(elapsed) % 3600 // 60), elapsed % 60))
    print("timeTrajet asked   : ", timeTrajet, " secondes")
    print("lengthTrajet       : ", lengthTrajet, " mm")
    print("timeBetween_2_Step : ", timeBetween_2_Step, " secondes")
    print("number of step     : ", int(timeTrajet*loopMultiply))
    print("distance by 2 step : ", stepBySecond/loopMultiply, " mm")
    print("axis               : ", direction, "(0 = x, 1 = y, other = z)")
    print("________________")
except Exception:
    print("Select one object")
with this configuration i obtain:

14:43:50 ________________
14:43:50 Real Time elapsed : 00:00:9.937
14:43:50 timeTrajet asked : 10.0 secondes
14:43:50 lengthTrajet : 30000.0 mm
14:43:50 timeBetween_2_Step : 0.0 secondes
14:43:50 number of step : 1240
14:43:50 distance by 2 step : 24.193548387096776 mm
14:43:50 axis : 1 (0 = x, 1 = y, other = z)
14:43:50 ________________

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply