| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2016 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
! |
| 24 |
! This module handles all of the settings relating to the exact solution |
| 25 |
! plotting and calls the appropriate routines to change these settings and |
| 26 |
! plot the actual solutions. |
| 27 |
! |
| 28 |
! The only thing to do with exact solutions that is not entirely handled |
| 29 |
! by this module is the toy star AC plane solution (because |
| 30 |
! it is called under different circumstances to the other solutions). |
| 31 |
! |
| 32 |
module exact |
| 33 |
use params, only:maxplot |
| 34 |
implicit none |
| 35 |
! |
| 36 |
!--maximum number of solutions in any one plot |
| 37 |
! |
| 38 |
integer, parameter :: maxexact=32 |
| 39 |
integer, parameter :: maxlabels = maxplot |
| 40 |
character(len=30) :: exact_labels(maxlabels) |
| 41 |
! |
| 42 |
!--options used to plot the exact solution line |
| 43 |
! |
| 44 |
integer :: maxexactpts, iExactLineColour(maxexact), iExactLineStyle(maxexact),iPlotExactOnlyOnPanel |
| 45 |
integer :: iNormaliseErrors |
| 46 |
logical :: iApplyTransExactFile,iCalculateExactErrors,iPlotResiduals |
| 47 |
logical :: iApplyUnitsExactFile,iPlotExactUnder |
| 48 |
real :: fracinsetResiduals,residualmax,ExactAlpha |
| 49 |
character(len=60) :: ExactLegendText(maxexact) |
| 50 |
! |
| 51 |
!--declare all of the parameters required for the various exact solutions |
| 52 |
! |
| 53 |
!--toy star |
| 54 |
integer :: iACplane ! label position of toy star AC plane plot |
| 55 |
integer :: norder,morder ! for toy star |
| 56 |
real, public :: atstar,ctstar,sigma |
| 57 |
real :: htstar,alphatstar,betatstar,ctstar1,ctstar2 |
| 58 |
real :: sigma0,totmass |
| 59 |
!--sound wave |
| 60 |
integer :: iwaveploty,iwaveplotx ! linear wave |
| 61 |
real :: ampl,lambda,period,xzero |
| 62 |
!--sedov blast wave |
| 63 |
real :: rhosedov,esedov |
| 64 |
!--polytrope |
| 65 |
real :: polyk |
| 66 |
!--mhd shock solutions |
| 67 |
integer :: ishk |
| 68 |
real :: xshock |
| 69 |
!--density profiles |
| 70 |
integer :: iprofile,icolpoten,icolfgrav |
| 71 |
real, dimension(2) :: Msphere,rsoft |
| 72 |
!--from file |
| 73 |
integer :: iexactplotx(maxexact), iexactploty(maxexact) |
| 74 |
logical :: iauto_map_columns |
| 75 |
!--shock tube |
| 76 |
real :: rho_L, rho_R, pr_L, pr_R, v_L, v_R |
| 77 |
!--rho vs h |
| 78 |
real :: hfact |
| 79 |
!--read from file |
| 80 |
integer :: imapexact(maxlabels),nfiles |
| 81 |
character(len=120) :: filename_exact(maxexact) |
| 82 |
!--equilibrium torus |
| 83 |
real :: Mstar,Rtorus,distortion |
| 84 |
!--ring spreading |
| 85 |
real :: Mring,Rring,viscnu |
| 86 |
!--dusty waves |
| 87 |
real :: cs,Kdrag,rhozero,rdust_to_gas |
| 88 |
!--arbitrary function |
| 89 |
integer :: nfunc |
| 90 |
character(len=120), dimension(maxexact) :: funcstring |
| 91 |
!--Roche potential |
| 92 |
real :: mprim,msec |
| 93 |
real :: xprim(3),xsec(3) |
| 94 |
logical :: use_sink_data |
| 95 |
integer, parameter :: iexact_rochelobe = 15 |
| 96 |
!--C-shock |
| 97 |
real :: machs,macha |
| 98 |
!--planet-disc interaction |
| 99 |
real :: HonR,rplanet,q_index,phase |
| 100 |
real :: spiral_params(7,maxexact) |
| 101 |
integer :: ispiral,narms |
| 102 |
logical :: iread_wakeparams,iclockwise,inonlin |
| 103 |
!--bondi flow |
| 104 |
logical :: relativistic, geodesic_flow,is_wind |
| 105 |
real :: const1,const2 |
| 106 |
!--gamma, for manual setting |
| 107 |
real :: gamma_exact,gamma2_exact |
| 108 |
logical :: use_gamma_exact,use_gamma2_exact |
| 109 |
! |
| 110 |
!--sort these into a namelist for input/output |
| 111 |
! |
| 112 |
namelist /exactopts/ iexactplotx,iexactploty,filename_exact,maxexactpts, & |
| 113 |
iExactLineColour,iExactLineStyle,iApplyTransExactFile,iCalculateExactErrors, & |
| 114 |
iPlotResiduals,fracinsetResiduals,residualmax,iPlotExactOnlyOnPanel,& |
| 115 |
iApplyUnitsExactFile,iNormaliseErrors,iPlotExactUnder,ExactAlpha |
| 116 |
|
| 117 |
namelist /exactparams/ ampl,lambda,period,iwaveploty,iwaveplotx,xzero, & |
| 118 |
htstar,atstar,ctstar,alphatstar,betatstar,ctstar1,ctstar2, & |
| 119 |
polyk,sigma0,norder,morder,rhosedov,esedov, & |
| 120 |
rho_L, rho_R, pr_L, pr_R, v_L, v_R,ishk,hfact, & |
| 121 |
iprofile,Msphere,rsoft,icolpoten,icolfgrav,Mstar,Rtorus,distortion, & |
| 122 |
Mring,Rring,viscnu,nfunc,funcstring,cs,Kdrag,rhozero,rdust_to_gas, & |
| 123 |
mprim,msec,imapexact,iauto_map_columns,xshock,totmass,machs,macha,& |
| 124 |
use_sink_data,xprim,xsec,nfiles,& |
| 125 |
gamma_exact,gamma2_exact,use_gamma_exact,use_gamma2_exact,& |
| 126 |
HonR,rplanet,q_index,relativistic,geodesic_flow,is_wind,& |
| 127 |
const1,const2,ispiral,narms,spiral_params,phase,& |
| 128 |
iread_wakeparams,iclockwise,inonlin |
| 129 |
|
| 130 |
public :: defaults_set_exact,submenu_exact,options_exact,read_exactparams |
| 131 |
public :: exact_solution,get_nexact |
| 132 |
public :: exactopts,exactparams |
| 133 |
public :: exact_set_rocheparam |
| 134 |
|
| 135 |
contains |
| 136 |
!---------------------------------------------------------------------- |
| 137 |
! sets default values of the exact solution parameters |
| 138 |
!---------------------------------------------------------------------- |
| 139 |
subroutine defaults_set_exact |
| 140 |
use plotlib, only:plotlib_maxlinestyle |
| 141 |
integer :: i |
| 142 |
|
| 143 |
lambda = 1.0 ! sound wave exact solution : wavelength |
| 144 |
ampl = 0.005 ! sound wave exact solution : amplitude |
| 145 |
period = 1.0 |
| 146 |
iwaveploty = 7 |
| 147 |
iwaveplotx = 1 |
| 148 |
xzero = 0. |
| 149 |
htstar = 1. ! toy star crap |
| 150 |
atstar = 1. |
| 151 |
ctstar = 1. |
| 152 |
alphatstar = 0. |
| 153 |
betatstar = 0. |
| 154 |
ctstar1 = 0. |
| 155 |
ctstar2 = 0. |
| 156 |
totmass = 1. |
| 157 |
norder = -1 |
| 158 |
morder = 0 |
| 159 |
sigma0 = 0. |
| 160 |
rhosedov = 1.0 ! sedov blast wave |
| 161 |
esedov = 1.0 ! blast wave energy |
| 162 |
polyk = 1.0 ! polytropic k |
| 163 |
! shock tube (default is sod problem) |
| 164 |
rho_L = 1.0 |
| 165 |
rho_R = 0.125 |
| 166 |
pr_L = 1.0 |
| 167 |
pr_R = 0.1 |
| 168 |
v_L = 0.0 |
| 169 |
v_R = 0.0 |
| 170 |
ishk = 1 |
| 171 |
xshock = 0. |
| 172 |
hfact = 1.2 |
| 173 |
! read from file |
| 174 |
nfiles = 1 |
| 175 |
filename_exact = ' ' |
| 176 |
imapexact = 0 |
| 177 |
iauto_map_columns = .true. |
| 178 |
iexactplotx = 0 |
| 179 |
iexactploty = 0 |
| 180 |
! density profile parameters |
| 181 |
iprofile = 1 |
| 182 |
rsoft(1) = 1.0 |
| 183 |
rsoft(2) = 0.1 |
| 184 |
Msphere(1) = 1.0 |
| 185 |
Msphere(2) = 0.0 |
| 186 |
icolpoten = 0 |
| 187 |
icolfgrav = 0 |
| 188 |
! equilibrium torus |
| 189 |
Mstar = 1.0 |
| 190 |
Rtorus = 1.0 |
| 191 |
distortion = 1.1 |
| 192 |
! ring spreading |
| 193 |
Mring = 1.0 |
| 194 |
Rring = 1.0 |
| 195 |
viscnu = 1.e-3 |
| 196 |
! dusty waves |
| 197 |
Kdrag = 1.0 |
| 198 |
cs = 1.0 |
| 199 |
rhozero = 1.0 |
| 200 |
rdust_to_gas = 0.0 |
| 201 |
! Roche lobes |
| 202 |
use_sink_data = .true. |
| 203 |
mprim = 1. |
| 204 |
msec = 1. |
| 205 |
xprim = 0. |
| 206 |
xsec = 0. |
| 207 |
xsec(1) = 1. |
| 208 |
! C-shock |
| 209 |
machs = 50. ! sonic Mach number |
| 210 |
macha = 5. ! Alfvenic Mach number |
| 211 |
! planet-disc interaction |
| 212 |
HonR = 0.05 |
| 213 |
rplanet = 1. |
| 214 |
q_index = 0.25 |
| 215 |
ispiral = 1 |
| 216 |
narms = 1 |
| 217 |
phase = 0. |
| 218 |
spiral_params = 0. |
| 219 |
spiral_params(2,:) = 360. |
| 220 |
iread_wakeparams = .true. |
| 221 |
iclockwise = .false. |
| 222 |
inonlin = .false. |
| 223 |
! Bondi |
| 224 |
relativistic = .true. |
| 225 |
geodesic_flow = .false. |
| 226 |
is_wind = .true. |
| 227 |
const1 = 8. |
| 228 |
const2 = 1. |
| 229 |
|
| 230 |
! gamma, if not read from file |
| 231 |
gamma_exact = 5./3. |
| 232 |
gamma2_exact = 1. |
| 233 |
use_gamma_exact = .false. |
| 234 |
use_gamma2_exact = .false. |
| 235 |
|
| 236 |
! arbitrary function |
| 237 |
nfunc = 1 |
| 238 |
funcstring = ' ' |
| 239 |
|
| 240 |
maxexactpts = 1001 ! points in exact solution plot |
| 241 |
iExactLineColour = 1 ! foreground |
| 242 |
do i=1,size(iExactLineStyle) |
| 243 |
iExactLineStyle(i) = mod(i,plotlib_maxlinestyle) |
| 244 |
enddo |
| 245 |
iApplyTransExactFile = .true. ! false if exact from file is already logged |
| 246 |
iApplyUnitsExactFile = .false. |
| 247 |
iCalculateExactErrors = .true. |
| 248 |
iNormaliseErrors = 1 |
| 249 |
iPlotResiduals = .false. |
| 250 |
fracinsetResiduals = 0.15 |
| 251 |
residualmax = 0.0 |
| 252 |
iPlotExactOnlyOnPanel = 0 |
| 253 |
iPlotExactUnder = .false. |
| 254 |
ExactLegendText = '' |
| 255 |
ExactAlpha = 1.0 |
| 256 |
|
| 257 |
end subroutine defaults_set_exact |
| 258 |
|
| 259 |
!---------------------------------------------------------------------- |
| 260 |
! sets which exact solution to calculate + parameters for this |
| 261 |
!---------------------------------------------------------------------- |
| 262 |
subroutine submenu_exact(iexact) |
| 263 |
use settings_data, only:ndim,ncolumns,ncalc |
| 264 |
use prompting, only:prompt,print_logical |
| 265 |
use filenames, only:rootname,ifileopen,fileprefix |
| 266 |
use exactfunction, only:check_function |
| 267 |
use mhdshock, only:nmhdshocksolns,mhdprob |
| 268 |
use planetdisc, only:maxspirals,labelspiral |
| 269 |
use asciiutils, only:get_ncolumns,get_nrows,string_replace,match_tag_start,& |
| 270 |
add_escape_chars,read_asciifile,read_column_labels |
| 271 |
use labels, only:label |
| 272 |
use map_columns, only:map_columns_in_file,map_columns_interactive,print_mapping |
| 273 |
integer, intent(inout) :: iexact |
| 274 |
integer :: ierr,itry,i,ncols,nadjust,nrows,nlab_exact |
| 275 |
integer, allocatable :: imapauto(:) |
| 276 |
logical :: ians,iexist,ltmp,prompt_for_gamma,apply_to_all |
| 277 |
character(len=len(filename_exact)) :: filename_tmp |
| 278 |
character(len=4) :: str |
| 279 |
character(len=len(funcstring)) :: func_prev |
| 280 |
|
| 281 |
print 10 |
| 282 |
10 format(' 0) none ',/, & |
| 283 |
' 1) ANY function f(x,t)',/, & |
| 284 |
' 2) read from file ',/, & |
| 285 |
' 3) shock tube ',/, & |
| 286 |
' 4) sedov blast wave ',/, & |
| 287 |
' 5) polytrope ',/, & |
| 288 |
' 6) toy star ',/, & |
| 289 |
' 7) gresho vortex ',/, & |
| 290 |
' 8) mhd shock tubes (tabulated) ',/, & |
| 291 |
' 9) h vs rho ',/, & |
| 292 |
'10) Plummer/Hernquist spheres ',/, & |
| 293 |
'11) torus ',/, & |
| 294 |
'12) ring spreading ',/, & |
| 295 |
'13) special relativistic shock tube', /, & |
| 296 |
'14) dusty waves', /, & |
| 297 |
'15) Roche lobes/potential ',/, & |
| 298 |
'16) C-shock ',/, & |
| 299 |
'17) Spiral arms (planet-disc interaction)',/, & |
| 300 |
'18) Bondi flow') |
| 301 |
call prompt('enter exact solution to plot',iexact,0,18) |
| 302 |
print "(a,i2)",'plotting exact solution number ',iexact |
| 303 |
! |
| 304 |
!--enter parameters for various exact solutions |
| 305 |
! |
| 306 |
prompt_for_gamma = .false. |
| 307 |
apply_to_all = .true. |
| 308 |
select case(iexact) |
| 309 |
case(1) |
| 310 |
call prompt('enter number of functions to plot ',nfunc,1,maxexact) |
| 311 |
print "(/,a,6(/,11x,a))",' Examples: sin(2*pi*x - 0.1*t)','sqrt(0.5*x)','x^2', & |
| 312 |
'exp(-2*x**2 + 0.1*t)','log10(x/2)','exp(y),y=sin(pi*x)','cos(z/y),z=acos(y),y=x^2' |
| 313 |
ierr = 0 |
| 314 |
overfunc: do i=1,nfunc |
| 315 |
ierr = 1 |
| 316 |
itry = 0 |
| 317 |
func_prev = funcstring(i) |
| 318 |
do while(ierr /= 0 .and. itry < 10) |
| 319 |
if (nfunc > 1) print "(/,a,i2,/,11('-'),/)",'Function ',i |
| 320 |
call prompt('enter function f(x,t) to plot ',funcstring(i),noblank=.true.) |
| 321 |
call check_function(funcstring(i),ierr) |
| 322 |
if (ierr /= 0 .and. len(funcstring(i))==len_trim(funcstring(i))) then |
| 323 |
print "(a,i3,a)",& |
| 324 |
' (errors are probably because string is too long, max length = ',& |
| 325 |
len(funcstring(i)),')' |
| 326 |
endif |
| 327 |
itry = itry + 1 |
| 328 |
enddo |
| 329 |
if (itry >= 10) then |
| 330 |
print "(a)",' *** too many tries, aborting ***' |
| 331 |
ierr = i-1 |
| 332 |
exit overfunc |
| 333 |
endif |
| 334 |
print* |
| 335 |
call prompt('enter y axis of exact solution (0=all plots)',iexactploty(i),0) |
| 336 |
if (iexactploty(i) > 0) then |
| 337 |
call prompt('enter x axis of exact solution ',iexactplotx(i),1) |
| 338 |
endif |
| 339 |
if (len_trim(ExactLegendText(i))==0 .or. trim(funcstring(i)) /= trim(func_prev)) then |
| 340 |
ExactLegendText(i) = trim(funcstring(i)) |
| 341 |
endif |
| 342 |
call prompt('enter text to display in legend (blank=do not show)',ExactLegendText(i)) |
| 343 |
enddo overfunc |
| 344 |
if (ierr /= 0) nfunc = ierr |
| 345 |
case(2) |
| 346 |
! |
| 347 |
! try to read filenames from .exactfiles if it exists |
| 348 |
! |
| 349 |
call read_exactparams(iexact,trim(rootname(1)),ierr) |
| 350 |
! |
| 351 |
! then prompt user |
| 352 |
! |
| 353 |
call prompt('enter number of files to read per plot ',nfiles,1,maxexact) |
| 354 |
if (ierr /= 0 .and. nfiles > 1) then |
| 355 |
print "(2(/,a))",' Hint: create a file called '//trim(fileprefix)//'.exactfiles', & |
| 356 |
' with one filename per line to automatically read the filenames' |
| 357 |
else |
| 358 |
print "(a,i2,a)",' got ',nfiles,' filenames from '//trim(fileprefix)//'.exactfiles' |
| 359 |
endif |
| 360 |
|
| 361 |
nadjust = -1 |
| 362 |
over_files: do i=1,nfiles |
| 363 |
iexist = .false. |
| 364 |
do while(.not.iexist) |
| 365 |
if (i==1) print "(/,a)",'Use %f to represent current dump file, e.g. %f.exact looks for dump_000.exact' |
| 366 |
write(str,"(i4)") i |
| 367 |
call prompt('enter filename #'//trim(adjustl(str)),filename_exact(i)) |
| 368 |
!--substitute %f for filename |
| 369 |
filename_tmp = filename_exact(i) |
| 370 |
call string_replace(filename_tmp,'%f',trim(rootname(ifileopen))) |
| 371 |
!--check the first file for errors |
| 372 |
inquire(file=filename_tmp,exist=iexist) |
| 373 |
if (iexist) then |
| 374 |
allocate(imapauto(size(imapexact))) |
| 375 |
imapauto = 0 |
| 376 |
call map_columns_in_file(filename_tmp,ncols,nrows,imapauto,& |
| 377 |
label(1:ncolumns+ncalc),exact_labels,nlab_exact,ierr) |
| 378 |
if (ierr==0) then |
| 379 |
! if more than two columns mapped successfully, prompt to keep this automatic |
| 380 |
if (all(imapexact==0)) imapexact = imapauto |
| 381 |
! manual assignment of column mappings |
| 382 |
call map_columns_interactive(imapexact,label(1:ncolumns+ncalc),& |
| 383 |
exact_labels,nlab_exact) |
| 384 |
! disable automated mapping if edits were made |
| 385 |
if (any(imapexact(1:nlab_exact) /= imapauto(1:nlab_exact))) iauto_map_columns = .false. |
| 386 |
print "(a)",' automated mapping is '//print_logical(iauto_map_columns) |
| 387 |
|
| 388 |
if (nrows > maxexactpts) maxexactpts = nrows |
| 389 |
if (count(imapexact > 0) < 2) print "(/,a,/)",' WARNING: not enough columns mapped to plot anything' |
| 390 |
! re-prompt if there are less than two useable columns in the file |
| 391 |
if (ncols < 2) then |
| 392 |
iexist = .false. |
| 393 |
call prompt('Error: file contains < 2 readable columns: try again?',ians) |
| 394 |
if (.not.ians) then |
| 395 |
nadjust = i-1 |
| 396 |
exit over_files |
| 397 |
endif |
| 398 |
endif |
| 399 |
else |
| 400 |
iexist = .false. |
| 401 |
call prompt('Error opening '//trim(filename_tmp)//': try again?',ians) |
| 402 |
if (.not.ians) then |
| 403 |
nadjust = i-1 |
| 404 |
exit over_files |
| 405 |
endif |
| 406 |
endif |
| 407 |
if (allocated(imapauto)) deallocate(imapauto) |
| 408 |
else |
| 409 |
ians = .true. |
| 410 |
call prompt('file does not exist: try again? ',ians) |
| 411 |
if (.not.ians) then |
| 412 |
nadjust = i-1 |
| 413 |
exit over_files |
| 414 |
endif |
| 415 |
endif |
| 416 |
enddo |
| 417 |
!if (i==1) then |
| 418 |
! call prompt('Apply above settings to all files?',apply_to_all) |
| 419 |
! if (apply_to_all) then |
| 420 |
! iexactploty(:) = iexactploty(i) |
| 421 |
! iexactplotx(:) = iexactplotx(i) |
| 422 |
! endif |
| 423 |
!endif |
| 424 |
|
| 425 |
if (len_trim(ExactLegendText(i))==0) ExactLegendText(i) = add_escape_chars(filename_exact(i)) |
| 426 |
!call prompt('enter text to display in legend (blank=do not show)',ExactLegendText(i)) |
| 427 |
enddo over_files |
| 428 |
if (nadjust >= 0) then |
| 429 |
nfiles = nadjust |
| 430 |
if (nfiles == 1) then |
| 431 |
print "(/,a)",'Using 1 file only' |
| 432 |
elseif (nfiles > 0) then |
| 433 |
write(str,"(i4)") nfiles |
| 434 |
print "(/,a)",'Using '//trim(adjustl(str))//' files' |
| 435 |
endif |
| 436 |
endif |
| 437 |
if (nfiles > 0) then ! only ask if filename was read OK |
| 438 |
ltmp = .not.iApplyTransExactFile |
| 439 |
if (.not.any(exact_labels(:)(1:3) == 'log')) then |
| 440 |
call prompt(' are exact solutions already logged?',ltmp) |
| 441 |
endif |
| 442 |
iApplyTransExactFile = .not.ltmp |
| 443 |
ltmp = .not.iApplyUnitsExactFile |
| 444 |
call prompt(' are exact solutions in physical units?',ltmp) |
| 445 |
iApplyUnitsExactFile = .not.ltmp |
| 446 |
endif |
| 447 |
case(3,13) |
| 448 |
! |
| 449 |
!--read shock parameters from the .shk file |
| 450 |
! |
| 451 |
call read_exactparams(iexact,trim(rootname(1)),ierr) |
| 452 |
if (ierr /= 0) then |
| 453 |
call prompt('enter initial x position of shock',xshock) |
| 454 |
call prompt('enter density to left of shock ',rho_L,0.0) |
| 455 |
call prompt('enter density to right of shock ',rho_R,0.0) |
| 456 |
call prompt('enter pressure to left of shock ',pr_L,0.0) |
| 457 |
call prompt('enter pressure to right of shock ',pr_R,0.0) |
| 458 |
if (iexact==13) then |
| 459 |
call prompt('enter velocity to left of shock ',v_L,max=1.0) |
| 460 |
call prompt('enter velocity to right of shock ',v_R,max=1.0) |
| 461 |
else |
| 462 |
call prompt('enter velocity to left of shock ',v_L) |
| 463 |
call prompt('enter velocity to right of shock ',v_R) |
| 464 |
call prompt('enter dust-to-gas ratio ',rdust_to_gas,0.) |
| 465 |
endif |
| 466 |
endif |
| 467 |
prompt_for_gamma = .true. |
| 468 |
case(4) |
| 469 |
call prompt('enter density of ambient medium ',rhosedov,0.0) |
| 470 |
call prompt('enter blast wave energy E ',esedov,0.0) |
| 471 |
prompt_for_gamma = .true. |
| 472 |
case(5) |
| 473 |
call prompt('enter polytropic k ',polyk) |
| 474 |
call prompt('enter total mass ',totmass) |
| 475 |
prompt_for_gamma = .true. |
| 476 |
case(6) |
| 477 |
print "(a)",' toy star: ' |
| 478 |
call read_exactparams(iexact,trim(rootname(1)),ierr) |
| 479 |
call prompt('enter polytropic k ',polyk) |
| 480 |
call prompt('enter total mass ',totmass) |
| 481 |
call prompt('enter central density rho_0 (rho = rho_0 - cr^2)',htstar) |
| 482 |
call prompt('enter parameter c (rho = rho_0 - cr^2)',ctstar,0.0) |
| 483 |
sigma = 0. |
| 484 |
call prompt('enter parameter sigma (By = sigma*rho)',sigma0) |
| 485 |
sigma = sigma0 |
| 486 |
ians = .false. |
| 487 |
call prompt('linear oscillations?',ians) |
| 488 |
if (ians) then |
| 489 |
call prompt('enter order of radial mode',norder,0) |
| 490 |
if (ndim >= 2) call prompt('enter order of angular mode',morder,0) |
| 491 |
call prompt('enter velocity amplitude a (v = a*r) ',atstar) |
| 492 |
else |
| 493 |
print "(a)",'using exact non-linear solution:' |
| 494 |
ians = .true. |
| 495 |
if (norder < 0 .and. morder < 0) ians = .false. |
| 496 |
if (ndim >= 2) call prompt('axisymmetric?',ians) |
| 497 |
if (ians .or. ndim==1) then |
| 498 |
norder = -1 |
| 499 |
morder = 0 |
| 500 |
call prompt('enter v_r amplitude ',alphatstar) |
| 501 |
if (ndim >= 2) call prompt('enter v_phi amplitude ',betatstar) |
| 502 |
else |
| 503 |
norder = -1 |
| 504 |
morder = -1 |
| 505 |
call prompt('enter vxx amplitude ',alphatstar) |
| 506 |
call prompt('enter vyy amplitude ',betatstar) |
| 507 |
call prompt('enter vxy amplitude ',ctstar1) |
| 508 |
call prompt('enter vyx amplitude ',ctstar2) |
| 509 |
endif |
| 510 |
endif |
| 511 |
prompt_for_gamma = .true. |
| 512 |
!case(7) |
| 513 |
! call prompt('enter y-plot to place sine wave on',iwaveploty,1) |
| 514 |
! call prompt('enter x-plot to place sine wave on',iwaveplotx,1) |
| 515 |
! call prompt('enter starting x position',xzero) |
| 516 |
! call prompt('enter wavelength lambda ',lambda,0.0) |
| 517 |
! call prompt('enter amplitude ',ampl,0.0) |
| 518 |
! call prompt('enter period ',period) |
| 519 |
case(8) |
| 520 |
print "(a)",' MHD shock tube tables: ' |
| 521 |
if (ishk <= 0) ishk = 1 |
| 522 |
do i=1,nmhdshocksolns |
| 523 |
print "(i2,') ',a)",i,trim(mhdprob(i)) |
| 524 |
enddo |
| 525 |
call prompt('enter solution to plot ',ishk,1,7) |
| 526 |
call prompt('enter initial x position of shock ',xshock) |
| 527 |
case(9) |
| 528 |
call prompt('enter hfact [h = hfact*(m/rho)**1/ndim]',hfact,0.) |
| 529 |
case(10) |
| 530 |
print 20 |
| 531 |
20 format(' 1) Plummer sphere [ rho = 3M r_s**2 /(4 pi (r**2 + r_s**2)**5/2) ]',/, & |
| 532 |
' 2) Hernquist model [ rho = M r_s /(2 pi r (r_s + r)**3 ]') |
| 533 |
call prompt('enter density profile to plot',iprofile,1,2) |
| 534 |
call prompt('enter total mass of sphere M',Msphere(1),0.) |
| 535 |
call prompt('enter scale length length r_s,',rsoft(1),0.) |
| 536 |
ians = .false. |
| 537 |
if (icolpoten > 0) ians = .true. |
| 538 |
call prompt('Are the gravitational potential and/or force dumped?',ians) |
| 539 |
if (ians) then |
| 540 |
call prompt('enter column containing grav. potential',icolpoten,0) |
| 541 |
call prompt('enter column containing grav. force',icolfgrav,0) |
| 542 |
endif |
| 543 |
call prompt('enter mass of 2nd component',Msphere(2),0.) |
| 544 |
call prompt('enter scale length r_s for 2nd component,',rsoft(2),0.) |
| 545 |
case(11) |
| 546 |
call prompt('enter mass of central object',Mstar,0.) |
| 547 |
call prompt('enter radius of torus centre',Rtorus,0.) |
| 548 |
call prompt('enter distortion parameter ',distortion,1.,2.) |
| 549 |
if (abs(polyk-1.0) < tiny(polyk)) polyk = 0.0764 |
| 550 |
call prompt('enter K in P= K*rho^gamma',polyk,0.) |
| 551 |
prompt_for_gamma = .true. |
| 552 |
case(12) |
| 553 |
call prompt('enter mass of ring',Mring,0.) |
| 554 |
call prompt('enter radius of ring centre R0',Rring,0.) |
| 555 |
call prompt('enter viscosity parameter nu',viscnu,0.) |
| 556 |
case(14) |
| 557 |
call prompt('enter starting x position',xzero) |
| 558 |
call prompt('enter wavelength lambda ',lambda,0.) |
| 559 |
call prompt('enter amplitude of perturbation',ampl,0.) |
| 560 |
call prompt('enter sound speed in gas ',cs,0.) |
| 561 |
call prompt('enter initial gas density ',rhozero,0.) |
| 562 |
call prompt('enter dust-to-gas ratio ',rdust_to_gas,0.) |
| 563 |
call prompt('enter drag coefficient K ',Kdrag,0.) |
| 564 |
case(15) |
| 565 |
call prompt('use data from sink particles?',use_sink_data) |
| 566 |
if (.not.use_sink_data) then |
| 567 |
call prompt('enter mass of primary star ',mprim,0.) |
| 568 |
call prompt('enter mass of secondary star ',msec,0.,mprim) |
| 569 |
call prompt('enter x position of primary',xprim(1)) |
| 570 |
call prompt('enter y position of primary',xprim(2)) |
| 571 |
call prompt('enter x position of secondary',xsec(1)) |
| 572 |
call prompt('enter y position of secondary',xsec(2)) |
| 573 |
endif |
| 574 |
case(16) |
| 575 |
call prompt('enter sonic Mach number',machs,0.) |
| 576 |
call prompt('enter Alfvenic Mach number ',macha,0.) |
| 577 |
case(17) |
| 578 |
do i=1,maxspirals |
| 579 |
print "(1x,i1,')',1x,a)",i,trim(labelspiral(i)) |
| 580 |
enddo |
| 581 |
call prompt('Which spiral arm solution to plot?',ispiral,0,maxspirals) |
| 582 |
select case(ispiral) |
| 583 |
case(2) |
| 584 |
call prompt('enter number of spiral arms to plot',narms,1,maxexact) |
| 585 |
print "(3(/,a),/)",' Spiral data can be read from '//trim(fileprefix)//'.spirals file', & |
| 586 |
' with one line per arm and columns corresponding to:', & |
| 587 |
' PAmin, PAmax, a0, a1, a2, a3, a4' |
| 588 |
do i=1,narms |
| 589 |
print "(a,i1,a)",' -- arm ',i,' --' |
| 590 |
call prompt('enter starting position angle (deg)',spiral_params(1,i)) |
| 591 |
call prompt('enter finishing position angle (deg)',spiral_params(2,i)) |
| 592 |
call prompt('enter a0 in r = \sum a_i phi^i',spiral_params(3,i)) |
| 593 |
call prompt('enter a1 in r = \sum a_i phi^i',spiral_params(4,i)) |
| 594 |
call prompt('enter a2 in r = \sum a_i phi^i',spiral_params(5,i)) |
| 595 |
call prompt('enter a3 in r = \sum a_i phi^i',spiral_params(6,i)) |
| 596 |
call prompt('enter a4 in r = \sum a_i phi^i',spiral_params(7,i)) |
| 597 |
enddo |
| 598 |
case default |
| 599 |
if (ifileopen > 0) call get_planetdisc_parameters_from_data(rplanet,HonR,q_index,phase,ierr) |
| 600 |
if (ierr == 0) call prompt(' use wake parameters above?',iread_wakeparams) |
| 601 |
if (ierr /= 0) iread_wakeparams = .false. |
| 602 |
if (.not.iread_wakeparams) then |
| 603 |
call prompt('enter disc aspect ratio at planet location (H/R)',HonR,0.,1.) |
| 604 |
call prompt('enter planet orbital radius ',rplanet,0.) |
| 605 |
call prompt('enter power-law index of sound speed cs ~ R^-q',q_index) |
| 606 |
call prompt('enter orbital phase in degrees ',phase) |
| 607 |
call prompt('clockwise rotation?',iclockwise) |
| 608 |
endif |
| 609 |
call prompt('apply non-linear corrections from Rafikov?',inonlin) |
| 610 |
end select |
| 611 |
case(18) |
| 612 |
prompt_for_gamma = .true. |
| 613 |
call prompt('is it a wind (instead of accretion)?',is_wind) |
| 614 |
call prompt('enter mass of central object',Mstar,0.) |
| 615 |
call prompt('do you want a relativistic solution?',relativistic) |
| 616 |
if (.not.relativistic) then |
| 617 |
prompt_for_gamma = .false. |
| 618 |
call prompt('enter Parker/Bondi critical radius (rcrit)',const1) |
| 619 |
call prompt('enter density at critical radius (rhocrit)',const2) |
| 620 |
elseif (relativistic) then |
| 621 |
call prompt('is it the geodesic flow?',geodesic_flow) |
| 622 |
if (geodesic_flow) then |
| 623 |
const1 = 1. |
| 624 |
const2 = 1.e-9 |
| 625 |
call prompt('enter constant den0',const1,min=0.) |
| 626 |
call prompt('enter constant en0 ',const2,min=0.) |
| 627 |
else |
| 628 |
call prompt('enter the critical radius in units of the central mass M',const1,min=2.) |
| 629 |
const1 = const1*Mstar |
| 630 |
const2 = 1. |
| 631 |
call prompt('enter adiabat (entropy normalisation)',const2,min=0.) |
| 632 |
endif |
| 633 |
endif |
| 634 |
|
| 635 |
end select |
| 636 |
|
| 637 |
if (prompt_for_gamma) then |
| 638 |
call prompt('set adiabatic gamma manually? (no=read from dumps)',use_gamma_exact) |
| 639 |
if (use_gamma_exact) then |
| 640 |
call prompt('enter gamma',gamma_exact) |
| 641 |
endif |
| 642 |
if (iexact==3 .or. iexact==13) then |
| 643 |
call prompt('plot 2nd solution with different gamma?',use_gamma2_exact) |
| 644 |
if (use_gamma2_exact) then |
| 645 |
call prompt('enter gamma for the second solution',gamma2_exact) |
| 646 |
endif |
| 647 |
endif |
| 648 |
endif |
| 649 |
|
| 650 |
end subroutine submenu_exact |
| 651 |
|
| 652 |
!--------------------------------------------------- |
| 653 |
! return number of exact solutions being plotted |
| 654 |
!--------------------------------------------------- |
| 655 |
integer function get_nexact(iexact) result(nexact) |
| 656 |
integer, intent(in) :: iexact |
| 657 |
|
| 658 |
select case(iexact) |
| 659 |
case(2) |
| 660 |
nexact = nfiles |
| 661 |
case(1) |
| 662 |
nexact = nfunc |
| 663 |
case default |
| 664 |
nexact = 1 |
| 665 |
end select |
| 666 |
|
| 667 |
end function get_nexact |
| 668 |
|
| 669 |
!--------------------------------------------------- |
| 670 |
! sets options relating to exact solution plotting |
| 671 |
!--------------------------------------------------- |
| 672 |
subroutine options_exact(iexact) |
| 673 |
use prompting, only:prompt |
| 674 |
use plotlib, only:plotlib_maxlinestyle,plotlib_maxlinecolour |
| 675 |
integer, intent(in) :: iexact |
| 676 |
character(len=12) :: string |
| 677 |
integer :: nexact,i |
| 678 |
|
| 679 |
call prompt('enter number of exact solution points ',maxexactpts,10,1000000) |
| 680 |
nexact = get_nexact(iexact) |
| 681 |
string = '' |
| 682 |
do i=1,nexact |
| 683 |
if (nexact > 1) write(string,"(a,i2)") 'for line ',i |
| 684 |
call prompt('enter line colour '//trim(string),iExactLineColour(i),0,plotlib_maxlinecolour) |
| 685 |
enddo |
| 686 |
do i=1,nexact |
| 687 |
if (nexact > 1) write(string,"(a,i2)") 'for line ',i |
| 688 |
call prompt('enter line style '//trim(string),iExactLineStyle(i),1,plotlib_maxlinestyle) |
| 689 |
enddo |
| 690 |
call prompt('Plot exact solution under data (default is over)? ',iPlotExactUnder) |
| 691 |
call prompt('Enter opacity for exact solution lines',ExactAlpha,0.0,1.0) |
| 692 |
do i=1,nexact |
| 693 |
call prompt('enter text to display in legend (blank=do not show)',ExactLegendText(i)) |
| 694 |
enddo |
| 695 |
|
| 696 |
call prompt('calculate error norms?',iCalculateExactErrors) |
| 697 |
if (iCalculateExactErrors) then |
| 698 |
print "(/,' 0 : not normalised L1 = 1/N \sum |y - y_exact|',/,"// & |
| 699 |
"' 1 : normalised L1 = 1/N 1/max(y_exact) \sum |y - y_exact|')" |
| 700 |
call prompt('enter choice of error norm',iNormaliseErrors) |
| 701 |
endif |
| 702 |
if (iCalculateExactErrors) then |
| 703 |
call prompt('plot residuals (as inset in main plot)?',iPlotResiduals) |
| 704 |
if (iPlotResiduals) then |
| 705 |
call prompt('enter fraction of plot to use for inset', & |
| 706 |
fracinsetResiduals,0.1,0.9) |
| 707 |
call prompt('enter max residual (0 for adaptive)',residualmax,0.) |
| 708 |
endif |
| 709 |
endif |
| 710 |
print "(/,' 0 : plot exact solution (where available) on every panel ',/,"// & |
| 711 |
"' -1 : plot exact solution on first row only ',/,"// & |
| 712 |
"' -2 : plot exact solution on first column only ',/,"// & |
| 713 |
"' n : plot exact solution on nth panel only ')" |
| 714 |
|
| 715 |
call prompt('Enter selection ',iPlotExactOnlyOnPanel,-2) |
| 716 |
|
| 717 |
end subroutine options_exact |
| 718 |
|
| 719 |
!----------------------------------------------------------------------- |
| 720 |
! read exact solution parameters from files |
| 721 |
! (in ndspmhd these files are used in the input to the code) |
| 722 |
! |
| 723 |
! called after main data read and if exact solution chosen from menu |
| 724 |
!----------------------------------------------------------------------- |
| 725 |
subroutine read_exactparams(iexact,rootname,ierr) |
| 726 |
use settings_data, only:ndim,iverbose |
| 727 |
use prompting, only:prompt |
| 728 |
use exactfunction, only:check_function |
| 729 |
use filenames, only:fileprefix,ifileopen |
| 730 |
use asciiutils, only:read_asciifile,get_line_containing,read_var_from_file |
| 731 |
integer, intent(in) :: iexact |
| 732 |
character(len=*), intent(in) :: rootname |
| 733 |
integer, intent(out) :: ierr |
| 734 |
|
| 735 |
integer :: idash,nf,i,j,idrag,idum,linenum,k,ieq,ierrs(6),narmsread,nfiles_got |
| 736 |
character(len=len_trim(rootname)+8) :: filename |
| 737 |
character(len=120) :: line |
| 738 |
character(len=30) :: var |
| 739 |
logical :: iexist |
| 740 |
|
| 741 |
idash = index(rootname,'_',back=.true.) |
| 742 |
if (idash==0) idash = len_trim(rootname)+1 |
| 743 |
|
| 744 |
select case(iexact) |
| 745 |
case(1) |
| 746 |
! |
| 747 |
!--read functions from file |
| 748 |
! |
| 749 |
filename=trim(rootname)//'.func' |
| 750 |
call read_asciifile(trim(filename),nf,funcstring,ierr) |
| 751 |
if (ierr==-1) then |
| 752 |
if (iverbose > 0) write(*,"(a)",advance='no') ' no file '//trim(filename)//'; ' |
| 753 |
filename = trim(fileprefix)//'.func' |
| 754 |
call read_asciifile(trim(filename),nf,funcstring,ierr) |
| 755 |
if (ierr==-1) then |
| 756 |
if (iverbose > 0) print "(a)",' no file '//trim(filename) |
| 757 |
return |
| 758 |
endif |
| 759 |
endif |
| 760 |
|
| 761 |
if (nf > 0) then |
| 762 |
i = 0 |
| 763 |
do while(i < nf) |
| 764 |
i = i + 1 |
| 765 |
call check_function(funcstring(i),ierr,verbose=.false.) |
| 766 |
if (ierr /= 0) then |
| 767 |
print "(a)",' error parsing function '//trim(funcstring(i))//', skipping...' |
| 768 |
do j=i+1,nf |
| 769 |
funcstring(j-1) = funcstring(j) |
| 770 |
enddo |
| 771 |
funcstring(nf) = ' ' |
| 772 |
nf = nf - 1 |
| 773 |
i = i - 1 |
| 774 |
endif |
| 775 |
enddo |
| 776 |
nfunc = nf |
| 777 |
if (iverbose > 0) print "(a,i2,a)",' read ',nfunc,' functions from '//trim(filename) |
| 778 |
else |
| 779 |
print "(a)",' *** NO FUNCTIONS READ: none will be plotted ***' |
| 780 |
ierr = 2 |
| 781 |
endif |
| 782 |
case(2) |
| 783 |
filename = trim(fileprefix)//'.exactfiles' |
| 784 |
call read_asciifile(trim(filename),nfiles_got,filename_exact,ierr) |
| 785 |
if (ierr==-1 .and. nfiles_got <= 0 .and. len_trim(filename_exact(1))==0) then ! look in .setup file only if no filenames set |
| 786 |
if (iverbose > 1) print "(a)",' no file '//trim(filename) |
| 787 |
! |
| 788 |
! if no .exactfiles, see if the phantom .setup file exists |
| 789 |
! and have a look for "outputfilename" |
| 790 |
! |
| 791 |
filename = trim(rootname(1:idash-1))//'.setup' |
| 792 |
call read_var_from_file('outputfilename',filename_exact(1),filename,ierr) |
| 793 |
if (ierr == 0) then |
| 794 |
nfiles = 1 |
| 795 |
else |
| 796 |
! |
| 797 |
! failing this, have a look for a .profile file |
| 798 |
! |
| 799 |
filename = trim(rootname(1:idash-1))//'.profile' |
| 800 |
inquire(file=filename,exist=iexist) |
| 801 |
if (iexist) then |
| 802 |
filename_exact(1) = filename |
| 803 |
nfiles = 1 |
| 804 |
ierr = 0 |
| 805 |
else |
| 806 |
! |
| 807 |
! failing this, look for a trajectory file |
| 808 |
! |
| 809 |
nfiles = 0 |
| 810 |
do i=1,2 |
| 811 |
write(filename,"(a,i1)") trim(rootname(1:idash-1))//'.trajectory',i |
| 812 |
inquire(file=filename,exist=iexist) |
| 813 |
if (iexist) then |
| 814 |
nfiles = nfiles + 1 |
| 815 |
filename_exact(nfiles) = filename |
| 816 |
iExactLineStyle = 1 |
| 817 |
ExactAlpha = 0.5 |
| 818 |
ierr = 0 |
| 819 |
endif |
| 820 |
enddo |
| 821 |
endif |
| 822 |
endif |
| 823 |
return |
| 824 |
elseif (nfiles_got > 0) then |
| 825 |
nfiles = nfiles_got |
| 826 |
endif |
| 827 |
case(3,13) |
| 828 |
! |
| 829 |
!--shock tube parameters from .shk file |
| 830 |
! |
| 831 |
filename = trim(rootname(1:idash-1))//'.shk' |
| 832 |
inquire(file=filename,exist=iexist) |
| 833 |
if (iexist) then |
| 834 |
open(unit=19,file=filename,status='old',iostat=ierr) |
| 835 |
if (ierr==0) then |
| 836 |
read(19,*,iostat=ierrs(1)) rho_L, rho_R |
| 837 |
read(19,*,iostat=ierrs(2)) pr_L, pr_R |
| 838 |
read(19,*,iostat=ierrs(3)) v_L, v_R |
| 839 |
if (any(ierrs(1:3)/=0)) then |
| 840 |
print*,'error reading ',filename |
| 841 |
ierr = 1 |
| 842 |
endif |
| 843 |
endif |
| 844 |
close(unit=19) |
| 845 |
else |
| 846 |
print*,'no file ',filename |
| 847 |
! |
| 848 |
! look for .setup file for Phantom |
| 849 |
! |
| 850 |
filename= trim(rootname(1:idash-1))//'.setup' |
| 851 |
inquire(file=filename,exist=iexist) |
| 852 |
open(unit=19,file=filename,status='old',iostat=ierr) |
| 853 |
ierrs(:) = 0 |
| 854 |
do while(ierr==0) |
| 855 |
read(19,"(a)",iostat=ierr) line |
| 856 |
ieq = index(line,'=') |
| 857 |
if (ierr==0 .and. ieq > 1) then |
| 858 |
var = trim(adjustl(line(1:ieq-1))) |
| 859 |
select case(trim(var)) |
| 860 |
case('densleft') |
| 861 |
read(line(ieq+1:),*,iostat=ierrs(1)) rho_L |
| 862 |
case('densright') |
| 863 |
read(line(ieq+1:),*,iostat=ierrs(1)) rho_R |
| 864 |
case('prleft') |
| 865 |
read(line(ieq+1:),*,iostat=ierrs(1)) pr_L |
| 866 |
case('prright') |
| 867 |
read(line(ieq+1:),*,iostat=ierrs(1)) pr_R |
| 868 |
case('vxleft') |
| 869 |
read(line(ieq+1:),*,iostat=ierrs(1)) v_L |
| 870 |
case('vxright') |
| 871 |
read(line(ieq+1:),*,iostat=ierrs(1)) v_R |
| 872 |
case('dtg') |
| 873 |
read(line(ieq+1:),*,iostat=ierrs(1)) rdust_to_gas |
| 874 |
end select |
| 875 |
endif |
| 876 |
enddo |
| 877 |
ierr = 0 |
| 878 |
if (.not.iexist .or. any(ierrs(1:6)/=0)) ierr = 1 |
| 879 |
endif |
| 880 |
if (iexist) then |
| 881 |
print*,'>> read ',filename |
| 882 |
print*,' rhoL, rho_R = ',rho_L,rho_R |
| 883 |
print*,' pr_L, pr_R = ',pr_L, pr_R |
| 884 |
print*,' v_L, v_R = ',v_L, v_R |
| 885 |
endif |
| 886 |
|
| 887 |
|
| 888 |
case(6) |
| 889 |
! |
| 890 |
!--read toy star file for toy star solution |
| 891 |
! |
| 892 |
select case(ndim) |
| 893 |
case(1) |
| 894 |
filename = trim(rootname(1:idash-1))//'.tstar' |
| 895 |
open(unit=20,ERR=8801,FILE=filename,STATUS='old') |
| 896 |
read(20,*,ERR=8888) Htstar,Ctstar,Atstar |
| 897 |
read(20,*,ERR=8888) sigma0 |
| 898 |
read(20,*,ERR=8888) norder |
| 899 |
close(UNIT=20) |
| 900 |
print*,' >> read ',filename |
| 901 |
print*,' H,C,A,sigma,n = ',Htstar,Ctstar,Atstar,sigma0,norder |
| 902 |
return |
| 903 |
8801 continue |
| 904 |
print*,'no file ',filename |
| 905 |
ierr = 1 |
| 906 |
return |
| 907 |
8888 print*,'error reading ',filename |
| 908 |
close(UNIT=20) |
| 909 |
ierr = 2 |
| 910 |
return |
| 911 |
case(2) |
| 912 |
filename = trim(rootname(1:idash-1))//'.tstar2D' |
| 913 |
open(unit=20,ERR=9901,FILE=filename,STATUS='old') |
| 914 |
read(20,*,ERR=9902) Htstar,Ctstar,Atstar |
| 915 |
read(20,*,ERR=9902) alphatstar,betatstar,ctstar1,ctstar2 |
| 916 |
read(20,*,ERR=9902) norder,morder |
| 917 |
close(UNIT=20) |
| 918 |
print*,' >> read ',filename |
| 919 |
print*,' j,m = ',norder,morder |
| 920 |
print*,' rho_0 = ',Htstar,' - ',Ctstar,' r^2' |
| 921 |
if (norder >= 0 .and. morder >= 0) then |
| 922 |
print*,' v = ',Atstar,' r' |
| 923 |
else |
| 924 |
print*,' vx = ',alphatstar,'x +',ctstar1,'y' |
| 925 |
print*,' vy = ',ctstar2,'x +',betatstar,'y' |
| 926 |
endif |
| 927 |
return |
| 928 |
9901 continue |
| 929 |
print*,'no file ',filename |
| 930 |
ierr = 1 |
| 931 |
return |
| 932 |
9902 print*,'error reading ',filename |
| 933 |
close(UNIT=20) |
| 934 |
ierr = 2 |
| 935 |
return |
| 936 |
end select |
| 937 |
case(8) |
| 938 |
! |
| 939 |
!--attempt to guess which MHD shock tube has been done from filename |
| 940 |
! |
| 941 |
!read(rootname(5:5),*,iostat=ios) ishk |
| 942 |
!if (ios /= 0) ishk = 1 |
| 943 |
! |
| 944 |
!--prompt for shock type if not set |
| 945 |
! |
| 946 |
if (ishk <= 0) then ! prompt |
| 947 |
ishk = 1 |
| 948 |
call prompt('enter shock solution to plot',ishk,1,7) |
| 949 |
endif |
| 950 |
return |
| 951 |
case(14) |
| 952 |
! |
| 953 |
!--dustywave parameters from ndspmhd or Phantom input file |
| 954 |
! |
| 955 |
filename = trim(rootname(1:idash-1))//'.in' |
| 956 |
var = 'Kdrag' !ndspmhd |
| 957 |
linenum = get_line_containing(filename,trim(var)) |
| 958 |
if (linenum==0) then |
| 959 |
var = 'K_code' !phantom |
| 960 |
linenum = get_line_containing(filename,trim(var)) |
| 961 |
endif |
| 962 |
open(unit=19,file=filename,status='old',iostat=ierr) |
| 963 |
if (ierr==0) then |
| 964 |
do i=1,linenum-1 |
| 965 |
read(19,*,iostat=ierr) |
| 966 |
enddo |
| 967 |
read(19,"(a)",iostat=ierr) line |
| 968 |
if (ierr==0) then |
| 969 |
k = index(line,trim(var)) |
| 970 |
if (k > 0) read(line(k+len_trim(var)+2:),*,iostat=ierr) Kdrag |
| 971 |
if (ierr==0) then |
| 972 |
print*,'>> read '//trim(var)//' = ',Kdrag,' from '//trim(filename) |
| 973 |
else |
| 974 |
read(line,*,iostat=ierr) idrag, idum, idum, Kdrag |
| 975 |
if (ierr==0) then |
| 976 |
print*,'>> read '//trim(var)//' = ',Kdrag,' from old-style '//trim(filename) |
| 977 |
else |
| 978 |
print*,'>> error reading Kdrag from '//trim(filename) |
| 979 |
endif |
| 980 |
endif |
| 981 |
else |
| 982 |
print*,'>> error reading Kdrag from '//trim(filename) |
| 983 |
endif |
| 984 |
endif |
| 985 |
close(unit=19) |
| 986 |
return |
| 987 |
case(17) |
| 988 |
! |
| 989 |
!--spiral arm parameters from .spirals file |
| 990 |
! |
| 991 |
select case(ispiral) |
| 992 |
case(2) |
| 993 |
filename=trim(rootname)//'.spirals' |
| 994 |
narmsread = 0 |
| 995 |
call read_asciifile(trim(filename),narmsread,spiral_params,ierr) |
| 996 |
if (ierr==-1) then |
| 997 |
if (iverbose > 0) write(*,"(a)",advance='no') ' no file '//trim(filename)//'; ' |
| 998 |
filename = trim(fileprefix)//'.spirals' |
| 999 |
call read_asciifile(trim(filename),narmsread,spiral_params,ierr) |
| 1000 |
if (ierr==-1) then |
| 1001 |
if (iverbose > 0) print "(a)",' no file '//trim(filename) |
| 1002 |
else |
| 1003 |
if (iverbose > 0) print*,trim(filename)//' read ',narmsread,' arms, err = ',ierr |
| 1004 |
if (narmsread >= 0) narms = narmsread |
| 1005 |
endif |
| 1006 |
else |
| 1007 |
if (iverbose > 0) print*,trim(filename)//' read ',narmsread,' arms, err = ',ierr |
| 1008 |
narms = max(narmsread,0) |
| 1009 |
endif |
| 1010 |
case default |
| 1011 |
if (ifileopen > 0 .and. iread_wakeparams) call get_planetdisc_parameters_from_data(rplanet,HonR,q_index,phase,ierr) |
| 1012 |
end select |
| 1013 |
end select |
| 1014 |
|
| 1015 |
end subroutine read_exactparams |
| 1016 |
|
| 1017 |
!----------------------------------------------------------------------- |
| 1018 |
! subroutine to automatically extract parameters needed for |
| 1019 |
! planet wake exact solution from the data |
| 1020 |
!----------------------------------------------------------------------- |
| 1021 |
subroutine get_planetdisc_parameters_from_data(rp,HR,q,angle,ierr) |
| 1022 |
use physcon, only:pi |
| 1023 |
use filenames, only:ifileopen |
| 1024 |
use settings_data, only:ntypes,ndim,ndimV,ncolumns |
| 1025 |
use particle_data, only:headervals,dat,iamtype,npartoftype |
| 1026 |
use part_utils, only:locate_nth_particle_of_type,get_binary |
| 1027 |
use labels, only:get_sink_type,ix,ivx,ipmass,headertags |
| 1028 |
use asciiutils, only:get_value |
| 1029 |
use system_utils, only:ienvlist |
| 1030 |
real, intent(inout) :: rp,HR,q,angle |
| 1031 |
integer, intent(out) :: ierr |
| 1032 |
integer :: isinklist(2),isink1,isink2,itype,j,ntot |
| 1033 |
logical :: got_sinks |
| 1034 |
real :: x0(3),v0(3),domega,omega,polyk,cs |
| 1035 |
|
| 1036 |
! do nothing if there is no data |
| 1037 |
j = 1 ! use first data in memory |
| 1038 |
if (ifileopen <= 0) return |
| 1039 |
if (size(npartoftype(1,:)) < j) return |
| 1040 |
|
| 1041 |
! either use --wake to get which planet, or --corotate |
| 1042 |
isinklist = ienvlist('SPLASH_WAKE',2) |
| 1043 |
if (all(isinklist==0)) isinklist = ienvlist('SPLASH_COROTATE',2) |
| 1044 |
if (all(isinklist==0)) isinklist = (/1,2/) |
| 1045 |
|
| 1046 |
itype = get_sink_type(ntypes) |
| 1047 |
got_sinks = .false. |
| 1048 |
if (itype > 0) got_sinks = all(isinklist > 0) .and. (npartoftype(itype,j) > 0) |
| 1049 |
if (got_sinks .and. all(ix > 0)) then |
| 1050 |
call locate_nth_particle_of_type(isinklist(1),isink1,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 1051 |
call locate_nth_particle_of_type(isinklist(2),isink2,itype,iamtype(:,j),npartoftype(:,j),ntot) |
| 1052 |
call get_binary(isink1,isink2,dat(:,:,j),x0,v0,angle,domega,ndim,ndimV,ncolumns,ix,ivx,ipmass,0,ierr) |
| 1053 |
if (ierr /= 0) return |
| 1054 |
! phase angle for planet |
| 1055 |
angle = -angle*180./pi ! convert to degrees |
| 1056 |
! radial location of planet |
| 1057 |
rp = norm2(dat(isink2,ix(:),j) - x0) |
| 1058 |
! power law index of sound speed profile, if found in file header |
| 1059 |
q = get_value('qfacdisc',headertags,headervals(:,j)) |
| 1060 |
if (q <= 0.) q = q_index ! revert to previous value if not read |
| 1061 |
! disc scale height, convert to aspect ratio |
| 1062 |
polyk = 2./3.*get_value('RK2',headertags,headervals(:,j)) ! polytropic K |
| 1063 |
cs = sqrt(polyk*(rp**2)**(-q)) ! sound speed in code units |
| 1064 |
omega = sqrt(dat(isink1,ipmass,j)/rp**3) ! Keplerian speed |
| 1065 |
HR = (cs/omega)/rp ! pressure scale height |
| 1066 |
if (HR < 0.001 .or. HR > 0.5) HR = HonR ! do not grab stupid numbers |
| 1067 |
! report results |
| 1068 |
print "(4(a,g10.3))",' planet wake parameters: rp is ',rp,' phase is ',angle,' q is ',q,' HonR is ',HR |
| 1069 |
endif |
| 1070 |
|
| 1071 |
end subroutine get_planetdisc_parameters_from_data |
| 1072 |
|
| 1073 |
!----------------------------------------------------------------------- |
| 1074 |
! subroutine to set parameters needed for Roche lobe plotting |
| 1075 |
!----------------------------------------------------------------------- |
| 1076 |
subroutine exact_set_rocheparam(m1,m2,x1,y1,x2,y2) |
| 1077 |
real, intent(in) :: m1,m2,x1,y1,x2,y2 |
| 1078 |
|
| 1079 |
mprim = m1 |
| 1080 |
msec = m2 |
| 1081 |
xprim(1) = x1 |
| 1082 |
xprim(2) = y1 |
| 1083 |
xsec(1) = x2 |
| 1084 |
xsec(2) = y2 |
| 1085 |
|
| 1086 |
end subroutine exact_set_rocheparam |
| 1087 |
|
| 1088 |
!----------------------------------------------------------------------- |
| 1089 |
! this subroutine drives the exact solution plotting using the |
| 1090 |
! parameters which have been set |
| 1091 |
! |
| 1092 |
! acts as an interface between the main plotting loop and the |
| 1093 |
! exact solution calculation subroutines |
| 1094 |
! |
| 1095 |
! The exact solution is returned from the calculation via the arrays |
| 1096 |
! xexact and yexact. This means that the appropriate transformations |
| 1097 |
! can be applied (e.g. if the graph is logarithmic) and also ensures |
| 1098 |
! that the line style and colour settings are applied properly. |
| 1099 |
! |
| 1100 |
! Note that we attempt to space the solution evenly in the transformed |
| 1101 |
! space (ie. in the current plot window), but this can be overwritten |
| 1102 |
! in the subroutines (for example if an uneven sampling is desired or |
| 1103 |
! the plotting is via some similarity variable as in the Sedov solution). |
| 1104 |
! In these cases the resulting arrays are then transformed, possibly leading |
| 1105 |
! to poor sampling in some regions (e.g. an evenly spaced array will become |
| 1106 |
! highly uneven in logarithmic space). |
| 1107 |
! |
| 1108 |
! Note that any subroutine could in principle do its own plotting, |
| 1109 |
! provided that it returns ierr > 0 which means that the generic line |
| 1110 |
! is not plotted. Obviously transformations could not be applied in |
| 1111 |
! this case. |
| 1112 |
! |
| 1113 |
!----------------------------------------------------------------------- |
| 1114 |
|
| 1115 |
subroutine exact_solution(iexact,iplotx,iploty,itransx,itransy,igeom, & |
| 1116 |
ndim,ndimV,time,xmin,xmax,gamma,xplot,yplot,& |
| 1117 |
itag,iamtype,noftype,iplot_type, & |
| 1118 |
pmassmin,pmassmax,npart,imarker,unitsx,unitsy,irescale,iaxisy) |
| 1119 |
use params, only:int1,maxparttypes |
| 1120 |
use settings_data, only:ncolumns,ncalc |
| 1121 |
use labels, only:ix,irad,iBfirst,ivx,irho,ike,iutherm,ih,ipr,iJfirst,& |
| 1122 |
irhorestframe,is_coord,ideltav,idustfrac,label |
| 1123 |
use filenames, only:ifileopen,rootname |
| 1124 |
use asciiutils, only:string_replace,match_integer |
| 1125 |
use prompting, only:prompt |
| 1126 |
use exactfromfile, only:exact_fromfile |
| 1127 |
use mhdshock, only:exact_mhdshock |
| 1128 |
use polytrope, only:exact_polytrope |
| 1129 |
use rhoh, only:exact_rhoh |
| 1130 |
use sedov, only:exact_sedov |
| 1131 |
use shock, only:exact_shock |
| 1132 |
use shock_sr, only:exact_shock_sr |
| 1133 |
use torus, only:exact_torus |
| 1134 |
use toystar1D, only:exact_toystar1D !, exact_toystar_ACplane |
| 1135 |
use toystar2D, only:exact_toystar2D |
| 1136 |
use wave, only:exact_wave |
| 1137 |
use densityprofiles, only:exact_densityprofiles |
| 1138 |
use exactfunction, only:exact_function |
| 1139 |
use ringspread, only:exact_ringspread |
| 1140 |
use dustywaves, only:exact_dustywave |
| 1141 |
use rochelobe, only:exact_rochelobe |
| 1142 |
use gresho, only:exact_gresho |
| 1143 |
use Cshock, only:exact_Cshock |
| 1144 |
use planetdisc, only:exact_planetdisc |
| 1145 |
use bondi, only:exact_bondi |
| 1146 |
use transforms, only:transform,transform_inverse |
| 1147 |
use map_columns, only:map_columns_in_file |
| 1148 |
use plotlib, only:plot_qci,plot_qls,plot_sci,plot_sls,plot_line,plotlib_maxlinestyle,plot_set_opacity |
| 1149 |
integer, intent(in) :: iexact,iplotx,iploty,itransx,itransy,igeom |
| 1150 |
integer, intent(in) :: ndim,ndimV,npart,imarker,iaxisy |
| 1151 |
real, intent(in) :: time,xmin,xmax,gamma,unitsx,unitsy |
| 1152 |
real, intent(in) :: pmassmin,pmassmax |
| 1153 |
real, intent(in) :: xplot(npart),yplot(npart) |
| 1154 |
integer, intent(in) :: itag(npart) |
| 1155 |
integer(int1), intent(in) :: iamtype(:) |
| 1156 |
integer, intent(in) :: noftype(maxparttypes) |
| 1157 |
logical, intent(in) :: iplot_type(maxparttypes) |
| 1158 |
logical, intent(in) :: irescale |
| 1159 |
integer :: mytransx,mytransy,imapx,imapy |
| 1160 |
|
| 1161 |
real, parameter :: zero = 1.e-10 |
| 1162 |
integer :: i,ierr,iexactpts,iCurrentColour,iCurrentLineStyle,LineStyle |
| 1163 |
integer :: ncols,nrows,nlab_exact,nsh |
| 1164 |
real, allocatable :: xexact(:),yexact(:),xtemp(:) |
| 1165 |
real :: dx,timei,gammai |
| 1166 |
character(len=len(filename_exact)) :: filename_tmp |
| 1167 |
|
| 1168 |
! |
| 1169 |
!--change line style and colour settings, but save old ones |
| 1170 |
! |
| 1171 |
call plot_qci(iCurrentColour) |
| 1172 |
call plot_qls(iCurrentLineStyle) |
| 1173 |
call plot_sci(iExactLineColour(1)) |
| 1174 |
call plot_sls(iExactLineStyle(1)) |
| 1175 |
call plot_set_opacity(ExactAlpha) |
| 1176 |
! |
| 1177 |
!--get exact solution parameters from code input files, if present |
| 1178 |
! |
| 1179 |
if (ifileopen > 0) call read_exactparams(iexact,rootname(ifileopen),ierr) |
| 1180 |
! |
| 1181 |
!--allocate memory |
| 1182 |
! |
| 1183 |
allocate(xexact(maxexactpts),yexact(maxexactpts),xtemp(maxexactpts),stat=ierr) |
| 1184 |
if (ierr /= 0) then |
| 1185 |
print "(a)",'*** ERROR allocating memory for exact solution plotting, skipping ***' |
| 1186 |
if (allocated(xexact)) deallocate(xexact) |
| 1187 |
if (allocated(yexact)) deallocate(yexact) |
| 1188 |
if (allocated(xtemp)) deallocate(xtemp) |
| 1189 |
return |
| 1190 |
endif |
| 1191 |
|
| 1192 |
! |
| 1193 |
!--set x axis (can be overwritten) |
| 1194 |
! Need to space x in transformed space (e.g. in log space) |
| 1195 |
! but send the values of x in *real* space to the calculation routines |
| 1196 |
! then need to plot x in transformed space |
| 1197 |
! |
| 1198 |
! Best solution is to set x grid initially, and inverse transform to get x values. |
| 1199 |
! These values can then be overwritten, if required in the exact subroutines |
| 1200 |
! We then re-transform the x array to plot it, which means that if spacing is |
| 1201 |
! overwritten the resulting array can still be transformed into log space |
| 1202 |
! but spacing will not be even |
| 1203 |
! |
| 1204 |
|
| 1205 |
!--note that xmin and xmax will already have been transformed prior to input |
| 1206 |
! as these were the limits used for plotting the particles |
| 1207 |
! |
| 1208 |
dx = (xmax - xmin)/real(maxexactpts) |
| 1209 |
do i=1,maxexactpts |
| 1210 |
xexact(i) = xmin + (i-1)*dx |
| 1211 |
enddo |
| 1212 |
xtemp = xexact |
| 1213 |
if (itransx > 0) call transform_inverse(xexact,itransx) |
| 1214 |
|
| 1215 |
iexactpts = maxexactpts |
| 1216 |
! |
| 1217 |
!--exact solution plots must return a zero or negative value of ierr to be plotted |
| 1218 |
! (-ve ierr indicates a partial solution) |
| 1219 |
! |
| 1220 |
ierr = 666 |
| 1221 |
|
| 1222 |
! |
| 1223 |
!--use time=0 if time has not been read from dump file (indicated by t < 0) |
| 1224 |
! |
| 1225 |
if (time > 0) then |
| 1226 |
timei = time |
| 1227 |
else |
| 1228 |
timei = 0. |
| 1229 |
endif |
| 1230 |
if (use_gamma_exact .and. gamma_exact >= 1.) then |
| 1231 |
gammai = gamma_exact |
| 1232 |
elseif (gamma >= 1.) then |
| 1233 |
gammai = gamma |
| 1234 |
else |
| 1235 |
gammai = 5./3. |
| 1236 |
endif |
| 1237 |
|
| 1238 |
select case(iexact) |
| 1239 |
case(1) ! arbitrary function parsing |
| 1240 |
do i=1,nfunc |
| 1241 |
if ((iplotx==iexactplotx(i) .and. iploty==iexactploty(i)) .or. iexactploty(i)==0) then |
| 1242 |
!--allow user-specified colours and line styles |
| 1243 |
LineStyle = mod(iExactLineStyle(i),plotlib_maxlinestyle) |
| 1244 |
|
| 1245 |
call exact_function(funcstring(i),xexact,yexact,timei,ierr) |
| 1246 |
!--plot each solution separately and calculate errors |
| 1247 |
call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot, & |
| 1248 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,& |
| 1249 |
ls=LineStyle,lc=iExactLineColour(i)) |
| 1250 |
ierr = 1 ! indicate that we have already plotted the solution |
| 1251 |
endif |
| 1252 |
enddo |
| 1253 |
case(2) ! exact solution read from file |
| 1254 |
do i=1,nfiles |
| 1255 |
!--substitute %f for filename |
| 1256 |
filename_tmp = filename_exact(i) |
| 1257 |
call string_replace(filename_tmp,'%f',trim(rootname(ifileopen))) |
| 1258 |
!--auto-magically map columns onto splash columns (if not mapped manually) |
| 1259 |
if (iauto_map_columns) then |
| 1260 |
call map_columns_in_file(filename_tmp,ncols,nrows,imapexact,& |
| 1261 |
label(1:ncolumns+ncalc),exact_labels,nlab_exact,ierr) |
| 1262 |
endif |
| 1263 |
! see if there are columns in the exact file that match those of the current plot |
| 1264 |
imapx = match_integer(imapexact,iplotx) |
| 1265 |
imapy = match_integer(imapexact,iploty) |
| 1266 |
! if so, go ahead and read the data and plot the exact solution |
| 1267 |
if (imapx > 0 .and. imapy > 0) then |
| 1268 |
!--read exact solution from file |
| 1269 |
print "(a)",'> reading '//trim(exact_labels(imapx))//' and '//trim(exact_labels(imapy))//' from '//trim(filename_tmp) |
| 1270 |
call exact_fromfile(filename_tmp,xexact,yexact,imapx,imapy,iexactpts,ierr) |
| 1271 |
! if everything has been done automatically, try to guess whether |
| 1272 |
! the solution is in code units or physical units |
| 1273 |
if (iRescale .and. iauto_map_columns) then |
| 1274 |
iApplyUnitsExactFile = guess_whether_to_apply_units_to_exact(xplot,yplot,xexact,yexact,unitsx,unitsy) |
| 1275 |
endif |
| 1276 |
!--plot this untransformed (as may already be in log space) |
| 1277 |
if (ierr <= 0) then |
| 1278 |
if (iApplyTransExactFile) then |
| 1279 |
!--change into physical units if appropriate |
| 1280 |
if (iRescale .and. iApplyUnitsExactFile) then |
| 1281 |
xexact(1:iexactpts) = xexact(1:iexactpts)*unitsx |
| 1282 |
yexact(1:iexactpts) = yexact(1:iexactpts)*unitsy |
| 1283 |
endif |
| 1284 |
endif |
| 1285 |
!--change line style between files |
| 1286 |
LineStyle = mod(iExactLineStyle(i),plotlib_maxlinestyle) |
| 1287 |
!--do not apply log or other transformations if option set for this |
| 1288 |
! or if the label starts with 'log'... |
| 1289 |
mytransy = get_transform(itransy,iApplyTransExactFile,exact_labels(imapy)(1:3)) |
| 1290 |
mytransx = get_transform(itransx,iApplyTransExactFile,exact_labels(imapx)(1:3)) |
| 1291 |
|
| 1292 |
!--plot each solution separately and calculate errors |
| 1293 |
call plot_exact_solution(mytransx,mytransy,iexactpts,npart,xexact,yexact,xplot,yplot,& |
| 1294 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,& |
| 1295 |
ls=LineStyle,lc=iExactLineColour(i)) |
| 1296 |
ierr = 1 ! indicate that we have already plotted the solution |
| 1297 |
endif |
| 1298 |
else |
| 1299 |
! if nothing matched, make sure we do not plot anything |
| 1300 |
ierr = 2 |
| 1301 |
endif |
| 1302 |
enddo |
| 1303 |
case(3)! shock tube |
| 1304 |
if (iplotx==ix(1) .and. igeom <= 1) then |
| 1305 |
nsh = 1 |
| 1306 |
if (use_gamma2_exact) nsh = 2 |
| 1307 |
do i=1,nsh ! make 2 to plot both adiabatic and isothermal solutions |
| 1308 |
if (i==2) then |
| 1309 |
call plot_sls(4) |
| 1310 |
gammai = gamma2_exact |
| 1311 |
endif |
| 1312 |
if (iploty==irho) then |
| 1313 |
call exact_shock(1,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1314 |
rdust_to_gas,xexact,yexact,ierr) |
| 1315 |
elseif (iploty==ipr) then |
| 1316 |
call exact_shock(2,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1317 |
rdust_to_gas,xexact,yexact,ierr) |
| 1318 |
elseif (iploty==ivx) then |
| 1319 |
call exact_shock(3,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1320 |
rdust_to_gas,xexact,yexact,ierr) |
| 1321 |
elseif (iploty==iutherm) then |
| 1322 |
call exact_shock(4,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1323 |
rdust_to_gas,xexact,yexact,ierr) |
| 1324 |
elseif (iploty==ideltav) then |
| 1325 |
call exact_shock(5,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1326 |
rdust_to_gas,xexact,yexact,ierr) |
| 1327 |
elseif (iploty==idustfrac) then |
| 1328 |
call exact_shock(6,timei,gammai,xshock,rho_L,rho_R,pr_L,pr_R,v_L,v_R, & |
| 1329 |
rdust_to_gas,xexact,yexact,ierr) |
| 1330 |
endif |
| 1331 |
if (i==1 .and. ierr==0) call plot_line(iexactpts,xexact,yexact) |
| 1332 |
enddo |
| 1333 |
endif |
| 1334 |
|
| 1335 |
case(4)! sedov blast wave |
| 1336 |
! this subroutine does change xexact |
| 1337 |
if (iplotx==irad .or. (igeom==3 .and. iplotx==ix(1))) then |
| 1338 |
if (iploty==irho) then |
| 1339 |
call exact_sedov(1,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1340 |
elseif (iploty==ipr) then |
| 1341 |
call exact_sedov(2,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1342 |
elseif (iploty==iutherm) then |
| 1343 |
call exact_sedov(3,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1344 |
elseif (iploty==ike) then |
| 1345 |
call exact_sedov(4,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1346 |
elseif (iploty==ivx .and. igeom==3) then |
| 1347 |
call exact_sedov(5,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1348 |
endif |
| 1349 |
elseif (igeom <= 1 .and. is_coord(iplotx,ndim) .and. is_coord(iploty,ndim)) then |
| 1350 |
call exact_sedov(0,timei,gammai,rhosedov,esedov,xmax,xexact,yexact,ierr) |
| 1351 |
endif |
| 1352 |
|
| 1353 |
case(5)! polytrope |
| 1354 |
if (iploty==irho .and. (iplotx==irad .or.(igeom==3 .and. iplotx==ix(1)))) then |
| 1355 |
call exact_polytrope(gammai,polyk,totmass,xexact,yexact,iexactpts,ierr) |
| 1356 |
endif |
| 1357 |
|
| 1358 |
case(6)! toy star |
| 1359 |
if (iBfirst /= 0) then |
| 1360 |
sigma = sigma0 |
| 1361 |
else |
| 1362 |
sigma = 0. |
| 1363 |
endif |
| 1364 |
if (ndim==1) then |
| 1365 |
! |
| 1366 |
!--1D toy star solutions |
| 1367 |
! |
| 1368 |
if (iplotx==ix(1) .or. iplotx==irad) then! if x axis is x or r |
| 1369 |
if (iploty==irho) then |
| 1370 |
call exact_toystar1D(1,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1371 |
xexact,yexact,iexactpts,ierr) |
| 1372 |
elseif (iploty==ipr) then |
| 1373 |
call exact_toystar1D(2,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1374 |
xexact,yexact,iexactpts,ierr) |
| 1375 |
elseif (iploty==iutherm) then |
| 1376 |
call exact_toystar1D(3,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1377 |
xexact,yexact,iexactpts,ierr) |
| 1378 |
elseif (iploty==ivx) then |
| 1379 |
call exact_toystar1D(4,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1380 |
xexact,yexact,iexactpts,ierr) |
| 1381 |
elseif (iploty==iBfirst+1) then |
| 1382 |
call exact_toystar1D(5,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1383 |
xexact,yexact,iexactpts,ierr) |
| 1384 |
endif |
| 1385 |
elseif (iplotx==irho) then |
| 1386 |
if (iploty==iBfirst+1) then |
| 1387 |
call exact_toystar1D(6,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1388 |
xexact,yexact,iexactpts,ierr) |
| 1389 |
endif |
| 1390 |
endif |
| 1391 |
|
| 1392 |
if (iploty==iacplane) then! plot point on a-c plane |
| 1393 |
call exact_toystar1D(7,timei,gammai,htstar,atstar,ctstar,sigma,norder, & |
| 1394 |
xexact,yexact,iexactpts,ierr) |
| 1395 |
endif |
| 1396 |
else |
| 1397 |
! |
| 1398 |
!--2D toy star solutions |
| 1399 |
! these routines change xexact |
| 1400 |
! |
| 1401 |
if (igeom==1 .and.((iplotx==ix(1) .and. iploty==ivx) & |
| 1402 |
.or. (iplotx==ix(2) .and. iploty==ivx+1))) then |
| 1403 |
call exact_toystar2D(4,timei,gammai,polyk,totmass, & |
| 1404 |
atstar,htstar,ctstar,norder,morder, & |
| 1405 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1406 |
endif |
| 1407 |
if (iplotx==irad .or. (igeom==2 .and. iplotx==ix(1))) then |
| 1408 |
if (iploty==irho) then |
| 1409 |
call exact_toystar2D(1,timei,gammai,polyk,totmass, & |
| 1410 |
atstar,htstar,ctstar,norder,morder, & |
| 1411 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1412 |
elseif (iploty==ipr) then |
| 1413 |
call exact_toystar2D(2,timei,gammai,polyk,totmass, & |
| 1414 |
atstar,htstar,ctstar,norder,morder, & |
| 1415 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1416 |
elseif (iploty==iutherm) then |
| 1417 |
call exact_toystar2D(3,timei,gammai,polyk,totmass, & |
| 1418 |
atstar,htstar,ctstar,norder,morder, & |
| 1419 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1420 |
elseif (igeom==2 .and. iploty==ivx) then |
| 1421 |
call exact_toystar2D(4,timei,gammai,polyk,totmass, & |
| 1422 |
atstar,htstar,ctstar,norder,morder, & |
| 1423 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1424 |
elseif (iploty==ike) then |
| 1425 |
call exact_toystar2D(5,timei,gammai,polyk,totmass, & |
| 1426 |
atstar,htstar,ctstar,norder,morder, & |
| 1427 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1428 |
endif |
| 1429 |
elseif (is_coord(iplotx,ndim) .and. is_coord(iploty,ndim) .and. igeom==1) then |
| 1430 |
call exact_toystar2D(0,timei,gammai,polyk,totmass, & |
| 1431 |
atstar,htstar,ctstar,norder,morder, & |
| 1432 |
alphatstar,betatstar,ctstar1,ctstar2,xexact,yexact,ierr) |
| 1433 |
endif |
| 1434 |
endif |
| 1435 |
|
| 1436 |
case(7)! Gresho vortex |
| 1437 |
!if ((iploty==iwaveploty).and.(iplotx==iwaveplotx)) then |
| 1438 |
! ymean = SUM(yplot(1:npart))/REAL(npart) |
| 1439 |
! call exact_wave(timei,ampl,period,lambda,xzero,ymean,xexact,yexact,ierr) |
| 1440 |
!endif |
| 1441 |
if (igeom==2 .and. ndim >= 2) then |
| 1442 |
if (iploty==ivx+1) then |
| 1443 |
call exact_gresho(1,xexact,yexact,ierr) |
| 1444 |
elseif (iploty==ipr) then |
| 1445 |
call exact_gresho(2,xexact,yexact,ierr) |
| 1446 |
endif |
| 1447 |
endif |
| 1448 |
case(8) ! mhd shock tubes |
| 1449 |
! this subroutine modifies xexact |
| 1450 |
if (iplotx==ix(1) .and. igeom <= 1) then |
| 1451 |
if (iploty==irho) then |
| 1452 |
call exact_mhdshock(1,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1453 |
xexact,yexact,iexactpts,ierr) |
| 1454 |
elseif (iploty==ipr) then |
| 1455 |
call exact_mhdshock(2,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1456 |
xexact,yexact,iexactpts,ierr) |
| 1457 |
elseif (iploty==ivx) then |
| 1458 |
call exact_mhdshock(3,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1459 |
xexact,yexact,iexactpts,ierr) |
| 1460 |
elseif (iploty==ivx+1 .and. ndimV > 1) then |
| 1461 |
call exact_mhdshock(4,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1462 |
xexact,yexact,iexactpts,ierr) |
| 1463 |
elseif (iploty==ivx+ndimV-1 .and. ndimV > 2) then |
| 1464 |
call exact_mhdshock(5,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1465 |
xexact,yexact,iexactpts,ierr) |
| 1466 |
elseif (iploty==iBfirst+1 .and. ndimV > 1) then |
| 1467 |
call exact_mhdshock(6,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1468 |
xexact,yexact,iexactpts,ierr) |
| 1469 |
elseif (iploty==iBfirst+ndimV-1 .and. ndimV > 2) then |
| 1470 |
call exact_mhdshock(7,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1471 |
xexact,yexact,iexactpts,ierr) |
| 1472 |
elseif (iploty==iutherm) then |
| 1473 |
call exact_mhdshock(8,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1474 |
xexact,yexact,iexactpts,ierr) |
| 1475 |
elseif (iploty==iBfirst) then |
| 1476 |
call exact_mhdshock(9,ishk,timei,gammai,xmin,xmax,xshock, & |
| 1477 |
xexact,yexact,iexactpts,ierr) |
| 1478 |
endif |
| 1479 |
endif |
| 1480 |
case(9) |
| 1481 |
!--h = (1/rho)^(1/ndim) |
| 1482 |
if (((iploty==ih).and.(iplotx==irho)) .or. & |
| 1483 |
((iplotx==ih).and.(iploty==irho))) then |
| 1484 |
if (iplotx==ih) then |
| 1485 |
call exact_rhoh(2,ndim,hfact,pmassmin,xexact,yexact,ierr) |
| 1486 |
else |
| 1487 |
call exact_rhoh(1,ndim,hfact,pmassmin,xexact,yexact,ierr) |
| 1488 |
endif |
| 1489 |
|
| 1490 |
!--if variable particle masses, plot one for each pmass value |
| 1491 |
if (abs(pmassmin-pmassmax) > zero .and. pmassmin > zero) then |
| 1492 |
!--plot first line |
| 1493 |
if (ierr <= 0) then |
| 1494 |
xtemp = xexact ! must not transform xexact as this is done again below |
| 1495 |
if (itransx > 0) call transform(xtemp,itransx) |
| 1496 |
if (itransy > 0) call transform(yexact,itransy) |
| 1497 |
call plot_line(iexactpts,xtemp(1:iexactpts),yexact(1:iexactpts)) |
| 1498 |
endif |
| 1499 |
!--leave this one to be plotted below |
| 1500 |
if (iplotx==ih) then |
| 1501 |
call exact_rhoh(2,ndim,hfact,pmassmax,xexact,yexact,ierr) |
| 1502 |
else |
| 1503 |
call exact_rhoh(1,ndim,hfact,pmassmax,xexact,yexact,ierr) |
| 1504 |
endif |
| 1505 |
endif |
| 1506 |
endif |
| 1507 |
case(10) ! density profiles |
| 1508 |
if (iplotx==irad .or.(igeom==3 .and. iplotx==ix(1))) then |
| 1509 |
if (iploty==irho) then |
| 1510 |
call exact_densityprofiles(1,iprofile,Msphere,rsoft,xexact,yexact,ierr) |
| 1511 |
elseif (iploty==icolpoten) then |
| 1512 |
call exact_densityprofiles(2,iprofile,Msphere,rsoft,xexact,yexact,ierr) |
| 1513 |
elseif (iploty==icolfgrav) then |
| 1514 |
call exact_densityprofiles(3,iprofile,Msphere,rsoft,xexact,yexact,ierr) |
| 1515 |
endif |
| 1516 |
endif |
| 1517 |
case(11) ! torus |
| 1518 |
if (iplotx==irad .or.(igeom==3 .and. iplotx==ix(1))) then |
| 1519 |
if (iploty==irho) then |
| 1520 |
call exact_torus(1,1,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1521 |
elseif (iploty==ipr) then |
| 1522 |
call exact_torus(2,1,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1523 |
elseif (iploty==iutherm) then |
| 1524 |
call exact_torus(3,1,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1525 |
endif |
| 1526 |
!--pr vs z at r=Rtorus |
| 1527 |
elseif (igeom==2 .and. iplotx==ix(3) .and.iploty==ipr) then |
| 1528 |
call exact_torus(4,1,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1529 |
endif |
| 1530 |
!--solutions for tokamak torus |
| 1531 |
if (igeom==4 .and. iplotx==ix(1)) then |
| 1532 |
if (iploty==irho) then |
| 1533 |
call exact_torus(1,2,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1534 |
elseif (iploty==ipr) then |
| 1535 |
call exact_torus(2,2,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1536 |
elseif (iploty==iutherm) then |
| 1537 |
call exact_torus(3,2,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1538 |
elseif (iploty==iBfirst+1 .and. iBfirst > 0) then |
| 1539 |
call exact_torus(4,2,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1540 |
elseif (iploty==iJfirst+2 .and. iJfirst > 0) then |
| 1541 |
call exact_torus(5,2,Mstar,Rtorus,polyk,distortion,gammai,xexact,yexact,ierr) |
| 1542 |
endif |
| 1543 |
endif |
| 1544 |
case(12) |
| 1545 |
if (iplotx==irad .or.((igeom==3 .or. igeom==2) .and. iplotx==ix(1))) then |
| 1546 |
if (iploty==irho) then |
| 1547 |
call exact_ringspread(1,timei,Mring,Rring,viscnu,xexact,yexact,ierr) |
| 1548 |
endif |
| 1549 |
endif |
| 1550 |
case(13) ! special relativistic shock tube |
| 1551 |
if (iplotx==ix(1) .and. igeom <= 1) then |
| 1552 |
if (iploty==irhorestframe) then |
| 1553 |
call exact_shock_sr(1,timei,gammai,rho_L,rho_R,pr_L,pr_R,v_L,v_R,xexact,yexact,ierr) |
| 1554 |
elseif (iploty==ipr) then |
| 1555 |
call exact_shock_sr(2,timei,gammai,rho_L,rho_R,pr_L,pr_R,v_L,v_R,xexact,yexact,ierr) |
| 1556 |
elseif (iploty==ivx) then |
| 1557 |
call exact_shock_sr(3,timei,gammai,rho_L,rho_R,pr_L,pr_R,v_L,v_R,xexact,yexact,ierr) |
| 1558 |
elseif (iploty==iutherm) then |
| 1559 |
call exact_shock_sr(4,timei,gammai,rho_L,rho_R,pr_L,pr_R,v_L,v_R,xexact,yexact,ierr) |
| 1560 |
elseif (iploty==irho) then |
| 1561 |
call exact_shock_sr(5,timei,gammai,rho_L,rho_R,pr_L,pr_R,v_L,v_R,xexact,yexact,ierr) |
| 1562 |
endif |
| 1563 |
endif |
| 1564 |
case(14) ! dusty wave exact solution |
| 1565 |
if (iplotx==ix(1) .and. igeom <= 1) then |
| 1566 |
if (iploty==ivx) then |
| 1567 |
!--plot gas solution and calculate errors |
| 1568 |
call exact_dustywave(1,timei,ampl,cs,Kdrag,lambda,xzero,rhozero,rhozero*rdust_to_gas,xexact,yexact,ierr) |
| 1569 |
call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot, & |
| 1570 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,ls=1,matchtype=1) |
| 1571 |
!--plot dust solution |
| 1572 |
if (Kdrag > 0.) then |
| 1573 |
call exact_dustywave(2,timei,ampl,cs,Kdrag,lambda,xzero,rhozero,rhozero*rdust_to_gas,xexact,yexact,ierr) |
| 1574 |
call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot, & |
| 1575 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,ls=2,matchtype=2) |
| 1576 |
endif |
| 1577 |
ierr = 1 |
| 1578 |
elseif (iploty==irho) then |
| 1579 |
!--plot gas solution and calculate errors |
| 1580 |
call exact_dustywave(3,timei,ampl,cs,Kdrag,lambda,xzero,rhozero,rhozero*rdust_to_gas,xexact,yexact,ierr) |
| 1581 |
call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot,& |
| 1582 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,ls=1,matchtype=1) |
| 1583 |
!--plot dust solution |
| 1584 |
if (Kdrag > 0.) then |
| 1585 |
call exact_dustywave(4,timei,ampl,cs,Kdrag,lambda,xzero,rhozero,rhozero*rdust_to_gas,xexact,yexact,ierr) |
| 1586 |
call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot,& |
| 1587 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,ls=2,matchtype=2) |
| 1588 |
endif |
| 1589 |
ierr = 1 |
| 1590 |
endif |
| 1591 |
endif |
| 1592 |
case(15) ! Roche potential |
| 1593 |
if (igeom==1 .and. ndim >= 2 .and. iplotx==ix(1) .and. iploty==ix(2)) then |
| 1594 |
call exact_rochelobe(xprim(1),xprim(2),xsec(1),xsec(2),mprim,msec,xexact,yexact,ierr) |
| 1595 |
endif |
| 1596 |
case(16) ! C-shock |
| 1597 |
if (ndim >= 1 .and. iplotx==ix(1) .and. igeom <= 1) then |
| 1598 |
if (iploty==irho) then |
| 1599 |
call exact_Cshock(1,timei,gammai,machs,macha,xmin,xmax,xexact,yexact,ierr) |
| 1600 |
elseif (iploty==iBfirst+1 .and. iBfirst > 0) then |
| 1601 |
call exact_Cshock(2,timei,gammai,machs,macha,xmin,xmax,xexact,yexact,ierr) |
| 1602 |
elseif (iploty==ivx) then |
| 1603 |
call exact_Cshock(3,timei,gammai,machs,macha,xmin,xmax,xexact,yexact,ierr) |
| 1604 |
elseif (iploty==ivx+1 .and. ndimV > 1) then |
| 1605 |
call exact_Cshock(4,timei,gammai,machs,macha,xmin,xmax,xexact,yexact,ierr) |
| 1606 |
elseif (iploty==iBfirst .and. iBfirst > 0) then |
| 1607 |
call exact_Cshock(5,timei,gammai,machs,macha,xmin,xmax,xexact,yexact,ierr) |
| 1608 |
endif |
| 1609 |
endif |
| 1610 |
case(17) ! planet-disc interaction |
| 1611 |
if (ndim >= 2 .and. iplotx==ix(1) .and. iploty==ix(2)) then |
| 1612 |
call exact_planetdisc(igeom,ispiral,iclockwise,inonlin,timei,HonR,rplanet,q_index,phase,narms,& |
| 1613 |
spiral_params,xexact,yexact,ierr) |
| 1614 |
endif |
| 1615 |
case(18) |
| 1616 |
if (iplotx==irad .or. (igeom==3 .and. iplotx==ix(1))) then |
| 1617 |
if (iploty==ivx .and. igeom==3) then |
| 1618 |
call exact_bondi(1,timei,gammai,const1,const2,Mstar,relativistic,geodesic_flow,is_wind,xexact,yexact,ierr) |
| 1619 |
elseif (iploty==iutherm .and. igeom==3) then |
| 1620 |
call exact_bondi(2,timei,gammai,const1,const2,Mstar,relativistic,geodesic_flow,is_wind,xexact,yexact,ierr) |
| 1621 |
elseif (iploty==irho .and. igeom==3) then |
| 1622 |
call exact_bondi(3,timei,gammai,const1,const2,Mstar,relativistic,geodesic_flow,is_wind,xexact,yexact,ierr) |
| 1623 |
endif |
| 1624 |
endif |
| 1625 |
end select |
| 1626 |
|
| 1627 |
!---------------------------------------------------------- |
| 1628 |
! plot this as a line on the current graph |
| 1629 |
!---------------------------------------------------------- |
| 1630 |
if (ierr <= 0) call plot_exact_solution(itransx,itransy,iexactpts,npart,xexact,yexact,xplot,yplot, & |
| 1631 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy) |
| 1632 |
! |
| 1633 |
!--reset line and colour settings |
| 1634 |
! |
| 1635 |
call plot_sci(iCurrentColour) |
| 1636 |
call plot_sls(iCurrentLineStyle) |
| 1637 |
call plot_set_opacity(1.0) |
| 1638 |
! |
| 1639 |
!--deallocate memory |
| 1640 |
! |
| 1641 |
if (allocated(xexact)) deallocate(xexact) |
| 1642 |
if (allocated(yexact)) deallocate(yexact) |
| 1643 |
if (allocated(xtemp)) deallocate(xtemp) |
| 1644 |
|
| 1645 |
end subroutine exact_solution |
| 1646 |
|
| 1647 |
!------------------------------------------------------------------ |
| 1648 |
! try to figure out how to correctly transform the exact solution |
| 1649 |
!------------------------------------------------------------------ |
| 1650 |
integer function get_transform(itrans,apply_trans,label_start) result(mytrans) |
| 1651 |
use transforms, only:islogged |
| 1652 |
use asciiutils, only:lcase |
| 1653 |
integer, intent(in) :: itrans |
| 1654 |
logical, intent(in) :: apply_trans |
| 1655 |
character(len=3), intent(in) :: label_start |
| 1656 |
|
| 1657 |
! by default, the data transformation is also applied to the exact solution |
| 1658 |
mytrans = itrans |
| 1659 |
! disable this if the flag to switch it off is set |
| 1660 |
if (.not.apply_trans) mytrans = 0 |
| 1661 |
|
| 1662 |
if (lcase(label_start)=='log') then |
| 1663 |
if (islogged(itrans)) then |
| 1664 |
! disable exact solution transform if solution is already logged |
| 1665 |
mytrans = 0 |
| 1666 |
else |
| 1667 |
! if exact solution is logged but data isn't, apply inverse transform |
| 1668 |
mytrans = -1 |
| 1669 |
endif |
| 1670 |
endif |
| 1671 |
|
| 1672 |
end function get_transform |
| 1673 |
|
| 1674 |
!------------------------------------------------------------------ |
| 1675 |
! try to figure out how to correctly transform the exact solution |
| 1676 |
!------------------------------------------------------------------ |
| 1677 |
logical function guess_whether_to_apply_units_to_exact(xplot,yplot,xexact,yexact,unitsx,unitsy) |
| 1678 |
real, intent(in) :: xplot(:),yplot(:),xexact(:),yexact(:) |
| 1679 |
real, intent(in) :: unitsx,unitsy |
| 1680 |
|
| 1681 |
real :: range_xplot, range_yplot |
| 1682 |
real :: range_xexact_no_units, range_yexact_no_units |
| 1683 |
real :: range_xexact_with_units, range_yexact_with_units |
| 1684 |
|
| 1685 |
! Calculate ranges for xplot and yplot |
| 1686 |
range_xplot = maxval(xplot) - minval(xplot) |
| 1687 |
range_yplot = maxval(yplot) - minval(yplot) |
| 1688 |
|
| 1689 |
! Calculate ranges for xexact and yexact without applying units |
| 1690 |
range_xexact_no_units = maxval(xexact) - minval(xexact) |
| 1691 |
range_yexact_no_units = maxval(yexact) - minval(yexact) |
| 1692 |
|
| 1693 |
! Calculate ranges for xexact and yexact with applying units |
| 1694 |
range_xexact_with_units = maxval(xexact * unitsx) - minval(xexact * unitsx) |
| 1695 |
range_yexact_with_units = maxval(yexact * unitsy) - minval(yexact * unitsy) |
| 1696 |
|
| 1697 |
! Determine if applying units results in a closer range to xplot and yplot |
| 1698 |
! that is at least an order of magnitude closer in one of the axes |
| 1699 |
if (abs(range_xexact_with_units - range_xplot) < 10.*abs(range_xexact_no_units - range_xplot) .or. & |
| 1700 |
abs(range_yexact_with_units - range_yplot) < 10.*abs(range_yexact_no_units - range_yplot)) then |
| 1701 |
guess_whether_to_apply_units_to_exact = .true. |
| 1702 |
else |
| 1703 |
guess_whether_to_apply_units_to_exact = .false. |
| 1704 |
endif |
| 1705 |
|
| 1706 |
end function guess_whether_to_apply_units_to_exact |
| 1707 |
|
| 1708 |
!------------------------------------------------------------------ |
| 1709 |
! Wrapper routine to plot the exact solution line on current graph |
| 1710 |
! and calculate errors with respect to the data |
| 1711 |
!------------------------------------------------------------------ |
| 1712 |
subroutine plot_exact_solution(itransx,itransy,iexactpts,np,xexact,yexact,xplot,yplot,& |
| 1713 |
itag,iamtype,noftype,iplot_type,xmin,xmax,imarker,iaxisy,& |
| 1714 |
ls,lc,matchtype,err) |
| 1715 |
use transforms, only:transform,transform_inverse |
| 1716 |
use plotlib, only:plot_line,plot_sls,plot_sci,plot_qci,plot_set_opacity |
| 1717 |
use params, only:int1,maxparttypes |
| 1718 |
integer, intent(in) :: itransx,itransy,iexactpts,np,imarker,iaxisy |
| 1719 |
real, intent(inout) :: xexact(:),yexact(:) |
| 1720 |
real, intent(in) :: xplot(:),yplot(:),xmin,xmax |
| 1721 |
integer, intent(in) :: itag(:) |
| 1722 |
integer(int1), intent(in) :: iamtype(:) |
| 1723 |
integer, intent(in) :: noftype(maxparttypes) |
| 1724 |
logical, intent(in) :: iplot_type(maxparttypes) |
| 1725 |
integer, intent(in), optional :: ls, matchtype, lc |
| 1726 |
logical, intent(in), optional :: err |
| 1727 |
real :: residuals(np),ypart(np) |
| 1728 |
real :: errL1,errL2,errLinf |
| 1729 |
integer :: iused,ierr,iCurrentColour,imatchtype |
| 1730 |
logical :: plot_err |
| 1731 |
character(len=12) :: str1,str2 |
| 1732 |
|
| 1733 |
call plot_qci(iCurrentColour) |
| 1734 |
if (present(lc)) call plot_sci(lc) |
| 1735 |
call plot_set_opacity(ExactAlpha) |
| 1736 |
|
| 1737 |
if (itransx /= 0) call transform(xexact(1:iexactpts),itransx) |
| 1738 |
if (itransy /= 0) call transform(yexact(1:iexactpts),itransy) |
| 1739 |
|
| 1740 |
if (present(ls)) call plot_sls(ls) |
| 1741 |
|
| 1742 |
call plot_line(iexactpts,xexact(1:iexactpts),yexact(1:iexactpts)) |
| 1743 |
! |
| 1744 |
!--calculate errors |
| 1745 |
! |
| 1746 |
if (present(err)) then |
| 1747 |
plot_err = err |
| 1748 |
else |
| 1749 |
plot_err = .true. |
| 1750 |
endif |
| 1751 |
if (present(matchtype)) then |
| 1752 |
imatchtype = matchtype |
| 1753 |
else |
| 1754 |
imatchtype = 0 |
| 1755 |
endif |
| 1756 |
|
| 1757 |
if (iCalculateExactErrors .and. plot_err) then |
| 1758 |
!--untransform y axis again for error calculation |
| 1759 |
if (itransy /= 0) call transform_inverse(yexact(1:iexactpts),itransy) |
| 1760 |
!--untransform particle y axis also |
| 1761 |
ypart(1:np) = yplot(1:np) |
| 1762 |
if (itransy /= 0) call transform_inverse(ypart(1:np),itransy) |
| 1763 |
!--calculate errors |
| 1764 |
call calculate_errors(xexact(1:iexactpts),yexact(1:iexactpts),xplot(1:np),ypart,& |
| 1765 |
itag,iamtype,noftype,iplot_type,xmin,xmax,residuals, & |
| 1766 |
errL1,errL2,errLinf,iused,imatchtype) |
| 1767 |
if (iused /= np) then |
| 1768 |
write(str1,"(i12)",iostat=ierr) iused |
| 1769 |
write(str2,"(i12)",iostat=ierr) np |
| 1770 |
print "(3(a,es12.5,1x),'(used ',a,'/',a,' parts)')",' L1 err = ',errL1,'L2 err = ',errL2, & |
| 1771 |
'L(inf) err = ',errLinf,trim(adjustl(str1)),trim(adjustl(str2)) |
| 1772 |
else |
| 1773 |
print "(3(a,es12.5,1x))",' L1 err = ',errL1,'L2 err = ',errL2, & |
| 1774 |
'L(inf) err = ',errLinf |
| 1775 |
endif |
| 1776 |
if (iPlotResiduals) then |
| 1777 |
call plot_sci(1) |
| 1778 |
call plot_residuals(xplot,residuals,imarker,iaxisy) |
| 1779 |
endif |
| 1780 |
endif |
| 1781 |
call plot_sci(iCurrentColour) |
| 1782 |
call plot_set_opacity(1.0) |
| 1783 |
|
| 1784 |
end subroutine plot_exact_solution |
| 1785 |
|
| 1786 |
!-------------------------------- |
| 1787 |
! Calculate various error norms |
| 1788 |
!-------------------------------- |
| 1789 |
subroutine calculate_errors(xexact,yexact,xpts,ypts,itag,iamtype,noftype,iplot_type,& |
| 1790 |
xmin,xmax,residual,errL1,errL2,errLinf,iused,imatchtype) |
| 1791 |
use part_utils, only:igettype |
| 1792 |
use params, only:int1,maxparttypes |
| 1793 |
real, intent(in) :: xexact(:),yexact(:),xpts(:),ypts(:),xmin,xmax |
| 1794 |
integer, intent(in) :: itag(:) |
| 1795 |
integer(int1), intent(in) :: iamtype(:) |
| 1796 |
integer, intent(in) :: noftype(maxparttypes) |
| 1797 |
logical, intent(in) :: iplot_type(maxparttypes) |
| 1798 |
real, intent(out) :: residual(size(xpts)) |
| 1799 |
real, intent(out) :: errL1,errL2,errLinf |
| 1800 |
integer, intent(out) :: iused |
| 1801 |
integer, intent(in) :: imatchtype |
| 1802 |
integer :: i,j,npart,nerr,nused,itype |
| 1803 |
real :: xi,dy,dx,yexacti,err1,ymax |
| 1804 |
logical :: mixedtypes |
| 1805 |
|
| 1806 |
errL1 = 0. |
| 1807 |
errL2 = 0. |
| 1808 |
errLinf = 0. |
| 1809 |
residual = 0. |
| 1810 |
npart = size(xpts) |
| 1811 |
iused = 0 |
| 1812 |
ymax = 0. |
| 1813 |
nerr = 0 |
| 1814 |
nused = 0 |
| 1815 |
mixedtypes = size(iamtype) > 1 |
| 1816 |
|
| 1817 |
do i=1,npart |
| 1818 |
xi = xpts(i) |
| 1819 |
yexacti = 0. |
| 1820 |
if (xi >= xmin .and. xi <= xmax .and. itag(i) > 0) then |
| 1821 |
if (mixedtypes) then |
| 1822 |
itype = min(max(int(iamtype(i)),1),maxparttypes) |
| 1823 |
else |
| 1824 |
itype = igettype(i,noftype) |
| 1825 |
endif |
| 1826 |
if (iplot_type(itype) .and. ((imatchtype==0).or.(itype==imatchtype))) then |
| 1827 |
! |
| 1828 |
!--find nearest point in exact solution table |
| 1829 |
! |
| 1830 |
do j=1,size(xexact)-1 |
| 1831 |
if ((xexact(j) <= xi .and. xexact(j+1) > xi) .or. & |
| 1832 |
(xexact(j+1) <= xi .and. xexact(j) > xi)) then |
| 1833 |
if (abs(residual(i)) > tiny(residual)) nerr = nerr + 1 |
| 1834 |
!--linear interpolation from tabulated exact solution |
| 1835 |
dy = yexact(j+1) - yexact(j) |
| 1836 |
dx = xexact(j+1) - xexact(j) |
| 1837 |
if (dx > 0.) then |
| 1838 |
yexacti = yexact(j) + dy/dx*(xi - xexact(j)) |
| 1839 |
residual(i) = ypts(i) - yexacti |
| 1840 |
elseif (dy >= 0.) then |
| 1841 |
yexacti = yexact(j) |
| 1842 |
residual(i) = ypts(i) - yexacti |
| 1843 |
else |
| 1844 |
nerr = nerr + 1 |
| 1845 |
residual(i) = 0. |
| 1846 |
endif |
| 1847 |
iused = iused + 1 |
| 1848 |
ymax = max(ymax,abs(yexacti)) |
| 1849 |
endif |
| 1850 |
enddo |
| 1851 |
err1 = abs(residual(i)) |
| 1852 |
errL1 = errL1 + err1 |
| 1853 |
errL2 = errL2 + err1**2 |
| 1854 |
errLinf = max(errLinf,err1) |
| 1855 |
if (yexacti > tiny(yexacti)) residual(i) = residual(i)/abs(yexacti) |
| 1856 |
nused = nused + 1 |
| 1857 |
endif |
| 1858 |
endif |
| 1859 |
enddo |
| 1860 |
! |
| 1861 |
!--normalise errors (use maximum y value) |
| 1862 |
! |
| 1863 |
if (nused > 0) then |
| 1864 |
if (iNormaliseErrors==1 .and. ymax > tiny(ymax)) then |
| 1865 |
errL1 = errL1/(nused*ymax) |
| 1866 |
errL2 = sqrt(errL2/(nused*ymax**2)) |
| 1867 |
errLinf = errLinf/ymax |
| 1868 |
else |
| 1869 |
errL1 = errL1/nused |
| 1870 |
errL2 = sqrt(errL2/(nused)) |
| 1871 |
endif |
| 1872 |
else |
| 1873 |
!print "(a)",' error normalising errors' |
| 1874 |
errL1 = 0. |
| 1875 |
errL2 = 0. |
| 1876 |
errLinf = 0. |
| 1877 |
endif |
| 1878 |
if (nerr > 0) print*,'WARNING: ',nerr,' errors in residual calculation' |
| 1879 |
|
| 1880 |
end subroutine calculate_errors |
| 1881 |
|
| 1882 |
!------------------------------------ |
| 1883 |
! Plot residual errors as inset plot |
| 1884 |
!------------------------------------ |
| 1885 |
subroutine plot_residuals(xpts,residuals,imarker,iaxisy) |
| 1886 |
use plotlib, only:plot_qvp,plot_qwin,plot_svp,plot_qci,plot_qfs, & |
| 1887 |
plot_qcs,plot_sci,plot_sfs,plot_svp,plot_box, & |
| 1888 |
plot_pt,plot_swin,plot_rect |
| 1889 |
real, intent(in) :: xpts(:),residuals(:) |
| 1890 |
integer, intent(in) :: imarker,iaxisy |
| 1891 |
real :: vptxminold,vptxmaxold,vptyminold,vptymaxold |
| 1892 |
real :: vptxmin,vptxmax,vptymin,vptymax |
| 1893 |
real :: xminold,xmaxold,yminold,ymaxold,ymin,ymax |
| 1894 |
real :: xch,ych |
| 1895 |
integer :: ioldcolour,ioldfill |
| 1896 |
|
| 1897 |
!--query old viewport and window size |
| 1898 |
call plot_qvp(0,vptxminold,vptxmaxold,vptyminold,vptymaxold) |
| 1899 |
call plot_qwin(xminold,xmaxold,yminold,ymaxold) |
| 1900 |
|
| 1901 |
!--use specified bottom % of viewport |
| 1902 |
vptxmin = vptxminold |
| 1903 |
vptxmax = vptxmaxold |
| 1904 |
vptymin = vptyminold |
| 1905 |
vptymax = vptyminold + FracinsetResiduals*(vptymaxold - vptyminold) |
| 1906 |
call plot_svp(vptxmin,vptxmax,vptymin,vptymax) |
| 1907 |
|
| 1908 |
!--set window |
| 1909 |
if (residualmax < tiny(residualmax)) then |
| 1910 |
ymax = maxval(abs(residuals)) |
| 1911 |
print*,'max residual = ',ymax |
| 1912 |
else |
| 1913 |
ymax = residualmax |
| 1914 |
endif |
| 1915 |
ymin = -ymax |
| 1916 |
|
| 1917 |
!--erase space for residual plot |
| 1918 |
call plot_qci(ioldcolour) |
| 1919 |
call plot_qfs(ioldfill) |
| 1920 |
call plot_qcs(0,xch,ych) |
| 1921 |
call plot_sci(0) |
| 1922 |
call plot_sfs(1) |
| 1923 |
if (iaxisy < 0) then |
| 1924 |
call plot_svp(vptxmin,vptxmax,vptymin,vptymax) |
| 1925 |
else |
| 1926 |
call plot_svp(vptxmin - 3.*xch,vptxmax,vptymin,vptymax) |
| 1927 |
endif |
| 1928 |
call plot_swin(xminold,xmaxold,ymin,ymax) |
| 1929 |
call plot_rect(xminold,xmaxold,ymin,ymax) |
| 1930 |
!--restore fill style |
| 1931 |
call plot_sfs(ioldfill) |
| 1932 |
call plot_sci(1) |
| 1933 |
|
| 1934 |
!--set window and draw axes |
| 1935 |
call plot_svp(vptxmin,vptxmax,vptymin,vptymax) |
| 1936 |
call plot_swin(xminold,xmaxold,ymin,ymax) |
| 1937 |
if (iaxisy < 0) then |
| 1938 |
call plot_box('ABCST',0.0,0,'BCST',0.0,0) |
| 1939 |
else |
| 1940 |
call plot_box('ABCST',0.0,0,'BVNCST',0.0,0) |
| 1941 |
endif |
| 1942 |
|
| 1943 |
!--plot residuals |
| 1944 |
call plot_sci(ioldcolour) |
| 1945 |
call plot_pt(size(xpts),xpts,residuals,imarker) |
| 1946 |
|
| 1947 |
!--restore old viewport, window and colour index |
| 1948 |
call plot_svp(vptxminold,vptxmaxold,vptyminold,vptymaxold) |
| 1949 |
call plot_swin(xminold,xmaxold,yminold,ymaxold) |
| 1950 |
|
| 1951 |
end subroutine plot_residuals |
| 1952 |
|
| 1953 |
end module exact |