### Example configuration file for Google Engine Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Example of a configuration file with a [google] section defining options like server_location, instance_type, startup, etc. All options are optional. ```ini [google] SERVER_LOCATION = us-east1-b instance_type = n1-standard-1 image_id = femag-v1 startup = ./cloud_init.txt company_name = Semafor delete_buckets = 1 server_config = ./gcloud.json startup_script = ./startup.sh ``` -------------------------------- ### Install femagtools with pip proxy Source: https://femagtools.readthedocs.io/en/latest/_sources/index.rst.txt Installs femagtools with pip when a proxy is needed. ```bash $ pip --proxy http://proxy.hell:3128 install femagtools ``` -------------------------------- ### Install femagtools with pip Source: https://femagtools.readthedocs.io/en/latest/_sources/index.rst.txt Installs femagtools on any Python 2.7 or 3.x distribution with Numpy, Scipy and Pip. ```bash $ pip install femagtools ``` -------------------------------- ### Amazon configuration file example Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Example configuration file with an [amazon] section defining instance attributes. Note that security_group_ids is a list and must have a trailing comma if only one security group is used. ```ini [amazon] iam_instance_profile = ecsInstanceRole key_name = test-key-pair-eucentral-1 security_group_ids = sg-8475b5dd, server_location = eu-central-1 instance_type = t2.small image_id = ami-6d4ceb03 cloud_init = ./cloud_init.txt ``` -------------------------------- ### BCH reader example output dictionary Source: https://femagtools.readthedocs.io/en/latest/_sources/bchreader.rst.txt Example of the dictionary returned by the BCH reader, showing loss values and harmonic spectrum details. The 'fft' key contains per-component (rotor, stajo, staza) tuples for order, frequency, hysteresis, and eddy losses. ```python {'beta': 0.0, 'current': 0.0, 'magnetB': 0.0, 'magnetJ': 0.053, 'r1': 0.0, 'rotfe': 483.806, 'stajo': 1242.913, 'staza': 1664.52, 'total': 3391.292, 'winding': 0.0, 'fft': { 'rotor': {'eddy': (475.937,), 'freq': (600.0,), 'hyst': (7.869,), 'order': (6,)}, 'stajo': {'eddy': (15.777, 138.777, 394.427, 206.489, 313.927, 134.139, 5.329), 'freq': (100.0, 300.0, 500.0, 700.0, 900.0, 1100.0, 1300.0), 'hyst': (9.983, 9.178, 9.391, 2.508, 2.307, 0.66, 0.019), 'order': (1, 3, 5, 7, 9, 11, 13)}, 'staza': {'eddy': (13.06, 117.544, 325.934, 212.208, 417.321, 326.528, 220.231), 'freq': (100.0, 300.0, 500.0, 700.0, 900.0, 1100.0, 1300.0), 'hyst': (8.135, 7.774, 7.76, 2.578, 3.067, 1.606, 0.776), 'order': (1, 3, 5, 7, 9, 11, 13)}} } ``` -------------------------------- ### Example: User defined magnet slot with DXF Source: https://femagtools.readthedocs.io/en/latest/models.html Shows how to use a DXF file for the magnet geometry, with parameters for position and splitting intersecting lines. ```python machine = dict( name="Motor", ... magnet=dict( mcvkey_yoke='dummy', mcvkey_shaft="dummy", dxffile=dict( name='mymagnet.dxf', position='in', split=True ) ), ... ``` ``` -------------------------------- ### Install femagtools with conda Source: https://femagtools.readthedocs.io/en/latest/_sources/index.rst.txt Installs femagtools via Anaconda using the semafor and conda-forge channels. ```bash $ conda install -c semafor -c conda-forge femagtools ``` -------------------------------- ### Example server configuration JSON Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt JSON configuration for instance attributes. Attributes like sourceImage, machineType, name, bucket_id are set automatically if missing. ```json { "disks": [ { "boot": true, "autoDelete": true } ], "networkInterfaces": [{ "network": "global/networks/default", "accessConfigs": [ {"type": "ONE_TO_ONE_NAT", "name": "External NAT"} ] }], "serviceAccounts": [{ "email": "default", "scopes": [ "https://www.googleapis.com/auth/devstorage.read_write", "https://www.googleapis.com/auth/logging.write" ] }], "metadata": { "items": [{ "key": "text", "value": "Run femag" }] } } ``` -------------------------------- ### Example startup.sh script Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Defines the processing sequence after instance startup. The files for one calculation are transferred in a tar.gz file. The script downloads data, extracts, runs xfemag, and uploads results. ```bash #!/bin/bash # [START startup_script] CS_BUCKET=$(curl http://metadata/computeMetadata/v1/instance/attributes/bucket -H "Metadata-Flavor: Google") mkdir data gsutil rsync gs://$CS_BUCKET data cd data tar -xzf *.tar.gz xfemag -b femag.fsl exit_code gsutil rsync /data gs://$CS_BUCKET # [END startup_script] ``` -------------------------------- ### PM/Rel Machine Simulation (pm_sym_fast) Example: Operating Conditions Source: https://femagtools.readthedocs.io/en/latest/models.html Example of setting up operating conditions for the pm_sym_fast calculation mode. The dictionary includes parameters like wind_temp, magn_temp, current, speed, and plots. Note that the 'plots' parameter is a list of plot types to be created after calculation. ```python operatingConditions = dict( calculationMode="pm_sym_fast", wind_temp=60.0, magn_temp=60.0, current=50.0, speed=50.0, plots=['field_lines', 'Babs']) ``` -------------------------------- ### Weight attribute example Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example output of the Weight attribute, a dictionary with keys 'total', 'iron', 'conductor', and 'magnet' representing weights in kg. ```python {'total': 28.188, 'iron': 24.165, 'conductor': 2.853, 'magnet': 1.17} ``` -------------------------------- ### Google Engine startup.sh Script Source: https://femagtools.readthedocs.io/en/latest/engine.html Startup script that runs after the instance starts. It downloads the bucket, extracts the tar.gz file, runs xfemag, and uploads results back. The files for one calculation are transferred in a tar.gz file. ```bash #!/bin/bash # [START startup_script] CS_BUCKET=$(curl http://metadata/computeMetadata/v1/instance/attributes/bucket -H "Metadata-Flavor: Google") mkdir data gsutil rsync gs://$CS_BUCKET data cd data tar -xzf *.tar.gz xfemag -b femag.fsl exit_code gsutil rsync /data gs://$CS_BUCKET # [END startup_script] ``` -------------------------------- ### Amazon cloud init bash script example Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Cloud init script that runs on instance startup. Uses {{ENV}} to inject environment variables including BUCKET_NAME, downloads files from S3, extracts tar.gz, runs xfemag, and syncs results back. ```bash #!/bin/bash {{ENV}} mkdir ~/.aws echo -e '[default]\nregion = '$SERVER_LOCATION'\noutput = json' > ~/.aws/config yum install -y aws-cli libquadmath mkdir ~/data aws s3 sync s3://$BUCKET_NAME/ ~/data cd ~/data tar -xzf *.tar.gz /usr/local/bin/xfemag -b femag.fsl ~/data/exit_code aws s3 sync ~/data s3://$BUCKET_NAME ``` -------------------------------- ### DqPar object example dictionary Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example dictionary for the DqPar object, containing d/q-axis inductances, fluxes, voltages, and performance data at two beta angles. The 'u1' list has three entries while other lists have two, and 'kt' is a single-element list. ```python {'psiq': [0.330062, 0.33031268], 'psid': [0.08589968, -0.005226678], 'ld': [0.0008623392, 0.0008623392], 'lq': [0.0013202480000000002, 0.001458122], 'psim': [0.08589968, 0.08589968], 'speed': 50.0, 'npoles': 8, 'lfe': 0.08356, 'psim0': 0.1153128, 'u1': [145.0, 428.5, 415.1], 'gamma': [75.44, 90.91], 'dag': 0.16117, 'i1': [0, 250.0, 250.0], 'beta': [0.0, -25.0], 'kt': [1.14], 'up0': 145.0, 'up': 108.0, 'p2': [80958.54109011423, 127081.80850105156], 'phi': [50.44, 65.91], 'torque': [257.69904, 404.51396], 'cosphi': [0.63688591473536493, 0.40817113454379084]} ``` -------------------------------- ### Inertia attribute example Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example output of the Inertia attribute, a list of inertia values for stator and rotor in kg m²/mm. ```python [0.23, 0.39] ``` -------------------------------- ### Get an element by key from ISA7 file Source: https://femagtools.readthedocs.io/en/latest/_sources/intro.rst.txt Retrieves the first element from an ISA7 file. ```python >>> el = isa.elements[0] ``` -------------------------------- ### Machine object example dictionary Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example dictionary for the Machine object, showing typical values for a 3-phase, 4-pole-pair machine with 48 stator slots. Note the missing comma after the 'plfe' entry in the original source. ```python {'m': 3, 'p': 4, 'qs_sim': 12, 'p_sim': 2, 'Q': 48, 'n': 50.0, 'kcu': 40.0, 'r1': 0.055, 'AJ': 84365.4609, 'A': 213.2994, 'fd': 119.0008, 'J': 39.5526, 'lfe': 0.08356, 'ld': 0.0008625, 'lq': 0.00132, 'psim': 0.1152, 'torque': 405.7295, 'p2': 127463.7, 'plfe1_0': 172.9209, 'plmag_0': 0.0239, 'plfe2_0': 0.7076, 'i1': 500.0, 'beta': [0.0, -25.0], 'plfe1': [1463.3809, 1374.8728], 'plfe2': [71.727, 77.0296], 'plmag': [4.1524, 15.1965], 'plcu': [10305.4824, 10305.4824], 'pltotal': [11844.7427, 11772.581300000002], 'plfe': [1535.1079000000002, 1451.9024000000002] 'eff': 91.5449} ``` -------------------------------- ### Weights attribute example Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example output of the Weights attribute, a list of lists containing weights for stator and rotor in kg. ```python [[18.802, 2.853, 0.0], [5.363, 0.0, 1.17], ``` -------------------------------- ### Losses attribute example Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example output of the Losses attribute, a list of dictionaries with loss components and harmonic spectrum data. ```python {'beta': 0.0, 'current': 0.0, 'magnetB': 0.0, 'magnetJ': 0.053, 'r1': 0.0, 'rotfe': 483.806, 'stajo': 1242.913, 'staza': 1664.52, 'total': 3391.292, 'winding': 0.0, 'fft': { 'rotor': {'eddy': (475.937,), 'freq': (600.0,), 'hyst': (7.869,), 'order': (6,)}, 'stajo': {'eddy': (15.777, 138.777, 394.427, 206.489, 313.927, 134.139, 5.329), 'freq': (100.0, 300.0, 500.0, 700.0, 900.0, 1100.0, 1300.0), 'hyst': (9.983, 9.178, 9.391, 2.508, 2.307, 0.66, 0.019), 'order': (1, 3, 5, 7, 9, 11, 13)}, 'staza': {'eddy': (13.06, 117.544, 325.934, 212.208, 417.321, 326.528, 220.231), 'freq': (100.0, 300.0, 500.0, 700.0, 900.0, 1100.0, 1300.0), 'hyst': (8.135, 7.774, 7.76, 2.578, 3.067, 1.606, 0.776), 'order': (1, 3, 5, 7, 9, 11, 13)}} } ``` -------------------------------- ### ld_lq_fast calculation parameters Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Example of setting up the feapars dictionary for the ld_lq_fast calculation mode, which is used for identifying d- and q-axis inductances. The parameters include speed, magnet temperature, current limits, and beta angle range. ```python feapars = dict( num_move_steps=25, calculationMode="ld_lq_fast", magn_temp=60.0, i1_max=150.0, beta_max=0.0, beta_min=-60.0, num_cur_steps=3, num_beta_steps"=4, speed=50.0) ``` -------------------------------- ### pm_sym_fast calculation parameters Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Example of setting up the feapars dictionary for the pm_sym_fast calculation mode, which is used for PM/Rel machine simulation. The parameters include winding temperature, current, and angle. ```python feapars = dict( num_move_steps=25, calculationMode="pm_sym_fast", magn_temp=60.0, current=50.0, angl_i_up=0.0, speed=50.0) ``` -------------------------------- ### Windings attribute example Source: https://femagtools.readthedocs.io/en/latest/bchreader.html Example output of the Windings attribute, a dictionary with winding keys containing lists for N, R, dir, and PHI. ```python { 1: {'N': [4.0, 4.0, 4.0, 4.0], 'R': [92e-3, 92.0086, 92e-3, 92e-3], 'dir': [1, 1, 1, -1], 'PHI': [3.0203, 4.4797, 11.9797, 40.5202]}, 2: {'N': [4.0, 4.0, 4.0, 4.0], 'R': [92e-3, 92e-3, 92e-3, 92.0086], 'dir': [1, 1, 1, 1], 'PHI': [25.5202, 33.0202, 34.4797, 41.9797]}, 3: {'N': [4.0, 4.0, 4.0, 4.0], 'R': [92e-3, 92e-3, 92e-3, 92e-3], 'dir': [-1, -1, -1, -1], 'PHI': [10.5202, 18.0202, 19.4797, 26.9797]} } ``` -------------------------------- ### Example: Define a machine with a magnetSector slot Source: https://femagtools.readthedocs.io/en/latest/models.html Shows a complete machine dictionary with a magnetSector slot, including stator and windings. The magnet uses mcvkey_shaft and mcvkey_yoke set to 'dummy'. ```python machine = dict( name="PM 130 L4", lfe=0.1, poles=4, outer_diam=0.13, bore_diam=0.07, inner_diam=0.015, airgap=0.001, stator=dict( num_slots=12, num_slots_gen=3, mcvkey_yoke="dummy", rlength=1.0, stator1=dict( slot_rf1=0.057, tip_rh1=0.037, tip_rh2=0.037, tooth_width=0.009, slot_width=0.003) ), magnet=dict( mcvkey_shaft="dummy", mcvkey_yoke="dummy", magnetSector=dict ( magn_num=1, magn_width_pct=0.8, magn_height=0.004, magn_shape=0.0, bridge_height=0.0, magn_type=1, condshaft_r=0.02, magn_ori=2, magn_rfe=0.0, bridge_width=0.0, magn_len=1.0 ) ), windings=dict( num_phases=3, num_wires=100, coil_span=3.0, num_layers=1) ) ``` ``` -------------------------------- ### Operating conditions for cogging calculation example Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Defines operating conditions for cogging calculation with calculation mode, magnet temperature, number of move steps, and speed. ```python operatingConditions = dict( calculationMode="cogg_fast", magn_temp=60.0, num_move_steps=49, speed=50.0) ``` -------------------------------- ### Create machine model from single DXF file Source: https://femagtools.readthedocs.io/en/latest/models.html Configuration dictionary for creating a machine model from a single DXF file named 'motor.dxf'. Parameters like poles, outer diameter, bore diameter, airgap, and slot counts are set automatically. The example shows placeholders for stator and magnet material keys. ```python machine = dict( name="Motor", lfe=0.001, dxffile=dict( name='motor.dxf' ), stator=dict( mcvkey_yoke='dummy', mcvkey_shaft="dummy" ), magnet=dict( mcvkey_yoke="dummy", mcvkey_shaft="dummy" ), ... ``` -------------------------------- ### psd_psq_fast calculation parameters Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Example of setting up the feapars dictionary for the psd_psq_fast calculation mode, which is used for identifying flux linkages. The parameters include current limits for Id and Iq, and step sizes. ```python feapars = dict( num_move_steps=25, calculationMode="psd_psq_fast", magn_temp=60.0, maxid=0.0, minid=-150.0, maxiq=150.0 miniq=0.0, delta_id=50.0, delta_iq=50.0, speed=50.0) ``` -------------------------------- ### Calculation with existing model Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Example of running a FEMAG calculation on an existing model using the femagtools.Femag class. It shows how to specify the machine name, working directory, and operating conditions. ```python machine = "PM 270 L8" workdir = os.path.join( os.path.expanduser('~'), 'femag') femag = femagtools.Femag(workdir) operatingConditions = dict( angl_i_up=-38.7, calculationMode="pm_sym_fast", magn_temp=60.0, num_move_steps=25, speed=50.0, wind_temp=60.0, current=108.0) r = femag(machine, operatingConditions) ``` -------------------------------- ### Minimal machine data for older FEMAG versions Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Example of the minimal machine dictionary required for older FEMAG versions, specifying the machine geometry and stator parameters. ```python machine = dict( name="PM 130 L4", lfe=0.1, poles=4, outer_diam=0.13, bore_diam=0.07, airgap=0.001, stator=dict( num_slots=12, num_slots_gen=3, mcvkey_yoke="dummy" ) ) ``` -------------------------------- ### Get an element by key Source: https://femagtools.readthedocs.io/en/latest/intro.html Retrieves an element from the ISA7 object using its index. ```python >>> el = isa.elements[0] ``` -------------------------------- ### Calculation with Existing Model: Operating Conditions Source: https://femagtools.readthedocs.io/en/latest/models.html Example of running a calculation with an existing model using the femagtools.Femag class. The operating conditions dictionary includes parameters like angl_i_up, calculationMode, magn_temp, num_move_steps, speed, wind_temp, and current. ```python machine = "PM 270 L8" workdir = os.path.join( os.path.expanduser('~'), 'femag') femag = femagtools.Femag(workdir) operatingConditions = dict( angl_i_up=-38.7, calculationMode="pm_sym_fast", magn_temp=60.0, num_move_steps=25, speed=50.0, wind_temp=60.0, current=108.0) r = femag(machine, operatingConditions) ``` -------------------------------- ### Google Engine Server Configuration JSON Source: https://femagtools.readthedocs.io/en/latest/engine.html Example JSON server configuration for Google Cloud instances. Only set attributes valid for all instances; missing attributes like sourceImage, machineType, name, and bucket_id are set automatically at runtime. ```json { "disks": [ { "boot": true, "autoDelete": true } ], "networkInterfaces": [{ "network": "global/networks/default", "accessConfigs": [ {"type": "ONE_TO_ONE_NAT", "name": "External NAT"} ] }], "serviceAccounts": [{ "email": "default", "scopes": [ "https://www.googleapis.com/auth/devstorage.read_write", "https://www.googleapis.com/auth/logging.write" ] }], "metadata": { "items": [{ "key": "text", "value": "Run femag" }] } } ``` -------------------------------- ### FSL template for user-specified magnet geometry (spoke.mako) Source: https://femagtools.readthedocs.io/en/latest/models.html Example FSL template file 'spoke.mako' using 4 parameters (shaft_diam, magn_height, magn_width, slot_width) to define a spoke magnet geometry. It uses Mako syntax with ${} placeholders and references global values like da2, dy2, taup, etc. ```mako -- Model parameters ds = ${model['shaft_diam']}*1e3 hm = ${model['magn_height']}*1e3 bm = ${model['magn_width']}*1e3 ws = ${model['slot_width']}*1e3 -- calculate slot height and pole pitch hs = (da2-dy2)/2 - bm taup = math.pi/m.num_poles x = {} y = {} -- characteristic points of model ar = math.sqrt(dy2^2+hm^2)/2 x[1] = ar*math.cos(taup - math.atan2(hm/2, dy2/2)) y[1] = 0 x[2],y[2] = pr2c(dy2/2+bm, 0) x[3],y[3] = pr2c(da2/2, 0) x[4],y[4] = pr2c(da2/2, taup - math.atan2(ws/2,(da2/2))) x[5],y[5] = pr2c(da2/2-hs, taup - math.atan2(ws/2,(da2/2 - hs))) x[6],y[6] = pr2c(da2/2-hs, taup - math.atan2(hm/2, da2/2-hs)) x[7],y[7] = pr2c(ar, taup - math.atan2(hm/2, dy2/2)) x[8],y[8] = pr2c(dy2/2, taup) x[9],y[9] = pr2c(da2/2 - hs, taup) x[10],y[10] = pr2c(da2/2, taup) ``` -------------------------------- ### Magnet material definition example Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Defines a magnet material with name, remanence, and relative permeability. The name must be unique within the list and may be referenced in the magnet model. ```python magnets = [dict(name='MX-333', remanenc=1.2, relperm=1.05)] ``` -------------------------------- ### Define machine with FSL stator slot Source: https://femagtools.readthedocs.io/en/latest/models.html Example of a machine dictionary using a user-defined FSL file for stator geometry. The stator dictionary includes mcvkey_yoke and mcvkey_shaft set to 'dummy' and an empty mystator dictionary. The FSL file must exist and be readable. ```python machine = dict( name="Motor", ... stator=dict( mcvkey_yoke='dummy', mcvkey_shaft="dummy", mystator=dict() ), ... ) ``` -------------------------------- ### User-defined stator slots with DXF file (mystator.dxf) Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Defines a machine model with a stator that uses a DXF file for stator geometry. The stator dictionary includes mcvkey_yoke and a dxffile dictionary with name, position, and split options. The example is truncated with '...' indicating omitted parameters. ```python machine = dict( name="Motor", ... stator=dict( mcvkey_yoke='dummy', dxffile=dict( name="mystator.dxf", position='out', split=True ) ), ... ``` -------------------------------- ### Magnet material with nonlinear BH curve example Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Defines a magnet material using a nonlinear BH curve via mcvkey, with orientation and relative length. The mcvkey can reference a file or an entry in the magnetizing curve dict. ```python magnets=[dict(name='BH53M', mcvkey='BH53M', orient='mcartiso', rlen=1.0)] ``` -------------------------------- ### User-defined stator slots with FSL file (mystator.fsl) Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Defines a machine model with a stator that uses a user-defined FSL file for stator geometry. The stator dictionary includes mcvkey_yoke and mcvkey_shaft, and a mystator entry referencing the FSL file. The example is truncated with '...' indicating omitted parameters. ```python machine = dict( name="Motor", ... stator=dict( mcvkey_yoke='dummy', mcvkey_shaft="dummy", mystator=dict() ), ... ``` -------------------------------- ### Initialize Google Engine and Load Config Source: https://femagtools.readthedocs.io/en/latest/engine.html Initializes the Google engine and loads a configuration file. Requires Google credentials configured with the google command tool and a user with correct authority. ```python import femagtools engine = femagtools.google.Engine() # Load config file engine.config.from_ini_file('config.ini') ``` -------------------------------- ### Use femagtools Google Engine with config file Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Initializes the Google Engine and loads a configuration file. Requires femagtools and a config.ini file present. ```python import femagtools engine = femagtools.google.Engine() # Load config file engine.config.from_ini_file('config.ini') ``` -------------------------------- ### Create machine model from separate stator and rotor DXF files Source: https://femagtools.readthedocs.io/en/latest/models.html Configuration dictionary for creating a machine model using two separate DXF files: one for the stator and one for the rotor. The stator file is positioned 'out' and the rotor file 'in', both with split enabled. Material keys are placeholders. ```python machine = dict( name="Motor", lfe=0.001, stator=dict( mcvkey_yoke='dummy', dxffile=dict( name='mystator.dxf', position='out', split=True ) ), magnet=dict( mcvkey_yoke="dummy", mcvkey_shaft="dummy", dxffile=dict( name='myrotor.dxf', position='in', split=True ) ), ... ``` -------------------------------- ### Create a FE model from templates Source: https://femagtools.readthedocs.io/en/latest/_sources/intro.rst.txt Defines a machine dictionary with stator, magnet, and windings parameters, then creates an FSL file using femagtools.create_fsl. ```python machine = dict( name = "PM 130 L4", lfe = 0.1, poles = 4, outer_diam = 0.13, bore_diam = 0.07, inner_diam = 0.015, airgap = 0.001, stator = dict( num_slots = 12, mcvkey_yoke = "dummy", rlength = 1.0, stator1 = dict( slot_rf1 = 0.057, tip_rh1 = 0.037, tip_rh2 = 0.037, tooth_width = 0.009, slot_width = 0.003) ), magnet = dict( mcvkey_shaft = "dummy", mcvkey_yoke = "dummy", magnetSector = dict ( magn_num = 1, magn_width_pct = 0.8, magn_height = 0.004, magn_shape = 0.0, bridge_height = 0.0, magn_type = 1, condshaft_r = 0.02, magn_ori = 2, magn_rfe = 0.0, bridge_width = 0.0, magn_len = 1.0 ) ), windings = dict( num_phases = 3, num_wires = 100, coil_span = 3.0, num_layers = 1) ) fsl = femagtools.create_fsl(model) with open('femag.fsl', 'w') as f: f.write('\n'.join(fsl)) ``` -------------------------------- ### Get a superelement by element Source: https://femagtools.readthedocs.io/en/latest/intro.html Retrieves a superelement using the element's se_key and checks if the element is in the superelement's elements list. ```python >>> spel = isa.superelements[el.se_key] >>> el in spel.elements True ``` -------------------------------- ### Configure logging for long-running commands Source: https://femagtools.readthedocs.io/en/latest/intro.html Sets up basic logging to INFO level with a timestamp and message format. Recommended when executing long-running commands to monitor progress. ```python import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') ``` -------------------------------- ### Get node coordinates of an element Source: https://femagtools.readthedocs.io/en/latest/intro.html Retrieves the coordinates of the element's vertices and prints them. The output shows a list of (x, y) tuples. ```python >>> el_coords = [v.xy for v in el.vertices] >>> print(el_coords) [(0.036389999091625214, 1.142020034095026e-09), (0.03499503806233406, 0.0005893968627788126), (0.03500000014901161, 0.0)] ``` -------------------------------- ### Convert a BCH file to XML via command line Source: https://femagtools.readthedocs.io/en/latest/_sources/intro.rst.txt Converts a BCH file to XML using the command line module femagtools.bchxml. Creates a file with the same name but .xml extension. ```bash python -m femagtools.bchxml TEST_002.BCH ``` -------------------------------- ### Convert BCH file to XML via command line Source: https://femagtools.readthedocs.io/en/latest/intro.html Runs the femagtools.bchxml module as a script to convert a BCH file to XML. The output file is named TEST_002.xml. ```bash python -m femagtools.bchxml TEST_002.BCH ``` -------------------------------- ### Create Multi-Core Engine Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Instantiates the multi-core engine which uses a local process pool to manage calculation tasks. ```python engine = femagtools.multiproc.Engine() ``` -------------------------------- ### Create Amazon Engine with config file Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Instantiates the Amazon engine for executing FEMAG tasks in the Amazon EC2 cloud. Requires configured AWS credentials under ~/.aws/credentials. ```python import femagtools engine = femagtools.amazon.Engine(buckets=None, configfile='config.ini') ``` -------------------------------- ### Create FSL file with femagtools.create_fsl Source: https://femagtools.readthedocs.io/en/latest/intro.html Defines a PM 130 L4 machine model using nested dictionaries for stator, magnet, and windings, then creates an FSL file with femagtools.create_fsl and writes it to 'femag.fsl'. Opening this file in FEMAG generates the shown geometry. ```python machine = dict( name = "PM 130 L4", lfe = 0.1, poles = 4, outer_diam = 0.13, bore_diam = 0.07, inner_diam = 0.015, airgap = 0.001, stator = dict( num_slots = 12, mcvkey_yoke = "dummy", rlength = 1.0, stator1 = dict( slot_rf1 = 0.057, tip_rh1 = 0.037, tip_rh2 = 0.037, tooth_width = 0.009, slot_width = 0.003) ), magnet = dict( mcvkey_shaft = "dummy", mcvkey_yoke = "dummy", magnetSector = dict ( magn_num = 1, magn_width_pct = 0.8, magn_height = 0.004, magn_shape = 0.0, bridge_height = 0.0, magn_type = 1, condshaft_r = 0.02, magn_ori = 2, magn_rfe = 0.0, bridge_width = 0.0, magn_len = 1.0 ) ), windings = dict( num_phases = 3, num_wires = 100, coil_span = 3.0, num_layers = 1) ) fsl = femagtools.create_fsl(model) with open('femag.fsl', 'w') as f: f.write('\n'.join(fsl)) ``` -------------------------------- ### Magnet definition in Python file with mako include Source: https://femagtools.readthedocs.io/en/latest/models.html Defines a magnet with a spoke geometry in a Python file that includes a mako template. The parameters magn_height, shaft_diam, slot_width, and magn_width are set. The complete example is in stator1-spoke.py and spokefml.mako. ```python .. magnet=dict( mcvkey_yoke="dummy", spoke=dict( magn_height=0.008, shaft_diam=0.01, slot_width=0.004, magn_width=0.024 ) .. ``` -------------------------------- ### Use FSL file for user-defined slots with empty dict Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Shows how to use a user-defined FSL file for magnet geometry by providing an empty dict (myrotor) in the magnet section. The FSL file must exist and be readable. ```python machine = dict( name="Motor", ... magnet=dict( mcvkey_yoke='dummy', mcvkey_shaft="dummy", myrotor=dict() ), ... ``` -------------------------------- ### Separate DXF files for stator and rotor Source: https://femagtools.readthedocs.io/en/latest/_sources/models.rst.txt Use this snippet to define a motor geometry with separate DXF files for the stator and rotor. The stator DXF is positioned 'out' and the rotor 'in', both with split=True. Parameters are set automatically as in the single-file example. ```python machine = dict( name="Motor", lfe=0.001, stator=dict( mcvkey_yoke='dummy', dxffile=dict( name='mystator.dxf', position='out', split=True ) ), magnet=dict( mcvkey_yoke="dummy", mcvkey_shaft="dummy", dxffile=dict( name='myrotor.dxf', position='in', split=True ) ), ... ``` -------------------------------- ### Run FEMAG as a ZMQ service with ZmqFemag.send_fsl Source: https://femagtools.readthedocs.io/en/latest/femag.html Use this snippet to run FEMAG as a service over TCP/IP using ZMQ. It reads an FSL file, sends it to a ZmqFemag instance, and parses the returned strings as JSON. Requires a Femag version with ZMQ support. ```python with open('femag.fsl') as f: fslcmds = f.read() femag = femagtools.femag.ZmqFemag(5555, 'localhost') ret = femag.send_fsl(fslcmds) r = [json.loads(s) for s in ret] ``` -------------------------------- ### Inspect element properties in ISA7 file Source: https://femagtools.readthedocs.io/en/latest/_sources/intro.rst.txt Prints the magnetic and reluctance properties of an element. ```python >>> el.mag (0.8485281467437744, 0.8485281467437744) >>> el.reluc (0.9523810148239136, 0.9523810148239136) ``` -------------------------------- ### Execute parameter variations with femagtools Source: https://femagtools.readthedocs.io/en/latest/_sources/intro.rst.txt Sets up a parameter variation with objective variables for torque, ripple, and iron losses, and decision variable angl_i_up. Defines operating conditions, uses multiprocessing engine, and runs the grid. Results are stored in a dict with keys 'x' and 'f'. ```python parvar = { "objective_vars": [ {"name": "dqPar.torque[-1]"}, {"name": "torque[-1].ripple"}, {"name": "machine.plfe[-1]"}], "population_size": 3, "decision_vars": [ {"steps": 3, "bounds": [-50, 0], "name": "angl_i_up"} } operatingConditions = dict( angl_i_up=0.0, calculationMode="pm_sym_fast", wind_temp=60.0, magn_temp=60.0, current=50.0, speed=50.0) numcores = 3 engine = femagtools.multiproc.Engine(numcores) mcvDir = os.path.join( os.path.expanduser('~'), 'mcv') g = femagtools.grid.Grid(workdir, magnetizingCurves=mcvDir) results = g(parvar, pmMachine, operatingConditions, engine) ``` -------------------------------- ### Add Existing Google Buckets Source: https://femagtools.readthedocs.io/en/latest/engine.html Defines a list of existing Google buckets with their IDs and local folders. Use this if you have already uploaded FEMAG files to buckets. ```python buckets = [{'id': '926c39a7-db69-42f8-bf86-2fd1f8559188-0', 'folder': '~/parvar/0'}, {'id': '99ec9af5-ecb5-4029-88d6-70da9841ef91-1', 'folder': '~/parvar/1'}, {'id': '4c61ebb3-89df-4e3a-ba46-288f8e0672a6-2', 'folder': '~/parvar/2'}] ``` -------------------------------- ### Create Condor Engine Source: https://femagtools.readthedocs.io/en/latest/_sources/engine.rst.txt Instantiates the Condor engine which uses an HT Condor pool to manage calculation tasks in a corporate network. ```python engine = femagtools.condor.Engine() ``` -------------------------------- ### Read airgap data file and compute base harmonic with femagtools.airgap.read Source: https://femagtools.readthedocs.io/en/latest/_modules/femagtools/airgap.html The femagtools.airgap module defines the read() function, which loads an airgap data file with columns (phi, Br, Bphi) and returns a dictionary with the base harmonic amplitude, phase, position, and field values. It uses numpy for FFT analysis and handles incomplete files by returning an empty dict. The module also includes a command-line entry point that reads a filename from arguments or stdin and prints the Bamp value. ```python # -*- coding: utf-8 -*- """ femagtools.airgap ~~~~~~~~~~~~~~~~~ Read airgap dat file """ import sys import numpy as np import logging logger = logging.getLogger(__name__) [docs]def read(filename, taup): """read dat file with columns (phi, Br, Bphi) returns samples, values, amplitude and phase of base harmonic Args: filename: the name of the file to be processed taup: angle of a effective pole pair (urwicklung) in degrees """ bag = np.loadtxt(filename).T if len(bag) < 3: logger.warn("%s has incomplete content", filename) return(dict()) phi = bag[0] nsamples=len(phi) br = bag[1] phisteps = [phi[i+1] - phi[i] for i in range(len(phi)-1)] dphi = sum(phisteps)/len(phisteps) if round(phi[-1]/taup) < 1: br = np.append(br, -1*br) freq = np.fft.fftfreq(len(br), d=dphi) # compute FFT from induction Y = 2*np.fft.rfft(br)/len(br) # find the peak and interpolate i = np.argmax(abs(Y)) logger.debug("Len %d max phi %f max amp %f", len(phi), phi[-1], abs(Y[i])) if freq[i] > 0: logger.info("%s: Period %f max phi %f B amp %f", filename, 1/freq[i], len(br)*dphi, abs(Y[i])) a = abs(Y[i]) T0 = abs(1/freq[i]) x0 = np.angle(Y[i]) phi = [ix*dphi for ix in range(len(br))] x = np.array([2*x/T0*np.pi for x in phi]) return dict(Bamp=a, phi0=x0, pos=phi[:nsamples], B=br.tolist()[:nsamples], B_fft=(a*np.cos(x+x0)[:nsamples]).tolist()) if __name__ == "__main__": logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') if len(sys.argv) == 2: filename = sys.argv[1] else: filename = sys.stdin.readline().strip() print(read(filename)['Bamp']) ``` -------------------------------- ### Print node coordinates from ISA7 file Source: https://femagtools.readthedocs.io/en/latest/intro.html Accesses the first node and prints its x, y, and xy coordinates. The output shows the coordinate values. ```python >>> n = isa.nodes[0] >>> print(n.x) (0.03380740433931351) >>> print(n.y) (0.009058667346835136) >>> print(n.xy) (0.03380740433931351, 0.009058667346835136) ``` -------------------------------- ### Read an ISA7/I7 file Source: https://femagtools.readthedocs.io/en/latest/intro.html Reads an ISA7/I7 file using isa7.read. The filename extension is optional. ```python >>> isa = isa7.read('foo') ```