PUL_parameter_module.F90 19.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
!
! This file is part of SACAMOS, State of the Art CAble MOdels in Spice. 
! It was developed by the University of Nottingham and the Netherlands Aerospace 
! Centre (NLR) for ESA under contract number 4000112765/14/NL/HK.
! 
! Copyright (C) 2016-2017 University of Nottingham
! 
! SACAMOS is free software: you can redistribute it and/or modify it under the 
! terms of the GNU General Public License as published by the Free Software 
! Foundation, either version 3 of the License, or (at your option) any later 
! version.
! 
! SACAMOS is distributed in the hope that it will be useful, but 
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
! for more details.
! 
! A copy of the GNU General Public License version 3 can be found in the 
! file GNU_GPL_v3 in the root or at <http://www.gnu.org/licenses/>.
! 
! SACAMOS uses the EISPACK library (in /SRC/EISPACK). EISPACK is subject to 
! the GNU Lesser General Public License. A copy of the GNU Lesser General Public 
! License version can be found in the file GNU_LGPL in the root of EISPACK 
! (/SRC/EISPACK ) or at <http://www.gnu.org/licenses/>.
! 
! The University of Nottingham can be contacted at: ggiemr@nottingham.ac.uk
!
! File Contents:
! MODULE PUL_parameter_module
!   CONTAINS
!     SUBROUTINE allocate_and_reset_PUL_data
!     SUBROUTINE deallocate_PUL_data
!     FUNCTION point_is_inside
!     SUBROUTINE Z_Y_from_L_C
!     SUBROUTINE write_Dshape_gmsh
!
! plus the following in include files:
!Laplace.F90:        SUBROUTINE Laplace
!PUL_analytic.F90:   SUBROUTINE PUL_LC_calc_wide_separation_approximation
!PUL_analytic.F90:   SUBROUTINE PUL_LC_calc_overshield_wide_separation_approximation
!PUL_analytic.F90:   SUBROUTINE calculate_height_over_ground_plane
!PUL_LC_Laplace.F90: SUBROUTINE PUL_LC_Laplace
!Aprod.F90:          SUBROUTINE Aprod
!Aprod.F90:          SUBROUTINE ATprod
!Aprod.F90:          SUBROUTINE zAprod
!Aprod.F90:          SUBROUTINE zATprod
!CG_solve.F90:       SUBROUTINE solve_real_symm(n, b, x,tol)
!CG_solve.F90:       SUBROUTINE solve_complex_symm(n, b, x,tol)
!
!
!
! NAME
!     MODULE PUL_parameters
!
!     Data relating to the calculation of PUL_parameters
!     
! COMMENTS
!    The conjugate gradient solutions are included in this module rather than the maths module
!    as they are intimately linked with the matrix-vector product subroutine which in turn relies
!    on the sparse matrix storage structure in this module
!
! HISTORY
!    started 25/11/2015 CJS
!    30/3/2016 CJS fix factor of 2 in mutual inductance of wires over ground plane
!    18_4_2016 CJS include calculation for conductors within a cylindrical shield for oversheild domains
!    5_7_2016 CJS include numerical Laplace solver for L,C,G in inhomogeneous regions
!    13/3/2018CJS include iterative solver stuff based on Stanford University symmlq.f
!    16/3/2018 CJS add y offset for ML_flex_cable (PUL%ox, and PUL%oy)(PUL%rdox, and PUL%rdoy)
!    19/6/2018 CJS include iterative sparse matrix solver based on the biconjugate gradient method
!
MODULE PUL_parameter_module

USE type_specifications
USE filter_module
USE frequency_spec
USE general_module

IMPLICIT NONE

! Main structure used to hold data for the per-unit-length parameter calculation
TYPE::PUL_type

  integer                     :: n_conductors    ! number of conductors
  
! conductor based arrays:
  integer,allocatable         :: shape(:)        ! holds a nuber which indicates the shape of the conductor
  real(dp),allocatable        :: r(:)            ! radius of a circular conductor
  real(dp),allocatable        :: x(:)            ! x coordinate of the centre of the cable to which this conductor belongs
  real(dp),allocatable        :: y(:)            ! y coordinate of the centre of the cable to which this conductor belongs
  real(dp),allocatable        :: ox(:)           ! offset in the x direction of this conductor from the cable centre (x():),y(:) above) 
  real(dp),allocatable        :: oy(:)           ! offset in the y direction of this conductor from the cable centre (x():),y(:) above) 
  real(dp),allocatable        :: rh(:)           ! height (y dimension) of rectangular conductor
  real(dp),allocatable        :: rw(:)           ! width1  (x dimension) of rectangular conductor/ Dshape
  real(dp),allocatable        :: rw2(:)          ! width2  (x dimension) of rectangular conductor/ Dshape
  real(dp),allocatable        :: rd(:)           ! radius of dielectric surrounding a circular conductor
  real(dp),allocatable        :: rdh(:)          ! height (y dimension) of rectangular dielectric around conductor
  real(dp),allocatable        :: rdw(:)          ! width  (x dimension) of rectangular dielectric around conductor
  real(dp),allocatable        :: rdox(:)          ! offset of dielectric in the x direction of this conductor from the cable centre
  real(dp),allocatable        :: rdoy(:)          ! offset of dielectric in the y direction of this conductor from the cable centre
  real(dp),allocatable        :: rtheta(:)       ! rotation angle of conductor
  type(Sfilter),allocatable   :: epsr(:)         ! relative permittivity of dielecrtric surrounding the conductor
  
  logical             :: ground_plane_present    ! flag to indicate the presence of a ground plane
  real(dp)            :: ground_plane_angle      ! angle of ground plane normal from the x axis
  real(dp)            :: ground_plane_offset     ! ground plane offset
  
  logical             :: overshield_present      ! flag to indicate the presence of an overshield
  integer             :: overshield_shape        ! holds a nuber which indicates the shape of the opvershield 
  real(dp)            :: overshield_x            ! x coordinate of the centre of the overshield
  real(dp)            :: overshield_y            ! y coordinate of the centre of the overshield 
  real(dp)            :: overshield_r            ! radius of a circular overshield
  real(dp)            :: overshield_h            ! height (y dimension) of Dshape overshield
  real(dp)            :: overshield_w            ! width1 (x) parameter of Dshape overshield
  real(dp)            :: overshield_w2           ! width2 (x) parameter of Dshape overshield
  
  type(Sfilter)       :: epsr_background         ! relative permittivity of background dielecrtric (unually air)
    
  type(matrix)        :: L     ! inductance matrix
  type(matrix)        :: C     ! capacitance matrix
  type(matrix)        :: G     ! conductance matrix
  
  type(Sfilter_matrix):: Zfilter   ! frequency dependent impedance matrix
  type(Sfilter_matrix):: Yfilter   ! frequency dependent impedance matrix
  
  integer                       :: filter_fit_order  ! order for filter fitting for frequency dependent models
  type(frequency_specification) :: filter_fit_freq   ! frequency range for filter fitting for frequency dependent models
  
END TYPE PUL_type 

integer,public :: n_entry

! 1D arrays used in the construction of the K matrix ( K(i_K(:),j_K(:))=K(i_K(:),j_K(:))+s_K(:) )
integer,allocatable,public         :: i_K(:)
integer,allocatable,public         :: j_K(:)
real(dp),allocatable,public        :: s_K_re(:)
complex(dp),allocatable,public     :: s_K(:)


CONTAINS 

include "PUL_analytic.F90"

include "PUL_LC_Laplace.F90"

include "Laplace.F90"

include "Aprod.F90"

include "CG_solve.F90"

! NAME
!     SUBROUTINE allocate_and_reset_PUL_data
!
!     allocate and reset per-unit-length calculation data
!     
! COMMENTS
!     
!
! HISTORY
!    started 10/10/2015 CJS
!

  SUBROUTINE allocate_and_reset_PUL_data(PUL,n_conductors)

  USE type_specifications
  USE general_module

  IMPLICIT NONE

! variables passed to subroutine

  type(PUL_type),intent(OUT)   :: PUL
  integer,intent(IN)           :: n_conductors
  
! local variables

  integer :: i

! START

! allocate memory for PUL structure
  PUL%n_conductors=n_conductors
  ALLOCATE( PUL%shape( PUL%n_conductors) ) 
  ALLOCATE( PUL%x( PUL%n_conductors) ) 
  ALLOCATE( PUL%y( PUL%n_conductors) ) 
  ALLOCATE( PUL%r( PUL%n_conductors) ) 
  ALLOCATE( PUL%ox( PUL%n_conductors) ) 
  ALLOCATE( PUL%oy( PUL%n_conductors) ) 
  ALLOCATE( PUL%rd( PUL%n_conductors) ) 
  ALLOCATE( PUL%rdw( PUL%n_conductors) ) 
  ALLOCATE( PUL%rdh( PUL%n_conductors) ) 
  ALLOCATE( PUL%rdox( PUL%n_conductors) ) 
  ALLOCATE( PUL%rdoy( PUL%n_conductors) ) 
  ALLOCATE( PUL%epsr( PUL%n_conductors) )     
  ALLOCATE( PUL%rh( PUL%n_conductors) ) 
  ALLOCATE( PUL%rw( PUL%n_conductors) ) 
  ALLOCATE( PUL%rw2( PUL%n_conductors) ) 
  ALLOCATE( PUL%rtheta( PUL%n_conductors) ) 
  
! reset all the elements of the PUL structure
  do i=1,PUL%n_conductors
  
    PUL%shape(i)=0
    PUL%x(i)=0d0 
    PUL%y(i)=0d0 
    PUL%r(i)=0d0 
    PUL%ox(i)=0d0 
    PUL%oy(i)=0d0 
    PUL%rh(i)=0d0 
    PUL%rw(i)=0d0 
    PUL%rw2(i)=0d0 
    PUL%rd(i)=0d0 
    PUL%rdw(i)=0d0 
    PUL%rdh(i)=0d0 
    PUL%rdox(i)=0d0 
    PUL%rdoy(i)=0d0 
    PUL%rtheta(i)=0d0
    PUL%epsr(i)=1d0

  end do
  
  PUL%ground_plane_present=.FALSE.
  PUL%ground_plane_angle=0d0
  PUL%ground_plane_offset=0d0
  
  PUL%overshield_present=.FALSE.
  PUL%overshield_shape=circle    ! circle by default
  PUL%overshield_x=0d0
  PUL%overshield_y=0d0
  PUL%overshield_r=0d0
  PUL%overshield_w=0d0
  PUL%overshield_w2=0d0
  PUL%overshield_h=0d0
  
  PUL%epsr_background=1d0

  RETURN

  END SUBROUTINE allocate_and_reset_PUL_data

! NAME
!     SUBROUTINE deallocate_PUL_data
!
!     deallocate per-unit-length calculation data
!     
! COMMENTS
!     
!
! HISTORY
!    started 2/12/2015 CJS
!    5/6/2016 CJS include additional variables for numerical Laplace solution.
!

  SUBROUTINE deallocate_PUL_data(PUL)

  USE type_specifications
  USE general_module

  IMPLICIT NONE

! variables passed to subroutine

  type(PUL_type),intent(INOUT)    :: PUL
  
! local variables

  integer :: i

! START

  if (allocated(PUL%shape )    ) DEALLOCATE( PUL%shape )
  if (allocated(PUL%x )    ) DEALLOCATE( PUL%x )
  if (allocated(PUL%y )    ) DEALLOCATE( PUL%y )
  if (allocated(PUL%r )    ) DEALLOCATE( PUL%r )
  if (allocated(PUL%ox )    ) DEALLOCATE( PUL%ox )
  if (allocated(PUL%oy )    ) DEALLOCATE( PUL%oy )
  if (allocated(PUL%rh )    ) DEALLOCATE( PUL%rh )
  if (allocated(PUL%rw )    ) DEALLOCATE( PUL%rw )
  if (allocated(PUL%rw2 )    ) DEALLOCATE( PUL%rw2 )
  if (allocated(PUL%rd )   ) DEALLOCATE( PUL%rd )
  if (allocated(PUL%rdw )   ) DEALLOCATE( PUL%rdw )
  if (allocated(PUL%rdh )   ) DEALLOCATE( PUL%rdh )
  if (allocated(PUL%rdox )   ) DEALLOCATE( PUL%rdox )
  if (allocated(PUL%rdoy )   ) DEALLOCATE( PUL%rdoy )
  if (allocated(PUL%rtheta )    ) DEALLOCATE( PUL%rtheta )
  
  if (allocated(PUL%epsr ) ) then
    do i=1,PUL%n_conductors
      CALL deallocate_Sfilter(PUL%epsr(i))
    end do
    DEALLOCATE( PUL%epsr )
  end if
  
  CALL deallocate_Sfilter(PUL%epsr_background)
  
  if (allocated(PUL%L%mat) ) DEALLOCATE( PUL%L%mat )
  if (allocated(PUL%C%mat) ) DEALLOCATE( PUL%C%mat )
  if (allocated(PUL%G%mat) ) DEALLOCATE( PUL%G%mat )
  
  CALL deallocate_Sfilter_matrix( PUL%Zfilter )
  CALL deallocate_Sfilter_matrix( PUL%Yfilter )

  RETURN

  END SUBROUTINE deallocate_PUL_data
 
! NAME
!     FUNCTION point_is_inside(xt,yt,shape_type,x,y,r,rh,rw,rtheta)
!
!     function to determine whether conductors are inside dielectrics - used to create region boundary
!     lists for mesh generation 
!     
! COMMENTS
!     
!
! HISTORY
!    started 6/10/2016 CJS
!    add rox, roy instead of only the x offset, ro 16/3/2018 CJS
!
  
  logical FUNCTION point_is_inside(xt,yt,shape_type,x,y,r,rh,rw,rox,roy,rtheta)
  
  real(dp),intent(IN) ::   xt           ! test point x
  real(dp),intent(IN) ::   yt           ! test point y
  integer,intent(IN)  ::   shape_type   ! holds a nuber which indicates the shape of the test object
  real(dp),intent(IN) ::   x            ! x coordinate of the centre of the test object
  real(dp),intent(IN) ::   y            ! y coordinate of the centre of the test object
  real(dp),intent(IN) ::   r            ! radius of cylindrical test object
  real(dp),intent(IN) ::   rh           ! height (y dimension) of rectangular test object
  real(dp),intent(IN) ::   rw           ! width  (x dimension) of  test object
  real(dp),intent(IN) ::   rox          ! offset in the x direction of this test object from the centre
  real(dp),intent(IN) ::   roy          ! offset in the y direction of this test object from the centre
  real(dp),intent(IN) ::   rtheta       ! rotation angle of test object
 
! local variables

  real(dp)::   d
  real(dp)::   xt_r,yt_r
  real(dp)::   xt_ro,yt_ro
  real(dp)::   xt_o,yt_o
  real(dp)::   dx,dy

! START
  
  if (shape_type.EQ.circle) then

! calculate the distance between the test point and the centre of the dielectric cylinder  
    d=sqrt((x-xt)**2+(y-yt)**2)
    
    if (d.LT.r) then
      point_is_inside=.TRUE.
    else
      point_is_inside=.FALSE.    
    end if
  
  else
! rectangular conductor

    write(*,*)'Test point',xt,yt
    
! apply the inverse of the offset to the shape i.e. move it into the shifted, un-rotated coordinate system of the rectangle
    xt_o=xt-x
    yt_o=yt-y
    
    write(*,*)'Offset on test point',xt_o,yt_o

! apply the inverse of the rotation to the test point i.e. move it into the un-rotated coordinate system of the rectangle
    xt_r= xt_o*cos(rtheta)+yt_o*sin(rtheta)
    yt_r=-xt_o*sin(rtheta)+yt_o*cos(rtheta)

    write(*,*)'Inverse rotation on test point',xt_r,yt_r
    
! apply the inverse of the offset to the shape i.e. move it into the shifted, un-rotated coordinate system of the rectangle
    xt_ro=xt_r-rox
    yt_ro=yt_r-roy

    write(*,*)'Offset Inverse rotation on test point',xt_ro,yt_ro
    
! xt_ro,yt_ro is the the distance from the transformed test point to the centre of the rectangle in x and y   
    
    dx=xt_ro
    dy=yt_ro
    
!    write(*,*)'dielectric centre point',x,y,' offset',rox,roy,' angle',rtheta
!    write(*,*)'dx',dx,' rw/2',rw/2d0
!    write(*,*)'dy',dy,' rh/2',rh/2d0
    
    if ( (abs(dx).LT.rw/2d0).AND.(abs(dy).LT.rh/2d0) ) then
      point_is_inside=.TRUE.
      write(*,*)'POINT IS INSIDE'
    else
      point_is_inside=.FALSE.    
      write(*,*)'POINT IS OUTSIDE'
    end if
   
  end if
  
  
  END FUNCTION point_is_inside
!
! NAME
!     SUBROUTINE Z_Y_from_L_C(unit)
!
!     calculate frequency dependent impedance and admittance (filter function) matrices 
!     for inductance and capacitance matrices with frequency independent properties
!     Z=jwL  Y=jwC
!
! COMMENTS
!     
!
! HISTORY
!    started 2/12/2015 CJS
!

  SUBROUTINE Z_Y_from_L_C(L,C,Z,Y)

  USE type_specifications
  USE general_module
  USE maths
  USE filter_module

  IMPLICIT NONE

! variables passed to subroutine

  type(matrix),intent(IN)    :: L
  type(matrix),intent(IN)    :: C
  
  type(Sfilter_matrix),intent(OUT)    :: Z
  type(Sfilter_matrix),intent(OUT)    :: Y

! local variables

  integer :: dim
  integer :: row,col
  type(Sfilter) :: jw

! START

  jw=jwA_filter(1d0)

! Impedance matrix
  dim=L%dim
  Z%dim=dim
  if (.NOT.ALLOCATED(Z%sfilter_mat)) ALLOCATE(Z%sfilter_mat(dim,dim))
  do row=1,dim
    do col=1,dim
      Z%sfilter_mat(row,col)=L%mat(row,col)*jw
    end do
  end do
  
! Capacitance matrix
  dim=C%dim
  Y%dim=dim
  if (.NOT.ALLOCATED(Y%sfilter_mat)) ALLOCATE(Y%sfilter_mat(dim,dim))
  do row=1,dim
    do col=1,dim
      Y%sfilter_mat(row,col)=C%mat(row,col)*jw
    end do
  end do
  
! Deallocate work filter
  CALL deallocate_Sfilter(jw)
  
  RETURN
  
  END SUBROUTINE Z_Y_from_L_C
!
! NAME
!     SUBROUTINE write_Dshape_gmsh
!
!     write the points required for a Dshape connector shell model in gmsh
!     
! COMMENTS
!     
!
! HISTORY
!    started 15/11/2016 CJS
!

  SUBROUTINE write_Dshape_gmsh(x,y,w_in,w2_in,h_in,r,ox,oy,theta,dl,point,number,unit)

  USE type_specifications
  USE general_module

  IMPLICIT NONE

! variables passed to subroutine
  
  real(dp),intent(IN) :: x      ! x coordinate of the centre of the Dshape
  real(dp),intent(IN) :: y      ! y coordinate of the centre of the Dshape
  real(dp),intent(IN) :: w_in   ! width1 (x dimension) of the Dshape
  real(dp),intent(IN) :: w2_in  ! width2 (x dimension) of the Dshape
  real(dp),intent(IN) :: h_in   ! height (x dimension) of the Dshape
  real(dp),intent(IN) :: r      ! radius of curves in Dshape
  real(dp),intent(IN) :: ox     ! x offset
  real(dp),intent(IN) :: oy     ! y offset
  real(dp),intent(IN) :: theta  ! rotation angle of Dshape
  real(dp),intent(IN) :: dl     ! edge length for the line segments making up the Dshape

  integer,intent(INOUT)        :: point  ! point counter
  integer,intent(IN)           :: number ! number of the Dshape - used as a label in the gmsh file
  integer,intent(IN)           :: unit   ! unit to write to
  
! local variables

  real(dp) :: w1,w2,h
  
  real(dp) :: vx,vy
  real(dp) :: voxl,voyl
  real(dp) :: norm

  real(dp) :: xt,yt
  real(dp) :: xp,yp

  integer :: i

! START

      w1=w_in/2d0-r
      w2=w2_in/2d0-r
      h=h_in/2d0-r

! vector from top left conductor to bottem left conductor      
      vx=w1-w2
      vy=-2d0*h

! perpendicular vector to -x edge
      norm=sqrt(vx*vx+vy*vy)
      voxl=vy*r/norm
      voyl=-vx*r/norm

      write(unit,*)' // Dshape ',number
      point=point+1

! POINT 1      ! top right
      xt=w1+ox
      yt=h+r+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 2      ! top left
      xt=-w1+ox
      yt=h+r+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 3      ! top left centre
      xt=-w1+ox
      yt=h+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 4      ! top left edge
      xt=-w1+ox+voxl
      yt=h+voyl+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 5      ! bottom left edge
      xt=-w2+ox+voxl
      yt=-h+voyl+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 6      ! bottom left centre
      xt=-w2+ox
      yt=-h+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
       
! POINT 7      ! bottom left
      xt=-w2+ox
      yt=-(h+r)+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
       
! POINT 8      ! bottom right
      xt=w2+ox
      yt=-(h+r)+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 9      ! bottom right centre
      xt=w2+ox
      yt=-h+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 10      ! bottom right edge
      xt=w2+ox-voxl
      yt=-h+voyl+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 11      ! top right edge
      xt=w1+ox-voxl
      yt=h+voyl+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'
      point=point+1
      
! POINT 12      ! top right centre
      xt=w1+ox
      yt=h+oy
      xp=x+xt*cos(theta)-yt*sin(theta)
      yp=y+xt*sin(theta)+yt*cos(theta)
      write(unit,*)'Point(',point,' ) = {',xp,',',yp,',',0.0,',',dl,' };'

  RETURN

  END SUBROUTINE write_Dshape_gmsh
  
END MODULE PUL_parameter_module