Validation module

Contents


This section documents the validation framework used by component constructors. The design is deterministic, non‑magical, and trait‑driven. The flow is:

sanitize(Type, args, kwargs)  →  parse(Type, nt)  →  apply rules  →  construct

The typed cores accept numbers only. All proxy handling happens in the convenience constructors via validate!.


Architecture

Pipeline

  • sanitize(::Type{T}, args::Tuple, kwargs::NamedTuple)

    • Rejects wrong arities: exactly length(required_fields(T)) positionals are expected; optionals must be passed as keywords listed in keyword_fields(T).
    • Maps positionals to names using required_fields(T); merges keyword arguments; rejects unknown keywords.
    • If has_radii(T) == true, checks admissibility of raw radius inputs with is_radius_input(T, Val(:r_in), x) and is_radius_input(T, Val(:r_ex), x). The default accepts only real, non‑complex numbers; types may extend to allow proxies.
    • Returns a raw NamedTuple.
  • parse(::Type{T}, nt)

    • Normalizes raw inputs to canonical representation (e.g., radius proxies → numeric radii) while preserving domain semantics (e.g., uncertainty reset rules).
    • Returns a normalized NamedTuple.
  • Rule application

    • _rules(T) is generated from traits; evaluates over the normalized NamedTuple.
    • Standard bundles are injected when traits are true (e.g., for radii: Normalized, Finite, Nonneg, Less).
    • Per‑type extras come from extra_rules(T).
  • validate!(::Type{T}, args...; kwargs...)

    • Orchestrates the pipeline. Use this in all convenience constructors.

Traits (configuration surface)

  • has_radii(::Type{T})::Bool — enables the radii rule bundle and raw acceptance checks.
  • has_temperature(::Type{T})::Bool — enables finiteness check on :temperature.
  • required_fields(::Type{T})::NTuple — positional keys.
  • keyword_fields(::Type{T})::NTuple — keyword argument keys.
  • coercive_fields(::Type{T})::NTuple — values that participate in type promotion and will be coerced (default: required_fields ∪ keyword_fields).
  • is_radius_input(::Type{T}, Val(:field), x)::Bool — raw admissibility predicate for radii inputs; extend to allow proxies by field.
  • extra_rules(::Type{T})::NTuple{K,Rule} — additional constraints appended to the generated bundle.

Import before extending:

import ..Validation: has_radii, has_temperature, required_fields, keyword_fields,
                     coercive_fields, is_radius_input, parse, extra_rules

Failing to import will create shadow functions in your module; the engine will not see your methods.


Rules

Rules are small value types struct <: Rule with an _apply(::Rule, nt, ::Type{T}) method. All rule methods must:

  • Read data from the normalized NamedTuple nt.
  • Throw ArgumentError for logical violations; DomainError for numerical domain violations (non‑finite).
  • Avoid allocations; use @inline where appropriate.

Standard rules

  • Normalized(:field) — field must be numeric post‑parse.
  • Finite(:field)isfinite must hold.
  • Nonneg(:field) — value ≥ 0.
  • Positive(:field) — value > 0.
  • IntegerField(:field) — value isa Integer.
  • Less(:a,:b) — strict ordering a < b.
  • LessEq(:a,:b) — non‑strict ordering a ≤ b.
  • IsA{M}(:field) — type membership check.
  • OneOf(:field, set) — membership in a finite set.

Custom rule pattern

struct InRange{T} <: Validation.Rule
    name::Symbol; lo::T; hi::T
end

@inline function Validation._apply(r::InRange, nt, ::Type{T}) where {T}
    x = getfield(nt, r.name)
    (x isa Number && !(x isa Complex)) || throw(ArgumentError("[$(String(nameof(T)))] $(r.name) must be real"))
    (r.lo ≤ x ≤ r.hi) || throw(ArgumentError("[$(String(nameof(T)))] $(r.name) out of range $(r.lo):$(r.hi), got $(x)"))
end

Attach via extra_rules(::Type{X}) = (InRange(:alpha, 0.0, 1.0), ...).


Example implementation — DataModel.Tubular

Typed core (numbers only):

function Tubular(r_in::T, r_ex::T, material_props::Material{T}, temperature::T) where {T<:REALSCALAR}

Rationale: all proxy resolution must happen before reaching the typed core to avoid duplicate parsing and to keep type promotion deterministic.

Trait configuration:

const _REQ_TUBULAR = (:r_in, :r_ex, :material_props,)
const _OPT_TUBULAR = (:temperature,)
const _DEFS_TUBULAR = (T₀,)

Validation.has_radii(::Type{Tubular}) = true
Validation.has_temperature(::Type{Tubular}) = true
Validation.required_fields(::Type{Tubular}) = _REQ_TUBULAR
Validation.keyword_fields(::Type{Tubular}) = _OPT_TUBULAR
  • has_radii = true enables the radii bundle: Normalized(:r_in), Normalized(:r_ex), Finite, Nonneg, Less(:r_in,:r_ex).
  • has_temperature = true adds Finite(:temperature).
  • required_fields defines the mandatory positional fields.
  • keyword_fields defines the optional fields that will receive default values.

Raw proxy acceptance:

Validation.is_radius_input(::Type{Tubular}, ::Val{:r_in}, x::AbstractCablePart) = true
Validation.is_radius_input(::Type{Tubular}, ::Val{:r_ex}, x::Thickness) = true
Validation.is_radius_input(::Type{Tubular}, ::Val{:r_ex}, x::Diameter) = true

The inner radius may take an existing cable part (its r_ex); the outer radius may take a Thickness or Diameter wrapper.

Extra rules:

Validation.extra_rules(::Type{Tubular}) = (IsA{Material}(:material_props),)

Parsing:

Validation.parse(::Type{Tubular}, nt) = begin
    rin, rex = _normalize_radii(Tubular, nt.r_in, nt.r_ex)
    (; nt..., r_in=rin, r_ex=rex)
end

Convenience constructor:

@construct Tubular _REQ_TUBULAR _OPT_TUBULAR _DEFS_TUBULAR

This expands to a weakly‑typed method that calls validate!, promotes using _promotion_T, coerces via _coerced_args, and delegates to the numeric core.

Failure modes intentionally trapped:

  • Wrong arity, missing keys → sanitize via required_fields.
  • String/complex radii → sanitize via default is_radius_input (unless explicitly allowed).
  • Forgotten parsing after allowing proxies → caught by Normalized rules.
  • Geometry violations (r_in ≥ r_ex) → Less(:r_in,:r_ex).

Template for a new component

# 1) Numeric core (numbers only)
function NewPart(a::T, b::T, material::Material{T}, temperature::T) where {T<:REALSCALAR}
    # compute derived, then construct
end

# 2) Trait config
Validation.has_radii(::Type{NewPart}) = true
Validation.has_temperature(::Type{NewPart}) = true
Validation.required_fields(::Type{NewPart}) = (:a, :b, :material)
Validation.keyword_fields(::Type{NewPart})  = (:temperature,)

# 3) Raw acceptance (extend only what you intend to parse)
Validation.is_radius_input(::Type{NewPart}, ::Val{:r_in},  x::AbstractCablePart) = true
Validation.is_radius_input(::Type{NewPart}, ::Val{:r_ex}, x::Thickness)        = true

# 4) Extra rules
Validation.extra_rules(::Type{NewPart}) = (
    IsA{Material}(:material),
)

# 5) Parsing (proxy → numeric)
Validation.parse(::Type{NewPart}, nt) = begin
    a′, b′ = _normalize_radii(NewPart, nt.a, nt.b)
    (; nt..., a=a′, b=b′)
end

# 6) Convenience constructor — generated
@construct NewPart (:a, :b, :material) (:temperature,) (T₀,)

Extending traits

Traits are just methods. Add traits only when behavior toggles; avoid proliferation.

New feature flags

Example: a shielding flag with its own bundle.

Validation.has_shield(::Type) = false
Validation.has_shield(::Type{SomeType}) = true

Extend _rules inside Validation to splice the corresponding checks when has_shield(T) is true.

Field‑specific admissibility

If only :r_in should accept proxies, extend the field‑tagged predicate:

Validation.is_radius_input(::Type{X}, ::Val{:r_in},  p::AbstractCablePart) = true
Validation.is_radius_input(::Type{X}, ::Val{:r_ex}, ::AbstractCablePart)  = false

Testing guidelines

  • Test arity: (), (1), (1,2)ArgumentError.
  • Test raw type rejections: strings, complex numbers.
  • Test proxy acceptance: prior layer objects, Thickness, Diameter when allowed.
  • Test parse correctness: outputs numeric and respect uncertainty rules.
  • Test rule violations: negative radii, inverted radii, non‑finite values, invalid sets.
  • Test constructor round‑trip: convenience path and numeric core produce equivalent instances after coercion.

Usage notes

  • Keep all proxy handling in parse. Do not call normalizers in constructors.
  • Error messages must be terse and contextualized with the component type name.
  • Prefer tuple returns and NamedTuple updates to avoid allocations.
  • When adding rules, benchmark _apply implementations.

API reference

LineCableModels.ValidationModule
LineCableModels.Validation

The Validation module implements a trait-driven, three-phase input checking pipeline for component constructors in LineCableModels. Inputs are first sanitized (arity and shape checks on raw arguments), then parsed (proxy values normalized to numeric radii), and finally validated by a generated set of rules.

Overview

  • Centralized constructor input handling: sanitizeparse → rule application.
  • Trait hooks configure per‑type behavior (has_radii, has_temperature, required_fields, keyword_fields, coercive_fields, etc.).
  • Rules are small value objects (Rule subtypes) applied to a normalized NamedTuple.

Dependencies

  • Base
  • LineCableModels.Commons

Exports

source
LineCableModels.Validation.GreaterType
struct Greater <: LineCableModels.Validation.Rule

Rule that enforces a strict ordering constraint a > b between two fields.

  • a::Symbol: Left‑hand field name.

  • b::Symbol: Right‑hand field name.

source
LineCableModels.Validation.GreaterEqType
struct GreaterEq <: LineCableModels.Validation.Rule

Rule that enforces a non‑strict ordering constraint a ≥ b between two fields.

  • a::Symbol: Left‑hand field name.

  • b::Symbol: Right‑hand field name.

source
LineCableModels.Validation.IsAType
struct IsA{M} <: LineCableModels.Validation.Rule

Rule that enforces a field to be isa M for a specified type parameter M.

  • name::Symbol: Name of the field to check.
source
LineCableModels.Validation.LessType
struct Less <: LineCableModels.Validation.Rule

Rule that enforces a strict ordering constraint a < b between two fields.

  • a::Symbol: Left‑hand field name.

  • b::Symbol: Right‑hand field name.

source
LineCableModels.Validation.LessEqType
struct LessEq <: LineCableModels.Validation.Rule

Rule that enforces a non‑strict ordering constraint a ≤ b between two fields.

  • a::Symbol: Left‑hand field name.

  • b::Symbol: Right‑hand field name.

source
LineCableModels.Validation.NormalizedType
struct Normalized <: LineCableModels.Validation.Rule

Rule that enforces that a field has already been normalized to a numeric value during parsing. Intended to guard that parse has executed and removed proxies.

  • name::Symbol: Name of the field to check.
source
LineCableModels.Validation.PhysicalFillLimitType
struct PhysicalFillLimit <: LineCableModels.Validation.Rule

Rule that enforces that the number of discrete elements (e.g., wires or strands) does not exceed the theoretical physical maximum for a given geometry.

  • n_field::Symbol: Symbol representing the field containing the element count (e.g., :num_wires).

  • geometry_fields::Tuple{Vararg{Symbol}}: Tuple of symbols representing the geometric fields required to compute the limit.

source
LineCableModels.Validation.RuleType
abstract type Rule

Base abstract type for validation rules. All concrete rule types must subtype Rule and provide an _apply(::Rule, nt, ::Type{T}) method that checks a field in the normalized NamedTuple nt for the component type T.

source
LineCableModels.Validation.SatisfiesType
struct Satisfies <: LineCableModels.Validation.Rule

A highly flexible rule that enforces an arbitrary user-defined predicate across one or more fields. Useful for complex, cross-field physics or one-off geometrical constraints without polluting the ruleset with bespoke types.

  • fields::Tuple{Vararg{Symbol}}: Tuple of symbols representing the fields to be evaluated.

  • predicate::Function: A function (often anonymous) that accepts the extracted fields as arguments and returns a boolean.

  • error_msg::String: The diagnostic message appended to the error if the predicate returns false.

source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.IsA{M},
    nt,
    _::Type{T}
) -> Bool

Applies IsA{M} to ensure a field is of type M.

Arguments

  • r: Rule instance parameterized by M [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Finite,
    nt,
    _::Type{T}
) -> Any

Applies Finite to ensure the target field is a finite real number.

Arguments

  • r: Rule instance [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Greater,
    nt,
    _::Type{T}
) -> Any

Applies Greater to ensure nt[a] > nt[b].

Arguments

  • r: Rule instance with fields a and b [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.GreaterEq,
    nt,
    _::Type{T}
) -> Any

Applies GreaterEq to ensure nt[a] ≥ nt[b].

Arguments

  • r: Rule instance with fields a and b [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.IntegerField,
    nt,
    _::Type{T}
) -> Bool

Applies IntegerField to ensure the target field is an Integer.

Arguments

  • r: Rule instance [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Less,
    nt,
    _::Type{T}
) -> Any

Applies Less to ensure nt[a] < nt[b].

Arguments

  • r: Rule instance with fields a and b [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.LessEq,
    nt,
    _::Type{T}
) -> Any

Applies LessEq to ensure nt[a] ≤ nt[b].

Arguments

  • r: Rule instance with fields a and b [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Nonneg,
    nt,
    _::Type{T}
) -> Any

Applies Nonneg to ensure the target field is ≥ 0.

Arguments

  • r: Rule instance [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Normalized,
    nt,
    _::Type{T}
) -> Bool

Applies Normalized to ensure the field has been converted to a numeric value during parsing.

Arguments

  • r: Rule instance [dimensionless].
  • nt: Normalized NamedTuple [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    rule::LineCableModels.Validation.PhysicalFillLimit,
    nt,
    _::Type{T}
)

Applies PhysicalFillLimit to ensure the element count does not exceed the capacity computed by the extensible maxfill interface.

Arguments

  • rule: Rule instance with fields n_field and geometry_fields [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws an ArgumentError on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.Positive,
    nt,
    _::Type{T}
) -> Any

Applies Positive to ensure the target field is > 0.

Arguments

  • r: Rule instance [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._applyMethod
_apply(
    rule::LineCableModels.Validation.Satisfies,
    nt,
    _::Type{T}
)

Applies Satisfies to evaluate an arbitrary predicate function against the specified fields.

Arguments

  • rule: Rule instance with fields, predicate, and error_msg [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws an ArgumentError on failure.

Examples

Validation.extra_rules(::Type{SomeWeirdType}) = (
	# ... basic type rules ...
	
	Satisfies(
		(:width, :lay_angle, :overlap_pct),
		(w, a, pct) -> pct < 1.0 && pct >= 0.0 && w * cos(a) > 0,
		"Overlap percentage must be between 0 and 1, and effective width must be positive. Because I said so."
	)
)
source
LineCableModels.Validation._applyMethod
_apply(
    r::LineCableModels.Validation.OneOf{S},
    nt,
    _::Type{T}
) -> Any

Applies OneOf to ensure the target field is contained in a specified set.

Arguments

  • r: Rule instance with fields name and set [dimensionless].
  • nt: Normalized NamedTuple of inputs [dimensionless].
  • ::Type{T}: Component type [dimensionless].

Returns

  • Nothing. Throws on failure.
source
LineCableModels.Validation._ensure_realMethod
_ensure_real(field::Symbol, x, _::Type{T})

Asserts that x is a real (non‑complex) number. Used by rule implementations before performing numeric comparisons.

Arguments

  • field: Field name used in diagnostics [dimensionless].
  • x: Value to check [dimensionless].
  • ::Type{T}: Component type for contextualized messages [dimensionless].

Returns

  • Nothing. Throws on failure.

Errors

  • ArgumentError if x is not isa Number or is a Complex value.

Examples

_ensure_real(:r_in, 0.01, SomeType)  # ok
source
LineCableModels.Validation._kwdefaults_ntMethod
_kwdefaults_nt(_::Type{T}) -> NamedTuple

Internal helper that canonicalizes keyword_defaults(T) into a NamedTuple keyed by keyword_fields(T). Accepts:

  • () → returns an empty NamedTuple().
  • NamedTuple → returned unchanged.
  • Tuple → zipped by position with keyword_fields(T); lengths must match.

This function does not merge user-provided keywords; callers should perform merge(_kwdefaults_nt(T), kwargs) so that user values take precedence.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • NamedTuple mapping optional keyword field names to their default values.

Errors

  • If keyword_defaults(T) returns a Tuple whose length differs from length(keyword_fields(T)).
  • If keyword_defaults(T) returns a value that is neither () nor a NamedTuple nor a Tuple.

Examples

```julia

Suppose:

keywordfields(::Type{X}) = (:temperature, :laydirection)

keyword_defaults(::Type{X}) = (T₀, 1)

kwdefaultsnt(X) # => (temperature = T₀, lay_direction = 1)

If defaults are already a NamedTuple:

keyword_defaults(::Type{Y}) = (temperature = 25.0,)

kwdefaultsnt(Y) # => (temperature = 25.0,) ````

See also

source
LineCableModels.Validation._reprMethod
_repr(x) -> String

Returns a compact textual representation of x for error messages.

Arguments

  • x: Value to represent [dimensionless].

Returns

  • String with a compact repr [dimensionless].

Examples

s = _repr(:field)  # ":field"
source
LineCableModels.Validation._rulesMethod
_rules(_::Type{T}) -> Tuple

Generates (at compile time, via a @generated function) the tuple of rules to apply for component type T. The result concatenates standard bundles driven by traits and any rules returned by extra_rules(T).

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Tuple of Rule instances to apply in order.
source
LineCableModels.Validation._typenameMethod
_typename(_::Type{T}) -> String

Returns the simple (unqualified) name of type T as a String. Utility for constructing diagnostic messages.

Arguments

  • ::Type{T}: Type whose name is requested [dimensionless].

Returns

  • String with the type name [dimensionless].

Examples

name = _typename(Float64)  # "Float64"
source
LineCableModels.Validation.coercive_fieldsMethod
coercive_fields(_::Type{T}) -> NTuple{5, Symbol}

Trait hook listing coercive fields: values that participate in numeric promotion and will be converted to the promoted type by the convenience constructor. Defaults to all fields (required_fields ∪ keyword_fields). Types may override to exclude integers or categorical fields.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Tuple of field names that are coerced.
source
LineCableModels.Validation.extra_rulesMethod
extra_rules(
    _::Type
) -> Tuple{LineCableModels.Validation.IsA{Material}, LineCableModels.Validation.OneOf{Tuple{Int64, Int64}}, LineCableModels.Validation.Finite, LineCableModels.Validation.Nonneg, LineCableModels.Validation.Finite, LineCableModels.Validation.Positive}

Trait hook providing additional rule instances for a component type. Used to append per‑type constraints after the standard bundles.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Tuple of Rule instances.
source
LineCableModels.Validation.has_radiiMethod
has_radii(_::Type) -> Bool

Trait hook enabling the annular radii rule bundle on fields :r_in and :r_ex (normalized numbers required, finiteness, non‑negativity, and the ordering constraint :r_in < :r_ex). It does not indicate the mere existence of radii; it opts in to the annular/coaxial shell geometry checks.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Bool flag.

Examples

Validation.has_radii(Tubular)  # true
source
LineCableModels.Validation.has_temperatureMethod
has_temperature(_::Type) -> Bool

Trait hook indicating whether a component type uses a :temperature field subject to finiteness checks.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Bool flag.
source
LineCableModels.Validation.is_radius_inputMethod
is_radius_input(_::Type{T}, _::Val{F}, x) -> Bool

Field‑aware acceptance predicate used by sanitize to distinguish inner vs. outer radius policies. The default forwards to is_radius_input(::Type{T}, x) when no field‑specific method is defined.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • ::Val{F}: Field tag; typically Val(:r_in) or Val(:r_ex) [dimensionless].
  • x: Candidate value [dimensionless].

Returns

  • Bool indicating acceptance.

Examples

Validation.is_radius_input(Tubular, Val(:r_in), 0.01)   # true
Validation.is_radius_input(Tubular, Val(:r_ex), 0.01)  # true

See also

source
LineCableModels.Validation.is_radius_inputMethod
is_radius_input(_::Type{T}, x) -> Bool

Trait predicate that defines admissible raw radius inputs for a component type during sanitize. The default accepts real, non‑complex numbers only. Component code may extend this to allow proxies (e.g., AbstractCablePart, Thickness, Diameter).

Arguments

  • ::Type{T}: Component type [dimensionless].
  • x: Candidate value [dimensionless].

Returns

  • Bool indicating acceptance.

Examples

Validation.is_radius_input(Tubular, 0.01)  # true by default
Validation.is_radius_input(Tubular, 1 + 0im)  # false (complex)

See also

source
LineCableModels.Validation.is_radius_inputMethod
is_radius_input(
    _::Type{T},
    _::Val{:r_ex},
    x::Number
) -> Bool

Default policy for outer radius raw inputs (annular shells): accept real numbers. Proxies are rejected at this stage to prevent zero‑thickness stacking.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • ::Val{:r_ex}: Field tag for the outer radius [dimensionless].
  • x::Number: Candidate value [dimensionless].

Returns

  • Bool indicating acceptance (true for real, non‑complex numbers).

Examples

Validation.is_radius_input(Tubular, Val(:r_ex), 0.02)  # true
source
LineCableModels.Validation.is_radius_inputMethod
is_radius_input(
    _::Type{T},
    _::Val{:r_in},
    x::Number
) -> Bool

Default policy for inner radius raw inputs: accept real numbers.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • ::Val{:r_in}: Field tag for the inner radius [dimensionless].
  • x::Number: Candidate value [dimensionless].

Returns

  • Bool indicating acceptance (true for real, non‑complex numbers).

Examples

Validation.is_radius_input(Tubular, Val(:r_in), 0.0)   # true
Validation.is_radius_input(Tubular, Val(:r_in), 1+0im) # false
source
LineCableModels.Validation.keyword_defaultsMethod
keyword_defaults(_::Type) -> Tuple{Float64, Int64}

Trait hook supplying default values for optional keyword fields.

Return either:

  • a NamedTuple mapping defaults by name (e.g., (temperature = T₀,)), or
  • a plain Tuple of defaults aligned with keyword_fields(T) (same order + length).

Defaults are applied in sanitize after positional→named merge and before rule application. User-provided keywords always override these defaults.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • NamedTuple or Tuple with default keyword values.
source
LineCableModels.Validation.keyword_fieldsMethod
keyword_fields(_::Type) -> Tuple{Symbol, Symbol}

Trait hook listing optional keyword fields considered by sanitize.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Tuple of optional keyword field names.
source
LineCableModels.Validation.maxfillFunction
maxfill(::Type{T}, args...)

Calculates the maximum physical number of strands that can fit for component T. Custom shapes must overload this method.

source
LineCableModels.Validation.parseMethod
parse(
    _::Type,
    nt
) -> Union{NamedTuple, DataStructures.SortedMultiDict}

Parses and normalizes raw inputs produced by sanitize into the canonical form expected by rules. Default is identity; component code overrides this to resolve proxy radii to numeric values while preserving uncertainty semantics.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • nt::NamedTuple: Raw inputs from sanitize [dimensionless].

Returns

  • NamedTuple with normalized fields (e.g., numeric :r_in, :r_ex).
source
LineCableModels.Validation.required_fieldsMethod
required_fields(_::Type) -> NTuple{5, Symbol}

Trait hook listing required fields that must be present after positional→named merge in sanitize.

Arguments

  • ::Type{T}: Component type [dimensionless].

Returns

  • Tuple of required field names.
source
LineCableModels.Validation.sanitizeMethod
sanitize(
    _::Type{T},
    args::Tuple,
    kwargs::NamedTuple
) -> NamedTuple

Performs raw input checks and shapes the input into a NamedTuple without parsing proxies. Responsibilities: arity validation, positional→named mapping, required field presence, and raw acceptance of radius inputs via is_radius_input when has_radii(T) is true.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • args::Tuple: Positional arguments as received by the convenience constructor [dimensionless].
  • kwargs::NamedTuple: Keyword arguments [dimensionless].

Returns

  • NamedTuple with raw (unparsed) fields.

Errors

  • ArgumentError on invalid arity, excess positional arguments, missing required fields, or rejected raw radius inputs.

Notes

Required arguments must be positional; optional arguments must be passed as keywords. Positional arity must equal length(required_fields(T)).

Examples

nt = sanitize(Tubular, (0.01, 0.02, material), (; temperature = 20.0,))
source
LineCableModels.Validation.validate!Method
validate!(::Type{T}, args...; kwargs...) -> Any

Runs the full validation pipeline for a component type: sanitize (arity and raw checks), parse (proxy normalization), then application of the generated rule set. Intended to be called from convenience constructors.

Arguments

  • ::Type{T}: Component type [dimensionless].
  • args...: Positional arguments [dimensionless].
  • kwargs...: Keyword arguments [dimensionless].

Returns

  • NamedTuple containing normalized fields ready for construction.

Errors

  • ArgumentError from sanitize or rule checks; DomainError for finiteness violations.

Examples

nt = validate!(Tubular, 0.01, 0.02, material; temperature = 20.0)
# use nt.r_in, nt.r_ex, nt.temperature thereafter

See also

source

Index