NGsolveOCCgeometry.py

You can view and download this file on Github: NGsolveOCCgeometry.py

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Test for Hurty-Craig-Bampton modes using a simple flexible pendulum meshed with Netgen
  5#
  6# Author:   Johannes Gerstmayr
  7# Date:     2021-04-20
  8#
  9# Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details.
 10#
 11#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 12
 13
 14import exudyn as exu
 15from exudyn.utilities import *
 16import exudyn.graphics as graphics
 17
 18SC = exu.SystemContainer()
 19mbs = SC.AddSystem()
 20
 21import numpy as np
 22
 23import time
 24
 25from netgen.occ import *
 26from ngsolve import Mesh, Draw
 27
 28coarsefact = 1
 29#simple solid of revolution geometry:
 30wp = WorkPlane(Axes(p=(0,0,0), n=Z, h=X))
 31#wp.MoveTo(10,0).Line(18).Arc(5,180).Line(10).Close()
 32wp.MoveTo(10,0).Line(18).Arc(2,90).Line(6).Arc(2,90).Line(18).Rotate(90).Line(2).Rotate(90).Line(10).Arc(3,-180).Line(10).Close()
 33axis = Axis((0,0,0),Y)
 34body = wp.Face().Revolve(axis,360)
 35body.name='steel'
 36body.faces.Min(Y).name='my_bc3'
 37
 38body2 = Cylinder(Pnt(15,0,0),-Y,4,5)
 39body2.faces.Max(X).name='my_bc0'
 40body2.faces.Min(X).name='my_bc1'
 41body2.faces.Min(Y).name='my_bc2'
 42#body2.faces[0].name='my_bc'
 43body2.name='wood'
 44
 45#geo = OCCGeometry( p )
 46maxh = 2.5*coarsefact #*0.125
 47glued = Glue([body, body2]) #to combine different materials, use Glue
 48
 49geo = OCCGeometry(glued)
 50print('meshing ...')
 51geoMesh = geo.GenerateMesh(maxh=maxh,
 52                             curvaturesafety=0.5/coarsefact,#*10,
 53                             #segmentsperedge=12,
 54                             )
 55
 56mesh = Mesh(geoMesh)
 57
 58
 59print('mats=',mesh.GetMaterials()) #shows materials
 60print('bcs=',mesh.GetBoundaries()) #shows bc
 61
 62if True:
 63    import netgen.gui #this starts netgen gui; Press button "Visual" and activate "Auto-redraw after (sec)"; Then select "Mesh"
 64
 65
 66[points, triangles, normals] = graphics.NGsolveMesh2PointsAndTrigs(mesh=mesh,
 67                                                                   scale=0.01,
 68                                                                   meshOrder=2,
 69                                                                   addNormals=True,
 70                                                                   )
 71color = color4steelblue
 72meshColor=graphics.color.lawngreen[0:3]+[graphics.material.indexChrome]
 73
 74gMesh = graphics.FromPointsAndTrigs(points, triangles, normals=normals,
 75                                    color=meshColor)
 76
 77
 78if False:
 79    #optionally save STL mesh from netgen:
 80    mesh.ngmesh.Export('solution/ngsolveOCCtest.stl','STL Format')
 81
 82if True:
 83    #save mesh via Exudyn and graphicsData
 84    graphics.ExportSTL(gMesh, 'solution/ngsolveOCCtest2.stl', invertNormals=False, invertTriangles=False)
 85
 86    gMesh = graphics.FromSTLfileASCII('solution/ngsolveOCCtest2.stl',
 87                                      invertNormals=False, invertTriangles=False,
 88                                      color=meshColor)
 89    gMesh = graphics.AddEdgesAndSmoothenNormals(gMesh, edgeAngle=0.35*pi)
 90
 91gFloor = graphics.CheckerBoard(point=[0,0,-0.5],size=2)
 92mbs.CreateGround(graphicsDataList=[gMesh,
 93                                   gFloor])
 94
 95mbs.CreateMassPoint(physicsMass=1, show=False)
 96
 97mbs.Assemble()
 98
 99SC.visualizationSettings.window.renderWindowSize=[1200,800]
100SC.visualizationSettings.general.autoFitScene=False
101
102SC.visualizationSettings.general.drawCoordinateSystem = False
103SC.visualizationSettings.general.showSolverInformation = False
104SC.visualizationSettings.openGL.multiSampling=1
105SC.visualizationSettings.openGL.shadow = 0.2
106SC.visualizationSettings.openGL.lineWidth = 2
107#SC.visualizationSettings.openGL.light0position = [-2.0, 4.0, 1.0, 1.0]
108SC.visualizationSettings.loads.show = False
109SC.visualizationSettings.openGL.light0position=[2,-0.25,0.25,1]
110
111#raytracing options
112SC.visualizationSettings.exportImages.saveImageTimeOut = 200000
113SC.visualizationSettings.openGL.multiSampling = 1
114SC.visualizationSettings.openGL.enableLight1 = False
115SC.visualizationSettings.raytracer.numberOfThreads = 16 #number of threads!
116SC.visualizationSettings.raytracer.enable = False #set True for raytracing
117SC.visualizationSettings.raytracer.ambientLightColor = [0.5,0.5,0.5,1]
118SC.visualizationSettings.raytracer.backgroundColorReflections = [0.3,0.3,0.3,1]
119SC.visualizationSettings.raytracer.keepWindowActive= True
120SC.visualizationSettings.raytracer.searchTreeFactor = 8
121SC.visualizationSettings.raytracer.imageSizeFactor=2 #for faster rendering
122
123
124#visualize in Exudyn:
125SC.renderer.Start()              #start graphics visualization
126if 'renderState' in exu.sys: #reload last view
127    SC.renderer.SetState(exu.sys['renderState'])
128
129#to run Exudyn and netgen in parallel (not recommended), we need to run an event loop
130while SC.renderer.IsActive():
131    SC.renderer.DoIdleTasks(0) #press space to continue
132    time.sleep(0.04)
133    netgen.Redraw()
134
135SC.renderer.Stop() #safely close rendering window!