Class ComplexField
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
This class is a matrix of complex values. If no
imaginary part is needed (real valued fields) one can set a special
flag that indicates a real valued field (ComplexField with imaginary part
zero). This different internal representations are used to optimize the
computer memory and computational time.
Operators (\(a+b\), \(a-b\), \(a*b\) and \(a/b\)) can be used.
Passing \(a\) or \(b\) as Complex or double is supported (Except of \(/\) where \(b\) may only be a scalar).
Operator \(a|b\) is used for calculation of inner product of two ComplexFields:
\(a|b=\sum _{j=0}^{m}\sum _{i=0}^{n}a_{{i,j}}b_{{i,j}^{\star}}\) (\(z^{\star}\) means conjugation of complex number).
IsComplex property is always taken from first operand.
public class ComplexField : ILargeArray<Complex>, ICloneable, IDisposable
- Inheritance
-
ComplexField
- Implements
- Derived
- Inherited Members
Constructors
ComplexField()
Creates a ComplexField with 3 × 3 sampling points. The internal data presentation is complex.
public ComplexField()
ComplexField(ComplexField)
Copy constructor.
public ComplexField(ComplexField field)
Parameters
fieldComplexFieldField to copy.
ComplexField(Vector)
Creates a ComplexField with given number of sampling points. The internal data presentation is complex.
public ComplexField(Vector samplingPoints)
Parameters
samplingPointsVectorNumber of points in x- and y-direction.
ComplexField(Vector, bool, Func<int, int, double>, ParallelizationType)
Constructs a ComplexField object with given number of sampling points using a real-valued function which will be evaluated to fill in the complex amplitudes. The parameters x and y of the real function are measured in pixel coordinates whose origin is the upper left corner of the field.
public ComplexField(Vector samplingPoints, bool createComplexField, Func<int, int, double> function, ParallelizationType parallelizationType = ParallelizationType.Always)
Parameters
samplingPointsVectorNumber of pixels in x-and y-direction.
createComplexFieldboolIndicates if new ComplexField should internally store real + imaginary part (
createComplexField = true) or the real part only (createComplexField = false).functionFunc<int, int, double>Function delegate to be evaluated.
parallelizationTypeParallelizationTypeOptional type of the parallelization (ParallelizationType.AutomaticMeasure by default). Set it to ParallelizationType.NoParallelization if the method passed by the function delegate is not thread-safe.
ComplexField(Vector, bool, PrecisionMode, bool)
Creates a ComplexField with given number of sampling points. The internal data representation can be complex or real.
public ComplexField(Vector samplingPoints, bool isComplex, PrecisionMode precision = PrecisionMode.Double, bool initializeValues = true)
Parameters
samplingPointsVectorNumber of values in x- and y-direction.
isComplexboolIndicates if new Complex Field should internally store real + imaginary part (complex = true) or the real part only (complex = false) (imaginary part is zero).
precisionPrecisionModeOptional and obsolete. Should not be used.
initializeValuesboolIf this optional parameter is set to false, the field values are not initialized. Should be used only if the values are initialized immediately afterwards, but then performance is better.
ComplexField(Vector, Func<int, int, Complex>, ParallelizationType)
Constructs a ComplexField object with given number of sampling points using a complex-valued function which will be evaluated to fill in the complex amplitudes. The parameters x and y of the real function are measured in pixel coordinates whose origin is the upper left corner of the field.
public ComplexField(Vector samplingPoints, Func<int, int, Complex> function, ParallelizationType parallelizationType = ParallelizationType.Always)
Parameters
samplingPointsVectorNumber of pixels in x-and y-direction.
functionFunc<int, int, Complex>Function delegate to be evaluated.
parallelizationTypeParallelizationTypeOptional type of the parallelization (ParallelizationType.AutomaticMeasure by default). Set it to ParallelizationType.NoParallelization if the method passed by the function delegate is not thread-safe.
ComplexField(Vector, Complex, bool)
Creates a ComplexField with given number of sampling points. The internal data representation can be complex or real. Field is filled with constant value. In case of a real valued complex field only the real part of constant value is stored.
public ComplexField(Vector samplingPoints, Complex c, bool isComplex = true)
Parameters
samplingPointsVectorNumber of values in x- and y-direction.
cComplexComplex number with which the field is to be initialized.
isComplexboolThis optional parameter indicates if the new ComplexField should internally store real + imaginary part (true, which is the default) or the real part only (false) (imaginary part is zero).
Properties
IsComplex
Gets or sets the internal representation of the values. If IsComplex is true the real and imaginary part is stored. If IsComplex is false only the real part is stored. Then it is assumed that the imaginary part is zero. Setting this property will convert the ComplexField from present representation to new one. Information can be lost during this conversion.
public virtual bool IsComplex { get; set; }
Property Value
IsOneD
Indicates whether field is one-dimensional or not.
public virtual bool IsOneD { get; }
Property Value
this[int, int]
Indexer to access complex values of complex field. Property performs a range checking before every access. If you try to read a complex value and index is out of range Complex(0) is returned. If you try to set a complex value and index is out of range nothing will happen. Indexer returns always a Complex number. If IsComplex is false only the real part is stored.
public virtual Complex this[int x, int y] { get; set; }
Parameters
Property Value
SamplingPoints
Gets or sets the number of sampling points of this ComplexField. Setting a new number of sampling points will embed the sampling points in zero values or extract the central sampling points. See also EmbedExtract(Vector).
public virtual Vector SamplingPoints { get; set; }
Property Value
SamplingPointsOneD
Gets number of sampling points of one-dimensional field. An exception will be thrown, if field is two-dimensional.
public int SamplingPointsOneD { get; }
Property Value
Methods
AddConjugate()
Adds conjugated ComplexField to current one.
public void AddConjugate()
AddEqual(Complex)
Adds a Complex to all sampling points of this ComplexField.
public void AddEqual(Complex c)
Parameters
cComplexComplex number to add to current field.
AddEqual(ComplexField)
Adds another ComplexField to current one. Both fields must have the same number of sampling points.
public void AddEqual(ComplexField field)
Parameters
fieldComplexFieldComplex field to add to current field.
AddEqual(ComplexField, CancellationToken)
Adds another ComplexField to current one. Both fields must have the same number of sampling points.
public void AddEqual(ComplexField field, CancellationToken cancellationToken)
Parameters
fieldComplexFieldComplex field to add to current field.
cancellationTokenCancellationTokenToken for cooperative task cancellation.
ClipAmplitude(double)
Sets all amplitude values greater than clippingLevel to clippingLevel.
public void ClipAmplitude(double clippingLevel)
Parameters
clippingLeveldoubleMaximal value of amplitude.
Clone()
Clones this complex field.
public virtual object Clone()
Returns
Conjugate()
Conjugates current ComplexField.
public void Conjugate()
ConvertFrom2D_DoubleArray(double[,])
Converts a two dimensional double array to a two dimensional complex field
public static ComplexField ConvertFrom2D_DoubleArray(double[,] doubleArray)
Parameters
doubleArraydouble[,]The double array to convert
Returns
- ComplexField
Complex field, created from the double array
ConvertFrom2_1D_DoubleArrays(double[], double[])
Converts two one-dimensional double arrays to a two dimensional complex field of dimensions 2 × doubleArray1.Length
public static ComplexField ConvertFrom2_1D_DoubleArrays(double[] doubleArray1, double[] doubleArray2)
Parameters
doubleArray1double[]The first double array to convert
doubleArray2double[]The second double array to convert
Returns
- ComplexField
Complex field, created from the double arrays.
ConvertFrom_1D_ComplexArray(Complex[])
Converts one one-dimensional complex array to a one-dimensional complex field
public static ComplexFieldDerivative1D ConvertFrom_1D_ComplexArray(Complex[] complexArray)
Parameters
complexArrayComplex[]The complex array to convert
Returns
- ComplexFieldDerivative1D
Complex field, created from the complex array
ConvertFrom_1D_DoubleArray(double[])
Converts one one-dimensional double array to a one-dimensional complex field
public static CFieldDerivative1DReal ConvertFrom_1D_DoubleArray(double[] doubleArray)
Parameters
doubleArraydouble[]The double array to convert
Returns
- CFieldDerivative1DReal
Complex field, created from the double array
ConvertTo1D_DoubleArray(ComplexField, bool)
Converts a one dimensional complex field to a one dimensional double array
public static double[] ConvertTo1D_DoubleArray(ComplexField complexField, bool errorWhenComplex)
Parameters
complexFieldComplexFieldComplex field to convert
errorWhenComplexboolShall an exception be thrown if the complex field is not real valued? Please note: The Imaginary part will be ignored in every case!
Returns
- double[]
Double array, created from the complex field
ConvertTo2D_DoubleArray(ComplexField, bool)
Converts a two dimensional complex field to a two dimensional double array
public static double[,] ConvertTo2D_DoubleArray(ComplexField complexField, bool errorWhenComplex)
Parameters
complexFieldComplexFieldComplex field to convert
errorWhenComplexboolShall an exception be thrown if the complex field is not real valued? Please note: The Imaginary part will be ignored in every case!
Returns
- double[,]
Double array, created from the complex field
DivEqual(Complex)
Divides all values in this ComplexField by a complex number.
public void DivEqual(Complex c)
Parameters
cComplexComplex number to divide.
DivEqual(ComplexField)
Divides this ComplexField by passed one. Both fields must have the same number of sampling points.
public void DivEqual(ComplexField field)
Parameters
fieldComplexFieldComplex field used as divisor.
EmbedCorner(Vector)
Embeds this ComplexField into double side-length field of zero sampling points and places the original in bottom left corner of the new field. If this ComplexField is one-dimensional, only longer side of field is doubled.
public void EmbedCorner(Vector newSize)
Parameters
newSizeVectorNew Size in pixel.
EmbedExtract()
Embeds this ComplexField into double side-length field of zero sampling points and places the original in the middle of the new field. If this ComplexField is one-dimensional, only longer side of field is doubled.
public virtual void EmbedExtract()
EmbedExtract(Rectangle)
Extracts a region of this ComplexField including the bottom left corner but excluding the top right corner.
public virtual ComplexField EmbedExtract(Rectangle rectangle)
Parameters
rectangleRectangleRegion to extract.
Returns
- ComplexField
Result of operation.
EmbedExtract(Vector)
Embeds this ComplexField into field of passed size of zero sampling points and places the original in the middle of the new field. By decreasing size, field can be extracted.
public virtual void EmbedExtract(Vector newSize)
Parameters
newSizeVectorNew size in pixels.
Equals(object)
Checks whether two complex fields represent the same values.
public override bool Equals(object obj)
Parameters
objobjectComplex field to be compared
Returns
Extract(Vector, VectorL, bool)
Extracts the given region at given position out of the current field. Points exceeding boundaries of current field will be ignored.
public ComplexField Extract(Vector size, VectorL position, bool elliptical = false)
Parameters
sizeVectorsize of the region to extract.
positionVectorLPosition at which field is to be extracted.
ellipticalboolElliptical extraction?
Returns
- ComplexField
The extracted field
ExtractColumn(int)
Extracts a column out of the current field. Points exceeding boundaries of current field will be set to zero.
public ComplexField ExtractColumn(int colIndex)
Parameters
colIndexintIndex of the column to extract.
Returns
- ComplexField
A ComplexField with only the extracted column.
ExtractRow(int)
Extracts a row out of the current field. Points exceeding boundaries of current field will be set to zero.
public ComplexField ExtractRow(int rowIndex)
Parameters
rowIndexintindex of the row to extract.
Returns
- ComplexField
A ComplexField with only the extracted row.
Fill(Complex)
Fills whole current ComplexField with the specified complex value.
public void Fill(Complex c)
Parameters
cComplexComplex value to fill the field with.
Fill(Complex, Rectangle, bool, bool)
Fills whole ComplexField inside marker with the specified complex value. If inside is set to false, field outside marker will be filled.
public void Fill(Complex c, Rectangle marker, bool inside, bool elliptical = false)
Parameters
cComplexComplex value to fill the field with.
markerRectangleRegion that decides where to fill.
insideboolFill inside or outside of the marker.
ellipticalboolFill elliptical instead of rectangular region?
HorizontalMirror()
Performs a horizontal mirroring of this ComplexField. [SamplingPoints.X - x - 1, y] = [x, y]
public void HorizontalMirror()
Insert(ComplexField, VectorL, bool)
Inserts the given ComplexField into current field at given position. Points exceeding boundaries of current field will be ignored.
public void Insert(ComplexField field, VectorL position, bool elliptical = false)
Parameters
fieldComplexFieldComplex field to insert.
positionVectorLPosition at which field is to be inserted (offset of 'field' to 'this').
ellipticalboolElliptical insertion?
InsertColumn(int)
Inserts or appends an empty column.
public void InsertColumn(int colIndex)
Parameters
colIndexintIndex of column left of inserted column or -1 to append column.
InsertRow(int)
Inserts or appends an empty row.
public void InsertRow(int rowIndex)
Parameters
rowIndexintIndex of row below inserted row or -1 to append row.
InvertValues()
Sets all points where field is zero to one, and all other points of the field to zero
public void InvertValues()
LiftPositive()
Lifts real part of this ComplexField to positive numbers. Function detects the minimum real number. If this number is smaller than zero it adds the absolute value of the minimum to all values. If the minimum real number is larger than zero the present object is returned without changes.
public void LiftPositive()
ModifyComplexPart(ComplexPart, bool, double, double, CancellationToken?)
Extract, shifts or swaps complex parts of the complex field.
public void ModifyComplexPart(ComplexPart complexPart, bool makeRealValuedIfSuitable = false, double thresholdForPhaseArtifacts = 0, double amplitudeMaximum = 0, CancellationToken? cancellationToken = null)
Parameters
complexPartComplexPartEnumerator element for desired action on this ComplexField.
makeRealValuedIfSuitableboolIf this optional parameter is set to true the field is made real-valued if the imaginary part is zeroized. This is e.g. the case for extract amplitude and shift phase to real.
thresholdForPhaseArtifactsdoubleOptional threshold for suppressing phase artifacts.
amplitudeMaximumdoubleOptional amplitude maximum, needed for calculating an absolute artifacts threshold from the relative one.
cancellationTokenCancellationToken?Optional token for cooperative task cancellation.
ModifyPixels(Func<Complex, int, int, Complex>)
Modifies all pixels in parallel. Can be used if the new pixel value depends on the old pixel value and the current position in pixel coordinates (and maybe some fixed parameters).
public void ModifyPixels(Func<Complex, int, int, Complex> modificationMethod)
Parameters
ModifyPixels(Func<Complex, Complex>)
Modifies all pixels in parallel. Can be used if the new pixel value depends only on the old pixel value (and maybe some fixed parameters).
public void ModifyPixels(Func<Complex, Complex> modificationMethod)
Parameters
MultEqual(Complex)
Multiplies a Complex number to each sampling point of this ComplexField.
public void MultEqual(Complex c)
Parameters
cComplexComplex number used as factor.
MultEqual(ComplexField)
Multiplies another ComplexField with current one. Both fields must have the same number of sampling points.
public void MultEqual(ComplexField field)
Parameters
fieldComplexFieldComplex field used as factor.
MultEqual(IRegion1D2D)
Multiplies a IRegion1D2D with this ComplexField.
public void MultEqual(IRegion1D2D region)
Parameters
regionIRegion1D2DRegion used as factor. The coordinates of that region must be relative to this ComplexField. This means that the extension of the region is 1 and centered around (0, 0) if it covers exactly the complete ComplexField.
Normalize(Rectangle?)
Normalizes this ComplexField so that maximal amplitude inside the given rectangle is one.
public void Normalize(Rectangle? rectangle = null)
Parameters
rectangleRectangle?If this optional parameter is set only the region within the specified rectangle is taken into account for the calculation of the maximum being the normalization reference. Else the whole filed is normalized.
PowerEqual(Complex)
Raises every element of this ComplexField to the power of the passed complex number.
public void PowerEqual(Complex c)
Parameters
cComplexComplex exponent.
Replicate_Periodic(Vector)
Replicates current ComplexField periodically, old field is centered around (0,0). Needs new size.
public void Replicate_Periodic(Vector newSize)
Parameters
newSizeVectorNew size in pixels.
Rotate180()
Rotates this ComplexField through 180° about the field center.
public void Rotate180()
Shift(Vector, bool)
Shifts current ComplexField by a specified distance. Size is not modified, so sampling points can get lost.
public void Shift(Vector shift, bool assumePeriodicField = false)
Parameters
shiftVectorShift in pixels.
assumePeriodicFieldboolIf this optional parameter is set to true a periodic field is assumed. Else zeros occur outside of the shifted original field.
ShiftColumnFromOnePositionToAnother(int, int)
Shifts a single column from one pixel index to another
public void ShiftColumnFromOnePositionToAnother(int oldColIndex, int newColIndex)
Parameters
ShiftRowFromOnePositionToAnother(int, int)
Shifts a single row from one pixel index to another
public void ShiftRowFromOnePositionToAnother(int oldRowIndex, int newRowIndex)
Parameters
SortColumns(int[])
Method which brings all columns into a new, given order. Since this is not optimized, it shall not be used if a) the field is to be mirrored or b) only a single column is to be shifted.
public void SortColumns(int[] newColIndices)
Parameters
newColIndicesint[]Array with the new indices for all columns: the array index is the new index, the array item is the old index.
SortRows(int[])
Method which brings all rows into a new, given order. Since this is not optimized, it shall not be used if a) the field is to be mirrored or b) only a single row is to be shifted.
public void SortRows(int[] newRowIndices)
Parameters
newRowIndicesint[]Array with the new indices for all rows: the array index is the new index, the array item is the old index.
SubEqual(Complex)
Subtracts a Complex from all sampling points of this ComplexField.
public void SubEqual(Complex c)
Parameters
cComplexComplex number to subtract form current field.
SubEqual(ComplexField)
Subtracts another ComplexField from current one. Both fields must have the same number of sampling points.
public void SubEqual(ComplexField field)
Parameters
fieldComplexFieldComplex field to subtract form current field.
Transpose()
Transposes this ComplexField. This means [x, y] = [y, x].
public void Transpose()
VerticalMirror()
Performs a vertical mirroring of this ComplexField. [x, SamplingPoints.Y - y - 1] = [x, y]
public void VerticalMirror()
Operators
operator +(ComplexField, Complex)
Adds a complex value to all values of a complex field.
public static ComplexField operator +(ComplexField field, Complex c)
Parameters
fieldComplexFieldThe ComplexField.
cComplexThe complex value.
Returns
- ComplexField
The result of the operator.
operator +(ComplexField, ComplexField)
Adds two complex fields. Both fields must have the same number of sampling points. Keep in mind that the AddEqual(ComplexField) method is more performant than the += operator.
[Obsolete("Keep in mind that the AddEqual method is more performant than the += operator.")]
public static ComplexField operator +(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field to be added.
field2ComplexFieldThe second field to be added.
Returns
- ComplexField
The result of the operator.
Exceptions
operator |(ComplexField, ComplexField)
Computes the inner (or scalar) product of two complex fields as defined by (u|v) := Integrate[u(x) * v^(x), {x, -Infinity, Infinity}].
public static Complex operator |(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field.
field2ComplexFieldThe second field.
Returns
- Complex
The inner product.
operator /(ComplexField, Complex)
Divides a complex field by a complex number
public static ComplexField operator /(ComplexField field, Complex c)
Parameters
fieldComplexFieldThe complex field.
cComplexThe complex number.
Returns
- ComplexField
The result of the operation.
operator /(ComplexField, ComplexField)
Divides two complex fields.
public static ComplexField operator /(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field.
field2ComplexFieldThe second field.
Returns
- ComplexField
The result of the operation.
operator ==(ComplexField, ComplexField)
Compares two complex fields for equality
public static bool operator ==(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field.
field2ComplexFieldThe second field.
Returns
operator !=(ComplexField, ComplexField)
Compares two complex fields for inequality.
public static bool operator !=(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field.
field2ComplexFieldThe second field.
Returns
operator *(Complex, ComplexField)
Multiplies a complex value to a complex field.
public static ComplexField operator *(Complex c, ComplexField field)
Parameters
cComplexThe complex value.
fieldComplexFieldThe field.
Returns
- ComplexField
The result of the operator.
operator *(ComplexField, Complex)
Multiplies a complex value to all values of a complex field.
public static ComplexField operator *(ComplexField field, Complex c)
Parameters
fieldComplexFieldThe field.
cComplexThe complex value.
Returns
- ComplexField
The result of the operator.
operator *(ComplexField, ComplexField)
Multiplies two complex fields. Both fields must have the same number of sampling points. Keep in mind that the AddEqual(ComplexField) method is more performant than the += operator.
[Obsolete("Keep in mind that the AddEqual method is more performant than the += operator.")]
public static ComplexField operator *(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldthe first field
field2ComplexFieldthe second field
Returns
- ComplexField
The result of the operator.
Exceptions
operator -(Complex, ComplexField)
Subtracts a complex number and a complex field.
public static ComplexField operator -(Complex c, ComplexField field)
Parameters
cComplexComplex number.
fieldComplexFieldComplex Field to subtract.
Returns
- ComplexField
Difference of the complex field and the complex number.
operator -(ComplexField, Complex)
Subtracts a complex value from all values of a complex field.
public static ComplexField operator -(ComplexField field, Complex c)
Parameters
fieldComplexFieldThe Complex Field.
cComplexComplex number to subtract.
Returns
- ComplexField
Difference of the complex field and the complex number.
operator -(ComplexField, ComplexField)
Subtracts two complex fields.
public static ComplexField operator -(ComplexField field1, ComplexField field2)
Parameters
field1ComplexFieldThe first field.
field2ComplexFieldThe second field.
Returns
- ComplexField
The result of the operator.