thliebig / openEMS

openEMS is a free and open-source electromagnetic field solver using the EC-FDTD method.
http://openEMS.de
GNU General Public License v3.0
453 stars 156 forks source link

Python/CSXCAD AddBox error #75

Closed mysol closed 3 years ago

mysol commented 3 years ago

Hello! I've got a problem with command CSX.AddBox in python wrapper... Compiler returns an error: Traceback (most recent call last): File "dipole.py", line 48, in <module> box=CSX.AddBox(substrate, priority=0, start=start, stop=stop ) AttributeError: 'CSXCAD.CSXCAD.ContinuousStructure' object has no attribute 'AddBox'

All examples have the same error with "AddBox"

thliebig commented 3 years ago

The syntax should be: box=substrate.AddBox(priority=0, start=start, stop=stop)

mysol commented 3 years ago

The syntax should be: box=substrate.AddBox(priority=0, start=start, stop=stop)

yes, it works fine, but... Screenshot from 2021-07-23 16-42-12 Screenshot from 2021-07-23 16-42-55

import os, tempfile
from pylab import *
from mpl_toolkits.mplot3d import Axes3D

from CSXCAD import CSXCAD

from openEMS.openEMS import openEMS
from openEMS.physical_constants import *

Sim_Path = os.path.join(tempfile.gettempdir(), 'dipole')

unit = 1e-3 # all length in mm

SimBox = np.array([200, 200, 150])

CSX = CSXCAD.ContinuousStructure()
mesh = CSX.GetGrid()
mesh.SetDeltaUnit(unit)

mesh.AddLine('x', linspace(-SimBox[0]/2, SimBox[0]/2, num=SimBox[0]))
mesh.AddLine('y', linspace(-SimBox[1]/2, SimBox[1]/2, num=SimBox[1]))
mesh.AddLine('z', linspace(-SimBox[2]/3, SimBox[2]*2/3, num=SimBox[2]))

patch_width  = 32 #
# patch length in y-direction
patch_length = 40
substrate_thickness = 1.524

patch = CSX.AddMetal( 'patch' ) # create a perfect electric conductor (PEC)
start = [-patch_width/2, -patch_length/2, substrate_thickness]
stop  = [ patch_width/2 , patch_length/2, substrate_thickness]
patch.AddBox(priority=10, start=start, stop=stop) # add a box-primitive to the metal property 'patch'

CSX_file = os.path.join(Sim_Path, 'simp_patch.xml')
if not os.path.exists(Sim_Path):
    os.mkdir(Sim_Path)
CSX.Write2XML(CSX_file)
os.system(r'AppCSXCAD "{}"'.format(CSX_file))

UPDATE: OMG, "sudo" solved this problem... I'll need to check this...

Thank You for support! And for this awesome project)