PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/ramses/patch/hydro/andrea/read_params.f90

https://bitbucket.org/gdalmuti/ramses_new
FORTRAN Modern | 186 lines | 149 code | 14 blank | 23 comment | 23 complexity | 162c8b6f606f736b588520e4b0e99818 MD5 | raw file
Possible License(s): LGPL-3.0
  1. subroutine read_params
  2. use amr_commons
  3. use pm_parameters
  4. use poisson_parameters
  5. implicit none
  6. #ifndef WITHOUTMPI
  7. include 'mpif.h'
  8. #endif
  9. !--------------------------------------------------
  10. ! Local variables
  11. !--------------------------------------------------
  12. integer::i,narg,iargc,ierr,levelmax
  13. character(LEN=80)::infile
  14. integer(kind=8)::ngridtot=0
  15. integer(kind=8)::nparttot=0
  16. logical::nml_ok
  17. !--------------------------------------------------
  18. ! Namelist definitions
  19. !--------------------------------------------------
  20. namelist/run_params/cosmo,pic,poisson,hydro,verbose,debug &
  21. & ,nrestart,ncontrol,nstepmax,nsubcycle,nremap,ordering,static,geom
  22. namelist/output_params/noutput,foutput,fbackup,aout,tout,output_mode
  23. namelist/amr_params/levelmin,levelmax,ngridmax,ngridtot &
  24. & ,npartmax,nparttot,nexpand,boxlen
  25. namelist/poisson_params/epsilon,gravity_type,gravity_params
  26. namelist/halo_parameters/Mvir,overdensity
  27. namelist/jet_parameters/r_jet,h_jet,e_jet,t_jet
  28. ! MPI initialization
  29. #ifndef WITHOUTMPI
  30. call MPI_INIT(ierr)
  31. call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
  32. call MPI_COMM_SIZE(MPI_COMM_WORLD,ncpu,ierr)
  33. myid=myid+1 ! Carefull with this...
  34. #endif
  35. #ifdef WITHOUTMPI
  36. ncpu=1
  37. myid=1
  38. #endif
  39. !--------------------------------------------------
  40. ! Advertise RAMSES
  41. !--------------------------------------------------
  42. if(myid==1)then
  43. write(*,*)'_/_/_/ _/_/ _/ _/ _/_/_/ _/_/_/_/ _/_/_/ '
  44. write(*,*)'_/ _/ _/ _/ _/_/_/_/ _/ _/ _/ _/ _/ '
  45. write(*,*)'_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ '
  46. write(*,*)'_/_/_/ _/_/_/_/ _/ _/ _/_/ _/_/_/ _/_/ '
  47. write(*,*)'_/ _/ _/ _/ _/ _/ _/ _/ _/ '
  48. write(*,*)'_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ '
  49. write(*,*)'_/ _/ _/ _/ _/ _/ _/_/_/ _/_/_/_/ _/_/_/ '
  50. write(*,*)' Version 2.0 '
  51. write(*,*)' written by Romain Teyssier (CEA/DSM/DAPNIA/SAP) '
  52. write(*,*)' (c) CEA 1999-2005 '
  53. write(*,*)' '
  54. write(*,'(" Working with nproc = ",I4," for ndim = ",I1)')ncpu,ndim
  55. write(*,*)' '
  56. ! Read namelist filename from command line argument
  57. narg = iargc()
  58. IF(narg .LT. 1)THEN
  59. write(*,*)'You should type: hydro3d input.nml'
  60. write(*,*)'File input.nml should contain a parameter namelist'
  61. call clean_stop
  62. END IF
  63. CALL getarg(1,infile)
  64. endif
  65. #ifndef WITHOUTMPI
  66. call MPI_BCAST(infile,80,MPI_CHARACTER,0,MPI_COMM_WORLD,ierr)
  67. #endif
  68. !-------------------------------------------------
  69. ! Read the namelist
  70. !-------------------------------------------------
  71. INQUIRE(file=infile,exist=nml_ok)
  72. if(.not. nml_ok)then
  73. if(myid==1)then
  74. write(*,*)'File '//TRIM(infile)//' does not exist'
  75. endif
  76. call clean_stop
  77. end if
  78. open(1,file=infile)
  79. rewind(1)
  80. read(1,NML=run_params)
  81. rewind(1)
  82. read(1,NML=output_params)
  83. rewind(1)
  84. read(1,NML=amr_params)
  85. rewind(1)
  86. read(1,NML=poisson_params,END=81)
  87. 81 continue
  88. rewind(1)
  89. read(1,NML=halo_parameters)
  90. rewind(1)
  91. read(1,NML=jet_parameters)
  92. !--------------------------------------------------
  93. ! Check for errors in the namelist so far
  94. !--------------------------------------------------
  95. levelmin=MAX(levelmin,1)
  96. nlevelmax=levelmax
  97. nml_ok=.true.
  98. if(levelmin<1)then
  99. if(myid==1)write(*,*)'Error in the namelist:'
  100. if(myid==1)write(*,*)'levelmin should not be lower than 1 !!!'
  101. nml_ok=.false.
  102. end if
  103. if(nlevelmax<levelmin)then
  104. if(myid==1)write(*,*)'Error in the namelist:'
  105. if(myid==1)write(*,*)'levelmax should not be lower than levelmin'
  106. nml_ok=.false.
  107. end if
  108. if(ngridmax==0)then
  109. if(ngridtot==0)then
  110. if(myid==1)write(*,*)'Error in the namelist:'
  111. if(myid==1)write(*,*)'Allocate some space for refinements !!!'
  112. nml_ok=.false.
  113. else
  114. ngridmax=ngridtot/int(ncpu,kind=8)
  115. endif
  116. end if
  117. if(npartmax==0)then
  118. npartmax=nparttot/int(ncpu,kind=8)
  119. endif
  120. if(myid>1)verbose=.false.
  121. if(pic.and.(.not.poisson))then
  122. poisson=.true.
  123. endif
  124. call read_hydro_params(nml_ok)
  125. close(1)
  126. !-----------------
  127. ! Max size checks
  128. !-----------------
  129. if(nlevelmax>MAXLEVEL)then
  130. write(*,*) 'Error: nlevelmax>MAXLEVEL'
  131. call clean_stop
  132. end if
  133. if(nregion>MAXREGION)then
  134. write(*,*) 'Error: nregion>MAXREGION'
  135. call clean_stop
  136. end if
  137. !-----------------------------------
  138. ! Rearrange level dependent arrays
  139. !-----------------------------------
  140. do i=nlevelmax,levelmin,-1
  141. nsubcycle (i)=nsubcycle (i-levelmin+1)
  142. r_refine (i)=r_refine (i-levelmin+1)
  143. a_refine (i)=a_refine (i-levelmin+1)
  144. b_refine (i)=b_refine (i-levelmin+1)
  145. x_refine (i)=x_refine (i-levelmin+1)
  146. y_refine (i)=y_refine (i-levelmin+1)
  147. z_refine (i)=z_refine (i-levelmin+1)
  148. m_refine (i)=m_refine (i-levelmin+1)
  149. exp_refine(i)=exp_refine(i-levelmin+1)
  150. initfile (i)=initfile (i-levelmin+1)
  151. end do
  152. do i=1,levelmin-1
  153. nsubcycle (i)= 1
  154. r_refine (i)=-1.0
  155. a_refine (i)= 1.0
  156. b_refine (i)= 1.0
  157. x_refine (i)= 0.0
  158. y_refine (i)= 0.0
  159. z_refine (i)= 0.0
  160. m_refine (i)=-1.0
  161. exp_refine(i)= 2.0
  162. initfile (i)= ' '
  163. end do
  164. if(.not. nml_ok)then
  165. if(myid==1)write(*,*)'Too many errors in the namelist'
  166. if(myid==1)write(*,*)'Aborting...'
  167. call clean_stop
  168. end if
  169. #ifndef WITHOUTMPI
  170. call MPI_BARRIER(MPI_COMM_WORLD,ierr)
  171. #endif
  172. end subroutine read_params