Field integrals from magnetic solution

General discussion about Elmer
Post Reply
tobin
Posts: 7
Joined: 31 Mar 2023, 06:46
Antispam: Yes

Field integrals from magnetic solution

Post by tobin »

Hi folks,

I'm not sure whether this is better addressed in the solver or a post-processing step, hence I have put this in general.

I'm doing 3D magnetostatics — preparing a mesh with Gmsh and solving using the "WhitneyAVSolver". That's all great.

I would like to calculate some field integrals down some curves/lines. They could be in the mesh or defined later, e.g. using polylines. I want to calculate the integral of the flux density down these curves/lines, for example: ∫ By ds

What's the best way to achieve this? Any pointers appreciated!
tobin
Posts: 7
Joined: 31 Mar 2023, 06:46
Antispam: Yes

Re: Field integrals from magnetic solution

Post by tobin »

I investigated using the "SaveLine" solver. I have had some success but I generally require many lines (~100s) to be calculated and I couldn't work out an elegant way to script this. For the moment, I am saving the solution in a ".vtu" file and post-processing in python. I am extracting integrals using code such as:

Code: Select all

import vtk

# Open solution
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(filename)
reader.Update()

# Create line
line_source = vtk.vtkLineSource()
line_source.SetPoint1(x1, y1, z1)
line_source.SetPoint2(x2, y2, z2)
line_source.SetResolution(num_points)
line_source.Update()

# Interpolate the field values on the line
probe_filter = vtk.vtkProbeFilter()
probe_filter.SetSourceData(reader.GetOutput())
probe_filter.SetInputData(line_source.GetOutput())
probe_filter.Update()

# Integrate the field along the line
integrate_filter = vtk.vtkIntegrateAttributes()
integrate_filter.SetInputData(probe_filter.GetOutput())
integrate_filter.Update()

# Get the integrated result
result = integrate_filter.GetOutput().GetPointData().GetArray("magnetic flux density e")
int_bx, int_by, int_bz = result.GetTuple(0)
This seems to work pretty well. Unsolved problems are:
  1. I would like to include these lines in the mesh so that I am interpolating straight down mesh edges. I am unable to do this so far with gmsh -- I define "Physical Curves" in the geo file, but they disappear in the meshing step. This is probably a question for the gmsh forum.
  2. My model has symmetry, and when I calculate integrals on the boundary, there is significant error. I'm not sure how to improve results when they are co-incident with a solution boundary.
Post Reply