Skip to content

Commit

Permalink
CI: Add Continuous Integration.
Browse files Browse the repository at this point in the history
This Pull Request introduces Continuous Integration via GitHub Actions
on multiple operating systems, including Debian, Debian oldstable, Debian
oldoldstable, Fedora, AlmaLinux 8, AlmaLinux 9, and macOS on ARM. To ensure
POSIX compatibility, Alpine Linux is tested due to its non-GNU C library,
and FreeBSD is tested due to its non-Linux environment. For legacy
compatibility, Ubuntu 14.04 and CentOS 7 is also tested (may be dropped in
the future).

Two simple simulation examples are also used as "smoketests" to ensure
Octave and Python scripts can be executed without errors. The simulations
are limited to 1000 timesteps, so they can finish almost immediately
wihout wasting CPU time.

Signed-off-by: Yifeng Li <[email protected]>
  • Loading branch information
biergaizi authored and thliebig committed Dec 21, 2024
1 parent 8a351d3 commit faec0f2
Show file tree
Hide file tree
Showing 3 changed files with 735 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/smoketests/octave/MSL_NotchFilter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
%
% Tutorials / MSL_NotchFilter
%
% Description at:
% http://openems.de/index.php/Tutorial:_Microstrip_Notch_Filter
%
% (C) 2011-2015 Thorsten Liebig <[email protected]>

close all
clear
clc

%% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
physical_constants;
unit = 1e-6; % specify everything in um
MSL_length = 50000;
MSL_width = 600;
substrate_thickness = 254;
substrate_epr = 3.66;
stub_length = 12e3;
f_max = 7e9;

%% setup FDTD parameters & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%

% It's only a smoke test, terminate as soon as possible, otherwise we waste
% CPU time on GitHub Actions (especially for emulated ARM64 systems).
FDTD = InitFDTD('NrTS', 1000);

FDTD = SetGaussExcite( FDTD, f_max/2, f_max/2 );
BC = {'PML_8' 'PML_8' 'MUR' 'MUR' 'PEC' 'MUR'};
FDTD = SetBoundaryCond( FDTD, BC );

%% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSX = InitCSX();
resolution = c0/(f_max*sqrt(substrate_epr))/unit /50; % resolution of lambda/50
mesh.x = SmoothMeshLines( [0 MSL_width/2+[2*resolution/3 -resolution/3]/4], resolution/4, 1.5 ,0 );
mesh.x = SmoothMeshLines( [-MSL_length -mesh.x mesh.x MSL_length], resolution, 1.5 ,0 );
mesh.y = SmoothMeshLines( [0 MSL_width/2+[-resolution/3 +resolution/3*2]/4], resolution/4 , 1.5 ,0);
mesh.y = SmoothMeshLines( [-15*MSL_width -mesh.y mesh.y stub_length+[-resolution/3 +resolution/3*2]/4 15*MSL_width+stub_length], resolution, 1.3 ,0);
mesh.z = SmoothMeshLines( [linspace(0,substrate_thickness,5) 10*substrate_thickness], resolution );
CSX = DefineRectGrid( CSX, unit, mesh );

%% substrate
CSX = AddMaterial( CSX, 'RO4350B' );
CSX = SetMaterialProperty( CSX, 'RO4350B', 'Epsilon', substrate_epr );
start = [mesh.x(1), mesh.y(1), 0];
stop = [mesh.x(end), mesh.y(end), substrate_thickness];
CSX = AddBox( CSX, 'RO4350B', 0, start, stop );

%% MSL port
CSX = AddMetal( CSX, 'PEC' );
portstart = [ mesh.x(1), -MSL_width/2, substrate_thickness];
portstop = [ 0, MSL_width/2, 0];
[CSX,port{1}] = AddMSLPort( CSX, 999, 1, 'PEC', portstart, portstop, 0, [0 0 -1], 'ExcitePort', true, 'FeedShift', 10*resolution, 'MeasPlaneShift', MSL_length/3);

portstart = [mesh.x(end), -MSL_width/2, substrate_thickness];
portstop = [0 , MSL_width/2, 0];
[CSX,port{2}] = AddMSLPort( CSX, 999, 2, 'PEC', portstart, portstop, 0, [0 0 -1], 'MeasPlaneShift', MSL_length/3 );

%% Filter-stub
start = [-MSL_width/2, MSL_width/2, substrate_thickness];
stop = [ MSL_width/2, MSL_width/2+stub_length, substrate_thickness];
CSX = AddBox( CSX, 'PEC', 999, start, stop );

%% write/show/run the openEMS compatible xml-file
Sim_Path = 'tmp';
Sim_CSX = 'msl.xml';

[status, message, messageid] = rmdir( Sim_Path, 's' ); % clear previous directory
[status, message, messageid] = mkdir( Sim_Path ); % create empty simulation folder

WriteOpenEMS( [Sim_Path '/' Sim_CSX], FDTD, CSX );
RunOpenEMS( Sim_Path, Sim_CSX );

%% post-processing
close all
f = linspace( 1e6, f_max, 1601 );
port = calcPort( port, Sim_Path, f, 'RefImpedance', 50);

s11 = port{1}.uf.ref./ port{1}.uf.inc;
s21 = port{2}.uf.ref./ port{1}.uf.inc;
100 changes: 100 additions & 0 deletions .github/smoketests/python/MSL_NotchFilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
Microstrip Notch Filter Tutorial
(c) 2016-2023 Thorsten Liebig <[email protected]>
"""

### Import Libraries
import os, tempfile

# Don't delete this line, we need to test if matplotlib can be imported,
# although it's never used. Incompatible binaries between system and
# PyPI can cause this, see:
# https://github.com/thliebig/openEMS/issues/165
from pylab import *

from CSXCAD import ContinuousStructure
from openEMS import openEMS
from openEMS.physical_constants import *

### Setup the simulation
Sim_Path = os.path.join(tempfile.gettempdir(), 'NotchFilter')

unit = 1e-6 # specify everything in um
MSL_length = 50000
MSL_width = 600
substrate_thickness = 254
substrate_epr = 3.66
stub_length = 12e3
f_max = 7e9

### Setup FDTD parameters & excitation function

# It's only a smoke test, terminate as soon as possible, otherwise we waste
# CPU time on GitHub Actions (especially for emulated ARM64 systems).
FDTD = openEMS(NrTS=1000)

FDTD.SetGaussExcite( f_max/2, f_max/2 )
FDTD.SetBoundaryCond( ['PML_8', 'PML_8', 'MUR', 'MUR', 'PEC', 'MUR'] )

### Setup Geometry & Mesh
CSX = ContinuousStructure()
FDTD.SetCSX(CSX)
mesh = CSX.GetGrid()
mesh.SetDeltaUnit(unit)

resolution = C0/(f_max*sqrt(substrate_epr))/unit/50 # resolution of lambda/50
third_mesh = array([2*resolution/3, -resolution/3])/4

## Do manual meshing
mesh.AddLine('x', 0)
mesh.AddLine('x', MSL_width/2+third_mesh)
mesh.AddLine('x', -MSL_width/2-third_mesh)
mesh.SmoothMeshLines('x', resolution/4)

mesh.AddLine('x', [-MSL_length, MSL_length])
mesh.SmoothMeshLines('x', resolution)

mesh.AddLine('y', 0)
mesh.AddLine('y', MSL_width/2+third_mesh)
mesh.AddLine('y', -MSL_width/2-third_mesh)
mesh.SmoothMeshLines('y', resolution/4)

mesh.AddLine('y', [-15*MSL_width, 15*MSL_width+stub_length])
mesh.AddLine('y', (MSL_width/2+stub_length)+third_mesh)
mesh.SmoothMeshLines('y', resolution)

mesh.AddLine('z', linspace(0,substrate_thickness,5))
mesh.AddLine('z', 3000)
mesh.SmoothMeshLines('z', resolution)

## Add the substrate
substrate = CSX.AddMaterial( 'RO4350B', epsilon=substrate_epr)
start = [-MSL_length, -15*MSL_width, 0]
stop = [+MSL_length, +15*MSL_width+stub_length, substrate_thickness]
substrate.AddBox(start, stop )

## MSL port setup
port = [None, None]
pec = CSX.AddMetal( 'PEC' )
portstart = [ -MSL_length, -MSL_width/2, substrate_thickness]
portstop = [ 0, MSL_width/2, 0]
port[0] = FDTD.AddMSLPort( 1, pec, portstart, portstop, 'x', 'z', excite=-1, FeedShift=10*resolution, MeasPlaneShift=MSL_length/3, priority=10)

portstart = [MSL_length, -MSL_width/2, substrate_thickness]
portstop = [0 , MSL_width/2, 0]
port[1] = FDTD.AddMSLPort( 2, pec, portstart, portstop, 'x', 'z', MeasPlaneShift=MSL_length/3, priority=10 )

## Filter-Stub Definition
start = [-MSL_width/2, MSL_width/2, substrate_thickness]
stop = [ MSL_width/2, MSL_width/2+stub_length, substrate_thickness]
pec.AddBox(start, stop, priority=10 )

FDTD.Run(Sim_Path, cleanup=True)

### Post-processing
f = linspace( 1e6, f_max, 1601 )
for p in port:
p.CalcPort( Sim_Path, f, ref_impedance = 50)

s11 = port[0].uf_ref / port[0].uf_inc
s21 = port[1].uf_ref / port[0].uf_inc
Loading

0 comments on commit faec0f2

Please sign in to comment.