50#if defined(_WIN32) && !defined(_WIN64)
51#define dec_directives_win32
71#ifdef dec_directives_win32
82 INTEGER,
Dimension(:),
Pointer :: cntvect
97 coi_error = max( coi_error,
coidef_numnz( cntvect, 6*ne ) )
101 coi_error = max( coi_error,
coidef_optfile( cntvect,
'elec.opt' ) )
112#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
113 coi_error = max( coi_error,
coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
116 If ( coi_error .ne. 0 )
THEN
118 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
120 call flog(
"Skipping Solve due to setup errors", 1 )
126 If ( coi_error /= 0 )
then
127 call flog(
"Errors encountered during solution", 1 )
129 call flog(
"Status or Solution routine was not called", 1 )
131 call flog(
"Solver and Model Status was not as expected (1,2)", 1 )
135 write(*,*)
'End of Electron example. Return code=',coi_error
137 if (
coi_free(cntvect) /= 0 )
call flog(
"Error while freeing control vector",1)
139 call flog(
"Successful Solve", 0 )
149 Integer,
save :: seed = 12359
151 seed = mod(seed*1027+25,1048576)
152 rndx = float(seed)/float(1048576)
163Integer Function elec_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
164 colsta, rowno, value, nlflag, n, m, nz, &
166#ifdef dec_directives_win32
170 integer,
intent (in) :: n
171 integer,
intent (in) :: m
172 integer,
intent (in) :: nz
173 real*8,
intent (in out),
dimension(n) :: lower
174 real*8,
intent (in out),
dimension(n) :: curr
175 real*8,
intent (in out),
dimension(n) :: upper
176 integer,
intent (in out),
dimension(n) :: vsta
178 integer,
intent (out),
dimension(m) ::
type
179 integer,
intent (in out),
dimension(m) :: esta
181 real*8,
intent (in out),
dimension(m) :: rhs
182 integer,
intent (in out),
dimension(n+1) :: colsta
183 integer,
intent (out),
dimension(nz) :: rowno
184 integer,
intent (in out),
dimension(nz) :: nlflag
185 real*8,
intent (in out),
dimension(nz) ::
value
190 real*8,
parameter :: pi = 3.141592
192 Real,
External ::
rndx
203 curr(i ) = cos(theta)*sin(phi)
204 curr(i+ ne) = sin(theta)*sin(phi)
205 curr(i+2*ne) = cos(phi)
287Integer Function elec_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
288 n, nz, thread, usrmem )
289#ifdef dec_directives_win32
293 integer,
intent (in) :: n
294 integer,
intent (in) :: rowno
295 integer,
intent (in) :: nz
296 real*8,
intent (in),
dimension(n) :: x
297 real*8,
intent (in out) :: g
298 real*8,
intent (in out),
dimension(n) :: jac
299 integer,
intent (in),
dimension(nz) :: jcnm
301 integer,
intent (in) :: mode
303 integer,
intent (in) :: ignerr
305 integer,
intent (in out) :: errcnt
307 integer,
intent (in) :: thread
312 real*8 :: dist, dist32, tx, ty, tz
318 if ( rowno == ne+1 )
then
322 if ( mode .eq. 1 .or. mode .eq. 3 )
then
326 dist = (x(i)-x(j))**2 + (x(i+ne)-x(j+ne))**2 + (x(i+2*ne)-x(j+2*ne))**2
327 g = g + 1.d0/sqrt(dist)
334 if ( mode .eq. 2 .or. mode .eq. 3 )
then
340 dist = (x(i)-x(j))**2 + (x(i+ne)-x(j+ne))**2 + (x(i+2*ne)-x(j+2*ne))**2
341 dist32 = (1.d0/sqrt(dist))**3
342 tx = -(x(i)-x(j))*dist32
343 ty = -(x(i+ne)-x(j+ne))*dist32
344 tz = -(x(i+2*ne)-x(j+2*ne))*dist32
347 jac(i+ne) = jac(i+ne) + ty
348 jac(j+ne) = jac(j+ne) - ty
349 jac(i+2*ne) = jac(i+2*ne) + tz
350 jac(j+2*ne) = jac(j+2*ne) - tz
360 if ( mode .eq. 1 .or. mode .eq. 3 )
then
361 g = x(i)**2 + x(i+ne)**2 + x(i+2*ne)**2
366 if ( mode .eq. 2 .or. mode .eq. 3 )
then
368 jac(i+ne) = 2.d0*x(i+ne)
369 jac(i+2*ne) = 2.d0*x(i+2*ne)
Main program. A simple setup and call of CONOPT.
integer function std_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
integer function std_status(modsta, solsta, iter, objval, usrmem)
integer function std_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
integer function std_errmsg(rowno, colno, posno, msglen, usrmem, msg)
integer function elec_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
integer function elec_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer(c_int) function coidef_message(cntvect, coi_message)
define callback routine for handling messages returned during the solution process.
integer(c_int) function coidef_solution(cntvect, coi_solution)
define callback routine for returning the final solution values.
integer(c_int) function coidef_status(cntvect, coi_status)
define callback routine for returning the completion status.
integer(c_int) function coidef_readmatrix(cntvect, coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
integer(c_int) function coidef_errmsg(cntvect, coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
integer(c_int) function coidef_fdeval(cntvect, coi_fdeval)
define callback routine for performing function and derivative evaluations.
integer(c_int) function coidef_optfile(cntvect, optfile)
define callback routine for defining an options file.
integer(c_int) function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
integer(c_int) function coidef_numvar(cntvect, numvar)
defines the number of variables in the model.
integer(c_int) function coidef_numcon(cntvect, numcon)
defines the number of constraints in the model.
integer(c_int) function coidef_numnlnz(cntvect, numnlnz)
defines the Number of Nonlinear Nonzeros.
integer(c_int) function coidef_optdir(cntvect, optdir)
defines the Optimization Direction.
integer(c_int) function coidef_numnz(cntvect, numnz)
defines the number of nonzero elements in the Jacobian.
integer(c_int) function coidef_objcon(cntvect, objcon)
defines the Objective Constraint.
integer(c_int) function coi_create(cntvect)
initializes CONOPT and creates the control vector.
integer(c_int) function coi_free(cntvect)
frees the control vector.
integer(c_int) function coi_solve(cntvect)
method for starting the solving process of CONOPT.
float rndx()
Defines a pseudo random number between 0 and 1.
subroutine flog(msg, code)