sources_base.f90
Go to the documentation of this file.
1 !#############################################################################
2 !# #
3 !# fosite - 3D hydrodynamical simulation program #
4 !# module: sources_generic.f90 #
5 !# #
6 !# Copyright (C) 2007-2019 #
7 !# Tobias Illenseer <tillense@astrophysik.uni-kiel.de> #
8 !# Björn Sperling <sperling@astrophysik.uni-kiel.de> #
9 !# #
10 !# This program is free software; you can redistribute it and/or modify #
11 !# it under the terms of the GNU General Public License as published by #
12 !# the Free Software Foundation; either version 2 of the License, or (at #
13 !# your option) any later version. #
14 !# #
15 !# This program is distributed in the hope that it will be useful, but #
16 !# WITHOUT ANY WARRANTY; without even the implied warranty of #
17 !# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or #
18 !# NON INFRINGEMENT. See the GNU General Public License for more #
19 !# details. #
20 !# #
21 !# You should have received a copy of the GNU General Public License #
22 !# along with this program; if not, write to the Free Software #
23 !# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
24 !# #
25 !#############################################################################
26 !----------------------------------------------------------------------------!
33 !----------------------------------------------------------------------------!
41 !----------------------------------------------------------------------------!
44  USE mesh_base_mod
46  USE marray_base_mod
49  USE fluxes_base_mod
50  USE common_dict
51 #if defined(HAVE_FFTW)
52  USE fftw
53 #endif
54  IMPLICIT NONE
55  !--------------------------------------------------------------------------!
56  PRIVATE
57  TYPE, ABSTRACT, EXTENDS(logging_base) :: sources_base
59  CLASS(sources_base), POINTER :: next => null()
60  REAL :: time
61  REAL :: cvis
62  REAL :: gparam
63  LOGICAL :: update_disk_height
64  TYPE(marray_base) :: invheight2
65  TYPE(marray_base) :: height
66  TYPE(marray_base) :: h_ext
67  TYPE(marray_base) :: pot
68  REAL, DIMENSION(:,:,:), POINTER :: invr
69  INTEGER :: use_envelope
70 
71  CONTAINS
72 
73  PROCEDURE :: initsources
74  procedure(infosources), DEFERRED :: infosources
75  PROCEDURE :: externalsources
76  procedure(externalsources_single), DEFERRED :: externalsources_single
77  PROCEDURE :: calctimestep
78  procedure(calctimestep_single), DEFERRED :: calctimestep_single
79  PROCEDURE :: getsourcespointer
80  procedure(finalize), DEFERRED :: finalize
81  PROCEDURE :: finalize_base
82  END TYPE sources_base
83  abstract INTERFACE
84  SUBROUTINE infosources(this,Mesh)
86  IMPLICIT NONE
87  !------------------------------------------------------------------------!
88  CLASS(Sources_base),INTENT(IN) :: this
89  CLASS(Mesh_base),INTENT(IN) :: Mesh
90  END SUBROUTINE
91  SUBROUTINE calctimestep_single(this,Mesh,Physics,Fluxes,pvar,cvar,time,dt)
93  IMPLICIT NONE
94  !------------------------------------------------------------------------!
95  CLASS(sources_base),INTENT(INOUT) :: this
96  CLASS(mesh_base),INTENT(IN) :: Mesh
97  CLASS(physics_base),INTENT(INOUT) :: Physics
98  CLASS(fluxes_base),INTENT(IN) :: Fluxes
99  CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar
100  REAL,INTENT(IN) :: time
101  REAL, INTENT(OUT) :: dt
102  END SUBROUTINE
103  SUBROUTINE externalsources_single(this,Mesh,Physics,Fluxes,Sources,time,dt,pvar,cvar,sterm)
105  IMPLICIT NONE
106  !------------------------------------------------------------------------!
107  CLASS(sources_base),INTENT(INOUT) :: this
108  CLASS(mesh_base),INTENT(IN) :: Mesh
109  CLASS(physics_base),INTENT(INOUT) :: Physics
110  CLASS(sources_base), INTENT(INOUT) :: Sources
111  CLASS(fluxes_base),INTENT(IN) :: Fluxes
112  REAL,INTENT(IN) :: time, dt
113  CLASS(marray_compound),INTENT(INOUT):: pvar,cvar,sterm
114  END SUBROUTINE
115  SUBROUTINE finalize(this)
117  IMPLICIT NONE
118  !------------------------------------------------------------------------!
119  CLASS(sources_base),INTENT(INOUT) :: this
120  END SUBROUTINE
121  END INTERFACE
122  ! tempory storage for source terms
123  CLASS(marray_compound), POINTER, SAVE :: temp_sterm => null()
124  ! flags for source terms
125  INTEGER, PARAMETER :: gravity = 1
126 ! INTEGER, PARAMETER :: DISK_THOMSON = 2
127  INTEGER, PARAMETER :: viscosity = 3
128  INTEGER, PARAMETER :: c_accel = 4
129 ! INTEGER, PARAMETER :: COOLING = 5
130  INTEGER, PARAMETER :: rotating_frame = 20
131 ! INTEGER, PARAMETER :: SGS = 23
132  INTEGER, PARAMETER :: disk_cooling = 24
133 ! INTEGER, PARAMETER :: WAVE_DAMPING = 25
134 ! INTEGER, PARAMETER :: FORCING = 26
135 ! INTEGER, PARAMETER :: PLANET_HEATING = 27
136 ! INTEGER, PARAMETER :: PLANET_COOLING = 28
137 ! INTEGER, PARAMETER :: STELLAR_HEATING = 29
138  INTEGER, PARAMETER :: shearbox = 30
139  !--------------------------------------------------------------------------!
140  PUBLIC :: &
141  ! types
142  sources_base, &
143  ! constants
145  !--------------------------------------------------------------------------!
146 
147 CONTAINS
148 
150  SUBROUTINE initsources(this,Mesh,Fluxes,Physics,config,IO)
151  IMPLICIT NONE
152  !------------------------------------------------------------------------!
153  CLASS(sources_base), INTENT(IN) :: this
154  CLASS(mesh_base), INTENT(IN) :: Mesh
155  CLASS(fluxes_base), INTENT(IN) :: Fluxes
156  CLASS(physics_base), INTENT(IN) :: Physics
157  TYPE(Dict_TYP), POINTER :: config, IO
158  !------------------------------------------------------------------------!
159  CALL physics%new_statevector(temp_sterm,conservative)
160 
161  CALL this%Info(" SOURCES--> source term: " // this%GetName())
162  CALL this%InfoSources(mesh)
163  END SUBROUTINE initsources
164 
165 
166  SUBROUTINE externalsources(this,Mesh,Fluxes,Physics,time,dt,pvar,cvar,sterm)
167  IMPLICIT NONE
168  !------------------------------------------------------------------------!
169  CLASS(sources_base), TARGET, INTENT(INOUT) :: this
170  CLASS(mesh_base), INTENT(IN) :: Mesh
171  CLASS(fluxes_base), INTENT(IN) :: Fluxes
172  CLASS(physics_base), INTENT(INOUT) :: Physics
173  REAL, INTENT(IN) :: time,dt
174  CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar,sterm
175  !------------------------------------------------------------------------!
176  CLASS(Sources_base), POINTER :: srcptr
177  !------------------------------------------------------------------------!
178  ! reset sterm
179  sterm%data1d(:) = 0.0
180  ! go through all source terms in the list
181  srcptr => this
182  DO WHILE (ASSOCIATED(srcptr))
183 
184  CALL srcptr%ExternalSources_single(mesh,physics,fluxes,this,time,dt,pvar,cvar,temp_sterm)
185 
186  ! add to the sources
187  sterm%data1d(:) = sterm%data1d(:) + temp_sterm%data1d(:)
188 
189  ! next source term
190  srcptr => srcptr%next
191 
192  END DO
193  ! reset ghost cell data
194  IF (mesh%GINUM.GT.0) THEN
195  sterm%data4d(mesh%IGMIN:mesh%IMIN-mesh%IP1,:,:,:) = 0.0
196  sterm%data4d(mesh%IMAX+mesh%IP1:mesh%IGMAX,:,:,:) = 0.0
197  END IF
198  IF (mesh%GJNUM.GT.0) THEN
199  sterm%data4d(:,mesh%JGMIN:mesh%JMIN-mesh%JP1,:,:) = 0.0
200  sterm%data4d(:,mesh%JMAX+mesh%JP1:mesh%JGMAX,:,:) = 0.0
201  END IF
202  IF (mesh%GKNUM.GT.0) THEN
203  sterm%data4d(:,:,mesh%KGMIN:mesh%KMIN-mesh%KP1,:) = 0.0
204  sterm%data4d(:,:,mesh%KMAX+mesh%KP1:mesh%KGMAX,:) = 0.0
205  END IF
206  END SUBROUTINE externalsources
207 
208 
209  SUBROUTINE calctimestep(this,Mesh,Physics,Fluxes,pvar,cvar,time,dt,dtcause)
210  IMPLICIT NONE
211  !------------------------------------------------------------------------!
212  CLASS(sources_base), TARGET, INTENT(IN) :: this
213  CLASS(mesh_base), INTENT(IN) :: Mesh
214  CLASS(physics_base), INTENT(INOUT) :: Physics
215  CLASS(fluxes_base), INTENT(IN) :: Fluxes
216  CLASS(marray_compound), INTENT(INOUT) :: pvar,cvar
217  REAL, INTENT(IN) :: time
218  REAL, INTENT(OUT) :: dt
219  INTEGER, INTENT(OUT) :: dtcause
220  !------------------------------------------------------------------------!
221  CLASS(Sources_base), POINTER :: srcptr
222  REAL :: dt_new
223  !------------------------------------------------------------------------!
224  dt_new = dt
225 
226  ! go through all source terms in the list
227  srcptr => this
228  DO WHILE(ASSOCIATED(srcptr))
229 
230  CALL srcptr%CalcTimestep_single(mesh,physics,fluxes,pvar,cvar,time,dt_new)
231 
232 
233  IF (dt_new .LT. dt) dtcause=srcptr%GetType()
234  dt = min(dt,dt_new)
235  ! next source term
236  srcptr => srcptr%next
237  END DO
238  END SUBROUTINE calctimestep
239 
241  FUNCTION getsourcespointer(list,stype) RESULT(sp)
242  IMPLICIT NONE
243  !------------------------------------------------------------------------!
244  CLASS(sources_base), TARGET, INTENT(IN) :: list
245  CLASS(sources_base), POINTER :: sp
246  INTEGER, INTENT(IN) :: stype
247  !------------------------------------------------------------------------!
248  sp => list
249  DO
250  IF (ASSOCIATED(sp).EQV..false.) EXIT
251 !CDIR IEXPAND
252  IF (sp%GetType().EQ.stype) RETURN
253  sp => sp%next
254  END DO
255  END FUNCTION getsourcespointer
256 
258  SUBROUTINE finalize_base(this)
259  IMPLICIT NONE
260  !------------------------------------------------------------------------!
261  CLASS(sources_base), INTENT(INOUT) :: this
262  !------------------------------------------------------------------------!
263  IF (.NOT.this%Initialized()) &
264  CALL this%Error("sources_base::Finalize_base","not initialized")
265 
266  IF(ASSOCIATED(temp_sterm)) THEN
267  IF (ASSOCIATED(temp_sterm%data1d)) CALL temp_sterm%Destroy()
268  DEALLOCATE(temp_sterm)
269  NULLIFY(temp_sterm)
270  END IF
271  END SUBROUTINE finalize_base
272 
273 END MODULE sources_base_mod
integer, parameter, public disk_cooling
subroutine finalize(this)
Destructor of common class.
subroutine calctimestep(this, Mesh, Physics, Fluxes, pvar, cvar, time, dt, dtcause)
class(marray_compound), pointer, save temp_sterm
generic source terms module providing functionaly common to all source terms
derived class for compound of mesh arrays
base class for mesh arrays
Definition: marray_base.f90:36
Basic fosite module.
common data structure
fftw module
Definition: fftw.f90:29
integer, parameter, public rotating_frame
generic gravity terms module providing functionaly common to all gravity terms
subroutine initsources(this, Mesh, Fluxes, Physics, config, IO)
Initialize data in sources.
integer, parameter, public gravity
subroutine finalize_base(this)
Destructor.
basic mesh array class
Definition: marray_base.f90:64
integer, parameter, public viscosity
named integer constants for flavour of state vectors
class(sources_base) function, pointer getsourcespointer(list, stype)
Basic physics module.
Dictionary for generic data types.
Definition: common_dict.f90:61
subroutine externalsources(this, Mesh, Fluxes, Physics, time, dt, pvar, cvar, sterm)
integer, parameter, public shearbox
base module for numerical flux functions
Definition: fluxes_base.f90:39
integer, parameter, public c_accel