Changes between Version 51 and Version 52 of ModulesOnAstroBear
- Timestamp:
- 04/24/17 16:14:12 (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ModulesOnAstroBear
v51 v52 142 142 143 143 === Using Template Functions === 144 Oneway to apply our initial/boundary functions to grid patches is to use template subroutines. This involves writing IC and BC subroutines that adhere to a certain form and then passing them to the ApplyTemplate subroutine. The ApplyTemplate loops over the grid cells and converts the q-array to primitive form (density, velocity, pressure) before calling the template function (in this case !InitialCondition or !BoundaryCondition.144 The preferred way to apply our initial/boundary functions to grid patches is to use template subroutines. This involves writing IC and BC subroutines that adhere to a certain form and then passing them to the ApplyTemplate subroutine. The ApplyTemplate loops over the grid cells and converts the q-array to primitive form (density, velocity, pressure) before calling the template function (in this case !InitialCondition or !BoundaryCondition. 145 145 146 146 {{{ … … 190 190 }}} 191 191 192 A second option is to loop over the cells ourselves 192 === Manually Looping Over Zones === 193 193 194 194 … … 248 248 * Also note that all of our checks like (ivy /= 0) make our module "dimension safe" so it can run in 1D, 2D, or 3D and that it could run with an isothermal or ideal EOS. 249 249 250 251 252 Now let's say we want to be able to adjust the density of the clump, the radius of the clump, and the wind velocity at run-time. To do this we need to declare three variables within our module.. 253 254 {{{ 255 MODULE Problem 256 USE GlobalDeclarations 257 USE PhysicsDeclarations 258 USE DataDeclarations 259 IMPLICIT NONE 260 SAVE 261 PUBLIC ProblemModuleInit, ProblemGridInit, ProblemBeforeStep, & 262 ProblemAfterStep, ProblemSetErrFlag, ProblemBeforeGlobalStep 263 PRIVATE 264 REAL(KIND=qPREC) :: rho, radius, velocity 265 266 CONTAINS 267 268 SUBROUTINE ProblemModuleInit() 269 NAMELIST/ProblemData/ rho, radius, velocity 270 OPEN(UNIT=PROBLEM_DATA_HANDLE, FILE='problem.data', STATUS="OLD") 271 READ(PROBLEM_DATA_HANDLE,NML=ProblemData) 272 CLOSE(PROBLEM_DATA_HANDLE) 273 END SUBROUTINE 274 275 SUBROUTINE ProblemGridInit(Info) 276 TYPE(InfoDef) :: Info 277 INTEGER :: i,j,k 278 REAL(KIND=xPREC) :: pos(3) 279 280 ! Initialize background 281 Info%q(1:Info%mX(1),1:Info%mX(2),1:Info%mX(3), 1)=1d0 282 Info%q(1:Info%mX(1),1:Info%mX(2),1:Info%mX(3), ivx)=0d0 283 IF (ivy /= 0) Info%q(1:Info%mX(1),1:Info%mX(2),1:Info%mX(3), ivy)=0d0 284 IF (ivz /= 0) Info%q(1:Info%mX(1),1:Info%mX(2),1:Info%mX(3), ivz)=0d0 285 IF (iE /= 0) Info%q(1:Info%mX(1),1:Info%mX(2),1:Info%mX(3), iE)=gamma7 286 287 ! Increase density for points inside of clump 288 DO i=1, Info%mX(1) 289 DO j=1, Info%mX(2) 290 DO k=1, Info%mX(3) 291 pos=CellPos(Info, i, j, k) 292 IF (sqrt(sum(pos**2)) < radius) THEN 293 Info%q(i,j,k,irho) = rho 294 END IF 295 END DO 296 END DO 297 END DO 298 END SUBROUTINE 299 300 SUBROUTINE ProblemBeforeStep(Info) 301 TYPE(InfoDef) :: Info 302 INTEGER :: i,j,k, mbc(3) 303 REAL(KIND=xPREC) :: pos(3) 304 305 !determine number of ghost zones for each dimension 306 mbc=levels(Info%level)%gmbc(levels(Info%level)%step)*merge((/1,1,1/),(/0,0,0/),nDim>=(/1,2,3/)) 307 308 ! Initialize wind in leftmost boundary 309 DO i=1-mbc(1), Info%mX(1)+mbc(1) 310 DO j=1-mbc(2), Info%mX(2)+mbc(2) 311 DO k=1-mbc(3), Info%mX(3)+mbc(3) 312 pos=CellPos(Info, i, j, k) 313 IF (pos(1) < GxBounds(1,1)) THEN 314 Info%q(i,j,k,irho) = 1d0 315 Info%q(i,j,k,ivx)=velocity 316 IF (iE /= 0) Info%q(i,j,k, iE)=gamma7+half*velocity**2 317 IF (ivy /= 0) Info%q(i,j,k, ivy)=0d0 318 IF (ivz /= 0) Info%q(i,j,k, ivz)=0d0 319 END IF 320 END DO 321 END DO 322 END DO 323 END SUBROUTINE 324 325 SUBROUTINE ProblemAfterStep(Info) 326 TYPE(InfoDef) :: Info 327 END SUBROUTINE ProblemAfterStep 328 329 SUBROUTINE ProblemSetErrFlag(Info) 330 TYPE(InfoDef) :: Info 331 END SUBROUTINE ProblemSetErrFlag 332 333 SUBROUTINE ProblemBeforeGlobalStep(n) 334 INTEGER :: n 335 END SUBROUTINE ProblemBeforeGlobalStep 336 337 END MODULE 338 339 }}} 250 === Using Prebuilt Objects === 251 340 252 341 253 There are a lot of other ways we could modify this simple example to have the clump be located anywhere, to have a density profile that is smoothed at the edge, to be a different temperature, or move with a particular velocity, etc... Fortunately, clumps are a commonly used object (as are uniform backgrounds and winds) and there are modules designed to assist users in easily creating clumps, uniform backgrounds, and winds. For example the above module could be rewritten using an [AmbientObjects Ambient Object], a [ClumpObjects Clump Object], and a [WindObjects Wind Object]. … … 353 265 ProblemAfterStep, ProblemSetErrFlag, ProblemBeforeGlobalStep 354 266 PRIVATE 355 REAL(KIND=qPREC) :: rho, radius, velocity 267 REAL(KIND=qPREC) :: rhoAmb, Tamb, rhoClump, RClump, rhoWind, TWind, vWind 268 REAL(KIND=qPREC) :: pWind, pClump, pAmb 356 269 357 270 CONTAINS … … 366 279 CLOSE(PROBLEM_DATA_HANDLE) 367 280 281 rhoAmb = rhoAmb / rScale 282 rhoClump = rhoClump / rScale 283 rhoWind = rhoWind / rScale 284 TAmb = TAmb / TempScale 285 TWind = TWind / TempScale 286 RClump = RClump / lScale 287 vWind = vWind / velScale 288 289 pAmb = rhoAmb * TAmb 290 pWind = rhoWind * TWind 291 pClump = pAmb 368 292 369 293 CALL CreateAmbient(Ambient) 294 Ambient%density = rhoAmb 295 Ambient%pressure = pAmb 296 CALL UpdateAmbient(Ambient) 370 297 371 298 CALL CreateClump(Clump) 372 Clump%density=rho 373 Clump%radius=radius 299 Clump%density = rhoClump 300 Clump%radius = RClump 301 Clump%pressure = pClump 374 302 CALL UpdateClump(Clump) 375 303 376 304 CALL CreateWind(Wind) 377 Wind%velocity=velocity 305 Wind%density = rhoWind 306 Wind%velocity = vWind 307 Wind%temperature = TWind 308 Wind%direction = 1 309 Wind%edge = 1 378 310 CALL UpdateWind(Wind) 379 311 … … 416 348 {{{ 417 349 &ProblemData 418 rho = 10.0 419 radius = 1.0 420 velocity = 10.0 350 rhoAmb = 1.0 351 TAmb = 1.0 352 rhoClump = 10.0 353 rClump = 1.0 354 rhoWind = 1.0 355 TWind = 1.0 356 vWind = 10.0 421 357 / 422 358 }}}