Git Product home page Git Product logo

csxcad's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

csxcad's Issues

Python binding fails to compile: CSXCAD/CSPrimitives.pxd:22:0: 'ParameterObjects.pxd' not found

Cython fails to find *.pxd files in CSXCAD for some reason:

Error compiling Cython file:
------------------------------------------------------------
...
#

from libcpp.string cimport string
from libcpp cimport bool

from ParameterObjects cimport _ParameterSet, ParameterSet
^
------------------------------------------------------------

CSXCAD/CSPrimitives.pxd:22:0: 'ParameterObjects.pxd' not found

Error compiling Cython file:
------------------------------------------------------------
...
#

from libcpp.string cimport string
from libcpp cimport bool

from ParameterObjects cimport _ParameterSet, ParameterSet
^
------------------------------------------------------------

CSXCAD/CSPrimitives.pxd:22:0: 'ParameterObjects/_ParameterSet.pxd' not found

Python interface in Python 3 crashes with: has no attribute '__reduce_cython__'

Hi,

The Python 2 interface seems to work well, but when building it for Python 3, it crashes like this:

>>> import CSXCAD
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/CSXCAD/__init__.py", line 7, in <module>
    from CSXCAD.CSXCAD import ContinuousStructure
  File "CSXCAD/CSXCAD.pyx", line 53, in init CSXCAD.CSXCAD
AttributeError: type object 'CSXCAD.CSXCAD.ContinuousStructure' has no attribute '__reduce_cython__'
>>> 

It would be nice to have a working Python 3 interface since Python 2 is soon End Of Life - and Python 3 is so much nicer.

Python binding fails: Cython directive 'language_level' not set, using 2 for now (Py2); 'CSXCAD/CSXCAD/ContinuousStructure.pxd' not found; etc

ompiling openEMS/_nf2ff.pyx because it changed.
Compiling openEMS/openEMS.pyx because it changed.
[1/2] Cythonizing openEMS/_nf2ff.pyx
/usr/local/lib/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /disk-samsung/freebsd-ports/science/py-openems/work-py38/openEMS-0.0.35-71-g4c24b6e/python/openEMS/_nf2ff.pxd
  tree = Parsing.p_module(s, pxd, full_module_name)
[2/2] Cythonizing openEMS/openEMS.pyx
/usr/local/lib/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /disk-samsung/freebsd-ports/science/py-openems/work-py38/openEMS-0.0.35-71-g4c24b6e/python/openEMS/openEMS.pxd
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
#

from libcpp.string cimport string
from libcpp cimport bool

from CSXCAD.CSXCAD cimport _ContinuousStructure, ContinuousStructure
^
------------------------------------------------------------

openEMS/openEMS.pxd:22:0: 'CSXCAD/CSXCAD.pxd' not found

Error compiling Cython file:
------------------------------------------------------------
...
#

from libcpp.string cimport string
from libcpp cimport bool

from CSXCAD.CSXCAD cimport _ContinuousStructure, ContinuousStructure
^
------------------------------------------------------------

openEMS/openEMS.pxd:22:0: 'CSXCAD/CSXCAD/_ContinuousStructure.pxd' not found

Error compiling Cython file:
------------------------------------------------------------
...
#

from libcpp.string cimport string
from libcpp cimport bool

from CSXCAD.CSXCAD cimport _ContinuousStructure, ContinuousStructure
^
------------------------------------------------------------

openEMS/openEMS.pxd:22:0: 'CSXCAD/CSXCAD/ContinuousStructure.pxd' not found

Error compiling Cython file:
------------------------------------------------------------
...

cdef extern from "openEMS/openems.h":
    cdef cppclass _openEMS "openEMS":
        _openEMS() nogil except +
        void SetNumberOfTimeSteps(unsigned int val)
        void SetCSX(_ContinuousStructure* csx)
                   ^
------------------------------------------------------------

openEMS/openEMS.pxd:28:20: '_ContinuousStructure' is not a type identifier

Python-3.8

libCSXCAD.so.0.6.2 doesn't have a SONAME

====> Running Q/A tests (stage-qa)
Warning: /disk-samsung/freebsd-ports/cad/csxcad/work/stage/usr/local/lib/libCSXCAD.so.0.6.2 doesn't have a SONAME.
Warning: pkg(8) will not register it as being provided by the port.
Warning: If another port depend on it, pkg will not be able to know where it comes from.
Warning: It is directly in /usr/local/lib, it is probably used by other ports.

INSTALL and CSXCAD.pro files not updated

Now new way to build CSXCAD exists, but it is not mentioned in INSTALL file.
CSXCAD.pro still contains old version number 0.5.2. if qmake still can be used, please update.
If so, please add include dirs for vtk-6.2 and 6.3 (recent).

SmoothMeshLines2 division by zero messages

I am using openEMS_0.0.31_x64 with Octave3.6.4_gcc4.6.2 on a Windows 7 machine
I get warning: division by zero messages (and occasional crashes) with the following code:

%SmoothMeshLines2 bug
% I originally found the problem with the following array:
%mesh.x=[];
%mesh.x=[mesh.x -225.00000 -75.50000 -74.50000 -71.50000];
%mesh.x=[mesh.x -70.50000 -65.75000 -64.75000 -58.00000];
%mesh.x=[mesh.x -57.00000 -51.75000 -50.75000 -44.25000];
%mesh.x=[mesh.x -43.25000 -3.50000 -2.50000 -0.50000];
%mesh.x=[mesh.x 0.50000 2.50000 3.50000 43.25000];
%mesh.x=[mesh.x 44.25000 50.75000 51.75000 57.00000];
%mesh.x=[mesh.x 58.00000 64.75000 65.75000 70.50000];
%mesh.x=[mesh.x 71.50000 74.50000 75.50000 225.00000];
%mesh2.x= SmoothMeshLines2(mesh.x,40);

% but I can generate an error with as little as:
mesh.x=[-3.50000 -2.50000 -0.50000 0.50000];
mesh2.x= SmoothMeshLines2(mesh.x,40);

Python interface build process cannot find necessary headers

Certain python distributions (namely the one provided by Homebrew on macOS) do not provide the system include paths when building the python bindings, resulting in build failure.

See thliebig/openEMS-Project#167 (reply in thread) for more details.

Possible fixes

  • Figure out a cross-platform way of finding the default system include paths and specify them explicitly
  • Modify the compiler flags (in a way supported by both clang and gcc) so that system include paths will not be overwritten
  • Modify the directory structure (or use a symlink) so that header files are present in the same directory as the python input files
  • Modify references to headers to use headers in the repository via a relative path

Also thliebig/openEMS#135

Build fails: Found relative path while evaluating include directories of "CSXCAD":

-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
fparser_INCLUDE_DIR
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
   used as include directory in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src
fparser_LIBRARIES
    linked by target "CSXCAD" in directory /usr/ports/science/csxcad/work/CSXCAD-0.6.2-93-gef6e409/src

CMake Warning (dev) in src/CMakeLists.txt:
  Policy CMP0021 is not set: Fatal error on relative paths in
  INCLUDE_DIRECTORIES target property.  Run "cmake --help-policy CMP0021" for
  policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.

  Found relative path while evaluating include directories of "CSXCAD":

    "fparser_INCLUDE_DIR-NOTFOUND"

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CXX_FLAGS_DEBUG
    CMAKE_C_FLAGS_DEBUG
    CMAKE_C_FLAGS_RELEASE
    CMAKE_VERBOSE_MAKEFILE


CMake Generate step failed.  Build files cannot be regenerated correctly.

The build doesn't link binaries with libhdf5.so

CMakeLists.txt contains:

set(HDF5_INCLUDE_DIRS "${LOCALBASE}/include")
set(HDF5_LIBRARY_DIRS "${LOCALBASE}/lib")

instead of looking it up with pkgconfig.

In the end binaries aren't linked with libhdf5.so

Building on Enterprise Linux 8 (RHEL/Alma/Oracle/Rocky)

The following patch is required for systems running python 3.6. (I would set up a pull request, but I am unable to do that at the moment.)

diff --git a/python/setup.py b/python/setup.py
index 30b7feb..c8c6c05 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -32,5 +32,5 @@ setup(
   url = 'https://openEMS.de',
   packages=["CSXCAD", ],
   package_data={'CSXCAD': ['*.pxd']},
-  ext_modules = cythonize(extensions, language_level="3")
+  ext_modules = cythonize(extensions, language_level=3)
  )

this prevents errors like the following:

Traceback (most recent call last):
  File "setup.py", line 46, in <module>
    ext_modules = cythonize(extensions, language_level = "3")
  File "/usr/lib64/python3.6/site-packages/Cython/Build/Dependencies.py", line 888, in cythonize
    ctx = c_options.create_context()
  File "/usr/lib64/python3.6/site-packages/Cython/Compiler/Main.py", line 596, in create_context
    self.cplus, self.language_level, options=self)
  File "/usr/lib64/python3.6/site-packages/Cython/Compiler/Main.py", line 94, in __init__
    self.set_language_level(language_level)
  File "/usr/lib64/python3.6/site-packages/Cython/Compiler/Main.py", line 100, in set_language_level
    if level >= 3:

Unused primitive error

Since the commit 418a8a9 I get unused primitive errors for overlapping cylinder primitives. It affects cases where a coaxial cable is created and a cylinder is connected to the end to connect the coaxial line to PCB board. Maybe these changes affected something else. I will try to create a test case.

Why is a cylinder primitive unused when there are no mesh line at the edges? Even when there are enough fine grid cells inside the cylinder it is not used.

Reading Discrete Material fails with inappropriate type

Trying to read a xml file incoorpoorating a discrete Material ends up with:

  ---------------------------------------------------------------------- 
 | openEMS 64bit -- version v0.0.35
 | (C) 2010-2018 Thorsten Liebig <[email protected]>  GPL license
 ---------------------------------------------------------------------- 
	Used external libraries:
		CSXCAD -- Version: v0.6.2
		hdf5   -- Version: 1.10.4
		          compiled against: HDF5 library version: 1.10.4
		tinyxml -- compiled against: 2.6.2
		fparser
		boost  -- compiled against: 1_71
		vtk -- Version: 7.1.1
		       compiled against: 7.1.1

openEMS - disabling simulation => preprocessing only
openEMS - dumping material to 'material_dump.vtk'
openEMS - dumping PEC info to 'PEC_dump.vtk'
openEMS - dumping boxes to 'box_dump*.vtk'
openEMS - verbose level 2
Read openEMS xml file: simp_patch2.xml ...
Read openEMS Settings...
Read Geometry...
ReadHDF5: Reading "test_linux.hdf5"
ReadDataSet: Error, unknown data type
ReadHDF5: Error, failed to read or invalid mesh, abort...
HDF5-DIAG: Error detected in HDF5 (1.10.4) thread 140206025398080:
  #000: ../../../src/H5F.c line 668 in H5Fclose(): closing file ID failed
    major: File accessibilty
    minor: Unable to close file
  #001: ../../../src/H5Fint.c line 2033 in H5F__close(): invalid file identifier
    major: File accessibilty
    minor: Inappropriate type
Warning: Unknown Property found!!!

Trying to debug this its seems that the defines (e.g. H5T_NATIVE_FLOAT) of the h5t.h has values in the 64 bit Range. where as the type_id is UINT8. This seems to crash loading the discrete Material.

If tried this with aptitude Version of openEMS and the a self compiled Version on centOS8 using VTK 8.1 both on x86_64 archs. The result is comparative. The Windows version seems not to be affected.

Any hints?

Complete round-tripping CSXCAD files: Write2XML / ReadFromXML and CSPropLumpedElement vs LumpedPort

I want to round-trip openEMS simulations via CSXCAD files stored via Write2XML and re-created using ReadFromXML.

Doing so required me to create a custom class LumpedPortExt - code is below.

I have tested this with the CSXCAD created from the tutorial "Simple Patch" antenna: https://gist.github.com/oberstet/cf93ac19332ccbedeb1d414b461b9692

There is only a minor question left, pls see FIXME in the code below.

Should there be interest in merging, please let me know, I could push a PR.

Otherwise this might still help other users, hence I am posting this as an issue.


There is a problem doing so, since a CSXCAD.CSProperties.CSPropLumpedElement and other elements are stored in CSXCAD, but NOT the openEMS.ports.LumpedPort (as its own serialized object refering to the 4 objects created).

When originally calling AddLumpedPort, e.g. as in Simple Patch Antenna

# apply the excitation & resist as a current source
start = [feed_pos, 0, 0]
stop = [feed_pos, 0, substrate_thickness]
port = FDTD.AddLumpedPort(1, feed_R, start, stop, "z", 1.0, priority=5, edges2grid="xy")

this will actually create 4 objects in the CSXCAD continuous structure

  • port_resist_1
  • port_excite_1
  • port_ut_1
  • port_it_1

which gets serialized into XML via Write2XML like so

        <LumpedElement ID="3" Name="port_resist_1" Direction="2" Caps="1" R="5.000000e+01" C="nan" L="nan" LEtype="-1.000000e+00">
            <FillColor R="205" G="186" B="171" a="255" />
            <EdgeColor R="205" G="186" B="171" a="255" />
            <Primitives>
                <Box Priority="5">
                    <P1 X="-6.000000e+00" Y="0.000000e+00" Z="0.000000e+00" />
                    <P2 X="-6.000000e+00" Y="0.000000e+00" Z="1.524000e+00" />
                </Box>
            </Primitives>
        </LumpedElement>
        <Excitation ID="4" Name="port_excite_1" Number="0" Frequency="0.000000e+00" Delay="0.000000e+00" Type="0" Excite="0.000000e+00,0.000000e+00,-1.000000e+00" PropDir="0.000000e+00,0.000000e+00,0.000000e+00">
            <FillColor R="242" G="251" B="227" a="255" />
            <EdgeColor R="242" G="251" B="227" a="255" />
            <Primitives>
                <Box Priority="5">
                    <P1 X="-6.000000e+00" Y="0.000000e+00" Z="0.000000e+00" />
                    <P2 X="-6.000000e+00" Y="0.000000e+00" Z="1.524000e+00" />
                </Box>
            </Primitives>
            <Weight X="1.000000e+00" Y="1.000000e+00" Z="1.000000e+00" />
        </Excitation>
        <ProbeBox ID="5" Name="port_ut_1" Number="0" Type="0" Weight="-1" NormDir="-1" StartTime="0" StopTime="0">
            <FillColor R="70" G="124" B="194" a="255" />
            <EdgeColor R="70" G="124" B="194" a="255" />
            <Primitives>
                <Box Priority="0">
                    <P1 X="-6.000000e+00" Y="0.000000e+00" Z="0.000000e+00" />
                    <P2 X="-6.000000e+00" Y="0.000000e+00" Z="1.524000e+00" />
                </Box>
            </Primitives>
        </ProbeBox>
        <ProbeBox ID="6" Name="port_it_1" Number="0" NormDir="2" Type="1" Weight="1" StartTime="0" StopTime="0">
            <FillColor R="84" G="248" B="27" a="255" />
            <EdgeColor R="84" G="248" B="27" a="255" />
            <Primitives>
                <Box Priority="0">
                    <P1 X="-6.000000e+00" Y="0.000000e+00" Z="7.620000e-01" />
                    <P2 X="-6.000000e+00" Y="0.000000e+00" Z="7.620000e-01" />
                </Box>
            </Primitives>
        </ProbeBox>

However, when reading in such XML again via ReadFromXML, this will re-create the 4 individual objects

  • port_resist_1
  • port_excite_1
  • port_ut_1
  • port_it_1

but it will not re-created a LumpedPort!!

Specifically, it will create a CSXCAD.CSProperties.CSPropLumpedElement but NOT a openEMS.ports.LumpedPort


from typing import List

import numpy as np

from CSXCAD import ContinuousStructure
from CSXCAD.CSProperties import CSProperties, CSPropLumpedElement
from CSXCAD.CSPrimitives import CSPrimBox
from CSXCAD.Utilities import CheckNyDir
from openEMS.ports import LumpedPort


class LumpedPortExt(LumpedPort):
    """
    Extension class for ``LumpedPort`` which allows to instantiate a lumped port from
    the CSXCAD continuous structure (as serialized in CSXCAD XML files) based on the
    port number only, and assuming element names like openEMS creates.

    For example, when creating a ``LumpedPort`` with ``port_nr == 1``, this will create
    the following **four** CSXCAD objects (assuming no ``PortNamePrefix`` is used):

    - a *LumpedElement* element named ``"port_resist_1"``
    - an *Excitation* element named ``"port_excite_1"``
    - a *ProbeBox* element named ``"port_ut_1"``
    - a *ProbeBox* element named ``"port_it_1"`

    .. seealso::
        - `openEMS.openEMS.AddLumpedPort <https://docs.openems.de/python/openEMS/openEMS.html#openEMS.openEMS.AddLumpedPort>`_  # noqa
        - `openEMS.ports.LumpedPort <https://docs.openems.de/python/openEMS/ports.html#openEMS.ports.LumpedPort>`_
    """

    def __init__(self, CSX: ContinuousStructure, port_nr: int, **kw):
        """

        :param CSX: continuous structure
        :param port_nr: port number
        """
        if "PortNamePrefix" in kw:
            prefix = kw["PortNamePrefix"]
        else:
            prefix = ""
        lbl_temp = prefix + "port_{}" + "_{}".format(port_nr)

        elm_name = lbl_temp.format("resist")
        elm_props: List[CSProperties] = CSX.GetPropertiesByName(elm_name)

        if len(elm_props) != 1:
            raise RuntimeError(
                'unexpected element count {} for property "{}" - there must be exactly 1'.format(
                    len(elm_props), elm_name
                )
            )

        elm_prop: CSProperties = elm_props[0]
        elm_type = elm_prop.GetTypeString()

        match elm_type:
            case "LumpedElement":
                port: CSPropLumpedElement = elm_prop  # noqa
                assert port.GetQtyPrimitives() == 1
                pbox: CSPrimBox = port.GetAllPrimitives()[0]

                # FIXME:
                #  How to get this stuff from a CSPropLumpedElement originally created from a LumpedPort, and
                #    saved to  CSXCAD file?
                #  This isn't stored in CSXCAD at all, right?
                excite = 1.0
                if "priority" not in kw:
                    kw["priority"] = 5

                # we cannot just call our direct base class constructor, since that will create new
                # object in the CSX continuous structure - which we do not want, since the premise is
                # our CSX has already all objects, e.g. like what ReadFromXML() does create. we _only_ want
                # to create a LumpedPort Python side wrapping object
                #
                # super(LumpedPortExt, self).__init__(
                #     CSX,
                #     port_nr=port_nr,
                #     R=port.GetResistance(),
                #     start=pbox.GetStart(),
                #     stop=pbox.GetStop(),
                #     exc_dir=port.GetDirection(),
                #     **kw,
                # )
                #
                # because of above, we call the indirect base constructor (Port.__init__) and
                # manually initialize the LumpedPort object
                #
                super(LumpedPort, self).__init__(
                    CSX, port_nr=port_nr, start=pbox.GetStart(), stop=pbox.GetStop(), excite=excite, **kw
                )
                self.R = port.GetResistance()
                self.exc_ny = CheckNyDir(port.GetDirection())
                self.direction = np.sign(self.stop[self.exc_ny] - self.start[self.exc_ny])
                if not self.start[self.exc_ny] != self.stop[self.exc_ny]:
                    raise Exception("LumpedPort: start and stop may not be identical in excitation direction")
                self.U_filenames = [
                    self.lbl_temp.format("ut"),
                ]
                self.I_filenames = [
                    self.lbl_temp.format("it"),
                ]

            case "Metal":
                raise NotImplementedError("Metal property not implemented")
            case _:
                raise RuntimeError('unexpected property type "{}" for property "{}"'.format(elm_type, elm_name))

Understanding how primitives are picked up by mesh lines

Hi Thorsten, this is more of a question rather than a technical issue/bug, but since the forum is down at the moment, I thought I'd ask here (sorry for the long question - thought I'd try to be as thorough as possible 🙂):

I'm having a hard time understanding how openEMS "detects" shapes. Specifically, I'm only working with STLs that realistically represent the actual geometry model. E.g. a microstrip patch antenna will have a patch and ground plane microstrip thickness of 35 μm instead of being flat faces, and it is the goal of my mesh-generation algorithm to figure out precisely where to sample each mesh line.

While I've made quite a bit of progress on my automatic mesh-generation algorithm (which I'm hoping to contribute with), I've reached a point where I'm having a hard time understanding where certain mesh lines have to be placed on the model so that openEMS does not spit out Warning: Unused primitive detected in property: ... (which appears to be derived from here).

Here's an example: let's say you're given a realistic model of a patch antenna (where all objects are 3D volumes; no 2D surfaces). Where exactly on the model must you place lines, so that all 3 shapes (patch, substrate and ground plane) are properly detected?

image

One solution would obviously sample a line on the edge of every shape (with possibly a few more lines on the substrate to sample its thickness). However, that would imply that you end up with extremely narrow cells for the PEC thickness (patch and ground plane), yielding a tiny timestep.

What I've observed that typically works is sampling a single line right in the middle of ~35 μm microstrip traces, like so:
image

But this creates a few minor problems when it comes to algorithmically handling this detection and midpoint resampling (though I've already partially achieved this). Other times, sampling a single line at the edge of a trace also works, but not always, and it is unclear to me when a primitive becomes "unused" due to poor line sampling. Could you please comment on how CSXCAD/openEMS handles that?

Other proprietary software (like CST in this case) appear to handle such cases by only sampling one edge of thin PEC traces (which is easier in terms of automatic mesh generation, but it's unclear how their "CSXCAD"-equivalent geometry engine handles the representation of thin traces):
image

I think something that might be useful is for openEMS to look at the content of a cell (not just the edge/line), and determine what material it should be set to. That way (unless you've set the priority of the primitive low enough to be dominated by another primitive), you would never see primitives become "unused", as there would always be cells occupying that particular material.

One idea I haven't tried is to fill up the entire model with a dummy material representing air/vacuum (ε_r = 1) and set a low priority, so that the metals and dielectrics would be above in priority, and thus detected? Any idea if this idea is sensible at all?

I've also had a similar issue where the ridges of a horn antenna model were thin, and the mesh could only pick it up in certain spots (not yielding an Unusued primitive error):

e_field

But once I made the ridge thicker, it was properly picked up by the mesh:

e_field-1

Many thanks again for your time - really really appreciate it!

compiling issue with vtk 9.0

[  5%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPrimPolyhedronReader.cpp.o
[  5%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPropLumpedElement.cpp.o
[  7%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPropMetal.cpp.o
[ 10%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPropDiscMaterial.cpp.o
[ 12%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPropConductingSheet.cpp.o
[ 15%] Building CXX object src/CMakeFiles/CSXCAD.dir/CSPropExcitation.cpp.o
/home/spel/Downloads/CSXCAD/src/CSPrimPolyhedronReader.cpp: In member function ‘virtual bool CSPrimPolyhedronReader::ReadFile()’:
/home/spel/Downloads/CSXCAD/src/CSPrimPolyhedronReader.cpp:167:34: error: cannot bind non-const lvalue reference of type ‘const vtkIdType*&’ {aka ‘const long long int*&’} to an rvalue of type ‘const vtkIdType*’ {aka ‘const long long int*’}
  167 |  while (verts->GetNextCell(numP, vertices))
      |                                  ^~~~~~~~
In file included from /usr/local/include/vtk-9.0/vtkPolyData.h:69,
                 from /usr/local/include/vtk-9.0/vtkPolyDataAlgorithm.h:36,
                 from /usr/local/include/vtk-9.0/vtkAbstractPolyDataReader.h:34,
                 from /usr/local/include/vtk-9.0/vtkSTLReader.h:38,
                 from /home/spel/Downloads/CSXCAD/src/CSPrimPolyhedronReader.cpp:24:
/usr/local/include/vtk-9.0/vtkCellArray.h:1497:73: note:   initializing argument 2 of ‘int vtkCellArray::GetNextCell(vtkIdType&, const vtkIdType*&)’
 1497 | inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
      |                                                       ~~~~~~~~~~~~~~~~~~^~~
make[2]: *** [src/CMakeFiles/CSXCAD.dir/build.make:323: src/CMakeFiles/CSXCAD.dir/CSPrimPolyhedronReader.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:94: src/CMakeFiles/CSXCAD.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

is there any easy solution for this?

Bug: Polyhedron IsInside() only works after calling Update()?

Hi,

I just discovered, that polyhedron.IsInside(coord) returns False even if the coord is inside the polyhedron.

Only after calling polyhedron.Update(), the function works as expected.

I think, this may be a bug.

Script to reproduce:

#!/usr/bin/python

import numpy as np
import CSXCAD

cs = CSXCAD.ContinuousStructure()

metal = cs.AddMetal("METAL")
ph = metal.AddPolyhedron()

for phi in [0, 2*np.pi/3, -2*np.pi/3]:
    ph.AddVertex(np.cos(phi), np.sin(phi), -1.0)

ph.AddVertex(0, 0, 1)

ph.AddFace([0, 1, 2])
ph.AddFace([0, 3, 1])
ph.AddFace([0, 2, 3])
ph.AddFace([1, 3, 2])

cs.Write2XML('bug.xml')

cs2 = CSXCAD.ContinuousStructure()

cs2.ReadFromXML('bug.xml')

ph2 = cs2.GetAllPrimitives()[0]

print("Before Update(): " + str(ph2.IsInside([0, 0, 0])) + " (Should be True)")

ph2.Update()

print("After ph2.Update(): " + str(ph2.IsInside([0, 0, 0])) + " (Should be True)")

Result:

Before Update(): False (Should be True)
After ph2.Update(): True (Should be True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.