Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerWorkflows/FreeCADBatchFEMTools/tests/cylinders_thermo_structural_contact/cylinders.py
3206 views
1
# A test case for FreeCAD automatic scripting with thermo-structural (Elmer test is a modified fem/tests/ThermalBiMetal2)
2
# original date: November 2019
3
# Author: Eelis Takala
4
# email: [email protected]
5
doc = App.newDocument('Cylinders')
6
import sys
7
import os
8
import time
9
import math
10
import FreeCAD
11
import Part
12
13
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
14
import FreeCADBatchFEMTools as FBFT
15
16
script_directory = os.path.dirname(__file__)
17
18
def cylinder(r1, r2, h, symmetry_planes=None, name='cyl', mesh_size=10.):
19
if symmetry_planes == None: symmetry_planes = ['yz','zx', 'xy']
20
planes_original = list(symmetry_planes)
21
#if symmetry_planes == None: symmetry_planes = ['yz']
22
#if symmetry_planes == None: symmetry_planes = ['zx']
23
#if symmetry_planes == None: symmetry_planes = ['xy']
24
25
cyl = doc.addObject("PartDesign::Body","Cylinder")
26
sketch = cyl.newObject('Sketcher::SketchObject',name+' sketch')
27
sketch.MapMode = 'FlatFace'
28
sketch.addGeometry(Part.Circle(App.Vector(0.000000,0.000000,0),App.Vector(0,0,1),r2),False)
29
sketch.addGeometry(Part.Circle(App.Vector(0.000000,0.000000,0),App.Vector(0,0,1),r1),False)
30
doc.recompute()
31
32
pad = cyl.newObject("PartDesign::Pad",name + " pad")
33
pad.Profile = sketch
34
pad.Length = h
35
pad.Length2 = h
36
pad.Type = 0
37
pad.UpToFace = None
38
pad.Reversed = 0
39
pad.Midplane = 1
40
pad.Offset = 0.000000
41
doc.recompute()
42
43
cyl = FBFT.reduce_half_symmetry(cyl, name, App, doc, planes=symmetry_planes)
44
doc.recompute()
45
46
# create entities dict
47
#face_picks = [('alpha0', 0), ('b2', 1), ('b3', 2), ('b4', 3), ('b5', 4), ('b6', 5)]
48
#faces = FBFT.pick_faces_from_geometry(cyl, face_picks)
49
#faces = []
50
#for plane in planes_original:
51
#FBFT.add_symmetry_plane_faces_in_entity_list(faces, cyl, plane)
52
53
#if symmetry_planes == None: symmetry_planes = ['yz']
54
#if symmetry_planes == None: symmetry_planes = ['zx']
55
#if symmetry_planes == None: symmetry_planes = ['xy']
56
57
face_picks = [('outer', 0), ('yz', 1), ('xy', 2), ('zx', 3), ('end', 4), ('inner', 5)]
58
faces = FBFT.pick_faces_from_geometry(cyl, face_picks)
59
60
solids = []
61
FBFT.add_entity_in_list(solids, name, cyl, {'mesh size': mesh_size})
62
entities_dict = FBFT.create_entities_dict(name, faces, solids, cyl)
63
64
return entities_dict
65
66
def create_geometry():
67
68
mesh_size_max = 100.
69
cyl_entities_list = []
70
cyl_entities_list.append(cylinder(20, 10, 40., name='cyl1', mesh_size=3.))
71
cyl_entities_list.append(cylinder(30, 20, 20., name='cyl2', mesh_size=4.))
72
entities_dict = FBFT.merge_entities_dicts(cyl_entities_list, 'All', default_mesh_size=mesh_size_max,
73
add_prefixes={'solids': False, 'faces': True})
74
solid_objects = FBFT.get_solids_from_entities_dict(entities_dict)
75
76
mesh_object, compound_filter = FBFT.create_mesh_object_and_compound_filter(solid_objects, mesh_size_max, doc, separate_boundaries=True)
77
78
FBFT.find_boundaries_with_entities_dict(mesh_object, compound_filter, entities_dict, doc, separate_boundaries=True)
79
FBFT.find_bodies_with_entities_dict(mesh_object, compound_filter, entities_dict, doc)
80
FBFT.define_mesh_sizes(mesh_object, compound_filter, entities_dict, doc, point_search=False, ignore_list=['air'])
81
82
FBFT.fit_view()
83
FBFT.create_mesh(mesh_object)
84
FBFT.export_unv(os.path.join(script_directory, 'cylinders.unv'), mesh_object)
85
86
try:
87
create_geometry()
88
89
except Exception:
90
import traceback
91
print(str(traceback.format_exc()))
92
93
exit()
94
95