111 | | |
| 111 | {{{ |
| 112 | !######################################################################### |
| 113 | ! |
| 114 | ! Copyright (C) 2003-2012 Department of Physics and Astronomy, |
| 115 | ! University of Rochester, |
| 116 | ! Rochester, NY |
| 117 | ! |
| 118 | ! problem.f90 of module Bondi is part of AstroBEAR. |
| 119 | ! |
| 120 | ! AstroBEAR is free software: you can redistribute it and/or modify |
| 121 | ! it under the terms of the GNU General Public License as published by |
| 122 | ! the Free Software Foundation, either version 3 of the License, or |
| 123 | ! (at your option) any later version. |
| 124 | ! |
| 125 | ! AstroBEAR is distributed in the hope that it will be useful, |
| 126 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 127 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 128 | ! GNU General Public License for more details. |
| 129 | ! |
| 130 | ! You should have received a copy of the GNU General Public License |
| 131 | ! along with AstroBEAR. If not, see <http://www.gnu.org/licenses/>. |
| 132 | ! |
| 133 | !######################################################################### |
| 134 | !Bondi Module |
| 135 | |
| 136 | MODULE Problem |
| 137 | |
| 138 | USE DataDeclarations |
| 139 | USE GlobalDeclarations |
| 140 | USE PhysicsDeclarations |
| 141 | USE ParticleDeclarations |
| 142 | USE CommonFunctions |
| 143 | USE Bondi |
| 144 | USE Winds |
| 145 | IMPLICIT NONE |
| 146 | PRIVATE |
| 147 | |
| 148 | PUBLIC ProblemModuleInit, ProblemGridInit, & |
| 149 | ProblemBeforeStep, ProblemAfterStep, ProblemSetErrFlag, ProblemBeforeGlobalStep |
| 150 | TYPE(PointGravityDef), POINTER :: PointGravityObj |
| 151 | REAL(KIND=qprec) :: namb, tamb, ibs, obs, mcent, r_bh, ramb, mdot_bondi, camb, r_sonic!, mdot_ruffert |
| 152 | |
| 153 | |
| 154 | CONTAINS |
| 155 | |
| 156 | SUBROUTINE ProblemModuleInit |
| 157 | INTEGER :: iErr |
| 158 | TYPE(ParticleDef), POINTER :: Particle |
| 159 | NAMELIST /ProblemData/ namb, tamb, ibs, obs, mcent |
| 160 | |
| 161 | OPEN(UNIT=PROBLEM_DATA_HANDLE, FILE='problem.data') |
| 162 | READ(PROBLEM_DATA_HANDLE,NML=ProblemData) |
| 163 | CLOSE(PROBLEM_DATA_HANDLE, IOSTAT=iErr) |
| 164 | |
| 165 | ramb = (namb*amu*xmu)/rscale !convert from namb to mass density in computational units |
| 166 | camb=sqrt(gamma*tamb/tempscale) !calculate scaled sound speed of gas at infinity |
| 167 | |
| 168 | |
| 169 | IF (.not. lRestart) THEN |
| 170 | NULLIFY(Particle) |
| 171 | CALL CreateParticle(Particle) |
| 172 | Particle%q(1)=mcent*MSolar/rScale/lScale**3.0 |
| 173 | Particle%xloc=0 |
| 174 | Particle%iAccrete=2 !0=no accretion, 1=fed, 2=!KRUMHOLZ_ACCRETION |
| 175 | Particle%lFixed=.true. |
| 176 | particle%buffer(0:MaxLevel)=ceiling(ibs/levels(0:MaxLevel)%dx) |
| 177 | CALL AddSinkParticle(Particle) |
| 178 | CALL CreatePointGravityObject(Particle%PointGravityObj) |
| 179 | Particle%PointGravityObj%soft_length=1d0*levels(MaxLevel)%dx |
| 180 | Particle%PointGravityObj%soft_function=SPLINESOFT |
| 181 | Particle%PointGravityObj%Mass=mcent*MSolar/rScale/lScale**3.0 !Central object mass in computational units |
| 182 | ELSE !the next line is needed for restarts using only one particle, such as this module: |
| 183 | particle=>SinkParticles%self !must redefine the particle pointer upon restarts -- for multiple particles, will need to iterate over them (see the binary problem for ex) |
| 184 | END IF |
| 185 | |
| 186 | !Calculate theoretical accretion rate (computational units): |
| 187 | mdot_bondi=(4.0*pi*bondi_lambda*ramb*(ScaleGrav*Particle%q(1))**2.0) / (camb**3.0) |
| 188 | !Calculate the sonic radius (computational units): |
| 189 | r_sonic = ((5.0-3.0*gamma)/4.0)*((ScaleGrav*particle%q(1))/camb**2.0) |
| 190 | |
| 191 | IF (MPI_ID == 0) THEN |
| 192 | PRINT *, 'cs_inf=', camb |
| 193 | PRINT *, 'sonic radius=', r_sonic |
| 194 | PRINT *, 'T_inf=', Tamb/TempScale |
| 195 | PRINT *, "rho_inf=", ramb |
| 196 | PRINT *, "mdot_bondi (CU) = ", mdot_bondi |
| 197 | PRINT *, 'M_star=', particle%q(1) |
| 198 | END IF |
| 199 | |
| 200 | |
| 201 | !Calculate Bondi radius of initial particle mass |
| 202 | r_BH=ScaleGrav*Particle%q(1)/(gamma*tamb/TempScale) |
| 203 | IF (MPI_ID == 0) THEN |
| 204 | write(*,*) 'Bondi radius (CU)= ', r_BH |
| 205 | END IF |
| 206 | |
| 207 | END SUBROUTINE ProblemModuleInit |
| 208 | |
| 209 | !> Initial Conditions |
| 210 | !! @param Info Info object |
| 211 | SUBROUTINE ProblemGridInit(Info) |
| 212 | !! @brief Initializes the grid data according to the requirements of the problem. |
| 213 | !! @param Info A grid structure. |
| 214 | TYPE (InfoDef) :: Info |
| 215 | INTEGER :: i,j,k |
| 216 | INTEGER :: rmbc,zrmbc,level |
| 217 | INTEGER :: mx, my, mz |
| 218 | INTEGER :: iErr |
| 219 | REAL (KIND=qPrec), POINTER, DIMENSION (:,:,:,:) :: q |
| 220 | REAL(KIND=xprec) :: x,y,z,xl,yl,zl,dx,dy,dz,r |
| 221 | REAL(KIND=qPREC) :: x_, y_, z_, rho, v, temp |
| 222 | level=Info%level |
| 223 | q=>Info%q |
| 224 | ! Calculating the number of ghost cells on each side of the grid. |
| 225 | rmbc=levels(level)%gmbc(levels(level)%step) |
| 226 | dx=levels(level)%dX |
| 227 | dy=dx |
| 228 | SELECT CASE(nDim) |
| 229 | CASE(2) |
| 230 | zrmbc=0 |
| 231 | dz=0d0 |
| 232 | CASE(3) |
| 233 | zrmbc=rmbc |
| 234 | dz=dx |
| 235 | END SELECT |
| 236 | mx = Info%mX(1) |
| 237 | my = Info%mX(2) |
| 238 | mz = Info%mX(3) |
| 239 | xl=Info%xBounds(1,1) |
| 240 | yl=Info%xBounds(2,1) |
| 241 | zl=Info%xBounds(3,1) |
| 242 | |
| 243 | !All of the values below are in computational units |
| 244 | ! need the origin to be at 0,0,0: |
| 245 | DO i=1-rmbc, mx+rmbc |
| 246 | x = (xl+(REAL(i,xPrec)-half)*dx) |
| 247 | DO j=1-rmbc, my+rmbc |
| 248 | y = (yl+(REAL(j,xPrec)-half)*dy) |
| 249 | DO k=1-zrmbc, mz+zrmbc |
| 250 | z = (zl+(REAL(k,xPrec)-half)*dz) |
| 251 | r = sqrt(x**2 + y**2+z**2) |
| 252 | |
| 253 | ! Calculate non-dimensional radius(x_), density(z_), and velocity(y_ |
| 254 | !x_=max(r, ibs-5d0*levels(0)%dx)/r_BH --- commented to avoid Bondi solution being copied within IBS |
| 255 | x_=r/r_BH |
| 256 | z_=BH_alpha(x_) !nondimensional density (normalized to rho_inf) |
| 257 | y_=Bondi_lambda/(z_*x_**(myDim-1)) !nondimensional velocity (normalized to Cs_inf) |
| 258 | |
| 259 | |
| 260 | ! Then calculate physical values |
| 261 | rho=z_*namb/nScale |
| 262 | v=-y_*sqrt(gamma*tamb/TempScale) |
| 263 | temp=tamb*(z_**(gamma1))/TempScale |
| 264 | |
| 265 | q(i,j,k,1)=rho |
| 266 | q(i,j,k,ivx)=rho*v*x/r |
| 267 | q(i,j,k,ivy)=rho*v*y/r |
| 268 | q(i,j,k,ivz)=rho*v*z/r |
| 269 | q(i,j,k,iE)=half*rho*v**2+gamma7*rho*temp |
| 270 | END DO |
| 271 | END DO |
| 272 | END DO |
| 273 | END SUBROUTINE ProblemGridInit |
| 274 | |
| 275 | !! @param Info Info object |
| 276 | SUBROUTINE ProblemBeforeStep(Info) |
| 277 | !! @brief Performs any tasks required before the advance step. |
| 278 | !! @param Info A grid structure. |
| 279 | TYPE (InfoDef) :: Info |
| 280 | TYPE(WindDef), POINTER :: Wind |
| 281 | INTEGER :: i,j,k, iErr |
| 282 | INTEGER :: rmbc,zrmbc,level |
| 283 | INTEGER :: mx, my, mz, edge |
| 284 | REAL (KIND=qPrec), POINTER, DIMENSION (:,:,:,:) :: q |
| 285 | REAL(KIND=xprec) :: x,y,z,xl,yl,zl,dx,dy,dz,r |
| 286 | REAL(KIND=qPREC) :: x_, y_, z_, rho, v, temp |
| 287 | |
| 288 | |
| 289 | !Set up wind object which prevents any material from leaving the grid (i.e. Ghost zones setup): |
| 290 | DO i=1,nDim |
| 291 | DO edge=1,2 |
| 292 | IF (Gmthbc(i,edge) == 1) THEN |
| 293 | CALL CreateWind(Wind) |
| 294 | Wind%density=ramb |
| 295 | wind%temperature=tamb/tempscale |
| 296 | wind%type=OUTFLOW_ONLY |
| 297 | Wind%dir=i |
| 298 | Wind%edge=edge |
| 299 | END IF |
| 300 | END DO |
| 301 | END DO |
| 302 | |
| 303 | level=Info%level |
| 304 | q=>Info%q |
| 305 | ! Calculating the number of ghost cells on each side of the grid. |
| 306 | rmbc=levels(level)%gmbc(levels(level)%step) |
| 307 | dx=levels(level)%dX |
| 308 | dy=dx |
| 309 | SELECT CASE(nDim) |
| 310 | CASE(2) |
| 311 | zrmbc=0 |
| 312 | dz=0d0 |
| 313 | CASE(3) |
| 314 | zrmbc=rmbc |
| 315 | dz=dx |
| 316 | END SELECT |
| 317 | mx = Info%mX(1) |
| 318 | my = Info%mX(2) |
| 319 | mz = Info%mX(3) |
| 320 | xl=Info%xBounds(1,1) |
| 321 | yl=Info%xBounds(2,1) |
| 322 | zl=Info%xBounds(3,1) |
| 323 | |
| 324 | !All of the values below are in computational units |
| 325 | |
| 326 | DO i = 1-rmbc, mx+rmbc |
| 327 | x = (xl+(REAL(i,xPrec)-half)*dx) |
| 328 | DO j = 1-rmbc, my+rmbc |
| 329 | y = (yl+(REAL(j,xPrec)-half)*dy) |
| 330 | DO k = 1-zrmbc,mz+zrmbc |
| 331 | z = (zl+(REAL(k,xPrec)-half)*dz) |
| 332 | |
| 333 | r = sqrt(x**2 + y**2 +z**2) |
| 334 | |
| 335 | !Commented following line so that only solution copied to outer boundary sphere: |
| 336 | !IF (r < ibs .OR. r > obs) THEN !Set cells to analytic solution |
| 337 | IF (r > obs) THEN !Set cells to analytic solution |
| 338 | !same with following line: |
| 339 | !x_=max(ibs-5d0*levels(0)%dx, r)/r_BH !Adjust values deep inside inner region to avoid extremely high velocities etc... |
| 340 | x_=r/r_BH |
| 341 | z_=BH_alpha(x_) |
| 342 | y_=Bondi_lambda/(z_*x_**(myDim-1)) |
| 343 | rho=z_*namb/nScale |
| 344 | v=-y_*sqrt(gamma*tamb/TempScale) |
| 345 | temp=tamb*(z_**(gamma1))/TempScale |
| 346 | |
| 347 | q(i,j,k,1)=rho |
| 348 | q(i,j,k,ivx)=rho*v*x/r |
| 349 | q(i,j,k,ivy)=rho*v*y/r |
| 350 | !erica added z component: |
| 351 | q(i,j,k,ivz)=rho*v*z/r |
| 352 | q(i,j,k,iE)=half*rho*v**2+gamma7*rho*temp |
| 353 | |
| 354 | END IF |
| 355 | |
| 356 | |
| 357 | |
| 358 | END DO |
| 359 | END DO |
| 360 | END DO |
| 361 | |
| 362 | END SUBROUTINE ProblemBeforeStep |
| 363 | |
| 364 | !> Does nothing |
| 365 | !! @param Info Info object |
| 366 | SUBROUTINE ProblemAfterStep(Info) |
| 367 | !! @brief Performs any post-step corrections that are required. |
| 368 | !! @param Info A grid structure. |
| 369 | TYPE (InfoDef) :: Info |
| 370 | CALL ProblemBeforeStep(Info) |
| 371 | END SUBROUTINE ProblemAfterStep |
| 372 | |
| 373 | !> Does nothing |
| 374 | !! @param Info Info object |
| 375 | SUBROUTINE ProblemSetErrFlag(Info) |
| 376 | !! @brief Sets error flags according to problem-specific conditions.. |
| 377 | !! @param Info A grid structure. |
| 378 | TYPE (InfoDef) :: Info |
| 379 | END SUBROUTINE ProblemSetErrFlag |
| 380 | |
| 381 | SUBROUTINE ProblemBeforeGlobalStep(n) |
| 382 | INTEGER :: n |
| 383 | END SUBROUTINE ProblemBeforeGlobalStep |
| 384 | |
| 385 | END MODULE Problem |
| 386 | |
| 387 | |
| 388 | }}} |