Femagtools Package

femagtools

Python bindings for FEMAG

copyright:2016 Semafor Informatik & Energie AG, Basel
license:BSD, see LICENSE for more details.

Basic Classes

class femagtools.Femag(workdir, cmd=None, magnetizingCurves=None, magnets=None)[source]

Invoke and control execution of FEMAG

Parameters:
  • workdir – name of working directory
  • cmd – name of femag program
  • magnetizingCurves – collection of lamination material curves
  • magnets – collection of magnet material
cleanup()[source]

removes all created files in workdir

run(filename, options=['-b'], fsl_args=[])[source]

invoke FEMAG in current workdir

Parameters:
  • filename – name of file to execute
  • options – list of FEMAG options
  • fsl_args – list of FSL argument options
Raises:

FemagError

class femagtools.model.MachineModel(parameters)[source]

represents a machine model for a FE analysis

Parameters:parameters – string or dict containing the model parameters. For example:
{'lfe': 0.1,
'poles': 4,
'outer_diam': 0.13,
'bore_diam': 0.07,
'stator':{
'num_slots': 12,
'num_slots_gen': 3,
...
},
'magnet':{
    'material': 'M395',
    ..
}
}

if parameters is string it is interpreted as the model name. 
is_complete()[source]

check completeness of models

magnettype()[source]

return type of magnet slot

set_magcurves(magcurves, magnetmat={})[source]

set and return real names of magnetizing curve material

Parameters:magcurves
class:’MagnetizingCurve’ including

magnetizing curve materials

Returns:set of magnetizing curve names attached to this model
statortype()[source]

return type of stator slot

class femagtools.mcv.MagnetizingCurve(mcvpar)[source]
find(id)[source]

find mcv by id or name

find_by_name(name)[source]

find mcv by name

writefile(name, directory='.', writeproc='')[source]

find magnetic curve by name or id and write binary file returns filename if found else None

class femagtools.fsl.Builder[source]
create(model, fea, magnets=None)[source]

create model and analysis function

create_connect_models(model)[source]

return connect_model if rotating machine

read(fslfile)[source]

extracts parameters from content and creates template

Calculation Engines

class femagtools.job.Job(basedir)[source]

represents a FEMAG job consisting of one or more tasks each to be executed by a dedicated process

add_task()[source]

adds a new task to this job

cleanup()[source]

removes all files and directories of previous run

setExitStatus(taskid, status)[source]

set exit status of task

class femagtools.job.CloudJob(basedir)[source]

Inheritance of Job

Represents a femag amazon job

add_task()[source]

adds a new AmazonTask to this job

class femagtools.job.Task(id, directory)[source]

represents a single execution unit that may include data files

add_file(fname, content=None)[source]

adds a file required by this task :param fname: file name :param content: list of str written to file if not None

get_results()[source]

returns result of most recent BCH file

class femagtools.job.CloudTask(id, directory)[source]
class femagtools.multiproc.Engine(cmd=None, process_count=None)[source]

The MultiProc engine uses a pool of local calculation processes.

This is more or less a decorator for the Python multiprocessing Module

Parameters:
  • cmd – the program (executable image) to be run (femag dc is used if None)
  • process_count – number of processes (cpu_count() if None)
create_job(workdir)[source]

Create a FEMAG Job

Parameters:workdir – The workdir where the calculation files are stored
Returns:FEMAG Job
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error)
submit()[source]

Starts the FEMAG calculation(s) with the internal multiproc.run_femag() function

Returns:length of started tasks
multiproc.run_femag(workdir, fslfile)

Start the femag command as subprocess.

Internal:
Parameters:
  • cmd – The program (executable image) to be run
  • workdir – The workdir where the calculation files are stored
  • fslfile – The name of the start file (usually femag.fsl)
class femagtools.amazon.Engine(buckets=None, configfile='config.ini')[source]
create_job(workdir)[source]

Create a FEMAG CloudJob

Parameters:workdir (str) – The workdir where the calculation files are stored
Returns:Cloud job
Return type:CloudJob
default_config = {'COMPANY_NAME': 'femag', 'IMAGE_ID': 'ami-b0cc23df', 'ACL': 'authenticated-read', 'SERVER_LOCATION': 'eu-central-1', 'INSTANCE_TYPE': 't2.micro', 'ENGINE': 'amazon', 'FINISH_TASK_FILENAME': 'exit_code'}

The Amazon Engine

This enginge uses the boto3 Python module to interact
with the amazon ec2 and s3 services
Parameters:
  • buckets (list) – Existing buckets with femag calculation files
  • configfile (str) – Filename of config file
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error)
Return type:list
submit()[source]

Starts the FEMAG calculation(s) on Amazon

Returns:length of started tasks
Return type:int
class femagtools.google.Engine(buckets=None)[source]
create_job(workdir)[source]

Create a FEMAG CloudJob

Parameters:workdir (str) – The workdir where the calculation files are stored
Returns:Cloud job
Return type:CloudJob
join()[source]

Wait until all calculations are finished

Returns:list of all calculations status (C = Ok, X = error)
Return type:list
submit()[source]

Starts the FEMAG calculation(s) on Google Cloud

Returns:length of started tasks
Return type:int

Parameter Variation and Optimization

class femagtools.grid.Grid(workdir, magnetizingCurves=None, magnets=None)[source]

Parameter variation calculation

class femagtools.opt.Optimizer(workdir, magnetizingCurves, magnetMat)[source]