lib

package
v0.0.0-...-50c8c3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2025 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	C     = 299792458        // c  - speed of light (m/s)
	Mu_0  = 1.25663706212e-6 // μ₀ - permeability constant (~4π×10−7 H/m)
	Eps_0 = 8.8541878210e-12 // ε₀ - permittivity constant (F/m)
)
View Source
const (
	VaryK = 1
	VaryP = 2
)

Varying flags

View Source
const (

	// mathematical constants
	RectAng = math.Pi / 2 // right angle
	CircAng = 2 * math.Pi //full circle
)

Global settings and defaults

View Source
const (
	TRK_MARK   = -1
	TRK_SHORT  = -2
	TRK_LENGTH = -3
)
View Source
const Bulge = 100

Bulge specifies the number of segments involved in avoiding wire intersections.

View Source
const NumPlots = 15

NumPlots is the number of plot selections available in the GUI

Variables

View Source
var (
	ClrWhite = &color.RGBA{255, 255, 255, 0}
	ClrRed   = &color.RGBA{255, 0, 0, 0}
	ClrRedTr = &color.RGBA{255, 0, 0, 224}
	ClrPink  = &color.RGBA{255, 0, 255, 0}
	ClrBlack = &color.RGBA{0, 0, 0, 0}
	ClrGray  = &color.RGBA{127, 127, 127, 0}
	ClrBlue  = &color.RGBA{0, 0, 255, 0}
	ClrGreen = &color.RGBA{0, 255, 0, 0}
	ClrCyan  = &color.RGBA{0, 255, 255, 0}
)

Color definitions for drawing

View Source
var Cfg = &Config{

	Def: &Specification{
		K: 0.25,
		Wire: Wire{
			Diameter:     0.002,
			Material:     "",
			Conductivity: 0,
			Inductance:   0,
		},
		Ground: Ground{
			Height: 0,
			Mode:   0,
			Type:   -1,
			NRadl:  0,
			Epse:   0,
			Sig:    0,
		},
		Source: Source{
			Z:     Impedance{50, 0},
			Power: 1,
			Freq:  435000000,
			Span:  5000000,
		},
		Feedpt: Feedpt{
			Gap:       0,
			Extension: 0,
		},
	},

	Sim: &Simulation{

		MaxRounds:     5,
		MinZr:         1,
		MaxZr:         20000,
		MinChange:     0.001,
		ProgressCheck: 10,
		MinBend:       0.01,

		ExciteU:   1.0,
		PhiStep:   5.0,
		ThetaStep: 5.0,

		WireMax:      0.008,
		SegMinLambda: 0.002,
		SegMinWire:   4,
		MinRadius:    0.02,
	},

	Render: &RenderConfig{
		Canvas: "sdl",
		Width:  1024,
		Height: 768,
	},

	Mat: map[string]*Material{
		"Cu": {
			5.96e7,
			1.32e-6,
		},
		"CuL": {
			5.96e7,
			1.1e-7,
		},
		"Al": {
			3.5e7,
			2.5e-8,
		},
	},

	Plugins: make(map[string]string),
}

Cfg is the globally-accessible configuration (pre-set)

View Source
var CustomEvaluators = make(map[string]Evaluate)

CustomEvaluators is a list of custom comparator implementations

View Source
var PlotSpecial = []string{
	"Smith",
}

special graphs

View Source
var PlotValues = []string{

	"Gmax",
	"Gmean",
	"SD",
	"Zr",
	"Zi",

	"Geff",
	"Loss",
	"PwrFac",
}

list of plot targets

Functions

func BendMax

func BendMax(r, segL float64) float64

BendMax returns the max. bending angle between two segments of given length such that a resulting curve has a minimum radius of r.

func CheckDistances

func CheckDistances(segs []*Line, minD float64) (pos []int)

CheckDistances returns a list of segment indices where the smallest distance of segment to other segments in the list is below a given minimum. Only the higher index is reported.

func FormatDuration

func FormatDuration(v int64) string

FormatDuration for number of seconds

func FormatImpedance

func FormatImpedance(z complex128, n int) string

FormatImpedance with scaled numbers (magnitude)

func FormatNumber

func FormatNumber(v float64, n int) string

FormatNumber with magnitude

func FromReflection

func FromReflection(g, z0 complex128) complex128

FromReflection computes the impedance Z if a reference impedance Z0 and a complex reflection (Smith chart coordinate) are given.

func GenMdlParams

func GenMdlParams(
	param float64,
	spec *Specification,
	ini, perf *Performance,
	mdl, gen, opt string,
	seed int64,
	tag string,
	total Stats,
) (cmts []string)

GenMdlParams assembles model parameters as list of strings. The output is parsable with ParseMdlParams().

func GetFrequencyRange

func GetFrequencyRange(s string) (freq, sw int64, err error)

GetFrequencyRange parses band limits

func GetPlugin

func GetPlugin(name string) (pi *plugin.Plugin, err error)

GetPlugin by name. If name is prefixed with '@', it references a plugin entry in the configuration.

func GetRange

func GetRange(s string) (from, to float64, err error)

handle specified range

func GetSymbol

func GetSymbol[T any](pi *plugin.Plugin, name string) (sym T, err error)

GetSymbol from plugin (exported variable or function)

func GminEvaluate

func GminEvaluate(p *Performance, args string, feedZ complex128) (val float64)

Gmin evaluator (minimizing Gmax)

func InRange

func InRange(v, from, to float64) bool

InRange returns true if value v is in range (with tolerance)

func Intersects

func Intersects(segs []*Line) (pos []int)

Intersects returns a list of segment indices that intersect other segments in the list. Only the higher index is reported.

func IsNull

func IsNull(f float64) bool

IsNull returns true if number is zero (within tolerance)

func IsotropeEvaluate

func IsotropeEvaluate(p *Performance, args string, feedZ complex128) (val float64)

IsotropeEvaluate implements the Compare prototype It returns a value representing how spherical the radiation pattern is.

func MaterialProperties

func MaterialProperties(label string, dia float64) (conductivity, inductance float64, err error)

MaterialProperties returns material properties for label

func ParseImpedance

func ParseImpedance(s string) (Z complex128, err error)

ParseImpedance (complex value) from string. A valid string is formed from one or two numbers combined; the single number or one of the two numbers can be tagged by a "j" or "i" as imaginary. Spaces and multiplication signs in a string are ignored.

Examples of valid strings: * "50" // only real part -> (50,0) * "-j30.624" // only imaginary part -> (0,-30.624) * "87.37+j41.74" // complex number -> (87.37,41.74) * "j41.74+87.37" // complex number -> (87.37,41.74)

func ParseNumber

func ParseNumber(s string) (float64, error)

ParseNumber with magnitude

func PlotStyle

func PlotStyle(pos int) (pat string, style draw.LineStyle)

func Plotter

func Plotter(db *Database, sel *Selection, format string) (out map[string]string, err error)

Plotter for AntGen datasets

func Randomizer

func Randomizer(seed int64) *rand.Rand

Randomizer initialized with seed for deterministic randomization.

func ReadConfig

func ReadConfig(fname string) (err error)

ReadConfig from file

func Regions

func Regions(pos []int) (r [][2]int)

Regions condenses a list of indices into regions. The list "3 5 6 7 8 12 15 16 19" would be returned as "[3,3] [5,8] [12,12] [15,16] [19,19]"

func SplitParam

func SplitParam(line string) (kind string, vals []string)

SplitParam dissects a parameter string

func Sqr

func Sqr(v float64) float64

Sqr returns the square of a value

func TblValue

func TblValue[T any](tbl *Table, row, col int) (v T)

func ToReflection

func ToReflection(z, z0 complex128) complex128

ToReflection computes the complex reflection factor between Z and Z0. The value is within a unit circle in the complex plane (Smith chart).

Types

type Action

type Action func(ant *Antenna, key rune, step int) bool

Callback on key press

type Antenna

type Antenna struct {
	Lambda float64      // wavelength at operating frequency
	Perf   *Performance // antenna performance
	// contains filtered or unexported fields
}

Antenna geometry, parameter and performance

func BuildAntenna

func BuildAntenna(kind string, spec *Specification, nodes []*Node) (ant *Antenna)

BuildAntenna from given geometry

func NewAntenna

func NewAntenna(kind string) *Antenna

NewAntenna instantiates a new kind of antenna

func (*Antenna) Add

func (a *Antenna) Add(s *Line)

Add segment to antenna geometry

func (*Antenna) DumpNEC

func (a *Antenna) DumpNEC(wrt io.Writer, spec *Specification, comments []string)

DumpNEC writes an antenna simulation card deck to writer.

func (*Antenna) Eval

func (a *Antenna) Eval(freq int64, wire Wire, ground Ground) (err error)

Eval antenna performance at given frequency

func (*Antenna) FixGeometry

func (a *Antenna) FixGeometry(minD float64)

FixGeometry makes sure that an antenna geometry can be used for simulations (e.g. avoiding wire intersections by "bridging" wire crossings).

func (*Antenna) SetExcitation

func (a *Antenna) SetExcitation(pos int)

SetExcitation places the feed point on a wire segment

func (*Antenna) Type

func (a *Antenna) Type() string

Type of antenna

type BoundingBox

type BoundingBox struct {
	Xmin, Xmax float64
	Ymin, Ymax float64
	Zmin, Zmax float64
}

func NewBoundingBox

func NewBoundingBox() *BoundingBox

func (*BoundingBox) Include

func (b *BoundingBox) Include(v Vec3)

type Callback

type Callback func(ant *Antenna, pos int, msg string)

Callback when optimization improves

type Canvas

type Canvas interface {
	// Start a new (dynamic) rendering
	Run(Action)

	// Show antenna
	Show(ant *Antenna, pos int, msg string)

	SetHint(m string)

	// Circle primitive
	Circle(x, y, r, w float64, clrBorder, clrFill *color.RGBA)

	// Text primitive
	Text(x, y, fs float64, s string, clr *color.RGBA)

	// Line primitive
	Line(x1, y1, x2, y2, w float64, clr *color.RGBA)

	// Dump canvas to file
	Dump(fName string) error

	// Close a canvas. No further operations are allowed
	Close() error
}

Canvas for drawing the antenna

func GetCanvas

func GetCanvas(kind string, width, height int, side float64) (c Canvas, err error)

GetCanvas returns a canvas for drawing (factory)

func GetCanvasFromCfg

func GetCanvasFromCfg(cfg *RenderConfig, side float64) (Canvas, error)

GetCanvasFromCfg returns a canvas from configuration

type Change

type Change struct {
	Pos   int     `json:"pos"`
	Theta float64 `json:"theta"`
	Phi   float64 `json:"phi"`
}

func Changes

func Changes(nodes []*Node) []*Change

type Comparator

type Comparator struct {
	// contains filtered or unexported fields
}

Comparator creates a standard metric for antenna results. It is used in the optimization loop to find improvements towards a goal. The optimization algorithms interprets higher values as "better" values.

func NewComparator

func NewComparator(target string, spec *Specification) (cmp *Comparator, err error)

Create a new comparator for a target (and a possible target value). Known targets are: * Gmax: highest gain * Gmean: best mean gain * SD: smallest standard deviation * custom: custom comparator (possibly plugin)

func (*Comparator) Compare

func (cmp *Comparator) Compare(curr, old *Performance) (sign int, val float64)

Compare antenna results based on the optimization target. Returns 0 if same, -1 if worse, 1 if better

func (*Comparator) Next

func (cmp *Comparator) Next() (ok bool)

Next optimization target

func (*Comparator) Target

func (cmp *Comparator) Target() string

Target returns the current optimization target

func (*Comparator) Value

func (cmp *Comparator) Value(p *Performance) float64

Value returns the evaluated value from perfomance data.

type Config

type Config struct {
	Def     *Specification       `json:"default"`
	Sim     *Simulation          `json:"simulation"`
	Mat     map[string]*Material `json:"material"`
	Render  *RenderConfig        `json:"render"`
	Plugins map[string]string    `json:"plugins"`
}

Config for AntGen

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database for optimization results

func OpenDatabase

func OpenDatabase(fname string) (db *Database, err error)

Open SQLite3 database from file

func (*Database) Close

func (db *Database) Close() error

Close database

func (*Database) GetRows

func (db *Database) GetRows(clause, order string) (list []*Row, err error)

GetRows from the database with given where clause and ordering

func (*Database) Insert

func (db *Database) Insert(rec *Record) error

Insert model parameters into database

func (*Database) ListPlotSets

func (db *Database) ListPlotSets() (sets map[string]*PlotSet, err error)

ListPlotSets returns a list of names for available plot sets

func (*Database) Set

func (db *Database) Set(fdir string, filter Index) (set *Set, err error)

Set returns a set of performance records for a given directory

func (*Database) Stats

func (db *Database) Stats() (stats *DbStats)

Stats returns database statistics

func (*Database) VarLists

func (db *Database) VarLists(set string) (kList, pList []float64, err error)

VarLists returns a list of (unique) 'k' and 'param' values for a dataset. If 'set' is empty, the values represent parameters in the whole database.

type DbStats

type DbStats struct {
	NumAnt   int64  // number of antennas
	NumSteps int64  // number of optimization steps
	NumSims  int64  // number of simulations
	Elapsed  int64  // elapsed simulation time (seconds)
	Duration string // human-readble duration
}

DbStats holds database statistics

type Evaluate

type Evaluate func(perf *Performance, args string, feedZ complex128) float64

Evaluate performance (metric value optimized to maximum)

type Feedpt

type Feedpt struct {
	Gap       float64 `json:"gap"`       // distance between legs at feed point
	Extension float64 `json:"extension"` // extension of wire away from feedpt
}

func ParseFeedpt

func ParseFeedpt(feedptS string, warn bool) (fpt Feedpt, err error)

ParseFeedpt converts a feedpoint spec

type Gain

type Gain struct {
	Max  float64 // maximum gain
	Mean float64 // mean gain
	SD   float64 // standard deviation of mean
}

Gain of antenna

type GenGeo

type GenGeo struct {
	// contains filtered or unexported fields
}

GenGeo reads a geometry file instead of generating something new.

func (*GenGeo) Info

func (g *GenGeo) Info() string

Info about generator

func (*GenGeo) Init

func (g *GenGeo) Init(params string, lambda float64) error

Init generator with given parameters

func (*GenGeo) Name

func (g *GenGeo) Name() string

Name of generator

func (*GenGeo) Nodes

func (g *GenGeo) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenGeo) Volatile

func (g *GenGeo) Volatile() bool

Volatile returns true if the generator is randomized

type GenStraight

type GenStraight struct{}

GenStraight returns all segments lined-up in a straight line.

func (*GenStraight) Info

func (g *GenStraight) Info() string

Info about generator

func (*GenStraight) Init

func (g *GenStraight) Init(params string, lambda float64) error

Init generator with given parameters

func (*GenStraight) Name

func (g *GenStraight) Name() string

Name of generator

func (*GenStraight) Nodes

func (g *GenStraight) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenStraight) Volatile

func (g *GenStraight) Volatile() bool

Volatile returns true if the generator is randomized

type GenStroll

type GenStroll struct {
	// contains filtered or unexported fields
}

GenStroll grows a line (dipole leg) by moving in any direction but bounded by to positive x-coordinates.

func (*GenStroll) Info

func (g *GenStroll) Info() string

Info about generator

func (*GenStroll) Init

func (g *GenStroll) Init(params string, lambda float64) error

Init generator with given parameters

func (*GenStroll) Name

func (g *GenStroll) Name() string

Name of generator

func (*GenStroll) Nodes

func (g *GenStroll) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenStroll) Volatile

func (g *GenStroll) Volatile() bool

Volatile returns true if the generator is randomized

type GenTrespass

type GenTrespass struct {
	// contains filtered or unexported fields
}

GenTrespass grows a line (dipole leg) by moving in any direction and widthout bounds.

func (*GenTrespass) Info

func (g *GenTrespass) Info() string

Info about generator

func (*GenTrespass) Init

func (g *GenTrespass) Init(params string, lambda float64) error

Init generator with given parameters

func (*GenTrespass) Name

func (g *GenTrespass) Name() string

Name of generator

func (*GenTrespass) Nodes

func (g *GenTrespass) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenTrespass) Volatile

func (g *GenTrespass) Volatile() bool

Volatile returns true if the generator is randomized

type GenV

type GenV struct {
	// contains filtered or unexported fields
}

GenV returns a V-shaped dipole with 120° (¾π) angle between legs.

func (*GenV) Info

func (g *GenV) Info() string

Info about generator

func (*GenV) Init

func (g *GenV) Init(params string, lambda float64) (err error)

Init generator with given parameters

func (*GenV) Name

func (g *GenV) Name() string

Name of generator

func (*GenV) Nodes

func (g *GenV) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenV) Volatile

func (g *GenV) Volatile() bool

Volatile returns true if the generator is randomized

type GenWalk

type GenWalk struct {
	// contains filtered or unexported fields
}

GenWalk grows a line (dipole leg) by moving in one direction, so the maximum direction vector of a segment is ±½π.

func (*GenWalk) Info

func (g *GenWalk) Info() string

Info about generator

func (*GenWalk) Init

func (g *GenWalk) Init(params string, lambda float64) error

Init generator with given parameters

func (*GenWalk) Name

func (g *GenWalk) Name() string

Name of generator

func (*GenWalk) Nodes

func (g *GenWalk) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'.

func (*GenWalk) Volatile

func (g *GenWalk) Volatile() bool

Volatile returns true if the generator is randomized

type Generator

type Generator interface {

	// Init generator with given parameters
	Init(param string, lambda float64) error

	// Nodes returns the initial antenna geometry made from 'num' segments
	// of equal length 'segL'. Volatile generators build varying geometries
	// based on randomization.
	Nodes(num int, segL float64, rnd *rand.Rand) []*Node

	// Name of generator
	Name() string

	// Info about generator
	Info() string

	// Volatile returns true if the generator is randomized
	Volatile() bool
}

Generator interface

func GetGenerator

func GetGenerator(name string, lambda float64) (g Generator, err error)

GetGenerator by name

type Geometry

type Geometry struct {
	Cmts   []string `json:"comments"` // optimization info/comments
	Wire   Wire     `json:"wire"`     // wire parameters
	Feedpt Feedpt   `json:"feedpt"`   // feed point parameters
	Height float64  `json:"height"`   // height of antenna
	Nodes  []*Node  `json:"nodes"`    // node list
}

Geometry of 2D-bended antenna

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid implements the interface for heatmap grids

func NewGrid

func NewGrid(db *Database, sel *Selection, idx int) (g *Grid, err error)

NewGrid instantiates a new grid object from database

func (*Grid) Dims

func (g *Grid) Dims() (c, r int)

Dims returns the grid dimensions

func (*Grid) X

func (g *Grid) X(c int) float64

X returns the x-axis value in grid column c

func (*Grid) Y

func (g *Grid) Y(r int) float64

Y returns the y-axis value in grid row r

func (*Grid) Z

func (g *Grid) Z(c, r int) float64

Z returns the target value in grid cell

type Ground

type Ground struct {
	Height float64 `json:"height"` // height of antenna above ground
	Mode   int     `json:"mode"`   // ground mode (0=no ground, 1=sym ground, -1=no-sym ground)
	Type   int     `json:"type"`   // NEC2 ground type (-1: free space, 0: finite, 1:conductive, 2: finite(SN))
	NRadl  int     `json:"nradl"`  // number of radial wires in the ground screen
	Epse   float64 `json:"epse"`   // relative dielectric constant for ground in the vicinity of the antenna
	Sig    float64 `json:"sig"`    // conductivity in mhos/meter of the ground in the vicinity of the antenna
}

Ground parameters

func ParseGround

func ParseGround(groundS string, warn bool) (gnd Ground, err error)

ParseGround converts a ground spec into Ground

type Impedance

type Impedance struct {
	R float64 `json:"R"` // resistance
	X float64 `json:"X"` // reactance
}

Impedance (complex)

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index to performance record. Either 'k' or 'param' can be NaN (skipped), but not both.

func NewIndex

func NewIndex(k, param float64) Index

NewIndex from k and param

func (Index) K

func (i Index) K() float64

func (Index) Match

func (i Index) Match(j Index) bool

Match returns true if k and param match the index values. Handles NaN values as "match always"

func (Index) Param

func (i Index) Param() float64

type IndexList

type IndexList struct {
	// contains filtered or unexported fields
}

IndexList is a list of unique indices (usually over a set of data)

func NewIndexList

func NewIndexList() *IndexList

NewIndexList creates an empty list of indices

func (*IndexList) Add

func (il *IndexList) Add(i Index)

Add index to list

func (*IndexList) Sorted

func (il *IndexList) Sorted() (out []Index)

Sorted returns a sorted list of indices

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line in 3D space

func NewLine

func NewLine(s, e Vec3) *Line

NewLine creates a new 3D line

func (*Line) Dir

func (l *Line) Dir() Vec3

Dir is the direction of the line in 3D

func (*Line) Distance

func (li *Line) Distance(lj *Line) (d float64)

Distance between two lines

func (*Line) End

func (l *Line) End() Vec3

End point of line (3D)

func (*Line) Intersect

func (li *Line) Intersect(lj *Line) (p Vec3, cross bool)

Intersect returns true (and the intersection point) if two lines intersect

func (*Line) Length

func (l *Line) Length() float64

Length of line

func (*Line) Start

func (l *Line) Start() Vec3

Start point of line (3D)

func (*Line) String

func (l *Line) String() string

String returns the human-readable line

type LuaEvaluator

type LuaEvaluator struct {
	// contains filtered or unexported fields
}

LuaEvaluator provides an Evaluate() function for optimization written in LUA script.

func NewLuaEvaluator

func NewLuaEvaluator(script string) (ev *LuaEvaluator, err error)

NewLuaEvaluator instantiates a new LUA evaluator: 'param' is of form '<script filename>:<opt1>=<val>,<opt2>=...'

func (*LuaEvaluator) Evaluate

func (ev *LuaEvaluator) Evaluate(perf *Performance, args string, feedZ complex128) float64

Evaluate antenna performance and return result

type LuaGenerator

type LuaGenerator struct {
	// contains filtered or unexported fields
}

LuaGenerator is a generator where the Nodes() method is implemented as a LUA script.

func (*LuaGenerator) Info

func (g *LuaGenerator) Info() string

Info about generator

func (*LuaGenerator) Init

func (g *LuaGenerator) Init(param string, lambda float64) error

Init generator with given parameters

func (*LuaGenerator) Name

func (g *LuaGenerator) Name() string

Name of generator

func (*LuaGenerator) Nodes

func (g *LuaGenerator) Nodes(num int, segL float64, rnd *rand.Rand) []*Node

Nodes returns the initial antenna geometry made from 'num' segments of equal length 'segL'. Volatile generators build varying geometries based on randomization.

func (*LuaGenerator) Volatile

func (g *LuaGenerator) Volatile() bool

Volatile returns true if the generator is randomized

type Matcher

type Matcher struct {
	AtSource bool // placement of shunt element
	// contains filtered or unexported fields
}

Matcher between impedances. The shunt element (Cp/Lp) is located at the side with higher impedance (load if swap=false or source if swap=true). The matcher is either a low-pass (Cp/Ls) or a high-pass (Cs/Lp) filter.

func Zmatch

func Zmatch(Zs, Zl complex128) (Z complex128, m *Matcher)

Zmatch the source impedance Zs to the load impedance Zl. Z_L: load impedance (R_L + X_L*j) Z_P: Reactance parallel to load (X_P*j) [maxima-start]

    Zl: Rl+Xl*%i;
    Zp: Xp*%i;
    Z:  rectform((Zl*Zp)/(Zl+Zp));
    R:  expand(realpart(Z));
-->     (Rl*Xp^2) / ((Xp+Xl)^2 + Rl^2) == Rs
    solve(R-Rs,Xp);
-->     Xp = (sqrt(Rl*Rs*Xl^2 - Rl^2*Rs^2 + Rl^3*Rs) + Rs*Xl) / (Rl-Rs)
    Xr: imagpart(Z);

[maxima-end]

func (*Matcher) HighPass

func (m *Matcher) HighPass(freq float64) (Lp, Cs float64)

HighPass element values at given frequency

func (*Matcher) LowPass

func (m *Matcher) LowPass(freq float64) (Cp, Ls float64)

LowPass element values at given frequency

type Material

type Material struct {
	Conductivity float64 `json:"conductivity"` // wire conductivity (S/m)
	Inductance   float64 `json:"inductance"`   // wire inductance (H/m)
}

Material spec for wires

type Model

type Model interface {
	// Init model with antenna parameters and generator.
	Init(params string, spec *Specification, gen Generator) (side float64, err error)

	// Prepare initial geometry
	Prepare(seed int64, cb Callback) (ant *Antenna, err error)

	// Optimize antenna geometry based on random seed and comparator
	// (to evaluate progress during optimization)
	Optimize(seed int64, iter int, cmp *Comparator, cb Callback) (ant *Antenna, stats Stats, err error)

	// Info about the model (parameters)
	Info() string

	// Finalize model after optimization (write track and geometry files).
	Finalize(tag, outDir, outPrf string, cmts []string)
}

Model of an antenna.

type ModelDipole

type ModelDipole struct {
	Kind string         // kind of model
	Spec *Specification // antenna specs

	Nodes []*Node // list of segments
	Num   int     // number of segments
	SegL  float64 // segment length

	Track []*Change // list of changes
}

Model of a dipole antenna with symmetrical legs. Each leg is made from segments of equal length.

func (*ModelDipole) Finalize

func (mdl *ModelDipole) Finalize(tag, outDir, outPrf string, cmts []string)

Finalize model (write track and geometry files)

func (*ModelDipole) Init

func (mdl *ModelDipole) Init(params string, spec *Specification, gen Generator) (side float64, err error)

Init base model

type Node

type Node struct {
	Length float64 `json:"length"`    // length of segment
	Theta  float64 `json:"azimuth"`   // azimuth (angle in XY plane)
	Phi    float64 `json:"elevation"` // elevation (towards Z axis)
}

Node in a 3D geometry (relative vector)

func NewNode

func NewNode(len, theta, phi float64) (n *Node)

NewNode creates a new 3D node

func Smooth2D

func Smooth2D(nodes []*Node, rng int) (out []*Node)

func (*Node) AddAngles

func (n *Node) AddAngles(dTheta, dPhi float64)

AddAngles to the current direction of a node

func (*Node) Dir

func (n *Node) Dir() (v Vec3)

Dir returns the direction of the node as vector

func (*Node) Next

func (n *Node) Next() (v Vec3)

Next returns the position of the next node

func (*Node) SetAngles

func (n *Node) SetAngles(theta, phi float64)

SetAngles of a node

type Performance

type Performance struct {
	Gain *Gain       // antenna gain
	Z    complex128  // antenna impedance
	Rp   *RadPattern // radiation pattern
}

Performance of antenna

func (*Performance) Attenuation

func (p *Performance) Attenuation(Zs complex128) float64

Power factor (in dB) of a matched antenna.

func (*Performance) Loss

func (p *Performance) Loss(Zs complex128) float64

Loss (in dB) of transfering power from a source with impedance Zs to an unmatched antenna with impedance r.Z

func (*Performance) Resonance

func (p *Performance) Resonance() float64

Resonance is the "virtual loss" (in dB) due to antenna reactance. No loss implies resonance.

func (*Performance) SWR

func (p *Performance) SWR(Zs complex128) float64

SWR for (unmatched) antenna at source impedance

func (*Performance) String

func (p *Performance) String() string

String returns a human-readable performance text

type PlotSet

type PlotSet struct {
	Tag   string    // plot tag
	Dir   string    // dataset directory
	Klist []float64 // list of possible 'k' values
	Plist []float64 // list of possible 'param' values
	Kidx  int       // 'k' selection in KList
	Pidx  int       // 'param' selection in PList
}

func NewPlotSet

func NewPlotSet(dir string) *PlotSet

func (*PlotSet) Index

func (ds *PlotSet) Index(val float64, name string) int

func (*PlotSet) Params

func (ds *PlotSet) Params() (k, param float64)

type RadPattern

type RadPattern struct {
	NPhi, NTheta int
	Min, Max     float64
	Values       [][]float64
}

RadPattern is the radiation pattern of an antenna

func (*RadPattern) Spherical

func (rp *RadPattern) Spherical() (f float64)

Spherical is a metric for the isotropicity of a radition pattern. Values are positive; smaller numbers are "better". A value is calculated as ∑error(i)²/n over all points (with i = 1..n).

type Record

type Record struct {
	Freq   int64       // operating frequency
	Wire   Wire        // wire spec
	Gnd    Ground      // ground spec
	Feedpt Feedpt      // feedpoint spec
	K      float64     // k (dipole leg length)
	Param  float64     // free parameter (generator)
	Perf   Performance // final performance
	Mdl    string      // antenna model
	Gen    string      // antenna generator (initial geometry)
	Opt    string      // optimizer
	Seed   int64       // random seed
	Stats  Stats       // optimization stats
	Path   string      // relative path
	Tag    string      // model tag
}

Record in the database

func ParseMdlParams

func ParseMdlParams(cmts []string) (p *Record, ok bool, err error)

ParseMdlParams from model file (extract performance parameters)

func ParseMdlParamsFromNEC

func ParseMdlParamsFromNEC(fName, dirIn string) (p *Record, ok bool, err error)

ParseMdlParamsFromNEC retrieves model parameters from a NEC2 model file

type RenderConfig

type RenderConfig struct {
	Canvas string `json:"canvas"` // render engine/canvas
	Width  int    `json:"width"`  // width of canvas (usually in pixels)
	Height int    `json:"height"` // height of canvas (usually in pixels)
}

RenderConfig for rendering-related settings

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row in the performance table

func (*Row) Index

func (r *Row) Index() Index

Index of record (k,param)

func (*Row) Reference

func (r *Row) Reference() (id int64, fdir, ftag string)

Reference to database entry and related model file

func (*Row) Value

func (r *Row) Value(name string) float64

Value of a named performance parameter is returned

type SDLCanvas

type SDLCanvas struct {
	// contains filtered or unexported fields
}

SDLCanvas for windowed display

func NewSDLCanvas

func NewSDLCanvas(width, height int, side float64) (c *SDLCanvas, err error)

NewSDLCanvas creates a new SDL canvas for display

func (*SDLCanvas) Circle

func (c *SDLCanvas) Circle(x, y, r, w float64, clrBorder, clrFill *color.RGBA)

Circle primitive

func (*SDLCanvas) Close

func (c *SDLCanvas) Close() error

Close a canvas. No further operations are allowed

func (*SDLCanvas) Dump

func (c *SDLCanvas) Dump(fName string) error

Dump canvas to file

func (*SDLCanvas) Line

func (c *SDLCanvas) Line(x1, y1, x2, y2, w float64, clr *color.RGBA)

Line primitive

func (*SDLCanvas) Run

func (c *SDLCanvas) Run(cb Action)

Run the canvas (new rendering begins)

func (*SDLCanvas) SetHint

func (c *SDLCanvas) SetHint(m string)

func (*SDLCanvas) Show

func (c *SDLCanvas) Show(ant *Antenna, pos int, msg string)

Show antenna geometry with message and last change position

func (*SDLCanvas) Text

func (c *SDLCanvas) Text(x, y, fs float64, s string, clr *color.RGBA)

Text primitive

type SVGCanvas

type SVGCanvas struct {
	// contains filtered or unexported fields
}

SVGCanvas for writing SVG streams

func NewSVGCanvas

func NewSVGCanvas(_, _ int, _ float64) (*SVGCanvas, error)

NewSVGCanvas creates a new SVG canvas

func (*SVGCanvas) Circle

func (c *SVGCanvas) Circle(x, y, r, w float64, clrBorder, clrFill *color.RGBA)

Circle primitive

func (*SVGCanvas) Close

func (c *SVGCanvas) Close() (err error)

Close a canvas. No further operations are allowed

func (*SVGCanvas) Dump

func (c *SVGCanvas) Dump(fName string) (err error)

Dump canvas to file

func (*SVGCanvas) Line

func (c *SVGCanvas) Line(x1, y1, x2, y2, w float64, clr *color.RGBA)

Line primitive

func (*SVGCanvas) Run

func (c *SVGCanvas) Run(cb Action)

Perform rendering

func (*SVGCanvas) SetHint

func (c *SVGCanvas) SetHint(m string)

func (*SVGCanvas) Show

func (c *SVGCanvas) Show(ant *Antenna, _ int, msg string)

Show antenna on canvas

func (*SVGCanvas) Text

func (c *SVGCanvas) Text(x, y, fs float64, s string, clr *color.RGBA)

Text primitive

type Selection

type Selection struct {
	Target string             // Parameter (Gmax,Gmean,Zr,Zi)
	Sets   [NumPlots]*PlotSet // list of PlotSets selected
}

Selection of plot parameters

func NewSelection

func NewSelection(target string) *Selection

NewSelection for given target

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set of performance data from one run; either 'k' or 'param' (or both!) are varied across a defined span. The set is identified by 'fdir' (optimization results are grouped in distinct directories).

func NewSet

func NewSet() *Set

NewSet returns a new (empty) set

func (*Set) Add

func (s *Set) Add(r *Row)

Add row to set

func (*Set) Value

func (s *Set) Value(idx Index, name string) float64

Value returns a named column value from the set for a given index

func (*Set) Values

func (s *Set) Values(idx Index, names []string) map[string]float64

Values returns the values for named columns at a given index

func (*Set) Varying

func (s *Set) Varying(sweep *IndexList) (f int)

Varying returns the var. kind and adds indices to the sweep list

type Simulation

type Simulation struct {
	// optimization parameters (termination conditions)
	MaxRounds     int     `json:"maxRounds"`     // max. number of rounds in optimization
	MinZr         float64 `json:"minZr"`         // min. resistance of antenna
	MaxZr         float64 `json:"maxZr"`         // max. resistance of antenna
	MinChange     float64 `json:"minChange"`     // progress check: min. change in target value
	ProgressCheck int     `json:"progressCheck"` // number of steps between progress check
	MinBend       float64 `json:"minBend"`       // min. bending angle (fraction of max. angle)

	// simulation-related constants (NEC2 simulation)
	ExciteU   float64 `json:"exciteU"`   // excitation voltage
	PhiStep   float64 `json:"phiStep"`   // azimut step (degree)
	ThetaStep float64 `json:"thetaStep"` // elevation step (degree)

	// geometry-related constraints (NEC2 simulation)
	WireMax      float64 `json:"wireMax"`      // max. wire diameter (in wavelength)
	SegMinLambda float64 `json:"segMinLambda"` // min. segment length (in wavelength)
	SegMinWire   float64 `json:"segMinWire"`   // min. segment length (in wire diameter)
	MinRadius    float64 `json:"minRadius"`    // min. curve radius (in wavelength)
}

Simulation parameters

type SmithChart

type SmithChart struct {
	// contains filtered or unexported fields
}

SmithChart holds tracks (sequences of impedances) for plotting. It implements the plot.Plotter interface.

func (*SmithChart) Plot

func (sc *SmithChart) Plot(c draw.Canvas, plt *plot.Plot)

Plot is a plot.Plotter implementation

type Source

type Source struct {
	Z     Impedance `json:"Z"`     // source impedance
	Power float64   `json:"power"` // source power
	Freq  int64     `json:"freq"`  // frequency
	Span  int64     `json:"span"`  // freq span
}

Source parameters

func ParseSource

func ParseSource(sourceS string, warn bool) (src Source, err error)

ParseSource converts a source spec into Source

func (Source) Impedance

func (src Source) Impedance() complex128

Impedance of source

func (Source) Lambda

func (src Source) Lambda() float64

Lambda (wavelength) of source frequency

type Specification

type Specification struct {
	K      float64 `json:"k"`      // leg in wavelength
	Wire   Wire    `json:"wire"`   // wire parameters
	Ground Ground  `json:"ground"` // ground parameters
	Source Source  `json:"source"` // source parameters
	Feedpt Feedpt  `json:"feedpt"` // feed point parameters
}

Specification of antenna parameters

type Stats

type Stats struct {
	NumMthds int
	NumSteps int
	NumSims  int
	Elapsed  time.Duration
}

Stats return the optimization statistics

type Table

type Table struct {
	Name   string   // name of table (plot name)
	NumIdx int      // number of indices (parameters)
	Dims   []string // column names
	Vals   [][]any  // values (float64 or complex128)
	Refs   []int    // column references (to selection set)
}

Table data for post-processing (plot)

type Task

type Task struct {
	Ant *Antenna // antenna to be rendered
	Pos int      // position of last change (-1 no change)
	Msg string   // additional message for display
}

Task send via channel to render engine

type TrackList

type TrackList struct {
	Cmts   []string  `json:"comments"`
	SegL   float64   `json:"segL"`
	Num    int       `json:"num"`
	Wire   Wire      `json:"wire"`
	Height float64   `json:"height"`
	Track  []*Change `json:"track"`
}

func (*TrackList) Nodes

func (tl *TrackList) Nodes() []*Node

type Vec3

type Vec3 [3]float64

Vec3 is a 3D vector

func BestFitSphere

func BestFitSphere(pnts []Vec3) (r float64, ctr Vec3, err float64)

BestFitSphere returns the radius and center point of a sphere that bests fits the given points (least square fit).

func NewVec3

func NewVec3(x, y, z float64) (v Vec3)

NewVec3 creates a new 3D vector

func (Vec3) Add

func (v Vec3) Add(u Vec3) (d Vec3)

Add two vectors

func (Vec3) Dot

func (v Vec3) Dot(u Vec3) float64

Dot returns the dot product between two vectors

func (Vec3) Equals

func (v Vec3) Equals(u Vec3) bool

Equals returns true if two vectors are equal

func (Vec3) Length

func (v Vec3) Length() float64

Length of the vector

func (Vec3) MirrorX

func (v Vec3) MirrorX() (w Vec3)

MirrorX mirrors the vector (YZ plane)

func (Vec3) Move2D

func (v Vec3) Move2D(r, a float64) (w Vec3)

Move2D moves a vector in the XY plane

func (Vec3) Mult

func (v Vec3) Mult(k float64) (d Vec3)

Mult returns the multiplication of a vector with a scalar k

func (Vec3) Neg

func (v Vec3) Neg() (d Vec3)

Neg returns the negative vector

func (Vec3) Norm

func (v Vec3) Norm() (u Vec3)

Norm returns a normalized vector

func (Vec3) Prod

func (v Vec3) Prod(u Vec3) (d Vec3)

Prod returns the cross product between two vectors

func (Vec3) String

func (v Vec3) String() string

String returns a human-readable vector

func (Vec3) Sub

func (v Vec3) Sub(u Vec3) (d Vec3)

Sub (substract) two vectors

type Wire

type Wire struct {
	Diameter     float64 `json:"dia"`      // wire diameter
	Material     string  `json:"material"` // wire material
	Conductivity float64 `json:"G"`        // wire conductivity (S/m)
	Inductance   float64 `json:"L"`        // wire inductivity (H/m)
}

Wire parameters

func GetWire

func GetWire(mat string, dia float64) Wire

GetWire for specified diameter and material

func ParseWire

func ParseWire(wireS string, warn bool) (w Wire, err error)

ParseWire converts a specification string into a Wire

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL