home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / MATH / VISSIM.ZIP / VSOLVER.FOR < prev    next >
Text File  |  1993-11-30  |  3KB  |  71 lines

  1. c     Nonlinear Gauss Seidel static solver 
  2. c     DLL file for VisSim User defined static solver
  3. c
  4. c ... Basics:
  5. c     Requires Vissim version 1.3, impsim.lib (11/24/93) and higher
  6. c     The name of the dll is VSOLVER.DLL
  7. c     The name of the function is USERSOLVER
  8. c     Vissim will call usersolver at each dt.  Usersolver can call the 
  9. c     Vissim routine VSMREQUEST(CMD,VECVAL) where:
  10. c     CMD = an integer from 1 to 5 denoting a command;
  11. c           1 = VrGetConstraints = fills vecval with the constraint values
  12. c           2 = VGetUnk = fills vecval with the unknown output values
  13. c           3 = VSetUnk = vecval values go the vissim unknowns
  14. c           4 = VGetSolverInfo = fills vecval with 5 values;
  15. c                       element 1 = # of constraints
  16. c                       element 2 = # of unknowns
  17. c                       element 3 = relaxation value
  18. c                                         redefined for debug (1 = debug output on)
  19. c                       element 4 = max # of iterations
  20. c                       element 5 = convergence delta
  21. c           5 = VrExec = executes the block diagram
  22. c                6 = VGetUnkInputs = fills vecval with unknown input values
  23. c     VECVAL = a vector used to pass info to and from vissim
  24. c     The vsolver dll also needs a .def file with the EXPORT statement 
  25. c     defined as USERSOLVER.   
  26. c        
  27.     interface to subroutine debmsg[c,varying](fmt)
  28.     character*32 fmt[reference]
  29.     end
  30. c
  31.     subroutine usersolver
  32.     implicit real*8 (A-H,O-Z) 
  33.     parameter (nmax=20) 
  34.     common/vs/nc,nu
  35.     real*8 unk(nmax), con(nmax), unk_in(nmax), time  
  36. c  
  37.     call getSimTime(time)
  38.     ipass=0 !first pass flag, 1=first pass
  39.     if (time.eq.0.)  ipass=1
  40. c
  41. c     Get dimension info 1st pass only
  42.     if (ipass.eq.1) then
  43.         call vsmrequest(4,unk)
  44.         nc=unk(1)   !# of constraints
  45.         nu=unk(2)   !# of unknowns
  46.         relax=unk(3)    !relaxation factor
  47.         itermax=unk(4)     !max iterations
  48.         converg=unk(5)     !truncation error for jumpout
  49.     endif
  50. c
  51.  
  52. c     Iteration loop
  53.     do 20 k=1,itermax
  54. c
  55.         call vsmrequest(2,unk)  !get unknown outputs from vissim
  56.         call vsmrequest(5,unk)  !execute the diagram
  57.         call vsmrequest(6,unk_in)  !get unknown inputs from vissim
  58.         err=0.
  59.       do 10 i=1,nu !update unknowns and compute error in con vector 
  60.         err=err+abs(unk(i)-unk_in(i))
  61.             unk(i)=(unk_in(i)*relax) + (unk(i)*(1.-relax) )
  62.   10    continue
  63.         if (err.le.converg) goto 30 !jumpout if error satisfied
  64.         call vsmrequest(3,unk)  !send new unknowns back to vissim
  65.  
  66.   20  continue
  67.   30  continue
  68. c
  69.     return
  70.     end
  71.