Functions in emap5.c


Table of Contents


ComputeBddMatrix()

Prototype:   void ComputeBddMatrix(int ObservTrngle, int SourceTrngle,
                                double *ObsTrngleEdgeLen, double *SrcTrngleEdgeLen,
                                int *ObservTrngleNode, int *SourceTrngleNode,
                                int *ObservTrngleEdge, int *SourceTrngleEdge,
                               double *SrcTrngleNorm, double BE[][3] )
Description:    Compute the B matrix generated by FEM. Only Bdd has non-zero
                elements, thus only store Bdd.
Input value:
    int ObservTrngle, SourceTrngle --- the source and observing triangle
                                       indices to the trianle table
    double *ObsTrngleEdgeLen  --- the observing triangle's edge length
    double *SrcTrngleEdgeLen  --- the source triangle's edge length
    int *ObservTrngleNode  --- the observing triangle's nodes
    int *SourceTrngleNode  --- the source triangle's nodes
    int *ObservTrngleEdge  --- the observing triangle's edges
    int *SourceTrngleEdge  --- the source triangle's edges
    double *SrcTrngleNorm   --- the normal vector of the source triangle.
    double BE[][3]  --- to store the results of BE for this triangle pair.
Return value:     none
Global value used:  NodeCord, Junction, Bdd,
                    GlobalEdgeEnds, TrngleCenTroid,
Global value modified:      none
Subroutines called:    sign(),  TrngleArea(), VTXdot()
(Click to go back to Table of Contents.)

ComputeCMatrix()

Prototype:  void ComputeCMatrix(int ObservTrngle, int SourceTrngle,
                    double *ObsTrngleEdgeLen, double *SrcTrngleEdgeLen,
                    int *ObservTrngleNode, int *SourceTrngleNode,
                    int *ObservTrngleEdge, int *SourceTrngleEdge,
                    double **ObsPointArray)
Description:   Fill the Moment Method matrix C, partition it to
               Ccc, Ccd, Cdd and  Cdc.
Input value:
    int ObservTrngle, SourceTrngle --- the source and observing triangle
                                       indices to the trianle table
    double *ObsTrngleEdgeLen  --- the observing triangle's edge length
    double *SrcTrngleEdgeLen  --- the source triangle's edge length
    int *ObservTrngleNode  --- the observing triangle's nodes
    int *SourceTrngleNode  --- the source triangle's nodes
    int *ObservTrngleEdge  --- the observing triangle's edges
    int *SourceTrngleEdge  --- the source triangle's edges
    double **ObsPointArray --- the observing triangle's Gaussian Quadrature
                               point array
Return value:  none
Global value used:     TrngleNode,TrngleNormal,TotQuadPoint,
                       TrngleCenTroid, NodeCord, Ccc, Ccd,  Cdd, Cdc.
Global value modified:     none
Subroutines called:     ComputeGaussQuadPoint(),ComputeSingul(),
                        COMplex_Cmplx(), ComputeNonSingul(), COMplex_Add2(),
                        COMplex_Sub(), COMplex_Null()

(Click to go back to Table of Contents.)



ComputeCorrectionTerm()

Prototype:    void    ComputeCorrectionTerm()
Description:     To couple the MoM matrix equation to the FEM matrix equation. The main idea is to obtain Jd  from C and D. Then couple to the FEM matrix.
Input value:     none
Return value:     none
Global value used:     Ccc, Ccd, Cdc, Cdd, Bdd, TotExtMetalEdgeNum, HybrdBoundEdgeNum, Gd
Global value modified:    InvertMatrix(), COMplex_Add()
Subroutines called:     none.

(Click to go back to Table of Contents.)



ComputeDMatrix()

Prototype: void ComputeDMatrix(int  ObservTrngle, int SourceTrngle,
                    double *ObsTrngleEdgeLen, double *SrcTrngleEdgeLen,
                    int *ObservTrngleNode, int *SourceTrngleNode,
                    int *ObservTrngleEdge, int *SourceTrngleEdge,
                    double **ObsPointArray, double BE[][3])
Description:    Fill D matrix generated by MOM. Partition it to Dcd and Ddd.
Input value:
    int ObservTrngle, SourceTrngle --- the source and observing triangle
                                       indices to the trianle table
    double *ObsTrngleEdgeLen  --- the observing triangle's edge length
    double *SrcTrngleEdgeLen  --- the source triangle's edge length
    int *ObservTrngleNode  --- the observing triangle's nodes
    int *SourceTrngleNode  --- the source triangle's nodes
    int *ObservTrngleEdge  --- the observing triangle's edges
    int *SourceTrngleEdge  --- the source triangle's edges
    double **ObsPointArray --- the observing triangle's Gaussian Quadrature
                               point array
    double BE[][3]  --- store the results of BE for this triangle pair.
Return value:   none
Global value used:   Junction,  NordCord, Ddd, Dcd,
Global value modified:     none
Subroutines called:   sign(),  Real_Mul(), computeNonSingul1(),
                      COMplex_Add2(), COMplex_Null(),
                      ComputeGaussQuadPoint().
 
(Click to go back to Table of Contents.)

ComputeGaussQuadPoint()

Prototype:    void    ComputeGaussQuadPoint(int QuadPoint, int *TrngleNode, double *SrcPointCol)
Description: To compute the coordinates of 7-point Gauss nodes of a triangular patch.
Input value:
  • int QuadPoint  --- node index, it can be from 0 to 6.
  • int *TrngleNode  ---  the three nodes of a tringular patch.
  • double *SrcPointCol --- where to store the results
Return value: none
Global value used: NodeCord, Qpnt
Global value modified:    none
Subroutines called:    none
Note: Not very sure.
(Click to go back to Table of Contents.)
 


ComputeNonSingul()

Prototype:    void    ComputeNonSingul(int *TrngleNode, double One, double *MidPoint)
Description: To evaluate the MOM surface integral numerically when the observation triangle and the source triangle are different.
Input value:
  • int *TrngleNode --- nodes of the source triangle
  • double One  --- a factor
  • double *MidPoint --- middle point of the observing trianlge
Return value: none
Global value used: none
Global value modified: none
Subroutines called: COMplex_add(), COMplex_Cmplx(), COMplex_Expon(), Real_Mul(), COMplex_Sub()

(Click to go back to Table of Contents.)


ComputeNonSingul1()

Prototype: void ComputeNonSingul(int *TrngleNode, double One,
                                 double *MidPoint, complex *Ino_PQ,
                                 complex *Ixi_PQ,
                                 complex *Ieta_PQ, complex *Izeta_PQ)
Description: To evaluate the MOM surface integral numerically when the
             observation triangle and the source triangle are different.
Input value:
    int *TrngleNode --- nodes of the source triangle
    double One  --- a factor
    double *MidPoint --- middle point of the observing trianlge
Return value:
    complex *Ino_PQ   --- to store the value of Ino
    complex *Ixi_PQ   --- to store the value of Ixi
    complex *Ieta_PQ  --- to store the value of Ieta
    complex *Izeta_PQ --- to store the value of Izeta.
    The above values are used in ComputeCMatrix().
Global value used: none
Global value modified: none
Subroutines called: COMplex_add(), COMplex_Cmplx(), COMplex_Expon(),
                    Real_Mul(), COMplex_Sub()
 

(Click to go back to Table of Contents.)


ComputeParameters()

Prototype:    void    ComputeParameters()
Description:    To computes parameters(TetVolume, TrngleArea, TrngleCentroid and etc) which are necessary to build the FEM matrix and MOM matrix,
Input value:    none
Return value:    none
Global value used:     AbsPermeable, AbsPermitt, CFactor1, CFactor2, Cfactor3, EdgeLength, FreeSpaceVel, ImpeDance, NodeCord, OperateFreq, GlobalEdgeEnds, TetLocalEdge, TetLocalNodeNum, TetVolume, TotEdgeNum, TotTetElement, TotTrnlgeNum,TParam, TrngleArea, TrngleCentroid, WaveLength, WaveNumber,
Global value modified:     CFactor1, CFactor2, Cfactor3, FreeSpaceVel, TetVolume, TrngleArea, TrngleCentroid,
Subroutines called:     COMplex_Cmplx(), ComputeTetraHeronVolume(), ComputeTrngleCentroid(), Real_Mul() TetfaceAreaNormal(), VTXmag()

(Click to go back to Table of Contents.)


ComputeSingul()

Prototype:    void    ComputeSingul(int *Node, double *MidPoint, double AREA)
Description:     To evaluate the singularity of the MOM integral analytically when the observing triangle coincides with the source triangle. The results are stored in global variables RealIno, RealIxi and RealIeta.
Input value:
  • int *Node --- the nodes of the triangle
  • double *MidPoint --- middle point of the triangle
  • double AREA --- the area of the triangle
Return value: none
Global value used: double **NodeCord
Global value modified: RealIno, RealIxi, RealIeta
Subroutines called: none

(Click to go back to Table of Contents.)
 


ComputeSourceVector()

Prototype:    void    ComputeSourceVector(double WaveNum, double *MidPoint, complex *EiC)
Description:     To compute the E fields of an incident plane wave at the boundary surface.
Input value:
  • double WaveNum --- wavenumber of the plane wave.
  • double MidPoint --- midpoint of the observing triangle.
  • complex *EiC  --- where to store the results
Return value: none
Global value used: none
Global value modified: none
Subroutines called:  none

(Click to go back to Table of Contents.)

 


ComputeTetraHedronVolume()

Prototype:    void    ComputeTetraHedronVolume(int TetHedNum, double **Cord, int **TGNodeNum,double *TVolume)
Description:    To calculate the volume of a tetrahedron
Input value:
  • int TetHedNum --- the number of  the tetrahedron
  • double **cord  --- the global node table
  • int **TGNodeNum --- the global node numbers of the tetrahedron
  • double *TVolume, -- where to store the results.
Return value:     none
Global value used:     none
Global value modified:     none
Subroutines called:     VTXsub1()

(Click to go back to Table of Contents.)


ComputeTrngleCentroid()

Prototype:    void    ComputeTrngleCentroid( int TrngleNum, double **Cord, int **BFaceNode, double **CenTroid)
Description:     To compute the centroid of a triangular patch.
Input value:
  • int TrngleNum   --- the number of the triangle
  • double **Cord  --- the gloabl node table
  • int BFaceNode  --- the nodes of the triangle
  • double **Centroid -- where to store the results
Return value:    none
Global value used:    none
Global value modified:    none
Subroutines called:     VTXadd2()

(Click to go back to Table of Contents.)



ConjugateSolver()

Prototype:    void    ConjugateSolver(int MatrixSize, int *RowIIndex, int **RowICol, complex **RowIDat, complex *RHSVec, int ITmax, double TOL)
Description:     To solve a linear system using complex bi-conjugate gradient method.
Input value:
  • int MatrixSize--- the size of the matrix equation.
  • complex **RowIDat, int **RowICol, int *RowIIndex --- the FEM matrix stored using the row-indexed scheme
  • complex *RHSVec----  the right-hand side vector, the results are stored in this vector.
  • int ITmax  --- the maximum iteration number. If the solver runs the maximum iterations but still has not reach the tolerance, the solver will return and store the best results.
  • double TOL  --- the tolerance. If the solver reaches in the tolerance, it will stop and store the results.
Return value:     none
Global value used:     none
Global value modified:     none
Subroutines called:     CMPLX_Vector(), COMplex_Cmplx(), COMplex_Null(), COMplex_Sub(), COMplex_Conjg(), VectorNorm(), InnerProduct(), COMplex_Add(), COMplex_Div(), COMplex_Mul(),
Real_Div().

(Click to go back to Table of Contents.)



CreateRHSVector()

Prototype:    void    CreateRHSVector(int InnerEdgeNum, int BoundEdgeNum, int ForcdEdgeNum, complex **FCDMatrixData, complex **ForcdValue,complex *RHSVector)
Description:     To use boundary conditions to create the right-hand side vector. The final matrix equation is  [LHS][E]=[RHS]. After RHS is known,  [E] can be solved by using  ConjugateSolver() .
Input value:
  • int InnerEdgeNum, -- number of total inner edges
  • int BoundEdgeNum, ---number of total surface edges
  • int ForcdEdgeNum---number of total forced edges
Return value: none
Global value used:     SourceType ,GdVector, TotInnerEdgeNum
Global value modified:     none
Subroutines called:     COMplex_Mul(), COMplex_Add(), COMplex_Null(), Real_Mul()
 
(Click to go back to Table of Contents.)


FEMMatrixCompute()

Prototype:    void    FemMatrixCompute(int NumOfTetElement, int MaxElementPerRow, int **TetEdge, int **GlobalEdgeEnds,double **NodeCord, complex *TParam, complex *Epsilon, int **GBLmatColAddr, complex **GBLmat, int *GBLmatColIndex, double *TetVolume)
Description:     To build the FEM matrix and store them using row-indexed scheme.
Input value:
  • int NumOfTetElement --- total number of tetrahedron elements
  • int MaxElementPerRow --- the FEM matrix is a sparse matrix. Every row has a maximum number (MaxElementPerRow) of non-zero elemnet. Only non-zero elements are stored
  • int **TetEdge --- the edge table of tetrahedron elements
  • int **GlobalEdgeEnds --- global edge table
  • double **NodeCord, --- global node table
  • complex *TParam, --- store constants used by FEM
  • complex *Epsilon, --- the permittivity associated with each tetrahedron element.
  • int **GBLmatColAddr, complex **GBLmat, int *GBLmatColIndex,--- the FEM matrix stored using row-indexed  scheme.
  • double *TetVolume ---the volume of tetrahedron elements
Return value:     void
Global value used:     none
Global value modified: none
Subroutines called:     VTXsub(), VTXcross(), Sign()

(Click to go back to Table of Contents.)
 



MatrixVectorProduct()

Prototype:  void MatrixVectorProduct(char S, int Size, complex *XVec, complex *AVec, int *RIIndex,int **RICol,complex **RIDat)
Description:    To multiply the final matrix equation { [FEM] +[Cdd] } with a vector.
Input value:

  • complex **RIDat, int RIIndex, int **RICol --- the FEM matrix stored using the row-indexed scheme.
  • complex *XVec --- pointer to a vector of complex type
  • complex *AVec --- where the results are stored.
  • int Size  --- the dimension of the vectors.  The vector and the matrix should have the same dimension.
  • char S --- operation type. If s== '  ',  return [A]={[FEM] +[Cdd] }[X]. If S='*', return [A]={[FEM] +[Cdd] }*[X], where * denoteds conjugate.
Return value:   none
Global value used:  Cdd
Global value modified:     none
Subroutines called:   COMplex_Add(), COMplex_Null(), COMplex_Mul(), COMplex_Conjg()

(Click to go back to Table of Contents.)



InnerProduct()

Prototype:     complex Inner_Prod( complex *AVec,  complex *BVec, int Size )
Description:    To compute the inner product of  two vectors of complex type.
Input value:

  • complex *AVector, *BVector --- two vectors of complex type, they should have the same length
  • int Size  --- the length of the vectors.
Return value:   return the inner product of the two vectors.
                         If B=(x1, x2, ... xn), A=(y1, y2, ..., yn),
                         The inner product is defined as   x1y1* + x2y2* + ... +xnyn*, where * denotes conjugate.
Global value used:  none
Global value modified:     none
Subroutines called:   COMplex_Add().

(Click to go back to Table of Contents.)



InvertMatrix()

Prototype:    void    InvertMatrix(complex **Qmat, int MatrixSize)
Description:    To invert a complex matrix. The results are stored in the input matrix, thus no additional memory needed.
Input value:
  • complex **Qmat --- a complex matrix
  • int matrixSize --- the size of the matrix
Return value:     none
Global value used:     none
Global value modified:     none
Subroutines called:    COMplex_Abs(), COMplex_Div(), COMplex_Cmplx(), COMplex_Sub(), COMplex_Mul(), INT_Matrix(), free_INT_Matrix()
 
(Click to go back to Table of Contents.)

PartitionGlobalFEMMatrix()

Prototype:     void    PartitionGlobalFEMMatrix(int ** GBLmatColAddr, complex **GBLmat, int *GBLmatColIndex, int InnerEdgeNum, int BoundEdgeNum, int ForcdEdgeNum, int *InnerEdgeStat, int *BoundEdgeStat, int *ISourceEdgeStat, complex **LHSMatrixData, complex **FCDMatrixData, complex **Cdd )
Description:     Partition the FEM matrix in terms of the internal, boundary and far-field quantities
Input value:
  • int ** GBLmatColAddr, complex **GBLmat, int *GBLmatColIndex -- the FEM matrix stored using the row-indexed scheme.
  • int InnerEdgeNum --- number of total inner edges
  • int BoundEdgeNum --- number of total boundary edges
  • int ForcdEdgeNum --- number of total forced edges
  • int *InnerEdgeStat --- the global edge indices of the inner edges
  • int *BoundEdgeStat --- the global edge indices of the boundary edges
  • int *ISourceEdgeStat --- the global edge indices of the forced edges
  • complex **LHSMatrixData --- put the results into this matrix
  • complex **FCDMatrixData --- forced edge values
  • complex **Cdd --- submatrix of C
Return value:     none
Global value used:     GBLmatColAddr, GBLmat, GBLmatColIndex, TotInnerEdgeNUm, DielBoundEdgeNum, TotISourceEdgeNum, InnerEdgeStat, BoundEdgeStat, ISourceEdgeStat, LHSMatrixData, FCDMAtrixData, Cdd
Global value modified:     none
Subroutines called:     Search NonZeroElement(), COMplex_Add()

(Click to go back to Table of Contents.)


ReadInputFile()

Prototype:    void    ReadMeshFile()
Description:    To read data from an input  file, initialize global variables
Input value:     none
Return value:     none
Global value used:     TotEdgeNum, TotTetElement, TotNodeNum, TotTrngleNum, TotBoundEdgeNum, TotInnerEdgeNum, DielBoundEdgeNum, HybrdBoundEdgeNum, TrngleNode,TrngleEdge,NodeCord, TetNode, TetNode,Epsilon, TetEdge , GlobalEdgeEnds, PlusTrngleDet, PlusTrngleIndex,MinusTrngleDet, MinusTrngleIndex,InnerEdgeStat,BoundEdgeStat,SourceType,VsourceMag, VSourceNum, OperateFreq, VsourceEdge,VVal
Global value modified:     TotEdgeNum, TotTetElement, TotNodeNum, TotTrngleNum, TotBoundEdgeNum, TotInnerEdgeNum, DielBoundEdgeNum, HybrdBoundEdgeNum, TrngleNode,TrngleEdge,NodeCord, TetNode, TetNode,Epsilon, TetEdge , GlobalEdgeEnds, PlusTrngleDet, PlusTrngleIndex,MinusTrngleDet, MinusTrngleIndex,InnerEdgeStat,BoundEdgeStat,SourceType,VsourceMag, VSourceNum, OperateFreq, VsourceEdge,VVal
Subroutines called:     INT_Matrix(), INT_Vector()

(Click to go back to Table of Contents.)



PrintOutput()

Prototype:     void   PrintOutput()
Description:   To print out the field within the area specified by the input file.
Input value:     none
Return value:   none
Global value used:  InF, OutF, HybrdBoundEdgeNum, EdVector, JdVector, JcVector, GlobalEdgeEnds, HybrdBoundEdgeNum, TotInnerEdgeNum, NodeCord, RHSVector
Global value modified:     none
Subroutines called:  none

(Click to go back to Table of Contents.)
 


SearchNonZeroElement()

Prototype:    int    SearchNonZeroElement(int RowNum, int ColNum)
Description:     To search an element in the global FEM matrix. To conserve memory, only none-zero elements are stored in the FEM matrix using row-indexed scheme.  If the element is found, return the column index to the global FEM matrix. Otherwise, return -1.
Input value:
  • int RowNum --- row number, which is assigned to the observing edge
  • int ColNum ---  column number, which is assigned to the source edge.
Return value:  the column index to GBLmat.
Global value used: int *GBLmatColIndex, int *GBLmatColAddr
Global value modified: none
Subroutines called: none

(Click to go back to Table of Contents.)


SurfaceFieldCompute()

Prototype:  void  SurfaceFieldCompute()
Description:  To compute the equivalent surface current density (Jc and Jd )
Input value:  none
Return value:  none
Global value used:  TotInnerEdgeNum EdVector HybrdBoundEdgeNum,
                    JdVector, JcVector,TotExtMetalEdgeNum, Dcd,  EdVector,
Global value modified:  none
Subroutines called:   COMplex_Add(),COMplex_Mul()
 

(Click to go back to Table of Contents)



TetFaceAreaNormal()

Prototype:    void    TetFaceAreaNormal(int TrngleNum, double **Cord, int **BFaceNode, double **Normal, double *Area)
Description:     To compute the unit normal and the area of each face of the tetrahedron
Input value:
  • int TrngleNum --- index of the tetrahedron
  • double **Cord --- the global node table
  • int **BFaceNode  --- the nodes of each face
  • double **Normal -- where to store the centroid of each face
  • double *Area  --- where to store the area of each face
Return value:    none
Global value used:     none
Global value modified:     none
Subroutines called:     VTXcross1(), VTXsub1(), VTXcross()

(Click to go back to Table of Contents.)



VectorNorm()

Prototype:    double VectorNorm(complex *Vec, int Size)
Description:     To compute the the Euclidean norm of a complex vector
Input value:
  • complex *Vec  --- pointer to a vector of complex type
  • int Size  ---  the length of the vector
Return value:    the Euclidean norm of the vector. If the vector is (x1, x2, ..., xn),
                          the norm is defined as sqrt( |x1|^2 +|x2|^2+...+|xn|^2).
Global value used:     none
Global value modified:     none
Subroutines called:     COMplex_Abs().

(Click to go back to Table of Contents.)