Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerWorkflows/FreeCADBatchFEMTools/tests/massive_coil/massive_generation.py
3206 views
1
"""
2
Massive coil generation and solving test for
3
FreeCADBatchFEMTools - A library for using FreeCAD for FEM preprocessing in batch mode
4
5
Copyright 1st May 2018 - , Trafotek Oy, Finland
6
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation; either
10
version 2.1 of the License, or (at your option) any later version.
11
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
16
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library (in file ../LGPL-2.1); if not, write
19
to the Free Software Foundation, Inc., 51 Franklin Street,
20
Fifth Floor, Boston, MA 02110-1301 USA
21
22
Authors: Eelis Takala, Janne Keranen
23
Emails: [email protected], [email protected]
24
Address: Trafotek Oy
25
Kaarinantie 700
26
20540 Turku
27
Finland
28
29
Original Date: May 2018
30
"""
31
doc = App.newDocument("Massive winding")
32
import os
33
import sys
34
import Part
35
import ObjectsFem
36
37
PWD = os.path.dirname(os.path.realpath(__file__))
38
module_path = PWD + "/../.."
39
sys.path.insert(0, module_path)
40
41
from FreeCADBatchFEMTools import fit_view
42
from FreeCADBatchFEMTools import pick_faces_from_geometry
43
from FreeCADBatchFEMTools import add_entity_in_list
44
from FreeCADBatchFEMTools import create_entities_dict
45
from FreeCADBatchFEMTools import merge_entities_dicts
46
from FreeCADBatchFEMTools import get_solids_from_entities_dict
47
from FreeCADBatchFEMTools import create_mesh_object_and_compound_filter
48
from FreeCADBatchFEMTools import find_boundaries_with_entities_dict
49
from FreeCADBatchFEMTools import find_bodies_with_entities_dict
50
from FreeCADBatchFEMTools import define_mesh_sizes
51
from FreeCADBatchFEMTools import create_mesh
52
from FreeCADBatchFEMTools import run_elmergrid
53
54
def create_core(h, w, a, b, name, mesh_sizes=None):
55
56
core = doc.addObject('PartDesign::Body',name+'_obj')
57
sketch = core.newObject('Sketcher::SketchObject',name+' sketch')
58
#sketch.Support = (doc.XY_Plane, [''])
59
sketch.MapMode = 'FlatFace'
60
61
sketch.addGeometry(Part.LineSegment(App.Vector(0,-h/2, 0),App.Vector(0,h/2, 0)),False)
62
sketch.addGeometry(Part.LineSegment(App.Vector(0,h/2, 0),App.Vector(w/2, h/2, 0)),False)
63
sketch.addGeometry(Part.LineSegment(App.Vector(w/2,h/2,0),App.Vector(w/2,a/2,0)),False)
64
sketch.addGeometry(Part.LineSegment(App.Vector(w/2,a/2,0),App.Vector(b/2,a/2,0)),False)
65
sketch.addGeometry(Part.LineSegment(App.Vector(b/2,a/2,0),App.Vector(b/2,-a/2,0)),False)
66
sketch.addGeometry(Part.LineSegment(App.Vector(b/2,-a/2,0),App.Vector(w/2,-a/2,0)),False)
67
sketch.addGeometry(Part.LineSegment(App.Vector(w/2,-a/2,0),App.Vector(w/2,-h/2,0)),False)
68
sketch.addGeometry(Part.LineSegment(App.Vector(w/2,-h/2,0),App.Vector(0,-h/2,0)),False)
69
70
doc.recompute()
71
fit_view()
72
73
rev = core.newObject("PartDesign::Revolution",name + " rev")
74
rev.Profile = sketch
75
rev.ReferenceAxis = (sketch,['V_Axis'])
76
rev.Angle=180
77
rev.Reversed = 1
78
doc.recompute()
79
# #fit_view()
80
81
# Here we define the entities dictionary.
82
face_picks=[
83
('infinity_xz0',6),
84
('infinity_xz1',0),
85
('cylinder_lateral_surface',1),
86
('cylinder_lateral_surface',5),
87
('xy0',7),
88
('xy0',8)
89
]
90
faces = pick_faces_from_geometry(core, face_picks)
91
92
solids = []
93
add_entity_in_list(solids, name, core, mesh_sizes=mesh_sizes)
94
95
entities_out = create_entities_dict(name, faces, solids, main_object=core)
96
return entities_out
97
98
def create_coil (r, R, h, z, name, face_entities=True, mesh_sizes=None):
99
coil = doc.addObject('PartDesign::Body',name+'_obj')
100
sketch = coil.newObject('Sketcher::SketchObject',name+' sketch')
101
#sketch.Support = (doc.XY_Plane, [''])
102
sketch.MapMode = 'FlatFace'
103
104
sketch.addGeometry(Part.LineSegment(App.Vector(r,-h/2+z, 0),App.Vector(r,h/2+z, 0)),False)
105
sketch.addGeometry(Part.LineSegment(App.Vector(r,h/2+z, 0),App.Vector(R,h/2+z, 0)),False)
106
sketch.addGeometry(Part.LineSegment(App.Vector(R,h/2+z, 0),App.Vector(R,-h/2+z, 0)),False)
107
sketch.addGeometry(Part.LineSegment(App.Vector(R,-h/2+z, 0),App.Vector(r,-h/2+z, 0)),False)
108
doc.recompute()
109
fit_view()
110
111
rev = coil.newObject("PartDesign::Revolution",name + " rev")
112
rev.Profile = sketch
113
rev.ReferenceAxis = (sketch,['V_Axis'])
114
rev.Angle=180
115
rev.Reversed = 1
116
doc.recompute()
117
118
coil_faces=coil.Shape.Faces
119
120
# Here we define the entities dictionary. Note that each coil contain the same
121
# names for each geometric entity. That is why the 'name' key is required
122
# in the dictionary.
123
124
# Naming of the faces can be avoided by giving face_entities=False as argument
125
faces=[]
126
if(face_entities):
127
face_picks=[('gamma0',4),
128
('gamma1',5)]
129
130
faces = pick_faces_from_geometry(coil, face_picks)
131
132
solids=[]
133
add_entity_in_list(solids, name, coil, mesh_sizes=mesh_sizes)
134
135
entities_out = create_entities_dict(name, faces, solids, main_object=coil)
136
137
return entities_out
138
139
def create_air(coil_inner_radius, coil_outer_radius, coil_height, airgap, z, coil_entities, name, mesh_sizes=None):
140
141
airpluscoil_entities=create_coil(coil_inner_radius-airgap, coil_outer_radius+airgap, coil_height+airgap*2, z, name = "air and coil", face_entities=False)
142
143
air = doc.addObject("Part::Cut","air"+'_obj')
144
air.Base = airpluscoil_entities['main object']
145
air.Tool = coil_entities['main object']
146
doc.recompute()
147
148
# Here we define the entities dictionary.
149
face_picks=[
150
('xy0',3),
151
('xy0',4),
152
('cylinder_lateral_surface',5)
153
]
154
155
faces = pick_faces_from_geometry(air, face_picks)
156
157
solids=[]
158
add_entity_in_list(solids, name, air, mesh_sizes=mesh_sizes)
159
entities_out = create_entities_dict(name, faces, solids, main_object=air)
160
161
return entities_out
162
163
164
def create_solids(model_parameters):
165
coil_inner_radius = model_parameters['coil_inner_radius']
166
coil_outer_radius = model_parameters['coil_outer_radius']
167
coil_height = model_parameters['coil_height']
168
z = model_parameters['z']
169
core_height = model_parameters['core_height']
170
core_diameter = model_parameters['core_diameter']
171
core_center_length = model_parameters['core_center_length']
172
core_center_diameter = model_parameters['core_center_diameter']
173
airgap = model_parameters['airgap']
174
default_mesh_size = model_parameters['default_mesh_size']
175
coil_mesh_sizes = model_parameters['coil_mesh_sizes']
176
core_mesh_sizes = model_parameters['core_mesh_sizes']
177
air_mesh_sizes = model_parameters['air_mesh_sizes']
178
179
coil_entities = create_coil(coil_inner_radius, coil_outer_radius,
180
coil_height, z, name = "L1", mesh_sizes=coil_mesh_sizes)
181
core_entities = create_core(core_height,core_diameter,core_center_length,
182
core_center_diameter, name = 'core', mesh_sizes=core_mesh_sizes)
183
air_entities = create_air(coil_inner_radius, coil_outer_radius, coil_height,
184
airgap, z, coil_entities, name = 'air', mesh_sizes=air_mesh_sizes)
185
186
doc.recompute()
187
name = 'All'
188
solids_entities = merge_entities_dicts([core_entities, coil_entities, air_entities],
189
name, default_mesh_size = default_mesh_size, add_prefixes={'solids':False, 'faces':True})
190
return solids_entities
191
192
##### Tests #####
193
def test_all():
194
model_parameters = {}
195
model_parameters['coil_inner_radius'] = 0.11/2
196
model_parameters['coil_outer_radius'] = 0.11/2+0.1
197
model_parameters['coil_height'] = 0.1
198
model_parameters['z'] =.0
199
model_parameters['core_height'] =.31
200
model_parameters['core_diameter'] =.32
201
model_parameters['core_center_length'] =.11
202
model_parameters['core_center_diameter'] =.1
203
model_parameters['airgap'] =.005
204
model_parameters['default_mesh_size'] = 0.04 #If default mesh size is smaller than given mesh sizes, fallback value is used.
205
model_parameters['coil_mesh_sizes'] = {
206
'L1':0.02,
207
'alpha0':0.01
208
}
209
model_parameters['core_mesh_sizes'] = {'core':0.04}
210
model_parameters['air_mesh_sizes'] = {'air':0.009}
211
212
default_mesh_size = model_parameters['default_mesh_size']
213
214
entities_dict = create_solids(model_parameters)
215
solid_objects = get_solids_from_entities_dict(entities_dict)
216
217
mesh_object, compound_filter = create_mesh_object_and_compound_filter(solid_objects,default_mesh_size, doc)
218
find_boundaries_with_entities_dict(mesh_object, compound_filter, entities_dict, doc)
219
find_bodies_with_entities_dict(mesh_object, compound_filter, entities_dict, doc)
220
define_mesh_sizes(mesh_object, compound_filter, entities_dict, doc)
221
fit_view()
222
create_mesh(mesh_object)
223
export_path=PWD+"/circuits_harmonic_massive/1962.unv"
224
run_elmergrid(export_path, mesh_object)
225
#################
226
227
test_all() #This test is with all the definitions and examples
228
if not FreeCAD.GuiUp:
229
exit()
230
231
232