Skip to content

andrrei509/quickfield-magnetostatics-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuickField Magnetostatics. Batch Result Extractor

Automatically extract B (magnetic flux density) and H (magnetic field intensity) from QuickField magnetostatic simulations, at multiple points, across multiple parameter sweeps, without clicking through the GUI one point at a time.

Python Platform License


Why?

When running magnetostatic simulations in QuickField you often need to:

  • Read B and H at many measurement points
  • Repeat this across multiple solver runs (different mesh densities, permeabilities, current densities, etc.)
  • Copy the values into a table for your report

Doing this manually through the QuickField GUI is slow and error prone. This script automates it:

  1. Connects to a running QuickField instance via COM
  2. Reads exact B and H at every point you define (same values as the GUI)
  3. Auto detects when you re-solve and prints updated tables instantly
  4. Optionally exports to CSV for easy spreadsheet import

One terminal, leave it running, re-solve as many times as you want → all tables printed automatically.


Installation

Prerequisites

  • Windows (QuickField is Windows-only)
  • QuickField with COM/ActiveField support (Student, Professional, or Full edition)
  • Python 3.8+

Setup

# Clone the repo
git clone https://github.com/andrrei509/quickfield-magnetostatics-extractor.git
cd quickfield-magnetostatics-extractor

# Install dependencies
pip install -r requirements.txt

Or just install the single dependency directly:

pip install pywin32

Quick Start

  1. Open your problem in QuickField and solve it
  2. Run the extractor:
python extract_results.py
  1. You'll see a table like this:
========================================================================
  Run #1  |  14:32:07  |  Mesh: 247 nodes
========================================================================
  Pt    (X, Y)          |B| [T]        |H| [A/m]
  ----  --------------  --------------  --------------
  P1    (+4.50,+0.00)   1.234567e-03    982.456123
  P2    (+2.75,+0.00)   5.678901e-03    4518.234567
  ...

  Pt    Bx [T]          By [T]          Hx [A/m]       Hy [A/m]
  ----  --------------  --------------  --------------  --------------
  P1    1.234000e-03    5.670000e-05    982.345000      45.123000
  ...
========================================================================
  1. Change parameters in QuickField (mesh, μᵣ, J, geometry, …), re-solve → new table appears automatically
  2. Ctrl+C to stop

Configuration

Defining measurement points

There are three ways to define where B and H are measured:

1. Command-line (quick & dirty)

python extract_results.py --points "A,1.0,0; B,0,1.0; C,-1.0,0; D,0,-1.0"

Format: Label,X,Y separated by semicolons.

2. JSON config file (recommended for reuse)

Create a file like my_points.json:

{
  "points": [
    { "label": "Center", "x": 0.0,  "y": 0.0  },
    { "label": "Top",    "x": 0.0,  "y": 5.0  },
    { "label": "Right",  "x": 5.0,  "y": 0.0  },
    { "label": "Bottom", "x": 0.0,  "y": -5.0 },
    { "label": "Left",   "x": -5.0, "y": 0.0  }
  ]
}

Then run:

python extract_results.py --config my_points.json

See points_example.json for a complete example.

3. Edit the script defaults

Modify the DEFAULT_POINTS list near the top of extract_results.py.

CSV export

Append results from every run to a CSV file:

python extract_results.py --csv results.csv

Each re-solve appends new rows with a run number and timestamp, perfect for importing into Excel.

Poll interval

Change how often the script checks for new results (default: 3 seconds):

python extract_results.py --interval 1

All options

usage: extract_results [-h] [--points POINTS] [--config CONFIG]
                       [--csv CSV] [--interval INTERVAL] [--version]

options:
  -h, --help            show this help message and exit
  --points, -p POINTS   Semicolon-separated points: "Label,X,Y; Label,X,Y"
  --config, -c CONFIG   Path to a JSON file with point definitions
  --csv CSV             Path to CSV file (results appended after each run)
  --interval, -i SECS   Polling interval in seconds (default: 3)
  --version, -V         show version and exit

How It Works

The script uses COM automation (via pywin32) to talk to QuickField's ActiveField API:

QuickField.Application
  └─ ActiveProblem
       └─ Result
            └─ GetLocalValues(point)
                 ├─ .Grad   → B vector (Bx, By) in Tesla
                 └─ .KGrad  → H vector (Hx, Hy) in A/m
  • Grad = gradient of the magnetic vector potential = B (flux density)
  • KGrad = reluctivity × gradient = H (field intensity)

These are the exact same values displayed in QuickField's postprocessor, no manual calculations, no approximations.

The script uses early binding (win32com.client.gencache.EnsureDispatch) which generates a Python type library from QuickField's COM interface. This gives proper IntelliSense and reliable property access.


Repository Structure

├── extract_results.py     # Main script
├── points_example.json    # Example point configuration
├── requirements.txt       # Python dependencies
├── LICENSE                # MIT License
├── .gitignore             # Git ignore rules
├── README.md              # This file
├── your_file.pbm          # Empty QuickField problem (replace with the files QuickField generates)
├── your_file.mod          # Empty QuickField model (replace with the files QuickField generates)
├── your_file.res          # Empty QuickField results (replace with the files QuickField generates)
└── your_file.dms          # Empty QuickField data (replace with the files QuickField generates)

Troubleshooting

Problem Solution
Cannot connect to QuickField Make sure QuickField is running with a problem loaded
No active problem Open a .pbm problem file in QuickField
Problem not solved yet Click Problem → Solve in QuickField
N/A for a point That point is outside the mesh, check your coordinates
ModuleNotFoundError: win32com Run pip install pywin32
COM cache errors Delete %LOCALAPPDATA%\Temp\gen_py and retry

Contributing

Contributions welcome. Some ideas:

  • Support for other QuickField problem types (electrostatics, heat transfer, …)
  • GUI wrapper (tkinter/PyQt)
  • Plotting with matplotlib
  • Support for contour/line integrals, not just point values

License

MIT (use it however you want)


Acknowledgments

Built for the FEE3 (Fundamentals of Electrical Engineering) labs, but designed to be useful for anyone working with QuickField magnetostatics.

About

QuickField Magnetostatics problem table generator

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages