-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_field_calc.py
More file actions
76 lines (68 loc) · 2.44 KB
/
test_field_calc.py
File metadata and controls
76 lines (68 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
Test script for magnetic field calculation (simpler than plotting).
"""
import sys
sys.path.insert(0, '/home/alf/OpenMagnetics/PyMKF/build/cp312-cp312-linux_x86_64')
import PyOpenMagnetics as pom
import time
print('Setting up test data...')
core_input = {
'functionalDescription': {
'type': 'two-piece set',
'material': '3C95',
'shape': 'E 42/21/15',
'gapping': [{'type': 'subtractive', 'length': 0.0005}],
'numberStacks': 1
}
}
core_data = pom.calculate_core_data(core_input, True)
bobbin = pom.create_basic_bobbin(core_data, True)
wire = pom.find_wire_by_name('Round 0.5 - Grade 1')
coil_spec = {
'bobbin': bobbin,
'functionalDescription': [{
'name': 'Primary',
'numberTurns': 5,
'numberParallels': 1,
'isolationSide': 'primary',
'wire': wire
}]
}
# Wind the coil properly to get turn coordinates
coil = pom.wind(coil_spec, 1, [1.0], [0], [[0.001, 0.001]])
print(f'Coil wound with {len(coil.get("turnsDescription", []))} turns')
magnetic = {'core': core_data, 'coil': coil}
# Create proper inputs and process them
inputs = {
'designRequirements': {
'magnetizingInductance': {'nominal': 100e-6},
'turnsRatios': []
},
'operatingPoints': [{
'name': 'Test',
'conditions': {'ambientTemperature': 25},
'excitationsPerWinding': [{
'frequency': 100000,
'current': {
'waveform': {'data': [-5, 5, -5], 'time': [0, 2.5e-6, 10e-6]}
}
}]
}]
}
print('Processing inputs...')
processed_inputs = pom.process_inputs(inputs)
operating_point = processed_inputs['operatingPoints'][0]
print(f'Operating point processed. Current has harmonics: {"harmonics" in operating_point["excitationsPerWinding"][0]["current"]}')
print('\nCalling calculate_magnetic_field_strength_field...')
start = time.time()
try:
result = pom.calculate_magnetic_field_strength_field(operating_point, magnetic)
elapsed = time.time() - start
print(f'Field calculation took {elapsed:.2f}s')
if 'data' in result and isinstance(result['data'], str) and 'Exception' in result['data']:
print(f'Error: {result["data"]}')
else:
print(f'Success! Result keys: {list(result.keys()) if isinstance(result, dict) else type(result)}')
except Exception as e:
print(f'Exception: {e}')