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 → constructThe 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 inkeyword_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 withis_radius_input(T, Val(:r_in), x)andis_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.
- Rejects wrong arities: exactly
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 normalizedNamedTuple.- 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_rulesFailing 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
NamedTuplent. - Throw
ArgumentErrorfor logical violations;DomainErrorfor numerical domain violations (non‑finite). - Avoid allocations; use
@inlinewhere appropriate.
Standard rules
Normalized(:field)— field must be numeric post‑parse.Finite(:field)—isfinitemust hold.Nonneg(:field)— value≥ 0.Positive(:field)— value> 0.IntegerField(:field)— valueisa Integer.Less(:a,:b)— strict orderinga < b.LessEq(:a,:b)— non‑strict orderinga ≤ 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)"))
endAttach 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_TUBULARhas_radii = trueenables the radii bundle:Normalized(:r_in),Normalized(:r_ex),Finite,Nonneg,Less(:r_in,:r_ex).has_temperature = trueaddsFinite(:temperature).required_fieldsdefines the mandatory positional fields.keyword_fieldsdefines 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) = trueThe 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)
endConvenience constructor:
@construct Tubular _REQ_TUBULAR _OPT_TUBULAR _DEFS_TUBULARThis 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 →
sanitizeviarequired_fields. - String/complex radii →
sanitizevia defaultis_radius_input(unless explicitly allowed). - Forgotten parsing after allowing proxies → caught by
Normalizedrules. - 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}) = trueExtend _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) = falseTesting guidelines
- Test arity:
(),(1),(1,2)→ArgumentError. - Test raw type rejections: strings, complex numbers.
- Test proxy acceptance: prior layer objects,
Thickness,Diameterwhen 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
NamedTupleupdates to avoid allocations. - When adding rules, benchmark
_applyimplementations.
API reference
LineCableModels.Validation — Module
LineCableModels.ValidationThe 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:
sanitize→parse→ rule application. - Trait hooks configure per‑type behavior (
has_radii,has_temperature,required_fields,keyword_fields,coercive_fields, etc.). - Rules are small value objects (
Rulesubtypes) applied to a normalizedNamedTuple.
Dependencies
BaseLineCableModels.Commons
Exports
LineCableModels.Validation.Finite — Type
struct Finite <: LineCableModels.Validation.RuleRule that enforces finiteness of a numeric field.
name::Symbol: Name of the field to check.
LineCableModels.Validation.Greater — Type
struct Greater <: LineCableModels.Validation.RuleRule that enforces a strict ordering constraint a > b between two fields.
a::Symbol: Left‑hand field name.b::Symbol: Right‑hand field name.
LineCableModels.Validation.GreaterEq — Type
struct GreaterEq <: LineCableModels.Validation.RuleRule that enforces a non‑strict ordering constraint a ≥ b between two fields.
a::Symbol: Left‑hand field name.b::Symbol: Right‑hand field name.
LineCableModels.Validation.IntegerField — Type
struct IntegerField <: LineCableModels.Validation.RuleRule that enforces a field to be of an integer type.
name::Symbol: Name of the field to check.
LineCableModels.Validation.IsA — Type
struct IsA{M} <: LineCableModels.Validation.RuleRule that enforces a field to be isa M for a specified type parameter M.
name::Symbol: Name of the field to check.
LineCableModels.Validation.Less — Type
struct Less <: LineCableModels.Validation.RuleRule that enforces a strict ordering constraint a < b between two fields.
a::Symbol: Left‑hand field name.b::Symbol: Right‑hand field name.
LineCableModels.Validation.LessEq — Type
struct LessEq <: LineCableModels.Validation.RuleRule that enforces a non‑strict ordering constraint a ≤ b between two fields.
a::Symbol: Left‑hand field name.b::Symbol: Right‑hand field name.
LineCableModels.Validation.Nonneg — Type
struct Nonneg <: LineCableModels.Validation.RuleRule that enforces a field to be non‑negative (≥ 0).
name::Symbol: Name of the field to check.
LineCableModels.Validation.Normalized — Type
struct Normalized <: LineCableModels.Validation.RuleRule 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.
LineCableModels.Validation.OneOf — Type
struct OneOf{S} <: LineCableModels.Validation.RuleRule that enforces a field to be in the set S.
name::Symbolset::Any
LineCableModels.Validation.PhysicalFillLimit — Type
struct PhysicalFillLimit <: LineCableModels.Validation.RuleRule 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.
LineCableModels.Validation.Positive — Type
struct Positive <: LineCableModels.Validation.RuleRule that enforces a field to be strictly positive (> 0).
name::Symbol: Name of the field to check.
LineCableModels.Validation.Rule — Type
abstract type RuleBase 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.
LineCableModels.Validation.Satisfies — Type
struct Satisfies <: LineCableModels.Validation.RuleA 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 returnsfalse.
LineCableModels.Validation._apply — Method
_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 byM[dimensionless].nt: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_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: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.Greater,
nt,
_::Type{T}
) -> Any
Applies Greater to ensure nt[a] > nt[b].
Arguments
r: Rule instance with fieldsaandb[dimensionless].nt: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.GreaterEq,
nt,
_::Type{T}
) -> Any
Applies GreaterEq to ensure nt[a] ≥ nt[b].
Arguments
r: Rule instance with fieldsaandb[dimensionless].nt: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_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: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.Less,
nt,
_::Type{T}
) -> Any
Applies Less to ensure nt[a] < nt[b].
Arguments
r: Rule instance with fieldsaandb[dimensionless].nt: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.LessEq,
nt,
_::Type{T}
) -> Any
Applies LessEq to ensure nt[a] ≤ nt[b].
Arguments
r: Rule instance with fieldsaandb[dimensionless].nt: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.Nonneg,
nt,
_::Type{T}
) -> Any
Applies Nonneg to ensure the target field is ≥ 0.
Arguments
r: Rule instance [dimensionless].nt: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_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: NormalizedNamedTuple[dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_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 fieldsn_fieldandgeometry_fields[dimensionless].nt: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws an
ArgumentErroron failure.
LineCableModels.Validation._apply — Method
_apply(
r::LineCableModels.Validation.Positive,
nt,
_::Type{T}
) -> Any
Applies Positive to ensure the target field is > 0.
Arguments
r: Rule instance [dimensionless].nt: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._apply — Method
_apply(
rule::LineCableModels.Validation.Satisfies,
nt,
_::Type{T}
)
Applies Satisfies to evaluate an arbitrary predicate function against the specified fields.
Arguments
rule: Rule instance withfields,predicate, anderror_msg[dimensionless].nt: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws an
ArgumentErroron 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."
)
)LineCableModels.Validation._apply — Method
_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 fieldsnameandset[dimensionless].nt: NormalizedNamedTupleof inputs [dimensionless].::Type{T}: Component type [dimensionless].
Returns
- Nothing. Throws on failure.
LineCableModels.Validation._ensure_real — Method
_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
ArgumentErrorifxis notisa Numberor is aComplexvalue.
Examples
_ensure_real(:r_in, 0.01, SomeType) # okLineCableModels.Validation._kwdefaults_nt — Method
_kwdefaults_nt(_::Type{T}) -> NamedTuple
Internal helper that canonicalizes keyword_defaults(T) into a NamedTuple keyed by keyword_fields(T). Accepts:
()→ returns an emptyNamedTuple().NamedTuple→ returned unchanged.Tuple→ zipped by position withkeyword_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
NamedTuplemapping optional keyword field names to their default values.
Errors
- If
keyword_defaults(T)returns aTuplewhose length differs fromlength(keyword_fields(T)). - If
keyword_defaults(T)returns a value that is neither()nor aNamedTuplenor aTuple.
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
LineCableModels.Validation._repr — Method
_repr(x) -> String
Returns a compact textual representation of x for error messages.
Arguments
x: Value to represent [dimensionless].
Returns
Stringwith a compactrepr[dimensionless].
Examples
s = _repr(:field) # ":field"LineCableModels.Validation._rules — Method
_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
Ruleinstances to apply in order.
LineCableModels.Validation._typename — Method
_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
Stringwith the type name [dimensionless].
Examples
name = _typename(Float64) # "Float64"LineCableModels.Validation.coercive_fields — Method
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.
LineCableModels.Validation.extra_rules — Method
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
Ruleinstances.
LineCableModels.Validation.has_radii — Method
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
Boolflag.
Examples
Validation.has_radii(Tubular) # trueLineCableModels.Validation.has_temperature — Method
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
Boolflag.
LineCableModels.Validation.is_radius_input — Method
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; typicallyVal(:r_in)orVal(:r_ex)[dimensionless].x: Candidate value [dimensionless].
Returns
Boolindicating acceptance.
Examples
Validation.is_radius_input(Tubular, Val(:r_in), 0.01) # true
Validation.is_radius_input(Tubular, Val(:r_ex), 0.01) # trueSee also
LineCableModels.Validation.is_radius_input — Method
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
Boolindicating acceptance.
Examples
Validation.is_radius_input(Tubular, 0.01) # true by default
Validation.is_radius_input(Tubular, 1 + 0im) # false (complex)See also
LineCableModels.Validation.is_radius_input — Method
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
Boolindicating acceptance (truefor real, non‑complex numbers).
Examples
Validation.is_radius_input(Tubular, Val(:r_ex), 0.02) # trueLineCableModels.Validation.is_radius_input — Method
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
Boolindicating acceptance (truefor 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) # falseLineCableModels.Validation.keyword_defaults — Method
keyword_defaults(_::Type) -> Tuple{Float64, Int64}
Trait hook supplying default values for optional keyword fields.
Return either:
- a
NamedTuplemapping defaults by name (e.g.,(temperature = T₀,)), or - a plain
Tupleof defaults aligned withkeyword_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
NamedTupleorTuplewith default keyword values.
LineCableModels.Validation.keyword_fields — Method
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.
LineCableModels.Validation.maxfill — Function
maxfill(::Type{T}, args...)Calculates the maximum physical number of strands that can fit for component T. Custom shapes must overload this method.
LineCableModels.Validation.parse — Method
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 fromsanitize[dimensionless].
Returns
NamedTuplewith normalized fields (e.g., numeric:r_in,:r_ex).
LineCableModels.Validation.required_fields — Method
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.
LineCableModels.Validation.sanitize — Method
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
NamedTuplewith raw (unparsed) fields.
Errors
ArgumentErroron 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,))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
NamedTuplecontaining normalized fields ready for construction.
Errors
ArgumentErrorfromsanitizeor rule checks;DomainErrorfor finiteness violations.
Examples
nt = validate!(Tubular, 0.01, 0.02, material; temperature = 20.0)
# use nt.r_in, nt.r_ex, nt.temperature thereafterSee also
Index
LineCableModels.ValidationLineCableModels.Validation.FiniteLineCableModels.Validation.GreaterLineCableModels.Validation.GreaterEqLineCableModels.Validation.IntegerFieldLineCableModels.Validation.IsALineCableModels.Validation.LessLineCableModels.Validation.LessEqLineCableModels.Validation.NonnegLineCableModels.Validation.NormalizedLineCableModels.Validation.OneOfLineCableModels.Validation.PhysicalFillLimitLineCableModels.Validation.PositiveLineCableModels.Validation.RuleLineCableModels.Validation.SatisfiesLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._applyLineCableModels.Validation._ensure_realLineCableModels.Validation._kwdefaults_ntLineCableModels.Validation._reprLineCableModels.Validation._rulesLineCableModels.Validation._typenameLineCableModels.Validation.coercive_fieldsLineCableModels.Validation.extra_rulesLineCableModels.Validation.has_radiiLineCableModels.Validation.has_temperatureLineCableModels.Validation.is_radius_inputLineCableModels.Validation.is_radius_inputLineCableModels.Validation.is_radius_inputLineCableModels.Validation.is_radius_inputLineCableModels.Validation.keyword_defaultsLineCableModels.Validation.keyword_fieldsLineCableModels.Validation.maxfillLineCableModels.Validation.parseLineCableModels.Validation.required_fieldsLineCableModels.Validation.sanitizeLineCableModels.Validation.validate!