QEDjl-project / QEDprocesses.jl

[WIP]: QEDprocesses.jl: Modeling of scattering processes for QED.jl
MIT License
1 stars 3 forks source link

Process and Model interface #3

Closed szabo137 closed 9 months ago

szabo137 commented 11 months ago

We must implement an interface for definitions of scattering processes and models to describe them.

Suggested implementation

Scattering Process Definition

Deriving from an AbstractProcessDefiniton===APD one needs to implement the following interface functions:

incoming_particles(proc_def::APD)  # returns the incoming particles or fields
outgoing_particles(proc_def::APD)  # returns the outgoing particles

Furthermore, one may implement additional functionality, which can be used on derived quantities like differential cross sections, e.g. polarisations or spins.

Compute Model Defintion

Deriving from an AbstractModelDefinition===AMD one needs to implement the following interface functions:

fundamental_interaction_type(models_def::AMD) # returns the fundamental interaction, e.g. :electromagnetic

Combined interface

The following functions need to be implemented using both,

initial_phasespace_dimension(proc_def::APD, model_def::AMD)                 # returns the dimensionality of the initial phase-space
final_phasespace_dimension(proc_def::APD, model_def::AMD)                   # returns the dimensionality of the final phase-space

Finally, the differential cross section needs to be implemented by providing a concrete implementation for

# returns the value of the differential cross section for given `initPS` and `finalPS`
_differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractVector{T}, finalPS::AbstractVector{T}) where {T<:Real} 

The correct input size does not need to be checked in _differential_cross_section, but will be checked in the derived implementations. Derived from the interface functions above, there should be generic implementations for total and differential cross-sections.

Those generic implementations should be implemented in several different versions:

Unsafe versions without input check

# returns the totalCS for a given `initPS` point without input-check
_total_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractVector{T}) where T<:Real

# returns the totalCS for several given `initPS` points without input-check
_total_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}) where T<:Real

# returns diffCS for single `initPS` and several `finalPS` points without input-check
_differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractVector{T}, finalPS::AbstractMatrix{T}) where {T<:Real}

# returns diffCS for several `initPS` and a single `finalPS` points without input-check
_differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}, finalPS::AbstractVector{T}) where {T<:Real}

# returns diffCS for several `initPS` and several `finalPS` points without input-check
_differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}, finalPS::AbstractMatrix{T}) where {T<:Real}

These functions must not be exported and used by the enduser.

Safe user versions

# returns the totalCS for a given `initPS` point with input-check
total_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractVector{T}) where T<:Real

# returns the totalCS for several given `initPS` points with input-check
total_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}) where T<:Real

# returns diffCS for single `initPS` and several `finalPS` points with input-check
differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractVector{T}, finalPS::AbstractMatrix{T}) where {T<:Real}

# returns diffCS for several `initPS` and a single `finalPS` points with input-check
differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}, finalPS::AbstractVector{T}) where {T<:Real}

# returns diffCS for several `initPS` and several `finalPS` points with input-check
differential_cross_section(proc_def::APD, model_def::AMD, initPS::AbstractMatrix{T}, finalPS::AbstractMatrix{T}) where {T<:Real}

The input-check means, that the length of the phase-space vectors is the same as the respective phase-space dimension. It does not mean, to check the correct energy-momentum conservation (or should it?).

Final thoughts

It might be more convenient to use the checked-unchecked concept for the implementation of differential_cross_section and total_cross_section. Let func be a function, which can be evaluated on a single vector of a certain given length, say n, and producing a scalar, then it is convenient to implement it as follows:

function _func(vec::AbstractVector)
  # Here is the actual function
  # Without the input validation
end

This allows implementations of the wrapper functions to check the input for correctness:


function func(vec::AbstractVector{T})
  length(vec)==n || error("Wrong input")
  return _func(vec)
end

Additionally, the above construction allows implementations using different input types and therefore different validations:

function func(A::AbstractMatrix{T}) where T<:Real
  size(A,1)==n || error("Wrong input")
  result = Vector{T}(undef, size(A,2))
  for idx in 1:size(A,2)
    result[idx] = _func(view(A,:,idx))
  end
end