Using a Control Program in Maxwell 2D and 3D Transient Solutions

User control programs are externally created executable files, or Python (*.py) scripts that are called after each time step, and allow you to control the source input, circuit elements, mechanical quantities, time step, and stopping criteria, based on the updated solutions.

Note: The control program is executed from a temp directory that Maxwell creates for every setup run (For parametric setup a temp folder is create for each task). The solver copies a control program file with name <setup_name>.py for Python, or <setup_name>.ctrlprog for compiled program to the temp directory.

The user control program uses the file with fixed name user.ctl to output control parameters to control the execution of the transient solver. Each file must use a predefined syntax which is flexible enough to cover a wide range of items.

The process shown in the flowchart can be summarized as:

  1. The solver calls the user-control program on initialization.

  2. The user-control program writes control information to file user.ctl.

  3. The transient solver reads control parameters from user.ctl.
  4. The transient solver solves the current time step.
  5. The transient solver copies the previous solution to previous.ctl and writes out solution information to solution.ctl. If requested, the solver exports:

    • B, H, J fields (bfield.ctl, hfield.ctl, jfield.ctl, respectively)
    • A field afield.ctl (available in 2D and 3D A-Phi only)
    • Phi field phifield.ctl (available in 3D A-Phi only).
  6. Return to the transient solver if the control program succeeds with exit status 0 or fails with exit status non-zero.

  7. Return to step 1 for the next time step.

  8. (Optional) Call script after last time step for post processing. If user selects the Call after last time step for post processing check box (refer to Activating a Control Program in Transient Solutions), then the control program is called after the simulation is completed.

    If you use a Python control program, the script is called with --post flag

    (for example: my_script.py --post).

    For a compiled control programs the script is called with -post flag

    (for example: my_tool.exe -post).

Note: By default a control program script will be called by the pre-installed Python interpreter:
<install_path>\Win64\commonfiles\CPython\37\
winx64\Release\python\python.exe

however, the user can specify a custom python interpreter to be used by setting following environment variable:
EM_CTRL_PROG_PYTHON_PATH=<path_to\python.exe>

Related Topics 

Activating a Control Program in Transient Solutions

Control Program File Formats in Transient Solutions