def initiate(RTMF, lPath_auto): #Open the initial file saved before flow rate assignment. var1 = VCmd.Activate(1, r"VHostManagerPlugin.VhmInterface", r"VhmCommand") var2 = VCmd.Activate(1, r"VSessionManager.Command", r"SessionCommand") var3 = VCmd.Activate(1, r"VToolKit.VSectionCutInterface", r"VEAction") ret = VE.ChangeContext(r"Visual-RTM") VE.SetActiveWindow(r"p1w1") ret = VExpMngr.LoadFile( lPath_auto + "\\pamrtm\\mainSimFiles\\" + RTMF + "_flowUnassigned.vdb", 0) VE.SetCurrentPage(1) ret = VE.ModelChange("M @0") return (var1)
def simPar(resin, lPath_auto): #Specify the RTM parameters. VE.SetActiveWindow(r"p1w1") ret = VE.ChangeContext(r"Visual-RTM") var116 = VCmd.Activate(1, r"VRTMUtilities.VRTMInterface", r"SimulationParameters") VCmd.SetStringValue(var116, r"Physics", r"Heated Filling") VCmd.SetDoubleValue(var116, r"InitialDegreeOfCure", 0.035) VCmd.SetStringValue(var116, r"MaterialDB", r"User") VCmd.SetStringValue(var116, r"InjectedResin", resin) VCmd.SetIntValue(var116, r"DetectAirTraps", 1) VCmd.Accept(var116) VCmd.Quit(var116) with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("simulation parameters selected\n")
def getInit(RTMfile): #This is typically run before all the other functions in here to initiate #communication with the model. var1=VCmd.Activate( 1, r"VHostManagerPlugin.VhmInterface", r"VhmCommand" ) var2=VCmd.Activate( 1, r"VSessionManager.Command", r"SessionCommand" ) var3=VCmd.Activate( 1, r"VToolKit.VSectionCutInterface", r"VEAction" ) ret=VE.ChangeContext( r"Visual-RTM" ) VE.SetActiveWindow( r"p1w1" ) ret=VExpMngr.LoadFile( r"D:\\IDPcode\\pamrtm\\mainSimFiles\\"+RTMfile+".vdb", 0 ) VE.SetCurrentPage( 1 ) ret=VE.ModelChange( "M @0" ) VScn.ExecutePythonInterpeter( r"C:\Program Files\ESI Group\Visual-Environment\15.0\COMMON\Resources\VisualProcessExec\user_scripts\CompositeLoadResult.py" ) import Viewer Viewer.SetTHPdisplayOnOff( 0 ) VE.Command( r">>> fpmmarkersize(3)" ) Viewer.SetLogConstantInfo( 0.000000000100000000000000003643 , 1 )
def initiate(filename, lPath_auto): #Basic settings and opening mesh-file. #__________________ VhmCommand BEGIN __________________ var1 = VCmd.Activate(1, r"VHostManagerPlugin.VhmInterface", r"VhmCommand") #__________________ SessionCommand BEGIN __________________ var2 = VCmd.Activate(1, r"VSessionManager.Command", r"SessionCommand") #__________________ VEAction BEGIN __________________ var3 = VCmd.Activate(1, r"VToolKit.VSectionCutInterface", r"VEAction") ret = VE.ChangeContext(r"Visual-RTM") #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬remove evenetually VE.SetActiveWindow(r"p1w1") ret = VE.ChangeContext(r"Visual-Mesh") ret = VE.ChangeSkin(r"General") #__________________ ModelingTolerance BEGIN __________________ var4 = VCmd.Activate(0, r"VMeshModeler.VmmICommandGui", r"ModelingTolerance") VCmd.SetIntValue(var4, r"ScaleModelToMMSystem", 0) VCmd.SetIntValue(var4, r"KeepFailedCADEntities", 1) VCmd.SetIntValue(var4, r"CheckUnitFlagAndNameToScaleModel", 0) VCmd.SetIntValue(var4, r"KeepBlankCADEntities", 1) VCmd.SetIntValue(var4, r"CleanSelfIntersectingSurfaces", 1) VCmd.SetIntValue(var4, r"StitchSurfaces", 1) VCmd.SetIntValue(var4, r"SurfaceStitchToleranceOption", 1) VCmd.SetIntValue(var4, r"CreatePartsByColor", 0) VCmd.SetIntValue(var4, r"ReadSubFigAsPartsOrAsm", 4) VCmd.SetIntValue(var4, r"RemovePointsAndCurves", 0) VCmd.SetIntValue(var4, r"CadAccuracyLevel", 0) VCmd.SetIntValue(var4, r"MergeLoopCurves", 1) VCmd.Accept(var4) VCmd.Quit(var4) #__________________ ModelingTolerance END __________________ #__________________ ModelingTolerance BEGIN __________________ var5 = VCmd.Activate(0, r"VMeshModeler.VmmICommandGui", r"ModelingTolerance") VCmd.Quit(var5) #__________________ ModelingTolerance END __________________ ret = VExpMngr.LoadFile( lPath_auto + "\\catiafiles\\meshfiles\\" + filename, 4) VE.SetCurrentPage(1) with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("initiated\n") return (var1)
def automesh(meshsize, RTMfile, RTMF, lPath_auto): #Automatically generates mesh for the simulation. ret = VE.ChangeContext(r"Visual-Mesh") ret = VE.ChangeSkin(r"General") VE.SetActiveWindow(r"p1w1") #__________________ TopologyMesh BEGIN __________________ var6 = VCmd.Activate(1, r"VMeshModeler.VmmICommandGui", r"TopologyMesh") #var7=VCmdGui.Create( r"VModelValidate.VCommandEleGeom" ) VCmd.SetObjectValue(var6, r"CurrentModel", "M @0") VCmd.SetDoubleValue(var6, r"ElementSize", meshsize) #VCmd.SetObjectValue( var6, r"SplitEdge1", NULL ) ret = VCmd.ExecuteCommand(var6, r"SetElementSizeToAllEdges") VCmd.SetIntValue(var6, r"MeshType", 2) VCmd.SetObjectValue(var6, r"SplitEdge1", NULL) ret = VCmd.ExecuteCommand(var6, r"MeshAllFaces") VCmd.Cancel(var6) VistaDb.ModelSetExportKeyWordOrder("M @0", 0) VistaDb.ModelSetExportStateAsNoInclude("M @0", 1) VExpMngr.ExportFile( lPath_auto + "\\pamrtm\\mainSimFiles\\" + RTMF + ".inp", 34) with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("meshed\n")
#automatically adjusted path lPath_auto = r'D:\sysi' with open(lPath_auto + "\\pamrtm\\mainsimfiles\\currentProgress.txt", "a") as text_file: text_file.write("The initial simulation starts here:") #input file - instead function arguments - which are not possible due to the command line passing fl = open(lPath_auto + "\\temporary\\RTM_in.txt", "rt") flstr = fl.read() RTMfile = flstr.split("---")[1] #__________________ SessionCommand BEGIN __________________ var2 = VCmd.Activate(1, r"VSessionManager.Command", r"SessionCommand") #__________________ VEAction BEGIN __________________ var3 = VCmd.Activate(1, r"VToolKit.VSectionCutInterface", r"VEAction") ret = VE.ChangeContext(r"Visual-RTM") VE.SetActiveWindow(r"p1w1") ret = VExpMngr.LoadFile( lPath_auto + "\\pamrtm\\mainsimfiles\\" + RTMfile + ".vdb", 0) VE.SetCurrentPage(1) ret = VE.ModelChange("M @0") var4 = VCmd.Activate(1, r"VRTMUtilities.VRTMInterface", r"SolverManager") ret = VCmd.ExecuteCommand(var4, r"RUN") ret = VCmd.ExecuteCommand(var4, r"OpenLogFile") VScn.ExecutePythonInterpeter( r"C:\Program Files\ESI Group\Visual-Environment\15.0\COMMON\Resources\VisualProcessExec\user_scripts\CompositeLoadResult.py" )
def asnSurf(var1, INITIAL, lPath_auto): #For each section create a list of surfaces that correspond to it #assign it as new part. BCs = np.loadtxt(open(lPath_auto + "\\temporary\\braidsegments.csv", "rb"), delimiter=",") if INITIAL == 0: surf_mat = np.load(lPath_auto + "\\temporary\\RTM_surfaces.npy") elif INITIAL == 1: surf_mat = np.load(lPath_auto + "\\temporary\\RTM_surfaces_2.npy") else: print("something went horribly wrong") with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("yupgogoyup\n") refPTS = np.loadtxt(open("D:\\sysi\\temporary\\secPTS.csv", "rb"), delimiter=",") secVECz = np.loadtxt(open("D:\\sysi\\temporary\\secVECz.csv", "rb"), delimiter=",") secVECy = np.loadtxt(open("D:\\sysi\\temporary\\secVECy.csv", "rb"), delimiter=",") secPTS = refPTS ret = VE.ChangeContext(r"Visual-RTM") VE.SetActiveWindow(r"p1w1") #The points section reference points are provided in local coordinate systems. #Therefore the surface coordinate systems have to be also translated, #globalToLocal function is used. with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("yupyup\n") step = refPTS[0, 2] u = 0 while u < np.size(surf_mat, 0): uu = 0 while uu < np.size(refPTS, 0): if refPTS[uu, 2] - step <= surf_mat[u, 3] <= refPTS[uu, 2] + step: secVECx = np.cross(secVECy[uu, :], secVECz[uu, :]) cSYS2 = np.array( ([secVECx[0], secVECx[1], secVECx[2] ], [secVECy[uu, 0], secVECy[uu, 1], secVECy[uu, 2]], [secVECz[uu, 0], secVECz[uu, 1], secVECz[uu, 2]])) point1 = np.array([0, 0, 0]) point2 = np.array( [secPTS[uu, 0], secPTS[uu, 1], secPTS[uu, 2]]) cSYS1 = np.array(([1, 0, 0], [0, 1, 0], [0, 0, 1])) GCP = np.array( [surf_mat[u, 1], surf_mat[u, 2], surf_mat[u, 3]]) kopyto = GlobalToLocal(point1, point2, cSYS1, cSYS2, GCP) surf_mat[u, 1] = kopyto[0] surf_mat[u, 2] = kopyto[1] uu = uu + 1 u = u + 1 np.savetxt(lPath_auto + "\\Temporary\\verify_toolbox.csv", surf_mat, delimiter=",") with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("eaiho\n") #Match surfaces to parts. i = 0 US = [] while i < 240: ii = 0 stringASN = " MFace " while ii < np.size(surf_mat, 0): if (BCs[i, 2] < surf_mat[ii, 1] < BCs[i, 1]) and ( BCs[i, 4] < surf_mat[ii, 2] < BCs[i, 3]) and (BCs[i, 6] < surf_mat[ii, 3] < BCs[i, 5]): stringASN = stringASN + r"@0/@" + str(int(surf_mat[ii, 0])) + " " surf_mat = np.delete(surf_mat, (ii), axis=0) ii = ii - 1 ii = ii + 1 with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("ssssss" + stringASN + "\n") if stringASN == " MFace ": US.append(BCs[i, 0]) VE.SetCurrentPage(1) ret = VE.ModelChange("M @0") lst1_count, lst1 = VScn.List(" P 10000 ") VCmd.SetObjectArrayValue(var1, r"GraphicSelection", lst1_count, lst1) ret = VCmd.ExecuteCommand(var1, r"EndSelection") VCmd.SetStringValue(var1, r"TargetName", r"Surface") lst1_count, lst1 = VScn.List(" MFace @0/@1026 ") VCmd.SetObjectArrayValue(var1, r"GraphicSelection", lst1_count, lst1) lst1_count, lst1 = VScn.List(stringASN) VCmd.SetObjectArrayValue(var1, r"GraphicSelection", lst1_count, lst1) lst1_count, lst1 = VScn.List(stringASN) VMaterial.VMeCadDataMove(lst1_count, lst1, NULL) VExpMngr.RefreshExplorer(r"Parts") VExpMngr.RefreshExplorer(r"Elements") i = i + 1 with open(lPath_auto + "\\temporary\\RTM_surf_matRR.txt", "w") as text_file: text_file.write(str(surf_mat)) with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("surfaces assigned\n") VExpMngr.ExportFile(lPath_auto + "\\pamrtm\\mainSimFiles\\vcelkamaja.vdb", 0) #Below adds flow mesh surface if already available. if INITIAL == 1: with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("flow mesh surface 1\n") FM_surf = np.load(r"D:\\sysi\\temporary\\FM_surfaces.npy") ret = VE.ChangeContext(r"Visual-RTM") VE.SetActiveWindow(r"p1w1") ii = 0 stringASN = " MFace " while ii < len(FM_surf): stringASN = stringASN + r"@0/@" + str(int(FM_surf[ii, 0])) + " " ii = ii + 1 #stringASN = stringASN+r"""" )"" VE.SetCurrentPage(1) ret = VE.ModelChange("M @0") lst1_count, lst1 = VScn.List(" P 10000 ") VCmd.SetObjectArrayValue(var1, r"GraphicSelection", lst1_count, lst1) ret = VCmd.ExecuteCommand(var1, r"EndSelection") VCmd.SetStringValue(var1, r"TargetName", r"Surface") lst1_count, lst1 = VScn.List(stringASN) VCmd.SetObjectArrayValue(var1, r"GraphicSelection", lst1_count, lst1) VMaterial.VMeCadDataMove(lst1_count, lst1, NULL) VExpMngr.RefreshExplorer(r"Parts") VExpMngr.RefreshExplorer(r"Elements") with open(lPath_auto + "\\pamrtm\\mainSimFiles\\currentProgress.txt", "a") as text_file: text_file.write("flow mesh surfaces assigned\n") VExpMngr.ExportFile( lPath_auto + "\\pamrtm\\mainSimFiles\\broukpytlik.vdb", 0) return (US)
def surfaceLocator(mesh_info, lPath_auto): #This function generates matrix of surfaces with their approximate 3D position. #The 3D position is recorded in global coordinate systems, as per CATIA .iges. iy = 0 surf_mat = np.zeros([1, 4]) temp_mat = np.zeros([1, 4]) #Allel is the number of expected surfaces based on CATIA mesh generation. allel = mesh_info[0] * mesh_info[1] while iy < (allel): #__________________ TopologyMesh BEGIN __________________ var444 = VCmd.Activate(1, r"VMeshModeler.VmmICommandGui", r"TopologyMesh") VCmd.SetObjectValue(var444, r"CurrentModel", "M @0") VCmd.SetDoubleValue(var444, r"ElementSize", 10) ret = VCmd.ExecuteCommand(var444, r"SetElementSizeToAllEdges") VCmd.SetObjectValue(var444, r"SplitEdge1", NULL) lst1_count, lst1 = VScn.List(" MFace @0/@" + str(iy) + " ") VCmd.SetObjectArrayValue(var444, r"CreateMesh", lst1_count, lst1) VCmd.SetObjectValue(var444, r"SplitEdge1", NULL) VCmd.Cancel(var444) #Generate .inp file for the single meshed surface. VistaDb.ModelSetExportKeyWordOrder("M @0", 0) VistaDb.ModelSetExportStateAsNoInclude("M @0", 1) VExpMngr.ExportFile( lPath_auto + "\\pamrtm\\mainsimfiles\\240\\" + str(iy) + r".inp", 34) #Delete the mesh, preparing it for the next element export. #__________________ TopologyMesh BEGIN __________________ var444 = VCmd.Activate(1, r"VMeshModeler.VmmICommandGui", r"TopologyMesh") VCmd.SetObjectValue(var444, r"CurrentModel", "M @0") VCmd.SetObjectValue(var444, r"SplitEdge1", NULL) lst1_count, lst1 = VScn.List(" MFace @0/@" + str(iy) + " ") VCmd.SetObjectArrayValue(var444, r"DeleteMesh", lst1_count, lst1) VCmd.SetObjectValue(var444, r"SplitEdge1", NULL) VCmd.Cancel(var444) #Next section processes the exported input file. #The nodes exported are collected, and their coordinates averaged. filer = str(iy) + ".inp" eex = open(lPath_auto + "\\pamrtm\\mainsimfiles\\240\\" + filer, "rt") ff = eex.read() ff = ff.split("*NODE")[1] ff = ff.split("*")[0] coord_mat = np.zeros([1, 4]) temp_mat = np.zeros([1, 4]) iiy = 0 #Turnign the input file into matrix. coms = ff.count(',') while iiy < coms: if iiy != 0: ex = ff.split(',')[iiy] ex = float(ex.split()[1]) else: ex = ff.split(',')[iiy] #node number temp_mat[0, 0] = float(ex) ex = ff.split(',')[iiy + 1] #x value temp_mat[0, 1] = float(ex) ex = ff.split(',')[iiy + 2] #y value temp_mat[0, 2] = float(ex) if iiy != coms - 3: ex = ff.split(',')[iiy + 3] ex = float(ex.split()[0]) else: ex = ff.split(',')[iiy + 3] ex = float(ex) #z value temp_mat[0, 3] = float(ex) coord_mat = np.concatenate((coord_mat, temp_mat), axis=0) #add to coord mat matrix iiy = iiy + 3 #delete the first row of coord mat coord_mat = np.delete(coord_mat, (0), axis=0) #average the matrix, input to surf_mat #surface number: temp_mat[0, 0] = iy #x value temp_mat[0, 1] = np.average(coord_mat[:, 1]) #y value temp_mat[0, 2] = np.average(coord_mat[:, 2]) #z value temp_mat[0, 3] = np.average(coord_mat[:, 3]) surf_mat = np.concatenate((surf_mat, temp_mat), axis=0) iy = iy + 1 eex.close() surf_mat = np.delete(surf_mat, (0), axis=0) #eex.close() #Just a marker of progress for log file. with open(lPath_auto + "\\pamrtm\\mainsimfiles\\currentProgress.txt", "a") as text_file: text_file.write("chopchop\n") #Delete current model to prevent any remaining mesh settings to affect #mesh in subsequent simulation. VE.SetCurrentPage(1) ret = VE.ModelChange("M @0") ret = VE.ModelDestroy("M @0") VE.SetCurrentPage(1) VE.SetCurrentPage(1) VE.SetActiveWindow(r"p1w1") VE.NewSession() #Safe the surface matrix. np.save(lPath_auto + "\\temporary\\RTM_surfaces.npy", surf_mat) #Delete the input files. filelist = [ f for f in os.listdir(lPath_auto + "\\pamrtm\\mainsimfiles\\240\\") if f.endswith(".inp") ] for f in filelist: os.remove(os.path.join(lPath_auto + "\\pamrtm\\mainsimfiles\\240\\", f))