u/erica/CoreCollapseBlog: problem.f90_mar15

File problem.f90_mar15, 5.9 KB (added by Erica Kaminski, 7 years ago)
Line 
1!#########################################################################
2!
3! Copyright (C) 2003-2012 Department of Physics and Astronomy,
4! University of Rochester,
5! Rochester, NY
6!
7! problem.f90 of module HydroStaticStar is part of AstroBEAR.
8!
9! AstroBEAR is free software: you can redistribute it and/or modify
10! it under the terms of the GNU General Public License as published by
11! the Free Software Foundation, either version 3 of the License, or
12! (at your option) any later version.
13!
14! AstroBEAR is distributed in the hope that it will be useful,
15! but WITHOUT ANY WARRANTY; without even the implied warranty of
16! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17! GNU General Public License for more details.
18!
19! You should have received a copy of the GNU General Public License
20! along with AstroBEAR. If not, see <http://www.gnu.org/licenses/>.
21!
22!#########################################################################
23!> @dir HydroStaticStar
24!! @brief Contains files necessary for the Hydrostatic Equilibrium calculations
25
26!> @file problem.f90
27!! @brief Main file for module Problem
28MODULE Problem
29 USE DataDeclarations
30 USE Ambients
31 !USE PointGravitySrc
32 !USE ParticleDeclarations !n
33 USE Clumps
34 USE Profiles
35 USE ProfileFunctions
36 USE Winds
37 IMPLICIT NONE
38 SAVE
39
40 PUBLIC ProblemModuleInit, ProblemGridInit, &
41 ProblemBeforeStep, ProblemAfterStep, ProblemSetErrFlag, ProblemBeforeGlobalStep
42
43CONTAINS
44
45 !> Initializes module variables
46 SUBROUTINE ProblemModuleInit()
47
48 TYPE(AmbientDef), POINTER :: Ambient
49 TYPE(WindDef), POINTER :: Wind
50 TYPE(ClumpDef), POINTER :: Clump
51 INTEGER :: edge
52 INTEGER :: i, nEntries !soft_function
53 REAL(KIND=qPREC), DIMENSION(3) :: xloc=(/0,0,0/), velocity= (/0,0,0/)
54 REAL(KIND=qPREC) :: rhoOut, pOut, tempOut, vxOut, vyOut, vzOut, BxOut, ByOut, BzOut, r_cutoff
55
56
57 NAMELIST /ClumpData/ xloc, velocity!, soft_radius, soft_function!, mass
58 NAMELIST /AmbientData/ rhoOut, pOut, tempOut, vxOut, vyOut, vzOut, BxOut, ByOut, BzOut
59
60 OPEN(UNIT=PROBLEM_DATA_HANDLE, FILE='problem.data', STATUS="OLD")
61 READ(PROBLEM_DATA_HANDLE,NML=AmbientData)
62 CALL CreateAmbient(Ambient)
63 Ambient%density=rhoOut/rscale
64 !Ambient%density=.1
65 !Ambient%pressure=10
66 Ambient%pressure=pOut/pscale
67 Ambient%PersistInBoundaries=.true.
68 CALL UpdateAmbient(Ambient)
69
70 READ(PROBLEM_DATA_HANDLE,NML=ClumpData)
71 CALL CreateClump(Clump)
72 Clump%position=xloc
73 Clump%velocity=velocity
74 !Clump%density=1 these things are set using the profile object
75 !Clump%temperature=1 ""
76 Clump%thickness=0d0
77 Clump%subsample=1
78
79 CLOSE(PROBLEM_DATA_HANDLE)
80
81 OPEN (UNIT=PROBLEM_DATA_HANDLE, FILE='progenitor_profiles.dat', STATUS="OLD", POSITION='REWIND')
82! PRINT *, 'OPENED FILE OKAY'
83 READ (PROBLEM_DATA_HANDLE, *) nEntries
84 ! PRINT *, 'nEntries=', nEntries
85 READ (PROBLEM_DATA_HANDLE, *) !Skip the header column
86 CALL CreateProfile(Clump%Profile, nEntries, (/Mass_Field, P_Field/), RADIAL) !Mass field - is gas density
87 DO i=1,nEntries
88 READ(PROBLEM_DATA_HANDLE, *) Clump%profile%data(i,:) ! position, density, pressure in cgs
89 ! PRINT *, 'CLUMP%PROFILE%DATA(I,1)=radius (cm)', 'CLUMP%PROFILE%DATA(I,2)=density (g/cc)', 'CLUMP%PROFILE%DATA(I,3)=press(dyn/cc)'
90 ! PRINT *, CLUMP%PROFILE%DATA(I,1), CLUMP%PROFILE%DATA(I,2), CLUMP%PROFILE%DATA(I,3)
91 Clump%profile%data(i,:)=Clump%profile%data(i,:) / (/lScale, rScale, pScale/) !rescale to cu
92 ! PRINT *, 'CLUMP%PROFILE%DATA(I,1)=radius (cu)', 'CLUMP%PROFILE%DATA(I,2)=density (cu)', 'CLUMP%PROFILE%DATA(I,3)=press(cu)'
93 ! PRINT *, CLUMP%PROFILE%DATA(I,1), CLUMP%PROFILE%DATA(I,2), CLUMP%PROFILE%DATA(I,3)
94 END DO
95 CLOSE(PROBLEM_DATA_HANDLE)
96
97
98 OPEN(UNIT=PROBLEM_DATA_HANDLE, FILE='profile_init.out')
99 WRITE(PROBLEM_DATA_HANDLE,'(3E25.15)') (/(clump%profile%data(i,:)*(/lscale, rScale, pScale/), i=1,nEntries)/)
100 CLOSE(PROBLEM_DATA_HANDLE)
101
102 pOut=pOut/pscale
103
104 CALL Profile_SelfGravityHSE_Outside(Clump%Profile, pOut) !Use scaled ambient pressure from profile data file to recalculate pressure profile in HSE
105 CALL UpdateProfile(Clump%Profile) !don't think this is actually needed -- subroutine is a stub in the code and data values are updated in prev func
106
107 OPEN(UNIT=PROBLEM_DATA_HANDLE, FILE='profile.out')
108 WRITE(PROBLEM_DATA_HANDLE,'(3E25.15)') (/(clump%profile%data(i,:)*(/lscale, rScale, pScale/), i=1,nEntries)/)
109 CLOSE(PROBLEM_DATA_HANDLE)
110
111 r_cutoff=Clump%profile%data(nEntries,1)
112 Clump%radius=r_cutoff
113 print *, 'clump%radius=', clump%radius, 'clump%radius (cm)=', clump%radius*lscale
114 CALL UpdateClump(Clump)
115
116 DO i=1,nDim
117 DO edge=1,2
118 IF (Gmthbc(i,edge) == 1) THEN
119 CALL CreateWind(Wind)
120 Wind%density=rhoOut
121 wind%temperature=tempOut
122 wind%type=OUTFLOW_ONLY
123 Wind%dir=i
124 Wind%edge=edge
125 END IF
126 END DO
127 END DO
128
129 END SUBROUTINE ProblemModuleInit
130
131 !> Applies initial conditions
132 !! @param Info Info object
133 SUBROUTINE ProblemGridInit(Info)
134 TYPE(InfoDef) :: Info
135 END SUBROUTINE ProblemGridInit
136
137 !> Applies Boundary conditions
138 !! @param Info Info object
139 SUBROUTINE ProblemBeforeStep(Info)
140 TYPE(InfoDef) :: Info
141 END SUBROUTINE ProblemBeforeStep
142
143 !> Could be used to update grids pre-output
144 !! @param Info Info Object
145 SUBROUTINE ProblemAfterStep(Info)
146 TYPE(InfoDef) :: Info
147 END SUBROUTINE ProblemAfterStep
148
149 !> Could be used to set force refinement
150 !! @param Info Info object
151 SUBROUTINE ProblemSetErrFlag(Info)
152 TYPE(InfoDef) :: Info
153 INTEGER :: i,j,k
154 Info%ErrFlag(:,:,:)=1 ! refines over entire grid
155 END SUBROUTINE ProblemSetErrFlag
156
157 SUBROUTINE ProblemBeforeGlobalStep(n)
158 INTEGER :: n
159 END SUBROUTINE ProblemBeforeGlobalStep
160
161END MODULE Problem
162