Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PLAG_ReadPdfFromFile.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 
24 !******************************************************************************
25 !
26 ! Purpose: read in user defined porbability density function (PDF) of
27 ! the mass injection process.
28 !
29 ! Description: none
30 !
31 ! Input: user input file.
32 !
33 ! Output: structure with information relative to the imposed pdf
34 !
35 ! Notes: none
36 !
37 !******************************************************************************
38 !
39 ! $Id: PLAG_ReadPdfFromFile.F90,v 1.4 2008/12/06 08:44:35 mtcampbe Exp $
40 !
41 ! Copyright: (c) 2005 by the University of Illinois
42 !
43 !******************************************************************************
44 
45 SUBROUTINE plag_readpdffromfile(regions, brbeg, brend )
46 
47  USE moddatatypes
48  USE moddatastruct, ONLY : t_region
49  USE modglobal, ONLY : t_global
50  USE moderror
51  USE modparameters
52 
54 
55  TYPE(t_region), POINTER :: regions(:)
56  INTEGER,INTENT(IN) :: brbeg,brend
57 
58 ! ... local variables
59  TYPE(t_global), POINTER :: global
60  CHARACTER(CHRLEN) :: fname
61  REAL(RFREAL),POINTER :: tmpvec(:,:)
62  REAL(RFREAL) :: tmpscal
63  INTEGER :: k,tmpint,errorflag,nbins,nrow
64 !******************************************************************************
65 
66 
67  global => regions(1)%global
68 
69  CALL registerfunction( global, 'PLAG_ReadPdfFromFile',&
70  'PLAG_ReadPdfFromFile.F90' )
71 
72 !OPEN PDF file
73  WRITE(fname,'(A,A,A)') trim(global%inDir),trim(global%casename),'.plag_injcpdf'
74  OPEN(if_plag_injcpdf,file=fname,form='formatted',status='old',iostat=errorflag)
75  global%error = errorflag
76  IF (global%error /= 0) &
77  CALL errorstop( global, err_file_open,__line__,'File: '//trim(fname) )
78  READ(if_plag_injcpdf,*,err=10,end=10) nbins
79 
80 !Allocation
81  do k = brbeg,brend
82  ALLOCATE(regions(k)%plagInput%PDF%pdfvalues(nbins+1,3), stat=errorflag )
83  enddo
84  global%error = errorflag
85  ALLOCATE(tmpvec(nbins+1,5), stat=errorflag)
86  global%error = abs(global%error) + abs(errorflag)
87  IF (global%error /= 0) CALL errorstop( global, err_allocate,__line__ )
88 
89 !Read in the discrete PDF
90  do k = 1,nbins
91  READ(if_plag_injcpdf,*,err=10,end=10) nrow,tmpvec(k,1:2)
92  enddo
93 
94  tmpvec(1,3) = (tmpvec(2,1)-tmpvec(1,1))
95  do k = 2,nbins
96  tmpvec(k,3) = 2_rfreal*(tmpvec(k,1)-tmpvec(k-1,1)) - tmpvec(k-1,3)
97  enddo
98 
99 !evaluate the two following cumulative sums
100  tmpvec(1,4:5) = 0_rfreal
101  do k = 1,nbins
102  tmpvec(k+1,4) = tmpvec(k,4) + tmpvec(k,2)*tmpvec(k,3)
103  tmpvec(k+1,5) = tmpvec(k,5) + tmpvec(k,3)
104  enddo
105  tmpvec(:,4) = tmpvec(:,4) / tmpvec(nbins+1,4)
106  tmpvec(:,5) = tmpvec(:,5) + tmpvec(1,1) - tmpvec(1,3)/2_rfreal
107 
108 
109 !assign the tmp vector entries to the region pointer
110  regions(brbeg:brend)%plagInput%PDF%nbins = nbins
111  do k = brbeg,brend
112  regions(k)%plagInput%PDF%pdfvalues(:,1:3) = tmpvec(:,3:5)
113  enddo
114 
115 !--find the maximum in the PDF curve. This is the most probable diameter value,
116 !--the one from which the search will start;
117  tmpscal = 0_rfreal
118  do k = 1,nbins
119  if(tmpvec(k+1,4) - tmpvec(k,4) > tmpscal) then
120  tmpint = k+1
121  tmpscal = tmpvec(k+1,4) - tmpvec(k,4)
122  endif
123  enddo
124  tmpscal = tmpvec(tmpint,4)
125  regions(brbeg:brend)%plagInput%PDF%locmax = tmpint
126  regions(brbeg:brend)%plagInput%PDF%valmax = tmpscal
127 
128  DEALLOCATE(tmpvec)
129  close(if_plag_injcpdf)
130 
131 goto 999
132 
133 10 CONTINUE
134  CALL errorstop( global, err_file_read,__line__,'File: '//trim(fname) )
135 
136 ! finalize --------------------------------------------------------------------
137 
138 999 CONTINUE
139 
140  CALL deregisterfunction( global )
141 
142 END SUBROUTINE plag_readpdffromfile
143 
144 !******************************************************************************
145 
146 
147 
148 
149 
150 
151 
j indices k indices k
Definition: Indexing.h:6
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE brbeg
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE form
const int nrow
Definition: ex1.C:95
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469
subroutine plag_readpdffromfile(regions, brbeg, brend)