⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 param.f

📁 对工业生产过程结晶过程的一个仿真程序软件包
💻 F
📖 第 1 页 / 共 2 页
字号:
* Copyright c 1998-2002 The Board of Trustees of the University of Illinois
* 		  All rights reserved.
* Developed by:	Large Scale Systems Research Laboratory
*               Professor Richard Braatz, Director*               Department of Chemical Engineering*		University of Illinois
*		http://brahms.scs.uiuc.edu
* * Permission hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the 
* Software is furnished to do so, subject to the following conditions:
* 		1. Redistributions of source code must retain the above copyright
*		   notice, this list of conditions and the following disclaimers.
*		2. Redistributions in binary form must reproduce the above 
*		   copyright notice, this list of conditions and the following 
*		   disclaimers in the documentation and/or other materials 
*		   provided with the distribution.
*		3. Neither the names of Large Scale Research Systems Laboratory,
*		   University of Illinois, nor the names of its contributors may
*		   be used to endorse or promote products derived from this 
*		   Software without specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*      param.f
*
*	  This program reads measured concentration and moments data

*       from files and estimates crystal growth and nucleation 

*	  kinetic parameters using the weighted least-squares method.

*	  The data for this program are appropriate for the 

*	  batch crystallization of crystals with one characteristic

*       dimension.
*      
*       There are two input data files.  The first file, named 

*       concen_data11, should contain the concentration data.  In

*	  case you have second concentration data set, its name

*	  should be "concen_data12", and so on.	 The second file,

*	  named "mu_data11" should contain the measured moments data, 

*       in the format as follows:

*

*       moment0, moment1, moment2, moment3, moment4

*

*	  If you have a second set of moment data, then it should

*	  be named "mu_data12", and so on.

*

*	  If you are using this code for the ChE 391 course for a

*	  crystal with one characteristic dimension, you 

*	  should only change CSTEP, MSTEP, Nsets, Cinterval,

*	  Minterval, x, weights, and Temp:

*

*	  CSTEP = total points in concentration measurements

*	  MSTEP = total points in moments measurements

*	  Nsets = numbers of data sets

*	  Cinterval = time interval between two concentration 

*				  measurements

*	  Minterval = time interval between two moment measurements

*	  x  =  initial guess of parameters

*	  weights = there are 6 weights to quantify the accuracy of

*			    the measurements.  Each weight is set to the

*			    inverse of the measurement error variance.

*				Normally it is very difficult to obtain an

*				accurate estimate of the zeroth order moment

*				and the fourth order moments, so the

*				corresponding weights for these moments are

*				normally set to zero.

*	  Temp = temperature profile (T(t))

*		  		

*	  Parameter changes	should be done both in the main 

*	  program and in the subroutine FCN.  Changes to Temp

*	  should be made in the subroutine Temp.

*

*	  If you are using this parameter estimation code for 

*	  another process, then you would need to change the model

*	  equations as well as the above variables.

*

*	  Output of the program is the best-fit model parameters,

*	  which is the vector called "x" in the output screen.  The
*       other parameters on the output screen give information on

*       the convergence of the parameter estimation algorithm,

*	  which can be ignored for most purposes.  The code takes

*	  up to 10 minutes to run, depending on the speed of the

*       computer and the quality of the initial parameter guesses. 

* 
*	The main program initializes the variables used by the
*	FFSQP subroutine, which minimizes the least-squared errors.  

*	Explanation of the variables is given in the FFSQP subroutine.

*	After initialization the program calls the FFSQP subroutine 

*	to solve the nonlinear constrained optimization problem.

*     Our experience is that the program converges provided that

*     you enter reasonable initial guesses.
*

*       Date:    February 12, 1998

*       Authors: Serena H. Chung and Richard D. Braatz

*                Department of Chemical Engineering

*                University of Illinois at Urbana-Champaign

*	  Modified:March 4, 2000

*	  By:      David L. Ma and Richard D. Braatz 

*

	use MSIMSL

      INTEGER CSTEP, MSTEP, Nsets, Cinterval, Minterval
      PARAMETER (CSTEP=158,Nsets=1, MSTEP=6)
      PARAMETER (Cinterval=1,Minterval=30)
      INTEGER nparam, npos1, npos2,I1
      PARAMETER (nparam = 4, npos1=12, npos2=8)
      CHARACTER*60 file_concen, file_mu, bob

      INTEGER  nf, nineqn, nineq, neqn, neq, iwsize, nwsize
      INTEGER mode, iprint,miter
      INTEGER inform, I
      PARAMETER(nf=1, nineq=0, neq=0)
      PARAMETER(mode=100,miter=10000)
      PARAMETER(iwsize=6*nparam+8*(nineq+neq)+7*(nf)+30) 
      PARAMETER(nwsize=4*nparam**2+5*(nineq+neq)*nparam+
     &		3*(nf)*nparam+
     &		26*(nparam+nf)+45*(nineq+neq)+100) 
      INTEGER iw(iwsize)
      REAL*8 bigbnd, eps, epseqn, udelta
      REAL*8 x(nparam), bl(nparam), bu(nparam)
      REAL*8 f(nf),g(nineq+neq+1),w(nwsize)
      INTEGER NWRITE, flag
      REAL*8 ConcData(Nsets,CSTEP), Mu0Data(Nsets,MSTEP)
      REAL*8 Mu1Data(Nsets,MSTEP), Mu2Data(Nsets,MSTEP)
      REAL*8 Mu3Data(Nsets,MSTEP), Mu4Data(Nsets,MSTEP)
      REAL*8 weight_conc, weight_mu0,weight_mu1,
     &       weight_mu2, weight_mu3, weight_mu4

      EXTERNAL FCN,cntr,grobfd,grcnfd

      COMMON /CONCEN/ConcData
      COMMON /MU0/Mu0Data

	COMMON /MU1/Mu1Data

	COMMON /MU2/Mu2Data

	COMMON /MU3/Mu3Data 

      COMMON /MU4/Mu4Data
      COMMON /DATA1/flag
      COMMON /DATA_OUT/NWRITE 

      COMMON /WEIGHT/weight_conc, weight_mu0,weight_mu1,
     &		     weight_mu2, weight_mu3, weight_mu4

*  Initial guess:

      DATA x/	1.15D0, 8.749D0,
     &		1.53D0, 17.742D0/

* file name

      file_concen='concen_data'
      file_mu='mu_data'

*Input the weights for least-squares parameter estimation


      weight_conc=1.0D0/0.3D0/0.3D0
      weight_mu0=0.0D0
      weight_mu1=1.0D0/0.901D5/0.901D5
      weight_mu2=1.0D0/0.28D8/0.28D8
      weight_mu3=1.0D0/0.12D11/0.12D11
      weight_mu4=0.0D0

*FFSQP parameters


      bigbnd=1.0D12
      eps=1.0D-8
      epseqn=0.0D0
      udelta=0.0D0
      iprint=2
      nineqn=0
      neqn=0

* Lower bounds:


  	bl(1)=1.0D0
      bl(2)=5.0D0
      bl(3)=1.0D0
      bl(4)=3.0D0


* Upper bounds:


  	bu(1)=2.0D0
      bu(2)=15.0D0
      bu(3)=3.0D0
      bu(4)=20.0D0


	DO I =1+10 , Nsets+10

	    I1=I-10
* Read in data from file
        DO  J = 1,CSTEP
             WRITE(file_concen(npos1:npos1+1), '(I2)') I

		   file_concen = file_concen(1:npos1+1) // '.txt'
             OPEN(UNIT=20, FILE=file_concen, FORM='FORMATTED',
     &             ACCESS='SEQUENTIAL', STATUS='OLD')
             READ(20,*) ConcData(I1,J)
	  ENDDO
	  CLOSE(UNIT=20)
	  DO J=1,MSTEP
             WRITE(file_mu(npos2:npos2+1), '(I2)') I

		   file_mu = file_mu(1:npos2+1) // '.txt'
             OPEN(UNIT=20, FILE=file_mu, FORM='FORMATTED',
     &             ACCESS='SEQUENTIAL', STATUS='OLD')
	     READ(20,*) Mu0Data(I1,J), Mu1Data(I1,J), Mu2Data(I1,J),
     &		          Mu3Data(I1,J), Mu4Data(I1,J)

	  ENDDO
	  CLOSE(UNIT=20)
  
 	ENDDO

      call FFSQP(nparam,nf,nineqn,nineq,neqn,neq,mode,iprint,
     *           miter,inform,bigbnd,eps,epseqn,udelta,bl,bu,x,f,g,
     *           iw,iwsize,w,nwsize,FCN,cntr,grobfd,grcnfd)



	OPEN(UNIT=20, FILE='param.dat', FORM='FORMATTED',

     &      ACCESS='SEQUENTIAL', STATUS='UNKNOWN')

      WRITE(20,10)x(1) 

	WRITE(20,10)x(2)

	WRITE(20,10)x(3)

	WRITE(20,10)x(4)

   10	FORMAT(E24.16)

      STOP
      END

*****************************************************************

      SUBROUTINE cntr(Nvar,jjj,x,gj)

*	cntr is the subroutine for the constraints.  The
*	constraints are listed in the following order:   
*	Nonlinear inequality constraints, linear inequality 
*	constraints, nonlinear equality constraints, and linear 
*	equality constraints.
*
*     input:   Nvar - number of parameters
*	         jjj  - indicates the jjj_th constraint
*	         x    - Nvar-dimensional vector of parameters
*	       
*     output:  gj   - the jjj_th constraint
*

      INTEGER Nvar,jjj
      REAL*8 x(*),gj


      RETURN
      END

******************************************************************
*
*       SUBROUTINE FCN(Nvar,j,THETA,Phi)
*
*       Nvar = number of parameters to be determined
*       THETA = vector of length N, parameters to be determined
*       Phi = objective function to be optimized
*
*       This subroutine simulates the operation of an industrial
*       crystallizer scaled-up from the experimental batch cooling
*       crystallizer described in S. M. Miller's Ph.D. thesis
*       published at the University of Texas at Austin in 1993.
*
*
*       Date:    February 12, 1998
*       Authors: Serena H. Chung and Richard D. Braatz
*                Department of Chemical Engineering
*                University of Illinois at Urbana-Champaign
*	  Modified:March 4, 2000

*	  By:      David L. Ma and Richard D. Braatz
*

      SUBROUTINE FCN(Nvar,j,THETA,Phi)

      INTEGER CSTEP, MSTEP, Nsets, Cinterval, Minterval
      PARAMETER (CSTEP=158,Nsets=1,MSTEP=6)
      PARAMETER (Cinterval=1,Minterval=30)

      INTEGER NN, NEQ,j,Nvar,MXPARM,Ndata
      PARAMETER (NN=CSTEP+1,NEQ=9,MXPARM=50,Ndata=Nsets)
      REAL*8 THETA(*), Phi
      INTEGER kfinal, I, Iteration
      INTEGER Norder, LDA, LDB, IPATH
      PARAMETER(Norder=3, LDA=3, LDB=3,IPATH=1)
      REAL*8 T, Y(NEQ)
      REAL*8 delt, tfinal
      REAL*8 mu00
      REAL*8 cell_length, Msolv, kv, ka, UA, densityc, densitys
      REAL*8 r0, alpha, g, kg, b, kb
      REAL*8 moment0(NN), moment1(NN), moment2(NN)
      REAL*8 moment3(NN), moment4(NN)
      REAL*8 time (NN), concentration(NN), seed_moment1(NN)
      REAL*8 seed_moment2(NN), seed_moment3(NN)
      REAL*8 temperature(NN), relsatn(NN)
      REAL*8 Temp, Csat

      REAL*8 ConcData(Ndata,CSTEP), Mu0Data(Nsets,MSTEP)
      REAL*8 Mu1Data(Nsets,MSTEP), Mu2Data(Nsets,MSTEP)
      REAL*8 Mu3Data(Nsets,MSTEP), Mu4Data(Nsets,MSTEP)
      REAL*8 weight_conc, weight_mu0,weight_mu1,
     &       weight_mu2, weight_mu3, weight_mu4

      REAL*8 AA(3,3), BB(3), gamma(3), lmin, lmax
      REAL*8 mass_seed, mean_seed, width
      
*lsodes' parameters
      
      INTEGER itol, iopt, itask, istate, mf
      INTEGER lrw, liw, iwork(200)
      REAL*8  rtol, atol, rwork(3800)      
            
      EXTERNAL MOMENTS, MOMENTSJ, DLSARG
      COMMON /GROWTH_DATA/kg, g
      COMMON /BIRTH_DATA/kb, b 
      COMMON /EXP_DATA/r0, alpha, mu00, UA, Msolv
      COMMON Iteration
      COMMON /CONCEN/ConcData
      COMMON /MU0/Mu0Data
      COMMON /MU1/Mu1Data
      COMMON /MU2/Mu2Data
      COMMON /MU3/Mu3Data 
      COMMON /MU4/Mu4Data

      COMMON /WEIGHT/weight_conc, weight_mu0,weight_mu1,
     &		     weight_mu2, weight_mu3, weight_mu4
 
      Phi=0.0D0
      error_conc=0.0D0
      error_trans=0.0D0
 
      DO 777 Iteration=1, Ndata

*Simulation parameters
*     controller time step in minutes
      delt=1.0D0
*     total time step
      kfinal=NN
*     final time in minutes
      tfinal=DFLOAT(NN)*delt

*Parameters for experimental set-up
*     cell length for spectrophotometer in millimeter
*     This was modified from that in Miller's thesis because
*     his value (2.0) did not agree with his simulation results
      cell_length=1.77D0
*     mass of solvent in grams, converted from 2000 gallons
      Msolv=7.57D6
*     volume shape factor (Appendix C in Miller)
      kv=1.0D0
*     area shape factor (Appendix C in Miller)
      ka=6.0D0
*     heat transfer coefficient multiplied by surface area
*     in calorie/minute/degree C 
*     density of solvent in g/cm^3 (solvent is water)
      densitys=1.0D0
*     density of crystal in g/cm^3 (Appendix C in Miller)
      densityc=2.11D0
*     seed size at nucleation
       r0=0.0D0
*     crystal density*volume shape factor,
*     in gram crystal/micron^3/particle
*     (alpha*L^3=mass of particle)
      alpha=kv*densityc*(1.0D-4)**3

*     Total mass of seed crystals (grams)	
      mass_seed = 230.0D0
*     Mean size of the seed crystals (microns)
      mean_seed = 196.0D0
*     Percent width of the initial seed distribution
      width = 6.12D0

*Growth and nucleation kinetic parameters (Table 4.6 in Miller)
*     (dimensionaless)
      g=THETA(1)
*     (mirons/minute)
      kg=DEXP(THETA(2))
*     (dimensionless)
      b=THETA(3)
*     (number of particles/cm^3/minute) 
      kb=DEXP(THETA(4))

*Optimization parameters:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -