diff --git a/config/linux_gcc.cmake b/config/linux_gcc.cmake index a8ceedf14f..8b92691509 100644 --- a/config/linux_gcc.cmake +++ b/config/linux_gcc.cmake @@ -11,7 +11,13 @@ if(NOT __processedUserDefaults) set(CMAKE_Fortran_COMPILER gfortran CACHE STRING "") # Note (12/2021): passing -march=native to gfortran seems to slow down the # PPM solver - set(CMAKE_Fortran_FLAGS "-ffixed-line-length-132" CACHE STRING "Default Fortran flags") + set(CMAKE_Fortran_FLAGS "-ffixed-line-length-132 -std=legacy " CACHE STRING "Default Fortran flags") + + set(__ARCH_C_OPT_FLAGS "-O3 -g -funroll-loops") + set(CMAKE_C_FLAGS_RELEASE "${__ARCH_C_OPT_FLAGS}") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g ${__ARCH_C_OPT_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${__ARCH_C_OPT_FLAGS}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g ${__ARCH_C_OPT_FLAGS}") # these flag(s) are currently only used when using openmp-simd optimizations # (to specify available/prefered instruction sets). diff --git a/config/linux_gcc_9.py b/config/linux_gcc_9.py new file mode 100755 index 0000000000..6a624d8b32 --- /dev/null +++ b/config/linux_gcc_9.py @@ -0,0 +1,78 @@ + +import os +from _common_search_paths import charm_path_search, grackle_path_search + +is_arch_valid = 1 + +# +#flags_arch = '-g -fprofile-arcs -ftest-coverage' # gcov +#flags_arch = '-O3 -fopenmp -Wall -g -ffast-math -funroll-loops -fPIC' +flags_arch = '-O3 -fopenmp -Wall -g -ffast-math -funroll-loops -fPIC' +#flags_arch = '-Wall -O1 -g -fPIC -pedantic' +#flags_arch = '-Wall -O0 -g' +#flags_arch = '-O3 -pg -g' +#flags_arch = '-Wall -g -fsanitize=address -fno-omit-frame-pointer' + +# rdynamic required for backtraces +#flags_link_charm = '-rdynamic' +#flags_link_charm = '-memory paranoid' +#flags_link_charm = '-fprofile-arcs' # gcov + +#optional fortran flag +flags_arch_fortran = '-ffixed-line-length-132 -std=legacy ' + +cc = 'gcc ' +f90 = 'gfortran' + +flags_prec_single = '' +flags_prec_double = '-fdefault-real-8 -fdefault-double-8' + +libpath_fortran = '/usr/lib/gcc/x86_64-linux-gnu/9' +libs_fortran = ['gfortran'] + +home = os.getenv('HOME') + +# use Charm++ with randomized message queues for debugging and stress-testing +# charm_path = home + '/Charm/charm.random' + +charm_path = charm_path_search(home) + +# use_papi = 1 +# papi_inc = os.getenv('PAPI_INC', '/usr/include') +# papi_lib = os.getenv('PAPI_LIB', '/usr/lib') + +hdf5_inc = os.getenv('HDF5_INC') +if hdf5_inc is None: + if os.path.exists('/usr/include/hdf5.h'): + hdf5_inc = '/usr/include' + elif os.path.exists('/usr/include/hdf5/serial/hdf5.h'): + hdf5_inc = '/usr/include/hdf5/serial' + else: + raise Exception('HDF5 include file was not found. Try setting the HDF5_INC environment variable such that $HDF5_INC/hdf5.h exists.') + +hdf5_lib = os.getenv('HDF5_LIB') +if hdf5_lib is None: + if os.path.exists('/usr/lib/libhdf5.a'): + hdf5_lib = '/usr/lib' + elif os.path.exists('/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.a'): + hdf5_lib = '/usr/lib/x86_64-linux-gnu/hdf5/serial' + else: + raise Exception('HDF5 lib file was not found. Try setting the HDF5_LIB environment variable such that $HDF5_LIB/libhdf5.a exists.') + +png_path = os.getenv('LIBPNG_HOME', '/lib/x86_64-linux-gnu') + +boost_inc = os.getenv('BOOST_INC', '/usr/include/boost') +boost_lib = os.getenv('BOOST_LIB', '/usr/lib/x86_64-linux-gnu') + +grackle_path = grackle_path_search(home) + +cello_var = os.environ.get('CELLO_VAR',"net") + +if (cello_var == "net"): + parallel_run = charm_path + "/bin/charmrun +p4 " + parallel_arg = " " + smp = 0 +elif (cello_var == "net-smp"): + parallel_run = charm_path + "/bin/charmrun +p4 " + parallel_arg = " ++ppn 4 " + smp = 1 diff --git a/config/linux_gnu.py b/config/linux_gnu.py new file mode 100755 index 0000000000..a11072c643 --- /dev/null +++ b/config/linux_gnu.py @@ -0,0 +1,69 @@ + +import os +from _common_search_paths import charm_path_search, grackle_path_search + +is_arch_valid = 1 + +# +#flags_arch = '-g -fprofile-arcs -ftest-coverage' # gcov +flags_arch = '-O3 -g -ffast-math -funroll-loops -fPIC' +#flags_arch = '-Wall -O3 -g' +#flags_arch = '-Wall -O0 -g' + +#flags_arch = '-O3 -pg -g' +#flags_arch = '-fprofile-arcs -ftest-coverage' +#flags_arch = '-Wall -g -fsanitize=address -fno-omit-frame-pointer' +#flags_arch = '-Wall -O3 -pg' + +# rdynamic required for backtraces +#flags_link_charm = '-rdynamic' +#flags_link_charm = '-memory paranoid' +#flags_link_charm = '-fprofile-arcs' # gcov + +#optional fortran flag +flags_arch_fortran = '-ffixed-line-length-132' + +cc = 'gcc ' +f90 = 'gfortran' + +flags_prec_single = '' +flags_prec_double = '-fdefault-real-8 -fdefault-double-8' + +libpath_fortran = '/usr/lib/x86_64-linux-gnu' +libs_fortran = ['gfortran'] + +home = os.getenv('HOME') + +# use Charm++ with randomized message queues for debugging and stress-testing +# charm_path = home + '/Charm/charm.random' + +charm_path = charm_path_search(home) + +# use_papi = 1 +# papi_inc = os.getenv('PAPI_INC', '/usr/include') +# papi_lib = os.getenv('PAPI_LIB', '/usr/lib') + +hdf5_inc = os.getenv('HDF5_INC') +if hdf5_inc is None: + if os.path.exists('/usr/include/hdf5.h'): + hdf5_inc = '/usr/include' + elif os.path.exists('/usr/include/hdf5/serial/hdf5.h'): + hdf5_inc = '/usr/include/hdf5/serial' + else: + raise Exception('HDF5 include file was not found. Try setting the HDF5_INC environment variable such that $HDF5_INC/hdf5.h exists.') + +hdf5_lib = os.getenv('HDF5_LIB') +if hdf5_lib is None: + if os.path.exists('/usr/lib/libhdf5.a'): + hdf5_lib = '/usr/lib' + elif os.path.exists('/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.a'): + hdf5_lib = '/usr/lib/x86_64-linux-gnu/hdf5/serial' + else: + raise Exception('HDF5 lib file was not found. Try setting the HDF5_LIB environment variable such that $HDF5_LIB/libhdf5.a exists.') + +png_path = os.getenv('LIBPNG_HOME', '/lib/x86_64-linux-gnu') + +boost_inc = os.getenv('BOOST_INC', '/usr/include/boost') +boost_lib = os.getenv('BOOST_LIB', '/usr/lib/x86_64-linux-gnu') + +grackle_path = grackle_path_search(home) diff --git a/doc/source/design/array.png b/doc/source/design/array.png new file mode 100644 index 0000000000..aea1c9dc07 Binary files /dev/null and b/doc/source/design/array.png differ diff --git a/doc/source/design/infer.png b/doc/source/design/infer.png new file mode 100644 index 0000000000..ba91606fe9 Binary files /dev/null and b/doc/source/design/infer.png differ diff --git a/doc/source/design/inference-array.png b/doc/source/design/inference-array.png new file mode 100644 index 0000000000..a4a0fffeca Binary files /dev/null and b/doc/source/design/inference-array.png differ diff --git a/doc/source/design/io-read.png b/doc/source/design/io-read.png index 4ed170aa53..d44ab1b94d 100644 Binary files a/doc/source/design/io-read.png and b/doc/source/design/io-read.png differ diff --git a/doc/source/design/lowres.png b/doc/source/design/lowres.png new file mode 100644 index 0000000000..947aaa6f90 Binary files /dev/null and b/doc/source/design/lowres.png differ diff --git a/doc/source/param/index.rst b/doc/source/param/index.rst index d389c7beb2..4d6d1dfab7 100644 --- a/doc/source/param/index.rst +++ b/doc/source/param/index.rst @@ -1,9 +1,15 @@ .. include:: ../roles.incl - + ************************* Enzo-E / Cello Parameters ************************* +.. toctree:: + :maxdepth: 1 + :glob: + :titlesonly: + :numbered: + This page documents all current parameters implemented in Enzo-E / Cello. Each parameter is summarized, its type or types are listed, and the default value (if any) is provided. The scope of the @@ -152,7 +158,6 @@ Mesh .. include:: mesh.incl - ------ Method ------ diff --git a/doc/source/param/method.incl b/doc/source/param/method.incl index ce5d70a452..d8a356c2c0 100644 --- a/doc/source/param/method.incl +++ b/doc/source/param/method.incl @@ -31,13 +31,17 @@ * :t:`"ppml"` :e:`for the PPML ideal MHD solver.` *This may be phased out in favor of using a more general "mhd" method instead, with a specific mhd solver specified.* + * :t:`"ppml_it"` :e:`alternate name for "ppml".` + * :t:`"ppml_ig"` :e:`for the adiabatic version of PPML.` *This may be phased + out in favor of using a more general "mhd" method instead, with a + specific mhd solver specified.* * :t:`"mhd_vlct"` :e:`for the VL + CT (van Leer + Constrained Transport) MHD solver.` * :t:`"trace"` :e:`for moving tracer particles.` **This will be phased out in favor of a more general "move_particles" method.** * :t:`"turbulence"` :e:`computes random forcing for turbulence simulations.` - + * :t:`"turbulence_ou"` :e:`implements Ornstein-Uhlenbeck driven turbulence.` :e:`Parameters specific to individual methods are specified in subgroups, e.g.`:: @@ -461,6 +465,12 @@ ppm .. include:: method_ppm.incl +ppml +---- + +.. include:: method_ppml.incl + + sink_maker ---------- @@ -569,6 +579,8 @@ turbulence :Scope: :z:`Enzo` :Todo: :o:`write` + :e:`Prescribes kinetic energy injection rate for a forcing method based on random but constant-in-time external x-, y-, z-acceleration fields. The code would normalize the accelerations so that the resulting actual injection rate is constant during the simulation and equal to edot. For details of the method see` `Mac Low (1999) `_ :e:`The default setting edot=-1 turns this forcing off.` + ---- .. par:parameter:: Method:turbulence:mach_number @@ -578,3 +590,10 @@ turbulence :Default: :d:`0.0` :Scope: :z:`Enzo` :Todo: :o:`write` + + :e:`Specifies the target sonic Mach number for a forced turbulence simulation. If` :p:`mach_number` :e:`is not zero, the energy injection rate will be calculated based on the Mach number.` + +turbulence_ou +------------- + +.. include:: method_turbulence_ou.incl diff --git a/doc/source/param/method_ppml.incl b/doc/source/param/method_ppml.incl new file mode 100644 index 0000000000..266f7fbc09 --- /dev/null +++ b/doc/source/param/method_ppml.incl @@ -0,0 +1,15 @@ + +:p:`Method:ppml` parameters are used to initialize parameters for +Enzo-E's PPML MHD methods. These include "ppml" (or "ppml_it") for the +idealized solver, and "ppml_ig" for the adiabatic version. + +---- + +.. par:parameter:: Method:ppml:dt_weight + + :Summary: :s:`Timestep adjust for Strang splitting` + :Type: :par:typefmt:`float` + :Default: :d:`1.0` + :Scope: :z:`Enzo` + + :e:`This parameter is used to implement Strang splitting to preserve the 2nd order of accurace of time integration of PPML when forcing and cooling/heating source terms are present. In that case dt_weight should be set to 0.5 and PPML called twice in the` :par:paramfmt:`Method:list` :e:` parameter list with methods implementing forcing terms between them. The default is not to use Strang splitting so dt_weight = 1.0` diff --git a/doc/source/param/method_turbulence_ou.incl b/doc/source/param/method_turbulence_ou.incl new file mode 100644 index 0000000000..0f23746869 --- /dev/null +++ b/doc/source/param/method_turbulence_ou.incl @@ -0,0 +1,187 @@ + +:p:`Method:turbulence_ou` parameters are used to initialize parameters +for Enzo-E's Ornstein-Uhlenbeck driven turbulence method. See Section +2.1 on Turbulence Forcing in `Wolfram Schmidt, Numerical Modelling of +Astrophysical Turbulence, Springer 2014 +`_. + + +---- + +.. par:parameter:: Method:turbulence_ou:edot + + :Summary: :s:`edot` + :Type: :par:typefmt:`float` + :Default: :d:`(0.0)` + :Scope: :z:`Enzo` + + :e:`Prescribes the kinetic energy injection rate for Ornstein-Uhlenbeck forcing; goes with` :p:`apply_injection_rate=true.` + + + +---- + +.. par:parameter:: Method:turbulence_ou:mach_number + + :Summary: :s:`mach_number` + :Type: :par:typefmt:`float` + :Default: :d:`(0.0)` + :Scope: :z:`Enzo` + + :e:`Specifies the target sonic Mach number for a forced turbulence simulation. If mach_number is not zero, the energy injection rate will be calculated based on the Mach number.` + +---- + +.. par:parameter:: Method:turbulence_ou:apply_cooling + + :Summary: :s:`apply_cooling` + :Type: :par:typefmt:`logical` + :Default: :d:`(false)` + :Scope: :z:`Enzo` + + :e:`A dummy parameter reserved for future use to include a generalized cooling function in the energy equation, which will be treated as a (possibly stiff) source term similar to the energy source associated with turbulence forcing. Cooling is intended for use as an energy sink balancing energy injection by the forcing if gamma\ne1 (e.g., as in Porter et al. (2002)) or in combination with heating to enable simulations of turbulent multiphase ISM. Cooling and heating functions can be defined analytically (e.g., as piecewise-linear approximations).` + +---- + +.. par:parameter:: Method:turbulence_ou:apply_forcing + + :Summary: :s:`apply_forcing` + :Type: :par:typefmt:`logical` + :Default: :d:`(false)` + :Scope: :z:`Enzo` + + :e:`A switch turning ON the implementation of Ornstein-Uhlenbeck forcing algorithm. If` :p:`apply_forcing=false`:e:`, OU forcing will be turned OFF.` + +---- + +.. par:parameter:: Method:turbulence_ou:apply_injection_rate + + :Summary: :s:`apply_injection_rate` + :Type: :par:typefmt:`logical` + :Default: :d:`(false)` + :Scope: :z:`Enzo` + + :e:`A switch turning ON an implementation of Ornstein-Uhlenbeck (OU) forcing algorithm, which uses a specified injection_rate instead of the Mach number to calculated the pumping. If` :p:`apply_injection_rate=true`:e:`, the OU forcing routine will keep the energy injection rate constant through the simulation, similar to edot in constant-in-time forcing. If` :p:`apply_injection_rate=false`:e:`, the actual injection rate will be free to oscillate around the mean prescribed by the OU algorithm.` + +---- + +.. par:parameter:: Method:turbulence_ou:cooling_term + + :Summary: :s:`cooling_term` + :Type: :par:typefmt:`integer` + :Default: :d:`(0)` + :Scope: :z:`Enzo` + + **Parameter description...** + +---- + +.. par:parameter:: Method:turbulence_ou:hc_alpha + + :Summary: :s:`hc_alpha` + :Type: :par:typefmt:`float` + :Default: :d:`(0.0)` + :Scope: :z:`Enzo` + + :e:`Parameter of the generalized cooling function.` + +---- + +.. par:parameter:: Method:turbulence_ou:hc_sigma + + :Summary: :s:`hc_sigma` + :Type: :par:typefmt:`float` + :Default: :d:`(0.0)` + :Scope: :z:`Enzo` + + :e:`Also a parameter for the cooling term for the case of Stefan's law used in Porter et al. (2002).` + +---- + +.. par:parameter:: Method:turbulence_ou:injection_rate + + :Summary: :s:`injection_rate` + :Type: :par:typefmt:`float` + :Default: :d:`(0.006)` + :Scope: :z:`Enzo` + + **Parameter description...** + +---- + +.. par:parameter:: Method:turbulence_ou:kfa + + :Summary: :s:`kfa` + :Type: :par:typefmt:`float` + :Default: :d:`(12.57)` + :Scope: :z:`Enzo` + + :e:`Maximum wave number for external forcing. The kfa/kfi parameters define a parabolic profile used to normalize contributions of different random modes contributing to the external acceleration fields. Modes with wave number outside the [kfi, kfa] interval are ignored.` + +---- + +.. par:parameter:: Method:turbulence_ou:kfi + + :Summary: :s:`kfi` + :Type: :par:typefmt:`float` + :Default: :d:`(6.27)` + :Scope: :z:`Enzo` + + :e:`Minimum wave number for external forcing.` + +---- + +.. par:parameter:: Method:turbulence_ou:olap + + :Summary: :s:`olap` + :Type: :par:typefmt:`integer` + :Default: :d:`(0)` + :Scope: :z:`Enzo` + + :e:`This is overlap parameter from the "donor" code, which used overlapping grids. It is equal to twice the number of ghost zones in Enzo fluid solvers, e.g.` :p:`olap=8` :e:`in case of 4 ghost zones. Not sure where and why exactly this is used in Enzo-E.` + +---- + +.. par:parameter:: Method:turbulence_ou:read_sol + + :Summary: :s:`read_sol` + :Type: :par:typefmt:`logical` + :Default: :d:`(false)` + :Scope: :z:`Enzo` + + :e:`Also a parameter from the "donor" code. There, it tells if the solution (including current fluid dynamic fields and state variables of OU forcing) should be read from files previously written. If true, the code will mimic a smooth restart from previously computed numerical solution by reading the flow fields and modal content of the OU force. If false, the fields and the forcing state will be calculated as if a new simulation of forced turbulence is initialized.` + +---- + +.. par:parameter:: Method:turbulence_ou:sol_weight + + :Summary: :s:`sol_weight` + :Type: :par:typefmt:`float` + :Default: :d:`(1.0)` + :Scope: :z:`Enzo` + + :e:`Solenoidal fraction of the OU acceleration fields. For purely solenoidal forcing` :p:`sol_weight=1.0`:e:`; for purely compressive forcing` :p:`sol_weight=0.0.` + +---- + +.. par:parameter:: Method:turbulence_ou:totemp + + :Summary: :s:`totemp` + :Type: :par:typefmt:`float` + :Default: :d:`(0.0)` + :Scope: :z:`Enzo` + + **Parameter description...** + +---- + +.. par:parameter:: Method:turbulence_ou:update_solution + + :Summary: :s:`update_solution` + :Type: :par:typefmt:`logical` + :Default: :d:`(false)` + :Scope: :z:`Enzo` + + **Parameter description...** + +---- diff --git a/doc/source/user/problem_method.rst b/doc/source/user/problem_method.rst index cf21151f4c..59201bc11d 100644 --- a/doc/source/user/problem_method.rst +++ b/doc/source/user/problem_method.rst @@ -850,11 +850,16 @@ See :ref:`using-fluid_props-de` for additional details. This method currently ignores all of the floor parameters that are set in the ``physics:fluid_props:floors`` section of the parameter file. -``"ppml"`` method -================= +``"ppml"`` (or ``"ppml_ig"``) method +==================================== PPML ideal MHD solver +``"ppml_it"`` method +==================== + +PPML adiabatic MHD solver + .. _vlct_overview: ``"sink_maker"`` method diff --git a/input/PPML/method_ppml-1.in b/input/PPML/method_ppml-1.in index be71638f53..a8a5aa37d1 100644 --- a/input/PPML/method_ppml-1.in +++ b/input/PPML/method_ppml-1.in @@ -7,7 +7,7 @@ Mesh { root_blocks = [1,1,1]; } Output { dump { name = ["method_ppml-1-%02d-%04d.h5", "proc","cycle"]; } } -Output { d_x { name = ["method_ppml-1-x-%04d.png", "cycle"]; } } -Output { d_y { name = ["method_ppml-1-y-%04d.png", "cycle"]; } } -Output { d_z { name = ["method_ppml-1-z-%04d.png", "cycle"]; } } +Output { d_x { name = ["method_ppml-1-x-%04d.png", "cycle"]; } } +Output { d_y { name = ["method_ppml-1-y-%04d.png", "cycle"]; } } +Output { d_z { name = ["method_ppml-1-z-%04d.png", "cycle"]; } } diff --git a/input/method_ppml-turbou.in b/input/method_ppml-turbou.in new file mode 100644 index 0000000000..7705773828 --- /dev/null +++ b/input/method_ppml-turbou.in @@ -0,0 +1,356 @@ + Adapt { + list = [ "shock", "shear" ]; + max_level = 0; + shear { + store = "refine_shear"; + type = "shear"; + }; + shock { + store = "refine_shock"; + type = "shock"; + }; + } + + Boundary { + type = "periodic"; + } + + Domain { + lower = [ 0.000000000000000, 0.000000000000000, 0.000000000000000 ]; + upper = [ 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + } + + Field { + alignment = 8; + gamma = 1.001000000000000; + ghost_depth = 4; + list = [ "bfieldx", "bfieldx_rx", "bfieldx_ry", "bfieldx_rz", "bfieldy", "bfieldy_rx", "bfieldy_ry", "bfieldy_rz", "bfieldz", "bfieldz_rx", "bfieldz_ry", "bfieldz_rz", "dens_rx", "dens_ry", "dens_rz", "velox", "velox_rx", "velox_ry", "velox_rz", "veloy", "veloy_rx", "veloy_ry", "veloy_rz", "veloz", "veloz_rx", "veloz_ry", "veloz_rz", "acceleration_x", "acceleration_y", "acceleration_z", "density", "driving_x", "driving_y", "driving_z", "internal_energy", "jacobian", "pressure", "refine_shear", "refine_shock", "resid_density", "resid_total_energy", "resid_velocity_x", "resid_velocity_y", "resid_velocity_z", "temperature", "total_energy", "velocity_x", "velocity_y", "velocity_z", "work_1", "work_2", "work_3", "work_4", "work_5", "work_6", "work_7", "acceleration_z", "driving_z", "resid_velocity_z", "velocity_z" ]; + padding = 0; + } + + Initial { + list = [ "value" ]; + value { + acceleration_x = 0.000000000000000; + acceleration_y = 0.000000000000000; + acceleration_z = 0.000000000000000; + bfieldx = 0.1000000000000000; + bfieldx_rx = 0.1000000000000000; + bfieldx_ry = 0.1000000000000000; + bfieldx_rz = 0.1000000000000000; + dens_rx = 1.000000000000000; + dens_ry = 1.000000000000000; + dens_rz = 1.000000000000000; + density = 1.000000000000000; + driving_x = 0.000000000000000; + driving_y = 0.000000000000000; + driving_z = 0.000000000000000; + internal_energy = 0.000000000000000; + temperature = 1.000000000000000; + total_energy = 140.0000000000000; + velocity_x = 0.000000000000000; + velocity_y = 0.000000000000000; + velocity_z = 0.000000000000000; + work_1 = 0.000000000000000; + work_2 = 0.000000000000000; + work_3 = 0.000000000000000; + work_4 = 0.000000000000000; + work_5 = 0.000000000000000; + work_6 = 0.000000000000000; + work_7 = 0.000000000000000; + work_z = 0.000000000000000; + }; + } + + Mesh { + root_blocks = [ 4, 4, 4 ]; + root_rank = 3; + root_size = [ 128, 128, 128 ]; + } + + Method { + list = [ "null", "turbulence_ou", "ppml" ]; + null { + dt = 0.1000000000000000; + }; + ppm { + courant = 0.5000000000000000; + diffusion = true; + dual_energy = false; + flattening = 3; + steepening = true; + }; + turbulence { + courant = 0.5000000000000000; + e_dot = -1.000000000000000; + mach_number = 1.000000000000000; + }; + turbulence_ou { + apply_cooling = false; + apply_forcing = true; + apply_injection_rate = false; + cooling_term = -1; + courant = 0.5000000000000000; + hc_alpha = 10.00000000000000; + hc_sigma = 0.09834480000000000; + injection_rate = 0.01000000000000000; + kfa = 12.57000000000000; + kfi = 6.270000000000000; + mach_number = 0.3000000000000000; + olap = 8; + read_sol = false; + sol_weight = 1.000000000000000; + totemp = 5.952380000000000; + update_solution = true; + }; + } + + Output { + ax_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "acceleration_x" ]; + image_size = [ 512, 512 ]; + name = [ "ax-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + ay_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "acceleration_y" ]; + image_size = [ 512, 512 ]; + name = [ "ay-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + az_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "accelerationy_z" ]; + image_size = [ 512, 512 ]; + name = [ "az-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + checkpoint { + dir = [ "checkpoint-%d", "flipflop" ]; + schedule { + start = 600.0000000000000; + step = 600.0000000000000; + var = "seconds"; + }; + type = "checkpoint"; + }; + de_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "density" ]; + image_size = [ 512, 512 ]; + name = [ "de-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + hdf5 { + name = [ "p%02d-c%04d.h5", "proc", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "data"; + }; + list = [ "checkpoint", "de_png", "vx_png", "vy_png", "ax_png", "ay_png", "w1_png", "w2_png", "w3_png", "w4_png", "w5_png", "w6_png", "w7_png", "vz_png", "az_png" ]; + mesh { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + image_max = 6.000000000000000; + image_min = 0.000000000000000; + image_reduce_type = "max"; + image_size = [ 1025, 1025 ]; + image_type = "mesh"; + name = [ "mesh-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + p_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "pressure" ]; + image_size = [ 512, 512 ]; + name = [ "p-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + refine_shear { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "refine_shear" ]; + image_size = [ 512, 512 ]; + name = [ "refine_shear-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + refine_shock { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "refine_shock" ]; + image_size = [ 512, 512 ]; + name = [ "refine_shock-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + te_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "total_energy" ]; + image_size = [ 512, 512 ]; + name = [ "te-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + vx_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "velocity_x" ]; + image_size = [ 512, 512 ]; + name = [ "vx-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + vy_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "velocity_y" ]; + image_size = [ 512, 512 ]; + name = [ "vy-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + vz_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "velocity_z" ]; + image_size = [ 512, 512 ]; + name = [ "vz-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w1_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_1" ]; + image_size = [ 512, 512 ]; + name = [ "w1-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w2_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_2" ]; + image_size = [ 512, 512 ]; + name = [ "w2-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w3_png { + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_3" ]; + image_size = [ 512, 512 ]; + name = [ "w3-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w4_png { + axis = "z"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_4" ]; + image_lower = [ 0.000000000000000, 0.000000000000000, 0.3750000000000000 ]; + image_size = [ 512, 512 ]; + image_upper = [ 1.000000000000000, 1.000000000000000, 0.3750000000000000 ]; + name = [ "w4-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w5_png { + axis = "x"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_5" ]; + image_lower = [ 0.3750000000000000, 0.000000000000000, 0.000000000000000 ]; + image_size = [ 512, 512 ]; + image_upper = [ 0.3750000000000000, 1.000000000000000, 1.000000000000000 ]; + name = [ "w5-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w6_png { + axis = "y"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_6" ]; + image_lower = [ 0.000000000000000, 0.3750000000000000, 0.000000000000000 ]; + image_size = [ 512, 512 ]; + image_upper = [ 1.000000000000000, 0.3750000000000000, 1.000000000000000 ]; + name = [ "w6-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + w7_png { + axis = "z"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 1.000000000000000, 0.000000000000000, 1.000000000000000, 0.000000000000000, 0.000000000000000 ]; + field_list = [ "work_7" ]; + image_lower = [ 0.000000000000000, 0.000000000000000, 0.3750000000000000 ]; + image_size = [ 512, 512 ]; + image_upper = [ 1.000000000000000, 1.000000000000000, 0.3750000000000000 ]; + name = [ "w7-%04d.png", "count" ]; + schedule { + step = 20; + var = "cycle"; + }; + type = "image"; + }; + } + + Stopping { + cycle = 100; + time = 5.000000000000000; + } diff --git a/input/ppml-turbo-test-it-128.in b/input/ppml-turbo-test-it-128.in new file mode 100644 index 0000000000..cdcda34eb3 --- /dev/null +++ b/input/ppml-turbo-test-it-128.in @@ -0,0 +1,111 @@ + Mesh { + root_rank = 3; + root_blocks = [ 4, 4, 4 ]; + root_size = [ 128, 128, 128 ]; + } + + Domain { + lower = [ 0.0000000000000, 0.0000000000000, 0.0000000000000 ]; + upper = [ 1.0000000000000, 1.0000000000000, 1.0000000000000 ]; + } + + Initial { + list = ["mhd_turbulence_it"]; + mhd_turbulence_it { + density = 1.0000000000000; + bfieldx = 1.0000000000000; + gamma = 1.0000000000000; + } + } + + Boundary { + type = "periodic"; + } + + Stopping { + cycle = 10; + time = 3.0000000; + } + + Method { + list = [ "ppml" , "mhd_turbulence_it"]; + ppml { + courant = 0.3000000000000000; + }; + mhd_turbulence_it { + courant = 0.3; + mach_number = 2.0; + e_dot = -1.0; + }; + } + + Field { + alignment = 8; + gamma = 1.000000000000000; + ghost_depth = 3; + list = [ "density", "velox", "veloy", "veloz", "bfieldx", "bfieldy", "bfieldz", "drivx", "drivy", "drivz", + "dens_rx", "velox_rx", "veloy_rx", "veloz_rx", "bfieldx_rx", "bfieldy_rx", "bfieldz_rx", "drivx_rx", "drivy_rx", "drivz_rx", + "dens_ry", "velox_ry", "veloy_ry", "veloz_ry", "bfieldx_ry", "bfieldy_ry", "bfieldz_ry", "drivx_ry", "drivy_ry", "drivz_ry", + "dens_rz", "velox_rz", "veloy_rz", "veloz_rz", "bfieldx_rz", "bfieldy_rz", "bfieldz_rz", "drivx_rz", "drivy_rz", "drivz_rz" ]; + padding = 0; + } + +Output { + +# NOTE: checkpoint must come first as workaround for bug #55 +# list = [ "d_x", "d_y", "d_z", "dump" ]; +# list = [ "checkpoint", "d_x", "d_y", "d_z", "dump" ]; + list = [ "checkpoint", "d_x", "d_y", "d_z" ]; + checkpoint { + type = "checkpoint"; + dir = ["checkpoint_%03d","count"]; + schedule { var = "seconds"; start=1800.0; step = 1800.0;} + }; + + d_x { + axis = "x"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "density" ]; + image_size = [ 128, 128 ]; + name = [ "turbo-test-ppml-it-x-%04d.png", "cycle" ]; + schedule { + step = 1; + var = "cycle"; + }; + type = "image"; + }; + d_y { + axis = "y"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "density" ]; + image_size = [ 128, 128 ]; + name = [ "turbo-test-ppml-it-y-%04d.png", "cycle" ]; + schedule { + step = 1; + var = "cycle"; + }; + type = "image"; + }; + d_z { + axis = "z"; + colormap = [ 0.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 0.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 0.000000000000000, + 1.000000000000000, 1.000000000000000, 1.000000000000000 ]; + field_list = [ "density" ]; + image_size = [ 128, 128 ]; + name = [ "turbo-test-ppml-it-z-%04d.png", "cycle" ]; + schedule { + step = 1; + var = "cycle"; + }; + type = "image"; + }; + } + diff --git a/input/test_turbulence_ou.in b/input/test_turbulence_ou.in new file mode 100644 index 0000000000..86f64c748a --- /dev/null +++ b/input/test_turbulence_ou.in @@ -0,0 +1,51 @@ +include "input/Hydro/method_turbulence3d.incl" + +Field { + list += [ + "acceleration_x", + "acceleration_y", + "acceleration_z", + "work_1", + "work_2", + "work_3"]; + } + Initial { + list = ["value"]; + turbulence { + density = 1.0000000000000; + temperature = 1.0000000000000; + } + } + +Method { + list = [ "ppm", "turbulence_ou"]; + ppm { + courant = 0.5; + diffusion = true; + dual_energy = false; + flattening = 3; + steepening = true; + } + turbulence_ou { + courant = 0.5; + mach_number = 0.3; + injection_rate = 0.01; + kfa = 12.57; + kfi = 6.27; + olap = 0; + read_sol = false; + sol_weight = 1.0; + totemp = 5.95238; + update_solution = true; + hc_alpha = 10.0; + hc_sigma = 0.0983448; + apply_cooling = false; + apply_forcing = true; + apply_injection_rate = true; + cooling_term = -1; + } +} +Mesh { + root_blocks = [ 2, 2, 2 ]; + root_size = [ 32, 32, 32 ]; + } diff --git a/src/Cello/_data.hpp b/src/Cello/_data.hpp index 2300cfa5ae..b434c4f412 100644 --- a/src/Cello/_data.hpp +++ b/src/Cello/_data.hpp @@ -94,6 +94,9 @@ class FieldFace; #include "data_ItIndexList.hpp" #include "data_ItIndexRange.hpp" +#include "data_Object.hpp" +#include "data_ObjectSphere.hpp" + #include "data_ParticleDescr.hpp" #include "data_ParticleData.hpp" #include "data_Particle.hpp" diff --git a/src/Cello/cello_Sync.hpp b/src/Cello/cello_Sync.hpp index 69a2be4c8d..e5e0e34f2e 100644 --- a/src/Cello/cello_Sync.hpp +++ b/src/Cello/cello_Sync.hpp @@ -52,7 +52,7 @@ class Sync { /// Reset the counter to 0 void reset () throw () ; - + /// Decrement the stopping value by one inline int operator -- () { --index_stop_; return index_stop_; } @@ -87,11 +87,11 @@ class Sync { /// Check whether stop reached void check_done_() throw (); - + private: // attributes int is_done_; - + /// Last value of the parallel sync index int index_stop_; diff --git a/src/Cello/charm_reductions.cpp b/src/Cello/charm_reductions.cpp index 321fd4aac3..d947ef94c6 100644 --- a/src/Cello/charm_reductions.cpp +++ b/src/Cello/charm_reductions.cpp @@ -65,9 +65,6 @@ CkReductionMsg * r_reduce_method_debug(int n, CkReductionMsg ** msgs) const int length = 1 + 4*num_fields; std::vector accum; - ASSERT1 ("r_reduce_method_debug", - "Sanity check failed on expected accumulator array %d", - length, (length < 500)); accum.resize(length); accum.clear(); diff --git a/src/Cello/control_output.cpp b/src/Cello/control_output.cpp index c7c5fbe0d5..586df66bdf 100644 --- a/src/Cello/control_output.cpp +++ b/src/Cello/control_output.cpp @@ -107,7 +107,6 @@ void Problem::output_next(Simulation * simulation) throw() void Simulation::output_start(int index_output) { - TRACE_OUTPUT("Simulation::output_start()"); Output * output = problem()->output(index_output); output->init(); output->open(); @@ -119,6 +118,7 @@ void Simulation::output_start(int index_output) void Simulation::r_output_barrier(CkReductionMsg * msg) { + TRACE_OUTPUT("Simulation::output_barrier()"); delete msg; Output * output = problem()->output(index_output_); output->write_simulation(this); diff --git a/src/Cello/control_refresh.cpp b/src/Cello/control_refresh.cpp index c558f14cf9..bfed7125d5 100644 --- a/src/Cello/control_refresh.cpp +++ b/src/Cello/control_refresh.cpp @@ -201,7 +201,6 @@ void Block::p_refresh_recv (MsgRefresh * msg_refresh) { const int id_refresh = msg_refresh->id_refresh(); CHECK_ID(id_refresh); - Sync * sync = sync_(id_refresh); if (sync->state() == RefreshState::READY) { diff --git a/src/Cello/control_stopping.cpp b/src/Cello/control_stopping.cpp index f1df80571c..c4d7e5bc4f 100644 --- a/src/Cello/control_stopping.cpp +++ b/src/Cello/control_stopping.cpp @@ -65,7 +65,8 @@ void Block::stopping_begin_() Method * method; double dt_block = std::numeric_limits::max(); while ((method = problem->method(index++))) { - dt_block = std::min(dt_block,method->timestep(this)); + double dt_method = method->timestep(this); + dt_block = std::min(dt_block,dt_method); } // Reduce timestep to coincide with scheduled output if needed diff --git a/src/Cello/data_FieldData.cpp b/src/Cello/data_FieldData.cpp index 7b5066175e..4fd79e9452 100644 --- a/src/Cello/data_FieldData.cpp +++ b/src/Cello/data_FieldData.cpp @@ -588,9 +588,9 @@ int FieldData::field_size ( const FieldDescr * field_descr, int id_field, - int * nx, - int * ny, - int * nz + int * mx, + int * my, + int * mz ) const throw() { // Adjust memory usage due to ghosts if needed @@ -609,9 +609,9 @@ int FieldData::field_size // Compute array size - if (nx) (*nx) = size_[0] + 2*gx + cx; - if (ny) (*ny) = size_[1] + 2*gy + cy; - if (nz) (*nz) = size_[2] + 2*gz + cz; + if (mx) (*mx) = size_[0] + 2*gx + cx; + if (my) (*my) = size_[1] + 2*gy + cy; + if (mz) (*mz) = size_[2] + 2*gz + cz; // Return array size in bytes @@ -620,9 +620,9 @@ int FieldData::field_size int bytes_total = bytes_per_element; - if (nx) bytes_total *= (*nx); - if (ny) bytes_total *= (*ny); - if (nz) bytes_total *= (*nz); + if (mx) bytes_total *= (*mx); + if (my) bytes_total *= (*my); + if (mz) bytes_total *= (*mz); return bytes_total; } diff --git a/src/Cello/data_FieldDescr.cpp b/src/Cello/data_FieldDescr.cpp index c8056aaf7b..0778a5e959 100644 --- a/src/Cello/data_FieldDescr.cpp +++ b/src/Cello/data_FieldDescr.cpp @@ -145,7 +145,6 @@ void FieldDescr::ghost_depth int FieldDescr::insert_permanent(const std::string & field_name) throw() { - bool permanent; int id = insert_(field_name, permanent = true); diff --git a/src/Cello/data_Object.hpp b/src/Cello/data_Object.hpp new file mode 100644 index 0000000000..8e8e17b291 --- /dev/null +++ b/src/Cello/data_Object.hpp @@ -0,0 +1,68 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file data_Object.hpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date 2022-11-12 +/// @brief [\ref Data] Declaration of the Object class + +#ifndef DATA_OBJECT_HPP +#define DATA_OBJECT_HPP + +class Object : public PUP::able { + + /// @class Object + /// @ingroup Data + /// @brief [\ref Data] + +public: // interface + + /// Constructor + Object() throw() + { } + + /// Charm++ PUP::able declarations + PUPable_abstract(Object); + + Object (CkMigrateMessage *m) + : PUP::able(m) + { } + + /// Copy constructor + Object(const Object & Object) throw() + { } + + /// Assignment operator + Object & operator= (const Object & Object) throw() + { } + + /// Destructor + virtual ~Object() throw() + { } + + /// CHARM++ Pack / Unpack function + void pup (PUP::er &p) + { + TRACEPUP; + PUP::able::pup(p); + } + +public: // virtual methods + + virtual void draw() { } + virtual void print(std::string) = 0; + + virtual int data_size () const = 0; + virtual char * save_data (char * buffer) const = 0; + virtual char * load_data (char * buffer) = 0; + +private: // functions + + +private: // attributes + + // NOTE: change pup() function whenever attributes change + +}; + +#endif /* DATA_OBJECT_HPP */ + diff --git a/src/Cello/data_ObjectSphere.hpp b/src/Cello/data_ObjectSphere.hpp new file mode 100644 index 0000000000..435fb21b48 --- /dev/null +++ b/src/Cello/data_ObjectSphere.hpp @@ -0,0 +1,126 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file data_ObjectSphere.hpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date 2022-11-12 +/// @brief [\ref Data] Declaration of the ObjectSphere class + +#ifndef DATA_OBJECT_SPHERE_HPP +#define DATA_OBJECT_SPHERE_HPP + +class ObjectSphere : public Object { + + /// @class ObjectSphere + /// @ingroup Data + /// @brief [\ref Data] + +public: // interface + + /// Constructor + ObjectSphere(double center[3], double radius) throw() + : Object(), + radius_(radius) + { + center_[0] = center[0]; + center_[1] = center[1]; + center_[2] = center[2]; + }; + + ObjectSphere() throw() + : Object() + { }; + + /// Charm++ PUP::able declarations + PUPable_decl(ObjectSphere); + + ObjectSphere (CkMigrateMessage *m) + : Object(m), + center_(), + radius_(0) + { } + + /// CHARM++ Pack / Unpack function + void pup (PUP::er &p) + { + TRACEPUP; + + Object::pup(p); + PUParray(p,center_,3); + p | radius_; + } + + ///-------------------- + /// PACKING / UNPACKING + ///-------------------- + + /// Return the number of bytes required to serialize the data object + int data_size () const + { + //-------------------------------------------------- + // 1. determine buffer size (must be consistent with #3) + //-------------------------------------------------- + + int size = 0; + + SIZE_ARRAY_TYPE(size,double,center_,3); + SIZE_SCALAR_TYPE(size,double,radius_); + + return size; + } + + //---------------------------------------------------------------------- + + /// Serialize the object into the provided empty memory buffer. + /// Returns the next open position in the buffer to simplify + /// serializing multiple objects in one buffer. + char * save_data (char * buffer) const + { + char * pc = buffer; + + SAVE_ARRAY_TYPE(pc,double,center_,3); + SAVE_SCALAR_TYPE(pc,double,radius_); + + ASSERT2 ("ObjectSphere::save_data()", + "Expecting buffer size %d actual size %d", + data_size(),(pc-buffer), + (data_size() == (pc-buffer))); + + return pc; + } + + //---------------------------------------------------------------------- + + /// Restore the object from the provided initialized memory buffer data. + /// Returns the next open position in the buffer to simplify + /// serializing multiple objects in one buffer. + char * load_data (char * buffer) + { + char * pc = buffer; + + LOAD_ARRAY_TYPE(pc,double,center_,3); + LOAD_SCALAR_TYPE(pc,double,radius_); + + return pc; + } + +public: // virtual methods + + virtual void draw() { CkPrintf ("ObjectSphere::draw()\n"); } + virtual void print(std::string msg) { + CkPrintf ("ObjectSphere::print() %s center %g %g %g radius %g\n", + msg.c_str(), center_[0],center_[1],center_[2],radius_); } + +private: // functions + + +private: // attributes + + // NOTE: change pup() function whenever attributes change + + double center_[3]; + double radius_; + +}; + +#endif /* DATA_OBJECT_SPHERE_HPP */ + diff --git a/src/Cello/disk_FileHdf5.cpp b/src/Cello/disk_FileHdf5.cpp index 0f75c66e67..398e5f7f21 100644 --- a/src/Cello/disk_FileHdf5.cpp +++ b/src/Cello/disk_FileHdf5.cpp @@ -326,7 +326,8 @@ void FileHdf5::data_read // error check H5Dread - ASSERT1("FileHdf5::data_read","H5Dread() returned %d",retval,(retval>=0)); + ASSERT3("FileHdf5::data_read","H5Dread() returned %d file %s data %s", + retval,file_name.c_str(),data_name_.c_str(),(retval>=0)); } diff --git a/src/Cello/error_Error.hpp b/src/Cello/error_Error.hpp index c8ec7a39dc..4002e0cee1 100644 --- a/src/Cello/error_Error.hpp +++ b/src/Cello/error_Error.hpp @@ -91,6 +91,14 @@ /// @brief Placeholder for code that is incomplete #define INCOMPLETE(M) \ { cello::message(stdout,"INCOMPLETE",__FILE__,__LINE__,"",M); } +#define INCOMPLETE1(M,A1) \ + { cello::message(stdout,"INCOMPLETE",__FILE__,__LINE__,"",M,A1); } +#define INCOMPLETE2(M,A1,A2) \ + { cello::message(stdout,"INCOMPLETE",__FILE__,__LINE__,"",M,A1,A2); } +#define INCOMPLETE3(M,A1,A2,A3) \ + { cello::message(stdout,"INCOMPLETE",__FILE__,__LINE__,"",M,A1,A2,A3); } +#define INCOMPLETE4(M,A1,A2,A3,A4) \ + { cello::message(stdout,"INCOMPLETE",__FILE__,__LINE__,"",M,A1,A2,A3,A4); } //---------------------------------------------------------------------- /// @def TRACE diff --git a/src/Cello/extract_field.cpp b/src/Cello/extract_field.cpp new file mode 100644 index 0000000000..dadb2c8e8d --- /dev/null +++ b/src/Cello/extract_field.cpp @@ -0,0 +1,206 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file extract_field.cpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date 2022-05-21 +/// @brief Program for extracting fields from checkpoint or data dumps + +#include "main.hpp" +#include "test.hpp" +#include "disk.hpp" +#include "memory.hpp" +#include +#include +#include "omp.h" + +// #define TRACE_MEM +#define VERBOSE +Main::Main(CkArgMsg* m) + : count_exit_(0), count_checkpoint_(0), + monitor_(NULL), fp_text_(), sync_text_() +{ + PARALLEL_INIT; + + int np = omp_get_num_threads(); + + Memory * memory = Memory::instance(); + long long bytes_0 = memory->bytes(); +#pragma omp parallel + { + if (omp_get_thread_num() == 0) { + np = omp_get_num_threads(); + } + } + CkPrintf ("num_threads = %d\n",np); + + // Read in list of h5 files "file_list" from provided directory + std::vector file_list; + int n_file; + const int n_field=m->argc - 2; + double t0 = omp_get_wtime(); + if (m->argc>1) { + std::string file_name = std::string(m->argv[1]) + "/check.file_list"; + std::ifstream file_stream; + file_stream.open(file_name); + file_stream >> n_file; + file_list.resize(n_file); + for (int i_f=0; i_f> file_list[i_f]; + } + file_stream.close(); + } else { + CkPrintf ("\n\n Usage: %s [ ... ]\n\n",m->argv[0]); + CkExit(); + } + const std::string path = std::string(m->argv[1]) + "/"; + int type_data=-1, mox=1,moy=1,moz=1; + FileHdf5 ** hdf5_out = new FileHdf5 *[n_field]; + + // Create output files for fields + cello_float ** field_out = new cello_float * [n_field]; + + for (int i_field=0; i_fieldargv[i_field+2]; + // Open output file for field + hdf5_out[i_field] = new FileHdf5(".",field + ".h5"); + hdf5_out[i_field]->file_create(); + + // Loop over data files, extracting current field and writing + } + + int count=0; + #pragma omp parallel for + for (int i_file=0; i_file> name_block; + block_stream >> level; + if (name_block.size() > 0 && level == 0) { + std::string group_name = "/" + name_block; + hdf5_in.group_chdir(group_name); + hdf5_in.group_open(); + + int is_leaf; + hdf5_in.group_read_meta(&is_leaf,"is_leaf",&type_scalar,&tx,&ty,&tz); + + if (is_leaf && level >= 0) { + int array[3]; + hdf5_in.group_read_meta(array,"array",&type_scalar,&tx,&ty,&tz); + int m4[4]; + + // Open input dataset + for (int i_field=0; i_fieldargv[i_field+2]; + std::string dataset_name = std::string("field_") + field; + hdf5_in.data_open (dataset_name, &type_data, + m4,m4+1,m4+2,m4+3); + int n4[4] = {1,1,1,1},o4[4] = {0,0,0,0}; + n4[0] = m4[0]; + n4[1] = m4[1]; + n4[2] = m4[2]; + const int gx=(m4[0]-nx)/2; + const int gy=(m4[1]-ny)/2; + const int gz=(m4[2]-nz)/2; + const int ox=array[0]*nx; + const int oy=array[1]*ny; + const int oz=array[2]*nz; + hdf5_in. data_slice + (m4[0],m4[1],m4[2],m4[3], + n4[0],n4[1],n4[2],n4[3], + o4[0],o4[1],o4[2],o4[3]); + + hdf5_in.mem_create (m4[0],m4[1],m4[2],m4[0],m4[1],m4[2],0,0,0); + cello_float * field_in = new cello_float [m4[0]*m4[1]*m4[2]]; + #pragma omp critical + if (field_out[i_field] == nullptr) { + field_out[i_field] = new cello_float [(long long)mox*moy*moz]; +#ifdef TRACE_MEM + CkPrintf ("TRACE_MEM %d + %Ld\n",i_field,(long long)mox*moy*moz*sizeof(cello_float)); +#endif + } +#ifdef TRACE_MEM + CkPrintf ("TRACE_MEM %d + %Ld\n",i_field,(long long)m4[0]*m4[1]*m4[2]*sizeof(cello_float)); +#endif + hdf5_in.data_read (field_in); + for (int iz=0; izargv[i_field+2]; + hdf5_out[i_field]->group_chdir (std::string("/") + field); + hdf5_out[i_field]->group_create(); + hdf5_out[i_field]->mem_create(mox,moy,moz,mox,moy,moz,0,0,0); + hdf5_out[i_field]->data_create(field,type_data,moz,moy,mox,1,moz,moy,mox,1); + CkPrintf ("\n writing %d %d %d field %s in %s.h5\n\n", + mox,moy,moz,field.c_str(),field.c_str()); + hdf5_out[i_field]->data_write(field_out[i_field]); + hdf5_out[i_field]->file_close(); + delete [] field_out[i_field]; +#ifdef TRACE_MEM + CkPrintf ("TRACE_MEM %d - %Ld\n",i_field,(long long)mox*moy*moz*sizeof(cello_float)); +#endif + field_out[i_field] = nullptr; + } + + double t1 = omp_get_wtime(); + CkPrintf ("%4.2f Done\n",t1-t0); + exit_(); + +} +PARALLEL_MAIN_END diff --git a/src/Cello/io_IoBlock.cpp b/src/Cello/io_IoBlock.cpp index 1be7a8aa1b..7e670f25b7 100644 --- a/src/Cello/io_IoBlock.cpp +++ b/src/Cello/io_IoBlock.cpp @@ -20,6 +20,7 @@ IoBlock::IoBlock() throw () meta_name_.push_back("time"); meta_name_.push_back("dt"); meta_name_.push_back("array"); + meta_name_.push_back("is_leaf"); meta_name_.push_back("index_order"); meta_name_.push_back("count_order"); } @@ -39,6 +40,7 @@ void IoBlock::set_block (Block * block) throw() time_ = block->time_; dt_ = block->dt_; for (i=0; i<3; i++) array_[i] = block->array_[i]; + is_leaf_ = block->is_leaf_ ? 1 : 0; block->get_order(&index_order_, &count_order_); } @@ -81,6 +83,9 @@ void IoBlock::meta_value *buffer = (void *) & array_; *type = type_int; *nxd = 3; + } else if (index == count++) { + *buffer = (void *) & is_leaf_; + *type = type_int; } else if (index == count++) { *buffer = (void *) & index_order_; *type = type_long_long; @@ -105,6 +110,7 @@ int IoBlock::data_size () const SIZE_SCALAR_TYPE(size,double, time_); SIZE_SCALAR_TYPE(size,double, dt_); SIZE_ARRAY_TYPE(size,int,array_,3); + SIZE_SCALAR_TYPE(size,int,is_leaf_); SIZE_SCALAR_TYPE(size,long long, index_order_); SIZE_SCALAR_TYPE(size,long long, count_order_); @@ -127,6 +133,7 @@ char * IoBlock::save_data (char * buffer) const SAVE_SCALAR_TYPE(pc,double, time_); SAVE_SCALAR_TYPE(pc,double, dt_); SAVE_ARRAY_TYPE(pc,int,array_,3); + SAVE_SCALAR_TYPE(pc,int, is_leaf_); SAVE_SCALAR_TYPE(pc,long long, index_order_); SAVE_SCALAR_TYPE(pc,long long, count_order_); @@ -155,6 +162,7 @@ char * IoBlock::load_data (char * buffer) LOAD_SCALAR_TYPE(pc,double, time_); LOAD_SCALAR_TYPE(pc,double, dt_); LOAD_ARRAY_TYPE(pc,int,array_,3); + LOAD_SCALAR_TYPE(pc,int,is_leaf_); LOAD_SCALAR_TYPE(pc,long long, index_order_); LOAD_SCALAR_TYPE(pc,long long, count_order_); @@ -177,6 +185,7 @@ void IoBlock::save_to (void * v) b->cycle_ = cycle_; b->time_ = time_; b->dt_ = dt_; + b->is_leaf_ = is_leaf_; b->set_order(index_order_, count_order_); } diff --git a/src/Cello/io_IoBlock.hpp b/src/Cello/io_IoBlock.hpp index 94397c14b3..e706b77a46 100644 --- a/src/Cello/io_IoBlock.hpp +++ b/src/Cello/io_IoBlock.hpp @@ -48,6 +48,7 @@ class IoBlock : public Io { p | time_; p | dt_; PUParray(p,array_,3); + p | is_leaf_; p | index_order_; p | count_order_; } @@ -106,6 +107,8 @@ class IoBlock : public Io { CkPrintf ("DEBUG_IO_BLOCK dt_ %g\n", dt_); CkPrintf ("DEBUG_IO_BLOCK array_ %d %d %d\n", array_[0], array_[1], array_[2]); + CkPrintf ("DEBUG_IO_BLOCK is_leaf_ %d\n", + is_leaf_); CkPrintf ("DEBUG_IO_BLOCK index_order_ %lld\n", index_order_); CkPrintf ("DEBUG_IO_BLOCK count_order_ %lld\n", count_order_); } @@ -119,6 +122,7 @@ class IoBlock : public Io { double time_; double dt_; int array_[3]; + int is_leaf_; long long index_order_; long long count_order_; diff --git a/src/Cello/io_IoHierarchy.cpp b/src/Cello/io_IoHierarchy.cpp index c6a6011ae8..20c8adcd46 100644 --- a/src/Cello/io_IoHierarchy.cpp +++ b/src/Cello/io_IoHierarchy.cpp @@ -12,15 +12,20 @@ IoHierarchy::IoHierarchy(const Hierarchy * hierarchy) throw () : Io() { + meta_name_.push_back("max_level"); meta_name_.push_back("lower"); meta_name_.push_back("upper"); - meta_name_.push_back("max_level"); + meta_name_.push_back("root_size"); + meta_name_.push_back("blocking"); + + max_level_ = hierarchy->max_level_; int i; for (i=0; i<3; i++) { lower_[i] = hierarchy->lower_[i]; upper_[i] = hierarchy->upper_[i]; + root_size_[i] = hierarchy->root_size_[i]; + blocking_[i] = hierarchy->blocking_[i]; } - max_level_ = hierarchy->max_level_; } @@ -37,10 +42,15 @@ void IoHierarchy::meta_value if (index == count++) { + *buffer = (void *) & max_level_; + *type = type_int; + + } else if (index == count++) { + *buffer = (void *) lower_; *type = type_double; *nxd = 3; - + } else if (index == count++) { *buffer = (void *) upper_; @@ -49,8 +59,15 @@ void IoHierarchy::meta_value } else if (index == count++) { - *buffer = (void *) & max_level_; + *buffer = (void *) root_size_; *type = type_int; + *nxd = 3; + + } else if (index == count++) { + + *buffer = (void *) blocking_; + *type = type_int; + *nxd = 3; } } @@ -61,9 +78,11 @@ void IoHierarchy::save_to (void * v) { Hierarchy * h = static_cast (v); + h->max_level_ = max_level_; for (int i=0; i<3; i++) { h->lower_[i] = lower_[i]; h->upper_[i] = upper_[i]; + h->root_size_[i] = root_size_[i]; + h->blocking_[i] = blocking_[i]; } - h->max_level_ = max_level_; } diff --git a/src/Cello/io_IoHierarchy.hpp b/src/Cello/io_IoHierarchy.hpp index a848d34819..41c4b2272f 100644 --- a/src/Cello/io_IoHierarchy.hpp +++ b/src/Cello/io_IoHierarchy.hpp @@ -41,9 +41,11 @@ class IoHierarchy : public Io { Io::pup(p); + p | max_level_; PUParray(p,lower_,3); PUParray(p,upper_,3); - p | max_level_; + PUParray(p,root_size_,3); + PUParray(p,blocking_,3); } @@ -58,9 +60,11 @@ class IoHierarchy : public Io { private: // attributes + int max_level_; double lower_[3]; double upper_[3]; - int max_level_; + int blocking_[3]; + int root_size_[3]; }; diff --git a/src/Cello/io_IoSimulation.cpp b/src/Cello/io_IoSimulation.cpp index e314d99dca..2af719e2b7 100644 --- a/src/Cello/io_IoSimulation.cpp +++ b/src/Cello/io_IoSimulation.cpp @@ -22,7 +22,6 @@ IoSimulation::IoSimulation(const Simulation * s) throw () meta_name_.push_back("dt"); } - //---------------------------------------------------------------------- void IoSimulation::meta_value diff --git a/src/Cello/io_OutputData.cpp b/src/Cello/io_OutputData.cpp index f6a4cdce44..4c0617fa77 100644 --- a/src/Cello/io_OutputData.cpp +++ b/src/Cello/io_OutputData.cpp @@ -19,7 +19,7 @@ OutputData::OutputData int index, const Factory * factory, Config * config -) throw () + ) throw () : Output(index,factory), text_block_count_(0) { @@ -27,16 +27,16 @@ OutputData::OutputData int stride; -#ifdef TRACE_OUTPUT +#ifdef TRACE_OUTPUT CkPrintf ("%d TRACE_OUTPUT output_stride_write = %d\n",CkMyPe(), config->output_stride_write[index_]); CkPrintf ("%d TRACE_OUTPUT output_stride_wait = %d\n",CkMyPe(), config->output_stride_wait[index_]); -#endif +#endif stride = config->output_stride_write[index_]; set_stride_write ((stride == 0) ? 1 : stride); - + stride = config->output_stride_wait[index_]; stride_wait_ = (stride == 0) ? 1 : stride; } @@ -67,13 +67,13 @@ void OutputData::pup (PUP::er &p) void OutputData::open () throw() { #ifdef TRACE_OUTPUT - CkPrintf ("%d TRACE_OUTPUT OutputData::open()\n",CkMyPe()); -#endif - std::string file_name = expand_name_(&file_name_,&file_args_); + CkPrintf ("%d TRACE_OUTPUT OutputData::open()\n",CkMyPe()); +#endif + std::string file_name = expand_name_(&file_name_,&file_args_); - std::string dir = directory(); + std::string dir = directory(); - Monitor::instance()->print + Monitor::instance()->print ("Output","writing data file %s", (dir + "/" + file_name).c_str()); @@ -87,8 +87,8 @@ void OutputData::open () throw() void OutputData::close () throw() { #ifdef TRACE_OUTPUT - CkPrintf ("%d TRACE_OUTPUT OutputData::close()\n",CkMyPe()); -#endif + CkPrintf ("%d TRACE_OUTPUT OutputData::close()\n",CkMyPe()); +#endif if (file_) file_->file_close(); delete file_; file_ = 0; } @@ -98,8 +98,8 @@ void OutputData::close () throw() void OutputData::finalize () throw () { #ifdef TRACE_OUTPUT - CkPrintf ("%d TRACE_OUTPUT OutputData::finalize()\n",CkMyPe()); -#endif + CkPrintf ("%d TRACE_OUTPUT OutputData::finalize()\n",CkMyPe()); +#endif Output::finalize(); } @@ -126,8 +126,8 @@ void OutputData::write_hierarchy ( const Hierarchy * hierarchy ) throw() void OutputData::write_block ( const Block * block ) throw() { #ifdef TRACE_OUTPUT - CkPrintf ("%d TRACE_OUTPUT OutputData::write_block()\n",CkMyPe()); -#endif + CkPrintf ("%d TRACE_OUTPUT OutputData::write_block()\n",CkMyPe()); +#endif char file[256]; char dir[256]; @@ -151,7 +151,7 @@ void OutputData::write_block ( const Block * block ) throw() const int num_blocks = cello::hierarchy()->num_blocks(); int count = 0; - + // Write DIR.parameters file if (block->index().is_root()) { @@ -160,36 +160,36 @@ void OutputData::write_block ( const Block * block ) throw() std::string libconfig_file_name = name_dir+"/"+name_file+".libconfig"; g_parameters.write(libconfig_file_name.c_str(),param_write_libconfig); } - + // Contribute to DIR.block_list file - + count = (text_block_count_ == 0) ? num_blocks : 0; sprintf (file,"%s.block_list",name_file.c_str()); sprintf (dir, "%s", name_dir.c_str()); sprintf (line,"%s %s\n", block->name().c_str(),name_out_file.c_str()); - + proxy_main.p_text_file_write(strlen(dir)+1, dir, strlen(file)+1, file, strlen(line)+1, line, count); - + // Contribute to DIR.file_list file if (text_block_count_ == 0) { - + count = 0; - + sprintf (file,"%s.file_list",name_file.c_str()); sprintf (dir, "%s", name_dir.c_str()); sprintf (line,"%s\n", name_out_file.c_str()); - + proxy_main.p_text_file_write(strlen(dir)+1, dir, strlen(file)+1, file, strlen(line)+1, line, count); - } + } // Increment block counter @@ -220,9 +220,9 @@ void OutputData::write_block ( const Block * block ) throw() //---------------------------------------------------------------------- void OutputData::write_field_data -( - const FieldData * field_data, - int index_field) throw() +( + const FieldData * field_data, + int index_field) throw() { io_field_data()->set_field_data((FieldData*)field_data); io_field_data()->set_field_index(index_field); @@ -233,7 +233,7 @@ void OutputData::write_field_data int nxd,nyd,nzd; // Array dimension int nx,ny,nz; // Array size - io_field_data()->field_array(&buffer, &name, &type, + io_field_data()->field_array(&buffer, &name, &type, &nxd,&nyd,&nzd, &nx, &ny, &nz); @@ -259,7 +259,7 @@ void OutputData::write_particle_data int it) throw() { ParticleDescr * particle_descr = cello::particle_descr(); - + const Particle particle ( (ParticleDescr*) particle_descr, (ParticleData*) particle_data); @@ -268,7 +268,7 @@ void OutputData::write_particle_data io_particle_data()->set_particle_data ( (ParticleData*) particle_data); io_particle_data()->set_particle_index(it); - // loop through attributes + // loop through attributes // loop through blocks // write particle data for [it][ib][ia] @@ -283,50 +283,49 @@ void OutputData::write_particle_data const std::string name = "particle_" + particle.type_name(it) + "_" + particle.attribute_name(it,ia); - + const int type = particle.attribute_type(it,ia); // create the disk array file_->data_create(name.c_str(),type,np,1,1,1,np,1,1,1); - + int i0 = 0; // for each batch of particles - + for (int ib=0; ibmem_create(mb,1,1,mb,1,1,0,0,0); - + const void * buffer = (const void *) particle.attribute_array(it,ia,ib); // find the hyper_slab of the disk dataset file_->data_slice - (np, 1, 1, 1, - mb, 1, 1, 1, - i0, 0, 0, 0); - + (np, 1, 1, 1, + mb, 1, 1, 1, + i0, 0, 0, 0); + i0 += mb; // write the batch to disk file_->data_write(buffer); - + file_->mem_close(); } // check that the number of particles equals the number written - + ASSERT2 ("OutputData::write_particle_data()", - "Particle count mismatch %d particles %d written", - np,i0, - np == i0); + "Particle count mismatch %d particles %d written", + np,i0, + np == i0); // close the attribute dataset file_->data_close(); } - } //====================================================================== diff --git a/src/Cello/io_OutputImage.cpp b/src/Cello/io_OutputImage.cpp index 5585ae7e41..6e2f727ce4 100644 --- a/src/Cello/io_OutputImage.cpp +++ b/src/Cello/io_OutputImage.cpp @@ -814,7 +814,7 @@ void OutputImage::image_write_ () throw() if (min <= value && value <= max) { // map v to lower colormap index - size_t k = (n - 1)*(value - min) / (max-min); + size_t k = (max>min)?(n - 1)*(value - min) / (max-min) : n/2; // prevent k == colormap_[0].size()-1, which happens if value == max @@ -824,7 +824,7 @@ void OutputImage::image_write_ () throw() double lo = min + k *(max-min)/(n-1); double hi = min + (k+1)*(max-min)/(n-1); - double ratio = (value - lo) / (hi-lo); + double ratio = (hi>lo)?(value - lo) / (hi-lo) : 0.5; r = (1-ratio)*colormap_[0][k] + ratio*colormap_[0][k+1]; g = (1-ratio)*colormap_[1][k] + ratio*colormap_[1][k+1]; diff --git a/src/Cello/main.cpp b/src/Cello/main.cpp index 060ce59037..6e310f0868 100644 --- a/src/Cello/main.cpp +++ b/src/Cello/main.cpp @@ -110,8 +110,8 @@ void Main::p_checkpoint_output(int count, std::string dir_name) CkPrintf ("Calling CkStartCheckpoint\n"); CkCallback callback(CkIndex_EnzoSimulation::r_write_checkpoint_output(),proxy_simulation); CkStartCheckpoint (dir_checkpoint_,callback,false,1); - // "OLD" CHARM++ (version < 7.0.0) USE: - //CkStartCheckpoint (dir_checkpoint_,callback); + // "OLD" CHARM++ (version < 7.0.0) USE: + // CkStartCheckpoint (dir_checkpoint_,callback); #endif } // -------------------------------------------------- diff --git a/src/Cello/mesh.ci b/src/Cello/mesh.ci index 1ab3796149..dd5a150e74 100644 --- a/src/Cello/mesh.ci +++ b/src/Cello/mesh.ci @@ -59,6 +59,7 @@ module mesh { PUPable MethodOutput; PUPable MethodRefresh; PUPable MethodTrace; + PUPable ObjectSphere; PUPable OutputCheckpoint; PUPable OutputData; PUPable OutputImage; diff --git a/src/Cello/mesh_Hierarchy.cpp b/src/Cello/mesh_Hierarchy.cpp index b2aa0d97c5..fb369060b4 100644 --- a/src/Cello/mesh_Hierarchy.cpp +++ b/src/Cello/mesh_Hierarchy.cpp @@ -51,11 +51,11 @@ Hierarchy::Hierarchy num_blocks_level_.resize(max_level - min_level + 1); for (int i=0; i<3; i++) { - root_size_[i] = 1; lower_[i] = 0.0; upper_[i] = 1.0; blocking_[i] = 0; periodicity_[i] = 0; + root_size_[i] = 1; } } @@ -103,12 +103,12 @@ void Hierarchy::pup (PUP::er &p) p | block_array_; - PUParray(p,root_size_,3); PUParray(p,lower_,3); PUParray(p,upper_,3); PUParray(p,blocking_,3); PUParray(p,periodicity_,3); + PUParray(p,root_size_,3); } @@ -182,11 +182,19 @@ void Hierarchy::upper(double * x, double * y, double * z) const throw () //---------------------------------------------------------------------- -void Hierarchy::root_blocks (int * nbx, int * nby, int * nbz) const throw() +void Hierarchy::root_blocks +(int * nbx, int * nby, int * nbz,int level) const throw() { if (nbx) (*nbx) = blocking_[0]; if (nby) (*nby) = blocking_[1]; if (nbz) (*nbz) = blocking_[2]; + if (level > 0) { + const int r = std::pow(2,level); + const int rank = cello::rank(); + if (nbx && rank >= 1) (*nbx) *= r; + if (nby && rank >= 2) (*nby) *= r; + if (nbz && rank >= 3) (*nbz) *= r; + } } //---------------------------------------------------------------------- diff --git a/src/Cello/mesh_Hierarchy.hpp b/src/Cello/mesh_Hierarchy.hpp index d655f23aff..1a0f35cdf1 100644 --- a/src/Cello/mesh_Hierarchy.hpp +++ b/src/Cello/mesh_Hierarchy.hpp @@ -38,11 +38,11 @@ class Hierarchy { block_array_() { for (int axis=0; axis<3; axis++) { - root_size_[axis] = 0; lower_[axis] = 0.0; upper_[axis] = 0.0; blocking_[axis] = 0; periodicity_[axis] = 0; + root_size_[axis] = 0; } } @@ -65,11 +65,10 @@ class Hierarchy { /// Set domain upper extent void set_upper(double x, double y, double z) throw (); - - /// Set root-level grid size + /// Set root-level grid size in cells void set_root_size(int nx, int ny, int nz) throw (); - /// Set root-level grid size + /// Set root-level grid size in blocks void set_blocking(int nbx, int nby, int nbz) throw (); //---------------------------------------------------------------------- @@ -197,13 +196,14 @@ class Hierarchy { { return num_zones_total_; } CProxy_Block new_block_proxy (bool allocate_data) throw(); - + void create_block_array () throw(); void create_subblock_array () throw(); /// Return the number of root-level Blocks along each rank - void root_blocks (int * nbx, int * nby=0, int * nbz=0) const throw(); + /// in the given level (default level is root) + void root_blocks (int * nbx, int * nby=0, int * nbz=0, int level=0) const throw(); /// Return the factory object associated with the Hierarchy const Factory * factory () const throw() @@ -247,9 +247,6 @@ class Hierarchy { /// Array of Blocks CProxy_Block block_array_; - /// Size of the root grid - int root_size_[3]; - /// Lower extent of the hierarchy double lower_[3]; @@ -262,6 +259,9 @@ class Hierarchy { /// Periodicity of boundary conditions on faces int periodicity_[3]; + /// Size of the root grid + int root_size_[3]; + public: // static attributes /// Current number of blocks on this node diff --git a/src/Cello/mesh_Index.hpp b/src/Cello/mesh_Index.hpp index e0b1696740..cb3b82b5d9 100644 --- a/src/Cello/mesh_Index.hpp +++ b/src/Cello/mesh_Index.hpp @@ -226,7 +226,7 @@ class Index { void clean_ (); int num_bits_(int value) const; - + void print_ (FILE * fp, const char * msg, int max_level, @@ -244,26 +244,17 @@ class Index { #ifndef TEST PUPbytes(Index) -#endif - -#ifndef TEST -// public: -// void pup(PUP::er &p) { -// } -PUPbytes(NodeBits) -#endif - -//---------------------------------------------------------------------- -#ifndef TEST -class CkArrayIndexIndex:public CkArrayIndex { - Index * index_; -public: - CkArrayIndexIndex(const Index &in) - { - index_ = new (index) Index(in); - nInts=sizeof(Index)/sizeof(int); - } -}; + PUPbytes(NodeBits) + + class CkArrayIndexIndex:public CkArrayIndex { + Index * index_; + public: + CkArrayIndexIndex(const Index &in) + { + index_ = new (index) Index(in); + nInts=sizeof(Index)/sizeof(int); + } + }; #endif #endif /* INDEX_HPP */ diff --git a/src/Cello/problem_MethodDebug.cpp b/src/Cello/problem_MethodDebug.cpp index cfe0cd5450..0311ddcaf4 100644 --- a/src/Cello/problem_MethodDebug.cpp +++ b/src/Cello/problem_MethodDebug.cpp @@ -10,6 +10,7 @@ #include "test.hpp" // #define DEBUG_DEBUG +// #define CHECK_FOR_NANS //---------------------------------------------------------------------- MethodDebug::MethodDebug @@ -94,9 +95,20 @@ void MethodDebug::compute ( Block * block) throw() reduce[k+kmax] = std::max(reduce[k+1],(long double)(values[i])); reduce[k+ksum] += values[i]; reduce[k+knum] += rel_vol; - } +#ifdef CHECK_FOR_NANS + static int count_nan = 0; + if (values[i] != values[i] && count_nan++ < 10) { + WARNING5("MethodDebug", + "Found NAN in field %s block %s element %d %d %d", + field.field_name(index_field).c_str(), + block->name().c_str(), + ix,iy,iz); + } +#endif + } } } + k += 4; } diff --git a/src/Cello/problem_ProlongLinear.cpp b/src/Cello/problem_ProlongLinear.cpp index b57386019b..30468e9804 100644 --- a/src/Cello/problem_ProlongLinear.cpp +++ b/src/Cello/problem_ProlongLinear.cpp @@ -11,7 +11,7 @@ #include "problem.hpp" // #define TRACE_SUMS - +// #define TRACE_PROLONG //---------------------------------------------------------------------- ProlongLinear::ProlongLinear() throw() @@ -265,7 +265,7 @@ void ProlongLinear::apply_ const int mfx = mf3[0]; const int mcy = mc3[1]; const int myf = mf3[1]; - + for (int ifx = 0; ifx> 1) - gcx; diff --git a/src/Cello/problem_Refresh.hpp b/src/Cello/problem_Refresh.hpp index aea1b43b07..8d84048dad 100644 --- a/src/Cello/problem_Refresh.hpp +++ b/src/Cello/problem_Refresh.hpp @@ -27,8 +27,8 @@ class Refresh : public PUP::able { field_list_src_(), field_list_dst_(), all_particles_(false), - particle_list_(), particles_are_copied_(false), + particle_list_(), all_fluxes_(false), ghost_depth_(0), min_face_rank_(0), @@ -57,8 +57,8 @@ class Refresh : public PUP::able { field_list_src_(), field_list_dst_(), all_particles_(false), - particle_list_(), particles_are_copied_(false), + particle_list_(), all_fluxes_(false), ghost_depth_(ghost_depth), min_face_rank_(min_face_rank), @@ -85,8 +85,8 @@ class Refresh : public PUP::able { field_list_src_(), field_list_dst_(), all_particles_(false), - particle_list_(), particles_are_copied_(false), + particle_list_(), all_fluxes_(false), ghost_depth_(0), min_face_rank_(0), @@ -113,8 +113,8 @@ class Refresh : public PUP::able { p | field_list_src_; p | field_list_dst_; p | all_particles_; - p | particle_list_; p | particles_are_copied_; + p | particle_list_; p | all_fluxes_; p | ghost_depth_; p | min_face_rank_; diff --git a/src/Cello/simulation_Simulation.cpp b/src/Cello/simulation_Simulation.cpp index 242e4bc928..ae31ec837e 100644 --- a/src/Cello/simulation_Simulation.cpp +++ b/src/Cello/simulation_Simulation.cpp @@ -23,8 +23,8 @@ Simulation::Simulation const char * parameter_file, int n ) -/// Initialize the Simulation object -: + /// Initialize the Simulation object + : #if defined(CELLO_DEBUG) || defined(CELLO_VERBOSE) fp_debug_(NULL), #endif @@ -345,9 +345,9 @@ void Simulation::refine_create_block(MsgRefine * msg) int v3[3]; index.values(v3); ASSERT3 ("Simulation::p_refine_create_block", - "index %08x %08x %08x is already in the msg_refine mapping", - v3[0],v3[1],v3[2], - (msg == NULL)); + "index %08x %08x %08x is already in the msg_refine mapping", + v3[0],v3[1],v3[2], + (msg == NULL)); } msg_refine_map_[index] = msg; @@ -536,7 +536,7 @@ void Simulation::initialize_data_descr_() throw() int alignment = config_->field_alignment; ASSERT1 ("Simulation::initialize_data_descr_", - "Illegal Field:alignment parameter value %d", + "Illegal Field:alignment parameter value %d", alignment, 1 <= alignment ); @@ -711,6 +711,8 @@ void Simulation::initialize_hierarchy_() throw() config_->mesh_min_level, config_->mesh_max_level); + // Domain extents + hierarchy_->set_lower (config_->domain_lower[0], config_->domain_lower[1], @@ -745,8 +747,8 @@ void Simulation::initialize_hierarchy_() throw() boundary->periodicity(lp3); } int p3[3] = {lp3[0] ? root_blocks[0] : 0, - lp3[1] ? root_blocks[1] : 0, - lp3[2] ? root_blocks[2] : 0 }; + lp3[1] ? root_blocks[1] : 0, + lp3[2] ? root_blocks[2] : 0 }; hierarchy_->set_periodicity (p3[0],p3[1],p3[2]); } @@ -1036,7 +1038,6 @@ void Simulation::r_monitor_performance_reduce(CkReductionMsg * msg) const long long num_blocks_level = counters_reduce[m++]; // NL monitor()->print("performance","simulation num-blocks-level %d %lld", i,num_blocks_level); - num_total_blocks += num_blocks_level; // compute leaf blocks given number of blocks per level // (NOTE: num_blocks_level (i>0) is evenly divisible by num_children @@ -1104,14 +1105,6 @@ void Simulation::r_monitor_performance_reduce(CkReductionMsg * msg) const double avg_proc_blocks = 1.0*num_blocks_total/CkNumPes(); const double avg_node_blocks = 1.0*num_blocks_total/CkNumNodes(); - - // monitor()->print - // ("Performance","simulation balance-blocks-core %f", - // 100.0*(max_proc_blocks / avg_proc_blocks - 1.0 )); - // monitor()->print - // ("Performance","simulation balance-blocks-node %f", - // 100.0*(max_node_blocks / avg_node_blocks - 1.0 )); - monitor()->print ("Performance","simulation balance-eff-blocks-core %f (%.0f/%lld)", avg_proc_blocks / max_proc_blocks, diff --git a/src/Cello/simulation_Simulation.hpp b/src/Cello/simulation_Simulation.hpp index 26e79ce26b..1a7faf72b0 100644 --- a/src/Cello/simulation_Simulation.hpp +++ b/src/Cello/simulation_Simulation.hpp @@ -585,7 +585,6 @@ class Simulation : public CBase_Simulation std::string restart_directory_; int restart_num_files_; std::ifstream restart_stream_file_list_; - }; #endif /* SIMULATION_SIMULATION_HPP */ diff --git a/src/Enzo/CMakeLists.txt b/src/Enzo/CMakeLists.txt index 9ccb4598d4..1e7004d06f 100644 --- a/src/Enzo/CMakeLists.txt +++ b/src/Enzo/CMakeLists.txt @@ -26,7 +26,7 @@ target_link_libraries(main_enzoCharmModule INTERFACE enzoCharmModule) # the CONFIGURE_DEPENDS flag. # - See the CMake Primer section of the developer documentation for more details file(GLOB SRC_FILES CONFIGURE_DEPENDS - *.cpp *.F *.hpp fortran.h fortran_types.h + *.cpp *.F *.hpp *.h *.c ) set(Cello_LIBS "cello_component;charm_component;control;disk;error;data;io;memory;mesh;monitor;parameters;parallel;performance;problem;compute;simulation;test_Unit") @@ -75,20 +75,19 @@ target_link_options(main_enzo PRIVATE ${Cello_TARGET_LINK_OPTIONS}) # add files in enzo-core to enzo target (and define a unit test) add_subdirectory(enzo-core) -# add files in hydro-mhd to enzo target and define the riemann library -add_subdirectory(hydro-mhd) - # add source files from other subdirectories to the enzo target add_subdirectory(assorted) add_subdirectory(chemistry) add_subdirectory(cosmology) add_subdirectory(fluid-props) add_subdirectory(gravity) +add_subdirectory(hydro-mhd) add_subdirectory(initial) add_subdirectory(io) add_subdirectory(mesh) add_subdirectory(obsolete) add_subdirectory(particle) +add_subdirectory(turbulence) add_subdirectory(utils) # note that the tests subdirectory introduces problem initializers that can diff --git a/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.cpp b/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.cpp new file mode 100644 index 0000000000..d83cf6dcd6 --- /dev/null +++ b/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.cpp @@ -0,0 +1,650 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoMethodTurbulenceMhdIG.cpp +/// @author Alexei Kritsuk (akritsuk@ucsd.edu) +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Wed Jul 23 00:31:04 UTC 2014 +/// @date Thu Sep 20 00:31:04 UTC 2018 +/// @brief Implements the EnzoMethodTurbulenceMhdIG class with Ornstein-Uhlenbeck pumping + +#include "cello.hpp" + +#include "enzo.hpp" + +#include "enzo.decl.h" + +enum { + id_vad, + id_aad, + id_vvd, + id_vv, + id_dvx, + id_dvy, + id_dvz, + id_dax, + id_day, + id_daz, + id_bx, + id_by, + id_bz, + id_bb, + id_bbod, + id_divb, + id_d, + id_dd, + id_lnd, + id_dlnd, + id_pr, + id_prod, + id_zones, + id_mind, + id_maxd, + num_reduce +}; + +//#define DEBUG_TURBULENCE + +#ifdef DEBUG_TURBULENCE +# define TRACE_TURBULENCE CkPrintf ("%s:%d TRACE DEBUG_TURBULENCE\n",__FILE__,__LINE__); +#else +# define TRACE_TURBULENCE /* */ +#endif + +//---------------------------------------------------------------------- + +CkReduction::reducerType r_method_turbulence_id_type; + +void register_method_turbulence_mhd_ig(void) +{ + r_method_turbulence_id_type = CkReduction::addReducer(r_method_turbulence_mhd_ig); +} + +CkReductionMsg * r_method_turbulence_mhd_ig(int n, CkReductionMsg ** msgs) +{ + double accum[num_reduce] = { 0.0 }; + accum[id_mind] = std::numeric_limits::max(); + accum[id_maxd] = - std::numeric_limits::max(); + + for (int i=0; igetData(); + for (int ig=0; igrefresh_set_name(ir_post_,name()); + refresh_post->add_all_fields(); + + // TURBULENCE parameters initialized in EnzoBlock::initialize() +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIG::pup (PUP::er &p) +{ + + // NOTE: change this function whenever attributes change + + TRACEPUP; + + Method::pup(p); + + p | gamma_; + p | density_initial_; + p | pressure_initial_; + p | bfieldx_initial_; + p | mach_number_; + p | solenoidal_fraction_; + p | kfmin_; + p | kfmax_; + p | comoving_coordinates_; + +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIG::compute ( Block * block) throw() +{ + TRACE_TURBULENCE; + + EnzoBlock * enzo_block = static_cast (block); + + Field field = block->data()->field(); + + enzo_float * density = (enzo_float *) field.values("density"); + enzo_float * dens_rx = (enzo_float *) field.values("dens_rx"); + enzo_float * dens_ry = (enzo_float *) field.values("dens_ry"); + enzo_float * dens_rz = (enzo_float *) field.values("dens_rz"); + + enzo_float * pressure = (enzo_float *) field.values("pressure"); + enzo_float * press_rx = (enzo_float *) field.values("press_rx"); + enzo_float * press_ry = (enzo_float *) field.values("press_ry"); + enzo_float * press_rz = (enzo_float *) field.values("press_rz"); + + enzo_float * velocity[3] = { + (enzo_float *) field.values("velox"), + (enzo_float *) field.values("veloy"), + (enzo_float *) field.values("veloz") }; + + enzo_float * velo_rx[3] = { + (enzo_float *) field.values("velox_rx"), + (enzo_float *) field.values("veloy_rx"), + (enzo_float *) field.values("veloz_rx") }; + + enzo_float * velo_ry[3] = { + (enzo_float *) field.values("velox_ry"), + (enzo_float *) field.values("veloy_ry"), + (enzo_float *) field.values("veloz_ry") }; + + enzo_float * velo_rz[3] = { + (enzo_float *) field.values("velox_rz"), + (enzo_float *) field.values("veloy_rz"), + (enzo_float *) field.values("veloz_rz") }; + + enzo_float * driving[3] = { + (enzo_float *) field.values("drivx"), + (enzo_float *) field.values("drivy"), + (enzo_float *) field.values("drivz") }; + + enzo_float * driv_rx[3] = { + (enzo_float *) field.values("drivx_rx"), + (enzo_float *) field.values("drivy_rx"), + (enzo_float *) field.values("drivz_rx") }; + + enzo_float * driv_ry[3] = { + (enzo_float *) field.values("drivx_ry"), + (enzo_float *) field.values("drivy_ry"), + (enzo_float *) field.values("drivz_ry") }; + + enzo_float * driv_rz[3] = { + (enzo_float *) field.values("drivx_rz"), + (enzo_float *) field.values("drivy_rz"), + (enzo_float *) field.values("drivz_rz") }; + + enzo_float * bfield[3] = { + (enzo_float *) field.values("bfieldx"), + (enzo_float *) field.values("bfieldy"), + (enzo_float *) field.values("bfieldz") }; + + enzo_float * bfield_rx[3] = { + (enzo_float *) field.values("bfieldx_rx"), + (enzo_float *) field.values("bfieldy_rx"), + (enzo_float *) field.values("bfieldz_rx") }; + + enzo_float * bfield_ry[3] = { + (enzo_float *) field.values("bfieldx_ry"), + (enzo_float *) field.values("bfieldy_ry"), + (enzo_float *) field.values("bfieldz_ry") }; + + enzo_float * bfield_rz[3] = { + (enzo_float *) field.values("bfieldx_rz"), + (enzo_float *) field.values("bfieldy_rz"), + (enzo_float *) field.values("bfieldz_rz") }; + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + int gx,gy,gz; + field.ghost_depth(0,&gx,&gy,&gz); + + const int n = num_reduce; + double * g = new double [n+1]; + + for (int i=0; i::max(); + g[id_maxd] = - std::numeric_limits::max(); + + int mx,my,mz; + field.dimensions (0,&mx,&my,&mz); + const int rank = ((mz == 1) ? ((my == 1) ? 1 : 2) : 3); + + //--------------------------------------------------------------------- + // OU pumping call starts here + + double xdm,ydm,zdm; + cello::hierarchy()->lower(&xdm,&ydm,&zdm); + double xdp,ydp,zdp; + cello::hierarchy()->upper(&xdp,&ydp,&zdp); + + double Lbox[3]; + Lbox[0] = (xdp - xdm); + Lbox[1] = (rank >= 2) ? (ydp - ydm) : 1.0; + Lbox[2] = (rank >= 3) ? (zdp - zdm) : 1.0; + + + // if ( rank == 3) { + + // FORTRAN_NAME(OUpumpInit) + // ( &gamma_, + // &density_initial_, + // &pressure_initial_, + // &solenoidal_fraction_, + // &mach_number_, + // &kfmin_, + // &kfmax_, + // Lbox ); + + + // // FORTRAN_NAME(OUpumpCompute) + // // ( &rank, &mx, &my, &mz, // rank and local block dimensions + // // &nx, &ny, &nz, // root + // // &gx, &gy, &gz, // number of ghost zones + // // (enzo_float *)v3[0], // flow fields invilved + // // (enzo_float *)v3[1], + // // (enzo_float *)v3[2], + // // (enzo_float *)density, + // // &mx,&my,&mz, // zone sizes + // // &o3[0],&o3[1],&o3[2], + // // &dt ); // time step + + // turbForce3D(nc, ni, nj, nk, nig, njg, nkg, w, grid, dt, res, update_sol) + + // } + + // OU pumping call ends here + //--------------------------------------------------------------------- + + + if (block->is_leaf()) { + + // Loops cover only active zones of this block and + // compute averages for zone centers (mostly) to be used for forcing normalization + + for (int iz=0; iz= 2) ? d*velocity[1][i] : 0.0; // 5 + g[id_dvz] += (rank >= 3) ? d*velocity[2][i] : 0.0; // 6 + /* + g[id_dax] += d*driving[0][i]; // 7 + g[id_day] += (rank >= 2) ? d*driving[1][i] : 0.0; // 8 + g[id_daz] += (rank >= 3) ? d*driving[2][i] : 0.0; // 9 + */ + g[id_dax] += ( d*driving[0][i] + dens_rx[i]*driv_rx[0][i] + + dens_ry[i]*driv_ry[0][i] + + dens_rz[i]*driv_rz[0][i] )/4.0; // 7 + g[id_day] += (rank >= 2) ? ( d*driving[1][i] + dens_rx[i]*driv_rx[1][i] + + dens_ry[i]*driv_ry[1][i] + + dens_rz[i]*driv_rz[1][i] )/4.0 : 0.0; // 8 + g[id_daz] += (rank >= 3) ? ( d*driving[2][i] + dens_rx[i]*driv_rx[2][i] + + dens_ry[i]*driv_ry[2][i] + + dens_rz[i]*driv_rz[2][i] )/4.0 : 0.0; // 9 + + g[id_bx] += bfield[0][i]; // 10 + g[id_by] += (rank >= 2) ? bfield[1][i] : 0.0; // 11 + g[id_bz] += (rank >= 3) ? bfield[2][i] : 0.0; // 12 + + // PPML-style divergence calculation in 3D. + // One can also use max|div(b)| for control, see Fig. 18 in Ustyugov et al. (2009, JCP 228, 7614). + int is = 1; + int js = mx; + int ks = mx*my; + g[id_divb] += fabs(bfield_rx[0][i+is] - bfield_rx[0][i-is] + // 15 + bfield_rx[0][i+is+js] - bfield_rx[0][i-is+js] + + bfield_rx[0][i+is+ks] - bfield_rx[0][i-is+ks] + + bfield_rx[0][i+is+js+ks] - bfield_rx[0][i-is+js+ks] + + + bfield_ry[1][i+js] - bfield_ry[1][i-js] + + bfield_ry[1][i+js+is] - bfield_ry[1][i-js+is] + + bfield_ry[1][i+js+ks] - bfield_ry[1][i-js+ks] + + bfield_ry[1][i+js+is+ks] - bfield_ry[1][i-js+is+ks] + + + bfield_rz[2][i+ks] - bfield_rz[2][i-ks] + + bfield_rz[2][i+ks+is] - bfield_rz[2][i-ks+is] + + bfield_rz[2][i+ks+js] - bfield_rz[2][i-ks+js] + + bfield_rz[2][i+ks+is+js] - bfield_rz[2][i-ks+is+js]); + + g[id_mind] = // 23 + std::min(g[id_mind], (double) d); + g[id_maxd] = // 24 + std::max(g[id_maxd], (double) d); + } + } + } + } + TRACE_TURBULENCE; + CkCallback callback (CkIndex_EnzoBlock::r_method_turbulence_ig_end(NULL), + enzo_block->proxy_array()); + enzo_block->contribute(n,g,r_method_turbulence_ig_type,callback); +} + +//---------------------------------------------------------------------- + +// SEE main.cpp for implementation + +// CkReductionMsg * r_method_turbulence(int n, CkReductionMsg ** msgs) + +//---------------------------------------------------------------------- + +void EnzoBlock::r_method_turbulence_ig_end(CkReductionMsg * msg) +{ + TRACE_TURBULENCE; + performance_start_(perf_compute,__FILE__,__LINE__); + method()->compute_resume (this,msg); + performance_stop_(perf_compute,__FILE__,__LINE__); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIG::compute_resume +(Block * block, + CkReductionMsg * msg) throw() +{ + TRACE_TURBULENCE; + + EnzoBlock * enzo_block = static_cast (block); + + double * g = msg->getData(); + + Data * data = block->data(); + Field field = data->field(); + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + + double dt = block->dt(); + + int mx,my,mz; + field.dimensions (0,&mx,&my,&mz); + const int rank = ((mz == 1) ? ((my == 1) ? 1 : 2) : 3); + + double xdm,ydm,zdm; + cello::hierarchy()->lower(&xdm,&ydm,&zdm); + double xdp,ydp,zdp; + cello::hierarchy()->upper(&xdp,&ydp,&zdp); + + double bnotx = bfieldx_initial_; + + if (edot_ < 0.0) { + // Only compute if needed at the beginning--could/should be in + // EnzoInitialTurbulence + double domain_x = (xdp - xdm); + double domain_y = (rank >= 2) ? (ydp - ydm) : 1.0; + double domain_z = (rank >= 3) ? (zdp - zdm) : 1.0; + double box_size = domain_x; + double box_mass = domain_x * domain_y * domain_z * density_initial_; + + float v_rms = mach_number_; + + edot_ = 0.81/box_size*box_mass*v_rms*v_rms*v_rms; + edot_ *= 0.8; + } + + double norm = 0.0; + + if (edot_ != 0.0) { + + double vad = g[id_vad]; + double aad = g[id_aad]; + double zon = g[id_zones]; + + const bool small_g0 = std::abs(vad) < 1e-30; + + norm = small_g0 ? 0.0001 : 1.25*dt*edot_*zon/vad; + + } + + // ASSUMES CONSTANT TIME STEP + + // double dt0 = dt; + // norm = (dt/dt0)*norm; + + + if (block->index().is_root()) { + + Monitor * monitor = cello::monitor(); + + monitor->print ("Method","sum v*a*d " "%.17g", g[id_vad]); + monitor->print ("Method","sum a*a*d " "%.17g", g[id_aad]); + monitor->print ("Method","sum v*v*d " "%.17g", g[id_vvd]); + monitor->print ("Method","sum v*v " "%.17g", g[id_vv]); + monitor->print ("Method","sum b*b " "%.17g", g[id_bb]); + monitor->print ("Method","sum b*b/d " "%.17g", g[id_bbod]); + monitor->print ("Method","sum pr " "%.17g", g[id_pr]); + monitor->print ("Method","sum pr/d " "%.17g", g[id_prod]); + + monitor->print ("Method","sum d*ax " "%.17g", g[id_dax]); + monitor->print ("Method","sum d*ay " "%.17g", g[id_day]); + monitor->print ("Method","sum d*az " "%.17g", g[id_daz]); + + monitor->print ("Method","sum d*vx " "%.17g", g[id_dvx]); + monitor->print ("Method","sum d*vy " "%.17g", g[id_dvy]); + monitor->print ("Method","sum d*vz " "%.17g", g[id_dvz]); + + monitor->print ("Method","sum bx " "%.17g", g[id_bx]); + monitor->print ("Method","sum by " "%.17g", g[id_by]); + monitor->print ("Method","sum bz " "%.17g", g[id_bz]); + + monitor->print ("Method","sum d " "%.17g", g[id_d]); + monitor->print ("Method","sum d*d " "%.17g", g[id_dd]); + monitor->print ("Method","sum ln(d) " "%.17g", g[id_lnd]); + monitor->print ("Method","sum d*ln(d) " "%.17g", g[id_dlnd]); + monitor->print ("Method","min d " "%.17g", g[id_mind]); + monitor->print ("Method","max d " "%.17g", g[id_maxd]); + + monitor->print ("Method","sum zones " "%.17g", g[id_zones]); + + monitor->print ("Method","norm " "%.17g", norm); + monitor->print ("Method","gamma " "%.17g", gamma_); + + monitor->print ("Method","kinetic energy " "%.17g", + 0.50*g[id_vvd]/g[id_zones]); + monitor->print ("Method","turbulent magnetic energy " "%.17g", + 0.50*(g[id_bb]/g[id_zones]-bnotx*bnotx)); + if (gamma_ != 1.0) { + monitor->print ("Method","internal energy " "%.17g", + g[id_pr]/g[id_zones]/(gamma-1.0); + } + monitor->print ("Method","potential energy " "%.17g", + g[id_dlnd]/g[id_zones]); + monitor->print ("Method","zones " "%.17g", + g[id_zones]); + monitor->print ("Method","bnotx " "%.17g", + bnotx); + monitor->print ("Method"," " "%.17g", + g[id_d]/g[id_zones]); + monitor->print ("Method"," " "%.17g", + g[id_lnd]/g[id_zones]); + monitor->print ("Method","volume-weighed rms Mach_s " "%.17g", + sqrt(g[id_vv]/g[id_zones])); + monitor->print ("Method","volume-weighed rms Mach_a " "%.17g", + sqrt(g[id_vv] / + g[id_bbod])); + monitor->print ("Method","mass-weighted rms Mach_s " "%.17g", + sqrt(g[id_vvd]/g[id_zones])); + monitor->print ("Method","density variance " "%.17g", + sqrt(g[id_dd]/g[id_zones])); + monitor->print ("Method","<|div(b)|> " "%.17g", + g[id_divb]/8.0/g[id_zones]); + monitor->print ("Method","density contrast " "%.17g", + g[id_maxd] / + g[id_mind]); + } + + if (block->is_leaf()) { + compute_resume_(block,msg); + } + + enzo_block->compute_done(); + +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIG::compute_resume_ +(Block * block, CkReductionMsg * msg) throw() +{ + double * g = (double *)msg->getData(); + + TRACE_TURBULENCE; + + // Compute normalization + + EnzoBlock * enzo_block = static_cast (block); + + Field field = block->data()->field(); + + int mx,my,mz; // total block size + int nx,ny,nz; // active block size + int gx,gy,gz; // number of ghost layers on each side of the block + field.dimensions (0,&mx,&my,&mz); + field.size (&nx,&ny,&nz); + field.ghost_depth(0,&gx,&gy,&gz); + + double dt = block->dt(); + + double vad = g[id_vad]; + double aad = g[id_aad]; + double zon = g[id_zones]; + + const bool small_g0 = std::abs(vad) < 1e-30; + + double norm = small_g0 ? 0.0001 : 1.25*dt*edot_*zon/vad; + + // ASSUMES CONSTANT TIME STEP + + double dt0 = dt; + norm = (dt/dt0)*norm; + + const int rank = (my == 1) ? 1 : ((mz == 1) ? 2 : 3); + + enzo_float * v3[3] = { + (enzo_float*) field.values ("velox"), + (enzo_float*) field.values ("veloy"), + (enzo_float*) field.values ("veloz") }; + enzo_float * v3_rx[3] = { + (enzo_float*) field.values ("velox_rx"), + (enzo_float*) field.values ("veloy_rx"), + (enzo_float*) field.values ("veloz_rx") }; + enzo_float * v3_ry[3] = { + (enzo_float*) field.values ("velox_ry"), + (enzo_float*) field.values ("veloy_ry"), + (enzo_float*) field.values ("veloz_ry") }; + enzo_float * v3_rz[3] = { + (enzo_float*) field.values ("velox_rz"), + (enzo_float*) field.values ("veloy_rz"), + (enzo_float*) field.values ("veloz_rz") }; + enzo_float * a3[3] = { + (enzo_float*) field.values ("drivx"), + (enzo_float*) field.values ("drivy"), + (enzo_float*) field.values ("drivz") }; + enzo_float * a3_rx[3] = { + (enzo_float*) field.values ("drivx_rx"), + (enzo_float*) field.values ("drivy_rx"), + (enzo_float*) field.values ("drivz_rx") }; + enzo_float * a3_ry[3] = { + (enzo_float*) field.values ("drivx_ry"), + (enzo_float*) field.values ("drivy_ry"), + (enzo_float*) field.values ("drivz_ry") }; + enzo_float * a3_rz[3] = { + (enzo_float*) field.values ("drivx_rz"), + (enzo_float*) field.values ("drivy_rz"), + (enzo_float*) field.values ("drivz_rz") }; + + // compute components of injected bulk momentum + + const enzo_float bm[3] = + { enzo_float(g[id_dax]/g[id_zones]), + enzo_float(g[id_day]/g[id_zones]), + enzo_float(g[id_daz]/g[id_zones]) }; + + // apply forcing + // only active zones are updated (assuming mean density of 1) + + int mx = (rank >= 1) ? nx + 2*gx : nx; + int my = (rank >= 2) ? ny + 2*gy : ny; + int mz = (rank >= 3) ? nz + 2*gz : nz; + for (int i=0; icompute_done(); +} diff --git a/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.hpp b/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.hpp new file mode 100644 index 0000000000..71d9b3c58a --- /dev/null +++ b/src/Enzo/New/enzo_EnzoMethodTurbulenceMhdIG.hpp @@ -0,0 +1,92 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoMethodMHDTurbulenceIG.hpp +/// @author Alexei Kritsuk (kritsuk@gmail.com) +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Wed Jul 23 00:31:13 UTC 2014 +/// @date Thu Sep 20 00:31:13 UTC 2018 +/// @brief [\ref Enzo] Implementation of Enzo Ideal Gas TURBULENCE MHD method with Ornstein-Uhlenbeck pumping + +#ifndef ENZO_ENZO_METHOD_MHDTURBULENCEIG_HPP +#define ENZO_ENZO_METHOD_MHDTURBULENCEIG_HPP + +//---------------------------------------------------------------------- + +class EnzoMethodTurbulenceMhdIG : public Method { + + /// @class EnzoMethodTurbulenceMhdIG + /// @ingroup Enzo + /// @brief [\ref Enzo] Encapsulate Enzo's IDEAL GAS MHD TURBULENCE forcing method + +public: // interface + + /// Create a new EnzoMethodTurbulenceIG object + EnzoMethodTurbulenceMhdIG + (double gamma, + double density_initial, + double pressure_initial, + double bfieldx_initial, + double mach_number, + double solenoidal_fraction, + double kfmin, + double kfmax, + bool comoving_coordinates); + + /// Charm++ PUP::able declarations + PUPable_decl(EnzoMethodTurbulenceMhdIG); + + /// Charm++ PUP::able migration constructor + EnzoMethodTurbulenceMhdIG (CkMigrateMessage *m) + : Method (m), + density_initial_(0.0), + bfieldx_initial_(0.0), + edot_(0.0), + mach_number_(0.0), + comoving_coordinates_(false) + { } + + /// CHARM++ Pack / Unpack function + void pup (PUP::er &p); + + /// Apply the method to advance a block one timestep + virtual void compute( Block * block) throw(); + + virtual std::string name () throw () + { return "turbulence_mhd_ig"; } + + /// Resume computation after a reduction + virtual void compute_resume ( Block * block, + CkReductionMsg * msg) throw(); + +private: // methods + + void compute_resume_ (Block * block, CkReductionMsg * msg) throw(); + +private: // attributes + + double gamma_; + + double pressure_initial_; + + double solenoidal_fraction_; + + double kfmin_; + double kfmax_; + + // Initial density + double density_initial_; + + // Initial B-field + double bfieldx_initial_; + + // Corresponds to Enzo "RandomForcingEdot" parameter + double edot_; + + // Mach number + double mach_number_; + + // Comoving Coordinates + bool comoving_coordinates_; +}; + +#endif /* ENZO_ENZO_METHOD_MHDTURBULENCEIG_HPP */ diff --git a/src/Enzo/PPML_IG_Conservative.F b/src/Enzo/PPML_IG_Conservative.F new file mode 100644 index 0000000000..ec189b4772 --- /dev/null +++ b/src/Enzo/PPML_IG_Conservative.F @@ -0,0 +1,38 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine Conserv_ig(gamma,nx,ny,nz,dn,vx,vy,vz,bx,by,bz,pn, + & qu1,qu2,qu3,qu4,qu5,qu6,qu7,qu8) + Implicit NONE + + Integer nx,ny,nz,i,j,k + ENZO_REAL gamma + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + ENZO_REAL pn(nx,ny,nz) + ENZO_REAL qu1(nx,ny,nz) + ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) + ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) + ENZO_REAL qu8(nx,ny,nz) + + Do k=1,nz + Do j=1,ny + Do i=1,nx + QU1(i,j,k)=dn(i,j,k) + QU2(i,j,k)=dn(i,j,k)*vx(i,j,k) + QU3(i,j,k)=dn(i,j,k)*vy(i,j,k) + QU4(i,j,k)=dn(i,j,k)*vz(i,j,k) + QU5(i,j,k)=bx(i,j,k) + QU6(i,j,k)=by(i,j,k) + QU7(i,j,k)=bz(i,j,k) + QU8(i,j,k)=pn(i,j,k)/(gamma-1.)+dn(i,j,k)* + & +(vx(i,j,k)**2+vy(i,j,k)**2+vz(i,j,k)**2)/2. + & +(bx(i,j,k)**2+by(i,j,k)**2+bz(i,j,k)**2)/2. + Enddo + Enddo + Enddo + + RETURN + END diff --git a/src/Enzo/PPML_IG_HLLD.F b/src/Enzo/PPML_IG_HLLD.F new file mode 100644 index 0000000000..bf320fa86d --- /dev/null +++ b/src/Enzo/PPML_IG_HLLD.F @@ -0,0 +1,884 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine HLLDx_ig(gamma,pl,pr,bs,f,us) + Implicit NONE + + Integer m + ENZO_REAL ql(8),qr(8),f(8),qlz(8),qrz(8),qzz(8),fl(8),fr(8),us(8) + ENZO_REAL ul,ur,cfl,cfr,ptl,ptr,sl,sr,slu,sru,smu,sm,ptz + ENZO_REAL rlz,slz,rrz,srz,gamma + ENZO_REAL pl(8),pr(8),bs(3) + + call cons_ig(gamma,pl,ql) + call cons_ig(gamma,pr,qr) + call pressx_ig(gamma,ql,bs,ul,ptl,cfl) + call pressx_ig(gamma,qr,bs,ur,ptr,cfr) + + sl = min(ul,ur) - max(cfl,cfr) + sr = max(ul,ur) + max(cfl,cfr) + + if(sl.gt.0.)then + + call fluxx_ig(gamma,pl,bs,f) + + do m=1,8 + us(m) = ql(m) + enddo + + return + + endif + + if(sr.lt.0.)then + + call fluxx_ig(gamma,pr,bs,f) + + do m=1,8 + us(m) = qr(m) + enddo + + return + + endif + + slu = sl - ul + sru = sr - ur + smu = sru*qr(1)-slu*ql(1) + sm = (sru*qr(1)*ur - slu*ql(1)*ul - ptr + ptl)/smu + + ptz = (sru*qr(1)*ptl - slu*ql(1)*ptr + ql(1)*qr(1)*sru*slu + 1 *(ur - ul))/smu + + + rlz = ql(1)*slu/(sl - sm) + slz = sm - abs(ql(5)+bs(1))/sqrt(rlz) + + if(sl.le.0.and.slz.ge.0.)then + + call fluxx_ig(gamma,pl,bs,fl) + call quzx_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + + do m=1,8 + f(m) = fl(m) + sl*(qlz(m) - ql(m)) + us(m) = qlz(m) + enddo + + return + + endif + + + rrz = qr(1)*sru/(sr - sm) + srz = sm + abs(qr(5)+bs(1))/sqrt(rrz) !+bs(1) + + if(srz.le.0.and.sr.ge.0.)then + + call fluxx_ig(gamma,pr,bs,fr) + call quzx_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + do m=1,8 + f(m) = fr(m) + sr*(qrz(m) - qr(m)) + us(m) = qrz(m) + enddo + + return + + endif + + call quzx_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + call quzx_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + if(slz.le.0.and.sm.ge.0.)then + + call fluxx_ig(gamma,pl,bs,fl) + + call quzzx_ig(1,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fl(m) + slz*qzz(m) - (slz - sl)*qlz(m) - sl*ql(m) + us(m) = qzz(m) + enddo + + return + + endif + + if(sm.le.0.and.srz.ge.0.)then + + call fluxx_ig(gamma,pr,bs,fr) + + call quzzx_ig(2,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fr(m) + srz*qzz(m) - (srz - sr)*qrz(m) - sr*qr(m) + us(m) = qzz(m) + enddo + + return + + endif + + return + end + + + Subroutine quzx_ig(gamma,sm,sa,cfa,ptz,qa,bs,qz) + Implicit NONE + + ENZO_REAL qa(8),qz(8),qb(8),bs(3) + ENZO_REAL gamma,ua,v2,b2,pg,sam,sap,slu,slm,psb,vb,vbz,rlz + ENZO_REAL rsm,smb,smr,vba,eps,sm,sa,cfa,ptz + ENZO_REAL qb5,qb6,qb7,bp,bp0,pta,rst + + call prim_ig(gamma,qa,qb) + + ua = qb(2) + v2 = qb(2)**2 + qb(3)**2 + qb(4)**2 + b2 = qb(5)**2 + qb(6)**2 + qb(7)**2 + pg = qb(8) + + qb5 = qa(5)+bs(1) + qb6 = qa(6)+bs(2) + qb7 = qa(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + pta = pg + bp/2.-bp0/2. + + sam = ua - cfa + sap = ua + cfa + + slu = sa - ua + slm = sa - sm + psb = qb(1)*slu*slm - qb5**2 + + if(abs(psb).le.1.e-12) then + + qz(1) = qb(1) + qz(2) = ua + qz(3) = qb(3) + qz(4) = qb(4) + qz(5) = qb5 + qz(6) = 0. + qz(7) = 0. + + vb = ua*qb5 + vbz= sm*qb5 + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) +c qz(8)=(slu*qa(8) - pta*ua + ptz*sm + qa(5)*(vb - vbz))/(sa - sm) + qz(8) = qa(8) + + else + + rlz = qb(1)*slu/slm + rsm = qb(1)*slu**2 - qb5**2 + smb = (sm - ua)/psb + smr = rsm/psb + + rst = qb(1)*slu*smb + + qz(1) = rlz + qz(2) = sm + qz(3) = qb(3)-qb5*qb6*smb + qz(4) = qb(4)-qb5*qb7*smb + qz(5) = qb(5) + qz(6) = qb(6)*smr + bs(2)*rst + qz(7) = qb(7)*smr + bs(3)*rst + + vba = qb(2)*qb(5) + qb(3)*qb(6) + qb(4)*qb(7) + vbz = qz(2)*qz(5) + qz(3)*qz(6) + qz(4)*qz(7) + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) + + qz(8) = (slu*qa(8) - pta*ua + ptz*sm + qb5*(vba - vbz))/slm + + endif + + return + end + + Subroutine quzzx_ig(nt,gamma,sm,ql,qr,bs,q) + Implicit NONE + + integer nt + ENZO_REAL ql(8),qr(8),q(8),qlm(8),qrm(8),bs(3) + ENZO_REAL sl,sr,xs,xt,r1,r5,vm,r8,sa,sn,tm,vz,sm,gamma + ENZO_REAL o1 + + o1 = 1.0d0 + + call prim_ig(gamma,ql,qlm) + call prim_ig(gamma,qr,qrm) + + sl = sqrt(qlm(1)) + sr = sqrt(qrm(1)) + xs = sl+sr + xt = sqrt(qlm(1)*qrm(1)) + + if(nt.eq.1)then + + r1 = qlm(1) + r5 = qlm(5) + vm = qlm(2)*qlm(5) + qlm(3)*qlm(6) + qlm(4)*qlm(7) + r8 = ql(8) + sa = sl + sn = sign(o1,r5+bs(1)) + tm = -1. + + else + + r1 = qrm(1) + r5 = qrm(5) + vm = qrm(2)*qrm(5) + qrm(3)*qrm(6) + qrm(4)*qrm(7) + r8 = qr(8) + sa = sr + sn = sign(o1,r5+bs(1)) + tm = 1. + + endif + + q(1) = r1 + q(2) = sm + q(3) = (sl*qlm(3) + sr*qrm(3) + (qr(6) - ql(6))*sn)/xs + q(4) = (sl*qlm(4) + sr*qrm(4) + (qr(7) - ql(7))*sn)/xs + q(5) = r5 + q(6) = (sl*qr(6) + sr*ql(6) + (qrm(3) - qlm(3))*sn*xt)/xs + q(7) = (sl*qr(7) + sr*ql(7) + (qrm(4) - qlm(4))*sn*xt)/xs + + vz = q(2)*q(5) + q(3)*q(6) + q(4)*q(7) + + q(2) = q(1)*q(2) + q(3) = q(1)*q(3) + q(4) = q(1)*q(4) + + q(8) = r8 + tm*sa*(vm-vz)*sn + + return + end + + Subroutine pressx_ig(gamma,ql,bs,ul,pt,cfl) + Implicit NONE + + ENZO_REAL ql(8),bs(3) + ENZO_REAL gamma,ul,ck,cb,ds,cfl,qb5,qb6,qb7,bp,bp0,vk,bm,pg,pt + + qb5 = ql(5)+bs(1) + qb6 = ql(6)+bs(2) + qb7 = ql(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + vk = ql(2)**2 + ql(3)**2 + ql(4)**2 + bm = ql(5)**2 + ql(6)**2 + ql(7)**2 + pg = (gamma-1.)*(ql(8) - vk/ql(1)/2. - bm/2.) + + pt = pg + bp/2.-bp0/2. + + ul = ql(2)/ql(1) + + ck = gamma*pg + cb = ck + bp + ds = cb*cb - 4.*ck*qb5**2 + if(ds.le.0.) ds=0. + cfl= sqrt((cb + sqrt(ds))/2./ql(1)) + + return + end + + Subroutine HLLDy_ig(gamma,pl,pr,bs,f,us) + Implicit NONE + + Integer m + ENZO_REAL ql(8),qr(8),f(8),qlz(8),qrz(8),qzz(8),fl(8),fr(8),us(8) + ENZO_REAL ul,ur,cfl,cfr,ptl,ptr,sl,sr,slu,sru,smu,sm,ptz,gamma + ENZO_REAL rlz,slz,rrz,srz + ENZO_REAL pl(8),pr(8),bs(3) + + call cons_ig(gamma,pl,ql) + call cons_ig(gamma,pr,qr) + + call pressy_ig(gamma,ql,bs,ul,ptl,cfl) + call pressy_ig(gamma,qr,bs,ur,ptr,cfr) + + sl = min(ul,ur) - max(cfl,cfr) + sr = max(ul,ur) + max(cfl,cfr) + + if(sl.gt.0.)then + + call fluxy_ig(gamma,pl,bs,f) + + do m=1,8 + us(m) = ql(m) + enddo + + return + + endif + + if(sr.lt.0.)then + + call fluxy_ig(gamma,pr,bs,f) + + do m=1,8 + us(m) = qr(m) + enddo + + return + + endif + + slu = sl - ul + sru = sr - ur + smu = sru*qr(1)-slu*ql(1) + sm = (sru*qr(1)*ur - slu*ql(1)*ul - ptr + ptl)/smu + + ptz = (sru*qr(1)*ptl - slu*ql(1)*ptr + ql(1)*qr(1)*sru*slu + & *(ur - ul))/smu + + + rlz = ql(1)*slu/(sl - sm) + slz = sm - abs(ql(6)+bs(2))/sqrt(rlz) + + if(sl.le.0.and.slz.ge.0.)then + + call fluxy_ig(gamma,pl,bs,fl) + call quzy_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + + do m=1,8 + f(m) = fl(m) + sl*(qlz(m) - ql(m)) + us(m) = qlz(m) + enddo + + return + + endif + + + rrz = qr(1)*sru/(sr - sm) + srz = sm + abs(qr(6)+bs(2))/sqrt(rrz) + + if(srz.le.0.and.sr.ge.0.)then + + call fluxy_ig(gamma,pr,bs,fr) + call quzy_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + do m=1,8 + f(m) = fr(m) + sr*(qrz(m) - qr(m)) + us(m) = qrz(m) + enddo + + return + + endif + + call quzy_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + call quzy_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + if(slz.le.0.and.sm.ge.0.)then + + call fluxy_ig(gamma,pl,bs,fl) + + call quzzy_ig(1,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fl(m) + slz*qzz(m) - (slz - sl)*qlz(m) - sl*ql(m) + us(m) = qzz(m) + enddo + + return + + endif + + if(sm.le.0.and.srz.ge.0.)then + + call fluxy_ig(gamma,pr,bs,fr) + + call quzzy_ig(2,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fr(m) + srz*qzz(m) - (srz - sr)*qrz(m) - sr*qr(m) + us(m) = qzz(m) + enddo + + return + + endif + + return + end + + + Subroutine quzy_ig(gamma,sm,sa,cfa,ptz,qa,bs,qz) + Implicit NONE + + ENZO_REAL qa(8),qz(8),qb(8),bs(3) + ENZO_REAL gamma,ua,v2,b2,pg,pta,sam,sap,slu,slm,psb,vb,vbz,rlz + ENZO_REAL rsm,smb,smr,vba,eps,sm,sa,cfa,ptz + ENZO_REAL qb5,qb6,qb7,bp,bp0,rst + + call prim_ig(gamma,qa,qb) + + ua = qb(3) + v2 = qb(2)**2 + qb(3)**2 + qb(4)**2 + b2 = qb(5)**2 + qb(6)**2 + qb(7)**2 + pg = qb(8) + + qb5 = qa(5)+bs(1) + qb6 = qa(6)+bs(2) + qb7 = qa(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + pta = pg + bp/2.-bp0/2. + + sam = ua - cfa + sap = ua + cfa + + slu = sa - ua + slm = sa - sm + psb = qb(1)*slu*slm - qb6**2 + + if(abs(psb).le.1.e-12) then + + qz(1) = qb(1) + qz(2) = qb(2) + qz(3) = ua + qz(4) = qb(4) + qz(5) = 0. + qz(6) = qb6 + qz(7) = 0. + + vb = ua*qb6 + vbz= sm*qb6 + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) +c qz(8)=(slu*qa(8) - pta*ua + ptz*sm + qa(6)*(vb - vbz))/(sa - sm) + qz(8) = qa(8) + + else + + rlz = qb(1)*slu/slm + rsm = qb(1)*slu**2 - qb6**2 + smb = (sm - ua)/psb + smr = rsm/psb + + rst = qb(1)*slu*smb + + qz(1) = rlz + qz(2) = qb(2)-qb6*qb5*smb + qz(3) = sm + qz(4) = qb(4)-qb6*qb7*smb + qz(5) = qb(5)*smr + bs(1)*rst + qz(6) = qb(6) + qz(7) = qb(7)*smr + bs(3)*rst + + vba = qb(2)*qb(5) + qb(3)*qb(6) + qb(4)*qb(7) + vbz = qz(2)*qz(5) + qz(3)*qz(6) + qz(4)*qz(7) + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) + + qz(8) = (slu*qa(8) - pta*ua + ptz*sm + qb6*(vba - vbz))/slm + + endif + + return + end + + Subroutine quzzy_ig(nt,gamma,sm,ql,qr,bs,q) + Implicit NONE + + integer nt + ENZO_REAL ql(8),qr(8),q(8),qlm(8),qrm(8),bs(3) + ENZO_REAL sl,sr,xs,xt,r1,r6,vm,r8,sa,sn,tm,vz,sm,gamma + ENZO_REAL o1 + + o1 = 1.0d0 + + call prim_ig(gamma,ql,qlm) + call prim_ig(gamma,qr,qrm) + + sl = sqrt(qlm(1)) + sr = sqrt(qrm(1)) + xs = sl+sr + xt = sqrt(qlm(1)*qrm(1)) + + if(nt.eq.1)then + + r1 = qlm(1) + r6 = qlm(6) + vm = qlm(2)*qlm(5) + qlm(3)*qlm(6) + qlm(4)*qlm(7) + r8 = ql(8) + sa = sl + sn = sign(o1,r6+bs(2)) + tm = -1. + + else + + r1 = qrm(1) + r6 = qrm(6) + vm = qrm(2)*qrm(5) + qrm(3)*qrm(6) + qrm(4)*qrm(7) + r8 = qr(8) + sa = sr + sn = sign(o1,r6+bs(2)) + tm = 1. + + endif + + q(1) = r1 + q(2) = (sl*qlm(2) + sr*qrm(2) + (qr(5) - ql(5))*sn)/xs + q(3) = sm + q(4) = (sl*qlm(4) + sr*qrm(4) + (qr(7) - ql(7))*sn)/xs + q(5) = (sl*qr(5) + sr*ql(5) + (qrm(2) - qlm(2))*sn*xt)/xs + q(6) = r6 + q(7) = (sl*qr(7) + sr*ql(7) + (qrm(4) - qlm(4))*sn*xt)/xs + + vz = q(2)*q(5) + q(3)*q(6) + q(4)*q(7) + + q(2) = q(1)*q(2) + q(3) = q(1)*q(3) + q(4) = q(1)*q(4) + + q(8) = r8 + tm*sa*(vm-vz)*sn + + return + end + + Subroutine pressy_ig(gamma,ql,bs,ul,pt,cfl) + Implicit NONE + + ENZO_REAL ql(8),bs(3) + ENZO_REAL gamma,ul,ck,cb,ds,cfl,qb5,qb6,qb7,bp,bp0,vk,bm,pg,pt + + + qb5 = ql(5)+bs(1) + qb6 = ql(6)+bs(2) + qb7 = ql(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + vk = ql(2)**2 + ql(3)**2 + ql(4)**2 + bm = ql(5)**2 + ql(6)**2 + ql(7)**2 + pg = (gamma-1.)*(ql(8) - vk/ql(1)/2. - bm/2.) + + pt = pg + bp/2.-bp0/2. + + ul = ql(3)/ql(1) + + ck = gamma*pg + cb = ck + bp + ds = cb*cb - 4.*ck*qb6**2 + if(ds.le.0.) ds=0. + cfl= sqrt((cb + sqrt(ds))/2./ql(1)) + + return + end + + + Subroutine HLLDz_ig(gamma,pl,pr,bs,f,us) + Implicit NONE + + Integer m + ENZO_REAL ql(8),qr(8),f(8),qlz(8),qrz(8),qzz(8),fl(8),fr(8),us(8) + ENZO_REAL ul,ur,cfl,cfr,ptl,ptr,sl,sr,slu,sru,smu,sm,ptz + ENZO_REAL rlz,slz,rrz,srz,gamma + ENZO_REAL pl(8),pr(8),bs(3) + + call cons_ig(gamma,pl,ql) + call cons_ig(gamma,pr,qr) + + call pressz_ig(gamma,ql,bs,ul,ptl,cfl) + call pressz_ig(gamma,qr,bs,ur,ptr,cfr) + + sl = min(ul,ur) - max(cfl,cfr) + sr = max(ul,ur) + max(cfl,cfr) + + if(sl.gt.0.)then + + call fluxz_ig(gamma,pl,bs,f) + + do m=1,8 + us(m) = ql(m) + enddo + + return + + endif + + if(sr.lt.0.)then + + call fluxz_ig(gamma,pr,bs,f) + + do m=1,8 + us(m) = qr(m) + enddo + + return + + endif + + slu = sl - ul + sru = sr - ur + smu = sru*qr(1)-slu*ql(1) + sm = (sru*qr(1)*ur - slu*ql(1)*ul - ptr + ptl)/smu + + ptz = (sru*qr(1)*ptl - slu*ql(1)*ptr + ql(1)*qr(1)*sru*slu + & *(ur - ul))/smu + + + rlz = ql(1)*slu/(sl - sm) + slz = sm - abs(ql(7)+bs(3))/sqrt(rlz) + + if(sl.le.0.and.slz.ge.0.)then + + call fluxz_ig(gamma,pl,bs,fl) + call quz_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + + do m=1,8 + f(m) = fl(m) + sl*(qlz(m) - ql(m)) + us(m) = qlz(m) + enddo + + return + + endif + + + rrz = qr(1)*sru/(sr - sm) + srz = sm + abs(qr(7)+bs(3))/sqrt(rrz) + + if(srz.le.0.and.sr.ge.0.)then + + call fluxz_ig(gamma,pr,bs,fr) + call quz_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + do m=1,8 + f(m) = fr(m) + sr*(qrz(m) - qr(m)) + us(m) = qrz(m) + enddo + + return + + endif + + call quz_ig(gamma,sm,sl,cfl,ptz,ql,bs,qlz) + call quz_ig(gamma,sm,sr,cfr,ptz,qr,bs,qrz) + + if(slz.le.0.and.sm.ge.0.)then + + call fluxz_ig(gamma,pl,bs,fl) + + call quzz_ig(1,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fl(m) + slz*qzz(m) - (slz - sl)*qlz(m) - sl*ql(m) + us(m) = qzz(m) + enddo + + return + + endif + + if(sm.le.0.and.srz.ge.0.)then + + call fluxz_ig(gamma,pr,bs,fr) + + call quzz_ig(2,gamma,sm,qlz,qrz,bs,qzz) + + do m=1,8 + f(m) = fr(m) + srz*qzz(m) - (srz - sr)*qrz(m) - sr*qr(m) + us(m) = qzz(m) + enddo + + return + + endif + + return + end + + + Subroutine quz_ig(gamma,sm,sa,cfa,ptz,qa,bs,qz) + Implicit NONE + + ENZO_REAL qa(8),qz(8),qb(8),bs(3) + ENZO_REAL gamma,ua,v2,b2,pg,sam,sap,slu,slm,psb,vb,vbz,rlz + ENZO_REAL rsm,smb,smr,vba,eps,sm,sa,cfa,ptz + ENZO_REAL qb5,qb6,qb7,bp,bp0,pta,rst + + call prim_ig(gamma,qa,qb) + + ua = qb(4) + v2 = qb(2)**2 + qb(3)**2 + qb(4)**2 + b2 = qb(5)**2 + qb(6)**2 + qb(7)**2 + pg = qb(8) + + qb5 = qa(5)+bs(1) + qb6 = qa(6)+bs(2) + qb7 = qa(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + pta = pg + bp/2.-bp0/2. + + sam = ua - cfa + sap = ua + cfa + + slu = sa - ua + slm = sa - sm + psb = qb(1)*slu*slm - qb7**2 + + if(abs(psb).le.1.e-12) then + + qz(1) = qb(1) + qz(2) = qb(2) + qz(3) = qb(3) + qz(4) = ua + qz(5) = 0. + qz(6) = 0. + qz(7) = qb7 + + vb = ua*qb7 + vbz= sm*qb7 + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) +c qz(8)=(slu*qa(8) - pta*ua + ptz*sm + qa(7)*(vb - vbz))/(sa - sm) + qz(8) = qa(8) + + else + + rlz = qb(1)*slu/slm + rsm = qb(1)*slu**2 - qb7**2 + smb = (sm - ua)/psb + smr = rsm/psb + + rst = qb(1)*slu*smb + + qz(1) = rlz + qz(2) = qb(2) - qb5*qb7*smb + qz(3) = qb(3) - qb6*qb7*smb + qz(4) = sm + qz(5) = qb(5)*smr + bs(1)*rst + qz(6) = qb(6)*smr + bs(2)*rst + qz(7) = qb(7) + + vba = qb(2)*qb(5) + qb(3)*qb(6) + qb(4)*qb(7) + vbz = qz(2)*qz(5) + qz(3)*qz(6) + qz(4)*qz(7) + + qz(2) = qz(1)*qz(2) + qz(3) = qz(1)*qz(3) + qz(4) = qz(1)*qz(4) + + qz(8) = (slu*qa(8) - pta*ua + ptz*sm + qb7*(vba - vbz))/slm + + endif + + return + end + + Subroutine quzz_ig(nt,gamma,sm,ql,qr,bs,q) + Implicit NONE + + integer nt + ENZO_REAL ql(8),qr(8),q(8),qlm(8),qrm(8),bs(3) + ENZO_REAL sl,sr,xs,xt,r1,r7,vm,r8,sa,sn,tm,vz,sm,gamma + ENZO_REAL o1 + + o1 = 1.0d0 + + call prim_ig(gamma,ql,qlm) + call prim_ig(gamma,qr,qrm) + + sl = sqrt(qlm(1)) + sr = sqrt(qrm(1)) + xs = sl+sr + xt = sqrt(qlm(1)*qrm(1)) + + if(nt.eq.1)then + + r1 = qlm(1) + r7 = qlm(7) + vm = qlm(2)*qlm(5) + qlm(3)*qlm(6) + qlm(4)*qlm(7) + r8 = ql(8) + sa = sl + sn = sign(o1,r7+bs(3)) + tm = -1. + + else + + r1 = qrm(1) + r7 = qrm(7) + vm = qrm(2)*qrm(5) + qrm(3)*qrm(6) + qrm(4)*qrm(7) + r8 = qr(8) + sa = sr + sn = sign(o1,r7+bs(3)) + tm = 1. + + endif + + q(1) = r1 + q(2) = (sl*qlm(2) + sr*qrm(2) + (qr(5) - ql(5))*sn)/xs + q(3) = (sl*qlm(3) + sr*qrm(3) + (qr(6) - ql(6))*sn)/xs + q(4) = sm + q(5) = (sl*qr(5) + sr*ql(5) + (qrm(2) - qlm(2))*sn*xt)/xs + q(6) = (sl*qr(6) + sr*ql(6) + (qrm(3) - qlm(3))*sn*xt)/xs + q(7) = r7 + + vz = q(2)*q(5) + q(3)*q(6) + q(4)*q(7) + + q(2) = q(1)*q(2) + q(3) = q(1)*q(3) + q(4) = q(1)*q(4) + + q(8) = r8 + tm*sa*(vm-vz)*sn + + return + end + + Subroutine pressz_ig(gamma,ql,bs,ul,pt,cfl) + Implicit NONE + + ENZO_REAL ql(8),bs(3) + ENZO_REAL gamma,ul,ck,cb,ds,cfl,qb5,qb6,qb7,bp,bp0,vk,bm,pg,pt + + qb5 = ql(5)+bs(1) + qb6 = ql(6)+bs(2) + qb7 = ql(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + vk = ql(2)**2 + ql(3)**2 + ql(4)**2 + bm = ql(5)**2 + ql(6)**2 + ql(7)**2 + pg = (gamma-1.)*(ql(8) - vk/ql(1)/2. - bm/2.) + + pt = pg + bp/2.-bp0/2. + + ul = ql(4)/ql(1) + + ck = gamma*pg + cb = ck + bp + ds = cb*cb - 4.*ck*qb7**2 + if(ds.le.0.) ds=0. + cfl= sqrt((cb + sqrt(ds))/2./ql(1)) + + return + end + diff --git a/src/Enzo/PPML_IG_MAIN.F b/src/Enzo/PPML_IG_MAIN.F new file mode 100644 index 0000000000..73b08982ba --- /dev/null +++ b/src/Enzo/PPML_IG_MAIN.F @@ -0,0 +1,1633 @@ +c See LICENSE_PPML file for license and copyright information +c PPML MHD solver for Ideal Gas (PPML_IG) + +#include "fortran.h" + + /* #define INCLUDE_GRAVITY */ /* INCOMPLETE */ + + Subroutine PPML_IG(dn,vx,vy,vz,bx,by,bz,pn, + & dnrx,vxrx,vyrx,vzrx,bxrx,byrx,bzrx,pnrx, + & dnry,vxry,vyry,vzry,bxry,byry,bzry,pnry, + & dnrz,vxrz,vyrz,vzrz,bxrz,byrz,bzrz,pnrz, +#ifdef INCLUDE_GRAVITY + & gravity, + & gx,gy,gz, +#endif + & b0, !new + & gamma, !new + & dt, dx,dy,dz, + & nx, ny, nz, + & GridStartIndex, GridEndIndex, + & nsubgrids, lface, rface, + & fistart, fiend, fjstart, fjend, + & array, dnindex, + & vxindex, vyindex, vzindex, + & bxindex, byindex, bzindex, + & pindex, + & f1,f2,f3,f4,f5,f6,f7,f8, + & g1,g2,g3,g4,g5,g6,g7,g8, + & h1,h2,h3,h4,h5,h6,h7,h8, + & ex,ey,ez, + & qu1,qu2,qu3,qu4,qu5,qu6,qu7,qu8) + + Implicit NONE + +c i1,j1,k1 - initial point of grid +c i2,j2,k2 - last point of grid +c ighost,jghost,kghost - number of ghost zones +c dn,vx,vy,vz,bx,by,bz,pn - centered primitive variables +c dnrx,vxrx,vyrx,vzrx,bxrx,byrx,bzrx,pnrx - x-right primitive variables +c dnry,vxry,vyry,vzry,bxry,byry,bzry,pnry - y-right primitive variables +c dnrz,vxrz,vyrz,vzrz,bxrz,byrz,bzrz,pnrz - z-right primitive variables +c f1,f2,f3,f4,f5,f6,f7,f8 - x-fluxes +c g1,g2,g3,g4,g5,g6,g7,g8 - y-fluxes +c h1,h2,h3,h4,h5,h6,h7,h8 - z-fluxes +c gravity - yes/no +c gx,gy,gz - components of gravitation +c b0 - components of uniform magnetic field +#ifdef INCLUDE_GRAVITY + integer gravity +#endif + Integer nx,ny,nz,ighost,jghost,kghost,nsubgrids + Integer nxb,nxe,nyb,nye,nzb,nze + Integer i1,j1,k1,i2,j2,k2,CycleNumber + Integer nxp,nyp,nzp,i,j,k,m,n,idim,offset + Integer GridStartIndex(3), GridEndIndex(3) + Integer m1,m2,m3 + + integer fistart(nsubgrids*3), fiend(nsubgrids*3), + & fjstart(nsubgrids*3), fjend(nsubgrids*3), + & lface(nsubgrids*3) , rface(nsubgrids*3) + integer dnindex(nsubgrids*6), vxindex(nsubgrids*6), + & vyindex(nsubgrids*6), vzindex(nsubgrids*6), + & bxindex(nsubgrids*6), byindex(nsubgrids*6), + & bzindex(nsubgrids*6), pindex(nsubgrids*6) + + ENZO_REAL array(1) + + ENZO_REAL dn(nx,ny,nz),pn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + + ENZO_REAL dnrx(nx,ny,nz),pnrx(nx,ny,nz) + ENZO_REAL vxrx(nx,ny,nz),vyrx(nx,ny,nz),vzrx(nx,ny,nz) + ENZO_REAL bxrx(nx,ny,nz),byrx(nx,ny,nz),bzrx(nx,ny,nz) + + ENZO_REAL dnry(nx,ny,nz),pnry(nx,ny,nz) + ENZO_REAL vxry(nx,ny,nz),vyry(nx,ny,nz),vzry(nx,ny,nz) + ENZO_REAL bxry(nx,ny,nz),byry(nx,ny,nz),bzry(nx,ny,nz) + + ENZO_REAL dnrz(nx,ny,nz),pnrz(nx,ny,nz) + ENZO_REAL vxrz(nx,ny,nz),vyrz(nx,ny,nz),vzrz(nx,ny,nz) + ENZO_REAL bxrz(nx,ny,nz),byrz(nx,ny,nz),bzrz(nx,ny,nz) + + ENZO_REAL f1(nx,ny,nz) + ENZO_REAL f2(nx,ny,nz),f3(nx,ny,nz),f4(nx,ny,nz) + ENZO_REAL f5(nx,ny,nz),f6(nx,ny,nz),f7(nx,ny,nz) + ENZO_REAL f8(nx,ny,nz) + + ENZO_REAL g1(nx,ny,nz) + ENZO_REAL g2(nx,ny,nz),g3(nx,ny,nz),g4(nx,ny,nz) + ENZO_REAL g5(nx,ny,nz),g6(nx,ny,nz),g7(nx,ny,nz) + ENZO_REAL g8(nx,ny,nz) + + ENZO_REAL h1(nx,ny,nz) + ENZO_REAL h2(nx,ny,nz),h3(nx,ny,nz),h4(nx,ny,nz) + ENZO_REAL h5(nx,ny,nz),h6(nx,ny,nz),h7(nx,ny,nz) + ENZO_REAL h8(nx,ny,nz) + + ENZO_REAL ex(nx,ny,nz),ey(nx,ny,nz),ez(nx,ny,nz) + + ENZO_REAL qu1(nx,ny,nz) + ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) + ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) + ENZO_REAL qu8(nx,ny,nz) + +#ifdef INCLUDE_GRAVITY + ENZO_REAL gx(nx,ny,nz),gy(nx,ny,nz),gz(nx,ny,nz) + ENZO_REAL sx(nx,8),sy(ny,8),sz(nz,8) !AK 8? +#endif + ENZO_REAL pn1, pn2 + ENZO_REAL b0(3) + ENZO_REAL bpx(nx,3),bpy(ny,3),bpz(nz,3) + + ENZO_REAL Qp1(nx,8),Qr1(nx,8) + ENZO_REAL Qdy1(nx,8),Qdz1(nx,8) + ENZO_REAL Qlx1(nx,8),Qrx1(nx,8),Qvl1(nx,8),Qvr1(nx,8) + ENZO_REAL Qrp1(nx,8),Fm1(nx,8) + ENZO_REAL dx1(nx),dx2(nx) + + ENZO_REAL Qp2(ny,8),Qr2(ny,8) + ENZO_REAL Qdx2(ny,8),Qdz2(ny,8) + ENZO_REAL Qlx2(ny,8),Qrx2(ny,8),Qvl2(ny,8),Qvr2(ny,8) + ENZO_REAL Qrp2(ny,8),Fm2(ny,8) + ENZO_REAL dy1(ny),dy2(ny) + + ENZO_REAL Qp3(nz,8),Qr3(nz,8) + ENZO_REAL Qdx3(nz,8),Qdy3(nz,8) + ENZO_REAL Qlx3(nz,8),Qrx3(nz,8),Qvl3(nz,8),Qvr3(nz,8) + ENZO_REAL Qrp3(nz,8),Fm3(nz,8) + ENZO_REAL dz1(nz),dz2(nz) + + ENZO_REAL df(nx,ny),vf(nx,ny),uf(nx,ny),wf(nx,ny) + ENZO_REAL bf(nx,ny),tf(nx,ny),pf(nx,ny),rf(nx,ny) + ENZO_REAL dg(ny,nz),vg(ny,nz),ug(ny,nz),wg(ny,nz) + ENZO_REAL bg(ny,nz),tg(ny,nz),pg(ny,nz),rg(ny,nz) + ENZO_REAL dh(nz,nx),vh(nz,nx),uh(nz,nx),wh(nz,nx) + ENZO_REAL bh(nz,nx),th(nz,nx),ph(nz,nx),rh(nz,nx) + + ENZO_REAL vax,vay,vaz,cga,cgs + ENZO_REAL dn1,dn2,vx1,vx2,vy1,vy2,vz1,vz2 + ENZO_REAL bx1,bx2,by1,by2,bz1,bz2 + + ENZO_REAL epsk,v2k,exc,dexy,dexy1,dexy2,exi1,exi2,exk1,exk2 + ENZO_REAL Vleer,dsc,dx,dy,dz,dt + + ENZO_REAL qh(8),qh5,qh6,qh7 + + ENZO_REAL gamma +c +c check-it +c + if (nx.le.0) then +C ERROR_MESSAGE + endif + + i1=GridStartIndex(1)+1 + j1=GridStartIndex(2)+1 + k1=GridStartIndex(3)+1 + + i2=GridEndIndex(1)+1 + j2=GridEndIndex(2)+1 + k2=GridEndIndex(3)+1 + + ighost=GridStartIndex(1) + jghost=GridStartIndex(2) + kghost=GridStartIndex(3) +! SU kghost=GridEndIndex(3) + + if (i1.eq.0) then +C ERROR_MESSAGE + endif + + +! ighost=3 +! jghost=3 +! kghost=3 + +! i1=4 +! j1=4 +! k1=4 + +! i2=Nx-3 +! j2=Ny-3 +! k2=Nz-3 + + + nxb=i1-ighost + nxe=i2+ighost + + nyb=j1-jghost + nye=j2+jghost + + nzb=k1-kghost + nze=k2+kghost + + nxp=nxe-nxb+1 + nyp=nye-nyb+1 + nzp=nze-nzb+1 + +c------------------------------------------------------- +c +c Calculation of flux in x - direction +c +c-------------------------------------------------------- + + Do k=nzb+1,nze-1 + Do j=nyb+1,nye-1 + + Do i=nxb,nxe + + Qp1(i,1)=dn(i,j,k) + Qp1(i,2)=vx(i,j,k) + Qp1(i,3)=vy(i,j,k) + Qp1(i,4)=vz(i,j,k) + Qp1(i,5)=bx(i,j,k) + Qp1(i,6)=by(i,j,k) + Qp1(i,7)=bz(i,j,k) + Qp1(i,8)=pn(i,j,k) + + Qr1(i,1)=dnrx(i,j,k) + Qr1(i,2)=vxrx(i,j,k) + Qr1(i,3)=vyrx(i,j,k) + Qr1(i,4)=vzrx(i,j,k) + Qr1(i,5)=bxrx(i,j,k) + Qr1(i,6)=byrx(i,j,k) + Qr1(i,7)=bzrx(i,j,k) + Qr1(i,8)=pnrx(i,j,k) + + Qdy1(i,1)=VLeer(dn(i,j+1,k)-dn(i,j,k),dn(i,j,k)-dn(i,j-1,k)) + Qdy1(i,2)=VLeer(vx(i,j+1,k)-vx(i,j,k),vx(i,j,k)-vx(i,j-1,k)) + Qdy1(i,3)=VLeer(vy(i,j+1,k)-vy(i,j,k),vy(i,j,k)-vy(i,j-1,k)) + Qdy1(i,4)=VLeer(vz(i,j+1,k)-vz(i,j,k),vz(i,j,k)-vz(i,j-1,k)) + Qdy1(i,5)=VLeer(bx(i,j+1,k)-bx(i,j,k),bx(i,j,k)-bx(i,j-1,k)) + Qdy1(i,6)=VLeer(by(i,j+1,k)-by(i,j,k),by(i,j,k)-by(i,j-1,k)) + Qdy1(i,7)=VLeer(bz(i,j+1,k)-bz(i,j,k),bz(i,j,k)-bz(i,j-1,k)) + Qdy1(i,8)=VLeer(pn(i,j+1,k)-pn(i,j,k),pn(i,j,k)-pn(i,j-1,k)) + + Qdz1(i,1)=VLeer(dn(i,j,k+1)-dn(i,j,k),dn(i,j,k)-dn(i,j,k-1)) + Qdz1(i,2)=VLeer(vx(i,j,k+1)-vx(i,j,k),vx(i,j,k)-vx(i,j,k-1)) + Qdz1(i,3)=VLeer(vy(i,j,k+1)-vy(i,j,k),vy(i,j,k)-vy(i,j,k-1)) + Qdz1(i,4)=VLeer(vz(i,j,k+1)-vz(i,j,k),vz(i,j,k)-vz(i,j,k-1)) + Qdz1(i,5)=VLeer(bx(i,j,k+1)-bx(i,j,k),bx(i,j,k)-bx(i,j,k-1)) + Qdz1(i,6)=VLeer(by(i,j,k+1)-by(i,j,k),by(i,j,k)-by(i,j,k-1)) + Qdz1(i,7)=VLeer(bz(i,j,k+1)-bz(i,j,k),bz(i,j,k)-bz(i,j,k-1)) + Qdz1(i,8)=VLeer(pn(i,j,k+1)-pn(i,j,k),pn(i,j,k)-pn(i,j,k-1)) + +#ifdef INCLUDE_GRAVITY + Sx(i,1)=0. + if (gravity .eq. 1) then + Sx(i,2)=gx(i,j,k) + Sx(i,3)=gy(i,j,k) + Sx(i,4)=gz(i,j,k) + else + Sx(i,2)=0. + Sx(i,3)=0. + Sx(i,4)=0. + endif + Sx(i,5)=0. + Sx(i,6)=0. + Sx(i,7)=0. + Sx(i,8)=0. +#endif + Bpx(i,1)=b0(1) + Bpx(i,2)=b0(2) + Bpx(i,3)=b0(3) + + Enddo + + Do i=nxb,nxe + + dx1(i)=0. + dx2(i)=0. + + Enddo + + Do i=nxb+2,nxe-2 + + vax=0.5*(vx(i+2,j,k)+vx(i+1,j,k)) + vay=0.5*(vx(i,j,k)+vx(i-1,j,k)) + + vaz=0.5*(vy(i,j+1,k)+vy(i+1,j+1,k)) + cga=0.5*(vy(i,j-1,k)+vy(i+1,j-1,k)) + + dsc=0.5*(vz(i,j,k+1)+vz(i+1,j,k+1)) + cgs=0.5*(vz(i,j,k-1)+vz(i+1,j,k-1)) + + dx2(i)=vax-vay+vaz-cga+dsc-cgs + + vax=0.5*(vx(i+1,j,k)+vx(i,j,k)) + vay=0.5*(vx(i-1,j,k)+vx(i-2,j,k)) + + vaz=0.5*(vy(i-1,j+1,k)+vy(i,j+1,k)) + cga=0.5*(vy(i-1,j-1,k)+vy(i,j-1,k)) + + dsc=0.5*(vz(i-1,j,k+1)+vz(i,j,k+1)) + cgs=0.5*(vz(i-1,j,k-1)+vz(i,j,k-1)) + + dx1(i)=vax-vay+vaz-cga+dsc-cgs + + Enddo + + Call Monot_ig(1,nxp,gamma,Dx1,Dx2,Bpx,qp1,qr1,qlx1,qrx1) + + Do i=nxb+1,nxe + Qlx1(i,5)=Qr1(i-1,5) + Qrx1(i,5)=Qr1(i,5) + Enddo + + Do i=nxb+1,nxe-1 + + dn1=Qp1(i,1) + dn2=dn1 + + vx1=Qp1(i,2) + vx2=vx1 + vy1=Qp1(i,3) + vy2=vy1 + vz1=Qp1(i,4) + vz2=vz1 + + bx1=Qp1(i,5) + bx2=bx1 + by1=Qp1(i,6) + by2=by1 + bz1=Qp1(i,7) + bz2=bz1 + + pn1=Qp1(i,8) + pn2=pn1 + + do m3=k-1,k+1 + do m2=j-1,j+1 + do m1=i-1,i+1 + + dn1=min(dn1,dn(m1,m2,m3)) + dn2=max(dn2,dn(m1,m2,m3)) + + vx1=min(vx1,vx(m1,m2,m3)) + vx2=max(vx2,vx(m1,m2,m3)) + + vy1=min(vy1,vy(m1,m2,m3)) + vy2=max(vy2,vy(m1,m2,m3)) + + vz1=min(vz1,vz(m1,m2,m3)) + vz2=max(vz2,vz(m1,m2,m3)) + + bx1=min(bx1,bx(m1,m2,m3)) + bx2=max(bx2,bx(m1,m2,m3)) + + by1=min(by1,by(m1,m2,m3)) + by2=max(by2,by(m1,m2,m3)) + + bz1=min(bz1,bz(m1,m2,m3)) + bz2=max(bz2,bz(m1,m2,m3)) + + pn1=min(pn1,pn(m1,m2,m3)) + pn2=max(pn2,pn(m1,m2,m3)) + + Enddo + Enddo + Enddo + + qlx1(i,1)=max(dn1,min(dn2,qlx1(i,1))) + qrx1(i,1)=max(dn1,min(dn2,qrx1(i,1))) + + qlx1(i,2)=max(vx1,min(vx2,qlx1(i,2))) + qrx1(i,2)=max(vx1,min(vx2,qrx1(i,2))) + + qlx1(i,3)=max(vy1,min(vy2,qlx1(i,3))) + qrx1(i,3)=max(vy1,min(vy2,qrx1(i,3))) + + qlx1(i,4)=max(vz1,min(vz2,qlx1(i,4))) + qrx1(i,4)=max(vz1,min(vz2,qrx1(i,4))) + + qlx1(i,6)=max(by1,min(by2,qlx1(i,6))) + qrx1(i,6)=max(by1,min(by2,qrx1(i,6))) + + qlx1(i,7)=max(bz1,min(bz2,qlx1(i,7))) + qrx1(i,7)=max(bz1,min(bz2,qrx1(i,7))) + + qlx1(i,8)=max(pn1,min(pn2,qlx1(i,8))) + qrx1(i,8)=max(pn1,min(pn2,qrx1(i,8))) + + Enddo + + CALL QDD6_ig(nxp,Qrx1,Qlx1,Qvr1,Qvl1,Qp1) + + Do i=nxb,nxe + Qvl1(i,5)=Qlx1(i,5) + Qvr1(i,5)=Qrx1(i,5) + Enddo + +#ifdef INCLUDE_GRAVITY + CALL POTOKx_ig(nxp,gamma,Dx,Dt,Bpx,Qvl1,Qvr1,Qp1,Qdy1,Qdz1,Sx,Qrp1,Fm1) +#else + CALL POTOKx_ig(nxp,gamma,Dx,Dt,Bpx,Qvl1,Qvr1,Qp1,Qdy1,Qdz1,Qrp1,fm1) +#endif + Do i=i1-1,i2 + + dnrx(i,j,k)=Qrp1(i,1) + vxrx(i,j,k)=Qrp1(i,2) + vyrx(i,j,k)=Qrp1(i,3) + vzrx(i,j,k)=Qrp1(i,4) + byrx(i,j,k)=Qrp1(i,6) + bzrx(i,j,k)=Qrp1(i,7) + pnrx(i,j,k)=Qrp1(i,8) + + F1(i,j,k)=fm1(i,1) + F2(i,j,k)=fm1(i,2) + F3(i,j,k)=fm1(i,3) + F4(i,j,k)=fm1(i,4) + F5(i,j,k)=fm1(i,5) + F6(i,j,k)=fm1(i,6) + F7(i,j,k)=fm1(i,7) + F8(i,j,k)=fm1(i,8) + + Enddo + + Enddo + Enddo + +c------------------------------------------------------- +c +c Calculation of flux in y - direction +c +c-------------------------------------------------------- + + Do k=nzb+1,nze-1 + Do i=nxb+1,nxe-1 + + Do j=nyb,nye + + Qp2(j,1)=dn(i,j,k) + Qp2(j,2)=vx(i,j,k) + Qp2(j,3)=vy(i,j,k) + Qp2(j,4)=vz(i,j,k) + Qp2(j,5)=bx(i,j,k) + Qp2(j,6)=by(i,j,k) + Qp2(j,7)=bz(i,j,k) + Qp2(j,8)=pn(i,j,k) + + Qr2(j,1)=dnry(i,j,k) + Qr2(j,2)=vxry(i,j,k) + Qr2(j,3)=vyry(i,j,k) + Qr2(j,4)=vzry(i,j,k) + Qr2(j,5)=bxry(i,j,k) + Qr2(j,6)=byry(i,j,k) + Qr2(j,7)=bzry(i,j,k) + Qr2(j,8)=pnry(i,j,k) + + Qdx2(j,1)=VLeer(dn(i+1,j,k)-dn(i,j,k),dn(i,j,k)-dn(i-1,j,k)) + Qdx2(j,2)=VLeer(vx(i+1,j,k)-vx(i,j,k),vx(i,j,k)-vx(i-1,j,k)) + Qdx2(j,3)=VLeer(vy(i+1,j,k)-vy(i,j,k),vy(i,j,k)-vy(i-1,j,k)) + Qdx2(j,4)=VLeer(vz(i+1,j,k)-vz(i,j,k),vz(i,j,k)-vz(i-1,j,k)) + Qdx2(j,5)=VLeer(bx(i+1,j,k)-bx(i,j,k),bx(i,j,k)-bx(i-1,j,k)) + Qdx2(j,6)=VLeer(by(i+1,j,k)-by(i,j,k),by(i,j,k)-by(i-1,j,k)) + Qdx2(j,7)=VLeer(bz(i+1,j,k)-bz(i,j,k),bz(i,j,k)-bz(i-1,j,k)) + Qdx2(j,8)=VLeer(pn(i+1,j,k)-pn(i,j,k),pn(i,j,k)-pn(i-1,j,k)) + + Qdz2(j,1)=VLeer(dn(i,j,k+1)-dn(i,j,k),dn(i,j,k)-dn(i,j,k-1)) + Qdz2(j,2)=VLeer(vx(i,j,k+1)-vx(i,j,k),vx(i,j,k)-vx(i,j,k-1)) + Qdz2(j,3)=VLeer(vy(i,j,k+1)-vy(i,j,k),vy(i,j,k)-vy(i,j,k-1)) + Qdz2(j,4)=VLeer(vz(i,j,k+1)-vz(i,j,k),vz(i,j,k)-vz(i,j,k-1)) + Qdz2(j,5)=VLeer(bx(i,j,k+1)-bx(i,j,k),bx(i,j,k)-bx(i,j,k-1)) + Qdz2(j,6)=VLeer(by(i,j,k+1)-by(i,j,k),by(i,j,k)-by(i,j,k-1)) + Qdz2(j,7)=VLeer(bz(i,j,k+1)-bz(i,j,k),bz(i,j,k)-bz(i,j,k-1)) + Qdz2(j,8)=VLeer(pn(i,j,k+1)-pn(i,j,k),pn(i,j,k)-pn(i,j,k-1)) + +#ifdef INCLUDE_GRAVITY + Sy(j,1)=0. + if (gravity .eq. 1) then + Sy(j,2)=gx(i,j,k) + Sy(j,3)=gy(i,j,k) + Sy(j,4)=gz(i,j,k) + else + Sy(j,2)=0. + Sy(j,3)=0. + Sy(j,4)=0. + endif + Sy(j,5)=0. + Sy(j,6)=0. + Sy(j,7)=0. + Sy(j,8)=0. +#endif + + Bpy(j,1)=b0(1) + Bpy(j,2)=b0(2) + Bpy(j,3)=b0(3) + + Enddo + + Do j=nyb,nye + + dy1(j)=0. + dy2(j)=0. + + Enddo + + Do j=nyb+2,nye-2 + + vax=0.5*(vy(i,j+2,k)+vy(i,j+1,k)) + vay=0.5*(vy(i,j,k)+vy(i,j-1,k)) + + vaz=0.5*(vx(i+1,j,k)+vx(i+1,j+1,k)) + cga=0.5*(vx(i-1,j,k)+vx(i-1,j+1,k)) + + dsc=0.5*(vz(i,j,k+1)+vz(i,j+1,k+1)) + cgs=0.5*(vz(i,j,k-1)+vz(i,j+1,k-1)) + + dy2(j)=vax-vay+vaz-cga+dsc-cgs + + vax=0.5*(vy(i,j+1,k)+vy(i,j,k)) + vay=0.5*(vy(i,j-1,k)+vy(i,j-2,k)) + + vaz=0.5*(vx(i+1,j-1,k)+vx(i+1,j,k)) + cga=0.5*(vx(i-1,j-1,k)+vx(i-1,j,k)) + + dsc=0.5*(vz(i,j-1,k+1)+vz(i,j,k+1)) + cgs=0.5*(vz(i,j-1,k-1)+vz(i,j,k-1)) + + dy1(j)=vax-vay+vaz-cga+dsc-cgs + + + Enddo + + Call Monot_ig(2,nyp,gamma,Dy1,Dy2,Bpy,qp2,qr2,qlx2,qrx2) + + Do j=nyb+1,nye + Qlx2(j,6)=Qr2(j-1,6) + Qrx2(j,6)=Qr2(j,6) + Enddo + + Do j=nyb+1,nye-1 + + dn1=Qp2(j,1) + dn2=dn1 + + vx1=Qp2(j,2) + vx2=vx1 + vy1=Qp2(j,3) + vy2=vy1 + vz1=Qp2(j,4) + vz2=vz1 + + bx1=Qp2(j,5) + bx2=bx1 + by1=Qp2(j,6) + by2=by1 + bz1=Qp2(j,7) + bz2=bz1 + + pn1=Qp2(j,8) + pn2=pn1 + + do m3=k-1,k+1 + do m2=j-1,j+1 + do m1=i-1,i+1 + + dn1=min(dn1,dn(m1,m2,m3)) + dn2=max(dn2,dn(m1,m2,m3)) + + vx1=min(vx1,vx(m1,m2,m3)) + vx2=max(vx2,vx(m1,m2,m3)) + + vy1=min(vy1,vy(m1,m2,m3)) + vy2=max(vy2,vy(m1,m2,m3)) + + vz1=min(vz1,vz(m1,m2,m3)) + vz2=max(vz2,vz(m1,m2,m3)) + + bx1=min(bx1,bx(m1,m2,m3)) + bx2=max(bx2,bx(m1,m2,m3)) + + by1=min(by1,by(m1,m2,m3)) + by2=max(by2,by(m1,m2,m3)) + + bz1=min(bz1,bz(m1,m2,m3)) + bz2=max(bz2,bz(m1,m2,m3)) + + pn1=min(pn1,pn(m1,m2,m3)) + pn2=max(pn2,pn(m1,m2,m3)) + + Enddo + Enddo + Enddo + + qlx2(j,1)=max(dn1,min(dn2,qlx2(j,1))) + qrx2(j,1)=max(dn1,min(dn2,qrx2(j,1))) + + qlx2(j,2)=max(vx1,min(vx2,qlx2(j,2))) + qrx2(j,2)=max(vx1,min(vx2,qrx2(j,2))) + + qlx2(j,3)=max(vy1,min(vy2,qlx2(j,3))) + qrx2(j,3)=max(vy1,min(vy2,qrx2(j,3))) + + qlx2(j,4)=max(vz1,min(vz2,qlx2(j,4))) + qrx2(j,4)=max(vz1,min(vz2,qrx2(j,4))) + + qlx2(j,5)=max(bx1,min(bx2,qlx2(j,5))) + qrx2(j,5)=max(bx1,min(bx2,qrx2(j,5))) + + qlx2(j,7)=max(bz1,min(bz2,qlx2(j,7))) + qrx2(j,7)=max(bz1,min(bz2,qrx2(j,7))) + + qlx2(j,8)=max(pn1,min(pn2,qlx2(j,8))) + qrx2(j,8)=max(pn1,min(pn2,qrx2(j,8))) + + Enddo + + CALL QDD6_ig(nyp,Qrx2,Qlx2,Qvr2,Qvl2,Qp2) + + Do j=nyb,nye + Qvl2(j,6)=Qlx2(j,6) + Qvr2(j,6)=Qrx2(j,6) + Enddo + +#ifdef INCLUDE_GRAVITY + CALL POTOKy_ig(nyp,gamma,Dx,Dt,Bpy,Qvl2,Qvr2,Qp2,Qdx2,Qdz2,Sy,Qrp2,Fm2) +#else + CALL POTOKy_ig(nyp,gamma,Dx,Dt,Bpy,Qvl2,Qvr2,Qp2,Qdx2,Qdz2,Qrp2,Fm2) +#endif + + + Do j=j1-1,j2 + + dnry(i,j,k)=Qrp2(j,1) + vxry(i,j,k)=Qrp2(j,2) + vyry(i,j,k)=Qrp2(j,3) + vzry(i,j,k)=Qrp2(j,4) + bxry(i,j,k)=Qrp2(j,5) + bzry(i,j,k)=Qrp2(j,7) + pnry(i,j,k)=Qrp2(j,8) + + G1(i,j,k)=Fm2(j,1) + G2(i,j,k)=Fm2(j,2) + G3(i,j,k)=Fm2(j,3) + G4(i,j,k)=Fm2(j,4) + G5(i,j,k)=Fm2(j,5) + G6(i,j,k)=Fm2(j,6) + G7(i,j,k)=Fm2(j,7) + G8(i,j,k)=Fm2(j,8) + + Enddo + + Enddo + Enddo + +c------------------------------------------------------- +c +c Calculation of flux in z - direction +c +c-------------------------------------------------------- + + Do j=nyb+1,nye-1 + Do i=nxb+1,nxe-1 + + Do k=nzb,nze + + Qp3(k,1)=dn(i,j,k) + Qp3(k,2)=vx(i,j,k) + Qp3(k,3)=vy(i,j,k) + Qp3(k,4)=vz(i,j,k) + Qp3(k,5)=bx(i,j,k) + Qp3(k,6)=by(i,j,k) + Qp3(k,7)=bz(i,j,k) + Qp3(k,8)=pn(i,j,k) + + Qr3(k,1)=dnrz(i,j,k) + Qr3(k,2)=vxrz(i,j,k) + Qr3(k,3)=vyrz(i,j,k) + Qr3(k,4)=vzrz(i,j,k) + Qr3(k,5)=bxrz(i,j,k) + Qr3(k,6)=byrz(i,j,k) + Qr3(k,7)=bzrz(i,j,k) + Qr3(k,8)=pnrz(i,j,k) + + Qdx3(k,1)=VLeer(dn(i+1,j,k)-dn(i,j,k),dn(i,j,k)-dn(i-1,j,k)) + Qdx3(k,2)=VLeer(vx(i+1,j,k)-vx(i,j,k),vx(i,j,k)-vx(i-1,j,k)) + Qdx3(k,3)=VLeer(vy(i+1,j,k)-vy(i,j,k),vy(i,j,k)-vy(i-1,j,k)) + Qdx3(k,4)=VLeer(vz(i+1,j,k)-vz(i,j,k),vz(i,j,k)-vz(i-1,j,k)) + Qdx3(k,5)=VLeer(bx(i+1,j,k)-bx(i,j,k),bx(i,j,k)-bx(i-1,j,k)) + Qdx3(k,6)=VLeer(by(i+1,j,k)-by(i,j,k),by(i,j,k)-by(i-1,j,k)) + Qdx3(k,7)=VLeer(bz(i+1,j,k)-bz(i,j,k),bz(i,j,k)-bz(i-1,j,k)) + Qdx3(k,8)=VLeer(pn(i+1,j,k)-pn(i,j,k),pn(i,j,k)-pn(i-1,j,k)) + + Qdy3(k,1)=VLeer(dn(i,j+1,k)-dn(i,j,k),dn(i,j,k)-dn(i,j-1,k)) + Qdy3(k,2)=VLeer(vx(i,j+1,k)-vx(i,j,k),vx(i,j,k)-vx(i,j-1,k)) + Qdy3(k,3)=VLeer(vy(i,j+1,k)-vy(i,j,k),vy(i,j,k)-vy(i,j-1,k)) + Qdy3(k,4)=VLeer(vz(i,j+1,k)-vz(i,j,k),vz(i,j,k)-vz(i,j-1,k)) + Qdy3(k,5)=VLeer(bx(i,j+1,k)-bx(i,j,k),bx(i,j,k)-bx(i,j-1,k)) + Qdy3(k,6)=VLeer(by(i,j+1,k)-by(i,j,k),by(i,j,k)-by(i,j-1,k)) + Qdy3(k,7)=VLeer(bz(i,j+1,k)-bz(i,j,k),bz(i,j,k)-bz(i,j-1,k)) + Qdy3(k,8)=VLeer(pn(i,j+1,k)-pn(i,j,k),pn(i,j,k)-pn(i,j-1,k)) + +#ifdef INCLUDE_GRAVITY + Sz(k,1)=0. + if (gravity .eq. 1) then + Sz(k,2)=gx(i,j,k) + Sz(k,3)=gy(i,j,k) + Sz(k,4)=gz(i,j,k) + else + Sz(k,2)=0. + Sz(k,3)=0. + Sz(k,4)=0. + endif + Sz(k,5)=0. + Sz(k,6)=0. + Sz(k,7)=0. + Sz(k,8)=0. +#endif + + Bpz(k,1)=b0(1) + Bpz(k,2)=b0(2) + Bpz(k,3)=b0(3) + + Enddo + + Do k=nzb,nze + + dz1(k)=0. + dz2(k)=0. + + Enddo + + Do k=nzb+2,nze-2 + + vax=0.5*(vz(i,j,k+2)+vz(i,j,k+1)) + vay=0.5*(vz(i,j,k)+vz(i,j,k-1)) + + vaz=0.5*(vx(i+1,j,k)+vx(i+1,j,k+1)) + cga=0.5*(vx(i-1,j,k)+vx(i-1,j,k+1)) + + dsc=0.5*(vy(i,j+1,k)+vy(i,j+1,k+1)) + cgs=0.5*(vy(i,j-1,k)+vy(i,j-1,k+1)) + + dz2(k)=vax-vay+vaz-cga+dsc-cgs + + vax=0.5*(vz(i,j,k+1)+vz(i,j,k)) + vay=0.5*(vz(i,j,k-1)+vz(i,j,k-2)) + + vaz=0.5*(vx(i+1,j,k-1)+vx(i+1,j,k)) + cga=0.5*(vx(i-1,j,k-1)+vx(i-1,j,k)) + + dsc=0.5*(vy(i,j+1,k-1)+vy(i,j+1,k)) + cgs=0.5*(vy(i,j-1,k-1)+vy(i,j-1,k)) + + dz1(k)=vax-vay+vaz-cga+dsc-cgs + + + Enddo + + Call Monot_ig(3,nzp,gamma,Dz1,Dz2,Bpz,Qp3,Qr3,qlx3,qrx3) + + Do k=nzb+1,nze + Qlx3(k,7)=Qr3(k-1,7) + Qrx3(k,7)=Qr3(k,7) + Enddo + + Do k=nzb+1,nze-1 + + dn1=Qp3(k,1) + dn2=dn1 + + vx1=Qp3(k,2) + vx2=vx1 + vy1=Qp3(k,3) + vy2=vy1 + vz1=Qp3(k,4) + vz2=vz1 + + bx1=Qp3(k,5) + bx2=bx1 + by1=Qp3(k,6) + by2=by1 + bz1=Qp3(k,7) + bz2=bz1 + + pn1=Qp3(k,8) + pn2=pn1 + + do m3=k-1,k+1 + do m2=j-1,j+1 + do m1=i-1,i+1 + + dn1=min(dn1,dn(m1,m2,m3)) + dn2=max(dn2,dn(m1,m2,m3)) + + vx1=min(vx1,vx(m1,m2,m3)) + vx2=max(vx2,vx(m1,m2,m3)) + + vy1=min(vy1,vy(m1,m2,m3)) + vy2=max(vy2,vy(m1,m2,m3)) + + vz1=min(vz1,vz(m1,m2,m3)) + vz2=max(vz2,vz(m1,m2,m3)) + + bx1=min(bx1,bx(m1,m2,m3)) + bx2=max(bx2,bx(m1,m2,m3)) + + by1=min(by1,by(m1,m2,m3)) + by2=max(by2,by(m1,m2,m3)) + + bz1=min(bz1,bz(m1,m2,m3)) + bz2=max(bz2,bz(m1,m2,m3)) + + pn1=min(pn1,pn(m1,m2,m3)) + pn2=max(pn2,pn(m1,m2,m3)) + + Enddo + Enddo + Enddo + + qlx3(k,1)=max(dn1,min(dn2,qlx3(k,1))) + qrx3(k,1)=max(dn1,min(dn2,qrx3(k,1))) + + qlx3(k,2)=max(vx1,min(vx2,qlx3(k,2))) + qrx3(k,2)=max(vx1,min(vx2,qrx3(k,2))) + + qlx3(k,3)=max(vy1,min(vy2,qlx3(k,3))) + qrx3(k,3)=max(vy1,min(vy2,qrx3(k,3))) + + qlx3(k,4)=max(vz1,min(vz2,qlx3(k,4))) + qrx3(k,4)=max(vz1,min(vz2,qrx3(k,4))) + + qlx3(k,5)=max(bx1,min(bx2,qlx3(k,5))) + qrx3(k,5)=max(bx1,min(bx2,qrx3(k,5))) + + qlx3(k,6)=max(by1,min(by2,qlx3(k,6))) + qrx3(k,6)=max(by1,min(by2,qrx3(k,6))) + +! bug qlx3(k,7)=max(bz1,min(bz2,qlx3(k,7))) +! bug qrx3(k,7)=max(bz1,min(bz2,qrx3(k,7))) + + qlx3(k,8)=max(pn1,min(pn2,qlx3(k,8))) + qrx3(k,8)=max(pn1,min(pn2,qrx3(k,8))) + + Enddo + + CALL QDD6_ig(nzp,Qrx3,Qlx3,Qvr3,Qvl3,Qp3) + + Do k=nzb,nze + Qvl3(k,7)=Qlx3(k,7) + Qvr3(k,7)=Qrx3(k,7) + Enddo + +#ifdef INCLUDE_GRAVITY + CALL POTOKz_ig(nzp,gamma,Dx,Dt,Bpz,Qvl3,Qvr3,Qp3,Qdx3,Qdy3,Sz,Qrp3,Fm3) +#else + CALL POTOKz_ig(nzp,gamma,Dx,Dt,Bpz,Qvl3,Qvr3,Qp3,Qdx3,Qdy3,Qrp3,Fm3) +#endif + + Do k=k1-1,k2 + + dnrz(i,j,k)=Qrp3(k,1) + vxrz(i,j,k)=Qrp3(k,2) + vyrz(i,j,k)=Qrp3(k,3) + vzrz(i,j,k)=Qrp3(k,4) + bxrz(i,j,k)=Qrp3(k,5) + byrz(i,j,k)=Qrp3(k,6) + pnrz(i,j,k)=Qrp3(k,8) + + H1(i,j,k)=Fm3(k,1) + H2(i,j,k)=Fm3(k,2) + H3(i,j,k)=Fm3(k,3) + H4(i,j,k)=Fm3(k,4) + H5(i,j,k)=Fm3(k,5) + H6(i,j,k)=Fm3(k,6) + H7(i,j,k)=Fm3(k,7) + H8(i,j,k)=Fm3(k,8) + + Enddo + + Enddo + Enddo + +!--------------------------------------------------------------- +! +! Gardiner&Stone CT +! +!----------------------------------------------------------------- + + epsk=1.0e-12 + + DO K=k1-1,k2 + DO J=j1-1,j2 + DO I=i1,i2 + + v2k=0.5*(vz(i,j,k)+vz(i,j,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vy(i,j,k)*(bz(i,j,k)+b0(3))-vz(i,j,k)* + & (by(i,j,k)+b0(2))) + + dexy=-g7(i,j,k)-exc + + else + + exc=-(vy(i,j,k+1)*(bz(i,j,k+1)+b0(3))- + & vz(i,j,k+1)*(by(i,j,k+1)+b0(2))) + + dexy=-g7(i,j,k+1)-exc + + endif + + else + + exc=-(vy(i,j,k)*(bz(i,j,k)+b0(3))-vz(i,j,k)* + & (by(i,j,k)+b0(2))) + + dexy1=-g7(i,j,k)-exc + + exc=-(vy(i,j,k+1)*(bz(i,j,k+1)+b0(3))- + & vz(i,j,k+1)*(by(i,j,k+1)+b0(2))) + + dexy2=-g7(i,j,k+1)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi1=h6(i,j,k)+dexy + + + + v2k=0.5*(vz(i,j+1,k)+vz(i,j+1,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vy(i,j+1,k)*(bz(i,j+1,k)+b0(3))- + & vz(i,j+1,k)*(by(i,j+1,k)+b0(2))) + dexy=-g7(i,j,k)-exc + + else + + + exc=-(vy(i,j+1,k+1)*(bz(i,j+1,k+1)+b0(3))- + & vz(i,j+1,k+1)*(by(i,j+1,k+1)+b0(2))) + dexy=-g7(i,j,k+1)-exc + + endif + else + + exc=-(vy(i,j+1,k)*(bz(i,j+1,k)+b0(3))-vz(i,j+1,k)* + & (by(i,j+1,k)+b0(2))) + dexy1=-g7(i,j,k)-exc + + exc=-(vy(i,j+1,k+1)*(bz(i,j+1,k+1)+b0(3))- + & vz(i,j+1,k+1)*(by(i,j+1,k+1)+b0(2))) + dexy2=-g7(i,j,k+1)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi2=h6(i,j+1,k)+dexy + + + + + v2k=0.5*(vy(i,j,k)+vy(i,j+1,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vy(i,j,k)*(bz(i,j,k)+b0(3))-vz(i,j,k)* + & (by(i,j,k)+b0(2))) + dexy=h6(i,j,k)-exc + + else + + exc=-(vy(i,j+1,k)*(bz(i,j+1,k)+b0(3))- + & vz(i,j+1,k)*(by(i,j+1,k)+b0(2))) + dexy=h6(i,j+1,k)-exc + + endif + + else + + exc=-(vy(i,j,k)*(bz(i,j,k)+b0(3))- + & vz(i,j,k)*(by(i,j,k)+b0(2))) + dexy1=h6(i,j,k)-exc + + exc=-(vy(i,j+1,k)*(bz(i,j+1,k)+b0(3))- + & vz(i,j+1,k)*(by(i,j+1,k)+b0(2))) + dexy2=h6(i,j+1,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exk1=-g7(i,j,k)+dexy + + + + v2k=0.5*(vy(i,j,k+1)+vy(i,j+1,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vy(i,j,k+1)*(bz(i,j,k+1)+b0(3))- + & vz(i,j,k+1)*(by(i,j,k+1)+b0(2))) + + dexy=h6(i,j,k)-exc + + else + + exc=-(vy(i,j+1,k+1)*(bz(i,j+1,k+1)+b0(3))- + & vz(i,j+1,k+1)*(by(i,j+1,k+1)+b0(2))) + + dexy=h6(i,j+1,k)-exc + + endif + + + else + + exc=-(vy(i,j,k+1)*(bz(i,j,k+1)+b0(3))- + & vz(i,j,k+1)*(by(i,j,k+1)+b0(2))) + + dexy1=h6(i,j,k)-exc + + exc=-(vy(i,j+1,k+1)*(bz(i,j+1,k+1)+b0(3))- + & vz(i,j+1,k+1)*(by(i,j+1,k+1)+b0(2))) + + dexy2=h6(i,j+1,k)-exc + + dexy=0.5*(dexy1+dexy2) + + + endif + + exk2=-g7(i,j,k+1)+dexy + + ex(I,J,K)=0.25*(exi1+exi2+exk1+exk2) + + ENDDO + ENDDO + ENDDO + + DO K=k1-1,k2 + DO J=j1,j2 + DO I=i1-1,i2 + + + v2k=0.5*(vx(i,j,k)+vx(i+1,j,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + exc=-(vz(i,j,k)*(bx(i,j,k)+b0(1))-vx(i,j,k)* + & (bz(i,j,k)+b0(3))) + + dexy=-h5(i,j,k)-exc + + else + + exc=-(vz(i+1,j,k)*(bx(i+1,j,k)+b0(1))- + & vx(i+1,j,k)*(bz(i+1,j,k)+b0(3))) + + dexy=-h5(i+1,j,k)-exc + + endif + + + else + + exc=-(vz(i,j,k)*(bx(i,j,k)+b0(1))- + & vx(i,j,k)*(bz(i,j,k)+b0(3))) + + dexy1=-h5(i,j,k)-exc + + exc=-(vz(i+1,j,k)*(bx(i+1,j,k)+b0(1))- + & vx(i+1,j,k)*(bz(i+1,j,k)+b0(3))) + + dexy2=-h5(i+1,j,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi1=f7(i,j,k)+dexy + + + + + v2k=0.5*(vx(i,j,k+1)+vx(i+1,j,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vz(i,j,k+1)*(bx(i,j,k+1)+b0(1))- + & vx(i,j,k+1)*(bz(i,j,k+1)+b0(3))) + + dexy=-h5(i,j,k)-exc + + else + + exc=-(vz(i+1,j,k+1)*(bx(i+1,j,k+1)+b0(1))- + & vx(i+1,j,k+1)*(bz(i+1,j,k+1)+b0(3))) + + dexy=-h5(i+1,j,k)-exc + + endif + + else + + exc=-(vz(i,j,k+1)*(bx(i,j,k+1)+b0(1))- + & vx(i,j,k+1)*(bz(i,j,k+1)+b0(3))) + + dexy1=-h5(i,j,k)-exc + + exc=-(vz(i+1,j,k+1)*(bx(i+1,j,k+1)+b0(1))- + & vx(i+1,j,k+1)*(bz(i+1,j,k+1)+b0(3))) + + dexy2=-h5(i+1,j,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi2=f7(i,j,k+1)+dexy + + + + + + v2k=0.5*(vz(i,j,k)+vz(i,j,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vz(i,j,k)*(bx(i,j,k)+b0(1))- + & vx(i,j,k)*(bz(i,j,k)+b0(3))) + + dexy=f7(i,j,k)-exc + + else + + exc=-(vz(i,j,k+1)*(bx(i,j,k+1)+b0(1))- + & vx(i,j,k+1)*(bz(i,j,k+1)+b0(3))) + + dexy=f7(i,j,k+1)-exc + + endif + + else + + exc=-(vz(i,j,k)*(bx(i,j,k)+b0(1))- + & vx(i,j,k)*(bz(i,j,k)+b0(3))) + + dexy1=f7(i,j,k)-exc + + exc=-(vz(i,j,k+1)*(bx(i,j,k+1)+b0(1))- + & vx(i,j,k+1)*(bz(i,j,k+1)+b0(3))) + + dexy2=f7(i,j,k+1)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exk1=-h5(i,j,k)+dexy + + + + + v2k=0.5*(vz(i+1,j,k)+vz(i+1,j,k+1)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vz(i+1,j,k)*(bx(i+1,j,k)+b0(1))- + & vx(i+1,j,k)*(bz(i+1,j,k)+b0(3))) + + dexy=f7(i,j,k)-exc + + else + + exc=-(vz(i+1,j,k+1)*(bx(i+1,j,k+1)+b0(1))- + & vx(i+1,j,k+1)*(bz(i+1,j,k+1)+b0(3))) + + dexy=f7(i,j,k+1)-exc + + endif + + else + + exc=-(vz(i+1,j,k)*(bx(i+1,j,k)+b0(1))- + & vx(i+1,j,k)*(bz(i+1,j,k)+b0(3))) + + dexy1=f7(i,j,k)-exc + + exc=-(vz(i+1,j,k+1)*(bx(i+1,j,k+1)+b0(1))- + & vx(i+1,j,k+1)*(bz(i+1,j,k+1)+b0(3))) + + dexy2=f7(i,j,k+1)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exk2=-h5(i+1,j,k)+dexy + + + ey(I,J,K)=0.25*(exi1+exi2+exk1+exk2) + + ENDDO + ENDDO + ENDDO + + + + DO K=k1,k2 + DO J=j1-1,j2 + DO I=i1-1,i2 + + v2k=0.5*(vy(i,j,k)+vy(i,j+1,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vx(i,j,k)*(by(i,j,k)+b0(2))- + & vy(i,j,k)*(bx(i,j,k)+b0(1))) + + dexy=-f6(i,j,k)-exc + + else + + exc=-(vx(i,j+1,k)*(by(i,j+1,k)+b0(2))- + & vy(i,j+1,k)*(bx(i,j+1,k)+b0(1))) + + dexy=-f6(i,j+1,k)-exc + + endif + + else + + exc=-(vx(i,j,k)*(by(i,j,k)+b0(2))- + & vy(i,j,k)*(bx(i,j,k)+b0(1))) + + dexy1=-f6(i,j,k)-exc + + exc=-(vx(i,j+1,k)*(by(i,j+1,k)+b0(2))- + & vy(i,j+1,k)*(bx(i,j+1,k)+b0(1))) + + dexy2=-f6(i,j+1,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi1=g5(i,j,k)+dexy + + + + + v2k=0.5*(vy(i+1,j,k)+vy(i+1,j+1,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vx(i+1,j,k)*(by(i+1,j,k)+b0(2))- + & vy(i+1,j,k)*(bx(i+1,j,k)+b0(1))) + + dexy=-f6(i,j,k)-exc + + else + + exc=-(vx(i+1,j+1,k)*(by(i+1,j+1,k)+b0(2))- + & vy(i+1,j+1,k)*(bx(i+1,j+1,k)+b0(1))) + + dexy=-f6(i,j+1,k)-exc + + endif + + else + + exc=-(vx(i+1,j,k)*(by(i+1,j,k)+b0(2))- + & vy(i+1,j,k)*(bx(i+1,j,k)+b0(1))) + + dexy1=-f6(i,j,k)-exc + + exc=-(vx(i+1,j+1,k)*(by(i+1,j+1,k)+b0(2))- + & vy(i+1,j+1,k)*(bx(i+1,j+1,k)+b0(1))) + + dexy2=-f6(i,j+1,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exi2=g5(i+1,j,k)+dexy + + + + + v2k=0.5*(vx(i,j,k)+vx(i+1,j,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vx(i,j,k)*(by(i,j,k)+b0(2))- + & vy(i,j,k)*(bx(i,j,k)+b0(1))) + + dexy=g5(i,j,k)-exc + + else + + exc=-(vx(i+1,j,k)*(by(i+1,j,k)+b0(2))- + & vy(i+1,j,k)*(bx(i+1,j,k)+b0(1))) + + dexy=g5(i+1,j,k)-exc + + endif + + else + + exc=-(vx(i,j,k)*(by(i,j,k)+b0(2))- + & vy(i,j,k)*(bx(i,j,k)+b0(1))) + + dexy1=g5(i,j,k)-exc + + exc=-(vx(i+1,j,k)*(by(i+1,j,k)+b0(2))- + & vy(i+1,j,k)*(bx(i+1,j,k)+b0(1))) + + dexy2=g5(i+1,j,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exk1=-f6(i,j,k)+dexy + + + v2k=0.5*(vx(i,j+1,k)+vx(i+1,j+1,k)) + + if(abs(v2k).gt.epsk)then + + if(v2k.gt.0.)then + + exc=-(vx(i,j+1,k)*(by(i,j+1,k)+b0(2))- + & vy(i,j+1,k)*(bx(i,j+1,k)+b0(1))) + + dexy=g5(i,j,k)-exc + + else + + exc=-(vx(i+1,j+1,k)*(by(i+1,j+1,k)+b0(2))- + & vy(i+1,j+1,k)*(bx(i+1,j+1,k)+b0(1))) + + dexy=g5(i+1,j,k)-exc + + endif + + else + + exc=-(vx(i,j+1,k)*(by(i,j+1,k)+b0(2))- + & vy(i,j+1,k)*(bx(i,j+1,k)+b0(1))) + + dexy1=g5(i,j,k)-exc + + exc=-(vx(i+1,j+1,k)*(by(i+1,j+1,k)+b0(2))- + & vy(i+1,j+1,k)*(bx(i+1,j+1,k)+b0(1))) + + dexy2=g5(i+1,j,k)-exc + + dexy=0.5*(dexy1+dexy2) + + endif + + exk2=-f6(i,j+1,k)+dexy + + ez(I,J,K)=0.25*(exi1+exi2+exk1+exk2) + + ENDDO + ENDDO + ENDDO + +c------------------------------------------------------------------- +c +c Evolution of all variables +c +c------------------------------------------------------------------- + + Do k=k1,k2 + Do j=j1,j2 + Do i=i1-1,i2 + +! bug bxr(i,j,k)=bxr(I,J,K)-Dt/Dx* + bxrx(i,j,k)=bxrx(I,J,K)-Dt/Dx* + & (ez(I,J,K )-ez(I,J-1,K)+ + & ey(I,J,K-1)-ey(I,J, K)) + + Enddo + Enddo + Enddo + + Do k=k1,k2 + Do j=j1-1,j2 + Do i=i1,i2 + +! bug byr(i,j,k)=byr(I,J,K)-Dt/Dx* + byry(i,j,k)=byry(I,J,K)-Dt/Dy* + & (ex(I, J,K)-ex(I,J,K-1)+ + & ez(I-1,J,K)-ez(I,J,K)) + + Enddo + Enddo + Enddo + + Do k=k1-1,k2 + Do j=j1,j2 + Do i=i1,i2 + +! bug bzr(i,j,k)=bzr(I,J,K)-Dt/Dx* + bzrz(i,j,k)=bzrz(I,J,K)-Dt/Dz* + & (ex(I,J-1,K)-ex(I, J,K)+ + & ey(I,J, K)-ey(I-1,J,K)) + + Enddo + Enddo + Enddo + + + +c open(10,file='res.dat',access='append') +c write(10,*) i1,i2,j1,j2,k1,k2 +c do i=i1,i2 +c j=(j1+j2)/2 +c k=(k1+k2)/2 +c print*,i,f1(i,j,k) +c write(10,*) i,f1(i,j,k) +c enddo +c close(10) + + Call Conserv_ig(gamma,nxp,nyp,nzp,dn,vx,vy,vz,bx,by,bz,pn, + & qu1,qu2,qu3,qu4,qu5,qu6,qu7,qu8) + + Do k=k1,k2 + Do j=j1,j2 + Do i=i1,i2 + + QH(1)=QU1(I,J,K)-Dt/Dx*(F1(I,J,K)-F1(I-1,J,K) + & +G1(I,J,K)-G1(I,J-1,K)+H1(I,J,K)-H1(I,J,K-1)) + + QH(2)=QU2(I,J,K)-Dt/Dx*(F2(I,J,K)-F2(I-1,J,K) + & +G2(I,J,K)-G2(I,J-1,K)+H2(I,J,K)-H2(I,J,K-1)) + + QH(3)=QU3(I,J,K)-Dt/Dx*(F3(I,J,K)-F3(I-1,J,K) + & +G3(I,J,K)-G3(I,J-1,K)+H3(I,J,K)-H3(I,J,K-1)) + + QH(4)=QU4(I,J,K)-Dt/Dx*(F4(I,J,K)-F4(I-1,J,K) + & +G4(I,J,K)-G4(I,J-1,K)+H4(I,J,K)-H4(I,J,K-1)) + + QH(5)=QU5(I,J,K)-Dt/Dx*(F5(I,J,K)-F5(I-1,J,K) + & +G5(I,J,K)-G5(I,J-1,K)+H5(I,J,K)-H5(I,J,K-1)) + + QH(6)=QU6(I,J,K)-Dt/Dx*(F6(I,J,K)-F6(I-1,J,K) + & +G6(I,J,K)-G6(I,J-1,K)+H6(I,J,K)-H6(I,J,K-1)) + + QH(7)=QU7(I,J,K)-Dt/Dx*(F7(I,J,K)-F7(I-1,J,K) + & +G7(I,J,K)-G7(I,J-1,K)+H7(I,J,K)-H7(I,J,K-1)) + + QH(8)=QU8(I,J,K)-Dt/Dx*(F8(I,J,K)-F8(I-1,J,K) + & +G8(I,J,K)-G8(I,J-1,K)+H8(I,J,K)-H8(I,J,K-1)) + + qh(5)=0.5*(bxrx(i,j,k)+bxrx(i-1,j,k)) + qh(6)=0.5*(byry(i,j,k)+byry(i,j-1,k)) + qh(7)=0.5*(bzrz(i,j,k)+bzrz(i,j,k-1)) + +#ifdef INCLUDE_GRAVITY + if (gravity .eq. 1) then + QH(2)=QH(2)+DT*(QU1(I,J,K)+QH(1))/2.*GX(I,J,K) + QH(3)=QH(3)+DT*(QU1(I,J,K)+QH(1))/2.*GY(I,J,K) + QH(4)=QH(4)+DT*(QU1(I,J,K)+QH(1))/2.*GZ(I,J,K) + endif +#endif + QU1(I,J,K)=QH(1) + QU2(I,J,K)=QH(2) + QU3(I,J,K)=QH(3) + QU4(I,J,K)=QH(4) + QU5(I,J,K)=QH(5) + QU6(I,J,K)=QH(6) + QU7(I,J,K)=QH(7) + QU8(I,J,K)=QH(8) + + Enddo + Enddo + Enddo + + Call Primitiv_ig(gamma,nxp,nyp,nzp,qu1,qu2,qu3,qu4,qu5,qu6,qu7,qu8, + & dn,vx,vy,vz,bx,by,bz,pn) + + +c +c Check this slice against the list of subgrids +c (all subgrid quantities are zero based) +c + Do k=k1,k2 + do n=0, nsubgrids-1 + Do j=j1,j2 + Do i=i1,i2 + df(i,j)=f1(i,j,k) + vf(i,j)=f2(i,j,k) + uf(i,j)=f3(i,j,k) + wf(i,j)=f4(i,j,k) + bf(i,j)=f5(i,j,k) + tf(i,j)=f6(i,j,k) + pf(i,j)=f7(i,j,k) + rf(i,j)=f8(i,j,k) + enddo + enddo + if (k .ge. fjstart(n*3+1)+1 .and. k .le. fjend(n*3+1)+1) + & then + idim = fiend(n*3+1) - fistart(n*3+1) + 1 + do j=fistart(n*3+1)+1, fiend(n*3+1)+1 + offset = j-fistart(n*3+1) + (k-fjstart(n*3+1)-1)*idim + array(dnindex(n*6+1)+offset) = df(lface(n*3+1)+1, j) + array(dnindex(n*6+2)+offset) = df(rface(n*3+1)+2, j) + array(vxindex(n*6+1)+offset) = vf(lface(n*3+1)+1, j) + array(vxindex(n*6+2)+offset) = vf(rface(n*3+1)+2, j) + array(vyindex(n*6+1)+offset) = uf(lface(n*3+1)+1, j) + array(vyindex(n*6+2)+offset) = uf(rface(n*3+1)+2, j) + array(vzindex(n*6+1)+offset) = wf(lface(n*3+1)+1, j) + array(vzindex(n*6+2)+offset) = wf(rface(n*3+1)+2, j) + array(bxindex(n*6+1)+offset) = bf(lface(n*3+1)+1, j) + array(bxindex(n*6+2)+offset) = bf(rface(n*3+1)+2, j) + array(byindex(n*6+1)+offset) = tf(lface(n*3+1)+1, j) + array(byindex(n*6+2)+offset) = tf(rface(n*3+1)+2, j) + array(bzindex(n*6+1)+offset) = pf(lface(n*3+1)+1, j) + array(bzindex(n*6+2)+offset) = pf(rface(n*3+1)+2, j) + array(bzindex(n*6+1)+offset) = rf(lface(n*3+1)+1, j) + array(bzindex(n*6+2)+offset) = rf(rface(n*3+1)+2, j) + enddo + endif + enddo + enddo + + Do i=i1,i2 + do n=0, nsubgrids-1 + Do j=j1,j2 + Do k=k1,k2 + dg(j,k)=g1(i,j,k) + vg(j,k)=g2(i,j,k) + ug(j,k)=g3(i,j,k) + wg(j,k)=g4(i,j,k) + bg(j,k)=g5(i,j,k) + tg(j,k)=g6(i,j,k) + pg(j,k)=g7(i,j,k) + rg(j,k)=g8(i,j,k) + enddo + enddo + if (i .ge. fistart(n*3+2)+1 .and. i .le. fiend(n*3+2)+1) + & then + idim = fiend(n*3+2) - fistart(n*3+2) + 1 + do k=fjstart(n*3+2)+1, fjend(n*3+2)+1 + offset = i-fistart(n*3+2) + (k-fjstart(n*3+2)-1)*idim + array(dnindex(n*6+3)+offset) = dg(lface(n*3+2)+1, k) + array(dnindex(n*6+4)+offset) = dg(rface(n*3+2)+2, k) + array(vxindex(n*6+3)+offset) = vg(lface(n*3+2)+1, k) + array(vxindex(n*6+4)+offset) = vg(rface(n*3+2)+2, k) + array(vyindex(n*6+3)+offset) = ug(lface(n*3+2)+1, k) + array(vyindex(n*6+4)+offset) = ug(rface(n*3+2)+2, k) + array(vzindex(n*6+3)+offset) = wg(lface(n*3+2)+1, k) + array(vzindex(n*6+4)+offset) = wg(rface(n*3+2)+2, k) + array(bxindex(n*6+3)+offset) = bg(lface(n*3+2)+1, k) + array(bxindex(n*6+4)+offset) = bg(rface(n*3+2)+2, k) + array(byindex(n*6+3)+offset) = tg(lface(n*3+2)+1, k) + array(byindex(n*6+4)+offset) = tg(rface(n*3+2)+2, k) + array(bzindex(n*6+3)+offset) = pg(lface(n*3+2)+1, k) + array(bzindex(n*6+4)+offset) = pg(rface(n*3+2)+2, k) + array(bzindex(n*6+3)+offset) = rg(lface(n*3+2)+1, k) + array(bzindex(n*6+4)+offset) = rg(rface(n*3+2)+2, k) + enddo + endif + enddo + enddo + + Do j=j1,j2 + do n=0, nsubgrids-1 + Do i=i1,i2 + Do k=k1,k2 + dh(k,i)=h1(i,j,k) + vh(k,i)=h2(i,j,k) + uh(k,i)=h3(i,j,k) + wh(k,i)=h4(i,j,k) + bh(k,i)=h5(i,j,k) + th(k,i)=h6(i,j,k) + ph(k,i)=h7(i,j,k) + rh(k,i)=h8(i,j,k) + enddo + enddo + if (j .ge. fjstart(n*3+3)+1 .and. j .le. fjend(n*3+3)+1) + & then + idim = fiend(n*3+3) - fistart(n*3+3) + 1 + do i=fistart(n*3+3)+1, fiend(n*3+3)+1 + offset = i-fistart(n*3+3) + (j-fjstart(n*3+3)-1)*idim + array(dnindex(n*6+5)+offset) = dh(lface(n*3+3)+1, i) + array(dnindex(n*6+6)+offset) = dh(rface(n*3+3)+2, i) + array(vxindex(n*6+5)+offset) = vh(lface(n*3+3)+1, i) + array(vxindex(n*6+6)+offset) = vh(rface(n*3+3)+2, i) + array(vyindex(n*6+5)+offset) = uh(lface(n*3+3)+1, i) + array(vyindex(n*6+6)+offset) = uh(rface(n*3+3)+2, i) + array(vzindex(n*6+5)+offset) = wh(lface(n*3+3)+1, i) + array(vzindex(n*6+6)+offset) = wh(rface(n*3+3)+2, i) + array(bxindex(n*6+5)+offset) = bh(lface(n*3+3)+1, i) + array(bxindex(n*6+6)+offset) = bh(rface(n*3+3)+2, i) + array(byindex(n*6+5)+offset) = th(lface(n*3+3)+1, i) + array(byindex(n*6+6)+offset) = th(rface(n*3+3)+2, i) + array(bzindex(n*6+5)+offset) = ph(lface(n*3+3)+1, i) + array(bzindex(n*6+6)+offset) = ph(rface(n*3+3)+2, i) + array(bzindex(n*6+5)+offset) = rh(lface(n*3+3)+1, i) + array(bzindex(n*6+6)+offset) = rh(rface(n*3+3)+2, i) + enddo + endif + enddo + enddo + + Return + End diff --git a/src/Enzo/PPML_IG_OUforcing.F.backup b/src/Enzo/PPML_IG_OUforcing.F.backup new file mode 100644 index 0000000000..2580e1e095 --- /dev/null +++ b/src/Enzo/PPML_IG_OUforcing.F.backup @@ -0,0 +1,375 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + +C ************************************************************************ +C *** Ornstein-Uhlenbeck forcing source terms for 3D turbulence simulation +C *** Adopted by Dmitry Kotov from AREPO code developed by Volker Springel +C ************************************************************************ + + subroutine OUpumpInit_ig(gamma,rho0,P0,SolWeight,Mach,kmin,kmax,argx) + implicit none + + include 'PPML_IG_OUforcing.h' + + integer :: ikmax, ikx, iky, ikz, N, i, j + integer :: myid + ENZO_REAL :: gamma, rho0, P0, Mach, Eturb, c_s + ENZO_REAL :: kmax, kmin, boxSize, kx, ky, kz, kk, kc, amp + ENZO_REAL :: RandomPhase, argx(3) + ENZO_REAL, parameter :: PI_2 = 3.14159265d0*2.d0 + +c call GETDATA("gamma", gamma, argi) +c call GETDATA("Lx",argx(1),argi) +c call GETDATA("Ly",argx(2),argi) +c call GETDATA("Lz",argx(3),argi) + +c if ((argx(1) .ne. argx(2)).or.(argx(2).ne.argx(3))) +c & stop "Box sizes must be equal" + + boxSize = argx(1) ! default 1.0 + +c call GETDATA("SolWeight", SolWeight, argi) ! default 1.0 +c call GETDATA("Mach", Mach, argi) ! default 0.2 +c call GETDATA("kfi", kmin, argi) ! default 6.27 +c call GETDATA("kfa", kmax, argi) ! default 12.57 + + call initrandom() + +!AK what's P0? mean pressure? same Q for rho0 +c P0 = 1.d0 +c rho0 = 1.d0 + +!AK totTime is time counter used to control the addition of new random phases (should be kept for restarts). + totTime = 0d0 + c_s = sqrt(gamma*P0/rho0) +!AK If this is the so-called dynamical time, then it corresponds to a force acting on Lbox/2. +!AK A more general expression would use 2pi/kc as the spatial scale determining the time correlation. +! TDecay is the correlation time (= 1/2 of eddy-turnover time scale [at what spatial scale?]) +! Autocorrelation time of the force TDecay [same as the integral time scale (T=Linjection/Velo_injection)] + TDecay = boxSize/(2.d0*Mach*c_s) +!AK DtFreq time interval between the updates of phases (10 updates per one correlation time). + DtFreq = 0.1d0*TDecay +!AK ideally, kc should be a weighted average of all wave numbers from the spherical shell [kmin,kmax]. +!AK But in this case a centered parabola is used as a weight, so this should be ok. + kc = 0.5d0*(kmin + kmax) +!AK Why division by kc instead of multiplication? This makes no sense to me. +!AK should be: Eturb = 0.5*(Mach*c_s)**3/(2*pi/kc)=0.159*0.5*(Mach*c_s)**3*kc~0.006 for Mach=0.2 and kc~10 + Eturb = 0.119d0 * 0.5d0*(Mach*c_s)**3/kc ! default 5.d-5 (?) +!AK The variance of the OU process =sigma^2 (sigma=kc*(Mach*c_s)**2/sqrt(2*pi)~0.2 for Mach=0.2). + OUVar = sqrt(Eturb/TDecay) + +!8/31/16 12:18 PM, Andreas Bauer wrote: +!ST_decay 2.5 +!ST_energy 0.00005 +!ST_DtFreq 0.25 +!ST_Kmin 6.27 +!ST_Kmax 12.57 +!ST_SolWeight 1. +!ST_AmplFac 1. +!ST_Seed 42 +!ST_SpectForm 1 +!sigma is given by StOUVar = sqrt(All.StEnergy / All.StDecay) +!The used spectral form is parameterization 1 in our implementation, i.e. a paraboloid from k_min to k_max. + +c if(myid.eq.0) then +c print *, 'c_s = ', c_s +c print *, 'TDecay = ', TDecay +c print *, 'DtFreq = ', DtFreq +c print *, 'OUVar = ', OUVar +c print *, 'Eturb = ', Eturb +c print *, 'kc = ', kc +c endif + + ikmax = boxSize*kmax/PI_2 + + NModes = 0 + do ikx = 0, ikmax + kx = PI_2*ikx/boxSize + do iky = 0, ikmax + ky = PI_2*iky/boxSize + do ikz = 0, ikmax + kz = PI_2*ikz/boxSize + + kk = sqrt(kx*kx + ky*ky + kz*kz) + + if((kk.ge.kmin).and.(kk.le.kmax)) then + NModes = NModes + 4 + endif + + enddo + enddo + enddo + + allocate(Mode(3,NModes)) + allocate(OUPhase(2,3,NModes), Ampl(NModes), Phase(2,3,NModes)) + +!AK correction for projecting out non-solenoidal part, see Schmidt, Hillebrandt & Niemeyer [2005, p. 706, eq. (40)] + WeightNorm =sqrt(3.d0)/sqrt(1.d0-2.d0*SolWeight+3.d0*SolWeight**2) + + N = 0 + do ikx = 0, ikmax + kx = PI_2*ikx/boxSize + do iky = 0, ikmax + ky = PI_2*iky/boxSize + do ikz = 0, ikmax + kz = PI_2*ikz/boxSize + + kk = sqrt(kx*kx + ky*ky + kz*kz) + + if((kk.ge.kmin).and.(kk.le.kmax)) then + amp = 1.d0 - 4.d0*(kk-kc)**2/(kmax-kmin)**2 + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = ky + Mode(3,N) = kz + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = -ky + Mode(3,N) = kz + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = ky + Mode(3,N) = -kz + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = -ky + Mode(3,N) = -kz + endif + + enddo + enddo + enddo + +!AK if solution needs to be written, write random seeds as well +c call GETDATA('readinsol', argx, argi) + + if (argi(1) .ne. 0) then + open (42, file='OUturb.bin', form='UNFORMATTED', + & access='STREAM', action='read') + read (42) argi(1) + if (argi(1) .ne. NModes) then + stop "wrong number of modes in OUturb.bin" + endif + print *, 'reading phases for ', NModes, ' modes' + read (42) OUPhase, Ampl + close (42) + else + do j = 1, NModes + do i = 1, 3 + OUPhase(1,i,j) = RandomPhase()*OUVar + OUPhase(2,i,j) = RandomPhase()*OUVar + enddo + enddo + + call calcPhases() + endif + + end subroutine + +C ********************************************************************** + subroutine cleanupTurbForcing3D_ig(myid) + implicit none + include 'PPML_IG_OUforcing.h' + integer :: myid + + if (myid.eq.0) then + open (42, file='OUturb.bin', form='UNFORMATTED', + & access='STREAM') + write (42) NModes, OUPhase, Ampl + close (42) + endif + + deallocate(Mode, OUPhase, Ampl, Phase) + end subroutine + +C ********************************************************************** + ENZO_REAL function RandomPhase_ig() + implicit none + ENZO_REAL r0, r1, randomnr + ENZO_REAL, parameter :: PI_2 = 3.14159265d0*2.d0 + + r0 = randomnr() + r1 = randomnr() + + RandomPhase = sqrt(-2.d0*log(r0))*cos(PI_2*r1) + end function + +C ********************************************************************** + subroutine calcPhases_ig() + implicit none + include 'PPML_IG_OUforcing.h' + integer :: i, j + ENZO_REAL :: ka, kb, kk, kk1, diva, divb, curla, curlb + + do j = 1, NModes + ka = 0d0 + kb = 0d0 + kk = 0d0 + + do i = 1, 3 + kk = kk + Mode(i,j)**2 + ka = ka + Mode(i,j)*OUPhase(2,i,j) + kb = kb + Mode(i,j)*OUPhase(1,i,j) + enddo + + kk1 = 1.d0/kk + +!AK This is the projection operator +!AK Compare to eq. (39) from Schmidt et al. (2005, Comb. Theory & Modelling, vol. 9, pp. 693-720) + do i = 1, 3 + diva = Mode(i,j)*ka*kk1 + divb = Mode(i,j)*kb*kk1 + curla = OUPhase(1,i,j) - divb + curlb = OUPhase(2,i,j) - diva + Phase(1,i,j) = SolWeight*curla + (1.d0 - SolWeight)*divb + Phase(2,i,j) = SolWeight*curlb + (1.d0 - SolWeight)*diva + enddo + + enddo + + end subroutine + +C ********************************************************************** + subroutine updatePhases_ig() + implicit none + include 'PPML_IG_OUforcing.h' + ENZO_REAL :: damping, dfact, RandomPhase + integer :: i, j, n + +!AK damping is the decay factor; TDecay is the correlation length; +!AK DtFreq is the time interval for updating the phases. + damping = exp(-DtFreq/TDecay) + dfact = sqrt(1.d0 - damping**2) + + do j = 1, NModes + do i = 1, 3 + do n = 1, 2 + OUPhase(n,i,j) = OUPhase(n,i,j)*damping + + * OUVar*dfact*RandomPhase() + enddo + enddo + enddo + + end subroutine + +C ********************************************************************** +c 3D Turbulent forcing source term a la Ornstein-Uhlenbeck +c Updates res: res = res + source*dt +c by DK +c INPUT: +c nc - number of components +c ni, nj, nk - local domain dimensions +c nig, njg, nkg - global domain dimensions +c w - flow field +c grid - grid coordinates +c dt - time step +c update_sol - flag to update w +c OUTPUT: +c res - residual (updated) +c*********************************************************************** + subroutine turbForce3D_ig(nc, ni, nj, nk, nig, njg, nkg, + * w, grid, dt, res, update_sol) + implicit none + include 'PPML_IG_OUforcing.h' +#ifdef USING_MPI + include 'mpif.h' + integer err + ENZO_REAL gvmpi(4) +#endif + integer :: nc, ni, nj, nk, argi(1), ol2, i, j, k, m, dir + integer :: nig, njg, nkg + ENZO_REAL :: grid(3,ni,nj,nk), w(nc,ni,nj,nk), res(nc,ni,nj,nk) + ENZO_REAL :: rho, dt, dumx, acc(3), du(3), gv(4), kr + logical :: update_sol + + if(nk.eq.1) stop "turbForce3D is for 3D only" + if((nig.ne.njg).or.(nig.ne.nkg)) then + stop "turbForceNorm2d assume ni=nj" + endif + +! boolean switch: return if no need to pump +c call GETDATA("apply_forcing", dumx, argi) +c if(argi(1).eq.0) return + +!AK overlap (number of ghost zones on one side) + call GETDATA_ig("olap", dumx, argi) + ol2 = argi(1)/2 + + if(dt*0.5d0 .gt. DtFreq) then ! require at least two dt in DtFreq + print *, "dt = ", dt, " > DtFreq = ", DtFreq + stop "dt too big" + endif + + totTime = totTime + dt + if(totTime .gt. DtFreq) then + call updatePhases_ig() + call calcPhases_ig() + totTime = totTime - DtFreq + endif + + gv = 0d0 + do k=1+ol2,nk-ol2 + do j=1+ol2,nj-ol2 + do i=1+ol2,ni-ol2 + + acc = 0d0 + do m=1, NModes + kr = 0d0 + do dir=1,3 + kr = kr + Mode(dir,m)*grid(dir,i,j,k) + enddo +!AK why do we need both sin() and cos() and why Phase is not in the arguments? + acc(1:3) = acc(1:3) + Ampl(m)*( Phase(1,1:3,m)*cos(kr) + + & Phase(2,1:3,m)*sin(kr) ) + + enddo + + du = acc*(2.d0*WeightNorm)*dt + + rho = w(1,i,j,k) + res(2:4,i,j,k) = res(2:4,i,j,k) + du(1:3)*rho + res(5,i,j,k) = res(5,i,j,k) + dot_product(du,du)*0.5d0*rho + + * dot_product(w(2:4,i,j,k), du(1:3)) + + gv(1:3) = gv(1:3) + du(1:3)*rho + gv(4) = gv(4) + rho + enddo + enddo + enddo + +#ifdef USING_MPI +! gv is a 4-vector which includes sums for 3 momentum components (1-3) and sum density (4) + call MPI_AllReduce(gv, gvmpi, 4, MPI_DOUBLE_PRECISION, MPI_SUM, + * MPI_COMM_WORLD, err ) + gv = gvmpi +#endif + +! force total impulse (momentum) increment to zero (for active zones only) + du = -gv(1:3)/gv(4) + do k=1+ol2,nk-ol2 + do j=1+ol2,nj-ol2 + do i=1+ol2,ni-ol2 + rho = w(1,i,j,k) + res(2:4,i,j,k) = res(2:4,i,j,k) + du(1:3)*rho + res(5,i,j,k) = res(5,i,j,k) + dot_product(du,du)*0.5d0*rho + + * dot_product(w(2:4,i,j,k), du(1:3)) + enddo + enddo + enddo + +! update solution + if(update_sol) then +!AK do we need to initialize res(1,...) and res(6:8,...) with zeroes? + w = w + res + endif + + end subroutine diff --git a/src/Enzo/PPML_IG_OUforcing.h b/src/Enzo/PPML_IG_OUforcing.h new file mode 100644 index 0000000000..2e135be745 --- /dev/null +++ b/src/Enzo/PPML_IG_OUforcing.h @@ -0,0 +1,9 @@ + common /TURB3D/ OUPhase, Ampl, Phase, Mode, totTime, DtFreq + common /TURB3D/ OUVar, TDecay, SolWeight, WeightNorm, NModes + real*8 :: totTime, TDecay, DtFreq, SolWeight, WeightNorm + real*8 :: OUVar ! Ornstein-Uhlenbeck var + integer :: NModes + real*8, pointer :: OUPhase(:,:,:) ! Ornstein-Uhlenbeck phases + real*8, pointer :: Ampl(:) + real*8, pointer :: Phase(:,:,:) + real*8, pointer :: Mode(:,:) \ No newline at end of file diff --git a/src/Enzo/PPML_IG_Primitive.F b/src/Enzo/PPML_IG_Primitive.F new file mode 100644 index 0000000000..e1b4a457c2 --- /dev/null +++ b/src/Enzo/PPML_IG_Primitive.F @@ -0,0 +1,41 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine Primitiv_ig(gamma,nx,ny,nz,qu1,qu2,qu3,qu4,qu5,qu6, + & qu7,qu8,dn,vx,vy,vz,bx,by,bz,pn) + Implicit NONE + + Integer nx,ny,nz,i,j,k + + ENZO_REAL gamma + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + ENZO_REAL pn(nx,ny,nz) + + ENZO_REAL qu1(nx,ny,nz) + ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) + ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) + ENZO_REAL qu8(nx,ny,nz) + + Do k=1,nz + Do j=1,ny + Do i=1,nx + dn(i,j,k)=QU1(i,j,k) + vx(i,j,k)=QU2(i,j,k)/QU1(i,j,k) + vy(i,j,k)=QU3(i,j,k)/QU1(i,j,k) + vz(i,j,k)=QU4(i,j,k)/QU1(i,j,k) + bx(i,j,k)=QU5(i,j,k) + by(i,j,k)=QU6(i,j,k) + bz(i,j,k)=QU7(i,j,k) + pn(i,j,k)=(gamma-1.)*(qu8(i,j,k) + & -(qu2(i,j,k)**2+qu3(i,j,k)**2+qu4(i,j,k)**2)/qu1(i,j,k)/2.- + & -(qu5(i,j,k)**2+qu6(i,j,k)**2+qu7(i,j,k)**2)/2.) + + Enddo + Enddo + Enddo + + RETURN + END diff --git a/src/Enzo/PPML_IG_TimeStep.F b/src/Enzo/PPML_IG_TimeStep.F new file mode 100644 index 0000000000..8d783332be --- /dev/null +++ b/src/Enzo/PPML_IG_TimeStep.F @@ -0,0 +1,75 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine calc_dt_ppml_ig(nx,ny,nz, + & i1,i2,j1,j2,k1,k2, + & dx,dy,dz, + & dn,vx,vy,vz,bx,by,bz,pn, + & b0,gamma,dt) + + Implicit NONE + + Integer nx,ny,nz,i,j,k,i1,j1,k1,i2,j2,k2 + + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + ENZO_REAL pn(nx,ny,nz) + + ENZO_REAL dtmx,dtmy,dtmz,rr0,bkb,vah,vax,vay,vaz,cg + ENZO_REAL cga,dsc,cfsx,cgs,taux,cfsy,tauy,cfsz,tauz,c0,dt + ENZO_REAL dx,dy,dz,gamma,bx0,by0,bz0 + + ENZO_REAL B0(3) + + DTMX=1.E+10 + DTMY=1.E+10 + DTMZ=1.E+10 + + c0=0.8d0 + + DO K=k1,k2 + DO J=j1,j2 + DO I=i1,i2 + + Bx0=bx(I,J,K)+B0(1) + By0=by(I,J,K)+B0(2) + Bz0=bz(I,J,K)+B0(3) + + RR0=dn(I,J,K) + BKB=Bx0**2+By0**2+Bz0**2 + VAH=BKB/RR0 + VAX=Bx0**2/RR0 + VAY=By0**2/RR0 + VAZ=Bz0**2/RR0 + CG=GAMMA*pn(I,J,K)/RR0 + CGA=CG+VAH + DSC=CGA**2-4.d0*VAX*CG + IF(DSC.LT.0.) DSC=0. + CFSX=dsqrt(1.0d0*DSC) + CGS=dsqrt((CGA+CFSX)/2.d0) + TAUX=DX/(DABS(1.0d0*vx(I,J,K))+CGS) + DSC=CGA**2-4.d0*VAY*CG + IF(DSC.LT.0.) DSC=0. + CFSY=dsqrt(1.0d0*DSC) + CGS=dsqrt(1.0d0*(CGA+CFSY)/2.d0) + TAUY=DY/(DABS(1.0d0*vy(I,J,K))+CGS) + DSC=CGA**2-4.d0*VAZ*CG + IF(DSC.LT.0.) DSC=0. + CFSZ=dsqrt(1.0d0*DSC) + CGS=dsqrt(1.0d0*(CGA+CFSZ)/2.d0) + TAUZ=DZ/(DABS(1.0d0*vz(I,J,K))+CGS) + + DTMX=MIN(DTMX,TAUX) + DTMY=MIN(DTMY,TAUY) + DTMZ=MIN(DTMZ,TAUZ) + + ENDDO + ENDDO + ENDDO + + DT=C0/(1.D0/DTMX+1.D0/DTMY+1.D0/DTMZ) + + Return + End diff --git a/src/Enzo/PPML_IG_monot.F b/src/Enzo/PPML_IG_monot.F new file mode 100644 index 0000000000..3efce728c3 --- /dev/null +++ b/src/Enzo/PPML_IG_monot.F @@ -0,0 +1,258 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine Monot_ig(md,nx,gamma,dv1,dv2,bpx,qp,qm,qxl,qxr) + Implicit NONE + + External Xmedian + + Integer mk,imd,md,nx,i,j,k,m + + ENZO_REAL q1(8),q2(8),q3(8),q4(8),q5(8) + ENZO_REAL qpl(8),qpr(8),vl(8),vr(8),bs(3) + ENZO_REAL a1(8),a2(8),a3(8),a4(8),a5(8) + ENZO_REAL u1(8),u2(8),u3(8),u4(8),u5(8) + ENZO_REAL b1(8),b2(8),c1(8),c2(8) + ENZO_REAL ql(8,8),qr(8,8),uv(8) + ENZO_REAL qp(nx,8),qm(nx,8),qxl(nx,8),qxr(nx,8) + ENZO_REAL dv1(nx),dv2(nx),bpx(nx,3) + + ENZO_REAL uwl,uwr,vx1,vx2,vx3,vx4,vx5,vl1,vr1,dml,gamma + ENZO_REAL dmr,dwl,dwr,sjn,sjm,sjx,sjy,uvr,uvl,Xmedian + ENZO_REAL o1 + + o1 = 1.0d0 + + Do i=1,Nx + Do m=1,8 + qxl(i,m)=0. + qxr(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-2 + + Do m=1,8 + Q1(m)=Qp(i-2,m) + Q2(m)=Qp(i-1,m) + Q3(m)=Qp(i,m) + Q4(m)=Qp(i+1,m) + Q5(m)=Qp(i+2,m) + Enddo + + Do m=1,8 + Qpl(m)=qm(i-1,m) + Qpr(m)=qm(i,m) + Enddo + + Do m=1,3 + bs(m)=Bpx(i,m) + Enddo + + if(md.eq.1)CALL VECTLRx_ig(gamma,q3,bs,QL,QR,UV) + if(md.eq.2)CALL VECTLRy_ig(gamma,q3,bs,QL,QR,UV) + if(md.eq.3)CALL VECTLRz_ig(gamma,q3,bs,QL,QR,UV) + + CALL AMPLTD_ig(QL,q1,u1) + CALL AMPLTD_ig(QL,q2,u2) + CALL AMPLTD_ig(QL,q3,u3) + CALL AMPLTD_ig(QL,q4,u4) + CALL AMPLTD_ig(QL,q5,u5) + CALL AMPLTD_ig(QL,qpl,c1) + CALL AMPLTD_ig(QL,qpr,c2) + + Do m=1,8 + + uwl = Xmedian(u3(m),c1(m),u2(m)) + uwr = Xmedian(u3(m),c2(m),u4(m)) + + b1(m) = Xmedian(u3(m),uwl,3.d0*u3(m)-2.d0*uwr) + b2(m) = Xmedian(u3(m),uwr,3.d0*u3(m)-2.d0*uwl) + + Enddo + + imd=0 + + Do m=1,8 + + if((b1(m)-c1(m))**2.gt.1e-12.or.(b2(m)-c2(m))**2. + & gt.1e-12) imd=1 + + enddo + + If(imd.eq.0)then + + CALL AMPLTD_ig(QR,c2,b2) + + Do m=1,8 + qxr(i,m)=b2(m) + enddo + + CALL AMPLTD_ig(QR,c1,b1) + + Do m=1,8 + qxl(i,m)=b1(m) + enddo + + Else + + do m=1,8 + + vx1=u1(m) + vx2=u2(m) + vx3=u3(m) + vx4=u4(m) + vx5=u5(m) + + CALL W5RECM_ig(vx1,vx2,vx3,vx4,vx5,VL1,VR1) + + vl(m)=vl1 + vr(m)=vr1 + + enddo + + Do m=1,8 + + If((b1(m)-u3(m))**2.lt.1e-12.and.(b2(m)-u3(m))**2. + & lt.1.e-12)then + + dml = Xmedian(u3(m),vl(m),c1(m)) + dmr = Xmedian(u3(m),vr(m),c2(m)) + + dwl = Xmedian(u3(m),dml,u2(m)) + dwr = Xmedian(u3(m),dmr,u4(m)) + + uwl = Xmedian(u3(m),3.d0*u3(m)-2.d0*dwr,dml) + uwr = Xmedian(u3(m),3.d0*u3(m)-2.d0*dwl,dmr) + + c1(m) = Xmedian(uwl,dml,c1(m)) + c2(m) = Xmedian(uwr,dmr,c2(m)) + + Else + + sjn = 0.5d0*(u4(m)-u2(m)) + sjm = 2.d0*Xmedian(0.,u4(m)-u3(m),u3(m)-u2(m)) + sjx = Xmedian(0.,sjn,sjm) + + sjn = 0.5d0*(u5(m)-u3(m)) + sjm = 2.d0*Xmedian(0.,u5(m)-u4(m),u4(m)-u3(m)) + sjy = Xmedian(0.,sjn,sjm) + + dwr = 0.5d0*(u3(m)+u4(m))-(sjy-sjx)/6.d0 + + sjn = 0.5d0*(u2(m)-u4(m)) + sjm = 2.d0*Xmedian(0.,u2(m)-u3(m),u3(m)-u4(m)) + sjx = Xmedian(0.,sjn,sjm) + + sjn = 0.5d0*(u1(m)-u3(m)) + sjm = 2.d0*Xmedian(0.,u1(m)-u2(m),u2(m)-u3(m)) + sjy = Xmedian(0.,sjn,sjm) + + dwl = 0.5d0*(u3(m)+u2(m))-(sjy-sjx)/6.d0 + + uwr = Xmedian(dwr,vr(m),c2(m)) + uwl = Xmedian(dwl,vl(m),c1(m)) + + dmr = Xmedian(u3(m),uwr,u4(m)) + dml = Xmedian(u3(m),uwl,u2(m)) + + uvr = Xmedian(u3(m),3.d0*u3(m)-2.d0*dml,dmr) + uvl = Xmedian(u3(m),3.d0*u3(m)-2.d0*dmr,dml) + + c1(m) = Xmedian(uvl,vl(m),c1(m)) + c2(m) = Xmedian(uvr,vr(m),c2(m)) + + Endif + + Enddo + + CALL AMPLTD_ig(QR,c2,b2) + + Do m=1,8 + qxr(i,m)=b2(m) + enddo + + CALL AMPLTD_ig(QR,c1,b1) + + Do m=1,8 + qxl(i,m)=b1(m) + enddo + + Endif + + if(b1(1).lt.1.e-5) then + + Do m=1,8 + + uwl=q4(m)-q3(m) + uwr=q3(m)-q2(m) + + u1(m)=0.5d0*(SIGN(o1,uwl)+SIGN(o1,uwr))* + & min(abs(uwl),abs(uwr)) + + Enddo + + Do m=1,8 + qxl(i,m)=q3(m)-u1(m)/2.d0 + Enddo + + if(abs(qxl(i,1)-q3(1)).ge.0.8d0*q3(1))then + + Do m=1,8 + qxl(i,m)=q3(m) + Enddo + + Endif + + Endif + + If(b2(1).lt.1.0e-5) then + + Do m=1,8 + + uwl=q4(m)-q3(m) + uwr=q3(m)-q2(m) + + u1(m)=0.5d0*(SIGN(o1,uwl)+SIGN(o1,uwr))* + & min(abs(uwl),abs(uwr)) + + Enddo + + Do m=1,8 + qxr(i,m)=q3(m)+u1(m)/2.d0 + Enddo + + If(abs(qxr(i,1)-q3(1)).ge.0.8d0*q3(1))then + + Do m=1,8 + qxr(i,m)=q3(m) + Enddo + + Endif + + Endif + + if(abs(q4(1)-q3(1))/max(q4(1),q3(1)).gt.0.8d0. + & and.dv2(i).lt.0.)then + + do m=1,8 + qxr(i,m)=q3(m) + enddo + + endif + + if(abs(q2(1)-q3(1))/max(q2(1),q3(1)).gt.0.8d0. + & and.dv1(i).lt.0.)then + + do m=1,8 + qxl(i,m)=q3(m) + enddo + + endif + + + Enddo + + Return + End diff --git a/src/Enzo/PPML_IG_potokx.F b/src/Enzo/PPML_IG_potokx.F new file mode 100644 index 0000000000..a00e4f91d9 --- /dev/null +++ b/src/Enzo/PPML_IG_potokx.F @@ -0,0 +1,333 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" +#ifdef INCLUDE_GRAVITY + Subroutine POTOKx_ig(Nx,gamma,Dx,Dt,Bp,Qlx,Qrx,Qpm,Qdy,Qdz,Sx, + & Qrp,Fm) +#else + Subroutine POTOKx_ig(Nx,gamma,Dx,Dt,Bp,Qlx,Qrx,Qpm,Qdy,Qdz, + & Qrp,Fm) +#endif + Implicit NONE + + Integer nx,i,j,k,m,l + + ENZO_REAL Qlx(Nx,8),Qrx(Nx,8),Qpm(Nx,8),Qdy(Nx,8),Qdz(Nx,8) + ENZO_REAL Qrp(Nx,8),Fm(Nx,8),Bp(Nx,3) + + ENZO_REAL qp(8),px(8),qc(8),qvl(8),qvr(8),BS(3) + ENZO_REAL vm(8),ql(8,8),qr(8,8),uv(8),vl(8) + ENZO_REAL sl(8),qul(8),qur(8),tl(8) + ENZO_REAL tr(8),fr(8),f(8),ur(8),qv(8) + ENZO_REAL udy(8),udz(8),ay(8,8),az(8,8),av(8) + ENZO_REAL tvl(8),tvr(8),tp(8),tc(8),tdy(8),tdz(8) + ENZO_REAL DT,DX,DTX,DXI,TL5,gamma + ENZO_REAL bl,br,fl1,fr1,ul_v,ur_v,cfl,qsr(8) + ENZO_REAL Sxl(8),Sxr(8) +#ifdef INCLUDE_GRAVITY + ENZO_REAL Sx(Nx,8) +#endif + + Do i=1,Nx + Do m=1,8 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-3 + Do m=1,8 + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udy(m)=Qdy(i,m) + Udz(m)=Qdz(i,m) +#ifdef INCLUDE_GRAVITY + Sxl(m)=Sx(i,m) +#else + Sxl(m)=0.0d0 +#endif + + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdy(m)=Qdy(i+1,m) + Tdz(m)=Qdz(i+1,m) +#ifdef INCLUDE_GRAVITY + Sxr(m)=Sx(i+1,m) +#else + Sxr(m)=0.0d0 +#endif + Enddo + + Do m=1,3 + Bs(m)=Bp(i,m) + Enddo + + DTX=DT/DX + + CALL VECTEGx_ig(gamma,QP,BS,QC) + CALL VECTEGx_ig(gamma,TP,BS,TC) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRX_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AY_ig(gamma,QP,BS,AY) + CALL MATR_AZ_ig(gamma,QP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SXL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRX_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AY_ig(gamma,TP,BS,AY) + CALL MATR_AZ_ig(gamma,TP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SXR(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + do M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + enddo + + TL(5)=QVR(5) + TR(5)=TVL(5) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDx_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + Do M=1,8 + Fm(I,M)=FR(M) + Enddo + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRX_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AY_ig(gamma,QP,BS,AY) + CALL MATR_AZ_ig(gamma,QP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SXL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRX_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AY_ig(gamma,TP,BS,AY) + CALL MATR_AZ_ig(gamma,TP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SXR(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + + DO M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL(5)=QVR(5) + TR(5)=TVL(5) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDx_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + + CALL PRIM_ig(gamma,UR,PX) + + DO M=1,8 + QRP(I,M)=PX(M) + ENDDO + + Enddo + + Return + End + diff --git a/src/Enzo/PPML_IG_potoky.F b/src/Enzo/PPML_IG_potoky.F new file mode 100644 index 0000000000..1937f2eb91 --- /dev/null +++ b/src/Enzo/PPML_IG_potoky.F @@ -0,0 +1,338 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + +#ifdef INCLUDE_GRAVITY + Subroutine POTOKy_ig(Nx,gamma,Dx,Dt,Bp,Qlx,Qrx,Qpm,Qdx,Qdz,Sy, + & Qrp,Fm) +#else + Subroutine POTOKy_ig(Nx,gamma,Dx,Dt,Bp,Qlx,Qrx,Qpm,Qdx,Qdz, + & Qrp,Fm) +#endif + + Implicit NONE + Integer nx,i,j,k,m,l + + ENZO_REAL Qlx(Nx,8),Qrx(Nx,8),Qpm(Nx,8),Qdx(Nx,8),Qdz(Nx,8) + ENZO_REAL Qrp(Nx,8),Fm(Nx,8),Bp(Nx,3) + + ENZO_REAL qp(8),px(8),qc(8),qvl(8),qvr(8),bs(3) + ENZO_REAL vm(8),ql(8,8),qr(8,8),uv(8),vl(8) + ENZO_REAL sl(8),qul(8),qur(8),tl(8) + ENZO_REAL tr(8),fr(8),f(8),ur(8),qv(8) + ENZO_REAL udx(8),udz(8),ax(8,8),az(8,8),av(8) + ENZO_REAL tvl(8),tvr(8),tp(8),tc(8),tdx(8),tdz(8) + ENZO_REAL DT,DX,DTX,DXI,TL6,gamma + ENZO_REAL bl,br,fl1,fr1,ul_v,ur_v,cfl,qsr(8) + ENZO_REAL Syl(8),Syr(8) +#ifdef INCLUDE_GRAVITY + ENZO_REAL Sy(Nx,8) +#endif + + Do i=1,Nx + Do m=1,8 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-3 + + Do m=1,8 + + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udx(m)=Qdx(i,m) + Udz(m)=Qdz(i,m) +#ifdef INCLUDE_GRAVITY + Syl(m)=Sy(i,m) +#else + Syl(m)=0.0d0 +#endif + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdx(m)=Qdx(i+1,m) + Tdz(m)=Qdz(i+1,m) +#ifdef INCLUDE_GRAVITY + Syr(m)=Sy(i+1,m) +#else + Syr(m)=0.0d0 +#endif + Enddo + + Do m=1,3 + Bs(m)=Bp(i,m) + Enddo + + + DTX=DT/DX + + CALL VECTEGy_ig(gamma,Qp,Bs,Qc) + CALL VECTEGy_ig(gamma,Tp,Bs,Tc) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRY_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,QP,BS,AX) + CALL MATR_AZ_ig(gamma,QP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SYL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRY_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,TP,BS,AX) + CALL MATR_AZ_ig(gamma,TP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDZ(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SYR(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL(6)=QVR(6) + TR(6)=TVL(6) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDy_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + DO M=1,8 + FM(I,M)=FR(M) + ENDDO + + + + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRY_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,QP,BS,AX) + CALL MATR_AZ_ig(gamma,QP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SYL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRY_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,TP,BS,AX) + CALL MATR_AZ_ig(gamma,TP,BS,AZ) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL(6)=QVR(6) + TR(6)=TVL(6) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDy_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + + CALL PRIM_ig(gamma,UR,PX) + + DO M=1,8 + QRP(I,M)=PX(M) + ENDDO + + ENDDO + + return + end diff --git a/src/Enzo/PPML_IG_potokz.F b/src/Enzo/PPML_IG_potokz.F new file mode 100644 index 0000000000..7e7f4636b9 --- /dev/null +++ b/src/Enzo/PPML_IG_potokz.F @@ -0,0 +1,337 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + +#ifdef INCLUDE_GRAVITY + Subroutine POTOKz_ig(Nx,gamma,Dx,Dt,Bpx,Qlx,Qrx,Qpm,Qdx,Qdy,Sz, + & Qrp,Fm) +#else + Subroutine POTOKz_ig(Nx,gamma,Dx,Dt,Bpx,Qlx,Qrx,Qpm,Qdx,Qdy, + & Qrp,Fm) +#endif + Implicit NONE + + Integer nx,i,j,k,m,l + + ENZO_REAL Qlx(Nx,8),Qrx(Nx,8),Qpm(Nx,8),Qdx(Nx,8),Qdy(Nx,8) + ENZO_REAL Qrp(Nx,8),Fm(Nx,8),Bpx(Nx,3) + + ENZO_REAL qp(8),px(8),qc(8),qvl(8),qvr(8),bs(3) + ENZO_REAL vm(8),ql(8,8),qr(8,8),uv(8),vl(8) + ENZO_REAL sl(8),qul(8),qur(8),tl(8) + ENZO_REAL tr(8),fr(8),f(8),ur(8),qv(8) + ENZO_REAL udx(8),udy(8),ay(8,8),ax(8,8),av(8) + ENZO_REAL tvl(8),tvr(8),tp(8),tc(8),tdx(8),tdy(8) + ENZO_REAL DT,DX,DTX,DXI,TL7,gamma + ENZO_REAL bl,br,fl1,fr1,ul_v,ur_v,cfl,qsr(8) + ENZO_REAL Szl(8),Szr(8) +#ifdef INCLUDE_GRAVITY + ENZO_REAL Sz(Nx,8) +#endif + + Do i=1,Nx + Do m=1,8 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + DO i=3,Nx-3 + Do m=1,8 + + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udx(m)=Qdx(i,m) + Udy(m)=Qdy(i,m) +#ifdef INCLUDE_GRAVITY + Szl(m)=Sz(i,m) +#else + Szl(m)=0.0d0 +#endif + + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdx(m)=Qdx(i+1,m) + Tdy(m)=Qdy(i+1,m) +#ifdef INCLUDE_GRAVITY + Szr(m)=Sz(i+1,m) +#else + Szr(m)=0.0d0 +#endif + + + Enddo + + Do m=1,3 + Bs(m)=Bpx(i,m) + Enddo + + + DTX=DT/DX + + CALL VECTEGz_ig(gamma,Qp,BS,Qc) + CALL VECTEGz_ig(gamma,Tp,BS,Tc) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRZ_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,QP,BS,AX) + CALL MATR_AY_ig(gamma,QP,BS,AY) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SZL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRZ_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,TP,BS,AX) + CALL MATR_AY_ig(gamma,TP,BS,AY) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SZR(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL(7)=QVR(7) + TR(7)=TVL(7) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDz_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + + DO M=1,8 + FM(I,M)=FR(M) + ENDDO + + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,VM) + + CALL VECTLRZ_ig(gamma,QP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,QP,BS,AX) + CALL MATR_AY_ig(gamma,QP,BS,AY) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SZL(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML_ig(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,VM) + + CALL VECTLRZ_ig(gamma,TP,BS,QL,QR,UV) + CALL MATR_AX_ig(gamma,TP,BS,AX) + CALL MATR_AY_ig(gamma,TP,BS,AY) + + DO L=1,8 + VL(L)=0. + ENDDO + + DO M=1,8 + AV(M)=0. + DO L=1,8 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) + ENDDO + AV(M)=AV(M)*DTX/2.-SZR(M)*DT/2. + ENDDO + + DO M=1,8 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML_ig(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,8 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,8 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,8 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,8 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL(7)=QVR(7) + TR(7)=TVL(7) + + CALL CONS_ig(gamma,TL,PX) + CALL CONS_ig(gamma,TR,VL) + CALL HLLDz_ig(gamma,PX,VL,BS,FR,UR) !HLLD method + + CALL PRIM_ig(gamma,UR,PX) + + DO M=1,8 + QRP(I,M)=PX(M) + ENDDO + + ENDDO + + return + end diff --git a/src/Enzo/PPML_IG_sub.F b/src/Enzo/PPML_IG_sub.F new file mode 100644 index 0000000000..36b17e2106 --- /dev/null +++ b/src/Enzo/PPML_IG_sub.F @@ -0,0 +1,1627 @@ +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + SUBROUTINE VECTLRx_ig(gamma,QU,BS,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),QR(8,8),U(8),BS(3) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BXX,BYZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BY,BZ,BSGN,CD2,GAMMA,QU5,QU6,QU7 + + DLT=1.E-12 + X22=1./SQRT(2.) + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAX + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + CA=ABS(BVX) + + BXX=QU5**2 + BYZ=QU6**2+QU7**2 + SBB=SQRT(BYZ) + BMG=BXX+BYZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BXX) + + IF(BYZ.GT.DLT*BMG) THEN + + ASS=SQRT(CWH**2+4.*CKV*(VAY+VAZ)) + AS=SQRT(ABS((1.-CWH/ASS)/2.)) + AF=SQRT(ABS((1.+CWH/ASS)/2.)) + + BY=QU6/SBB + BZ=QU7/SBB + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=SQRT(ABS((1.-SIGN(1.,CWH))/2.)) + AF=SQRT(ABS((1.+SIGN(1.,CWH))/2.)) + CS=SQRT(ABS((CKV+VAX-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAX+SIGN(1.,CWH)*CWH)/2.)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + BY=X22 + BZ=X22 + + ENDIF + + + BSGN=SIGN(1.,QU5) + CD2=2.*CKV + + QL(1,1)=0. + QL(1,2)=-QU(1)*AF*CF/CD2 + QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 + QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 + QL(1,5)=0. + QL(1,6)=SK1*CSR*AS*BY/CD2 + QL(1,7)=SK1*CSR*AS*BZ/CD2 + QL(1,8)=AF/CD2 + + QL(2,1)=0. + QL(2,2)=0. + QL(2,3)=-QU(1)*BZ*BSGN/2. + QL(2,4)=QU(1)*BY*BSGN/2. + QL(2,5)=0. + QL(2,6)=-SK1*BZ/2. + QL(2,7)=SK1*BY/2. + QL(2,8)=0. + + QL(3,1)=0. + QL(3,2)=-QU(1)*AS*CS/CD2 + QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 + QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 + QL(3,5)=0. + QL(3,6)=-SK1*CSR*AF*BY/CD2 + QL(3,7)=-SK1*CSR*AF*BZ/CD2 + QL(3,8)=AS/CD2 + + QL(4,1)=1. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=0. + QL(4,8)=-1./CKV + + QL(5,1)=0. + QL(5,2)=QU(1)*AS*CS/CD2 + QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 + QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 + QL(5,5)=0. + QL(5,6)=-SK1*CSR*AF*BY/CD2 + QL(5,7)=-SK1*CSR*AF*BZ/CD2 + QL(5,8)=AS/CD2 + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=-QU(1)*BZ*BSGN/2. + QL(6,4)=QU(1)*BY*BSGN/2. + QL(6,5)=0. + QL(6,6)=SK1*BZ/2. + QL(6,7)=-SK1*BY/2. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=QU(1)*AF*CF/CD2 + QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 + QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 + QL(7,5)=0. + QL(7,6)=SK1*CSR*AS*BY/CD2 + QL(7,7)=SK1*CSR*AS*BZ/CD2 + QL(7,8)=AF/CD2 + + QL(8,1)=0. + QL(8,2)=0. + QL(8,3)=0. + QL(8,4)=0. + QL(8,5)=1. + QL(8,6)=0. + QL(8,7)=0. + QL(8,8)=0. + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=1. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + QR(1,8)=0. + + QR(2,1)=-AF*CF/QU(1) + QR(2,2)=0. + QR(2,3)=-AS*CS/QU(1) + QR(2,4)=0. + QR(2,5)=AS*CS/QU(1) + QR(2,6)=0. + QR(2,7)=AF*CF/QU(1) + QR(2,8)=0. + + QR(3,1)=AS*CS*BY*BSGN/QU(1) + QR(3,2)=-BZ*BSGN/QU(1) + QR(3,3)=-AF*CF*BY*BSGN/QU(1) + QR(3,4)=0. + QR(3,5)=AF*CF*BY*BSGN/QU(1) + QR(3,6)=-BZ*BSGN/QU(1) + QR(3,7)=-AS*CS*BY*BSGN/QU(1) + QR(3,8)=0. + + QR(4,1)=AS*CS*BZ*BSGN/QU(1) + QR(4,2)=BY*BSGN/QU(1) + QR(4,3)=-AF*CF*BZ*BSGN/QU(1) + QR(4,4)=0. + QR(4,5)=AF*CF*BZ*BSGN/QU(1) + QR(4,6)=BY*BSGN/QU(1) + QR(4,7)=-AS*CS*BZ*BSGN/QU(1) + QR(4,8)=0. + + QR(5,1)=0. + QR(5,2)=0. + QR(5,3)=0. + QR(5,4)=0. + QR(5,5)=0. + QR(5,6)=0. + QR(5,7)=0. + QR(5,8)=1. + + QR(6,1)=AS*BY*CSR/SK1 + QR(6,2)=-BZ/SK1 + QR(6,3)=-AF*BY*CSR/SK1 + QR(6,4)=0. + QR(6,5)=-AF*BY*CSR/SK1 + QR(6,6)=BZ/SK1 + QR(6,7)=AS*BY*CSR/SK1 + QR(6,8)=0. + + QR(7,1)=AS*BZ*CSR/SK1 + QR(7,2)=BY/SK1 + QR(7,3)=-AF*BZ*CSR/SK1 + QR(7,4)=0. + QR(7,5)=-AF*BZ*CSR/SK1 + QR(7,6)=-BY/SK1 + QR(7,7)=AS*BZ*CSR/SK1 + QR(7,8)=0. + + QR(8,1)=AF*CKV + QR(8,2)=0. + QR(8,3)=AS*CKV + QR(8,4)=0. + QR(8,5)=AS*CKV + QR(8,6)=0. + QR(8,7)=AF*CKV + QR(8,8)=0. + + U(1)=QU(2)-CF + U(2)=QU(2)-CA + U(3)=QU(2)-CS + U(4)=QU(2) + U(5)=QU(2)+CS + U(6)=QU(2)+CA + U(7)=QU(2)+CF + U(8)=QU(2) + + RETURN + END + + SUBROUTINE VECTLRy_ig(gamma,QU,BS,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),QR(8,8),U(8),BS(3) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BX,BZ,BSGN,CD2,GAMMA,QU5,QU6,QU7 + + DLT=1.E-12 + X22=1./SQRT(2.) + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAY + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + CA=ABS(BVY) + + BYY=QU6**2 + BXZ=QU5**2+QU7**2 + SBB=SQRT(BXZ) + BMG=BYY+BXZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BYY) + + IF(BXZ.GT.DLT*BMG) THEN + + ASS=SQRT(CWH**2+4.*CKV*(VAX+VAZ)) + AS=SQRT(ABS((1.-CWH/ASS)/2.)) + AF=SQRT(ABS((1.+CWH/ASS)/2.)) + + BX=QU5/SBB + BZ=QU7/SBB + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=SQRT(ABS((1.-SIGN(1.,CWH))/2.)) + AF=SQRT(ABS((1.+SIGN(1.,CWH))/2.)) + CS=SQRT(ABS((CKV+VAY-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAY+SIGN(1.,CWH)*CWH)/2.)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + + BX=X22 + BZ=X22 + + ENDIF + + BSGN=SIGN(1.,QU6) + CD2=2.*CKV + + QL(1,1)=0. + QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 + QL(1,3)=-QU(1)*AF*CF/CD2 + QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 + QL(1,5)=SK1*CSR*AS*BX/CD2 + QL(1,6)=0. + QL(1,7)=SK1*CSR*AS*BZ/CD2 + QL(1,8)=AF/CD2 + + QL(2,1)=0. + QL(2,2)=-QU(1)*BZ*BSGN/2. + QL(2,3)=0. + QL(2,4)=QU(1)*BX*BSGN/2. + QL(2,5)=-SK1*BZ/2. + QL(2,6)=0. + QL(2,7)=SK1*BX/2. + QL(2,8)=0. + + QL(3,1)=0. + QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 + QL(3,3)=-QU(1)*AS*CS/CD2 + QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 + QL(3,5)=-SK1*CSR*AF*BX/CD2 + QL(3,6)=0. + QL(3,7)=-SK1*CSR*AF*BZ/CD2 + QL(3,8)=AS/CD2 + + QL(4,1)=1. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=0. + QL(4,8)=-1./CKV + + QL(5,1)=0. + QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 + QL(5,3)=QU(1)*AS*CS/CD2 + QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 + QL(5,5)=-SK1*CSR*AF*BX/CD2 + QL(5,6)=0. + QL(5,7)=-SK1*CSR*AF*BZ/CD2 + QL(5,8)=AS/CD2 + + QL(6,1)=0. + QL(6,2)=-QU(1)*BZ*BSGN/2. + QL(6,3)=0. + QL(6,4)=QU(1)*BX*BSGN/2. + QL(6,5)=SK1*BZ/2. + QL(6,6)=0. + QL(6,7)=-SK1*BX/2. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 + QL(7,3)=QU(1)*AF*CF/CD2 + QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 + QL(7,5)=SK1*CSR*AS*BX/CD2 + QL(7,6)=0. + QL(7,7)=SK1*CSR*AS*BZ/CD2 + QL(7,8)=AF/CD2 + + QL(8,1)=0. + QL(8,2)=0. + QL(8,3)=0. + QL(8,4)=0. + QL(8,5)=0. + QL(8,6)=1. + QL(8,7)=0. + QL(8,8)=0. + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=1. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + QR(1,8)=0. + + QR(2,1)=AS*CS*BX*BSGN/QU(1) + QR(2,2)=-BZ*BSGN/QU(1) + QR(2,3)=-AF*CF*BX*BSGN/QU(1) + QR(2,4)=0. + QR(2,5)=AF*CF*BX*BSGN/QU(1) + QR(2,6)=-BZ*BSGN/QU(1) + QR(2,7)=-AS*CS*BX*BSGN/QU(1) + QR(2,8)=0. + + QR(3,1)=-AF*CF/QU(1) + QR(3,2)=0. + QR(3,3)=-AS*CS/QU(1) + QR(3,4)=0. + QR(3,5)=AS*CS/QU(1) + QR(3,6)=0. + QR(3,7)=AF*CF/QU(1) + QR(3,8)=0. + + QR(4,1)=AS*CS*BZ*BSGN/QU(1) + QR(4,2)=BX*BSGN/QU(1) + QR(4,3)=-AF*CF*BZ*BSGN/QU(1) + QR(4,4)=0. + QR(4,5)=AF*CF*BZ*BSGN/QU(1) + QR(4,6)=BX*BSGN/QU(1) + QR(4,7)=-AS*CS*BZ*BSGN/QU(1) + QR(4,8)=0. + + QR(5,1)=AS*BX*CSR/SK1 + QR(5,2)=-BZ/SK1 + QR(5,3)=-AF*BX*CSR/SK1 + QR(5,4)=0. + QR(5,5)=-AF*BX*CSR/SK1 + QR(5,6)=BZ/SK1 + QR(5,7)=AS*BX*CSR/SK1 + QR(5,8)=0. + + QR(6,1)=0. + QR(6,2)=0. + QR(6,3)=0. + QR(6,4)=0. + QR(6,5)=0. + QR(6,6)=0. + QR(6,7)=0. + QR(6,8)=1. + + QR(7,1)=AS*BZ*CSR/SK1 + QR(7,2)=BX/SK1 + QR(7,3)=-AF*BZ*CSR/SK1 + QR(7,4)=0. + QR(7,5)=-AF*BZ*CSR/SK1 + QR(7,6)=-BX/SK1 + QR(7,7)=AS*BZ*CSR/SK1 + QR(7,8)=0. + + QR(8,1)=AF*CKV + QR(8,2)=0. + QR(8,3)=AS*CKV + QR(8,4)=0. + QR(8,5)=AS*CKV + QR(8,6)=0. + QR(8,7)=AF*CKV + QR(8,8)=0. + + U(1)=QU(3)-CF + U(2)=QU(3)-CA + U(3)=QU(3)-CS + U(4)=QU(3) + U(5)=QU(3)+CS + U(6)=QU(3)+CA + U(7)=QU(3)+CF + U(8)=QU(3) + + RETURN + END + + SUBROUTINE VECTLRz_ig(gamma,QU,BS,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),QR(8,8),U(8),BS(3) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BX,BY,BSGN,CD2,GAMMA + ENZO_REAL QU5,QU6,QU7 + + DLT=1.E-12 + X22=1./SQRT(2.) + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAZ + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + CA=ABS(BVZ) + + BYY=QU7**2 + BXZ=QU5**2+QU6**2 + SBB=SQRT(BXZ) + BMG=BYY+BXZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BYY) + + IF(BXZ.GT.DLT*BMG) THEN + + ASS=SQRT(CWH**2+4.*CKV*(VAX+VAY)) + AS=SQRT(ABS((1.-CWH/ASS)/2.)) + AF=SQRT(ABS((1.+CWH/ASS)/2.)) + + BX=QU5/SBB + BY=QU6/SBB + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=SQRT(ABS((1.-SIGN(1.,CWH))/2.)) + AF=SQRT(ABS((1.+SIGN(1.,CWH))/2.)) + CS=SQRT(ABS((CKV+VAZ-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAZ+SIGN(1.,CWH)*CWH)/2.)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + + BX=X22 + BY=X22 + + ENDIF + + BSGN=SIGN(1.,QU7) + CD2=2.*CKV + + QL(1,1)=0. + QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 + QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 + QL(1,4)=-QU(1)*AF*CF/CD2 + QL(1,5)=SK1*CSR*AS*BX/CD2 + QL(1,6)=SK1*CSR*AS*BY/CD2 + QL(1,7)=0. + QL(1,8)=AF/CD2 + + QL(2,1)=0. + QL(2,2)=-QU(1)*BY*BSGN/2. + QL(2,3)=QU(1)*BX*BSGN/2. + QL(2,4)=0. + QL(2,5)=-SK1*BY/2. + QL(2,6)=SK1*BX/2. + QL(2,7)=0. + QL(2,8)=0. + + QL(3,1)=0. + QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 + QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 + QL(3,4)=-QU(1)*AS*CS/CD2 + QL(3,5)=-SK1*CSR*AF*BX/CD2 + QL(3,6)=-SK1*CSR*AF*BY/CD2 + QL(3,7)=0. + QL(3,8)=AS/CD2 + + QL(4,1)=1. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=0. + QL(4,8)=-1./CKV + + QL(5,1)=0. + QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 + QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 + QL(5,4)=QU(1)*AS*CS/CD2 + QL(5,5)=-SK1*CSR*AF*BX/CD2 + QL(5,6)=-SK1*CSR*AF*BY/CD2 + QL(5,7)=0. + QL(5,8)=AS/CD2 + + QL(6,1)=0. + QL(6,2)=-QU(1)*BY*BSGN/2. + QL(6,3)=QU(1)*BX*BSGN/2. + QL(6,4)=0. + QL(6,5)=SK1*BY/2. + QL(6,6)=-SK1*BX/2. + QL(6,7)=0. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 + QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 + QL(7,4)=QU(1)*AF*CF/CD2 + QL(7,5)=SK1*CSR*AS*BX/CD2 + QL(7,6)=SK1*CSR*AS*BY/CD2 + QL(7,7)=0. + QL(7,8)=AF/CD2 + + QL(8,1)=0. + QL(8,2)=0. + QL(8,3)=0. + QL(8,4)=0. + QL(8,5)=0. + QL(8,6)=0. + QL(8,7)=1. + QL(8,8)=0. + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=1. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + QR(1,8)=0. + + QR(2,1)=AS*CS*BX*BSGN/QU(1) + QR(2,2)=-BY*BSGN/QU(1) + QR(2,3)=-AF*CF*BX*BSGN/QU(1) + QR(2,4)=0. + QR(2,5)=AF*CF*BX*BSGN/QU(1) + QR(2,6)=-BY*BSGN/QU(1) + QR(2,7)=-AS*CS*BX*BSGN/QU(1) + QR(2,8)=0. + + QR(3,1)=AS*CS*BY*BSGN/QU(1) + QR(3,2)=BX*BSGN/QU(1) + QR(3,3)=-AF*CF*BY*BSGN/QU(1) + QR(3,4)=0. + QR(3,5)=AF*CF*BY*BSGN/QU(1) + QR(3,6)=BX*BSGN/QU(1) + QR(3,7)=-AS*CS*BY*BSGN/QU(1) + QR(3,8)=0. + + QR(4,1)=-AF*CF/QU(1) + QR(4,2)=0. + QR(4,3)=-AS*CS/QU(1) + QR(4,4)=0. + QR(4,5)=AS*CS/QU(1) + QR(4,6)=0. + QR(4,7)=AF*CF/QU(1) + QR(4,8)=0. + + QR(5,1)=AS*BX*CSR/SK1 + QR(5,2)=-BY/SK1 + QR(5,3)=-AF*BX*CSR/SK1 + QR(5,4)=0. + QR(5,5)=-AF*BX*CSR/SK1 + QR(5,6)=BY/SK1 + QR(5,7)=AS*BX*CSR/SK1 + QR(5,8)=0. + + QR(6,1)=AS*BY*CSR/SK1 + QR(6,2)=BX/SK1 + QR(6,3)=-AF*BY*CSR/SK1 + QR(6,4)=0. + QR(6,5)=-AF*BY*CSR/SK1 + QR(6,6)=-BX/SK1 + QR(6,7)=AS*BY*CSR/SK1 + QR(6,8)=0. + + QR(7,1)=0. + QR(7,2)=0. + QR(7,3)=0. + QR(7,4)=0. + QR(7,5)=0. + QR(7,6)=0. + QR(7,7)=0. + QR(7,8)=1. + + QR(8,1)=AF*CKV + QR(8,2)=0. + QR(8,3)=AS*CKV + QR(8,4)=0. + QR(8,5)=AS*CKV + QR(8,6)=0. + QR(8,7)=AF*CKV + QR(8,8)=0. + + U(1)=QU(4)-CF + U(2)=QU(4)-CA + U(3)=QU(4)-CS + U(4)=QU(4) + U(5)=QU(4)+CS + U(6)=QU(4)+CA + U(7)=QU(4)+CF + U(8)=QU(4) + + RETURN + END + + + SUBROUTINE VECTEGx_ig(gamma,QU,BS,U) + Implicit NONE + + ENZO_REAL QU(8),U(8),BS(3) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,VA,BXX,BYZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,GAMMA,QU5,QU6,QU7 + + DLT=1.E-12 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAX + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + VA=ABS(BVX) + + BXX=QU5**2 + BYZ=QU6**2+QU7**2 + SBB=SQRT(BYZ) + BMG=BXX+BYZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BXX) + + IF(BYZ.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=SQRT(ABS((CKV+VAX-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAX+SIGN(1.,CWH)*CWH)/2.)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(2)-CF + U(2)=QU(2)-VA + U(3)=QU(2)-CS + U(4)=QU(2) + U(5)=QU(2)+CS + U(6)=QU(2)+VA + U(7)=QU(2)+CF + U(8)=QU(2) + + RETURN + END + + SUBROUTINE VECTEGy_ig(gamma,QU,BS,U) + Implicit NONE + + ENZO_REAL QU(8),U(8),BS(3) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,VA,BYY,BXZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,GAMMA ,QU5,QU6,QU7 + + DLT=1.E-12 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAY + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + VA=ABS(BVY) + + BYY=QU6**2 + BXZ=QU5**2+QU7**2 + SBB=SQRT(BXZ) + BMG=BYY+BXZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BYY) + + IF(BXZ.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=SQRT(ABS((CKV+VAY-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAY+SIGN(1.,CWH)*CWH)/2.)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(3)-CF + U(2)=QU(3)-VA + U(3)=QU(3)-CS + U(4)=QU(3) + U(5)=QU(3)+CS + U(6)=QU(3)+VA + U(7)=QU(3)+CF + U(8)=QU(3) + + RETURN + END + + SUBROUTINE VECTEGz_ig(gamma,QU,BS,U) + Implicit NONE + + ENZO_REAL QU(8),U(8),BS(3) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,VA,BXY,BZZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,GAMMA,QU5,QU6,QU7 + + DLT=1.E-12 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + SK1=SQRT(QU(1)) + BVX=QU5/SK1 + BVY=QU6/SK1 + BVZ=QU7/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=GAMMA*QU(8)/QU(1) + CSR=SQRT(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.*CKV*VAZ + IF(DSCV.LT.0.) DSCV=0. + DSCV=SQRT(DSCV) + VF2=(CSV+DSCV)/2. + VS2=(CSV-DSCV)/2. + IF(VS2.LT.0.) VS2=0. + CF=SQRT(VF2) + CS=SQRT(VS2) + VA=ABS(BVZ) + + BZZ=QU7**2 + BXY=QU5**2+QU6**2 + SBB=SQRT(BXY) + BMG=BXY+BZZ + GPP=GAMMA*QU(8) + GPB=ABS(GPP-BZZ) + + IF(BXY.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=SQRT(ABS((CKV+VAZ-SIGN(1.,CWH)*CWH)/2.)) + CF=SQRT(ABS((CKV+VAZ+SIGN(1.,CWH)*CWH)/2.)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(4)-CF + U(2)=QU(4)-VA + U(3)=QU(4)-CS + U(4)=QU(4) + U(5)=QU(4)+CS + U(6)=QU(4)+VA + U(7)=QU(4)+CF + U(8)=QU(4) + + RETURN + END + + SUBROUTINE FLUXx_ig(gamma,QP,BS,F) + Implicit NONE + + ENZO_REAL QP(8),Q(8),BS(3),F(8) + ENZO_REAL gamma,qb5,qb6,qb7,bp,bp0,ux,uy,uz,vk,bm,pg,vb,pt + + CALL CONS_ig(gamma,QP,Q) + + qb5 = q(5)+bs(1) + qb6 = q(6)+bs(2) + qb7 = q(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + ux = q(2)/q(1) + uy = q(3)/q(1) + uz = q(4)/q(1) + + vk = q(2)**2 + q(3)**2 + q(4)**2 + bm = q(5)**2 + q(6)**2 + q(7)**2 + pg = (gamma-1.)*(q(8) - vk/q(1)/2. - bm/2.) + + vb = ux*q(5) + uy*q(6) + uz*q(7) + pt = pg + bp/2.-bp0/2. + + + f(1) = q(2) + f(2) = q(2)*ux + pt - qb5**2 + bs(1)**2 + f(3) = q(3)*ux - qb5*qb6 + bs(1)*bs(2) + f(4) = q(4)*ux - qb5*qb7 + bs(1)*bs(3) + f(5) = 0. + f(6) = qb6*ux - qb5*uy + f(7) = qb7*ux - qb5*uz + f(8) = (q(8) + pt)*ux - qb5*vb + + RETURN + END + + SUBROUTINE FLUXy_ig(gamma,QP,BS,F) + Implicit NONE + + ENZO_REAL QP(8),Q(8),BS(3),F(8) + ENZO_REAL gamma,qb5,qb6,qb7,bp,bp0,ux,uy,uz,vk,bm,pg,vb,pt + + CALL CONS_ig(gamma,QP,Q) + + qb5 = q(5)+bs(1) + qb6 = q(6)+bs(2) + qb7 = q(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + ux = q(2)/q(1) + uy = q(3)/q(1) + uz = q(4)/q(1) + + vk = q(2)**2 + q(3)**2 + q(4)**2 + bm = q(5)**2 + q(6)**2 + q(7)**2 + pg = (gamma-1.)*(q(8) - vk/q(1)/2. - bm/2.) + + vb = ux*q(5) + uy*q(6) + uz*q(7) + pt = pg + bp/2.-bp0/2. + + f(1) = q(3) + f(2) = q(2)*uy - qb5*qb6 + bs(1)*bs(2) + f(3) = q(3)*uy + pt - qb6**2 + bs(2)**2 + f(4) = q(4)*uy - qb6*qb7 + bs(2)*bs(3) + f(5) = qb5*uy - qb6*ux + f(6) = 0. + f(7) = qb7*uy - qb6*uz + f(8) = (q(8) + pt)*uy - qb6*vb + + RETURN + END + + SUBROUTINE FLUXz_ig(gamma,QP,BS,F) + Implicit NONE + + ENZO_REAL QP(8),Q(8),BS(3),F(8) + ENZO_REAL gamma,qb5,qb6,qb7,bp,bp0,ux,uy,uz,vk,bm,pg,vb,pt + + CALL CONS_ig(gamma,QP,Q) + + qb5 = q(5)+bs(1) + qb6 = q(6)+bs(2) + qb7 = q(7)+bs(3) + + bp = qb5**2 + qb6**2 + qb7**2 + bp0 = bs(1)**2 + bs(2)**2 + bs(3)**2 + + ux = q(2)/q(1) + uy = q(3)/q(1) + uz = q(4)/q(1) + + vk = q(2)**2 + q(3)**2 + q(4)**2 + bm = q(5)**2 + q(6)**2 + q(7)**2 + pg = (gamma-1.)*(q(8) - vk/q(1)/2. - bm/2.) + + vb = ux*q(5) + uy*q(6) + uz*q(7) + pt = pg + bp/2.-bp0/2. + + f(1) = q(4) + f(2) = q(2)*uz - qb5*qb7 + bs(1)*bs(3) + f(3) = q(3)*uz - qb6*qb7 + bs(2)*bs(3) + f(4) = q(4)*uz + pt - qb7**2 + bs(3)**2 + f(5) = qb5*uz - qb7*ux + f(6) = qb6*uz - qb7*uy + f(7) = 0. + f(8) = (q(8) + pt)*uz - qb7*vb + + RETURN + END + + SUBROUTINE FPMR_ig(Y,QL,QR,QP,QC) + Implicit NONE + + ENZO_REAL QL(8),QR(8),QP(8),QC(8) + ENZO_REAL DQ,Q6,Y + integer M + + DO M=1,8 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.) + QC(M)=QL(M)+Y/2.*(DQ+(1.-2./3.*Y)*Q6) + ENDDO + + RETURN + END + + SUBROUTINE FPML_ig(Y,QL,QR,QP,QC) + Implicit NONE + + integer m + ENZO_REAL QL(8),QR(8),QP(8),QC(8) + ENZO_REAL DQ,Q6,y + + DO M=1,8 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.) + QC(M)=QR(M)-Y/2.*(DQ-(1.-2./3.*Y)*Q6) + ENDDO + + RETURN + END + + SUBROUTINE FQML_ig(Y,QL,QR,QP,QC) + Implicit NONE + + Integer M + ENZO_REAL QL(8),QR(8),QP(8),QC(8) + ENZO_REAL DQ,Q6,Y + + DO M=1,8 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.) + QC(M)=QL(M)+Y*(DQ+(1.-Y)*Q6) + ENDDO + + RETURN + END + + + Subroutine QDD6_ig(Nx,Qvr,Qvl,Qrx,Qlx,Qp) + Implicit NONE + + Integer m,nx,i + ENZO_REAL Qvr(Nx,8),Qvl(Nx,8),Qp(Nx,8) + ENZO_REAL Qrx(Nx,8),Qlx(Nx,8) + ENZO_REAL DQ,Q6 + + Do I=1,Nx + + DO M=1,8 + + IF((QVR(I,M)-QP(I,M))*(QP(I,M)-QVL(I,M)).LE.0.)THEN + QRX(I,M)=QP(I,M) + QLX(I,M)=QP(I,M) + ELSE + + DQ=QVR(I,M)-QVL(I,M) + Q6=6.0*(QP(I,M)-(QVR(I,M)+QVL(I,M))/2.) + + QLX(I,M)=QVL(I,M) + QRX(I,M)=QVR(I,M) + + IF(DQ*Q6.GT.DQ**2) QLX(I,M)=3.*QP(I,M)-2.*QVR(I,M) + IF(DQ*Q6.LT.-DQ**2) QRX(I,M)=3.*QP(I,M)-2.*QVL(I,M) + + ENDIF + + ENDDO + ENDDO + + Return + End + + SUBROUTINE MATR_AX_ig(gamma,QU,BS,QL) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),BS(3) + ENZO_REAL GAMMA,QU5,QU6,QU7 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + QL(1,1)=QU(2) + QL(1,2)=QU(1) + QL(1,3)=0. + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + QL(1,8)=0. + + QL(2,1)=0. + QL(2,2)=QU(2) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=0. + QL(2,6)=QU6/QU(1) + QL(2,7)=QU7/QU(1) + QL(2,8)=1./QU(1) + + QL(3,1)=0. + QL(3,2)=0. + QL(3,3)=QU(2) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=-QU5/QU(1) + QL(3,7)=0. + QL(3,8)=0. + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(2) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=-QU5/QU(1) + QL(4,8)=0. + + QL(5,1)=0. + QL(5,2)=0. + QL(5,3)=0. + QL(5,4)=0. + QL(5,5)=QU(2) + QL(5,6)=0. + QL(5,7)=0. + QL(5,8)=0. + + QL(6,1)=0. + QL(6,2)=QU6 + QL(6,3)=-QU5 + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=QU(2) + QL(6,7)=0. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=QU7 + QL(7,3)=0. + QL(7,4)=-QU5 + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(2) + QL(7,8)=0. + + QL(8,1)=0. + QL(8,2)=GAMMA*QU(8) + QL(8,3)=0. + QL(8,4)=0. + QL(8,5)=0. + QL(8,6)=0. + QL(8,7)=0. + QL(8,8)=QU(2) + + RETURN + END + + SUBROUTINE MATR_AY_ig(gamma,QU,BS,QL) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),BS(3) + ENZO_REAL GAMMA,QU5,QU6,QU7 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + QL(1,1)=QU(3) + QL(1,2)=0. + QL(1,3)=QU(1) + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + QL(1,8)=0. + + QL(2,1)=0. + QL(2,2)=QU(3) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=-QU6/QU(1) + QL(2,6)=0. + QL(2,7)=0. + QL(2,8)=0. + + QL(3,1)=0. + QL(3,2)=0. + QL(3,3)=QU(3) + QL(3,4)=0. + QL(3,5)=QU5/QU(1) + QL(3,6)=0. + QL(3,7)=QU7/QU(1) + QL(3,8)=1./QU(1) + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(3) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=-QU6/QU(1) + QL(4,8)=0. + + QL(5,1)=0. + QL(5,2)=-QU6 + QL(5,3)=QU5 + QL(5,4)=0. + QL(5,5)=QU(3) + QL(5,6)=0. + QL(5,7)=0. + QL(5,8)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=0. + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=QU(3) + QL(6,7)=0. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=QU7 + QL(7,4)=-QU6 + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(3) + QL(7,8)=0. + + QL(8,1)=0. + QL(8,2)=0. + QL(8,3)=GAMMA*QU(8) + QL(8,4)=0. + QL(8,5)=0. + QL(8,6)=0. + QL(8,7)=0. + QL(8,8)=QU(3) + + RETURN + END + + SUBROUTINE MATR_AZ_ig(gamma,QU,BS,QL) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),BS(3) + ENZO_REAL GAMMA,QU5,QU6,QU7 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + QL(1,1)=QU(4) + QL(1,2)=0. + QL(1,3)=0. + QL(1,4)=QU(1) + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + QL(1,8)=0. + + QL(2,1)=0. + QL(2,2)=QU(4) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=-QU7/QU(1) + QL(2,6)=0. + QL(2,7)=0. + QL(2,8)=0. + + QL(3,1)=0. + QL(3,2)=0. + QL(3,3)=QU(4) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=-QU7/QU(1) + QL(3,7)=0. + QL(3,8)=0. + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(4) + QL(4,5)=QU5/QU(1) + QL(4,6)=QU6/QU(1) + QL(4,7)=0. + QL(4,8)=1./QU(1) + + + QL(5,1)=0. + QL(5,2)=-QU7 + QL(5,3)=0. + QL(5,4)=QU5 + QL(5,5)=QU(4) + QL(5,6)=0. + QL(5,7)=0. + QL(5,8)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=-QU7 + QL(6,4)=QU6 + QL(6,5)=0. + QL(6,6)=QU(4) + QL(6,7)=0. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=0. + QL(7,4)=0. + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(4) + QL(7,8)=0. + + QL(8,1)=0. + QL(8,2)=0. + QL(8,3)=0. + QL(8,4)=GAMMA*QU(8) + QL(8,5)=0. + QL(8,6)=0. + QL(8,7)=0. + QL(8,8)=QU(4) + + RETURN + END + + SUBROUTINE DUDW_ig(gamma,QU,BS,QL) + Implicit NONE + + ENZO_REAL QU(8),QL(8,8),BS(3) + ENZO_REAL GAMMA,QU5,QU6,QU7 + + QU5=QU(5)+BS(1) + QU6=QU(6)+BS(2) + QU7=QU(7)+BS(3) + + QL(1,1)=1. + QL(1,2)=0. + QL(1,3)=0. + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + QL(1,8)=0. + + QL(2,1)=QU(2) + QL(2,2)=QU(1) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=0. + QL(2,6)=0. + QL(2,7)=0. + QL(2,8)=0. + + QL(3,1)=QU(3) + QL(3,2)=0. + QL(3,3)=QU(1) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=0. + QL(3,7)=0. + QL(3,8)=0. + + QL(4,1)=QU(4) + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(1) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=0. + QL(4,8)=0. + + QL(5,1)=0. + QL(5,2)=0. + QL(5,3)=0. + QL(5,4)=0. + QL(5,5)=1. + QL(5,6)=0. + QL(5,7)=0. + QL(5,8)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=0. + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=1. + QL(6,7)=0. + QL(6,8)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=0. + QL(7,4)=0. + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=1. + QL(7,8)=0. + + QL(8,1)=(QU(2)**2+QU(3)**2+QU(4)**2)/2. + QL(8,2)=QU(1)*QU(2) + QL(8,3)=QU(1)*QU(3) + QL(8,4)=QU(1)*QU(4) + QL(8,5)=QU5 + QL(8,6)=QU6 + QL(8,7)=QU7 + QL(8,8)=1./(GAMMA-1.) + + RETURN + END + + SUBROUTINE AMPLTD_ig(QL,QD,SL) + Implicit NONE + + Integer L,M + ENZO_REAL QL(8,8),QD(8),SL(8) + + DO M=1,8 + SL(M)=0. + DO L=1,8 + SL(M)=SL(M)+QL(M,L)*QD(L) + ENDDO + ENDDO + + RETURN + END + + Function Xminmod_ig(x,y) + + ENZO_REAL x,y,Xminmod + + Xminmod = 0.5*(sign(1.,x) + sign(1.,y))*min(abs(x),abs(y)) + + Return + End + + Function Xmedian_ig(x,y,z) + + ENZO_REAL x,y,z,Xminmod,Xmedian + + External Xminmod + + Xmedian = x + Xminmod(y-x,z-x) + + Return + End + + SUBROUTINE W5RECM_ig(VP1,VP2,VP3,VP4,VP5,VL,VR) + Implicit NONE + + ENZO_REAL IS1,IS2,IS3,DELTA,WS1,WS2,WS3,WJ1,WJ2,WJ3 + ENZO_REAL AJ1,AJ2,AJ3,AJS,WM1,WM2,WM3,VL,VR + ENZO_REAL VP1,VP2,VP3,VP4,VP5 + + DELTA = 1.0e-10 + + WS1 = 0.1 + WS2 = 0.6 + WS3 = 0.3 + + + WJ1 = (11.*VP3 - 7.*VP2 + 2.*VP1)/6. + WJ2 = (2. *VP4 + 5.*VP3 - VP2)/6. + WJ3 = ( -VP5 + 5.*VP4 + 2.*VP3)/6. + + IS1 = 13./12.*(VP3 - 2.*VP2 + VP1)**2 + & + (3.*VP3 - 4.*VP2 + VP1)**2/4. + IS2 = 13./12.*(VP4 - 2.*VP3 + VP2)**2 + & + (VP4 - VP2)**2/4. + IS3 = 13./12.*(VP5 - 2.*VP4 + VP3)**2 + & + (VP5 - 4.*VP4 + 3.*VP3)**2/4. + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.*WS1*WM1 + WM1*WM1)/(WS1*WS1 + & + WM1*(1. - 2.*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.*WS2*WM2 + WM2*WM2)/(WS2*WS2 + & + WM2*(1. - 2.*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.*WS3*WM3 + WM3*WM3)/(WS3*WS3 + & + WM3*(1. - 2.*WS3)) + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + VR = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + WJ1 = (11.*VP3 - 7.*VP4 + 2.*VP5)/6. + WJ2 = (2. *VP2 + 5.*VP3 - VP4)/6. + WJ3 = ( -VP1 + 5.*VP2 + 2.*VP3)/6. + + IS1 = 13./12.*(VP3 - 2.*VP4 + VP5)**2 + & + (3.*VP3 - 4.*VP4 + VP5)**2/4. + IS2 = 13./12.*(VP2 - 2.*VP3 + VP4)**2 + & + (VP2 - VP4)**2/4. + IS3 = 13./12.*(VP1 - 2.*VP2 + VP3)**2 + & + (VP1 - 4.*VP2 + 3.*VP3)**2/4. + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.*WS1*WM1 + WM1*WM1)/(WS1*WS1 + & + WM1*(1. - 2.*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.*WS2*WM2 + WM2*WM2)/(WS2*WS2 + & + WM2*(1. - 2.*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.*WS3*WM3 + WM3*WM3)/(WS3*WS3 + & + WM3*(1. - 2.*WS3)) + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + VL = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + RETURN + END + + Function VLeer_ig(a,b) + + ENZO_REAL a,b,VLeer + + if(a*a+b*b.ne.0)then + VLeer=max(a*b,0.)*(a+b)/(a*a+b*b) + + else + VLeer=0. + endif + + Return + End + + SUBROUTINE PRIM_ig(gamma,QU,QP) + Implicit NONE + + ENZO_REAL QU(8),QP(8) + ENZO_REAL gamma,VKV,BKV + + QP(1)=QU(1) + QP(2)=QU(2)/QU(1) + QP(3)=QU(3)/QU(1) + QP(4)=QU(4)/QU(1) + QP(5)=QU(5) + QP(6)=QU(6) + QP(7)=QU(7) + + VKV=QU(2)**2+QU(3)**2+QU(4)**2 + BKV=QU(5)**2+QU(6)**2+QU(7)**2 + + QP(8)=(GAMMA-1.)*(QU(8)-VKV/QU(1)/2.-BKV/2.) + + RETURN + END + + SUBROUTINE CONS_ig(gamma,QP,QU) + Implicit NONE + + ENZO_REAL QU(8),QP(8) + ENZO_REAL gamma,VKV,BKV + + QU(1)=QP(1) + QU(2)=QP(2)*QP(1) + QU(3)=QP(3)*QP(1) + QU(4)=QP(4)*QP(1) + QU(5)=QP(5) + QU(6)=QP(6) + QU(7)=QP(7) + + VKV=QP(2)**2+QP(3)**2+QP(4)**2 + BKV=QP(5)**2+QP(6)**2+QP(7)**2 + + QU(8)=QP(8)/(GAMMA-1.)+QP(1)*VKV/2.+BKV/2. + + RETURN + END diff --git a/src/Enzo/_enzo.hpp b/src/Enzo/_enzo.hpp index 241d3611f5..01be2b27e5 100644 --- a/src/Enzo/_enzo.hpp +++ b/src/Enzo/_enzo.hpp @@ -122,18 +122,6 @@ enum return_enum { const int field_undefined = -1; -//---------------------------------------------------------------------- - -struct enzo_fluxes -{ - long_int LeftFluxStartGlobalIndex [MAX_DIMENSION][MAX_DIMENSION]; - long_int LeftFluxEndGlobalIndex [MAX_DIMENSION][MAX_DIMENSION]; - long_int RightFluxStartGlobalIndex[MAX_DIMENSION][MAX_DIMENSION]; - long_int RightFluxEndGlobalIndex [MAX_DIMENSION][MAX_DIMENSION]; - enzo_float *LeftFluxes [MAX_NUMBER_OF_BARYON_FIELDS][MAX_DIMENSION]; - enzo_float *RightFluxes[MAX_NUMBER_OF_BARYON_FIELDS][MAX_DIMENSION]; -}; - //---------------------------------------------------------------------- // Cello include file //---------------------------------------------------------------------- @@ -202,6 +190,7 @@ extern "C" { // declare the names of Grackle types so can reduce the usage of #include "io/IoEnzoBlock.hpp" #include "io/IoEnzoReader.hpp" #include "io/IoEnzoWriter.hpp" +#include "io/IoEnzoSimulation.hpp" #include "enzo-core/EnzoBoundary.hpp" @@ -223,6 +212,7 @@ extern "C" { // declare the names of Grackle types so can reduce the usage of #include "initial/EnzoInitialShockTube.hpp" #include "initial/EnzoInitialSoup.hpp" #include "initial/EnzoInitialTurbulence.hpp" +#include "turbulence/EnzoInitialTurbulenceMhdIT.hpp" #include "initial/EnzoInitialIsolatedGalaxy.hpp" #include "initial/EnzoInitialBurkertBodenheimer.hpp" #include "tests/EnzoInitialMergeSinksTest.hpp" @@ -282,13 +272,15 @@ extern "C" { // declare the names of Grackle types so can reduce the usage of #include "particle/EnzoMethodPmUpdate.hpp" #include "hydro-mhd/EnzoMethodPpm.hpp" #include "hydro-mhd/EnzoMethodPpml.hpp" +#include "hydro-mhd/ppml_ig/EnzoMethodPpmlIG.hpp" #include "particle/formation/EnzoMethodSinkMaker.hpp" #include "particle/formation/EnzoMethodStarMaker.hpp" #include "particle/formation/EnzoMethodStarMakerSTARSS.hpp" #include "particle/formation/EnzoMethodStarMakerStochasticSF.hpp" #include "particle/formation/EnzoMethodThresholdAccretion.hpp" #include "assorted/EnzoMethodTurbulence.hpp" - +#include "turbulence/EnzoMethodTurbulenceMhdIT.hpp" +#include "turbulence/EnzoMethodTurbulenceOU.hpp" #include "gravity/matrix/EnzoMatrixDiagonal.hpp" #include "gravity/matrix/EnzoMatrixIdentity.hpp" #include "gravity/matrix/EnzoMatrixLaplace.hpp" diff --git a/src/Enzo/assorted/EnzoMethodTurbulence.cpp b/src/Enzo/assorted/EnzoMethodTurbulence.cpp index fac547285b..7f60edec17 100644 --- a/src/Enzo/assorted/EnzoMethodTurbulence.cpp +++ b/src/Enzo/assorted/EnzoMethodTurbulence.cpp @@ -10,7 +10,7 @@ #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" // #define DEBUG_TURBULENCE @@ -120,7 +120,7 @@ void EnzoMethodTurbulence::compute ( Block * block) throw() int ndy = ny + 2*gy; const int n = max_turbulence_array; - double g[n]; + long double g[n]; for (int i=0; iproxy_array()); - enzo_block->contribute(n*sizeof(double),g,r_method_turbulence_type,callback); + + enzo_block->contribute(n*sizeof(long double),g,r_method_turbulence_type,callback); } //---------------------------------------------------------------------- @@ -189,7 +190,7 @@ void register_method_turbulence(void) CkReductionMsg * r_method_turbulence(int n, CkReductionMsg ** msgs) { - double accum[max_turbulence_array]; + long double accum[max_turbulence_array]; for (int i=0; i::max(); for (int i=0; igetData(); + long double * values = (long double *) msgs[i]->getData(); for (int ig=0; iggetData(); + long double * g = (long double *)msg->getData(); Data * data = block->data(); Field field = data->field(); @@ -327,41 +328,41 @@ void EnzoMethodTurbulence::compute_resume Monitor * monitor = cello::monitor(); - monitor->print ("Method","sum v*a*d " "%.17g", g[index_turbulence_vad]); - monitor->print ("Method","sum a*a*d " "%.17g",g[index_turbulence_aad]); - monitor->print ("Method","sum v*v*d/t " "%.17g",g[index_turbulence_vvdot]); - monitor->print ("Method","sum v*v/t " "%.17g",g[index_turbulence_vvot]); - monitor->print ("Method","sum v*v*d " "%.17g",g[index_turbulence_vvd]); - monitor->print ("Method","sum v*v " "%.17g",g[index_turbulence_vv]); - monitor->print ("Method","sum d*d " "%.17g",g[index_turbulence_dd]); + monitor->print ("Method","sum v*a*d " "%.17Lg", g[index_turbulence_vad]); + monitor->print ("Method","sum a*a*d " "%.17Lg",g[index_turbulence_aad]); + monitor->print ("Method","sum v*v*d/t " "%.17Lg",g[index_turbulence_vvdot]); + monitor->print ("Method","sum v*v/t " "%.17Lg",g[index_turbulence_vvot]); + monitor->print ("Method","sum v*v*d " "%.17Lg",g[index_turbulence_vvd]); + monitor->print ("Method","sum v*v " "%.17Lg",g[index_turbulence_vv]); + monitor->print ("Method","sum d*d " "%.17Lg",g[index_turbulence_dd]); - monitor->print ("Method","sum d*ax " "%.17g",g[index_turbulence_dax]); - monitor->print ("Method","sum d*ay " "%.17g",g[index_turbulence_day]); - monitor->print ("Method","sum d*az " "%.17g",g[index_turbulence_daz]); + monitor->print ("Method","sum d*ax " "%.17Lg",g[index_turbulence_dax]); + monitor->print ("Method","sum d*ay " "%.17Lg",g[index_turbulence_day]); + monitor->print ("Method","sum d*az " "%.17Lg",g[index_turbulence_daz]); - monitor->print ("Method","sum d*vx " "%.17g",g[index_turbulence_dvx]); - monitor->print ("Method","sum d*vy " "%.17g",g[index_turbulence_dvy]); - monitor->print ("Method","sum d*vz " "%.17g",g[index_turbulence_dvz]); + monitor->print ("Method","sum d*vx " "%.17Lg",g[index_turbulence_dvx]); + monitor->print ("Method","sum d*vy " "%.17Lg",g[index_turbulence_dvy]); + monitor->print ("Method","sum d*vz " "%.17Lg",g[index_turbulence_dvz]); - monitor->print ("Method","sum d*ln(d) " "%.17g",g[index_turbulence_dlnd]); - monitor->print ("Method","sum zones " "%.17g",g[index_turbulence_zones]); + monitor->print ("Method","sum d*ln(d) " "%.17Lg",g[index_turbulence_dlnd]); + monitor->print ("Method","sum zones " "%.17Lg",g[index_turbulence_zones]); - monitor->print ("Method","min d " "%.17g",g[index_turbulence_mind]); - monitor->print ("Method","max d " "%.17g",g[index_turbulence_maxd]); - monitor->print ("Method","sum d " "%.17g",g[index_turbulence_d]); - monitor->print ("Method","norm " "%.17g",norm); + monitor->print ("Method","min d " "%.17Lg",g[index_turbulence_mind]); + monitor->print ("Method","max d " "%.17Lg",g[index_turbulence_maxd]); + monitor->print ("Method","sum d " "%.17Lg",g[index_turbulence_d]); + monitor->print ("Method","norm " "%.17Lg",norm); - monitor->print ("Method","kinetic energy " "%.17g", + monitor->print ("Method","kinetic energy " "%.17Lg", 0.50*g[index_turbulence_vvd]/n); - monitor->print ("Method","mass weighted rms Mach " "%.17g", + monitor->print ("Method","mass weighted rms Mach " "%.17Lg", sqrt(g[index_turbulence_vvdot]/n)); - monitor->print ("Method","volume weighed rms Mach " "%.17g", + monitor->print ("Method","volume weighed rms Mach " "%.17Lg", sqrt(g[index_turbulence_vvot]/n)); - monitor->print ("Method","rms Velocity " "%.17g", + monitor->print ("Method","rms Velocity " "%.17Lg", sqrt(g[index_turbulence_vv]/n)); - monitor->print ("Method","Density variance " "%.17g", + monitor->print ("Method","Density variance " "%.17Lg", sqrt(g[index_turbulence_dd]/n)); - monitor->print ("Method","min/max Density " "%.17g", + monitor->print ("Method","min/max Density " "%.17Lg", g[index_turbulence_mind] / g[index_turbulence_maxd]); } @@ -395,7 +396,7 @@ void EnzoMethodTurbulence::compute_resume_ int n = nx*ny*nz; - double * g = (double *)msg->getData(); + long double * g = (long double *)msg->getData(); double dt = block->dt(); diff --git a/src/Enzo/cnames.h b/src/Enzo/cnames.h new file mode 100644 index 0000000000..7afb96d160 --- /dev/null +++ b/src/Enzo/cnames.h @@ -0,0 +1,21 @@ + +#define write_wp write_wp_ +#define write_wp_dim write_wp_dim_ +#define read_wp read_wp_ +#define read_wp_dim read_wp_dim_ + +#define read_wp_dim_mb read_wp_dim_mb_ +#define read_wp_mb_allgrids read_wp_mb_allgrids_ +#define read_wp_mb read_wp_mb_ +#define write_wp_dim_mb write_wp_dim_mb_ +#define write_wp_mb write_wp_mb_ +#define write_wp_mb_allgrids write_wp_mb_allgrids_ + +#define initrandom initrandom_ +#define initrandomx initrandomx_ +#define randomnr randomnr_ +#define seedrang seedrang_ +#define crandseed crandseed_ +#define gettimec gettimec_ + +#define write_tecplot write_tecplot_ diff --git a/src/Enzo/cosmology/EnzoMethodComovingExpansion.cpp b/src/Enzo/cosmology/EnzoMethodComovingExpansion.cpp index 01e09b6ac0..f14d7f2cc8 100644 --- a/src/Enzo/cosmology/EnzoMethodComovingExpansion.cpp +++ b/src/Enzo/cosmology/EnzoMethodComovingExpansion.cpp @@ -8,7 +8,7 @@ #include "cello.hpp" #include "charm_simulation.hpp" #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" //---------------------------------------------------------------------- EnzoMethodComovingExpansion::EnzoMethodComovingExpansion diff --git a/src/Enzo/crand.cpp b/src/Enzo/crand.cpp new file mode 100644 index 0000000000..68d9343517 --- /dev/null +++ b/src/Enzo/crand.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include "cnames.h" +#include "enzo_defines.hpp" + +extern "C" { + + unsigned int curr_rand_seed = 0; + + void initrandomx(int* x) + { + srand(*x); + } + + void initrandom() + { + srand((int)time(0)); + } + + double randomnr() + { + return ((double)(rand_r(&curr_rand_seed)))/RAND_MAX; + } + + int crandseed() + { + return curr_rand_seed; + } + void FORTRAN_NAME(setcrandseed)(int * rand_seed) + { + curr_rand_seed = *rand_seed; + } + + void seedrang( int* ss ) + { + int fd = open("/dev/urandom",O_RDONLY); + int mask = 0x0001FFFF; + int nr; + nr = read(fd,ss,sizeof(int)); + *ss &= mask; + close(fd); + } +} diff --git a/src/Enzo/enzo-core/EnzoBlock.cpp b/src/Enzo/enzo-core/EnzoBlock.cpp index a245374358..c33dddd003 100644 --- a/src/Enzo/enzo-core/EnzoBlock.cpp +++ b/src/Enzo/enzo-core/EnzoBlock.cpp @@ -125,12 +125,6 @@ void EnzoBlock::initialize(const EnzoConfig * enzo_config) // Check NumberOfBaryonFields - if (NumberOfBaryonFields[in] > MAX_NUMBER_OF_BARYON_FIELDS) { - ERROR2 ("EnzoBlock::initialize", - "MAX_NUMBER_OF_BARYON_FIELDS = %d is too small for %d fields", - MAX_NUMBER_OF_BARYON_FIELDS,NumberOfBaryonFields[in] ); - } - DomainLeftEdge [in*3+0] = enzo_config->domain_lower[0]; DomainLeftEdge [in*3+1] = enzo_config->domain_lower[1]; DomainLeftEdge [in*3+2] = enzo_config->domain_lower[2]; diff --git a/src/Enzo/enzo-core/EnzoBlock.hpp b/src/Enzo/enzo-core/EnzoBlock.hpp index ec3a94bd45..a5b6cfc664 100644 --- a/src/Enzo/enzo-core/EnzoBlock.hpp +++ b/src/Enzo/enzo-core/EnzoBlock.hpp @@ -12,7 +12,7 @@ // #define TRACE_BLOCK -#include "enzo.decl.h" +#include "charm_enzo.hpp" class EnzoBlock : public CBase_EnzoBlock @@ -160,6 +160,9 @@ class EnzoBlock : public CBase_EnzoBlock /// Solve the mhd equations (with ppml), saving subgrid fluxes int SolveMHDEquations(enzo_float dt); + /// Solve the mhd equations (with ppml), saving subgrid fluxes + int SolveMHDEquationsIG(enzo_float dt, enzo_float gamma, enzo_float b0[3]); + /// Set EnzoBlock's dt (overloaded to update EnzoBlock::dt) virtual void set_dt (double dt) throw(); @@ -176,9 +179,18 @@ class EnzoBlock : public CBase_EnzoBlock /// Perform the necessary reductions CkReductionMsg * r_method_turbulence(int n, CkReductionMsg ** msgs); + CkReductionMsg * r_method_turbulence_mhd_ig(int n, CkReductionMsg ** msgs); + CkReductionMsg * r_method_turbulence_mhd_it(int n, CkReductionMsg ** msgs); /// Compute sum, min, and max of g values for EnzoMethodTurbulence void r_method_turbulence_end(CkReductionMsg *msg); + void r_method_turbulence_mhd_ig_end(CkReductionMsg *msg); + void r_method_turbulence_mhd_it_end(CkReductionMsg *msg); + + /// EnzoTurbulenceOU + void r_method_turbulence_ou_shift(CkReductionMsg *msg); + void r_method_turbulence_ou_update(CkReductionMsg *msg); + void r_method_turbulence_ou_end(CkReductionMsg *msg); void p_initial_hdf5_recv(MsgInitial * msg_initial); diff --git a/src/Enzo/enzo-core/EnzoConfig.cpp b/src/Enzo/enzo-core/EnzoConfig.cpp index 7dc6ebea5c..bdde08d8b9 100644 --- a/src/Enzo/enzo-core/EnzoConfig.cpp +++ b/src/Enzo/enzo-core/EnzoConfig.cpp @@ -16,7 +16,7 @@ EnzoConfig g_enzo_config; EnzoConfig::EnzoConfig() throw () : - adapt_mass_type(0), + adapt_mass_type(), ppm_diffusion(false), ppm_flattening(0), ppm_minimum_pressure_support_parameter(0), @@ -172,6 +172,7 @@ EnzoConfig::EnzoConfig() throw () initial_soup_density(0.0), // EnzoInitialTurbulence initial_turbulence_density(0.0), + initial_turbulence_bfieldx(0.0), initial_turbulence_pressure(0.0), initial_turbulence_temperature(0.0), // EnzoInitialIsolatedGalaxy @@ -226,6 +227,10 @@ EnzoConfig::EnzoConfig() throw () initial_bb_test_external_density(0.0), // EnzoMethodHeat method_heat_alpha(0.0), + // EnzoMethodPpml + method_ppml_dt_weight(), + // EnzoMethodPpmlIg + method_ppml_b0(), // EnzoMethodHydro method_hydro_method(""), method_hydro_dual_energy(false), @@ -254,7 +259,6 @@ EnzoConfig::EnzoConfig() throw () method_feedback_analytic_SNR_shell_mass(true), method_feedback_fade_SNR(true), method_feedback_NEvents(-1), - method_feedback_radiation(true), // EnzoMethodM1Closure method_m1_closure(false), method_m1_closure_N_groups(1), // # of frequency bins @@ -304,6 +308,22 @@ EnzoConfig::EnzoConfig() throw () // EnzoMethodTurbulence method_turbulence_edot(0.0), method_turbulence_mach_number(0.0), + // EnzoMethodTurbulenceOU + method_turbulence_apply_cooling(false), + method_turbulence_apply_forcing(false), + method_turbulence_apply_injection_rate(false), + method_turbulence_cooling_term(0), + method_turbulence_hc_alpha(0.0), + method_turbulence_hc_sigma(0.0), + method_turbulence_injection_rate(0.006), + method_turbulence_kfa(12.57), + method_turbulence_kfi(6.27), + method_turbulence_olap(0), + method_turbulence_read_sol(false), + method_turbulence_sol_weight(1.0), + method_turbulence_totemp(0.0), + method_turbulence_update_solution(false), + // EnzoMethodGrackle method_grackle_use_grackle(false), method_grackle_chemistry(), method_grackle_use_cooling_timestep(false), @@ -496,6 +516,7 @@ void EnzoConfig::pup (PUP::er &p) p | initial_sedov_random_te_multiplier; p | initial_turbulence_density; + p | initial_turbulence_bfieldx; p | initial_turbulence_pressure; p | initial_turbulence_temperature; @@ -634,6 +655,9 @@ void EnzoConfig::pup (PUP::er &p) p | method_heat_alpha; + p | method_ppml_dt_weight; + PUParray(p,method_ppml_b0,3); + p | method_turbulence_edot; p | method_hydro_method; p | method_hydro_dual_energy; p | method_hydro_dual_energy_eta_1; @@ -712,6 +736,9 @@ void EnzoConfig::pup (PUP::er &p) p | method_turbulence_edot; + p | method_turbulence_edot; + p | method_turbulence_mach_number; + p | method_gravity_grav_const; p | method_gravity_solver; p | method_gravity_order; @@ -778,6 +805,21 @@ void EnzoConfig::pup (PUP::er &p) p | units_length; p | units_time; + p | method_turbulence_apply_cooling; + p | method_turbulence_apply_forcing; + p | method_turbulence_apply_injection_rate; + p | method_turbulence_cooling_term; + p | method_turbulence_hc_alpha; + p | method_turbulence_hc_sigma; + p | method_turbulence_injection_rate; + p | method_turbulence_kfa; + p | method_turbulence_kfi; + p | method_turbulence_olap; + p | method_turbulence_read_sol; + p | method_turbulence_sol_weight; + p | method_turbulence_totemp; + p | method_turbulence_update_solution; + p | method_grackle_use_grackle; if (method_grackle_use_grackle) { @@ -843,6 +885,7 @@ void EnzoConfig::read(Parameters * p) throw() read_method_merge_sinks_(p); read_method_pm_deposit_(p); read_method_pm_update_(p); + read_method_ppml_(p); read_method_ppm_(p); read_method_m1_closure_(p); read_method_sink_maker_(p); @@ -2045,12 +2088,70 @@ void EnzoConfig::read_method_ppm_(Parameters * p) //---------------------------------------------------------------------- +void EnzoConfig::read_method_ppml_(Parameters * p) +{ + // EnzoMethodPpml + method_ppml_dt_weight = p->value_float ("Method:ppml:dt_weight",1.0); + + // EnzoMethodPpmlIg + method_ppml_b0[0] = p->list_value_float (0,"Method:ppml_ig:b0",1.0); + method_ppml_b0[1] = p->list_value_float (1,"Method:ppml_ig:b0",1.0); + method_ppml_b0[2] = p->list_value_float (2,"Method:ppml_ig:b0",1.0); +} + +//---------------------------------------------------------------------- + void EnzoConfig::read_method_turbulence_(Parameters * p) { + + double mach = 0.0; method_turbulence_edot = p->value_float ("Method:turbulence:edot",-1.0); - method_turbulence_mach_number = p->value_float - ("Method:turbulence:mach_number",0.0); + method_turbulence_mach_number = mach = p->value_float + ("Method:turbulence:mach_number",mach); + + // MHD Turbulence method and initialization + + initial_turbulence_density = p->value_float + ("Initial:turbulence_mhd_it:density",1.0); + initial_turbulence_bfieldx = p->value_float + ("Initial:turbulence_mhd_it:bfieldx",0.0); + method_turbulence_edot = p->value_float + ("Method:turbulence_mhd_it:edot",-1.0); + method_turbulence_mach_number = mach = p->value_float + ("Method:turbulence_mhd_it:mach_number",mach); + + // MethodTurbulenceOU + method_turbulence_apply_cooling = p->value_logical + ("Method:turbulence_ou:apply_cooling",false); + method_turbulence_apply_forcing = p->value_logical + ("Method:turbulence_ou:apply_forcing",false); + method_turbulence_apply_injection_rate = p->value_logical + ("Method:turbulence_ou:apply_injection_rate",false); + method_turbulence_cooling_term = p->value_integer + ("Method:turbulence_ou:cooling_term",0); + method_turbulence_hc_alpha = p->value_float + ("Method:turbulence_ou:hc_alpha",0.0); + method_turbulence_hc_sigma = p->value_float + ("Method:turbulence_ou:hc_sigma",0.0); + method_turbulence_injection_rate = p->value_float + ("Method:turbulence_ou:injection_rate",0.006); + method_turbulence_kfi = p->value_float + ("Method:turbulence_ou:kfi",6.27); + method_turbulence_kfa= p->value_float + ("Method:turbulence_ou:kfa",12.57); + method_turbulence_mach_number = mach = p->value_float + ("Method:turbulence_ou:mach_number",mach); + method_turbulence_olap = p->value_integer + ("Method:turbulence_ou:olap",0); + method_turbulence_read_sol = p->value_logical + ("Method:turbulence_ou:read_sol",false); + method_turbulence_sol_weight = p->value_float + ("Method:turbulence_ou:sol_weight",1.0); + method_turbulence_totemp = p->value_float + ("Method:turbulence_ou:totemp",0.0); + method_turbulence_update_solution = p->value_logical + ("Method:turbulence_ou:update_solution",false); } //---------------------------------------------------------------------- @@ -2286,7 +2387,7 @@ namespace{ // STEP 2: determine the eos-type std::string type; if (is_type_specified) { - type = p->value(prefix + "type",""); + type = p->value_string(prefix + "type",""); } else if (is_gamma_specified) { WARNING1("parse_eos_choice_", "Going forward, \"Physics:fluid_props:eos:type\" must be set " diff --git a/src/Enzo/enzo-core/EnzoConfig.hpp b/src/Enzo/enzo-core/EnzoConfig.hpp index 02f8d8b805..8689813fd0 100644 --- a/src/Enzo/enzo-core/EnzoConfig.hpp +++ b/src/Enzo/enzo-core/EnzoConfig.hpp @@ -248,6 +248,7 @@ class EnzoConfig : public Config { initial_soup_rotate(false), // EnzoInitialTurbulence initial_turbulence_density(0.0), + initial_turbulence_bfieldx(0.0), initial_turbulence_pressure(0.0), initial_turbulence_temperature(0.0), @@ -285,7 +286,10 @@ class EnzoConfig : public Config { // EnzoMethodHeat method_heat_alpha(0.0), - + // EnzoMethodPpml + method_ppml_dt_weight(1.0), + // EnzoMethodPpmlIg + method_ppml_b0(), // EnzoMethodHydro method_hydro_method(""), method_hydro_dual_energy(false), @@ -344,6 +348,21 @@ class EnzoConfig : public Config { // EnzoMethodTurbulence method_turbulence_edot(0.0), method_turbulence_mach_number(0.0), + // EnzoMethodTurbulenceOU + method_turbulence_apply_cooling(false), + method_turbulence_apply_forcing(false), + method_turbulence_apply_injection_rate(false), + method_turbulence_cooling_term(0), + method_turbulence_hc_alpha(0.0), + method_turbulence_hc_sigma(0.0), + method_turbulence_injection_rate(0.006), + method_turbulence_kfa(12.57), + method_turbulence_kfi(6.27), + method_turbulence_olap(0), + method_turbulence_read_sol(false), + method_turbulence_sol_weight(1.0), + method_turbulence_totemp(0.0), + method_turbulence_update_solution(false), // EnzoMethodGrackle method_grackle_use_grackle(false), method_grackle_chemistry(), @@ -482,6 +501,7 @@ class EnzoConfig : public Config { void read_method_merge_sinks_(Parameters *); void read_method_pm_deposit_(Parameters *); void read_method_pm_update_(Parameters *); + void read_method_ppml_(Parameters *); void read_method_ppm_(Parameters *); void read_method_sink_maker_(Parameters *); void read_method_star_maker_(Parameters *); @@ -681,6 +701,7 @@ class EnzoConfig : public Config { /// EnzoInitialTurbulence double initial_turbulence_density; + double initial_turbulence_bfieldx; double initial_turbulence_pressure; double initial_turbulence_temperature; @@ -774,6 +795,12 @@ class EnzoConfig : public Config { /// EnzoMethodHeat double method_heat_alpha; + /// EnzoMethodPpml + double method_ppml_dt_weight; + + /// EnzoMethodPpmlIg + double method_ppml_b0[3]; + /// EnzoMethodHydro std::string method_hydro_method; bool method_hydro_dual_energy; @@ -862,6 +889,23 @@ class EnzoConfig : public Config { double method_turbulence_edot; double method_turbulence_mach_number; + /// EnzoMethodTurbulenceOU + + bool method_turbulence_apply_cooling; + bool method_turbulence_apply_forcing; + bool method_turbulence_apply_injection_rate; + int method_turbulence_cooling_term; + double method_turbulence_hc_alpha; + double method_turbulence_hc_sigma; + double method_turbulence_injection_rate; + double method_turbulence_kfa; + double method_turbulence_kfi; + int method_turbulence_olap; + bool method_turbulence_read_sol; + double method_turbulence_sol_weight; + double method_turbulence_totemp; + bool method_turbulence_update_solution; + /// EnzoMethodGrackle bool method_grackle_use_grackle; GrackleChemistryData method_grackle_chemistry; diff --git a/src/Enzo/enzo-core/EnzoMsgCheck.cpp b/src/Enzo/enzo-core/EnzoMsgCheck.cpp index f17cf4414b..0f22eda52a 100644 --- a/src/Enzo/enzo-core/EnzoMsgCheck.cpp +++ b/src/Enzo/enzo-core/EnzoMsgCheck.cpp @@ -26,7 +26,7 @@ EnzoMsgCheck::EnzoMsgCheck() block_upper_(), block_size_(), tag_(), - io_block_(), + io_block_(nullptr), index_this_(), index_next_(), name_this_(), @@ -110,7 +110,8 @@ EnzoMsgCheck * EnzoMsgCheck::unpack(void * buffer) // Allocate storage using CkAllocBuffer (not new!) - EnzoMsgCheck * msg = (EnzoMsgCheck *) CkAllocBuffer (buffer,sizeof(EnzoMsgCheck)); + EnzoMsgCheck * msg = (EnzoMsgCheck *) CkAllocBuffer + (buffer,sizeof(EnzoMsgCheck)); msg = new ((void*)msg) EnzoMsgCheck; diff --git a/src/Enzo/enzo-core/EnzoMsgCheck.hpp b/src/Enzo/enzo-core/EnzoMsgCheck.hpp index ac312a847d..0a46d0f861 100644 --- a/src/Enzo/enzo-core/EnzoMsgCheck.hpp +++ b/src/Enzo/enzo-core/EnzoMsgCheck.hpp @@ -31,7 +31,8 @@ class EnzoMsgCheck : public CMessage_EnzoMsgCheck { /// Copy constructor EnzoMsgCheck(const EnzoMsgCheck & enzo_msg_check) throw() - : CMessage_EnzoMsgCheck() // do NOT call copy constructor on base + : CMessage_EnzoMsgCheck(), // do NOT call copy constructor on base + buffer_(nullptr) { ++counter[cello::index_static()]; copy_(enzo_msg_check); diff --git a/src/Enzo/enzo-core/EnzoProblem.cpp b/src/Enzo/enzo-core/EnzoProblem.cpp index fc36355dc8..c92e0bad5d 100644 --- a/src/Enzo/enzo-core/EnzoProblem.cpp +++ b/src/Enzo/enzo-core/EnzoProblem.cpp @@ -205,6 +205,12 @@ Initial * EnzoProblem::create_initial_ enzo_config->initial_turbulence_pressure, enzo_config->initial_turbulence_temperature, enzo::fluid_props()->gamma()); + } else if (type == "turbulence_mhd_it") { + initial = new EnzoInitialTurbulenceMhdIT + (cycle,time, + enzo_config->initial_turbulence_density, + enzo_config->initial_turbulence_bfieldx, + enzo::fluid_props()->gamma()); } else if (type == "pm") { std::string param_str = "Initial:" + config->initial_list[index] + ":mask"; initial = new EnzoInitialPm @@ -612,9 +618,13 @@ Method * EnzoProblem::create_method_ ); */ - } else if (name == "ppml") { + } else if (name == "ppml" || name == "ppml_it") { + + method = new EnzoMethodPpml(enzo_config->method_ppml_dt_weight); + + } else if (name == "ppml_ig") { - method = new EnzoMethodPpml; + method = new EnzoMethodPpmlIG; } else if (name == "pm_deposit") { @@ -657,6 +667,37 @@ Method * EnzoProblem::create_method_ enzo_config->method_turbulence_mach_number, enzo_config->physics_cosmology); + } else if (name == "turbulence_mhd_it") { + + method = new EnzoMethodTurbulenceMhdIT + (enzo_config->method_turbulence_edot, + enzo_config->initial_turbulence_density, + enzo_config->initial_turbulence_bfieldx, + enzo_config->method_turbulence_mach_number, + enzo_config->physics_cosmology); + + } else if (name == "turbulence_ou") { + + method = new EnzoMethodTurbulenceOU + (enzo::fluid_props()->gamma(), + enzo_config->domain_lower, + enzo_config->domain_upper, + enzo_config->method_turbulence_apply_cooling, + enzo_config->method_turbulence_apply_forcing, + enzo_config->method_turbulence_apply_injection_rate, + enzo_config->method_turbulence_cooling_term, + enzo_config->method_turbulence_hc_alpha, + enzo_config->method_turbulence_hc_sigma, + enzo_config->method_turbulence_injection_rate, + enzo_config->method_turbulence_kfi, + enzo_config->method_turbulence_kfa, + enzo_config->method_turbulence_mach_number, + enzo_config->method_turbulence_olap, + enzo_config->method_turbulence_read_sol, + enzo_config->method_turbulence_sol_weight, + enzo_config->method_turbulence_totemp, + enzo_config->method_turbulence_update_solution); + } else if (name == "cosmology") { method = new EnzoMethodCosmology; diff --git a/src/Enzo/enzo-core/EnzoProblem.hpp b/src/Enzo/enzo-core/EnzoProblem.hpp index b1cd2b20bb..2992812467 100644 --- a/src/Enzo/enzo-core/EnzoProblem.hpp +++ b/src/Enzo/enzo-core/EnzoProblem.hpp @@ -68,7 +68,7 @@ class EnzoProblem : public Problem { /// Create named refine object virtual Refine * create_refine_ (std::string type, - int index, + int index, Config * config, Parameters * parameters) throw (); diff --git a/src/Enzo/enzo-core/EnzoSimulation.cpp b/src/Enzo/enzo-core/EnzoSimulation.cpp index e2f0581d5f..5e9f98c045 100644 --- a/src/Enzo/enzo-core/EnzoSimulation.cpp +++ b/src/Enzo/enzo-core/EnzoSimulation.cpp @@ -37,8 +37,13 @@ EnzoSimulation::EnzoSimulation check_num_files_(0), check_ordering_(""), check_directory_(), - restart_level_(0) + restart_level_(0), + turbou_real_state_(), + turbou_int_state_() { + // Set turbulence state arrays to non-0 for checkpoint/restart to work + turbou_real_state_.push_back(0.0); + turbou_int_state_.push_back(0); #ifdef CHECK_MEMORY mtrace(); #endif diff --git a/src/Enzo/enzo-core/EnzoSimulation.hpp b/src/Enzo/enzo-core/EnzoSimulation.hpp index abf5bbb987..620391ba7d 100644 --- a/src/Enzo/enzo-core/EnzoSimulation.hpp +++ b/src/Enzo/enzo-core/EnzoSimulation.hpp @@ -13,7 +13,7 @@ class CProxy_IoEnzoReader; class CProxy_IoEnzoWriter; #include "charm++.h" -#include "enzo.decl.h" +#include "charm_enzo.hpp" class EnzoSimulation : public CBase_EnzoSimulation @@ -23,6 +23,8 @@ class EnzoSimulation : public CBase_EnzoSimulation /// @ingroup Enzo /// @brief [\ref Enzo] Simulation class for CHARM++ Enzo-E + friend class IoEnzoSimulation; + public: // functions /// CHARM++ Constructor @@ -65,16 +67,25 @@ class EnzoSimulation : public CBase_EnzoSimulation /// EnzoMethodCheck void r_method_check_enter (CkReductionMsg *); void p_check_done(); - void p_set_io_reader(CProxy_IoEnzoReader io_reader); - void p_set_io_writer(CProxy_IoEnzoWriter io_writer); + void p_set_io_reader(CProxy_IoEnzoReader proxy); + void p_set_io_writer(CProxy_IoEnzoWriter proxy); + void set_sync_check_writer(int count) { sync_check_writer_created_.set_stop(count); } + void p_io_reader_created(); /// Read in and initialize the next refinement level from a checkpoint; /// or exit if done void p_restart_next_level(); void p_restart_level_created(); + void p_restart_get_io_simulation(int n, char * buffer); + + /// Save or restore state for EnzoMethodTurbulenceOU for + /// checkpoint/restart (implementation in + /// enzo_EnzoMethodTurbulenceOU.cpp) + void get_turbou_state(); + void put_turbou_state(); public: // virtual functions @@ -86,7 +97,6 @@ class EnzoSimulation : public CBase_EnzoSimulation private: // functions - private: // virtual functions virtual void initialize_config_() throw(); @@ -103,8 +113,11 @@ class EnzoSimulation : public CBase_EnzoSimulation /// Balance Method synchronization Sync sync_method_balance_; /// Current restart level - int restart_level_; - + int restart_level_; + /// Turbulence state for checkpoint/restart + /// (should be moved to a Simulation Scalar object) + std::vector turbou_real_state_; + std::vector turbou_int_state_; /// MsgCheck objects for newly created Blocks on this process std::map msg_check_map_; }; diff --git a/src/Enzo/enzo-e.cpp b/src/Enzo/enzo-e.cpp index 0d9db65a29..dbd907e8c0 100644 --- a/src/Enzo/enzo-e.cpp +++ b/src/Enzo/enzo-e.cpp @@ -1,6 +1,7 @@ // See LICENSE_CELLO file for license and copyright information //---------------------------------------------------------------------- + #include /// @file enzo-e.cpp /// @author James Bordner (jobordner@ucsd.edu) @@ -49,8 +50,6 @@ extern CProxy_EnzoSimulation proxy_enzo_simulation; extern CProxy_Simulation proxy_simulation; -extern CProxy_IoEnzoWriter proxy_io_enzo_writer; -extern CProxy_IoEnzoReader proxy_io_enzo_reader; //---------------------------------------------------------------------- diff --git a/src/Enzo/enzo.ci b/src/Enzo/enzo.ci index a1ef3d0f02..7d2111cbe1 100644 --- a/src/Enzo/enzo.ci +++ b/src/Enzo/enzo.ci @@ -8,6 +8,7 @@ module enzo { initnode void register_method_turbulence(void); + initnode void register_method_turbulence_mhd_it(void); initnode void mutex_init(); initnode void mutex_init_bcg_iter(); @@ -65,8 +66,10 @@ module enzo { PUPable EnzoInitialShuCollapse; PUPable EnzoInitialSoup; PUPable EnzoInitialTurbulence; + PUPable EnzoInitialTurbulenceMhdIT; PUPable IoEnzoBlock; + PUPable IoEnzoSimulation; // EnzoRefine PUPable EnzoRefineMass; @@ -109,7 +112,10 @@ module enzo { PUPable EnzoMethodBalance; PUPable EnzoMethodSinkMaker; PUPable EnzoMethodThresholdAccretion; + PUPable EnzoMethodPpmlIG; PUPable EnzoMethodTurbulence; + PUPable EnzoMethodTurbulenceMhdIT; + PUPable EnzoMethodTurbulenceOU; PUPable EnzoIntegrationQuanUpdate; PUPable EnzoReconstructorNN; @@ -177,6 +183,7 @@ module enzo { entry void p_io_reader_created(); entry void p_restart_next_level(); entry void p_restart_level_created(); + entry void p_restart_get_io_simulation(int n, char buffer[n]); }; //---------------------------------------------------------------------- @@ -194,7 +201,13 @@ module enzo { entry void p_method_m1_closure_set_global_averages(CkReductionMsg *msg); // EnzoMethodTurbulence synchronization entry methods + entry void r_method_turbulence_end(CkReductionMsg *msg); + entry void r_method_turbulence_mhd_it_end(CkReductionMsg *msg); + + entry void r_method_turbulence_ou_shift(CkReductionMsg *msg); + entry void r_method_turbulence_ou_update(CkReductionMsg *msg); + entry void r_method_turbulence_ou_end(CkReductionMsg *msg); entry void p_initial_hdf5_recv(MsgInitial * msg_initial); diff --git a/src/Enzo/enzo.hpp b/src/Enzo/enzo.hpp index d9e1b14e90..9f9ef7002f 100644 --- a/src/Enzo/enzo.hpp +++ b/src/Enzo/enzo.hpp @@ -60,7 +60,6 @@ class EnzoMethodGrackle; /// Namespace for Enzo global accessor functions namespace enzo { - CProxy_EnzoBlock block_array(); EnzoBlock * block ( Block * block); const EnzoConfig * config(); diff --git a/src/Enzo/enzo_fortran.hpp b/src/Enzo/enzo_fortran.hpp index bda7ad891b..1de5ca34f9 100644 --- a/src/Enzo/enzo_fortran.hpp +++ b/src/Enzo/enzo_fortran.hpp @@ -50,14 +50,100 @@ extern "C" void FORTRAN_NAME(turboinit2d) int *in, int *jn, int *ig, int *jg); -// extern "C" void FORTRAN_NAME(calc_dt_30)( -// int *rank, int *idim, int *jdim, int *kdim, -// int *i1, int *i2, int *j1, int *j2, int *k1, int *k2, -// hydro_method *ihydro, float *C2, -// FLOAT *dx, FLOAT *dy, FLOAT *dz, float *vgx, float *vgy, -// float *vgz, float *gamma, int *ipfree, float *aye, -// float *d, float *p, float *u, float *v, float *w, -// float *dt, float *dtviscous); +extern "C" void FORTRAN_NAME(cello_init_turbulence_ou) + (int * is_root, + int * rank, + double fomain_size[], + double * gamma, + int * apply_injection_rate, + int * cooling_term, + double * injection_rate, + double * kmin, + double * kmax, + double * mach, + int * read_sol, + double * sol_weight, + double * weight_norm + ); + +extern "C" int FORTRAN_NAME(cello_turbou_state_size) + (int * n_buffer_real, int * n_buffer_int); + +extern "C" void FORTRAN_NAME(cello_get_turbou_state) + (double * buffer_real, int * buffer_int); + +extern "C" void FORTRAN_NAME(cello_put_turbou_state) + (double * buffer_real, int * buffer_int); + +extern "C" void FORTRAN_NAME(turbforceou) + (int * mx, int * my, int * mz, + int * ni, int * nj, int * nk, + double * field_density, double * grid, + double * wk, double * time, double * dt, + int * cello_update_sol, + int * cello_apply_cooling, + int * cello_apply_forcing, + int * cello_apply_injection_rate, + int * cello_update_phases, + int * cello_cooling_term, + double * cello_gamma, + double * cello_injection_rate, + int * olap, + double * r_gv + ); + +extern "C" void FORTRAN_NAME(turbforceshift) + (int * mx, int * my, int * mz, + int * ni, int * nj, int * nk, + double * field_density, + double * field_momentum_x, + double * field_momentum_y, + double * field_momentum_z, + double * field_jacobian, + double * wk, + int * cello_update_sol, + int * cello_apply_injection_rate, + int * cello_olap, + double * cello_injection_rate, + double * r_gv, + double * r_av); + +extern "C" void FORTRAN_NAME(turbforceupdate) + (int * mx, int * my, int * mz, + int * ni, int * nj, int * nk, + double * field_density, + double * field_momentum_x, + double * field_momentum_y, + double * field_momentum_z, + int * have_faces, + double * field_momentum_xx, + double * field_momentum_xy, + double * field_momentum_xz, + double * field_momentum_yx, + double * field_momentum_yy, + double * field_momentum_yz, + double * field_momentum_zx, + double * field_momentum_zy, + double * field_momentum_zz, + double * field_energy, + double * resid_density, + double * resid_momentum_x, + double * resid_momentum_y, + double * resid_momentum_z, + double * resid_energy, + double * field_temperature, + double * wk, double * dt, + double * turbAcc, + int * cello_update_sol, + int * cello_apply_injection_rate, + double * cello_injection_rate, + int * cello_cooling_term, + int * cello_apply_cooling, + double * cello_gamma, + double * cello_hc_alpha, + double * cello_hc_sigma, + double * cello_totemp, + double * r_av ); extern "C" void FORTRAN_NAME(calc_dt_ppml) (int *idim, int *jdim, int *kdim, @@ -119,4 +205,71 @@ extern "C" void FORTRAN_NAME(ppml) enzo_float *qu1,enzo_float *qu2,enzo_float *qu3,enzo_float *qu4, enzo_float *qu5,enzo_float *qu6,enzo_float *qu7); +extern "C" void FORTRAN_NAME(OUpumpInit) + ( enzo_float *gamma_, + enzo_float *density_initial_, + enzo_float *pressure_initial_, + enzo_float *solenoidal_fraction_, + enzo_float *mach_number_, + enzo_float *kfmin_, + enzo_float *kfmax_, + enzo_float *Lbox ); + +extern "C" void FORTRAN_NAME(OUpumpCompute) + ( int *rank, int *mx, int *my, int *mz, // rank and local block dimensions + int *nig, int *njg, int *nkg, // root + int *gx, int *gy, int *gz, // number of ghost zones + enzo_float *vx, // flow fields invilved + enzo_float *vy, + enzo_float *vz, + enzo_float *density, + int *ndx,int *ndy,int *ndz, // zone sizes + int *ox,int *oy,int *oz, + enzo_float *dt ); // time step + +extern "C" void FORTRAN_NAME(ppml_ig) + (enzo_float *density, + enzo_float *velox, enzo_float *veloy, enzo_float *veloz, + enzo_float *bfieldx, enzo_float *bfieldy, enzo_float *bfieldz, + enzo_float *pressure, + enzo_float *dens_rx, + enzo_float *velox_rx,enzo_float *veloy_rx,enzo_float *veloz_rx, + enzo_float *bfieldx_rx,enzo_float *bfieldy_rx,enzo_float *bfieldz_rx, + enzo_float *press_rx, + enzo_float *dens_ry, + enzo_float *velox_ry,enzo_float *veloy_ry,enzo_float *veloz_ry, + enzo_float *bfieldx_ry,enzo_float *bfieldy_ry,enzo_float *bfieldz_ry, + enzo_float *press_ry, + enzo_float *dens_rz, + enzo_float *velox_rz,enzo_float *veloy_rz,enzo_float *veloz_rz, + enzo_float *bfieldx_rz,enzo_float *bfieldy_rz,enzo_float *bfieldz_rz, + enzo_float *press_rz, + enzo_float *b0, enzo_float *gamma, + enzo_float *dt, enzo_float *hx, enzo_float *hy, enzo_float *hz, + int *mx, int *my, int *mz, + int *GridStartIndex, int *GridEndIndex, + int *NumberOfSubgrids, int *leftface, int *rightface, + int *istart, int *iend, int *jstart, int *jend, + enzo_float *standard, int *dnindex, + int *vxindex, int *vyindex, int *vzindex, + int *bxindex, int *byindex, int *bzindex, + int *pindex, + enzo_float *f1,enzo_float *f2,enzo_float *f3,enzo_float *f4, + enzo_float *f5,enzo_float *f6,enzo_float *f7,enzo_float *f8, + enzo_float *g1,enzo_float *g2,enzo_float *g3,enzo_float *g4, + enzo_float *g5,enzo_float *g6,enzo_float *g7,enzo_float *g8, + enzo_float *h1,enzo_float *h2,enzo_float *h3,enzo_float *h4, + enzo_float *h5,enzo_float *h6,enzo_float *h7,enzo_float *h8, + enzo_float *ex,enzo_float *ey,enzo_float *ez, + enzo_float *qu1,enzo_float *qu2,enzo_float *qu3,enzo_float *qu4, + enzo_float *qu5,enzo_float *qu6,enzo_float *qu7,enzo_float *qu8); + +extern "C" void FORTRAN_NAME(calc_dt_ppml_ig) + (int *idim, int *jdim, int *kdim, + int *i1, int *i2, int *j1, int *j2, int *k1, int *k2, + enzo_float *dx, enzo_float *dy, enzo_float *dz, + enzo_float *dn, enzo_float *vx, enzo_float *vy, enzo_float *vz, + enzo_float *bx, enzo_float *by, enzo_float *bz, + enzo_float *pr, enzo_float *b0, enzo_float * gamma, + enzo_float *dt); #endif /* ENZO_FORTRAN_HPP */ diff --git a/src/Enzo/enzo_reductions.hpp b/src/Enzo/enzo_reductions.hpp index 5f0b00f088..5ba07c08a3 100644 --- a/src/Enzo/enzo_reductions.hpp +++ b/src/Enzo/enzo_reductions.hpp @@ -1,5 +1,12 @@ +//extern CkReduction::reducerType r_method_turbulence_mhd_ig_type; +extern CkReduction::reducerType r_method_turbulence_mhd_it_type; extern CkReduction::reducerType r_method_turbulence_type; + +//extern CkReductionMsg * r_method_turbulence_mhd_ig(int n, CkReductionMsg ** msgs); +extern CkReductionMsg * r_method_turbulence_mhd_it(int n, CkReductionMsg ** msgs); extern CkReductionMsg * r_method_turbulence(int n, CkReductionMsg ** msgs); -extern void register_method_turbulence(void); +//extern void register_method_turbulence_mhd_ig(void); +extern void register_method_turbulence_mhd_it(void); +extern void register_method_turbulence(void); diff --git a/src/Enzo/fluid-props/EnzoComputeTemperature.hpp b/src/Enzo/fluid-props/EnzoComputeTemperature.hpp index 356acc17c5..e413f9f593 100644 --- a/src/Enzo/fluid-props/EnzoComputeTemperature.hpp +++ b/src/Enzo/fluid-props/EnzoComputeTemperature.hpp @@ -24,7 +24,7 @@ class EnzoComputeTemperature : public Compute { (double density_floor, double temperature_floor, double mol_weight, - bool comoving_coordinates); + bool comoving_coordinates = false); /// Create a new EnzoComputeTemperature object EnzoComputeTemperature(const EnzoPhysicsFluidProps* fluid_props, diff --git a/src/Enzo/gravity/EnzoMethodGravity.cpp b/src/Enzo/gravity/EnzoMethodGravity.cpp index ed7addccf7..01049eb878 100644 --- a/src/Enzo/gravity/EnzoMethodGravity.cpp +++ b/src/Enzo/gravity/EnzoMethodGravity.cpp @@ -9,7 +9,7 @@ #include "cello.hpp" #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" // #define DEBUG_COPY_B // #define DEBUG_COPY_DENSITIES diff --git a/src/Enzo/gravity/EnzoMethodPmDeposit.cpp b/src/Enzo/gravity/EnzoMethodPmDeposit.cpp index 206f89611e..1732fde05c 100644 --- a/src/Enzo/gravity/EnzoMethodPmDeposit.cpp +++ b/src/Enzo/gravity/EnzoMethodPmDeposit.cpp @@ -212,7 +212,6 @@ namespace { // define local helper functions in anonymous namespace #ifdef DEBUG_COLLAPS CkPrintf ("DEBUG_COLLAPSE vxa[0] = %lg\n",vxa[0]); #endif - for (int ip=0; ipdata()->field(); enzo_float* R0 = (enzo_float*) field.values(ir0_); @@ -1634,7 +1633,7 @@ void EnzoSolverBiCgStab::end (EnzoBlock* block, int retval) throw () { TRACE_BCG(block,this,"end"); deallocate_temporary_(block); - + Solver::end_(block); } diff --git a/src/Enzo/gravity/solvers/EnzoSolverCg.cpp b/src/Enzo/gravity/solvers/EnzoSolverCg.cpp index b2fb337c53..ee468e519e 100644 --- a/src/Enzo/gravity/solvers/EnzoSolverCg.cpp +++ b/src/Enzo/gravity/solvers/EnzoSolverCg.cpp @@ -6,7 +6,7 @@ /// @brief Implements the CG Krylov iterative linear solver #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" // #define COPY_FIELD diff --git a/src/Enzo/gravity/solvers/EnzoSolverDiagonal.cpp b/src/Enzo/gravity/solvers/EnzoSolverDiagonal.cpp index f7922af103..50781afe34 100644 --- a/src/Enzo/gravity/solvers/EnzoSolverDiagonal.cpp +++ b/src/Enzo/gravity/solvers/EnzoSolverDiagonal.cpp @@ -7,7 +7,7 @@ #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" // #define DEBUG_SOLVER diff --git a/src/Enzo/gravity/solvers/EnzoSolverMg0.cpp b/src/Enzo/gravity/solvers/EnzoSolverMg0.cpp index 1c2e42e991..21dd4bfb9f 100644 --- a/src/Enzo/gravity/solvers/EnzoSolverMg0.cpp +++ b/src/Enzo/gravity/solvers/EnzoSolverMg0.cpp @@ -103,7 +103,7 @@ #include "cello.hpp" #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" // #define DEBUG_SOLVER_CONTROL diff --git a/src/Enzo/hydro-mhd/CMakeLists.txt b/src/Enzo/hydro-mhd/CMakeLists.txt index 930d92a1e0..e54ab757e0 100644 --- a/src/Enzo/hydro-mhd/CMakeLists.txt +++ b/src/Enzo/hydro-mhd/CMakeLists.txt @@ -26,3 +26,4 @@ target_sources(enzo PRIVATE ${LOCAL_SRC_FILES}) # STEP 2: define the riemann library add_subdirectory(riemann) +add_subdirectory(ppml_ig) diff --git a/src/Enzo/hydro-mhd/EnzoMethodPpml.cpp b/src/Enzo/hydro-mhd/EnzoMethodPpml.cpp index 293cfe8523..7033a67f62 100644 --- a/src/Enzo/hydro-mhd/EnzoMethodPpml.cpp +++ b/src/Enzo/hydro-mhd/EnzoMethodPpml.cpp @@ -13,9 +13,10 @@ //---------------------------------------------------------------------- -EnzoMethodPpml::EnzoMethodPpml() +EnzoMethodPpml::EnzoMethodPpml(double dt_weight) : Method(), - comoving_coordinates_(enzo::config()->physics_cosmology) + comoving_coordinates_(enzo::config()->physics_cosmology), + dt_weight_(dt_weight) { // Initialize the default Refresh object cello::simulation()->refresh_set_name(ir_post_,name()); @@ -48,20 +49,22 @@ void EnzoMethodPpml::pup (PUP::er &p) Method::pup(p); p | comoving_coordinates_; + p | dt_weight_; } //---------------------------------------------------------------------- void EnzoMethodPpml::compute ( Block * block ) throw() { + if (block->is_leaf()) { - if (!block->is_leaf()) return; + EnzoBlock * enzo_block = enzo::block(block); + double dt = dt_weight_ * block->dt(); + enzo_block->SolveMHDEquations ( dt ); - EnzoBlock * enzo_block = enzo::block(block); - - enzo_block->SolveMHDEquations ( block->dt() ); + } - enzo_block->compute_done(); + block->compute_done(); } @@ -69,7 +72,6 @@ void EnzoMethodPpml::compute ( Block * block ) throw() double EnzoMethodPpml::timestep (Block * block) throw() { - EnzoBlock * enzo_block = enzo::block(block); /* initialize */ @@ -149,22 +151,22 @@ double EnzoMethodPpml::timestep (Block * block) throw() enzo_float * bz = (enzo_float *) field.values("bfieldz"); FORTRAN_NAME(calc_dt_ppml) - (enzo_block->GridDimension, - enzo_block->GridDimension+1, - enzo_block->GridDimension+2, - enzo_block->GridStartIndex, - enzo_block->GridEndIndex, - enzo_block->GridStartIndex+1, - enzo_block->GridEndIndex+1, - enzo_block->GridStartIndex+2, - enzo_block->GridEndIndex+2, - &enzo_block->CellWidth[0], - &enzo_block->CellWidth[1], - &enzo_block->CellWidth[2], - d, - vx, vy, vz, - bx, by, bz, - &dtBaryons); + (enzo_block->GridDimension, // ( ) + enzo_block->GridDimension+1, // ( ) + enzo_block->GridDimension+2, // ( ) + enzo_block->GridStartIndex, // ( ) + enzo_block->GridEndIndex, // ( ) + enzo_block->GridStartIndex+1, // ( ) + enzo_block->GridEndIndex+1, // ( ) + enzo_block->GridStartIndex+2, // ( ) + enzo_block->GridEndIndex+2, // ( ) + &enzo_block->CellWidth[0], // ( ) + &enzo_block->CellWidth[1], // ( ) + &enzo_block->CellWidth[2], // ( ) + d, // ( ) + vx, vy, vz, // ( ) + bx, by, bz, // ( ) + &dtBaryons); // ( ) /* Multiply resulting dt by CourantSafetyNumber (for extra safety!). */ dtBaryons *= courant_; @@ -177,7 +179,6 @@ double EnzoMethodPpml::timestep (Block * block) throw() dt = MIN(dt, dtBaryons); - return dt; } diff --git a/src/Enzo/hydro-mhd/EnzoMethodPpml.hpp b/src/Enzo/hydro-mhd/EnzoMethodPpml.hpp index e4cb85b3f8..3106d0d5e7 100644 --- a/src/Enzo/hydro-mhd/EnzoMethodPpml.hpp +++ b/src/Enzo/hydro-mhd/EnzoMethodPpml.hpp @@ -17,7 +17,7 @@ class EnzoMethodPpml : public Method { public: // interface /// Creae a new EnzoMethodPpml object - EnzoMethodPpml(); + EnzoMethodPpml(double dt_weight); /// Charm++ PUP::able declarations PUPable_decl(EnzoMethodPpml); @@ -25,7 +25,8 @@ class EnzoMethodPpml : public Method { /// Charm++ PUP::able migration constructor EnzoMethodPpml (CkMigrateMessage *m) : Method (m), - comoving_coordinates_(false) + comoving_coordinates_(false), + dt_weight_(1.0) {} /// CHARM++ Pack / Unpack function @@ -43,6 +44,7 @@ class EnzoMethodPpml : public Method { protected: // interface bool comoving_coordinates_; + double dt_weight_; }; #endif /* ENZO_ENZO_METHOD_PPML_HPP */ diff --git a/src/Enzo/hydro-mhd/SolveMHDEquations.cpp b/src/Enzo/hydro-mhd/SolveMHDEquations.cpp index 2fa7daed7b..24f46e846d 100644 --- a/src/Enzo/hydro-mhd/SolveMHDEquations.cpp +++ b/src/Enzo/hydro-mhd/SolveMHDEquations.cpp @@ -21,6 +21,38 @@ #include "enzo.hpp" +// #define DEBUG_FIELDS + +#ifdef DEBUG_FIELDS +# define CHECK_FIELD(VALUES,NAME) \ + ASSERT1("CHECK_FIELD", \ + "Field %s must be defined", \ + NAME, \ + (VALUES != nullptr)); + +# define FIELD_STATS(NAME,VALUES,mx,my,mz,gx,gy,gz) \ + { \ + double avg=0.0, max=-1.0, min=1e9; \ + int count=0; \ + for (int iz=gz; izLeftFluxEndGlobalIndex[dim][j] - -// SubgridFluxes[i]->LeftFluxStartGlobalIndex[dim][j] + 1; - -// /* set unused dims (for the solver, which is hardwired for 3d). */ - -// for (j = GridRank; j < 3; j++) { -// SubgridFluxes[i]->LeftFluxStartGlobalIndex[dim][j] = 0; -// SubgridFluxes[i]->LeftFluxEndGlobalIndex[dim][j] = 0; -// SubgridFluxes[i]->RightFluxStartGlobalIndex[dim][j] = 0; -// SubgridFluxes[i]->RightFluxEndGlobalIndex[dim][j] = 0; -// } - -// /* Allocate space (if necessary). */ - -// for (field = 0; field < NumberOfBaryonFields; field++) { -// if (SubgridFluxes[i]->LeftFluxes[field][dim] == NULL) -// SubgridFluxes[i]->LeftFluxes[field][dim] = new enzo_float[size]; -// if (SubgridFluxes[i]->RightFluxes[field][dim] == NULL) -// SubgridFluxes[i]->RightFluxes[field][dim] = new enzo_float[size]; -// for (n = 0; n < size; n++) { -// SubgridFluxes[i]->LeftFluxes[field][dim][n] = 0; -// SubgridFluxes[i]->RightFluxes[field][dim][n] = 0; -// } -// } - -// for (field = NumberOfBaryonFields; field < MAX_NUMBER_OF_BARYON_FIELDS; -// field++) { -// SubgridFluxes[i]->LeftFluxes[field][dim] = NULL; -// SubgridFluxes[i]->RightFluxes[field][dim] = NULL; -// } - -// } // next dimension - -// /* make things pretty */ - -// for (dim = GridRank; dim < 3; dim++) -// for (field = 0; field < MAX_NUMBER_OF_BARYON_FIELDS; field++) { -// SubgridFluxes[i]->LeftFluxes[field][dim] = NULL; -// SubgridFluxes[i]->RightFluxes[field][dim] = NULL; -// } - -// } // end of loop over subgrids + CHECK_FIELD(density,"density"); + CHECK_FIELD(velox,"velox"); + CHECK_FIELD(veloy,"veloy"); + CHECK_FIELD(veloz,"veloz"); + CHECK_FIELD(bfieldx,"bfieldx"); + CHECK_FIELD(bfieldy,"bfieldy"); + CHECK_FIELD(bfieldz,"bfieldz"); + CHECK_FIELD(dens_rx,"dens_rx"); + CHECK_FIELD(velox_rx,"velox_rx"); + CHECK_FIELD(veloy_rx,"veloy_rx"); + CHECK_FIELD(veloz_rx,"veloz_rx"); + CHECK_FIELD(bfieldx_rx,"bfieldx_rx"); + CHECK_FIELD(bfieldy_rx,"bfieldy_rx"); + CHECK_FIELD(bfieldz_rx,"bfieldz_rx"); + CHECK_FIELD(dens_ry,"dens_ry"); + CHECK_FIELD(velox_ry,"velox_ry"); + CHECK_FIELD(veloy_ry,"veloy_ry"); + CHECK_FIELD(veloz_ry,"veloz_ry"); + CHECK_FIELD(bfieldx_ry,"bfieldx_ry"); + CHECK_FIELD(bfieldy_ry,"bfieldy_ry"); + CHECK_FIELD(bfieldz_ry,"bfieldz_ry"); + CHECK_FIELD(dens_rz,"dens_rz"); + CHECK_FIELD(velox_rz,"velox_rz"); + CHECK_FIELD(veloy_rz,"veloy_rz"); + CHECK_FIELD(veloz_rz,"veloz_rz"); + CHECK_FIELD(bfieldx_rz,"bfieldx_rz"); + CHECK_FIELD(bfieldy_rz,"bfieldy_rz"); + CHECK_FIELD(bfieldz_rz,"bfieldz_rz"); /* compute global start index for left edge of entire grid (including boundary zones) */ @@ -328,27 +338,50 @@ int EnzoBlock::SolveMHDEquations( enzo_float dt ) /* note: Start/EndIndex are zero based */ - /* current PPML implementation only supports 3D and does not support color fields */ - - FORTRAN_NAME(ppml) - (density,velox, veloy, veloz, bfieldx, bfieldy, bfieldz, - dens_rx,velox_rx,veloy_rx,veloz_rx,bfieldx_rx,bfieldy_rx,bfieldz_rx, - dens_ry,velox_ry,veloy_ry,veloz_ry,bfieldx_ry,bfieldy_ry,bfieldz_ry, - dens_rz,velox_rz,veloy_rz,veloz_rz,bfieldx_rz,bfieldy_rz,bfieldz_rz, - &dt, &CellWidthTemp[0], &CellWidthTemp[1], &CellWidthTemp[2], - &GridDimension[0], &GridDimension[1], &GridDimension[2], - GridStartIndex, GridEndIndex, - &NumberOfSubgrids, leftface, rightface, - istart, iend, jstart, jend, - standard, dnindex, - vxindex, vyindex, vzindex, - bxindex, byindex, bzindex, - f1,f2,f3,f4,f5,f6,f7, - g1,g2,g3,g4,g5,g6,g7, - h1,h2,h3,h4,h5,h6,h7, - ex,ey,ez, - qu1,qu2,qu3,qu4,qu5,qu6,qu7); + /* current PPML implementation only supports 3D and does not + support color fields */ + + enzo_float *velocity_x = (enzo_float *) field.values ("velocity_x"); + enzo_float *velocity_y = (enzo_float *) field.values ("velocity_y"); + enzo_float *velocity_z = (enzo_float *) field.values ("velocity_z"); + bool have_velocity = (velocity_x != nullptr); + + int mx,my,mz; + field.dimensions(0,&mx,&my,&mz); + const int m = mx*my*mz; + + if (have_velocity) { + std::copy_n(velocity_x,m,velox); + std::copy_n(velocity_y,m,veloy); + std::copy_n(velocity_z,m,veloz); + } + + FORTRAN_NAME(ppml) + (density,velox, veloy, veloz, bfieldx, bfieldy, bfieldz, + dens_rx,velox_rx,veloy_rx,veloz_rx,bfieldx_rx,bfieldy_rx,bfieldz_rx, + dens_ry,velox_ry,veloy_ry,veloz_ry,bfieldx_ry,bfieldy_ry,bfieldz_ry, + dens_rz,velox_rz,veloy_rz,veloz_rz,bfieldx_rz,bfieldy_rz,bfieldz_rz, + &dt, &CellWidthTemp[0], &CellWidthTemp[1], &CellWidthTemp[2], + &GridDimension[0], &GridDimension[1], &GridDimension[2], + GridStartIndex, GridEndIndex, + &NumberOfSubgrids, leftface, rightface, + istart, iend, jstart, jend, + standard, dnindex, + vxindex, vyindex, vzindex, + bxindex, byindex, bzindex, + f1,f2,f3,f4,f5,f6,f7, + g1,g2,g3,g4,g5,g6,g7, + h1,h2,h3,h4,h5,h6,h7, + ex,ey,ez, + qu1,qu2,qu3,qu4,qu5,qu6,qu7); + /* deallocate temporary space for solver */ + + if (have_velocity) { + std::copy_n(velox,m,velocity_x); + std::copy_n(veloy,m,velocity_y); + std::copy_n(veloz,m,velocity_z); + } delete [] temp; diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_Conservative.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_Conservative.F index 1166a2d99a..ee1ac22fde 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_Conservative.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_Conservative.F @@ -1,33 +1,33 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine Conserv(nx,ny,nz,dn,vx,vy,vz,bx,by,bz, - & qu1,qu2,qu3,qu4,qu5,qu6,qu7) - Implicit NONE - - Integer nx,ny,nz,i,j,k - ENZO_REAL dn(nx,ny,nz) - ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) - ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) - - ENZO_REAL qu1(nx,ny,nz) - ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) - ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) - - Do k=1,nz - Do j=1,ny - Do i=1,nx - QU1(i,j,k)=dn(i,j,k) - QU2(i,j,k)=dn(i,j,k)*vx(i,j,k) - QU3(i,j,k)=dn(i,j,k)*vy(i,j,k) - QU4(i,j,k)=dn(i,j,k)*vz(i,j,k) - QU5(i,j,k)=bx(i,j,k) - QU6(i,j,k)=by(i,j,k) - QU7(i,j,k)=bz(i,j,k) - Enddo - Enddo - Enddo - - RETURN - END +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine Conserv(nx,ny,nz,dn,vx,vy,vz,bx,by,bz, + & qu1,qu2,qu3,qu4,qu5,qu6,qu7) + Implicit NONE + + Integer nx,ny,nz,i,j,k + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + + ENZO_REAL qu1(nx,ny,nz) + ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) + ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) + + Do k=1,nz + Do j=1,ny + Do i=1,nx + QU1(i,j,k)=dn(i,j,k) + QU2(i,j,k)=dn(i,j,k)*vx(i,j,k) + QU3(i,j,k)=dn(i,j,k)*vy(i,j,k) + QU4(i,j,k)=dn(i,j,k)*vz(i,j,k) + QU5(i,j,k)=bx(i,j,k) + QU6(i,j,k)=by(i,j,k) + QU7(i,j,k)=bz(i,j,k) + Enddo + Enddo + Enddo + + RETURN + END diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_HLLD.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_HLLD.F index 50dbe06f8c..7ac7e679c1 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_HLLD.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_HLLD.F @@ -1,697 +1,697 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine HLLDx(UL,UR,F,U) !SL and SR from min/max - Implicit NONE - - ENZO_REAL U(7),F(7),UL(7),UR(7) - - Integer i - ENZO_REAL Uhll(7),Fhll(7) - ENZO_REAL FL(7),FR(7) - ENZO_REAL SL,SR,SL_rot,SR_rot - ENZO_REAL cf,ca ! fast and Alfven velocities - ENZO_REAL Bx,By,Bz,BB - ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R - ENZO_REAL ptL, ptR - ENZO_REAL u_ast - ENZO_REAL UL_ast(7),UR_ast(7) - -!temporary - ENZO_REAL f2,f3,X,g3,g4,g5,g6 - ENZO_REAL S1L, S1R, S2L, S2R - ENZO_REAL a,a1,a2,ds - - - ENZO_REAL one - parameter(one = 1.0) - - a1=1. - a2=1. - - a=a1 - - u_L=UL(2)/UL(1) - v_L=UL(3)/UL(1) - w_L=UL(4)/UL(1) - - u_R=UR(2)/UR(1) - v_R=UR(3)/UR(1) - w_R=UR(4)/UR (1) - - Bx=(Ul(5)+Ur(5))/2.e0 - - By=UL(6) - Bz=UL(7) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(Bx)/sqrt(UL(1)) - f2=a*a+BB/UL(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - ptL=a*a*UL(1)+BB/2.e0 - - S1L=u_L-cf - S1R=u_L+cf - - By=UR(6) - Bz=UR(7) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(Bx)/sqrt(UR(1)) - f2=a*a+BB/UR(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - - ptR=a*a*UR(1)+BB/2.e0 - - S2L=u_R-cf - S2R=u_R+cf - - SL=min(S1L,S2L) - SR=max(S1R,S2R) - - if (SL.ge.0.) then - - F(1)=UL(2) - F(2)=UL(2)*u_L+ptL-Ul(5)*Ul(5) - F(3)=UL(3)*u_L-Ul(5)*Ul(6) - F(4)=UL(4)*u_L-Ul(5)*Ul(7) - F(5)=0. - F(6)=UL(6)*u_L-Ul(5)*v_L - F(7)=UL(7)*u_L-Ul(5)*w_L - - U(1)=UL(1) - U(2)=UL(2) - U(3)=UL(3) - U(4)=UL(4) - U(5)=UL(5) - U(6)=UL(6) - U(7)=UL(7) - - goto 8888 - endif - - if (SR.le.0.) then - F(1)=UR(2) - F(2)=UR(2)*u_R+ptR-Ur(5)*Ur(5) - F(3)=UR(3)*u_R-Ur(5)*Ur(6) - F(4)=UR(4)*u_R-Ur(5)*Ur(7) - F(5)=0. - F(6)=UR(6)*u_R-Ur(5)*v_R - F(7)=UR(7)*u_R-Ur(5)*w_R - U(1)=UR(1) - U(2)=UR(2) - U(3)=UR(3) - U(4)=UR(4) - U(5)=UR(5) - U(6)=UR(6) - U(7)=UR(7) - goto 8888 - endif - - Fl(1)=UL(2) - Fl(2)=UL(2)*u_L+ptL-Ul(5)*Ul(5) - Fl(3)=UL(3)*u_L-Ul(5)*Ul(6) - Fl(4)=UL(4)*u_L-Ul(5)*Ul(7) - Fl(5)=0. - Fl(6)=UL(6)*u_L-Ul(5)*v_L - Fl(7)=UL(7)*u_L-Ul(5)*w_L - - Fr(1)=UR(2) - Fr(2)=UR(2)*u_R+ptR-Ur(5)*Ur(5) - Fr(3)=UR(3)*u_R-Ur(5)*Ur(6) - Fr(4)=UR(4)*u_R-Ur(5)*Ur(7) - Fr(5)=0. - Fr(6)=UR(6)*u_R-Ur(5)*v_R - Fr(7)=UR(7)*u_R-Ur(5)*w_R - - Do i=1,7 - Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) - Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) - enddo - - u_ast=Fhll(1)/Uhll(1) - ca=abs(Bx)/sqrt(Uhll(1)) - - SL_rot=u_ast-ca - SR_rot=u_ast+ca - - UL_ast(1)=Uhll(1) - UL_ast(2)=Uhll(2) - - f3=(SL-SL_rot)*(SL-SR_rot) - - if (f3.ne.0.) then - UL_ast(3)=Uhll(1)*v_L-Bx*UL(6)*(u_ast-u_L)/f3 - UL_ast(4)=Uhll(1)*w_L-Bx*UL(7)*(u_ast-u_L)/f3 - Ul_ast(5)=bx - UL_ast(6)=UL(6)*(UL(1)*((SL-u_L)**2)-Bx*Bx)/Uhll(1)/f3 - UL_ast(7)=UL(7)*(UL(1)*((SL-u_L)**2)-Bx*Bx)/Uhll(1)/f3 - else - UL_ast(3)=UL(3) - UL_ast(4)=UL(4) - Ul_ast(5)=bx - UL_ast(6)=UL(6) - UL_ast(7)=UL(7) - endif - - if ((SL.lt.0.).and.(0.le.SL_rot)) then - Do i=1,7 - F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) - U(i)=UL_ast(i) - enddo - goto 8888 - endif - - UR_ast(1)=Uhll(1) - UR_ast(2)=Uhll(2) - - f3=(SR-SL_rot)*(SR-SR_rot) - - if (f3.ne.0.) then - UR_ast(3)=Uhll(1)*v_R-Bx*UR(6)*(u_ast-u_R)/f3 - UR_ast(4)=Uhll(1)*w_R-Bx*UR(7)*(u_ast-u_R)/f3 - UR_ast(5)=bx - UR_ast(6)=UR(6)*(UR(1)*((SR-u_R)**2)-Bx*Bx)/Uhll(1)/f3 - UR_ast(7)=UR(7)*(UR(1)*((SR-u_R)**2)-Bx*Bx)/Uhll(1)/f3 - else - UR_ast(3)=UR(3) - UR_ast(4)=UR(4) - UR_ast(5)=bx - UR_ast(6)=UR(6) - UR_ast(7)=UR(7) - endif - - if ((SR_rot.lt.0.).and.(0.le.SR)) then - Do i=1,7 - F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) - U(i)=UR_ast(i) - enddo - goto 8888 - endif - - X=sqrt(Uhll(1))*sign(one,Bx) - - g3=(UL_ast(3)+UR_ast(3)+X*(UR_ast(6)-UL_ast(6)))/2.e0 - g4=(UL_ast(4)+UR_ast(4)+X*(UR_ast(7)-UL_ast(7)))/2.e0 - g5=(UL_ast(6)+UR_ast(6)+(UR_ast(3)-UL_ast(3))/X)/2.e0 - g6=(UL_ast(7)+UR_ast(7)+(UR_ast(4)-UL_ast(4))/X)/2.e0 - - - F(1)=Fhll(1) - F(2)=Fhll(2) - F(3)=g3*u_ast-Bx*g5 - F(4)=g4*u_ast-Bx*g6 - F(5)=0. - F(6)=g5*u_ast-Bx*g3/uhll(1) - F(7)=g6*u_ast-Bx*g4/uhll(1) - - U(1)=Uhll(1) - U(2)=Uhll(2) - U(3)=g3 - U(4)=g4 - U(5)=bx - U(6)=g5 - U(7)=g6 - -c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then -c ERROR_MESSAGE - -c print*,'Error in HLLDS procedure! Press any key.' -c pause -c endif - - 8888 continue - -c print*,'hlld finished' -c pause - - End ! Subroutine HLLDx - - Subroutine HLLDy(UL,UR,F,U) !SL and SR from min/max - - ENZO_REAL U(7),F(7),UL(7),UR(7) - - Integer i - ENZO_REAL Uhll(7),Fhll(7) - ENZO_REAL FL(7),FR(7) - ENZO_REAL SL,SR,SL_rot,SR_rot - ENZO_REAL cf,ca ! fast and Alfven velocities - ENZO_REAL Bx,By,Bz,BB - ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R - ENZO_REAL ptL, ptR - ENZO_REAL u_ast - ENZO_REAL UL_ast(7),UR_ast(7) - -!temporary - ENZO_REAL f2,f3,X,g2,g4,g5,g7 - ENZO_REAL S1L, S1R, S2L, S2R - ENZO_REAL a,a1,a2,ds - - - ENZO_REAL one - parameter(one = 1.0) - -! bug common/aspd/a1,a2 - a1=1. - a2=1. - - a=a1 - - u_L=UL(2)/UL(1) - v_L=UL(3)/UL(1) - w_L=UL(4)/UL(1) - - u_R=UR(2)/UR(1) - v_R=UR(3)/UR(1) - w_R=UR(4)/UR(1) - - By=(Ul(6)+Ur(6))/2.e0 - - Bx=UL(5) - Bz=UL(7) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(By)/sqrt(UL(1)) - f2=a*a+BB/UL(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - ptL=a*a*UL(1)+BB/2.e0 - - S1L=v_L-cf - S1R=v_L+cf - - Bx=UR(5) - Bz=UR(7) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(By)/sqrt(UR(1)) - f2=a*a+BB/UR(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - ptR=a*a*UR(1)+BB/2.e0 - - S2L=v_R-cf - S2R=v_R+cf - - SL=min(S1L,S2L) - SR=max(S1R,S2R) - - if (SL.ge.0.) then - - F(1)=UL(3) - F(2)=UL(2)*v_L-Ul(5)*Ul(6) - F(3)=UL(3)*v_L+ptl-Ul(6)*Ul(6) - F(4)=UL(4)*v_L-Ul(6)*Ul(7) - F(5)=UL(5)*v_L-Ul(6)*u_L - F(6)=0. - F(7)=UL(7)*v_L-Ul(6)*w_L - - U(1)=UL(1) - U(2)=UL(2) - U(3)=UL(3) - U(4)=UL(4) - U(5)=UL(5) - U(6)=UL(6) - U(7)=UL(7) - - goto 7777 - endif - - if (SR.le.0.) then - - F(1)=UR(3) - F(2)=UR(2)*v_R-Ur(5)*UR(6) - F(3)=UR(3)*v_R+ptR-UR(6)*UR(6) - F(4)=UR(4)*v_R-UR(6)*UR(7) - F(5)=UR(5)*v_R-UR(6)*u_R - F(6)=0. - F(7)=UR(7)*v_R-UR(6)*w_R - - U(1)=UR(1) - U(2)=UR(2) - U(3)=UR(3) - U(4)=UR(4) - U(5)=UR(5) - U(6)=UR(6) - U(7)=UR(7) - - goto 7777 - endif - - Fl(1)=UL(3) - Fl(2)=UL(2)*v_L-Ul(5)*Ul(6) - Fl(3)=UL(3)*v_L+ptl-Ul(6)*Ul(6) - Fl(4)=UL(4)*v_L-Ul(6)*Ul(7) - Fl(5)=UL(5)*v_L-Ul(6)*u_L - Fl(6)=0. - Fl(7)=UL(7)*v_L-Ul(6)*w_L - - Fr(1)=UR(3) - Fr(2)=UR(2)*v_R-UR(5)*UR(6) - Fr(3)=UR(3)*v_R+ptR-UR(6)*UR(6) - Fr(4)=UR(4)*v_R-UR(6)*UR(7) - Fr(5)=UR(5)*v_R-UR(6)*u_R - Fr(6)=0. - Fr(7)=UR(7)*v_R-UR(6)*w_R - - Do i=1,7 - Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) - Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) - enddo - - u_ast=Fhll(1)/Uhll(1) - ca=abs(By)/sqrt(Uhll(1)) - - SL_rot=u_ast-ca - SR_rot=u_ast+ca - - UL_ast(1)=Uhll(1) - UL_ast(3)=Uhll(3) - - f3=(SL-SL_rot)*(SL-SR_rot) - - if (f3.ne.0.) then - UL_ast(2)=Uhll(1)*u_L-By*UL(5)*(u_ast-v_L)/f3 - UL_ast(4)=Uhll(1)*w_L-By*UL(7)*(u_ast-v_L)/f3 - UL_ast(5)=UL(5)*(UL(1)*((SL-v_L)**2)-By*By)/Uhll(1)/f3 - UL_ast(6)=by - UL_ast(7)=UL(7)*(UL(1)*((SL-v_L)**2)-By*By)/Uhll(1)/f3 - else - UL_ast(2)=UL(2) - UL_ast(4)=UL(4) - UL_ast(5)=UL(5) - UL_ast(6)=by - UL_ast(7)=UL(7) - endif - - if ((SL.lt.0.).and.(0.le.SL_rot)) then - Do i=1,7 - F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) - U(i)=UL_ast(i) - enddo - goto 7777 - endif - - UR_ast(1)=Uhll(1) - UR_ast(3)=Uhll(3) - - f3=(SR-SL_rot)*(SR-SR_rot) - - if (f3.ne.0.) then - UR_ast(2)=Uhll(1)*u_R-By*UR(5)*(u_ast-v_R)/f3 - UR_ast(4)=Uhll(1)*w_R-By*UR(7)*(u_ast-v_R)/f3 - UR_ast(5)=UR(5)*(UR(1)*((SR-v_R)**2)-By*By)/Uhll(1)/f3 - UR_ast(6)=by - UR_ast(7)=UR(7)*(UR(1)*((SR-v_R)**2)-By*By)/Uhll(1)/f3 - else - UR_ast(2)=UR(2) - UR_ast(4)=UR(4) - UR_ast(5)=UR(5) - UR_ast(6)=by - UR_ast(7)=UR(7) - endif - - if ((SR_rot.lt.0.).and.(0.le.SR)) then - Do i=1,7 - F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) - U(i)=UR_ast(i) - enddo - goto 7777 - endif - - X=sqrt(Uhll(1))*sign(one,By) - - g2=(UL_ast(2)+UR_ast(2)+X*(UR_ast(5)-UL_ast(5)))/2.e0 - g4=(UL_ast(4)+UR_ast(4)+X*(UR_ast(7)-UL_ast(7)))/2.e0 - g5=(UL_ast(5)+UR_ast(5)+(UR_ast(2)-UL_ast(2))/X)/2.e0 - g7=(UL_ast(7)+UR_ast(7)+(UR_ast(4)-UL_ast(4))/X)/2.e0 - - F(1)=Fhll(1) - F(2)=g2*u_ast-By*g5 - F(3)=Fhll(3) - F(4)=g4*u_ast-By*g7 - F(5)=g5*u_ast-By*g2/uhll(1) - F(6)=0. - F(7)=g7*u_ast-By*g4/uhll(1) - - U(1)=Uhll(1) - U(2)=g2 - U(3)=Uhll(3) - U(4)=g4 - U(5)=g5 - U(6)=by - U(7)=g7 - -c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then -c ERROR_MESSAGE - -c print*,'Error in HLLDS procedure! Press any key.' -c pause -c endif - -7777 continue - -c print*,'hlld finished' -c pause - - End ! Subroutine HLLDy - - - Subroutine HLLDz(UL,UR,F,U) !SL and SR from min/max - - ENZO_REAL U(7),F(7),UL(7),UR(7) - - Integer i - ENZO_REAL Uhll(7),Fhll(7) - ENZO_REAL FL(7),FR(7) - ENZO_REAL SL,SR,SL_rot,SR_rot - ENZO_REAL cf,ca ! fast and Alfven velocities - ENZO_REAL Bx,By,Bz,BB - ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R - ENZO_REAL ptL, ptR - ENZO_REAL u_ast - ENZO_REAL UL_ast(7),UR_ast(7) - - !temporary - ENZO_REAL f2,f3,X,g2,g3,g5,g6 - ENZO_REAL S1L, S1R, S2L, S2R - ENZO_REAL a,a1,a2,ds - - ENZO_REAL one - parameter(one = 1.0) - -!bug common/aspd/a1,a2 - a1=1. - a2=1. - - a=a1 - - u_L=UL(2)/UL(1) - v_L=UL(3)/UL(1) - w_L=UL(4)/UL(1) - - u_R=UR(2)/UR(1) - v_R=UR(3)/UR(1) - w_R=UR(4)/UR(1) - - Bz=(Ul(7)+Ur(7))/2.e0 - - Bx=UL(5) - By=UL(6) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(Bz)/sqrt(UL(1)) - f2=a*a+BB/UL(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - ptL=a*a*UL(1)+BB/2.e0 - - S1L=w_L-cf - S1R=w_L+cf - - Bx=UR(5) - By=UR(6) - - BB=Bx*Bx+By*By+Bz*Bz - ca=abs(Bz)/sqrt(UR(1)) - f2=a*a+BB/UR(1) - ds=f2*f2-4.e0*a*a*ca*ca - if(ds.lt.0.) ds=0. - cf=sqrt(0.5e0*(f2+sqrt(ds))) - - ptR=a*a*UR(1)+BB/2.e0 - - S2L=w_R-cf - S2R=w_R+cf - - SL=min(S1L,S2L) - SR=max(S1R,S2R) - - if (SL.ge.0.) then - - F(1)=UL(4) - F(2)=UL(2)*w_L-Ul(5)*Ul(7) - F(3)=UL(3)*w_L-Ul(6)*Ul(7) - F(4)=UL(4)*w_L+ptl-Ul(7)*Ul(7) - F(5)=UL(5)*w_L-Ul(7)*u_L - F(6)=UL(6)*w_L-Ul(7)*v_L - F(7)=0. - - U(1)=UL(1) - U(2)=UL(2) - U(3)=UL(3) - U(4)=UL(4) - U(5)=UL(5) - U(6)=UL(6) - U(7)=UL(7) - - goto 6666 - endif - - if (SR.le.0.) then - - F(1)=UR(4) - F(2)=UR(2)*w_R-UR(5)*UR(7) - F(3)=UR(3)*w_R-UR(6)*UR(7) - F(4)=UR(4)*w_R+ptR-UR(7)*UR(7) - F(5)=UR(5)*w_R-UR(7)*u_R - F(6)=UR(6)*w_R-UR(7)*v_R - F(7)=0. - - U(1)=UR(1) - U(2)=UR(2) - U(3)=UR(3) - U(4)=UR(4) - U(5)=UR(5) - U(6)=UR(6) - U(7)=UR(7) - - goto 6666 - endif - - Fl(1)=UL(4) - Fl(2)=UL(2)*w_L-Ul(5)*Ul(7) - Fl(3)=UL(3)*w_L-Ul(6)*Ul(7) - Fl(4)=UL(4)*w_L+ptl-Ul(7)*Ul(7) - Fl(5)=UL(5)*w_L-Ul(7)*u_L - Fl(6)=UL(6)*w_L-Ul(7)*v_L - Fl(7)=0. - - Fr(1)=UR(4) - Fr(2)=UR(2)*w_R-UR(5)*UR(7) - Fr(3)=UR(3)*w_R-UR(6)*UR(7) - Fr(4)=UR(4)*w_R+ptR-UR(7)*UR(7) - Fr(5)=UR(5)*w_R-UR(7)*u_R - Fr(6)=UR(6)*w_R-UR(7)*v_R - Fr(7)=0. - - Do i=1,7 - Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) - Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) - enddo - - u_ast=Fhll(1)/Uhll(1) - ca=abs(Bz)/sqrt(Uhll(1)) - - SL_rot=u_ast-ca - SR_rot=u_ast+ca - - UL_ast(1)=Uhll(1) - UL_ast(4)=Uhll(4) - - f3=(SL-SL_rot)*(SL-SR_rot) - - if (f3.ne.0.) then - UL_ast(2)=Uhll(1)*u_L-Bz*UL(5)*(u_ast-w_L)/f3 - UL_ast(3)=Uhll(1)*v_L-Bz*UL(6)*(u_ast-w_L)/f3 - UL_ast(5)=UL(5)*(UL(1)*((SL-w_L)**2)-Bz*Bz)/Uhll(1)/f3 - UL_ast(6)=UL(6)*(UL(1)*((SL-w_L)**2)-Bz*Bz)/Uhll(1)/f3 - Ul_ast(7)=bz - else - UL_ast(2)=UL(2) - UL_ast(3)=UL(3) - UL_ast(5)=UL(5) - UL_ast(6)=UL(6) - Ul_ast(7)=bz - endif - - if ((SL.lt.0.).and.(0.le.SL_rot)) then - Do i=1,7 - F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) - U(i)=UL_ast(i) - enddo - goto 6666 - endif - - UR_ast(1)=Uhll(1) - UR_ast(4)=Uhll(4) - - f3=(SR-SL_rot)*(SR-SR_rot) - - if (f3.ne.0.) then - UR_ast(2)=Uhll(1)*u_R-Bz*UR(5)*(u_ast-w_R)/f3 - UR_ast(3)=Uhll(1)*v_R-Bz*UR(6)*(u_ast-w_R)/f3 - UR_ast(5)=UR(5)*(UR(1)*((SR-w_R)**2)-Bz*Bz)/Uhll(1)/f3 - UR_ast(6)=UR(6)*(UR(1)*((SR-w_R)**2)-Bz*Bz)/Uhll(1)/f3 - UR_ast(7)=bz - else - UR_ast(2)=UR(2) - UR_ast(3)=UR(3) - UR_ast(5)=UR(5) - UR_ast(6)=UR(6) - UR_ast(7)=bz - endif - - if ((SR_rot.lt.0.).and.(0.le.SR)) then - Do i=1,7 - F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) - U(i)=UR_ast(i) - enddo - goto 6666 - endif - - X=sqrt(Uhll(1))*sign(one,Bz) - - g2=(UL_ast(2)+UR_ast(2)+X*(UR_ast(5)-UL_ast(5)))/2.e0 - g3=(UL_ast(3)+UR_ast(3)+X*(UR_ast(6)-UL_ast(6)))/2.e0 - g5=(UL_ast(5)+UR_ast(5)+(UR_ast(2)-UL_ast(2))/X)/2.e0 - g6=(UL_ast(6)+UR_ast(6)+(UR_ast(3)-UL_ast(3))/X)/2.e0 - - - F(1)=Fhll(1) - F(2)=g2*u_ast-Bz*g5 - F(3)=g3*u_ast-Bz*g6 - F(4)=Fhll(4) - F(5)=g5*u_ast-Bz*g2/uhll(1) - F(6)=g6*u_ast-Bz*g3/uhll(1) - F(7)=0. - - U(1)=Uhll(1) - U(2)=g2 - U(3)=g3 - U(4)=Uhll(4) - U(5)=g5 - U(6)=g6 - U(7)=bz - -c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then -c ERROR_MESSAGE - -c print*,'Error in HLLDS procedure! Press any key.' -c pause -c endif - -6666 continue - -c print*,'hlld finished' -c pause - - End ! Subroutine HLLDz +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine HLLDx(UL,UR,F,U) !SL and SR from min/max + Implicit NONE + + ENZO_REAL U(7),F(7),UL(7),UR(7) + + Integer i + ENZO_REAL Uhll(7),Fhll(7) + ENZO_REAL FL(7),FR(7) + ENZO_REAL SL,SR,SL_rot,SR_rot + ENZO_REAL cf,ca ! fast and Alfven velocities + ENZO_REAL Bx,By,Bz,BB + ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R + ENZO_REAL ptL, ptR + ENZO_REAL u_ast + ENZO_REAL UL_ast(7),UR_ast(7) + +!temporary + ENZO_REAL f2,f3,X,g3,g4,g5,g6 + ENZO_REAL S1L, S1R, S2L, S2R + ENZO_REAL a,a1,a2,ds + + + ENZO_REAL one + parameter(one = 1.0) + + a1=1. + a2=1. + + a=a1 + + u_L=UL(2)/UL(1) + v_L=UL(3)/UL(1) + w_L=UL(4)/UL(1) + + u_R=UR(2)/UR(1) + v_R=UR(3)/UR(1) + w_R=UR(4)/UR (1) + + Bx=(Ul(5)+Ur(5))/2.e0 + + By=UL(6) + Bz=UL(7) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(Bx)/sqrt(UL(1)) + f2=a*a+BB/UL(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + ptL=a*a*UL(1)+BB/2.e0 + + S1L=u_L-cf + S1R=u_L+cf + + By=UR(6) + Bz=UR(7) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(Bx)/sqrt(UR(1)) + f2=a*a+BB/UR(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + + ptR=a*a*UR(1)+BB/2.e0 + + S2L=u_R-cf + S2R=u_R+cf + + SL=min(S1L,S2L) + SR=max(S1R,S2R) + + if (SL.ge.0.) then + + F(1)=UL(2) + F(2)=UL(2)*u_L+ptL-Ul(5)*Ul(5) + F(3)=UL(3)*u_L-Ul(5)*Ul(6) + F(4)=UL(4)*u_L-Ul(5)*Ul(7) + F(5)=0. + F(6)=UL(6)*u_L-Ul(5)*v_L + F(7)=UL(7)*u_L-Ul(5)*w_L + + U(1)=UL(1) + U(2)=UL(2) + U(3)=UL(3) + U(4)=UL(4) + U(5)=UL(5) + U(6)=UL(6) + U(7)=UL(7) + + goto 8888 + endif + + if (SR.le.0.) then + F(1)=UR(2) + F(2)=UR(2)*u_R+ptR-Ur(5)*Ur(5) + F(3)=UR(3)*u_R-Ur(5)*Ur(6) + F(4)=UR(4)*u_R-Ur(5)*Ur(7) + F(5)=0. + F(6)=UR(6)*u_R-Ur(5)*v_R + F(7)=UR(7)*u_R-Ur(5)*w_R + U(1)=UR(1) + U(2)=UR(2) + U(3)=UR(3) + U(4)=UR(4) + U(5)=UR(5) + U(6)=UR(6) + U(7)=UR(7) + goto 8888 + endif + + Fl(1)=UL(2) + Fl(2)=UL(2)*u_L+ptL-Ul(5)*Ul(5) + Fl(3)=UL(3)*u_L-Ul(5)*Ul(6) + Fl(4)=UL(4)*u_L-Ul(5)*Ul(7) + Fl(5)=0. + Fl(6)=UL(6)*u_L-Ul(5)*v_L + Fl(7)=UL(7)*u_L-Ul(5)*w_L + + Fr(1)=UR(2) + Fr(2)=UR(2)*u_R+ptR-Ur(5)*Ur(5) + Fr(3)=UR(3)*u_R-Ur(5)*Ur(6) + Fr(4)=UR(4)*u_R-Ur(5)*Ur(7) + Fr(5)=0. + Fr(6)=UR(6)*u_R-Ur(5)*v_R + Fr(7)=UR(7)*u_R-Ur(5)*w_R + + Do i=1,7 + Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) + Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) + enddo + + u_ast=Fhll(1)/Uhll(1) + ca=abs(Bx)/sqrt(Uhll(1)) + + SL_rot=u_ast-ca + SR_rot=u_ast+ca + + UL_ast(1)=Uhll(1) + UL_ast(2)=Uhll(2) + + f3=(SL-SL_rot)*(SL-SR_rot) + + if (f3.ne.0.) then + UL_ast(3)=Uhll(1)*v_L-Bx*UL(6)*(u_ast-u_L)/f3 + UL_ast(4)=Uhll(1)*w_L-Bx*UL(7)*(u_ast-u_L)/f3 + Ul_ast(5)=bx + UL_ast(6)=UL(6)*(UL(1)*((SL-u_L)**2)-Bx*Bx)/Uhll(1)/f3 + UL_ast(7)=UL(7)*(UL(1)*((SL-u_L)**2)-Bx*Bx)/Uhll(1)/f3 + else + UL_ast(3)=UL(3) + UL_ast(4)=UL(4) + Ul_ast(5)=bx + UL_ast(6)=UL(6) + UL_ast(7)=UL(7) + endif + + if ((SL.lt.0.).and.(0.le.SL_rot)) then + Do i=1,7 + F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) + U(i)=UL_ast(i) + enddo + goto 8888 + endif + + UR_ast(1)=Uhll(1) + UR_ast(2)=Uhll(2) + + f3=(SR-SL_rot)*(SR-SR_rot) + + if (f3.ne.0.) then + UR_ast(3)=Uhll(1)*v_R-Bx*UR(6)*(u_ast-u_R)/f3 + UR_ast(4)=Uhll(1)*w_R-Bx*UR(7)*(u_ast-u_R)/f3 + UR_ast(5)=bx + UR_ast(6)=UR(6)*(UR(1)*((SR-u_R)**2)-Bx*Bx)/Uhll(1)/f3 + UR_ast(7)=UR(7)*(UR(1)*((SR-u_R)**2)-Bx*Bx)/Uhll(1)/f3 + else + UR_ast(3)=UR(3) + UR_ast(4)=UR(4) + UR_ast(5)=bx + UR_ast(6)=UR(6) + UR_ast(7)=UR(7) + endif + + if ((SR_rot.lt.0.).and.(0.le.SR)) then + Do i=1,7 + F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) + U(i)=UR_ast(i) + enddo + goto 8888 + endif + + X=sqrt(Uhll(1))*sign(one,Bx) + + g3=(UL_ast(3)+UR_ast(3)+X*(UR_ast(6)-UL_ast(6)))/2.e0 + g4=(UL_ast(4)+UR_ast(4)+X*(UR_ast(7)-UL_ast(7)))/2.e0 + g5=(UL_ast(6)+UR_ast(6)+(UR_ast(3)-UL_ast(3))/X)/2.e0 + g6=(UL_ast(7)+UR_ast(7)+(UR_ast(4)-UL_ast(4))/X)/2.e0 + + + F(1)=Fhll(1) + F(2)=Fhll(2) + F(3)=g3*u_ast-Bx*g5 + F(4)=g4*u_ast-Bx*g6 + F(5)=0. + F(6)=g5*u_ast-Bx*g3/uhll(1) + F(7)=g6*u_ast-Bx*g4/uhll(1) + + U(1)=Uhll(1) + U(2)=Uhll(2) + U(3)=g3 + U(4)=g4 + U(5)=bx + U(6)=g5 + U(7)=g6 + +c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then +c ERROR_MESSAGE + +c print*,'Error in HLLDS procedure! Press any key.' +c pause +c endif + + 8888 continue + +c print*,'hlld finished' +c pause + + End ! Subroutine HLLDx + + Subroutine HLLDy(UL,UR,F,U) !SL and SR from min/max + + ENZO_REAL U(7),F(7),UL(7),UR(7) + + Integer i + ENZO_REAL Uhll(7),Fhll(7) + ENZO_REAL FL(7),FR(7) + ENZO_REAL SL,SR,SL_rot,SR_rot + ENZO_REAL cf,ca ! fast and Alfven velocities + ENZO_REAL Bx,By,Bz,BB + ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R + ENZO_REAL ptL, ptR + ENZO_REAL u_ast + ENZO_REAL UL_ast(7),UR_ast(7) + +!temporary + ENZO_REAL f2,f3,X,g2,g4,g5,g7 + ENZO_REAL S1L, S1R, S2L, S2R + ENZO_REAL a,a1,a2,ds + + + ENZO_REAL one + parameter(one = 1.0) + +! bug common/aspd/a1,a2 + a1=1. + a2=1. + + a=a1 + + u_L=UL(2)/UL(1) + v_L=UL(3)/UL(1) + w_L=UL(4)/UL(1) + + u_R=UR(2)/UR(1) + v_R=UR(3)/UR(1) + w_R=UR(4)/UR(1) + + By=(Ul(6)+Ur(6))/2.e0 + + Bx=UL(5) + Bz=UL(7) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(By)/sqrt(UL(1)) + f2=a*a+BB/UL(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + ptL=a*a*UL(1)+BB/2.e0 + + S1L=v_L-cf + S1R=v_L+cf + + Bx=UR(5) + Bz=UR(7) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(By)/sqrt(UR(1)) + f2=a*a+BB/UR(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + ptR=a*a*UR(1)+BB/2.e0 + + S2L=v_R-cf + S2R=v_R+cf + + SL=min(S1L,S2L) + SR=max(S1R,S2R) + + if (SL.ge.0.) then + + F(1)=UL(3) + F(2)=UL(2)*v_L-Ul(5)*Ul(6) + F(3)=UL(3)*v_L+ptl-Ul(6)*Ul(6) + F(4)=UL(4)*v_L-Ul(6)*Ul(7) + F(5)=UL(5)*v_L-Ul(6)*u_L + F(6)=0. + F(7)=UL(7)*v_L-Ul(6)*w_L + + U(1)=UL(1) + U(2)=UL(2) + U(3)=UL(3) + U(4)=UL(4) + U(5)=UL(5) + U(6)=UL(6) + U(7)=UL(7) + + goto 7777 + endif + + if (SR.le.0.) then + + F(1)=UR(3) + F(2)=UR(2)*v_R-Ur(5)*UR(6) + F(3)=UR(3)*v_R+ptR-UR(6)*UR(6) + F(4)=UR(4)*v_R-UR(6)*UR(7) + F(5)=UR(5)*v_R-UR(6)*u_R + F(6)=0. + F(7)=UR(7)*v_R-UR(6)*w_R + + U(1)=UR(1) + U(2)=UR(2) + U(3)=UR(3) + U(4)=UR(4) + U(5)=UR(5) + U(6)=UR(6) + U(7)=UR(7) + + goto 7777 + endif + + Fl(1)=UL(3) + Fl(2)=UL(2)*v_L-Ul(5)*Ul(6) + Fl(3)=UL(3)*v_L+ptl-Ul(6)*Ul(6) + Fl(4)=UL(4)*v_L-Ul(6)*Ul(7) + Fl(5)=UL(5)*v_L-Ul(6)*u_L + Fl(6)=0. + Fl(7)=UL(7)*v_L-Ul(6)*w_L + + Fr(1)=UR(3) + Fr(2)=UR(2)*v_R-UR(5)*UR(6) + Fr(3)=UR(3)*v_R+ptR-UR(6)*UR(6) + Fr(4)=UR(4)*v_R-UR(6)*UR(7) + Fr(5)=UR(5)*v_R-UR(6)*u_R + Fr(6)=0. + Fr(7)=UR(7)*v_R-UR(6)*w_R + + Do i=1,7 + Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) + Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) + enddo + + u_ast=Fhll(1)/Uhll(1) + ca=abs(By)/sqrt(Uhll(1)) + + SL_rot=u_ast-ca + SR_rot=u_ast+ca + + UL_ast(1)=Uhll(1) + UL_ast(3)=Uhll(3) + + f3=(SL-SL_rot)*(SL-SR_rot) + + if (f3.ne.0.) then + UL_ast(2)=Uhll(1)*u_L-By*UL(5)*(u_ast-v_L)/f3 + UL_ast(4)=Uhll(1)*w_L-By*UL(7)*(u_ast-v_L)/f3 + UL_ast(5)=UL(5)*(UL(1)*((SL-v_L)**2)-By*By)/Uhll(1)/f3 + UL_ast(6)=by + UL_ast(7)=UL(7)*(UL(1)*((SL-v_L)**2)-By*By)/Uhll(1)/f3 + else + UL_ast(2)=UL(2) + UL_ast(4)=UL(4) + UL_ast(5)=UL(5) + UL_ast(6)=by + UL_ast(7)=UL(7) + endif + + if ((SL.lt.0.).and.(0.le.SL_rot)) then + Do i=1,7 + F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) + U(i)=UL_ast(i) + enddo + goto 7777 + endif + + UR_ast(1)=Uhll(1) + UR_ast(3)=Uhll(3) + + f3=(SR-SL_rot)*(SR-SR_rot) + + if (f3.ne.0.) then + UR_ast(2)=Uhll(1)*u_R-By*UR(5)*(u_ast-v_R)/f3 + UR_ast(4)=Uhll(1)*w_R-By*UR(7)*(u_ast-v_R)/f3 + UR_ast(5)=UR(5)*(UR(1)*((SR-v_R)**2)-By*By)/Uhll(1)/f3 + UR_ast(6)=by + UR_ast(7)=UR(7)*(UR(1)*((SR-v_R)**2)-By*By)/Uhll(1)/f3 + else + UR_ast(2)=UR(2) + UR_ast(4)=UR(4) + UR_ast(5)=UR(5) + UR_ast(6)=by + UR_ast(7)=UR(7) + endif + + if ((SR_rot.lt.0.).and.(0.le.SR)) then + Do i=1,7 + F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) + U(i)=UR_ast(i) + enddo + goto 7777 + endif + + X=sqrt(Uhll(1))*sign(one,By) + + g2=(UL_ast(2)+UR_ast(2)+X*(UR_ast(5)-UL_ast(5)))/2.e0 + g4=(UL_ast(4)+UR_ast(4)+X*(UR_ast(7)-UL_ast(7)))/2.e0 + g5=(UL_ast(5)+UR_ast(5)+(UR_ast(2)-UL_ast(2))/X)/2.e0 + g7=(UL_ast(7)+UR_ast(7)+(UR_ast(4)-UL_ast(4))/X)/2.e0 + + F(1)=Fhll(1) + F(2)=g2*u_ast-By*g5 + F(3)=Fhll(3) + F(4)=g4*u_ast-By*g7 + F(5)=g5*u_ast-By*g2/uhll(1) + F(6)=0. + F(7)=g7*u_ast-By*g4/uhll(1) + + U(1)=Uhll(1) + U(2)=g2 + U(3)=Uhll(3) + U(4)=g4 + U(5)=g5 + U(6)=by + U(7)=g7 + +c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then +c ERROR_MESSAGE + +c print*,'Error in HLLDS procedure! Press any key.' +c pause +c endif + +7777 continue + +c print*,'hlld finished' +c pause + + End ! Subroutine HLLDy + + + Subroutine HLLDz(UL,UR,F,U) !SL and SR from min/max + + ENZO_REAL U(7),F(7),UL(7),UR(7) + + Integer i + ENZO_REAL Uhll(7),Fhll(7) + ENZO_REAL FL(7),FR(7) + ENZO_REAL SL,SR,SL_rot,SR_rot + ENZO_REAL cf,ca ! fast and Alfven velocities + ENZO_REAL Bx,By,Bz,BB + ENZO_REAL u_L,v_L,w_L,u_R,v_R,w_R + ENZO_REAL ptL, ptR + ENZO_REAL u_ast + ENZO_REAL UL_ast(7),UR_ast(7) + + !temporary + ENZO_REAL f2,f3,X,g2,g3,g5,g6 + ENZO_REAL S1L, S1R, S2L, S2R + ENZO_REAL a,a1,a2,ds + + ENZO_REAL one + parameter(one = 1.0) + +!bug common/aspd/a1,a2 + a1=1. + a2=1. + + a=a1 + + u_L=UL(2)/UL(1) + v_L=UL(3)/UL(1) + w_L=UL(4)/UL(1) + + u_R=UR(2)/UR(1) + v_R=UR(3)/UR(1) + w_R=UR(4)/UR(1) + + Bz=(Ul(7)+Ur(7))/2.e0 + + Bx=UL(5) + By=UL(6) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(Bz)/sqrt(UL(1)) + f2=a*a+BB/UL(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + ptL=a*a*UL(1)+BB/2.e0 + + S1L=w_L-cf + S1R=w_L+cf + + Bx=UR(5) + By=UR(6) + + BB=Bx*Bx+By*By+Bz*Bz + ca=abs(Bz)/sqrt(UR(1)) + f2=a*a+BB/UR(1) + ds=f2*f2-4.e0*a*a*ca*ca + if(ds.lt.0.) ds=0. + cf=sqrt(0.5e0*(f2+sqrt(ds))) + + ptR=a*a*UR(1)+BB/2.e0 + + S2L=w_R-cf + S2R=w_R+cf + + SL=min(S1L,S2L) + SR=max(S1R,S2R) + + if (SL.ge.0.) then + + F(1)=UL(4) + F(2)=UL(2)*w_L-Ul(5)*Ul(7) + F(3)=UL(3)*w_L-Ul(6)*Ul(7) + F(4)=UL(4)*w_L+ptl-Ul(7)*Ul(7) + F(5)=UL(5)*w_L-Ul(7)*u_L + F(6)=UL(6)*w_L-Ul(7)*v_L + F(7)=0. + + U(1)=UL(1) + U(2)=UL(2) + U(3)=UL(3) + U(4)=UL(4) + U(5)=UL(5) + U(6)=UL(6) + U(7)=UL(7) + + goto 6666 + endif + + if (SR.le.0.) then + + F(1)=UR(4) + F(2)=UR(2)*w_R-UR(5)*UR(7) + F(3)=UR(3)*w_R-UR(6)*UR(7) + F(4)=UR(4)*w_R+ptR-UR(7)*UR(7) + F(5)=UR(5)*w_R-UR(7)*u_R + F(6)=UR(6)*w_R-UR(7)*v_R + F(7)=0. + + U(1)=UR(1) + U(2)=UR(2) + U(3)=UR(3) + U(4)=UR(4) + U(5)=UR(5) + U(6)=UR(6) + U(7)=UR(7) + + goto 6666 + endif + + Fl(1)=UL(4) + Fl(2)=UL(2)*w_L-Ul(5)*Ul(7) + Fl(3)=UL(3)*w_L-Ul(6)*Ul(7) + Fl(4)=UL(4)*w_L+ptl-Ul(7)*Ul(7) + Fl(5)=UL(5)*w_L-Ul(7)*u_L + Fl(6)=UL(6)*w_L-Ul(7)*v_L + Fl(7)=0. + + Fr(1)=UR(4) + Fr(2)=UR(2)*w_R-UR(5)*UR(7) + Fr(3)=UR(3)*w_R-UR(6)*UR(7) + Fr(4)=UR(4)*w_R+ptR-UR(7)*UR(7) + Fr(5)=UR(5)*w_R-UR(7)*u_R + Fr(6)=UR(6)*w_R-UR(7)*v_R + Fr(7)=0. + + Do i=1,7 + Uhll(i)=(SR*UR(i)-SL*UL(i)-FR(i)+FL(i))/(SR-SL) + Fhll(i)=(SR*FL(i)-SL*FR(i)+SL*SR*(UR(i)-UL(i)))/(SR-SL) + enddo + + u_ast=Fhll(1)/Uhll(1) + ca=abs(Bz)/sqrt(Uhll(1)) + + SL_rot=u_ast-ca + SR_rot=u_ast+ca + + UL_ast(1)=Uhll(1) + UL_ast(4)=Uhll(4) + + f3=(SL-SL_rot)*(SL-SR_rot) + + if (f3.ne.0.) then + UL_ast(2)=Uhll(1)*u_L-Bz*UL(5)*(u_ast-w_L)/f3 + UL_ast(3)=Uhll(1)*v_L-Bz*UL(6)*(u_ast-w_L)/f3 + UL_ast(5)=UL(5)*(UL(1)*((SL-w_L)**2)-Bz*Bz)/Uhll(1)/f3 + UL_ast(6)=UL(6)*(UL(1)*((SL-w_L)**2)-Bz*Bz)/Uhll(1)/f3 + Ul_ast(7)=bz + else + UL_ast(2)=UL(2) + UL_ast(3)=UL(3) + UL_ast(5)=UL(5) + UL_ast(6)=UL(6) + Ul_ast(7)=bz + endif + + if ((SL.lt.0.).and.(0.le.SL_rot)) then + Do i=1,7 + F(i)=FL(i)+SL*(UL_ast(i)-UL(i)) + U(i)=UL_ast(i) + enddo + goto 6666 + endif + + UR_ast(1)=Uhll(1) + UR_ast(4)=Uhll(4) + + f3=(SR-SL_rot)*(SR-SR_rot) + + if (f3.ne.0.) then + UR_ast(2)=Uhll(1)*u_R-Bz*UR(5)*(u_ast-w_R)/f3 + UR_ast(3)=Uhll(1)*v_R-Bz*UR(6)*(u_ast-w_R)/f3 + UR_ast(5)=UR(5)*(UR(1)*((SR-w_R)**2)-Bz*Bz)/Uhll(1)/f3 + UR_ast(6)=UR(6)*(UR(1)*((SR-w_R)**2)-Bz*Bz)/Uhll(1)/f3 + UR_ast(7)=bz + else + UR_ast(2)=UR(2) + UR_ast(3)=UR(3) + UR_ast(5)=UR(5) + UR_ast(6)=UR(6) + UR_ast(7)=bz + endif + + if ((SR_rot.lt.0.).and.(0.le.SR)) then + Do i=1,7 + F(i)=FR(i)+SR*(UR_ast(i)-UR(i)) + U(i)=UR_ast(i) + enddo + goto 6666 + endif + + X=sqrt(Uhll(1))*sign(one,Bz) + + g2=(UL_ast(2)+UR_ast(2)+X*(UR_ast(5)-UL_ast(5)))/2.e0 + g3=(UL_ast(3)+UR_ast(3)+X*(UR_ast(6)-UL_ast(6)))/2.e0 + g5=(UL_ast(5)+UR_ast(5)+(UR_ast(2)-UL_ast(2))/X)/2.e0 + g6=(UL_ast(6)+UR_ast(6)+(UR_ast(3)-UL_ast(3))/X)/2.e0 + + + F(1)=Fhll(1) + F(2)=g2*u_ast-Bz*g5 + F(3)=g3*u_ast-Bz*g6 + F(4)=Fhll(4) + F(5)=g5*u_ast-Bz*g2/uhll(1) + F(6)=g6*u_ast-Bz*g3/uhll(1) + F(7)=0. + + U(1)=Uhll(1) + U(2)=g2 + U(3)=g3 + U(4)=Uhll(4) + U(5)=g5 + U(6)=g6 + U(7)=bz + +c if (.not.((SL_rot.le.0.).and.(0.le.SR_rot))) then +c ERROR_MESSAGE + +c print*,'Error in HLLDS procedure! Press any key.' +c pause +c endif + + 6666 continue + +c print*,'hlld finished' +c pause + + End ! Subroutine HLLDz diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_MAIN.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_MAIN.F index f70c5c45d0..3cb3ca3ebc 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_MAIN.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_MAIN.F @@ -125,7 +125,11 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, if (nx.le.0) then C ERROR_MESSAGE endif - + +c +c Active cells start from i,j,k1 and end at i,j,k2 +c Number of ghost zones i,j,kghost=3 for PPM, supposed to be 2 for PPML +c i1=GridStartIndex(1)+1 j1=GridStartIndex(2)+1 k1=GridStartIndex(3)+1 @@ -155,7 +159,11 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, ! i2=Nx-3 ! j2=Ny-3 ! k2=Nz-3 - +c +c nx(yz)b=1 -- fist zone of the grid +c nx(yz)e -- last +c nx(yz)p -- total number of grid zones in a given direction (duplicates nx,y,z for no reason) +c nxb=i1-ighost nxe=i2+ighost @@ -261,7 +269,9 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, dx1(i)=vax-vay+vaz-cga+dsc-cgs Enddo - +c +c 1D monotonicity constraint (Procedire 1) ??? [AK] +c Call Monot(1,nxp,Dx1,Dx2,qp1,qr1,qlx1,qrx1) Do i=nxb+1,nxe @@ -269,6 +279,9 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, Qrx1(i,5)=Qr1(i,5) Enddo +c +c 2D monotonicity constraint (Timothy Barth, homepage @ NASA AMES) +c Do i=nxb+1,nxe-1 dn1=Qp1(i,1) @@ -336,7 +349,9 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, qrx1(i,7)=max(bz1,min(bz2,qrx1(i,7))) Enddo - +c +c PPM correction for local extremum +c CALL QDD6(nxp,Qrx1,Qlx1,Qvr1,Qvl1,Qp1) Do i=nxb,nxe @@ -351,7 +366,7 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, dnrx(i,j,k)=Qrp1(i,1) vxrx(i,j,k)=Qrp1(i,2) vyrx(i,j,k)=Qrp1(i,3) - vzrx(i,j,k)=Qrp1(i,4) + vzrx(i,j,k)=Qrp1(i,4) byrx(i,j,k)=Qrp1(i,6) bzrx(i,j,k)=Qrp1(i,7) @@ -772,6 +787,15 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, C ! Gardiner&Stone CT C ! C !----------------------------------------------------------------- +! +! This piece follows Ustyugov et al. (2009), page 7622, Fig. 7 +! and computes E-field values at the grid nodes (see last equation on p. 7622): +! Ex(ijk), Ey(ijk), and Ez(ijk). +! +! The B-fields on cell edges are computed using Stokes' theorem (46) and equations on page 7623 +! in the next step named "Evolution of all variables." +! Then at the very end cell-centered B-fields are computed as averages. + epsk=1.0e-12 DO K=k1-1,k2 @@ -1285,7 +1309,13 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, c Evolution of all variables c c------------------------------------------------------------------- - +! +! This piece computes B-fields at cell interfaces, subject to div(B)=0 constraint. +! These primitive variables cannot be computed simply as a solution to the Riemann problem. +! The CT-based B-fields are only computed for active zones and only as r-states, with one +! exception. The aligned field component (e.g. bxrx along x) is computed as the right face +! value for the 1st ghost zone to the left from active area. +! Do k=k1,k2 Do j=j1,j2 Do i=i1-1,i2 @@ -1334,6 +1364,7 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, c enddo c close(10) + Call Conserv(nxp,nyp,nzp,dn,vx,vy,vz,bx,by,bz, & qu1,qu2,qu3,qu4,qu5,qu6,qu7) @@ -1362,6 +1393,11 @@ Subroutine PPML(dn,vx,vy,vz,bx,by,bz, QH(7)=QU7(I,J,K)-Dt/Dx*(F7(I,J,K)-F7(I-1,J,K) & +G7(I,J,K)-G7(I,J-1,K)+H7(I,J,K)-H7(I,J,K-1)) +c +c Update for cell-centered B-field components [Ustyugov et al. (2009), page 7623] +c Why do we need QH(5,6,7) computed above through fluxes? Why do we duplicate? =AK +c + qh(5)=0.5*(bxrx(i,j,k)+bxrx(i-1,j,k)) qh(6)=0.5*(byry(i,j,k)+byry(i,j-1,k)) qh(7)=0.5*(bzrz(i,j,k)+bzrz(i,j,k-1)) diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_Primitive.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_Primitive.F index e6954ce518..09eaa5e343 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_Primitive.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_Primitive.F @@ -1,32 +1,32 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine Primitiv(nx,ny,nz,qu1,qu2,qu3,qu4,qu5,qu6,qu7, - & dn,vx,vy,vz,bx,by,bz) - Implicit NONE - Integer nx,ny,nz,i,j,k - ENZO_REAL dn(nx,ny,nz) - ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) - ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) - - ENZO_REAL qu1(nx,ny,nz) - ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) - ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) - - Do k=1,nz - Do j=1,ny - Do i=1,nx - dn(i,j,k)=QU1(i,j,k) - vx(i,j,k)=QU2(i,j,k)/QU1(i,j,k) - vy(i,j,k)=QU3(i,j,k)/QU1(i,j,k) - vz(i,j,k)=QU4(i,j,k)/QU1(i,j,k) - bx(i,j,k)=QU5(i,j,k) - by(i,j,k)=QU6(i,j,k) - bz(i,j,k)=QU7(i,j,k) - Enddo - Enddo - Enddo - - RETURN - END +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine Primitiv(nx,ny,nz,qu1,qu2,qu3,qu4,qu5,qu6,qu7, + & dn,vx,vy,vz,bx,by,bz) + Implicit NONE + Integer nx,ny,nz,i,j,k + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + + ENZO_REAL qu1(nx,ny,nz) + ENZO_REAL qu2(nx,ny,nz),qu3(nx,ny,nz),qu4(nx,ny,nz) + ENZO_REAL qu5(nx,ny,nz),qu6(nx,ny,nz),qu7(nx,ny,nz) + + Do k=1,nz + Do j=1,ny + Do i=1,nx + dn(i,j,k)=QU1(i,j,k) + vx(i,j,k)=QU2(i,j,k)/QU1(i,j,k) + vy(i,j,k)=QU3(i,j,k)/QU1(i,j,k) + vz(i,j,k)=QU4(i,j,k)/QU1(i,j,k) + bx(i,j,k)=QU5(i,j,k) + by(i,j,k)=QU6(i,j,k) + bz(i,j,k)=QU7(i,j,k) + Enddo + Enddo + Enddo + + RETURN + END diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_TimeStep.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_TimeStep.F index 6819fa474b..150d7f0335 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_TimeStep.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_TimeStep.F @@ -1,121 +1,106 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine calc_dt_ppml - & (nx,ny,nz, - & i1,i2,j1,j2,k1,k2, - & dx,dy,dz, - & dn,vx,vy,vz,bx,by,bz, - & dt) - - Implicit NONE - - Integer nx,ny,nz,i,j,k,i1,j1,k1,i2,j2,k2 - - Integer ii1,ii2,jj1,jj2,kk1,kk2 - - ENZO_REAL dn(nx,ny,nz) - ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) - ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) - - ENZO_REAL dtmx,dtmy,dtmz,rr0,bkb,vah,vax,vay,vaz,cg,a2 - ENZO_REAL cga,dsc,cfsx,cgs,taux,cfsy,tauy,cfsz,tauz,c0,dt -! ENZO_REAL dx(nx),dy(ny),dz(nz) - ENZO_REAL dx,dy,dz - ENZO_REAL dmin,dmax - ENZO_REAL vxmin,vxmax,vymin,vymax,vzmin,vzmax - ENZO_REAL bxmin,bxmax,bymin,bymax,bzmin,bzmax -! print*, 'nx,ny,nz=',nx,ny,nz -! print*, 'i1,i2=',i1,i2 -! print*, 'j1,j2=',j1,j2 -! print*, 'k1,k2=',k1,k2 -!! print*, 'dx(i1)=',dx(1) -!! print*, 'dy(j1)=',dy(1) -!! print*, 'dz(k1)=',dz(1) -! print*, 'dx=',dx -! print*, 'dy=',dy -! print*, 'dz=',dz -! print*, 'dn(10,10,1)=',dn(10,10,1) -! print*, 'vx(10,10,1)=',vx(10,10,1) -! print*, 'vy(10,10,1)=',vy(10,10,1) -! print*, 'vz(10,10,1)=',vz(10,10,1) -! print*, 'bx(10,10,1)=',bx(10,10,1) -! print*, 'by(10,10,1)=',by(10,10,1) -! print*, 'bz(10,10,1)=',bz(10,10,1) -! print*, 'dt=',dt - - DTMX=1.E+10 - DTMY=1.E+10 - DTMZ=1.E+10 - - c0=0.8d0 - a2=1.0d0 - - dmin = 1.e36 - dmax = -1e36 - vxmin = 1.e36 - vxmax = -1e36 - vymin = 1.e36 - vymax = -1e36 - vzmin = 1.e36 - vzmax = -1e36 - bxmin = 1.e36 - bxmax = -1e36 - bymin = 1.e36 - bymax = -1e36 - bzmin = 1.e36 - bzmax = -1e36 - -! Adjust array bounds for C / C++ -! copies since original variables are call by reference - - ii1 = i1 + 1 - ii2 = i2 + 1 - jj1 = j1 + 1 - jj2 = j2 + 1 - kk1 = k1 + 1 - kk2 = k2 + 1 - - DO K=kk1,kk2 - DO J=jj1,jj2 - DO I=ii1,ii2 - - RR0=dn(I,J,K) - BKB=bx(I,J,K)**2+by(I,J,K)**2+bz(I,J,K)**2 - VAH=BKB/RR0 - VAX=bx(I,J,K)**2/RR0 - VAY=by(I,J,K)**2/RR0 - VAZ=bz(I,J,K)**2/RR0 - CG=A2 - CGA=CG+VAH - DSC=CGA**2-4.d0*VAX*CG - IF(DSC.LT.0.) DSC=0. - CFSX=sqrt(DSC) - CGS=sqrt((CGA+CFSX)/2.d0) -! TAUX=DX(ii1)/(abs(vx(I,J,K))+CGS) - TAUX=DX/(abs(vx(I,J,K))+CGS) - DSC=CGA**2-4.d0*VAY*CG - IF(DSC.LT.0.) DSC=0. - CFSY=sqrt(DSC) - CGS=sqrt((CGA+CFSY)/2.d0) -! TAUY=DY(jj1)/(abs(vy(I,J,K))+CGS) - TAUY=DY/(abs(vy(I,J,K))+CGS) - DSC=CGA**2-4.d0*VAZ*CG - IF(DSC.LT.0.) DSC=0. - CFSZ=sqrt(DSC) - CGS=sqrt((CGA+CFSZ)/2.d0) -! TAUZ=DZ(kk1)/(abs(vz(I,J,K))+CGS) - TAUZ=DZ/(abs(vz(I,J,K))+CGS) - - DTMX=MIN(DTMX,TAUX) - DTMY=MIN(DTMY,TAUY) - DTMZ=MIN(DTMZ,TAUZ) - ENDDO - ENDDO - ENDDO - - DT=C0/(1.D0/DTMX+1.D0/DTMY+1.D0/DTMZ) -! - Return - End +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine calc_dt_ppml + & (nx,ny,nz, + & i1,i2,j1,j2,k1,k2, + & dx,dy,dz, + & dn,vx,vy,vz,bx,by,bz, + & dt) + + Implicit NONE + + Integer nx,ny,nz,i,j,k,i1,j1,k1,i2,j2,k2 + + Integer ii1,ii2,jj1,jj2,kk1,kk2 + + ENZO_REAL dn(nx,ny,nz) + ENZO_REAL vx(nx,ny,nz),vy(nx,ny,nz),vz(nx,ny,nz) + ENZO_REAL bx(nx,ny,nz),by(nx,ny,nz),bz(nx,ny,nz) + + ENZO_REAL dtmx,dtmy,dtmz,rr0,bkb,vah,vax,vay,vaz,cg,a2 + ENZO_REAL cga,dsc,cfsx,cgs,taux,cfsy,tauy,cfsz,tauz,c0,dt +! ENZO_REAL dx(nx),dy(ny),dz(nz) + ENZO_REAL dx,dy,dz + ENZO_REAL dmin,dmax + ENZO_REAL vxmin,vxmax,vymin,vymax,vzmin,vzmax + ENZO_REAL bxmin,bxmax,bymin,bymax,bzmin,bzmax +! print*, 'nx,ny,nz=',nx,ny,nz +! print*, 'i1,i2=',i1,i2 +! print*, 'j1,j2=',j1,j2 +! print*, 'k1,k2=',k1,k2 +!! print*, 'dx(i1)=',dx(1) +!! print*, 'dy(j1)=',dy(1) +!! print*, 'dz(k1)=',dz(1) +! print*, 'dx=',dx +! print*, 'dy=',dy +! print*, 'dz=',dz +! print*, 'dn(10,10,1)=',dn(10,10,1) +! print*, 'vx(10,10,1)=',vx(10,10,1) +! print*, 'vy(10,10,1)=',vy(10,10,1) +! print*, 'vz(10,10,1)=',vz(10,10,1) +! print*, 'bx(10,10,1)=',bx(10,10,1) +! print*, 'by(10,10,1)=',by(10,10,1) +! print*, 'bz(10,10,1)=',bz(10,10,1) +! print*, 'dt=',dt + + DTMX=1.E+10 + DTMY=1.E+10 + DTMZ=1.E+10 + + c0=0.8d0 + a2=1.0d0 + +! Adjust array bounds for C / C++ +! copies since original variables are call by reference + + ii1 = i1 + 1 + ii2 = i2 + 1 + jj1 = j1 + 1 + jj2 = j2 + 1 + kk1 = k1 + 1 + kk2 = k2 + 1 + + DO K=kk1,kk2 + DO J=jj1,jj2 + DO I=ii1,ii2 + + RR0=dn(I,J,K) + BKB=bx(I,J,K)**2+by(I,J,K)**2+bz(I,J,K)**2 + VAH=BKB/RR0 + VAX=bx(I,J,K)**2/RR0 + VAY=by(I,J,K)**2/RR0 + VAZ=bz(I,J,K)**2/RR0 + CG=A2 + CGA=CG+VAH + DSC=CGA**2-4.d0*VAX*CG + IF(DSC.LT.0.) DSC=0. + CFSX=sqrt(DSC) + CGS=sqrt((CGA+CFSX)/2.d0) +! TAUX=DX(ii1)/(abs(vx(I,J,K))+CGS) + TAUX=DX/(abs(vx(I,J,K))+CGS) + DSC=CGA**2-4.d0*VAY*CG + IF(DSC.LT.0.) DSC=0. + CFSY=sqrt(DSC) + CGS=sqrt((CGA+CFSY)/2.d0) +! TAUY=DY(jj1)/(abs(vy(I,J,K))+CGS) + TAUY=DY/(abs(vy(I,J,K))+CGS) + DSC=CGA**2-4.d0*VAZ*CG + IF(DSC.LT.0.) DSC=0. + CFSZ=sqrt(DSC) + CGS=sqrt((CGA+CFSZ)/2.d0) +! TAUZ=DZ(kk1)/(abs(vz(I,J,K))+CGS) + TAUZ=DZ/(abs(vz(I,J,K))+CGS) + + DTMX=MIN(DTMX,TAUX) + DTMY=MIN(DTMY,TAUY) + DTMZ=MIN(DTMZ,TAUZ) + ENDDO + ENDDO + ENDDO + + DT=C0/(1.D0/DTMX+1.D0/DTMY+1.D0/DTMZ) +! + Return + End diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_monot.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_monot.F index 0a5ded13ce..4f6ea07c2b 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_monot.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_monot.F @@ -1,357 +1,357 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - - Subroutine Monot(md,nx,dv1,dv2,qp,qm,qxl,qxr) - Implicit NONE - - External Xmedian - - Integer imd,md,nx,i,m - - ENZO_REAL q1(7),q2(7),q3(7),q4(7),q5(7) - ENZO_REAL qpl(7),qpr(7),vl(7),vr(7) - ENZO_REAL u1(7),u2(7),u3(7),u4(7),u5(7) - ENZO_REAL b1(7),b2(7),c1(7),c2(7) - ENZO_REAL ql(7,7),qr(7,7),uv(7) - ENZO_REAL qp(nx,7),qm(nx,7),qxl(nx,7),qxr(nx,7) - ENZO_REAL dv1(nx),dv2(nx) - - ENZO_REAL uwl,uwr,vx1,vx2,vx3,vx4,vx5,vl1,vr1,dml - ENZO_REAL dmr,dwl,dwr,sjn,sjm,sjx,sjy,uvr,uvl,Xmedian - - ENZO_REAL IS1,IS2,IS3,DELTA,WS1,WS2,WS3,WJ1,WJ2,WJ3 - ENZO_REAL AJ1,AJ2,AJ3,AJS,WM1,WM2,WM3 - - ENZO_REAL o2, o4, o6, o12 - - ENZO_REAL one - parameter (one = 1.0) - - o2 = 1.0E0 / 2.0E0 - o4 = 1.0E0 / 4.0E0 - o6 = 1.0E0 / 6.0E0 - o12 = 1.0E0 / 12.0E0 - -C ENZO_REAL VP1,VP2,VP3,VP4,VP5 - - Do i=1,Nx - Do m=1,7 - qxl(i,m)=0. - qxr(i,m)=0. - Enddo - Enddo - - Do i=3,Nx-2 - - Do m=1,7 - Q1(m)=Qp(i-2,m) - Q2(m)=Qp(i-1,m) - Q3(m)=Qp(i,m) - Q4(m)=Qp(i+1,m) - Q5(m)=Qp(i+2,m) - Enddo - - Do m=1,7 - Qpl(m)=qm(i-1,m) - Qpr(m)=qm(i,m) - Enddo - - if(md.eq.1)CALL VECTLRx(q3,QL,QR,UV) - if(md.eq.2)CALL VECTLRy(q3,QL,QR,UV) - if(md.eq.3)CALL VECTLRz(q3,QL,QR,UV) - - CALL AMPLTD(QL,q1,u1) - CALL AMPLTD(QL,q2,u2) - CALL AMPLTD(QL,q3,u3) - CALL AMPLTD(QL,q4,u4) - CALL AMPLTD(QL,q5,u5) - CALL AMPLTD(QL,qpl,c1) - CALL AMPLTD(QL,qpr,c2) - -c Do m=1,7 -c c1(m)=(7.e0*(u2(m)+u3(m))-(u1(m)+u4(m)))*o12 -c c2(m)=(7.e0*(u3(m)+u4(m))-(u2(m)+u5(m)))*o12 -c enddo - - Do m=1,7 - - uwl = Xmedian(u3(m),c1(m),u2(m)) - uwr = Xmedian(u3(m),c2(m),u4(m)) - - b1(m) = Xmedian(u3(m),uwl,3.e0*u3(m)-2.e0*uwr) - b2(m) = Xmedian(u3(m),uwr,3.e0*u3(m)-2.e0*uwl) - - Enddo - - imd=0 - - Do m=1,7 - - if((b1(m)-c1(m))**2.gt.1e-12.or.(b2(m)-c2(m))**2. - & gt.1e-12) imd=1 - - enddo - - If(imd.eq.0)then - - CALL AMPLTD(QR,c2,b2) - - Do m=1,7 - qxr(i,m)=b2(m) - enddo - - CALL AMPLTD(QR,c1,b1) - - Do m=1,7 - qxl(i,m)=b1(m) - enddo - - Else - - do m=1,7 - - vx1=u1(m) - vx2=u2(m) - vx3=u3(m) - vx4=u4(m) - vx5=u5(m) - -C CALL W5RECM(vx1,vx2,vx3,vx4,vx5,VL1,VR1) - DELTA = ENZO_TINY - - WS1 = 0.1E0 - WS2 = 0.6E0 - WS3 = 0.3E0 - - - WJ1 = (11.E0*VX3 - 7.E0*VX2 + 2.E0*VX1)*o6 - WJ2 = (2.E0 *VX4 + 5.E0*VX3 - VX2)*o6 - WJ3 = ( -VX5 + 5.E0*VX4 + 2.E0*VX3)*o6 - - IS1 = 13.E0*o12*(VX3 - 2.E0*VX2 + VX1)**2 - & + (3.E0*VX3 - 4.E0*VX2 + VX1)**2*o4 - IS2 = 13.E0*o12*(VX4 - 2.E0*VX3 + VX2)**2 - & + (VX4 - VX2)**2*o4 - IS3 = 13.E0*o12*(VX5 - 2.E0*VX4 + VX3)**2 - & + (VX5 - 4.E0*VX4 + 3.E0*VX3)**2*o4 - - AJ1 = WS1/(IS1+DELTA)**2 - AJ2 = WS2/(IS2+DELTA)**2 - AJ3 = WS3/(IS3+DELTA)**2 - - AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) - - WM1 = AJ1*AJS - WM2 = AJ2*AJS - WM3 = AJ3*AJS - - AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1) / - $ (WS1*WS1 + WM1*(1.E0 - 2.E0*WS1)) - AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2) / - $ (WS2*WS2 + WM2*(1.E0 - 2.E0*WS2)) - AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3) / - $ (WS3*WS3 + WM3*(1.E0 - 2.E0*WS3)) - - AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) - - WM1 = AJ1*AJS - WM2 = AJ2*AJS - WM3 = AJ3*AJS - - VR1 = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 - - WJ1 = (11.E0*VX3 - 7.E0*VX4 + 2.E0*VX5)*o6 - WJ2 = (2.E0 *VX2 + 5.E0*VX3 - VX4)*o6 - WJ3 = ( -VX1 + 5.E0*VX2 + 2.E0*VX3)*o6 - - IS1 = 13.E0*o12*(VX3 - 2.E0*VX4 + VX5)**2 - & + (3.E0*VX3 - 4.E0*VX4 + VX5)**2*o4 - IS2 = 13.E0*o12*(VX2 - 2.E0*VX3 + VX4)**2 - & + (VX2 - VX4)**2*o4 - IS3 = 13.E0*o12*(VX1 - 2.E0*VX2 + VX3)**2 - & + (VX1 - 4.E0*VX2 + 3.E0*VX3)**2*o4 - - AJ1 = WS1/(IS1+DELTA)**2 - AJ2 = WS2/(IS2+DELTA)**2 - AJ3 = WS3/(IS3+DELTA)**2 - - AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) - - WM1 = AJ1*AJS - WM2 = AJ2*AJS - WM3 = AJ3*AJS - - AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1) / - $ (WS1*WS1 + WM1*(1.E0 - 2.E0*WS1)) - AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2) / - $ (WS2*WS2 + WM2*(1.E0 - 2.E0*WS2)) - AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3) / - $ (WS3*WS3 + WM3*(1.E0 - 2.E0*WS3)) - - AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) - - WM1 = AJ1*AJS - WM2 = AJ2*AJS - WM3 = AJ3*AJS - - VL1 = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 - - vl(m)=vl1 - vr(m)=vr1 - - enddo - - Do m=1,7 - - If((b1(m)-u3(m))**2.lt.1e-12.and.(b2(m)-u3(m))**2. - & lt.1.e-12)then - - dml = Xmedian(u3(m),vl(m),c1(m)) - dmr = Xmedian(u3(m),vr(m),c2(m)) - - dwl = Xmedian(u3(m),dml,u2(m)) - dwr = Xmedian(u3(m),dmr,u4(m)) - - uwl = Xmedian(u3(m),3.e0*u3(m)-2.e0*dwr,dml) - uwr = Xmedian(u3(m),3.e0*u3(m)-2.e0*dwl,dmr) - - c1(m) = Xmedian(uwl,dml,c1(m)) - c2(m) = Xmedian(uwr,dmr,c2(m)) - - Else - - sjn = 0.5e0*(u4(m)-u2(m)) - sjm = 2.e0*Xmedian(0.,u4(m)-u3(m),u3(m)-u2(m)) - sjx = Xmedian(0.,sjn,sjm) - - sjn = 0.5e0*(u5(m)-u3(m)) - sjm = 2.e0*Xmedian(0.,u5(m)-u4(m),u4(m)-u3(m)) - sjy = Xmedian(0.,sjn,sjm) - - dwr = 0.5e0*(u3(m)+u4(m))-(sjy-sjx)/6.e0 - - sjn = 0.5e0*(u2(m)-u4(m)) - sjm = 2.e0*Xmedian(0.,u2(m)-u3(m),u3(m)-u4(m)) - sjx = Xmedian(0.,sjn,sjm) - - sjn = 0.5e0*(u1(m)-u3(m)) - sjm = 2.e0*Xmedian(0.,u1(m)-u2(m),u2(m)-u3(m)) - sjy = Xmedian(0.,sjn,sjm) - - dwl = 0.5e0*(u3(m)+u2(m))-(sjy-sjx)/6.e0 - - uwr = Xmedian(dwr,vr(m),c2(m)) - uwl = Xmedian(dwl,vl(m),c1(m)) - - dmr = Xmedian(u3(m),uwr,u4(m)) - dml = Xmedian(u3(m),uwl,u2(m)) - - uvr = Xmedian(u3(m),3.e0*u3(m)-2.e0*dml,dmr) - uvl = Xmedian(u3(m),3.e0*u3(m)-2.e0*dmr,dml) - - c1(m) = Xmedian(uvl,vl(m),c1(m)) - c2(m) = Xmedian(uvr,vr(m),c2(m)) - - Endif - - Enddo - - CALL AMPLTD(QR,c2,b2) - - Do m=1,7 - qxr(i,m)=b2(m) - enddo - - CALL AMPLTD(QR,c1,b1) - - Do m=1,7 - qxl(i,m)=b1(m) - enddo - - Endif - - if(b1(1).lt.1.e-5) then - - Do m=1,7 - - uwl=q4(m)-q3(m) - uwr=q3(m)-q2(m) - - u1(m)=0.5e0*(SIGN(one,uwl)+SIGN(one,uwr))* - & min(abs(uwl),abs(uwr)) - - Enddo - - Do m=1,7 - - qxl(i,m)=q3(m)-u1(m)*o2 - - Enddo - - if(abs(qxl(i,1)-q3(1)).ge.0.8e0*q3(1))then - - Do m=1,7 - - qxl(i,m)=q3(m) - - Enddo - - Endif - - Endif - - If(b2(1).lt.1.0e-5) then - - Do m=1,7 - - uwl=q4(m)-q3(m) - uwr=q3(m)-q2(m) - - u1(m)=0.5e0*(SIGN(one,uwl)+SIGN(one,uwr))* - & min(abs(uwl),abs(uwr)) - - Enddo - - Do m=1,7 - - qxr(i,m)=q3(m)+u1(m)*o2 - - Enddo - - If(abs(qxr(i,1)-q3(1)).ge.0.8e0*q3(1))then - - Do m=1,7 - - qxr(i,m)=q3(m) - - Enddo - - Endif - - Endif - - if(abs(q4(1)-q3(1))/max(q4(1),q3(1)).gt.0.8e0. - & and.dv2(i).lt.0.)then - - do m=1,7 - qxr(i,m)=q3(m) - enddo - - endif - - if(abs(q2(1)-q3(1))/max(q2(1),q3(1)).gt.0.8e0. - & and.dv1(i).lt.0.)then - - do m=1,7 - qxl(i,m)=q3(m) - enddo - - endif - - - Enddo - - Return - End +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + + Subroutine Monot(md,nx,dv1,dv2,qp,qm,qxl,qxr) + Implicit NONE + + External Xmedian + + Integer imd,md,nx,i,m + + ENZO_REAL q1(7),q2(7),q3(7),q4(7),q5(7) + ENZO_REAL qpl(7),qpr(7),vl(7),vr(7) + ENZO_REAL u1(7),u2(7),u3(7),u4(7),u5(7) + ENZO_REAL b1(7),b2(7),c1(7),c2(7) + ENZO_REAL ql(7,7),qr(7,7),uv(7) + ENZO_REAL qp(nx,7),qm(nx,7),qxl(nx,7),qxr(nx,7) + ENZO_REAL dv1(nx),dv2(nx) + + ENZO_REAL uwl,uwr,vx1,vx2,vx3,vx4,vx5,vl1,vr1,dml + ENZO_REAL dmr,dwl,dwr,sjn,sjm,sjx,sjy,uvr,uvl,Xmedian + + ENZO_REAL IS1,IS2,IS3,DELTA,WS1,WS2,WS3,WJ1,WJ2,WJ3 + ENZO_REAL AJ1,AJ2,AJ3,AJS,WM1,WM2,WM3 + + ENZO_REAL o2, o4, o6, o12 + + ENZO_REAL one + parameter (one = 1.0) + + o2 = 1.0E0 / 2.0E0 + o4 = 1.0E0 / 4.0E0 + o6 = 1.0E0 / 6.0E0 + o12 = 1.0E0 / 12.0E0 + +C ENZO_REAL VP1,VP2,VP3,VP4,VP5 + + Do i=1,Nx + Do m=1,7 + qxl(i,m)=0. + qxr(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-2 + + Do m=1,7 + Q1(m)=Qp(i-2,m) + Q2(m)=Qp(i-1,m) + Q3(m)=Qp(i, m) + Q4(m)=Qp(i+1,m) + Q5(m)=Qp(i+2,m) + Enddo + + Do m=1,7 + Qpl(m)=qm(i-1,m) + Qpr(m)=qm(i, m) + Enddo + + if(md.eq.1)CALL VECTLRx(q3,QL,QR,UV) + if(md.eq.2)CALL VECTLRy(q3,QL,QR,UV) + if(md.eq.3)CALL VECTLRz(q3,QL,QR,UV) + + CALL AMPLTD(QL, q1,u1) + CALL AMPLTD(QL, q2,u2) + CALL AMPLTD(QL, q3,u3) + CALL AMPLTD(QL, q4,u4) + CALL AMPLTD(QL, q5,u5) + CALL AMPLTD(QL,qpl,c1) + CALL AMPLTD(QL,qpr,c2) + +c Do m=1,7 +c c1(m)=(7.e0*(u2(m)+u3(m))-(u1(m)+u4(m)))*o12 +c c2(m)=(7.e0*(u3(m)+u4(m))-(u2(m)+u5(m)))*o12 +c enddo + + Do m=1,7 + + uwl = Xmedian(u3(m),c1(m),u2(m)) + uwr = Xmedian(u3(m),c2(m),u4(m)) + + b1(m) = Xmedian(u3(m),uwl,3.e0*u3(m)-2.e0*uwr) + b2(m) = Xmedian(u3(m),uwr,3.e0*u3(m)-2.e0*uwl) + + Enddo + + imd=0 + + Do m=1,7 + + if((b1(m)-c1(m))**2.gt.1e-12.or.(b2(m)-c2(m))**2. + & gt.1e-12) imd=1 + + enddo + + If(imd.eq.0)then + + CALL AMPLTD(QR,c2,b2) + + Do m=1,7 + qxr(i,m)=b2(m) + enddo + + CALL AMPLTD(QR,c1,b1) + + Do m=1,7 + qxl(i,m)=b1(m) + enddo + + Else + + do m=1,7 + + vx1=u1(m) + vx2=u2(m) + vx3=u3(m) + vx4=u4(m) + vx5=u5(m) + +C CALL W5RECM(vx1,vx2,vx3,vx4,vx5,VL1,VR1) + DELTA = ENZO_TINY + + WS1 = 0.1E0 + WS2 = 0.6E0 + WS3 = 0.3E0 + + + WJ1 = (11.E0*VX3 - 7.E0*VX2 + 2.E0*VX1)*o6 + WJ2 = (2.E0 *VX4 + 5.E0*VX3 - VX2)*o6 + WJ3 = ( -VX5 + 5.E0*VX4 + 2.E0*VX3)*o6 + + IS1 = 13.E0*o12*(VX3 - 2.E0*VX2 + VX1)**2 + & + (3.E0*VX3 - 4.E0*VX2 + VX1)**2*o4 + IS2 = 13.E0*o12*(VX4 - 2.E0*VX3 + VX2)**2 + & + (VX4 - VX2)**2*o4 + IS3 = 13.E0*o12*(VX5 - 2.E0*VX4 + VX3)**2 + & + (VX5 - 4.E0*VX4 + 3.E0*VX3)**2*o4 + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) + + WM1 = AJ1*AJS + WM2 = AJ2*AJS + WM3 = AJ3*AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1) / + $ (WS1*WS1 + WM1*(1.E0 - 2.E0*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2) / + $ (WS2*WS2 + WM2*(1.E0 - 2.E0*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3) / + $ (WS3*WS3 + WM3*(1.E0 - 2.E0*WS3)) + + AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) + + WM1 = AJ1*AJS + WM2 = AJ2*AJS + WM3 = AJ3*AJS + + VR1 = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + WJ1 = (11.E0*VX3 - 7.E0*VX4 + 2.E0*VX5)*o6 + WJ2 = (2.E0 *VX2 + 5.E0*VX3 - VX4)*o6 + WJ3 = ( -VX1 + 5.E0*VX2 + 2.E0*VX3)*o6 + + IS1 = 13.E0*o12*(VX3 - 2.E0*VX4 + VX5)**2 + & + (3.E0*VX3 - 4.E0*VX4 + VX5)**2*o4 + IS2 = 13.E0*o12*(VX2 - 2.E0*VX3 + VX4)**2 + & + (VX2 - VX4)**2*o4 + IS3 = 13.E0*o12*(VX1 - 2.E0*VX2 + VX3)**2 + & + (VX1 - 4.E0*VX2 + 3.E0*VX3)**2*o4 + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) + + WM1 = AJ1*AJS + WM2 = AJ2*AJS + WM3 = AJ3*AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1) / + $ (WS1*WS1 + WM1*(1.E0 - 2.E0*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2) / + $ (WS2*WS2 + WM2*(1.E0 - 2.E0*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3) / + $ (WS3*WS3 + WM3*(1.E0 - 2.E0*WS3)) + + AJS = 1.E0/(AJ1 + AJ2 +AJ3 ) + + WM1 = AJ1*AJS + WM2 = AJ2*AJS + WM3 = AJ3*AJS + + VL1 = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + vl(m)=vl1 + vr(m)=vr1 + + enddo + + Do m=1,7 + + If((b1(m)-u3(m))**2.lt.1e-12.and.(b2(m)-u3(m))**2. + & lt.1.e-12)then + + dml = Xmedian(u3(m),vl(m),c1(m)) + dmr = Xmedian(u3(m),vr(m),c2(m)) + + dwl = Xmedian(u3(m),dml,u2(m)) + dwr = Xmedian(u3(m),dmr,u4(m)) + + uwl = Xmedian(u3(m),3.e0*u3(m)-2.e0*dwr,dml) + uwr = Xmedian(u3(m),3.e0*u3(m)-2.e0*dwl,dmr) + + c1(m) = Xmedian(uwl,dml,c1(m)) + c2(m) = Xmedian(uwr,dmr,c2(m)) + + Else + + sjn = 0.5e0*(u4(m)-u2(m)) + sjm = 2.e0*Xmedian(0.,u4(m)-u3(m),u3(m)-u2(m)) + sjx = Xmedian(0.,sjn,sjm) + + sjn = 0.5e0*(u5(m)-u3(m)) + sjm = 2.e0*Xmedian(0.,u5(m)-u4(m),u4(m)-u3(m)) + sjy = Xmedian(0.,sjn,sjm) + + dwr = 0.5e0*(u3(m)+u4(m))-(sjy-sjx)/6.e0 + + sjn = 0.5e0*(u2(m)-u4(m)) + sjm = 2.e0*Xmedian(0.,u2(m)-u3(m),u3(m)-u4(m)) + sjx = Xmedian(0.,sjn,sjm) + + sjn = 0.5e0*(u1(m)-u3(m)) + sjm = 2.e0*Xmedian(0.,u1(m)-u2(m),u2(m)-u3(m)) + sjy = Xmedian(0.,sjn,sjm) + + dwl = 0.5e0*(u3(m)+u2(m))-(sjy-sjx)/6.e0 + + uwr = Xmedian(dwr,vr(m),c2(m)) + uwl = Xmedian(dwl,vl(m),c1(m)) + + dmr = Xmedian(u3(m),uwr,u4(m)) + dml = Xmedian(u3(m),uwl,u2(m)) + + uvr = Xmedian(u3(m),3.e0*u3(m)-2.e0*dml,dmr) + uvl = Xmedian(u3(m),3.e0*u3(m)-2.e0*dmr,dml) + + c1(m) = Xmedian(uvl,vl(m),c1(m)) + c2(m) = Xmedian(uvr,vr(m),c2(m)) + + Endif + + Enddo + + CALL AMPLTD(QR,c2,b2) + + Do m=1,7 + qxr(i,m)=b2(m) + enddo + + CALL AMPLTD(QR,c1,b1) + + Do m=1,7 + qxl(i,m)=b1(m) + enddo + + Endif + + if(b1(1).lt.1.e-5) then + + Do m=1,7 + + uwl=q4(m)-q3(m) + uwr=q3(m)-q2(m) + + u1(m)=0.5e0*(SIGN(one,uwl)+SIGN(one,uwr))* + & min(abs(uwl),abs(uwr)) + + Enddo + + Do m=1,7 + + qxl(i,m)=q3(m)-u1(m)*o2 + + Enddo + + if(abs(qxl(i,1)-q3(1)).ge.0.8e0*q3(1))then + + Do m=1,7 + + qxl(i,m)=q3(m) + + Enddo + + Endif + + Endif + + If(b2(1).lt.1.0e-5) then + + Do m=1,7 + + uwl=q4(m)-q3(m) + uwr=q3(m)-q2(m) + + u1(m)=0.5e0*(SIGN(one,uwl)+SIGN(one,uwr))* + & min(abs(uwl),abs(uwr)) + + Enddo + + Do m=1,7 + + qxr(i,m)=q3(m)+u1(m)*o2 + + Enddo + + If(abs(qxr(i,1)-q3(1)).ge.0.8e0*q3(1))then + + Do m=1,7 + + qxr(i,m)=q3(m) + + Enddo + + Endif + + Endif + + if(abs(q4(1)-q3(1))/max(q4(1),q3(1)).gt.0.8e0. + & and.dv2(i).lt.0.)then + + do m=1,7 + qxr(i,m)=q3(m) + enddo + + endif + + if(abs(q2(1)-q3(1))/max(q2(1),q3(1)).gt.0.8e0. + & and.dv1(i).lt.0.)then + + do m=1,7 + qxl(i,m)=q3(m) + enddo + + endif + + + Enddo + + Return + End diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokx.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokx.F index 021c2b968e..f7c3834a27 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokx.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokx.F @@ -1,320 +1,320 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine POTOKx(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdy,Qdz,Qrp,Fm) - Implicit NONE - - Integer nx,i,m,l - - ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdy(Nx,7),Qdz(Nx,7) - ENZO_REAL Qrp(Nx,7),Fm(Nx,7) - - ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) - ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) - ENZO_REAL sl(7),qul(7),qur(7),tl(7) - ENZO_REAL tr(7),fr(7),ur(7),qv(7) - ENZO_REAL udy(7),udz(7),ay(7,7),az(7,7),av(7) - ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdy(7),tdz(7) - ENZO_REAL DT,DX,DTX,DXI,TL5 - - Do i=1,Nx - Do m=1,7 - qrp(i,m)=0. - fm(i,m)=0. - Enddo - Enddo - - Do i=3,Nx-3 - - Do m=1,7 - - Qvl(m)=Qlx(i,m) - Qvr(m)=Qrx(i,m) - Qp(m)=Qpm(i,m) - Udy(m)=Qdy(i,m) - Udz(m)=Qdz(i,m) - - Tvl(m)=Qlx(i+1,m) - Tvr(m)=Qrx(i+1,m) - Tp(m)=Qpm(i+1,m) - Tdy(m)=Qdy(i+1,m) - Tdz(m)=Qdz(i+1,m) - - Enddo - - DTX=DT/DX - - CALL VECTEGx(QP,QC) - CALL VECTEGx(TP,TC) - - IF(QC(7).GT.0.)THEN - - DXI=QC(7)*DTX - - CALL FPML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRX(QP,QL,QR,UV) - CALL MATR_AY(QP,AY) - CALL MATR_AZ(QP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=QC(M)*DTX - - CALL FPML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,VM) - - CALL VECTLRX(TP,QL,QR,UV) - CALL MATR_AY(TP,AY) - CALL MATR_AZ(TP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - do M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - enddo - - TL5=0.5d0*(TL(5)+TR(5)) - - TL(5)=TL5 - TR(5)=TL5 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDx(PX,VL,FR,UR) !HLLD method - - Do M=1,7 - Fm(I,M)=FR(M) - Enddo - - - - - - - - IF(QC(7).GT.0.)THEN - - DXI=1.-QC(7)*DTX - - CALL FQML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRX(QP,QL,QR,UV) - CALL MATR_AY(QP,AY) - CALL MATR_AZ(QP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=1.-QC(M)*DTX - - CALL FQML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=QP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FQML(DXI,TVL,TVR,TP,VM) - - CALL VECTLRX(TP,QL,QR,UV) - CALL MATR_AY(TP,AY) - CALL MATR_AZ(TP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FQML(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=TP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - - DO M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - ENDDO - - TL5=0.5d0*(TL(5)+TR(5)) - - TL(5)=TL5 - TR(5)=TL5 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDx(PX,VL,FR,UR) !HLLD method - - - CALL PRIM(UR,PX) - - DO M=1,7 - QRP(I,M)=PX(M) - ENDDO - - Enddo - - Return - End +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine POTOKx(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdy,Qdz,Qrp,Fm) + Implicit NONE + + Integer nx,i,m,l + + ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdy(Nx,7),Qdz(Nx,7) + ENZO_REAL Qrp(Nx,7),Fm(Nx,7) + + ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) + ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) + ENZO_REAL sl(7),qul(7),qur(7),tl(7) + ENZO_REAL tr(7),fr(7),ur(7),qv(7) + ENZO_REAL udy(7),udz(7),ay(7,7),az(7,7),av(7) + ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdy(7),tdz(7) + ENZO_REAL DT,DX,DTX,DXI,TL5 + + Do i=1,Nx + Do m=1,7 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-3 + + Do m=1,7 + + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udy(m)=Qdy(i,m) + Udz(m)=Qdz(i,m) + + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdy(m)=Qdy(i+1,m) + Tdz(m)=Qdz(i+1,m) + + Enddo + + DTX=DT/DX + + CALL VECTEGx(QP,QC) + CALL VECTEGx(TP,TC) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRX(QP,QL,QR,UV) + CALL MATR_AY(QP,AY) + CALL MATR_AZ(QP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,VM) + + CALL VECTLRX(TP,QL,QR,UV) + CALL MATR_AY(TP,AY) + CALL MATR_AZ(TP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + do M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + enddo + + TL5=0.5d0*(TL(5)+TR(5)) + + TL(5)=TL5 + TR(5)=TL5 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDx(PX,VL,FR,UR) !HLLD method + + Do M=1,7 + Fm(I,M)=FR(M) + Enddo + + + + + + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRX(QP,QL,QR,UV) + CALL MATR_AY(QP,AY) + CALL MATR_AZ(QP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AY(M,L)*UDy(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=QP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML(DXI,TVL,TVR,TP,VM) + + CALL VECTLRX(TP,QL,QR,UV) + CALL MATR_AY(TP,AY) + CALL MATR_AZ(TP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AY(M,L)*TDy(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=TP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + + DO M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL5=0.5d0*(TL(5)+TR(5)) + + TL(5)=TL5 + TR(5)=TL5 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDx(PX,VL,FR,UR) !HLLD method + + + CALL PRIM(UR,PX) + + DO M=1,7 + QRP(I,M)=PX(M) + ENDDO + + Enddo + + Return + End diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potoky.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potoky.F index 0aa10dc2e8..f2e134b6da 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potoky.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potoky.F @@ -1,319 +1,319 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine POTOKy(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdx,Qdz,Qrp,Fm) - Implicit NONE - Integer nx,i,m,l - - ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdx(Nx,7),Qdz(Nx,7) - ENZO_REAL Qrp(Nx,7),Fm(Nx,7) - - ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) - ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) - ENZO_REAL sl(7),qul(7),qur(7),tl(7) - ENZO_REAL tr(7),fr(7),ur(7),qv(7) - ENZO_REAL udx(7),udz(7),ax(7,7),az(7,7),av(7) - ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdx(7),tdz(7) - ENZO_REAL DT,DX,DTX,DXI,TL6 - - Do i=1,Nx - Do m=1,7 - qrp(i,m)=0. - fm(i,m)=0. - Enddo - Enddo - - Do i=3,Nx-3 - - Do m=1,7 - - Qvl(m)=Qlx(i,m) - Qvr(m)=Qrx(i,m) - Qp(m)=Qpm(i,m) - Udx(m)=Qdx(i,m) - Udz(m)=Qdz(i,m) - - Tvl(m)=Qlx(i+1,m) - Tvr(m)=Qrx(i+1,m) - Tp(m)=Qpm(i+1,m) - Tdx(m)=Qdx(i+1,m) - Tdz(m)=Qdz(i+1,m) - - Enddo - - DTX=DT/DX - - CALL VECTEGy(Qp,Qc) - CALL VECTEGy(Tp,Tc) - - IF(QC(7).GT.0.)THEN - - DXI=QC(7)*DTX - - CALL FPML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRY(QP,QL,QR,UV) - CALL MATR_AX(QP,AX) - CALL MATR_AZ(QP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=QC(M)*DTX - - CALL FPML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,VM) - - CALL VECTLRY(TP,QL,QR,UV) - CALL MATR_AX(TP,AX) - CALL MATR_AZ(TP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDZ(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - DO M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - ENDDO - - TL6=0.5d0*(TL(6)+TR(6)) - - TL(6)=TL6 - TR(6)=TL6 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDy(PX,VL,FR,UR) !HLLD method - - DO M=1,7 - FM(I,M)=FR(M) - ENDDO - - - - - - - - IF(QC(7).GT.0.)THEN - - DXI=1.-QC(7)*DTX - - CALL FQML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRY(QP,QL,QR,UV) - CALL MATR_AX(QP,AX) - CALL MATR_AZ(QP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=1.-QC(M)*DTX - - CALL FQML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=QP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FQML(DXI,TVL,TVR,TP,VM) - - CALL VECTLRY(TP,QL,QR,UV) - CALL MATR_AX(TP,AX) - CALL MATR_AZ(TP,AZ) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDz(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FQML(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=TP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - DO M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - ENDDO - - TL6=0.5d0*(TL(6)+TR(6)) - - TL(6)=TL6 - TR(6)=TL6 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDy(PX,VL,FR,UR) !HLLD method - - - CALL PRIM(UR,PX) - - DO M=1,7 - QRP(I,M)=PX(M) - ENDDO - - ENDDO - - return - end +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine POTOKy(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdx,Qdz,Qrp,Fm) + Implicit NONE + Integer nx,i,m,l + + ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdx(Nx,7),Qdz(Nx,7) + ENZO_REAL Qrp(Nx,7),Fm(Nx,7) + + ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) + ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) + ENZO_REAL sl(7),qul(7),qur(7),tl(7) + ENZO_REAL tr(7),fr(7),ur(7),qv(7) + ENZO_REAL udx(7),udz(7),ax(7,7),az(7,7),av(7) + ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdx(7),tdz(7) + ENZO_REAL DT,DX,DTX,DXI,TL6 + + Do i=1,Nx + Do m=1,7 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + Do i=3,Nx-3 + + Do m=1,7 + + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udx(m)=Qdx(i,m) + Udz(m)=Qdz(i,m) + + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdx(m)=Qdx(i+1,m) + Tdz(m)=Qdz(i+1,m) + + Enddo + + DTX=DT/DX + + CALL VECTEGy(Qp,Qc) + CALL VECTEGy(Tp,Tc) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRY(QP,QL,QR,UV) + CALL MATR_AX(QP,AX) + CALL MATR_AZ(QP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,VM) + + CALL VECTLRY(TP,QL,QR,UV) + CALL MATR_AX(TP,AX) + CALL MATR_AZ(TP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDZ(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL6=0.5d0*(TL(6)+TR(6)) + + TL(6)=TL6 + TR(6)=TL6 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDy(PX,VL,FR,UR) !HLLD method + + DO M=1,7 + FM(I,M)=FR(M) + ENDDO + + + + + + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRY(QP,QL,QR,UV) + CALL MATR_AX(QP,AX) + CALL MATR_AZ(QP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AZ(M,L)*UDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=QP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML(DXI,TVL,TVR,TP,VM) + + CALL VECTLRY(TP,QL,QR,UV) + CALL MATR_AX(TP,AX) + CALL MATR_AZ(TP,AZ) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AZ(M,L)*TDz(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=TP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL6=0.5d0*(TL(6)+TR(6)) + + TL(6)=TL6 + TR(6)=TL6 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDy(PX,VL,FR,UR) !HLLD method + + + CALL PRIM(UR,PX) + + DO M=1,7 + QRP(I,M)=PX(M) + ENDDO + + ENDDO + + return + end diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokz.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokz.F index 09748a9680..00d11bb4b1 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokz.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_potokz.F @@ -1,317 +1,317 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - Subroutine POTOKz(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdx,Qdy,Qrp,Fm) - Implicit NONE - Integer nx,i,m,l - ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdx(Nx,7),Qdy(Nx,7) - ENZO_REAL Qrp(Nx,7),Fm(Nx,7) - - ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) - ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) - ENZO_REAL sl(7),qul(7),qur(7),tl(7) - ENZO_REAL tr(7),fr(7),ur(7),qv(7) - ENZO_REAL udx(7),udy(7),ay(7,7),ax(7,7),av(7) - ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdx(7),tdy(7) - ENZO_REAL DT,DX,DTX,DXI,TL7 - - Do i=1,Nx - Do m=1,7 - qrp(i,m)=0. - fm(i,m)=0. - Enddo - Enddo - - DO i=3,Nx-3 - - Do m=1,7 - - Qvl(m)=Qlx(i,m) - Qvr(m)=Qrx(i,m) - Qp(m)=Qpm(i,m) - Udx(m)=Qdx(i,m) - Udy(m)=Qdy(i,m) - - Tvl(m)=Qlx(i+1,m) - Tvr(m)=Qrx(i+1,m) - Tp(m)=Qpm(i+1,m) - Tdx(m)=Qdx(i+1,m) - Tdy(m)=Qdy(i+1,m) - - Enddo - - DTX=DT/DX - - CALL VECTEGz(Qp,Qc) - CALL VECTEGz(Tp,Tc) - - IF(QC(7).GT.0.)THEN - - DXI=QC(7)*DTX - - CALL FPML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRZ(QP,QL,QR,UV) - CALL MATR_AX(QP,AX) - CALL MATR_AY(QP,AY) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=QC(M)*DTX - - CALL FPML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,VM) - - CALL VECTLRZ(TP,QL,QR,UV) - CALL MATR_AX(TP,AX) - CALL MATR_AY(TP,AY) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FPMR(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=VM(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - DO M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - ENDDO - - TL7=0.5d0*(TL(7)+TR(7)) - - TL(7)=TL7 - TR(7)=TL7 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDz(PX,VL,FR,UR) !HLLD method - - - DO M=1,7 - FM(I,M)=FR(M) - ENDDO - - - - - - - - IF(QC(7).GT.0.)THEN - - DXI=1.-QC(7)*DTX - - CALL FQML(DXI,QVL,QVR,QP,VM) - - CALL VECTLRZ(QP,QL,QR,UV) - CALL MATR_AX(QP,AX) - CALL MATR_AY(QP,AY) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(QC(M).GT.0.)THEN - - DXI=1.-QC(M)*DTX - - CALL FQML(DXI,QVL,QVR,QP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUL(M)=QP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUL(M)=QVR(M) - ENDDO - - ENDIF - - IF(TC(1).LT.0.)THEN - - DXI=-TC(1)*DTX - - CALL FQML(DXI,TVL,TVR,TP,VM) - - CALL VECTLRZ(TP,QL,QR,UV) - CALL MATR_AX(TP,AX) - CALL MATR_AY(TP,AY) - - DO L=1,7 - VL(L)=0. - ENDDO - - DO M=1,7 - AV(M)=0. - DO L=1,7 - AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) - ENDDO - AV(M)=AV(M)*DTX/2. - ENDDO - - DO M=1,7 - - IF(TC(M).LT.0.)THEN - - DXI=-TC(M)*DTX - - CALL FQML(DXI,TVL,TVR,TP,QV) - - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) - ENDDO - - DO L=1,7 - VL(L)=VL(L)+QR(L,M)*SL(M) - ENDDO - - ENDIF - - ENDDO - - DO M=1,7 - QUR(M)=TP(M)-VL(M) - ENDDO - - ELSE - - DO M=1,7 - QUR(M)=TVL(M) - ENDDO - - ENDIF - - DO M=1,7 - TL(M)=QUL(M) - TR(M)=QUR(M) - ENDDO - - TL7=0.5d0*(TL(7)+TR(7)) - - TL(7)=TL7 - TR(7)=TL7 - - CALL CONS(TL,PX) - CALL CONS(TR,VL) - CALL HLLDz(PX,VL,FR,UR) !HLLD method - - CALL PRIM(UR,PX) - - DO M=1,7 - QRP(I,M)=PX(M) - ENDDO - - ENDDO - - return - end +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + Subroutine POTOKz(Nx,Dx,Dt,Qlx,Qrx,Qpm,Qdx,Qdy,Qrp,Fm) + Implicit NONE + Integer nx,i,m,l + ENZO_REAL Qlx(Nx,7),Qrx(Nx,7),Qpm(Nx,7),Qdx(Nx,7),Qdy(Nx,7) + ENZO_REAL Qrp(Nx,7),Fm(Nx,7) + + ENZO_REAL qp(7),px(7),qc(7),qvl(7),qvr(7) + ENZO_REAL vm(7),ql(7,7),qr(7,7),uv(7),vl(7) + ENZO_REAL sl(7),qul(7),qur(7),tl(7) + ENZO_REAL tr(7),fr(7),ur(7),qv(7) + ENZO_REAL udx(7),udy(7),ay(7,7),ax(7,7),av(7) + ENZO_REAL tvl(7),tvr(7),tp(7),tc(7),tdx(7),tdy(7) + ENZO_REAL DT,DX,DTX,DXI,TL7 + + Do i=1,Nx + Do m=1,7 + qrp(i,m)=0. + fm(i,m)=0. + Enddo + Enddo + + DO i=3,Nx-3 + + Do m=1,7 + + Qvl(m)=Qlx(i,m) + Qvr(m)=Qrx(i,m) + Qp(m)=Qpm(i,m) + Udx(m)=Qdx(i,m) + Udy(m)=Qdy(i,m) + + Tvl(m)=Qlx(i+1,m) + Tvr(m)=Qrx(i+1,m) + Tp(m)=Qpm(i+1,m) + Tdx(m)=Qdx(i+1,m) + Tdy(m)=Qdy(i+1,m) + + Enddo + + DTX=DT/DX + + CALL VECTEGz(Qp,Qc) + CALL VECTEGz(Tp,Tc) + + IF(QC(7).GT.0.)THEN + + DXI=QC(7)*DTX + + CALL FPML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRZ(QP,QL,QR,UV) + CALL MATR_AX(QP,AX) + CALL MATR_AY(QP,AY) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=QC(M)*DTX + + CALL FPML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,VM) + + CALL VECTLRZ(TP,QL,QR,UV) + CALL MATR_AX(TP,AX) + CALL MATR_AY(TP,AY) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FPMR(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(VM(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=VM(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL7=0.5d0*(TL(7)+TR(7)) + + TL(7)=TL7 + TR(7)=TL7 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDz(PX,VL,FR,UR) !HLLD method + + + DO M=1,7 + FM(I,M)=FR(M) + ENDDO + + + + + + + + IF(QC(7).GT.0.)THEN + + DXI=1.-QC(7)*DTX + + CALL FQML(DXI,QVL,QVR,QP,VM) + + CALL VECTLRZ(QP,QL,QR,UV) + CALL MATR_AX(QP,AX) + CALL MATR_AY(QP,AY) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*UDX(L)+AY(M,L)*UDY(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(QC(M).GT.0.)THEN + + DXI=1.-QC(M)*DTX + + CALL FQML(DXI,QVL,QVR,QP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(QP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUL(M)=QP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUL(M)=QVR(M) + ENDDO + + ENDIF + + IF(TC(1).LT.0.)THEN + + DXI=-TC(1)*DTX + + CALL FQML(DXI,TVL,TVR,TP,VM) + + CALL VECTLRZ(TP,QL,QR,UV) + CALL MATR_AX(TP,AX) + CALL MATR_AY(TP,AY) + + DO L=1,7 + VL(L)=0. + ENDDO + + DO M=1,7 + AV(M)=0. + DO L=1,7 + AV(M)=AV(M)+AX(M,L)*TDX(L)+AY(M,L)*TDY(L) + ENDDO + AV(M)=AV(M)*DTX/2. + ENDDO + + DO M=1,7 + + IF(TC(M).LT.0.)THEN + + DXI=-TC(M)*DTX + + CALL FQML(DXI,TVL,TVR,TP,QV) + + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*(TP(L)-QV(L)+AV(L)) + ENDDO + + DO L=1,7 + VL(L)=VL(L)+QR(L,M)*SL(M) + ENDDO + + ENDIF + + ENDDO + + DO M=1,7 + QUR(M)=TP(M)-VL(M) + ENDDO + + ELSE + + DO M=1,7 + QUR(M)=TVL(M) + ENDDO + + ENDIF + + DO M=1,7 + TL(M)=QUL(M) + TR(M)=QUR(M) + ENDDO + + TL7=0.5d0*(TL(7)+TR(7)) + + TL(7)=TL7 + TR(7)=TL7 + + CALL CONS(TL,PX) + CALL CONS(TR,VL) + CALL HLLDz(PX,VL,FR,UR) !HLLD method + + CALL PRIM(UR,PX) + + DO M=1,7 + QRP(I,M)=PX(M) + ENDDO + + ENDDO + + return + end diff --git a/src/Enzo/hydro-mhd/ppml_fortran/PPML_sub.F b/src/Enzo/hydro-mhd/ppml_fortran/PPML_sub.F index e27ba5f32d..704f065e36 100644 --- a/src/Enzo/hydro-mhd/ppml_fortran/PPML_sub.F +++ b/src/Enzo/hydro-mhd/ppml_fortran/PPML_sub.F @@ -1,1482 +1,1482 @@ -c See LICENSE_PPML file for license and copyright information - -#include "fortran.h" - - SUBROUTINE VECTLRx(QU,QL,QR,U) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) - ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,CA,BXX,BYZ,SBB,BMG,GPP,GPB - ENZO_REAL ASS,AS,AF,BY,BZ,BSGN,CD2 - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - X22=1.e0/sqrt(2.e0) - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=a2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAX - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - CA=abs(BVX) - - BXX=QU(5)**2 - BYZ=QU(6)**2+QU(7)**2 - SBB=sqrt(BYZ) - BMG=BXX+BYZ - GPP=a2*QU(1) - GPB=abs(GPP-BXX) - - IF(BYZ.GT.DLT*BMG) THEN - - ASS=sqrt(CWH**2+4.e0*CKV*(VAY+VAZ)) - AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) - AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) - - BY=QU(6)/SBB - BZ=QU(7)/SBB - - - ELSE - - IF(GPB.GT.DLT*GPP) THEN - AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) - AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) - CS=sqrt(abs((CKV+VAX-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAX+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - AS=X22 - AF=X22 - CS=CSR - CF=CSR - ENDIF - - BY=X22 - BZ=X22 - - ENDIF - - BSGN=SIGN(one,QU(5)) - CD2=2.e0*CKV - - QL(1,1)=AF/2.e0 - QL(1,2)=-QU(1)*AF*CF/CD2 - QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 - QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 - QL(1,5)=0. - QL(1,6)=SK1*CSR*AS*BY/CD2 - QL(1,7)=SK1*CSR*AS*BZ/CD2 - - QL(2,1)=0. - QL(2,2)=0. - QL(2,3)=-QU(1)*BZ*BSGN/2.e0 - QL(2,4)=QU(1)*BY*BSGN/2.e0 - QL(2,5)=0. - QL(2,6)=-SK1*BZ/2.e0 - QL(2,7)=SK1*BY/2.e0 - - QL(3,1)=AS/2.e0 - QL(3,2)=-QU(1)*AS*CS/CD2 - QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 - QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 - QL(3,5)=0. - QL(3,6)=-SK1*CSR*AF*BY/CD2 - QL(3,7)=-SK1*CSR*AF*BZ/CD2 - - QL(4,1)=0. - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=0. - QL(4,5)=1.e0 - QL(4,6)=0. - QL(4,7)=0. - - QL(5,1)=AS/2.e0 - QL(5,2)=QU(1)*AS*CS/CD2 - QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 - QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 - QL(5,5)=0. - QL(5,6)=-SK1*CSR*AF*BY/CD2 - QL(5,7)=-SK1*CSR*AF*BZ/CD2 - - QL(6,1)=0. - QL(6,2)=0. - QL(6,3)=-QU(1)*BZ*BSGN/2.e0 - QL(6,4)=QU(1)*BY*BSGN/2.e0 - QL(6,5)=0. - QL(6,6)=SK1*BZ/2.e0 - QL(6,7)=-SK1*BY/2.e0 - - QL(7,1)=AF/2.e0 - QL(7,2)=QU(1)*AF*CF/CD2 - QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 - QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 - QL(7,5)=0. - QL(7,6)=SK1*CSR*AS*BY/CD2 - QL(7,7)=SK1*CSR*AS*BZ/CD2 - - - QR(1,1)=AF - QR(1,2)=0. - QR(1,3)=AS - QR(1,4)=0. - QR(1,5)=AS - QR(1,6)=0. - QR(1,7)=AF - - QR(2,1)=-AF*CF/QU(1) - QR(2,2)=0. - QR(2,3)=-AS*CS/QU(1) - QR(2,4)=0. - QR(2,5)=AS*CS/QU(1) - QR(2,6)=0. - QR(2,7)=AF*CF/QU(1) - - QR(3,1)=AS*CS*BY*BSGN/QU(1) - QR(3,2)=-BZ*BSGN/QU(1) - QR(3,3)=-AF*CF*BY*BSGN/QU(1) - QR(3,4)=0. - QR(3,5)=AF*CF*BY*BSGN/QU(1) - QR(3,6)=-BZ*BSGN/QU(1) - QR(3,7)=-AS*CS*BY*BSGN/QU(1) - - QR(4,1)=AS*CS*BZ*BSGN/QU(1) - QR(4,2)=BY*BSGN/QU(1) - QR(4,3)=-AF*CF*BZ*BSGN/QU(1) - QR(4,4)=0. - QR(4,5)=AF*CF*BZ*BSGN/QU(1) - QR(4,6)=BY*BSGN/QU(1) - QR(4,7)=-AS*CS*BZ*BSGN/QU(1) - - QR(5,1)=0. - QR(5,2)=0. - QR(5,3)=0. - QR(5,4)=1.e0 - QR(5,5)=0. - QR(5,6)=0. - QR(5,7)=0. - - QR(6,1)=AS*BY*CSR/SK1 - QR(6,2)=-BZ/SK1 - QR(6,3)=-AF*BY*CSR/SK1 - QR(6,4)=0. - QR(6,5)=-AF*BY*CSR/SK1 - QR(6,6)=BZ/SK1 - QR(6,7)=AS*BY*CSR/SK1 - - QR(7,1)=AS*BZ*CSR/SK1 - QR(7,2)=BY/SK1 - QR(7,3)=-AF*BZ*CSR/SK1 - QR(7,4)=0. - QR(7,5)=-AF*BZ*CSR/SK1 - QR(7,6)=-BY/SK1 - QR(7,7)=AS*BZ*CSR/SK1 - - - U(1)=QU(2)-CF - U(2)=QU(2)-CA - U(3)=QU(2)-CS - U(4)=QU(2) - U(5)=QU(2)+CS - U(6)=QU(2)+CA - U(7)=QU(2)+CF - - RETURN - END - - SUBROUTINE VECTLRy(QU,QL,QR,U) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) - ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB - ENZO_REAL ASS,AS,AF,BX,BZ,BSGN,CD2 - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - X22=1.e0/sqrt(2.e0) - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=A2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAY - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - CA=abs(BVY) - - BYY=QU(6)**2 - BXZ=QU(5)**2+QU(7)**2 - SBB=sqrt(BXZ) - BMG=BYY+BXZ - GPP=A2*QU(1) - GPB=abs(GPP-BYY) - - IF(BXZ.GT.DLT*BMG) THEN - - ASS=sqrt(CWH**2+4.e0*CKV*(VAX+VAZ)) - AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) - AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) - - BX=QU(5)/SBB - BZ=QU(7)/SBB - - ELSE - - IF(GPB.GT.DLT*GPP) THEN - AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) - AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) - CS=sqrt(abs((CKV+VAY-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAY+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - AS=X22 - AF=X22 - CS=CSR - CF=CSR - ENDIF - - BX=X22 - BZ=X22 - - ENDIF - - BSGN=SIGN(one,QU(6)) - CD2=2.e0*CKV - - QL(1,1)=AF/2.e0 - QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 - QL(1,3)=-QU(1)*AF*CF/CD2 - QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 - QL(1,5)=SK1*CSR*AS*BX/CD2 - QL(1,6)=0. - QL(1,7)=SK1*CSR*AS*BZ/CD2 - - QL(2,1)=0. - QL(2,2)=-QU(1)*BZ*BSGN/2.e0 - QL(2,3)=0. - QL(2,4)=QU(1)*BX*BSGN/2.e0 - QL(2,5)=-SK1*BZ/2.e0 - QL(2,6)=0. - QL(2,7)=SK1*BX/2.e0 - - QL(3,1)=AS/2.e0 - QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 - QL(3,3)=-QU(1)*AS*CS/CD2 - QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 - QL(3,5)=-SK1*CSR*AF*BX/CD2 - QL(3,6)=0. - QL(3,7)=-SK1*CSR*AF*BZ/CD2 - - QL(4,1)=0. - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=0. - QL(4,5)=0. - QL(4,6)=1.e0 - QL(4,7)=0. - - QL(5,1)=AS/2.e0 - QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 - QL(5,3)=QU(1)*AS*CS/CD2 - QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 - QL(5,5)=-SK1*CSR*AF*BX/CD2 - QL(5,6)=0. - QL(5,7)=-SK1*CSR*AF*BZ/CD2 - - QL(6,1)=0. - QL(6,2)=-QU(1)*BZ*BSGN/2.e0 - QL(6,3)=0. - QL(6,4)=QU(1)*BX*BSGN/2.e0 - QL(6,5)=SK1*BZ/2.e0 - QL(6,6)=0. - QL(6,7)=-SK1*BX/2.e0 - - QL(7,1)=AF/2.e0 - QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 - QL(7,3)=QU(1)*AF*CF/CD2 - QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 - QL(7,5)=SK1*CSR*AS*BX/CD2 - QL(7,6)=0. - QL(7,7)=SK1*CSR*AS*BZ/CD2 - - QR(1,1)=AF - QR(1,2)=0. - QR(1,3)=AS - QR(1,4)=0. - QR(1,5)=AS - QR(1,6)=0. - QR(1,7)=AF - - QR(2,1)=AS*CS*BX*BSGN/QU(1) - QR(2,2)=-BZ*BSGN/QU(1) - QR(2,3)=-AF*CF*BX*BSGN/QU(1) - QR(2,4)=0. - QR(2,5)=AF*CF*BX*BSGN/QU(1) - QR(2,6)=-BZ*BSGN/QU(1) - QR(2,7)=-AS*CS*BX*BSGN/QU(1) - - QR(3,1)=-AF*CF/QU(1) - QR(3,2)=0. - QR(3,3)=-AS*CS/QU(1) - QR(3,4)=0. - QR(3,5)=AS*CS/QU(1) - QR(3,6)=0. - QR(3,7)=AF*CF/QU(1) - - QR(4,1)=AS*CS*BZ*BSGN/QU(1) - QR(4,2)=BX*BSGN/QU(1) - QR(4,3)=-AF*CF*BZ*BSGN/QU(1) - QR(4,4)=0. - QR(4,5)=AF*CF*BZ*BSGN/QU(1) - QR(4,6)=BX*BSGN/QU(1) - QR(4,7)=-AS*CS*BZ*BSGN/QU(1) - - QR(5,1)=AS*BX*CSR/SK1 - QR(5,2)=-BZ/SK1 - QR(5,3)=-AF*BX*CSR/SK1 - QR(5,4)=0. - QR(5,5)=-AF*BX*CSR/SK1 - QR(5,6)=BZ/SK1 - QR(5,7)=AS*BX*CSR/SK1 - - QR(6,1)=0. - QR(6,2)=0. - QR(6,3)=0. - QR(6,4)=1.e0 - QR(6,5)=0. - QR(6,6)=0. - QR(6,7)=0. - - QR(7,1)=AS*BZ*CSR/SK1 - QR(7,2)=BX/SK1 - QR(7,3)=-AF*BZ*CSR/SK1 - QR(7,4)=0. - QR(7,5)=-AF*BZ*CSR/SK1 - QR(7,6)=-BX/SK1 - QR(7,7)=AS*BZ*CSR/SK1 - - - U(1)=QU(3)-CF - U(2)=QU(3)-CA - U(3)=QU(3)-CS - U(4)=QU(3) - U(5)=QU(3)+CS - U(6)=QU(3)+CA - U(7)=QU(3)+CF - - RETURN - END - - SUBROUTINE VECTLRz(QU,QL,QR,U) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) - ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB - ENZO_REAL ASS,AS,AF,BX,BY,BSGN,CD2 - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - X22=1.e0/sqrt(2.e0) - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=A2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAZ - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - CA=abs(BVZ) - - BYY=QU(7)**2 - BXZ=QU(5)**2+QU(6)**2 - SBB=sqrt(BXZ) - BMG=BYY+BXZ - GPP=A2*QU(1) - GPB=abs(GPP-BYY) - - IF(BXZ.GT.DLT*BMG) THEN - - ASS=sqrt(CWH**2+4.e0*CKV*(VAX+VAY)) - AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) - AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) - - BX=QU(5)/SBB - BY=QU(6)/SBB - - ELSE - - IF(GPB.GT.DLT*GPP) THEN - AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) - AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) - CS=sqrt(abs((CKV+VAZ-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAZ+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - AS=X22 - AF=X22 - CS=CSR - CF=CSR - ENDIF - - BX=X22 - BY=X22 - - ENDIF - - BSGN=SIGN(one,QU(7)) - CD2=2.e0*CKV - - QL(1,1)=AF/2.e0 - QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 - QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 - QL(1,4)=-QU(1)*AF*CF/CD2 - QL(1,5)=SK1*CSR*AS*BX/CD2 - QL(1,6)=SK1*CSR*AS*BY/CD2 - QL(1,7)=0. - - QL(2,1)=0. - QL(2,2)=-QU(1)*BY*BSGN/2.e0 - QL(2,3)=QU(1)*BX*BSGN/2.e0 - QL(2,4)=0. - QL(2,5)=-SK1*BY/2.e0 - QL(2,6)=SK1*BX/2.e0 - QL(2,7)=0. - - QL(3,1)=AS/2.e0 - QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 - QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 - QL(3,4)=-QU(1)*AS*CS/CD2 - QL(3,5)=-SK1*CSR*AF*BX/CD2 - QL(3,6)=-SK1*CSR*AF*BY/CD2 - QL(3,7)=0. - - QL(4,1)=0. - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=0. - QL(4,5)=0. - QL(4,6)=0. - QL(4,7)=1.e0 - - QL(5,1)=AS/2.e0 - QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 - QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 - QL(5,4)=QU(1)*AS*CS/CD2 - QL(5,5)=-SK1*CSR*AF*BX/CD2 - QL(5,6)=-SK1*CSR*AF*BY/CD2 - QL(5,7)=0. - - QL(6,1)=0. - QL(6,2)=-QU(1)*BY*BSGN/2.e0 - QL(6,3)=QU(1)*BX*BSGN/2.e0 - QL(6,4)=0. - QL(6,5)=SK1*BY/2.e0 - QL(6,6)=-SK1*BX/2.e0 - QL(6,7)=0. - - QL(7,1)=AF/2.e0 - QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 - QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 - QL(7,4)=QU(1)*AF*CF/CD2 - QL(7,5)=SK1*CSR*AS*BX/CD2 - QL(7,6)=SK1*CSR*AS*BY/CD2 - QL(7,7)=0. - - - QR(1,1)=AF - QR(1,2)=0. - QR(1,3)=AS - QR(1,4)=0. - QR(1,5)=AS - QR(1,6)=0. - QR(1,7)=AF - - QR(2,1)=AS*CS*BX*BSGN/QU(1) - QR(2,2)=-BY*BSGN/QU(1) - QR(2,3)=-AF*CF*BX*BSGN/QU(1) - QR(2,4)=0. - QR(2,5)=AF*CF*BX*BSGN/QU(1) - QR(2,6)=-BY*BSGN/QU(1) - QR(2,7)=-AS*CS*BX*BSGN/QU(1) - - QR(3,1)=AS*CS*BY*BSGN/QU(1) - QR(3,2)=BX*BSGN/QU(1) - QR(3,3)=-AF*CF*BY*BSGN/QU(1) - QR(3,4)=0. - QR(3,5)=AF*CF*BY*BSGN/QU(1) - QR(3,6)=BX*BSGN/QU(1) - QR(3,7)=-AS*CS*BY*BSGN/QU(1) - - QR(4,1)=-AF*CF/QU(1) - QR(4,2)=0. - QR(4,3)=-AS*CS/QU(1) - QR(4,4)=0. - QR(4,5)=AS*CS/QU(1) - QR(4,6)=0. - QR(4,7)=AF*CF/QU(1) - - QR(5,1)=AS*BX*CSR/SK1 - QR(5,2)=-BY/SK1 - QR(5,3)=-AF*BX*CSR/SK1 - QR(5,4)=0. - QR(5,5)=-AF*BX*CSR/SK1 - QR(5,6)=BY/SK1 - QR(5,7)=AS*BX*CSR/SK1 - - QR(6,1)=AS*BY*CSR/SK1 - QR(6,2)=BX/SK1 - QR(6,3)=-AF*BY*CSR/SK1 - QR(6,4)=0. - QR(6,5)=-AF*BY*CSR/SK1 - QR(6,6)=-BX/SK1 - QR(6,7)=AS*BY*CSR/SK1 - - QR(7,1)=0. - QR(7,2)=0. - QR(7,3)=0. - QR(7,4)=1.e0 - QR(7,5)=0. - QR(7,6)=0. - QR(7,7)=0. - - - U(1)=QU(4)-CF - U(2)=QU(4)-CA - U(3)=QU(4)-CS - U(4)=QU(4) - U(5)=QU(4)+CS - U(6)=QU(4)+CA - U(7)=QU(4)+CF - - RETURN - END - - - SUBROUTINE VECTEGx(QU,U) - Implicit NONE - - ENZO_REAL QU(7),U(7) - ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,VA,BXX,BYZ,SBB,BMG,GPP,GPB - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=a2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAX - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - VA=abs(BVX) - - BXX=QU(5)**2 - BYZ=QU(6)**2+QU(7)**2 - SBB=sqrt(BYZ) - BMG=BXX+BYZ - GPP=a2*QU(1) - GPB=abs(GPP-BXX) - - IF(BYZ.LE.DLT*BMG) THEN - - IF(GPB.GT.DLT*GPP) THEN - CS=sqrt(abs((CKV+VAX-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAX+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - CS=CSR - CF=CSR - ENDIF - - ENDIF - - U(1)=QU(2)-CF - U(2)=QU(2)-VA - U(3)=QU(2)-CS - U(4)=QU(2) - U(5)=QU(2)+CS - U(6)=QU(2)+VA - U(7)=QU(2)+CF - - RETURN - END - - SUBROUTINE VECTEGy(QU,U) - Implicit NONE - - ENZO_REAL QU(7),U(7) - ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,VA,BYY,BXZ,SBB,BMG,GPP,GPB - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=a2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAY - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - VA=abs(BVY) - - BYY=QU(6)**2 - BXZ=QU(5)**2+QU(7)**2 - SBB=sqrt(BXZ) - BMG=BYY+BXZ - GPP=a2*QU(1) - GPB=abs(GPP-BYY) - - IF(BXZ.LE.DLT*BMG) THEN - - IF(GPB.GT.DLT*GPP) THEN - CS=sqrt(abs((CKV+VAY-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAY+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - CS=CSR - CF=CSR - ENDIF - - ENDIF - - U(1)=QU(3)-CF - U(2)=QU(3)-VA - U(3)=QU(3)-CS - U(4)=QU(3) - U(5)=QU(3)+CS - U(6)=QU(3)+VA - U(7)=QU(3)+CF - - RETURN - END - - SUBROUTINE VECTEGz(QU,U) - Implicit NONE - - ENZO_REAL QU(7),U(7) - ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ,VA - ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 - ENZO_REAL VS2,CF,CS,BXX,BYZ,SBB,BMG,GPP,GPB - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - DLT=1.E-12 - - SK1=sqrt(QU(1)) - BVX=QU(5)/SK1 - BVY=QU(6)/SK1 - BVZ=QU(7)/SK1 - VAX=BVX**2 - VAY=BVY**2 - VAZ=BVZ**2 - VAH=VAX+VAY+VAZ - CKV=a2 - CSR=sqrt(CKV) - CSV=CKV+VAH - CWH=CKV-VAH - DSCV=CSV**2-4.e0*CKV*VAZ - IF(DSCV.LT.0.) DSCV=0. - DSCV=sqrt(DSCV) - VF2=(CSV+DSCV)/2.e0 - VS2=(CSV-DSCV)/2.e0 - IF(VS2.LT.0.) VS2=0. - CF=sqrt(VF2) - CS=sqrt(VS2) - VA=abs(BVZ) - - BXX=QU(7)**2 - BYZ=QU(5)**2+QU(6)**2 - SBB=sqrt(BYZ) - BMG=BXX+BYZ - GPP=a2*QU(1) - GPB=abs(GPP-BXX) - - IF(BYZ.LE.DLT*BMG) THEN - - IF(GPB.GT.DLT*GPP) THEN - CS=sqrt(abs((CKV+VAZ-SIGN(one,CWH)*CWH)/2.e0)) - CF=sqrt(abs((CKV+VAZ+SIGN(one,CWH)*CWH)/2.e0)) - ELSE - CS=CSR - CF=CSR - ENDIF - - ENDIF - - U(1)=QU(4)-CF - U(2)=QU(4)-VA - U(3)=QU(4)-CS - U(4)=QU(4) - U(5)=QU(4)+CS - U(6)=QU(4)+VA - U(7)=QU(4)+CF - - RETURN - END - - SUBROUTINE FLUXx(QU,F) - Implicit NONE - - ENZO_REAL QU(7),F(7) - ENZO_REAL A1,A2,BKV,PXX - - ENZO_REAL one - parameter (one = 1.0) - - a1=1. - a2=1. - - BKV=QU(5)**2+QU(6)**2+QU(7)**2 - - PXX=a2*qu(1)+BKV/2.e0 - - F(1)=qu(1)*qu(2) - F(2)=qu(1)*qu(2)**2+PXX-QU(5)**2 - F(3)=qu(1)*qu(2)*QU(3)-QU(5)*QU(6) - F(4)=qu(1)*qu(2)*QU(4)-QU(5)*QU(7) - F(5)=0. - F(6)=qu(2)*QU(6)-QU(3)*QU(5) - F(7)=qu(2)*QU(7)-QU(4)*QU(5) - - RETURN - END - - SUBROUTINE FLUXy(QU,F) - Implicit NONE - - ENZO_REAL QU(7),F(7) - ENZO_REAL A1,A2,BKV,PXX - - ENZO_REAL one - parameter (one = 1.0) - - A1=1. - A2=1. - - BKV=QU(5)**2+QU(6)**2+QU(7)**2 - - PXX=A2*qu(1)+BKV/2.e0 - - F(1)=qu(1)*qu(3) - F(2)=qu(1)*qu(2)*QU(3)-QU(6)*QU(5) - F(3)=qu(1)*qu(3)**2+PXX-QU(6)**2 - F(4)=qu(1)*qu(3)*QU(4)-QU(6)*QU(7) - F(5)=QU(3)*QU(5)-qu(2)*QU(6) - F(6)=0. - F(7)=QU(3)*QU(7)-qu(4)*QU(6) - - RETURN - END - - SUBROUTINE FLUXz(QU,F) - Implicit NONE - - ENZO_REAL QU(7),F(7) - ENZO_REAL A1,A2,BKV,PXX - - ENZO_REAL one - parameter (one = 1.0) - - A1=1. - A2=1. - - BKV=QU(5)**2+QU(6)**2+QU(7)**2 - - PXX=A2*qu(1)+BKV/2.e0 - - F(1)=qu(1)*qu(4) - F(2)=qu(1)*qu(2)*QU(4)-QU(5)*QU(7) - F(3)=qu(1)*qu(3)*QU(4)-QU(6)*QU(7) - F(4)=qu(1)*qu(4)**2+PXX-QU(7)**2 - F(5)=QU(4)*QU(5)-qu(2)*QU(7) - F(6)=QU(4)*QU(6)-qu(3)*QU(7) - F(7)=0. - - RETURN - END - - SUBROUTINE FPMR(Y,QL,QR,QP,QC) - Implicit NONE - - Integer m - ENZO_REAL QL(7),QR(7),QP(7),QC(7) - ENZO_REAL DQ,Q6,Y - - DO M=1,7 - DQ=QR(M)-QL(M) - Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) - QC(M)=QL(M)+Y/2.e0*(DQ+(1.e0-2.e0/3.*Y)*Q6) - ENDDO - - RETURN - END - - SUBROUTINE FPML(Y,QL,QR,QP,QC) - Implicit NONE - - Integer m - ENZO_REAL QL(7),QR(7),QP(7),QC(7) - ENZO_REAL DQ,Q6,y - - DO M=1,7 - DQ=QR(M)-QL(M) - Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) - QC(M)=QR(M)-Y/2.e0*(DQ-(1.e0-2.e0/3.*Y)*Q6) - ENDDO - - RETURN - END - - SUBROUTINE FQML(Y,QL,QR,QP,QC) - Implicit NONE - - Integer m - ENZO_REAL QL(7),QR(7),QP(7),QC(7) - ENZO_REAL DQ,Q6,Y - - DO M=1,7 - DQ=QR(M)-QL(M) - Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) - QC(M)=QL(M)+Y*(DQ+(1.e0-Y)*Q6) - ENDDO - - RETURN - END - - subroutine averx(qul,qur,qsr) - Implicit NONE - - ENZO_REAL qul(7),qur(7),qsr(7) - ENZO_REAL RL,RR,RS - - rl=sqrt(qul(1)) - rr=sqrt(qur(1)) - rs=rl+rr - - qsr(1)=rl*rr - qsr(2)=(rl*qul(2)+rr*qur(2))/rs - qsr(3)=(rl*qul(3)+rr*qur(3))/rs - qsr(4)=(rl*qul(4)+rr*qur(4))/rs - qsr(5)=(qul(5)+qur(5))/2.e0 - qsr(6)=(qul(6)/rl+qur(6)/rr)/rs*qsr(1) - qsr(7)=(qul(7)/rl+qur(7)/rr)/rs*qsr(1) - - return - end - - subroutine avery(qul,qur,qsr) - Implicit NONE - - ENZO_REAL qul(7),qur(7),qsr(7) - ENZO_REAL RL,RR,RS - - rl=sqrt(qul(1)) - rr=sqrt(qur(1)) - rs=rl+rr - - qsr(1)=rl*rr - qsr(2)=(rl*qul(2)+rr*qur(2))/rs - qsr(3)=(rl*qul(3)+rr*qur(3))/rs - qsr(4)=(rl*qul(4)+rr*qur(4))/rs - qsr(5)=(qul(5)/rl+qur(5)/rr)/rs*qsr(1) - qsr(6)=(qul(6)+qur(6))/2.e0 - qsr(7)=(qul(7)/rl+qur(7)/rr)/rs*qsr(1) - - return - end - - subroutine averz(qul,qur,qsr) - Implicit NONE - - ENZO_REAL qul(7),qur(7),qsr(7) - ENZO_REAL RL,RR,RS - - rl=sqrt(qul(1)) - rr=sqrt(qur(1)) - rs=rl+rr - - qsr(1)=rl*rr - qsr(2)=(rl*qul(2)+rr*qur(2))/rs - qsr(3)=(rl*qul(3)+rr*qur(3))/rs - qsr(4)=(rl*qul(4)+rr*qur(4))/rs - qsr(5)=(qul(5)/rl+qur(5)/rr)/rs*qsr(1) - qsr(6)=(qul(6)/rl+qur(6)/rr)/rs*qsr(1) - qsr(7)=(qul(7)+qur(7))/2.e0 - - return - end - - - Subroutine QDD6(Nx,Qvr,Qvl,Qrx,Qlx,Qp) - Implicit NONE - Integer m,nx,i - ENZO_REAL Qvr(Nx,7),Qvl(Nx,7),Qp(Nx,7) - ENZO_REAL Qrx(Nx,7),Qlx(Nx,7) - ENZO_REAL DQ,Q6 - - Do I=1,Nx - - DO M=1,7 - - IF((QVR(I,M)-QP(I,M))*(QP(I,M)-QVL(I,M)).LE.0.)THEN - QRX(I,M)=QP(I,M) - QLX(I,M)=QP(I,M) - ELSE - - DQ=QVR(I,M)-QVL(I,M) - Q6=6.0*(QP(I,M)-(QVR(I,M)+QVL(I,M))/2.) - - QLX(I,M)=QVL(I,M) - QRX(I,M)=QVR(I,M) - - IF(DQ*Q6.GT.DQ**2) QLX(I,M)=3.*QP(I,M)-2.*QVR(I,M) - IF(DQ*Q6.LT.-DQ**2) QRX(I,M)=3.*QP(I,M)-2.*QVL(I,M) - - ENDIF - - ENDDO - ENDDO - - Return - End - - SUBROUTINE MATR_AX(QU,QL) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7) - ENZO_REAL A1,A2 - - A1=1. - A2=1. - - QL(1,1)=QU(2) - QL(1,2)=QU(1) - QL(1,3)=0. - QL(1,4)=0. - QL(1,5)=0. - QL(1,6)=0. - QL(1,7)=0. - - QL(2,1)=a2/QU(1) - QL(2,2)=QU(2) - QL(2,3)=0. - QL(2,4)=0. - QL(2,5)=0. - QL(2,6)=QU(6)/QU(1) - QL(2,7)=QU(7)/QU(1) - - QL(3,1)=0. - QL(3,2)=0. - QL(3,3)=QU(2) - QL(3,4)=0. - QL(3,5)=0. - QL(3,6)=-QU(5)/QU(1) - QL(3,7)=0. - - QL(4,1)=0. - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=QU(2) - QL(4,5)=0. - QL(4,6)=0. - QL(4,7)=-QU(5)/QU(1) - - QL(5,1)=0. - QL(5,2)=0. - QL(5,3)=0. - QL(5,4)=0. - QL(5,5)=QU(2) - QL(5,6)=0. - QL(5,7)=0. - - QL(6,1)=0. - QL(6,2)=QU(6) - QL(6,3)=-QU(5) - QL(6,4)=0. - QL(6,5)=0. - QL(6,6)=QU(2) - QL(6,7)=0. - - QL(7,1)=0. - QL(7,2)=QU(7) - QL(7,3)=0. - QL(7,4)=-QU(5) - QL(7,5)=0. - QL(7,6)=0. - QL(7,7)=QU(2) - - RETURN - END - - SUBROUTINE MATR_AY(QU,QL) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7) - ENZO_REAL A1,A2 - - A1=1. - A2=1. - - QL(1,1)=QU(3) - QL(1,2)=0. - QL(1,3)=QU(1) - QL(1,4)=0. - QL(1,5)=0. - QL(1,6)=0. - QL(1,7)=0. - - QL(2,1)=0. - QL(2,2)=QU(3) - QL(2,3)=0. - QL(2,4)=0. - QL(2,5)=-QU(6)/QU(1) - QL(2,6)=0. - QL(2,7)=0. - - QL(3,1)=a2/QU(1) - QL(3,2)=0. - QL(3,3)=QU(3) - QL(3,4)=0. - QL(3,5)=QU(5)/QU(1) - QL(3,6)=0. - QL(3,7)=QU(7)/QU(1) - - QL(4,1)=0. - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=QU(3) - QL(4,5)=0. - QL(4,6)=0. - QL(4,7)=-QU(6)/QU(1) - - QL(5,1)=0. - QL(5,2)=-QU(6) - QL(5,3)=QU(5) - QL(5,4)=0. - QL(5,5)=QU(3) - QL(5,6)=0. - QL(5,7)=0. - - QL(6,1)=0. - QL(6,2)=0. - QL(6,3)=0. - QL(6,4)=0. - QL(6,5)=0. - QL(6,6)=QU(3) - QL(6,7)=0. - - QL(7,1)=0. - QL(7,2)=0. - QL(7,3)=QU(7) - QL(7,4)=-QU(6) - QL(7,5)=0. - QL(7,6)=0. - QL(7,7)=QU(3) - - RETURN - END - - SUBROUTINE MATR_AZ(QU,QL) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7) - ENZO_REAL A1,A2 - - A1=1. - A2=1. - - QL(1,1)=QU(4) - QL(1,2)=0. - QL(1,3)=0. - QL(1,4)=QU(1) - QL(1,5)=0. - QL(1,6)=0. - QL(1,7)=0. - - QL(2,1)=0. - QL(2,2)=QU(4) - QL(2,3)=0. - QL(2,4)=0. - QL(2,5)=-QU(7)/QU(1) - QL(2,6)=0. - QL(2,7)=0. - - QL(3,1)=0. - QL(3,2)=0. - QL(3,3)=QU(4) - QL(3,4)=0. - QL(3,5)=0. - QL(3,6)=-QU(7)/QU(1) - QL(3,7)=0. - - QL(4,1)=a2/QU(1) - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=QU(4) - QL(4,5)=QU(5)/QU(1) - QL(4,6)=QU(6)/QU(1) - QL(4,7)=0. - - QL(5,1)=0. - QL(5,2)=-QU(7) - QL(5,3)=0. - QL(5,4)=QU(5) - QL(5,5)=QU(4) - QL(5,6)=0. - QL(5,7)=0. - - QL(6,1)=0. - QL(6,2)=0. - QL(6,3)=-QU(7) - QL(6,4)=QU(6) - QL(6,5)=0. - QL(6,6)=QU(4) - QL(6,7)=0. - - QL(7,1)=0. - QL(7,2)=0. - QL(7,3)=0. - QL(7,4)=0. - QL(7,5)=0. - QL(7,6)=0. - QL(7,7)=QU(4) - - RETURN - END - - SUBROUTINE DUDW(Qu,QL) - Implicit NONE - - ENZO_REAL QU(7),QL(7,7) - - QL(1,1)=1. - QL(1,2)=0. - QL(1,3)=0. - QL(1,4)=0. - QL(1,5)=0. - QL(1,6)=0. - QL(1,7)=0. - - QL(2,1)=QU(2) - QL(2,2)=QU(1) - QL(2,3)=0. - QL(2,4)=0. - QL(2,5)=0. - QL(2,6)=0. - QL(2,7)=0. - - QL(3,1)=QU(3) - QL(3,2)=0. - QL(3,3)=QU(1) - QL(3,4)=0. - QL(3,5)=0. - QL(3,6)=0. - QL(3,7)=0. - - QL(4,1)=QU(4) - QL(4,2)=0. - QL(4,3)=0. - QL(4,4)=QU(1) - QL(4,5)=0. - QL(4,6)=0. - QL(4,7)=0. - - QL(5,1)=0. - QL(5,2)=0. - QL(5,3)=0. - QL(5,4)=0. - QL(5,5)=1. - QL(5,6)=0. - QL(5,7)=0. - - QL(6,1)=0. - QL(6,2)=0. - QL(6,3)=0. - QL(6,4)=0. - QL(6,5)=0. - QL(6,6)=1. - QL(6,7)=0. - - QL(7,1)=0. - QL(7,2)=0. - QL(7,3)=0. - QL(7,4)=0. - QL(7,5)=0. - QL(7,6)=0. - QL(7,7)=1. - - RETURN - END - - SUBROUTINE AMPLTD(QL,QD,SL) - Implicit NONE - - Integer m,l - ENZO_REAL QL(7,7),QD(7),SL(7) - - DO M=1,7 - SL(M)=0. - DO L=1,7 - SL(M)=SL(M)+QL(M,L)*QD(L) - ENDDO - ENDDO - - RETURN - END - - Function Xminmod(x,y) - - ENZO_REAL x,y,Xminmod - ENZO_REAL one - parameter (one = 1.0) - - Xminmod = 0.5*(SIGN(one,x) + SIGN(one,y))*min(abs(x),abs(y)) - - Return - End - - Function Xmedian(x,y,z) - - ENZO_REAL x,y,z,Xminmod,Xmedian - - External Xminmod - - Xmedian = x + Xminmod(y-x,z-x) - - Return - End - - SUBROUTINE W5RECM(VP1,VP2,VP3,VP4,VP5,VL,VR) - Implicit NONE - - ENZO_REAL IS1,IS2,IS3,DELTA,WS1,WS2,WS3,WJ1,WJ2,WJ3 - ENZO_REAL AJ1,AJ2,AJ3,AJS,WM1,WM2,WM3,VL,VR - ENZO_REAL VP1,VP2,VP3,VP4,VP5 - - DELTA = 1.0d-20 - - WS1 = 0.1E0 - WS2 = 0.6E0 - WS3 = 0.3E0 - - - WJ1 = (11.E0*VP3 - 7.E0*VP2 + 2.E0*VP1)/6.E0 - WJ2 = (2.E0 *VP4 + 5.E0*VP3 - VP2)/6.E0 - WJ3 = ( -VP5 + 5.E0*VP4 + 2.E0*VP3)/6.E0 - - IS1 = 13.E0/12.E0*(VP3 - 2.E0*VP2 + VP1)**2 - & + (3.E0*VP3 - 4.E0*VP2 + VP1)**2/4.E0 - IS2 = 13.E0/12.E0*(VP4 - 2.E0*VP3 + VP2)**2 - & + (VP4 - VP2)**2/4.E0 - IS3 = 13.E0/12.E0*(VP5 - 2.E0*VP4 + VP3)**2 - & + (VP5 - 4.E0*VP4 + 3.E0*VP3)**2/4.E0 - - AJ1 = WS1/(IS1+DELTA)**2 - AJ2 = WS2/(IS2+DELTA)**2 - AJ3 = WS3/(IS3+DELTA)**2 - - AJS = AJ1 + AJ2 +AJ3 - - WM1 = AJ1/AJS - WM2 = AJ2/AJS - WM3 = AJ3/AJS - - AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1)/(WS1*WS1 - & + WM1*(1.E0 - 2.E0*WS1)) - AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2)/(WS2*WS2 - & + WM2*(1.E0 - 2.E0*WS2)) - AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3)/(WS3*WS3 - & + WM3*(1.E0 - 2.E0*WS3)) - - AJS = AJ1 + AJ2 +AJ3 - - WM1 = AJ1/AJS - WM2 = AJ2/AJS - WM3 = AJ3/AJS - - VR = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 - - WJ1 = (11.E0*VP3 - 7.E0*VP4 + 2.E0*VP5)/6.E0 - WJ2 = (2.E0 *VP2 + 5.E0*VP3 - VP4)/6.E0 - WJ3 = ( -VP1 + 5.E0*VP2 + 2.E0*VP3)/6.E0 - - IS1 = 13.E0/12.E0*(VP3 - 2.E0*VP4 + VP5)**2 - & + (3.E0*VP3 - 4.E0*VP4 + VP5)**2/4.E0 - IS2 = 13.E0/12.E0*(VP2 - 2.E0*VP3 + VP4)**2 - & + (VP2 - VP4)**2/4.E0 - IS3 = 13.E0/12.E0*(VP1 - 2.E0*VP2 + VP3)**2 - & + (VP1 - 4.E0*VP2 + 3.E0*VP3)**2/4.E0 - - AJ1 = WS1/(IS1+DELTA)**2 - AJ2 = WS2/(IS2+DELTA)**2 - AJ3 = WS3/(IS3+DELTA)**2 - - AJS = AJ1 + AJ2 +AJ3 - - WM1 = AJ1/AJS - WM2 = AJ2/AJS - WM3 = AJ3/AJS - - AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1)/(WS1*WS1 - & + WM1*(1.E0 - 2.E0*WS1)) - AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2)/(WS2*WS2 - & + WM2*(1.E0 - 2.E0*WS2)) - AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3)/(WS3*WS3 - & + WM3*(1.E0 - 2.E0*WS3)) - - AJS = AJ1 + AJ2 +AJ3 - - WM1 = AJ1/AJS - WM2 = AJ2/AJS - WM3 = AJ3/AJS - - VL = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 - - RETURN - END - - Function VLeer(a,b) - - ENZO_REAL a,b,VLeer - - if(a*a+b*b.ne.0)then - VLeer=max(a*b,0.)*(a+b)/(a*a+b*b) - - else - VLeer=0. - endif - - Return - End - - SUBROUTINE PRIM(QU,QP) - - ENZO_REAL QU(7),QP(7) - - QP(1)=QU(1) - QP(2)=QU(2)/QU(1) - QP(3)=QU(3)/QU(1) - QP(4)=QU(4)/QU(1) - QP(5)=QU(5) - QP(6)=QU(6) - QP(7)=QU(7) - - RETURN - END - - SUBROUTINE CONS(QP,QU) - - ENZO_REAL QU(7),QP(7) - - QU(1)=QP(1) - QU(2)=QP(2)*QP(1) - QU(3)=QP(3)*QP(1) - QU(4)=QP(4)*QP(1) - QU(5)=QP(5) - QU(6)=QP(6) - QU(7)=QP(7) - - RETURN - END +c See LICENSE_PPML file for license and copyright information + +#include "fortran.h" + + SUBROUTINE VECTLRx(QU,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BXX,BYZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BY,BZ,BSGN,CD2 + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + X22=1.e0/sqrt(2.e0) + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=a2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAX + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + CA=abs(BVX) + + BXX=QU(5)**2 + BYZ=QU(6)**2+QU(7)**2 + SBB=sqrt(BYZ) + BMG=BXX+BYZ + GPP=a2*QU(1) + GPB=abs(GPP-BXX) + + IF(BYZ.GT.DLT*BMG) THEN + + ASS=sqrt(CWH**2+4.e0*CKV*(VAY+VAZ)) + AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) + AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) + + BY=QU(6)/SBB + BZ=QU(7)/SBB + + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) + AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) + CS=sqrt(abs((CKV+VAX-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAX+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + + BY=X22 + BZ=X22 + + ENDIF + + BSGN=SIGN(one,QU(5)) + CD2=2.e0*CKV + + QL(1,1)=AF/2.e0 + QL(1,2)=-QU(1)*AF*CF/CD2 + QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 + QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 + QL(1,5)=0. + QL(1,6)=SK1*CSR*AS*BY/CD2 + QL(1,7)=SK1*CSR*AS*BZ/CD2 + + QL(2,1)=0. + QL(2,2)=0. + QL(2,3)=-QU(1)*BZ*BSGN/2.e0 + QL(2,4)=QU(1)*BY*BSGN/2.e0 + QL(2,5)=0. + QL(2,6)=-SK1*BZ/2.e0 + QL(2,7)=SK1*BY/2.e0 + + QL(3,1)=AS/2.e0 + QL(3,2)=-QU(1)*AS*CS/CD2 + QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 + QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 + QL(3,5)=0. + QL(3,6)=-SK1*CSR*AF*BY/CD2 + QL(3,7)=-SK1*CSR*AF*BZ/CD2 + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=1.e0 + QL(4,6)=0. + QL(4,7)=0. + + QL(5,1)=AS/2.e0 + QL(5,2)=QU(1)*AS*CS/CD2 + QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 + QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 + QL(5,5)=0. + QL(5,6)=-SK1*CSR*AF*BY/CD2 + QL(5,7)=-SK1*CSR*AF*BZ/CD2 + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=-QU(1)*BZ*BSGN/2.e0 + QL(6,4)=QU(1)*BY*BSGN/2.e0 + QL(6,5)=0. + QL(6,6)=SK1*BZ/2.e0 + QL(6,7)=-SK1*BY/2.e0 + + QL(7,1)=AF/2.e0 + QL(7,2)=QU(1)*AF*CF/CD2 + QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 + QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 + QL(7,5)=0. + QL(7,6)=SK1*CSR*AS*BY/CD2 + QL(7,7)=SK1*CSR*AS*BZ/CD2 + + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=0. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + + QR(2,1)=-AF*CF/QU(1) + QR(2,2)=0. + QR(2,3)=-AS*CS/QU(1) + QR(2,4)=0. + QR(2,5)=AS*CS/QU(1) + QR(2,6)=0. + QR(2,7)=AF*CF/QU(1) + + QR(3,1)=AS*CS*BY*BSGN/QU(1) + QR(3,2)=-BZ*BSGN/QU(1) + QR(3,3)=-AF*CF*BY*BSGN/QU(1) + QR(3,4)=0. + QR(3,5)=AF*CF*BY*BSGN/QU(1) + QR(3,6)=-BZ*BSGN/QU(1) + QR(3,7)=-AS*CS*BY*BSGN/QU(1) + + QR(4,1)=AS*CS*BZ*BSGN/QU(1) + QR(4,2)=BY*BSGN/QU(1) + QR(4,3)=-AF*CF*BZ*BSGN/QU(1) + QR(4,4)=0. + QR(4,5)=AF*CF*BZ*BSGN/QU(1) + QR(4,6)=BY*BSGN/QU(1) + QR(4,7)=-AS*CS*BZ*BSGN/QU(1) + + QR(5,1)=0. + QR(5,2)=0. + QR(5,3)=0. + QR(5,4)=1.e0 + QR(5,5)=0. + QR(5,6)=0. + QR(5,7)=0. + + QR(6,1)=AS*BY*CSR/SK1 + QR(6,2)=-BZ/SK1 + QR(6,3)=-AF*BY*CSR/SK1 + QR(6,4)=0. + QR(6,5)=-AF*BY*CSR/SK1 + QR(6,6)=BZ/SK1 + QR(6,7)=AS*BY*CSR/SK1 + + QR(7,1)=AS*BZ*CSR/SK1 + QR(7,2)=BY/SK1 + QR(7,3)=-AF*BZ*CSR/SK1 + QR(7,4)=0. + QR(7,5)=-AF*BZ*CSR/SK1 + QR(7,6)=-BY/SK1 + QR(7,7)=AS*BZ*CSR/SK1 + + + U(1)=QU(2)-CF + U(2)=QU(2)-CA + U(3)=QU(2)-CS + U(4)=QU(2) + U(5)=QU(2)+CS + U(6)=QU(2)+CA + U(7)=QU(2)+CF + + RETURN + END + + SUBROUTINE VECTLRy(QU,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BX,BZ,BSGN,CD2 + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + X22=1.e0/sqrt(2.e0) + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=A2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAY + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + CA=abs(BVY) + + BYY=QU(6)**2 + BXZ=QU(5)**2+QU(7)**2 + SBB=sqrt(BXZ) + BMG=BYY+BXZ + GPP=A2*QU(1) + GPB=abs(GPP-BYY) + + IF(BXZ.GT.DLT*BMG) THEN + + ASS=sqrt(CWH**2+4.e0*CKV*(VAX+VAZ)) + AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) + AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) + + BX=QU(5)/SBB + BZ=QU(7)/SBB + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) + AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) + CS=sqrt(abs((CKV+VAY-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAY+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + + BX=X22 + BZ=X22 + + ENDIF + + BSGN=SIGN(one,QU(6)) + CD2=2.e0*CKV + + QL(1,1)=AF/2.e0 + QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 + QL(1,3)=-QU(1)*AF*CF/CD2 + QL(1,4)=QU(1)*AS*CS*BZ*BSGN/CD2 + QL(1,5)=SK1*CSR*AS*BX/CD2 + QL(1,6)=0. + QL(1,7)=SK1*CSR*AS*BZ/CD2 + + QL(2,1)=0. + QL(2,2)=-QU(1)*BZ*BSGN/2.e0 + QL(2,3)=0. + QL(2,4)=QU(1)*BX*BSGN/2.e0 + QL(2,5)=-SK1*BZ/2.e0 + QL(2,6)=0. + QL(2,7)=SK1*BX/2.e0 + + QL(3,1)=AS/2.e0 + QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 + QL(3,3)=-QU(1)*AS*CS/CD2 + QL(3,4)=-QU(1)*AF*CF*BZ*BSGN/CD2 + QL(3,5)=-SK1*CSR*AF*BX/CD2 + QL(3,6)=0. + QL(3,7)=-SK1*CSR*AF*BZ/CD2 + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=0. + QL(4,6)=1.e0 + QL(4,7)=0. + + QL(5,1)=AS/2.e0 + QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 + QL(5,3)=QU(1)*AS*CS/CD2 + QL(5,4)=QU(1)*AF*CF*BZ*BSGN/CD2 + QL(5,5)=-SK1*CSR*AF*BX/CD2 + QL(5,6)=0. + QL(5,7)=-SK1*CSR*AF*BZ/CD2 + + QL(6,1)=0. + QL(6,2)=-QU(1)*BZ*BSGN/2.e0 + QL(6,3)=0. + QL(6,4)=QU(1)*BX*BSGN/2.e0 + QL(6,5)=SK1*BZ/2.e0 + QL(6,6)=0. + QL(6,7)=-SK1*BX/2.e0 + + QL(7,1)=AF/2.e0 + QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 + QL(7,3)=QU(1)*AF*CF/CD2 + QL(7,4)=-QU(1)*AS*CS*BZ*BSGN/CD2 + QL(7,5)=SK1*CSR*AS*BX/CD2 + QL(7,6)=0. + QL(7,7)=SK1*CSR*AS*BZ/CD2 + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=0. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + + QR(2,1)=AS*CS*BX*BSGN/QU(1) + QR(2,2)=-BZ*BSGN/QU(1) + QR(2,3)=-AF*CF*BX*BSGN/QU(1) + QR(2,4)=0. + QR(2,5)=AF*CF*BX*BSGN/QU(1) + QR(2,6)=-BZ*BSGN/QU(1) + QR(2,7)=-AS*CS*BX*BSGN/QU(1) + + QR(3,1)=-AF*CF/QU(1) + QR(3,2)=0. + QR(3,3)=-AS*CS/QU(1) + QR(3,4)=0. + QR(3,5)=AS*CS/QU(1) + QR(3,6)=0. + QR(3,7)=AF*CF/QU(1) + + QR(4,1)=AS*CS*BZ*BSGN/QU(1) + QR(4,2)=BX*BSGN/QU(1) + QR(4,3)=-AF*CF*BZ*BSGN/QU(1) + QR(4,4)=0. + QR(4,5)=AF*CF*BZ*BSGN/QU(1) + QR(4,6)=BX*BSGN/QU(1) + QR(4,7)=-AS*CS*BZ*BSGN/QU(1) + + QR(5,1)=AS*BX*CSR/SK1 + QR(5,2)=-BZ/SK1 + QR(5,3)=-AF*BX*CSR/SK1 + QR(5,4)=0. + QR(5,5)=-AF*BX*CSR/SK1 + QR(5,6)=BZ/SK1 + QR(5,7)=AS*BX*CSR/SK1 + + QR(6,1)=0. + QR(6,2)=0. + QR(6,3)=0. + QR(6,4)=1.e0 + QR(6,5)=0. + QR(6,6)=0. + QR(6,7)=0. + + QR(7,1)=AS*BZ*CSR/SK1 + QR(7,2)=BX/SK1 + QR(7,3)=-AF*BZ*CSR/SK1 + QR(7,4)=0. + QR(7,5)=-AF*BZ*CSR/SK1 + QR(7,6)=-BX/SK1 + QR(7,7)=AS*BZ*CSR/SK1 + + + U(1)=QU(3)-CF + U(2)=QU(3)-CA + U(3)=QU(3)-CS + U(4)=QU(3) + U(5)=QU(3)+CS + U(6)=QU(3)+CA + U(7)=QU(3)+CF + + RETURN + END + + SUBROUTINE VECTLRz(QU,QL,QR,U) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7),QR(7,7),U(7) + ENZO_REAL DLT,X22,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,CA,BYY,BXZ,SBB,BMG,GPP,GPB + ENZO_REAL ASS,AS,AF,BX,BY,BSGN,CD2 + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + X22=1.e0/sqrt(2.e0) + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=A2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAZ + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + CA=abs(BVZ) + + BYY=QU(7)**2 + BXZ=QU(5)**2+QU(6)**2 + SBB=sqrt(BXZ) + BMG=BYY+BXZ + GPP=A2*QU(1) + GPB=abs(GPP-BYY) + + IF(BXZ.GT.DLT*BMG) THEN + + ASS=sqrt(CWH**2+4.e0*CKV*(VAX+VAY)) + AS=sqrt(abs((1.e0-CWH/ASS)/2.e0)) + AF=sqrt(abs((1.e0+CWH/ASS)/2.e0)) + + BX=QU(5)/SBB + BY=QU(6)/SBB + + ELSE + + IF(GPB.GT.DLT*GPP) THEN + AS=sqrt(abs((1.e0-SIGN(one,CWH))/2.e0)) + AF=sqrt(abs((1.e0+SIGN(one,CWH))/2.e0)) + CS=sqrt(abs((CKV+VAZ-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAZ+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + AS=X22 + AF=X22 + CS=CSR + CF=CSR + ENDIF + + BX=X22 + BY=X22 + + ENDIF + + BSGN=SIGN(one,QU(7)) + CD2=2.e0*CKV + + QL(1,1)=AF/2.e0 + QL(1,2)=QU(1)*AS*CS*BX*BSGN/CD2 + QL(1,3)=QU(1)*AS*CS*BY*BSGN/CD2 + QL(1,4)=-QU(1)*AF*CF/CD2 + QL(1,5)=SK1*CSR*AS*BX/CD2 + QL(1,6)=SK1*CSR*AS*BY/CD2 + QL(1,7)=0. + + QL(2,1)=0. + QL(2,2)=-QU(1)*BY*BSGN/2.e0 + QL(2,3)=QU(1)*BX*BSGN/2.e0 + QL(2,4)=0. + QL(2,5)=-SK1*BY/2.e0 + QL(2,6)=SK1*BX/2.e0 + QL(2,7)=0. + + QL(3,1)=AS/2.e0 + QL(3,2)=-QU(1)*AF*CF*BX*BSGN/CD2 + QL(3,3)=-QU(1)*AF*CF*BY*BSGN/CD2 + QL(3,4)=-QU(1)*AS*CS/CD2 + QL(3,5)=-SK1*CSR*AF*BX/CD2 + QL(3,6)=-SK1*CSR*AF*BY/CD2 + QL(3,7)=0. + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=0. + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=1.e0 + + QL(5,1)=AS/2.e0 + QL(5,2)=QU(1)*AF*CF*BX*BSGN/CD2 + QL(5,3)=QU(1)*AF*CF*BY*BSGN/CD2 + QL(5,4)=QU(1)*AS*CS/CD2 + QL(5,5)=-SK1*CSR*AF*BX/CD2 + QL(5,6)=-SK1*CSR*AF*BY/CD2 + QL(5,7)=0. + + QL(6,1)=0. + QL(6,2)=-QU(1)*BY*BSGN/2.e0 + QL(6,3)=QU(1)*BX*BSGN/2.e0 + QL(6,4)=0. + QL(6,5)=SK1*BY/2.e0 + QL(6,6)=-SK1*BX/2.e0 + QL(6,7)=0. + + QL(7,1)=AF/2.e0 + QL(7,2)=-QU(1)*AS*CS*BX*BSGN/CD2 + QL(7,3)=-QU(1)*AS*CS*BY*BSGN/CD2 + QL(7,4)=QU(1)*AF*CF/CD2 + QL(7,5)=SK1*CSR*AS*BX/CD2 + QL(7,6)=SK1*CSR*AS*BY/CD2 + QL(7,7)=0. + + + QR(1,1)=AF + QR(1,2)=0. + QR(1,3)=AS + QR(1,4)=0. + QR(1,5)=AS + QR(1,6)=0. + QR(1,7)=AF + + QR(2,1)=AS*CS*BX*BSGN/QU(1) + QR(2,2)=-BY*BSGN/QU(1) + QR(2,3)=-AF*CF*BX*BSGN/QU(1) + QR(2,4)=0. + QR(2,5)=AF*CF*BX*BSGN/QU(1) + QR(2,6)=-BY*BSGN/QU(1) + QR(2,7)=-AS*CS*BX*BSGN/QU(1) + + QR(3,1)=AS*CS*BY*BSGN/QU(1) + QR(3,2)=BX*BSGN/QU(1) + QR(3,3)=-AF*CF*BY*BSGN/QU(1) + QR(3,4)=0. + QR(3,5)=AF*CF*BY*BSGN/QU(1) + QR(3,6)=BX*BSGN/QU(1) + QR(3,7)=-AS*CS*BY*BSGN/QU(1) + + QR(4,1)=-AF*CF/QU(1) + QR(4,2)=0. + QR(4,3)=-AS*CS/QU(1) + QR(4,4)=0. + QR(4,5)=AS*CS/QU(1) + QR(4,6)=0. + QR(4,7)=AF*CF/QU(1) + + QR(5,1)=AS*BX*CSR/SK1 + QR(5,2)=-BY/SK1 + QR(5,3)=-AF*BX*CSR/SK1 + QR(5,4)=0. + QR(5,5)=-AF*BX*CSR/SK1 + QR(5,6)=BY/SK1 + QR(5,7)=AS*BX*CSR/SK1 + + QR(6,1)=AS*BY*CSR/SK1 + QR(6,2)=BX/SK1 + QR(6,3)=-AF*BY*CSR/SK1 + QR(6,4)=0. + QR(6,5)=-AF*BY*CSR/SK1 + QR(6,6)=-BX/SK1 + QR(6,7)=AS*BY*CSR/SK1 + + QR(7,1)=0. + QR(7,2)=0. + QR(7,3)=0. + QR(7,4)=1.e0 + QR(7,5)=0. + QR(7,6)=0. + QR(7,7)=0. + + + U(1)=QU(4)-CF + U(2)=QU(4)-CA + U(3)=QU(4)-CS + U(4)=QU(4) + U(5)=QU(4)+CS + U(6)=QU(4)+CA + U(7)=QU(4)+CF + + RETURN + END + + + SUBROUTINE VECTEGx(QU,U) + Implicit NONE + + ENZO_REAL QU(7),U(7) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,VA,BXX,BYZ,SBB,BMG,GPP,GPB + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=a2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAX + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + VA=abs(BVX) + + BXX=QU(5)**2 + BYZ=QU(6)**2+QU(7)**2 + SBB=sqrt(BYZ) + BMG=BXX+BYZ + GPP=a2*QU(1) + GPB=abs(GPP-BXX) + + IF(BYZ.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=sqrt(abs((CKV+VAX-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAX+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(2)-CF + U(2)=QU(2)-VA + U(3)=QU(2)-CS + U(4)=QU(2) + U(5)=QU(2)+CS + U(6)=QU(2)+VA + U(7)=QU(2)+CF + + RETURN + END + + SUBROUTINE VECTEGy(QU,U) + Implicit NONE + + ENZO_REAL QU(7),U(7) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,VA,BYY,BXZ,SBB,BMG,GPP,GPB + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=a2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAY + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + VA=abs(BVY) + + BYY=QU(6)**2 + BXZ=QU(5)**2+QU(7)**2 + SBB=sqrt(BXZ) + BMG=BYY+BXZ + GPP=a2*QU(1) + GPB=abs(GPP-BYY) + + IF(BXZ.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=sqrt(abs((CKV+VAY-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAY+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(3)-CF + U(2)=QU(3)-VA + U(3)=QU(3)-CS + U(4)=QU(3) + U(5)=QU(3)+CS + U(6)=QU(3)+VA + U(7)=QU(3)+CF + + RETURN + END + + SUBROUTINE VECTEGz(QU,U) + Implicit NONE + + ENZO_REAL QU(7),U(7) + ENZO_REAL DLT,SK1,BVX,BVY,BVZ,VAX,VAY,VAZ,VA + ENZO_REAL VAH,CKV,A1,A2,CSR,CSV,CWH,DSCV,VF2 + ENZO_REAL VS2,CF,CS,BXX,BYZ,SBB,BMG,GPP,GPB + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + DLT=1.E-12 + + SK1=sqrt(QU(1)) + BVX=QU(5)/SK1 + BVY=QU(6)/SK1 + BVZ=QU(7)/SK1 + VAX=BVX**2 + VAY=BVY**2 + VAZ=BVZ**2 + VAH=VAX+VAY+VAZ + CKV=a2 + CSR=sqrt(CKV) + CSV=CKV+VAH + CWH=CKV-VAH + DSCV=CSV**2-4.e0*CKV*VAZ + IF(DSCV.LT.0.) DSCV=0. + DSCV=sqrt(DSCV) + VF2=(CSV+DSCV)/2.e0 + VS2=(CSV-DSCV)/2.e0 + IF(VS2.LT.0.) VS2=0. + CF=sqrt(VF2) + CS=sqrt(VS2) + VA=abs(BVZ) + + BXX=QU(7)**2 + BYZ=QU(5)**2+QU(6)**2 + SBB=sqrt(BYZ) + BMG=BXX+BYZ + GPP=a2*QU(1) + GPB=abs(GPP-BXX) + + IF(BYZ.LE.DLT*BMG) THEN + + IF(GPB.GT.DLT*GPP) THEN + CS=sqrt(abs((CKV+VAZ-SIGN(one,CWH)*CWH)/2.e0)) + CF=sqrt(abs((CKV+VAZ+SIGN(one,CWH)*CWH)/2.e0)) + ELSE + CS=CSR + CF=CSR + ENDIF + + ENDIF + + U(1)=QU(4)-CF + U(2)=QU(4)-VA + U(3)=QU(4)-CS + U(4)=QU(4) + U(5)=QU(4)+CS + U(6)=QU(4)+VA + U(7)=QU(4)+CF + + RETURN + END + + SUBROUTINE FLUXx(QU,F) + Implicit NONE + + ENZO_REAL QU(7),F(7) + ENZO_REAL A1,A2,BKV,PXX + + ENZO_REAL one + parameter (one = 1.0) + + a1=1. + a2=1. + + BKV=QU(5)**2+QU(6)**2+QU(7)**2 + + PXX=a2*qu(1)+BKV/2.e0 + + F(1)=qu(1)*qu(2) + F(2)=qu(1)*qu(2)**2+PXX-QU(5)**2 + F(3)=qu(1)*qu(2)*QU(3)-QU(5)*QU(6) + F(4)=qu(1)*qu(2)*QU(4)-QU(5)*QU(7) + F(5)=0. + F(6)=qu(2)*QU(6)-QU(3)*QU(5) + F(7)=qu(2)*QU(7)-QU(4)*QU(5) + + RETURN + END + + SUBROUTINE FLUXy(QU,F) + Implicit NONE + + ENZO_REAL QU(7),F(7) + ENZO_REAL A1,A2,BKV,PXX + + ENZO_REAL one + parameter (one = 1.0) + + A1=1. + A2=1. + + BKV=QU(5)**2+QU(6)**2+QU(7)**2 + + PXX=A2*qu(1)+BKV/2.e0 + + F(1)=qu(1)*qu(3) + F(2)=qu(1)*qu(2)*QU(3)-QU(6)*QU(5) + F(3)=qu(1)*qu(3)**2+PXX-QU(6)**2 + F(4)=qu(1)*qu(3)*QU(4)-QU(6)*QU(7) + F(5)=QU(3)*QU(5)-qu(2)*QU(6) + F(6)=0. + F(7)=QU(3)*QU(7)-qu(4)*QU(6) + + RETURN + END + + SUBROUTINE FLUXz(QU,F) + Implicit NONE + + ENZO_REAL QU(7),F(7) + ENZO_REAL A1,A2,BKV,PXX + + ENZO_REAL one + parameter (one = 1.0) + + A1=1. + A2=1. + + BKV=QU(5)**2+QU(6)**2+QU(7)**2 + + PXX=A2*qu(1)+BKV/2.e0 + + F(1)=qu(1)*qu(4) + F(2)=qu(1)*qu(2)*QU(4)-QU(5)*QU(7) + F(3)=qu(1)*qu(3)*QU(4)-QU(6)*QU(7) + F(4)=qu(1)*qu(4)**2+PXX-QU(7)**2 + F(5)=QU(4)*QU(5)-qu(2)*QU(7) + F(6)=QU(4)*QU(6)-qu(3)*QU(7) + F(7)=0. + + RETURN + END + + SUBROUTINE FPMR(Y,QL,QR,QP,QC) + Implicit NONE + + Integer m + ENZO_REAL QL(7),QR(7),QP(7),QC(7) + ENZO_REAL DQ,Q6,Y + + DO M=1,7 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) + QC(M)=QL(M)+Y/2.e0*(DQ+(1.e0-2.e0/3.*Y)*Q6) + ENDDO + + RETURN + END + + SUBROUTINE FPML(Y,QL,QR,QP,QC) + Implicit NONE + + Integer m + ENZO_REAL QL(7),QR(7),QP(7),QC(7) + ENZO_REAL DQ,Q6,y + + DO M=1,7 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) + QC(M)=QR(M)-Y/2.e0*(DQ-(1.e0-2.e0/3.*Y)*Q6) + ENDDO + + RETURN + END + + SUBROUTINE FQML(Y,QL,QR,QP,QC) + Implicit NONE + + Integer m + ENZO_REAL QL(7),QR(7),QP(7),QC(7) + ENZO_REAL DQ,Q6,Y + + DO M=1,7 + DQ=QR(M)-QL(M) + Q6=6.0*(QP(M)-(QR(M)+QL(M))/2.e0) + QC(M)=QL(M)+Y*(DQ+(1.e0-Y)*Q6) + ENDDO + + RETURN + END + + subroutine averx(qul,qur,qsr) + Implicit NONE + + ENZO_REAL qul(7),qur(7),qsr(7) + ENZO_REAL RL,RR,RS + + rl=sqrt(qul(1)) + rr=sqrt(qur(1)) + rs=rl+rr + + qsr(1)=rl*rr + qsr(2)=(rl*qul(2)+rr*qur(2))/rs + qsr(3)=(rl*qul(3)+rr*qur(3))/rs + qsr(4)=(rl*qul(4)+rr*qur(4))/rs + qsr(5)=(qul(5)+qur(5))/2.e0 + qsr(6)=(qul(6)/rl+qur(6)/rr)/rs*qsr(1) + qsr(7)=(qul(7)/rl+qur(7)/rr)/rs*qsr(1) + + return + end + + subroutine avery(qul,qur,qsr) + Implicit NONE + + ENZO_REAL qul(7),qur(7),qsr(7) + ENZO_REAL RL,RR,RS + + rl=sqrt(qul(1)) + rr=sqrt(qur(1)) + rs=rl+rr + + qsr(1)=rl*rr + qsr(2)=(rl*qul(2)+rr*qur(2))/rs + qsr(3)=(rl*qul(3)+rr*qur(3))/rs + qsr(4)=(rl*qul(4)+rr*qur(4))/rs + qsr(5)=(qul(5)/rl+qur(5)/rr)/rs*qsr(1) + qsr(6)=(qul(6)+qur(6))/2.e0 + qsr(7)=(qul(7)/rl+qur(7)/rr)/rs*qsr(1) + + return + end + + subroutine averz(qul,qur,qsr) + Implicit NONE + + ENZO_REAL qul(7),qur(7),qsr(7) + ENZO_REAL RL,RR,RS + + rl=sqrt(qul(1)) + rr=sqrt(qur(1)) + rs=rl+rr + + qsr(1)=rl*rr + qsr(2)=(rl*qul(2)+rr*qur(2))/rs + qsr(3)=(rl*qul(3)+rr*qur(3))/rs + qsr(4)=(rl*qul(4)+rr*qur(4))/rs + qsr(5)=(qul(5)/rl+qur(5)/rr)/rs*qsr(1) + qsr(6)=(qul(6)/rl+qur(6)/rr)/rs*qsr(1) + qsr(7)=(qul(7)+qur(7))/2.e0 + + return + end + + + Subroutine QDD6(Nx,Qvr,Qvl,Qrx,Qlx,Qp) + Implicit NONE + Integer m,nx,i + ENZO_REAL Qvr(Nx,7),Qvl(Nx,7),Qp(Nx,7) + ENZO_REAL Qrx(Nx,7),Qlx(Nx,7) + ENZO_REAL DQ,Q6 + + Do I=1,Nx + + DO M=1,7 + + IF((QVR(I,M)-QP(I,M))*(QP(I,M)-QVL(I,M)).LE.0.)THEN + QRX(I,M)=QP(I,M) + QLX(I,M)=QP(I,M) + ELSE + + DQ=QVR(I,M)-QVL(I,M) + Q6=6.0*(QP(I,M)-(QVR(I,M)+QVL(I,M))/2.) + + QLX(I,M)=QVL(I,M) + QRX(I,M)=QVR(I,M) + + IF(DQ*Q6.GT.DQ**2) QLX(I,M)=3.*QP(I,M)-2.*QVR(I,M) + IF(DQ*Q6.LT.-DQ**2) QRX(I,M)=3.*QP(I,M)-2.*QVL(I,M) + + ENDIF + + ENDDO + ENDDO + + Return + End + + SUBROUTINE MATR_AX(QU,QL) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7) + ENZO_REAL A1,A2 + + A1=1. + A2=1. + + QL(1,1)=QU(2) + QL(1,2)=QU(1) + QL(1,3)=0. + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + + QL(2,1)=a2/QU(1) + QL(2,2)=QU(2) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=0. + QL(2,6)=QU(6)/QU(1) + QL(2,7)=QU(7)/QU(1) + + QL(3,1)=0. + QL(3,2)=0. + QL(3,3)=QU(2) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=-QU(5)/QU(1) + QL(3,7)=0. + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(2) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=-QU(5)/QU(1) + + QL(5,1)=0. + QL(5,2)=0. + QL(5,3)=0. + QL(5,4)=0. + QL(5,5)=QU(2) + QL(5,6)=0. + QL(5,7)=0. + + QL(6,1)=0. + QL(6,2)=QU(6) + QL(6,3)=-QU(5) + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=QU(2) + QL(6,7)=0. + + QL(7,1)=0. + QL(7,2)=QU(7) + QL(7,3)=0. + QL(7,4)=-QU(5) + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(2) + + RETURN + END + + SUBROUTINE MATR_AY(QU,QL) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7) + ENZO_REAL A1,A2 + + A1=1. + A2=1. + + QL(1,1)=QU(3) + QL(1,2)=0. + QL(1,3)=QU(1) + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + + QL(2,1)=0. + QL(2,2)=QU(3) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=-QU(6)/QU(1) + QL(2,6)=0. + QL(2,7)=0. + + QL(3,1)=a2/QU(1) + QL(3,2)=0. + QL(3,3)=QU(3) + QL(3,4)=0. + QL(3,5)=QU(5)/QU(1) + QL(3,6)=0. + QL(3,7)=QU(7)/QU(1) + + QL(4,1)=0. + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(3) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=-QU(6)/QU(1) + + QL(5,1)=0. + QL(5,2)=-QU(6) + QL(5,3)=QU(5) + QL(5,4)=0. + QL(5,5)=QU(3) + QL(5,6)=0. + QL(5,7)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=0. + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=QU(3) + QL(6,7)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=QU(7) + QL(7,4)=-QU(6) + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(3) + + RETURN + END + + SUBROUTINE MATR_AZ(QU,QL) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7) + ENZO_REAL A1,A2 + + A1=1. + A2=1. + + QL(1,1)=QU(4) + QL(1,2)=0. + QL(1,3)=0. + QL(1,4)=QU(1) + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + + QL(2,1)=0. + QL(2,2)=QU(4) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=-QU(7)/QU(1) + QL(2,6)=0. + QL(2,7)=0. + + QL(3,1)=0. + QL(3,2)=0. + QL(3,3)=QU(4) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=-QU(7)/QU(1) + QL(3,7)=0. + + QL(4,1)=a2/QU(1) + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(4) + QL(4,5)=QU(5)/QU(1) + QL(4,6)=QU(6)/QU(1) + QL(4,7)=0. + + QL(5,1)=0. + QL(5,2)=-QU(7) + QL(5,3)=0. + QL(5,4)=QU(5) + QL(5,5)=QU(4) + QL(5,6)=0. + QL(5,7)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=-QU(7) + QL(6,4)=QU(6) + QL(6,5)=0. + QL(6,6)=QU(4) + QL(6,7)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=0. + QL(7,4)=0. + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=QU(4) + + RETURN + END + + SUBROUTINE DUDW(Qu,QL) + Implicit NONE + + ENZO_REAL QU(7),QL(7,7) + + QL(1,1)=1. + QL(1,2)=0. + QL(1,3)=0. + QL(1,4)=0. + QL(1,5)=0. + QL(1,6)=0. + QL(1,7)=0. + + QL(2,1)=QU(2) + QL(2,2)=QU(1) + QL(2,3)=0. + QL(2,4)=0. + QL(2,5)=0. + QL(2,6)=0. + QL(2,7)=0. + + QL(3,1)=QU(3) + QL(3,2)=0. + QL(3,3)=QU(1) + QL(3,4)=0. + QL(3,5)=0. + QL(3,6)=0. + QL(3,7)=0. + + QL(4,1)=QU(4) + QL(4,2)=0. + QL(4,3)=0. + QL(4,4)=QU(1) + QL(4,5)=0. + QL(4,6)=0. + QL(4,7)=0. + + QL(5,1)=0. + QL(5,2)=0. + QL(5,3)=0. + QL(5,4)=0. + QL(5,5)=1. + QL(5,6)=0. + QL(5,7)=0. + + QL(6,1)=0. + QL(6,2)=0. + QL(6,3)=0. + QL(6,4)=0. + QL(6,5)=0. + QL(6,6)=1. + QL(6,7)=0. + + QL(7,1)=0. + QL(7,2)=0. + QL(7,3)=0. + QL(7,4)=0. + QL(7,5)=0. + QL(7,6)=0. + QL(7,7)=1. + + RETURN + END + + SUBROUTINE AMPLTD(QL,QD,SL) + Implicit NONE + + Integer m,l + ENZO_REAL QL(7,7),QD(7),SL(7) + + DO M=1,7 + SL(M)=0. + DO L=1,7 + SL(M)=SL(M)+QL(M,L)*QD(L) + ENDDO + ENDDO + + RETURN + END + + Function Xminmod(x,y) + + ENZO_REAL x,y,Xminmod + ENZO_REAL one + parameter (one = 1.0) + + Xminmod = 0.5*(SIGN(one,x) + SIGN(one,y))*min(abs(x),abs(y)) + + Return + End + + Function Xmedian(x,y,z) + + ENZO_REAL x,y,z,Xminmod,Xmedian + + External Xminmod + + Xmedian = x + Xminmod(y-x,z-x) + + Return + End + + SUBROUTINE W5RECM(VP1,VP2,VP3,VP4,VP5,VL,VR) + Implicit NONE + + ENZO_REAL IS1,IS2,IS3,DELTA,WS1,WS2,WS3,WJ1,WJ2,WJ3 + ENZO_REAL AJ1,AJ2,AJ3,AJS,WM1,WM2,WM3,VL,VR + ENZO_REAL VP1,VP2,VP3,VP4,VP5 + + DELTA = 1.0d-20 + + WS1 = 0.1E0 + WS2 = 0.6E0 + WS3 = 0.3E0 + + + WJ1 = (11.E0*VP3 - 7.E0*VP2 + 2.E0*VP1)/6.E0 + WJ2 = (2.E0 *VP4 + 5.E0*VP3 - VP2)/6.E0 + WJ3 = ( -VP5 + 5.E0*VP4 + 2.E0*VP3)/6.E0 + + IS1 = 13.E0/12.E0*(VP3 - 2.E0*VP2 + VP1)**2 + & + (3.E0*VP3 - 4.E0*VP2 + VP1)**2/4.E0 + IS2 = 13.E0/12.E0*(VP4 - 2.E0*VP3 + VP2)**2 + & + (VP4 - VP2)**2/4.E0 + IS3 = 13.E0/12.E0*(VP5 - 2.E0*VP4 + VP3)**2 + & + (VP5 - 4.E0*VP4 + 3.E0*VP3)**2/4.E0 + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1)/(WS1*WS1 + & + WM1*(1.E0 - 2.E0*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2)/(WS2*WS2 + & + WM2*(1.E0 - 2.E0*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3)/(WS3*WS3 + & + WM3*(1.E0 - 2.E0*WS3)) + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + VR = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + WJ1 = (11.E0*VP3 - 7.E0*VP4 + 2.E0*VP5)/6.E0 + WJ2 = (2.E0 *VP2 + 5.E0*VP3 - VP4)/6.E0 + WJ3 = ( -VP1 + 5.E0*VP2 + 2.E0*VP3)/6.E0 + + IS1 = 13.E0/12.E0*(VP3 - 2.E0*VP4 + VP5)**2 + & + (3.E0*VP3 - 4.E0*VP4 + VP5)**2/4.E0 + IS2 = 13.E0/12.E0*(VP2 - 2.E0*VP3 + VP4)**2 + & + (VP2 - VP4)**2/4.E0 + IS3 = 13.E0/12.E0*(VP1 - 2.E0*VP2 + VP3)**2 + & + (VP1 - 4.E0*VP2 + 3.E0*VP3)**2/4.E0 + + AJ1 = WS1/(IS1+DELTA)**2 + AJ2 = WS2/(IS2+DELTA)**2 + AJ3 = WS3/(IS3+DELTA)**2 + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + AJ1 = WM1*(WS1 + WS1*WS1 - 3.E0*WS1*WM1 + WM1*WM1)/(WS1*WS1 + & + WM1*(1.E0 - 2.E0*WS1)) + AJ2 = WM2*(WS2 + WS2*WS2 - 3.E0*WS2*WM2 + WM2*WM2)/(WS2*WS2 + & + WM2*(1.E0 - 2.E0*WS2)) + AJ3 = WM3*(WS3 + WS3*WS3 - 3.E0*WS3*WM3 + WM3*WM3)/(WS3*WS3 + & + WM3*(1.E0 - 2.E0*WS3)) + + AJS = AJ1 + AJ2 +AJ3 + + WM1 = AJ1/AJS + WM2 = AJ2/AJS + WM3 = AJ3/AJS + + VL = WM1*WJ1 + WM2*WJ2 + WM3*WJ3 + + RETURN + END + + Function VLeer(a,b) + + ENZO_REAL a,b,VLeer + + if(a*a+b*b.ne.0)then + VLeer=max(a*b,0.)*(a+b)/(a*a+b*b) + + else + VLeer=0. + endif + + Return + End + + SUBROUTINE PRIM(QU,QP) + + ENZO_REAL QU(7),QP(7) + + QP(1)=QU(1) + QP(2)=QU(2)/QU(1) + QP(3)=QU(3)/QU(1) + QP(4)=QU(4)/QU(1) + QP(5)=QU(5) + QP(6)=QU(6) + QP(7)=QU(7) + + RETURN + END + + SUBROUTINE CONS(QP,QU) + + ENZO_REAL QU(7),QP(7) + + QU(1)=QP(1) + QU(2)=QP(2)*QP(1) + QU(3)=QP(3)*QP(1) + QU(4)=QP(4)*QP(1) + QU(5)=QP(5) + QU(6)=QP(6) + QU(7)=QP(7) + + RETURN + END diff --git a/src/Enzo/hydro-mhd/ppml_ig/CMakeLists.txt b/src/Enzo/hydro-mhd/ppml_ig/CMakeLists.txt new file mode 100644 index 0000000000..04415f3667 --- /dev/null +++ b/src/Enzo/hydro-mhd/ppml_ig/CMakeLists.txt @@ -0,0 +1,21 @@ +# See LICENSE_CELLO file for license and copyright information + +# STEP 1: adds source files related to Hydro/MHD integrators to the enzo target +# +# in the future, we may want to slightly refactor the files in this +# subdirectory so that they can be compiled into their own subtarget (there's +# a lot here that the rest of Enzo-E doesn't need to know anything about and +# this can improve compile times) + +# Get the list of source files in this directory & the fortran subdirectories +# - we do this using GLOB patterns. This approach is not recommended by the +# authors of CMake (their recommendation is to explicitly list all files that +# must be installed). +# - Some of the disadvantages of this approach are mitigated by inclusion of +# the CONFIGURE_DEPENDS flag. +# - See the CMake Primer section of the developer documentation for more details +file(GLOB LOCAL_SRC_FILES CONFIGURE_DEPENDS + *.cpp *.hpp +) +target_sources(enzo PRIVATE ${LOCAL_SRC_FILES}) + diff --git a/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.cpp b/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.cpp new file mode 100644 index 0000000000..652bfefe6e --- /dev/null +++ b/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.cpp @@ -0,0 +1,223 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoMethodPpmlIG.cpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Fri Apr 2 17:05:23 PDT 2010 +/// @author Alexei Kritsuk (akritsuk@ucsd.edu) +/// @date Tue Sep 18 14:16:01 PDT 2018 +/// @brief Implements the EnzoMethodPpmlIG class + +//---------------------------------------------------------------------- + +#include "cello.hpp" +#include "enzo.hpp" + +//---------------------------------------------------------------------- + +// #define DEBUG_FIELDS + +#ifdef DEBUG_FIELDS +# define CHECK_FIELD(VALUES,NAME) \ + ASSERT1("CHECK_FIELD", \ + "Field %s must be defined", \ + NAME, \ + (VALUES != nullptr)); + +# define FIELD_STATS(NAME,VALUES,mx,my,mz,gx,gy,gz) \ + { \ + double avg=0.0, max=-1.0, min=1e9; \ + int count=0; \ + for (int iz=gz; izphysics_cosmology), + gamma_ (enzo::fluid_props()->gamma()), + b0_() +{ + b0_[0] = enzo::config()->method_ppml_b0[0]; + b0_[1] = enzo::config()->method_ppml_b0[1]; + b0_[2] = enzo::config()->method_ppml_b0[2]; + // Initialize the default Refresh object + + cello::simulation()->refresh_set_name(ir_post_,name()); + + Refresh * refresh = cello::refresh(ir_post_); + refresh->add_all_fields(); +} + +//---------------------------------------------------------------------- + +void EnzoMethodPpmlIG::pup (PUP::er &p) +{ + // NOTE: change this function whenever attributes change + + TRACEPUP; + + Method::pup(p); + p | comoving_coordinates_; + p | gamma_; + PUParray(p,b0_,3); +} + +//---------------------------------------------------------------------- + +void EnzoMethodPpmlIG::compute ( Block * block ) throw() +{ + + if (block->is_leaf()) { + EnzoBlock * enzo_block = static_cast (block); + enzo_block->SolveMHDEquationsIG ( block->dt(), gamma_, b0_ ); + } + + block->compute_done(); +} + +//---------------------------------------------------------------------- + +double EnzoMethodPpmlIG::timestep (Block * block) throw() +{ + EnzoBlock * enzo_block = static_cast (block); + + /* initialize */ + + enzo_float dt; + // enzo_float dtTemp; + enzo_float dtBaryons = ENZO_HUGE_VAL; + // enzo_float dtViscous = ENZO_HUGE_VAL; + // enzo_float dtParticles = ENZO_HUGE_VAL; + // enzo_float dtExpansion = ENZO_HUGE_VAL; + // enzo_float dtAcceleration = ENZO_HUGE_VAL; + // int dim, i, result; + + /* Compute the field size. */ + + // int size = 1; + // for (dim = 0; dim < GridRank; dim++) + // size *= GridDimension[dim]; + + /* If using comoving coordinates, compute the expansion factor a. Otherwise, + set it to one. */ + + enzo_float cosmo_a = 1.0, cosmo_dadt = 0.0; + + EnzoPhysicsCosmology * cosmology = enzo::cosmology(); + + ASSERT ("EnzoMethodPpmlIG::timestep()", + "comoving_coordinates enabled but missing EnzoPhysicsCosmology", + ! (comoving_coordinates_ && (cosmology == NULL)) ); + + if (cosmology) { + cosmology->compute_expansion_factor (&cosmo_a, &cosmo_dadt,enzo_block->time()); + } + // float afloat = float(a); + + /* 1) Compute Courant condition for baryons. */ + + const int in = cello::index_static(); + if (EnzoBlock::NumberOfBaryonFields[in] > 0) { + + /* Find fields: density, total energy, velocity1-3. */ + + // int DensNum, GENum, Vel1Num, Vel2Num, Vel3Num, TENum; + // float *pressure_field; + + // if (HydroMethod != PPML_Isothermal3D) { + // if (this->IdentifyPhysicalQuantities(DensNum, GENum, Vel1Num, Vel2Num, + // Vel3Num, TENum) == FAIL) { + // fprintf(stderr, "ComputeTimeStep: IdentifyPhysicalQuantities error.\n"); + // exit(FAIL); + + + // /* Compute the pressure. */ + + // pressure_field = new float[size]; + // if (DualEnergyFormalism) + // result = this->ComputePressureDualEnergyFormalism(Time, pressure_field); + // else + // result = this->ComputePressure(Time, pressure_field); + + // if (result == FAIL) { + // fprintf(stderr, "Error in grid->ComputePressure.\n"); + // exit(EXIT_FAILURE); + // } + // } + + /* Call fortran routine to do calculation. */ + + Field field = enzo_block->data()->field(); + + enzo_float * d = (enzo_float *) field.values("density"); + enzo_float * vx = (enzo_float *) field.values("velox"); + enzo_float * vy = (enzo_float *) field.values("veloy"); + enzo_float * vz = (enzo_float *) field.values("veloz"); + enzo_float * bx = (enzo_float *) field.values("bfieldx"); + enzo_float * by = (enzo_float *) field.values("bfieldy"); + enzo_float * bz = (enzo_float *) field.values("bfieldz"); + enzo_float * pr = (enzo_float *) field.values("pressure"); + CHECK_FIELD(d,"density"); + CHECK_FIELD(vx,"velox"); + CHECK_FIELD(vy,"veloy"); + CHECK_FIELD(vz,"veloz"); + CHECK_FIELD(bx,"bfieldx"); + CHECK_FIELD(by,"bfieldy"); + CHECK_FIELD(bz,"bfieldz"); + CHECK_FIELD(pr,"pressure"); + + /// Compute pressure + // const int in = cello::index_static(); + // EnzoComputePressure compute_pressure (EnzoBlock::Gamma[in], false); + // compute_pressure.compute(enzo_block, pr); + + FORTRAN_NAME(calc_dt_ppml_ig) + (enzo_block->GridDimension, + enzo_block->GridDimension+1, + enzo_block->GridDimension+2, + enzo_block->GridStartIndex, + enzo_block->GridEndIndex, + enzo_block->GridStartIndex+1, + enzo_block->GridEndIndex+1, + enzo_block->GridStartIndex+2, + enzo_block->GridEndIndex+2, + &enzo_block->CellWidth[0], + &enzo_block->CellWidth[1], + &enzo_block->CellWidth[2], + d, + vx, vy, vz, + bx, by, bz, pr, + b0_, &gamma_, + &dtBaryons); + + dtBaryons *= courant_; + + } + + /* 5) calculate minimum timestep */ + + dt = std::numeric_limits::max(); + + dt = MIN(dt, dtBaryons); + + return dt; +} + +//---------------------------------------------------------------------- diff --git a/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.hpp b/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.hpp new file mode 100644 index 0000000000..be30d6e445 --- /dev/null +++ b/src/Enzo/hydro-mhd/ppml_ig/EnzoMethodPpmlIG.hpp @@ -0,0 +1,55 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoMethodPpmlIG.hpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Mon May 17 14:16:01 PDT 2010 +/// @author Alexei Kritsuk (akritsuk@ucsd.edu) +/// @date Tue Sep 18 14:16:01 PDT 2018 +/// @brief [\ref Enzo] Implementation of Enzo PPML method for ideal gas + +#ifndef ENZO_ENZO_METHOD_PPMLIG_HPP +#define ENZO_ENZO_METHOD_PPMLIG_HPP + +class EnzoMethodPpmlIG : public Method { + +/// @class EnzoMethodPpmlIG +/// @ingroup Enzo +/// @brief [\ref Enzo] Encapsulate Enzo's PPML MHD method for ideal gas + +public: // interface + + /// Creae a new EnzoMethodPpmlIG object + EnzoMethodPpmlIG(); + + /// Charm++ PUP::able declarations + PUPable_decl(EnzoMethodPpmlIG); + + /// Charm++ PUP::able migration constructor + EnzoMethodPpmlIG (CkMigrateMessage *m) + : Method (m), + comoving_coordinates_(false), + gamma_(0.0), + b0_() + {} + + /// CHARM++ Pack / Unpack function + void pup (PUP::er &p); + + /// Apply the method to advance a block one timestep + virtual void compute( Block * block ) throw(); + + virtual std::string name () throw () + { return "ppml_ig"; } + + /// Compute maximum timestep for this method + virtual double timestep ( Block * block) throw(); + +protected: // interface + + bool comoving_coordinates_; + enzo_float gamma_; + enzo_float b0_[3]; + +}; + +#endif /* ENZO_ENZO_METHOD_PPMLIG_HPP */ diff --git a/src/Enzo/hydro-mhd/ppml_ig/SolveMHDEquationsIG.cpp b/src/Enzo/hydro-mhd/ppml_ig/SolveMHDEquationsIG.cpp new file mode 100644 index 0000000000..cfdca9f4a3 --- /dev/null +++ b/src/Enzo/hydro-mhd/ppml_ig/SolveMHDEquationsIG.cpp @@ -0,0 +1,326 @@ +// See LICENSE_ENZO file for license and copyright information + +/*********************************************************************** +/ +/ GRID CLASS (SOLVE THE MHD EQUATIONS (with PPML for Ideal Gas), SAVING SUBGRID FLUXES) +/ +/ written by: Greg Bryan +/ date: November, 1994 +/ modified1: Alexei Kritsuk, April 2009 (PPML), Sept 2018 (PPML-IG) +/ +/ PURPOSE: +/ +/ RETURNS: +/ ENZO_SUCCESS or ENZO_FAIL +/ +************************************************************************/ + +// Solve the MHD equations with the solver, saving the subgrid fluxes + +#include "cello.hpp" +#include "enzo.hpp" + +//---------------------------------------------------------------------- + +// #define DEBUG_FIELDS + +#ifdef DEBUG_FIELDS +# define CHECK_FIELD(VALUES,NAME) \ + ASSERT1("CHECK_FIELD", \ + "Field %s must be defined", \ + NAME, \ + (VALUES != nullptr)); + +# define FIELD_STATS(NAME,VALUES,mx,my,mz,gx,gy,gz) \ + { \ + double avg=0.0, max=-1.0, min=1e9; \ + int count=0; \ + for (int iz=gz; iz 0) { + + /* initialize */ + + int dim, i, size; + // Elong_int GridGlobalStart[MAX_DIMENSION]; + + /* Compute size (in floats) of the current grid. */ + + const int in = cello::index_static(); + + size = 1; + for (dim = 0; dim < GridRank[in]; dim++) + size *= GridDimension[dim]; + + /* Get easy to handle pointers for each variable. */ + + + Field field = data()->field(); + + enzo_float *density = (enzo_float *) field.values ("density"); + enzo_float *velox = (enzo_float *) field.values ("velox"); + enzo_float *veloy = (enzo_float *) field.values ("veloy"); + enzo_float *veloz = (enzo_float *) field.values ("veloz"); + enzo_float *bfieldx = (enzo_float *) field.values ("bfieldx"); + enzo_float *bfieldy = (enzo_float *) field.values ("bfieldy"); + enzo_float *bfieldz = (enzo_float *) field.values ("bfieldz"); + enzo_float *pressure = (enzo_float *) field.values ("pressure"); + + enzo_float *dens_rx = (enzo_float *) field.values ("dens_rx"); + enzo_float *velox_rx = (enzo_float *) field.values ("velox_rx"); + enzo_float *veloy_rx = (enzo_float *) field.values ("veloy_rx"); + enzo_float *veloz_rx = (enzo_float *) field.values ("veloz_rx"); + enzo_float *bfieldx_rx = (enzo_float *) field.values ("bfieldx_rx"); + enzo_float *bfieldy_rx = (enzo_float *) field.values ("bfieldy_rx"); + enzo_float *bfieldz_rx = (enzo_float *) field.values ("bfieldz_rx"); + enzo_float *press_rx = (enzo_float *) field.values ("press_rx"); + + enzo_float *dens_ry = (enzo_float *) field.values ("dens_ry"); + enzo_float *velox_ry = (enzo_float *) field.values ("velox_ry"); + enzo_float *veloy_ry = (enzo_float *) field.values ("veloy_ry"); + enzo_float *veloz_ry = (enzo_float *) field.values ("veloz_ry"); + enzo_float *bfieldx_ry = (enzo_float *) field.values ("bfieldx_ry"); + enzo_float *bfieldy_ry = (enzo_float *) field.values ("bfieldy_ry"); + enzo_float *bfieldz_ry = (enzo_float *) field.values ("bfieldz_ry"); + enzo_float *press_ry = (enzo_float *) field.values ("press_ry"); + + enzo_float *dens_rz = (enzo_float *) field.values ("dens_rz"); + enzo_float *velox_rz = (enzo_float *) field.values ("velox_rz"); + enzo_float *veloy_rz = (enzo_float *) field.values ("veloy_rz"); + enzo_float *veloz_rz = (enzo_float *) field.values ("veloz_rz"); + enzo_float *bfieldx_rz = (enzo_float *) field.values ("bfieldx_rz"); + enzo_float *bfieldy_rz = (enzo_float *) field.values ("bfieldy_rz"); + enzo_float *bfieldz_rz = (enzo_float *) field.values ("bfieldz_rz"); + enzo_float *press_rz = (enzo_float *) field.values ("press_rz"); + + CHECK_FIELD(density,"density"); + CHECK_FIELD(velox,"velox"); + CHECK_FIELD(veloy,"veloy"); + CHECK_FIELD(veloz,"veloz"); + CHECK_FIELD(bfieldx,"bfieldx"); + CHECK_FIELD(bfieldy,"bfieldy"); + CHECK_FIELD(bfieldz,"bfieldz"); + CHECK_FIELD(pressure,"pressure"); + + CHECK_FIELD(dens_rx,"dens_rx"); + CHECK_FIELD(velox_rx,"velox_rx"); + CHECK_FIELD(veloy_rx,"veloy_rx"); + CHECK_FIELD(veloz_rx,"veloz_rx"); + CHECK_FIELD(bfieldx_rx,"bfieldx_rx"); + CHECK_FIELD(bfieldy_rx,"bfieldy_rx"); + CHECK_FIELD(bfieldz_rx,"bfieldz_rx"); + CHECK_FIELD(press_rx,"press_rx"); + + CHECK_FIELD(dens_ry,"dens_ry"); + CHECK_FIELD(velox_ry,"velox_ry"); + CHECK_FIELD(veloy_ry,"veloy_ry"); + CHECK_FIELD(veloz_ry,"veloz_ry"); + CHECK_FIELD(bfieldx_ry,"bfieldx_ry"); + CHECK_FIELD(bfieldy_ry,"bfieldy_ry"); + CHECK_FIELD(bfieldz_ry,"bfieldz_ry"); + CHECK_FIELD(press_ry,"press_ry"); + + CHECK_FIELD(dens_rz,"dens_rz"); + CHECK_FIELD(velox_rz,"velox_rz"); + CHECK_FIELD(veloy_rz,"veloy_rz"); + CHECK_FIELD(veloz_rz,"veloz_rz"); + CHECK_FIELD(bfieldx_rz,"bfieldx_rz"); + CHECK_FIELD(bfieldy_rz,"bfieldy_rz"); + CHECK_FIELD(bfieldz_rz,"bfieldz_rz"); + CHECK_FIELD(press_rz,"press_rz"); + + + for (i = GridRank[in]; i < 3; i++) { + GridDimension[i] = 1; + GridStartIndex[i] = 0; + GridEndIndex[i] = 0; + // GridGlobalStart[i] = 0; + } + + /* allocate temporary space for solver */ + + enzo_float *temp = new enzo_float[size*(35)]; + enzo_float *p = temp; + enzo_float *f1 = p; p += size; + enzo_float *f2 = p; p += size; + enzo_float *f3 = p; p += size; + enzo_float *f4 = p; p += size; + enzo_float *f5 = p; p += size; + enzo_float *f6 = p; p += size; + enzo_float *f7 = p; p += size; + enzo_float *f8 = p; p += size; + enzo_float *g1 = p; p += size; + enzo_float *g2 = p; p += size; + enzo_float *g3 = p; p += size; + enzo_float *g4 = p; p += size; + enzo_float *g5 = p; p += size; + enzo_float *g6 = p; p += size; + enzo_float *g7 = p; p += size; + enzo_float *g8 = p; p += size; + enzo_float *h1 = p; p += size; + enzo_float *h2 = p; p += size; + enzo_float *h3 = p; p += size; + enzo_float *h4 = p; p += size; + enzo_float *h5 = p; p += size; + enzo_float *h6 = p; p += size; + enzo_float *h7 = p; p += size; + enzo_float *h8 = p; p += size; + enzo_float *ex = p; p += size; + enzo_float *ey = p; p += size; + enzo_float *ez = p; p += size; + enzo_float *qu1 = p; p += size; + enzo_float *qu2 = p; p += size; + enzo_float *qu3 = p; p += size; + enzo_float *qu4 = p; p += size; + enzo_float *qu5 = p; p += size; + enzo_float *qu6 = p; p += size; + enzo_float *qu7 = p; p += size; + enzo_float *qu8 = p; p += size; + + ASSERT ("EnzoBlock::SolveMHDEquationsIG", + "Insufficient temporary storage", + (p-temp) <= 35*size); + // k <= 35); + + /* create and fill in arrays which are easiler for the solver to + understand. */ + + int NumberOfSubgrids = 0; // JB + + enzo_float *standard = NULL; + + int *leftface = NULL; + int *rightface = NULL; + int *istart = NULL; + int *jstart = NULL; + int *iend = NULL; + int *jend = NULL; + int *dnindex = NULL; + int *vxindex = NULL; + int *vyindex = NULL; + int *vzindex = NULL; + int *bxindex = NULL; + int *byindex = NULL; + int *bzindex = NULL; + int *prindex = NULL; + + /* If using comoving coordinates, multiply dx by a(n+1/2). + In one fell swoop, this recasts the equations solved by solver + in comoving form (except for the expansion terms which are taken + care of elsewhere). */ + + /* Create a cell width array to pass (and convert to absolute coords). */ + // this is not going to work for cosmology right away !AK + + enzo_float a = 1.0; + enzo_float CellWidthTemp[MAX_DIMENSION]; + for (dim = 0; dim < MAX_DIMENSION; dim++) { + if (dim < GridRank[in]) + CellWidthTemp[dim] = enzo_float(a*CellWidth[dim]); + else + CellWidthTemp[dim] = 1.0; + } + + /* Prepare Gravity. */ + + /* call a Fortran routine to actually compute the hydro equations + on this grid. + Notice that it is hard-wired for three dimensions, but it does + the right thing for < 3 dimensions. */ + /* note: Start/EndIndex are zero based */ + + + /* current PPML-IG implementation only supports 3D and does not + support color fields */ + + int mx,my,mz; + field.dimensions(0,&mx,&my,&mz); + const int m = mx*my*mz; + + enzo_float *velocity_x = (enzo_float *) field.values ("velocity_x"); + enzo_float *velocity_y = (enzo_float *) field.values ("velocity_y"); + enzo_float *velocity_z = (enzo_float *) field.values ("velocity_z"); + bool have_velocity = (velocity_x != nullptr); + + if (have_velocity) { + std::copy_n(velocity_x,m,velox); + std::copy_n(velocity_y,m,veloy); + std::copy_n(velocity_z,m,veloz); + } + + int gx,gy,gz; + field.ghost_depth(0,&gx,&gy,&gz); + + FIELD_STATS("press_rx",press_rx,mx,my,mz,gx,gy,gz); + + FORTRAN_NAME(ppml_ig) + (density,velox, veloy, veloz, bfieldx, bfieldy, bfieldz, pressure, + dens_rx,velox_rx,veloy_rx,veloz_rx,bfieldx_rx,bfieldy_rx,bfieldz_rx,press_rx, + dens_ry,velox_ry,veloy_ry,veloz_ry,bfieldx_ry,bfieldy_ry,bfieldz_ry,press_ry, + dens_rz,velox_rz,veloy_rz,veloz_rz,bfieldx_rz,bfieldy_rz,bfieldz_rz,press_rz, + // gravity,gx,gy,gz, + b0, &gamma, + &dt, &CellWidthTemp[0], &CellWidthTemp[1], &CellWidthTemp[2], + &GridDimension[0], &GridDimension[1], &GridDimension[2], + GridStartIndex, GridEndIndex, + &NumberOfSubgrids, leftface, rightface, + istart, iend, jstart, jend, + standard, dnindex, + vxindex, vyindex, vzindex, + bxindex, byindex, bzindex, + prindex, + f1,f2,f3,f4,f5,f6,f7,f8, + g1,g2,g3,g4,g5,g6,g7,g8, + h1,h2,h3,h4,h5,h6,h7,h8, + ex,ey,ez, + qu1,qu2,qu3,qu4,qu5,qu6,qu7,qu8); + + FIELD_STATS("press_rx",press_rx,mx,my,mz,gx,gy,gz); + + if (have_velocity) { + std::copy_n(velox,m,velocity_x); + std::copy_n(veloy,m,velocity_y); + std::copy_n(veloz,m,velocity_z); + } + + /* deallocate temporary space for solver */ + + delete [] temp; + + delete [] leftface; + + } // end: if (NumberOfBaryonFields > 0) + + return ENZO_SUCCESS; + +} diff --git a/src/Enzo/io/EnzoMethodCheck.cpp b/src/Enzo/io/EnzoMethodCheck.cpp index 005e9cd86d..5394611bdc 100644 --- a/src/Enzo/io/EnzoMethodCheck.cpp +++ b/src/Enzo/io/EnzoMethodCheck.cpp @@ -421,7 +421,7 @@ FileHdf5 * IoEnzoWriter::file_open_ void IoEnzoWriter::file_write_hierarchy_() { - IoSimulation io_simulation = (cello::simulation()); + IoEnzoSimulation io_simulation (enzo::simulation()); for (size_t i=0; iturbou_real_state_), + enzo_turbou_int_state_(s->turbou_int_state_), + num_real_(s->turbou_real_state_.size()), + num_int_(s->turbou_int_state_.size()) +{ + // save number of meta data elements in IoSimulation's + + index_enzo_ = meta_count(); + + if (num_real_ > 0) { + meta_name_.push_back("enzo_turbou_num_real"); + meta_name_.push_back("enzo_turbou_num_int"); + meta_name_.push_back("enzo_turbou_real_state"); + meta_name_.push_back("enzo_turbou_int_state"); + } +} + +//---------------------------------------------------------------------- + +void IoEnzoSimulation::meta_value +(int index, + void ** buffer, std::string * name, int * type, + int * nxd, int * nyd, int * nzd) throw() +{ + + if (index < index_enzo_) { + + IoSimulation::meta_value(index,buffer,name,type,nxd,nyd,nzd); + + } else { + + Io::meta_value(index,buffer,name,type,nxd,nyd,nzd); + + int index_count = index_enzo_; + + if (index == index_count++) { + + *buffer = (void *) &num_real_; + *type = type_int; + *nxd = 1; + + } else if (index == index_count++) { + + *buffer = (void *) &num_int_; + *type = type_int; + *nxd = 1; + + } else if (index == index_count++) { + + if (enzo_turbou_real_state_.size() < num_real_) { + enzo_turbou_real_state_.resize(num_real_); + } + *buffer = (void *) enzo_turbou_real_state_.data(); + *type = type_double; + *nxd = num_real_; + + } else if (index == index_count++) { + if (enzo_turbou_int_state_.size() < num_int_) { + enzo_turbou_int_state_.resize(num_int_); + } + *buffer = (void *) enzo_turbou_int_state_.data(); + *type = type_int; + *nxd = num_int_; + + } + } +} +//---------------------------------------------------------------------- + +void IoEnzoSimulation::data_value +(int index, + void ** buffer, std::string * name, int * type, + int * nxd, int * nyd, int * nzd) throw() +{ +} + +//====================================================================== + +int IoEnzoSimulation::data_size () const +{ + int size = 0; + + size += IoSimulation::data_size(); + + SIZE_SCALAR_TYPE(size,int,num_real_); + SIZE_SCALAR_TYPE(size,int,num_int_); + SIZE_VECTOR_TYPE(size,double,enzo_turbou_real_state_); + SIZE_VECTOR_TYPE(size,int,enzo_turbou_int_state_); + + return size; +} + +//---------------------------------------------------------------------- + +char * IoEnzoSimulation::save_data (char * buffer) const +{ + char * pc = buffer; + + pc = IoSimulation::save_data(pc); + + SAVE_SCALAR_TYPE(pc,int,num_real_); + SAVE_SCALAR_TYPE(pc,int,num_int_); + SAVE_VECTOR_TYPE(pc,double,enzo_turbou_real_state_); + SAVE_VECTOR_TYPE(pc,int,enzo_turbou_int_state_); + + ASSERT2 ("IoEnzoSimulation::save_data()", + "Expecting buffer size %d actual size %d", + IoEnzoSimulation::data_size(),(pc-buffer), + (IoEnzoSimulation::data_size() == (pc-buffer))); + + // return first byte after filled buffer + return pc; +} + +//---------------------------------------------------------------------- + +char * IoEnzoSimulation::load_data (char * buffer) +{ + char * pc = buffer; + + pc = IoSimulation::load_data(pc); + + LOAD_SCALAR_TYPE(pc,int,num_real_); + LOAD_SCALAR_TYPE(pc,int,num_int_); + LOAD_VECTOR_TYPE(pc,double,enzo_turbou_real_state_); + LOAD_VECTOR_TYPE(pc,int,enzo_turbou_int_state_); + + return pc; +} + +//---------------------------------------------------------------------- + +void IoEnzoSimulation::save_to (void * v) +{ + IoSimulation::save_to(v); + + EnzoSimulation * enzo_simulation = (EnzoSimulation *)v; + + enzo_simulation->turbou_real_state_ = enzo_turbou_real_state_; + enzo_simulation->turbou_int_state_ = enzo_turbou_int_state_; + +} + +//---------------------------------------------------------------------- diff --git a/src/Enzo/io/IoEnzoSimulation.hpp b/src/Enzo/io/IoEnzoSimulation.hpp new file mode 100644 index 0000000000..f6966069a0 --- /dev/null +++ b/src/Enzo/io/IoEnzoSimulation.hpp @@ -0,0 +1,83 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_IoEnzoSimulation.hpp +/// @author James Bordner (jobordner@ucsd.edu) +/// @date 2022-05-12 +/// @brief [\ref Enzo] Declaration of the IoEnzoSimulation class + +#ifndef IO_IO_ENZO_SIMULATION_HPP +#define IO_IO_ENZO_SIMULATION_HPP + +class EnzoSimulation; + +class IoEnzoSimulation : public IoSimulation { + + /// @class IoEnzoSimulation + /// @ingroup Enzo + /// @brief [\ref Enzo] Class for interfacing between EnzoSimulation and Output objects + +public: // interface + + /// Constructor + IoEnzoSimulation(const EnzoSimulation * simulation) throw(); + + /// CHARM++ PUP::able declaration + PUPable_decl(IoEnzoSimulation); + + /// CHARM++ migration constructor + IoEnzoSimulation(CkMigrateMessage *m) : IoSimulation(m) {} + + /// CHARM++ Pack / Unpack function + inline void pup (PUP::er &p) + { + // NOTE: change this function whenever attributes change + IoSimulation::pup(p); + TRACEPUP; + + p | index_enzo_; + + p | enzo_turbou_real_state_; + p | enzo_turbou_int_state_; + p | num_real_; + p | num_int_; + + } + + /// Return the ith metadata item associated with the EnzoSimulation object + void meta_value + (int index, + void ** buffer, std::string * name, int * type, + int * nxd=0, int * nyd=0, int * nzd=0) throw(); + + /// Return the ith data item associated with the EnzoSimulation object + void data_value + (int index, + void ** buffer, std::string * name, int * type, + int * nxd=0, int * nyd=0, int * nzd=0) throw(); + + /// PACKING / UNPACKING + + /// Return the number of bytes required to serialize the data object + virtual int data_size () const; + + /// Serialize the object into the provided empty memory buffer. + virtual char * save_data (char * buffer) const; + + /// Restore the object from the provided initialized memory buffer data. + virtual char * load_data (char * buffer); + + /// Copy the values to the object + virtual void save_to (void *); + +private: + + int index_enzo_; + + std::vector enzo_turbou_real_state_; + std::vector enzo_turbou_int_state_; + int num_real_; + int num_int_; +}; + +#endif /* IO_IO_ENZO_SIMULATION_HPP */ + diff --git a/src/Enzo/io/control_restart.cpp b/src/Enzo/io/control_restart.cpp index 53d513bd64..d298738a31 100644 --- a/src/Enzo/io/control_restart.cpp +++ b/src/Enzo/io/control_restart.cpp @@ -134,7 +134,10 @@ void Simulation::p_restart_enter (std::string name_dir) TRACE_SYNC(sync_restart_created_,"sync_restart_created_ set_stop()"); sync_restart_created_.set_stop(restart_num_files_); TRACE_SYNC(sync_restart_next_,"sync_restart_next_ set_stop()"); - sync_restart_next_.set_stop(restart_num_files_); + + // Synchronize after all files are done reading AND all EnzoMsgRestart + // objects received + sync_restart_next_.set_stop(restart_num_files_ + CkNumPes()); // Create new empty IoEnzoReader chare array and distribute to other processing elements CProxy_MappingIo io_map = CProxy_MappingIo::ckNew(restart_num_files_); @@ -172,7 +175,6 @@ void EnzoSimulation::p_io_reader_created() // Wait for all io_readers to be created TRACE_SYNC(sync_restart_created_,"sync_restart_created_ next()"); if (sync_restart_created_.next()) { - // distribute array proxy to other simulation objects proxy_enzo_simulation.p_set_io_reader(proxy_io_enzo_reader); } } @@ -353,6 +355,7 @@ void IoEnzoReader::block_ready_() // Wait for all of the reader's blocks in the current level to be // ready if (sync_blocks_.next()) { + TRACE_READER("p_block_ready() calling p_restart_next_level",this); proxy_enzo_simulation[0].p_restart_next_level(); } } @@ -365,6 +368,8 @@ void EnzoSimulation::p_restart_next_level() TRACE_SIMULATION("EnzoSimulation::p_restart_next_level()",this); TRACE_SYNC(sync_restart_next_,"sync_restart_next_ next()"); if (sync_restart_next_.next()) { + // first update sync stop to only count restart_num_files_ + sync_restart_next_.set_stop(restart_num_files_); const int max_level = cello::config()->mesh_max_level; if (++restart_level_ <= max_level) { proxy_io_enzo_reader.p_create_level(restart_level_); @@ -588,7 +593,6 @@ std::ifstream IoEnzoReader::stream_open_blocks_ void IoEnzoReader::file_read_hierarchy_() { - // Simulation data if (thisIndex == 0) { IoSimulation io_simulation = (cello::simulation()); for (size_t i=0; ifile_read_meta(buffer,name.c_str(),&type_scalar,&nx,&ny,&nz); } - // Get current state double time,dt; int cycle; @@ -621,6 +624,27 @@ void IoEnzoReader::file_read_hierarchy_() //---------------------------------------------------------------------- +void EnzoSimulation::p_restart_get_io_simulation(int n, char * buffer) + +{ + char * p = buffer; + + IoEnzoSimulation io_simulation (enzo::simulation()); + p = io_simulation.load_data(p); + io_simulation.save_to((void *)this); + + IoHierarchy io_hierarchy (cello::hierarchy()); + p = io_hierarchy.load_data(p); + io_hierarchy.save_to((void *)this); + + // Synchronize at root EnzoSimulation + if (thisIndex == 0) { + TRACE_SIMULATION("p_restart_get_io_simulation() calling p_restart_next_level",this); + proxy_enzo_simulation[0].p_restart_next_level(); + } +} +//---------------------------------------------------------------------- + void IoEnzoReader::file_read_block_ (EnzoMsgCheck * msg_check, std::string name_block) diff --git a/src/Enzo/mesh/EnzoRefineMass.cpp b/src/Enzo/mesh/EnzoRefineMass.cpp index 9b5725db89..20d5fe7185 100644 --- a/src/Enzo/mesh/EnzoRefineMass.cpp +++ b/src/Enzo/mesh/EnzoRefineMass.cpp @@ -10,7 +10,7 @@ #include "enzo.hpp" #include "charm_simulation.hpp" #include "enzo.hpp" -#include "enzo.decl.h" +#include "charm_enzo.hpp" //---------------------------------------------------------------------- diff --git a/src/Enzo/opkda1.F b/src/Enzo/opkda1.F new file mode 100644 index 0000000000..daccfc9f47 --- /dev/null +++ b/src/Enzo/opkda1.F @@ -0,0 +1,10135 @@ +*DECK DUMACH + DOUBLE PRECISION FUNCTION DUMACH () +C***BEGIN PROLOGUE DUMACH +C***PURPOSE Compute the unit roundoff of the machine. +C***CATEGORY R1 +C***TYPE DOUBLE PRECISION (RUMACH-S, DUMACH-D) +C***KEYWORDS MACHINE CONSTANTS +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C *Usage: +C DOUBLE PRECISION A, DUMACH +C A = DUMACH() +C +C *Function Return Values: +C A : the unit roundoff of the machine. +C +C *Description: +C The unit roundoff is defined as the smallest positive machine +C number u such that 1.0 + u .ne. 1.0. This is computed by DUMACH +C in a machine-independent manner. +C +C***REFERENCES (NONE) +C***ROUTINES CALLED DUMSUM +C***REVISION HISTORY (YYYYMMDD) +C 19930216 DATE WRITTEN +C 19930818 Added SLATEC-format prologue. (FNF) +C 20030707 Added DUMSUM to force normal storage of COMP. (ACH) +C***END PROLOGUE DUMACH +C + DOUBLE PRECISION U, COMP +C***FIRST EXECUTABLE STATEMENT DUMACH + U = 1.0D0 + 10 U = U*0.5D0 + CALL DUMSUM(1.0D0, U, COMP) + IF (COMP .NE. 1.0D0) GO TO 10 + DUMACH = U*2.0D0 + RETURN +C----------------------- End of Function DUMACH ------------------------ + END + SUBROUTINE DUMSUM(A,B,C) +C Routine to force normal storing of A + B, for DUMACH. + DOUBLE PRECISION A, B, C + C = A + B + RETURN + END +*DECK DCFODE + SUBROUTINE DCFODE (METH, ELCO, TESCO) +C***BEGIN PROLOGUE DCFODE +C***SUBSIDIARY +C***PURPOSE Set ODE integrator coefficients. +C***TYPE DOUBLE PRECISION (SCFODE-S, DCFODE-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C DCFODE is called by the integrator routine to set coefficients +C needed there. The coefficients for the current method, as +C given by the value of METH, are set for all orders and saved. +C The maximum order assumed here is 12 if METH = 1 and 5 if METH = 2. +C (A smaller value of the maximum order is also allowed.) +C DCFODE is called once at the beginning of the problem, +C and is not called again unless and until METH is changed. +C +C The ELCO array contains the basic method coefficients. +C The coefficients el(i), 1 .le. i .le. nq+1, for the method of +C order nq are stored in ELCO(i,nq). They are given by a genetrating +C polynomial, i.e., +C l(x) = el(1) + el(2)*x + ... + el(nq+1)*x**nq. +C For the implicit Adams methods, l(x) is given by +C dl/dx = (x+1)*(x+2)*...*(x+nq-1)/factorial(nq-1), l(-1) = 0. +C For the BDF methods, l(x) is given by +C l(x) = (x+1)*(x+2)* ... *(x+nq)/K, +C where K = factorial(nq)*(1 + 1/2 + ... + 1/nq). +C +C The TESCO array contains test constants used for the +C local error test and the selection of step size and/or order. +C At order nq, TESCO(k,nq) is used for the selection of step +C size at order nq - 1 if k = 1, at order nq if k = 2, and at order +C nq + 1 if k = 3. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C***END PROLOGUE DCFODE +C**End + INTEGER METH + INTEGER I, IB, NQ, NQM1, NQP1 + DOUBLE PRECISION ELCO, TESCO + DOUBLE PRECISION AGAMQ, FNQ, FNQM1, PC, PINT, RAGQ, + 1 RQFAC, RQ1FAC, TSIGN, XPIN + DIMENSION ELCO(13,12), TESCO(3,12) + DIMENSION PC(12) +C +C***FIRST EXECUTABLE STATEMENT DCFODE + GO TO (100, 200), METH +C + 100 ELCO(1,1) = 1.0D0 + ELCO(2,1) = 1.0D0 + TESCO(1,1) = 0.0D0 + TESCO(2,1) = 2.0D0 + TESCO(1,2) = 1.0D0 + TESCO(3,12) = 0.0D0 + PC(1) = 1.0D0 + RQFAC = 1.0D0 + DO 140 NQ = 2,12 +C----------------------------------------------------------------------- +C The PC array will contain the coefficients of the polynomial +C p(x) = (x+1)*(x+2)*...*(x+nq-1). +C Initially, p(x) = 1. +C----------------------------------------------------------------------- + RQ1FAC = RQFAC + RQFAC = RQFAC/NQ + NQM1 = NQ - 1 + FNQM1 = NQM1 + NQP1 = NQ + 1 +C Form coefficients of p(x)*(x+nq-1). ---------------------------------- + PC(NQ) = 0.0D0 + DO 110 IB = 1,NQM1 + I = NQP1 - IB + 110 PC(I) = PC(I-1) + FNQM1*PC(I) + PC(1) = FNQM1*PC(1) +C Compute integral, -1 to 0, of p(x) and x*p(x). ----------------------- + PINT = PC(1) + XPIN = PC(1)/2.0D0 + TSIGN = 1.0D0 + DO 120 I = 2,NQ + TSIGN = -TSIGN + PINT = PINT + TSIGN*PC(I)/I + 120 XPIN = XPIN + TSIGN*PC(I)/(I+1) +C Store coefficients in ELCO and TESCO. -------------------------------- + ELCO(1,NQ) = PINT*RQ1FAC + ELCO(2,NQ) = 1.0D0 + DO 130 I = 2,NQ + 130 ELCO(I+1,NQ) = RQ1FAC*PC(I)/I + AGAMQ = RQFAC*XPIN + RAGQ = 1.0D0/AGAMQ + TESCO(2,NQ) = RAGQ + IF (NQ .LT. 12) TESCO(1,NQP1) = RAGQ*RQFAC/NQP1 + TESCO(3,NQM1) = RAGQ + 140 CONTINUE + RETURN +C + 200 PC(1) = 1.0D0 + RQ1FAC = 1.0D0 + DO 230 NQ = 1,5 +C----------------------------------------------------------------------- +C The PC array will contain the coefficients of the polynomial +C p(x) = (x+1)*(x+2)*...*(x+nq). +C Initially, p(x) = 1. +C----------------------------------------------------------------------- + FNQ = NQ + NQP1 = NQ + 1 +C Form coefficients of p(x)*(x+nq). ------------------------------------ + PC(NQP1) = 0.0D0 + DO 210 IB = 1,NQ + I = NQ + 2 - IB + 210 PC(I) = PC(I-1) + FNQ*PC(I) + PC(1) = FNQ*PC(1) +C Store coefficients in ELCO and TESCO. -------------------------------- + DO 220 I = 1,NQP1 + 220 ELCO(I,NQ) = PC(I)/PC(2) + ELCO(2,NQ) = 1.0D0 + TESCO(1,NQ) = RQ1FAC + TESCO(2,NQ) = NQP1/ELCO(1,NQ) + TESCO(3,NQ) = (NQ+2)/ELCO(1,NQ) + RQ1FAC = RQ1FAC/FNQ + 230 CONTINUE + RETURN +C----------------------- END OF SUBROUTINE DCFODE ---------------------- + END +*DECK DINTDY + SUBROUTINE DINTDY (T, K, YH, NYH, DKY, IFLAG) +C***BEGIN PROLOGUE DINTDY +C***SUBSIDIARY +C***PURPOSE Interpolate solution derivatives. +C***TYPE DOUBLE PRECISION (SINTDY-S, DINTDY-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C DINTDY computes interpolated values of the K-th derivative of the +C dependent variable vector y, and stores it in DKY. This routine +C is called within the package with K = 0 and T = TOUT, but may +C also be called by the user for any K up to the current order. +C (See detailed instructions in the usage documentation.) +C +C The computed values in DKY are gotten by interpolation using the +C Nordsieck history array YH. This array corresponds uniquely to a +C vector-valued polynomial of degree NQCUR or less, and DKY is set +C to the K-th derivative of this polynomial at T. +C The formula for DKY is: +C q +C DKY(i) = sum c(j,K) * (T - tn)**(j-K) * h**(-j) * YH(i,j+1) +C j=K +C where c(j,K) = j*(j-1)*...*(j-K+1), q = NQCUR, tn = TCUR, h = HCUR. +C The quantities nq = NQCUR, l = nq+1, N = NEQ, tn, and h are +C communicated by COMMON. The above sum is done in reverse order. +C IFLAG is returned negative if either K or T is out of bounds. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED XERRWD +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C 010418 Reduced size of Common block /DLS001/. (ACH) +C 031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C 050427 Corrected roundoff decrement in TP. (ACH) +C***END PROLOGUE DINTDY +C**End + INTEGER K, NYH, IFLAG + DOUBLE PRECISION T, YH, DKY + DIMENSION YH(NYH,*), DKY(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, IC, J, JB, JB2, JJ, JJ1, JP1 + DOUBLE PRECISION C, R, S, TP + CHARACTER*80 MSG +C +C***FIRST EXECUTABLE STATEMENT DINTDY + IFLAG = 0 + IF (K .LT. 0 .OR. K .GT. NQ) GO TO 80 + TP = TN - HU - 100.0D0*UROUND*SIGN(ABS(TN) + ABS(HU), HU) + IF ((T-TP)*(T-TN) .GT. 0.0D0) GO TO 90 +C + S = (T - TN)/H + IC = 1 + IF (K .EQ. 0) GO TO 15 + JJ1 = L - K + DO 10 JJ = JJ1,NQ + 10 IC = IC*JJ + 15 C = IC + DO 20 I = 1,N + 20 DKY(I) = C*YH(I,L) + IF (K .EQ. NQ) GO TO 55 + JB2 = NQ - K + DO 50 JB = 1,JB2 + J = NQ - JB + JP1 = J + 1 + IC = 1 + IF (K .EQ. 0) GO TO 35 + JJ1 = JP1 - K + DO 30 JJ = JJ1,J + 30 IC = IC*JJ + 35 C = IC + DO 40 I = 1,N + 40 DKY(I) = C*YH(I,JP1) + S*DKY(I) + 50 CONTINUE + IF (K .EQ. 0) RETURN + 55 R = H**(-K) + DO 60 I = 1,N + 60 DKY(I) = R*DKY(I) + RETURN +C + 80 MSG = 'DINTDY- K (=I1) illegal ' + CALL XERRWD (MSG, 30, 51, 0, 1, K, 0, 0, 0.0D0, 0.0D0) + IFLAG = -1 + RETURN + 90 MSG = 'DINTDY- T (=R1) illegal ' + CALL XERRWD (MSG, 30, 52, 0, 0, 0, 0, 1, T, 0.0D0) + MSG=' T not in interval TCUR - HU (= R1) to TCUR (=R2) ' + CALL XERRWD (MSG, 60, 52, 0, 0, 0, 0, 2, TP, TN) + IFLAG = -2 + RETURN +C----------------------- END OF SUBROUTINE DINTDY ---------------------- + END +*DECK DPREPJ + SUBROUTINE DPREPJ (NEQ, Y, YH, NYH, EWT, FTEM, SAVF, WM, IWM, + 1 F, JAC) +C***BEGIN PROLOGUE DPREPJ +C***SUBSIDIARY +C***PURPOSE Compute and process Newton iteration matrix. +C***TYPE DOUBLE PRECISION (SPREPJ-S, DPREPJ-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C DPREPJ is called by DSTODE to compute and process the matrix +C P = I - h*el(1)*J , where J is an approximation to the Jacobian. +C Here J is computed by the user-supplied routine JAC if +C MITER = 1 or 4, or by finite differencing if MITER = 2, 3, or 5. +C If MITER = 3, a diagonal approximation to J is used. +C J is stored in WM and replaced by P. If MITER .ne. 3, P is then +C subjected to LU decomposition in preparation for later solution +C of linear systems with P as coefficient matrix. This is done +C by DGEFA if MITER = 1 or 2, and by DGBFA if MITER = 4 or 5. +C +C In addition to variables described in DSTODE and DLSODE prologues, +C communication with DPREPJ uses the following: +C Y = array containing predicted values on entry. +C FTEM = work array of length N (ACOR in DSTODE). +C SAVF = array containing f evaluated at predicted y. +C WM = real work space for matrices. On output it contains the +C inverse diagonal matrix if MITER = 3 and the LU decomposition +C of P if MITER is 1, 2 , 4, or 5. +C Storage of matrix elements starts at WM(3). +C WM also contains the following matrix-related data: +C WM(1) = SQRT(UROUND), used in numerical Jacobian increments. +C WM(2) = H*EL0, saved for later use if MITER = 3. +C IWM = integer work space containing pivot information, starting at +C IWM(21), if MITER is 1, 2, 4, or 5. IWM also contains band +C parameters ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5. +C EL0 = EL(1) (input). +C IERPJ = output error flag, = 0 if no trouble, .gt. 0 if +C P matrix found to be singular. +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses the COMMON variables EL0, H, TN, UROUND, +C MITER, N, NFE, and NJE. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED DGBFA, DGEFA, DVNORM +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890504 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C 010418 Reduced size of Common block /DLS001/. (ACH) +C 031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C***END PROLOGUE DPREPJ +C**End + EXTERNAL F, JAC + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, EWT, FTEM, SAVF, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), FTEM(*), SAVF(*), + 1 WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, I2, IER, II, J, J1, JJ, LENP, + 1 MBA, MBAND, MEB1, MEBAND, ML, ML3, MU, NP1 + DOUBLE PRECISION CON, DI, FAC, HL0, R, R0, SRUR, YI, YJ, YJJ, + 1 DVNORM +C +C***FIRST EXECUTABLE STATEMENT DPREPJ + NJE = NJE + 1 + IERPJ = 0 + JCUR = 1 + HL0 = H*EL0 + GO TO (100, 200, 300, 400, 500), MITER +C If MITER = 1, call JAC and multiply by scalar. ----------------------- + 100 LENP = N*N + DO 110 I = 1,LENP + 110 WM(I+2) = 0.0D0 + CALL JAC (NEQ, TN, Y, 0, 0, WM(3), N) + CON = -HL0 + DO 120 I = 1,LENP + 120 WM(I+2) = WM(I+2)*CON + GO TO 240 +C If MITER = 2, make N calls to F to approximate J. -------------------- + 200 FAC = DVNORM (N, SAVF, EWT) + R0 = 1000.0D0*ABS(H)*UROUND*N*FAC + IF (R0 .EQ. 0.0D0) R0 = 1.0D0 + SRUR = WM(1) + J1 = 2 + DO 230 J = 1,N + YJ = Y(J) + R = MAX(SRUR*ABS(YJ),R0/EWT(J)) + Y(J) = Y(J) + R + FAC = -HL0/R + CALL F (NEQ, TN, Y, FTEM) + DO 220 I = 1,N + 220 WM(I+J1) = (FTEM(I) - SAVF(I))*FAC + Y(J) = YJ + J1 = J1 + N + 230 CONTINUE + NFE = NFE + N +C Add identity matrix. ------------------------------------------------- + 240 J = 3 + NP1 = N + 1 + DO 250 I = 1,N + WM(J) = WM(J) + 1.0D0 + 250 J = J + NP1 +C Do LU decomposition on P. -------------------------------------------- + CALL DGEFA (WM(3), N, N, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C If MITER = 3, construct a diagonal approximation to J and P. --------- + 300 WM(2) = HL0 + R = EL0*0.1D0 + DO 310 I = 1,N + 310 Y(I) = Y(I) + R*(H*SAVF(I) - YH(I,2)) + CALL F (NEQ, TN, Y, WM(3)) + NFE = NFE + 1 + DO 320 I = 1,N + R0 = H*SAVF(I) - YH(I,2) + DI = 0.1D0*R0 - H*(WM(I+2) - SAVF(I)) + WM(I+2) = 1.0D0 + IF (ABS(R0) .LT. UROUND/EWT(I)) GO TO 320 + IF (ABS(DI) .EQ. 0.0D0) GO TO 330 + WM(I+2) = 0.1D0*R0/DI + 320 CONTINUE + RETURN + 330 IERPJ = 1 + RETURN +C If MITER = 4, call JAC and multiply by scalar. ----------------------- + 400 ML = IWM(1) + MU = IWM(2) + ML3 = ML + 3 + MBAND = ML + MU + 1 + MEBAND = MBAND + ML + LENP = MEBAND*N + DO 410 I = 1,LENP + 410 WM(I+2) = 0.0D0 + CALL JAC (NEQ, TN, Y, ML, MU, WM(ML3), MEBAND) + CON = -HL0 + DO 420 I = 1,LENP + 420 WM(I+2) = WM(I+2)*CON + GO TO 570 +C If MITER = 5, make MBAND calls to F to approximate J. ---------------- + 500 ML = IWM(1) + MU = IWM(2) + MBAND = ML + MU + 1 + MBA = MIN(MBAND,N) + MEBAND = MBAND + ML + MEB1 = MEBAND - 1 + SRUR = WM(1) + FAC = DVNORM (N, SAVF, EWT) + R0 = 1000.0D0*ABS(H)*UROUND*N*FAC + IF (R0 .EQ. 0.0D0) R0 = 1.0D0 + DO 560 J = 1,MBA + DO 530 I = J,N,MBAND + YI = Y(I) + R = MAX(SRUR*ABS(YI),R0/EWT(I)) + 530 Y(I) = Y(I) + R + CALL F (NEQ, TN, Y, FTEM) + DO 550 JJ = J,N,MBAND + Y(JJ) = YH(JJ,1) + YJJ = Y(JJ) + R = MAX(SRUR*ABS(YJJ),R0/EWT(JJ)) + FAC = -HL0/R + I1 = MAX(JJ-MU,1) + I2 = MIN(JJ+ML,N) + II = JJ*MEB1 - ML + 2 + DO 540 I = I1,I2 + 540 WM(II+I) = (FTEM(I) - SAVF(I))*FAC + 550 CONTINUE + 560 CONTINUE + NFE = NFE + MBA +C Add identity matrix. ------------------------------------------------- + 570 II = MBAND + 2 + DO 580 I = 1,N + WM(II) = WM(II) + 1.0D0 + 580 II = II + MEBAND +C Do LU decomposition of P. -------------------------------------------- + CALL DGBFA (WM(3), MEBAND, N, ML, MU, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C----------------------- END OF SUBROUTINE DPREPJ ---------------------- + END +*DECK DSOLSY + SUBROUTINE DSOLSY (WM, IWM, X, TEM) +C***BEGIN PROLOGUE DSOLSY +C***SUBSIDIARY +C***PURPOSE ODEPACK linear system solver. +C***TYPE DOUBLE PRECISION (SSOLSY-S, DSOLSY-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C This routine manages the solution of the linear system arising from +C a chord iteration. It is called if MITER .ne. 0. +C If MITER is 1 or 2, it calls DGESL to accomplish this. +C If MITER = 3 it updates the coefficient h*EL0 in the diagonal +C matrix, and then computes the solution. +C If MITER is 4 or 5, it calls DGBSL. +C Communication with DSOLSY uses the following variables: +C WM = real work space containing the inverse diagonal matrix if +C MITER = 3 and the LU decomposition of the matrix otherwise. +C Storage of matrix elements starts at WM(3). +C WM also contains the following matrix-related data: +C WM(1) = SQRT(UROUND) (not used here), +C WM(2) = HL0, the previous value of h*EL0, used if MITER = 3. +C IWM = integer work space containing pivot information, starting at +C IWM(21), if MITER is 1, 2, 4, or 5. IWM also contains band +C parameters ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5. +C X = the right-hand side vector on input, and the solution vector +C on output, of length N. +C TEM = vector of work space of length N, not used in this version. +C IERSL = output flag (in COMMON). IERSL = 0 if no trouble occurred. +C IERSL = 1 if a singular matrix arose with MITER = 3. +C This routine also uses the COMMON variables EL0, H, MITER, and N. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED DGBSL, DGESL +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C 010418 Reduced size of Common block /DLS001/. (ACH) +C 031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C***END PROLOGUE DSOLSY +C**End + INTEGER IWM + DOUBLE PRECISION WM, X, TEM + DIMENSION WM(*), IWM(*), X(*), TEM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, MEBAND, ML, MU + DOUBLE PRECISION DI, HL0, PHL0, R +C +C***FIRST EXECUTABLE STATEMENT DSOLSY + IERSL = 0 + GO TO (100, 100, 300, 400, 400), MITER + 100 CALL DGESL (WM(3), N, N, IWM(21), X, 0) + RETURN +C + 300 PHL0 = WM(2) + HL0 = H*EL0 + WM(2) = HL0 + IF (HL0 .EQ. PHL0) GO TO 330 + R = HL0/PHL0 + DO 320 I = 1,N + DI = 1.0D0 - R*(1.0D0 - 1.0D0/WM(I+2)) + IF (ABS(DI) .EQ. 0.0D0) GO TO 390 + 320 WM(I+2) = 1.0D0/DI + 330 DO 340 I = 1,N + 340 X(I) = WM(I+2)*X(I) + RETURN + 390 IERSL = 1 + RETURN +C + 400 ML = IWM(1) + MU = IWM(2) + MEBAND = 2*ML + MU + 1 + CALL DGBSL (WM(3), MEBAND, N, ML, MU, IWM(21), X, 0) + RETURN +C----------------------- END OF SUBROUTINE DSOLSY ---------------------- + END +*DECK DSRCOM + SUBROUTINE DSRCOM (RSAV, ISAV, JOB) +C***BEGIN PROLOGUE DSRCOM +C***SUBSIDIARY +C***PURPOSE Save/restore ODEPACK COMMON blocks. +C***TYPE DOUBLE PRECISION (SSRCOM-S, DSRCOM-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C This routine saves or restores (depending on JOB) the contents of +C the COMMON block DLS001, which is used internally +C by one or more ODEPACK solvers. +C +C RSAV = real array of length 218 or more. +C ISAV = integer array of length 37 or more. +C JOB = flag indicating to save or restore the COMMON blocks: +C JOB = 1 if COMMON is to be saved (written to RSAV/ISAV) +C JOB = 2 if COMMON is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED (NONE) +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 921116 Deleted treatment of block /EH0001/. (ACH) +C 930801 Reduced Common block length by 2. (ACH) +C 930809 Renamed to allow single/double precision versions. (ACH) +C 010418 Reduced Common block length by 209+12. (ACH) +C 031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C 031112 Added SAVE statement for data-loaded constants. +C***END PROLOGUE DSRCOM +C**End + INTEGER ISAV, JOB + INTEGER ILS + INTEGER I, LENILS, LENRLS + DOUBLE PRECISION RSAV, RLS + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS + COMMON /DLS001/ RLS(218), ILS(37) + DATA LENRLS/218/, LENILS/37/ +C +C***FIRST EXECUTABLE STATEMENT DSRCOM + IF (JOB .EQ. 2) GO TO 100 +C + DO 10 I = 1,LENRLS + 10 RSAV(I) = RLS(I) + DO 20 I = 1,LENILS + 20 ISAV(I) = ILS(I) + RETURN +C + 100 CONTINUE + DO 110 I = 1,LENRLS + 110 RLS(I) = RSAV(I) + DO 120 I = 1,LENILS + 120 ILS(I) = ISAV(I) + RETURN +C----------------------- END OF SUBROUTINE DSRCOM ---------------------- + END +*DECK DSTODE + SUBROUTINE DSTODE (NEQ, Y, YH, NYH, YH1, EWT, SAVF, ACOR, + 1 WM, IWM, F, JAC, PJAC, SLVS) +C***BEGIN PROLOGUE DSTODE +C***SUBSIDIARY +C***PURPOSE Performs one step of an ODEPACK integration. +C***TYPE DOUBLE PRECISION (SSTODE-S, DSTODE-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C DSTODE performs one step of the integration of an initial value +C problem for a system of ordinary differential equations. +C Note: DSTODE is independent of the value of the iteration method +C indicator MITER, when this is .ne. 0, and hence is independent +C of the type of chord method used, or the Jacobian structure. +C Communication with DSTODE is done with the following variables: +C +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls to F and JAC. +C Y = an array of length .ge. N used as the Y argument in +C all calls to F and JAC. +C YH = an NYH by LMAX array containing the dependent variables +C and their approximate scaled derivatives, where +C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate +C j-th derivative of y(i), scaled by h**j/factorial(j) +C (j = 0,1,...,NQ). on entry for the first step, the first +C two columns of YH must be set from the initial values. +C NYH = a constant integer .ge. N, the first dimension of YH. +C YH1 = a one-dimensional array occupying the same space as YH. +C EWT = an array of length N containing multiplicative weights +C for local error measurements. Local errors in Y(i) are +C compared to 1.0/EWT(i) in various error tests. +C SAVF = an array of working storage, of length N. +C Also used for input of YH(*,MAXORD+2) when JSTART = -1 +C and MAXORD .lt. the current order NQ. +C ACOR = a work array of length N, used for the accumulated +C corrections. On a successful return, ACOR(i) contains +C the estimated one-step local error in Y(i). +C WM,IWM = real and integer work arrays associated with matrix +C operations in chord iteration (MITER .ne. 0). +C PJAC = name of routine to evaluate and preprocess Jacobian matrix +C and P = I - h*el0*JAC, if a chord method is being used. +C SLVS = name of routine to solve linear system in chord iteration. +C CCMAX = maximum relative change in h*el0 before PJAC is called. +C H = the step size to be attempted on the next step. +C H is altered by the error control algorithm during the +C problem. H can be either positive or negative, but its +C sign must remain constant throughout the problem. +C HMIN = the minimum absolute value of the step size h to be used. +C HMXI = inverse of the maximum absolute value of h to be used. +C HMXI = 0.0 is allowed and corresponds to an infinite hmax. +C HMIN and HMXI may be changed at any time, but will not +C take effect until the next change of h is considered. +C TN = the independent variable. TN is updated on each step taken. +C JSTART = an integer used for input only, with the following +C values and meanings: +C 0 perform the first step. +C .gt.0 take a new step continuing from the last. +C -1 take the next step with a new value of H, MAXORD, +C N, METH, MITER, and/or matrix parameters. +C -2 take the next step with a new value of H, +C but with other inputs unchanged. +C On return, JSTART is set to 1 to facilitate continuation. +C KFLAG = a completion code with the following meanings: +C 0 the step was succesful. +C -1 the requested error could not be achieved. +C -2 corrector convergence could not be achieved. +C -3 fatal error in PJAC or SLVS. +C A return with KFLAG = -1 or -2 means either +C abs(H) = HMIN or 10 consecutive failures occurred. +C On a return with KFLAG negative, the values of TN and +C the YH array are as of the beginning of the last +C step, and H is the last step size attempted. +C MAXORD = the maximum order of integration method to be allowed. +C MAXCOR = the maximum number of corrector iterations allowed. +C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0). +C MXNCF = maximum number of convergence failures allowed. +C METH/MITER = the method flags. See description in driver. +C N = the number of first-order differential equations. +C The values of CCMAX, H, HMIN, HMXI, TN, JSTART, KFLAG, MAXORD, +C MAXCOR, MSBP, MXNCF, METH, MITER, and N are communicated via COMMON. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED DCFODE, DVNORM +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C 010418 Reduced size of Common block /DLS001/. (ACH) +C 031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C***END PROLOGUE DSTODE +C**End + EXTERNAL F, JAC, PJAC, SLVS + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, YH1, EWT, SAVF, ACOR, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), YH1(*), EWT(*), SAVF(*), + 1 ACOR(*), WM(*), IWM(*) + INTEGER IOWND, IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, IREDO, IRET, J, JB, M, NCF, NEWQ + DOUBLE PRECISION CONIT, CRATE, EL, ELCO, HOLD, RMAX, TESCO, + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DCON, DDN, DEL, DELP, DSM, DUP, EXDN, EXSM, EXUP, + 1 R, RH, RHDN, RHSM, RHUP, TOLD, DVNORM + COMMON /DLS001/ CONIT, CRATE, EL(13), ELCO(13,12), + 1 HOLD, RMAX, TESCO(3,12), + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 3 IOWND(6), IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C +C***FIRST EXECUTABLE STATEMENT DSTODE + KFLAG = 0 + TOLD = TN + NCF = 0 + IERPJ = 0 + IERSL = 0 + JCUR = 0 + ICF = 0 + DELP = 0.0D0 + IF (JSTART .GT. 0) GO TO 200 + IF (JSTART .EQ. -1) GO TO 100 + IF (JSTART .EQ. -2) GO TO 160 +C----------------------------------------------------------------------- +C On the first call, the order is set to 1, and other variables are +C initialized. RMAX is the maximum ratio by which H can be increased +C in a single step. It is initially 1.E4 to compensate for the small +C initial H, but then is normally equal to 10. If a failure +C occurs (in corrector convergence or error test), RMAX is set to 2 +C for the next increase. +C----------------------------------------------------------------------- + LMAX = MAXORD + 1 + NQ = 1 + L = 2 + IALTH = 2 + RMAX = 10000.0D0 + RC = 0.0D0 + EL0 = 1.0D0 + CRATE = 0.7D0 + HOLD = H + MEO = METH + NSLP = 0 + IPUP = MITER + IRET = 3 + GO TO 140 +C----------------------------------------------------------------------- +C The following block handles preliminaries needed when JSTART = -1. +C IPUP is set to MITER to force a matrix update. +C If an order increase is about to be considered (IALTH = 1), +C IALTH is reset to 2 to postpone consideration one more step. +C If the caller has changed METH, DCFODE is called to reset +C the coefficients of the method. +C If the caller has changed MAXORD to a value less than the current +C order NQ, NQ is reduced to MAXORD, and a new H chosen accordingly. +C If H is to be changed, YH must be rescaled. +C If H or METH is being changed, IALTH is reset to L = NQ + 1 +C to prevent further changes in H for that many steps. +C----------------------------------------------------------------------- + 100 IPUP = MITER + LMAX = MAXORD + 1 + IF (IALTH .EQ. 1) IALTH = 2 + IF (METH .EQ. MEO) GO TO 110 + CALL DCFODE (METH, ELCO, TESCO) + MEO = METH + IF (NQ .GT. MAXORD) GO TO 120 + IALTH = L + IRET = 1 + GO TO 150 + 110 IF (NQ .LE. MAXORD) GO TO 160 + 120 NQ = MAXORD + L = LMAX + DO 125 I = 1,L + 125 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + DDN = DVNORM (N, SAVF, EWT)/TESCO(1,L) + EXDN = 1.0D0/L + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + RH = MIN(RHDN,1.0D0) + IREDO = 3 + IF (H .EQ. HOLD) GO TO 170 + RH = MIN(RH,ABS(H/HOLD)) + H = HOLD + GO TO 175 +C----------------------------------------------------------------------- +C DCFODE is called to get all the integration coefficients for the +C current METH. Then the EL vector and related constants are reset +C whenever the order NQ is changed, or at the start of the problem. +C----------------------------------------------------------------------- + 140 CALL DCFODE (METH, ELCO, TESCO) + 150 DO 155 I = 1,L + 155 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + GO TO (160, 170, 200), IRET +C----------------------------------------------------------------------- +C If H is being changed, the H ratio RH is checked against +C RMAX, HMIN, and HMXI, and the YH array rescaled. IALTH is set to +C L = NQ + 1 to prevent a change of H for that many steps, unless +C forced by a convergence or error test failure. +C----------------------------------------------------------------------- + 160 IF (H .EQ. HOLD) GO TO 200 + RH = H/HOLD + H = HOLD + IREDO = 3 + GO TO 175 + 170 RH = MAX(RH,HMIN/ABS(H)) + 175 RH = MIN(RH,RMAX) + RH = RH/MAX(1.0D0,ABS(H)*HMXI*RH) + R = 1.0D0 + DO 180 J = 2,L + R = R*RH + DO 180 I = 1,N + 180 YH(I,J) = YH(I,J)*R + H = H*RH + RC = RC*RH + IALTH = L + IF (IREDO .EQ. 0) GO TO 690 +C----------------------------------------------------------------------- +C This section computes the predicted values by effectively +C multiplying the YH array by the Pascal Triangle matrix. +C RC is the ratio of new to old values of the coefficient H*EL(1). +C When RC differs from 1 by more than CCMAX, IPUP is set to MITER +C to force PJAC to be called, if a Jacobian is involved. +C In any case, PJAC is called at least every MSBP steps. +C----------------------------------------------------------------------- + 200 IF (ABS(RC-1.0D0) .GT. CCMAX) IPUP = MITER + IF (NST .GE. NSLP+MSBP) IPUP = MITER + TN = TN + H + I1 = NQNYH + 1 + DO 215 JB = 1,NQ + I1 = I1 - NYH +Cdir$ ivdep + DO 210 I = I1,NQNYH + 210 YH1(I) = YH1(I) + YH1(I+NYH) + 215 CONTINUE +C----------------------------------------------------------------------- +C Up to MAXCOR corrector iterations are taken. A convergence test is +C made on the R.M.S. norm of each correction, weighted by the error +C weight vector EWT. The sum of the corrections is accumulated in the +C vector ACOR(i). The YH array is not altered in the corrector loop. +C----------------------------------------------------------------------- + 220 M = 0 + DO 230 I = 1,N + 230 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + IF (IPUP .LE. 0) GO TO 250 +C----------------------------------------------------------------------- +C If indicated, the matrix P = I - h*el(1)*J is reevaluated and +C preprocessed before starting the corrector iteration. IPUP is set +C to 0 as an indicator that this has been done. +C----------------------------------------------------------------------- + CALL PJAC (NEQ, Y, YH, NYH, EWT, ACOR, SAVF, WM, IWM, F, JAC) + IPUP = 0 + RC = 1.0D0 + NSLP = NST + CRATE = 0.7D0 + IF (IERPJ .NE. 0) GO TO 430 + 250 DO 260 I = 1,N + 260 ACOR(I) = 0.0D0 + 270 IF (MITER .NE. 0) GO TO 350 +C----------------------------------------------------------------------- +C In the case of functional iteration, update Y directly from +C the result of the last function evaluation. +C----------------------------------------------------------------------- + DO 290 I = 1,N + SAVF(I) = H*SAVF(I) - YH(I,2) + 290 Y(I) = SAVF(I) - ACOR(I) + DEL = DVNORM (N, Y, EWT) + DO 300 I = 1,N + Y(I) = YH(I,1) + EL(1)*SAVF(I) + 300 ACOR(I) = SAVF(I) + GO TO 400 +C----------------------------------------------------------------------- +C In the case of the chord method, compute the corrector error, +C and solve the linear system with that as right-hand side and +C P as coefficient matrix. +C----------------------------------------------------------------------- + 350 DO 360 I = 1,N + 360 Y(I) = H*SAVF(I) - (YH(I,2) + ACOR(I)) + CALL SLVS (WM, IWM, Y, SAVF) + IF (IERSL .LT. 0) GO TO 430 + IF (IERSL .GT. 0) GO TO 410 + DEL = DVNORM (N, Y, EWT) + DO 380 I = 1,N + ACOR(I) = ACOR(I) + Y(I) + 380 Y(I) = YH(I,1) + EL(1)*ACOR(I) +C----------------------------------------------------------------------- +C Test for convergence. If M.gt.0, an estimate of the convergence +C rate constant is stored in CRATE, and this is used in the test. +C----------------------------------------------------------------------- + 400 IF (M .NE. 0) CRATE = MAX(0.2D0*CRATE,DEL/DELP) + DCON = DEL*MIN(1.0D0,1.5D0*CRATE)/(TESCO(2,NQ)*CONIT) + IF (DCON .LE. 1.0D0) GO TO 450 + M = M + 1 + IF (M .EQ. MAXCOR) GO TO 410 + IF (M .GE. 2 .AND. DEL .GT. 2.0D0*DELP) GO TO 410 + DELP = DEL + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + GO TO 270 +C----------------------------------------------------------------------- +C The corrector iteration failed to converge. +C If MITER .ne. 0 and the Jacobian is out of date, PJAC is called for +C the next try. Otherwise the YH array is retracted to its values +C before prediction, and H is reduced, if possible. If H cannot be +C reduced or MXNCF failures have occurred, exit with KFLAG = -2. +C----------------------------------------------------------------------- + 410 IF (MITER .EQ. 0 .OR. JCUR .EQ. 1) GO TO 430 + ICF = 1 + IPUP = MITER + GO TO 220 + 430 ICF = 2 + NCF = NCF + 1 + RMAX = 2.0D0 + TN = TOLD + I1 = NQNYH + 1 + DO 445 JB = 1,NQ + I1 = I1 - NYH +Cdir$ ivdep + DO 440 I = I1,NQNYH + 440 YH1(I) = YH1(I) - YH1(I+NYH) + 445 CONTINUE + IF (IERPJ .LT. 0 .OR. IERSL .LT. 0) GO TO 680 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 670 + IF (NCF .EQ. MXNCF) GO TO 670 + RH = 0.25D0 + IPUP = MITER + IREDO = 1 + GO TO 170 +C----------------------------------------------------------------------- +C The corrector has converged. JCUR is set to 0 +C to signal that the Jacobian involved may need updating later. +C The local error test is made and control passes to statement 500 +C if it fails. +C----------------------------------------------------------------------- + 450 JCUR = 0 + IF (M .EQ. 0) DSM = DEL/TESCO(2,NQ) + IF (M .GT. 0) DSM = DVNORM (N, ACOR, EWT)/TESCO(2,NQ) + IF (DSM .GT. 1.0D0) GO TO 500 +C----------------------------------------------------------------------- +C After a successful step, update the YH array. +C Consider changing H if IALTH = 1. Otherwise decrease IALTH by 1. +C If IALTH is then 1 and NQ .lt. MAXORD, then ACOR is saved for +C use in a possible order increase on the next step. +C If a change in H is considered, an increase or decrease in order +C by one is considered also. A change in H is made only if it is by a +C factor of at least 1.1. If not, IALTH is set to 3 to prevent +C testing for that many steps. +C----------------------------------------------------------------------- + KFLAG = 0 + IREDO = 0 + NST = NST + 1 + HU = H + NQU = NQ + DO 470 J = 1,L + DO 470 I = 1,N + 470 YH(I,J) = YH(I,J) + EL(J)*ACOR(I) + IALTH = IALTH - 1 + IF (IALTH .EQ. 0) GO TO 520 + IF (IALTH .GT. 1) GO TO 700 + IF (L .EQ. LMAX) GO TO 700 + DO 490 I = 1,N + 490 YH(I,LMAX) = ACOR(I) + GO TO 700 +C----------------------------------------------------------------------- +C The error test failed. KFLAG keeps track of multiple failures. +C Restore TN and the YH array to their previous values, and prepare +C to try the step again. Compute the optimum step size for this or +C one lower order. After 2 or more failures, H is forced to decrease +C by a factor of 0.2 or less. +C----------------------------------------------------------------------- + 500 KFLAG = KFLAG - 1 + TN = TOLD + I1 = NQNYH + 1 + DO 515 JB = 1,NQ + I1 = I1 - NYH +Cdir$ ivdep + DO 510 I = I1,NQNYH + 510 YH1(I) = YH1(I) - YH1(I+NYH) + 515 CONTINUE + RMAX = 2.0D0 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 660 + IF (KFLAG .LE. -3) GO TO 640 + IREDO = 2 + RHUP = 0.0D0 + GO TO 540 +C----------------------------------------------------------------------- +C Regardless of the success or failure of the step, factors +C RHDN, RHSM, and RHUP are computed, by which H could be multiplied +C at order NQ - 1, order NQ, or order NQ + 1, respectively. +C In the case of failure, RHUP = 0.0 to avoid an order increase. +C The largest of these is determined and the new order chosen +C accordingly. If the order is to be increased, we compute one +C additional scaled derivative. +C----------------------------------------------------------------------- + 520 RHUP = 0.0D0 + IF (L .EQ. LMAX) GO TO 540 + DO 530 I = 1,N + 530 SAVF(I) = ACOR(I) - YH(I,LMAX) + DUP = DVNORM (N, SAVF, EWT)/TESCO(3,NQ) + EXUP = 1.0D0/(L+1) + RHUP = 1.0D0/(1.4D0*DUP**EXUP + 0.0000014D0) + 540 EXSM = 1.0D0/L + RHSM = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RHDN = 0.0D0 + IF (NQ .EQ. 1) GO TO 560 + DDN = DVNORM (N, YH(1,L), EWT)/TESCO(1,NQ) + EXDN = 1.0D0/NQ + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + 560 IF (RHSM .GE. RHUP) GO TO 570 + IF (RHUP .GT. RHDN) GO TO 590 + GO TO 580 + 570 IF (RHSM .LT. RHDN) GO TO 580 + NEWQ = NQ + RH = RHSM + GO TO 620 + 580 NEWQ = NQ - 1 + RH = RHDN + IF (KFLAG .LT. 0 .AND. RH .GT. 1.0D0) RH = 1.0D0 + GO TO 620 + 590 NEWQ = L + RH = RHUP + IF (RH .LT. 1.1D0) GO TO 610 + R = EL(L)/L + DO 600 I = 1,N + 600 YH(I,NEWQ+1) = ACOR(I)*R + GO TO 630 + 610 IALTH = 3 + GO TO 700 + 620 IF ((KFLAG .EQ. 0) .AND. (RH .LT. 1.1D0)) GO TO 610 + IF (KFLAG .LE. -2) RH = MIN(RH,0.2D0) +C----------------------------------------------------------------------- +C If there is a change of order, reset NQ, l, and the coefficients. +C In any case H is reset according to RH and the YH array is rescaled. +C Then exit from 690 if the step was OK, or redo the step otherwise. +C----------------------------------------------------------------------- + IF (NEWQ .EQ. NQ) GO TO 170 + 630 NQ = NEWQ + L = NQ + 1 + IRET = 2 + GO TO 150 +C----------------------------------------------------------------------- +C Control reaches this section if 3 or more failures have occured. +C If 10 failures have occurred, exit with KFLAG = -1. +C It is assumed that the derivatives that have accumulated in the +C YH array have errors of the wrong order. Hence the first +C derivative is recomputed, and the order is set to 1. Then +C H is reduced by a factor of 10, and the step is retried, +C until it succeeds or H reaches HMIN. +C----------------------------------------------------------------------- + 640 IF (KFLAG .EQ. -10) GO TO 660 + RH = 0.1D0 + RH = MAX(HMIN/ABS(H),RH) + H = H*RH + DO 645 I = 1,N + 645 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + DO 650 I = 1,N + 650 YH(I,2) = H*SAVF(I) + IPUP = MITER + IALTH = 5 + IF (NQ .EQ. 1) GO TO 200 + NQ = 1 + L = 2 + IRET = 3 + GO TO 150 +C----------------------------------------------------------------------- +C All returns are made through this section. H is saved in HOLD +C to allow the caller to change H on the next step. +C----------------------------------------------------------------------- + 660 KFLAG = -1 + GO TO 720 + 670 KFLAG = -2 + GO TO 720 + 680 KFLAG = -3 + GO TO 720 + 690 RMAX = 10.0D0 + 700 R = 1.0D0/TESCO(2,NQU) + DO 710 I = 1,N + 710 ACOR(I) = ACOR(I)*R + 720 HOLD = H + JSTART = 1 + RETURN +C----------------------- END OF SUBROUTINE DSTODE ---------------------- + END +*DECK DEWSET + SUBROUTINE DEWSET (N, ITOL, RTOL, ATOL, YCUR, EWT) +C***BEGIN PROLOGUE DEWSET +C***SUBSIDIARY +C***PURPOSE Set error weight vector. +C***TYPE DOUBLE PRECISION (SEWSET-S, DEWSET-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C This subroutine sets the error weight vector EWT according to +C EWT(i) = RTOL(i)*ABS(YCUR(i)) + ATOL(i), i = 1,...,N, +C with the subscript on RTOL and/or ATOL possibly replaced by 1 above, +C depending on the value of ITOL. +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C***END PROLOGUE DEWSET +C**End + INTEGER N, ITOL + INTEGER I + DOUBLE PRECISION RTOL, ATOL, YCUR, EWT + DIMENSION RTOL(*), ATOL(*), YCUR(N), EWT(N) +C +C***FIRST EXECUTABLE STATEMENT DEWSET + GO TO (10, 20, 30, 40), ITOL + 10 CONTINUE + DO 15 I = 1,N + 15 EWT(I) = RTOL(1)*ABS(YCUR(I)) + ATOL(1) + RETURN + 20 CONTINUE + DO 25 I = 1,N + 25 EWT(I) = RTOL(1)*ABS(YCUR(I)) + ATOL(I) + RETURN + 30 CONTINUE + DO 35 I = 1,N + 35 EWT(I) = RTOL(I)*ABS(YCUR(I)) + ATOL(1) + RETURN + 40 CONTINUE + DO 45 I = 1,N + 45 EWT(I) = RTOL(I)*ABS(YCUR(I)) + ATOL(I) + RETURN +C----------------------- END OF SUBROUTINE DEWSET ---------------------- + END +*DECK DVNORM + DOUBLE PRECISION FUNCTION DVNORM (N, V, W) +C***BEGIN PROLOGUE DVNORM +C***SUBSIDIARY +C***PURPOSE Weighted root-mean-square vector norm. +C***TYPE DOUBLE PRECISION (SVNORM-S, DVNORM-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C This function routine computes the weighted root-mean-square norm +C of the vector of length N contained in the array V, with weights +C contained in the array W of length N: +C DVNORM = SQRT( (1/N) * SUM( V(i)*W(i) )**2 ) +C +C***SEE ALSO DLSODE +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791129 DATE WRITTEN +C 890501 Modified prologue to SLATEC/LDOC format. (FNF) +C 890503 Minor cosmetic changes. (FNF) +C 930809 Renamed to allow single/double precision versions. (ACH) +C***END PROLOGUE DVNORM +C**End + INTEGER N, I + DOUBLE PRECISION V, W, SUM + DIMENSION V(N), W(N) +C +C***FIRST EXECUTABLE STATEMENT DVNORM + SUM = 0.0D0 + DO 10 I = 1,N + 10 SUM = SUM + (V(I)*W(I))**2 + DVNORM = SQRT(SUM/N) + RETURN +C----------------------- END OF FUNCTION DVNORM ------------------------ + END +*DECK DIPREP + SUBROUTINE DIPREP (NEQ, Y, RWORK, IA, JA, IPFLAG, F, JAC) + EXTERNAL F, JAC + INTEGER NEQ, IA, JA, IPFLAG + DOUBLE PRECISION Y, RWORK + DIMENSION NEQ(*), Y(*), RWORK(*), IA(*), JA(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION RLSS + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IMAX, LEWTN, LYHD, LYHN +C----------------------------------------------------------------------- +C This routine serves as an interface between the driver and +C Subroutine DPREP. It is called only if MITER is 1 or 2. +C Tasks performed here are: +C * call DPREP, +C * reset the required WM segment length LENWK, +C * move YH back to its final location (following WM in RWORK), +C * reset pointers for YH, SAVF, EWT, and ACOR, and +C * move EWT to its new position if ISTATE = 1. +C IPFLAG is an output error indication flag. IPFLAG = 0 if there was +C no trouble, and IPFLAG is the value of the DPREP error flag IPPER +C if there was trouble in Subroutine DPREP. +C----------------------------------------------------------------------- + IPFLAG = 0 +C Call DPREP to do matrix preprocessing operations. -------------------- + CALL DPREP (NEQ, Y, RWORK(LYH), RWORK(LSAVF), RWORK(LEWT), + 1 RWORK(LACOR), IA, JA, RWORK(LWM), RWORK(LWM), IPFLAG, F, JAC) + LENWK = MAX(LREQ,LWMIN) + IF (IPFLAG .LT. 0) RETURN +C If DPREP was successful, move YH to end of required space for WM. ---- + LYHN = LWM + LENWK + IF (LYHN .GT. LYH) RETURN + LYHD = LYH - LYHN + IF (LYHD .EQ. 0) GO TO 20 + IMAX = LYHN - 1 + LENYHM + DO 10 I = LYHN,IMAX + 10 RWORK(I) = RWORK(I+LYHD) + LYH = LYHN +C Reset pointers for SAVF, EWT, and ACOR. ------------------------------ + 20 LSAVF = LYH + LENYH + LEWTN = LSAVF + N + LACOR = LEWTN + N + IF (ISTATC .EQ. 3) GO TO 40 +C If ISTATE = 1, move EWT (left) to its new position. ------------------ + IF (LEWTN .GT. LEWT) RETURN + DO 30 I = 1,N + 30 RWORK(I+LEWTN-1) = RWORK(I+LEWT-1) + 40 LEWT = LEWTN + RETURN +C----------------------- End of Subroutine DIPREP ---------------------- + END +*DECK DPREP + SUBROUTINE DPREP (NEQ, Y, YH, SAVF, EWT, FTEM, IA, JA, + 1 WK, IWK, IPPER, F, JAC) + EXTERNAL F,JAC + INTEGER NEQ, IA, JA, IWK, IPPER + DOUBLE PRECISION Y, YH, SAVF, EWT, FTEM, WK + DIMENSION NEQ(*), Y(*), YH(*), SAVF(*), EWT(*), FTEM(*), + 1 IA(*), JA(*), WK(*), IWK(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH, + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IBR, IER, IPIL, IPIU, IPTT1, IPTT2, J, JFOUND, K, + 1 KNEW, KMAX, KMIN, LDIF, LENIGP, LIWK, MAXG, NP1, NZSUT + DOUBLE PRECISION DQ, DYJ, ERWT, FAC, YJ +C----------------------------------------------------------------------- +C This routine performs preprocessing related to the sparse linear +C systems that must be solved if MITER = 1 or 2. +C The operations that are performed here are: +C * compute sparseness structure of Jacobian according to MOSS, +C * compute grouping of column indices (MITER = 2), +C * compute a new ordering of rows and columns of the matrix, +C * reorder JA corresponding to the new ordering, +C * perform a symbolic LU factorization of the matrix, and +C * set pointers for segments of the IWK/WK array. +C In addition to variables described previously, DPREP uses the +C following for communication: +C YH = the history array. Only the first column, containing the +C current Y vector, is used. Used only if MOSS .ne. 0. +C SAVF = a work array of length NEQ, used only if MOSS .ne. 0. +C EWT = array of length NEQ containing (inverted) error weights. +C Used only if MOSS = 2 or if ISTATE = MOSS = 1. +C FTEM = a work array of length NEQ, identical to ACOR in the driver, +C used only if MOSS = 2. +C WK = a real work array of length LENWK, identical to WM in +C the driver. +C IWK = integer work array, assumed to occupy the same space as WK. +C LENWK = the length of the work arrays WK and IWK. +C ISTATC = a copy of the driver input argument ISTATE (= 1 on the +C first call, = 3 on a continuation call). +C IYS = flag value from ODRV or CDRV. +C IPPER = output error flag with the following values and meanings: +C 0 no error. +C -1 insufficient storage for internal structure pointers. +C -2 insufficient storage for JGROUP. +C -3 insufficient storage for ODRV. +C -4 other error flag from ODRV (should never occur). +C -5 insufficient storage for CDRV. +C -6 other error flag from CDRV. +C----------------------------------------------------------------------- + IBIAN = LRAT*2 + IPIAN = IBIAN + 1 + NP1 = N + 1 + IPJAN = IPIAN + NP1 + IBJAN = IPJAN - 1 + LIWK = LENWK*LRAT + IF (IPJAN+N-1 .GT. LIWK) GO TO 210 + IF (MOSS .EQ. 0) GO TO 30 +C + IF (ISTATC .EQ. 3) GO TO 20 +C ISTATE = 1 and MOSS .ne. 0. Perturb Y for structure determination. -- + DO 10 I = 1,N + ERWT = 1.0D0/EWT(I) + FAC = 1.0D0 + 1.0D0/(I + 1.0D0) + Y(I) = Y(I) + FAC*SIGN(ERWT,Y(I)) + 10 CONTINUE + GO TO (70, 100), MOSS +C + 20 CONTINUE +C ISTATE = 3 and MOSS .ne. 0. Load Y from YH(*,1). -------------------- + DO 25 I = 1,N + 25 Y(I) = YH(I) + GO TO (70, 100), MOSS +C +C MOSS = 0. Process user's IA,JA. Add diagonal entries if necessary. - + 30 KNEW = IPJAN + KMIN = IA(1) + IWK(IPIAN) = 1 + DO 60 J = 1,N + JFOUND = 0 + KMAX = IA(J+1) - 1 + IF (KMIN .GT. KMAX) GO TO 45 + DO 40 K = KMIN,KMAX + I = JA(K) + IF (I .EQ. J) JFOUND = 1 + IF (KNEW .GT. LIWK) GO TO 210 + IWK(KNEW) = I + KNEW = KNEW + 1 + 40 CONTINUE + IF (JFOUND .EQ. 1) GO TO 50 + 45 IF (KNEW .GT. LIWK) GO TO 210 + IWK(KNEW) = J + KNEW = KNEW + 1 + 50 IWK(IPIAN+J) = KNEW + 1 - IPJAN + KMIN = KMAX + 1 + 60 CONTINUE + GO TO 140 +C +C MOSS = 1. Compute structure from user-supplied Jacobian routine JAC. + 70 CONTINUE +C A dummy call to F allows user to create temporaries for use in JAC. -- + CALL F (NEQ, TN, Y, SAVF) + K = IPJAN + IWK(IPIAN) = 1 + DO 90 J = 1,N + IF (K .GT. LIWK) GO TO 210 + IWK(K) = J + K = K + 1 + DO 75 I = 1,N + 75 SAVF(I) = 0.0D0 + CALL JAC (NEQ, TN, Y, J, IWK(IPIAN), IWK(IPJAN), SAVF) + DO 80 I = 1,N + IF (ABS(SAVF(I)) .LE. SETH) GO TO 80 + IF (I .EQ. J) GO TO 80 + IF (K .GT. LIWK) GO TO 210 + IWK(K) = I + K = K + 1 + 80 CONTINUE + IWK(IPIAN+J) = K + 1 - IPJAN + 90 CONTINUE + GO TO 140 +C +C MOSS = 2. Compute structure from results of N + 1 calls to F. ------- + 100 K = IPJAN + IWK(IPIAN) = 1 + CALL F (NEQ, TN, Y, SAVF) + DO 120 J = 1,N + IF (K .GT. LIWK) GO TO 210 + IWK(K) = J + K = K + 1 + YJ = Y(J) + ERWT = 1.0D0/EWT(J) + DYJ = SIGN(ERWT,YJ) + Y(J) = YJ + DYJ + CALL F (NEQ, TN, Y, FTEM) + Y(J) = YJ + DO 110 I = 1,N + DQ = (FTEM(I) - SAVF(I))/DYJ + IF (ABS(DQ) .LE. SETH) GO TO 110 + IF (I .EQ. J) GO TO 110 + IF (K .GT. LIWK) GO TO 210 + IWK(K) = I + K = K + 1 + 110 CONTINUE + IWK(IPIAN+J) = K + 1 - IPJAN + 120 CONTINUE +C + 140 CONTINUE + IF (MOSS .EQ. 0 .OR. ISTATC .NE. 1) GO TO 150 +C If ISTATE = 1 and MOSS .ne. 0, restore Y from YH. -------------------- + DO 145 I = 1,N + 145 Y(I) = YH(I) + 150 NNZ = IWK(IPIAN+N) - 1 + LENIGP = 0 + IPIGP = IPJAN + NNZ + IF (MITER .NE. 2) GO TO 160 +C +C Compute grouping of column indices (MITER = 2). ---------------------- + MAXG = NP1 + IPJGP = IPJAN + NNZ + IBJGP = IPJGP - 1 + IPIGP = IPJGP + N + IPTT1 = IPIGP + NP1 + IPTT2 = IPTT1 + N + LREQ = IPTT2 + N - 1 + IF (LREQ .GT. LIWK) GO TO 220 + CALL JGROUP (N, IWK(IPIAN), IWK(IPJAN), MAXG, NGP, IWK(IPIGP), + 1 IWK(IPJGP), IWK(IPTT1), IWK(IPTT2), IER) + IF (IER .NE. 0) GO TO 220 + LENIGP = NGP + 1 +C +C Compute new ordering of rows/columns of Jacobian. -------------------- + 160 IPR = IPIGP + LENIGP + IPC = IPR + IPIC = IPC + N + IPISP = IPIC + N + IPRSP = (IPISP - 2)/LRAT + 2 + IESP = LENWK + 1 - IPRSP + IF (IESP .LT. 0) GO TO 230 + IBR = IPR - 1 + DO 170 I = 1,N + 170 IWK(IBR+I) = I + NSP = LIWK + 1 - IPISP + CALL ODRV (N, IWK(IPIAN), IWK(IPJAN), WK, IWK(IPR), IWK(IPIC), + 1 NSP, IWK(IPISP), 1, IYS) + IF (IYS .EQ. 11*N+1) GO TO 240 + IF (IYS .NE. 0) GO TO 230 +C +C Reorder JAN and do symbolic LU factorization of matrix. -------------- + IPA = LENWK + 1 - NNZ + NSP = IPA - IPRSP + LREQ = MAX(12*N/LRAT, 6*N/LRAT+2*N+NNZ) + 3 + LREQ = LREQ + IPRSP - 1 + NNZ + IF (LREQ .GT. LENWK) GO TO 250 + IBA = IPA - 1 + DO 180 I = 1,NNZ + 180 WK(IBA+I) = 0.0D0 + IPISP = LRAT*(IPRSP - 1) + 1 + CALL CDRV (N,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),WK(IPA),WK(IPA),NSP,IWK(IPISP),WK(IPRSP),IESP,5,IYS) + LREQ = LENWK - IESP + IF (IYS .EQ. 10*N+1) GO TO 250 + IF (IYS .NE. 0) GO TO 260 + IPIL = IPISP + IPIU = IPIL + 2*N + 1 + NZU = IWK(IPIL+N) - IWK(IPIL) + NZL = IWK(IPIU+N) - IWK(IPIU) + IF (LRAT .GT. 1) GO TO 190 + CALL ADJLR (N, IWK(IPISP), LDIF) + LREQ = LREQ + LDIF + 190 CONTINUE + IF (LRAT .EQ. 2 .AND. NNZ .EQ. N) LREQ = LREQ + 1 + NSP = NSP + LREQ - LENWK + IPA = LREQ + 1 - NNZ + IBA = IPA - 1 + IPPER = 0 + RETURN +C + 210 IPPER = -1 + LREQ = 2 + (2*N + 1)/LRAT + LREQ = MAX(LENWK+1,LREQ) + RETURN +C + 220 IPPER = -2 + LREQ = (LREQ - 1)/LRAT + 1 + RETURN +C + 230 IPPER = -3 + CALL CNTNZU (N, IWK(IPIAN), IWK(IPJAN), NZSUT) + LREQ = LENWK - IESP + (3*N + 4*NZSUT - 1)/LRAT + 1 + RETURN +C + 240 IPPER = -4 + RETURN +C + 250 IPPER = -5 + RETURN +C + 260 IPPER = -6 + LREQ = LENWK + RETURN +C----------------------- End of Subroutine DPREP ----------------------- + END +*DECK JGROUP + SUBROUTINE JGROUP (N,IA,JA,MAXG,NGRP,IGP,JGP,INCL,JDONE,IER) + INTEGER N, IA, JA, MAXG, NGRP, IGP, JGP, INCL, JDONE, IER + DIMENSION IA(*), JA(*), IGP(*), JGP(*), INCL(*), JDONE(*) +C----------------------------------------------------------------------- +C This subroutine constructs groupings of the column indices of +C the Jacobian matrix, used in the numerical evaluation of the +C Jacobian by finite differences. +C +C Input: +C N = the order of the matrix. +C IA,JA = sparse structure descriptors of the matrix by rows. +C MAXG = length of available storage in the IGP array. +C +C Output: +C NGRP = number of groups. +C JGP = array of length N containing the column indices by groups. +C IGP = pointer array of length NGRP + 1 to the locations in JGP +C of the beginning of each group. +C IER = error indicator. IER = 0 if no error occurred, or 1 if +C MAXG was insufficient. +C +C INCL and JDONE are working arrays of length N. +C----------------------------------------------------------------------- + INTEGER I, J, K, KMIN, KMAX, NCOL, NG +C + IER = 0 + DO 10 J = 1,N + 10 JDONE(J) = 0 + NCOL = 1 + DO 60 NG = 1,MAXG + IGP(NG) = NCOL + DO 20 I = 1,N + 20 INCL(I) = 0 + DO 50 J = 1,N +C Reject column J if it is already in a group.-------------------------- + IF (JDONE(J) .EQ. 1) GO TO 50 + KMIN = IA(J) + KMAX = IA(J+1) - 1 + DO 30 K = KMIN,KMAX +C Reject column J if it overlaps any column already in this group.------ + I = JA(K) + IF (INCL(I) .EQ. 1) GO TO 50 + 30 CONTINUE +C Accept column J into group NG.---------------------------------------- + JGP(NCOL) = J + NCOL = NCOL + 1 + JDONE(J) = 1 + DO 40 K = KMIN,KMAX + I = JA(K) + 40 INCL(I) = 1 + 50 CONTINUE +C Stop if this group is empty (grouping is complete).------------------- + IF (NCOL .EQ. IGP(NG)) GO TO 70 + 60 CONTINUE +C Error return if not all columns were chosen (MAXG too small).--------- + IF (NCOL .LE. N) GO TO 80 + NG = MAXG + 70 NGRP = NG - 1 + RETURN + 80 IER = 1 + RETURN +C----------------------- End of Subroutine JGROUP ---------------------- + END +*DECK ADJLR + SUBROUTINE ADJLR (N, ISP, LDIF) + INTEGER N, ISP, LDIF + DIMENSION ISP(*) +C----------------------------------------------------------------------- +C This routine computes an adjustment, LDIF, to the required +C integer storage space in IWK (sparse matrix work space). +C It is called only if the word length ratio is LRAT = 1. +C This is to account for the possibility that the symbolic LU phase +C may require more storage than the numerical LU and solution phases. +C----------------------------------------------------------------------- + INTEGER IP, JLMAX, JUMAX, LNFC, LSFC, NZLU +C + IP = 2*N + 1 +C Get JLMAX = IJL(N) and JUMAX = IJU(N) (sizes of JL and JU). ---------- + JLMAX = ISP(IP) + JUMAX = ISP(IP+IP) +C NZLU = (size of L) + (size of U) = (IL(N+1)-IL(1)) + (IU(N+1)-IU(1)). + NZLU = ISP(N+1) - ISP(1) + ISP(IP+N+1) - ISP(IP+1) + LSFC = 12*N + 3 + 2*MAX(JLMAX,JUMAX) + LNFC = 9*N + 2 + JLMAX + JUMAX + NZLU + LDIF = MAX(0, LSFC - LNFC) + RETURN +C----------------------- End of Subroutine ADJLR ----------------------- + END +*DECK CNTNZU + SUBROUTINE CNTNZU (N, IA, JA, NZSUT) + INTEGER N, IA, JA, NZSUT + DIMENSION IA(*), JA(*) +C----------------------------------------------------------------------- +C This routine counts the number of nonzero elements in the strict +C upper triangle of the matrix M + M(transpose), where the sparsity +C structure of M is given by pointer arrays IA and JA. +C This is needed to compute the storage requirements for the +C sparse matrix reordering operation in ODRV. +C----------------------------------------------------------------------- + INTEGER II, JJ, J, JMIN, JMAX, K, KMIN, KMAX, NUM +C + NUM = 0 + DO 50 II = 1,N + JMIN = IA(II) + JMAX = IA(II+1) - 1 + IF (JMIN .GT. JMAX) GO TO 50 + DO 40 J = JMIN,JMAX + IF (JA(J) - II) 10, 40, 30 + 10 JJ =JA(J) + KMIN = IA(JJ) + KMAX = IA(JJ+1) - 1 + IF (KMIN .GT. KMAX) GO TO 30 + DO 20 K = KMIN,KMAX + IF (JA(K) .EQ. II) GO TO 40 + 20 CONTINUE + 30 NUM = NUM + 1 + 40 CONTINUE + 50 CONTINUE + NZSUT = NUM + RETURN +C----------------------- End of Subroutine CNTNZU ---------------------- + END +*DECK DPRJS + SUBROUTINE DPRJS (NEQ,Y,YH,NYH,EWT,FTEM,SAVF,WK,IWK,F,JAC) + EXTERNAL F,JAC + INTEGER NEQ, NYH, IWK + DOUBLE PRECISION Y, YH, EWT, FTEM, SAVF, WK + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), FTEM(*), SAVF(*), + 1 WK(*), IWK(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH, + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IMUL, J, JJ, JOK, JMAX, JMIN, K, KMAX, KMIN, NG + DOUBLE PRECISION CON, DI, FAC, HL0, PIJ, R, R0, RCON, RCONT, + 1 SRUR, DVNORM +C----------------------------------------------------------------------- +C DPRJS is called to compute and process the matrix +C P = I - H*EL(1)*J , where J is an approximation to the Jacobian. +C J is computed by columns, either by the user-supplied routine JAC +C if MITER = 1, or by finite differencing if MITER = 2. +C if MITER = 3, a diagonal approximation to J is used. +C if MITER = 1 or 2, and if the existing value of the Jacobian +C (as contained in P) is considered acceptable, then a new value of +C P is reconstructed from the old value. In any case, when MITER +C is 1 or 2, the P matrix is subjected to LU decomposition in CDRV. +C P and its LU decomposition are stored (separately) in WK. +C +C In addition to variables described previously, communication +C with DPRJS uses the following: +C Y = array containing predicted values on entry. +C FTEM = work array of length N (ACOR in DSTODE). +C SAVF = array containing f evaluated at predicted y. +C WK = real work space for matrices. On output it contains the +C inverse diagonal matrix if MITER = 3, and P and its sparse +C LU decomposition if MITER is 1 or 2. +C Storage of matrix elements starts at WK(3). +C WK also contains the following matrix-related data: +C WK(1) = SQRT(UROUND), used in numerical Jacobian increments. +C WK(2) = H*EL0, saved for later use if MITER = 3. +C IWK = integer work space for matrix-related data, assumed to +C be equivalenced to WK. In addition, WK(IPRSP) and IWK(IPISP) +C are assumed to have identical locations. +C EL0 = EL(1) (input). +C IERPJ = output error flag (in Common). +C = 0 if no error. +C = 1 if zero pivot found in CDRV. +C = 2 if a singular matrix arose with MITER = 3. +C = -1 if insufficient storage for CDRV (should not occur here). +C = -2 if other error found in CDRV (should not occur here). +C JCUR = output flag showing status of (approximate) Jacobian matrix: +C = 1 to indicate that the Jacobian is now current, or +C = 0 to indicate that a saved value was used. +C This routine also uses other variables in Common. +C----------------------------------------------------------------------- + HL0 = H*EL0 + CON = -HL0 + IF (MITER .EQ. 3) GO TO 300 +C See whether J should be reevaluated (JOK = 0) or not (JOK = 1). ------ + JOK = 1 + IF (NST .EQ. 0 .OR. NST .GE. NSLJ+MSBJ) JOK = 0 + IF (ICF .EQ. 1 .AND. ABS(RC - 1.0D0) .LT. CCMXJ) JOK = 0 + IF (ICF .EQ. 2) JOK = 0 + IF (JOK .EQ. 1) GO TO 250 +C +C MITER = 1 or 2, and the Jacobian is to be reevaluated. --------------- + 20 JCUR = 1 + NJE = NJE + 1 + NSLJ = NST + IPLOST = 0 + CONMIN = ABS(CON) + GO TO (100, 200), MITER +C +C If MITER = 1, call JAC, multiply by scalar, and add identity. -------- + 100 CONTINUE + KMIN = IWK(IPIAN) + DO 130 J = 1, N + KMAX = IWK(IPIAN+J) - 1 + DO 110 I = 1,N + 110 FTEM(I) = 0.0D0 + CALL JAC (NEQ, TN, Y, J, IWK(IPIAN), IWK(IPJAN), FTEM) + DO 120 K = KMIN, KMAX + I = IWK(IBJAN+K) + WK(IBA+K) = FTEM(I)*CON + IF (I .EQ. J) WK(IBA+K) = WK(IBA+K) + 1.0D0 + 120 CONTINUE + KMIN = KMAX + 1 + 130 CONTINUE + GO TO 290 +C +C If MITER = 2, make NGP calls to F to approximate J and P. ------------ + 200 CONTINUE + FAC = DVNORM(N, SAVF, EWT) + R0 = 1000.0D0 * ABS(H) * UROUND * N * FAC + IF (R0 .EQ. 0.0D0) R0 = 1.0D0 + SRUR = WK(1) + JMIN = IWK(IPIGP) + DO 240 NG = 1,NGP + JMAX = IWK(IPIGP+NG) - 1 + DO 210 J = JMIN,JMAX + JJ = IWK(IBJGP+J) + R = MAX(SRUR*ABS(Y(JJ)),R0/EWT(JJ)) + 210 Y(JJ) = Y(JJ) + R + CALL F (NEQ, TN, Y, FTEM) + DO 230 J = JMIN,JMAX + JJ = IWK(IBJGP+J) + Y(JJ) = YH(JJ,1) + R = MAX(SRUR*ABS(Y(JJ)),R0/EWT(JJ)) + FAC = -HL0/R + KMIN =IWK(IBIAN+JJ) + KMAX =IWK(IBIAN+JJ+1) - 1 + DO 220 K = KMIN,KMAX + I = IWK(IBJAN+K) + WK(IBA+K) = (FTEM(I) - SAVF(I))*FAC + IF (I .EQ. JJ) WK(IBA+K) = WK(IBA+K) + 1.0D0 + 220 CONTINUE + 230 CONTINUE + JMIN = JMAX + 1 + 240 CONTINUE + NFE = NFE + NGP + GO TO 290 +C +C If JOK = 1, reconstruct new P from old P. ---------------------------- + 250 JCUR = 0 + RCON = CON/CON0 + RCONT = ABS(CON)/CONMIN + IF (RCONT .GT. RBIG .AND. IPLOST .EQ. 1) GO TO 20 + KMIN = IWK(IPIAN) + DO 275 J = 1,N + KMAX = IWK(IPIAN+J) - 1 + DO 270 K = KMIN,KMAX + I = IWK(IBJAN+K) + PIJ = WK(IBA+K) + IF (I .NE. J) GO TO 260 + PIJ = PIJ - 1.0D0 + IF (ABS(PIJ) .GE. PSMALL) GO TO 260 + IPLOST = 1 + CONMIN = MIN(ABS(CON0),CONMIN) + 260 PIJ = PIJ*RCON + IF (I .EQ. J) PIJ = PIJ + 1.0D0 + WK(IBA+K) = PIJ + 270 CONTINUE + KMIN = KMAX + 1 + 275 CONTINUE +C +C Do numerical factorization of P matrix. ------------------------------ + 290 NLU = NLU + 1 + CON0 = CON + IERPJ = 0 + DO 295 I = 1,N + 295 FTEM(I) = 0.0D0 + CALL CDRV (N,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),FTEM,FTEM,NSP,IWK(IPISP),WK(IPRSP),IESP,2,IYS) + IF (IYS .EQ. 0) RETURN + IMUL = (IYS - 1)/N + IERPJ = -2 + IF (IMUL .EQ. 8) IERPJ = 1 + IF (IMUL .EQ. 10) IERPJ = -1 + RETURN +C +C If MITER = 3, construct a diagonal approximation to J and P. --------- + 300 CONTINUE + JCUR = 1 + NJE = NJE + 1 + WK(2) = HL0 + IERPJ = 0 + R = EL0*0.1D0 + DO 310 I = 1,N + 310 Y(I) = Y(I) + R*(H*SAVF(I) - YH(I,2)) + CALL F (NEQ, TN, Y, WK(3)) + NFE = NFE + 1 + DO 320 I = 1,N + R0 = H*SAVF(I) - YH(I,2) + DI = 0.1D0*R0 - H*(WK(I+2) - SAVF(I)) + WK(I+2) = 1.0D0 + IF (ABS(R0) .LT. UROUND/EWT(I)) GO TO 320 + IF (ABS(DI) .EQ. 0.0D0) GO TO 330 + WK(I+2) = 0.1D0*R0/DI + 320 CONTINUE + RETURN + 330 IERPJ = 2 + RETURN +C----------------------- End of Subroutine DPRJS ----------------------- + END +*DECK DSOLSS + SUBROUTINE DSOLSS (WK, IWK, X, TEM) + INTEGER IWK + DOUBLE PRECISION WK, X, TEM + DIMENSION WK(*), IWK(*), X(*), TEM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION RLSS + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I + DOUBLE PRECISION DI, HL0, PHL0, R +C----------------------------------------------------------------------- +C This routine manages the solution of the linear system arising from +C a chord iteration. It is called if MITER .ne. 0. +C If MITER is 1 or 2, it calls CDRV to accomplish this. +C If MITER = 3 it updates the coefficient H*EL0 in the diagonal +C matrix, and then computes the solution. +C communication with DSOLSS uses the following variables: +C WK = real work space containing the inverse diagonal matrix if +C MITER = 3 and the LU decomposition of the matrix otherwise. +C Storage of matrix elements starts at WK(3). +C WK also contains the following matrix-related data: +C WK(1) = SQRT(UROUND) (not used here), +C WK(2) = HL0, the previous value of H*EL0, used if MITER = 3. +C IWK = integer work space for matrix-related data, assumed to +C be equivalenced to WK. In addition, WK(IPRSP) and IWK(IPISP) +C are assumed to have identical locations. +C X = the right-hand side vector on input, and the solution vector +C on output, of length N. +C TEM = vector of work space of length N, not used in this version. +C IERSL = output flag (in Common). +C IERSL = 0 if no trouble occurred. +C IERSL = -1 if CDRV returned an error flag (MITER = 1 or 2). +C This should never occur and is considered fatal. +C IERSL = 1 if a singular matrix arose with MITER = 3. +C This routine also uses other variables in Common. +C----------------------------------------------------------------------- + IERSL = 0 + GO TO (100, 100, 300), MITER + 100 CALL CDRV (N,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),X,X,NSP,IWK(IPISP),WK(IPRSP),IESP,4,IERSL) + IF (IERSL .NE. 0) IERSL = -1 + RETURN +C + 300 PHL0 = WK(2) + HL0 = H*EL0 + WK(2) = HL0 + IF (HL0 .EQ. PHL0) GO TO 330 + R = HL0/PHL0 + DO 320 I = 1,N + DI = 1.0D0 - R*(1.0D0 - 1.0D0/WK(I+2)) + IF (ABS(DI) .EQ. 0.0D0) GO TO 390 + 320 WK(I+2) = 1.0D0/DI + 330 DO 340 I = 1,N + 340 X(I) = WK(I+2)*X(I) + RETURN + 390 IERSL = 1 + RETURN +C +C----------------------- End of Subroutine DSOLSS ---------------------- + END +*DECK DSRCMS + SUBROUTINE DSRCMS (RSAV, ISAV, JOB) +C----------------------------------------------------------------------- +C This routine saves or restores (depending on JOB) the contents of +C the Common blocks DLS001, DLSS01, which are used +C internally by one or more ODEPACK solvers. +C +C RSAV = real array of length 224 or more. +C ISAV = integer array of length 71 or more. +C JOB = flag indicating to save or restore the Common blocks: +C JOB = 1 if Common is to be saved (written to RSAV/ISAV) +C JOB = 2 if Common is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C----------------------------------------------------------------------- + INTEGER ISAV, JOB + INTEGER ILS, ILSS + INTEGER I, LENILS, LENISS, LENRLS, LENRSS + DOUBLE PRECISION RSAV, RLS, RLSS + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS, LENRSS, LENISS + COMMON /DLS001/ RLS(218), ILS(37) + COMMON /DLSS01/ RLSS(6), ILSS(34) + DATA LENRLS/218/, LENILS/37/, LENRSS/6/, LENISS/34/ +C + IF (JOB .EQ. 2) GO TO 100 + DO 10 I = 1,LENRLS + 10 RSAV(I) = RLS(I) + DO 15 I = 1,LENRSS + 15 RSAV(LENRLS+I) = RLSS(I) +C + DO 20 I = 1,LENILS + 20 ISAV(I) = ILS(I) + DO 25 I = 1,LENISS + 25 ISAV(LENILS+I) = ILSS(I) +C + RETURN +C + 100 CONTINUE + DO 110 I = 1,LENRLS + 110 RLS(I) = RSAV(I) + DO 115 I = 1,LENRSS + 115 RLSS(I) = RSAV(LENRLS+I) +C + DO 120 I = 1,LENILS + 120 ILS(I) = ISAV(I) + DO 125 I = 1,LENISS + 125 ILSS(I) = ISAV(LENILS+I) +C + RETURN +C----------------------- End of Subroutine DSRCMS ---------------------- + END +*DECK ODRV + subroutine odrv + * (n, ia,ja,a, p,ip, nsp,isp, path, flag) +c 5/2/83 +c*********************************************************************** +c odrv -- driver for sparse matrix reordering routines +c*********************************************************************** +c +c description +c +c odrv finds a minimum degree ordering of the rows and columns +c of a matrix m stored in (ia,ja,a) format (see below). for the +c reordered matrix, the work and storage required to perform +c gaussian elimination is (usually) significantly less. +c +c note.. odrv and its subordinate routines have been modified to +c compute orderings for general matrices, not necessarily having any +c symmetry. the miminum degree ordering is computed for the +c structure of the symmetric matrix m + m-transpose. +c modifications to the original odrv module have been made in +c the coding in subroutine mdi, and in the initial comments in +c subroutines odrv and md. +c +c if only the nonzero entries in the upper triangle of m are being +c stored, then odrv symmetrically reorders (ia,ja,a), (optionally) +c with the diagonal entries placed first in each row. this is to +c ensure that if m(i,j) will be in the upper triangle of m with +c respect to the new ordering, then m(i,j) is stored in row i (and +c thus m(j,i) is not stored), whereas if m(i,j) will be in the +c strict lower triangle of m, then m(j,i) is stored in row j (and +c thus m(i,j) is not stored). +c +c +c storage of sparse matrices +c +c the nonzero entries of the matrix m are stored row-by-row in the +c array a. to identify the individual nonzero entries in each row, +c we need to know in which column each entry lies. these column +c indices are stored in the array ja. i.e., if a(k) = m(i,j), then +c ja(k) = j. to identify the individual rows, we need to know where +c each row starts. these row pointers are stored in the array ia. +c i.e., if m(i,j) is the first nonzero entry (stored) in the i-th row +c and a(k) = m(i,j), then ia(i) = k. moreover, ia(n+1) points to +c the first location following the last element in the last row. +c thus, the number of entries in the i-th row is ia(i+1) - ia(i), +c the nonzero entries in the i-th row are stored consecutively in +c +c a(ia(i)), a(ia(i)+1), ..., a(ia(i+1)-1), +c +c and the corresponding column indices are stored consecutively in +c +c ja(ia(i)), ja(ia(i)+1), ..., ja(ia(i+1)-1). +c +c when the coefficient matrix is symmetric, only the nonzero entries +c in the upper triangle need be stored. for example, the matrix +c +c ( 1 0 2 3 0 ) +c ( 0 4 0 0 0 ) +c m = ( 2 0 5 6 0 ) +c ( 3 0 6 7 8 ) +c ( 0 0 0 8 9 ) +c +c could be stored as +c +c - 1 2 3 4 5 6 7 8 9 10 11 12 13 +c ---+-------------------------------------- +c ia - 1 4 5 8 12 14 +c ja - 1 3 4 2 1 3 4 1 3 4 5 4 5 +c a - 1 2 3 4 2 5 6 3 6 7 8 8 9 +c +c or (symmetrically) as +c +c - 1 2 3 4 5 6 7 8 9 +c ---+-------------------------- +c ia - 1 4 5 7 9 10 +c ja - 1 3 4 2 3 4 4 5 5 +c a - 1 2 3 4 5 6 7 8 9 . +c +c +c parameters +c +c n - order of the matrix +c +c ia - integer one-dimensional array containing pointers to delimit +c rows in ja and a. dimension = n+1 +c +c ja - integer one-dimensional array containing the column indices +c corresponding to the elements of a. dimension = number of +c nonzero entries in (the upper triangle of) m +c +c a - real one-dimensional array containing the nonzero entries in +c (the upper triangle of) m, stored by rows. dimension = +c number of nonzero entries in (the upper triangle of) m +c +c p - integer one-dimensional array used to return the permutation +c of the rows and columns of m corresponding to the minimum +c degree ordering. dimension = n +c +c ip - integer one-dimensional array used to return the inverse of +c the permutation returned in p. dimension = n +c +c nsp - declared dimension of the one-dimensional array isp. nsp +c must be at least 3n+4k, where k is the number of nonzeroes +c in the strict upper triangle of m +c +c isp - integer one-dimensional array used for working storage. +c dimension = nsp +c +c path - integer path specification. values and their meanings are - +c 1 find minimum degree ordering only +c 2 find minimum degree ordering and reorder symmetrically +c stored matrix (used when only the nonzero entries in +c the upper triangle of m are being stored) +c 3 reorder symmetrically stored matrix as specified by +c input permutation (used when an ordering has already +c been determined and only the nonzero entries in the +c upper triangle of m are being stored) +c 4 same as 2 but put diagonal entries at start of each row +c 5 same as 3 but put diagonal entries at start of each row +c +c flag - integer error flag. values and their meanings are - +c 0 no errors detected +c 9n+k insufficient storage in md +c 10n+1 insufficient storage in odrv +c 11n+1 illegal path specification +c +c +c conversion from real to double precision +c +c change the real declarations in odrv and sro to double precision +c declarations. +c +c----------------------------------------------------------------------- +c + integer ia(*), ja(*), p(*), ip(*), isp(*), path, flag, + * v, l, head, tmp, q +c... real a(*) + double precision a(*) + logical dflag +c +c----initialize error flag and validate path specification + flag = 0 + if (path.lt.1 .or. 5.lt.path) go to 111 +c +c----allocate storage and find minimum degree ordering + if ((path-1) * (path-2) * (path-4) .ne. 0) go to 1 + max = (nsp-n)/2 + v = 1 + l = v + max + head = l + max + next = head + n + if (max.lt.n) go to 110 +c + call md + * (n, ia,ja, max,isp(v),isp(l), isp(head),p,ip, isp(v), flag) + if (flag.ne.0) go to 100 +c +c----allocate storage and symmetrically reorder matrix + 1 if ((path-2) * (path-3) * (path-4) * (path-5) .ne. 0) go to 2 + tmp = (nsp+1) - n + q = tmp - (ia(n+1)-1) + if (q.lt.1) go to 110 +c + dflag = path.eq.4 .or. path.eq.5 + call sro + * (n, ip, ia, ja, a, isp(tmp), isp(q), dflag) +c + 2 return +c +c ** error -- error detected in md + 100 return +c ** error -- insufficient storage + 110 flag = 10*n + 1 + return +c ** error -- illegal path specified + 111 flag = 11*n + 1 + return + end + subroutine md + * (n, ia,ja, max, v,l, head,last,next, mark, flag) +c*********************************************************************** +c md -- minimum degree algorithm (based on element model) +c*********************************************************************** +c +c description +c +c md finds a minimum degree ordering of the rows and columns of a +c general sparse matrix m stored in (ia,ja,a) format. +c when the structure of m is nonsymmetric, the ordering is that +c obtained for the symmetric matrix m + m-transpose. +c +c +c additional parameters +c +c max - declared dimension of the one-dimensional arrays v and l. +c max must be at least n+2k, where k is the number of +c nonzeroes in the strict upper triangle of m + m-transpose +c +c v - integer one-dimensional work array. dimension = max +c +c l - integer one-dimensional work array. dimension = max +c +c head - integer one-dimensional work array. dimension = n +c +c last - integer one-dimensional array used to return the permutation +c of the rows and columns of m corresponding to the minimum +c degree ordering. dimension = n +c +c next - integer one-dimensional array used to return the inverse of +c the permutation returned in last. dimension = n +c +c mark - integer one-dimensional work array (may be the same as v). +c dimension = n +c +c flag - integer error flag. values and their meanings are - +c 0 no errors detected +c 9n+k insufficient storage in md +c +c +c definitions of internal parameters +c +c ---------+--------------------------------------------------------- +c v(s) - value field of list entry +c ---------+--------------------------------------------------------- +c l(s) - link field of list entry (0 =) end of list) +c ---------+--------------------------------------------------------- +c l(vi) - pointer to element list of uneliminated vertex vi +c ---------+--------------------------------------------------------- +c l(ej) - pointer to boundary list of active element ej +c ---------+--------------------------------------------------------- +c head(d) - vj =) vj head of d-list d +c - 0 =) no vertex in d-list d +c +c +c - vi uneliminated vertex +c - vi in ek - vi not in ek +c ---------+-----------------------------+--------------------------- +c next(vi) - undefined but nonnegative - vj =) vj next in d-list +c - - 0 =) vi tail of d-list +c ---------+-----------------------------+--------------------------- +c last(vi) - (not set until mdp) - -d =) vi head of d-list d +c --vk =) compute degree - vj =) vj last in d-list +c - ej =) vi prototype of ej - 0 =) vi not in any d-list +c - 0 =) do not compute degree - +c ---------+-----------------------------+--------------------------- +c mark(vi) - mark(vk) - nonneg. tag .lt. mark(vk) +c +c +c - vi eliminated vertex +c - ei active element - otherwise +c ---------+-----------------------------+--------------------------- +c next(vi) - -j =) vi was j-th vertex - -j =) vi was j-th vertex +c - to be eliminated - to be eliminated +c ---------+-----------------------------+--------------------------- +c last(vi) - m =) size of ei = m - undefined +c ---------+-----------------------------+--------------------------- +c mark(vi) - -m =) overlap count of ei - undefined +c - with ek = m - +c - otherwise nonnegative tag - +c - .lt. mark(vk) - +c +c----------------------------------------------------------------------- +c + integer ia(*), ja(*), v(*), l(*), head(*), last(*), next(*), + * mark(*), flag, tag, dmin, vk,ek, tail + equivalence (vk,ek) +c +c----initialization + tag = 0 + call mdi + * (n, ia,ja, max,v,l, head,last,next, mark,tag, flag) + if (flag.ne.0) return +c + k = 0 + dmin = 1 +c +c----while k .lt. n do + 1 if (k.ge.n) go to 4 +c +c------search for vertex of minimum degree + 2 if (head(dmin).gt.0) go to 3 + dmin = dmin + 1 + go to 2 +c +c------remove vertex vk of minimum degree from degree list + 3 vk = head(dmin) + head(dmin) = next(vk) + if (head(dmin).gt.0) last(head(dmin)) = -dmin +c +c------number vertex vk, adjust tag, and tag vk + k = k+1 + next(vk) = -k + last(ek) = dmin - 1 + tag = tag + last(ek) + mark(vk) = tag +c +c------form element ek from uneliminated neighbors of vk + call mdm + * (vk,tail, v,l, last,next, mark) +c +c------purge inactive elements and do mass elimination + call mdp + * (k,ek,tail, v,l, head,last,next, mark) +c +c------update degrees of uneliminated vertices in ek + call mdu + * (ek,dmin, v,l, head,last,next, mark) +c + go to 1 +c +c----generate inverse permutation from permutation + 4 do 5 k=1,n + next(k) = -next(k) + 5 last(next(k)) = k +c + return + end + subroutine mdi + * (n, ia,ja, max,v,l, head,last,next, mark,tag, flag) +c*********************************************************************** +c mdi -- initialization +c*********************************************************************** + integer ia(*), ja(*), v(*), l(*), head(*), last(*), next(*), + * mark(*), tag, flag, sfs, vi,dvi, vj +c +c----initialize degrees, element lists, and degree lists + do 1 vi=1,n + mark(vi) = 1 + l(vi) = 0 + 1 head(vi) = 0 + sfs = n+1 +c +c----create nonzero structure +c----for each nonzero entry a(vi,vj) + do 6 vi=1,n + jmin = ia(vi) + jmax = ia(vi+1) - 1 + if (jmin.gt.jmax) go to 6 + do 5 j=jmin,jmax + vj = ja(j) + if (vj-vi) 2, 5, 4 +c +c------if a(vi,vj) is in strict lower triangle +c------check for previous occurrence of a(vj,vi) + 2 lvk = vi + kmax = mark(vi) - 1 + if (kmax .eq. 0) go to 4 + do 3 k=1,kmax + lvk = l(lvk) + if (v(lvk).eq.vj) go to 5 + 3 continue +c----for unentered entries a(vi,vj) + 4 if (sfs.ge.max) go to 101 +c +c------enter vj in element list for vi + mark(vi) = mark(vi) + 1 + v(sfs) = vj + l(sfs) = l(vi) + l(vi) = sfs + sfs = sfs+1 +c +c------enter vi in element list for vj + mark(vj) = mark(vj) + 1 + v(sfs) = vi + l(sfs) = l(vj) + l(vj) = sfs + sfs = sfs+1 + 5 continue + 6 continue +c +c----create degree lists and initialize mark vector + do 7 vi=1,n + dvi = mark(vi) + next(vi) = head(dvi) + head(dvi) = vi + last(vi) = -dvi + nextvi = next(vi) + if (nextvi.gt.0) last(nextvi) = vi + 7 mark(vi) = tag +c + return +c +c ** error- insufficient storage + 101 flag = 9*n + vi + return + end + subroutine mdm + * (vk,tail, v,l, last,next, mark) +c*********************************************************************** +c mdm -- form element from uneliminated neighbors of vk +c*********************************************************************** + integer vk, tail, v(*), l(*), last(*), next(*), mark(*), + * tag, s,ls,vs,es, b,lb,vb, blp,blpmax + equivalence (vs, es) +c +c----initialize tag and list of uneliminated neighbors + tag = mark(vk) + tail = vk +c +c----for each vertex/element vs/es in element list of vk + ls = l(vk) + 1 s = ls + if (s.eq.0) go to 5 + ls = l(s) + vs = v(s) + if (next(vs).lt.0) go to 2 +c +c------if vs is uneliminated vertex, then tag and append to list of +c------uneliminated neighbors + mark(vs) = tag + l(tail) = s + tail = s + go to 4 +c +c------if es is active element, then ... +c--------for each vertex vb in boundary list of element es + 2 lb = l(es) + blpmax = last(es) + do 3 blp=1,blpmax + b = lb + lb = l(b) + vb = v(b) +c +c----------if vb is untagged vertex, then tag and append to list of +c----------uneliminated neighbors + if (mark(vb).ge.tag) go to 3 + mark(vb) = tag + l(tail) = b + tail = b + 3 continue +c +c--------mark es inactive + mark(es) = tag +c + 4 go to 1 +c +c----terminate list of uneliminated neighbors + 5 l(tail) = 0 +c + return + end + subroutine mdp + * (k,ek,tail, v,l, head,last,next, mark) +c*********************************************************************** +c mdp -- purge inactive elements and do mass elimination +c*********************************************************************** + integer ek, tail, v(*), l(*), head(*), last(*), next(*), + * mark(*), tag, free, li,vi,lvi,evi, s,ls,es, ilp,ilpmax +c +c----initialize tag + tag = mark(ek) +c +c----for each vertex vi in ek + li = ek + ilpmax = last(ek) + if (ilpmax.le.0) go to 12 + do 11 ilp=1,ilpmax + i = li + li = l(i) + vi = v(li) +c +c------remove vi from degree list + if (last(vi).eq.0) go to 3 + if (last(vi).gt.0) go to 1 + head(-last(vi)) = next(vi) + go to 2 + 1 next(last(vi)) = next(vi) + 2 if (next(vi).gt.0) last(next(vi)) = last(vi) +c +c------remove inactive items from element list of vi + 3 ls = vi + 4 s = ls + ls = l(s) + if (ls.eq.0) go to 6 + es = v(ls) + if (mark(es).lt.tag) go to 5 + free = ls + l(s) = l(ls) + ls = s + 5 go to 4 +c +c------if vi is interior vertex, then remove from list and eliminate + 6 lvi = l(vi) + if (lvi.ne.0) go to 7 + l(i) = l(li) + li = i +c + k = k+1 + next(vi) = -k + last(ek) = last(ek) - 1 + go to 11 +c +c------else ... +c--------classify vertex vi + 7 if (l(lvi).ne.0) go to 9 + evi = v(lvi) + if (next(evi).ge.0) go to 9 + if (mark(evi).lt.0) go to 8 +c +c----------if vi is prototype vertex, then mark as such, initialize +c----------overlap count for corresponding element, and move vi to end +c----------of boundary list + last(vi) = evi + mark(evi) = -1 + l(tail) = li + tail = li + l(i) = l(li) + li = i + go to 10 +c +c----------else if vi is duplicate vertex, then mark as such and adjust +c----------overlap count for corresponding element + 8 last(vi) = 0 + mark(evi) = mark(evi) - 1 + go to 10 +c +c----------else mark vi to compute degree + 9 last(vi) = -ek +c +c--------insert ek in element list of vi + 10 v(free) = ek + l(free) = l(vi) + l(vi) = free + 11 continue +c +c----terminate boundary list + 12 l(tail) = 0 +c + return + end + subroutine mdu + * (ek,dmin, v,l, head,last,next, mark) +c*********************************************************************** +c mdu -- update degrees of uneliminated vertices in ek +c*********************************************************************** + integer ek, dmin, v(*), l(*), head(*), last(*), next(*), + * mark(*), tag, vi,evi,dvi, s,vs,es, b,vb, ilp,ilpmax, + * blp,blpmax + equivalence (vs, es) +c +c----initialize tag + tag = mark(ek) - last(ek) +c +c----for each vertex vi in ek + i = ek + ilpmax = last(ek) + if (ilpmax.le.0) go to 11 + do 10 ilp=1,ilpmax + i = l(i) + vi = v(i) + if (last(vi)) 1, 10, 8 +c +c------if vi neither prototype nor duplicate vertex, then merge elements +c------to compute degree + 1 tag = tag + 1 + dvi = last(ek) +c +c--------for each vertex/element vs/es in element list of vi + s = l(vi) + 2 s = l(s) + if (s.eq.0) go to 9 + vs = v(s) + if (next(vs).lt.0) go to 3 +c +c----------if vs is uneliminated vertex, then tag and adjust degree + mark(vs) = tag + dvi = dvi + 1 + go to 5 +c +c----------if es is active element, then expand +c------------check for outmatched vertex + 3 if (mark(es).lt.0) go to 6 +c +c------------for each vertex vb in es + b = es + blpmax = last(es) + do 4 blp=1,blpmax + b = l(b) + vb = v(b) +c +c--------------if vb is untagged, then tag and adjust degree + if (mark(vb).ge.tag) go to 4 + mark(vb) = tag + dvi = dvi + 1 + 4 continue +c + 5 go to 2 +c +c------else if vi is outmatched vertex, then adjust overlaps but do not +c------compute degree + 6 last(vi) = 0 + mark(es) = mark(es) - 1 + 7 s = l(s) + if (s.eq.0) go to 10 + es = v(s) + if (mark(es).lt.0) mark(es) = mark(es) - 1 + go to 7 +c +c------else if vi is prototype vertex, then calculate degree by +c------inclusion/exclusion and reset overlap count + 8 evi = last(vi) + dvi = last(ek) + last(evi) + mark(evi) + mark(evi) = 0 +c +c------insert vi in appropriate degree list + 9 next(vi) = head(dvi) + head(dvi) = vi + last(vi) = -dvi + if (next(vi).gt.0) last(next(vi)) = vi + if (dvi.lt.dmin) dmin = dvi +c + 10 continue +c + 11 return + end + subroutine sro + * (n, ip, ia,ja,a, q, r, dflag) +c*********************************************************************** +c sro -- symmetric reordering of sparse symmetric matrix +c*********************************************************************** +c +c description +c +c the nonzero entries of the matrix m are assumed to be stored +c symmetrically in (ia,ja,a) format (i.e., not both m(i,j) and m(j,i) +c are stored if i ne j). +c +c sro does not rearrange the order of the rows, but does move +c nonzeroes from one row to another to ensure that if m(i,j) will be +c in the upper triangle of m with respect to the new ordering, then +c m(i,j) is stored in row i (and thus m(j,i) is not stored), whereas +c if m(i,j) will be in the strict lower triangle of m, then m(j,i) is +c stored in row j (and thus m(i,j) is not stored). +c +c +c additional parameters +c +c q - integer one-dimensional work array. dimension = n +c +c r - integer one-dimensional work array. dimension = number of +c nonzero entries in the upper triangle of m +c +c dflag - logical variable. if dflag = .true., then store nonzero +c diagonal elements at the beginning of the row +c +c----------------------------------------------------------------------- +c + integer ip(*), ia(*), ja(*), q(*), r(*) +c... real a(*), ak + double precision a(*), ak + logical dflag +c +c +c--phase 1 -- find row in which to store each nonzero +c----initialize count of nonzeroes to be stored in each row + do 1 i=1,n + 1 q(i) = 0 +c +c----for each nonzero element a(j) + do 3 i=1,n + jmin = ia(i) + jmax = ia(i+1) - 1 + if (jmin.gt.jmax) go to 3 + do 2 j=jmin,jmax +c +c--------find row (=r(j)) and column (=ja(j)) in which to store a(j) ... + k = ja(j) + if (ip(k).lt.ip(i)) ja(j) = i + if (ip(k).ge.ip(i)) k = i + r(j) = k +c +c--------... and increment count of nonzeroes (=q(r(j)) in that row + 2 q(k) = q(k) + 1 + 3 continue +c +c +c--phase 2 -- find new ia and permutation to apply to (ja,a) +c----determine pointers to delimit rows in permuted (ja,a) + do 4 i=1,n + ia(i+1) = ia(i) + q(i) + 4 q(i) = ia(i+1) +c +c----determine where each (ja(j),a(j)) is stored in permuted (ja,a) +c----for each nonzero element (in reverse order) + ilast = 0 + jmin = ia(1) + jmax = ia(n+1) - 1 + j = jmax + do 6 jdummy=jmin,jmax + i = r(j) + if (.not.dflag .or. ja(j).ne.i .or. i.eq.ilast) go to 5 +c +c------if dflag, then put diagonal nonzero at beginning of row + r(j) = ia(i) + ilast = i + go to 6 +c +c------put (off-diagonal) nonzero in last unused location in row + 5 q(i) = q(i) - 1 + r(j) = q(i) +c + 6 j = j-1 +c +c +c--phase 3 -- permute (ja,a) to upper triangular form (wrt new ordering) + do 8 j=jmin,jmax + 7 if (r(j).eq.j) go to 8 + k = r(j) + r(j) = r(k) + r(k) = k + jak = ja(k) + ja(k) = ja(j) + ja(j) = jak + ak = a(k) + a(k) = a(j) + a(j) = ak + go to 7 + 8 continue +c + return + end +*DECK CDRV + subroutine cdrv + * (n, r,c,ic, ia,ja,a, b, z, nsp,isp,rsp,esp, path, flag) +c*** subroutine cdrv +c*** driver for subroutines for solving sparse nonsymmetric systems of +c linear equations (compressed pointer storage) +c +c +c parameters +c class abbreviations are-- +c n - integer variable +c f - real variable +c v - supplies a value to the driver +c r - returns a result from the driver +c i - used internally by the driver +c a - array +c +c class - parameter +c ------+---------- +c - +c the nonzero entries of the coefficient matrix m are stored +c row-by-row in the array a. to identify the individual nonzero +c entries in each row, we need to know in which column each entry +c lies. the column indices which correspond to the nonzero entries +c of m are stored in the array ja. i.e., if a(k) = m(i,j), then +c ja(k) = j. in addition, we need to know where each row starts and +c how long it is. the index positions in ja and a where the rows of +c m begin are stored in the array ia. i.e., if m(i,j) is the first +c nonzero entry (stored) in the i-th row and a(k) = m(i,j), then +c ia(i) = k. moreover, the index in ja and a of the first location +c following the last element in the last row is stored in ia(n+1). +c thus, the number of entries in the i-th row is given by +c ia(i+1) - ia(i), the nonzero entries of the i-th row are stored +c consecutively in +c a(ia(i)), a(ia(i)+1), ..., a(ia(i+1)-1), +c and the corresponding column indices are stored consecutively in +c ja(ia(i)), ja(ia(i)+1), ..., ja(ia(i+1)-1). +c for example, the 5 by 5 matrix +c ( 1. 0. 2. 0. 0.) +c ( 0. 3. 0. 0. 0.) +c m = ( 0. 4. 5. 6. 0.) +c ( 0. 0. 0. 7. 0.) +c ( 0. 0. 0. 8. 9.) +c would be stored as +c - 1 2 3 4 5 6 7 8 9 +c ---+-------------------------- +c ia - 1 3 4 7 8 10 +c ja - 1 3 2 2 3 4 4 4 5 +c a - 1. 2. 3. 4. 5. 6. 7. 8. 9. . +c +c nv - n - number of variables/equations. +c fva - a - nonzero entries of the coefficient matrix m, stored +c - by rows. +c - size = number of nonzero entries in m. +c nva - ia - pointers to delimit the rows in a. +c - size = n+1. +c nva - ja - column numbers corresponding to the elements of a. +c - size = size of a. +c fva - b - right-hand side b. b and z can the same array. +c - size = n. +c fra - z - solution x. b and z can be the same array. +c - size = n. +c +c the rows and columns of the original matrix m can be +c reordered (e.g., to reduce fillin or ensure numerical stability) +c before calling the driver. if no reordering is done, then set +c r(i) = c(i) = ic(i) = i for i=1,...,n. the solution z is returned +c in the original order. +c if the columns have been reordered (i.e., c(i).ne.i for some +c i), then the driver will call a subroutine (nroc) which rearranges +c each row of ja and a, leaving the rows in the original order, but +c placing the elements of each row in increasing order with respect +c to the new ordering. if path.ne.1, then nroc is assumed to have +c been called already. +c +c nva - r - ordering of the rows of m. +c - size = n. +c nva - c - ordering of the columns of m. +c - size = n. +c nva - ic - inverse of the ordering of the columns of m. i.e., +c - ic(c(i)) = i for i=1,...,n. +c - size = n. +c +c the solution of the system of linear equations is divided into +c three stages -- +c nsfc -- the matrix m is processed symbolically to determine where +c fillin will occur during the numeric factorization. +c nnfc -- the matrix m is factored numerically into the product ldu +c of a unit lower triangular matrix l, a diagonal matrix +c d, and a unit upper triangular matrix u, and the system +c mx = b is solved. +c nnsc -- the linear system mx = b is solved using the ldu +c or factorization from nnfc. +c nntc -- the transposed linear system mt x = b is solved using +c the ldu factorization from nnf. +c for several systems whose coefficient matrices have the same +c nonzero structure, nsfc need be done only once (for the first +c system). then nnfc is done once for each additional system. for +c several systems with the same coefficient matrix, nsfc and nnfc +c need be done only once (for the first system). then nnsc or nntc +c is done once for each additional right-hand side. +c +c nv - path - path specification. values and their meanings are -- +c - 1 perform nroc, nsfc, and nnfc. +c - 2 perform nnfc only (nsfc is assumed to have been +c - done in a manner compatible with the storage +c - allocation used in the driver). +c - 3 perform nnsc only (nsfc and nnfc are assumed to +c - have been done in a manner compatible with the +c - storage allocation used in the driver). +c - 4 perform nntc only (nsfc and nnfc are assumed to +c - have been done in a manner compatible with the +c - storage allocation used in the driver). +c - 5 perform nroc and nsfc. +c +c various errors are detected by the driver and the individual +c subroutines. +c +c nr - flag - error flag. values and their meanings are -- +c - 0 no errors detected +c - n+k null row in a -- row = k +c - 2n+k duplicate entry in a -- row = k +c - 3n+k insufficient storage in nsfc -- row = k +c - 4n+1 insufficient storage in nnfc +c - 5n+k null pivot -- row = k +c - 6n+k insufficient storage in nsfc -- row = k +c - 7n+1 insufficient storage in nnfc +c - 8n+k zero pivot -- row = k +c - 10n+1 insufficient storage in cdrv +c - 11n+1 illegal path specification +c +c working storage is needed for the factored form of the matrix +c m plus various temporary vectors. the arrays isp and rsp should be +c equivalenced. integer storage is allocated from the beginning of +c isp and real storage from the end of rsp. +c +c nv - nsp - declared dimension of rsp. nsp generally must +c - be larger than 8n+2 + 2k (where k = (number of +c - nonzero entries in m)). +c nvira - isp - integer working storage divided up into various arrays +c - needed by the subroutines. isp and rsp should be +c - equivalenced. +c - size = lratio*nsp. +c fvira - rsp - real working storage divided up into various arrays +c - needed by the subroutines. isp and rsp should be +c - equivalenced. +c - size = nsp. +c nr - esp - if sufficient storage was available to perform the +c - symbolic factorization (nsfc), then esp is set to +c - the amount of excess storage provided (negative if +c - insufficient storage was available to perform the +c - numeric factorization (nnfc)). +c +c +c conversion to double precision +c +c to convert these routines for double precision arrays.. +c (1) use the double precision declarations in place of the real +c declarations in each subprogram, as given in comment cards. +c (2) change the data-loaded value of the integer lratio +c in subroutine cdrv, as indicated below. +c (3) change e0 to d0 in the constants in statement number 10 +c in subroutine nnfc and the line following that. +c + integer r(*), c(*), ic(*), ia(*), ja(*), isp(*), esp, path, + * flag, d, u, q, row, tmp, ar, umax +c real a(*), b(*), z(*), rsp(*) + double precision a(*), b(*), z(*), rsp(*) +c +c set lratio equal to the ratio between the length of floating point +c and integer array data. e. g., lratio = 1 for (real, integer), +c lratio = 2 for (double precision, integer) +c + data lratio/2/ +c + if (path.lt.1 .or. 5.lt.path) go to 111 +c******initialize and divide up temporary storage ******************* + il = 1 + ijl = il + (n+1) + iu = ijl + n + iju = iu + (n+1) + irl = iju + n + jrl = irl + n + jl = jrl + n +c +c ****** reorder a if necessary, call nsfc if flag is set *********** + if ((path-1) * (path-5) .ne. 0) go to 5 + max = (lratio*nsp + 1 - jl) - (n+1) - 5*n + jlmax = max/2 + q = jl + jlmax + ira = q + (n+1) + jra = ira + n + irac = jra + n + iru = irac + n + jru = iru + n + jutmp = jru + n + jumax = lratio*nsp + 1 - jutmp + esp = max/lratio + if (jlmax.le.0 .or. jumax.le.0) go to 110 +c + do 1 i=1,n + if (c(i).ne.i) go to 2 + 1 continue + go to 3 + 2 ar = nsp + 1 - n + call nroc + * (n, ic, ia,ja,a, isp(il), rsp(ar), isp(iu), flag) + if (flag.ne.0) go to 100 +c + 3 call nsfc + * (n, r, ic, ia,ja, + * jlmax, isp(il), isp(jl), isp(ijl), + * jumax, isp(iu), isp(jutmp), isp(iju), + * isp(q), isp(ira), isp(jra), isp(irac), + * isp(irl), isp(jrl), isp(iru), isp(jru), flag) + if(flag .ne. 0) go to 100 +c ****** move ju next to jl ***************************************** + jlmax = isp(ijl+n-1) + ju = jl + jlmax + jumax = isp(iju+n-1) + if (jumax.le.0) go to 5 + do 4 j=1,jumax + 4 isp(ju+j-1) = isp(jutmp+j-1) +c +c ****** call remaining subroutines ********************************* + 5 jlmax = isp(ijl+n-1) + ju = jl + jlmax + jumax = isp(iju+n-1) + l = (ju + jumax - 2 + lratio) / lratio + 1 + lmax = isp(il+n) - 1 + d = l + lmax + u = d + n + row = nsp + 1 - n + tmp = row - n + umax = tmp - u + esp = umax - (isp(iu+n) - 1) +c + if ((path-1) * (path-2) .ne. 0) go to 6 + if (umax.lt.0) go to 110 + call nnfc + * (n, r, c, ic, ia, ja, a, z, b, + * lmax, isp(il), isp(jl), isp(ijl), rsp(l), rsp(d), + * umax, isp(iu), isp(ju), isp(iju), rsp(u), + * rsp(row), rsp(tmp), isp(irl), isp(jrl), flag) + if(flag .ne. 0) go to 100 +c + 6 if ((path-3) .ne. 0) go to 7 + call nnsc + * (n, r, c, isp(il), isp(jl), isp(ijl), rsp(l), + * rsp(d), isp(iu), isp(ju), isp(iju), rsp(u), + * z, b, rsp(tmp)) +c + 7 if ((path-4) .ne. 0) go to 8 + call nntc + * (n, r, c, isp(il), isp(jl), isp(ijl), rsp(l), + * rsp(d), isp(iu), isp(ju), isp(iju), rsp(u), + * z, b, rsp(tmp)) + 8 return +c +c ** error.. error detected in nroc, nsfc, nnfc, or nnsc + 100 return +c ** error.. insufficient storage + 110 flag = 10*n + 1 + return +c ** error.. illegal path specification + 111 flag = 11*n + 1 + return + end + subroutine nroc (n, ic, ia, ja, a, jar, ar, p, flag) +c +c ---------------------------------------------------------------- +c +c yale sparse matrix package - nonsymmetric codes +c solving the system of equations mx = b +c +c i. calling sequences +c the coefficient matrix can be processed by an ordering routine +c (e.g., to reduce fillin or ensure numerical stability) before using +c the remaining subroutines. if no reordering is done, then set +c r(i) = c(i) = ic(i) = i for i=1,...,n. if an ordering subroutine +c is used, then nroc should be used to reorder the coefficient matrix +c the calling sequence is -- +c ( (matrix ordering)) +c (nroc (matrix reordering)) +c nsfc (symbolic factorization to determine where fillin will +c occur during numeric factorization) +c nnfc (numeric factorization into product ldu of unit lower +c triangular matrix l, diagonal matrix d, and unit +c upper triangular matrix u, and solution of linear +c system) +c nnsc (solution of linear system for additional right-hand +c side using ldu factorization from nnfc) +c (if only one system of equations is to be solved, then the +c subroutine trk should be used.) +c +c ii. storage of sparse matrices +c the nonzero entries of the coefficient matrix m are stored +c row-by-row in the array a. to identify the individual nonzero +c entries in each row, we need to know in which column each entry +c lies. the column indices which correspond to the nonzero entries +c of m are stored in the array ja. i.e., if a(k) = m(i,j), then +c ja(k) = j. in addition, we need to know where each row starts and +c how long it is. the index positions in ja and a where the rows of +c m begin are stored in the array ia. i.e., if m(i,j) is the first +c (leftmost) entry in the i-th row and a(k) = m(i,j), then +c ia(i) = k. moreover, the index in ja and a of the first location +c following the last element in the last row is stored in ia(n+1). +c thus, the number of entries in the i-th row is given by +c ia(i+1) - ia(i), the nonzero entries of the i-th row are stored +c consecutively in +c a(ia(i)), a(ia(i)+1), ..., a(ia(i+1)-1), +c and the corresponding column indices are stored consecutively in +c ja(ia(i)), ja(ia(i)+1), ..., ja(ia(i+1)-1). +c for example, the 5 by 5 matrix +c ( 1. 0. 2. 0. 0.) +c ( 0. 3. 0. 0. 0.) +c m = ( 0. 4. 5. 6. 0.) +c ( 0. 0. 0. 7. 0.) +c ( 0. 0. 0. 8. 9.) +c would be stored as +c - 1 2 3 4 5 6 7 8 9 +c ---+-------------------------- +c ia - 1 3 4 7 8 10 +c ja - 1 3 2 2 3 4 4 4 5 +c a - 1. 2. 3. 4. 5. 6. 7. 8. 9. . +c +c the strict upper (lower) triangular portion of the matrix +c u (l) is stored in a similar fashion using the arrays iu, ju, u +c (il, jl, l) except that an additional array iju (ijl) is used to +c compress storage of ju (jl) by allowing some sequences of column +c (row) indices to used for more than one row (column) (n.b., l is +c stored by columns). iju(k) (ijl(k)) points to the starting +c location in ju (jl) of entries for the kth row (column). +c compression in ju (jl) occurs in two ways. first, if a row +c (column) i was merged into the current row (column) k, and the +c number of elements merged in from (the tail portion of) row +c (column) i is the same as the final length of row (column) k, then +c the kth row (column) and the tail of row (column) i are identical +c and iju(k) (ijl(k)) points to the start of the tail. second, if +c some tail portion of the (k-1)st row (column) is identical to the +c head of the kth row (column), then iju(k) (ijl(k)) points to the +c start of that tail portion. for example, the nonzero structure of +c the strict upper triangular part of the matrix +c d 0 x x x +c 0 d 0 x x +c 0 0 d x 0 +c 0 0 0 d x +c 0 0 0 0 d +c would be represented as +c - 1 2 3 4 5 6 +c ----+------------ +c iu - 1 4 6 7 8 8 +c ju - 3 4 5 4 +c iju - 1 2 4 3 . +c the diagonal entries of l and u are assumed to be equal to one and +c are not stored. the array d contains the reciprocals of the +c diagonal entries of the matrix d. +c +c iii. additional storage savings +c in nsfc, r and ic can be the same array in the calling +c sequence if no reordering of the coefficient matrix has been done. +c in nnfc, r, c, and ic can all be the same array if no +c reordering has been done. if only the rows have been reordered, +c then c and ic can be the same array. if the row and column +c orderings are the same, then r and c can be the same array. z and +c row can be the same array. +c in nnsc or nntc, r and c can be the same array if no +c reordering has been done or if the row and column orderings are the +c same. z and b can be the same array. however, then b will be +c destroyed. +c +c iv. parameters +c following is a list of parameters to the programs. names are +c uniform among the various subroutines. class abbreviations are -- +c n - integer variable +c f - real variable +c v - supplies a value to a subroutine +c r - returns a result from a subroutine +c i - used internally by a subroutine +c a - array +c +c class - parameter +c ------+---------- +c fva - a - nonzero entries of the coefficient matrix m, stored +c - by rows. +c - size = number of nonzero entries in m. +c fva - b - right-hand side b. +c - size = n. +c nva - c - ordering of the columns of m. +c - size = n. +c fvra - d - reciprocals of the diagonal entries of the matrix d. +c - size = n. +c nr - flag - error flag. values and their meanings are -- +c - 0 no errors detected +c - n+k null row in a -- row = k +c - 2n+k duplicate entry in a -- row = k +c - 3n+k insufficient storage for jl -- row = k +c - 4n+1 insufficient storage for l +c - 5n+k null pivot -- row = k +c - 6n+k insufficient storage for ju -- row = k +c - 7n+1 insufficient storage for u +c - 8n+k zero pivot -- row = k +c nva - ia - pointers to delimit the rows of a. +c - size = n+1. +c nvra - ijl - pointers to the first element in each column in jl, +c - used to compress storage in jl. +c - size = n. +c nvra - iju - pointers to the first element in each row in ju, used +c - to compress storage in ju. +c - size = n. +c nvra - il - pointers to delimit the columns of l. +c - size = n+1. +c nvra - iu - pointers to delimit the rows of u. +c - size = n+1. +c nva - ja - column numbers corresponding to the elements of a. +c - size = size of a. +c nvra - jl - row numbers corresponding to the elements of l. +c - size = jlmax. +c nv - jlmax - declared dimension of jl. jlmax must be larger than +c - the number of nonzeros in the strict lower triangle +c - of m plus fillin minus compression. +c nvra - ju - column numbers corresponding to the elements of u. +c - size = jumax. +c nv - jumax - declared dimension of ju. jumax must be larger than +c - the number of nonzeros in the strict upper triangle +c - of m plus fillin minus compression. +c fvra - l - nonzero entries in the strict lower triangular portion +c - of the matrix l, stored by columns. +c - size = lmax. +c nv - lmax - declared dimension of l. lmax must be larger than +c - the number of nonzeros in the strict lower triangle +c - of m plus fillin (il(n+1)-1 after nsfc). +c nv - n - number of variables/equations. +c nva - r - ordering of the rows of m. +c - size = n. +c fvra - u - nonzero entries in the strict upper triangular portion +c - of the matrix u, stored by rows. +c - size = umax. +c nv - umax - declared dimension of u. umax must be larger than +c - the number of nonzeros in the strict upper triangle +c - of m plus fillin (iu(n+1)-1 after nsfc). +c fra - z - solution x. +c - size = n. +c +c ---------------------------------------------------------------- +c +c*** subroutine nroc +c*** reorders rows of a, leaving row order unchanged +c +c +c input parameters.. n, ic, ia, ja, a +c output parameters.. ja, a, flag +c +c parameters used internally.. +c nia - p - at the kth step, p is a linked list of the reordered +c - column indices of the kth row of a. p(n+1) points +c - to the first entry in the list. +c - size = n+1. +c nia - jar - at the kth step,jar contains the elements of the +c - reordered column indices of a. +c - size = n. +c fia - ar - at the kth step, ar contains the elements of the +c - reordered row of a. +c - size = n. +c + integer ic(*), ia(*), ja(*), jar(*), p(*), flag +c real a(*), ar(*) + double precision a(*), ar(*) +c +c ****** for each nonempty row ******************************* + do 5 k=1,n + jmin = ia(k) + jmax = ia(k+1) - 1 + if(jmin .gt. jmax) go to 5 + p(n+1) = n + 1 +c ****** insert each element in the list ********************* + do 3 j=jmin,jmax + newj = ic(ja(j)) + i = n + 1 + 1 if(p(i) .ge. newj) go to 2 + i = p(i) + go to 1 + 2 if(p(i) .eq. newj) go to 102 + p(newj) = p(i) + p(i) = newj + jar(newj) = ja(j) + ar(newj) = a(j) + 3 continue +c ****** replace old row in ja and a ************************* + i = n + 1 + do 4 j=jmin,jmax + i = p(i) + ja(j) = jar(i) + 4 a(j) = ar(i) + 5 continue + flag = 0 + return +c +c ** error.. duplicate entry in a + 102 flag = n + k + return + end + subroutine nsfc + * (n, r, ic, ia,ja, jlmax,il,jl,ijl, jumax,iu,ju,iju, + * q, ira,jra, irac, irl,jrl, iru,jru, flag) +c*** subroutine nsfc +c*** symbolic ldu-factorization of nonsymmetric sparse matrix +c (compressed pointer storage) +c +c +c input variables.. n, r, ic, ia, ja, jlmax, jumax. +c output variables.. il, jl, ijl, iu, ju, iju, flag. +c +c parameters used internally.. +c nia - q - suppose m* is the result of reordering m. if +c - processing of the ith row of m* (hence the ith +c - row of u) is being done, q(j) is initially +c - nonzero if m*(i,j) is nonzero (j.ge.i). since +c - values need not be stored, each entry points to the +c - next nonzero and q(n+1) points to the first. n+1 +c - indicates the end of the list. for example, if n=9 +c - and the 5th row of m* is +c - 0 x x 0 x 0 0 x 0 +c - then q will initially be +c - a a a a 8 a a 10 5 (a - arbitrary). +c - as the algorithm proceeds, other elements of q +c - are inserted in the list because of fillin. +c - q is used in an analogous manner to compute the +c - ith column of l. +c - size = n+1. +c nia - ira, - vectors used to find the columns of m. at the kth +c nia - jra, step of the factorization, irac(k) points to the +c nia - irac head of a linked list in jra of row indices i +c - such that i .ge. k and m(i,k) is nonzero. zero +c - indicates the end of the list. ira(i) (i.ge.k) +c - points to the smallest j such that j .ge. k and +c - m(i,j) is nonzero. +c - size of each = n. +c nia - irl, - vectors used to find the rows of l. at the kth step +c nia - jrl of the factorization, jrl(k) points to the head +c - of a linked list in jrl of column indices j +c - such j .lt. k and l(k,j) is nonzero. zero +c - indicates the end of the list. irl(j) (j.lt.k) +c - points to the smallest i such that i .ge. k and +c - l(i,j) is nonzero. +c - size of each = n. +c nia - iru, - vectors used in a manner analogous to irl and jrl +c nia - jru to find the columns of u. +c - size of each = n. +c +c internal variables.. +c jlptr - points to the last position used in jl. +c juptr - points to the last position used in ju. +c jmin,jmax - are the indices in a or u of the first and last +c elements to be examined in a given row. +c for example, jmin=ia(k), jmax=ia(k+1)-1. +c + integer cend, qm, rend, rk, vj + integer ia(*), ja(*), ira(*), jra(*), il(*), jl(*), ijl(*) + integer iu(*), ju(*), iju(*), irl(*), jrl(*), iru(*), jru(*) + integer r(*), ic(*), q(*), irac(*), flag +c +c ****** initialize pointers **************************************** + np1 = n + 1 + jlmin = 1 + jlptr = 0 + il(1) = 1 + jumin = 1 + juptr = 0 + iu(1) = 1 + do 1 k=1,n + irac(k) = 0 + jra(k) = 0 + jrl(k) = 0 + 1 jru(k) = 0 +c ****** initialize column pointers for a *************************** + do 2 k=1,n + rk = r(k) + iak = ia(rk) + if (iak .ge. ia(rk+1)) go to 101 + jaiak = ic(ja(iak)) + if (jaiak .gt. k) go to 105 + jra(k) = irac(jaiak) + irac(jaiak) = k + 2 ira(k) = iak +c +c ****** for each column of l and row of u ************************** + do 41 k=1,n +c +c ****** initialize q for computing kth column of l ***************** + q(np1) = np1 + luk = -1 +c ****** by filling in kth column of a ****************************** + vj = irac(k) + if (vj .eq. 0) go to 5 + 3 qm = np1 + 4 m = qm + qm = q(m) + if (qm .lt. vj) go to 4 + if (qm .eq. vj) go to 102 + luk = luk + 1 + q(m) = vj + q(vj) = qm + vj = jra(vj) + if (vj .ne. 0) go to 3 +c ****** link through jru ******************************************* + 5 lastid = 0 + lasti = 0 + ijl(k) = jlptr + i = k + 6 i = jru(i) + if (i .eq. 0) go to 10 + qm = np1 + jmin = irl(i) + jmax = ijl(i) + il(i+1) - il(i) - 1 + long = jmax - jmin + if (long .lt. 0) go to 6 + jtmp = jl(jmin) + if (jtmp .ne. k) long = long + 1 + if (jtmp .eq. k) r(i) = -r(i) + if (lastid .ge. long) go to 7 + lasti = i + lastid = long +c ****** and merge the corresponding columns into the kth column **** + 7 do 9 j=jmin,jmax + vj = jl(j) + 8 m = qm + qm = q(m) + if (qm .lt. vj) go to 8 + if (qm .eq. vj) go to 9 + luk = luk + 1 + q(m) = vj + q(vj) = qm + qm = vj + 9 continue + go to 6 +c ****** lasti is the longest column merged into the kth ************ +c ****** see if it equals the entire kth column ********************* + 10 qm = q(np1) + if (qm .ne. k) go to 105 + if (luk .eq. 0) go to 17 + if (lastid .ne. luk) go to 11 +c ****** if so, jl can be compressed ******************************** + irll = irl(lasti) + ijl(k) = irll + 1 + if (jl(irll) .ne. k) ijl(k) = ijl(k) - 1 + go to 17 +c ****** if not, see if kth column can overlap the previous one ***** + 11 if (jlmin .gt. jlptr) go to 15 + qm = q(qm) + do 12 j=jlmin,jlptr + if (jl(j) - qm) 12, 13, 15 + 12 continue + go to 15 + 13 ijl(k) = j + do 14 i=j,jlptr + if (jl(i) .ne. qm) go to 15 + qm = q(qm) + if (qm .gt. n) go to 17 + 14 continue + jlptr = j - 1 +c ****** move column indices from q to jl, update vectors *********** + 15 jlmin = jlptr + 1 + ijl(k) = jlmin + if (luk .eq. 0) go to 17 + jlptr = jlptr + luk + if (jlptr .gt. jlmax) go to 103 + qm = q(np1) + do 16 j=jlmin,jlptr + qm = q(qm) + 16 jl(j) = qm + 17 irl(k) = ijl(k) + il(k+1) = il(k) + luk +c +c ****** initialize q for computing kth row of u ******************** + q(np1) = np1 + luk = -1 +c ****** by filling in kth row of reordered a *********************** + rk = r(k) + jmin = ira(k) + jmax = ia(rk+1) - 1 + if (jmin .gt. jmax) go to 20 + do 19 j=jmin,jmax + vj = ic(ja(j)) + qm = np1 + 18 m = qm + qm = q(m) + if (qm .lt. vj) go to 18 + if (qm .eq. vj) go to 102 + luk = luk + 1 + q(m) = vj + q(vj) = qm + 19 continue +c ****** link through jrl, ****************************************** + 20 lastid = 0 + lasti = 0 + iju(k) = juptr + i = k + i1 = jrl(k) + 21 i = i1 + if (i .eq. 0) go to 26 + i1 = jrl(i) + qm = np1 + jmin = iru(i) + jmax = iju(i) + iu(i+1) - iu(i) - 1 + long = jmax - jmin + if (long .lt. 0) go to 21 + jtmp = ju(jmin) + if (jtmp .eq. k) go to 22 +c ****** update irl and jrl, ***************************************** + long = long + 1 + cend = ijl(i) + il(i+1) - il(i) + irl(i) = irl(i) + 1 + if (irl(i) .ge. cend) go to 22 + j = jl(irl(i)) + jrl(i) = jrl(j) + jrl(j) = i + 22 if (lastid .ge. long) go to 23 + lasti = i + lastid = long +c ****** and merge the corresponding rows into the kth row ********** + 23 do 25 j=jmin,jmax + vj = ju(j) + 24 m = qm + qm = q(m) + if (qm .lt. vj) go to 24 + if (qm .eq. vj) go to 25 + luk = luk + 1 + q(m) = vj + q(vj) = qm + qm = vj + 25 continue + go to 21 +c ****** update jrl(k) and irl(k) *********************************** + 26 if (il(k+1) .le. il(k)) go to 27 + j = jl(irl(k)) + jrl(k) = jrl(j) + jrl(j) = k +c ****** lasti is the longest row merged into the kth *************** +c ****** see if it equals the entire kth row ************************ + 27 qm = q(np1) + if (qm .ne. k) go to 105 + if (luk .eq. 0) go to 34 + if (lastid .ne. luk) go to 28 +c ****** if so, ju can be compressed ******************************** + irul = iru(lasti) + iju(k) = irul + 1 + if (ju(irul) .ne. k) iju(k) = iju(k) - 1 + go to 34 +c ****** if not, see if kth row can overlap the previous one ******** + 28 if (jumin .gt. juptr) go to 32 + qm = q(qm) + do 29 j=jumin,juptr + if (ju(j) - qm) 29, 30, 32 + 29 continue + go to 32 + 30 iju(k) = j + do 31 i=j,juptr + if (ju(i) .ne. qm) go to 32 + qm = q(qm) + if (qm .gt. n) go to 34 + 31 continue + juptr = j - 1 +c ****** move row indices from q to ju, update vectors ************** + 32 jumin = juptr + 1 + iju(k) = jumin + if (luk .eq. 0) go to 34 + juptr = juptr + luk + if (juptr .gt. jumax) go to 106 + qm = q(np1) + do 33 j=jumin,juptr + qm = q(qm) + 33 ju(j) = qm + 34 iru(k) = iju(k) + iu(k+1) = iu(k) + luk +c +c ****** update iru, jru ******************************************** + i = k + 35 i1 = jru(i) + if (r(i) .lt. 0) go to 36 + rend = iju(i) + iu(i+1) - iu(i) + if (iru(i) .ge. rend) go to 37 + j = ju(iru(i)) + jru(i) = jru(j) + jru(j) = i + go to 37 + 36 r(i) = -r(i) + 37 i = i1 + if (i .eq. 0) go to 38 + iru(i) = iru(i) + 1 + go to 35 +c +c ****** update ira, jra, irac ************************************** + 38 i = irac(k) + if (i .eq. 0) go to 41 + 39 i1 = jra(i) + ira(i) = ira(i) + 1 + if (ira(i) .ge. ia(r(i)+1)) go to 40 + irai = ira(i) + jairai = ic(ja(irai)) + if (jairai .gt. i) go to 40 + jra(i) = irac(jairai) + irac(jairai) = i + 40 i = i1 + if (i .ne. 0) go to 39 + 41 continue +c + ijl(n) = jlptr + iju(n) = juptr + flag = 0 + return +c +c ** error.. null row in a + 101 flag = n + rk + return +c ** error.. duplicate entry in a + 102 flag = 2*n + rk + return +c ** error.. insufficient storage for jl + 103 flag = 3*n + k + return +c ** error.. null pivot + 105 flag = 5*n + k + return +c ** error.. insufficient storage for ju + 106 flag = 6*n + k + return + end + subroutine nnfc + * (n, r,c,ic, ia,ja,a, z, b, + * lmax,il,jl,ijl,l, d, umax,iu,ju,iju,u, + * row, tmp, irl,jrl, flag) +c*** subroutine nnfc +c*** numerical ldu-factorization of sparse nonsymmetric matrix and +c solution of system of linear equations (compressed pointer +c storage) +c +c +c input variables.. n, r, c, ic, ia, ja, a, b, +c il, jl, ijl, lmax, iu, ju, iju, umax +c output variables.. z, l, d, u, flag +c +c parameters used internally.. +c nia - irl, - vectors used to find the rows of l. at the kth step +c nia - jrl of the factorization, jrl(k) points to the head +c - of a linked list in jrl of column indices j +c - such j .lt. k and l(k,j) is nonzero. zero +c - indicates the end of the list. irl(j) (j.lt.k) +c - points to the smallest i such that i .ge. k and +c - l(i,j) is nonzero. +c - size of each = n. +c fia - row - holds intermediate values in calculation of u and l. +c - size = n. +c fia - tmp - holds new right-hand side b* for solution of the +c - equation ux = b*. +c - size = n. +c +c internal variables.. +c jmin, jmax - indices of the first and last positions in a row to +c be examined. +c sum - used in calculating tmp. +c + integer rk,umax + integer r(*), c(*), ic(*), ia(*), ja(*), il(*), jl(*), ijl(*) + integer iu(*), ju(*), iju(*), irl(*), jrl(*), flag +c real a(*), l(*), d(*), u(*), z(*), b(*), row(*) +c real tmp(*), lki, sum, dk + double precision a(*), l(*), d(*), u(*), z(*), b(*), row(*) + double precision tmp(*), lki, sum, dk +c +c ****** initialize pointers and test storage *********************** + if(il(n+1)-1 .gt. lmax) go to 104 + if(iu(n+1)-1 .gt. umax) go to 107 + do 1 k=1,n + irl(k) = il(k) + jrl(k) = 0 + 1 continue +c +c ****** for each row *********************************************** + do 19 k=1,n +c ****** reverse jrl and zero row where kth row of l will fill in *** + row(k) = 0 + i1 = 0 + if (jrl(k) .eq. 0) go to 3 + i = jrl(k) + 2 i2 = jrl(i) + jrl(i) = i1 + i1 = i + row(i) = 0 + i = i2 + if (i .ne. 0) go to 2 +c ****** set row to zero where u will fill in *********************** + 3 jmin = iju(k) + jmax = jmin + iu(k+1) - iu(k) - 1 + if (jmin .gt. jmax) go to 5 + do 4 j=jmin,jmax + 4 row(ju(j)) = 0 +c ****** place kth row of a in row ********************************** + 5 rk = r(k) + jmin = ia(rk) + jmax = ia(rk+1) - 1 + do 6 j=jmin,jmax + row(ic(ja(j))) = a(j) + 6 continue +c ****** initialize sum, and link through jrl *********************** + sum = b(rk) + i = i1 + if (i .eq. 0) go to 10 +c ****** assign the kth row of l and adjust row, sum **************** + 7 lki = -row(i) +c ****** if l is not required, then comment out the following line ** + l(irl(i)) = -lki + sum = sum + lki * tmp(i) + jmin = iu(i) + jmax = iu(i+1) - 1 + if (jmin .gt. jmax) go to 9 + mu = iju(i) - jmin + do 8 j=jmin,jmax + 8 row(ju(mu+j)) = row(ju(mu+j)) + lki * u(j) + 9 i = jrl(i) + if (i .ne. 0) go to 7 +c +c ****** assign kth row of u and diagonal d, set tmp(k) ************* + 10 if (row(k) .eq. 0.0d0) go to 108 + dk = 1.0d0 / row(k) + d(k) = dk + tmp(k) = sum * dk + if (k .eq. n) go to 19 + jmin = iu(k) + jmax = iu(k+1) - 1 + if (jmin .gt. jmax) go to 12 + mu = iju(k) - jmin + do 11 j=jmin,jmax + 11 u(j) = row(ju(mu+j)) * dk + 12 continue +c +c ****** update irl and jrl, keeping jrl in decreasing order ******** + i = i1 + if (i .eq. 0) go to 18 + 14 irl(i) = irl(i) + 1 + i1 = jrl(i) + if (irl(i) .ge. il(i+1)) go to 17 + ijlb = irl(i) - il(i) + ijl(i) + j = jl(ijlb) + 15 if (i .gt. jrl(j)) go to 16 + j = jrl(j) + go to 15 + 16 jrl(i) = jrl(j) + jrl(j) = i + 17 i = i1 + if (i .ne. 0) go to 14 + 18 if (irl(k) .ge. il(k+1)) go to 19 + j = jl(ijl(k)) + jrl(k) = jrl(j) + jrl(j) = k + 19 continue +c +c ****** solve ux = tmp by back substitution ********************** + k = n + do 22 i=1,n + sum = tmp(k) + jmin = iu(k) + jmax = iu(k+1) - 1 + if (jmin .gt. jmax) go to 21 + mu = iju(k) - jmin + do 20 j=jmin,jmax + 20 sum = sum - u(j) * tmp(ju(mu+j)) + 21 tmp(k) = sum + z(c(k)) = sum + 22 k = k-1 + flag = 0 + return +c +c ** error.. insufficient storage for l + 104 flag = 4*n + 1 + return +c ** error.. insufficient storage for u + 107 flag = 7*n + 1 + return +c ** error.. zero pivot + 108 flag = 8*n + k + return + end + subroutine nnsc + * (n, r, c, il, jl, ijl, l, d, iu, ju, iju, u, z, b, tmp) +c*** subroutine nnsc +c*** numerical solution of sparse nonsymmetric system of linear +c equations given ldu-factorization (compressed pointer storage) +c +c +c input variables.. n, r, c, il, jl, ijl, l, d, iu, ju, iju, u, b +c output variables.. z +c +c parameters used internally.. +c fia - tmp - temporary vector which gets result of solving ly = b. +c - size = n. +c +c internal variables.. +c jmin, jmax - indices of the first and last positions in a row of +c u or l to be used. +c + integer r(*), c(*), il(*), jl(*), ijl(*), iu(*), ju(*), iju(*) +c real l(*), d(*), u(*), b(*), z(*), tmp(*), tmpk, sum + double precision l(*), d(*), u(*), b(*), z(*), tmp(*), tmpk,sum +c +c ****** set tmp to reordered b ************************************* + do 1 k=1,n + 1 tmp(k) = b(r(k)) +c ****** solve ly = b by forward substitution ********************* + do 3 k=1,n + jmin = il(k) + jmax = il(k+1) - 1 + tmpk = -d(k) * tmp(k) + tmp(k) = -tmpk + if (jmin .gt. jmax) go to 3 + ml = ijl(k) - jmin + do 2 j=jmin,jmax + 2 tmp(jl(ml+j)) = tmp(jl(ml+j)) + tmpk * l(j) + 3 continue +c ****** solve ux = y by back substitution ************************ + k = n + do 6 i=1,n + sum = -tmp(k) + jmin = iu(k) + jmax = iu(k+1) - 1 + if (jmin .gt. jmax) go to 5 + mu = iju(k) - jmin + do 4 j=jmin,jmax + 4 sum = sum + u(j) * tmp(ju(mu+j)) + 5 tmp(k) = -sum + z(c(k)) = -sum + k = k - 1 + 6 continue + return + end + subroutine nntc + * (n, r, c, il, jl, ijl, l, d, iu, ju, iju, u, z, b, tmp) +c*** subroutine nntc +c*** numeric solution of the transpose of a sparse nonsymmetric system +c of linear equations given lu-factorization (compressed pointer +c storage) +c +c +c input variables.. n, r, c, il, jl, ijl, l, d, iu, ju, iju, u, b +c output variables.. z +c +c parameters used internally.. +c fia - tmp - temporary vector which gets result of solving ut y = b +c - size = n. +c +c internal variables.. +c jmin, jmax - indices of the first and last positions in a row of +c u or l to be used. +c + integer r(*), c(*), il(*), jl(*), ijl(*), iu(*), ju(*), iju(*) +c real l(*), d(*), u(*), b(*), z(*), tmp(*), tmpk,sum + double precision l(*), d(*), u(*), b(*), z(*), tmp(*), tmpk,sum +c +c ****** set tmp to reordered b ************************************* + do 1 k=1,n + 1 tmp(k) = b(c(k)) +c ****** solve ut y = b by forward substitution ******************* + do 3 k=1,n + jmin = iu(k) + jmax = iu(k+1) - 1 + tmpk = -tmp(k) + if (jmin .gt. jmax) go to 3 + mu = iju(k) - jmin + do 2 j=jmin,jmax + 2 tmp(ju(mu+j)) = tmp(ju(mu+j)) + tmpk * u(j) + 3 continue +c ****** solve lt x = y by back substitution ********************** + k = n + do 6 i=1,n + sum = -tmp(k) + jmin = il(k) + jmax = il(k+1) - 1 + if (jmin .gt. jmax) go to 5 + ml = ijl(k) - jmin + do 4 j=jmin,jmax + 4 sum = sum + l(j) * tmp(jl(ml+j)) + 5 tmp(k) = -sum * d(k) + z(r(k)) = tmp(k) + k = k - 1 + 6 continue + return + end +*DECK DSTODA + SUBROUTINE DSTODA (NEQ, Y, YH, NYH, YH1, EWT, SAVF, ACOR, + 1 WM, IWM, F, JAC, PJAC, SLVS) + EXTERNAL F, JAC, PJAC, SLVS + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, YH1, EWT, SAVF, ACOR, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), YH1(*), EWT(*), SAVF(*), + 1 ACOR(*), WM(*), IWM(*) + INTEGER IOWND, IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IOWND2, ICOUNT, IRFLAG, JTYP, MUSED, MXORDN, MXORDS + DOUBLE PRECISION CONIT, CRATE, EL, ELCO, HOLD, RMAX, TESCO, + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ROWND2, CM1, CM2, PDEST, PDLAST, RATIO, + 1 PDNORM + COMMON /DLS001/ CONIT, CRATE, EL(13), ELCO(13,12), + 1 HOLD, RMAX, TESCO(3,12), + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 3 IOWND(6), IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 4 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 5 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 6 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSA01/ ROWND2, CM1(12), CM2(5), PDEST, PDLAST, RATIO, + 1 PDNORM, + 2 IOWND2(3), ICOUNT, IRFLAG, JTYP, MUSED, MXORDN, MXORDS + INTEGER I, I1, IREDO, IRET, J, JB, M, NCF, NEWQ + INTEGER LM1, LM1P1, LM2, LM2P1, NQM1, NQM2 + DOUBLE PRECISION DCON, DDN, DEL, DELP, DSM, DUP, EXDN, EXSM, EXUP, + 1 R, RH, RHDN, RHSM, RHUP, TOLD, DMNORM + DOUBLE PRECISION ALPHA, DM1,DM2, EXM1,EXM2, + 1 PDH, PNORM, RATE, RH1, RH1IT, RH2, RM, SM1(12) + SAVE SM1 + DATA SM1/0.5D0, 0.575D0, 0.55D0, 0.45D0, 0.35D0, 0.25D0, + 1 0.20D0, 0.15D0, 0.10D0, 0.075D0, 0.050D0, 0.025D0/ +C----------------------------------------------------------------------- +C DSTODA performs one step of the integration of an initial value +C problem for a system of ordinary differential equations. +C Note: DSTODA is independent of the value of the iteration method +C indicator MITER, when this is .ne. 0, and hence is independent +C of the type of chord method used, or the Jacobian structure. +C Communication with DSTODA is done with the following variables: +C +C Y = an array of length .ge. N used as the Y argument in +C all calls to F and JAC. +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls to F and JAC. +C YH = an NYH by LMAX array containing the dependent variables +C and their approximate scaled derivatives, where +C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate +C j-th derivative of y(i), scaled by H**j/factorial(j) +C (j = 0,1,...,NQ). On entry for the first step, the first +C two columns of YH must be set from the initial values. +C NYH = a constant integer .ge. N, the first dimension of YH. +C YH1 = a one-dimensional array occupying the same space as YH. +C EWT = an array of length N containing multiplicative weights +C for local error measurements. Local errors in y(i) are +C compared to 1.0/EWT(i) in various error tests. +C SAVF = an array of working storage, of length N. +C ACOR = a work array of length N, used for the accumulated +C corrections. On a successful return, ACOR(i) contains +C the estimated one-step local error in y(i). +C WM,IWM = real and integer work arrays associated with matrix +C operations in chord iteration (MITER .ne. 0). +C PJAC = name of routine to evaluate and preprocess Jacobian matrix +C and P = I - H*EL0*Jac, if a chord method is being used. +C It also returns an estimate of norm(Jac) in PDNORM. +C SLVS = name of routine to solve linear system in chord iteration. +C CCMAX = maximum relative change in H*EL0 before PJAC is called. +C H = the step size to be attempted on the next step. +C H is altered by the error control algorithm during the +C problem. H can be either positive or negative, but its +C sign must remain constant throughout the problem. +C HMIN = the minimum absolute value of the step size H to be used. +C HMXI = inverse of the maximum absolute value of H to be used. +C HMXI = 0.0 is allowed and corresponds to an infinite HMAX. +C HMIN and HMXI may be changed at any time, but will not +C take effect until the next change of H is considered. +C TN = the independent variable. TN is updated on each step taken. +C JSTART = an integer used for input only, with the following +C values and meanings: +C 0 perform the first step. +C .gt.0 take a new step continuing from the last. +C -1 take the next step with a new value of H, +C N, METH, MITER, and/or matrix parameters. +C -2 take the next step with a new value of H, +C but with other inputs unchanged. +C On return, JSTART is set to 1 to facilitate continuation. +C KFLAG = a completion code with the following meanings: +C 0 the step was succesful. +C -1 the requested error could not be achieved. +C -2 corrector convergence could not be achieved. +C -3 fatal error in PJAC or SLVS. +C A return with KFLAG = -1 or -2 means either +C ABS(H) = HMIN or 10 consecutive failures occurred. +C On a return with KFLAG negative, the values of TN and +C the YH array are as of the beginning of the last +C step, and H is the last step size attempted. +C MAXORD = the maximum order of integration method to be allowed. +C MAXCOR = the maximum number of corrector iterations allowed. +C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0). +C MXNCF = maximum number of convergence failures allowed. +C METH = current method. +C METH = 1 means Adams method (nonstiff) +C METH = 2 means BDF method (stiff) +C METH may be reset by DSTODA. +C MITER = corrector iteration method. +C MITER = 0 means functional iteration. +C MITER = JT .gt. 0 means a chord iteration corresponding +C to Jacobian type JT. (The DLSODA/DLSODAR argument JT is +C communicated here as JTYP, but is not used in DSTODA +C except to load MITER following a method switch.) +C MITER may be reset by DSTODA. +C N = the number of first-order differential equations. +C----------------------------------------------------------------------- + KFLAG = 0 + TOLD = TN + NCF = 0 + IERPJ = 0 + IERSL = 0 + JCUR = 0 + ICF = 0 + DELP = 0.0D0 + IF (JSTART .GT. 0) GO TO 200 + IF (JSTART .EQ. -1) GO TO 100 + IF (JSTART .EQ. -2) GO TO 160 +C----------------------------------------------------------------------- +C On the first call, the order is set to 1, and other variables are +C initialized. RMAX is the maximum ratio by which H can be increased +C in a single step. It is initially 1.E4 to compensate for the small +C initial H, but then is normally equal to 10. If a failure +C occurs (in corrector convergence or error test), RMAX is set at 2 +C for the next increase. +C DCFODE is called to get the needed coefficients for both methods. +C----------------------------------------------------------------------- + LMAX = MAXORD + 1 + NQ = 1 + L = 2 + IALTH = 2 + RMAX = 10000.0D0 + RC = 0.0D0 + EL0 = 1.0D0 + CRATE = 0.7D0 + HOLD = H + NSLP = 0 + IPUP = MITER + IRET = 3 +C Initialize switching parameters. METH = 1 is assumed initially. ----- + ICOUNT = 20 + IRFLAG = 0 + PDEST = 0.0D0 + PDLAST = 0.0D0 + RATIO = 5.0D0 + CALL DCFODE (2, ELCO, TESCO) + DO 10 I = 1,5 + 10 CM2(I) = TESCO(2,I)*ELCO(I+1,I) + CALL DCFODE (1, ELCO, TESCO) + DO 20 I = 1,12 + 20 CM1(I) = TESCO(2,I)*ELCO(I+1,I) + GO TO 150 +C----------------------------------------------------------------------- +C The following block handles preliminaries needed when JSTART = -1. +C IPUP is set to MITER to force a matrix update. +C If an order increase is about to be considered (IALTH = 1), +C IALTH is reset to 2 to postpone consideration one more step. +C If the caller has changed METH, DCFODE is called to reset +C the coefficients of the method. +C If H is to be changed, YH must be rescaled. +C If H or METH is being changed, IALTH is reset to L = NQ + 1 +C to prevent further changes in H for that many steps. +C----------------------------------------------------------------------- + 100 IPUP = MITER + LMAX = MAXORD + 1 + IF (IALTH .EQ. 1) IALTH = 2 + IF (METH .EQ. MUSED) GO TO 160 + CALL DCFODE (METH, ELCO, TESCO) + IALTH = L + IRET = 1 +C----------------------------------------------------------------------- +C The el vector and related constants are reset +C whenever the order NQ is changed, or at the start of the problem. +C----------------------------------------------------------------------- + 150 DO 155 I = 1,L + 155 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + GO TO (160, 170, 200), IRET +C----------------------------------------------------------------------- +C If H is being changed, the H ratio RH is checked against +C RMAX, HMIN, and HMXI, and the YH array rescaled. IALTH is set to +C L = NQ + 1 to prevent a change of H for that many steps, unless +C forced by a convergence or error test failure. +C----------------------------------------------------------------------- + 160 IF (H .EQ. HOLD) GO TO 200 + RH = H/HOLD + H = HOLD + IREDO = 3 + GO TO 175 + 170 RH = MAX(RH,HMIN/ABS(H)) + 175 RH = MIN(RH,RMAX) + RH = RH/MAX(1.0D0,ABS(H)*HMXI*RH) +C----------------------------------------------------------------------- +C If METH = 1, also restrict the new step size by the stability region. +C If this reduces H, set IRFLAG to 1 so that if there are roundoff +C problems later, we can assume that is the cause of the trouble. +C----------------------------------------------------------------------- + IF (METH .EQ. 2) GO TO 178 + IRFLAG = 0 + PDH = MAX(ABS(H)*PDLAST,0.000001D0) + IF (RH*PDH*1.00001D0 .LT. SM1(NQ)) GO TO 178 + RH = SM1(NQ)/PDH + IRFLAG = 1 + 178 CONTINUE + R = 1.0D0 + DO 180 J = 2,L + R = R*RH + DO 180 I = 1,N + 180 YH(I,J) = YH(I,J)*R + H = H*RH + RC = RC*RH + IALTH = L + IF (IREDO .EQ. 0) GO TO 690 +C----------------------------------------------------------------------- +C This section computes the predicted values by effectively +C multiplying the YH array by the Pascal triangle matrix. +C RC is the ratio of new to old values of the coefficient H*EL(1). +C When RC differs from 1 by more than CCMAX, IPUP is set to MITER +C to force PJAC to be called, if a Jacobian is involved. +C In any case, PJAC is called at least every MSBP steps. +C----------------------------------------------------------------------- + 200 IF (ABS(RC-1.0D0) .GT. CCMAX) IPUP = MITER + IF (NST .GE. NSLP+MSBP) IPUP = MITER + TN = TN + H + I1 = NQNYH + 1 + DO 215 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 210 I = I1,NQNYH + 210 YH1(I) = YH1(I) + YH1(I+NYH) + 215 CONTINUE + PNORM = DMNORM (N, YH1, EWT) +C----------------------------------------------------------------------- +C Up to MAXCOR corrector iterations are taken. A convergence test is +C made on the RMS-norm of each correction, weighted by the error +C weight vector EWT. The sum of the corrections is accumulated in the +C vector ACOR(i). The YH array is not altered in the corrector loop. +C----------------------------------------------------------------------- + 220 M = 0 + RATE = 0.0D0 + DEL = 0.0D0 + DO 230 I = 1,N + 230 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + IF (IPUP .LE. 0) GO TO 250 +C----------------------------------------------------------------------- +C If indicated, the matrix P = I - H*EL(1)*J is reevaluated and +C preprocessed before starting the corrector iteration. IPUP is set +C to 0 as an indicator that this has been done. +C----------------------------------------------------------------------- + CALL PJAC (NEQ, Y, YH, NYH, EWT, ACOR, SAVF, WM, IWM, F, JAC) + IPUP = 0 + RC = 1.0D0 + NSLP = NST + CRATE = 0.7D0 + IF (IERPJ .NE. 0) GO TO 430 + 250 DO 260 I = 1,N + 260 ACOR(I) = 0.0D0 + 270 IF (MITER .NE. 0) GO TO 350 +C----------------------------------------------------------------------- +C In the case of functional iteration, update Y directly from +C the result of the last function evaluation. +C----------------------------------------------------------------------- + DO 290 I = 1,N + SAVF(I) = H*SAVF(I) - YH(I,2) + 290 Y(I) = SAVF(I) - ACOR(I) + DEL = DMNORM (N, Y, EWT) + DO 300 I = 1,N + Y(I) = YH(I,1) + EL(1)*SAVF(I) + 300 ACOR(I) = SAVF(I) + GO TO 400 +C----------------------------------------------------------------------- +C In the case of the chord method, compute the corrector error, +C and solve the linear system with that as right-hand side and +C P as coefficient matrix. +C----------------------------------------------------------------------- + 350 DO 360 I = 1,N + 360 Y(I) = H*SAVF(I) - (YH(I,2) + ACOR(I)) + CALL SLVS (WM, IWM, Y, SAVF) + IF (IERSL .LT. 0) GO TO 430 + IF (IERSL .GT. 0) GO TO 410 + DEL = DMNORM (N, Y, EWT) + DO 380 I = 1,N + ACOR(I) = ACOR(I) + Y(I) + 380 Y(I) = YH(I,1) + EL(1)*ACOR(I) +C----------------------------------------------------------------------- +C Test for convergence. If M .gt. 0, an estimate of the convergence +C rate constant is stored in CRATE, and this is used in the test. +C +C We first check for a change of iterates that is the size of +C roundoff error. If this occurs, the iteration has converged, and a +C new rate estimate is not formed. +C In all other cases, force at least two iterations to estimate a +C local Lipschitz constant estimate for Adams methods. +C On convergence, form PDEST = local maximum Lipschitz constant +C estimate. PDLAST is the most recent nonzero estimate. +C----------------------------------------------------------------------- + 400 CONTINUE + IF (DEL .LE. 100.0D0*PNORM*UROUND) GO TO 450 + IF (M .EQ. 0 .AND. METH .EQ. 1) GO TO 405 + IF (M .EQ. 0) GO TO 402 + RM = 1024.0D0 + IF (DEL .LE. 1024.0D0*DELP) RM = DEL/DELP + RATE = MAX(RATE,RM) + CRATE = MAX(0.2D0*CRATE,RM) + 402 DCON = DEL*MIN(1.0D0,1.5D0*CRATE)/(TESCO(2,NQ)*CONIT) + IF (DCON .GT. 1.0D0) GO TO 405 + PDEST = MAX(PDEST,RATE/ABS(H*EL(1))) + IF (PDEST .NE. 0.0D0) PDLAST = PDEST + GO TO 450 + 405 CONTINUE + M = M + 1 + IF (M .EQ. MAXCOR) GO TO 410 + IF (M .GE. 2 .AND. DEL .GT. 2.0D0*DELP) GO TO 410 + DELP = DEL + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + GO TO 270 +C----------------------------------------------------------------------- +C The corrector iteration failed to converge. +C If MITER .ne. 0 and the Jacobian is out of date, PJAC is called for +C the next try. Otherwise the YH array is retracted to its values +C before prediction, and H is reduced, if possible. If H cannot be +C reduced or MXNCF failures have occurred, exit with KFLAG = -2. +C----------------------------------------------------------------------- + 410 IF (MITER .EQ. 0 .OR. JCUR .EQ. 1) GO TO 430 + ICF = 1 + IPUP = MITER + GO TO 220 + 430 ICF = 2 + NCF = NCF + 1 + RMAX = 2.0D0 + TN = TOLD + I1 = NQNYH + 1 + DO 445 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 440 I = I1,NQNYH + 440 YH1(I) = YH1(I) - YH1(I+NYH) + 445 CONTINUE + IF (IERPJ .LT. 0 .OR. IERSL .LT. 0) GO TO 680 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 670 + IF (NCF .EQ. MXNCF) GO TO 670 + RH = 0.25D0 + IPUP = MITER + IREDO = 1 + GO TO 170 +C----------------------------------------------------------------------- +C The corrector has converged. JCUR is set to 0 +C to signal that the Jacobian involved may need updating later. +C The local error test is made and control passes to statement 500 +C if it fails. +C----------------------------------------------------------------------- + 450 JCUR = 0 + IF (M .EQ. 0) DSM = DEL/TESCO(2,NQ) + IF (M .GT. 0) DSM = DMNORM (N, ACOR, EWT)/TESCO(2,NQ) + IF (DSM .GT. 1.0D0) GO TO 500 +C----------------------------------------------------------------------- +C After a successful step, update the YH array. +C Decrease ICOUNT by 1, and if it is -1, consider switching methods. +C If a method switch is made, reset various parameters, +C rescale the YH array, and exit. If there is no switch, +C consider changing H if IALTH = 1. Otherwise decrease IALTH by 1. +C If IALTH is then 1 and NQ .lt. MAXORD, then ACOR is saved for +C use in a possible order increase on the next step. +C If a change in H is considered, an increase or decrease in order +C by one is considered also. A change in H is made only if it is by a +C factor of at least 1.1. If not, IALTH is set to 3 to prevent +C testing for that many steps. +C----------------------------------------------------------------------- + KFLAG = 0 + IREDO = 0 + NST = NST + 1 + HU = H + NQU = NQ + MUSED = METH + DO 460 J = 1,L + DO 460 I = 1,N + 460 YH(I,J) = YH(I,J) + EL(J)*ACOR(I) + ICOUNT = ICOUNT - 1 + IF (ICOUNT .GE. 0) GO TO 488 + IF (METH .EQ. 2) GO TO 480 +C----------------------------------------------------------------------- +C We are currently using an Adams method. Consider switching to BDF. +C If the current order is greater than 5, assume the problem is +C not stiff, and skip this section. +C If the Lipschitz constant and error estimate are not polluted +C by roundoff, go to 470 and perform the usual test. +C Otherwise, switch to the BDF methods if the last step was +C restricted to insure stability (irflag = 1), and stay with Adams +C method if not. When switching to BDF with polluted error estimates, +C in the absence of other information, double the step size. +C +C When the estimates are OK, we make the usual test by computing +C the step size we could have (ideally) used on this step, +C with the current (Adams) method, and also that for the BDF. +C If NQ .gt. MXORDS, we consider changing to order MXORDS on switching. +C Compare the two step sizes to decide whether to switch. +C The step size advantage must be at least RATIO = 5 to switch. +C----------------------------------------------------------------------- + IF (NQ .GT. 5) GO TO 488 + IF (DSM .GT. 100.0D0*PNORM*UROUND .AND. PDEST .NE. 0.0D0) + 1 GO TO 470 + IF (IRFLAG .EQ. 0) GO TO 488 + RH2 = 2.0D0 + NQM2 = MIN(NQ,MXORDS) + GO TO 478 + 470 CONTINUE + EXSM = 1.0D0/L + RH1 = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RH1IT = 2.0D0*RH1 + PDH = PDLAST*ABS(H) + IF (PDH*RH1 .GT. 0.00001D0) RH1IT = SM1(NQ)/PDH + RH1 = MIN(RH1,RH1IT) + IF (NQ .LE. MXORDS) GO TO 474 + NQM2 = MXORDS + LM2 = MXORDS + 1 + EXM2 = 1.0D0/LM2 + LM2P1 = LM2 + 1 + DM2 = DMNORM (N, YH(1,LM2P1), EWT)/CM2(MXORDS) + RH2 = 1.0D0/(1.2D0*DM2**EXM2 + 0.0000012D0) + GO TO 476 + 474 DM2 = DSM*(CM1(NQ)/CM2(NQ)) + RH2 = 1.0D0/(1.2D0*DM2**EXSM + 0.0000012D0) + NQM2 = NQ + 476 CONTINUE + IF (RH2 .LT. RATIO*RH1) GO TO 488 +C THE SWITCH TEST PASSED. RESET RELEVANT QUANTITIES FOR BDF. ---------- + 478 RH = RH2 + ICOUNT = 20 + METH = 2 + MITER = JTYP + PDLAST = 0.0D0 + NQ = NQM2 + L = NQ + 1 + GO TO 170 +C----------------------------------------------------------------------- +C We are currently using a BDF method. Consider switching to Adams. +C Compute the step size we could have (ideally) used on this step, +C with the current (BDF) method, and also that for the Adams. +C If NQ .gt. MXORDN, we consider changing to order MXORDN on switching. +C Compare the two step sizes to decide whether to switch. +C The step size advantage must be at least 5/RATIO = 1 to switch. +C If the step size for Adams would be so small as to cause +C roundoff pollution, we stay with BDF. +C----------------------------------------------------------------------- + 480 CONTINUE + EXSM = 1.0D0/L + IF (MXORDN .GE. NQ) GO TO 484 + NQM1 = MXORDN + LM1 = MXORDN + 1 + EXM1 = 1.0D0/LM1 + LM1P1 = LM1 + 1 + DM1 = DMNORM (N, YH(1,LM1P1), EWT)/CM1(MXORDN) + RH1 = 1.0D0/(1.2D0*DM1**EXM1 + 0.0000012D0) + GO TO 486 + 484 DM1 = DSM*(CM2(NQ)/CM1(NQ)) + RH1 = 1.0D0/(1.2D0*DM1**EXSM + 0.0000012D0) + NQM1 = NQ + EXM1 = EXSM + 486 RH1IT = 2.0D0*RH1 + PDH = PDNORM*ABS(H) + IF (PDH*RH1 .GT. 0.00001D0) RH1IT = SM1(NQM1)/PDH + RH1 = MIN(RH1,RH1IT) + RH2 = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + IF (RH1*RATIO .LT. 5.0D0*RH2) GO TO 488 + ALPHA = MAX(0.001D0,RH1) + DM1 = (ALPHA**EXM1)*DM1 + IF (DM1 .LE. 1000.0D0*UROUND*PNORM) GO TO 488 +C The switch test passed. Reset relevant quantities for Adams. -------- + RH = RH1 + ICOUNT = 20 + METH = 1 + MITER = 0 + PDLAST = 0.0D0 + NQ = NQM1 + L = NQ + 1 + GO TO 170 +C +C No method switch is being made. Do the usual step/order selection. -- + 488 CONTINUE + IALTH = IALTH - 1 + IF (IALTH .EQ. 0) GO TO 520 + IF (IALTH .GT. 1) GO TO 700 + IF (L .EQ. LMAX) GO TO 700 + DO 490 I = 1,N + 490 YH(I,LMAX) = ACOR(I) + GO TO 700 +C----------------------------------------------------------------------- +C The error test failed. KFLAG keeps track of multiple failures. +C Restore TN and the YH array to their previous values, and prepare +C to try the step again. Compute the optimum step size for this or +C one lower order. After 2 or more failures, H is forced to decrease +C by a factor of 0.2 or less. +C----------------------------------------------------------------------- + 500 KFLAG = KFLAG - 1 + TN = TOLD + I1 = NQNYH + 1 + DO 515 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 510 I = I1,NQNYH + 510 YH1(I) = YH1(I) - YH1(I+NYH) + 515 CONTINUE + RMAX = 2.0D0 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 660 + IF (KFLAG .LE. -3) GO TO 640 + IREDO = 2 + RHUP = 0.0D0 + GO TO 540 +C----------------------------------------------------------------------- +C Regardless of the success or failure of the step, factors +C RHDN, RHSM, and RHUP are computed, by which H could be multiplied +C at order NQ - 1, order NQ, or order NQ + 1, respectively. +C In the case of failure, RHUP = 0.0 to avoid an order increase. +C The largest of these is determined and the new order chosen +C accordingly. If the order is to be increased, we compute one +C additional scaled derivative. +C----------------------------------------------------------------------- + 520 RHUP = 0.0D0 + IF (L .EQ. LMAX) GO TO 540 + DO 530 I = 1,N + 530 SAVF(I) = ACOR(I) - YH(I,LMAX) + DUP = DMNORM (N, SAVF, EWT)/TESCO(3,NQ) + EXUP = 1.0D0/(L+1) + RHUP = 1.0D0/(1.4D0*DUP**EXUP + 0.0000014D0) + 540 EXSM = 1.0D0/L + RHSM = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RHDN = 0.0D0 + IF (NQ .EQ. 1) GO TO 550 + DDN = DMNORM (N, YH(1,L), EWT)/TESCO(1,NQ) + EXDN = 1.0D0/NQ + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) +C If METH = 1, limit RH according to the stability region also. -------- + 550 IF (METH .EQ. 2) GO TO 560 + PDH = MAX(ABS(H)*PDLAST,0.000001D0) + IF (L .LT. LMAX) RHUP = MIN(RHUP,SM1(L)/PDH) + RHSM = MIN(RHSM,SM1(NQ)/PDH) + IF (NQ .GT. 1) RHDN = MIN(RHDN,SM1(NQ-1)/PDH) + PDEST = 0.0D0 + 560 IF (RHSM .GE. RHUP) GO TO 570 + IF (RHUP .GT. RHDN) GO TO 590 + GO TO 580 + 570 IF (RHSM .LT. RHDN) GO TO 580 + NEWQ = NQ + RH = RHSM + GO TO 620 + 580 NEWQ = NQ - 1 + RH = RHDN + IF (KFLAG .LT. 0 .AND. RH .GT. 1.0D0) RH = 1.0D0 + GO TO 620 + 590 NEWQ = L + RH = RHUP + IF (RH .LT. 1.1D0) GO TO 610 + R = EL(L)/L + DO 600 I = 1,N + 600 YH(I,NEWQ+1) = ACOR(I)*R + GO TO 630 + 610 IALTH = 3 + GO TO 700 +C If METH = 1 and H is restricted by stability, bypass 10 percent test. + 620 IF (METH .EQ. 2) GO TO 622 + IF (RH*PDH*1.00001D0 .GE. SM1(NEWQ)) GO TO 625 + 622 IF (KFLAG .EQ. 0 .AND. RH .LT. 1.1D0) GO TO 610 + 625 IF (KFLAG .LE. -2) RH = MIN(RH,0.2D0) +C----------------------------------------------------------------------- +C If there is a change of order, reset NQ, L, and the coefficients. +C In any case H is reset according to RH and the YH array is rescaled. +C Then exit from 690 if the step was OK, or redo the step otherwise. +C----------------------------------------------------------------------- + IF (NEWQ .EQ. NQ) GO TO 170 + 630 NQ = NEWQ + L = NQ + 1 + IRET = 2 + GO TO 150 +C----------------------------------------------------------------------- +C Control reaches this section if 3 or more failures have occured. +C If 10 failures have occurred, exit with KFLAG = -1. +C It is assumed that the derivatives that have accumulated in the +C YH array have errors of the wrong order. Hence the first +C derivative is recomputed, and the order is set to 1. Then +C H is reduced by a factor of 10, and the step is retried, +C until it succeeds or H reaches HMIN. +C----------------------------------------------------------------------- + 640 IF (KFLAG .EQ. -10) GO TO 660 + RH = 0.1D0 + RH = MAX(HMIN/ABS(H),RH) + H = H*RH + DO 645 I = 1,N + 645 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + DO 650 I = 1,N + 650 YH(I,2) = H*SAVF(I) + IPUP = MITER + IALTH = 5 + IF (NQ .EQ. 1) GO TO 200 + NQ = 1 + L = 2 + IRET = 3 + GO TO 150 +C----------------------------------------------------------------------- +C All returns are made through this section. H is saved in HOLD +C to allow the caller to change H on the next step. +C----------------------------------------------------------------------- + 660 KFLAG = -1 + GO TO 720 + 670 KFLAG = -2 + GO TO 720 + 680 KFLAG = -3 + GO TO 720 + 690 RMAX = 10.0D0 + 700 R = 1.0D0/TESCO(2,NQU) + DO 710 I = 1,N + 710 ACOR(I) = ACOR(I)*R + 720 HOLD = H + JSTART = 1 + RETURN +C----------------------- End of Subroutine DSTODA ---------------------- + END +*DECK DPRJA + SUBROUTINE DPRJA (NEQ, Y, YH, NYH, EWT, FTEM, SAVF, WM, IWM, + 1 F, JAC) + EXTERNAL F, JAC + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, EWT, FTEM, SAVF, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), FTEM(*), SAVF(*), + 1 WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IOWND2, IOWNS2, JTYP, MUSED, MXORDN, MXORDS + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ROWND2, ROWNS2, PDNORM + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSA01/ ROWND2, ROWNS2(20), PDNORM, + 1 IOWND2(3), IOWNS2(2), JTYP, MUSED, MXORDN, MXORDS + INTEGER I, I1, I2, IER, II, J, J1, JJ, LENP, + 1 MBA, MBAND, MEB1, MEBAND, ML, ML3, MU, NP1 + DOUBLE PRECISION CON, FAC, HL0, R, R0, SRUR, YI, YJ, YJJ, + 1 DMNORM, DFNORM, DBNORM +C----------------------------------------------------------------------- +C DPRJA is called by DSTODA to compute and process the matrix +C P = I - H*EL(1)*J , where J is an approximation to the Jacobian. +C Here J is computed by the user-supplied routine JAC if +C MITER = 1 or 4 or by finite differencing if MITER = 2 or 5. +C J, scaled by -H*EL(1), is stored in WM. Then the norm of J (the +C matrix norm consistent with the weighted max-norm on vectors given +C by DMNORM) is computed, and J is overwritten by P. P is then +C subjected to LU decomposition in preparation for later solution +C of linear systems with P as coefficient matrix. This is done +C by DGEFA if MITER = 1 or 2, and by DGBFA if MITER = 4 or 5. +C +C In addition to variables described previously, communication +C with DPRJA uses the following: +C Y = array containing predicted values on entry. +C FTEM = work array of length N (ACOR in DSTODA). +C SAVF = array containing f evaluated at predicted y. +C WM = real work space for matrices. On output it contains the +C LU decomposition of P. +C Storage of matrix elements starts at WM(3). +C WM also contains the following matrix-related data: +C WM(1) = SQRT(UROUND), used in numerical Jacobian increments. +C IWM = integer work space containing pivot information, starting at +C IWM(21). IWM also contains the band parameters +C ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5. +C EL0 = EL(1) (input). +C PDNORM= norm of Jacobian matrix. (Output). +C IERPJ = output error flag, = 0 if no trouble, .gt. 0 if +C P matrix found to be singular. +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses the Common variables EL0, H, TN, UROUND, +C MITER, N, NFE, and NJE. +C----------------------------------------------------------------------- + NJE = NJE + 1 + IERPJ = 0 + JCUR = 1 + HL0 = H*EL0 + GO TO (100, 200, 300, 400, 500), MITER +C If MITER = 1, call JAC and multiply by scalar. ----------------------- + 100 LENP = N*N + DO 110 I = 1,LENP + 110 WM(I+2) = 0.0D0 + CALL JAC (NEQ, TN, Y, 0, 0, WM(3), N) + CON = -HL0 + DO 120 I = 1,LENP + 120 WM(I+2) = WM(I+2)*CON + GO TO 240 +C If MITER = 2, make N calls to F to approximate J. -------------------- + 200 FAC = DMNORM (N, SAVF, EWT) + R0 = 1000.0D0*ABS(H)*UROUND*N*FAC + IF (R0 .EQ. 0.0D0) R0 = 1.0D0 + SRUR = WM(1) + J1 = 2 + DO 230 J = 1,N + YJ = Y(J) + R = MAX(SRUR*ABS(YJ),R0/EWT(J)) + Y(J) = Y(J) + R + FAC = -HL0/R + CALL F (NEQ, TN, Y, FTEM) + DO 220 I = 1,N + 220 WM(I+J1) = (FTEM(I) - SAVF(I))*FAC + Y(J) = YJ + J1 = J1 + N + 230 CONTINUE + NFE = NFE + N + 240 CONTINUE +C Compute norm of Jacobian. -------------------------------------------- + PDNORM = DFNORM (N, WM(3), EWT)/ABS(HL0) +C Add identity matrix. ------------------------------------------------- + J = 3 + NP1 = N + 1 + DO 250 I = 1,N + WM(J) = WM(J) + 1.0D0 + 250 J = J + NP1 +C Do LU decomposition on P. -------------------------------------------- + CALL DGEFA (WM(3), N, N, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C Dummy block only, since MITER is never 3 in this routine. ------------ + 300 RETURN +C If MITER = 4, call JAC and multiply by scalar. ----------------------- + 400 ML = IWM(1) + MU = IWM(2) + ML3 = ML + 3 + MBAND = ML + MU + 1 + MEBAND = MBAND + ML + LENP = MEBAND*N + DO 410 I = 1,LENP + 410 WM(I+2) = 0.0D0 + CALL JAC (NEQ, TN, Y, ML, MU, WM(ML3), MEBAND) + CON = -HL0 + DO 420 I = 1,LENP + 420 WM(I+2) = WM(I+2)*CON + GO TO 570 +C If MITER = 5, make MBAND calls to F to approximate J. ---------------- + 500 ML = IWM(1) + MU = IWM(2) + MBAND = ML + MU + 1 + MBA = MIN(MBAND,N) + MEBAND = MBAND + ML + MEB1 = MEBAND - 1 + SRUR = WM(1) + FAC = DMNORM (N, SAVF, EWT) + R0 = 1000.0D0*ABS(H)*UROUND*N*FAC + IF (R0 .EQ. 0.0D0) R0 = 1.0D0 + DO 560 J = 1,MBA + DO 530 I = J,N,MBAND + YI = Y(I) + R = MAX(SRUR*ABS(YI),R0/EWT(I)) + 530 Y(I) = Y(I) + R + CALL F (NEQ, TN, Y, FTEM) + DO 550 JJ = J,N,MBAND + Y(JJ) = YH(JJ,1) + YJJ = Y(JJ) + R = MAX(SRUR*ABS(YJJ),R0/EWT(JJ)) + FAC = -HL0/R + I1 = MAX(JJ-MU,1) + I2 = MIN(JJ+ML,N) + II = JJ*MEB1 - ML + 2 + DO 540 I = I1,I2 + 540 WM(II+I) = (FTEM(I) - SAVF(I))*FAC + 550 CONTINUE + 560 CONTINUE + NFE = NFE + MBA + 570 CONTINUE +C Compute norm of Jacobian. -------------------------------------------- + PDNORM = DBNORM (N, WM(ML+3), MEBAND, ML, MU, EWT)/ABS(HL0) +C Add identity matrix. ------------------------------------------------- + II = MBAND + 2 + DO 580 I = 1,N + WM(II) = WM(II) + 1.0D0 + 580 II = II + MEBAND +C Do LU decomposition of P. -------------------------------------------- + CALL DGBFA (WM(3), MEBAND, N, ML, MU, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C----------------------- End of Subroutine DPRJA ----------------------- + END +*DECK DMNORM + DOUBLE PRECISION FUNCTION DMNORM (N, V, W) +C----------------------------------------------------------------------- +C This function routine computes the weighted max-norm +C of the vector of length N contained in the array V, with weights +C contained in the array w of length N: +C DMNORM = MAX(i=1,...,N) ABS(V(i))*W(i) +C----------------------------------------------------------------------- + INTEGER N, I + DOUBLE PRECISION V, W, VM + DIMENSION V(N), W(N) + VM = 0.0D0 + DO 10 I = 1,N + 10 VM = MAX(VM,ABS(V(I))*W(I)) + DMNORM = VM + RETURN +C----------------------- End of Function DMNORM ------------------------ + END +*DECK DFNORM + DOUBLE PRECISION FUNCTION DFNORM (N, A, W) +C----------------------------------------------------------------------- +C This function computes the norm of a full N by N matrix, +C stored in the array A, that is consistent with the weighted max-norm +C on vectors, with weights stored in the array W: +C DFNORM = MAX(i=1,...,N) ( W(i) * Sum(j=1,...,N) ABS(a(i,j))/W(j) ) +C----------------------------------------------------------------------- + INTEGER N, I, J + DOUBLE PRECISION A, W, AN, SUM + DIMENSION A(N,N), W(N) + AN = 0.0D0 + DO 20 I = 1,N + SUM = 0.0D0 + DO 10 J = 1,N + 10 SUM = SUM + ABS(A(I,J))/W(J) + AN = MAX(AN,SUM*W(I)) + 20 CONTINUE + DFNORM = AN + RETURN +C----------------------- End of Function DFNORM ------------------------ + END +*DECK DBNORM + DOUBLE PRECISION FUNCTION DBNORM (N, A, NRA, ML, MU, W) +C----------------------------------------------------------------------- +C This function computes the norm of a banded N by N matrix, +C stored in the array A, that is consistent with the weighted max-norm +C on vectors, with weights stored in the array W. +C ML and MU are the lower and upper half-bandwidths of the matrix. +C NRA is the first dimension of the A array, NRA .ge. ML+MU+1. +C In terms of the matrix elements a(i,j), the norm is given by: +C DBNORM = MAX(i=1,...,N) ( W(i) * Sum(j=1,...,N) ABS(a(i,j))/W(j) ) +C----------------------------------------------------------------------- + INTEGER N, NRA, ML, MU + INTEGER I, I1, JLO, JHI, J + DOUBLE PRECISION A, W + DOUBLE PRECISION AN, SUM + DIMENSION A(NRA,N), W(N) + AN = 0.0D0 + DO 20 I = 1,N + SUM = 0.0D0 + I1 = I + MU + 1 + JLO = MAX(I-ML,1) + JHI = MIN(I+MU,N) + DO 10 J = JLO,JHI + 10 SUM = SUM + ABS(A(I1-J,J))/W(J) + AN = MAX(AN,SUM*W(I)) + 20 CONTINUE + DBNORM = AN + RETURN +C----------------------- End of Function DBNORM ------------------------ + END +*DECK DSRCMA + SUBROUTINE DSRCMA (RSAV, ISAV, JOB) +C----------------------------------------------------------------------- +C This routine saves or restores (depending on JOB) the contents of +C the Common blocks DLS001, DLSA01, which are used +C internally by one or more ODEPACK solvers. +C +C RSAV = real array of length 240 or more. +C ISAV = integer array of length 46 or more. +C JOB = flag indicating to save or restore the Common blocks: +C JOB = 1 if Common is to be saved (written to RSAV/ISAV) +C JOB = 2 if Common is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C----------------------------------------------------------------------- + INTEGER ISAV, JOB + INTEGER ILS, ILSA + INTEGER I, LENRLS, LENILS, LENRLA, LENILA + DOUBLE PRECISION RSAV + DOUBLE PRECISION RLS, RLSA + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS, LENRLA, LENILA + COMMON /DLS001/ RLS(218), ILS(37) + COMMON /DLSA01/ RLSA(22), ILSA(9) + DATA LENRLS/218/, LENILS/37/, LENRLA/22/, LENILA/9/ +C + IF (JOB .EQ. 2) GO TO 100 + DO 10 I = 1,LENRLS + 10 RSAV(I) = RLS(I) + DO 15 I = 1,LENRLA + 15 RSAV(LENRLS+I) = RLSA(I) +C + DO 20 I = 1,LENILS + 20 ISAV(I) = ILS(I) + DO 25 I = 1,LENILA + 25 ISAV(LENILS+I) = ILSA(I) +C + RETURN +C + 100 CONTINUE + DO 110 I = 1,LENRLS + 110 RLS(I) = RSAV(I) + DO 115 I = 1,LENRLA + 115 RLSA(I) = RSAV(LENRLS+I) +C + DO 120 I = 1,LENILS + 120 ILS(I) = ISAV(I) + DO 125 I = 1,LENILA + 125 ILSA(I) = ISAV(LENILS+I) +C + RETURN +C----------------------- End of Subroutine DSRCMA ---------------------- + END +*DECK DRCHEK + SUBROUTINE DRCHEK (JOB, G, NEQ, Y, YH,NYH, G0, G1, GX, JROOT, IRT) + EXTERNAL G + INTEGER JOB, NEQ, NYH, JROOT, IRT + DOUBLE PRECISION Y, YH, G0, G1, GX + DIMENSION NEQ(*), Y(*), YH(NYH,*), G0(*), G1(*), GX(*), JROOT(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IOWND3, IOWNR3, IRFND, ITASKC, NGC, NGE + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ROWNR3, T0, TLAST, TOUTC + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSR01/ ROWNR3(2), T0, TLAST, TOUTC, + 1 IOWND3(3), IOWNR3(2), IRFND, ITASKC, NGC, NGE + INTEGER I, IFLAG, JFLAG + DOUBLE PRECISION HMING, T1, TEMP1, TEMP2, X + LOGICAL ZROOT +C----------------------------------------------------------------------- +C This routine checks for the presence of a root in the vicinity of +C the current T, in a manner depending on the input flag JOB. It calls +C Subroutine DROOTS to locate the root as precisely as possible. +C +C In addition to variables described previously, DRCHEK +C uses the following for communication: +C JOB = integer flag indicating type of call: +C JOB = 1 means the problem is being initialized, and DRCHEK +C is to look for a root at or very near the initial T. +C JOB = 2 means a continuation call to the solver was just +C made, and DRCHEK is to check for a root in the +C relevant part of the step last taken. +C JOB = 3 means a successful step was just taken, and DRCHEK +C is to look for a root in the interval of the step. +C G0 = array of length NG, containing the value of g at T = T0. +C G0 is input for JOB .ge. 2, and output in all cases. +C G1,GX = arrays of length NG for work space. +C IRT = completion flag: +C IRT = 0 means no root was found. +C IRT = -1 means JOB = 1 and a root was found too near to T. +C IRT = 1 means a legitimate root was found (JOB = 2 or 3). +C On return, T0 is the root location, and Y is the +C corresponding solution vector. +C T0 = value of T at one endpoint of interval of interest. Only +C roots beyond T0 in the direction of integration are sought. +C T0 is input if JOB .ge. 2, and output in all cases. +C T0 is updated by DRCHEK, whether a root is found or not. +C TLAST = last value of T returned by the solver (input only). +C TOUTC = copy of TOUT (input only). +C IRFND = input flag showing whether the last step taken had a root. +C IRFND = 1 if it did, = 0 if not. +C ITASKC = copy of ITASK (input only). +C NGC = copy of NG (input only). +C----------------------------------------------------------------------- + IRT = 0 + DO 10 I = 1,NGC + 10 JROOT(I) = 0 + HMING = (ABS(TN) + ABS(H))*UROUND*100.0D0 +C + GO TO (100, 200, 300), JOB +C +C Evaluate g at initial T, and check for zero values. ------------------ + 100 CONTINUE + T0 = TN + CALL G (NEQ, T0, Y, NGC, G0) + NGE = 1 + ZROOT = .FALSE. + DO 110 I = 1,NGC + 110 IF (ABS(G0(I)) .LE. 0.0D0) ZROOT = .TRUE. + IF (.NOT. ZROOT) GO TO 190 +C g has a zero at T. Look at g at T + (small increment). -------------- + TEMP2 = MAX(HMING/ABS(H), 0.1D0) + TEMP1 = TEMP2*H + T0 = T0 + TEMP1 + DO 120 I = 1,N + 120 Y(I) = Y(I) + TEMP2*YH(I,2) + CALL G (NEQ, T0, Y, NGC, G0) + NGE = NGE + 1 + ZROOT = .FALSE. + DO 130 I = 1,NGC + 130 IF (ABS(G0(I)) .LE. 0.0D0) ZROOT = .TRUE. + IF (.NOT. ZROOT) GO TO 190 +C g has a zero at T and also close to T. Take error return. ----------- + IRT = -1 + RETURN +C + 190 CONTINUE + RETURN +C +C + 200 CONTINUE + IF (IRFND .EQ. 0) GO TO 260 +C If a root was found on the previous step, evaluate G0 = g(T0). ------- + CALL DINTDY (T0, 0, YH, NYH, Y, IFLAG) + CALL G (NEQ, T0, Y, NGC, G0) + NGE = NGE + 1 + ZROOT = .FALSE. + DO 210 I = 1,NGC + 210 IF (ABS(G0(I)) .LE. 0.0D0) ZROOT = .TRUE. + IF (.NOT. ZROOT) GO TO 260 +C g has a zero at T0. Look at g at T + (small increment). ------------- + TEMP1 = SIGN(HMING,H) + T0 = T0 + TEMP1 + IF ((T0 - TN)*H .LT. 0.0D0) GO TO 230 + TEMP2 = TEMP1/H + DO 220 I = 1,N + 220 Y(I) = Y(I) + TEMP2*YH(I,2) + GO TO 240 + 230 CALL DINTDY (T0, 0, YH, NYH, Y, IFLAG) + 240 CALL G (NEQ, T0, Y, NGC, G0) + NGE = NGE + 1 + ZROOT = .FALSE. + DO 250 I = 1,NGC + IF (ABS(G0(I)) .GT. 0.0D0) GO TO 250 + JROOT(I) = 1 + ZROOT = .TRUE. + 250 CONTINUE + IF (.NOT. ZROOT) GO TO 260 +C g has a zero at T0 and also close to T0. Return root. --------------- + IRT = 1 + RETURN +C G0 has no zero components. Proceed to check relevant interval. ------ + 260 IF (TN .EQ. TLAST) GO TO 390 +C + 300 CONTINUE +C Set T1 to TN or TOUTC, whichever comes first, and get g at T1. ------- + IF (ITASKC.EQ.2 .OR. ITASKC.EQ.3 .OR. ITASKC.EQ.5) GO TO 310 + IF ((TOUTC - TN)*H .GE. 0.0D0) GO TO 310 + T1 = TOUTC + IF ((T1 - T0)*H .LE. 0.0D0) GO TO 390 + CALL DINTDY (T1, 0, YH, NYH, Y, IFLAG) + GO TO 330 + 310 T1 = TN + DO 320 I = 1,N + 320 Y(I) = YH(I,1) + 330 CALL G (NEQ, T1, Y, NGC, G1) + NGE = NGE + 1 +C Call DROOTS to search for root in interval from T0 to T1. ------------ + JFLAG = 0 + 350 CONTINUE + CALL DROOTS (NGC, HMING, JFLAG, T0, T1, G0, G1, GX, X, JROOT) + IF (JFLAG .GT. 1) GO TO 360 + CALL DINTDY (X, 0, YH, NYH, Y, IFLAG) + CALL G (NEQ, X, Y, NGC, GX) + NGE = NGE + 1 + GO TO 350 + 360 T0 = X + CALL DCOPY (NGC, GX, 1, G0, 1) + IF (JFLAG .EQ. 4) GO TO 390 +C Found a root. Interpolate to X and return. -------------------------- + CALL DINTDY (X, 0, YH, NYH, Y, IFLAG) + IRT = 1 + RETURN +C + 390 CONTINUE + RETURN +C----------------------- End of Subroutine DRCHEK ---------------------- + END +*DECK DROOTS + SUBROUTINE DROOTS (NG, HMIN, JFLAG, X0, X1, G0, G1, GX, X, JROOT) + INTEGER NG, JFLAG, JROOT + DOUBLE PRECISION HMIN, X0, X1, G0, G1, GX, X + DIMENSION G0(NG), G1(NG), GX(NG), JROOT(NG) + INTEGER IOWND3, IMAX, LAST, IDUM3 + DOUBLE PRECISION ALPHA, X2, RDUM3 + COMMON /DLSR01/ ALPHA, X2, RDUM3(3), + 1 IOWND3(3), IMAX, LAST, IDUM3(4) +C----------------------------------------------------------------------- +C This subroutine finds the leftmost root of a set of arbitrary +C functions gi(x) (i = 1,...,NG) in an interval (X0,X1). Only roots +C of odd multiplicity (i.e. changes of sign of the gi) are found. +C Here the sign of X1 - X0 is arbitrary, but is constant for a given +C problem, and -leftmost- means nearest to X0. +C The values of the vector-valued function g(x) = (gi, i=1...NG) +C are communicated through the call sequence of DROOTS. +C The method used is the Illinois algorithm. +C +C Reference: +C Kathie L. Hiebert and Lawrence F. Shampine, Implicitly Defined +C Output Points for Solutions of ODEs, Sandia Report SAND80-0180, +C February 1980. +C +C Description of parameters. +C +C NG = number of functions gi, or the number of components of +C the vector valued function g(x). Input only. +C +C HMIN = resolution parameter in X. Input only. When a root is +C found, it is located only to within an error of HMIN in X. +C Typically, HMIN should be set to something on the order of +C 100 * UROUND * MAX(ABS(X0),ABS(X1)), +C where UROUND is the unit roundoff of the machine. +C +C JFLAG = integer flag for input and output communication. +C +C On input, set JFLAG = 0 on the first call for the problem, +C and leave it unchanged until the problem is completed. +C (The problem is completed when JFLAG .ge. 2 on return.) +C +C On output, JFLAG has the following values and meanings: +C JFLAG = 1 means DROOTS needs a value of g(x). Set GX = g(X) +C and call DROOTS again. +C JFLAG = 2 means a root has been found. The root is +C at X, and GX contains g(X). (Actually, X is the +C rightmost approximation to the root on an interval +C (X0,X1) of size HMIN or less.) +C JFLAG = 3 means X = X1 is a root, with one or more of the gi +C being zero at X1 and no sign changes in (X0,X1). +C GX contains g(X) on output. +C JFLAG = 4 means no roots (of odd multiplicity) were +C found in (X0,X1) (no sign changes). +C +C X0,X1 = endpoints of the interval where roots are sought. +C X1 and X0 are input when JFLAG = 0 (first call), and +C must be left unchanged between calls until the problem is +C completed. X0 and X1 must be distinct, but X1 - X0 may be +C of either sign. However, the notion of -left- and -right- +C will be used to mean nearer to X0 or X1, respectively. +C When JFLAG .ge. 2 on return, X0 and X1 are output, and +C are the endpoints of the relevant interval. +C +C G0,G1 = arrays of length NG containing the vectors g(X0) and g(X1), +C respectively. When JFLAG = 0, G0 and G1 are input and +C none of the G0(i) should be zero. +C When JFLAG .ge. 2 on return, G0 and G1 are output. +C +C GX = array of length NG containing g(X). GX is input +C when JFLAG = 1, and output when JFLAG .ge. 2. +C +C X = independent variable value. Output only. +C When JFLAG = 1 on output, X is the point at which g(x) +C is to be evaluated and loaded into GX. +C When JFLAG = 2 or 3, X is the root. +C When JFLAG = 4, X is the right endpoint of the interval, X1. +C +C JROOT = integer array of length NG. Output only. +C When JFLAG = 2 or 3, JROOT indicates which components +C of g(x) have a root at X. JROOT(i) is 1 if the i-th +C component has a root, and JROOT(i) = 0 otherwise. +C----------------------------------------------------------------------- + INTEGER I, IMXOLD, NXLAST + DOUBLE PRECISION T2, TMAX, FRACINT, FRACSUB, ZERO,HALF,TENTH,FIVE + LOGICAL ZROOT, SGNCHG, XROOT + SAVE ZERO, HALF, TENTH, FIVE + DATA ZERO/0.0D0/, HALF/0.5D0/, TENTH/0.1D0/, FIVE/5.0D0/ +C + IF (JFLAG .EQ. 1) GO TO 200 +C JFLAG .ne. 1. Check for change in sign of g or zero at X1. ---------- + IMAX = 0 + TMAX = ZERO + ZROOT = .FALSE. + DO 120 I = 1,NG + IF (ABS(G1(I)) .GT. ZERO) GO TO 110 + ZROOT = .TRUE. + GO TO 120 +C At this point, G0(i) has been checked and cannot be zero. ------------ + 110 IF (SIGN(1.0D0,G0(I)) .EQ. SIGN(1.0D0,G1(I))) GO TO 120 + T2 = ABS(G1(I)/(G1(I)-G0(I))) + IF (T2 .LE. TMAX) GO TO 120 + TMAX = T2 + IMAX = I + 120 CONTINUE + IF (IMAX .GT. 0) GO TO 130 + SGNCHG = .FALSE. + GO TO 140 + 130 SGNCHG = .TRUE. + 140 IF (.NOT. SGNCHG) GO TO 400 +C There is a sign change. Find the first root in the interval. -------- + XROOT = .FALSE. + NXLAST = 0 + LAST = 1 +C +C Repeat until the first root in the interval is found. Loop point. --- + 150 CONTINUE + IF (XROOT) GO TO 300 + IF (NXLAST .EQ. LAST) GO TO 160 + ALPHA = 1.0D0 + GO TO 180 + 160 IF (LAST .EQ. 0) GO TO 170 + ALPHA = 0.5D0*ALPHA + GO TO 180 + 170 ALPHA = 2.0D0*ALPHA + 180 X2 = X1 - (X1 - X0)*G1(IMAX) / (G1(IMAX) - ALPHA*G0(IMAX)) +C If X2 is too close to X0 or X1, adjust it inward, by a fractional ---- +C distance that is between 0.1 and 0.5. -------------------------------- + IF (ABS(X2 - X0) < HALF*HMIN) THEN + FRACINT = ABS(X1 - X0)/HMIN + FRACSUB = TENTH + IF (FRACINT .LE. FIVE) FRACSUB = HALF/FRACINT + X2 = X0 + FRACSUB*(X1 - X0) + ENDIF + IF (ABS(X1 - X2) < HALF*HMIN) THEN + FRACINT = ABS(X1 - X0)/HMIN + FRACSUB = TENTH + IF (FRACINT .LE. FIVE) FRACSUB = HALF/FRACINT + X2 = X1 - FRACSUB*(X1 - X0) + ENDIF + JFLAG = 1 + X = X2 +C Return to the calling routine to get a value of GX = g(X). ----------- + RETURN +C Check to see in which interval g changes sign. ----------------------- + 200 IMXOLD = IMAX + IMAX = 0 + TMAX = ZERO + ZROOT = .FALSE. + DO 220 I = 1,NG + IF (ABS(GX(I)) .GT. ZERO) GO TO 210 + ZROOT = .TRUE. + GO TO 220 +C Neither G0(i) nor GX(i) can be zero at this point. ------------------- + 210 IF (SIGN(1.0D0,G0(I)) .EQ. SIGN(1.0D0,GX(I))) GO TO 220 + T2 = ABS(GX(I)/(GX(I) - G0(I))) + IF (T2 .LE. TMAX) GO TO 220 + TMAX = T2 + IMAX = I + 220 CONTINUE + IF (IMAX .GT. 0) GO TO 230 + SGNCHG = .FALSE. + IMAX = IMXOLD + GO TO 240 + 230 SGNCHG = .TRUE. + 240 NXLAST = LAST + IF (.NOT. SGNCHG) GO TO 250 +C Sign change between X0 and X2, so replace X1 with X2. ---------------- + X1 = X2 + CALL DCOPY (NG, GX, 1, G1, 1) + LAST = 1 + XROOT = .FALSE. + GO TO 270 + 250 IF (.NOT. ZROOT) GO TO 260 +C Zero value at X2 and no sign change in (X0,X2), so X2 is a root. ----- + X1 = X2 + CALL DCOPY (NG, GX, 1, G1, 1) + XROOT = .TRUE. + GO TO 270 +C No sign change between X0 and X2. Replace X0 with X2. --------------- + 260 CONTINUE + CALL DCOPY (NG, GX, 1, G0, 1) + X0 = X2 + LAST = 0 + XROOT = .FALSE. + 270 IF (ABS(X1-X0) .LE. HMIN) XROOT = .TRUE. + GO TO 150 +C +C Return with X1 as the root. Set JROOT. Set X = X1 and GX = G1. ----- + 300 JFLAG = 2 + X = X1 + CALL DCOPY (NG, G1, 1, GX, 1) + DO 320 I = 1,NG + JROOT(I) = 0 + IF (ABS(G1(I)) .GT. ZERO) GO TO 310 + JROOT(I) = 1 + GO TO 320 + 310 IF (SIGN(1.0D0,G0(I)) .NE. SIGN(1.0D0,G1(I))) JROOT(I) = 1 + 320 CONTINUE + RETURN +C +C No sign change in the interval. Check for zero at right endpoint. --- + 400 IF (.NOT. ZROOT) GO TO 420 +C +C Zero value at X1 and no sign change in (X0,X1). Return JFLAG = 3. --- + X = X1 + CALL DCOPY (NG, G1, 1, GX, 1) + DO 410 I = 1,NG + JROOT(I) = 0 + IF (ABS(G1(I)) .LE. ZERO) JROOT (I) = 1 + 410 CONTINUE + JFLAG = 3 + RETURN +C +C No sign changes in this interval. Set X = X1, return JFLAG = 4. ----- + 420 CALL DCOPY (NG, G1, 1, GX, 1) + X = X1 + JFLAG = 4 + RETURN +C----------------------- End of Subroutine DROOTS ---------------------- + END +*DECK DSRCAR + SUBROUTINE DSRCAR (RSAV, ISAV, JOB) +C----------------------------------------------------------------------- +C This routine saves or restores (depending on JOB) the contents of +C the Common blocks DLS001, DLSA01, DLSR01, which are used +C internally by one or more ODEPACK solvers. +C +C RSAV = real array of length 245 or more. +C ISAV = integer array of length 55 or more. +C JOB = flag indicating to save or restore the Common blocks: +C JOB = 1 if Common is to be saved (written to RSAV/ISAV) +C JOB = 2 if Common is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C----------------------------------------------------------------------- + INTEGER ISAV, JOB + INTEGER ILS, ILSA, ILSR + INTEGER I, IOFF, LENRLS, LENILS, LENRLA, LENILA, LENRLR, LENILR + DOUBLE PRECISION RSAV + DOUBLE PRECISION RLS, RLSA, RLSR + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS, LENRLA, LENILA, LENRLR, LENILR + COMMON /DLS001/ RLS(218), ILS(37) + COMMON /DLSA01/ RLSA(22), ILSA(9) + COMMON /DLSR01/ RLSR(5), ILSR(9) + DATA LENRLS/218/, LENILS/37/, LENRLA/22/, LENILA/9/ + DATA LENRLR/5/, LENILR/9/ +C + IF (JOB .EQ. 2) GO TO 100 + DO 10 I = 1,LENRLS + 10 RSAV(I) = RLS(I) + DO 15 I = 1,LENRLA + 15 RSAV(LENRLS+I) = RLSA(I) + IOFF = LENRLS + LENRLA + DO 20 I = 1,LENRLR + 20 RSAV(IOFF+I) = RLSR(I) +C + DO 30 I = 1,LENILS + 30 ISAV(I) = ILS(I) + DO 35 I = 1,LENILA + 35 ISAV(LENILS+I) = ILSA(I) + IOFF = LENILS + LENILA + DO 40 I = 1,LENILR + 40 ISAV(IOFF+I) = ILSR(I) +C + RETURN +C + 100 CONTINUE + DO 110 I = 1,LENRLS + 110 RLS(I) = RSAV(I) + DO 115 I = 1,LENRLA + 115 RLSA(I) = RSAV(LENRLS+I) + IOFF = LENRLS + LENRLA + DO 120 I = 1,LENRLR + 120 RLSR(I) = RSAV(IOFF+I) +C + DO 130 I = 1,LENILS + 130 ILS(I) = ISAV(I) + DO 135 I = 1,LENILA + 135 ILSA(I) = ISAV(LENILS+I) + IOFF = LENILS + LENILA + DO 140 I = 1,LENILR + 140 ILSR(I) = ISAV(IOFF+I) +C + RETURN +C----------------------- End of Subroutine DSRCAR ---------------------- + END +*DECK DSTODPK + SUBROUTINE DSTODPK (NEQ, Y, YH, NYH, YH1, EWT, SAVF, SAVX, ACOR, + 1 WM, IWM, F, JAC, PSOL) + EXTERNAL F, JAC, PSOL + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, YH1, EWT, SAVF, SAVX, ACOR, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), YH1(*), EWT(*), SAVF(*), + 1 SAVX(*), ACOR(*), WM(*), IWM(*) + INTEGER IOWND, IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + DOUBLE PRECISION CONIT, CRATE, EL, ELCO, HOLD, RMAX, TESCO, + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + COMMON /DLS001/ CONIT, CRATE, EL(13), ELCO(13,12), + 1 HOLD, RMAX, TESCO(3,12), + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 3 IOWND(6), IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C----------------------------------------------------------------------- +C DSTODPK performs one step of the integration of an initial value +C problem for a system of Ordinary Differential Equations. +C----------------------------------------------------------------------- +C The following changes were made to generate Subroutine DSTODPK +C from Subroutine DSTODE: +C 1. The array SAVX was added to the call sequence. +C 2. PJAC and SLVS were replaced by PSOL in the call sequence. +C 3. The Common block /DLPK01/ was added for communication. +C 4. The test constant EPCON is loaded into Common below statement +C numbers 125 and 155, and used below statement 400. +C 5. The Newton iteration counter MNEWT is set below 220 and 400. +C 6. The call to PJAC was replaced with a call to DPKSET (fixed name), +C with a longer call sequence, called depending on JACFLG. +C 7. The corrector residual is stored in SAVX (not Y) at 360, +C and the solution vector is in SAVX in the 380 loop. +C 8. SLVS was renamed DSOLPK and includes NEQ, SAVX, EWT, F, and JAC. +C SAVX was added because DSOLPK now needs Y and SAVF undisturbed. +C 9. The nonlinear convergence failure count NCFN is set at 430. +C----------------------------------------------------------------------- +C Note: DSTODPK is independent of the value of the iteration method +C indicator MITER, when this is .ne. 0, and hence is independent +C of the type of chord method used, or the Jacobian structure. +C Communication with DSTODPK is done with the following variables: +C +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls to F and JAC. +C Y = an array of length .ge. N used as the Y argument in +C all calls to F and JAC. +C YH = an NYH by LMAX array containing the dependent variables +C and their approximate scaled derivatives, where +C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate +C j-th derivative of y(i), scaled by H**j/factorial(j) +C (j = 0,1,...,NQ). On entry for the first step, the first +C two columns of YH must be set from the initial values. +C NYH = a constant integer .ge. N, the first dimension of YH. +C YH1 = a one-dimensional array occupying the same space as YH. +C EWT = an array of length N containing multiplicative weights +C for local error measurements. Local errors in y(i) are +C compared to 1.0/EWT(i) in various error tests. +C SAVF = an array of working storage, of length N. +C Also used for input of YH(*,MAXORD+2) when JSTART = -1 +C and MAXORD .lt. the current order NQ. +C SAVX = an array of working storage, of length N. +C ACOR = a work array of length N, used for the accumulated +C corrections. On a successful return, ACOR(i) contains +C the estimated one-step local error in y(i). +C WM,IWM = real and integer work arrays associated with matrix +C operations in chord iteration (MITER .ne. 0). +C CCMAX = maximum relative change in H*EL0 before DPKSET is called. +C H = the step size to be attempted on the next step. +C H is altered by the error control algorithm during the +C problem. H can be either positive or negative, but its +C sign must remain constant throughout the problem. +C HMIN = the minimum absolute value of the step size H to be used. +C HMXI = inverse of the maximum absolute value of H to be used. +C HMXI = 0.0 is allowed and corresponds to an infinite HMAX. +C HMIN and HMXI may be changed at any time, but will not +C take effect until the next change of H is considered. +C TN = the independent variable. TN is updated on each step taken. +C JSTART = an integer used for input only, with the following +C values and meanings: +C 0 perform the first step. +C .gt.0 take a new step continuing from the last. +C -1 take the next step with a new value of H, MAXORD, +C N, METH, MITER, and/or matrix parameters. +C -2 take the next step with a new value of H, +C but with other inputs unchanged. +C On return, JSTART is set to 1 to facilitate continuation. +C KFLAG = a completion code with the following meanings: +C 0 the step was succesful. +C -1 the requested error could not be achieved. +C -2 corrector convergence could not be achieved. +C -3 fatal error in DPKSET or DSOLPK. +C A return with KFLAG = -1 or -2 means either +C ABS(H) = HMIN or 10 consecutive failures occurred. +C On a return with KFLAG negative, the values of TN and +C the YH array are as of the beginning of the last +C step, and H is the last step size attempted. +C MAXORD = the maximum order of integration method to be allowed. +C MAXCOR = the maximum number of corrector iterations allowed. +C MSBP = maximum number of steps between DPKSET calls (MITER .gt. 0). +C MXNCF = maximum number of convergence failures allowed. +C METH/MITER = the method flags. See description in driver. +C N = the number of first-order differential equations. +C----------------------------------------------------------------------- + INTEGER I, I1, IREDO, IRET, J, JB, M, NCF, NEWQ + DOUBLE PRECISION DCON, DDN, DEL, DELP, DSM, DUP, EXDN, EXSM, EXUP, + 1 R, RH, RHDN, RHSM, RHUP, TOLD, DVNORM +C + KFLAG = 0 + TOLD = TN + NCF = 0 + IERPJ = 0 + IERSL = 0 + JCUR = 0 + ICF = 0 + DELP = 0.0D0 + IF (JSTART .GT. 0) GO TO 200 + IF (JSTART .EQ. -1) GO TO 100 + IF (JSTART .EQ. -2) GO TO 160 +C----------------------------------------------------------------------- +C On the first call, the order is set to 1, and other variables are +C initialized. RMAX is the maximum ratio by which H can be increased +C in a single step. It is initially 1.E4 to compensate for the small +C initial H, but then is normally equal to 10. If a failure +C occurs (in corrector convergence or error test), RMAX is set at 2 +C for the next increase. +C----------------------------------------------------------------------- + LMAX = MAXORD + 1 + NQ = 1 + L = 2 + IALTH = 2 + RMAX = 10000.0D0 + RC = 0.0D0 + EL0 = 1.0D0 + CRATE = 0.7D0 + HOLD = H + MEO = METH + NSLP = 0 + IPUP = MITER + IRET = 3 + GO TO 140 +C----------------------------------------------------------------------- +C The following block handles preliminaries needed when JSTART = -1. +C IPUP is set to MITER to force a matrix update. +C If an order increase is about to be considered (IALTH = 1), +C IALTH is reset to 2 to postpone consideration one more step. +C If the caller has changed METH, DCFODE is called to reset +C the coefficients of the method. +C If the caller has changed MAXORD to a value less than the current +C order NQ, NQ is reduced to MAXORD, and a new H chosen accordingly. +C If H is to be changed, YH must be rescaled. +C If H or METH is being changed, IALTH is reset to L = NQ + 1 +C to prevent further changes in H for that many steps. +C----------------------------------------------------------------------- + 100 IPUP = MITER + LMAX = MAXORD + 1 + IF (IALTH .EQ. 1) IALTH = 2 + IF (METH .EQ. MEO) GO TO 110 + CALL DCFODE (METH, ELCO, TESCO) + MEO = METH + IF (NQ .GT. MAXORD) GO TO 120 + IALTH = L + IRET = 1 + GO TO 150 + 110 IF (NQ .LE. MAXORD) GO TO 160 + 120 NQ = MAXORD + L = LMAX + DO 125 I = 1,L + 125 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + EPCON = CONIT*TESCO(2,NQ) + DDN = DVNORM (N, SAVF, EWT)/TESCO(1,L) + EXDN = 1.0D0/L + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + RH = MIN(RHDN,1.0D0) + IREDO = 3 + IF (H .EQ. HOLD) GO TO 170 + RH = MIN(RH,ABS(H/HOLD)) + H = HOLD + GO TO 175 +C----------------------------------------------------------------------- +C DCFODE is called to get all the integration coefficients for the +C current METH. Then the EL vector and related constants are reset +C whenever the order NQ is changed, or at the start of the problem. +C----------------------------------------------------------------------- + 140 CALL DCFODE (METH, ELCO, TESCO) + 150 DO 155 I = 1,L + 155 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + EPCON = CONIT*TESCO(2,NQ) + GO TO (160, 170, 200), IRET +C----------------------------------------------------------------------- +C If H is being changed, the H ratio RH is checked against +C RMAX, HMIN, and HMXI, and the YH array rescaled. IALTH is set to +C L = NQ + 1 to prevent a change of H for that many steps, unless +C forced by a convergence or error test failure. +C----------------------------------------------------------------------- + 160 IF (H .EQ. HOLD) GO TO 200 + RH = H/HOLD + H = HOLD + IREDO = 3 + GO TO 175 + 170 RH = MAX(RH,HMIN/ABS(H)) + 175 RH = MIN(RH,RMAX) + RH = RH/MAX(1.0D0,ABS(H)*HMXI*RH) + R = 1.0D0 + DO 180 J = 2,L + R = R*RH + DO 180 I = 1,N + 180 YH(I,J) = YH(I,J)*R + H = H*RH + RC = RC*RH + IALTH = L + IF (IREDO .EQ. 0) GO TO 690 +C----------------------------------------------------------------------- +C This section computes the predicted values by effectively +C multiplying the YH array by the Pascal triangle matrix. +C The flag IPUP is set according to whether matrix data is involved +C (JACFLG .ne. 0) or not (JACFLG = 0), to trigger a call to DPKSET. +C IPUP is set to MITER when RC differs from 1 by more than CCMAX, +C and at least every MSBP steps, when JACFLG = 1. +C RC is the ratio of new to old values of the coefficient H*EL(1). +C----------------------------------------------------------------------- + 200 IF (JACFLG .NE. 0) GO TO 202 + IPUP = 0 + CRATE = 0.7D0 + GO TO 205 + 202 IF (ABS(RC-1.0D0) .GT. CCMAX) IPUP = MITER + IF (NST .GE. NSLP+MSBP) IPUP = MITER + 205 TN = TN + H + I1 = NQNYH + 1 + DO 215 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 210 I = I1,NQNYH + 210 YH1(I) = YH1(I) + YH1(I+NYH) + 215 CONTINUE +C----------------------------------------------------------------------- +C Up to MAXCOR corrector iterations are taken. A convergence test is +C made on the RMS-norm of each correction, weighted by the error +C weight vector EWT. The sum of the corrections is accumulated in the +C vector ACOR(i). The YH array is not altered in the corrector loop. +C----------------------------------------------------------------------- + 220 M = 0 + MNEWT = 0 + DO 230 I = 1,N + 230 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + IF (IPUP .LE. 0) GO TO 250 +C----------------------------------------------------------------------- +C If indicated, DPKSET is called to update any matrix data needed, +C before starting the corrector iteration. +C IPUP is set to 0 as an indicator that this has been done. +C----------------------------------------------------------------------- + CALL DPKSET (NEQ, Y, YH1, EWT, ACOR, SAVF, WM, IWM, F, JAC) + IPUP = 0 + RC = 1.0D0 + NSLP = NST + CRATE = 0.7D0 + IF (IERPJ .NE. 0) GO TO 430 + 250 DO 260 I = 1,N + 260 ACOR(I) = 0.0D0 + 270 IF (MITER .NE. 0) GO TO 350 +C----------------------------------------------------------------------- +C In the case of functional iteration, update Y directly from +C the result of the last function evaluation. +C----------------------------------------------------------------------- + DO 290 I = 1,N + SAVF(I) = H*SAVF(I) - YH(I,2) + 290 Y(I) = SAVF(I) - ACOR(I) + DEL = DVNORM (N, Y, EWT) + DO 300 I = 1,N + Y(I) = YH(I,1) + EL(1)*SAVF(I) + 300 ACOR(I) = SAVF(I) + GO TO 400 +C----------------------------------------------------------------------- +C In the case of the chord method, compute the corrector error, +C and solve the linear system with that as right-hand side and +C P as coefficient matrix. +C----------------------------------------------------------------------- + 350 DO 360 I = 1,N + 360 SAVX(I) = H*SAVF(I) - (YH(I,2) + ACOR(I)) + CALL DSOLPK (NEQ, Y, SAVF, SAVX, EWT, WM, IWM, F, PSOL) + IF (IERSL .LT. 0) GO TO 430 + IF (IERSL .GT. 0) GO TO 410 + DEL = DVNORM (N, SAVX, EWT) + DO 380 I = 1,N + ACOR(I) = ACOR(I) + SAVX(I) + 380 Y(I) = YH(I,1) + EL(1)*ACOR(I) +C----------------------------------------------------------------------- +C Test for convergence. If M .gt. 0, an estimate of the convergence +C rate constant is stored in CRATE, and this is used in the test. +C----------------------------------------------------------------------- + 400 IF (M .NE. 0) CRATE = MAX(0.2D0*CRATE,DEL/DELP) + DCON = DEL*MIN(1.0D0,1.5D0*CRATE)/EPCON + IF (DCON .LE. 1.0D0) GO TO 450 + M = M + 1 + IF (M .EQ. MAXCOR) GO TO 410 + IF (M .GE. 2 .AND. DEL .GT. 2.0D0*DELP) GO TO 410 + MNEWT = M + DELP = DEL + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + GO TO 270 +C----------------------------------------------------------------------- +C The corrector iteration failed to converge. +C If MITER .ne. 0 and the Jacobian is out of date, DPKSET is called for +C the next try. Otherwise the YH array is retracted to its values +C before prediction, and H is reduced, if possible. If H cannot be +C reduced or MXNCF failures have occurred, exit with KFLAG = -2. +C----------------------------------------------------------------------- + 410 IF (MITER.EQ.0 .OR. JCUR.EQ.1 .OR. JACFLG.EQ.0) GO TO 430 + ICF = 1 + IPUP = MITER + GO TO 220 + 430 ICF = 2 + NCF = NCF + 1 + NCFN = NCFN + 1 + RMAX = 2.0D0 + TN = TOLD + I1 = NQNYH + 1 + DO 445 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 440 I = I1,NQNYH + 440 YH1(I) = YH1(I) - YH1(I+NYH) + 445 CONTINUE + IF (IERPJ .LT. 0 .OR. IERSL .LT. 0) GO TO 680 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 670 + IF (NCF .EQ. MXNCF) GO TO 670 + RH = 0.5D0 + IPUP = MITER + IREDO = 1 + GO TO 170 +C----------------------------------------------------------------------- +C The corrector has converged. JCUR is set to 0 +C to signal that the Jacobian involved may need updating later. +C The local error test is made and control passes to statement 500 +C if it fails. +C----------------------------------------------------------------------- + 450 JCUR = 0 + IF (M .EQ. 0) DSM = DEL/TESCO(2,NQ) + IF (M .GT. 0) DSM = DVNORM (N, ACOR, EWT)/TESCO(2,NQ) + IF (DSM .GT. 1.0D0) GO TO 500 +C----------------------------------------------------------------------- +C After a successful step, update the YH array. +C Consider changing H if IALTH = 1. Otherwise decrease IALTH by 1. +C If IALTH is then 1 and NQ .lt. MAXORD, then ACOR is saved for +C use in a possible order increase on the next step. +C If a change in H is considered, an increase or decrease in order +C by one is considered also. A change in H is made only if it is by a +C factor of at least 1.1. If not, IALTH is set to 3 to prevent +C testing for that many steps. +C----------------------------------------------------------------------- + KFLAG = 0 + IREDO = 0 + NST = NST + 1 + HU = H + NQU = NQ + DO 470 J = 1,L + DO 470 I = 1,N + 470 YH(I,J) = YH(I,J) + EL(J)*ACOR(I) + IALTH = IALTH - 1 + IF (IALTH .EQ. 0) GO TO 520 + IF (IALTH .GT. 1) GO TO 700 + IF (L .EQ. LMAX) GO TO 700 + DO 490 I = 1,N + 490 YH(I,LMAX) = ACOR(I) + GO TO 700 +C----------------------------------------------------------------------- +C The error test failed. KFLAG keeps track of multiple failures. +C Restore TN and the YH array to their previous values, and prepare +C to try the step again. Compute the optimum step size for this or +C one lower order. After 2 or more failures, H is forced to decrease +C by a factor of 0.2 or less. +C----------------------------------------------------------------------- + 500 KFLAG = KFLAG - 1 + TN = TOLD + I1 = NQNYH + 1 + DO 515 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 510 I = I1,NQNYH + 510 YH1(I) = YH1(I) - YH1(I+NYH) + 515 CONTINUE + RMAX = 2.0D0 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 660 + IF (KFLAG .LE. -3) GO TO 640 + IREDO = 2 + RHUP = 0.0D0 + GO TO 540 +C----------------------------------------------------------------------- +C Regardless of the success or failure of the step, factors +C RHDN, RHSM, and RHUP are computed, by which H could be multiplied +C at order NQ - 1, order NQ, or order NQ + 1, respectively. +C In the case of failure, RHUP = 0.0 to avoid an order increase. +C the largest of these is determined and the new order chosen +C accordingly. If the order is to be increased, we compute one +C additional scaled derivative. +C----------------------------------------------------------------------- + 520 RHUP = 0.0D0 + IF (L .EQ. LMAX) GO TO 540 + DO 530 I = 1,N + 530 SAVF(I) = ACOR(I) - YH(I,LMAX) + DUP = DVNORM (N, SAVF, EWT)/TESCO(3,NQ) + EXUP = 1.0D0/(L+1) + RHUP = 1.0D0/(1.4D0*DUP**EXUP + 0.0000014D0) + 540 EXSM = 1.0D0/L + RHSM = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RHDN = 0.0D0 + IF (NQ .EQ. 1) GO TO 560 + DDN = DVNORM (N, YH(1,L), EWT)/TESCO(1,NQ) + EXDN = 1.0D0/NQ + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + 560 IF (RHSM .GE. RHUP) GO TO 570 + IF (RHUP .GT. RHDN) GO TO 590 + GO TO 580 + 570 IF (RHSM .LT. RHDN) GO TO 580 + NEWQ = NQ + RH = RHSM + GO TO 620 + 580 NEWQ = NQ - 1 + RH = RHDN + IF (KFLAG .LT. 0 .AND. RH .GT. 1.0D0) RH = 1.0D0 + GO TO 620 + 590 NEWQ = L + RH = RHUP + IF (RH .LT. 1.1D0) GO TO 610 + R = EL(L)/L + DO 600 I = 1,N + 600 YH(I,NEWQ+1) = ACOR(I)*R + GO TO 630 + 610 IALTH = 3 + GO TO 700 + 620 IF ((KFLAG .EQ. 0) .AND. (RH .LT. 1.1D0)) GO TO 610 + IF (KFLAG .LE. -2) RH = MIN(RH,0.2D0) +C----------------------------------------------------------------------- +C If there is a change of order, reset NQ, L, and the coefficients. +C In any case H is reset according to RH and the YH array is rescaled. +C Then exit from 690 if the step was OK, or redo the step otherwise. +C----------------------------------------------------------------------- + IF (NEWQ .EQ. NQ) GO TO 170 + 630 NQ = NEWQ + L = NQ + 1 + IRET = 2 + GO TO 150 +C----------------------------------------------------------------------- +C Control reaches this section if 3 or more failures have occured. +C If 10 failures have occurred, exit with KFLAG = -1. +C It is assumed that the derivatives that have accumulated in the +C YH array have errors of the wrong order. Hence the first +C derivative is recomputed, and the order is set to 1. Then +C H is reduced by a factor of 10, and the step is retried, +C until it succeeds or H reaches HMIN. +C----------------------------------------------------------------------- + 640 IF (KFLAG .EQ. -10) GO TO 660 + RH = 0.1D0 + RH = MAX(HMIN/ABS(H),RH) + H = H*RH + DO 645 I = 1,N + 645 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + DO 650 I = 1,N + 650 YH(I,2) = H*SAVF(I) + IPUP = MITER + IALTH = 5 + IF (NQ .EQ. 1) GO TO 200 + NQ = 1 + L = 2 + IRET = 3 + GO TO 150 +C----------------------------------------------------------------------- +C All returns are made through this section. H is saved in HOLD +C to allow the caller to change H on the next step. +C----------------------------------------------------------------------- + 660 KFLAG = -1 + GO TO 720 + 670 KFLAG = -2 + GO TO 720 + 680 KFLAG = -3 + GO TO 720 + 690 RMAX = 10.0D0 + 700 R = 1.0D0/TESCO(2,NQU) + DO 710 I = 1,N + 710 ACOR(I) = ACOR(I)*R + 720 HOLD = H + JSTART = 1 + RETURN +C----------------------- End of Subroutine DSTODPK --------------------- + END +*DECK DPKSET + SUBROUTINE DPKSET (NEQ, Y, YSV, EWT, FTEM, SAVF, WM, IWM, F, JAC) + EXTERNAL F, JAC + INTEGER NEQ, IWM + DOUBLE PRECISION Y, YSV, EWT, FTEM, SAVF, WM + DIMENSION NEQ(*), Y(*), YSV(*), EWT(*), FTEM(*), SAVF(*), + 1 WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C----------------------------------------------------------------------- +C DPKSET is called by DSTODPK to interface with the user-supplied +C routine JAC, to compute and process relevant parts of +C the matrix P = I - H*EL(1)*J , where J is the Jacobian df/dy, +C as need for preconditioning matrix operations later. +C +C In addition to variables described previously, communication +C with DPKSET uses the following: +C Y = array containing predicted values on entry. +C YSV = array containing predicted y, to be saved (YH1 in DSTODPK). +C FTEM = work array of length N (ACOR in DSTODPK). +C SAVF = array containing f evaluated at predicted y. +C WM = real work space for matrices. +C Space for preconditioning data starts at WM(LOCWP). +C IWM = integer work space. +C Space for preconditioning data starts at IWM(LOCIWP). +C IERPJ = output error flag, = 0 if no trouble, .gt. 0 if +C JAC returned an error flag. +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses Common variables EL0, H, TN, IERPJ, JCUR, NJE. +C----------------------------------------------------------------------- + INTEGER IER + DOUBLE PRECISION HL0 +C + IERPJ = 0 + JCUR = 1 + HL0 = EL0*H + CALL JAC (F, NEQ, TN, Y, YSV, EWT, SAVF, FTEM, HL0, + 1 WM(LOCWP), IWM(LOCIWP), IER) + NJE = NJE + 1 + IF (IER .EQ. 0) RETURN + IERPJ = 1 + RETURN +C----------------------- End of Subroutine DPKSET ---------------------- + END +*DECK DSOLPK + SUBROUTINE DSOLPK (NEQ, Y, SAVF, X, EWT, WM, IWM, F, PSOL) + EXTERNAL F, PSOL + INTEGER NEQ, IWM + DOUBLE PRECISION Y, SAVF, X, EWT, WM + DIMENSION NEQ(*), Y(*), SAVF(*), X(*), EWT(*), WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C----------------------------------------------------------------------- +C This routine interfaces to one of DSPIOM, DSPIGMR, DPCG, DPCGS, or +C DUSOL, for the solution of the linear system arising from a Newton +C iteration. It is called if MITER .ne. 0. +C In addition to variables described elsewhere, +C communication with DSOLPK uses the following variables: +C WM = real work space containing data for the algorithm +C (Krylov basis vectors, Hessenberg matrix, etc.) +C IWM = integer work space containing data for the algorithm +C X = the right-hand side vector on input, and the solution vector +C on output, of length N. +C IERSL = output flag (in Common): +C IERSL = 0 means no trouble occurred. +C IERSL = 1 means the iterative method failed to converge. +C If the preconditioner is out of date, the step +C is repeated with a new preconditioner. +C Otherwise, the stepsize is reduced (forcing a +C new evaluation of the preconditioner) and the +C step is repeated. +C IERSL = -1 means there was a nonrecoverable error in the +C iterative solver, and an error exit occurs. +C This routine also uses the Common variables TN, EL0, H, N, MITER, +C DELT, EPCON, SQRTN, RSQRTN, MAXL, KMP, MNEWT, NNI, NLI, NPS, NCFL, +C LOCWP, LOCIWP. +C----------------------------------------------------------------------- + INTEGER IFLAG, LB, LDL, LHES, LIOM, LGMR, LPCG, LP, LQ, LR, + 1 LV, LW, LWK, LZ, MAXLP1, NPSL + DOUBLE PRECISION DELTA, HL0 +C + IERSL = 0 + HL0 = H*EL0 + DELTA = DELT*EPCON + GO TO (100, 200, 300, 400, 900, 900, 900, 900, 900), MITER +C----------------------------------------------------------------------- +C Use the SPIOM algorithm to solve the linear system P*x = -f. +C----------------------------------------------------------------------- + 100 CONTINUE + LV = 1 + LB = LV + N*MAXL + LHES = LB + N + LWK = LHES + MAXL*MAXL + CALL DCOPY (N, X, 1, WM(LB), 1) + CALL DSCAL (N, RSQRTN, EWT, 1) + CALL DSPIOM (NEQ, TN, Y, SAVF, WM(LB), EWT, N, MAXL, KMP, DELTA, + 1 HL0, JPRE, MNEWT, F, PSOL, NPSL, X, WM(LV), WM(LHES), IWM, + 2 LIOM, WM(LOCWP), IWM(LOCIWP), WM(LWK), IFLAG) + NNI = NNI + 1 + NLI = NLI + LIOM + NPS = NPS + NPSL + CALL DSCAL (N, SQRTN, EWT, 1) + IF (IFLAG .NE. 0) NCFL = NCFL + 1 + IF (IFLAG .GE. 2) IERSL = 1 + IF (IFLAG .LT. 0) IERSL = -1 + RETURN +C----------------------------------------------------------------------- +C Use the SPIGMR algorithm to solve the linear system P*x = -f. +C----------------------------------------------------------------------- + 200 CONTINUE + MAXLP1 = MAXL + 1 + LV = 1 + LB = LV + N*MAXL + LHES = LB + N + 1 + LQ = LHES + MAXL*MAXLP1 + LWK = LQ + 2*MAXL + LDL = LWK + MIN(1,MAXL-KMP)*N + CALL DCOPY (N, X, 1, WM(LB), 1) + CALL DSCAL (N, RSQRTN, EWT, 1) + CALL DSPIGMR (NEQ, TN, Y, SAVF, WM(LB), EWT, N, MAXL, MAXLP1, KMP, + 1 DELTA, HL0, JPRE, MNEWT, F, PSOL, NPSL, X, WM(LV), WM(LHES), + 2 WM(LQ), LGMR, WM(LOCWP), IWM(LOCIWP), WM(LWK), WM(LDL), IFLAG) + NNI = NNI + 1 + NLI = NLI + LGMR + NPS = NPS + NPSL + CALL DSCAL (N, SQRTN, EWT, 1) + IF (IFLAG .NE. 0) NCFL = NCFL + 1 + IF (IFLAG .GE. 2) IERSL = 1 + IF (IFLAG .LT. 0) IERSL = -1 + RETURN +C----------------------------------------------------------------------- +C Use DPCG to solve the linear system P*x = -f +C----------------------------------------------------------------------- + 300 CONTINUE + LR = 1 + LP = LR + N + LW = LP + N + LZ = LW + N + LWK = LZ + N + CALL DCOPY (N, X, 1, WM(LR), 1) + CALL DPCG (NEQ, TN, Y, SAVF, WM(LR), EWT, N, MAXL, DELTA, HL0, + 1 JPRE, MNEWT, F, PSOL, NPSL, X, WM(LP), WM(LW), WM(LZ), + 2 LPCG, WM(LOCWP), IWM(LOCIWP), WM(LWK), IFLAG) + NNI = NNI + 1 + NLI = NLI + LPCG + NPS = NPS + NPSL + IF (IFLAG .NE. 0) NCFL = NCFL + 1 + IF (IFLAG .GE. 2) IERSL = 1 + IF (IFLAG .LT. 0) IERSL = -1 + RETURN +C----------------------------------------------------------------------- +C Use DPCGS to solve the linear system P*x = -f +C----------------------------------------------------------------------- + 400 CONTINUE + LR = 1 + LP = LR + N + LW = LP + N + LZ = LW + N + LWK = LZ + N + CALL DCOPY (N, X, 1, WM(LR), 1) + CALL DPCGS (NEQ, TN, Y, SAVF, WM(LR), EWT, N, MAXL, DELTA, HL0, + 1 JPRE, MNEWT, F, PSOL, NPSL, X, WM(LP), WM(LW), WM(LZ), + 2 LPCG, WM(LOCWP), IWM(LOCIWP), WM(LWK), IFLAG) + NNI = NNI + 1 + NLI = NLI + LPCG + NPS = NPS + NPSL + IF (IFLAG .NE. 0) NCFL = NCFL + 1 + IF (IFLAG .GE. 2) IERSL = 1 + IF (IFLAG .LT. 0) IERSL = -1 + RETURN +C----------------------------------------------------------------------- +C Use DUSOL, which interfaces to PSOL, to solve the linear system +C (no Krylov iteration). +C----------------------------------------------------------------------- + 900 CONTINUE + LB = 1 + LWK = LB + N + CALL DCOPY (N, X, 1, WM(LB), 1) + CALL DUSOL (NEQ, TN, Y, SAVF, WM(LB), EWT, N, DELTA, HL0, MNEWT, + 1 PSOL, NPSL, X, WM(LOCWP), IWM(LOCIWP), WM(LWK), IFLAG) + NNI = NNI + 1 + NPS = NPS + NPSL + IF (IFLAG .NE. 0) NCFL = NCFL + 1 + IF (IFLAG .EQ. 3) IERSL = 1 + IF (IFLAG .LT. 0) IERSL = -1 + RETURN +C----------------------- End of Subroutine DSOLPK ---------------------- + END +*DECK DSPIOM + SUBROUTINE DSPIOM (NEQ, TN, Y, SAVF, B, WGHT, N, MAXL, KMP, DELTA, + 1 HL0, JPRE, MNEWT, F, PSOL, NPSL, X, V, HES, IPVT, + 2 LIOM, WP, IWP, WK, IFLAG) + EXTERNAL F, PSOL + INTEGER NEQ,N,MAXL,KMP,JPRE,MNEWT,NPSL,IPVT,LIOM,IWP,IFLAG + DOUBLE PRECISION TN,Y,SAVF,B,WGHT,DELTA,HL0,X,V,HES,WP,WK + DIMENSION NEQ(*), Y(*), SAVF(*), B(*), WGHT(*), X(*), V(N,*), + 1 HES(MAXL,MAXL), IPVT(*), WP(*), IWP(*), WK(*) +C----------------------------------------------------------------------- +C This routine solves the linear system A * x = b using a scaled +C preconditioned version of the Incomplete Orthogonalization Method. +C An initial guess of x = 0 is assumed. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C TN = current value of t. +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C B = the right hand side of the system A*x = b. +C B is also used as work space when computing the +C final approximation. +C (B is the same as V(*,MAXL+1) in the call to DSPIOM.) +C +C WGHT = array of length N containing scale factors. +C 1/WGHT(i) are the diagonal elements of the diagonal +C scaling matrix D. +C +C N = the order of the matrix A, and the lengths +C of the vectors Y, SAVF, B, WGHT, and X. +C +C MAXL = the maximum allowable order of the matrix HES. +C +C KMP = the number of previous vectors the new vector VNEW +C must be made orthogonal to. KMP .le. MAXL. +C +C DELTA = tolerance on residuals b - A*x in weighted RMS-norm. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C JPRE = preconditioner type flag. +C +C MNEWT = Newton iteration counter (.ge. 0). +C +C WK = real work array of length N used by DATV and PSOL. +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C On return +C +C X = the final computed approximation to the solution +C of the system A*x = b. +C +C V = the N by (LIOM+1) array containing the LIOM +C orthogonal vectors V(*,1) to V(*,LIOM). +C +C HES = the LU factorization of the LIOM by LIOM upper +C Hessenberg matrix whose entries are the +C scaled inner products of A*V(*,k) and V(*,i). +C +C IPVT = an integer array containg pivoting information. +C It is loaded in DHEFA and used in DHESL. +C +C LIOM = the number of iterations performed, and current +C order of the upper Hessenberg matrix HES. +C +C NPSL = the number of calls to PSOL. +C +C IFLAG = integer error flag: +C 0 means convergence in LIOM iterations, LIOM.le.MAXL. +C 1 means the convergence test did not pass in MAXL +C iterations, but the residual norm is .lt. 1, +C or .lt. norm(b) if MNEWT = 0, and so X is computed. +C 2 means the convergence test did not pass in MAXL +C iterations, residual .gt. 1, and X is undefined. +C 3 means there was a recoverable error in PSOL +C caused by the preconditioner being out of date. +C -1 means there was a nonrecoverable error in PSOL. +C +C----------------------------------------------------------------------- + INTEGER I, IER, INFO, J, K, LL, LM1 + DOUBLE PRECISION BNRM, BNRM0, PROD, RHO, SNORMW, DNRM2, TEM +C + IFLAG = 0 + LIOM = 0 + NPSL = 0 +C----------------------------------------------------------------------- +C The initial residual is the vector b. Apply scaling to b, and test +C for an immediate return with X = 0 or X = b. +C----------------------------------------------------------------------- + DO 10 I = 1,N + 10 V(I,1) = B(I)*WGHT(I) + BNRM0 = DNRM2 (N, V, 1) + BNRM = BNRM0 + IF (BNRM0 .GT. DELTA) GO TO 30 + IF (MNEWT .GT. 0) GO TO 20 + CALL DCOPY (N, B, 1, X, 1) + RETURN + 20 DO 25 I = 1,N + 25 X(I) = 0.0D0 + RETURN + 30 CONTINUE +C Apply inverse of left preconditioner to vector b. -------------------- + IER = 0 + IF (JPRE .EQ. 0 .OR. JPRE .EQ. 2) GO TO 55 + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, B, 1, IER) + NPSL = 1 + IF (IER .NE. 0) GO TO 300 +C Calculate norm of scaled vector V(*,1) and normalize it. ------------- + DO 50 I = 1,N + 50 V(I,1) = B(I)*WGHT(I) + BNRM = DNRM2(N, V, 1) + DELTA = DELTA*(BNRM/BNRM0) + 55 TEM = 1.0D0/BNRM + CALL DSCAL (N, TEM, V(1,1), 1) +C Zero out the HES array. ---------------------------------------------- + DO 65 J = 1,MAXL + DO 60 I = 1,MAXL + 60 HES(I,J) = 0.0D0 + 65 CONTINUE +C----------------------------------------------------------------------- +C Main loop on LL = l to compute the vectors V(*,2) to V(*,MAXL). +C The running product PROD is needed for the convergence test. +C----------------------------------------------------------------------- + PROD = 1.0D0 + DO 90 LL = 1,MAXL + LIOM = LL +C----------------------------------------------------------------------- +C Call routine DATV to compute VNEW = Abar*v(l), where Abar is +C the matrix A with scaling and inverse preconditioner factors applied. +C Call routine DORTHOG to orthogonalize the new vector vnew = V(*,l+1). +C Call routine DHEFA to update the factors of HES. +C----------------------------------------------------------------------- + CALL DATV (NEQ, Y, SAVF, V(1,LL), WGHT, X, F, PSOL, V(1,LL+1), + 1 WK, WP, IWP, HL0, JPRE, IER, NPSL) + IF (IER .NE. 0) GO TO 300 + CALL DORTHOG (V(1,LL+1), V, HES, N, LL, MAXL, KMP, SNORMW) + CALL DHEFA (HES, MAXL, LL, IPVT, INFO, LL) + LM1 = LL - 1 + IF (LL .GT. 1 .AND. IPVT(LM1) .EQ. LM1) PROD = PROD*HES(LL,LM1) + IF (INFO .NE. LL) GO TO 70 +C----------------------------------------------------------------------- +C The last pivot in HES was found to be zero. +C If vnew = 0 or l = MAXL, take an error return with IFLAG = 2. +C otherwise, continue the iteration without a convergence test. +C----------------------------------------------------------------------- + IF (SNORMW .EQ. 0.0D0) GO TO 120 + IF (LL .EQ. MAXL) GO TO 120 + GO TO 80 +C----------------------------------------------------------------------- +C Update RHO, the estimate of the norm of the residual b - A*x(l). +C test for convergence. If passed, compute approximation x(l). +C If failed and l .lt. MAXL, then continue iterating. +C----------------------------------------------------------------------- + 70 CONTINUE + RHO = BNRM*SNORMW*ABS(PROD/HES(LL,LL)) + IF (RHO .LE. DELTA) GO TO 200 + IF (LL .EQ. MAXL) GO TO 100 +C If l .lt. MAXL, store HES(l+1,l) and normalize the vector v(*,l+1). + 80 CONTINUE + HES(LL+1,LL) = SNORMW + TEM = 1.0D0/SNORMW + CALL DSCAL (N, TEM, V(1,LL+1), 1) + 90 CONTINUE +C----------------------------------------------------------------------- +C l has reached MAXL without passing the convergence test: +C If RHO is not too large, compute a solution anyway and return with +C IFLAG = 1. Otherwise return with IFLAG = 2. +C----------------------------------------------------------------------- + 100 CONTINUE + IF (RHO .LE. 1.0D0) GO TO 150 + IF (RHO .LE. BNRM .AND. MNEWT .EQ. 0) GO TO 150 + 120 CONTINUE + IFLAG = 2 + RETURN + 150 IFLAG = 1 +C----------------------------------------------------------------------- +C Compute the approximation x(l) to the solution. +C Since the vector X was used as work space, and the initial guess +C of the Newton correction is zero, X must be reset to zero. +C----------------------------------------------------------------------- + 200 CONTINUE + LL = LIOM + DO 210 K = 1,LL + 210 B(K) = 0.0D0 + B(1) = BNRM + CALL DHESL (HES, MAXL, LL, IPVT, B) + DO 220 K = 1,N + 220 X(K) = 0.0D0 + DO 230 I = 1,LL + CALL DAXPY (N, B(I), V(1,I), 1, X, 1) + 230 CONTINUE + DO 240 I = 1,N + 240 X(I) = X(I)/WGHT(I) + IF (JPRE .LE. 1) RETURN + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, X, 2, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) GO TO 300 + RETURN +C----------------------------------------------------------------------- +C This block handles error returns forced by routine PSOL. +C----------------------------------------------------------------------- + 300 CONTINUE + IF (IER .LT. 0) IFLAG = -1 + IF (IER .GT. 0) IFLAG = 3 + RETURN +C----------------------- End of Subroutine DSPIOM ---------------------- + END +*DECK DATV + SUBROUTINE DATV (NEQ, Y, SAVF, V, WGHT, FTEM, F, PSOL, Z, VTEM, + 1 WP, IWP, HL0, JPRE, IER, NPSL) + EXTERNAL F, PSOL + INTEGER NEQ, IWP, JPRE, IER, NPSL + DOUBLE PRECISION Y, SAVF, V, WGHT, FTEM, Z, VTEM, WP, HL0 + DIMENSION NEQ(*), Y(*), SAVF(*), V(*), WGHT(*), FTEM(*), Z(*), + 1 VTEM(*), WP(*), IWP(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C----------------------------------------------------------------------- +C This routine computes the product +C +C (D-inverse)*(P1-inverse)*(I - hl0*df/dy)*(P2-inverse)*(D*v), +C +C where D is a diagonal scaling matrix, and P1 and P2 are the +C left and right preconditioning matrices, respectively. +C v is assumed to have WRMS norm equal to 1. +C The product is stored in z. This is computed by a +C difference quotient, a call to F, and two calls to PSOL. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C V = real array of length N (can be the same array as Z). +C +C WGHT = array of length N containing scale factors. +C 1/WGHT(i) are the diagonal elements of the matrix D. +C +C FTEM = work array of length N. +C +C VTEM = work array of length N used to store the +C unscaled version of V. +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C JPRE = preconditioner type flag. +C +C +C On return +C +C Z = array of length N containing desired scaled +C matrix-vector product. +C +C IER = error flag from PSOL. +C +C NPSL = the number of calls to PSOL. +C +C In addition, this routine uses the Common variables TN, N, NFE. +C----------------------------------------------------------------------- + INTEGER I + DOUBLE PRECISION FAC, RNORM, DNRM2, TEMPN +C +C Set VTEM = D * V. + DO 10 I = 1,N + 10 VTEM(I) = V(I)/WGHT(I) + IER = 0 + IF (JPRE .GE. 2) GO TO 30 +C +C JPRE = 0 or 1. Save Y in Z and increment Y by VTEM. + CALL DCOPY (N, Y, 1, Z, 1) + DO 20 I = 1,N + 20 Y(I) = Z(I) + VTEM(I) + FAC = HL0 + GO TO 60 +C +C JPRE = 2 or 3. Apply inverse of right preconditioner to VTEM. + 30 CONTINUE + CALL PSOL (NEQ, TN, Y, SAVF, FTEM, HL0, WP, IWP, VTEM, 2, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) RETURN +C Calculate L-2 norm of (D-inverse) * VTEM. + DO 40 I = 1,N + 40 Z(I) = VTEM(I)*WGHT(I) + TEMPN = DNRM2 (N, Z, 1) + RNORM = 1.0D0/TEMPN +C Save Y in Z and increment Y by VTEM/norm. + CALL DCOPY (N, Y, 1, Z, 1) + DO 50 I = 1,N + 50 Y(I) = Z(I) + VTEM(I)*RNORM + FAC = HL0*TEMPN +C +C For all JPRE, call F with incremented Y argument, and restore Y. + 60 CONTINUE + CALL F (NEQ, TN, Y, FTEM) + NFE = NFE + 1 + CALL DCOPY (N, Z, 1, Y, 1) +C Set Z = (identity - hl0*Jacobian) * VTEM, using difference quotient. + DO 70 I = 1,N + 70 Z(I) = FTEM(I) - SAVF(I) + DO 80 I = 1,N + 80 Z(I) = VTEM(I) - FAC*Z(I) +C Apply inverse of left preconditioner to Z, if nontrivial. + IF (JPRE .EQ. 0 .OR. JPRE .EQ. 2) GO TO 85 + CALL PSOL (NEQ, TN, Y, SAVF, FTEM, HL0, WP, IWP, Z, 1, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) RETURN + 85 CONTINUE +C Apply D-inverse to Z and return. + DO 90 I = 1,N + 90 Z(I) = Z(I)*WGHT(I) + RETURN +C----------------------- End of Subroutine DATV ------------------------ + END +*DECK DORTHOG + SUBROUTINE DORTHOG (VNEW, V, HES, N, LL, LDHES, KMP, SNORMW) + INTEGER N, LL, LDHES, KMP + DOUBLE PRECISION VNEW, V, HES, SNORMW + DIMENSION VNEW(*), V(N,*), HES(LDHES,*) +C----------------------------------------------------------------------- +C This routine orthogonalizes the vector VNEW against the previous +C KMP vectors in the V array. It uses a modified Gram-Schmidt +C orthogonalization procedure with conditional reorthogonalization. +C This is the version of 28 may 1986. +C----------------------------------------------------------------------- +C +C On entry +C +C VNEW = the vector of length N containing a scaled product +C of the Jacobian and the vector V(*,LL). +C +C V = the N x l array containing the previous LL +C orthogonal vectors v(*,1) to v(*,LL). +C +C HES = an LL x LL upper Hessenberg matrix containing, +C in HES(i,k), k.lt.LL, scaled inner products of +C A*V(*,k) and V(*,i). +C +C LDHES = the leading dimension of the HES array. +C +C N = the order of the matrix A, and the length of VNEW. +C +C LL = the current order of the matrix HES. +C +C KMP = the number of previous vectors the new vector VNEW +C must be made orthogonal to (KMP .le. MAXL). +C +C +C On return +C +C VNEW = the new vector orthogonal to V(*,i0) to V(*,LL), +C where i0 = MAX(1, LL-KMP+1). +C +C HES = upper Hessenberg matrix with column LL filled in with +C scaled inner products of A*V(*,LL) and V(*,i). +C +C SNORMW = L-2 norm of VNEW. +C +C----------------------------------------------------------------------- + INTEGER I, I0 + DOUBLE PRECISION ARG, DDOT, DNRM2, SUMDSQ, TEM, VNRM +C +C Get norm of unaltered VNEW for later use. ---------------------------- + VNRM = DNRM2 (N, VNEW, 1) +C----------------------------------------------------------------------- +C Do modified Gram-Schmidt on VNEW = A*v(LL). +C Scaled inner products give new column of HES. +C Projections of earlier vectors are subtracted from VNEW. +C----------------------------------------------------------------------- + I0 = MAX(1,LL-KMP+1) + DO 10 I = I0,LL + HES(I,LL) = DDOT (N, V(1,I), 1, VNEW, 1) + TEM = -HES(I,LL) + CALL DAXPY (N, TEM, V(1,I), 1, VNEW, 1) + 10 CONTINUE +C----------------------------------------------------------------------- +C Compute SNORMW = norm of VNEW. +C If VNEW is small compared to its input value (in norm), then +C reorthogonalize VNEW to V(*,1) through V(*,LL). +C Correct if relative correction exceeds 1000*(unit roundoff). +C finally, correct SNORMW using the dot products involved. +C----------------------------------------------------------------------- + SNORMW = DNRM2 (N, VNEW, 1) + IF (VNRM + 0.001D0*SNORMW .NE. VNRM) RETURN + SUMDSQ = 0.0D0 + DO 30 I = I0,LL + TEM = -DDOT (N, V(1,I), 1, VNEW, 1) + IF (HES(I,LL) + 0.001D0*TEM .EQ. HES(I,LL)) GO TO 30 + HES(I,LL) = HES(I,LL) - TEM + CALL DAXPY (N, TEM, V(1,I), 1, VNEW, 1) + SUMDSQ = SUMDSQ + TEM**2 + 30 CONTINUE + IF (SUMDSQ .EQ. 0.0D0) RETURN + ARG = MAX(0.0D0,SNORMW**2 - SUMDSQ) + SNORMW = SQRT(ARG) +C + RETURN +C----------------------- End of Subroutine DORTHOG --------------------- + END +*DECK DSPIGMR + SUBROUTINE DSPIGMR (NEQ, TN, Y, SAVF, B, WGHT, N, MAXL, MAXLP1, + 1 KMP, DELTA, HL0, JPRE, MNEWT, F, PSOL, NPSL, X, V, HES, Q, + 2 LGMR, WP, IWP, WK, DL, IFLAG) + EXTERNAL F, PSOL + INTEGER NEQ,N,MAXL,MAXLP1,KMP,JPRE,MNEWT,NPSL,LGMR,IWP,IFLAG + DOUBLE PRECISION TN,Y,SAVF,B,WGHT,DELTA,HL0,X,V,HES,Q,WP,WK,DL + DIMENSION NEQ(*), Y(*), SAVF(*), B(*), WGHT(*), X(*), V(N,*), + 1 HES(MAXLP1,*), Q(*), WP(*), IWP(*), WK(*), DL(*) +C----------------------------------------------------------------------- +C This routine solves the linear system A * x = b using a scaled +C preconditioned version of the Generalized Minimal Residual method. +C An initial guess of x = 0 is assumed. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C TN = current value of t. +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C B = the right hand side of the system A*x = b. +C B is also used as work space when computing +C the final approximation. +C (B is the same as V(*,MAXL+1) in the call to DSPIGMR.) +C +C WGHT = the vector of length N containing the nonzero +C elements of the diagonal scaling matrix. +C +C N = the order of the matrix A, and the lengths +C of the vectors WGHT, B and X. +C +C MAXL = the maximum allowable order of the matrix HES. +C +C MAXLP1 = MAXL + 1, used for dynamic dimensioning of HES. +C +C KMP = the number of previous vectors the new vector VNEW +C must be made orthogonal to. KMP .le. MAXL. +C +C DELTA = tolerance on residuals b - A*x in weighted RMS-norm. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C JPRE = preconditioner type flag. +C +C MNEWT = Newton iteration counter (.ge. 0). +C +C WK = real work array used by routine DATV and PSOL. +C +C DL = real work array used for calculation of the residual +C norm RHO when the method is incomplete (KMP .lt. MAXL). +C Not needed or referenced in complete case (KMP = MAXL). +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C On return +C +C X = the final computed approximation to the solution +C of the system A*x = b. +C +C LGMR = the number of iterations performed and +C the current order of the upper Hessenberg +C matrix HES. +C +C NPSL = the number of calls to PSOL. +C +C V = the N by (LGMR+1) array containing the LGMR +C orthogonal vectors V(*,1) to V(*,LGMR). +C +C HES = the upper triangular factor of the QR decomposition +C of the (LGMR+1) by lgmr upper Hessenberg matrix whose +C entries are the scaled inner-products of A*V(*,i) +C and V(*,k). +C +C Q = real array of length 2*MAXL containing the components +C of the Givens rotations used in the QR decomposition +C of HES. It is loaded in DHEQR and used in DHELS. +C +C IFLAG = integer error flag: +C 0 means convergence in LGMR iterations, LGMR .le. MAXL. +C 1 means the convergence test did not pass in MAXL +C iterations, but the residual norm is .lt. 1, +C or .lt. norm(b) if MNEWT = 0, and so x is computed. +C 2 means the convergence test did not pass in MAXL +C iterations, residual .gt. 1, and X is undefined. +C 3 means there was a recoverable error in PSOL +C caused by the preconditioner being out of date. +C -1 means there was a nonrecoverable error in PSOL. +C +C----------------------------------------------------------------------- + INTEGER I, IER, INFO, IP1, I2, J, K, LL, LLP1 + DOUBLE PRECISION BNRM,BNRM0,C,DLNRM,PROD,RHO,S,SNORMW,DNRM2,TEM +C + IFLAG = 0 + LGMR = 0 + NPSL = 0 +C----------------------------------------------------------------------- +C The initial residual is the vector b. Apply scaling to b, and test +C for an immediate return with X = 0 or X = b. +C----------------------------------------------------------------------- + DO 10 I = 1,N + 10 V(I,1) = B(I)*WGHT(I) + BNRM0 = DNRM2 (N, V, 1) + BNRM = BNRM0 + IF (BNRM0 .GT. DELTA) GO TO 30 + IF (MNEWT .GT. 0) GO TO 20 + CALL DCOPY (N, B, 1, X, 1) + RETURN + 20 DO 25 I = 1,N + 25 X(I) = 0.0D0 + RETURN + 30 CONTINUE +C Apply inverse of left preconditioner to vector b. -------------------- + IER = 0 + IF (JPRE .EQ. 0 .OR. JPRE .EQ. 2) GO TO 55 + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, B, 1, IER) + NPSL = 1 + IF (IER .NE. 0) GO TO 300 +C Calculate norm of scaled vector V(*,1) and normalize it. ------------- + DO 50 I = 1,N + 50 V(I,1) = B(I)*WGHT(I) + BNRM = DNRM2 (N, V, 1) + DELTA = DELTA*(BNRM/BNRM0) + 55 TEM = 1.0D0/BNRM + CALL DSCAL (N, TEM, V(1,1), 1) +C Zero out the HES array. ---------------------------------------------- + DO 65 J = 1,MAXL + DO 60 I = 1,MAXLP1 + 60 HES(I,J) = 0.0D0 + 65 CONTINUE +C----------------------------------------------------------------------- +C Main loop to compute the vectors V(*,2) to V(*,MAXL). +C The running product PROD is needed for the convergence test. +C----------------------------------------------------------------------- + PROD = 1.0D0 + DO 90 LL = 1,MAXL + LGMR = LL +C----------------------------------------------------------------------- +C Call routine DATV to compute VNEW = Abar*v(ll), where Abar is +C the matrix A with scaling and inverse preconditioner factors applied. +C Call routine DORTHOG to orthogonalize the new vector VNEW = V(*,LL+1). +C Call routine DHEQR to update the factors of HES. +C----------------------------------------------------------------------- + CALL DATV (NEQ, Y, SAVF, V(1,LL), WGHT, X, F, PSOL, V(1,LL+1), + 1 WK, WP, IWP, HL0, JPRE, IER, NPSL) + IF (IER .NE. 0) GO TO 300 + CALL DORTHOG (V(1,LL+1), V, HES, N, LL, MAXLP1, KMP, SNORMW) + HES(LL+1,LL) = SNORMW + CALL DHEQR (HES, MAXLP1, LL, Q, INFO, LL) + IF (INFO .EQ. LL) GO TO 120 +C----------------------------------------------------------------------- +C Update RHO, the estimate of the norm of the residual b - A*xl. +C If KMP .lt. MAXL, then the vectors V(*,1),...,V(*,LL+1) are not +C necessarily orthogonal for LL .gt. KMP. The vector DL must then +C be computed, and its norm used in the calculation of RHO. +C----------------------------------------------------------------------- + PROD = PROD*Q(2*LL) + RHO = ABS(PROD*BNRM) + IF ((LL.GT.KMP) .AND. (KMP.LT.MAXL)) THEN + IF (LL .EQ. KMP+1) THEN + CALL DCOPY (N, V(1,1), 1, DL, 1) + DO 75 I = 1,KMP + IP1 = I + 1 + I2 = I*2 + S = Q(I2) + C = Q(I2-1) + DO 70 K = 1,N + 70 DL(K) = S*DL(K) + C*V(K,IP1) + 75 CONTINUE + ENDIF + S = Q(2*LL) + C = Q(2*LL-1)/SNORMW + LLP1 = LL + 1 + DO 80 K = 1,N + 80 DL(K) = S*DL(K) + C*V(K,LLP1) + DLNRM = DNRM2 (N, DL, 1) + RHO = RHO*DLNRM + ENDIF +C----------------------------------------------------------------------- +C Test for convergence. If passed, compute approximation xl. +C if failed and LL .lt. MAXL, then continue iterating. +C----------------------------------------------------------------------- + IF (RHO .LE. DELTA) GO TO 200 + IF (LL .EQ. MAXL) GO TO 100 +C----------------------------------------------------------------------- +C Rescale so that the norm of V(1,LL+1) is one. +C----------------------------------------------------------------------- + TEM = 1.0D0/SNORMW + CALL DSCAL (N, TEM, V(1,LL+1), 1) + 90 CONTINUE + 100 CONTINUE + IF (RHO .LE. 1.0D0) GO TO 150 + IF (RHO .LE. BNRM .AND. MNEWT .EQ. 0) GO TO 150 + 120 CONTINUE + IFLAG = 2 + RETURN + 150 IFLAG = 1 +C----------------------------------------------------------------------- +C Compute the approximation xl to the solution. +C Since the vector X was used as work space, and the initial guess +C of the Newton correction is zero, X must be reset to zero. +C----------------------------------------------------------------------- + 200 CONTINUE + LL = LGMR + LLP1 = LL + 1 + DO 210 K = 1,LLP1 + 210 B(K) = 0.0D0 + B(1) = BNRM + CALL DHELS (HES, MAXLP1, LL, Q, B) + DO 220 K = 1,N + 220 X(K) = 0.0D0 + DO 230 I = 1,LL + CALL DAXPY (N, B(I), V(1,I), 1, X, 1) + 230 CONTINUE + DO 240 I = 1,N + 240 X(I) = X(I)/WGHT(I) + IF (JPRE .LE. 1) RETURN + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, X, 2, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) GO TO 300 + RETURN +C----------------------------------------------------------------------- +C This block handles error returns forced by routine PSOL. +C----------------------------------------------------------------------- + 300 CONTINUE + IF (IER .LT. 0) IFLAG = -1 + IF (IER .GT. 0) IFLAG = 3 +C + RETURN +C----------------------- End of Subroutine DSPIGMR --------------------- + END +*DECK DPCG + SUBROUTINE DPCG (NEQ, TN, Y, SAVF, R, WGHT, N, MAXL, DELTA, HL0, + 1 JPRE, MNEWT, F, PSOL, NPSL, X, P, W, Z, LPCG, WP, IWP, WK, IFLAG) + EXTERNAL F, PSOL + INTEGER NEQ, N, MAXL, JPRE, MNEWT, NPSL, LPCG, IWP, IFLAG + DOUBLE PRECISION TN,Y,SAVF,R,WGHT,DELTA,HL0,X,P,W,Z,WP,WK + DIMENSION NEQ(*), Y(*), SAVF(*), R(*), WGHT(*), X(*), P(*), W(*), + 1 Z(*), WP(*), IWP(*), WK(*) +C----------------------------------------------------------------------- +C This routine computes the solution to the system A*x = b using a +C preconditioned version of the Conjugate Gradient algorithm. +C It is assumed here that the matrix A and the preconditioner +C matrix M are symmetric positive definite or nearly so. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C TN = current value of t. +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C R = the right hand side of the system A*x = b. +C +C WGHT = array of length N containing scale factors. +C 1/WGHT(i) are the diagonal elements of the diagonal +C scaling matrix D. +C +C N = the order of the matrix A, and the lengths +C of the vectors Y, SAVF, R, WGHT, P, W, Z, WK, and X. +C +C MAXL = the maximum allowable number of iterates. +C +C DELTA = tolerance on residuals b - A*x in weighted RMS-norm. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C JPRE = preconditioner type flag. +C +C MNEWT = Newton iteration counter (.ge. 0). +C +C WK = real work array used by routine DATP. +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C On return +C +C X = the final computed approximation to the solution +C of the system A*x = b. +C +C LPCG = the number of iterations performed, and current +C order of the upper Hessenberg matrix HES. +C +C NPSL = the number of calls to PSOL. +C +C IFLAG = integer error flag: +C 0 means convergence in LPCG iterations, LPCG .le. MAXL. +C 1 means the convergence test did not pass in MAXL +C iterations, but the residual norm is .lt. 1, +C or .lt. norm(b) if MNEWT = 0, and so X is computed. +C 2 means the convergence test did not pass in MAXL +C iterations, residual .gt. 1, and X is undefined. +C 3 means there was a recoverable error in PSOL +C caused by the preconditioner being out of date. +C 4 means there was a zero denominator in the algorithm. +C The system matrix or preconditioner matrix is not +C sufficiently close to being symmetric pos. definite. +C -1 means there was a nonrecoverable error in PSOL. +C +C----------------------------------------------------------------------- + INTEGER I, IER + DOUBLE PRECISION ALPHA,BETA,BNRM,PTW,RNRM,DDOT,DVNORM,ZTR,ZTR0 +C + IFLAG = 0 + NPSL = 0 + LPCG = 0 + DO 10 I = 1,N + 10 X(I) = 0.0D0 + BNRM = DVNORM (N, R, WGHT) +C Test for immediate return with X = 0 or X = b. ----------------------- + IF (BNRM .GT. DELTA) GO TO 20 + IF (MNEWT .GT. 0) RETURN + CALL DCOPY (N, R, 1, X, 1) + RETURN +C + 20 ZTR = 0.0D0 +C Loop point for PCG iterations. --------------------------------------- + 30 CONTINUE + LPCG = LPCG + 1 + CALL DCOPY (N, R, 1, Z, 1) + IER = 0 + IF (JPRE .EQ. 0) GO TO 40 + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, Z, 3, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) GO TO 100 + 40 CONTINUE + ZTR0 = ZTR + ZTR = DDOT (N, Z, 1, R, 1) + IF (LPCG .NE. 1) GO TO 50 + CALL DCOPY (N, Z, 1, P, 1) + GO TO 70 + 50 CONTINUE + IF (ZTR0 .EQ. 0.0D0) GO TO 200 + BETA = ZTR/ZTR0 + DO 60 I = 1,N + 60 P(I) = Z(I) + BETA*P(I) + 70 CONTINUE +C----------------------------------------------------------------------- +C Call DATP to compute A*p and return the answer in W. +C----------------------------------------------------------------------- + CALL DATP (NEQ, Y, SAVF, P, WGHT, HL0, WK, F, W) +C + PTW = DDOT (N, P, 1, W, 1) + IF (PTW .EQ. 0.0D0) GO TO 200 + ALPHA = ZTR/PTW + CALL DAXPY (N, ALPHA, P, 1, X, 1) + ALPHA = -ALPHA + CALL DAXPY (N, ALPHA, W, 1, R, 1) + RNRM = DVNORM (N, R, WGHT) + IF (RNRM .LE. DELTA) RETURN + IF (LPCG .LT. MAXL) GO TO 30 + IFLAG = 2 + IF (RNRM .LE. 1.0D0) IFLAG = 1 + IF (RNRM .LE. BNRM .AND. MNEWT .EQ. 0) IFLAG = 1 + RETURN +C----------------------------------------------------------------------- +C This block handles error returns from PSOL. +C----------------------------------------------------------------------- + 100 CONTINUE + IF (IER .LT. 0) IFLAG = -1 + IF (IER .GT. 0) IFLAG = 3 + RETURN +C----------------------------------------------------------------------- +C This block handles division by zero errors. +C----------------------------------------------------------------------- + 200 CONTINUE + IFLAG = 4 + RETURN +C----------------------- End of Subroutine DPCG ------------------------ + END +*DECK DPCGS + SUBROUTINE DPCGS (NEQ, TN, Y, SAVF, R, WGHT, N, MAXL, DELTA, HL0, + 1 JPRE, MNEWT, F, PSOL, NPSL, X, P, W, Z, LPCG, WP, IWP, WK, IFLAG) + EXTERNAL F, PSOL + INTEGER NEQ, N, MAXL, JPRE, MNEWT, NPSL, LPCG, IWP, IFLAG + DOUBLE PRECISION TN,Y,SAVF,R,WGHT,DELTA,HL0,X,P,W,Z,WP,WK + DIMENSION NEQ(*), Y(*), SAVF(*), R(*), WGHT(*), X(*), P(*), W(*), + 1 Z(*), WP(*), IWP(*), WK(*) +C----------------------------------------------------------------------- +C This routine computes the solution to the system A*x = b using a +C scaled preconditioned version of the Conjugate Gradient algorithm. +C It is assumed here that the scaled matrix D**-1 * A * D and the +C scaled preconditioner D**-1 * M * D are close to being +C symmetric positive definite. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C TN = current value of t. +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C R = the right hand side of the system A*x = b. +C +C WGHT = array of length N containing scale factors. +C 1/WGHT(i) are the diagonal elements of the diagonal +C scaling matrix D. +C +C N = the order of the matrix A, and the lengths +C of the vectors Y, SAVF, R, WGHT, P, W, Z, WK, and X. +C +C MAXL = the maximum allowable number of iterates. +C +C DELTA = tolerance on residuals b - A*x in weighted RMS-norm. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C JPRE = preconditioner type flag. +C +C MNEWT = Newton iteration counter (.ge. 0). +C +C WK = real work array used by routine DATP. +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C On return +C +C X = the final computed approximation to the solution +C of the system A*x = b. +C +C LPCG = the number of iterations performed, and current +C order of the upper Hessenberg matrix HES. +C +C NPSL = the number of calls to PSOL. +C +C IFLAG = integer error flag: +C 0 means convergence in LPCG iterations, LPCG .le. MAXL. +C 1 means the convergence test did not pass in MAXL +C iterations, but the residual norm is .lt. 1, +C or .lt. norm(b) if MNEWT = 0, and so X is computed. +C 2 means the convergence test did not pass in MAXL +C iterations, residual .gt. 1, and X is undefined. +C 3 means there was a recoverable error in PSOL +C caused by the preconditioner being out of date. +C 4 means there was a zero denominator in the algorithm. +C the scaled matrix or scaled preconditioner is not +C sufficiently close to being symmetric pos. definite. +C -1 means there was a nonrecoverable error in PSOL. +C +C----------------------------------------------------------------------- + INTEGER I, IER + DOUBLE PRECISION ALPHA, BETA, BNRM, PTW, RNRM, DVNORM, ZTR, ZTR0 +C + IFLAG = 0 + NPSL = 0 + LPCG = 0 + DO 10 I = 1,N + 10 X(I) = 0.0D0 + BNRM = DVNORM (N, R, WGHT) +C Test for immediate return with X = 0 or X = b. ----------------------- + IF (BNRM .GT. DELTA) GO TO 20 + IF (MNEWT .GT. 0) RETURN + CALL DCOPY (N, R, 1, X, 1) + RETURN +C + 20 ZTR = 0.0D0 +C Loop point for PCG iterations. --------------------------------------- + 30 CONTINUE + LPCG = LPCG + 1 + CALL DCOPY (N, R, 1, Z, 1) + IER = 0 + IF (JPRE .EQ. 0) GO TO 40 + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, Z, 3, IER) + NPSL = NPSL + 1 + IF (IER .NE. 0) GO TO 100 + 40 CONTINUE + ZTR0 = ZTR + ZTR = 0.0D0 + DO 45 I = 1,N + 45 ZTR = ZTR + Z(I)*R(I)*WGHT(I)**2 + IF (LPCG .NE. 1) GO TO 50 + CALL DCOPY (N, Z, 1, P, 1) + GO TO 70 + 50 CONTINUE + IF (ZTR0 .EQ. 0.0D0) GO TO 200 + BETA = ZTR/ZTR0 + DO 60 I = 1,N + 60 P(I) = Z(I) + BETA*P(I) + 70 CONTINUE +C----------------------------------------------------------------------- +C Call DATP to compute A*p and return the answer in W. +C----------------------------------------------------------------------- + CALL DATP (NEQ, Y, SAVF, P, WGHT, HL0, WK, F, W) +C + PTW = 0.0D0 + DO 80 I = 1,N + 80 PTW = PTW + P(I)*W(I)*WGHT(I)**2 + IF (PTW .EQ. 0.0D0) GO TO 200 + ALPHA = ZTR/PTW + CALL DAXPY (N, ALPHA, P, 1, X, 1) + ALPHA = -ALPHA + CALL DAXPY (N, ALPHA, W, 1, R, 1) + RNRM = DVNORM (N, R, WGHT) + IF (RNRM .LE. DELTA) RETURN + IF (LPCG .LT. MAXL) GO TO 30 + IFLAG = 2 + IF (RNRM .LE. 1.0D0) IFLAG = 1 + IF (RNRM .LE. BNRM .AND. MNEWT .EQ. 0) IFLAG = 1 + RETURN +C----------------------------------------------------------------------- +C This block handles error returns from PSOL. +C----------------------------------------------------------------------- + 100 CONTINUE + IF (IER .LT. 0) IFLAG = -1 + IF (IER .GT. 0) IFLAG = 3 + RETURN +C----------------------------------------------------------------------- +C This block handles division by zero errors. +C----------------------------------------------------------------------- + 200 CONTINUE + IFLAG = 4 + RETURN +C----------------------- End of Subroutine DPCGS ----------------------- + END +*DECK DATP + SUBROUTINE DATP (NEQ, Y, SAVF, P, WGHT, HL0, WK, F, W) + EXTERNAL F + INTEGER NEQ + DOUBLE PRECISION Y, SAVF, P, WGHT, HL0, WK, W + DIMENSION NEQ(*), Y(*), SAVF(*), P(*), WGHT(*), WK(*), W(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C----------------------------------------------------------------------- +C This routine computes the product +C +C w = (I - hl0*df/dy)*p +C +C This is computed by a call to F and a difference quotient. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C P = real array of length N. +C +C WGHT = array of length N containing scale factors. +C 1/WGHT(i) are the diagonal elements of the matrix D. +C +C WK = work array of length N. +C +C On return +C +C +C W = array of length N containing desired +C matrix-vector product. +C +C In addition, this routine uses the Common variables TN, N, NFE. +C----------------------------------------------------------------------- + INTEGER I + DOUBLE PRECISION FAC, PNRM, RPNRM, DVNORM +C + PNRM = DVNORM (N, P, WGHT) + RPNRM = 1.0D0/PNRM + CALL DCOPY (N, Y, 1, W, 1) + DO 20 I = 1,N + 20 Y(I) = W(I) + P(I)*RPNRM + CALL F (NEQ, TN, Y, WK) + NFE = NFE + 1 + CALL DCOPY (N, W, 1, Y, 1) + FAC = HL0*PNRM + DO 40 I = 1,N + 40 W(I) = P(I) - FAC*(WK(I) - SAVF(I)) + RETURN +C----------------------- End of Subroutine DATP ------------------------ + END +*DECK DUSOL + SUBROUTINE DUSOL (NEQ, TN, Y, SAVF, B, WGHT, N, DELTA, HL0, MNEWT, + 1 PSOL, NPSL, X, WP, IWP, WK, IFLAG) + EXTERNAL PSOL + INTEGER NEQ, N, MNEWT, NPSL, IWP, IFLAG + DOUBLE PRECISION TN, Y, SAVF, B, WGHT, DELTA, HL0, X, WP, WK + DIMENSION NEQ(*), Y(*), SAVF(*), B(*), WGHT(*), X(*), + 1 WP(*), IWP(*), WK(*) +C----------------------------------------------------------------------- +C This routine solves the linear system A * x = b using only a call +C to the user-supplied routine PSOL (no Krylov iteration). +C If the norm of the right-hand side vector b is smaller than DELTA, +C the vector X returned is X = b (if MNEWT = 0) or X = 0 otherwise. +C PSOL is called with an LR argument of 0. +C----------------------------------------------------------------------- +C +C On entry +C +C NEQ = problem size, passed to F and PSOL (NEQ(1) = N). +C +C TN = current value of t. +C +C Y = array containing current dependent variable vector. +C +C SAVF = array containing current value of f(t,y). +C +C B = the right hand side of the system A*x = b. +C +C WGHT = the vector of length N containing the nonzero +C elements of the diagonal scaling matrix. +C +C N = the order of the matrix A, and the lengths +C of the vectors WGHT, B and X. +C +C DELTA = tolerance on residuals b - A*x in weighted RMS-norm. +C +C HL0 = current value of (step size h) * (coefficient l0). +C +C MNEWT = Newton iteration counter (.ge. 0). +C +C WK = real work array used by PSOL. +C +C WP = real work array used by preconditioner PSOL. +C +C IWP = integer work array used by preconditioner PSOL. +C +C On return +C +C X = the final computed approximation to the solution +C of the system A*x = b. +C +C NPSL = the number of calls to PSOL. +C +C IFLAG = integer error flag: +C 0 means no trouble occurred. +C 3 means there was a recoverable error in PSOL +C caused by the preconditioner being out of date. +C -1 means there was a nonrecoverable error in PSOL. +C +C----------------------------------------------------------------------- + INTEGER I, IER + DOUBLE PRECISION BNRM, DVNORM +C + IFLAG = 0 + NPSL = 0 +C----------------------------------------------------------------------- +C Test for an immediate return with X = 0 or X = b. +C----------------------------------------------------------------------- + BNRM = DVNORM (N, B, WGHT) + IF (BNRM .GT. DELTA) GO TO 30 + IF (MNEWT .GT. 0) GO TO 10 + CALL DCOPY (N, B, 1, X, 1) + RETURN + 10 DO 20 I = 1,N + 20 X(I) = 0.0D0 + RETURN +C Make call to PSOL and copy result from B to X. ----------------------- + 30 IER = 0 + CALL PSOL (NEQ, TN, Y, SAVF, WK, HL0, WP, IWP, B, 0, IER) + NPSL = 1 + IF (IER .NE. 0) GO TO 100 + CALL DCOPY (N, B, 1, X, 1) + RETURN +C----------------------------------------------------------------------- +C This block handles error returns forced by routine PSOL. +C----------------------------------------------------------------------- + 100 CONTINUE + IF (IER .LT. 0) IFLAG = -1 + IF (IER .GT. 0) IFLAG = 3 + RETURN +C----------------------- End of Subroutine DUSOL ----------------------- + END +*DECK DSRCPK + SUBROUTINE DSRCPK (RSAV, ISAV, JOB) +C----------------------------------------------------------------------- +C This routine saves or restores (depending on JOB) the contents of +C the Common blocks DLS001, DLPK01, which are used +C internally by the DLSODPK solver. +C +C RSAV = real array of length 222 or more. +C ISAV = integer array of length 50 or more. +C JOB = flag indicating to save or restore the Common blocks: +C JOB = 1 if Common is to be saved (written to RSAV/ISAV) +C JOB = 2 if Common is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C----------------------------------------------------------------------- + INTEGER ISAV, JOB + INTEGER ILS, ILSP + INTEGER I, LENILP, LENRLP, LENILS, LENRLS + DOUBLE PRECISION RSAV, RLS, RLSP + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS, LENRLP, LENILP + COMMON /DLS001/ RLS(218), ILS(37) + COMMON /DLPK01/ RLSP(4), ILSP(13) + DATA LENRLS/218/, LENILS/37/, LENRLP/4/, LENILP/13/ +C + IF (JOB .EQ. 2) GO TO 100 + CALL DCOPY (LENRLS, RLS, 1, RSAV, 1) + CALL DCOPY (LENRLP, RLSP, 1, RSAV(LENRLS+1), 1) + DO 20 I = 1,LENILS + 20 ISAV(I) = ILS(I) + DO 40 I = 1,LENILP + 40 ISAV(LENILS+I) = ILSP(I) + RETURN +C + 100 CONTINUE + CALL DCOPY (LENRLS, RSAV, 1, RLS, 1) + CALL DCOPY (LENRLP, RSAV(LENRLS+1), 1, RLSP, 1) + DO 120 I = 1,LENILS + 120 ILS(I) = ISAV(I) + DO 140 I = 1,LENILP + 140 ILSP(I) = ISAV(LENILS+I) + RETURN +C----------------------- End of Subroutine DSRCPK ---------------------- + END +*DECK DHEFA + SUBROUTINE DHEFA (A, LDA, N, IPVT, INFO, JOB) + INTEGER LDA, N, IPVT(*), INFO, JOB + DOUBLE PRECISION A(LDA,*) +C----------------------------------------------------------------------- +C This routine is a modification of the LINPACK routine DGEFA and +C performs an LU decomposition of an upper Hessenberg matrix A. +C There are two options available: +C +C (1) performing a fresh factorization +C (2) updating the LU factors by adding a row and a +C column to the matrix A. +C----------------------------------------------------------------------- +C DHEFA factors an upper Hessenberg matrix by elimination. +C +C On entry +C +C A DOUBLE PRECISION(LDA, N) +C the matrix to be factored. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C the order of the matrix A . +C +C JOB INTEGER +C JOB = 1 means that a fresh factorization of the +C matrix A is desired. +C JOB .ge. 2 means that the current factorization of A +C will be updated by the addition of a row +C and a column. +C +C On return +C +C A an upper triangular matrix and the multipliers +C which were used to obtain it. +C The factorization can be written A = L*U where +C L is a product of permutation and unit lower +C triangular matrices and U is upper triangular. +C +C IPVT INTEGER(N) +C an integer vector of pivot indices. +C +C INFO INTEGER +C = 0 normal value. +C = k if U(k,k) .eq. 0.0 . This is not an error +C condition for this subroutine, but it does +C indicate that DHESL will divide by zero if called. +C +C Modification of LINPACK, by Peter Brown, LLNL. +C Written 7/20/83. This version dated 6/20/01. +C +C BLAS called: DAXPY, IDAMAX +C----------------------------------------------------------------------- + INTEGER IDAMAX, J, K, KM1, KP1, L, NM1 + DOUBLE PRECISION T +C + IF (JOB .GT. 1) GO TO 80 +C +C A new facorization is desired. This is essentially the LINPACK +C code with the exception that we know there is only one nonzero +C element below the main diagonal. +C +C Gaussian elimination with partial pivoting +C + INFO = 0 + NM1 = N - 1 + IF (NM1 .LT. 1) GO TO 70 + DO 60 K = 1, NM1 + KP1 = K + 1 +C +C Find L = pivot index +C + L = IDAMAX (2, A(K,K), 1) + K - 1 + IPVT(K) = L +C +C Zero pivot implies this column already triangularized +C + IF (A(L,K) .EQ. 0.0D0) GO TO 40 +C +C Interchange if necessary +C + IF (L .EQ. K) GO TO 10 + T = A(L,K) + A(L,K) = A(K,K) + A(K,K) = T + 10 CONTINUE +C +C Compute multipliers +C + T = -1.0D0/A(K,K) + A(K+1,K) = A(K+1,K)*T +C +C Row elimination with column indexing +C + DO 30 J = KP1, N + T = A(L,J) + IF (L .EQ. K) GO TO 20 + A(L,J) = A(K,J) + A(K,J) = T + 20 CONTINUE + CALL DAXPY (N-K, T, A(K+1,K), 1, A(K+1,J), 1) + 30 CONTINUE + GO TO 50 + 40 CONTINUE + INFO = K + 50 CONTINUE + 60 CONTINUE + 70 CONTINUE + IPVT(N) = N + IF (A(N,N) .EQ. 0.0D0) INFO = N + RETURN +C +C The old factorization of A will be updated. A row and a column +C has been added to the matrix A. +C N-1 is now the old order of the matrix. +C + 80 CONTINUE + NM1 = N - 1 +C +C Perform row interchanges on the elements of the new column, and +C perform elimination operations on the elements using the multipliers. +C + IF (NM1 .LE. 1) GO TO 105 + DO 100 K = 2,NM1 + KM1 = K - 1 + L = IPVT(KM1) + T = A(L,N) + IF (L .EQ. KM1) GO TO 90 + A(L,N) = A(KM1,N) + A(KM1,N) = T + 90 CONTINUE + A(K,N) = A(K,N) + A(K,KM1)*T + 100 CONTINUE + 105 CONTINUE +C +C Complete update of factorization by decomposing last 2x2 block. +C + INFO = 0 +C +C Find L = pivot index +C + L = IDAMAX (2, A(NM1,NM1), 1) + NM1 - 1 + IPVT(NM1) = L +C +C Zero pivot implies this column already triangularized +C + IF (A(L,NM1) .EQ. 0.0D0) GO TO 140 +C +C Interchange if necessary +C + IF (L .EQ. NM1) GO TO 110 + T = A(L,NM1) + A(L,NM1) = A(NM1,NM1) + A(NM1,NM1) = T + 110 CONTINUE +C +C Compute multipliers +C + T = -1.0D0/A(NM1,NM1) + A(N,NM1) = A(N,NM1)*T +C +C Row elimination with column indexing +C + T = A(L,N) + IF (L .EQ. NM1) GO TO 120 + A(L,N) = A(NM1,N) + A(NM1,N) = T + 120 CONTINUE + A(N,N) = A(N,N) + T*A(N,NM1) + GO TO 150 + 140 CONTINUE + INFO = NM1 + 150 CONTINUE + IPVT(N) = N + IF (A(N,N) .EQ. 0.0D0) INFO = N + RETURN +C----------------------- End of Subroutine DHEFA ----------------------- + END +*DECK DHESL + SUBROUTINE DHESL (A, LDA, N, IPVT, B) + INTEGER LDA, N, IPVT(*) + DOUBLE PRECISION A(LDA,*), B(*) +C----------------------------------------------------------------------- +C This is essentially the LINPACK routine DGESL except for changes +C due to the fact that A is an upper Hessenberg matrix. +C----------------------------------------------------------------------- +C DHESL solves the real system A * x = b +C using the factors computed by DHEFA. +C +C On entry +C +C A DOUBLE PRECISION(LDA, N) +C the output from DHEFA. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C the order of the matrix A . +C +C IPVT INTEGER(N) +C the pivot vector from DHEFA. +C +C B DOUBLE PRECISION(N) +C the right hand side vector. +C +C On return +C +C B the solution vector x . +C +C Modification of LINPACK, by Peter Brown, LLNL. +C Written 7/20/83. This version dated 6/20/01. +C +C BLAS called: DAXPY +C----------------------------------------------------------------------- + INTEGER K, KB, L, NM1 + DOUBLE PRECISION T +C + NM1 = N - 1 +C +C Solve A * x = b +C First solve L*y = b +C + IF (NM1 .LT. 1) GO TO 30 + DO 20 K = 1, NM1 + L = IPVT(K) + T = B(L) + IF (L .EQ. K) GO TO 10 + B(L) = B(K) + B(K) = T + 10 CONTINUE + B(K+1) = B(K+1) + T*A(K+1,K) + 20 CONTINUE + 30 CONTINUE +C +C Now solve U*x = y +C + DO 40 KB = 1, N + K = N + 1 - KB + B(K) = B(K)/A(K,K) + T = -B(K) + CALL DAXPY (K-1, T, A(1,K), 1, B(1), 1) + 40 CONTINUE + RETURN +C----------------------- End of Subroutine DHESL ----------------------- + END +*DECK DHEQR + SUBROUTINE DHEQR (A, LDA, N, Q, INFO, IJOB) + INTEGER LDA, N, INFO, IJOB + DOUBLE PRECISION A(LDA,*), Q(*) +C----------------------------------------------------------------------- +C This routine performs a QR decomposition of an upper +C Hessenberg matrix A. There are two options available: +C +C (1) performing a fresh decomposition +C (2) updating the QR factors by adding a row and a +C column to the matrix A. +C----------------------------------------------------------------------- +C DHEQR decomposes an upper Hessenberg matrix by using Givens +C rotations. +C +C On entry +C +C A DOUBLE PRECISION(LDA, N) +C the matrix to be decomposed. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C A is an (N+1) by N Hessenberg matrix. +C +C IJOB INTEGER +C = 1 means that a fresh decomposition of the +C matrix A is desired. +C .ge. 2 means that the current decomposition of A +C will be updated by the addition of a row +C and a column. +C On return +C +C A the upper triangular matrix R. +C The factorization can be written Q*A = R, where +C Q is a product of Givens rotations and R is upper +C triangular. +C +C Q DOUBLE PRECISION(2*N) +C the factors c and s of each Givens rotation used +C in decomposing A. +C +C INFO INTEGER +C = 0 normal value. +C = k if A(k,k) .eq. 0.0 . This is not an error +C condition for this subroutine, but it does +C indicate that DHELS will divide by zero +C if called. +C +C Modification of LINPACK, by Peter Brown, LLNL. +C Written 1/13/86. This version dated 6/20/01. +C----------------------------------------------------------------------- + INTEGER I, IQ, J, K, KM1, KP1, NM1 + DOUBLE PRECISION C, S, T, T1, T2 +C + IF (IJOB .GT. 1) GO TO 70 +C +C A new facorization is desired. +C +C QR decomposition without pivoting +C + INFO = 0 + DO 60 K = 1, N + KM1 = K - 1 + KP1 = K + 1 +C +C Compute kth column of R. +C First, multiply the kth column of A by the previous +C k-1 Givens rotations. +C + IF (KM1 .LT. 1) GO TO 20 + DO 10 J = 1, KM1 + I = 2*(J-1) + 1 + T1 = A(J,K) + T2 = A(J+1,K) + C = Q(I) + S = Q(I+1) + A(J,K) = C*T1 - S*T2 + A(J+1,K) = S*T1 + C*T2 + 10 CONTINUE +C +C Compute Givens components c and s +C + 20 CONTINUE + IQ = 2*KM1 + 1 + T1 = A(K,K) + T2 = A(KP1,K) + IF (T2 .NE. 0.0D0) GO TO 30 + C = 1.0D0 + S = 0.0D0 + GO TO 50 + 30 CONTINUE + IF (ABS(T2) .LT. ABS(T1)) GO TO 40 + T = T1/T2 + S = -1.0D0/SQRT(1.0D0+T*T) + C = -S*T + GO TO 50 + 40 CONTINUE + T = T2/T1 + C = 1.0D0/SQRT(1.0D0+T*T) + S = -C*T + 50 CONTINUE + Q(IQ) = C + Q(IQ+1) = S + A(K,K) = C*T1 - S*T2 + IF (A(K,K) .EQ. 0.0D0) INFO = K + 60 CONTINUE + RETURN +C +C The old factorization of A will be updated. A row and a column +C has been added to the matrix A. +C N by N-1 is now the old size of the matrix. +C + 70 CONTINUE + NM1 = N - 1 +C +C Multiply the new column by the N previous Givens rotations. +C + DO 100 K = 1,NM1 + I = 2*(K-1) + 1 + T1 = A(K,N) + T2 = A(K+1,N) + C = Q(I) + S = Q(I+1) + A(K,N) = C*T1 - S*T2 + A(K+1,N) = S*T1 + C*T2 + 100 CONTINUE +C +C Complete update of decomposition by forming last Givens rotation, +C and multiplying it times the column vector (A(N,N), A(N+1,N)). +C + INFO = 0 + T1 = A(N,N) + T2 = A(N+1,N) + IF (T2 .NE. 0.0D0) GO TO 110 + C = 1.0D0 + S = 0.0D0 + GO TO 130 + 110 CONTINUE + IF (ABS(T2) .LT. ABS(T1)) GO TO 120 + T = T1/T2 + S = -1.0D0/SQRT(1.0D0+T*T) + C = -S*T + GO TO 130 + 120 CONTINUE + T = T2/T1 + C = 1.0D0/SQRT(1.0D0+T*T) + S = -C*T + 130 CONTINUE + IQ = 2*N - 1 + Q(IQ) = C + Q(IQ+1) = S + A(N,N) = C*T1 - S*T2 + IF (A(N,N) .EQ. 0.0D0) INFO = N + RETURN +C----------------------- End of Subroutine DHEQR ----------------------- + END +*DECK DHELS + SUBROUTINE DHELS (A, LDA, N, Q, B) + INTEGER LDA, N + DOUBLE PRECISION A(LDA,*), B(*), Q(*) +C----------------------------------------------------------------------- +C This is part of the LINPACK routine DGESL with changes +C due to the fact that A is an upper Hessenberg matrix. +C----------------------------------------------------------------------- +C DHELS solves the least squares problem +C +C min (b-A*x, b-A*x) +C +C using the factors computed by DHEQR. +C +C On entry +C +C A DOUBLE PRECISION(LDA, N) +C the output from DHEQR which contains the upper +C triangular factor R in the QR decomposition of A. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C A is originally an (N+1) by N matrix. +C +C Q DOUBLE PRECISION(2*N) +C The coefficients of the N givens rotations +C used in the QR factorization of A. +C +C B DOUBLE PRECISION(N+1) +C the right hand side vector. +C +C On return +C +C B the solution vector x . +C +C Modification of LINPACK, by Peter Brown, LLNL. +C Written 1/13/86. This version dated 6/20/01. +C +C BLAS called: DAXPY +C----------------------------------------------------------------------- + INTEGER IQ, K, KB, KP1 + DOUBLE PRECISION C, S, T, T1, T2 +C +C Minimize (b-A*x, b-A*x) +C First form Q*b. +C + DO 20 K = 1, N + KP1 = K + 1 + IQ = 2*(K-1) + 1 + C = Q(IQ) + S = Q(IQ+1) + T1 = B(K) + T2 = B(KP1) + B(K) = C*T1 - S*T2 + B(KP1) = S*T1 + C*T2 + 20 CONTINUE +C +C Now solve R*x = Q*b. +C + DO 40 KB = 1, N + K = N + 1 - KB + B(K) = B(K)/A(K,K) + T = -B(K) + CALL DAXPY (K-1, T, A(1,K), 1, B(1), 1) + 40 CONTINUE + RETURN +C----------------------- End of Subroutine DHELS ----------------------- + END +*DECK DLHIN + SUBROUTINE DLHIN (NEQ, N, T0, Y0, YDOT, F, TOUT, UROUND, + 1 EWT, ITOL, ATOL, Y, TEMP, H0, NITER, IER) + EXTERNAL F + DOUBLE PRECISION T0, Y0, YDOT, TOUT, UROUND, EWT, ATOL, Y, + 1 TEMP, H0 + INTEGER NEQ, N, ITOL, NITER, IER + DIMENSION NEQ(*), Y0(*), YDOT(*), EWT(*), ATOL(*), Y(*), TEMP(*) +C----------------------------------------------------------------------- +C Call sequence input -- NEQ, N, T0, Y0, YDOT, F, TOUT, UROUND, +C EWT, ITOL, ATOL, Y, TEMP +C Call sequence output -- H0, NITER, IER +C Common block variables accessed -- None +C +C Subroutines called by DLHIN: F, DCOPY +C Function routines called by DLHIN: DVNORM +C----------------------------------------------------------------------- +C This routine computes the step size, H0, to be attempted on the +C first step, when the user has not supplied a value for this. +C +C First we check that TOUT - T0 differs significantly from zero. Then +C an iteration is done to approximate the initial second derivative +C and this is used to define H from WRMS-norm(H**2 * yddot / 2) = 1. +C A bias factor of 1/2 is applied to the resulting h. +C The sign of H0 is inferred from the initial values of TOUT and T0. +C +C Communication with DLHIN is done with the following variables: +C +C NEQ = NEQ array of solver, passed to F. +C N = size of ODE system, input. +C T0 = initial value of independent variable, input. +C Y0 = vector of initial conditions, input. +C YDOT = vector of initial first derivatives, input. +C F = name of subroutine for right-hand side f(t,y), input. +C TOUT = first output value of independent variable +C UROUND = machine unit roundoff +C EWT, ITOL, ATOL = error weights and tolerance parameters +C as described in the driver routine, input. +C Y, TEMP = work arrays of length N. +C H0 = step size to be attempted, output. +C NITER = number of iterations (and of f evaluations) to compute H0, +C output. +C IER = the error flag, returned with the value +C IER = 0 if no trouble occurred, or +C IER = -1 if TOUT and t0 are considered too close to proceed. +C----------------------------------------------------------------------- +C +C Type declarations for local variables -------------------------------- +C + DOUBLE PRECISION AFI, ATOLI, DELYI, HALF, HG, HLB, HNEW, HRAT, + 1 HUB, HUN, PT1, T1, TDIST, TROUND, TWO, DVNORM, YDDNRM + INTEGER I, ITER +C----------------------------------------------------------------------- +C The following Fortran-77 declaration is to cause the values of the +C listed (local) variables to be saved between calls to this integrator. +C----------------------------------------------------------------------- + SAVE HALF, HUN, PT1, TWO + DATA HALF /0.5D0/, HUN /100.0D0/, PT1 /0.1D0/, TWO /2.0D0/ +C + NITER = 0 + TDIST = ABS(TOUT - T0) + TROUND = UROUND*MAX(ABS(T0),ABS(TOUT)) + IF (TDIST .LT. TWO*TROUND) GO TO 100 +C +C Set a lower bound on H based on the roundoff level in T0 and TOUT. --- + HLB = HUN*TROUND +C Set an upper bound on H based on TOUT-T0 and the initial Y and YDOT. - + HUB = PT1*TDIST + ATOLI = ATOL(1) + DO 10 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + DELYI = PT1*ABS(Y0(I)) + ATOLI + AFI = ABS(YDOT(I)) + IF (AFI*HUB .GT. DELYI) HUB = DELYI/AFI + 10 CONTINUE +C +C Set initial guess for H as geometric mean of upper and lower bounds. - + ITER = 0 + HG = SQRT(HLB*HUB) +C If the bounds have crossed, exit with the mean value. ---------------- + IF (HUB .LT. HLB) THEN + H0 = HG + GO TO 90 + ENDIF +C +C Looping point for iteration. ----------------------------------------- + 50 CONTINUE +C Estimate the second derivative as a difference quotient in f. -------- + T1 = T0 + HG + DO 60 I = 1,N + 60 Y(I) = Y0(I) + HG*YDOT(I) + CALL F (NEQ, T1, Y, TEMP) + DO 70 I = 1,N + 70 TEMP(I) = (TEMP(I) - YDOT(I))/HG + YDDNRM = DVNORM (N, TEMP, EWT) +C Get the corresponding new value of H. -------------------------------- + IF (YDDNRM*HUB*HUB .GT. TWO) THEN + HNEW = SQRT(TWO/YDDNRM) + ELSE + HNEW = SQRT(HG*HUB) + ENDIF + ITER = ITER + 1 +C----------------------------------------------------------------------- +C Test the stopping conditions. +C Stop if the new and previous H values differ by a factor of .lt. 2. +C Stop if four iterations have been done. Also, stop with previous H +C if hnew/hg .gt. 2 after first iteration, as this probably means that +C the second derivative value is bad because of cancellation error. +C----------------------------------------------------------------------- + IF (ITER .GE. 4) GO TO 80 + HRAT = HNEW/HG + IF ( (HRAT .GT. HALF) .AND. (HRAT .LT. TWO) ) GO TO 80 + IF ( (ITER .GE. 2) .AND. (HNEW .GT. TWO*HG) ) THEN + HNEW = HG + GO TO 80 + ENDIF + HG = HNEW + GO TO 50 +C +C Iteration done. Apply bounds, bias factor, and sign. ---------------- + 80 H0 = HNEW*HALF + IF (H0 .LT. HLB) H0 = HLB + IF (H0 .GT. HUB) H0 = HUB + 90 H0 = SIGN(H0, TOUT - T0) +C Restore Y array from Y0, then exit. ---------------------------------- + CALL DCOPY (N, Y0, 1, Y, 1) + NITER = ITER + IER = 0 + RETURN +C Error return for TOUT - T0 too small. -------------------------------- + 100 IER = -1 + RETURN +C----------------------- End of Subroutine DLHIN ----------------------- + END +*DECK DSTOKA + SUBROUTINE DSTOKA (NEQ, Y, YH, NYH, YH1, EWT, SAVF, SAVX, ACOR, + 1 WM, IWM, F, JAC, PSOL) + EXTERNAL F, JAC, PSOL + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, YH1, EWT, SAVF, SAVX, ACOR, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), YH1(*), EWT(*), SAVF(*), + 1 SAVX(*), ACOR(*), WM(*), IWM(*) + INTEGER IOWND, IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER NEWT, NSFI, NSLJ, NJEV + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + DOUBLE PRECISION CONIT, CRATE, EL, ELCO, HOLD, RMAX, TESCO, + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION STIFR + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + COMMON /DLS001/ CONIT, CRATE, EL(13), ELCO(13,12), + 1 HOLD, RMAX, TESCO(3,12), + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 3 IOWND(6), IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLS002/ STIFR, NEWT, NSFI, NSLJ, NJEV + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C----------------------------------------------------------------------- +C DSTOKA performs one step of the integration of an initial value +C problem for a system of Ordinary Differential Equations. +C +C This routine was derived from Subroutine DSTODPK in the DLSODPK +C package by the addition of automatic functional/Newton iteration +C switching and logic for re-use of Jacobian data. +C----------------------------------------------------------------------- +C Note: DSTOKA is independent of the value of the iteration method +C indicator MITER, when this is .ne. 0, and hence is independent +C of the type of chord method used, or the Jacobian structure. +C Communication with DSTOKA is done with the following variables: +C +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls to F and JAC. +C Y = an array of length .ge. N used as the Y argument in +C all calls to F and JAC. +C YH = an NYH by LMAX array containing the dependent variables +C and their approximate scaled derivatives, where +C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate +C j-th derivative of y(i), scaled by H**j/factorial(j) +C (j = 0,1,...,NQ). On entry for the first step, the first +C two columns of YH must be set from the initial values. +C NYH = a constant integer .ge. N, the first dimension of YH. +C YH1 = a one-dimensional array occupying the same space as YH. +C EWT = an array of length N containing multiplicative weights +C for local error measurements. Local errors in y(i) are +C compared to 1.0/EWT(i) in various error tests. +C SAVF = an array of working storage, of length N. +C Also used for input of YH(*,MAXORD+2) when JSTART = -1 +C and MAXORD .lt. the current order NQ. +C SAVX = an array of working storage, of length N. +C ACOR = a work array of length N, used for the accumulated +C corrections. On a successful return, ACOR(i) contains +C the estimated one-step local error in y(i). +C WM,IWM = real and integer work arrays associated with matrix +C operations in chord iteration (MITER .ne. 0). +C CCMAX = maximum relative change in H*EL0 before DSETPK is called. +C H = the step size to be attempted on the next step. +C H is altered by the error control algorithm during the +C problem. H can be either positive or negative, but its +C sign must remain constant throughout the problem. +C HMIN = the minimum absolute value of the step size H to be used. +C HMXI = inverse of the maximum absolute value of H to be used. +C HMXI = 0.0 is allowed and corresponds to an infinite HMAX. +C HMIN and HMXI may be changed at any time, but will not +C take effect until the next change of H is considered. +C TN = the independent variable. TN is updated on each step taken. +C JSTART = an integer used for input only, with the following +C values and meanings: +C 0 perform the first step. +C .gt.0 take a new step continuing from the last. +C -1 take the next step with a new value of H, MAXORD, +C N, METH, MITER, and/or matrix parameters. +C -2 take the next step with a new value of H, +C but with other inputs unchanged. +C On return, JSTART is set to 1 to facilitate continuation. +C KFLAG = a completion code with the following meanings: +C 0 the step was succesful. +C -1 the requested error could not be achieved. +C -2 corrector convergence could not be achieved. +C -3 fatal error in DSETPK or DSOLPK. +C A return with KFLAG = -1 or -2 means either +C ABS(H) = HMIN or 10 consecutive failures occurred. +C On a return with KFLAG negative, the values of TN and +C the YH array are as of the beginning of the last +C step, and H is the last step size attempted. +C MAXORD = the maximum order of integration method to be allowed. +C MAXCOR = the maximum number of corrector iterations allowed. +C MSBP = maximum number of steps between DSETPK calls (MITER .gt. 0). +C MXNCF = maximum number of convergence failures allowed. +C METH/MITER = the method flags. See description in driver. +C N = the number of first-order differential equations. +C----------------------------------------------------------------------- + INTEGER I, I1, IREDO, IRET, J, JB, JOK, M, NCF, NEWQ, NSLOW + DOUBLE PRECISION DCON, DDN, DEL, DELP, DRC, DSM, DUP, EXDN, EXSM, + 1 EXUP, DFNORM, R, RH, RHDN, RHSM, RHUP, ROC, STIFF, TOLD, DVNORM +C + KFLAG = 0 + TOLD = TN + NCF = 0 + IERPJ = 0 + IERSL = 0 + JCUR = 0 + ICF = 0 + DELP = 0.0D0 + IF (JSTART .GT. 0) GO TO 200 + IF (JSTART .EQ. -1) GO TO 100 + IF (JSTART .EQ. -2) GO TO 160 +C----------------------------------------------------------------------- +C On the first call, the order is set to 1, and other variables are +C initialized. RMAX is the maximum ratio by which H can be increased +C in a single step. It is initially 1.E4 to compensate for the small +C initial H, but then is normally equal to 10. If a failure +C occurs (in corrector convergence or error test), RMAX is set at 2 +C for the next increase. +C----------------------------------------------------------------------- + LMAX = MAXORD + 1 + NQ = 1 + L = 2 + IALTH = 2 + RMAX = 10000.0D0 + RC = 0.0D0 + EL0 = 1.0D0 + CRATE = 0.7D0 + HOLD = H + MEO = METH + NSLP = 0 + NSLJ = 0 + IPUP = 0 + IRET = 3 + NEWT = 0 + STIFR = 0.0D0 + GO TO 140 +C----------------------------------------------------------------------- +C The following block handles preliminaries needed when JSTART = -1. +C IPUP is set to MITER to force a matrix update. +C If an order increase is about to be considered (IALTH = 1), +C IALTH is reset to 2 to postpone consideration one more step. +C If the caller has changed METH, DCFODE is called to reset +C the coefficients of the method. +C If the caller has changed MAXORD to a value less than the current +C order NQ, NQ is reduced to MAXORD, and a new H chosen accordingly. +C If H is to be changed, YH must be rescaled. +C If H or METH is being changed, IALTH is reset to L = NQ + 1 +C to prevent further changes in H for that many steps. +C----------------------------------------------------------------------- + 100 IPUP = MITER + LMAX = MAXORD + 1 + IF (IALTH .EQ. 1) IALTH = 2 + IF (METH .EQ. MEO) GO TO 110 + CALL DCFODE (METH, ELCO, TESCO) + MEO = METH + IF (NQ .GT. MAXORD) GO TO 120 + IALTH = L + IRET = 1 + GO TO 150 + 110 IF (NQ .LE. MAXORD) GO TO 160 + 120 NQ = MAXORD + L = LMAX + DO 125 I = 1,L + 125 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + EPCON = CONIT*TESCO(2,NQ) + DDN = DVNORM (N, SAVF, EWT)/TESCO(1,L) + EXDN = 1.0D0/L + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + RH = MIN(RHDN,1.0D0) + IREDO = 3 + IF (H .EQ. HOLD) GO TO 170 + RH = MIN(RH,ABS(H/HOLD)) + H = HOLD + GO TO 175 +C----------------------------------------------------------------------- +C DCFODE is called to get all the integration coefficients for the +C current METH. Then the EL vector and related constants are reset +C whenever the order NQ is changed, or at the start of the problem. +C----------------------------------------------------------------------- + 140 CALL DCFODE (METH, ELCO, TESCO) + 150 DO 155 I = 1,L + 155 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + EPCON = CONIT*TESCO(2,NQ) + GO TO (160, 170, 200), IRET +C----------------------------------------------------------------------- +C If H is being changed, the H ratio RH is checked against +C RMAX, HMIN, and HMXI, and the YH array rescaled. IALTH is set to +C L = NQ + 1 to prevent a change of H for that many steps, unless +C forced by a convergence or error test failure. +C----------------------------------------------------------------------- + 160 IF (H .EQ. HOLD) GO TO 200 + RH = H/HOLD + H = HOLD + IREDO = 3 + GO TO 175 + 170 RH = MAX(RH,HMIN/ABS(H)) + 175 RH = MIN(RH,RMAX) + RH = RH/MAX(1.0D0,ABS(H)*HMXI*RH) + R = 1.0D0 + DO 180 J = 2,L + R = R*RH + DO 180 I = 1,N + 180 YH(I,J) = YH(I,J)*R + H = H*RH + RC = RC*RH + IALTH = L + IF (IREDO .EQ. 0) GO TO 690 +C----------------------------------------------------------------------- +C This section computes the predicted values by effectively +C multiplying the YH array by the Pascal triangle matrix. +C The flag IPUP is set according to whether matrix data is involved +C (NEWT .gt. 0 .and. JACFLG .ne. 0) or not, to trigger a call to DSETPK. +C IPUP is set to MITER when RC differs from 1 by more than CCMAX, +C and at least every MSBP steps, when JACFLG = 1. +C RC is the ratio of new to old values of the coefficient H*EL(1). +C----------------------------------------------------------------------- + 200 IF (NEWT .EQ. 0 .OR. JACFLG .EQ. 0) THEN + DRC = 0.0D0 + IPUP = 0 + CRATE = 0.7D0 + ELSE + DRC = ABS(RC - 1.0D0) + IF (DRC .GT. CCMAX) IPUP = MITER + IF (NST .GE. NSLP+MSBP) IPUP = MITER + ENDIF + TN = TN + H + I1 = NQNYH + 1 + DO 215 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 210 I = I1,NQNYH + 210 YH1(I) = YH1(I) + YH1(I+NYH) + 215 CONTINUE +C----------------------------------------------------------------------- +C Up to MAXCOR corrector iterations are taken. A convergence test is +C made on the RMS-norm of each correction, weighted by the error +C weight vector EWT. The sum of the corrections is accumulated in the +C vector ACOR(i). The YH array is not altered in the corrector loop. +C Within the corrector loop, an estimated rate of convergence (ROC) +C and a stiffness ratio estimate (STIFF) are kept. Corresponding +C global estimates are kept as CRATE and stifr. +C----------------------------------------------------------------------- + 220 M = 0 + MNEWT = 0 + STIFF = 0.0D0 + ROC = 0.05D0 + NSLOW = 0 + DO 230 I = 1,N + 230 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + IF (NEWT .EQ. 0 .OR. IPUP .LE. 0) GO TO 250 +C----------------------------------------------------------------------- +C If indicated, DSETPK is called to update any matrix data needed, +C before starting the corrector iteration. +C JOK is set to indicate if the matrix data need not be recomputed. +C IPUP is set to 0 as an indicator that the matrix data is up to date. +C----------------------------------------------------------------------- + JOK = 1 + IF (NST .EQ. 0 .OR. NST .GT. NSLJ+50) JOK = -1 + IF (ICF .EQ. 1 .AND. DRC .LT. 0.2D0) JOK = -1 + IF (ICF .EQ. 2) JOK = -1 + IF (JOK .EQ. -1) THEN + NSLJ = NST + NJEV = NJEV + 1 + ENDIF + CALL DSETPK (NEQ, Y, YH1, EWT, ACOR, SAVF, JOK, WM, IWM, F, JAC) + IPUP = 0 + RC = 1.0D0 + DRC = 0.0D0 + NSLP = NST + CRATE = 0.7D0 + IF (IERPJ .NE. 0) GO TO 430 + 250 DO 260 I = 1,N + 260 ACOR(I) = 0.0D0 + 270 IF (NEWT .NE. 0) GO TO 350 +C----------------------------------------------------------------------- +C In the case of functional iteration, update Y directly from +C the result of the last function evaluation, and STIFF is set to 1.0. +C----------------------------------------------------------------------- + DO 290 I = 1,N + SAVF(I) = H*SAVF(I) - YH(I,2) + 290 Y(I) = SAVF(I) - ACOR(I) + DEL = DVNORM (N, Y, EWT) + DO 300 I = 1,N + Y(I) = YH(I,1) + EL(1)*SAVF(I) + 300 ACOR(I) = SAVF(I) + STIFF = 1.0D0 + GO TO 400 +C----------------------------------------------------------------------- +C In the case of the chord method, compute the corrector error, +C and solve the linear system with that as right-hand side and +C P as coefficient matrix. STIFF is set to the ratio of the norms +C of the residual and the correction vector. +C----------------------------------------------------------------------- + 350 DO 360 I = 1,N + 360 SAVX(I) = H*SAVF(I) - (YH(I,2) + ACOR(I)) + DFNORM = DVNORM (N, SAVX, EWT) + CALL DSOLPK (NEQ, Y, SAVF, SAVX, EWT, WM, IWM, F, PSOL) + IF (IERSL .LT. 0) GO TO 430 + IF (IERSL .GT. 0) GO TO 410 + DEL = DVNORM (N, SAVX, EWT) + IF (DEL .GT. 1.0D-8) STIFF = MAX(STIFF, DFNORM/DEL) + DO 380 I = 1,N + ACOR(I) = ACOR(I) + SAVX(I) + 380 Y(I) = YH(I,1) + EL(1)*ACOR(I) +C----------------------------------------------------------------------- +C Test for convergence. If M .gt. 0, an estimate of the convergence +C rate constant is made for the iteration switch, and is also used +C in the convergence test. If the iteration seems to be diverging or +C converging at a slow rate (.gt. 0.8 more than once), it is stopped. +C----------------------------------------------------------------------- + 400 IF (M .NE. 0) THEN + ROC = MAX(0.05D0, DEL/DELP) + CRATE = MAX(0.2D0*CRATE,ROC) + ENDIF + DCON = DEL*MIN(1.0D0,1.5D0*CRATE)/EPCON + IF (DCON .LE. 1.0D0) GO TO 450 + M = M + 1 + IF (M .EQ. MAXCOR) GO TO 410 + IF (M .GE. 2 .AND. DEL .GT. 2.0D0*DELP) GO TO 410 + IF (ROC .GT. 10.0D0) GO TO 410 + IF (ROC .GT. 0.8D0) NSLOW = NSLOW + 1 + IF (NSLOW .GE. 2) GO TO 410 + MNEWT = M + DELP = DEL + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + GO TO 270 +C----------------------------------------------------------------------- +C The corrector iteration failed to converge. +C If functional iteration is being done (NEWT = 0) and MITER .gt. 0 +C (and this is not the first step), then switch to Newton +C (NEWT = MITER), and retry the step. (Setting STIFR = 1023 insures +C that a switch back will not occur for 10 step attempts.) +C If Newton iteration is being done, but using a preconditioner that +C is out of date (JACFLG .ne. 0 .and. JCUR = 0), then signal for a +C re-evalutation of the preconditioner, and retry the step. +C In all other cases, the YH array is retracted to its values +C before prediction, and H is reduced, if possible. If H cannot be +C reduced or MXNCF failures have occurred, exit with KFLAG = -2. +C----------------------------------------------------------------------- + 410 ICF = 1 + IF (NEWT .EQ. 0) THEN + IF (NST .EQ. 0) GO TO 430 + IF (MITER .EQ. 0) GO TO 430 + NEWT = MITER + STIFR = 1023.0D0 + IPUP = MITER + GO TO 220 + ENDIF + IF (JCUR.EQ.1 .OR. JACFLG.EQ.0) GO TO 430 + IPUP = MITER + GO TO 220 + 430 ICF = 2 + NCF = NCF + 1 + NCFN = NCFN + 1 + RMAX = 2.0D0 + TN = TOLD + I1 = NQNYH + 1 + DO 445 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 440 I = I1,NQNYH + 440 YH1(I) = YH1(I) - YH1(I+NYH) + 445 CONTINUE + IF (IERPJ .LT. 0 .OR. IERSL .LT. 0) GO TO 680 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 670 + IF (NCF .EQ. MXNCF) GO TO 670 + RH = 0.5D0 + IPUP = MITER + IREDO = 1 + GO TO 170 +C----------------------------------------------------------------------- +C The corrector has converged. JCUR is set to 0 to signal that the +C preconditioner involved may need updating later. +C The stiffness ratio STIFR is updated using the latest STIFF value. +C The local error test is made and control passes to statement 500 +C if it fails. +C----------------------------------------------------------------------- + 450 JCUR = 0 + IF (NEWT .GT. 0) STIFR = 0.5D0*(STIFR + STIFF) + IF (M .EQ. 0) DSM = DEL/TESCO(2,NQ) + IF (M .GT. 0) DSM = DVNORM (N, ACOR, EWT)/TESCO(2,NQ) + IF (DSM .GT. 1.0D0) GO TO 500 +C----------------------------------------------------------------------- +C After a successful step, update the YH array. +C If Newton iteration is being done and STIFR is less than 1.5, +C then switch to functional iteration. +C Consider changing H if IALTH = 1. Otherwise decrease IALTH by 1. +C If IALTH is then 1 and NQ .lt. MAXORD, then ACOR is saved for +C use in a possible order increase on the next step. +C If a change in H is considered, an increase or decrease in order +C by one is considered also. A change in H is made only if it is by a +C factor of at least 1.1. If not, IALTH is set to 3 to prevent +C testing for that many steps. +C----------------------------------------------------------------------- + KFLAG = 0 + IREDO = 0 + NST = NST + 1 + IF (NEWT .EQ. 0) NSFI = NSFI + 1 + IF (NEWT .GT. 0 .AND. STIFR .LT. 1.5D0) NEWT = 0 + HU = H + NQU = NQ + DO 470 J = 1,L + DO 470 I = 1,N + 470 YH(I,J) = YH(I,J) + EL(J)*ACOR(I) + IALTH = IALTH - 1 + IF (IALTH .EQ. 0) GO TO 520 + IF (IALTH .GT. 1) GO TO 700 + IF (L .EQ. LMAX) GO TO 700 + DO 490 I = 1,N + 490 YH(I,LMAX) = ACOR(I) + GO TO 700 +C----------------------------------------------------------------------- +C The error test failed. KFLAG keeps track of multiple failures. +C Restore TN and the YH array to their previous values, and prepare +C to try the step again. Compute the optimum step size for this or +C one lower order. After 2 or more failures, H is forced to decrease +C by a factor of 0.2 or less. +C----------------------------------------------------------------------- + 500 KFLAG = KFLAG - 1 + TN = TOLD + I1 = NQNYH + 1 + DO 515 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 510 I = I1,NQNYH + 510 YH1(I) = YH1(I) - YH1(I+NYH) + 515 CONTINUE + RMAX = 2.0D0 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 660 + IF (KFLAG .LE. -3) GO TO 640 + IREDO = 2 + RHUP = 0.0D0 + GO TO 540 +C----------------------------------------------------------------------- +C Regardless of the success or failure of the step, factors +C RHDN, RHSM, and RHUP are computed, by which H could be multiplied +C at order NQ - 1, order NQ, or order NQ + 1, respectively. +C in the case of failure, RHUP = 0.0 to avoid an order increase. +C the largest of these is determined and the new order chosen +C accordingly. If the order is to be increased, we compute one +C additional scaled derivative. +C----------------------------------------------------------------------- + 520 RHUP = 0.0D0 + IF (L .EQ. LMAX) GO TO 540 + DO 530 I = 1,N + 530 SAVF(I) = ACOR(I) - YH(I,LMAX) + DUP = DVNORM (N, SAVF, EWT)/TESCO(3,NQ) + EXUP = 1.0D0/(L+1) + RHUP = 1.0D0/(1.4D0*DUP**EXUP + 0.0000014D0) + 540 EXSM = 1.0D0/L + RHSM = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RHDN = 0.0D0 + IF (NQ .EQ. 1) GO TO 560 + DDN = DVNORM (N, YH(1,L), EWT)/TESCO(1,NQ) + EXDN = 1.0D0/NQ + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + 560 IF (RHSM .GE. RHUP) GO TO 570 + IF (RHUP .GT. RHDN) GO TO 590 + GO TO 580 + 570 IF (RHSM .LT. RHDN) GO TO 580 + NEWQ = NQ + RH = RHSM + GO TO 620 + 580 NEWQ = NQ - 1 + RH = RHDN + IF (KFLAG .LT. 0 .AND. RH .GT. 1.0D0) RH = 1.0D0 + GO TO 620 + 590 NEWQ = L + RH = RHUP + IF (RH .LT. 1.1D0) GO TO 610 + R = EL(L)/L + DO 600 I = 1,N + 600 YH(I,NEWQ+1) = ACOR(I)*R + GO TO 630 + 610 IALTH = 3 + GO TO 700 + 620 IF ((KFLAG .EQ. 0) .AND. (RH .LT. 1.1D0)) GO TO 610 + IF (KFLAG .LE. -2) RH = MIN(RH,0.2D0) +C----------------------------------------------------------------------- +C If there is a change of order, reset NQ, L, and the coefficients. +C In any case H is reset according to RH and the YH array is rescaled. +C Then exit from 690 if the step was OK, or redo the step otherwise. +C----------------------------------------------------------------------- + IF (NEWQ .EQ. NQ) GO TO 170 + 630 NQ = NEWQ + L = NQ + 1 + IRET = 2 + GO TO 150 +C----------------------------------------------------------------------- +C Control reaches this section if 3 or more failures have occured. +C If 10 failures have occurred, exit with KFLAG = -1. +C It is assumed that the derivatives that have accumulated in the +C YH array have errors of the wrong order. Hence the first +C derivative is recomputed, and the order is set to 1. Then +C H is reduced by a factor of 10, and the step is retried, +C until it succeeds or H reaches HMIN. +C----------------------------------------------------------------------- + 640 IF (KFLAG .EQ. -10) GO TO 660 + RH = 0.1D0 + RH = MAX(HMIN/ABS(H),RH) + H = H*RH + DO 645 I = 1,N + 645 Y(I) = YH(I,1) + CALL F (NEQ, TN, Y, SAVF) + NFE = NFE + 1 + DO 650 I = 1,N + 650 YH(I,2) = H*SAVF(I) + IPUP = MITER + IALTH = 5 + IF (NQ .EQ. 1) GO TO 200 + NQ = 1 + L = 2 + IRET = 3 + GO TO 150 +C----------------------------------------------------------------------- +C All returns are made through this section. H is saved in HOLD +C to allow the caller to change H on the next step. +C----------------------------------------------------------------------- + 660 KFLAG = -1 + GO TO 720 + 670 KFLAG = -2 + GO TO 720 + 680 KFLAG = -3 + GO TO 720 + 690 RMAX = 10.0D0 + 700 R = 1.0D0/TESCO(2,NQU) + DO 710 I = 1,N + 710 ACOR(I) = ACOR(I)*R + 720 HOLD = H + JSTART = 1 + RETURN +C----------------------- End of Subroutine DSTOKA ---------------------- + END +*DECK DSETPK + SUBROUTINE DSETPK (NEQ, Y, YSV, EWT, FTEM, SAVF, JOK, WM, IWM, + 1 F, JAC) + EXTERNAL F, JAC + INTEGER NEQ, JOK, IWM + DOUBLE PRECISION Y, YSV, EWT, FTEM, SAVF, WM + DIMENSION NEQ(*), Y(*), YSV(*), EWT(*), FTEM(*), SAVF(*), + 1 WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C----------------------------------------------------------------------- +C DSETPK is called by DSTOKA to interface with the user-supplied +C routine JAC, to compute and process relevant parts of +C the matrix P = I - H*EL(1)*J , where J is the Jacobian df/dy, +C as need for preconditioning matrix operations later. +C +C In addition to variables described previously, communication +C with DSETPK uses the following: +C Y = array containing predicted values on entry. +C YSV = array containing predicted y, to be saved (YH1 in DSTOKA). +C FTEM = work array of length N (ACOR in DSTOKA). +C SAVF = array containing f evaluated at predicted y. +C JOK = input flag showing whether it was judged that Jacobian matrix +C data need not be recomputed (JOK = 1) or needs to be +C (JOK = -1). +C WM = real work space for matrices. +C Space for preconditioning data starts at WM(LOCWP). +C IWM = integer work space. +C Space for preconditioning data starts at IWM(LOCIWP). +C IERPJ = output error flag, = 0 if no trouble, .gt. 0 if +C JAC returned an error flag. +C JCUR = output flag to indicate whether the matrix data involved +C is now current (JCUR = 1) or not (JCUR = 0). +C This routine also uses Common variables EL0, H, TN, IERPJ, JCUR, NJE. +C----------------------------------------------------------------------- + INTEGER IER + DOUBLE PRECISION HL0 +C + IERPJ = 0 + JCUR = 0 + IF (JOK .EQ. -1) JCUR = 1 + HL0 = EL0*H + CALL JAC (F, NEQ, TN, Y, YSV, EWT, SAVF, FTEM, HL0, JOK, + 1 WM(LOCWP), IWM(LOCIWP), IER) + NJE = NJE + 1 + IF (IER .EQ. 0) RETURN + IERPJ = 1 + RETURN +C----------------------- End of Subroutine DSETPK ---------------------- + END +*DECK DSRCKR + SUBROUTINE DSRCKR (RSAV, ISAV, JOB) +C----------------------------------------------------------------------- +C This routine saves or restores (depending on JOB) the contents of +C the Common blocks DLS001, DLS002, DLSR01, DLPK01, which +C are used internally by the DLSODKR solver. +C +C RSAV = real array of length 228 or more. +C ISAV = integer array of length 63 or more. +C JOB = flag indicating to save or restore the Common blocks: +C JOB = 1 if Common is to be saved (written to RSAV/ISAV) +C JOB = 2 if Common is to be restored (read from RSAV/ISAV) +C A call with JOB = 2 presumes a prior call with JOB = 1. +C----------------------------------------------------------------------- + INTEGER ISAV, JOB + INTEGER ILS, ILS2, ILSR, ILSP + INTEGER I, IOFF, LENILP, LENRLP, LENILS, LENRLS, LENILR, LENRLR + DOUBLE PRECISION RSAV, RLS, RLS2, RLSR, RLSP + DIMENSION RSAV(*), ISAV(*) + SAVE LENRLS, LENILS, LENRLP, LENILP, LENRLR, LENILR + COMMON /DLS001/ RLS(218), ILS(37) + COMMON /DLS002/ RLS2, ILS2(4) + COMMON /DLSR01/ RLSR(5), ILSR(9) + COMMON /DLPK01/ RLSP(4), ILSP(13) + DATA LENRLS/218/, LENILS/37/, LENRLP/4/, LENILP/13/ + DATA LENRLR/5/, LENILR/9/ +C + IF (JOB .EQ. 2) GO TO 100 + CALL DCOPY (LENRLS, RLS, 1, RSAV, 1) + RSAV(LENRLS+1) = RLS2 + CALL DCOPY (LENRLR, RLSR, 1, RSAV(LENRLS+2), 1) + CALL DCOPY (LENRLP, RLSP, 1, RSAV(LENRLS+LENRLR+2), 1) + DO 20 I = 1,LENILS + 20 ISAV(I) = ILS(I) + ISAV(LENILS+1) = ILS2(1) + ISAV(LENILS+2) = ILS2(2) + ISAV(LENILS+3) = ILS2(3) + ISAV(LENILS+4) = ILS2(4) + IOFF = LENILS + 2 + DO 30 I = 1,LENILR + 30 ISAV(IOFF+I) = ILSR(I) + IOFF = IOFF + LENILR + DO 40 I = 1,LENILP + 40 ISAV(IOFF+I) = ILSP(I) + RETURN +C + 100 CONTINUE + CALL DCOPY (LENRLS, RSAV, 1, RLS, 1) + RLS2 = RSAV(LENRLS+1) + CALL DCOPY (LENRLR, RSAV(LENRLS+2), 1, RLSR, 1) + CALL DCOPY (LENRLP, RSAV(LENRLS+LENRLR+2), 1, RLSP, 1) + DO 120 I = 1,LENILS + 120 ILS(I) = ISAV(I) + ILS2(1) = ISAV(LENILS+1) + ILS2(2) = ISAV(LENILS+2) + ILS2(3) = ISAV(LENILS+3) + ILS2(4) = ISAV(LENILS+4) + IOFF = LENILS + 2 + DO 130 I = 1,LENILR + 130 ILSR(I) = ISAV(IOFF+I) + IOFF = IOFF + LENILR + DO 140 I = 1,LENILP + 140 ILSP(I) = ISAV(IOFF+I) + RETURN +C----------------------- End of Subroutine DSRCKR ---------------------- + END +*DECK DAINVG + SUBROUTINE DAINVG (RES, ADDA, NEQ, T, Y, YDOT, MITER, + 1 ML, MU, PW, IPVT, IER ) + EXTERNAL RES, ADDA + INTEGER NEQ, MITER, ML, MU, IPVT, IER + INTEGER I, LENPW, MLP1, NROWPW + DOUBLE PRECISION T, Y, YDOT, PW + DIMENSION Y(*), YDOT(*), PW(*), IPVT(*) +C----------------------------------------------------------------------- +C This subroutine computes the initial value +C of the vector YDOT satisfying +C A * YDOT = g(t,y) +C when A is nonsingular. It is called by DLSODI for +C initialization only, when ISTATE = 0 . +C DAINVG returns an error flag IER: +C IER = 0 means DAINVG was successful. +C IER .ge. 2 means RES returned an error flag IRES = IER. +C IER .lt. 0 means the a-matrix was found to be singular. +C----------------------------------------------------------------------- +C + IF (MITER .GE. 4) GO TO 100 +C +C Full matrix case ----------------------------------------------------- +C + LENPW = NEQ*NEQ + DO 10 I = 1, LENPW + 10 PW(I) = 0.0D0 +C + IER = 1 + CALL RES ( NEQ, T, Y, PW, YDOT, IER ) + IF (IER .GT. 1) RETURN +C + CALL ADDA ( NEQ, T, Y, 0, 0, PW, NEQ ) + CALL DGEFA ( PW, NEQ, NEQ, IPVT, IER ) + IF (IER .EQ. 0) GO TO 20 + IER = -IER + RETURN + 20 CALL DGESL ( PW, NEQ, NEQ, IPVT, YDOT, 0 ) + RETURN +C +C Band matrix case ----------------------------------------------------- +C + 100 CONTINUE + NROWPW = 2*ML + MU + 1 + LENPW = NEQ * NROWPW + DO 110 I = 1, LENPW + 110 PW(I) = 0.0D0 +C + IER = 1 + CALL RES ( NEQ, T, Y, PW, YDOT, IER ) + IF (IER .GT. 1) RETURN +C + MLP1 = ML + 1 + CALL ADDA ( NEQ, T, Y, ML, MU, PW(MLP1), NROWPW ) + CALL DGBFA ( PW, NROWPW, NEQ, ML, MU, IPVT, IER ) + IF (IER .EQ. 0) GO TO 120 + IER = -IER + RETURN + 120 CALL DGBSL ( PW, NROWPW, NEQ, ML, MU, IPVT, YDOT, 0 ) + RETURN +C----------------------- End of Subroutine DAINVG ---------------------- + END +*DECK DSTODI + SUBROUTINE DSTODI (NEQ, Y, YH, NYH, YH1, EWT, SAVF, SAVR, + 1 ACOR, WM, IWM, RES, ADDA, JAC, PJAC, SLVS ) + EXTERNAL RES, ADDA, JAC, PJAC, SLVS + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, YH1, EWT, SAVF, SAVR, ACOR, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), YH1(*), EWT(*), SAVF(*), + 1 SAVR(*), ACOR(*), WM(*), IWM(*) + INTEGER IOWND, IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION CONIT, CRATE, EL, ELCO, HOLD, RMAX, TESCO, + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ CONIT, CRATE, EL(13), ELCO(13,12), + 1 HOLD, RMAX, TESCO(3,12), + 2 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 3 IOWND(6), IALTH, IPUP, LMAX, MEO, NQNYH, NSLP, + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, IREDO, IRES, IRET, J, JB, KGO, M, NCF, NEWQ + DOUBLE PRECISION DCON, DDN, DEL, DELP, DSM, DUP, + 1 ELJH, EL1H, EXDN, EXSM, EXUP, + 2 R, RH, RHDN, RHSM, RHUP, TOLD, DVNORM +C----------------------------------------------------------------------- +C DSTODI performs one step of the integration of an initial value +C problem for a system of Ordinary Differential Equations. +C Note: DSTODI is independent of the value of the iteration method +C indicator MITER, and hence is independent +C of the type of chord method used, or the Jacobian structure. +C Communication with DSTODI is done with the following variables: +C +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls to RES, ADDA, +C and JAC. +C Y = an array of length .ge. N used as the Y argument in +C all calls to RES, JAC, and ADDA. +C NEQ = integer array containing problem size in NEQ(1), and +C passed as the NEQ argument in all calls tO RES, G, ADDA, +C and JAC. +C YH = an NYH by LMAX array containing the dependent variables +C and their approximate scaled derivatives, where +C LMAX = MAXORD + 1. YH(i,j+1) contains the approximate +C j-th derivative of y(i), scaled by H**j/factorial(j) +C (j = 0,1,...,NQ). On entry for the first step, the first +C two columns of YH must be set from the initial values. +C NYH = a constant integer .ge. N, the first dimension of YH. +C YH1 = a one-dimensional array occupying the same space as YH. +C EWT = an array of length N containing multiplicative weights +C for local error measurements. Local errors in y(i) are +C compared to 1.0/EWT(i) in various error tests. +C SAVF = an array of working storage, of length N. also used for +C input of YH(*,MAXORD+2) when JSTART = -1 and MAXORD is less +C than the current order NQ. +C Same as YDOTI in the driver. +C SAVR = an array of working storage, of length N. +C ACOR = a work array of length N used for the accumulated +C corrections. On a succesful return, ACOR(i) contains +C the estimated one-step local error in y(i). +C WM,IWM = real and integer work arrays associated with matrix +C operations in chord iteration. +C PJAC = name of routine to evaluate and preprocess Jacobian matrix. +C SLVS = name of routine to solve linear system in chord iteration. +C CCMAX = maximum relative change in H*EL0 before PJAC is called. +C H = the step size to be attempted on the next step. +C H is altered by the error control algorithm during the +C problem. H can be either positive or negative, but its +C sign must remain constant throughout the problem. +C HMIN = the minimum absolute value of the step size H to be used. +C HMXI = inverse of the maximum absolute value of H to be used. +C HMXI = 0.0 is allowed and corresponds to an infinite HMAX. +C HMIN and HMXI may be changed at any time, but will not +C take effect until the next change of H is considered. +C TN = the independent variable. TN is updated on each step taken. +C JSTART = an integer used for input only, with the following +C values and meanings: +C 0 perform the first step. +C .gt.0 take a new step continuing from the last. +C -1 take the next step with a new value of H, MAXORD, +C N, METH, MITER, and/or matrix parameters. +C -2 take the next step with a new value of H, +C but with other inputs unchanged. +C On return, JSTART is set to 1 to facilitate continuation. +C KFLAG = a completion code with the following meanings: +C 0 the step was succesful. +C -1 the requested error could not be achieved. +C -2 corrector convergence could not be achieved. +C -3 RES ordered immediate return. +C -4 error condition from RES could not be avoided. +C -5 fatal error in PJAC or SLVS. +C A return with KFLAG = -1, -2, or -4 means either +C ABS(H) = HMIN or 10 consecutive failures occurred. +C On a return with KFLAG negative, the values of TN and +C the YH array are as of the beginning of the last +C step, and H is the last step size attempted. +C MAXORD = the maximum order of integration method to be allowed. +C MAXCOR = the maximum number of corrector iterations allowed. +C MSBP = maximum number of steps between PJAC calls. +C MXNCF = maximum number of convergence failures allowed. +C METH/MITER = the method flags. See description in driver. +C N = the number of first-order differential equations. +C----------------------------------------------------------------------- + KFLAG = 0 + TOLD = TN + NCF = 0 + IERPJ = 0 + IERSL = 0 + JCUR = 0 + ICF = 0 + DELP = 0.0D0 + IF (JSTART .GT. 0) GO TO 200 + IF (JSTART .EQ. -1) GO TO 100 + IF (JSTART .EQ. -2) GO TO 160 +C----------------------------------------------------------------------- +C On the first call, the order is set to 1, and other variables are +C initialized. RMAX is the maximum ratio by which H can be increased +C in a single step. It is initially 1.E4 to compensate for the small +C initial H, but then is normally equal to 10. If a failure +C occurs (in corrector convergence or error test), RMAX is set at 2 +C for the next increase. +C----------------------------------------------------------------------- + LMAX = MAXORD + 1 + NQ = 1 + L = 2 + IALTH = 2 + RMAX = 10000.0D0 + RC = 0.0D0 + EL0 = 1.0D0 + CRATE = 0.7D0 + HOLD = H + MEO = METH + NSLP = 0 + IPUP = MITER + IRET = 3 + GO TO 140 +C----------------------------------------------------------------------- +C The following block handles preliminaries needed when JSTART = -1. +C IPUP is set to MITER to force a matrix update. +C If an order increase is about to be considered (IALTH = 1), +C IALTH is reset to 2 to postpone consideration one more step. +C If the caller has changed METH, DCFODE is called to reset +C the coefficients of the method. +C If the caller has changed MAXORD to a value less than the current +C order NQ, NQ is reduced to MAXORD, and a new H chosen accordingly. +C If H is to be changed, YH must be rescaled. +C If H or METH is being changed, IALTH is reset to L = NQ + 1 +C to prevent further changes in H for that many steps. +C----------------------------------------------------------------------- + 100 IPUP = MITER + LMAX = MAXORD + 1 + IF (IALTH .EQ. 1) IALTH = 2 + IF (METH .EQ. MEO) GO TO 110 + CALL DCFODE (METH, ELCO, TESCO) + MEO = METH + IF (NQ .GT. MAXORD) GO TO 120 + IALTH = L + IRET = 1 + GO TO 150 + 110 IF (NQ .LE. MAXORD) GO TO 160 + 120 NQ = MAXORD + L = LMAX + DO 125 I = 1,L + 125 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + DDN = DVNORM (N, SAVF, EWT)/TESCO(1,L) + EXDN = 1.0D0/L + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + RH = MIN(RHDN,1.0D0) + IREDO = 3 + IF (H .EQ. HOLD) GO TO 170 + RH = MIN(RH,ABS(H/HOLD)) + H = HOLD + GO TO 175 +C----------------------------------------------------------------------- +C DCFODE is called to get all the integration coefficients for the +C current METH. Then the EL vector and related constants are reset +C whenever the order NQ is changed, or at the start of the problem. +C----------------------------------------------------------------------- + 140 CALL DCFODE (METH, ELCO, TESCO) + 150 DO 155 I = 1,L + 155 EL(I) = ELCO(I,NQ) + NQNYH = NQ*NYH + RC = RC*EL(1)/EL0 + EL0 = EL(1) + CONIT = 0.5D0/(NQ+2) + GO TO (160, 170, 200), IRET +C----------------------------------------------------------------------- +C If H is being changed, the H ratio RH is checked against +C RMAX, HMIN, and HMXI, and the YH array rescaled. IALTH is set to +C L = NQ + 1 to prevent a change of H for that many steps, unless +C forced by a convergence or error test failure. +C----------------------------------------------------------------------- + 160 IF (H .EQ. HOLD) GO TO 200 + RH = H/HOLD + H = HOLD + IREDO = 3 + GO TO 175 + 170 RH = MAX(RH,HMIN/ABS(H)) + 175 RH = MIN(RH,RMAX) + RH = RH/MAX(1.0D0,ABS(H)*HMXI*RH) + R = 1.0D0 + DO 180 J = 2,L + R = R*RH + DO 180 I = 1,N + 180 YH(I,J) = YH(I,J)*R + H = H*RH + RC = RC*RH + IALTH = L + IF (IREDO .EQ. 0) GO TO 690 +C----------------------------------------------------------------------- +C This section computes the predicted values by effectively +C multiplying the YH array by the Pascal triangle matrix. +C RC is the ratio of new to old values of the coefficient H*EL(1). +C When RC differs from 1 by more than CCMAX, IPUP is set to MITER +C to force PJAC to be called. +C In any case, PJAC is called at least every MSBP steps. +C----------------------------------------------------------------------- + 200 IF (ABS(RC-1.0D0) .GT. CCMAX) IPUP = MITER + IF (NST .GE. NSLP+MSBP) IPUP = MITER + TN = TN + H + I1 = NQNYH + 1 + DO 215 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 210 I = I1,NQNYH + 210 YH1(I) = YH1(I) + YH1(I+NYH) + 215 CONTINUE +C----------------------------------------------------------------------- +C Up to MAXCOR corrector iterations are taken. A convergence test is +C made on the RMS-norm of each correction, weighted by H and the +C error weight vector EWT. The sum of the corrections is accumulated +C in ACOR(i). The YH array is not altered in the corrector loop. +C----------------------------------------------------------------------- + 220 M = 0 + DO 230 I = 1,N + SAVF(I) = YH(I,2) / H + 230 Y(I) = YH(I,1) + IF (IPUP .LE. 0) GO TO 240 +C----------------------------------------------------------------------- +C If indicated, the matrix P = A - H*EL(1)*dr/dy is reevaluated and +C preprocessed before starting the corrector iteration. IPUP is set +C to 0 as an indicator that this has been done. +C----------------------------------------------------------------------- + CALL PJAC (NEQ, Y, YH, NYH, EWT, ACOR, SAVR, SAVF, WM, IWM, + 1 RES, JAC, ADDA ) + IPUP = 0 + RC = 1.0D0 + NSLP = NST + CRATE = 0.7D0 + IF (IERPJ .EQ. 0) GO TO 250 + IF (IERPJ .LT. 0) GO TO 435 + IRES = IERPJ + GO TO (430, 435, 430), IRES +C Get residual at predicted values, if not already done in PJAC. ------- + 240 IRES = 1 + CALL RES ( NEQ, TN, Y, SAVF, SAVR, IRES ) + NFE = NFE + 1 + KGO = ABS(IRES) + GO TO ( 250, 435, 430 ) , KGO + 250 DO 260 I = 1,N + 260 ACOR(I) = 0.0D0 +C----------------------------------------------------------------------- +C Solve the linear system with the current residual as +C right-hand side and P as coefficient matrix. +C----------------------------------------------------------------------- + 270 CONTINUE + CALL SLVS (WM, IWM, SAVR, SAVF) + IF (IERSL .LT. 0) GO TO 430 + IF (IERSL .GT. 0) GO TO 410 + EL1H = EL(1) * H + DEL = DVNORM (N, SAVR, EWT) * ABS(H) + DO 380 I = 1,N + ACOR(I) = ACOR(I) + SAVR(I) + SAVF(I) = ACOR(I) + YH(I,2)/H + 380 Y(I) = YH(I,1) + EL1H*ACOR(I) +C----------------------------------------------------------------------- +C Test for convergence. If M .gt. 0, an estimate of the convergence +C rate constant is stored in CRATE, and this is used in the test. +C----------------------------------------------------------------------- + IF (M .NE. 0) CRATE = MAX(0.2D0*CRATE,DEL/DELP) + DCON = DEL*MIN(1.0D0,1.5D0*CRATE)/(TESCO(2,NQ)*CONIT) + IF (DCON .LE. 1.0D0) GO TO 460 + M = M + 1 + IF (M .EQ. MAXCOR) GO TO 410 + IF (M .GE. 2 .AND. DEL .GT. 2.0D0*DELP) GO TO 410 + DELP = DEL + IRES = 1 + CALL RES ( NEQ, TN, Y, SAVF, SAVR, IRES ) + NFE = NFE + 1 + KGO = ABS(IRES) + GO TO ( 270, 435, 410 ) , KGO +C----------------------------------------------------------------------- +C The correctors failed to converge, or RES has returned abnormally. +C on a convergence failure, if the Jacobian is out of date, PJAC is +C called for the next try. Otherwise the YH array is retracted to its +C values before prediction, and H is reduced, if possible. +C take an error exit if IRES = 2, or H cannot be reduced, or MXNCF +C failures have occurred, or a fatal error occurred in PJAC or SLVS. +C----------------------------------------------------------------------- + 410 ICF = 1 + IF (JCUR .EQ. 1) GO TO 430 + IPUP = MITER + GO TO 220 + 430 ICF = 2 + NCF = NCF + 1 + RMAX = 2.0D0 + 435 TN = TOLD + I1 = NQNYH + 1 + DO 445 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 440 I = I1,NQNYH + 440 YH1(I) = YH1(I) - YH1(I+NYH) + 445 CONTINUE + IF (IRES .EQ. 2) GO TO 680 + IF (IERPJ .LT. 0 .OR. IERSL .LT. 0) GO TO 685 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 450 + IF (NCF .EQ. MXNCF) GO TO 450 + RH = 0.25D0 + IPUP = MITER + IREDO = 1 + GO TO 170 + 450 IF (IRES .EQ. 3) GO TO 680 + GO TO 670 +C----------------------------------------------------------------------- +C The corrector has converged. JCUR is set to 0 +C to signal that the Jacobian involved may need updating later. +C The local error test is made and control passes to statement 500 +C if it fails. +C----------------------------------------------------------------------- + 460 JCUR = 0 + IF (M .EQ. 0) DSM = DEL/TESCO(2,NQ) + IF (M .GT. 0) DSM = ABS(H) * DVNORM (N, ACOR, EWT)/TESCO(2,NQ) + IF (DSM .GT. 1.0D0) GO TO 500 +C----------------------------------------------------------------------- +C After a successful step, update the YH array. +C Consider changing H if IALTH = 1. Otherwise decrease IALTH by 1. +C If IALTH is then 1 and NQ .lt. MAXORD, then ACOR is saved for +C use in a possible order increase on the next step. +C If a change in H is considered, an increase or decrease in order +C by one is considered also. A change in H is made only if it is by a +C factor of at least 1.1. If not, IALTH is set to 3 to prevent +C testing for that many steps. +C----------------------------------------------------------------------- + KFLAG = 0 + IREDO = 0 + NST = NST + 1 + HU = H + NQU = NQ + DO 470 J = 1,L + ELJH = EL(J)*H + DO 470 I = 1,N + 470 YH(I,J) = YH(I,J) + ELJH*ACOR(I) + IALTH = IALTH - 1 + IF (IALTH .EQ. 0) GO TO 520 + IF (IALTH .GT. 1) GO TO 700 + IF (L .EQ. LMAX) GO TO 700 + DO 490 I = 1,N + 490 YH(I,LMAX) = ACOR(I) + GO TO 700 +C----------------------------------------------------------------------- +C The error test failed. KFLAG keeps track of multiple failures. +C restore TN and the YH array to their previous values, and prepare +C to try the step again. Compute the optimum step size for this or +C one lower order. After 2 or more failures, H is forced to decrease +C by a factor of 0.1 or less. +C----------------------------------------------------------------------- + 500 KFLAG = KFLAG - 1 + TN = TOLD + I1 = NQNYH + 1 + DO 515 JB = 1,NQ + I1 = I1 - NYH +CDIR$ IVDEP + DO 510 I = I1,NQNYH + 510 YH1(I) = YH1(I) - YH1(I+NYH) + 515 CONTINUE + RMAX = 2.0D0 + IF (ABS(H) .LE. HMIN*1.00001D0) GO TO 660 + IF (KFLAG .LE. -7) GO TO 660 + IREDO = 2 + RHUP = 0.0D0 + GO TO 540 +C----------------------------------------------------------------------- +C Regardless of the success or failure of the step, factors +C RHDN, RHSM, and RHUP are computed, by which H could be multiplied +C at order NQ - 1, order NQ, or order NQ + 1, respectively. +C In the case of failure, RHUP = 0.0 to avoid an order increase. +C The largest of these is determined and the new order chosen +C accordingly. If the order is to be increased, we compute one +C additional scaled derivative. +C----------------------------------------------------------------------- + 520 RHUP = 0.0D0 + IF (L .EQ. LMAX) GO TO 540 + DO 530 I = 1,N + 530 SAVF(I) = ACOR(I) - YH(I,LMAX) + DUP = ABS(H) * DVNORM (N, SAVF, EWT)/TESCO(3,NQ) + EXUP = 1.0D0/(L+1) + RHUP = 1.0D0/(1.4D0*DUP**EXUP + 0.0000014D0) + 540 EXSM = 1.0D0/L + RHSM = 1.0D0/(1.2D0*DSM**EXSM + 0.0000012D0) + RHDN = 0.0D0 + IF (NQ .EQ. 1) GO TO 560 + DDN = DVNORM (N, YH(1,L), EWT)/TESCO(1,NQ) + EXDN = 1.0D0/NQ + RHDN = 1.0D0/(1.3D0*DDN**EXDN + 0.0000013D0) + 560 IF (RHSM .GE. RHUP) GO TO 570 + IF (RHUP .GT. RHDN) GO TO 590 + GO TO 580 + 570 IF (RHSM .LT. RHDN) GO TO 580 + NEWQ = NQ + RH = RHSM + GO TO 620 + 580 NEWQ = NQ - 1 + RH = RHDN + IF (KFLAG .LT. 0 .AND. RH .GT. 1.0D0) RH = 1.0D0 + GO TO 620 + 590 NEWQ = L + RH = RHUP + IF (RH .LT. 1.1D0) GO TO 610 + R = H*EL(L)/L + DO 600 I = 1,N + 600 YH(I,NEWQ+1) = ACOR(I)*R + GO TO 630 + 610 IALTH = 3 + GO TO 700 + 620 IF ((KFLAG .EQ. 0) .AND. (RH .LT. 1.1D0)) GO TO 610 + IF (KFLAG .LE. -2) RH = MIN(RH,0.1D0) +C----------------------------------------------------------------------- +C If there is a change of order, reset NQ, L, and the coefficients. +C In any case H is reset according to RH and the YH array is rescaled. +C Then exit from 690 if the step was OK, or redo the step otherwise. +C----------------------------------------------------------------------- + IF (NEWQ .EQ. NQ) GO TO 170 + 630 NQ = NEWQ + L = NQ + 1 + IRET = 2 + GO TO 150 +C----------------------------------------------------------------------- +C All returns are made through this section. H is saved in HOLD +C to allow the caller to change H on the next step. +C----------------------------------------------------------------------- + 660 KFLAG = -1 + GO TO 720 + 670 KFLAG = -2 + GO TO 720 + 680 KFLAG = -1 - IRES + GO TO 720 + 685 KFLAG = -5 + GO TO 720 + 690 RMAX = 10.0D0 + 700 R = H/TESCO(2,NQU) + DO 710 I = 1,N + 710 ACOR(I) = ACOR(I)*R + 720 HOLD = H + JSTART = 1 + RETURN +C----------------------- End of Subroutine DSTODI ---------------------- + END +*DECK DPREPJI + SUBROUTINE DPREPJI (NEQ, Y, YH, NYH, EWT, RTEM, SAVR, S, WM, IWM, + 1 RES, JAC, ADDA) + EXTERNAL RES, JAC, ADDA + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, EWT, RTEM, SAVR, S, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), RTEM(*), + 1 S(*), SAVR(*), WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, I2, IER, II, IRES, J, J1, JJ, LENP, + 1 MBA, MBAND, MEB1, MEBAND, ML, ML3, MU + DOUBLE PRECISION CON, FAC, HL0, R, SRUR, YI, YJ, YJJ +C----------------------------------------------------------------------- +C DPREPJI is called by DSTODI to compute and process the matrix +C P = A - H*EL(1)*J , where J is an approximation to the Jacobian dr/dy, +C where r = g(t,y) - A(t,y)*s. Here J is computed by the user-supplied +C routine JAC if MITER = 1 or 4, or by finite differencing if MITER = +C 2 or 5. J is stored in WM, rescaled, and ADDA is called to generate +C P. P is then subjected to LU decomposition in preparation +C for later solution of linear systems with P as coefficient +C matrix. This is done by DGEFA if MITER = 1 or 2, and by +C DGBFA if MITER = 4 or 5. +C +C In addition to variables described previously, communication +C with DPREPJI uses the following: +C Y = array containing predicted values on entry. +C RTEM = work array of length N (ACOR in DSTODI). +C SAVR = array used for output only. On output it contains the +C residual evaluated at current values of t and y. +C S = array containing predicted values of dy/dt (SAVF in DSTODI). +C WM = real work space for matrices. On output it contains the +C LU decomposition of P. +C Storage of matrix elements starts at WM(3). +C WM also contains the following matrix-related data: +C WM(1) = SQRT(UROUND), used in numerical Jacobian increments. +C IWM = integer work space containing pivot information, starting at +C IWM(21). IWM also contains the band parameters +C ML = IWM(1) and MU = IWM(2) if MITER is 4 or 5. +C EL0 = el(1) (input). +C IERPJ = output error flag. +C = 0 if no trouble occurred, +C = 1 if the P matrix was found to be singular, +C = IRES (= 2 or 3) if RES returned IRES = 2 or 3. +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses the Common variables EL0, H, TN, UROUND, +C MITER, N, NFE, and NJE. +C----------------------------------------------------------------------- + NJE = NJE + 1 + HL0 = H*EL0 + IERPJ = 0 + JCUR = 1 + GO TO (100, 200, 300, 400, 500), MITER +C If MITER = 1, call RES, then JAC, and multiply by scalar. ------------ + 100 IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + LENP = N*N + DO 110 I = 1,LENP + 110 WM(I+2) = 0.0D0 + CALL JAC ( NEQ, TN, Y, S, 0, 0, WM(3), N ) + CON = -HL0 + DO 120 I = 1,LENP + 120 WM(I+2) = WM(I+2)*CON + GO TO 240 +C If MITER = 2, make N + 1 calls to RES to approximate J. -------------- + 200 CONTINUE + IRES = -1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + SRUR = WM(1) + J1 = 2 + DO 230 J = 1,N + YJ = Y(J) + R = MAX(SRUR*ABS(YJ),0.01D0/EWT(J)) + Y(J) = Y(J) + R + FAC = -HL0/R + CALL RES ( NEQ, TN, Y, S, RTEM, IRES ) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + DO 220 I = 1,N + 220 WM(I+J1) = (RTEM(I) - SAVR(I))*FAC + Y(J) = YJ + J1 = J1 + N + 230 CONTINUE + IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 +C Add matrix A. -------------------------------------------------------- + 240 CONTINUE + CALL ADDA(NEQ, TN, Y, 0, 0, WM(3), N) +C Do LU decomposition on P. -------------------------------------------- + CALL DGEFA (WM(3), N, N, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C Dummy section for MITER = 3 + 300 RETURN +C If MITER = 4, call RES, then JAC, and multiply by scalar. ------------ + 400 IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + ML = IWM(1) + MU = IWM(2) + ML3 = ML + 3 + MBAND = ML + MU + 1 + MEBAND = MBAND + ML + LENP = MEBAND*N + DO 410 I = 1,LENP + 410 WM(I+2) = 0.0D0 + CALL JAC ( NEQ, TN, Y, S, ML, MU, WM(ML3), MEBAND) + CON = -HL0 + DO 420 I = 1,LENP + 420 WM(I+2) = WM(I+2)*CON + GO TO 570 +C If MITER = 5, make ML + MU + 2 calls to RES to approximate J. -------- + 500 CONTINUE + IRES = -1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + ML = IWM(1) + MU = IWM(2) + ML3 = ML + 3 + MBAND = ML + MU + 1 + MBA = MIN(MBAND,N) + MEBAND = MBAND + ML + MEB1 = MEBAND - 1 + SRUR = WM(1) + DO 560 J = 1,MBA + DO 530 I = J,N,MBAND + YI = Y(I) + R = MAX(SRUR*ABS(YI),0.01D0/EWT(I)) + 530 Y(I) = Y(I) + R + CALL RES ( NEQ, TN, Y, S, RTEM, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + DO 550 JJ = J,N,MBAND + Y(JJ) = YH(JJ,1) + YJJ = Y(JJ) + R = MAX(SRUR*ABS(YJJ),0.01D0/EWT(JJ)) + FAC = -HL0/R + I1 = MAX(JJ-MU,1) + I2 = MIN(JJ+ML,N) + II = JJ*MEB1 - ML + 2 + DO 540 I = I1,I2 + 540 WM(II+I) = (RTEM(I) - SAVR(I))*FAC + 550 CONTINUE + 560 CONTINUE + IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 +C Add matrix A. -------------------------------------------------------- + 570 CONTINUE + CALL ADDA(NEQ, TN, Y, ML, MU, WM(ML3), MEBAND) +C Do LU decomposition of P. -------------------------------------------- + CALL DGBFA (WM(3), MEBAND, N, ML, MU, IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C Error return for IRES = 2 or IRES = 3 return from RES. --------------- + 600 IERPJ = IRES + RETURN +C----------------------- End of Subroutine DPREPJI --------------------- + END +*DECK DAIGBT + SUBROUTINE DAIGBT (RES, ADDA, NEQ, T, Y, YDOT, + 1 MB, NB, PW, IPVT, IER ) + EXTERNAL RES, ADDA + INTEGER NEQ, MB, NB, IPVT, IER + INTEGER I, LENPW, LBLOX, LPB, LPC + DOUBLE PRECISION T, Y, YDOT, PW + DIMENSION Y(*), YDOT(*), PW(*), IPVT(*), NEQ(*) +C----------------------------------------------------------------------- +C This subroutine computes the initial value +C of the vector YDOT satisfying +C A * YDOT = g(t,y) +C when A is nonsingular. It is called by DLSOIBT for +C initialization only, when ISTATE = 0 . +C DAIGBT returns an error flag IER: +C IER = 0 means DAIGBT was successful. +C IER .ge. 2 means RES returned an error flag IRES = IER. +C IER .lt. 0 means the A matrix was found to have a singular +C diagonal block (hence YDOT could not be solved for). +C----------------------------------------------------------------------- + LBLOX = MB*MB*NB + LPB = 1 + LBLOX + LPC = LPB + LBLOX + LENPW = 3*LBLOX + DO 10 I = 1,LENPW + 10 PW(I) = 0.0D0 + IER = 1 + CALL RES (NEQ, T, Y, PW, YDOT, IER) + IF (IER .GT. 1) RETURN + CALL ADDA (NEQ, T, Y, MB, NB, PW(1), PW(LPB), PW(LPC) ) + CALL DDECBT (MB, NB, PW, PW(LPB), PW(LPC), IPVT, IER) + IF (IER .EQ. 0) GO TO 20 + IER = -IER + RETURN + 20 CALL DSOLBT (MB, NB, PW, PW(LPB), PW(LPC), YDOT, IPVT) + RETURN +C----------------------- End of Subroutine DAIGBT ---------------------- + END +*DECK DPJIBT + SUBROUTINE DPJIBT (NEQ, Y, YH, NYH, EWT, RTEM, SAVR, S, WM, IWM, + 1 RES, JAC, ADDA) + EXTERNAL RES, JAC, ADDA + INTEGER NEQ, NYH, IWM + DOUBLE PRECISION Y, YH, EWT, RTEM, SAVR, S, WM + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), RTEM(*), + 1 S(*), SAVR(*), WM(*), IWM(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, IER, IIA, IIB, IIC, IPA, IPB, IPC, IRES, J, J1, J2, + 1 K, K1, LENP, LBLOX, LPB, LPC, MB, MBSQ, MWID, NB + DOUBLE PRECISION CON, FAC, HL0, R, SRUR +C----------------------------------------------------------------------- +C DPJIBT is called by DSTODI to compute and process the matrix +C P = A - H*EL(1)*J , where J is an approximation to the Jacobian dr/dy, +C and r = g(t,y) - A(t,y)*s. Here J is computed by the user-supplied +C routine JAC if MITER = 1, or by finite differencing if MITER = 2. +C J is stored in WM, rescaled, and ADDA is called to generate P. +C P is then subjected to LU decomposition by DDECBT in preparation +C for later solution of linear systems with P as coefficient matrix. +C +C In addition to variables described previously, communication +C with DPJIBT uses the following: +C Y = array containing predicted values on entry. +C RTEM = work array of length N (ACOR in DSTODI). +C SAVR = array used for output only. On output it contains the +C residual evaluated at current values of t and y. +C S = array containing predicted values of dy/dt (SAVF in DSTODI). +C WM = real work space for matrices. On output it contains the +C LU decomposition of P. +C Storage of matrix elements starts at WM(3). +C WM also contains the following matrix-related data: +C WM(1) = SQRT(UROUND), used in numerical Jacobian increments. +C IWM = integer work space containing pivot information, starting at +C IWM(21). IWM also contains block structure parameters +C MB = IWM(1) and NB = IWM(2). +C EL0 = EL(1) (input). +C IERPJ = output error flag. +C = 0 if no trouble occurred, +C = 1 if the P matrix was found to be unfactorable, +C = IRES (= 2 or 3) if RES returned IRES = 2 or 3. +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses the Common variables EL0, H, TN, UROUND, +C MITER, N, NFE, and NJE. +C----------------------------------------------------------------------- + NJE = NJE + 1 + HL0 = H*EL0 + IERPJ = 0 + JCUR = 1 + MB = IWM(1) + NB = IWM(2) + MBSQ = MB*MB + LBLOX = MBSQ*NB + LPB = 3 + LBLOX + LPC = LPB + LBLOX + LENP = 3*LBLOX + GO TO (100, 200), MITER +C If MITER = 1, call RES, then JAC, and multiply by scalar. ------------ + 100 IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + DO 110 I = 1,LENP + 110 WM(I+2) = 0.0D0 + CALL JAC (NEQ, TN, Y, S, MB, NB, WM(3), WM(LPB), WM(LPC)) + CON = -HL0 + DO 120 I = 1,LENP + 120 WM(I+2) = WM(I+2)*CON + GO TO 260 +C +C If MITER = 2, make 3*MB + 1 calls to RES to approximate J. ----------- + 200 CONTINUE + IRES = -1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + MWID = 3*MB + SRUR = WM(1) + DO 205 I = 1,LENP + 205 WM(2+I) = 0.0D0 + DO 250 K = 1,3 + DO 240 J = 1,MB +C Increment Y(I) for group of column indices, and call RES. ---- + J1 = J+(K-1)*MB + DO 210 I = J1,N,MWID + R = MAX(SRUR*ABS(Y(I)),0.01D0/EWT(I)) + Y(I) = Y(I) + R + 210 CONTINUE + CALL RES (NEQ, TN, Y, S, RTEM, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + DO 215 I = 1,N + 215 RTEM(I) = RTEM(I) - SAVR(I) + K1 = K + DO 230 I = J1,N,MWID +C Get Jacobian elements in column I (block-column K1). ------- + Y(I) = YH(I,1) + R = MAX(SRUR*ABS(Y(I)),0.01D0/EWT(I)) + FAC = -HL0/R +C Compute and load elements PA(*,J,K1). ---------------------- + IIA = I - J + IPA = 2 + (J-1)*MB + (K1-1)*MBSQ + DO 221 J2 = 1,MB + 221 WM(IPA+J2) = RTEM(IIA+J2)*FAC + IF (K1 .LE. 1) GO TO 223 +C Compute and load elements PB(*,J,K1-1). -------------------- + IIB = IIA - MB + IPB = IPA + LBLOX - MBSQ + DO 222 J2 = 1,MB + 222 WM(IPB+J2) = RTEM(IIB+J2)*FAC + 223 CONTINUE + IF (K1 .GE. NB) GO TO 225 +C Compute and load elements PC(*,J,K1+1). -------------------- + IIC = IIA + MB + IPC = IPA + 2*LBLOX + MBSQ + DO 224 J2 = 1,MB + 224 WM(IPC+J2) = RTEM(IIC+J2)*FAC + 225 CONTINUE + IF (K1 .NE. 3) GO TO 227 +C Compute and load elements PC(*,J,1). ----------------------- + IPC = IPA - 2*MBSQ + 2*LBLOX + DO 226 J2 = 1,MB + 226 WM(IPC+J2) = RTEM(J2)*FAC + 227 CONTINUE + IF (K1 .NE. NB-2) GO TO 229 +C Compute and load elements PB(*,J,NB). ---------------------- + IIB = N - MB + IPB = IPA + 2*MBSQ + LBLOX + DO 228 J2 = 1,MB + 228 WM(IPB+J2) = RTEM(IIB+J2)*FAC + 229 K1 = K1 + 3 + 230 CONTINUE + 240 CONTINUE + 250 CONTINUE +C RES call for first corrector iteration. ------------------------------ + IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 +C Add matrix A. -------------------------------------------------------- + 260 CONTINUE + CALL ADDA (NEQ, TN, Y, MB, NB, WM(3), WM(LPB), WM(LPC)) +C Do LU decomposition on P. -------------------------------------------- + CALL DDECBT (MB, NB, WM(3), WM(LPB), WM(LPC), IWM(21), IER) + IF (IER .NE. 0) IERPJ = 1 + RETURN +C Error return for IRES = 2 or IRES = 3 return from RES. --------------- + 600 IERPJ = IRES + RETURN +C----------------------- End of Subroutine DPJIBT ---------------------- + END +*DECK DSLSBT + SUBROUTINE DSLSBT (WM, IWM, X, TEM) + INTEGER IWM + INTEGER LBLOX, LPB, LPC, MB, NB + DOUBLE PRECISION WM, X, TEM + DIMENSION WM(*), IWM(*), X(*), TEM(*) +C----------------------------------------------------------------------- +C This routine acts as an interface between the core integrator +C routine and the DSOLBT routine for the solution of the linear system +C arising from chord iteration. +C Communication with DSLSBT uses the following variables: +C WM = real work space containing the LU decomposition, +C starting at WM(3). +C IWM = integer work space containing pivot information, starting at +C IWM(21). IWM also contains block structure parameters +C MB = IWM(1) and NB = IWM(2). +C X = the right-hand side vector on input, and the solution vector +C on output, of length N. +C TEM = vector of work space of length N, not used in this version. +C----------------------------------------------------------------------- + MB = IWM(1) + NB = IWM(2) + LBLOX = MB*MB*NB + LPB = 3 + LBLOX + LPC = LPB + LBLOX + CALL DSOLBT (MB, NB, WM(3), WM(LPB), WM(LPC), X, IWM(21)) + RETURN +C----------------------- End of Subroutine DSLSBT ---------------------- + END +*DECK DDECBT + SUBROUTINE DDECBT (M, N, A, B, C, IP, IER) + INTEGER M, N, IP(M,N), IER + DOUBLE PRECISION A(M,M,N), B(M,M,N), C(M,M,N) +C----------------------------------------------------------------------- +C Block-tridiagonal matrix decomposition routine. +C Written by A. C. Hindmarsh. +C Latest revision: November 10, 1983 (ACH) +C Reference: UCID-30150 +C Solution of Block-Tridiagonal Systems of Linear +C Algebraic Equations +C A.C. Hindmarsh +C February 1977 +C The input matrix contains three blocks of elements in each block-row, +C including blocks in the (1,3) and (N,N-2) block positions. +C DDECBT uses block Gauss elimination and Subroutines DGEFA and DGESL +C for solution of blocks. Partial pivoting is done within +C block-rows only. +C +C Note: this version uses LINPACK routines DGEFA/DGESL instead of +C of dec/sol for solution of blocks, and it uses the BLAS routine DDOT +C for dot product calculations. +C +C Input: +C M = order of each block. +C N = number of blocks in each direction of the matrix. +C N must be 4 or more. The complete matrix has order M*N. +C A = M by M by N array containing diagonal blocks. +C A(i,j,k) contains the (i,j) element of the k-th block. +C B = M by M by N array containing the super-diagonal blocks +C (in B(*,*,k) for k = 1,...,N-1) and the block in the (N,N-2) +C block position (in B(*,*,N)). +C C = M by M by N array containing the subdiagonal blocks +C (in C(*,*,k) for k = 2,3,...,N) and the block in the +C (1,3) block position (in C(*,*,1)). +C IP = integer array of length M*N for working storage. +C Output: +C A,B,C = M by M by N arrays containing the block-LU decomposition +C of the input matrix. +C IP = M by N array of pivot information. IP(*,k) contains +C information for the k-th digonal block. +C IER = 0 if no trouble occurred, or +C = -1 if the input value of M or N was illegal, or +C = k if a singular matrix was found in the k-th diagonal block. +C Use DSOLBT to solve the associated linear system. +C +C External routines required: DGEFA and DGESL (from LINPACK) and +C DDOT (from the BLAS, or Basic Linear Algebra package). +C----------------------------------------------------------------------- + INTEGER NM1, NM2, KM1, I, J, K + DOUBLE PRECISION DP, DDOT + IF (M .LT. 1 .OR. N .LT. 4) GO TO 210 + NM1 = N - 1 + NM2 = N - 2 +C Process the first block-row. ----------------------------------------- + CALL DGEFA (A, M, M, IP, IER) + K = 1 + IF (IER .NE. 0) GO TO 200 + DO 10 J = 1,M + CALL DGESL (A, M, M, IP, B(1,J,1), 0) + CALL DGESL (A, M, M, IP, C(1,J,1), 0) + 10 CONTINUE +C Adjust B(*,*,2). ----------------------------------------------------- + DO 40 J = 1,M + DO 30 I = 1,M + DP = DDOT (M, C(I,1,2), M, C(1,J,1), 1) + B(I,J,2) = B(I,J,2) - DP + 30 CONTINUE + 40 CONTINUE +C Main loop. Process block-rows 2 to N-1. ----------------------------- + DO 100 K = 2,NM1 + KM1 = K - 1 + DO 70 J = 1,M + DO 60 I = 1,M + DP = DDOT (M, C(I,1,K), M, B(1,J,KM1), 1) + A(I,J,K) = A(I,J,K) - DP + 60 CONTINUE + 70 CONTINUE + CALL DGEFA (A(1,1,K), M, M, IP(1,K), IER) + IF (IER .NE. 0) GO TO 200 + DO 80 J = 1,M + 80 CALL DGESL (A(1,1,K), M, M, IP(1,K), B(1,J,K), 0) + 100 CONTINUE +C Process last block-row and return. ----------------------------------- + DO 130 J = 1,M + DO 120 I = 1,M + DP = DDOT (M, B(I,1,N), M, B(1,J,NM2), 1) + C(I,J,N) = C(I,J,N) - DP + 120 CONTINUE + 130 CONTINUE + DO 160 J = 1,M + DO 150 I = 1,M + DP = DDOT (M, C(I,1,N), M, B(1,J,NM1), 1) + A(I,J,N) = A(I,J,N) - DP + 150 CONTINUE + 160 CONTINUE + CALL DGEFA (A(1,1,N), M, M, IP(1,N), IER) + K = N + IF (IER .NE. 0) GO TO 200 + RETURN +C Error returns. ------------------------------------------------------- + 200 IER = K + RETURN + 210 IER = -1 + RETURN +C----------------------- End of Subroutine DDECBT ---------------------- + END +*DECK DSOLBT + SUBROUTINE DSOLBT (M, N, A, B, C, Y, IP) + INTEGER M, N, IP(M,N) + DOUBLE PRECISION A(M,M,N), B(M,M,N), C(M,M,N), Y(M,N) +C----------------------------------------------------------------------- +C Solution of block-tridiagonal linear system. +C Coefficient matrix must have been previously processed by DDECBT. +C M, N, A,B,C, and IP must not have been changed since call to DDECBT. +C Written by A. C. Hindmarsh. +C Input: +C M = order of each block. +C N = number of blocks in each direction of matrix. +C A,B,C = M by M by N arrays containing block LU decomposition +C of coefficient matrix from DDECBT. +C IP = M by N integer array of pivot information from DDECBT. +C Y = array of length M*N containg the right-hand side vector +C (treated as an M by N array here). +C Output: +C Y = solution vector, of length M*N. +C +C External routines required: DGESL (LINPACK) and DDOT (BLAS). +C----------------------------------------------------------------------- +C + INTEGER NM1, NM2, I, K, KB, KM1, KP1 + DOUBLE PRECISION DP, DDOT + NM1 = N - 1 + NM2 = N - 2 +C Forward solution sweep. ---------------------------------------------- + CALL DGESL (A, M, M, IP, Y, 0) + DO 30 K = 2,NM1 + KM1 = K - 1 + DO 20 I = 1,M + DP = DDOT (M, C(I,1,K), M, Y(1,KM1), 1) + Y(I,K) = Y(I,K) - DP + 20 CONTINUE + CALL DGESL (A(1,1,K), M, M, IP(1,K), Y(1,K), 0) + 30 CONTINUE + DO 50 I = 1,M + DP = DDOT (M, C(I,1,N), M, Y(1,NM1), 1) + 1 + DDOT (M, B(I,1,N), M, Y(1,NM2), 1) + Y(I,N) = Y(I,N) - DP + 50 CONTINUE + CALL DGESL (A(1,1,N), M, M, IP(1,N), Y(1,N), 0) +C Backward solution sweep. --------------------------------------------- + DO 80 KB = 1,NM1 + K = N - KB + KP1 = K + 1 + DO 70 I = 1,M + DP = DDOT (M, B(I,1,K), M, Y(1,KP1), 1) + Y(I,K) = Y(I,K) - DP + 70 CONTINUE + 80 CONTINUE + DO 100 I = 1,M + DP = DDOT (M, C(I,1,1), M, Y(1,3), 1) + Y(I,1) = Y(I,1) - DP + 100 CONTINUE + RETURN +C----------------------- End of Subroutine DSOLBT ---------------------- + END +*DECK DIPREPI + SUBROUTINE DIPREPI (NEQ, Y, S, RWORK, IA, JA, IC, JC, IPFLAG, + 1 RES, JAC, ADDA) + EXTERNAL RES, JAC, ADDA + INTEGER NEQ, IA, JA, IC, JC, IPFLAG + DOUBLE PRECISION Y, S, RWORK + DIMENSION NEQ(*), Y(*), S(*), RWORK(*), IA(*), JA(*), IC(*), JC(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION RLSS + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IMAX, LEWTN, LYHD, LYHN +C----------------------------------------------------------------------- +C This routine serves as an interface between the driver and +C Subroutine DPREPI. Tasks performed here are: +C * call DPREPI, +C * reset the required WM segment length LENWK, +C * move YH back to its final location (following WM in RWORK), +C * reset pointers for YH, SAVR, EWT, and ACOR, and +C * move EWT to its new position if ISTATE = 0 or 1. +C IPFLAG is an output error indication flag. IPFLAG = 0 if there was +C no trouble, and IPFLAG is the value of the DPREPI error flag IPPER +C if there was trouble in Subroutine DPREPI. +C----------------------------------------------------------------------- + IPFLAG = 0 +C Call DPREPI to do matrix preprocessing operations. ------------------- + CALL DPREPI (NEQ, Y, S, RWORK(LYH), RWORK(LSAVF), RWORK(LEWT), + 1 RWORK(LACOR), IA, JA, IC, JC, RWORK(LWM), RWORK(LWM), IPFLAG, + 2 RES, JAC, ADDA) + LENWK = MAX(LREQ,LWMIN) + IF (IPFLAG .LT. 0) RETURN +C If DPREPI was successful, move YH to end of required space for WM. --- + LYHN = LWM + LENWK + IF (LYHN .GT. LYH) RETURN + LYHD = LYH - LYHN + IF (LYHD .EQ. 0) GO TO 20 + IMAX = LYHN - 1 + LENYHM + DO 10 I=LYHN,IMAX + 10 RWORK(I) = RWORK(I+LYHD) + LYH = LYHN +C Reset pointers for SAVR, EWT, and ACOR. ------------------------------ + 20 LSAVF = LYH + LENYH + LEWTN = LSAVF + N + LACOR = LEWTN + N + IF (ISTATC .EQ. 3) GO TO 40 +C If ISTATE = 1, move EWT (left) to its new position. ------------------ + IF (LEWTN .GT. LEWT) RETURN + DO 30 I=1,N + 30 RWORK(I+LEWTN-1) = RWORK(I+LEWT-1) + 40 LEWT = LEWTN + RETURN +C----------------------- End of Subroutine DIPREPI --------------------- + END +*DECK DPREPI + SUBROUTINE DPREPI (NEQ, Y, S, YH, SAVR, EWT, RTEM, IA, JA, IC, JC, + 1 WK, IWK, IPPER, RES, JAC, ADDA) + EXTERNAL RES, JAC, ADDA + INTEGER NEQ, IA, JA, IC, JC, IWK, IPPER + DOUBLE PRECISION Y, S, YH, SAVR, EWT, RTEM, WK + DIMENSION NEQ(*), Y(*), S(*), YH(*), SAVR(*), EWT(*), RTEM(*), + 1 IA(*), JA(*), IC(*), JC(*), WK(*), IWK(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION RLSS + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IBR, IER, IPIL, IPIU, IPTT1, IPTT2, J, K, KNEW, KAMAX, + 1 KAMIN, KCMAX, KCMIN, LDIF, LENIGP, LENWK1, LIWK, LJFO, MAXG, + 2 NP1, NZSUT + DOUBLE PRECISION ERWT, FAC, YJ +C----------------------------------------------------------------------- +C This routine performs preprocessing related to the sparse linear +C systems that must be solved. +C The operations that are performed here are: +C * compute sparseness structure of the iteration matrix +C P = A - con*J according to MOSS, +C * compute grouping of column indices (MITER = 2), +C * compute a new ordering of rows and columns of the matrix, +C * reorder JA corresponding to the new ordering, +C * perform a symbolic LU factorization of the matrix, and +C * set pointers for segments of the IWK/WK array. +C In addition to variables described previously, DPREPI uses the +C following for communication: +C YH = the history array. Only the first column, containing the +C current Y vector, is used. Used only if MOSS .ne. 0. +C S = array of length NEQ, identical to YDOTI in the driver, used +C only if MOSS .ne. 0. +C SAVR = a work array of length NEQ, used only if MOSS .ne. 0. +C EWT = array of length NEQ containing (inverted) error weights. +C Used only if MOSS = 2 or 4 or if ISTATE = MOSS = 1. +C RTEM = a work array of length NEQ, identical to ACOR in the driver, +C used only if MOSS = 2 or 4. +C WK = a real work array of length LENWK, identical to WM in +C the driver. +C IWK = integer work array, assumed to occupy the same space as WK. +C LENWK = the length of the work arrays WK and IWK. +C ISTATC = a copy of the driver input argument ISTATE (= 1 on the +C first call, = 3 on a continuation call). +C IYS = flag value from ODRV or CDRV. +C IPPER = output error flag , with the following values and meanings: +C = 0 no error. +C = -1 insufficient storage for internal structure pointers. +C = -2 insufficient storage for JGROUP. +C = -3 insufficient storage for ODRV. +C = -4 other error flag from ODRV (should never occur). +C = -5 insufficient storage for CDRV. +C = -6 other error flag from CDRV. +C = -7 if the RES routine returned error flag IRES = IER = 2. +C = -8 if the RES routine returned error flag IRES = IER = 3. +C----------------------------------------------------------------------- + IBIAN = LRAT*2 + IPIAN = IBIAN + 1 + NP1 = N + 1 + IPJAN = IPIAN + NP1 + IBJAN = IPJAN - 1 + LENWK1 = LENWK - N + LIWK = LENWK*LRAT + IF (MOSS .EQ. 0) LIWK = LIWK - N + IF (MOSS .EQ. 1 .OR. MOSS .EQ. 2) LIWK = LENWK1*LRAT + IF (IPJAN+N-1 .GT. LIWK) GO TO 310 + IF (MOSS .EQ. 0) GO TO 30 +C + IF (ISTATC .EQ. 3) GO TO 20 +C ISTATE = 1 and MOSS .ne. 0. Perturb Y for structure determination. +C Initialize S with random nonzero elements for structure determination. + DO 10 I=1,N + ERWT = 1.0D0/EWT(I) + FAC = 1.0D0 + 1.0D0/(I + 1.0D0) + Y(I) = Y(I) + FAC*SIGN(ERWT,Y(I)) + S(I) = 1.0D0 + FAC*ERWT + 10 CONTINUE + GO TO (70, 100, 150, 200), MOSS +C + 20 CONTINUE +C ISTATE = 3 and MOSS .ne. 0. Load Y from YH(*,1) and S from YH(*,2). -- + DO 25 I = 1,N + Y(I) = YH(I) + 25 S(I) = YH(N+I) + GO TO (70, 100, 150, 200), MOSS +C +C MOSS = 0. Process user's IA,JA and IC,JC. ---------------------------- + 30 KNEW = IPJAN + KAMIN = IA(1) + KCMIN = IC(1) + IWK(IPIAN) = 1 + DO 60 J = 1,N + DO 35 I = 1,N + 35 IWK(LIWK+I) = 0 + KAMAX = IA(J+1) - 1 + IF (KAMIN .GT. KAMAX) GO TO 45 + DO 40 K = KAMIN,KAMAX + I = JA(K) + IWK(LIWK+I) = 1 + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 40 CONTINUE + 45 KAMIN = KAMAX + 1 + KCMAX = IC(J+1) - 1 + IF (KCMIN .GT. KCMAX) GO TO 55 + DO 50 K = KCMIN,KCMAX + I = JC(K) + IF (IWK(LIWK+I) .NE. 0) GO TO 50 + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 50 CONTINUE + 55 IWK(IPIAN+J) = KNEW + 1 - IPJAN + KCMIN = KCMAX + 1 + 60 CONTINUE + GO TO 240 +C +C MOSS = 1. Compute structure from user-supplied Jacobian routine JAC. - + 70 CONTINUE +C A dummy call to RES allows user to create temporaries for use in JAC. + IER = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IER) + IF (IER .GT. 1) GO TO 370 + DO 75 I = 1,N + SAVR(I) = 0.0D0 + 75 WK(LENWK1+I) = 0.0D0 + K = IPJAN + IWK(IPIAN) = 1 + DO 95 J = 1,N + CALL ADDA (NEQ, TN, Y, J, IWK(IPIAN), IWK(IPJAN), WK(LENWK1+1)) + CALL JAC (NEQ, TN, Y, S, J, IWK(IPIAN), IWK(IPJAN), SAVR) + DO 90 I = 1,N + LJFO = LENWK1 + I + IF (WK(LJFO) .EQ. 0.0D0) GO TO 80 + WK(LJFO) = 0.0D0 + SAVR(I) = 0.0D0 + GO TO 85 + 80 IF (SAVR(I) .EQ. 0.0D0) GO TO 90 + SAVR(I) = 0.0D0 + 85 IF (K .GT. LIWK) GO TO 310 + IWK(K) = I + K = K+1 + 90 CONTINUE + IWK(IPIAN+J) = K + 1 - IPJAN + 95 CONTINUE + GO TO 240 +C +C MOSS = 2. Compute structure from results of N + 1 calls to RES. ------ + 100 DO 105 I = 1,N + 105 WK(LENWK1+I) = 0.0D0 + K = IPJAN + IWK(IPIAN) = 1 + IER = -1 + IF (MITER .EQ. 1) IER = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IER) + IF (IER .GT. 1) GO TO 370 + DO 130 J = 1,N + CALL ADDA (NEQ, TN, Y, J, IWK(IPIAN), IWK(IPJAN), WK(LENWK1+1)) + YJ = Y(J) + ERWT = 1.0D0/EWT(J) + Y(J) = YJ + SIGN(ERWT,YJ) + CALL RES (NEQ, TN, Y, S, RTEM, IER) + IF (IER .GT. 1) RETURN + Y(J) = YJ + DO 120 I = 1,N + LJFO = LENWK1 + I + IF (WK(LJFO) .EQ. 0.0D0) GO TO 110 + WK(LJFO) = 0.0D0 + GO TO 115 + 110 IF (RTEM(I) .EQ. SAVR(I)) GO TO 120 + 115 IF (K .GT. LIWK) GO TO 310 + IWK(K) = I + K = K + 1 + 120 CONTINUE + IWK(IPIAN+J) = K + 1 - IPJAN + 130 CONTINUE + GO TO 240 +C +C MOSS = 3. Compute structure from the user's IA/JA and JAC routine. --- + 150 CONTINUE +C A dummy call to RES allows user to create temporaries for use in JAC. + IER = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IER) + IF (IER .GT. 1) GO TO 370 + DO 155 I = 1,N + 155 SAVR(I) = 0.0D0 + KNEW = IPJAN + KAMIN = IA(1) + IWK(IPIAN) = 1 + DO 190 J = 1,N + CALL JAC (NEQ, TN, Y, S, J, IWK(IPIAN), IWK(IPJAN), SAVR) + KAMAX = IA(J+1) - 1 + IF (KAMIN .GT. KAMAX) GO TO 170 + DO 160 K = KAMIN,KAMAX + I = JA(K) + SAVR(I) = 0.0D0 + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 160 CONTINUE + 170 KAMIN = KAMAX + 1 + DO 180 I = 1,N + IF (SAVR(I) .EQ. 0.0D0) GO TO 180 + SAVR(I) = 0.0D0 + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 180 CONTINUE + IWK(IPIAN+J) = KNEW + 1 - IPJAN + 190 CONTINUE + GO TO 240 +C +C MOSS = 4. Compute structure from user's IA/JA and N + 1 RES calls. --- + 200 KNEW = IPJAN + KAMIN = IA(1) + IWK(IPIAN) = 1 + IER = -1 + IF (MITER .EQ. 1) IER = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IER) + IF (IER .GT. 1) GO TO 370 + DO 235 J = 1,N + YJ = Y(J) + ERWT = 1.0D0/EWT(J) + Y(J) = YJ + SIGN(ERWT,YJ) + CALL RES (NEQ, TN, Y, S, RTEM, IER) + IF (IER .GT. 1) RETURN + Y(J) = YJ + KAMAX = IA(J+1) - 1 + IF (KAMIN .GT. KAMAX) GO TO 225 + DO 220 K = KAMIN,KAMAX + I = JA(K) + RTEM(I) = SAVR(I) + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 220 CONTINUE + 225 KAMIN = KAMAX + 1 + DO 230 I = 1,N + IF (RTEM(I) .EQ. SAVR(I)) GO TO 230 + IF (KNEW .GT. LIWK) GO TO 310 + IWK(KNEW) = I + KNEW = KNEW + 1 + 230 CONTINUE + IWK(IPIAN+J) = KNEW + 1 - IPJAN + 235 CONTINUE +C + 240 CONTINUE + IF (MOSS .EQ. 0 .OR. ISTATC .EQ. 3) GO TO 250 +C If ISTATE = 0 or 1 and MOSS .ne. 0, restore Y from YH. --------------- + DO 245 I = 1,N + 245 Y(I) = YH(I) + 250 NNZ = IWK(IPIAN+N) - 1 + IPPER = 0 + NGP = 0 + LENIGP = 0 + IPIGP = IPJAN + NNZ + IF (MITER .NE. 2) GO TO 260 +C +C Compute grouping of column indices (MITER = 2). ---------------------- +C + MAXG = NP1 + IPJGP = IPJAN + NNZ + IBJGP = IPJGP - 1 + IPIGP = IPJGP + N + IPTT1 = IPIGP + NP1 + IPTT2 = IPTT1 + N + LREQ = IPTT2 + N - 1 + IF (LREQ .GT. LIWK) GO TO 320 + CALL JGROUP (N, IWK(IPIAN), IWK(IPJAN), MAXG, NGP, IWK(IPIGP), + 1 IWK(IPJGP), IWK(IPTT1), IWK(IPTT2), IER) + IF (IER .NE. 0) GO TO 320 + LENIGP = NGP + 1 +C +C Compute new ordering of rows/columns of Jacobian. -------------------- + 260 IPR = IPIGP + LENIGP + IPC = IPR + IPIC = IPC + N + IPISP = IPIC + N + IPRSP = (IPISP-2)/LRAT + 2 + IESP = LENWK + 1 - IPRSP + IF (IESP .LT. 0) GO TO 330 + IBR = IPR - 1 + DO 270 I = 1,N + 270 IWK(IBR+I) = I + NSP = LIWK + 1 - IPISP + CALL ODRV(N, IWK(IPIAN), IWK(IPJAN), WK, IWK(IPR), IWK(IPIC), NSP, + 1 IWK(IPISP), 1, IYS) + IF (IYS .EQ. 11*N+1) GO TO 340 + IF (IYS .NE. 0) GO TO 330 +C +C Reorder JAN and do symbolic LU factorization of matrix. -------------- + IPA = LENWK + 1 - NNZ + NSP = IPA - IPRSP + LREQ = MAX(12*N/LRAT, 6*N/LRAT+2*N+NNZ) + 3 + LREQ = LREQ + IPRSP - 1 + NNZ + IF (LREQ .GT. LENWK) GO TO 350 + IBA = IPA - 1 + DO 280 I = 1,NNZ + 280 WK(IBA+I) = 0.0D0 + IPISP = LRAT*(IPRSP - 1) + 1 + CALL CDRV(N,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),WK(IPA),WK(IPA),NSP,IWK(IPISP),WK(IPRSP),IESP,5,IYS) + LREQ = LENWK - IESP + IF (IYS .EQ. 10*N+1) GO TO 350 + IF (IYS .NE. 0) GO TO 360 + IPIL = IPISP + IPIU = IPIL + 2*N + 1 + NZU = IWK(IPIL+N) - IWK(IPIL) + NZL = IWK(IPIU+N) - IWK(IPIU) + IF (LRAT .GT. 1) GO TO 290 + CALL ADJLR (N, IWK(IPISP), LDIF) + LREQ = LREQ + LDIF + 290 CONTINUE + IF (LRAT .EQ. 2 .AND. NNZ .EQ. N) LREQ = LREQ + 1 + NSP = NSP + LREQ - LENWK + IPA = LREQ + 1 - NNZ + IBA = IPA - 1 + IPPER = 0 + RETURN +C + 310 IPPER = -1 + LREQ = 2 + (2*N + 1)/LRAT + LREQ = MAX(LENWK+1,LREQ) + RETURN +C + 320 IPPER = -2 + LREQ = (LREQ - 1)/LRAT + 1 + RETURN +C + 330 IPPER = -3 + CALL CNTNZU (N, IWK(IPIAN), IWK(IPJAN), NZSUT) + LREQ = LENWK - IESP + (3*N + 4*NZSUT - 1)/LRAT + 1 + RETURN +C + 340 IPPER = -4 + RETURN +C + 350 IPPER = -5 + RETURN +C + 360 IPPER = -6 + LREQ = LENWK + RETURN +C + 370 IPPER = -IER - 5 + LREQ = 2 + (2*N + 1)/LRAT + RETURN +C----------------------- End of Subroutine DPREPI ---------------------- + END +*DECK DAINVGS + SUBROUTINE DAINVGS (NEQ, T, Y, WK, IWK, TEM, YDOT, IER, RES, ADDA) + EXTERNAL RES, ADDA + INTEGER NEQ, IWK, IER + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IMUL, J, K, KMIN, KMAX + DOUBLE PRECISION T, Y, WK, TEM, YDOT + DOUBLE PRECISION RLSS + DIMENSION Y(*), WK(*), IWK(*), TEM(*), YDOT(*) + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU +C----------------------------------------------------------------------- +C This subroutine computes the initial value of the vector YDOT +C satisfying +C A * YDOT = g(t,y) +C when A is nonsingular. It is called by DLSODIS for initialization +C only, when ISTATE = 0. The matrix A is subjected to LU +C decomposition in CDRV. Then the system A*YDOT = g(t,y) is solved +C in CDRV. +C In addition to variables described previously, communication +C with DAINVGS uses the following: +C Y = array of initial values. +C WK = real work space for matrices. On output it contains A and +C its LU decomposition. The LU decomposition is not entirely +C sparse unless the structure of the matrix A is identical to +C the structure of the Jacobian matrix dr/dy. +C Storage of matrix elements starts at WK(3). +C WK(1) = SQRT(UROUND), not used here. +C IWK = integer work space for matrix-related data, assumed to +C be equivalenced to WK. In addition, WK(IPRSP) and WK(IPISP) +C are assumed to have identical locations. +C TEM = vector of work space of length N (ACOR in DSTODI). +C YDOT = output vector containing the initial dy/dt. YDOT(i) contains +C dy(i)/dt when the matrix A is non-singular. +C IER = output error flag with the following values and meanings: +C = 0 if DAINVGS was successful. +C = 1 if the A-matrix was found to be singular. +C = 2 if RES returned an error flag IRES = IER = 2. +C = 3 if RES returned an error flag IRES = IER = 3. +C = 4 if insufficient storage for CDRV (should not occur here). +C = 5 if other error found in CDRV (should not occur here). +C----------------------------------------------------------------------- +C + DO 10 I = 1,NNZ + 10 WK(IBA+I) = 0.0D0 +C + IER = 1 + CALL RES (NEQ, T, Y, WK(IPA), YDOT, IER) + IF (IER .GT. 1) RETURN +C + KMIN = IWK(IPIAN) + DO 30 J = 1,NEQ + KMAX = IWK(IPIAN+J) - 1 + DO 15 K = KMIN,KMAX + I = IWK(IBJAN+K) + 15 TEM(I) = 0.0D0 + CALL ADDA (NEQ, T, Y, J, IWK(IPIAN), IWK(IPJAN), TEM) + DO 20 K = KMIN,KMAX + I = IWK(IBJAN+K) + 20 WK(IBA+K) = TEM(I) + KMIN = KMAX + 1 + 30 CONTINUE + NLU = NLU + 1 + IER = 0 + DO 40 I = 1,NEQ + 40 TEM(I) = 0.0D0 +C +C Numerical factorization of matrix A. --------------------------------- + CALL CDRV (NEQ,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),TEM,TEM,NSP,IWK(IPISP),WK(IPRSP),IESP,2,IYS) + IF (IYS .EQ. 0) GO TO 50 + IMUL = (IYS - 1)/NEQ + IER = 5 + IF (IMUL .EQ. 8) IER = 1 + IF (IMUL .EQ. 10) IER = 4 + RETURN +C +C Solution of the linear system. --------------------------------------- + 50 CALL CDRV (NEQ,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),YDOT,YDOT,NSP,IWK(IPISP),WK(IPRSP),IESP,4,IYS) + IF (IYS .NE. 0) IER = 5 + RETURN +C----------------------- End of Subroutine DAINVGS --------------------- + END +*DECK DPRJIS + SUBROUTINE DPRJIS (NEQ, Y, YH, NYH, EWT, RTEM, SAVR, S, WK, IWK, + 1 RES, JAC, ADDA) + EXTERNAL RES, JAC, ADDA + INTEGER NEQ, NYH, IWK + DOUBLE PRECISION Y, YH, EWT, RTEM, SAVR, S, WK + DIMENSION NEQ(*), Y(*), YH(NYH,*), EWT(*), RTEM(*), + 1 S(*), SAVR(*), WK(*), IWK(*) + INTEGER IOWND, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION RLSS + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 IOWND(6), IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + COMMON /DLSS01/ RLSS(6), + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, IMUL, IRES, J, JJ, JMAX, JMIN, K, KMAX, KMIN, NG + DOUBLE PRECISION CON, FAC, HL0, R, SRUR +C----------------------------------------------------------------------- +C DPRJIS is called to compute and process the matrix +C P = A - H*EL(1)*J, where J is an approximation to the Jacobian dr/dy, +C where r = g(t,y) - A(t,y)*s. J is computed by columns, either by +C the user-supplied routine JAC if MITER = 1, or by finite differencing +C if MITER = 2. J is stored in WK, rescaled, and ADDA is called to +C generate P. The matrix P is subjected to LU decomposition in CDRV. +C P and its LU decomposition are stored separately in WK. +C +C In addition to variables described previously, communication +C with DPRJIS uses the following: +C Y = array containing predicted values on entry. +C RTEM = work array of length N (ACOR in DSTODI). +C SAVR = array containing r evaluated at predicted y. On output it +C contains the residual evaluated at current values of t and y. +C S = array containing predicted values of dy/dt (SAVF in DSTODI). +C WK = real work space for matrices. On output it contains P and +C its sparse LU decomposition. Storage of matrix elements +C starts at WK(3). +C WK also contains the following matrix-related data. +C WK(1) = SQRT(UROUND), used in numerical Jacobian increments. +C IWK = integer work space for matrix-related data, assumed to be +C equivalenced to WK. In addition, WK(IPRSP) and IWK(IPISP) +C are assumed to have identical locations. +C EL0 = EL(1) (input). +C IERPJ = output error flag (in COMMON). +C = 0 if no error. +C = 1 if zero pivot found in CDRV. +C = IRES (= 2 or 3) if RES returned IRES = 2 or 3. +C = -1 if insufficient storage for CDRV (should not occur). +C = -2 if other error found in CDRV (should not occur here). +C JCUR = output flag = 1 to indicate that the Jacobian matrix +C (or approximation) is now current. +C This routine also uses other variables in Common. +C----------------------------------------------------------------------- + HL0 = H*EL0 + CON = -HL0 + JCUR = 1 + NJE = NJE + 1 + GO TO (100, 200), MITER +C +C If MITER = 1, call RES, then call JAC and ADDA for each column. ------ + 100 IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + KMIN = IWK(IPIAN) + DO 130 J = 1,N + KMAX = IWK(IPIAN+J)-1 + DO 110 I = 1,N + 110 RTEM(I) = 0.0D0 + CALL JAC (NEQ, TN, Y, S, J, IWK(IPIAN), IWK(IPJAN), RTEM) + DO 120 I = 1,N + 120 RTEM(I) = RTEM(I)*CON + CALL ADDA (NEQ, TN, Y, J, IWK(IPIAN), IWK(IPJAN), RTEM) + DO 125 K = KMIN,KMAX + I = IWK(IBJAN+K) + WK(IBA+K) = RTEM(I) + 125 CONTINUE + KMIN = KMAX + 1 + 130 CONTINUE + GO TO 290 +C +C If MITER = 2, make NGP + 1 calls to RES to approximate J and P. ------ + 200 CONTINUE + IRES = -1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + SRUR = WK(1) + JMIN = IWK(IPIGP) + DO 240 NG = 1,NGP + JMAX = IWK(IPIGP+NG) - 1 + DO 210 J = JMIN,JMAX + JJ = IWK(IBJGP+J) + R = MAX(SRUR*ABS(Y(JJ)),0.01D0/EWT(JJ)) + 210 Y(JJ) = Y(JJ) + R + CALL RES (NEQ,TN,Y,S,RTEM,IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 + DO 230 J = JMIN,JMAX + JJ = IWK(IBJGP+J) + Y(JJ) = YH(JJ,1) + R = MAX(SRUR*ABS(Y(JJ)),0.01D0/EWT(JJ)) + FAC = -HL0/R + KMIN = IWK(IBIAN+JJ) + KMAX = IWK(IBIAN+JJ+1) - 1 + DO 220 K = KMIN,KMAX + I = IWK(IBJAN+K) + RTEM(I) = (RTEM(I) - SAVR(I))*FAC + 220 CONTINUE + CALL ADDA (NEQ, TN, Y, JJ, IWK(IPIAN), IWK(IPJAN), RTEM) + DO 225 K = KMIN,KMAX + I = IWK(IBJAN+K) + WK(IBA+K) = RTEM(I) + 225 CONTINUE + 230 CONTINUE + JMIN = JMAX + 1 + 240 CONTINUE + IRES = 1 + CALL RES (NEQ, TN, Y, S, SAVR, IRES) + NFE = NFE + 1 + IF (IRES .GT. 1) GO TO 600 +C +C Do numerical factorization of P matrix. ------------------------------ + 290 NLU = NLU + 1 + IERPJ = 0 + DO 295 I = 1,N + 295 RTEM(I) = 0.0D0 + CALL CDRV (N,IWK(IPR),IWK(IPC),IWK(IPIC),IWK(IPIAN),IWK(IPJAN), + 1 WK(IPA),RTEM,RTEM,NSP,IWK(IPISP),WK(IPRSP),IESP,2,IYS) + IF (IYS .EQ. 0) RETURN + IMUL = (IYS - 1)/N + IERPJ = -2 + IF (IMUL .EQ. 8) IERPJ = 1 + IF (IMUL .EQ. 10) IERPJ = -1 + RETURN +C Error return for IRES = 2 or IRES = 3 return from RES. --------------- + 600 IERPJ = IRES + RETURN +C----------------------- End of Subroutine DPRJIS ---------------------- + END diff --git a/src/Enzo/opkda2.F b/src/Enzo/opkda2.F new file mode 100644 index 0000000000..1c41ad0462 --- /dev/null +++ b/src/Enzo/opkda2.F @@ -0,0 +1,1449 @@ +*DECK DGEFA + SUBROUTINE DGEFA (A, LDA, N, IPVT, INFO) +C***BEGIN PROLOGUE DGEFA +C***PURPOSE Factor a matrix using Gaussian elimination. +C***CATEGORY D2A1 +C***TYPE DOUBLE PRECISION (SGEFA-S, DGEFA-D, CGEFA-C) +C***KEYWORDS GENERAL MATRIX, LINEAR ALGEBRA, LINPACK, +C MATRIX FACTORIZATION +C***AUTHOR Moler, C. B., (U. of New Mexico) +C***DESCRIPTION +C +C DGEFA factors a double precision matrix by Gaussian elimination. +C +C DGEFA is usually called by DGECO, but it can be called +C directly with a saving in time if RCOND is not needed. +C (Time for DGECO) = (1 + 9/N)*(Time for DGEFA) . +C +C On Entry +C +C A DOUBLE PRECISION(LDA, N) +C the matrix to be factored. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C the order of the matrix A . +C +C On Return +C +C A an upper triangular matrix and the multipliers +C which were used to obtain it. +C The factorization can be written A = L*U where +C L is a product of permutation and unit lower +C triangular matrices and U is upper triangular. +C +C IPVT INTEGER(N) +C an integer vector of pivot indices. +C +C INFO INTEGER +C = 0 normal value. +C = K if U(K,K) .EQ. 0.0 . This is not an error +C condition for this subroutine, but it does +C indicate that DGESL or DGEDI will divide by zero +C if called. Use RCOND in DGECO for a reliable +C indication of singularity. +C +C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W. +C Stewart, LINPACK Users' Guide, SIAM, 1979. +C***ROUTINES CALLED DAXPY, DSCAL, IDAMAX +C***REVISION HISTORY (YYMMDD) +C 780814 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900326 Removed duplicate information from DESCRIPTION section. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DGEFA + INTEGER LDA,N,IPVT(*),INFO + DOUBLE PRECISION A(LDA,*) +C + DOUBLE PRECISION T + INTEGER IDAMAX,J,K,KP1,L,NM1 +C +C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING +C +C***FIRST EXECUTABLE STATEMENT DGEFA + INFO = 0 + NM1 = N - 1 + IF (NM1 .LT. 1) GO TO 70 + DO 60 K = 1, NM1 + KP1 = K + 1 +C +C FIND L = PIVOT INDEX +C + L = IDAMAX(N-K+1,A(K,K),1) + K - 1 + IPVT(K) = L +C +C ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED +C + IF (A(L,K) .EQ. 0.0D0) GO TO 40 +C +C INTERCHANGE IF NECESSARY +C + IF (L .EQ. K) GO TO 10 + T = A(L,K) + A(L,K) = A(K,K) + A(K,K) = T + 10 CONTINUE +C +C COMPUTE MULTIPLIERS +C + T = -1.0D0/A(K,K) + CALL DSCAL(N-K,T,A(K+1,K),1) +C +C ROW ELIMINATION WITH COLUMN INDEXING +C + DO 30 J = KP1, N + T = A(L,J) + IF (L .EQ. K) GO TO 20 + A(L,J) = A(K,J) + A(K,J) = T + 20 CONTINUE + CALL DAXPY(N-K,T,A(K+1,K),1,A(K+1,J),1) + 30 CONTINUE + GO TO 50 + 40 CONTINUE + INFO = K + 50 CONTINUE + 60 CONTINUE + 70 CONTINUE + IPVT(N) = N + IF (A(N,N) .EQ. 0.0D0) INFO = N + RETURN + END +*DECK DGESL + SUBROUTINE DGESL (A, LDA, N, IPVT, B, JOB) +C***BEGIN PROLOGUE DGESL +C***PURPOSE Solve the real system A*X=B or TRANS(A)*X=B using the +C factors computed by DGECO or DGEFA. +C***CATEGORY D2A1 +C***TYPE DOUBLE PRECISION (SGESL-S, DGESL-D, CGESL-C) +C***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX, SOLVE +C***AUTHOR Moler, C. B., (U. of New Mexico) +C***DESCRIPTION +C +C DGESL solves the double precision system +C A * X = B or TRANS(A) * X = B +C using the factors computed by DGECO or DGEFA. +C +C On Entry +C +C A DOUBLE PRECISION(LDA, N) +C the output from DGECO or DGEFA. +C +C LDA INTEGER +C the leading dimension of the array A . +C +C N INTEGER +C the order of the matrix A . +C +C IPVT INTEGER(N) +C the pivot vector from DGECO or DGEFA. +C +C B DOUBLE PRECISION(N) +C the right hand side vector. +C +C JOB INTEGER +C = 0 to solve A*X = B , +C = nonzero to solve TRANS(A)*X = B where +C TRANS(A) is the transpose. +C +C On Return +C +C B the solution vector X . +C +C Error Condition +C +C A division by zero will occur if the input factor contains a +C zero on the diagonal. Technically this indicates singularity +C but it is often caused by improper arguments or improper +C setting of LDA . It will not occur if the subroutines are +C called correctly and if DGECO has set RCOND .GT. 0.0 +C or DGEFA has set INFO .EQ. 0 . +C +C To compute INVERSE(A) * C where C is a matrix +C with P columns +C CALL DGECO(A,LDA,N,IPVT,RCOND,Z) +C IF (RCOND is too small) GO TO ... +C DO 10 J = 1, P +C CALL DGESL(A,LDA,N,IPVT,C(1,J),0) +C 10 CONTINUE +C +C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W. +C Stewart, LINPACK Users' Guide, SIAM, 1979. +C***ROUTINES CALLED DAXPY, DDOT +C***REVISION HISTORY (YYMMDD) +C 780814 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900326 Removed duplicate information from DESCRIPTION section. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DGESL + INTEGER LDA,N,IPVT(*),JOB + DOUBLE PRECISION A(LDA,*),B(*) +C + DOUBLE PRECISION DDOT,T + INTEGER K,KB,L,NM1 +C***FIRST EXECUTABLE STATEMENT DGESL + NM1 = N - 1 + IF (JOB .NE. 0) GO TO 50 +C +C JOB = 0 , SOLVE A * X = B +C FIRST SOLVE L*Y = B +C + IF (NM1 .LT. 1) GO TO 30 + DO 20 K = 1, NM1 + L = IPVT(K) + T = B(L) + IF (L .EQ. K) GO TO 10 + B(L) = B(K) + B(K) = T + 10 CONTINUE + CALL DAXPY(N-K,T,A(K+1,K),1,B(K+1),1) + 20 CONTINUE + 30 CONTINUE +C +C NOW SOLVE U*X = Y +C + DO 40 KB = 1, N + K = N + 1 - KB + B(K) = B(K)/A(K,K) + T = -B(K) + CALL DAXPY(K-1,T,A(1,K),1,B(1),1) + 40 CONTINUE + GO TO 100 + 50 CONTINUE +C +C JOB = NONZERO, SOLVE TRANS(A) * X = B +C FIRST SOLVE TRANS(U)*Y = B +C + DO 60 K = 1, N + T = DDOT(K-1,A(1,K),1,B(1),1) + B(K) = (B(K) - T)/A(K,K) + 60 CONTINUE +C +C NOW SOLVE TRANS(L)*X = Y +C + IF (NM1 .LT. 1) GO TO 90 + DO 80 KB = 1, NM1 + K = N - KB + B(K) = B(K) + DDOT(N-K,A(K+1,K),1,B(K+1),1) + L = IPVT(K) + IF (L .EQ. K) GO TO 70 + T = B(L) + B(L) = B(K) + B(K) = T + 70 CONTINUE + 80 CONTINUE + 90 CONTINUE + 100 CONTINUE + RETURN + END +*DECK DGBFA + SUBROUTINE DGBFA (ABD, LDA, N, ML, MU, IPVT, INFO) +C***BEGIN PROLOGUE DGBFA +C***PURPOSE Factor a band matrix using Gaussian elimination. +C***CATEGORY D2A2 +C***TYPE DOUBLE PRECISION (SGBFA-S, DGBFA-D, CGBFA-C) +C***KEYWORDS BANDED, LINEAR ALGEBRA, LINPACK, MATRIX FACTORIZATION +C***AUTHOR Moler, C. B., (U. of New Mexico) +C***DESCRIPTION +C +C DGBFA factors a double precision band matrix by elimination. +C +C DGBFA is usually called by DGBCO, but it can be called +C directly with a saving in time if RCOND is not needed. +C +C On Entry +C +C ABD DOUBLE PRECISION(LDA, N) +C contains the matrix in band storage. The columns +C of the matrix are stored in the columns of ABD and +C the diagonals of the matrix are stored in rows +C ML+1 through 2*ML+MU+1 of ABD . +C See the comments below for details. +C +C LDA INTEGER +C the leading dimension of the array ABD . +C LDA must be .GE. 2*ML + MU + 1 . +C +C N INTEGER +C the order of the original matrix. +C +C ML INTEGER +C number of diagonals below the main diagonal. +C 0 .LE. ML .LT. N . +C +C MU INTEGER +C number of diagonals above the main diagonal. +C 0 .LE. MU .LT. N . +C More efficient if ML .LE. MU . +C On Return +C +C ABD an upper triangular matrix in band storage and +C the multipliers which were used to obtain it. +C The factorization can be written A = L*U where +C L is a product of permutation and unit lower +C triangular matrices and U is upper triangular. +C +C IPVT INTEGER(N) +C an integer vector of pivot indices. +C +C INFO INTEGER +C = 0 normal value. +C = K if U(K,K) .EQ. 0.0 . This is not an error +C condition for this subroutine, but it does +C indicate that DGBSL will divide by zero if +C called. Use RCOND in DGBCO for a reliable +C indication of singularity. +C +C Band Storage +C +C If A is a band matrix, the following program segment +C will set up the input. +C +C ML = (band width below the diagonal) +C MU = (band width above the diagonal) +C M = ML + MU + 1 +C DO 20 J = 1, N +C I1 = MAX(1, J-MU) +C I2 = MIN(N, J+ML) +C DO 10 I = I1, I2 +C K = I - J + M +C ABD(K,J) = A(I,J) +C 10 CONTINUE +C 20 CONTINUE +C +C This uses rows ML+1 through 2*ML+MU+1 of ABD . +C In addition, the first ML rows in ABD are used for +C elements generated during the triangularization. +C The total number of rows needed in ABD is 2*ML+MU+1 . +C The ML+MU by ML+MU upper left triangle and the +C ML by ML lower right triangle are not referenced. +C +C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W. +C Stewart, LINPACK Users' Guide, SIAM, 1979. +C***ROUTINES CALLED DAXPY, DSCAL, IDAMAX +C***REVISION HISTORY (YYMMDD) +C 780814 DATE WRITTEN +C 890531 Changed all specific intrinsics to generic. (WRB) +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900326 Removed duplicate information from DESCRIPTION section. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DGBFA + INTEGER LDA,N,ML,MU,IPVT(*),INFO + DOUBLE PRECISION ABD(LDA,*) +C + DOUBLE PRECISION T + INTEGER I,IDAMAX,I0,J,JU,JZ,J0,J1,K,KP1,L,LM,M,MM,NM1 +C +C***FIRST EXECUTABLE STATEMENT DGBFA + M = ML + MU + 1 + INFO = 0 +C +C ZERO INITIAL FILL-IN COLUMNS +C + J0 = MU + 2 + J1 = MIN(N,M) - 1 + IF (J1 .LT. J0) GO TO 30 + DO 20 JZ = J0, J1 + I0 = M + 1 - JZ + DO 10 I = I0, ML + ABD(I,JZ) = 0.0D0 + 10 CONTINUE + 20 CONTINUE + 30 CONTINUE + JZ = J1 + JU = 0 +C +C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING +C + NM1 = N - 1 + IF (NM1 .LT. 1) GO TO 130 + DO 120 K = 1, NM1 + KP1 = K + 1 +C +C ZERO NEXT FILL-IN COLUMN +C + JZ = JZ + 1 + IF (JZ .GT. N) GO TO 50 + IF (ML .LT. 1) GO TO 50 + DO 40 I = 1, ML + ABD(I,JZ) = 0.0D0 + 40 CONTINUE + 50 CONTINUE +C +C FIND L = PIVOT INDEX +C + LM = MIN(ML,N-K) + L = IDAMAX(LM+1,ABD(M,K),1) + M - 1 + IPVT(K) = L + K - M +C +C ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED +C + IF (ABD(L,K) .EQ. 0.0D0) GO TO 100 +C +C INTERCHANGE IF NECESSARY +C + IF (L .EQ. M) GO TO 60 + T = ABD(L,K) + ABD(L,K) = ABD(M,K) + ABD(M,K) = T + 60 CONTINUE +C +C COMPUTE MULTIPLIERS +C + T = -1.0D0/ABD(M,K) + CALL DSCAL(LM,T,ABD(M+1,K),1) +C +C ROW ELIMINATION WITH COLUMN INDEXING +C + JU = MIN(MAX(JU,MU+IPVT(K)),N) + MM = M + IF (JU .LT. KP1) GO TO 90 + DO 80 J = KP1, JU + L = L - 1 + MM = MM - 1 + T = ABD(L,J) + IF (L .EQ. MM) GO TO 70 + ABD(L,J) = ABD(MM,J) + ABD(MM,J) = T + 70 CONTINUE + CALL DAXPY(LM,T,ABD(M+1,K),1,ABD(MM+1,J),1) + 80 CONTINUE + 90 CONTINUE + GO TO 110 + 100 CONTINUE + INFO = K + 110 CONTINUE + 120 CONTINUE + 130 CONTINUE + IPVT(N) = N + IF (ABD(M,N) .EQ. 0.0D0) INFO = N + RETURN + END +*DECK DGBSL + SUBROUTINE DGBSL (ABD, LDA, N, ML, MU, IPVT, B, JOB) +C***BEGIN PROLOGUE DGBSL +C***PURPOSE Solve the real band system A*X=B or TRANS(A)*X=B using +C the factors computed by DGBCO or DGBFA. +C***CATEGORY D2A2 +C***TYPE DOUBLE PRECISION (SGBSL-S, DGBSL-D, CGBSL-C) +C***KEYWORDS BANDED, LINEAR ALGEBRA, LINPACK, MATRIX, SOLVE +C***AUTHOR Moler, C. B., (U. of New Mexico) +C***DESCRIPTION +C +C DGBSL solves the double precision band system +C A * X = B or TRANS(A) * X = B +C using the factors computed by DGBCO or DGBFA. +C +C On Entry +C +C ABD DOUBLE PRECISION(LDA, N) +C the output from DGBCO or DGBFA. +C +C LDA INTEGER +C the leading dimension of the array ABD . +C +C N INTEGER +C the order of the original matrix. +C +C ML INTEGER +C number of diagonals below the main diagonal. +C +C MU INTEGER +C number of diagonals above the main diagonal. +C +C IPVT INTEGER(N) +C the pivot vector from DGBCO or DGBFA. +C +C B DOUBLE PRECISION(N) +C the right hand side vector. +C +C JOB INTEGER +C = 0 to solve A*X = B , +C = nonzero to solve TRANS(A)*X = B , where +C TRANS(A) is the transpose. +C +C On Return +C +C B the solution vector X . +C +C Error Condition +C +C A division by zero will occur if the input factor contains a +C zero on the diagonal. Technically this indicates singularity +C but it is often caused by improper arguments or improper +C setting of LDA . It will not occur if the subroutines are +C called correctly and if DGBCO has set RCOND .GT. 0.0 +C or DGBFA has set INFO .EQ. 0 . +C +C To compute INVERSE(A) * C where C is a matrix +C with P columns +C CALL DGBCO(ABD,LDA,N,ML,MU,IPVT,RCOND,Z) +C IF (RCOND is too small) GO TO ... +C DO 10 J = 1, P +C CALL DGBSL(ABD,LDA,N,ML,MU,IPVT,C(1,J),0) +C 10 CONTINUE +C +C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W. +C Stewart, LINPACK Users' Guide, SIAM, 1979. +C***ROUTINES CALLED DAXPY, DDOT +C***REVISION HISTORY (YYMMDD) +C 780814 DATE WRITTEN +C 890531 Changed all specific intrinsics to generic. (WRB) +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900326 Removed duplicate information from DESCRIPTION section. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DGBSL + INTEGER LDA,N,ML,MU,IPVT(*),JOB + DOUBLE PRECISION ABD(LDA,*),B(*) +C + DOUBLE PRECISION DDOT,T + INTEGER K,KB,L,LA,LB,LM,M,NM1 +C***FIRST EXECUTABLE STATEMENT DGBSL + M = MU + ML + 1 + NM1 = N - 1 + IF (JOB .NE. 0) GO TO 50 +C +C JOB = 0 , SOLVE A * X = B +C FIRST SOLVE L*Y = B +C + IF (ML .EQ. 0) GO TO 30 + IF (NM1 .LT. 1) GO TO 30 + DO 20 K = 1, NM1 + LM = MIN(ML,N-K) + L = IPVT(K) + T = B(L) + IF (L .EQ. K) GO TO 10 + B(L) = B(K) + B(K) = T + 10 CONTINUE + CALL DAXPY(LM,T,ABD(M+1,K),1,B(K+1),1) + 20 CONTINUE + 30 CONTINUE +C +C NOW SOLVE U*X = Y +C + DO 40 KB = 1, N + K = N + 1 - KB + B(K) = B(K)/ABD(M,K) + LM = MIN(K,M) - 1 + LA = M - LM + LB = K - LM + T = -B(K) + CALL DAXPY(LM,T,ABD(LA,K),1,B(LB),1) + 40 CONTINUE + GO TO 100 + 50 CONTINUE +C +C JOB = NONZERO, SOLVE TRANS(A) * X = B +C FIRST SOLVE TRANS(U)*Y = B +C + DO 60 K = 1, N + LM = MIN(K,M) - 1 + LA = M - LM + LB = K - LM + T = DDOT(LM,ABD(LA,K),1,B(LB),1) + B(K) = (B(K) - T)/ABD(M,K) + 60 CONTINUE +C +C NOW SOLVE TRANS(L)*X = Y +C + IF (ML .EQ. 0) GO TO 90 + IF (NM1 .LT. 1) GO TO 90 + DO 80 KB = 1, NM1 + K = N - KB + LM = MIN(ML,N-K) + B(K) = B(K) + DDOT(LM,ABD(M+1,K),1,B(K+1),1) + L = IPVT(K) + IF (L .EQ. K) GO TO 70 + T = B(L) + B(L) = B(K) + B(K) = T + 70 CONTINUE + 80 CONTINUE + 90 CONTINUE + 100 CONTINUE + RETURN + END +*DECK DAXPY + SUBROUTINE DAXPY (N, DA, DX, INCX, DY, INCY) +C***BEGIN PROLOGUE DAXPY +C***PURPOSE Compute a constant times a vector plus a vector. +C***CATEGORY D1A7 +C***TYPE DOUBLE PRECISION (SAXPY-S, DAXPY-D, CAXPY-C) +C***KEYWORDS BLAS, LINEAR ALGEBRA, TRIAD, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of Parameters +C +C --Input-- +C N number of elements in input vector(s) +C DA double precision scalar multiplier +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C DY double precision vector with N elements +C INCY storage spacing between elements of DY +C +C --Output-- +C DY double precision result (unchanged if N .LE. 0) +C +C Overwrite double precision DY with double precision DA*DX + DY. +C For I = 0 to N-1, replace DY(LY+I*INCY) with DA*DX(LX+I*INCX) + +C DY(LY+I*INCY), +C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is +C defined in a similar way using INCY. +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 920310 Corrected definition of LX in DESCRIPTION. (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DAXPY + DOUBLE PRECISION DX(*), DY(*), DA +C***FIRST EXECUTABLE STATEMENT DAXPY + IF (N.LE.0 .OR. DA.EQ.0.0D0) RETURN + IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60 +C +C Code for unequal or nonpositive increments. +C + 5 IX = 1 + IY = 1 + IF (INCX .LT. 0) IX = (-N+1)*INCX + 1 + IF (INCY .LT. 0) IY = (-N+1)*INCY + 1 + DO 10 I = 1,N + DY(IY) = DY(IY) + DA*DX(IX) + IX = IX + INCX + IY = IY + INCY + 10 CONTINUE + RETURN +C +C Code for both increments equal to 1. +C +C Clean-up loop so remaining vector length is a multiple of 4. +C + 20 M = MOD(N,4) + IF (M .EQ. 0) GO TO 40 + DO 30 I = 1,M + DY(I) = DY(I) + DA*DX(I) + 30 CONTINUE + IF (N .LT. 4) RETURN + 40 MP1 = M + 1 + DO 50 I = MP1,N,4 + DY(I) = DY(I) + DA*DX(I) + DY(I+1) = DY(I+1) + DA*DX(I+1) + DY(I+2) = DY(I+2) + DA*DX(I+2) + DY(I+3) = DY(I+3) + DA*DX(I+3) + 50 CONTINUE + RETURN +C +C Code for equal, positive, non-unit increments. +C + 60 NS = N*INCX + DO 70 I = 1,NS,INCX + DY(I) = DA*DX(I) + DY(I) + 70 CONTINUE + RETURN + END +*DECK DCOPY + SUBROUTINE DCOPY (N, DX, INCX, DY, INCY) +C***BEGIN PROLOGUE DCOPY +C***PURPOSE Copy a vector. +C***CATEGORY D1A5 +C***TYPE DOUBLE PRECISION (SCOPY-S, DCOPY-D, CCOPY-C, ICOPY-I) +C***KEYWORDS BLAS, COPY, LINEAR ALGEBRA, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of Parameters +C +C --Input-- +C N number of elements in input vector(s) +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C DY double precision vector with N elements +C INCY storage spacing between elements of DY +C +C --Output-- +C DY copy of vector DX (unchanged if N .LE. 0) +C +C Copy double precision DX to double precision DY. +C For I = 0 to N-1, copy DX(LX+I*INCX) to DY(LY+I*INCY), +C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is +C defined in a similar way using INCY. +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 920310 Corrected definition of LX in DESCRIPTION. (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DCOPY + DOUBLE PRECISION DX(*), DY(*) +C***FIRST EXECUTABLE STATEMENT DCOPY + IF (N .LE. 0) RETURN + IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60 +C +C Code for unequal or nonpositive increments. +C + 5 IX = 1 + IY = 1 + IF (INCX .LT. 0) IX = (-N+1)*INCX + 1 + IF (INCY .LT. 0) IY = (-N+1)*INCY + 1 + DO 10 I = 1,N + DY(IY) = DX(IX) + IX = IX + INCX + IY = IY + INCY + 10 CONTINUE + RETURN +C +C Code for both increments equal to 1. +C +C Clean-up loop so remaining vector length is a multiple of 7. +C + 20 M = MOD(N,7) + IF (M .EQ. 0) GO TO 40 + DO 30 I = 1,M + DY(I) = DX(I) + 30 CONTINUE + IF (N .LT. 7) RETURN + 40 MP1 = M + 1 + DO 50 I = MP1,N,7 + DY(I) = DX(I) + DY(I+1) = DX(I+1) + DY(I+2) = DX(I+2) + DY(I+3) = DX(I+3) + DY(I+4) = DX(I+4) + DY(I+5) = DX(I+5) + DY(I+6) = DX(I+6) + 50 CONTINUE + RETURN +C +C Code for equal, positive, non-unit increments. +C + 60 NS = N*INCX + DO 70 I = 1,NS,INCX + DY(I) = DX(I) + 70 CONTINUE + RETURN + END +*DECK DDOT + DOUBLE PRECISION FUNCTION DDOT (N, DX, INCX, DY, INCY) +C***BEGIN PROLOGUE DDOT +C***PURPOSE Compute the inner product of two vectors. +C***CATEGORY D1A4 +C***TYPE DOUBLE PRECISION (SDOT-S, DDOT-D, CDOTU-C) +C***KEYWORDS BLAS, INNER PRODUCT, LINEAR ALGEBRA, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of Parameters +C +C --Input-- +C N number of elements in input vector(s) +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C DY double precision vector with N elements +C INCY storage spacing between elements of DY +C +C --Output-- +C DDOT double precision dot product (zero if N .LE. 0) +C +C Returns the dot product of double precision DX and DY. +C DDOT = sum for I = 0 to N-1 of DX(LX+I*INCX) * DY(LY+I*INCY), +C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is +C defined in a similar way using INCY. +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 920310 Corrected definition of LX in DESCRIPTION. (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DDOT + DOUBLE PRECISION DX(*), DY(*) +C***FIRST EXECUTABLE STATEMENT DDOT + DDOT = 0.0D0 + IF (N .LE. 0) RETURN + IF (INCX .EQ. INCY) IF (INCX-1) 5,20,60 +C +C Code for unequal or nonpositive increments. +C + 5 IX = 1 + IY = 1 + IF (INCX .LT. 0) IX = (-N+1)*INCX + 1 + IF (INCY .LT. 0) IY = (-N+1)*INCY + 1 + DO 10 I = 1,N + DDOT = DDOT + DX(IX)*DY(IY) + IX = IX + INCX + IY = IY + INCY + 10 CONTINUE + RETURN +C +C Code for both increments equal to 1. +C +C Clean-up loop so remaining vector length is a multiple of 5. +C + 20 M = MOD(N,5) + IF (M .EQ. 0) GO TO 40 + DO 30 I = 1,M + DDOT = DDOT + DX(I)*DY(I) + 30 CONTINUE + IF (N .LT. 5) RETURN + 40 MP1 = M + 1 + DO 50 I = MP1,N,5 + DDOT = DDOT + DX(I)*DY(I) + DX(I+1)*DY(I+1) + DX(I+2)*DY(I+2) + + 1 DX(I+3)*DY(I+3) + DX(I+4)*DY(I+4) + 50 CONTINUE + RETURN +C +C Code for equal, positive, non-unit increments. +C + 60 NS = N*INCX + DO 70 I = 1,NS,INCX + DDOT = DDOT + DX(I)*DY(I) + 70 CONTINUE + RETURN + END +*DECK DNRM2 + DOUBLE PRECISION FUNCTION DNRM2 (N, DX, INCX) +C***BEGIN PROLOGUE DNRM2 +C***PURPOSE Compute the Euclidean length (L2 norm) of a vector. +C***CATEGORY D1A3B +C***TYPE DOUBLE PRECISION (SNRM2-S, DNRM2-D, SCNRM2-C) +C***KEYWORDS BLAS, EUCLIDEAN LENGTH, EUCLIDEAN NORM, L2, +C LINEAR ALGEBRA, UNITARY, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of parameters +C +C --Input-- +C N number of elements in input vector(s) +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C +C --Output-- +C DNRM2 double precision result (zero if N .LE. 0) +C +C Euclidean norm of the N-vector stored in DX with storage +C increment INCX. +C If N .LE. 0, return with result = 0. +C If N .GE. 1, then INCX must be .GE. 1 +C +C Four phase method using two built-in constants that are +C hopefully applicable to all machines. +C CUTLO = maximum of SQRT(U/EPS) over all known machines. +C CUTHI = minimum of SQRT(V) over all known machines. +C where +C EPS = smallest no. such that EPS + 1. .GT. 1. +C U = smallest positive no. (underflow limit) +C V = largest no. (overflow limit) +C +C Brief outline of algorithm. +C +C Phase 1 scans zero components. +C move to phase 2 when a component is nonzero and .LE. CUTLO +C move to phase 3 when a component is .GT. CUTLO +C move to phase 4 when a component is .GE. CUTHI/M +C where M = N for X() real and M = 2*N for complex. +C +C Values for CUTLO and CUTHI. +C From the environmental parameters listed in the IMSL converter +C document the limiting values are as follows: +C CUTLO, S.P. U/EPS = 2**(-102) for Honeywell. Close seconds are +C Univac and DEC at 2**(-103) +C Thus CUTLO = 2**(-51) = 4.44089E-16 +C CUTHI, S.P. V = 2**127 for Univac, Honeywell, and DEC. +C Thus CUTHI = 2**(63.5) = 1.30438E19 +C CUTLO, D.P. U/EPS = 2**(-67) for Honeywell and DEC. +C Thus CUTLO = 2**(-33.5) = 8.23181D-11 +C CUTHI, D.P. same as S.P. CUTHI = 1.30438D19 +C DATA CUTLO, CUTHI /8.232D-11, 1.304D19/ +C DATA CUTLO, CUTHI /4.441E-16, 1.304E19/ +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890531 Changed all specific intrinsics to generic. (WRB) +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 920501 Reformatted the REFERENCES section. (WRB) +C 050329 Converted Assigned GO TO to simple IF ... GO stmts. (ACH) +C***END PROLOGUE DNRM2 + INTEGER NEXT + DOUBLE PRECISION DX(*), CUTLO, CUTHI, HITEST, SUM, XMAX, ZERO, + + ONE + SAVE CUTLO, CUTHI, ZERO, ONE + DATA ZERO, ONE /0.0D0, 1.0D0/ +C + DATA CUTLO, CUTHI /8.232D-11, 1.304D19/ +C***FIRST EXECUTABLE STATEMENT DNRM2 + IF (N .GT. 0) GO TO 10 + DNRM2 = ZERO + GO TO 300 +C +C 10 ASSIGN 30 TO NEXT + 10 NEXT = 1 + SUM = ZERO + NN = N * INCX +C +C BEGIN MAIN LOOP +C + I = 1 + 20 IF (NEXT .EQ. 2) GO TO 50 + IF (NEXT .EQ. 3) GO TO 70 + IF (NEXT .EQ. 4) GO TO 110 +C 20 GO TO NEXT,(30, 50, 70, 110) + IF (ABS(DX(I)) .GT. CUTLO) GO TO 85 +C ASSIGN 50 TO NEXT + NEXT = 2 + XMAX = ZERO +C +C PHASE 1. SUM IS ZERO +C + 50 IF (DX(I) .EQ. ZERO) GO TO 200 + IF (ABS(DX(I)) .GT. CUTLO) GO TO 85 +C +C PREPARE FOR PHASE 2. +C +C ASSIGN 70 TO NEXT + NEXT = 3 + GO TO 105 +C +C PREPARE FOR PHASE 4. +C + 100 I = J +C ASSIGN 110 TO NEXT + NEXT = 4 + SUM = (SUM / DX(I)) / DX(I) + 105 XMAX = ABS(DX(I)) + GO TO 115 +C +C PHASE 2. SUM IS SMALL. +C SCALE TO AVOID DESTRUCTIVE UNDERFLOW. +C + 70 IF (ABS(DX(I)) .GT. CUTLO) GO TO 75 +C +C COMMON CODE FOR PHASES 2 AND 4. +C IN PHASE 4 SUM IS LARGE. SCALE TO AVOID OVERFLOW. +C + 110 IF (ABS(DX(I)) .LE. XMAX) GO TO 115 + SUM = ONE + SUM * (XMAX / DX(I))**2 + XMAX = ABS(DX(I)) + GO TO 200 +C + 115 SUM = SUM + (DX(I)/XMAX)**2 + GO TO 200 +C +C PREPARE FOR PHASE 3. +C + 75 SUM = (SUM * XMAX) * XMAX +C +C FOR REAL OR D.P. SET HITEST = CUTHI/N +C FOR COMPLEX SET HITEST = CUTHI/(2*N) +C + 85 HITEST = CUTHI / N +C +C PHASE 3. SUM IS MID-RANGE. NO SCALING. +C + DO 95 J = I,NN,INCX + IF (ABS(DX(J)) .GE. HITEST) GO TO 100 + 95 SUM = SUM + DX(J)**2 + DNRM2 = SQRT(SUM) + GO TO 300 +C + 200 CONTINUE + I = I + INCX + IF (I .LE. NN) GO TO 20 +C +C END OF MAIN LOOP. +C +C COMPUTE SQUARE ROOT AND ADJUST FOR SCALING. +C + DNRM2 = XMAX * SQRT(SUM) + 300 CONTINUE + RETURN + END +*DECK DSCAL + SUBROUTINE DSCAL (N, DA, DX, INCX) +C***BEGIN PROLOGUE DSCAL +C***PURPOSE Multiply a vector by a constant. +C***CATEGORY D1A6 +C***TYPE DOUBLE PRECISION (SSCAL-S, DSCAL-D, CSCAL-C) +C***KEYWORDS BLAS, LINEAR ALGEBRA, SCALE, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of Parameters +C +C --Input-- +C N number of elements in input vector(s) +C DA double precision scale factor +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C +C --Output-- +C DX double precision result (unchanged if N.LE.0) +C +C Replace double precision DX by double precision DA*DX. +C For I = 0 to N-1, replace DX(IX+I*INCX) with DA * DX(IX+I*INCX), +C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX. +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890831 Modified array declarations. (WRB) +C 890831 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900821 Modified to correct problem with a negative increment. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE DSCAL + DOUBLE PRECISION DA, DX(*) + INTEGER I, INCX, IX, M, MP1, N +C***FIRST EXECUTABLE STATEMENT DSCAL + IF (N .LE. 0) RETURN + IF (INCX .EQ. 1) GOTO 20 +C +C Code for increment not equal to 1. +C + IX = 1 + IF (INCX .LT. 0) IX = (-N+1)*INCX + 1 + DO 10 I = 1,N + DX(IX) = DA*DX(IX) + IX = IX + INCX + 10 CONTINUE + RETURN +C +C Code for increment equal to 1. +C +C Clean-up loop so remaining vector length is a multiple of 5. +C + 20 M = MOD(N,5) + IF (M .EQ. 0) GOTO 40 + DO 30 I = 1,M + DX(I) = DA*DX(I) + 30 CONTINUE + IF (N .LT. 5) RETURN + 40 MP1 = M + 1 + DO 50 I = MP1,N,5 + DX(I) = DA*DX(I) + DX(I+1) = DA*DX(I+1) + DX(I+2) = DA*DX(I+2) + DX(I+3) = DA*DX(I+3) + DX(I+4) = DA*DX(I+4) + 50 CONTINUE + RETURN + END +*DECK IDAMAX + INTEGER FUNCTION IDAMAX (N, DX, INCX) +C***BEGIN PROLOGUE IDAMAX +C***PURPOSE Find the smallest index of that component of a vector +C having the maximum magnitude. +C***CATEGORY D1A2 +C***TYPE DOUBLE PRECISION (ISAMAX-S, IDAMAX-D, ICAMAX-C) +C***KEYWORDS BLAS, LINEAR ALGEBRA, MAXIMUM COMPONENT, VECTOR +C***AUTHOR Lawson, C. L., (JPL) +C Hanson, R. J., (SNLA) +C Kincaid, D. R., (U. of Texas) +C Krogh, F. T., (JPL) +C***DESCRIPTION +C +C B L A S Subprogram +C Description of Parameters +C +C --Input-- +C N number of elements in input vector(s) +C DX double precision vector with N elements +C INCX storage spacing between elements of DX +C +C --Output-- +C IDAMAX smallest index (zero if N .LE. 0) +C +C Find smallest index of maximum magnitude of double precision DX. +C IDAMAX = first I, I = 1 to N, to maximize ABS(DX(IX+(I-1)*INCX)), +C where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX. +C +C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. +C Krogh, Basic linear algebra subprograms for Fortran +C usage, Algorithm No. 539, Transactions on Mathematical +C Software 5, 3 (September 1979), pp. 308-323. +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 791001 DATE WRITTEN +C 890531 Changed all specific intrinsics to generic. (WRB) +C 890531 REVISION DATE from Version 3.2 +C 891214 Prologue converted to Version 4.0 format. (BAB) +C 900821 Modified to correct problem with a negative increment. +C (WRB) +C 920501 Reformatted the REFERENCES section. (WRB) +C***END PROLOGUE IDAMAX + DOUBLE PRECISION DX(*), DMAX, XMAG + INTEGER I, INCX, IX, N +C***FIRST EXECUTABLE STATEMENT IDAMAX + IDAMAX = 0 + IF (N .LE. 0) RETURN + IDAMAX = 1 + IF (N .EQ. 1) RETURN +C + IF (INCX .EQ. 1) GOTO 20 +C +C Code for increments not equal to 1. +C + IX = 1 + IF (INCX .LT. 0) IX = (-N+1)*INCX + 1 + DMAX = ABS(DX(IX)) + IX = IX + INCX + DO 10 I = 2,N + XMAG = ABS(DX(IX)) + IF (XMAG .GT. DMAX) THEN + IDAMAX = I + DMAX = XMAG + ENDIF + IX = IX + INCX + 10 CONTINUE + RETURN +C +C Code for increments equal to 1. +C + 20 DMAX = ABS(DX(1)) + DO 30 I = 2,N + XMAG = ABS(DX(I)) + IF (XMAG .GT. DMAX) THEN + IDAMAX = I + DMAX = XMAG + ENDIF + 30 CONTINUE + RETURN + END +*DECK XERRWD + SUBROUTINE XERRWD (MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2) +C***BEGIN PROLOGUE XERRWD +C***SUBSIDIARY +C***PURPOSE Write error message with values. +C***CATEGORY R3C +C***TYPE DOUBLE PRECISION (XERRWV-S, XERRWD-D) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C Subroutines XERRWD, XSETF, XSETUN, and the function routine IXSAV, +C as given here, constitute a simplified version of the SLATEC error +C handling package. +C +C All arguments are input arguments. +C +C MSG = The message (character array). +C NMES = The length of MSG (number of characters). +C NERR = The error number (not used). +C LEVEL = The error level.. +C 0 or 1 means recoverable (control returns to caller). +C 2 means fatal (run is aborted--see note below). +C NI = Number of integers (0, 1, or 2) to be printed with message. +C I1,I2 = Integers to be printed, depending on NI. +C NR = Number of reals (0, 1, or 2) to be printed with message. +C R1,R2 = Reals to be printed, depending on NR. +C +C Note.. this routine is machine-dependent and specialized for use +C in limited context, in the following ways.. +C 1. The argument MSG is assumed to be of type CHARACTER, and +C the message is printed with a format of (1X,A). +C 2. The message is assumed to take only one line. +C Multi-line messages are generated by repeated calls. +C 3. If LEVEL = 2, control passes to the statement STOP +C to abort the run. This statement may be machine-dependent. +C 4. R1 and R2 are assumed to be in double precision and are printed +C in D21.13 format. +C +C***ROUTINES CALLED IXSAV +C***REVISION HISTORY (YYMMDD) +C 920831 DATE WRITTEN +C 921118 Replaced MFLGSV/LUNSAV by IXSAV. (ACH) +C 930329 Modified prologue to SLATEC format. (FNF) +C 930407 Changed MSG from CHARACTER*1 array to variable. (FNF) +C 930922 Minor cosmetic change. (FNF) +C***END PROLOGUE XERRWD +C +C*Internal Notes: +C +C For a different default logical unit number, IXSAV (or a subsidiary +C routine that it calls) will need to be modified. +C For a different run-abort command, change the statement following +C statement 100 at the end. +C----------------------------------------------------------------------- +C Subroutines called by XERRWD.. None +C Function routine called by XERRWD.. IXSAV +C----------------------------------------------------------------------- +C**End +C +C Declare arguments. +C + DOUBLE PRECISION R1, R2 + INTEGER NMES, NERR, LEVEL, NI, I1, I2, NR + CHARACTER*(*) MSG +C +C Declare local variables. +C + INTEGER LUNIT, IXSAV, MESFLG +C +C Get logical unit number and message print flag. +C +C***FIRST EXECUTABLE STATEMENT XERRWD + LUNIT = IXSAV (1, 0, .FALSE.) + MESFLG = IXSAV (2, 0, .FALSE.) + IF (MESFLG .EQ. 0) GO TO 100 +C +C Write the message. +C + WRITE (LUNIT,10) MSG + 10 FORMAT(1X,A) + IF (NI .EQ. 1) WRITE (LUNIT, 20) I1 + 20 FORMAT(6X,'In above message, I1 =',I10) + IF (NI .EQ. 2) WRITE (LUNIT, 30) I1,I2 + 30 FORMAT(6X,'In above message, I1 =',I10,3X,'I2 =',I10) + IF (NR .EQ. 1) WRITE (LUNIT, 40) R1 + 40 FORMAT(6X,'In above message, R1 =',D21.13) + IF (NR .EQ. 2) WRITE (LUNIT, 50) R1,R2 + 50 FORMAT(6X,'In above, R1 =',D21.13,3X,'R2 =',D21.13) +C +C Abort the run if LEVEL = 2. +C + 100 IF (LEVEL .NE. 2) RETURN + STOP +C----------------------- End of Subroutine XERRWD ---------------------- + END +*DECK XSETF + SUBROUTINE XSETF (MFLAG) +C***BEGIN PROLOGUE XSETF +C***PURPOSE Reset the error print control flag. +C***CATEGORY R3A +C***TYPE ALL (XSETF-A) +C***KEYWORDS ERROR CONTROL +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C XSETF sets the error print control flag to MFLAG: +C MFLAG=1 means print all messages (the default). +C MFLAG=0 means no printing. +C +C***SEE ALSO XERRWD, XERRWV +C***REFERENCES (NONE) +C***ROUTINES CALLED IXSAV +C***REVISION HISTORY (YYMMDD) +C 921118 DATE WRITTEN +C 930329 Added SLATEC format prologue. (FNF) +C 930407 Corrected SEE ALSO section. (FNF) +C 930922 Made user-callable, and other cosmetic changes. (FNF) +C***END PROLOGUE XSETF +C +C Subroutines called by XSETF.. None +C Function routine called by XSETF.. IXSAV +C----------------------------------------------------------------------- +C**End + INTEGER MFLAG, JUNK, IXSAV +C +C***FIRST EXECUTABLE STATEMENT XSETF + IF (MFLAG .EQ. 0 .OR. MFLAG .EQ. 1) JUNK = IXSAV (2,MFLAG,.TRUE.) + RETURN +C----------------------- End of Subroutine XSETF ----------------------- + END +*DECK XSETUN + SUBROUTINE XSETUN (LUN) +C***BEGIN PROLOGUE XSETUN +C***PURPOSE Reset the logical unit number for error messages. +C***CATEGORY R3B +C***TYPE ALL (XSETUN-A) +C***KEYWORDS ERROR CONTROL +C***DESCRIPTION +C +C XSETUN sets the logical unit number for error messages to LUN. +C +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***SEE ALSO XERRWD, XERRWV +C***REFERENCES (NONE) +C***ROUTINES CALLED IXSAV +C***REVISION HISTORY (YYMMDD) +C 921118 DATE WRITTEN +C 930329 Added SLATEC format prologue. (FNF) +C 930407 Corrected SEE ALSO section. (FNF) +C 930922 Made user-callable, and other cosmetic changes. (FNF) +C***END PROLOGUE XSETUN +C +C Subroutines called by XSETUN.. None +C Function routine called by XSETUN.. IXSAV +C----------------------------------------------------------------------- +C**End + INTEGER LUN, JUNK, IXSAV +C +C***FIRST EXECUTABLE STATEMENT XSETUN + IF (LUN .GT. 0) JUNK = IXSAV (1,LUN,.TRUE.) + RETURN +C----------------------- End of Subroutine XSETUN ---------------------- + END +*DECK IXSAV + INTEGER FUNCTION IXSAV (IPAR, IVALUE, ISET) +C***BEGIN PROLOGUE IXSAV +C***SUBSIDIARY +C***PURPOSE Save and recall error message control parameters. +C***CATEGORY R3C +C***TYPE ALL (IXSAV-A) +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C +C IXSAV saves and recalls one of two error message parameters: +C LUNIT, the logical unit number to which messages are printed, and +C MESFLG, the message print flag. +C This is a modification of the SLATEC library routine J4SAVE. +C +C Saved local variables.. +C LUNIT = Logical unit number for messages. The default is obtained +C by a call to IUMACH (may be machine-dependent). +C MESFLG = Print control flag.. +C 1 means print all messages (the default). +C 0 means no printing. +C +C On input.. +C IPAR = Parameter indicator (1 for LUNIT, 2 for MESFLG). +C IVALUE = The value to be set for the parameter, if ISET = .TRUE. +C ISET = Logical flag to indicate whether to read or write. +C If ISET = .TRUE., the parameter will be given +C the value IVALUE. If ISET = .FALSE., the parameter +C will be unchanged, and IVALUE is a dummy argument. +C +C On return.. +C IXSAV = The (old) value of the parameter. +C +C***SEE ALSO XERRWD, XERRWV +C***ROUTINES CALLED IUMACH +C***REVISION HISTORY (YYMMDD) +C 921118 DATE WRITTEN +C 930329 Modified prologue to SLATEC format. (FNF) +C 930915 Added IUMACH call to get default output unit. (ACH) +C 930922 Minor cosmetic changes. (FNF) +C 010425 Type declaration for IUMACH added. (ACH) +C***END PROLOGUE IXSAV +C +C Subroutines called by IXSAV.. None +C Function routine called by IXSAV.. IUMACH +C----------------------------------------------------------------------- +C**End + LOGICAL ISET + INTEGER IPAR, IVALUE +C----------------------------------------------------------------------- + INTEGER IUMACH, LUNIT, MESFLG +C----------------------------------------------------------------------- +C The following Fortran-77 declaration is to cause the values of the +C listed (local) variables to be saved between calls to this routine. +C----------------------------------------------------------------------- + SAVE LUNIT, MESFLG + DATA LUNIT/-1/, MESFLG/1/ +C +C***FIRST EXECUTABLE STATEMENT IXSAV + IF (IPAR .EQ. 1) THEN + IF (LUNIT .EQ. -1) LUNIT = IUMACH() + IXSAV = LUNIT + IF (ISET) LUNIT = IVALUE + ENDIF +C + IF (IPAR .EQ. 2) THEN + IXSAV = MESFLG + IF (ISET) MESFLG = IVALUE + ENDIF +C + RETURN +C----------------------- End of Function IXSAV ------------------------- + END +*DECK IUMACH + INTEGER FUNCTION IUMACH() +C***BEGIN PROLOGUE IUMACH +C***PURPOSE Provide standard output unit number. +C***CATEGORY R1 +C***TYPE INTEGER (IUMACH-I) +C***KEYWORDS MACHINE CONSTANTS +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C***DESCRIPTION +C *Usage: +C INTEGER LOUT, IUMACH +C LOUT = IUMACH() +C +C *Function Return Values: +C LOUT : the standard logical unit for Fortran output. +C +C***REFERENCES (NONE) +C***ROUTINES CALLED (NONE) +C***REVISION HISTORY (YYMMDD) +C 930915 DATE WRITTEN +C 930922 Made user-callable, and other cosmetic changes. (FNF) +C***END PROLOGUE IUMACH +C +C*Internal Notes: +C The built-in value of 6 is standard on a wide range of Fortran +C systems. This may be machine-dependent. +C**End +C***FIRST EXECUTABLE STATEMENT IUMACH + IUMACH = 6 +C + RETURN +C----------------------- End of Function IUMACH ------------------------ + END diff --git a/src/Enzo/opkdmain.F b/src/Enzo/opkdmain.F new file mode 100644 index 0000000000..dce6b1b874 --- /dev/null +++ b/src/Enzo/opkdmain.F @@ -0,0 +1,16585 @@ +*DECK DLSODE + SUBROUTINE DLSODE (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF) + EXTERNAL F, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW) +C***BEGIN PROLOGUE DLSODE +C***PURPOSE Livermore Solver for Ordinary Differential Equations. +C DLSODE solves the initial-value problem for stiff or +C nonstiff systems of first-order ODE's, +C dy/dt = f(t,y), or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(N)), i=1,...,N. +C***CATEGORY I1A +C***TYPE DOUBLE PRECISION (SLSODE-S, DLSODE-D) +C***KEYWORDS ORDINARY DIFFERENTIAL EQUATIONS, INITIAL VALUE PROBLEM, +C STIFF, NONSTIFF +C***AUTHOR Hindmarsh, Alan C., (LLNL) +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551. +C***DESCRIPTION +C +C NOTE: The "Usage" and "Arguments" sections treat only a subset of +C available options, in condensed fashion. The options +C covered and the information supplied will support most +C standard uses of DLSODE. +C +C For more sophisticated uses, full details on all options are +C given in the concluding section, headed "Long Description." +C A synopsis of the DLSODE Long Description is provided at the +C beginning of that section; general topics covered are: +C - Elements of the call sequence; optional input and output +C - Optional supplemental routines in the DLSODE package +C - internal COMMON block +C +C *Usage: +C Communication between the user and the DLSODE package, for normal +C situations, is summarized here. This summary describes a subset +C of the available options. See "Long Description" for complete +C details, including optional communication, nonstandard options, +C and instructions for special situations. +C +C A sample program is given in the "Examples" section. +C +C Refer to the argument descriptions for the definitions of the +C quantities that appear in the following sample declarations. +C +C For MF = 10, +C PARAMETER (LRW = 20 + 16*NEQ, LIW = 20) +C For MF = 21 or 22, +C PARAMETER (LRW = 22 + 9*NEQ + NEQ**2, LIW = 20 + NEQ) +C For MF = 24 or 25, +C PARAMETER (LRW = 22 + 10*NEQ + (2*ML+MU)*NEQ, +C * LIW = 20 + NEQ) +C +C EXTERNAL F, JAC +C INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK(LIW), +C * LIW, MF +C DOUBLE PRECISION Y(NEQ), T, TOUT, RTOL, ATOL(ntol), RWORK(LRW) +C +C CALL DLSODE (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, +C * ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF) +C +C *Arguments: +C F :EXT Name of subroutine for right-hand-side vector f. +C This name must be declared EXTERNAL in calling +C program. The form of F must be: +C +C SUBROUTINE F (NEQ, T, Y, YDOT) +C INTEGER NEQ +C DOUBLE PRECISION T, Y(*), YDOT(*) +C +C The inputs are NEQ, T, Y. F is to set +C +C YDOT(i) = f(i,T,Y(1),Y(2),...,Y(NEQ)), +C i = 1, ..., NEQ . +C +C NEQ :IN Number of first-order ODE's. +C +C Y :INOUT Array of values of the y(t) vector, of length NEQ. +C Input: For the first call, Y should contain the +C values of y(t) at t = T. (Y is an input +C variable only if ISTATE = 1.) +C Output: On return, Y will contain the values at the +C new t-value. +C +C T :INOUT Value of the independent variable. On return it +C will be the current value of t (normally TOUT). +C +C TOUT :IN Next point where output is desired (.NE. T). +C +C ITOL :IN 1 or 2 according as ATOL (below) is a scalar or +C an array. +C +C RTOL :IN Relative tolerance parameter (scalar). +C +C ATOL :IN Absolute tolerance parameter (scalar or array). +C If ITOL = 1, ATOL need not be dimensioned. +C If ITOL = 2, ATOL must be dimensioned at least NEQ. +C +C The estimated local error in Y(i) will be controlled +C so as to be roughly less (in magnitude) than +C +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C +C Thus the local error test passes if, in each +C component, either the absolute error is less than +C ATOL (or ATOL(i)), or the relative error is less +C than RTOL. +C +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative +C error control. Caution: Actual (global) errors may +C exceed these local tolerances, so choose them +C conservatively. +C +C ITASK :IN Flag indicating the task DLSODE is to perform. +C Use ITASK = 1 for normal computation of output +C values of y at t = TOUT. +C +C ISTATE:INOUT Index used for input and output to specify the state +C of the calculation. +C Input: +C 1 This is the first call for a problem. +C 2 This is a subsequent call. +C Output: +C 1 Nothing was done, because TOUT was equal to T. +C 2 DLSODE was successful (otherwise, negative). +C Note that ISTATE need not be modified after a +C successful return. +C -1 Excess work done on this call (perhaps wrong +C MF). +C -2 Excess accuracy requested (tolerances too +C small). +C -3 Illegal input detected (see printed message). +C -4 Repeated error test failures (check all +C inputs). +C -5 Repeated convergence failures (perhaps bad +C Jacobian supplied or wrong choice of MF or +C tolerances). +C -6 Error weight became zero during problem +C (solution component i vanished, and ATOL or +C ATOL(i) = 0.). +C +C IOPT :IN Flag indicating whether optional inputs are used: +C 0 No. +C 1 Yes. (See "Optional inputs" under "Long +C Description," Part 1.) +C +C RWORK :WORK Real work array of length at least: +C 20 + 16*NEQ for MF = 10, +C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22, +C 22 + 10*NEQ + (2*ML + MU)*NEQ for MF = 24 or 25. +C +C LRW :IN Declared length of RWORK (in user's DIMENSION +C statement). +C +C IWORK :WORK Integer work array of length at least: +C 20 for MF = 10, +C 20 + NEQ for MF = 21, 22, 24, or 25. +C +C If MF = 24 or 25, input in IWORK(1),IWORK(2) the +C lower and upper Jacobian half-bandwidths ML,MU. +C +C On return, IWORK contains information that may be +C of interest to the user: +C +C Name Location Meaning +C ----- --------- ----------------------------------------- +C NST IWORK(11) Number of steps taken for the problem so +C far. +C NFE IWORK(12) Number of f evaluations for the problem +C so far. +C NJE IWORK(13) Number of Jacobian evaluations (and of +C matrix LU decompositions) for the problem +C so far. +C NQU IWORK(14) Method order last used (successfully). +C LENRW IWORK(17) Length of RWORK actually required. This +C is defined on normal returns and on an +C illegal input return for insufficient +C storage. +C LENIW IWORK(18) Length of IWORK actually required. This +C is defined on normal returns and on an +C illegal input return for insufficient +C storage. +C +C LIW :IN Declared length of IWORK (in user's DIMENSION +C statement). +C +C JAC :EXT Name of subroutine for Jacobian matrix (MF = +C 21 or 24). If used, this name must be declared +C EXTERNAL in calling program. If not used, pass a +C dummy name. The form of JAC must be: +C +C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) +C INTEGER NEQ, ML, MU, NROWPD +C DOUBLE PRECISION T, Y(*), PD(NROWPD,*) +C +C See item c, under "Description" below for more +C information about JAC. +C +C MF :IN Method flag. Standard values are: +C 10 Nonstiff (Adams) method, no Jacobian used. +C 21 Stiff (BDF) method, user-supplied full Jacobian. +C 22 Stiff method, internally generated full +C Jacobian. +C 24 Stiff method, user-supplied banded Jacobian. +C 25 Stiff method, internally generated banded +C Jacobian. +C +C *Description: +C DLSODE solves the initial value problem for stiff or nonstiff +C systems of first-order ODE's, +C +C dy/dt = f(t,y) , +C +C or, in component form, +C +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) +C (i = 1, ..., NEQ) . +C +C DLSODE is a package based on the GEAR and GEARB packages, and on +C the October 23, 1978, version of the tentative ODEPACK user +C interface standard, with minor modifications. +C +C The steps in solving such a problem are as follows. +C +C a. First write a subroutine of the form +C +C SUBROUTINE F (NEQ, T, Y, YDOT) +C INTEGER NEQ +C DOUBLE PRECISION T, Y(*), YDOT(*) +C +C which supplies the vector function f by loading YDOT(i) with +C f(i). +C +C b. Next determine (or guess) whether or not the problem is stiff. +C Stiffness occurs when the Jacobian matrix df/dy has an +C eigenvalue whose real part is negative and large in magnitude +C compared to the reciprocal of the t span of interest. If the +C problem is nonstiff, use method flag MF = 10. If it is stiff, +C there are four standard choices for MF, and DLSODE requires the +C Jacobian matrix in some form. This matrix is regarded either +C as full (MF = 21 or 22), or banded (MF = 24 or 25). In the +C banded case, DLSODE requires two half-bandwidth parameters ML +C and MU. These are, respectively, the widths of the lower and +C upper parts of the band, excluding the main diagonal. Thus the +C band consists of the locations (i,j) with +C +C i - ML <= j <= i + MU , +C +C and the full bandwidth is ML + MU + 1 . +C +C c. If the problem is stiff, you are encouraged to supply the +C Jacobian directly (MF = 21 or 24), but if this is not feasible, +C DLSODE will compute it internally by difference quotients (MF = +C 22 or 25). If you are supplying the Jacobian, write a +C subroutine of the form +C +C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) +C INTEGER NEQ, ML, MU, NRWOPD +C DOUBLE PRECISION T, Y(*), PD(NROWPD,*) +C +C which provides df/dy by loading PD as follows: +C - For a full Jacobian (MF = 21), load PD(i,j) with df(i)/dy(j), +C the partial derivative of f(i) with respect to y(j). (Ignore +C the ML and MU arguments in this case.) +C - For a banded Jacobian (MF = 24), load PD(i-j+MU+1,j) with +C df(i)/dy(j); i.e., load the diagonal lines of df/dy into the +C rows of PD from the top down. +C - In either case, only nonzero elements need be loaded. +C +C d. Write a main program that calls subroutine DLSODE once for each +C point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages +C by DLSODE. +C +C Before the first call to DLSODE, set ISTATE = 1, set Y and T to +C the initial values, and set TOUT to the first output point. To +C continue the integration after a successful return, simply +C reset TOUT and call DLSODE again. No other parameters need be +C reset. +C +C *Examples: +C The following is a simple example problem, with the coding needed +C for its solution by DLSODE. The problem is from chemical kinetics, +C and consists of the following three rate equations: +C +C dy1/dt = -.04*y1 + 1.E4*y2*y3 +C dy2/dt = .04*y1 - 1.E4*y2*y3 - 3.E7*y2**2 +C dy3/dt = 3.E7*y2**2 +C +C on the interval from t = 0.0 to t = 4.E10, with initial conditions +C y1 = 1.0, y2 = y3 = 0. The problem is stiff. +C +C The following coding solves this problem with DLSODE, using +C MF = 21 and printing results at t = .4, 4., ..., 4.E10. It uses +C ITOL = 2 and ATOL much smaller for y2 than for y1 or y3 because y2 +C has much smaller values. At the end of the run, statistical +C quantities of interest are printed. +C +C EXTERNAL FEX, JEX +C INTEGER IOPT, IOUT, ISTATE, ITASK, ITOL, IWORK(23), LIW, LRW, +C * MF, NEQ +C DOUBLE PRECISION ATOL(3), RTOL, RWORK(58), T, TOUT, Y(3) +C NEQ = 3 +C Y(1) = 1.D0 +C Y(2) = 0.D0 +C Y(3) = 0.D0 +C T = 0.D0 +C TOUT = .4D0 +C ITOL = 2 +C RTOL = 1.D-4 +C ATOL(1) = 1.D-6 +C ATOL(2) = 1.D-10 +C ATOL(3) = 1.D-6 +C ITASK = 1 +C ISTATE = 1 +C IOPT = 0 +C LRW = 58 +C LIW = 23 +C MF = 21 +C DO 40 IOUT = 1,12 +C CALL DLSODE (FEX, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, +C * ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JEX, MF) +C WRITE(6,20) T, Y(1), Y(2), Y(3) +C 20 FORMAT(' At t =',D12.4,' y =',3D14.6) +C IF (ISTATE .LT. 0) GO TO 80 +C 40 TOUT = TOUT*10.D0 +C WRITE(6,60) IWORK(11), IWORK(12), IWORK(13) +C 60 FORMAT(/' No. steps =',i4,', No. f-s =',i4,', No. J-s =',i4) +C STOP +C 80 WRITE(6,90) ISTATE +C 90 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE FEX (NEQ, T, Y, YDOT) +C INTEGER NEQ +C DOUBLE PRECISION T, Y(3), YDOT(3) +C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3) +C YDOT(3) = 3.D7*Y(2)*Y(2) +C YDOT(2) = -YDOT(1) - YDOT(3) +C RETURN +C END +C +C SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD) +C INTEGER NEQ, ML, MU, NRPD +C DOUBLE PRECISION T, Y(3), PD(NRPD,3) +C PD(1,1) = -.04D0 +C PD(1,2) = 1.D4*Y(3) +C PD(1,3) = 1.D4*Y(2) +C PD(2,1) = .04D0 +C PD(2,3) = -PD(1,3) +C PD(3,2) = 6.D7*Y(2) +C PD(2,2) = -PD(1,2) - PD(3,2) +C RETURN +C END +C +C The output from this program (on a Cray-1 in single precision) +C is as follows. +C +C At t = 4.0000e-01 y = 9.851726e-01 3.386406e-05 1.479357e-02 +C At t = 4.0000e+00 y = 9.055142e-01 2.240418e-05 9.446344e-02 +C At t = 4.0000e+01 y = 7.158050e-01 9.184616e-06 2.841858e-01 +C At t = 4.0000e+02 y = 4.504846e-01 3.222434e-06 5.495122e-01 +C At t = 4.0000e+03 y = 1.831701e-01 8.940379e-07 8.168290e-01 +C At t = 4.0000e+04 y = 3.897016e-02 1.621193e-07 9.610297e-01 +C At t = 4.0000e+05 y = 4.935213e-03 1.983756e-08 9.950648e-01 +C At t = 4.0000e+06 y = 5.159269e-04 2.064759e-09 9.994841e-01 +C At t = 4.0000e+07 y = 5.306413e-05 2.122677e-10 9.999469e-01 +C At t = 4.0000e+08 y = 5.494530e-06 2.197825e-11 9.999945e-01 +C At t = 4.0000e+09 y = 5.129458e-07 2.051784e-12 9.999995e-01 +C At t = 4.0000e+10 y = -7.170603e-08 -2.868241e-13 1.000000e+00 +C +C No. steps = 330, No. f-s = 405, No. J-s = 69 +C +C *Accuracy: +C The accuracy of the solution depends on the choice of tolerances +C RTOL and ATOL. Actual (global) errors may exceed these local +C tolerances, so choose them conservatively. +C +C *Cautions: +C The work arrays should not be altered between calls to DLSODE for +C the same problem, except possibly for the conditional and optional +C inputs. +C +C *Portability: +C Since NEQ is dimensioned inside DLSODE, some compilers may object +C to a call to DLSODE with NEQ a scalar variable. In this event, +C use DIMENSION NEQ(1). Similar remarks apply to RTOL and ATOL. +C +C Note to Cray users: +C For maximum efficiency, use the CFT77 compiler. Appropriate +C compiler optimization directives have been inserted for CFT77. +C +C *Reference: +C Alan C. Hindmarsh, "ODEPACK, A Systematized Collection of ODE +C Solvers," in Scientific Computing, R. S. Stepleman, et al., Eds. +C (North-Holland, Amsterdam, 1983), pp. 55-64. +C +C *Long Description: +C The following complete description of the user interface to +C DLSODE consists of four parts: +C +C 1. The call sequence to subroutine DLSODE, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and user-supplied routines. +C Following these descriptions is a description of optional +C inputs available through the call sequence, and then a +C description of optional outputs in the work arrays. +C +C 2. Descriptions of other routines in the DLSODE package that may +C be (optionally) called by the user. These provide the ability +C to alter error message handling, save and restore the internal +C COMMON, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of COMMON block to be declared in overlay or +C similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODE package, either of +C which the user may replace with his own version, if desired. +C These relate to the measurement of errors. +C +C +C Part 1. Call Sequence +C ---------------------- +C +C Arguments +C --------- +C The call sequence parameters used for input only are +C +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, MF, +C +C and those used for both input and output are +C +C Y, T, ISTATE. +C +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here +C refers to the return from subroutine DLSODE to the user's calling +C program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F The name of the user-supplied subroutine defining the ODE +C system. The system must be put in the first-order form +C dy/dt = f(t,y), where f is a vector-valued function of +C the scalar t and the vector y. Subroutine F is to compute +C the function f. It is to have the form +C +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C +C where NEQ, T, and Y are input, and the array YDOT = +C f(T,Y) is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter Y(1),...,Y(NEQ). F must be +C declared EXTERNAL in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),..., if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODE, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY +C instead. +C +C NEQ The size of the ODE system (number of first-order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the +C problem. If NEQ is decreased (with ISTATE = 3 on input), +C the remaining components of Y should be left undisturbed, +C if these are to be accessed in F and/or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred +C to as a scalar in this user interface description. +C However, NEQ may be an array, with NEQ(1) set to the +C system size. (The DLSODE package accesses only NEQ(1).) +C In either case, this parameter is passed as the NEQ +C argument in all calls to F and JAC. Hence, if it is an +C array, locations NEQ(2),... may be used to store other +C integer data and pass it to F and/or JAC. Subroutines +C F and/or JAC must include NEQ in a DIMENSION statement +C in that case. +C +C Y A real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on +C the first call (ISTATE = 1), and only for output on +C other calls. On the first call, Y must contain the +C vector of initial values. On output, Y contains the +C computed solution vector, evaluated at T. If desired, +C the Y array may be used for other purposes between +C calls to the solver. +C +C This array is passed as the Y argument in all calls to F +C and JAC. Hence its length may exceed NEQ, and locations +C Y(NEQ+1),... may be used to store other real data and +C pass it to F and/or JAC. (The DLSODE package accesses +C only Y(1),...,Y(NEQ).) +C +C T The independent variable. On input, T is used only on +C the first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution Y is evaluated (usually the same as +C TOUT). On an error return, T is the farthest point +C reached. +C +C TOUT The next value of T at which a computed solution is +C desired. Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should not equal T for the next +C call. For the initial T, an input value of TOUT .NE. T +C is used in order to determine the direction of the +C integration (i.e., the algebraic sign of the step sizes) +C and the rough scale of the problem. Integration in +C either direction (forward or backward in T) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored +C after the first call (i.e., the first call with +C TOUT .NE. T). Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR. (See "Optional Outputs" below for +C TCUR and HU.) +C +C +C ITOL An indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL A relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under +C ATOL. Input only. +C +C ATOL An absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine the +C error control performed by the solver. The solver will +C control the vector e = (e(i)) of estimated local errors +C in Y, according to an inequality of the form +C +C rms-norm of ( e(i)/EWT(i) ) <= 1, +C +C where +C +C EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C +C and the rms-norm (root-mean-square norm) here is +C +C rms-norm(v) = SQRT(sum v(i)**2 / NEQ). +C +C Here EWT = (EWT(i)) is a vector of weights which must +C always be positive, and the values of RTOL and ATOL +C should all be nonnegative. The following table gives the +C types (scalar/array) of RTOL and ATOL, and the +C corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C ---- ------ ------ ----------------------------- +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e., of EWT) should be +C scaled down uniformly. +C +C ITASK An index specifying the task to be performed. Input +C only. ITASK has the following values and meanings: +C 1 Normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 Take one step only and return. +C 3 Stop at the first internal mesh point at or beyond +C t = TOUT and return. +C 4 Normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. TCRIT +C must be input as RWORK(1). TCRIT may be equal to or +C beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 Take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before +C TCRIT, in which case answers at T = TOUT are returned +C first). +C +C ISTATE An index used for input and output to specify the state +C of the calculation. +C +C On input, the values of ISTATE are as follows: +C 1 This is the first call for the problem +C (initializations will be done). See "Note" below. +C 2 This is not the first call, and the calculation is to +C continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. (If ITOL, +C RTOL, and/or ATOL are changed between calls with +C ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 This is not the first call, and the calculation is to +C continue normally, but with a change in input +C parameters other than TOUT and ITASK. Changes are +C allowed in NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, +C ML, MU, and any of the optional inputs except H0. +C (See IWORK description for ML and MU.) +C +C Note: A preliminary call with TOUT = T is not counted as +C a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) Thus the +C first call for which TOUT .NE. T requires ISTATE = 1 on +C input. +C +C On output, ISTATE has the following values and meanings: +C 1 Nothing was done, as TOUT was equal to T with +C ISTATE = 1 on input. +C 2 The integration was performed successfully. +C -1 An excessive amount of work (more than MXSTEP steps) +C was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value >1 and call again (the +C excess work step counter will be reset to 0). In +C addition, the user may increase MXSTEP to avoid this +C error return; see "Optional Inputs" below. +C -2 Too much accuracy was requested for the precision of +C the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the +C tolerance parameters must be reset, and ISTATE must +C be set to 3. The optional output TOLSF may be used +C for this purpose. (Note: If this condition is +C detected before taking any steps, then an illegal +C input return (ISTATE = -3) occurs instead.) +C -3 Illegal input was detected, before taking any +C integration steps. See written message for details. +C (Note: If the solver detects an infinite loop of +C calls to the solver with illegal input, it will cause +C the run to stop.) +C -4 There were repeated error-test failures on one +C attempted step, before completing the requested task, +C but the integration was successful as far as T. The +C problem may have a singularity, or the input may be +C inappropriate. +C -5 There were repeated convergence-test failures on one +C attempted step, before completing the requested task, +C but the integration was successful as far as T. This +C may be caused by an inaccurate Jacobian matrix, if +C one is being used. +C -6 EWT(i) became zero for some i during the integration. +C Pure relative error control (ATOL(i)=0.0) was +C requested on a variable which has now vanished. The +C integration was successful as far as T. +C +C Note: Since the normal output value of ISTATE is 2, it +C does not need to be reset for normal continuation. Also, +C since a negative input value of ISTATE will be regarded +C as illegal, a negative output value requires the user to +C change it, and possibly other inputs, before calling the +C solver again. +C +C IOPT An integer flag to specify whether any optional inputs +C are being used on this call. Input only. The optional +C inputs are listed under a separate heading below. +C 0 No optional inputs are being used. Default values +C will be used in all cases. +C 1 One or more optional inputs are being used. +C +C RWORK A real working array (double precision). The length of +C RWORK must be at least +C +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM +C +C where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LWM = 0 if MITER = 0, +C LWM = NEQ**2 + 2 if MITER = 1 or 2, +C LWM = NEQ + 2 if MITER = 3, and +C LWM = (2*ML + MU + 1)*NEQ + 2 +C if MITER = 4 or 5. +C (See the MF description below for METH and MITER.) +C +C Thus if MAXORD has its default value and NEQ is constant, +C this length is: +C 20 + 16*NEQ for MF = 10, +C 22 + 16*NEQ + NEQ**2 for MF = 11 or 12, +C 22 + 17*NEQ for MF = 13, +C 22 + 17*NEQ + (2*ML + MU)*NEQ for MF = 14 or 15, +C 20 + 9*NEQ for MF = 20, +C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22, +C 22 + 10*NEQ for MF = 23, +C 22 + 10*NEQ + (2*ML + MU)*NEQ for MF = 24 or 25. +C +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT, the critical value of t which the +C solver is not to overshoot. Required if ITASK +C is 4 or 5, and ignored otherwise. See ITASK. +C +C LRW The length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK An integer work array. Its length must be at least +C 20 if MITER = 0 or 3 (MF = 10, 13, 20, 23), or +C 20 + NEQ otherwise (MF = 11, 12, 14, 15, 21, 22, 24, 25). +C (See the MF description below for MITER.) The first few +C words of IWORK are used for conditional and optional +C inputs and optional outputs. +C +C The following two words in IWORK are conditional inputs: +C IWORK(1) = ML These are the lower and upper half- +C IWORK(2) = MU bandwidths, respectively, of the banded +C Jacobian, excluding the main diagonal. +C The band is defined by the matrix locations +C (i,j) with i - ML <= j <= i + MU. ML and MU +C must satisfy 0 <= ML,MU <= NEQ - 1. These are +C required if MITER is 4 or 5, and ignored +C otherwise. ML and MU may in fact be the band +C parameters for a matrix to which df/dy is only +C approximately equal. +C +C LIW The length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODE +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODE between calls, if +C desired (but not for use by F or JAC). +C +C JAC The name of the user-supplied routine (MITER = 1 or 4) to +C compute the Jacobian matrix, df/dy, as a function of the +C scalar t and the vector y. (See the MF description below +C for MITER.) It is to have the form +C +C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) +C DOUBLE PRECISION T, Y(*), PD(NROWPD,*) +C +C where NEQ, T, Y, ML, MU, and NROWPD are input and the +C array PD is to be loaded with partial derivatives +C (elements of the Jacobian matrix) on output. PD must be +C given a first dimension of NROWPD. T and Y have the same +C meaning as in subroutine F. +C +C In the full matrix case (MITER = 1), ML and MU are +C ignored, and the Jacobian is to be loaded into PD in +C columnwise manner, with df(i)/dy(j) loaded into PD(i,j). +C +C In the band matrix case (MITER = 4), the elements within +C the band are to be loaded into PD in columnwise manner, +C with diagonal lines of df/dy loaded into the rows of PD. +C Thus df(i)/dy(j) is to be loaded into PD(i-j+MU+1,j). ML +C and MU are the half-bandwidth parameters (see IWORK). +C The locations in PD in the two triangular areas which +C correspond to nonexistent matrix elements can be ignored +C or loaded arbitrarily, as they are overwritten by DLSODE. +C +C JAC need not provide df/dy exactly. A crude approximation +C (possibly with a smaller bandwidth) will do. +C +C In either case, PD is preset to zero by the solver, so +C that only the nonzero elements need be loaded by JAC. +C Each call to JAC is preceded by a call to F with the same +C arguments NEQ, T, and Y. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may +C be saved in a user COMMON block by F and not recomputed +C by JAC, if desired. Also, JAC may alter the Y array, if +C desired. JAC must be declared EXTERNAL in the calling +C program. +C +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding +C NEQ(1). See the descriptions of NEQ and Y above. +C +C MF The method flag. Used only for input. The legal values +C of MF are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, +C and 25. MF has decimal digits METH and MITER: +C MF = 10*METH + MITER . +C +C METH indicates the basic linear multistep method: +C 1 Implicit Adams method. +C 2 Method based on backward differentiation formulas +C (BDF's). +C +C MITER indicates the corrector iteration method: +C 0 Functional iteration (no Jacobian matrix is +C involved). +C 1 Chord iteration with a user-supplied full (NEQ by +C NEQ) Jacobian. +C 2 Chord iteration with an internally generated +C (difference quotient) full Jacobian (using NEQ +C extra calls to F per df/dy value). +C 3 Chord iteration with an internally generated +C diagonal Jacobian approximation (using one extra call +C to F per df/dy evaluation). +C 4 Chord iteration with a user-supplied banded Jacobian. +C 5 Chord iteration with an internally generated banded +C Jacobian (using ML + MU + 1 extra calls to F per +C df/dy evaluation). +C +C If MITER = 1 or 4, the user must supply a subroutine JAC +C (the name is arbitrary) as described above under JAC. +C For other values of MITER, a dummy argument can be used. +C +C Optional Inputs +C --------------- +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that case +C all of these inputs are examined. A value of zero for any of +C these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, +C and then set those of interest to nonzero values. +C +C Name Location Meaning and default value +C ------ --------- ----------------------------------------------- +C H0 RWORK(5) Step size to be attempted on the first step. +C The default value is determined by the solver. +C HMAX RWORK(6) Maximum absolute step size allowed. The +C default value is infinite. +C HMIN RWORK(7) Minimum absolute step size allowed. The +C default value is 0. (This lower bound is not +C enforced on the final step before reaching +C TCRIT when ITASK = 4 or 5.) +C MAXORD IWORK(5) Maximum order to be allowed. The default value +C is 12 if METH = 1, and 5 if METH = 2. (See the +C MF description above for METH.) If MAXORD +C exceeds the default value, it will be reduced +C to the default value. If MAXORD is changed +C during the problem, it may cause the current +C order to be reduced. +C MXSTEP IWORK(6) Maximum number of (internally defined) steps +C allowed during one call to the solver. The +C default value is 500. +C MXHNIL IWORK(7) Maximum number of messages printed (per +C problem) warning that T + H = T on a step +C (H = step size). This must be positive to +C result in a nondefault value. The default +C value is 10. +C +C Optional Outputs +C ---------------- +C As optional additional output from DLSODE, the variables listed +C below are quantities related to the performance of DLSODE which +C are available to the user. These are communicated by way of the +C work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined on +C any successful return from DLSODE, and on any return with ISTATE = +C -1, -2, -4, -5, or -6. On an illegal input return (ISTATE = -3), +C they will be unchanged from their existing values (if any), except +C possibly for TOLSF, LENRW, and LENIW. On any error return, +C outputs relevant to the error will be defined, as noted below. +C +C Name Location Meaning +C ----- --------- ------------------------------------------------ +C HU RWORK(11) Step size in t last used (successfully). +C HCUR RWORK(12) Step size to be attempted on the next step. +C TCUR RWORK(13) Current value of the independent variable which +C the solver has actually reached, i.e., the +C current internal mesh point in t. On output, +C TCUR will always be at least as far as the +C argument T, but may be farther (if interpolation +C was done). +C TOLSF RWORK(14) Tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy +C was detected (ISTATE = -3 if detected at the +C start of the problem, ISTATE = -2 otherwise). +C If ITOL is left unaltered but RTOL and ATOL are +C uniformly scaled up by a factor of TOLSF for the +C next call, then the solver is deemed likely to +C succeed. (The user may also ignore TOLSF and +C alter the tolerance parameters in any other way +C appropriate.) +C NST IWORK(11) Number of steps taken for the problem so far. +C NFE IWORK(12) Number of F evaluations for the problem so far. +C NJE IWORK(13) Number of Jacobian evaluations (and of matrix LU +C decompositions) for the problem so far. +C NQU IWORK(14) Method order last used (successfully). +C NQCUR IWORK(15) Order to be attempted on the next step. +C IMXER IWORK(16) Index of the component of largest magnitude in +C the weighted local error vector ( e(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C LENRW IWORK(17) Length of RWORK actually required. This is +C defined on normal returns and on an illegal +C input return for insufficient storage. +C LENIW IWORK(18) Length of IWORK actually required. This is +C defined on normal returns and on an illegal +C input return for insufficient storage. +C +C The following two arrays are segments of the RWORK array which may +C also be of interest to the user as optional outputs. For each +C array, the table below gives its internal name, its base address +C in RWORK, and its description. +C +C Name Base address Description +C ---- ------------ ---------------------------------------------- +C YH 21 The Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value of +C NEQ. For j = 0,1,...,NQCUR, column j + 1 of +C YH contains HCUR**j/factorial(j) times the jth +C derivative of the interpolating polynomial +C currently representing the solution, evaluated +C at t = TCUR. +C ACOR LENRW-NEQ+1 Array of size NEQ used for the accumulated +C corrections on each step, scaled on output to +C represent the estimated local error in Y on +C the last step. This is the vector e in the +C description of the error control. It is +C defined only on successful return from DLSODE. +C +C +C Part 2. Other Callable Routines +C -------------------------------- +C +C The following are optional calls which the user may make to gain +C additional capabilities in conjunction with DLSODE. +C +C Form of call Function +C ------------------------ ---------------------------------------- +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODE, if the +C default is not desired. The default +C value of LUN is 6. This call may be made +C at any time and will take effect +C immediately. +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODE. MFLAG = 0 means do +C not print. (Danger: this risks losing +C valuable information.) MFLAG = 1 means +C print (the default). This call may be +C made at any time and will take effect +C immediately. +C CALL DSRCOM(RSAV,ISAV,JOB) Saves and restores the contents of the +C internal COMMON blocks used by DLSODE +C (see Part 3 below). RSAV must be a +C real array of length 218 or more, and +C ISAV must be an integer array of length +C 37 or more. JOB = 1 means save COMMON +C into RSAV/ISAV. JOB = 2 means restore +C COMMON from same. DSRCOM is useful if +C one is interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODE. +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after a +C successful return from DLSODE. Detailed +C instructions follow. +C +C Detailed instructions for using DINTDY +C -------------------------------------- +C The form of the CALL is: +C +C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T Value of independent variable where answers are +C desired (normally the same as the T last returned by +C DLSODE). For valid results, T must lie between +C TCUR - HU and TCUR. (See "Optional Outputs" above +C for TCUR and HU.) +C K Integer order of the derivative desired. K must +C satisfy 0 <= K <= NQCUR, where NQCUR is the current +C order (see "Optional Outputs"). The capability +C corresponding to K = 0, i.e., computing y(t), is +C already provided by DLSODE directly. Since +C NQCUR >= 1, the first derivative dy/dt is always +C available with DINTDY. +C RWORK(21) The base address of the history array YH. +C NYH Column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY Real array of length NEQ containing the computed value +C of the Kth derivative of y(t). +C IFLAG Integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C +C +C Part 3. Common Blocks +C ---------------------- +C +C If DLSODE is to be used in an overlay situation, the user must +C declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODE, +C (2) the internal COMMON block /DLS001/, of length 255 +C (218 double precision words followed by 37 integer words). +C +C If DLSODE is used on a system in which the contents of internal +C COMMON blocks are not preserved between calls, the user should +C declare the above COMMON block in his main program to insure that +C its contents are preserved. +C +C If the solution of a given problem by DLSODE is to be interrupted +C and then later continued, as when restarting an interrupted run or +C alternating between two or more problems, the user should save, +C following the return from the last DLSODE call prior to the +C interruption, the contents of the call sequence variables and the +C internal COMMON block, and later restore these values before the +C next DLSODE call for that problem. In addition, if XSETUN and/or +C XSETF was called for non-default handling of error messages, then +C these calls must be repeated. To save and restore the COMMON +C block, use subroutine DSRCOM (see Part 2 above). +C +C +C Part 4. Optionally Replaceable Solver Routines +C ----------------------------------------------- +C +C Below are descriptions of two routines in the DLSODE package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since +C such a replacement may have a major impact on performance, it +C should be done only when absolutely necessary, and only with great +C caution. (Note: The means by which the package version of a +C routine is superseded by the user's version may be system- +C dependent.) +C +C DEWSET +C ------ +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODE call +C sequence, YCUR contains the current dependent variable vector, +C and EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in Y(i) to. The EWT array returned by DEWSET is passed to the +C DVNORM routine (see below), and also used by DLSODE in the +C computation of the optional output IMXER, the diagonal Jacobian +C approximation, and the increments for difference quotient +C Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in SEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is unnecessary +C when NST = 0). +C +C DVNORM +C ------ +C DVNORM is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C +C d = DVNORM (n, v, w) +C +C where: +C n = the length of the vector, +C v = real array of length n containing the vector, +C w = real array of length n containing weights, +C d = SQRT( (1/n) * sum(v(i)*w(i))**2 ). +C +C DVNORM is called with n = NEQ and with w(i) = 1.0/EWT(i), where +C EWT is as set by subroutine DEWSET. +C +C If the user supplies this function, it should return a nonnegative +C value of DVNORM suitable for use in the error control in DLSODE. +C None of the arguments should be altered by DVNORM. For example, a +C user-supplied DVNORM routine might: +C - Substitute a max-norm of (v(i)*w(i)) for the rms-norm, or +C - Ignore some components of v in the norm, with the effect of +C suppressing the error control on those components of Y. +C --------------------------------------------------------------------- +C***ROUTINES CALLED DEWSET, DINTDY, DUMACH, DSTODE, DVNORM, XERRWD +C***COMMON BLOCKS DLS001 +C***REVISION HISTORY (YYYYMMDD) +C 19791129 DATE WRITTEN +C 19791213 Minor changes to declarations; DELP init. in STODE. +C 19800118 Treat NEQ as array; integer declarations added throughout; +C minor changes to prologue. +C 19800306 Corrected TESCO(1,NQP1) setting in CFODE. +C 19800519 Corrected access of YH on forced order reduction; +C numerous corrections to prologues and other comments. +C 19800617 In main driver, added loading of SQRT(UROUND) in RWORK; +C minor corrections to main prologue. +C 19800923 Added zero initialization of HU and NQU. +C 19801218 Revised XERRWD routine; minor corrections to main prologue. +C 19810401 Minor changes to comments and an error message. +C 19810814 Numerous revisions: replaced EWT by 1/EWT; used flags +C JCUR, ICF, IERPJ, IERSL between STODE and subordinates; +C added tuning parameters CCMAX, MAXCOR, MSBP, MXNCF; +C reorganized returns from STODE; reorganized type decls.; +C fixed message length in XERRWD; changed default LUNIT to 6; +C changed Common lengths; changed comments throughout. +C 19870330 Major update by ACH: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODE; +C in STODE, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 19890426 Modified prologue to SLATEC/LDOC format. (FNF) +C 19890501 Many improvements to prologue. (FNF) +C 19890503 A few final corrections to prologue. (FNF) +C 19890504 Minor cosmetic changes. (FNF) +C 19890510 Corrected description of Y in Arguments section. (FNF) +C 19890517 Minor corrections to prologue. (FNF) +C 19920514 Updated with prologue edited 891025 by G. Shaw for manual. +C 19920515 Converted source lines to upper case. (FNF) +C 19920603 Revised XERRWD calls using mixed upper-lower case. (ACH) +C 19920616 Revised prologue comment regarding CFT. (ACH) +C 19921116 Revised prologue comments regarding Common. (ACH). +C 19930326 Added comment about non-reentrancy. (FNF) +C 19930723 Changed D1MACH to DUMACH. (FNF) +C 19930801 Removed ILLIN and NTREP from Common (affects driver logic); +C minor changes to prologue and internal comments; +C changed Hollerith strings to quoted strings; +C changed internal comments to mixed case; +C replaced XERRWD with new version using character type; +C changed dummy dimensions from 1 to *. (ACH) +C 19930809 Changed to generic intrinsic names; changed names of +C subprograms and Common blocks to DLSODE etc. (ACH) +C 19930929 Eliminated use of REAL intrinsic; other minor changes. (ACH) +C 20010412 Removed all 'own' variables from Common block /DLS001/ +C (affects declarations in 6 routines). (ACH) +C 20010509 Minor corrections to prologue. (ACH) +C 20031105 Restored 'own' variables to Common block /DLS001/, to +C enable interrupt/restart feature. (ACH) +C 20031112 Added SAVE statements for data-loaded constants. +C +C***END PROLOGUE DLSODE +C +C*Internal Notes: +C +C Other Routines in the DLSODE Package. +C +C In addition to Subroutine DLSODE, the DLSODE package includes the +C following subroutines and function routines: +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODE is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPREPJ computes and preprocesses the Jacobian matrix J = df/dy +C and the Newton iteration matrix P = I - h*l0*J. +C DSOLSY manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted R.M.S. norm of a vector. +C DSRCOM is a user-callable routine to save and restore +C the contents of the internal Common block. +C DGEFA and DGESL are routines from LINPACK for solving full +C systems of linear algebraic equations. +C DGBFA and DGBSL are routines from LINPACK for solving banded +C linear systems. +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DUMACH, IXSAV, and IUMACH are function routines. +C All the others are subroutines. +C +C**End +C +C Declare externals. + EXTERNAL DPREPJ, DSOLSY + DOUBLE PRECISION DUMACH, DVNORM +C +C Declare all other variables. + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, I2, IFLAG, IMXER, KGO, LF0, + 1 LENIW, LENRW, LENWM, ML, MORD, MU, MXHNL0, MXSTP0 + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*80 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following internal Common block contains +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODE, DINTDY, DSTODE, +C DPREPJ, and DSOLSY. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .GT. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- +C +C***FIRST EXECUTABLE STATEMENT DLSODE + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C MF, ML, and MU. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + METH = MF/10 + MITER = MF - 10*METH + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 0 .OR. MITER .GT. 5) GO TO 608 + IF (MITER .LE. 3) GO TO 30 + ML = IWORK(1) + MU = IWORK(2) + IF (ML .LT. 0 .OR. ML .GE. N) GO TO 609 + IF (MU .LT. 0 .OR. MU .GE. N) GO TO 610 + 30 CONTINUE +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .EQ. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted YH, WM, EWT, SAVF, ACOR. +C----------------------------------------------------------------------- + 60 LYH = 21 + IF (ISTATE .EQ. 1) NYH = N + LWM = LYH + (MAXORD + 1)*NYH + IF (MITER .EQ. 0) LENWM = 0 + IF (MITER .EQ. 1 .OR. MITER .EQ. 2) LENWM = N*N + 2 + IF (MITER .EQ. 3) LENWM = N + 2 + IF (MITER .GE. 4) LENWM = (2*ML + MU + 1)*N + 2 + LEWT = LWM + LENWM + LSAVF = LEWT + N + LACOR = LSAVF + N + LENRW = LACOR + N - 1 + IWORK(17) = LENRW + LIWM = 1 + LENIW = 20 + N + IF (MITER .EQ. 0 .OR. MITER .EQ. 3) LENIW = 20 + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 70 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 70 CONTINUE + IF (ISTATE .EQ. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTODE. ------- + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 90 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into SAVF. --------- + DO 80 I = 1,N + 80 RWORK(I+LSAVF-1) = RWORK(I+LWM-1) +C Reload WM(1) = RWORK(LWM), since LWM may have changed. --------------- + 90 IF (MITER .GT. 0) RWORK(LWM) = SQRT(UROUND) + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 110 JSTART = 0 + IF (MITER .GT. 0) RWORK(LWM) = SQRT(UROUND) + NHNIL = 0 + NST = 0 + NJE = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load the initial value vector in YH. --------------------------------- + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 120 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(I)) +C if this is positive, or MAX(ATOL(I)/ABS(Y(I))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * SUM ( f(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C f(i) = i-th component of initial value of f, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 140 + DO 130 I = 1,N + 130 TOL = MAX(TOL,RTOL(I)) + 140 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LF0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODE. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODE- Warning..internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODE- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODE(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,IWM,F,JAC,DPREPJ,DSOLSY) +C----------------------------------------------------------------------- + CALL DSTODE (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), IWORK(LIWM), + 2 F, JAC, DPREPJ, DSOLSY) + KGO = 1 - KFLAG + GO TO (300, 530, 540), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODE. +C If ITASK .NE. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. The optional outputs +C are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODE- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(I) .LE. 0.0 for some I (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODE- At T (=R1), EWT(I1) has become R2 .LE. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODE- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. see TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODE- At T(=R1) and step size H(=R2), the error' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODE- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODE- ISTATE (=I1) illegal ' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODE- ITASK (=I1) illegal ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODE- ISTATE .GT. 1 but DLSODE not initialized ' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODE- NEQ (=I1) .LT. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODE- ISTATE = 3 and NEQ increased (I1 to I2) ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODE- ITOL (=I1) illegal ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODE- IOPT (=I1) illegal ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODE- MF (=I1) illegal ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSODE- ML (=I1) illegal.. .LT.0 or .GE.NEQ (=I2)' + CALL XERRWD (MSG, 50, 9, 0, 2, ML, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 610 MSG = 'DLSODE- MU (=I1) illegal.. .LT.0 or .GE.NEQ (=I2)' + CALL XERRWD (MSG, 50, 10, 0, 2, MU, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODE- MAXORD (=I1) .LT. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODE- MXSTEP (=I1) .LT. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODE- MXHNIL (=I1) .LT. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODE- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODE- HMAX (=R1) .LT. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODE- HMIN (=R1) .LT. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 CONTINUE + MSG='DLSODE- RWORK length needed, LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 CONTINUE + MSG='DLSODE- IWORK length needed, LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODE- RTOL(I1) is R1 .LT. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODE- ATOL(I1) is R1 .LT. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODE- EWT(I1) is R1 .LE. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 CONTINUE + MSG='DLSODE- TOUT (=R1) too close to T(=R2) to start integration' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 CONTINUE + MSG='DLSODE- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 CONTINUE + MSG='DLSODE- ITASK = 4 OR 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 CONTINUE + MSG='DLSODE- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODE- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODE- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODE- Run aborted.. apparent infinite loop ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- END OF SUBROUTINE DLSODE ---------------------- + END +*DECK DLSODES + SUBROUTINE DLSODES (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF) + EXTERNAL F, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 12 November 2003 version of +C DLSODES: Livermore Solver for Ordinary Differential Equations +C with general Sparse Jacobian matrix. +C +C This version is in double precision. +C +C DLSODES solves the initial value problem for stiff or nonstiff +C systems of first order ODEs, +C dy/dt = f(t,y) , or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ). +C DLSODES is a variant of the DLSODE package, and is intended for +C problems in which the Jacobian matrix df/dy has an arbitrary +C sparse structure (when the problem is stiff). +C +C Authors: Alan C. Hindmarsh +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C and +C Andrew H. Sherman +C J. S. Nolen and Associates +C Houston, TX 77084 +C----------------------------------------------------------------------- +C References: +C 1. Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C +C 2. S. C. Eisenstat, M. C. Gursky, M. H. Schultz, and A. H. Sherman, +C Yale Sparse Matrix Package: I. The Symmetric Codes, +C Int. J. Num. Meth. Eng., 18 (1982), pp. 1145-1151. +C +C 3. S. C. Eisenstat, M. C. Gursky, M. H. Schultz, and A. H. Sherman, +C Yale Sparse Matrix Package: II. The Nonsymmetric Codes, +C Research Report No. 114, Dept. of Computer Sciences, Yale +C University, 1977. +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODES package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First provide a subroutine of the form: +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C which supplies the vector function f by loading YDOT(i) with f(i). +C +C B. Next determine (or guess) whether or not the problem is stiff. +C Stiffness occurs when the Jacobian matrix df/dy has an eigenvalue +C whose real part is negative and large in magnitude, compared to the +C reciprocal of the t span of interest. If the problem is nonstiff, +C use a method flag MF = 10. If it is stiff, there are two standard +C choices for the method flag, MF = 121 and MF = 222. In both cases, +C DLSODES requires the Jacobian matrix in some form, and it treats this +C matrix in general sparse form, with sparsity structure determined +C internally. (For options where the user supplies the sparsity +C structure, see the full description of MF below.) +C +C C. If the problem is stiff, you are encouraged to supply the Jacobian +C directly (MF = 121), but if this is not feasible, DLSODES will +C compute it internally by difference quotients (MF = 222). +C If you are supplying the Jacobian, provide a subroutine of the form: +C SUBROUTINE JAC (NEQ, T, Y, J, IAN, JAN, PDJ) +C DOUBLE PRECISION T, Y(*), IAN(*), JAN(*), PDJ(*) +C Here NEQ, T, Y, and J are input arguments, and the JAC routine is to +C load the array PDJ (of length NEQ) with the J-th column of df/dy. +C I.e., load PDJ(i) with df(i)/dy(J) for all relevant values of i. +C The arguments IAN and JAN should be ignored for normal situations. +C DLSODES will call the JAC routine with J = 1,2,...,NEQ. +C Only nonzero elements need be loaded. Usually, a crude approximation +C to df/dy, possibly with fewer nonzero elements, will suffice. +C +C D. Write a main program which calls Subroutine DLSODES once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages by +C DLSODES. On the first call to DLSODES, supply arguments as follows: +C F = name of subroutine for right-hand side vector f. +C This name must be declared External in calling program. +C NEQ = number of first order ODEs. +C Y = array of initial values, of length NEQ. +C T = the initial value of the independent variable t. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C The estimated local error in Y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of Y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 20 + 16*NEQ for MF = 10, +C 20 + (2 + 1./LENRAT)*NNZ + (11 + 9./LENRAT)*NEQ +C for MF = 121 or 222, +C where: +C NNZ = the number of nonzero elements in the sparse +C Jacobian (if this is unknown, use an estimate), and +C LENRAT = the real to integer wordlength ratio (usually 1 in +C single precision and 2 in double precision). +C In any case, the required size of RWORK cannot generally +C be predicted in advance if MF = 121 or 222, and the value +C above is a rough estimate of a crude lower bound. Some +C experimentation with this size may be necessary. +C (When known, the correct required length is an optional +C output, available in IWORK(17).) +C LRW = declared length of RWORK (in user dimension). +C IWORK = integer work array of length at least 30. +C LIW = declared length of IWORK (in user dimension). +C JAC = name of subroutine for Jacobian matrix (MF = 121). +C If used, this name must be declared External in calling +C program. If not used, pass a dummy name. +C MF = method flag. Standard values are: +C 10 for nonstiff (Adams) method, no Jacobian used +C 121 for stiff (BDF) method, user-supplied sparse Jacobian +C 222 for stiff method, internally generated sparse Jacobian +C Note that the main program must declare arrays Y, RWORK, IWORK, +C and possibly ATOL. +C +C E. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSODES was successful, negative otherwise. +C -1 means excess work done on this call (perhaps wrong MF). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of MF or tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 means a fatal error return flag came from sparse solver +C CDRV by way of DPRJS or DSOLSS. Should never happen. +C A return with ISTATE = -1, -4, or -5 may result from using +C an inappropriate sparsity structure, one that is quite +C different from the initial structure. Consider calling +C DLSODES again with ISTATE = 3 to force the structure to be +C reevaluated. See the full description of ISTATE below. +C +C F. To continue the integration after a successful return, simply +C reset TOUT and call DLSODES again. No other parameters need be reset. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is a simple example problem, with the coding +C needed for its solution by DLSODES. The problem is from chemical +C kinetics, and consists of the following 12 rate equations: +C dy1/dt = -rk1*y1 +C dy2/dt = rk1*y1 + rk11*rk14*y4 + rk19*rk14*y5 +C - rk3*y2*y3 - rk15*y2*y12 - rk2*y2 +C dy3/dt = rk2*y2 - rk5*y3 - rk3*y2*y3 - rk7*y10*y3 +C + rk11*rk14*y4 + rk12*rk14*y6 +C dy4/dt = rk3*y2*y3 - rk11*rk14*y4 - rk4*y4 +C dy5/dt = rk15*y2*y12 - rk19*rk14*y5 - rk16*y5 +C dy6/dt = rk7*y10*y3 - rk12*rk14*y6 - rk8*y6 +C dy7/dt = rk17*y10*y12 - rk20*rk14*y7 - rk18*y7 +C dy8/dt = rk9*y10 - rk13*rk14*y8 - rk10*y8 +C dy9/dt = rk4*y4 + rk16*y5 + rk8*y6 + rk18*y7 +C dy10/dt = rk5*y3 + rk12*rk14*y6 + rk20*rk14*y7 +C + rk13*rk14*y8 - rk7*y10*y3 - rk17*y10*y12 +C - rk6*y10 - rk9*y10 +C dy11/dt = rk10*y8 +C dy12/dt = rk6*y10 + rk19*rk14*y5 + rk20*rk14*y7 +C - rk15*y2*y12 - rk17*y10*y12 +C +C with rk1 = rk5 = 0.1, rk4 = rk8 = rk16 = rk18 = 2.5, +C rk10 = 5.0, rk2 = rk6 = 10.0, rk14 = 30.0, +C rk3 = rk7 = rk9 = rk11 = rk12 = rk13 = rk19 = rk20 = 50.0, +C rk15 = rk17 = 100.0. +C +C The t interval is from 0 to 1000, and the initial conditions +C are y1 = 1, y2 = y3 = ... = y12 = 0. The problem is stiff. +C +C The following coding solves this problem with DLSODES, using MF = 121 +C and printing results at t = .1, 1., 10., 100., 1000. It uses +C ITOL = 1 and mixed relative/absolute tolerance controls. +C During the run and at the end, statistical quantities of interest +C are printed (see optional outputs in the full description below). +C +C EXTERNAL FEX, JEX +C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y +C DIMENSION Y(12), RWORK(500), IWORK(30) +C DATA LRW/500/, LIW/30/ +C NEQ = 12 +C DO 10 I = 1,NEQ +C 10 Y(I) = 0.0D0 +C Y(1) = 1.0D0 +C T = 0.0D0 +C TOUT = 0.1D0 +C ITOL = 1 +C RTOL = 1.0D-4 +C ATOL = 1.0D-6 +C ITASK = 1 +C ISTATE = 1 +C IOPT = 0 +C MF = 121 +C DO 40 IOUT = 1,5 +C CALL DLSODES (FEX, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, +C 1 ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JEX, MF) +C WRITE(6,30)T,IWORK(11),RWORK(11),(Y(I),I=1,NEQ) +C 30 FORMAT(//' At t =',D11.3,4X, +C 1 ' No. steps =',I5,4X,' Last step =',D11.3/ +C 2 ' Y array = ',4D14.5/13X,4D14.5/13X,4D14.5) +C IF (ISTATE .LT. 0) GO TO 80 +C TOUT = TOUT*10.0D0 +C 40 CONTINUE +C LENRW = IWORK(17) +C LENIW = IWORK(18) +C NST = IWORK(11) +C NFE = IWORK(12) +C NJE = IWORK(13) +C NLU = IWORK(21) +C NNZ = IWORK(19) +C NNZLU = IWORK(25) + IWORK(26) + NEQ +C WRITE (6,70) LENRW,LENIW,NST,NFE,NJE,NLU,NNZ,NNZLU +C 70 FORMAT(//' Required RWORK size =',I4,' IWORK size =',I4/ +C 1 ' No. steps =',I4,' No. f-s =',I4,' No. J-s =',I4, +C 2 ' No. LU-s =',I4/' No. of nonzeros in J =',I5, +C 3 ' No. of nonzeros in LU =',I5) +C STOP +C 80 WRITE(6,90)ISTATE +C 90 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE FEX (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y, YDOT +C DOUBLE PRECISION RK1, RK2, RK3, RK4, RK5, RK6, RK7, RK8, RK9, +C 1 RK10, RK11, RK12, RK13, RK14, RK15, RK16, RK17 +C DIMENSION Y(12), YDOT(12) +C DATA RK1/0.1D0/, RK2/10.0D0/, RK3/50.0D0/, RK4/2.5D0/, RK5/0.1D0/, +C 1 RK6/10.0D0/, RK7/50.0D0/, RK8/2.5D0/, RK9/50.0D0/, RK10/5.0D0/, +C 2 RK11/50.0D0/, RK12/50.0D0/, RK13/50.0D0/, RK14/30.0D0/, +C 3 RK15/100.0D0/, RK16/2.5D0/, RK17/100.0D0/, RK18/2.5D0/, +C 4 RK19/50.0D0/, RK20/50.0D0/ +C YDOT(1) = -RK1*Y(1) +C YDOT(2) = RK1*Y(1) + RK11*RK14*Y(4) + RK19*RK14*Y(5) +C 1 - RK3*Y(2)*Y(3) - RK15*Y(2)*Y(12) - RK2*Y(2) +C YDOT(3) = RK2*Y(2) - RK5*Y(3) - RK3*Y(2)*Y(3) - RK7*Y(10)*Y(3) +C 1 + RK11*RK14*Y(4) + RK12*RK14*Y(6) +C YDOT(4) = RK3*Y(2)*Y(3) - RK11*RK14*Y(4) - RK4*Y(4) +C YDOT(5) = RK15*Y(2)*Y(12) - RK19*RK14*Y(5) - RK16*Y(5) +C YDOT(6) = RK7*Y(10)*Y(3) - RK12*RK14*Y(6) - RK8*Y(6) +C YDOT(7) = RK17*Y(10)*Y(12) - RK20*RK14*Y(7) - RK18*Y(7) +C YDOT(8) = RK9*Y(10) - RK13*RK14*Y(8) - RK10*Y(8) +C YDOT(9) = RK4*Y(4) + RK16*Y(5) + RK8*Y(6) + RK18*Y(7) +C YDOT(10) = RK5*Y(3) + RK12*RK14*Y(6) + RK20*RK14*Y(7) +C 1 + RK13*RK14*Y(8) - RK7*Y(10)*Y(3) - RK17*Y(10)*Y(12) +C 2 - RK6*Y(10) - RK9*Y(10) +C YDOT(11) = RK10*Y(8) +C YDOT(12) = RK6*Y(10) + RK19*RK14*Y(5) + RK20*RK14*Y(7) +C 1 - RK15*Y(2)*Y(12) - RK17*Y(10)*Y(12) +C RETURN +C END +C +C SUBROUTINE JEX (NEQ, T, Y, J, IA, JA, PDJ) +C DOUBLE PRECISION T, Y, PDJ +C DOUBLE PRECISION RK1, RK2, RK3, RK4, RK5, RK6, RK7, RK8, RK9, +C 1 RK10, RK11, RK12, RK13, RK14, RK15, RK16, RK17 +C DIMENSION Y(12), IA(*), JA(*), PDJ(12) +C DATA RK1/0.1D0/, RK2/10.0D0/, RK3/50.0D0/, RK4/2.5D0/, RK5/0.1D0/, +C 1 RK6/10.0D0/, RK7/50.0D0/, RK8/2.5D0/, RK9/50.0D0/, RK10/5.0D0/, +C 2 RK11/50.0D0/, RK12/50.0D0/, RK13/50.0D0/, RK14/30.0D0/, +C 3 RK15/100.0D0/, RK16/2.5D0/, RK17/100.0D0/, RK18/2.5D0/, +C 4 RK19/50.0D0/, RK20/50.0D0/ +C GO TO (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), J +C 1 PDJ(1) = -RK1 +C PDJ(2) = RK1 +C RETURN +C 2 PDJ(2) = -RK3*Y(3) - RK15*Y(12) - RK2 +C PDJ(3) = RK2 - RK3*Y(3) +C PDJ(4) = RK3*Y(3) +C PDJ(5) = RK15*Y(12) +C PDJ(12) = -RK15*Y(12) +C RETURN +C 3 PDJ(2) = -RK3*Y(2) +C PDJ(3) = -RK5 - RK3*Y(2) - RK7*Y(10) +C PDJ(4) = RK3*Y(2) +C PDJ(6) = RK7*Y(10) +C PDJ(10) = RK5 - RK7*Y(10) +C RETURN +C 4 PDJ(2) = RK11*RK14 +C PDJ(3) = RK11*RK14 +C PDJ(4) = -RK11*RK14 - RK4 +C PDJ(9) = RK4 +C RETURN +C 5 PDJ(2) = RK19*RK14 +C PDJ(5) = -RK19*RK14 - RK16 +C PDJ(9) = RK16 +C PDJ(12) = RK19*RK14 +C RETURN +C 6 PDJ(3) = RK12*RK14 +C PDJ(6) = -RK12*RK14 - RK8 +C PDJ(9) = RK8 +C PDJ(10) = RK12*RK14 +C RETURN +C 7 PDJ(7) = -RK20*RK14 - RK18 +C PDJ(9) = RK18 +C PDJ(10) = RK20*RK14 +C PDJ(12) = RK20*RK14 +C RETURN +C 8 PDJ(8) = -RK13*RK14 - RK10 +C PDJ(10) = RK13*RK14 +C PDJ(11) = RK10 +C 9 RETURN +C 10 PDJ(3) = -RK7*Y(3) +C PDJ(6) = RK7*Y(3) +C PDJ(7) = RK17*Y(12) +C PDJ(8) = RK9 +C PDJ(10) = -RK7*Y(3) - RK17*Y(12) - RK6 - RK9 +C PDJ(12) = RK6 - RK17*Y(12) +C 11 RETURN +C 12 PDJ(2) = -RK15*Y(2) +C PDJ(5) = RK15*Y(2) +C PDJ(7) = RK17*Y(10) +C PDJ(10) = -RK17*Y(10) +C PDJ(12) = -RK15*Y(2) - RK17*Y(10) +C RETURN +C END +C +C The output of this program (on a Cray-1 in single precision) +C is as follows: +C +C +C At t = 1.000e-01 No. steps = 12 Last step = 1.515e-02 +C Y array = 9.90050e-01 6.28228e-03 3.65313e-03 7.51934e-07 +C 1.12167e-09 1.18458e-09 1.77291e-12 3.26476e-07 +C 5.46720e-08 9.99500e-06 4.48483e-08 2.76398e-06 +C +C +C At t = 1.000e+00 No. steps = 33 Last step = 7.880e-02 +C Y array = 9.04837e-01 9.13105e-03 8.20622e-02 2.49177e-05 +C 1.85055e-06 1.96797e-06 1.46157e-07 2.39557e-05 +C 3.26306e-05 7.21621e-04 5.06433e-05 3.05010e-03 +C +C +C At t = 1.000e+01 No. steps = 48 Last step = 1.239e+00 +C Y array = 3.67876e-01 3.68958e-03 3.65133e-01 4.48325e-05 +C 6.10798e-05 4.33148e-05 5.90211e-05 1.18449e-04 +C 3.15235e-03 3.56531e-03 4.15520e-03 2.48741e-01 +C +C +C At t = 1.000e+02 No. steps = 91 Last step = 3.764e+00 +C Y array = 4.44981e-05 4.42666e-07 4.47273e-04 -3.53257e-11 +C 2.81577e-08 -9.67741e-11 2.77615e-07 1.45322e-07 +C 1.56230e-02 4.37394e-06 1.60104e-02 9.52246e-01 +C +C +C At t = 1.000e+03 No. steps = 111 Last step = 4.156e+02 +C Y array = -2.65492e-13 2.60539e-14 -8.59563e-12 6.29355e-14 +C -1.78066e-13 5.71471e-13 -1.47561e-12 4.58078e-15 +C 1.56314e-02 1.37878e-13 1.60184e-02 9.52719e-01 +C +C +C Required RWORK size = 442 IWORK size = 30 +C No. steps = 111 No. f-s = 142 No. J-s = 2 No. LU-s = 20 +C No. of nonzeros in J = 44 No. of nonzeros in LU = 50 +C +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODES. +C +C The user interface to DLSODES consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODES, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODES package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODES package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, MF, +C and those used for both input and output are +C Y, T, ISTATE. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODES to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F = the name of the user-supplied subroutine defining the +C ODE system. The system must be put in the first-order +C form dy/dt = f(t,y), where f is a vector-valued function +C of the scalar t and the vector y. Subroutine F is to +C compute the function f. It is to have the form +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C where NEQ, T, and Y are input, and the array YDOT = f(t,y) +C is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter y(1),...,y(NEQ). +C F must be declared External in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODES, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY instead. +C +C NEQ = the size of the ODE system (number of first order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in F and/or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODES package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to F and JAC. Hence, if it is an array, locations +C NEQ(2),... may be used to store other integer data and pass +C it to F and/or JAC. Subroutines F and/or JAC must include +C NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 1), and only for output on other calls. +C on the first call, Y must contain the vector of initial +C values. On output, Y contains the computed solution vector, +C evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to +C F and JAC. Hence its length may exceed NEQ, and locations +C Y(NEQ+1),... may be used to store other real data and +C pass it to F and/or JAC. (The DLSODES package accesses only +C Y(1),...,Y(NEQ).) +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C on output, after each call, T is the value at which a +C computed solution Y is evaluated (usually the same as TOUT). +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should .ne. T for the next call. +C For the initial T, an input value of TOUT .ne. T is used +C in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C the state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 1 means this is the first call for the problem +C (initializations will be done). See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, +C the conditional inputs IA and JA, +C and any of the optional inputs except H0. +C In particular, if MITER = 1 or 2, a call with ISTATE = 3 +C will cause the sparsity structure of the problem to be +C recomputed (or reread from IA and JA if MOSS = 0). +C Note: a preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 1 means nothing was done; TOUT = T and ISTATE = 1 on input. +C 2 means the integration was performed successfully. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix, +C if one is being used. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means a fatal error return flag came from the sparse +C solver CDRV by way of DPRJS or DSOLSS (numerical +C factorization or backsolve). This should never happen. +C The integration was successful as far as T. +C +C Note: an error return with ISTATE = -1, -4, or -5 and with +C MITER = 1 or 2 may mean that the sparsity structure of the +C problem has changed significantly since it was last +C determined (or input). In that case, one can attempt to +C complete the integration by setting ISTATE = 3 on the next +C call, so that a new structure determination is done. +C +C Note: since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a work array used for a mixture of real (double precision) +C and integer work space. +C The length of RWORK (in real words) must be at least +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LWM = 0 if MITER = 0, +C LWM = 2*NNZ + 2*NEQ + (NNZ+9*NEQ)/LENRAT if MITER = 1, +C LWM = 2*NNZ + 2*NEQ + (NNZ+10*NEQ)/LENRAT if MITER = 2, +C LWM = NEQ + 2 if MITER = 3. +C In the above formulas, +C NNZ = number of nonzero elements in the Jacobian matrix. +C LENRAT = the real to integer wordlength ratio (usually 1 in +C single precision and 2 in double precision). +C (See the MF description for METH and MITER.) +C Thus if MAXORD has its default value and NEQ is constant, +C the minimum length of RWORK is: +C 20 + 16*NEQ for MF = 10, +C 20 + 16*NEQ + LWM for MF = 11, 111, 211, 12, 112, 212, +C 22 + 17*NEQ for MF = 13, +C 20 + 9*NEQ for MF = 20, +C 20 + 9*NEQ + LWM for MF = 21, 121, 221, 22, 122, 222, +C 22 + 10*NEQ for MF = 23. +C If MITER = 1 or 2, the above formula for LWM is only a +C crude lower bound. The required length of RWORK cannot +C be readily predicted in general, as it depends on the +C sparsity structure of the problem. Some experimentation +C may be necessary. +C +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 31 + NEQ + NNZ if MOSS = 0 and MITER = 1 or 2, or +C 30 otherwise. +C (NNZ is the number of nonzero elements in df/dy.) +C +C In DLSODES, IWORK is used only for conditional and +C optional inputs and optional outputs. +C +C The following two blocks of words in IWORK are conditional +C inputs, required if MOSS = 0 and MITER = 1 or 2, but not +C otherwise (see the description of MF for MOSS). +C IWORK(30+j) = IA(j) (j=1,...,NEQ+1) +C IWORK(31+NEQ+k) = JA(k) (k=1,...,NNZ) +C The two arrays IA and JA describe the sparsity structure +C to be assumed for the Jacobian matrix. JA contains the row +C indices where nonzero elements occur, reading in columnwise +C order, and IA contains the starting locations in JA of the +C descriptions of columns 1,...,NEQ, in that order, with +C IA(1) = 1. Thus, for each column index j = 1,...,NEQ, the +C values of the row index i in column j where a nonzero +C element may occur are given by +C i = JA(k), where IA(j) .le. k .lt. IA(j+1). +C If NNZ is the total number of nonzero locations assumed, +C then the length of the JA array is NNZ, and IA(NEQ+1) must +C be NNZ + 1. Duplicate entries are not allowed. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODES +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODES between calls, if +C desired (but not for use by F or JAC). +C +C JAC = name of user-supplied routine (MITER = 1 or MOSS = 1) to +C compute the Jacobian matrix, df/dy, as a function of +C the scalar t and the vector y. It is to have the form +C SUBROUTINE JAC (NEQ, T, Y, J, IAN, JAN, PDJ) +C DOUBLE PRECISION T, Y(*), IAN(*), JAN(*), PDJ(*) +C where NEQ, T, Y, J, IAN, and JAN are input, and the array +C PDJ, of length NEQ, is to be loaded with column J +C of the Jacobian on output. Thus df(i)/dy(J) is to be +C loaded into PDJ(i) for all relevant values of i. +C Here T and Y have the same meaning as in Subroutine F, +C and J is a column index (1 to NEQ). IAN and JAN are +C undefined in calls to JAC for structure determination +C (MOSS = 1). otherwise, IAN and JAN are structure +C descriptors, as defined under optional outputs below, and +C so can be used to determine the relevant row indices i, if +C desired. +C JAC need not provide df/dy exactly. A crude +C approximation (possibly with greater sparsity) will do. +C In any case, PDJ is preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Calls to JAC are made with J = 1,...,NEQ, in that order, and +C each such set of calls is preceded by a call to F with the +C same arguments NEQ, T, and Y. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may be +C saved in a user Common block by F and not recomputed by JAC, +C if desired. JAC must not alter its input arguments. +C JAC must be declared External in the calling program. +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C MF = the method flag. Used only for input. +C MF has three decimal digits-- MOSS, METH, MITER-- +C MF = 100*MOSS + 10*METH + MITER. +C MOSS indicates the method to be used to obtain the sparsity +C structure of the Jacobian matrix if MITER = 1 or 2: +C MOSS = 0 means the user has supplied IA and JA +C (see descriptions under IWORK above). +C MOSS = 1 means the user has supplied JAC (see below) +C and the structure will be obtained from NEQ +C initial calls to JAC. +C MOSS = 2 means the structure will be obtained from NEQ+1 +C initial calls to F. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFs). +C MITER indicates the corrector iteration method: +C MITER = 0 means functional iteration (no Jacobian matrix +C is involved). +C MITER = 1 means chord iteration with a user-supplied +C sparse Jacobian, given by Subroutine JAC. +C MITER = 2 means chord iteration with an internally +C generated (difference quotient) sparse Jacobian +C (using NGP extra calls to F per df/dy value, +C where NGP is an optional output described below.) +C MITER = 3 means chord iteration with an internally +C generated diagonal Jacobian approximation +C (using 1 extra call to F per df/dy evaluation). +C If MITER = 1 or MOSS = 1, the user must supply a Subroutine +C JAC (the name is arbitrary) as described above under JAC. +C Otherwise, a dummy argument can be used. +C +C The standard choices for MF are: +C MF = 10 for a nonstiff problem, +C MF = 21 or 22 for a stiff problem with IA/JA supplied +C (21 if JAC is supplied, 22 if not), +C MF = 121 for a stiff problem with JAC supplied, +C but not IA/JA, +C MF = 222 for a stiff problem with neither IA/JA nor +C JAC supplied. +C The sparseness structure can be changed during the +C problem by making a call to DLSODES with ISTATE = 3. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C SETH RWORK(8) the element threshhold for sparsity determination +C when MOSS = 1 or 2. If the absolute value of +C an estimated Jacobian element is .le. SETH, it +C will be assumed to be absent in the structure. +C The default value of SETH is 0. +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODES, the variables listed +C below are quantities related to the performance of DLSODES +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODES, and on any return with +C ISTATE = -1, -2, -4, -5, or -6. On an illegal input return +C (ISTATE = -3), they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NFE IWORK(12) the number of f evaluations for the problem so far, +C excluding those for structure determination +C (MOSS = 2). +C +C NJE IWORK(13) the number of Jacobian evaluations for the problem +C so far, excluding those for structure determination +C (MOSS = 1). +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C NNZ IWORK(19) the number of nonzero elements in the Jacobian +C matrix, including the diagonal (MITER = 1 or 2). +C (This may differ from that given by IA(NEQ+1)-1 +C if MOSS = 0, because of added diagonal entries.) +C +C NGP IWORK(20) the number of groups of column indices, used in +C difference quotient Jacobian aproximations if +C MITER = 2. This is also the number of extra f +C evaluations needed for each Jacobian evaluation. +C +C NLU IWORK(21) the number of sparse LU decompositions for the +C problem so far. +C +C LYH IWORK(22) the base address in RWORK of the history array YH, +C described below in this list. +C +C IPIAN IWORK(23) the base address of the structure descriptor array +C IAN, described below in this list. +C +C IPJAN IWORK(24) the base address of the structure descriptor array +C JAN, described below in this list. +C +C NZL IWORK(25) the number of nonzero elements in the strict lower +C triangle of the LU factorization used in the chord +C iteration (MITER = 1 or 2). +C +C NZU IWORK(26) the number of nonzero elements in the strict upper +C triangle of the LU factorization used in the chord +C iteration (MITER = 1 or 2). +C The total number of nonzeros in the factorization +C is therefore NZL + NZU + NEQ. +C +C The following four arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address, and its description. +C For YH and ACOR, the base addresses are in RWORK (a real array). +C The integer arrays IAN and JAN are to be obtained by declaring an +C integer array IWK and identifying IWK(1) with RWORK(21), using either +C an equivalence statement or a subroutine call. Then the base +C addresses IPIAN (of IAN) and IPJAN (of JAN) in IWK are to be obtained +C as optional outputs IWORK(23) and IWORK(24), respectively. +C Thus IAN(1) is IWK(IPIAN), etc. +C +C Name Base Address Description +C +C IAN IPIAN (in IWK) structure descriptor array of size NEQ + 1. +C JAN IPJAN (in IWK) structure descriptor array of size NNZ. +C (see above) IAN and JAN together describe the sparsity +C structure of the Jacobian matrix, as used by +C DLSODES when MITER = 1 or 2. +C JAN contains the row indices of the nonzero +C locations, reading in columnwise order, and +C IAN contains the starting locations in JAN of +C the descriptions of columns 1,...,NEQ, in +C that order, with IAN(1) = 1. Thus for each +C j = 1,...,NEQ, the row indices i of the +C nonzero locations in column j are +C i = JAN(k), IAN(j) .le. k .lt. IAN(j+1). +C Note that IAN(NEQ+1) = NNZ + 1. +C (If MOSS = 0, IAN/JAN may differ from the +C input IA/JA because of a different ordering +C in each column, and added diagonal entries.) +C +C YH LYH the Nordsieck history array, of size NYH by +C (optional (NQCUR + 1), where NYH is the initial value +C output) of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. The base address LYH +C is another optional output, listed above. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output +C to represent the estimated local error in y +C on the last step. This is the vector E in +C the description of the error control. It is +C defined only on a successful return from +C DLSODES. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODES. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODES, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODES. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCMS(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODES (see Part 3 below). +C RSAV must be a real array of length 224 +C or more, and ISAV must be an integer +C array of length 71 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCMS is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODES. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODES. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C LYH = IWORK(22) +C CALL DINTDY (T, K, RWORK(LYH), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODES). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (See optional outputs). The capability corresponding +C to K = 0, i.e. computing y(T), is already provided +C by DLSODES directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C LYH = the base address of the history array YH, obtained +C as an optional output as shown above. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODES is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODES, and +C (2) the two internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLSS01/ of length 40 (6 double precision words +C followed by 34 integer words), +C +C If DLSODES is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODES is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODES call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODES call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCMS (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below are descriptions of two routines in the DLSODES package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C Subroutine DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODES call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSODES in the computation +C of the optional output IMXER, the diagonal Jacobian approximation, +C and the increments for difference quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSODES. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*W(i)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19810120 DATE WRITTEN +C 19820315 Upgraded MDI in ODRV package: operates on M + M-transpose. +C 19820426 Numerous revisions in use of work arrays; +C use wordlength ratio LENRAT; added IPISP & LRAT to Common; +C added optional outputs IPIAN/IPJAN; +C numerous corrections to comments. +C 19830503 Added routine CNTNZU; added NZL and NZU to /LSS001/; +C changed ADJLR call logic; added optional outputs NZL & NZU; +C revised counter initializations; revised PREP stmt. numbers; +C corrections to comments throughout. +C 19870320 Corrected jump on test of umax in CDRV routine; +C added ISTATE = -7 return. +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODE; +C in STODE, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C converted arithmetic IF statements to logical IF statements; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODES package. +C +C In addition to Subroutine DLSODES, the DLSODES package includes the +C following subroutines and function routines: +C DIPREP acts as an iterface between DLSODES and DPREP, and also does +C adjusting of work space pointers and work arrays. +C DPREP is called by DIPREP to compute sparsity and do sparse matrix +C preprocessing if MITER = 1 or 2. +C JGROUP is called by DPREP to compute groups of Jacobian column +C indices for use when MITER = 2. +C ADJLR adjusts the length of required sparse matrix work space. +C It is called by DPREP. +C CNTNZU is called by DPREP and counts the nonzero elements in the +C strict upper triangle of J + J-transpose, where J = df/dy. +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODE is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPRJS computes and preprocesses the Jacobian matrix J = df/dy +C and the Newton iteration matrix P = I - h*l0*J. +C DSOLSS manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSRCMS is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C ODRV constructs a reordering of the rows and columns of +C a matrix by the minimum degree algorithm. ODRV is a +C driver routine which calls Subroutines MD, MDI, MDM, +C MDP, MDU, and SRO. See Ref. 2 for details. (The ODRV +C module has been modified since Ref. 2, however.) +C CDRV performs reordering, symbolic factorization, numerical +C factorization, or linear system solution operations, +C depending on a path argument ipath. CDRV is a +C driver routine which calls Subroutines NROC, NSFC, +C NNFC, NNSC, and NNTC. See Ref. 3 for details. +C DLSODES uses CDRV to solve linear systems in which the +C coefficient matrix is P = I - con*J, where I is the +C identity, con is a scalar, and J is an approximation to +C the Jacobian df/dy. Because CDRV deals with rowwise +C sparsity descriptions, CDRV works with P-transpose, not P. +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DUMACH, IXSAV, and IUMACH are function routines. +C All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPRJS, DSOLSS + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, I1, I2, IFLAG, IMAX, IMUL, IMXER, IPFLAG, IPGO, IREM, + 1 J, KGO, LENRAT, LENYHT, LENIW, LENRW, LF0, LIA, LJA, + 2 LRTEM, LWTEM, LYHD, LYHN, MF1, MORD, MXHNL0, MXSTP0, NCOLM + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE LENRAT, MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following two internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODES, DIPREP, DPREP, +C DINTDY, DSTODE, DPRJS, and DSOLSS. +C The block DLSS01 is declared in subroutines DLSODES, DIPREP, DPREP, +C DPRJS, and DSOLSS. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLSS01/ CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH, + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C In the Data statement below, set LENRAT equal to the ratio of +C the wordlength for a real number to that for an integer. Usually, +C LENRAT = 1 for single precision and 2 for double precision. If the +C true ratio is not an integer, use the next smaller integer (.ge. 1). +C----------------------------------------------------------------------- + DATA LENRAT/2/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C If ISTATE = 1, the final setting of work space pointers, the matrix +C preprocessing, and other initializations are done in Block C. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C MF, ML, and MU. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + MOSS = MF/100 + MF1 = MF - 100*MOSS + METH = MF1/10 + MITER = MF1 - 10*METH + IF (MOSS .LT. 0 .OR. MOSS .GT. 2) GO TO 608 + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 0 .OR. MITER .GT. 3) GO TO 608 + IF (MITER .EQ. 0 .OR. MITER .EQ. 3) MOSS = 0 +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .EQ. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + SETH = 0.0D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 + SETH = RWORK(8) + IF (SETH .LT. 0.0D0) GO TO 609 +C Check RTOL and ATOL for legality. ------------------------------------ + 60 RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 65 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 65 CONTINUE +C----------------------------------------------------------------------- +C Compute required work array lengths, as far as possible, and test +C these against LRW and LIW. Then set tentative pointers for work +C arrays. Pointers to RWORK/IWORK segments are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted WM, YH, SAVF, EWT, ACOR. +C If MITER = 1 or 2, the required length of the matrix work space WM +C is not yet known, and so a crude minimum value is used for the +C initial tests of LRW and LIW, and YH is temporarily stored as far +C to the right in RWORK as possible, to leave the maximum amount +C of space for WM for matrix preprocessing. Thus if MITER = 1 or 2 +C and MOSS .ne. 2, some of the segments of RWORK are temporarily +C omitted, as they are not needed in the preprocessing. These +C omitted segments are: ACOR if ISTATE = 1, EWT and ACOR if ISTATE = 3 +C and MOSS = 1, and SAVF, EWT, and ACOR if ISTATE = 3 and MOSS = 0. +C----------------------------------------------------------------------- + LRAT = LENRAT + IF (ISTATE .EQ. 1) NYH = N + LWMIN = 0 + IF (MITER .EQ. 1) LWMIN = 4*N + 10*N/LRAT + IF (MITER .EQ. 2) LWMIN = 4*N + 11*N/LRAT + IF (MITER .EQ. 3) LWMIN = N + 2 + LENYH = (MAXORD+1)*NYH + LREST = LENYH + 3*N + LENRW = 20 + LWMIN + LREST + IWORK(17) = LENRW + LENIW = 30 + IF (MOSS .EQ. 0 .AND. MITER .NE. 0 .AND. MITER .NE. 3) + 1 LENIW = LENIW + N + 1 + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 + LIA = 31 + IF (MOSS .EQ. 0 .AND. MITER .NE. 0 .AND. MITER .NE. 3) + 1 LENIW = LENIW + IWORK(LIA+N) - 1 + IWORK(18) = LENIW + IF (LENIW .GT. LIW) GO TO 618 + LJA = LIA + N + 1 + LIA = MIN(LIA,LIW) + LJA = MIN(LJA,LIW) + LWM = 21 + IF (ISTATE .EQ. 1) NQ = 1 + NCOLM = MIN(NQ+1,MAXORD+2) + LENYHM = NCOLM*NYH + LENYHT = LENYH + IF (MITER .EQ. 1 .OR. MITER .EQ. 2) LENYHT = LENYHM + IMUL = 2 + IF (ISTATE .EQ. 3) IMUL = MOSS + IF (MOSS .EQ. 2) IMUL = 3 + LRTEM = LENYHT + IMUL*N + LWTEM = LWMIN + IF (MITER .EQ. 1 .OR. MITER .EQ. 2) LWTEM = LRW - 20 - LRTEM + LENWK = LWTEM + LYHN = LWM + LWTEM + LSAVF = LYHN + LENYHT + LEWT = LSAVF + N + LACOR = LEWT + N + ISTATC = ISTATE + IF (ISTATE .EQ. 1) GO TO 100 +C----------------------------------------------------------------------- +C ISTATE = 3. Move YH to its new location. +C Note that only the part of YH needed for the next step, namely +C MIN(NQ+1,MAXORD+2) columns, is actually moved. +C A temporary error weight array EWT is loaded if MOSS = 2. +C Sparse matrix processing is done in DIPREP/DPREP if MITER = 1 or 2. +C If MAXORD was reduced below NQ, then the pointers are finally set +C so that SAVF is identical to YH(*,MAXORD+2). +C----------------------------------------------------------------------- + LYHD = LYH - LYHN + IMAX = LYHN - 1 + LENYHM +C Move YH. Move right if LYHD < 0; move left if LYHD > 0. ------------- + IF (LYHD .LT. 0) THEN + DO 72 I = LYHN,IMAX + J = IMAX + LYHN - I + 72 RWORK(J) = RWORK(J+LYHD) + ENDIF + IF (LYHD .GT. 0) THEN + DO 76 I = LYHN,IMAX + 76 RWORK(I) = RWORK(I+LYHD) + ENDIF + 80 LYH = LYHN + IWORK(22) = LYH + IF (MITER .EQ. 0 .OR. MITER .EQ. 3) GO TO 92 + IF (MOSS .NE. 2) GO TO 85 +C Temporarily load EWT if MITER = 1 or 2 and MOSS = 2. ----------------- + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 82 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 82 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 85 CONTINUE +C DIPREP and DPREP do sparse matrix preprocessing if MITER = 1 or 2. --- + LSAVF = MIN(LSAVF,LRW) + LEWT = MIN(LEWT,LRW) + LACOR = MIN(LACOR,LRW) + CALL DIPREP (NEQ, Y, RWORK, IWORK(LIA),IWORK(LJA), IPFLAG, F, JAC) + LENRW = LWM - 1 + LENWK + LREST + IWORK(17) = LENRW + IF (IPFLAG .NE. -1) IWORK(23) = IPIAN + IF (IPFLAG .NE. -1) IWORK(24) = IPJAN + IPGO = -IPFLAG + 1 + GO TO (90, 628, 629, 630, 631, 632, 633), IPGO + 90 IWORK(22) = LYH + IF (LENRW .GT. LRW) GO TO 617 +C Set flag to signal parameter changes to DSTODE. ---------------------- + 92 JSTART = -1 + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C the sparse matrix preprocessing (MITER = 1 or 2), and the +C calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 CONTINUE + LYH = LYHN + IWORK(22) = LYH + TN = T + NST = 0 + H = 1.0D0 + NNZ = 0 + NGP = 0 + NZL = 0 + NZU = 0 +C Load the initial value vector in YH. --------------------------------- + DO 105 I = 1,N + 105 RWORK(I+LYH-1) = Y(I) +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 110 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 110 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + IF (MITER .EQ. 0 .OR. MITER .EQ. 3) GO TO 120 +C DIPREP and DPREP do sparse matrix preprocessing if MITER = 1 or 2. --- + LACOR = MIN(LACOR,LRW) + CALL DIPREP (NEQ, Y, RWORK, IWORK(LIA),IWORK(LJA), IPFLAG, F, JAC) + LENRW = LWM - 1 + LENWK + LREST + IWORK(17) = LENRW + IF (IPFLAG .NE. -1) IWORK(23) = IPIAN + IF (IPFLAG .NE. -1) IWORK(24) = IPJAN + IPGO = -IPFLAG + 1 + GO TO (115, 628, 629, 630, 631, 632, 633), IPGO + 115 IWORK(22) = LYH + IF (LENRW .GT. LRW) GO TO 617 +C Check TCRIT for legality (ITASK = 4 or 5). --------------------------- + 120 CONTINUE + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 125 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T +C Initialize all remaining parameters. --------------------------------- + 125 UROUND = DUMACH() + JSTART = 0 + IF (MITER .NE. 0) RWORK(LWM) = SQRT(UROUND) + MSBJ = 50 + NSLJ = 0 + CCMXJ = 0.2D0 + PSMALL = 1000.0D0*UROUND + RBIG = 0.01D0/PSMALL + NHNIL = 0 + NJE = 0 + NLU = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * Sum ( f(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C f(i) = i-th component of initial value of f, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C ABS(H0) is made .le. ABS(TOUT-T) in any case. +C----------------------------------------------------------------------- + LF0 = LYH + NYH + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 140 + DO 130 I = 1,N + 130 TOL = MAX(TOL,RTOL(I)) + 140 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LF0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODE. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODES- Warning..Internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODES- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODE(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,WM,F,JAC,DPRJS,DSOLSS) +C----------------------------------------------------------------------- + CALL DSTODE (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), RWORK(LWM), + 2 F, JAC, DPRJS, DSOLSS) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 550), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. if TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODES. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNZ + IWORK(20) = NGP + IWORK(21) = NLU + IWORK(25) = NZL + IWORK(26) = NZU + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODES- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODES- At T (=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODES- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODES- At T(=R1) and step size H(=R2), the error' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODES- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 560 +C KFLAG = -3. Fatal error flag returned by DPRJS or DSOLSS (CDRV). ---- + 550 MSG = 'DLSODES- At T (=R1) and step size H (=R2), a fatal' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' error flag was returned by CDRV (by way of ' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Subroutine DPRJS or DSOLSS) ' + CALL XERRWD (MSG, 40, 207, 0, 0, 0, 0, 2, TN, H) + ISTATE = -7 + GO TO 580 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNZ + IWORK(20) = NGP + IWORK(21) = NLU + IWORK(25) = NZL + IWORK(26) = NZU + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODES- ISTATE (=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODES- ITASK (=I1) illegal. ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODES- ISTATE.gt.1 but DLSODES not initialized. ' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODES- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODES- ISTATE = 3 and NEQ increased (I1 to I2). ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODES- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODES- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODES- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSODES- SETH (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 9, 0, 0, 0, 0, 1, SETH, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODES- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODES- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODES- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODES- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODES- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODES- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG = 'DLSODES- RWORK length is insufficient to proceed. ' + CALL XERRWD (MSG, 50, 17, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG = 'DLSODES- IWORK length is insufficient to proceed. ' + CALL XERRWD (MSG, 50, 18, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODES- RTOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODES- ATOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODES- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODES- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODES- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODES- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODES- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODES- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODES- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) + GO TO 700 + 628 MSG='DLSODES- RWORK length insufficient (for Subroutine DPREP). ' + CALL XERRWD (MSG, 60, 28, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 28, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 629 MSG='DLSODES- RWORK length insufficient (for Subroutine JGROUP). ' + CALL XERRWD (MSG, 60, 29, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 29, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 630 MSG='DLSODES- RWORK length insufficient (for Subroutine ODRV). ' + CALL XERRWD (MSG, 60, 30, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 30, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 631 MSG='DLSODES- Error from ODRV in Yale Sparse Matrix Package. ' + CALL XERRWD (MSG, 60, 31, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + IMUL = (IYS - 1)/N + IREM = IYS - IMUL*N + MSG=' At T (=R1), ODRV returned error flag = I1*NEQ + I2. ' + CALL XERRWD (MSG, 60, 31, 0, 2, IMUL, IREM, 1, TN, 0.0D0) + GO TO 700 + 632 MSG='DLSODES- RWORK length insufficient (for Subroutine CDRV). ' + CALL XERRWD (MSG, 60, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 32, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 633 MSG='DLSODES- Error from CDRV in Yale Sparse Matrix Package. ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + IMUL = (IYS - 1)/N + IREM = IYS - IMUL*N + MSG=' At T (=R1), CDRV returned error flag = I1*NEQ + I2. ' + CALL XERRWD (MSG, 60, 33, 0, 2, IMUL, IREM, 1, TN, 0.0D0) + IF (IMUL .EQ. 2) THEN + MSG=' Duplicate entry in sparsity structure descriptors. ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (IMUL .EQ. 3 .OR. IMUL .EQ. 6) THEN + MSG=' Insufficient storage for NSFC (called by CDRV). ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODES- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODES --------------------- + END +*DECK DLSODA + SUBROUTINE DLSODA (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, JT) + EXTERNAL F, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, JT + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 12 November 2003 version of +C DLSODA: Livermore Solver for Ordinary Differential Equations, with +C Automatic method switching for stiff and nonstiff problems. +C +C This version is in double precision. +C +C DLSODA solves the initial value problem for stiff or nonstiff +C systems of first order ODEs, +C dy/dt = f(t,y) , or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ). +C +C This a variant version of the DLSODE package. +C It switches automatically between stiff and nonstiff methods. +C This means that the user does not have to determine whether the +C problem is stiff or not, and the solver will automatically choose the +C appropriate method. It always starts with the nonstiff method. +C +C Authors: Alan C. Hindmarsh +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C and +C Linda R. Petzold +C Univ. of California at Santa Barbara +C Dept. of Computer Science +C Santa Barbara, CA 93106 +C +C References: +C 1. Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C 2. Linda R. Petzold, Automatic Selection of Methods for Solving +C Stiff and Nonstiff Systems of Ordinary Differential Equations, +C Siam J. Sci. Stat. Comput. 4 (1983), pp. 136-148. +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODA package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including alternative treatment of the Jacobian matrix, +C optional inputs and outputs, nonstandard options, and +C instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First provide a subroutine of the form: +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C which supplies the vector function f by loading YDOT(i) with f(i). +C +C B. Write a main program which calls Subroutine DLSODA once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages +C by DLSODA. On the first call to DLSODA, supply arguments as follows: +C F = name of subroutine for right-hand side vector f. +C This name must be declared External in calling program. +C NEQ = number of first order ODEs. +C Y = array of initial values, of length NEQ. +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C the estimated local error in y(i) will be controlled so as +C to be less than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 22 + NEQ * MAX(16, NEQ + 9). +C See also Paragraph E below. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least 20 + NEQ. +C LIW = declared length of IWORK (in user's dimension). +C JAC = name of subroutine for Jacobian matrix. +C Use a dummy name. See also Paragraph E below. +C JT = Jacobian type indicator. Set JT = 2. +C See also Paragraph E below. +C Note that the main program must declare arrays Y, RWORK, IWORK, +C and possibly ATOL. +C +C C. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSODA was successful, negative otherwise. +C -1 means excess work done on this call (perhaps wrong JT). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of JT or tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 means work space insufficient to finish (see messages). +C +C D. To continue the integration after a successful return, simply +C reset TOUT and call DLSODA again. No other parameters need be reset. +C +C E. Note: If and when DLSODA regards the problem as stiff, and +C switches methods accordingly, it must make use of the NEQ by NEQ +C Jacobian matrix, J = df/dy. For the sake of simplicity, the +C inputs to DLSODA recommended in Paragraph B above cause DLSODA to +C treat J as a full matrix, and to approximate it internally by +C difference quotients. Alternatively, J can be treated as a band +C matrix (with great potential reduction in the size of the RWORK +C array). Also, in either the full or banded case, the user can supply +C J in closed form, with a routine whose name is passed as the JAC +C argument. These alternatives are described in the paragraphs on +C RWORK, JAC, and JT in the full description of the call sequence below. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is a simple example problem, with the coding +C needed for its solution by DLSODA. The problem is from chemical +C kinetics, and consists of the following three rate equations: +C dy1/dt = -.04*y1 + 1.e4*y2*y3 +C dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2 +C dy3/dt = 3.e7*y2**2 +C on the interval from t = 0.0 to t = 4.e10, with initial conditions +C y1 = 1.0, y2 = y3 = 0. The problem is stiff. +C +C The following coding solves this problem with DLSODA, +C printing results at t = .4, 4., ..., 4.e10. It uses +C ITOL = 2 and ATOL much smaller for y2 than y1 or y3 because +C y2 has much smaller values. +C At the end of the run, statistical quantities of interest are +C printed (see optional outputs in the full description below). +C +C EXTERNAL FEX +C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y +C DIMENSION Y(3), ATOL(3), RWORK(70), IWORK(23) +C NEQ = 3 +C Y(1) = 1. +C Y(2) = 0. +C Y(3) = 0. +C T = 0. +C TOUT = .4 +C ITOL = 2 +C RTOL = 1.D-4 +C ATOL(1) = 1.D-6 +C ATOL(2) = 1.D-10 +C ATOL(3) = 1.D-6 +C ITASK = 1 +C ISTATE = 1 +C IOPT = 0 +C LRW = 70 +C LIW = 23 +C JT = 2 +C DO 40 IOUT = 1,12 +C CALL DLSODA(FEX,NEQ,Y,T,TOUT,ITOL,RTOL,ATOL,ITASK,ISTATE, +C 1 IOPT,RWORK,LRW,IWORK,LIW,JDUM,JT) +C WRITE(6,20)T,Y(1),Y(2),Y(3) +C 20 FORMAT(' At t =',D12.4,' Y =',3D14.6) +C IF (ISTATE .LT. 0) GO TO 80 +C 40 TOUT = TOUT*10. +C WRITE(6,60)IWORK(11),IWORK(12),IWORK(13),IWORK(19),RWORK(15) +C 60 FORMAT(/' No. steps =',I4,' No. f-s =',I4,' No. J-s =',I4/ +C 1 ' Method last used =',I2,' Last switch was at t =',D12.4) +C STOP +C 80 WRITE(6,90)ISTATE +C 90 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE FEX (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y, YDOT +C DIMENSION Y(3), YDOT(3) +C YDOT(1) = -.04*Y(1) + 1.D4*Y(2)*Y(3) +C YDOT(3) = 3.D7*Y(2)*Y(2) +C YDOT(2) = -YDOT(1) - YDOT(3) +C RETURN +C END +C +C The output of this program (on a CDC-7600 in single precision) +C is as follows: +C +C At t = 4.0000e-01 y = 9.851712e-01 3.386380e-05 1.479493e-02 +C At t = 4.0000e+00 Y = 9.055333e-01 2.240655e-05 9.444430e-02 +C At t = 4.0000e+01 Y = 7.158403e-01 9.186334e-06 2.841505e-01 +C At t = 4.0000e+02 Y = 4.505250e-01 3.222964e-06 5.494717e-01 +C At t = 4.0000e+03 Y = 1.831975e-01 8.941774e-07 8.168016e-01 +C At t = 4.0000e+04 Y = 3.898730e-02 1.621940e-07 9.610125e-01 +C At t = 4.0000e+05 Y = 4.936363e-03 1.984221e-08 9.950636e-01 +C At t = 4.0000e+06 Y = 5.161831e-04 2.065786e-09 9.994838e-01 +C At t = 4.0000e+07 Y = 5.179817e-05 2.072032e-10 9.999482e-01 +C At t = 4.0000e+08 Y = 5.283401e-06 2.113371e-11 9.999947e-01 +C At t = 4.0000e+09 Y = 4.659031e-07 1.863613e-12 9.999995e-01 +C At t = 4.0000e+10 Y = 1.404280e-08 5.617126e-14 1.000000e+00 +C +C No. steps = 361 No. f-s = 693 No. J-s = 64 +C Method last used = 2 Last switch was at t = 6.0092e-03 +C----------------------------------------------------------------------- +C Full description of user interface to DLSODA. +C +C The user interface to DLSODA consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODA, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODA package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of a subroutine in the DLSODA package, +C which the user may replace with his/her own version, if desired. +C this relates to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, JT, +C and those used for both input and output are +C Y, T, ISTATE. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODA to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F = the name of the user-supplied subroutine defining the +C ODE system. The system must be put in the first-order +C form dy/dt = f(t,y), where f is a vector-valued function +C of the scalar t and the vector y. Subroutine F is to +C compute the function f. It is to have the form +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C where NEQ, T, and Y are input, and the array YDOT = f(t,y) +C is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter Y(1),...,Y(NEQ). +C F must be declared External in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODA, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY instead. +C +C NEQ = the size of the ODE system (number of first order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in F and/or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODA package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to F and JAC. Hence, if it is an array, locations +C NEQ(2),... may be used to store other integer data and pass +C it to F and/or JAC. Subroutines F and/or JAC must include +C NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 1), and only for output on other calls. +C On the first call, Y must contain the vector of initial +C values. On output, Y contains the computed solution vector, +C evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to +C F and JAC. Hence its length may exceed NEQ, and locations +C Y(NEQ+1),... may be used to store other real data and +C pass it to F and/or JAC. (The DLSODA package accesses only +C Y(1),...,Y(NEQ).) +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C on output, after each call, T is the value at which a +C computed solution Y is evaluated (usually the same as TOUT). +C on an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should .ne. T for the next call. +C For the initial t, an input value of TOUT .ne. T is used +C in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C max-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT = (EWT(i)) is a vector of positive error weights. +C The values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting a +C user-supplied routine for the setting of EWT. +C See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C the state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 1 means this is the first call for the problem +C (initializations will be done). See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, JT, ML, MU, +C and any optional inputs except H0, MXORDN, and MXORDS. +C (See IWORK description for ML and MU.) +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 1 means nothing was done; TOUT = T and ISTATE = 1 on input. +C 2 means the integration was performed successfully. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix, +C if one is being used. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means the length of RWORK and/or IWORK was too small to +C proceed, but the integration was successful as far as T. +C This happens when DLSODA chooses to switch methods +C but LRW and/or LIW is too small for the new method. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real array (double precision) for work space, and (in the +C first 20 words) for conditional and optional inputs and +C optional outputs. +C As DLSODA switches automatically between stiff and nonstiff +C methods, the required length of RWORK can change during the +C problem. Thus the RWORK array passed to DLSODA can either +C have a static (fixed) length large enough for both methods, +C or have a dynamic (changing) length altered by the calling +C program in response to output from DLSODA. +C +C --- Fixed Length Case --- +C If the RWORK length is to be fixed, it should be at least +C MAX (LRN, LRS), +C where LRN and LRS are the RWORK lengths required when the +C current method is nonstiff or stiff, respectively. +C +C The separate RWORK length requirements LRN and LRS are +C as follows: +C IF NEQ is constant and the maximum method orders have +C their default values, then +C LRN = 20 + 16*NEQ, +C LRS = 22 + 9*NEQ + NEQ**2 if JT = 1 or 2, +C LRS = 22 + 10*NEQ + (2*ML+MU)*NEQ if JT = 4 or 5. +C Under any other conditions, LRN and LRS are given by: +C LRN = 20 + NYH*(MXORDN+1) + 3*NEQ, +C LRS = 20 + NYH*(MXORDS+1) + 3*NEQ + LMAT, +C where +C NYH = the initial value of NEQ, +C MXORDN = 12, unless a smaller value is given as an +C optional input, +C MXORDS = 5, unless a smaller value is given as an +C optional input, +C LMAT = length of matrix work space: +C LMAT = NEQ**2 + 2 if JT = 1 or 2, +C LMAT = (2*ML + MU + 1)*NEQ + 2 if JT = 4 or 5. +C +C --- Dynamic Length Case --- +C If the length of RWORK is to be dynamic, then it should +C be at least LRN or LRS, as defined above, depending on the +C current method. Initially, it must be at least LRN (since +C DLSODA starts with the nonstiff method). On any return +C from DLSODA, the optional output MCUR indicates the current +C method. If MCUR differs from the value it had on the +C previous return, or if there has only been one call to +C DLSODA and MCUR is now 2, then DLSODA has switched +C methods during the last call, and the length of RWORK +C should be reset (to LRN if MCUR = 1, or to LRS if +C MCUR = 2). (An increase in the RWORK length is required +C if DLSODA returned ISTATE = -7, but not otherwise.) +C After resetting the length, call DLSODA with ISTATE = 3 +C to signal that change. +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer array for work space. +C As DLSODA switches automatically between stiff and nonstiff +C methods, the required length of IWORK can change during +C problem, between +C LIS = 20 + NEQ and LIN = 20, +C respectively. Thus the IWORK array passed to DLSODA can +C either have a fixed length of at least 20 + NEQ, or have a +C dynamic length of at least LIN or LIS, depending on the +C current method. The comments on dynamic length under +C RWORK above apply here. Initially, this length need +C only be at least LIN = 20. +C +C The first few words of IWORK are used for conditional and +C optional inputs and optional outputs. +C +C The following 2 words in IWORK are conditional inputs: +C IWORK(1) = ML these are the lower and upper +C IWORK(2) = MU half-bandwidths, respectively, of the +C banded Jacobian, excluding the main diagonal. +C The band is defined by the matrix locations +C (i,j) with i-ML .le. j .le. i+MU. ML and MU +C must satisfy 0 .le. ML,MU .le. NEQ-1. +C These are required if JT is 4 or 5, and +C ignored otherwise. ML and MU may in fact be +C the band parameters for a matrix to which +C df/dy is only approximately equal. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The base addresses of the work arrays must not be +C altered between calls to DLSODA for the same problem. +C The contents of the work arrays must not be altered +C between calls, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODA between calls, if +C desired (but not for use by F or JAC). +C +C JAC = the name of the user-supplied routine to compute the +C Jacobian matrix, df/dy, if JT = 1 or 4. The JAC routine +C is optional, but if the problem is expected to be stiff much +C of the time, you are encouraged to supply JAC, for the sake +C of efficiency. (Alternatively, set JT = 2 or 5 to have +C DLSODA compute df/dy internally by difference quotients.) +C If and when DLSODA uses df/dy, it treats this NEQ by NEQ +C matrix either as full (JT = 1 or 2), or as banded (JT = +C 4 or 5) with half-bandwidths ML and MU (discussed under +C IWORK above). In either case, if JT = 1 or 4, the JAC +C routine must compute df/dy as a function of the scalar t +C and the vector y. It is to have the form +C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) +C DOUBLE PRECISION T, Y(*), PD(NROWPD,*) +C where NEQ, T, Y, ML, MU, and NROWPD are input and the array +C PD is to be loaded with partial derivatives (elements of +C the Jacobian matrix) on output. PD must be given a first +C dimension of NROWPD. T and Y have the same meaning as in +C Subroutine F. +C In the full matrix case (JT = 1), ML and MU are +C ignored, and the Jacobian is to be loaded into PD in +C columnwise manner, with df(i)/dy(j) loaded into PD(i,j). +C In the band matrix case (JT = 4), the elements +C within the band are to be loaded into PD in columnwise +C manner, with diagonal lines of df/dy loaded into the rows +C of PD. Thus df(i)/dy(j) is to be loaded into PD(i-j+MU+1,j). +C ML and MU are the half-bandwidth parameters (see IWORK). +C The locations in PD in the two triangular areas which +C correspond to nonexistent matrix elements can be ignored +C or loaded arbitrarily, as they are overwritten by DLSODA. +C JAC need not provide df/dy exactly. A crude +C approximation (possibly with a smaller bandwidth) will do. +C In either case, PD is preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Each call to JAC is preceded by a call to F with the same +C arguments NEQ, T, and Y. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may be +C saved in a user Common block by F and not recomputed by JAC, +C if desired. Also, JAC may alter the Y array, if desired. +C JAC must be declared External in the calling program. +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C JT = Jacobian type indicator. Used only for input. +C JT specifies how the Jacobian matrix df/dy will be +C treated, if and when DLSODA requires this matrix. +C JT has the following values and meanings: +C 1 means a user-supplied full (NEQ by NEQ) Jacobian. +C 2 means an internally generated (difference quotient) full +C Jacobian (using NEQ extra calls to F per df/dy value). +C 4 means a user-supplied banded Jacobian. +C 5 means an internally generated banded Jacobian (using +C ML+MU+1 extra calls to F per df/dy evaluation). +C If JT = 1 or 4, the user must supply a Subroutine JAC +C (the name is arbitrary) as described above under JAC. +C If JT = 2 or 5, a dummy argument can be used. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C IXPR IWORK(5) flag to generate extra printing at method switches. +C IXPR = 0 means no extra printing (the default). +C IXPR = 1 means print data on each switch. +C T, H, and NST will be printed on the same logical +C unit as used for error messages. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C +C MXORDN IWORK(8) the maximum order to be allowed for the nonstiff +C (Adams) method. the default value is 12. +C if MXORDN exceeds the default value, it will +C be reduced to the default value. +C MXORDN is held constant during the problem. +C +C MXORDS IWORK(9) the maximum order to be allowed for the stiff +C (BDF) method. The default value is 5. +C If MXORDS exceeds the default value, it will +C be reduced to the default value. +C MXORDS is held constant during the problem. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODA, the variables listed +C below are quantities related to the performance of DLSODA +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODA, and on any return with +C ISTATE = -1, -2, -4, -5, or -6. On an illegal input return +C (ISTATE = -3), they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C TSW RWORK(15) the value of t at the time of the last method +C switch, if any. +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NFE IWORK(12) the number of f evaluations for the problem so far. +C +C NJE IWORK(13) the number of Jacobian evaluations (and of matrix +C LU decompositions) for the problem so far. +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required, assuming +C that the length of RWORK is to be fixed for the +C rest of the problem, and that switching may occur. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required, assuming +C that the length of IWORK is to be fixed for the +C rest of the problem, and that switching may occur. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C MUSED IWORK(19) the method indicator for the last successful step: +C 1 means Adams (nonstiff), 2 means BDF (stiff). +C +C MCUR IWORK(20) the current method indicator: +C 1 means Adams (nonstiff), 2 means BDF (stiff). +C This is the method to be attempted +C on the next step. Thus it differs from MUSED +C only if a method switch has just been made. +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at T = TCUR. +C +C ACOR LACOR array of size NEQ used for the accumulated +C (from Common corrections on each step, scaled on output +C as noted) to represent the estimated local error in y +C on the last step. This is the vector E in +C the description of the error control. It is +C defined only on a successful return from +C DLSODA. The base address LACOR is obtained by +C including in the user's program the +C following 2 lines: +C COMMON /DLS001/ RLS(218), ILS(37) +C LACOR = ILS(22) +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODA. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) set the logical unit number, LUN, for +C output of messages from DLSODA, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) set a flag to control the printing of +C messages by DLSODA. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCMA(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODA (see Part 3 below). +C RSAV must be a real array of length 240 +C or more, and ISAV must be an integer +C array of length 46 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCMA is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODA. +C +C CALL DINTDY(,,,,,) provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODA. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODA). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(T), is already provided +C by DLSODA directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C RWORK(21) = the base address of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODA is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODA, and +C (2) the two internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLSA01/ of length 31 (22 double precision words +C followed by 9 integer words). +C +C If DLSODA is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODA is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODA call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODA call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCMA (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below is a description of a routine in the DLSODA package which +C relates to the measurement of errors, and can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C Subroutine DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODA call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the +C DMNORM routine, and also used by DLSODA in the computation +C of the optional output IMXER, and the increments for difference +C quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19811102 DATE WRITTEN +C 19820126 Fixed bug in tests of work space lengths; +C minor corrections in main prologue and comments. +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODA; +C in STODA, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 19970225 Fixed lines setting JSTART = -2 in Subroutine LSODA. +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20010613 Revised excess accuracy test (to match rest of ODEPACK). +C 20010808 Fixed bug in DPRJA (matrix in DBNORM call). +C 20020502 Corrected declarations in descriptions of user routines. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODA package. +C +C In addition to Subroutine DLSODA, the DLSODA package includes the +C following subroutines and function routines: +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODA is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPRJA computes and preprocesses the Jacobian matrix J = df/dy +C and the Newton iteration matrix P = I - h*l0*J. +C DSOLSY manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DMNORM computes the weighted max-norm of a vector. +C DFNORM computes the norm of a full matrix consistent with the +C weighted max-norm on vectors. +C DBNORM computes the norm of a band matrix consistent with the +C weighted max-norm on vectors. +C DSRCMA is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DGEFA and DGESL are routines from LINPACK for solving full +C systems of linear algebraic equations. +C DGBFA and DGBSL are routines from LINPACK for solving banded +C linear systems. +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DMNORM, DFNORM, DBNORM, DUMACH, IXSAV, and IUMACH are +C function routines. All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPRJA, DSOLSY + DOUBLE PRECISION DUMACH, DMNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER INSUFR, INSUFI, IXPR, IOWNS2, JTYP, MUSED, MXORDN, MXORDS + INTEGER I, I1, I2, IFLAG, IMXER, KGO, LF0, + 1 LENIW, LENRW, LENWM, ML, MORD, MU, MXHNL0, MXSTP0 + INTEGER LEN1, LEN1C, LEN1N, LEN1S, LEN2, LENIWC, LENRWC + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION TSW, ROWNS2, PDNORM + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following two internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODA, DINTDY, DSTODA, +C DPRJA, and DSOLSY. +C The block DLSA01 is declared in subroutines DLSODA, DSTODA, and DPRJA. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLSA01/ TSW, ROWNS2(20), PDNORM, + 1 INSUFR, INSUFI, IXPR, IOWNS2(2), JTYP, MUSED, MXORDN, MXORDS +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C JT, ML, and MU. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + IF (JT .EQ. 3 .OR. JT .LT. 1 .OR. JT .GT. 5) GO TO 608 + JTYP = JT + IF (JT .LE. 2) GO TO 30 + ML = IWORK(1) + MU = IWORK(2) + IF (ML .LT. 0 .OR. ML .GE. N) GO TO 609 + IF (MU .LT. 0 .OR. MU .GE. N) GO TO 610 + 30 CONTINUE +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + IXPR = 0 + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + HMXI = 0.0D0 + HMIN = 0.0D0 + IF (ISTATE .NE. 1) GO TO 60 + H0 = 0.0D0 + MXORDN = MORD(1) + MXORDS = MORD(2) + GO TO 60 + 40 IXPR = IWORK(5) + IF (IXPR .LT. 0 .OR. IXPR .GT. 1) GO TO 611 + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + MXORDN = IWORK(8) + IF (MXORDN .LT. 0) GO TO 628 + IF (MXORDN .EQ. 0) MXORDN = 100 + MXORDN = MIN(MXORDN,MORD(1)) + MXORDS = IWORK(9) + IF (MXORDS .LT. 0) GO TO 629 + IF (MXORDS .EQ. 0) MXORDS = 100 + MXORDS = MIN(MXORDS,MORD(2)) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C If ISTATE = 1, METH is initialized to 1 here to facilitate the +C checking of work space lengths. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted YH, WM, EWT, SAVF, ACOR. +C If the lengths provided are insufficient for the current method, +C an error return occurs. This is treated as illegal input on the +C first call, but as a problem interruption with ISTATE = -7 on a +C continuation call. If the lengths are sufficient for the current +C method but not for both methods, a warning message is sent. +C----------------------------------------------------------------------- + 60 IF (ISTATE .EQ. 1) METH = 1 + IF (ISTATE .EQ. 1) NYH = N + LYH = 21 + LEN1N = 20 + (MXORDN + 1)*NYH + LEN1S = 20 + (MXORDS + 1)*NYH + LWM = LEN1S + 1 + IF (JT .LE. 2) LENWM = N*N + 2 + IF (JT .GE. 4) LENWM = (2*ML + MU + 1)*N + 2 + LEN1S = LEN1S + LENWM + LEN1C = LEN1N + IF (METH .EQ. 2) LEN1C = LEN1S + LEN1 = MAX(LEN1N,LEN1S) + LEN2 = 3*N + LENRW = LEN1 + LEN2 + LENRWC = LEN1C + LEN2 + IWORK(17) = LENRW + LIWM = 1 + LENIW = 20 + N + LENIWC = 20 + IF (METH .EQ. 2) LENIWC = LENIW + IWORK(18) = LENIW + IF (ISTATE .EQ. 1 .AND. LRW .LT. LENRWC) GO TO 617 + IF (ISTATE .EQ. 1 .AND. LIW .LT. LENIWC) GO TO 618 + IF (ISTATE .EQ. 3 .AND. LRW .LT. LENRWC) GO TO 550 + IF (ISTATE .EQ. 3 .AND. LIW .LT. LENIWC) GO TO 555 + LEWT = LEN1 + 1 + INSUFR = 0 + IF (LRW .GE. LENRW) GO TO 65 + INSUFR = 2 + LEWT = LEN1C + 1 + MSG='DLSODA- Warning.. RWORK length is sufficient for now, but ' + CALL XERRWD (MSG, 60, 103, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' may not be later. Integration will proceed anyway. ' + CALL XERRWD (MSG, 60, 103, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Length needed is LENRW = I1, while LRW = I2.' + CALL XERRWD (MSG, 50, 103, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + 65 LSAVF = LEWT + N + LACOR = LSAVF + N + INSUFI = 0 + IF (LIW .GE. LENIW) GO TO 70 + INSUFI = 2 + MSG='DLSODA- Warning.. IWORK length is sufficient for now, but ' + CALL XERRWD (MSG, 60, 104, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' may not be later. Integration will proceed anyway. ' + CALL XERRWD (MSG, 60, 104, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Length needed is LENIW = I1, while LIW = I2.' + CALL XERRWD (MSG, 50, 104, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + 70 CONTINUE +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 75 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 75 CONTINUE + IF (ISTATE .EQ. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTODA. ------- + JSTART = -1 + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + TSW = T + MAXORD = MXORDN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 110 JSTART = 0 + NHNIL = 0 + NST = 0 + NJE = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + MUSED = 0 + MITER = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load the initial value vector in YH. --------------------------------- + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 120 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by: +C +C H0**(-2) = 1./(TOL * w0**2) + TOL * (norm(F))**2 +C +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C F = the initial value of the vector f(t,y), and +C norm() = the weighted vector norm used throughout, given by +C the DMNORM function routine, and weighted by the +C tolerances initially loaded into the EWT array. +C The sign of H0 is inferred from the initial values of TOUT and T. +C ABS(H0) is made .le. ABS(TOUT-T) in any case. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 140 + DO 130 I = 1,N + 130 TOL = MAX(TOL,RTOL(I)) + 140 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DMNORM (N, RWORK(LF0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + T = TN + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) T = TCRIT + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2 .AND. JSTART .GE. 0) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODA. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF (METH .EQ. MUSED) GO TO 255 + IF (INSUFR .EQ. 1) GO TO 550 + IF (INSUFI .EQ. 1) GO TO 555 + 255 IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DMNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODA- Warning..Internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODA- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODA(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,IWM,F,JAC,DPRJA,DSOLSY) +C----------------------------------------------------------------------- + CALL DSTODA (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), IWORK(LIWM), + 2 F, JAC, DPRJA, DSOLSY) + KGO = 1 - KFLAG + GO TO (300, 530, 540), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). +C If a method switch was just made, record TSW, reset MAXORD, +C set JSTART to -1 to signal DSTODA to complete the switch, +C and do extra printing of data if IXPR = 1. +C Then, in any case, check for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + IF (METH .EQ. MUSED) GO TO 310 + TSW = TN + MAXORD = MXORDN + IF (METH .EQ. 2) MAXORD = MXORDS + IF (METH .EQ. 2) RWORK(LWM) = SQRT(UROUND) + INSUFR = MIN(INSUFR,1) + INSUFI = MIN(INSUFI,1) + JSTART = -1 + IF (IXPR .EQ. 0) GO TO 310 + IF (METH .EQ. 2) THEN + MSG='DLSODA- A switch to the BDF (stiff) method has occurred ' + CALL XERRWD (MSG, 60, 105, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (METH .EQ. 1) THEN + MSG='DLSODA- A switch to the Adams (nonstiff) method has occurred' + CALL XERRWD (MSG, 60, 106, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + MSG=' at T = R1, tentative step size H = R2, step NST = I1 ' + CALL XERRWD (MSG, 60, 107, 0, 1, NST, 0, 2, TN, H) + 310 GO TO (320, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 320 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (JSTART .GE. 0) JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODA. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + RWORK(15) = TSW + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = MUSED + IWORK(20) = METH + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODA- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODA- At T (=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODA- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODA- At T(=R1) and step size H(=R2), the error' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODA- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 560 +C RWORK length too small to proceed. ----------------------------------- + 550 MSG = 'DLSODA- At current T(=R1), RWORK length too small' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' to proceed. The integration was otherwise successful.' + CALL XERRWD (MSG, 60, 206, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C IWORK length too small to proceed. ----------------------------------- + 555 MSG = 'DLSODA- At current T(=R1), IWORK length too small' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' to proceed. The integration was otherwise successful.' + CALL XERRWD (MSG, 60, 207, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + RWORK(15) = TSW + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = MUSED + IWORK(20) = METH + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODA- ISTATE (=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODA- ITASK (=I1) illegal. ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODA- ISTATE .gt. 1 but DLSODA not initialized.' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODA- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODA- ISTATE = 3 and NEQ increased (I1 to I2). ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODA- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODA- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODA- JT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, JT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSODA- ML (=I1) illegal: .lt.0 or .ge.NEQ (=I2) ' + CALL XERRWD (MSG, 50, 9, 0, 2, ML, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 610 MSG = 'DLSODA- MU (=I1) illegal: .lt.0 or .ge.NEQ (=I2) ' + CALL XERRWD (MSG, 50, 10, 0, 2, MU, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODA- IXPR (=I1) illegal. ' + CALL XERRWD (MSG, 30, 11, 0, 1, IXPR, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODA- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODA- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODA- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODA- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODA- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSODA- RWORK length needed, LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSODA- IWORK length needed, LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODA- RTOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODA- ATOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODA- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODA- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODA- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODA- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODA- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODA- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODA- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) + GO TO 700 + 628 MSG = 'DLSODA- MXORDN (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 28, 0, 1, MXORDN, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 629 MSG = 'DLSODA- MXORDS (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 29, 0, 1, MXORDS, 0, 0, 0.0D0, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODA- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODA ---------------------- + END +*DECK DLSODAR + SUBROUTINE DLSODAR (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, JT, + 2 G, NG, JROOT) + EXTERNAL F, JAC, G + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, JT, + 1 NG, JROOT + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW), + 1 JROOT(NG) +C----------------------------------------------------------------------- +C This is the 12 November 2003 version of +C DLSODAR: Livermore Solver for Ordinary Differential Equations, with +C Automatic method switching for stiff and nonstiff problems, +C and with Root-finding. +C +C This version is in double precision. +C +C DLSODAR solves the initial value problem for stiff or nonstiff +C systems of first order ODEs, +C dy/dt = f(t,y) , or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ). +C At the same time, it locates the roots of any of a set of functions +C g(i) = g(i,t,y(1),...,y(NEQ)) (i = 1,...,ng). +C +C This a variant version of the DLSODE package. It differs from it +C in two ways: +C (a) It switches automatically between stiff and nonstiff methods. +C This means that the user does not have to determine whether the +C problem is stiff or not, and the solver will automatically choose the +C appropriate method. It always starts with the nonstiff method. +C (b) It finds the root of at least one of a set of constraint +C functions g(i) of the independent and dependent variables. +C It finds only those roots for which some g(i), as a function +C of t, changes sign in the interval of integration. +C It then returns the solution at the root, if that occurs +C sooner than the specified stop condition, and otherwise returns +C the solution according the specified stop condition. +C +C Authors: Alan C. Hindmarsh, +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C and +C Linda R. Petzold +C Univ. of California at Santa Barbara +C Dept. of Computer Science +C Santa Barbara, CA 93106 +C +C References: +C 1. Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C 2. Linda R. Petzold, Automatic Selection of Methods for Solving +C Stiff and Nonstiff Systems of Ordinary Differential Equations, +C Siam J. Sci. Stat. Comput. 4 (1983), pp. 136-148. +C 3. Kathie L. Hiebert and Lawrence F. Shampine, Implicitly Defined +C Output Points for Solutions of ODEs, Sandia Report SAND80-0180, +C February 1980. +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODAR package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including alternative treatment of the Jacobian matrix, +C optional inputs and outputs, nonstandard options, and +C instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First provide a subroutine of the form: +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C which supplies the vector function f by loading YDOT(i) with f(i). +C +C B. Provide a subroutine of the form: +C SUBROUTINE G (NEQ, T, Y, NG, GOUT) +C DOUBLE PRECISION T, Y(*), GOUT(NG) +C which supplies the vector function g by loading GOUT(i) with +C g(i), the i-th constraint function whose root is sought. +C +C C. Write a main program which calls Subroutine DLSODAR once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages by +C DLSODAR. On the first call to DLSODAR, supply arguments as follows: +C F = name of subroutine for right-hand side vector f. +C This name must be declared External in calling program. +C NEQ = number of first order ODEs. +C Y = array of initial values, of length NEQ. +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C the estimated local error in y(i) will be controlled so as +C to be less than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 22 + NEQ * MAX(16, NEQ + 9) + 3*NG. +C See also Paragraph F below. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least 20 + NEQ. +C LIW = declared length of IWORK (in user's dimension). +C JAC = name of subroutine for Jacobian matrix. +C Use a dummy name. See also Paragraph F below. +C JT = Jacobian type indicator. Set JT = 2. +C See also Paragraph F below. +C G = name of subroutine for constraint functions, whose +C roots are desired during the integration. +C This name must be declared External in calling program. +C NG = number of constraint functions g(i). If there are none, +C set NG = 0, and pass a dummy name for G. +C JROOT = integer array of length NG for output of root information. +C See next paragraph. +C Note that the main program must declare arrays Y, RWORK, IWORK, +C JROOT, and possibly ATOL. +C +C D. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable. This is +C TOUT if ISTATE = 2, or the root location if ISTATE = 3, +C or the farthest point reached if DLSODAR was unsuccessful. +C ISTATE = 2 or 3 if DLSODAR was successful, negative otherwise. +C 2 means no root was found, and TOUT was reached as desired. +C 3 means a root was found prior to reaching TOUT. +C -1 means excess work done on this call (perhaps wrong JT). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of JT or tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 means work space insufficient to finish (see messages). +C JROOT = array showing roots found if ISTATE = 3 on return. +C JROOT(i) = 1 if g(i) has a root at t, or 0 otherwise. +C +C E. To continue the integration after a successful return, proceed +C as follows: +C (a) If ISTATE = 2 on return, reset TOUT and call DLSODAR again. +C (b) If ISTATE = 3 on return, reset ISTATE to 2, call DLSODAR again. +C In either case, no other parameters need be reset. +C +C F. Note: If and when DLSODAR regards the problem as stiff, and +C switches methods accordingly, it must make use of the NEQ by NEQ +C Jacobian matrix, J = df/dy. For the sake of simplicity, the +C inputs to DLSODAR recommended in Paragraph C above cause DLSODAR to +C treat J as a full matrix, and to approximate it internally by +C difference quotients. Alternatively, J can be treated as a band +C matrix (with great potential reduction in the size of the RWORK +C array). Also, in either the full or banded case, the user can supply +C J in closed form, with a routine whose name is passed as the JAC +C argument. These alternatives are described in the paragraphs on +C RWORK, JAC, and JT in the full description of the call sequence below. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is a simple example problem, with the coding +C needed for its solution by DLSODAR. The problem is from chemical +C kinetics, and consists of the following three rate equations: +C dy1/dt = -.04*y1 + 1.e4*y2*y3 +C dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2 +C dy3/dt = 3.e7*y2**2 +C on the interval from t = 0.0 to t = 4.e10, with initial conditions +C y1 = 1.0, y2 = y3 = 0. The problem is stiff. +C In addition, we want to find the values of t, y1, y2, and y3 at which +C (1) y1 reaches the value 1.e-4, and +C (2) y3 reaches the value 1.e-2. +C +C The following coding solves this problem with DLSODAR, +C printing results at t = .4, 4., ..., 4.e10, and at the computed +C roots. It uses ITOL = 2 and ATOL much smaller for y2 than y1 or y3 +C because y2 has much smaller values. +C At the end of the run, statistical quantities of interest are +C printed (see optional outputs in the full description below). +C +C EXTERNAL FEX, GEX +C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y +C DIMENSION Y(3), ATOL(3), RWORK(76), IWORK(23), JROOT(2) +C NEQ = 3 +C Y(1) = 1. +C Y(2) = 0. +C Y(3) = 0. +C T = 0. +C TOUT = .4 +C ITOL = 2 +C RTOL = 1.D-4 +C ATOL(1) = 1.D-6 +C ATOL(2) = 1.D-10 +C ATOL(3) = 1.D-6 +C ITASK = 1 +C ISTATE = 1 +C IOPT = 0 +C LRW = 76 +C LIW = 23 +C JT = 2 +C NG = 2 +C DO 40 IOUT = 1,12 +C 10 CALL DLSODAR(FEX,NEQ,Y,T,TOUT,ITOL,RTOL,ATOL,ITASK,ISTATE, +C 1 IOPT,RWORK,LRW,IWORK,LIW,JDUM,JT,GEX,NG,JROOT) +C WRITE(6,20)T,Y(1),Y(2),Y(3) +C 20 FORMAT(' At t =',D12.4,' Y =',3D14.6) +C IF (ISTATE .LT. 0) GO TO 80 +C IF (ISTATE .EQ. 2) GO TO 40 +C WRITE(6,30)JROOT(1),JROOT(2) +C 30 FORMAT(5X,' The above line is a root, JROOT =',2I5) +C ISTATE = 2 +C GO TO 10 +C 40 TOUT = TOUT*10. +C WRITE(6,60)IWORK(11),IWORK(12),IWORK(13),IWORK(10), +C 1 IWORK(19),RWORK(15) +C 60 FORMAT(/' No. steps =',I4,' No. f-s =',I4,' No. J-s =',I4, +C 1 ' No. g-s =',I4/ +C 2 ' Method last used =',I2,' Last switch was at t =',D12.4) +C STOP +C 80 WRITE(6,90)ISTATE +C 90 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE FEX (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y, YDOT +C DIMENSION Y(3), YDOT(3) +C YDOT(1) = -.04*Y(1) + 1.D4*Y(2)*Y(3) +C YDOT(3) = 3.D7*Y(2)*Y(2) +C YDOT(2) = -YDOT(1) - YDOT(3) +C RETURN +C END +C +C SUBROUTINE GEX (NEQ, T, Y, NG, GOUT) +C DOUBLE PRECISION T, Y, GOUT +C DIMENSION Y(3), GOUT(2) +C GOUT(1) = Y(1) - 1.D-4 +C GOUT(2) = Y(3) - 1.D-2 +C RETURN +C END +C +C The output of this program (on a CDC-7600 in single precision) +C is as follows: +C +C At t = 2.6400e-01 y = 9.899653e-01 3.470563e-05 1.000000e-02 +C The above line is a root, JROOT = 0 1 +C At t = 4.0000e-01 Y = 9.851712e-01 3.386380e-05 1.479493e-02 +C At t = 4.0000e+00 Y = 9.055333e-01 2.240655e-05 9.444430e-02 +C At t = 4.0000e+01 Y = 7.158403e-01 9.186334e-06 2.841505e-01 +C At t = 4.0000e+02 Y = 4.505250e-01 3.222964e-06 5.494717e-01 +C At t = 4.0000e+03 Y = 1.831975e-01 8.941774e-07 8.168016e-01 +C At t = 4.0000e+04 Y = 3.898730e-02 1.621940e-07 9.610125e-01 +C At t = 4.0000e+05 Y = 4.936363e-03 1.984221e-08 9.950636e-01 +C At t = 4.0000e+06 Y = 5.161831e-04 2.065786e-09 9.994838e-01 +C At t = 2.0745e+07 Y = 1.000000e-04 4.000395e-10 9.999000e-01 +C The above line is a root, JROOT = 1 0 +C At t = 4.0000e+07 Y = 5.179817e-05 2.072032e-10 9.999482e-01 +C At t = 4.0000e+08 Y = 5.283401e-06 2.113371e-11 9.999947e-01 +C At t = 4.0000e+09 Y = 4.659031e-07 1.863613e-12 9.999995e-01 +C At t = 4.0000e+10 Y = 1.404280e-08 5.617126e-14 1.000000e+00 +C +C No. steps = 361 No. f-s = 693 No. J-s = 64 No. g-s = 390 +C Method last used = 2 Last switch was at t = 6.0092e-03 +C +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODAR. +C +C The user interface to DLSODAR consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODAR, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODAR package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of a subroutine in the DLSODAR package, +C which the user may replace with his/her own version, if desired. +C this relates to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, +C JT, G, and NG, +C that used only for output is JROOT, +C and those used for both input and output are +C Y, T, ISTATE. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODAR to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F = the name of the user-supplied subroutine defining the +C ODE system. The system must be put in the first-order +C form dy/dt = f(t,y), where f is a vector-valued function +C of the scalar t and the vector y. Subroutine F is to +C compute the function f. It is to have the form +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C where NEQ, T, and Y are input, and the array YDOT = f(t,y) +C is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter Y(1),...,Y(NEQ). +C F must be declared External in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODAR, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY instead. +C +C NEQ = the size of the ODE system (number of first order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in F and/or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODAR package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to F, JAC, and G. Hence, if it is an array, locations +C NEQ(2),... may be used to store other integer data and pass +C it to F, JAC, and G. Each such subroutine must include +C NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 1), and only for output on other calls. +C On the first call, Y must contain the vector of initial +C values. On output, Y contains the computed solution vector, +C evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to F, +C JAC, and G. Hence its length may exceed NEQ, and locations +C Y(NEQ+1),... may be used to store other real data and +C pass it to F, JAC, and G. (The DLSODAR package accesses only +C Y(1),...,Y(NEQ).) +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution y is evaluated (usually the same as TOUT). +C If a root was found, T is the computed location of the +C root reached first, on output. +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should .ne. T for the next call. +C For the initial T, an input value of TOUT .ne. T is used +C in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C max-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT = (EWT(i)) is a vector of positive error weights. +C The values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting a +C user-supplied routine for the setting of EWT. +C See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C the state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 1 means this is the first call for the problem +C (initializations will be done). See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, JT, ML, MU, +C and any optional inputs except H0, MXORDN, and MXORDS. +C (See IWORK description for ML and MU.) +C In addition, immediately following a return with +C ISTATE = 3 (root found), NG and G may be changed. +C (But changing NG from 0 to .gt. 0 is not allowed.) +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 1 means nothing was done; TOUT = t and ISTATE = 1 on input. +C 2 means the integration was performed successfully, and +C no roots were found. +C 3 means the integration was successful, and one or more +C roots were found before satisfying the stop condition +C specified by ITASK. See JROOT. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix, +C if one is being used. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means the length of RWORK and/or IWORK was too small to +C proceed, but the integration was successful as far as T. +C This happens when DLSODAR chooses to switch methods +C but LRW and/or LIW is too small for the new method. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real array (double precision) for work space, and (in the +C first 20 words) for conditional and optional inputs and +C optional outputs. +C As DLSODAR switches automatically between stiff and nonstiff +C methods, the required length of RWORK can change during the +C problem. Thus the RWORK array passed to DLSODAR can either +C have a static (fixed) length large enough for both methods, +C or have a dynamic (changing) length altered by the calling +C program in response to output from DLSODAR. +C +C --- Fixed Length Case --- +C If the RWORK length is to be fixed, it should be at least +C max (LRN, LRS), +C where LRN and LRS are the RWORK lengths required when the +C current method is nonstiff or stiff, respectively. +C +C The separate RWORK length requirements LRN and LRS are +C as follows: +C If NEQ is constant and the maximum method orders have +C their default values, then +C LRN = 20 + 16*NEQ + 3*NG, +C LRS = 22 + 9*NEQ + NEQ**2 + 3*NG (JT = 1 or 2), +C LRS = 22 + 10*NEQ + (2*ML+MU)*NEQ + 3*NG (JT = 4 or 5). +C Under any other conditions, LRN and LRS are given by: +C LRN = 20 + NYH*(MXORDN+1) + 3*NEQ + 3*NG, +C LRS = 20 + NYH*(MXORDS+1) + 3*NEQ + LMAT + 3*NG, +C where +C NYH = the initial value of NEQ, +C MXORDN = 12, unless a smaller value is given as an +C optional input, +C MXORDS = 5, unless a smaller value is given as an +C optional input, +C LMAT = length of matrix work space: +C LMAT = NEQ**2 + 2 if JT = 1 or 2, +C LMAT = (2*ML + MU + 1)*NEQ + 2 if JT = 4 or 5. +C +C --- Dynamic Length Case --- +C If the length of RWORK is to be dynamic, then it should +C be at least LRN or LRS, as defined above, depending on the +C current method. Initially, it must be at least LRN (since +C DLSODAR starts with the nonstiff method). On any return +C from DLSODAR, the optional output MCUR indicates the current +C method. If MCUR differs from the value it had on the +C previous return, or if there has only been one call to +C DLSODAR and MCUR is now 2, then DLSODAR has switched +C methods during the last call, and the length of RWORK +C should be reset (to LRN if MCUR = 1, or to LRS if +C MCUR = 2). (An increase in the RWORK length is required +C if DLSODAR returned ISTATE = -7, but not otherwise.) +C After resetting the length, call DLSODAR with ISTATE = 3 +C to signal that change. +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer array for work space. +C As DLSODAR switches automatically between stiff and nonstiff +C methods, the required length of IWORK can change during +C problem, between +C LIS = 20 + NEQ and LIN = 20, +C respectively. Thus the IWORK array passed to DLSODAR can +C either have a fixed length of at least 20 + NEQ, or have a +C dynamic length of at least LIN or LIS, depending on the +C current method. The comments on dynamic length under +C RWORK above apply here. Initially, this length need +C only be at least LIN = 20. +C +C The first few words of IWORK are used for conditional and +C optional inputs and optional outputs. +C +C The following 2 words in IWORK are conditional inputs: +C IWORK(1) = ML These are the lower and upper +C IWORK(2) = MU half-bandwidths, respectively, of the +C banded Jacobian, excluding the main diagonal. +C The band is defined by the matrix locations +C (i,j) with i-ML .le. j .le. i+MU. ML and MU +C must satisfy 0 .le. ML,MU .le. NEQ-1. +C These are required if JT is 4 or 5, and +C ignored otherwise. ML and MU may in fact be +C the band parameters for a matrix to which +C df/dy is only approximately equal. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The base addresses of the work arrays must not be +C altered between calls to DLSODAR for the same problem. +C The contents of the work arrays must not be altered +C between calls, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODAR between calls, if +C desired (but not for use by F, JAC, or G). +C +C JAC = the name of the user-supplied routine to compute the +C Jacobian matrix, df/dy, if JT = 1 or 4. The JAC routine +C is optional, but if the problem is expected to be stiff much +C of the time, you are encouraged to supply JAC, for the sake +C of efficiency. (Alternatively, set JT = 2 or 5 to have +C DLSODAR compute df/dy internally by difference quotients.) +C If and when DLSODAR uses df/dy, it treats this NEQ by NEQ +C matrix either as full (JT = 1 or 2), or as banded (JT = +C 4 or 5) with half-bandwidths ML and MU (discussed under +C IWORK above). In either case, if JT = 1 or 4, the JAC +C routine must compute df/dy as a function of the scalar t +C and the vector y. It is to have the form +C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) +C DOUBLE PRECISION T, Y(*), PD(NROWPD,*) +C where NEQ, T, Y, ML, MU, and NROWPD are input and the array +C PD is to be loaded with partial derivatives (elements of +C the Jacobian matrix) on output. PD must be given a first +C dimension of NROWPD. T and Y have the same meaning as in +C Subroutine F. +C In the full matrix case (JT = 1), ML and MU are +C ignored, and the Jacobian is to be loaded into PD in +C columnwise manner, with df(i)/dy(j) loaded into pd(i,j). +C In the band matrix case (JT = 4), the elements +C within the band are to be loaded into PD in columnwise +C manner, with diagonal lines of df/dy loaded into the rows +C of PD. Thus df(i)/dy(j) is to be loaded into PD(i-j+MU+1,j). +C ML and MU are the half-bandwidth parameters (see IWORK). +C The locations in PD in the two triangular areas which +C correspond to nonexistent matrix elements can be ignored +C or loaded arbitrarily, as they are overwritten by DLSODAR. +C JAC need not provide df/dy exactly. A crude +C approximation (possibly with a smaller bandwidth) will do. +C In either case, PD is preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Each call to JAC is preceded by a call to F with the same +C arguments NEQ, T, and Y. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may be +C saved in a user Common block by F and not recomputed by JAC, +C if desired. Also, JAC may alter the Y array, if desired. +C JAC must be declared External in the calling program. +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C JT = Jacobian type indicator. Used only for input. +C JT specifies how the Jacobian matrix df/dy will be +C treated, if and when DLSODAR requires this matrix. +C JT has the following values and meanings: +C 1 means a user-supplied full (NEQ by NEQ) Jacobian. +C 2 means an internally generated (difference quotient) full +C Jacobian (using NEQ extra calls to F per df/dy value). +C 4 means a user-supplied banded Jacobian. +C 5 means an internally generated banded Jacobian (using +C ML+MU+1 extra calls to F per df/dy evaluation). +C If JT = 1 or 4, the user must supply a Subroutine JAC +C (the name is arbitrary) as described above under JAC. +C If JT = 2 or 5, a dummy argument can be used. +C +C G = the name of subroutine for constraint functions, whose +C roots are desired during the integration. It is to have +C the form +C SUBROUTINE G (NEQ, T, Y, NG, GOUT) +C DOUBLE PRECISION T, Y(*), GOUT(NG) +C where NEQ, T, Y, and NG are input, and the array GOUT +C is output. NEQ, T, and Y have the same meaning as in +C the F routine, and GOUT is an array of length NG. +C For i = 1,...,NG, this routine is to load into GOUT(i) +C the value at (T,Y) of the i-th constraint function g(i). +C DLSODAR will find roots of the g(i) of odd multiplicity +C (i.e. sign changes) as they occur during the integration. +C G must be declared External in the calling program. +C +C Caution: Because of numerical errors in the functions +C g(i) due to roundoff and integration error, DLSODAR may +C return false roots, or return the same root at two or more +C nearly equal values of t. If such false roots are +C suspected, the user should consider smaller error tolerances +C and/or higher precision in the evaluation of the g(i). +C +C If a root of some g(i) defines the end of the problem, +C the input to DLSODAR should nevertheless allow integration +C to a point slightly past that root, so that DLSODAR can +C locate the root by interpolation. +C +C Subroutine G may access user-defined quantities in +C NEQ(2),... and Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in G) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C NG = number of constraint functions g(i). If there are none, +C set NG = 0, and pass a dummy name for G. +C +C JROOT = integer array of length NG. Used only for output. +C On a return with ISTATE = 3 (one or more roots found), +C JROOT(i) = 1 if g(i) has a root at T, or JROOT(i) = 0 if not. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C IXPR IWORK(5) flag to generate extra printing at method switches. +C IXPR = 0 means no extra printing (the default). +C IXPR = 1 means print data on each switch. +C T, H, and NST will be printed on the same logical +C unit as used for error messages. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C +C MXORDN IWORK(8) the maximum order to be allowed for the nonstiff +C (Adams) method. The default value is 12. +C If MXORDN exceeds the default value, it will +C be reduced to the default value. +C MXORDN is held constant during the problem. +C +C MXORDS IWORK(9) the maximum order to be allowed for the stiff +C (BDF) method. The default value is 5. +C If MXORDS exceeds the default value, it will +C be reduced to the default value. +C MXORDS is held constant during the problem. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODAR, the variables listed +C below are quantities related to the performance of DLSODAR +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODAR, and on any return with +C ISTATE = -1, -2, -4, -5, or -6. On an illegal input return +C (ISTATE = -3), they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C TSW RWORK(15) the value of t at the time of the last method +C switch, if any. +C +C NGE IWORK(10) the number of g evaluations for the problem so far. +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NFE IWORK(12) the number of f evaluations for the problem so far. +C +C NJE IWORK(13) the number of Jacobian evaluations (and of matrix +C LU decompositions) for the problem so far. +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required, assuming +C that the length of RWORK is to be fixed for the +C rest of the problem, and that switching may occur. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required, assuming +C that the length of IWORK is to be fixed for the +C rest of the problem, and that switching may occur. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C MUSED IWORK(19) the method indicator for the last successful step: +C 1 means Adams (nonstiff), 2 means BDF (stiff). +C +C MCUR IWORK(20) the current method indicator: +C 1 means Adams (nonstiff), 2 means BDF (stiff). +C This is the method to be attempted +C on the next step. Thus it differs from MUSED +C only if a method switch has just been made. +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 + 3*NG the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. +C +C ACOR LACOR array of size NEQ used for the accumulated +C (from Common corrections on each step, scaled on output +C as noted) to represent the estimated local error in y +C on the last step. This is the vector E in +C the description of the error control. It is +C defined only on a successful return from +C DLSODAR. The base address LACOR is obtained by +C including in the user's program the +C following 2 lines: +C COMMON /DLS001/ RLS(218), ILS(37) +C LACOR = ILS(22) +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODAR. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODAR, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODAR. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCAR(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODAR (see Part 3 below). +C RSAV must be a real array of length 245 +C or more, and ISAV must be an integer +C array of length 55 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCAR is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODAR. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODAR. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C LYH = 21 + 3*NG +C CALL DINTDY (T, K, RWORK(LYH), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODAR). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(t), is already provided +C by DLSODAR directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C LYH = 21 + 3*NG = base address in RWORK of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODAR is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODAR, and +C (2) the three internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLSA01/ of length 31 (22 double precision words +C followed by 9 integer words). +C /DLSR01/ of length 7 (3 double precision words +C followed by 4 integer words). +C +C If DLSODAR is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODAR is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODAR call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODAR call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCAR (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below is a description of a routine in the DLSODAR package which +C relates to the measurement of errors, and can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C Subroutine DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODAR call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the +C DMNORM routine, and also used by DLSODAR in the computation +C of the optional output IMXER, and the increments for difference +C quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19811102 DATE WRITTEN +C 19820126 Fixed bug in tests of work space lengths; +C minor corrections in main prologue and comments. +C 19820507 Fixed bug in RCHEK in setting HMING. +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODA; +C in STODA, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 19970225 Fixed lines setting JSTART = -2 in Subroutine LSODAR. +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20010613 Revised excess accuracy test (to match rest of ODEPACK). +C 20010808 Fixed bug in DPRJA (matrix in DBNORM call). +C 20020502 Corrected declarations in descriptions of user routines. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODAR package. +C +C In addition to Subroutine DLSODAR, the DLSODAR package includes the +C following subroutines and function routines: +C DRCHEK does preliminary checking for roots, and serves as an +C interface between Subroutine DLSODAR and Subroutine DROOTS. +C DROOTS finds the leftmost root of a set of functions. +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODA is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPRJA computes and preprocesses the Jacobian matrix J = df/dy +C and the Newton iteration matrix P = I - h*l0*J. +C DSOLSY manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DMNORM computes the weighted max-norm of a vector. +C DFNORM computes the norm of a full matrix consistent with the +C weighted max-norm on vectors. +C DBNORM computes the norm of a band matrix consistent with the +C weighted max-norm on vectors. +C DSRCAR is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DGEFA and DGESL are routines from LINPACK for solving full +C systems of linear algebraic equations. +C DGBFA and DGBSL are routines from LINPACK for solving banded +C linear systems. +C DCOPY is one of the basic linear algebra modules (BLAS). +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DMNORM, DFNORM, DBNORM, DUMACH, IXSAV, and IUMACH are +C function routines. All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPRJA, DSOLSY + DOUBLE PRECISION DUMACH, DMNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER INSUFR, INSUFI, IXPR, IOWNS2, JTYP, MUSED, MXORDN, MXORDS + INTEGER LG0, LG1, LGX, IOWNR3, IRFND, ITASKC, NGC, NGE + INTEGER I, I1, I2, IFLAG, IMXER, KGO, LENIW, + 1 LENRW, LENWM, LF0, ML, MORD, MU, MXHNL0, MXSTP0 + INTEGER LEN1, LEN1C, LEN1N, LEN1S, LEN2, LENIWC, LENRWC + INTEGER IRFP, IRT, LENYH, LYHNEW + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION TSW, ROWNS2, PDNORM + DOUBLE PRECISION ROWNR3, T0, TLAST, TOUTC + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following three internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODAR, DINTDY, DSTODA, +C DPRJA, and DSOLSY. +C The block DLSA01 is declared in subroutines DLSODAR, DSTODA, DPRJA. +C The block DLSR01 is declared in subroutines DLSODAR, DRCHEK, DROOTS. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLSA01/ TSW, ROWNS2(20), PDNORM, + 1 INSUFR, INSUFI, IXPR, IOWNS2(2), JTYP, MUSED, MXORDN, MXORDS +C + COMMON /DLSR01/ ROWNR3(2), T0, TLAST, TOUTC, + 1 LG0, LG1, LGX, IOWNR3(2), IRFND, ITASKC, NGC, NGE +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + ITASKC = ITASK + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C JT, ML, MU, and NG. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + IF (JT .EQ. 3 .OR. JT .LT. 1 .OR. JT .GT. 5) GO TO 608 + JTYP = JT + IF (JT .LE. 2) GO TO 30 + ML = IWORK(1) + MU = IWORK(2) + IF (ML .LT. 0 .OR. ML .GE. N) GO TO 609 + IF (MU .LT. 0 .OR. MU .GE. N) GO TO 610 + 30 CONTINUE + IF (NG .LT. 0) GO TO 630 + IF (ISTATE .EQ. 1) GO TO 35 + IF (IRFND .EQ. 0 .AND. NG .NE. NGC) GO TO 631 + 35 NGC = NG +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + IXPR = 0 + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + HMXI = 0.0D0 + HMIN = 0.0D0 + IF (ISTATE .NE. 1) GO TO 60 + H0 = 0.0D0 + MXORDN = MORD(1) + MXORDS = MORD(2) + GO TO 60 + 40 IXPR = IWORK(5) + IF (IXPR .LT. 0 .OR. IXPR .GT. 1) GO TO 611 + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + MXORDN = IWORK(8) + IF (MXORDN .LT. 0) GO TO 628 + IF (MXORDN .EQ. 0) MXORDN = 100 + MXORDN = MIN(MXORDN,MORD(1)) + MXORDS = IWORK(9) + IF (MXORDS .LT. 0) GO TO 629 + IF (MXORDS .EQ. 0) MXORDS = 100 + MXORDS = MIN(MXORDS,MORD(2)) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C If ISTATE = 1, METH is initialized to 1 here to facilitate the +C checking of work space lengths. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted G0, G1, GX, YH, WM, +C EWT, SAVF, ACOR. +C If the lengths provided are insufficient for the current method, +C an error return occurs. This is treated as illegal input on the +C first call, but as a problem interruption with ISTATE = -7 on a +C continuation call. If the lengths are sufficient for the current +C method but not for both methods, a warning message is sent. +C----------------------------------------------------------------------- + 60 IF (ISTATE .EQ. 1) METH = 1 + IF (ISTATE .EQ. 1) NYH = N + LG0 = 21 + LG1 = LG0 + NG + LGX = LG1 + NG + LYHNEW = LGX + NG + IF (ISTATE .EQ. 1) LYH = LYHNEW + IF (LYHNEW .EQ. LYH) GO TO 62 +C If ISTATE = 3 and NG was changed, shift YH to its new location. ------ + LENYH = L*NYH + IF (LRW .LT. LYHNEW-1+LENYH) GO TO 62 + I1 = 1 + IF (LYHNEW .GT. LYH) I1 = -1 + CALL DCOPY (LENYH, RWORK(LYH), I1, RWORK(LYHNEW), I1) + LYH = LYHNEW + 62 CONTINUE + LEN1N = LYHNEW - 1 + (MXORDN + 1)*NYH + LEN1S = LYHNEW - 1 + (MXORDS + 1)*NYH + LWM = LEN1S + 1 + IF (JT .LE. 2) LENWM = N*N + 2 + IF (JT .GE. 4) LENWM = (2*ML + MU + 1)*N + 2 + LEN1S = LEN1S + LENWM + LEN1C = LEN1N + IF (METH .EQ. 2) LEN1C = LEN1S + LEN1 = MAX(LEN1N,LEN1S) + LEN2 = 3*N + LENRW = LEN1 + LEN2 + LENRWC = LEN1C + LEN2 + IWORK(17) = LENRW + LIWM = 1 + LENIW = 20 + N + LENIWC = 20 + IF (METH .EQ. 2) LENIWC = LENIW + IWORK(18) = LENIW + IF (ISTATE .EQ. 1 .AND. LRW .LT. LENRWC) GO TO 617 + IF (ISTATE .EQ. 1 .AND. LIW .LT. LENIWC) GO TO 618 + IF (ISTATE .EQ. 3 .AND. LRW .LT. LENRWC) GO TO 550 + IF (ISTATE .EQ. 3 .AND. LIW .LT. LENIWC) GO TO 555 + LEWT = LEN1 + 1 + INSUFR = 0 + IF (LRW .GE. LENRW) GO TO 65 + INSUFR = 2 + LEWT = LEN1C + 1 + MSG='DLSODAR- Warning.. RWORK length is sufficient for now, but ' + CALL XERRWD (MSG, 60, 103, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' may not be later. Integration will proceed anyway. ' + CALL XERRWD (MSG, 60, 103, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Length needed is LENRW = I1, while LRW = I2.' + CALL XERRWD (MSG, 50, 103, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + 65 LSAVF = LEWT + N + LACOR = LSAVF + N + INSUFI = 0 + IF (LIW .GE. LENIW) GO TO 70 + INSUFI = 2 + MSG='DLSODAR- Warning.. IWORK length is sufficient for now, but ' + CALL XERRWD (MSG, 60, 104, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' may not be later. Integration will proceed anyway. ' + CALL XERRWD (MSG, 60, 104, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Length needed is LENIW = I1, while LIW = I2.' + CALL XERRWD (MSG, 50, 104, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + 70 CONTINUE +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 75 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 75 CONTINUE + IF (ISTATE .EQ. 1) GO TO 100 +C if ISTATE = 3, set flag to signal parameter changes to DSTODA. ------- + JSTART = -1 + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. zero part of yh to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + TSW = T + MAXORD = MXORDN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 110 JSTART = 0 + NHNIL = 0 + NST = 0 + NJE = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + MUSED = 0 + MITER = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load the initial value vector in YH. --------------------------------- + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 120 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by: +C +C H0**(-2) = 1./(TOL * w0**2) + TOL * (norm(F))**2 +C +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C F = the initial value of the vector f(t,y), and +C norm() = the weighted vector norm used throughout, given by +C the DMNORM function routine, and weighted by the +C tolerances initially loaded into the EWT array. +C The sign of H0 is inferred from the initial values of TOUT and T. +C ABS(H0) is made .le. ABS(TOUT-T) in any case. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 140 + DO 130 I = 1,N + 130 TOL = MAX(TOL,RTOL(I)) + 140 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DMNORM (N, RWORK(LF0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) +C +C Check for a zero of g at T. ------------------------------------------ + IRFND = 0 + TOUTC = TOUT + IF (NGC .EQ. 0) GO TO 270 + CALL DRCHEK (1, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .EQ. 0) GO TO 270 + GO TO 632 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C First, DRCHEK is called to check for a root within the last step +C taken, other than the last root found there, if any. +C If ITASK = 2 or 5, and y(TN) has not yet been returned to the user +C because of an intervening root, return through Block G. +C----------------------------------------------------------------------- + 200 NSLAST = NST +C + IRFP = IRFND + IF (NGC .EQ. 0) GO TO 205 + IF (ITASK .EQ. 1 .OR. ITASK .EQ. 4) TOUTC = TOUT + CALL DRCHEK (2, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .NE. 1) GO TO 205 + IRFND = 1 + ISTATE = 3 + T = T0 + GO TO 425 + 205 CONTINUE + IRFND = 0 + IF (IRFP .EQ. 1 .AND. TLAST .NE. TN .AND. ITASK .EQ. 2) GO TO 400 +C + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + T = TN + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) T = TCRIT + IF (IRFP .EQ. 1 .AND. TLAST .NE. TN .AND. ITASK .EQ. 5) GO TO 400 + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2 .AND. JSTART .GE. 0) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODA. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF (METH .EQ. MUSED) GO TO 255 + IF (INSUFR .EQ. 1) GO TO 550 + IF (INSUFI .EQ. 1) GO TO 555 + 255 IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DMNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODAR- Warning..Internal T(=R1) and H(=R2) are ' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODAR- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODA(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,IWM,F,JAC,DPRJA,DSOLSY) +C----------------------------------------------------------------------- + CALL DSTODA (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), IWORK(LIWM), + 2 F, JAC, DPRJA, DSOLSY) + KGO = 1 - KFLAG + GO TO (300, 530, 540), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). +C If a method switch was just made, record TSW, reset MAXORD, +C set JSTART to -1 to signal DSTODA to complete the switch, +C and do extra printing of data if IXPR = 1. +C Then call DRCHEK to check for a root within the last step. +C Then, if no root was found, check for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + IF (METH .EQ. MUSED) GO TO 310 + TSW = TN + MAXORD = MXORDN + IF (METH .EQ. 2) MAXORD = MXORDS + IF (METH .EQ. 2) RWORK(LWM) = SQRT(UROUND) + INSUFR = MIN(INSUFR,1) + INSUFI = MIN(INSUFI,1) + JSTART = -1 + IF (IXPR .EQ. 0) GO TO 310 + IF (METH .EQ. 2) THEN + MSG='DLSODAR- A switch to the BDF (stiff) method has occurred ' + CALL XERRWD (MSG, 60, 105, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (METH .EQ. 1) THEN + MSG='DLSODAR- A switch to the Adams (nonstiff) method occurred ' + CALL XERRWD (MSG, 60, 106, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + MSG=' at T = R1, tentative step size H = R2, step NST = I1 ' + CALL XERRWD (MSG, 60, 107, 0, 1, NST, 0, 2, TN, H) + 310 CONTINUE +C + IF (NGC .EQ. 0) GO TO 315 + CALL DRCHEK (3, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .NE. 1) GO TO 315 + IRFND = 1 + ISTATE = 3 + T = T0 + GO TO 425 + 315 CONTINUE +C + GO TO (320, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 320 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (JSTART .GE. 0) JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODAR. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + 425 CONTINUE + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + RWORK(15) = TSW + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = MUSED + IWORK(20) = METH + IWORK(10) = NGE + TLAST = T + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODAR- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODAR- At T(=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODAR- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODAR- At T(=R1), step size H(=R2), the error ' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODAR- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 560 +C RWORK length too small to proceed. ----------------------------------- + 550 MSG = 'DLSODAR- At current T(=R1), RWORK length too small' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' to proceed. The integration was otherwise successful.' + CALL XERRWD (MSG, 60, 206, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C IWORK length too small to proceed. ----------------------------------- + 555 MSG = 'DLSODAR- At current T(=R1), IWORK length too small' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' to proceed. The integration was otherwise successful.' + CALL XERRWD (MSG, 60, 207, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + RWORK(15) = TSW + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = MUSED + IWORK(20) = METH + IWORK(10) = NGE + TLAST = T + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODAR- ISTATE(=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODAR- ITASK (=I1) illegal.' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODAR- ISTATE.gt.1 but DLSODAR not initialized.' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODAR- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODAR- ISTATE = 3 and NEQ increased (I1 to I2).' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODAR- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODAR- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODAR- JT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, JT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSODAR- ML (=I1) illegal: .lt.0 or .ge.NEQ (=I2)' + CALL XERRWD (MSG, 50, 9, 0, 2, ML, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 610 MSG = 'DLSODAR- MU (=I1) illegal: .lt.0 or .ge.NEQ (=I2)' + CALL XERRWD (MSG, 50, 10, 0, 2, MU, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODAR- IXPR (=I1) illegal. ' + CALL XERRWD (MSG, 30, 11, 0, 1, IXPR, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODAR- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODAR- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODAR- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODAR- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODAR- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSODAR- RWORK length needed, LENRW(=I1), exceeds LRW(=I2) ' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSODAR- IWORK length needed, LENIW(=I1), exceeds LIW(=I2) ' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODAR- RTOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODAR- ATOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODAR- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODAR- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODAR- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODAR- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODAR- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODAR- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODAR- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) + GO TO 700 + 628 MSG = 'DLSODAR- MXORDN (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 28, 0, 1, MXORDN, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 629 MSG = 'DLSODAR- MXORDS (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 29, 0, 1, MXORDS, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 630 MSG = 'DLSODAR- NG (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 30, 0, 1, NG, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 631 MSG = 'DLSODAR- NG changed (from I1 to I2) illegally, ' + CALL XERRWD (MSG, 50, 31, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' i.e. not immediately after a root was found.' + CALL XERRWD (MSG, 50, 31, 0, 2, NGC, NG, 0, 0.0D0, 0.0D0) + GO TO 700 + 632 MSG = 'DLSODAR- One or more components of g has a root ' + CALL XERRWD (MSG, 50, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' too near to the initial point. ' + CALL XERRWD (MSG, 40, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODAR- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODAR --------------------- + END +*DECK DLSODPK + SUBROUTINE DLSODPK (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, PSOL, MF) + EXTERNAL F, JAC, PSOL + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 18 November 2003 version of +C DLSODPK: Livermore Solver for Ordinary Differential equations, +C with Preconditioned Krylov iteration methods for the +C Newton correction linear systems. +C +C This version is in double precision. +C +C DLSODPK solves the initial value problem for stiff or nonstiff +C systems of first order ODEs, +C dy/dt = f(t,y) , or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ). +C----------------------------------------------------------------------- +C Introduction. +C +C This is a modification of the DLSODE package which incorporates +C various preconditioned Krylov subspace iteration methods for the +C linear algebraic systems that arise in the case of stiff systems. +C +C The linear systems that must be solved have the form +C A * x = b , where A = identity - hl0 * (df/dy) . +C Here hl0 is a scalar, and df/dy is the Jacobian matrix of partial +C derivatives of f (NEQ by NEQ). +C +C The particular Krylov method is chosen by setting the second digit, +C MITER, in the method flag MF. +C Currently, the values of MITER have the following meanings: +C +C MITER = 1 means the preconditioned Scaled Incomplete +C Orthogonalization Method (SPIOM). +C +C 2 means an incomplete version of the Preconditioned Scaled +C Generalized Minimal Residual method (SPIGMR). +C This is the best choice in general. +C +C 3 means the Preconditioned Conjugate Gradient method (PCG). +C Recommended only when df/dy is symmetric or nearly so. +C +C 4 means the scaled Preconditioned Conjugate Gradient method +C (PCGS). Recommended only when D-inverse * df/dy * D is +C symmetric or nearly so, where D is the diagonal scaling +C matrix with elements 1/EWT(i) (see RTOL/ATOL description). +C +C 9 means that only a user-supplied matrix P (approximating A) +C will be used, with no Krylov iteration done. This option +C allows the user to provide the complete linear system +C solution algorithm, if desired. +C +C The user can apply preconditioning to the linear system A*x = b, +C by means of arbitrary matrices (the preconditioners). +C In the case of SPIOM and SPIGMR, one can apply left and right +C preconditioners P1 and P2, and the basic iterative method is then +C applied to the matrix (P1-inverse)*A*(P2-inverse) instead of to the +C matrix A. The product P1*P2 should be an approximation to matrix A +C such that linear systems with P1 or P2 are easier to solve than with +C A. Preconditioning from the left only or right only means using +C P2 = identity or P1 = identity, respectively. +C In the case of the PCG and PCGS methods, there is only one +C preconditioner matrix P (but it can be the product of more than one). +C It should approximate the matrix A but allow for relatively +C easy solution of linear systems with coefficient matrix P. +C For PCG, P should be positive definite symmetric, or nearly so, +C and for PCGS, the scaled preconditioner D-inverse * P * D +C should be symmetric or nearly so. +C If the Jacobian J = df/dy splits in a natural way into a sum +C J = J1 + J2, then one possible choice of preconditioners is +C P1 = identity - hl0 * J1 and P2 = identity - hl0 * J2 +C provided each of these is easy to solve (or approximately solve). +C +C----------------------------------------------------------------------- +C References: +C 1. Peter N. Brown and Alan C. Hindmarsh, Reduced Storage Matrix +C Methods in Stiff ODE Systems, J. Appl. Math. & Comp., 31 (1989), +C pp. 40-91; also L.L.N.L. Report UCRL-95088, Rev. 1, June 1987. +C 2. Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C----------------------------------------------------------------------- +C Authors: Alan C. Hindmarsh and Peter N. Brown +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODPK package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the demonstration +C program distributed with this solver. +C +C A. First provide a subroutine of the form: +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C which supplies the vector function f by loading YDOT(i) with f(i). +C +C B. Next determine (or guess) whether or not the problem is stiff. +C Stiffness occurs when the Jacobian matrix df/dy has an eigenvalue +C whose real part is negative and large in magnitude, compared to the +C reciprocal of the t span of interest. If the problem is nonstiff, +C use a method flag MF = 10. If it is stiff, MF should be between 21 +C and 24, or possibly 29. MF = 22 is generally the best choice. +C Use 23 or 24 only if symmetry is present. Use MF = 29 if the +C complete linear system solution is to be provided by the user. +C The following four parameters must also be set. +C IWORK(1) = LWP = length of real array WP for preconditioning. +C IWORK(2) = LIWP = length of integer array IWP for preconditioning. +C IWORK(3) = JPRE = preconditioner type flag: +C = 0 for no preconditioning (P1 = P2 = P = identity) +C = 1 for left-only preconditioning (P2 = identity) +C = 2 for right-only preconditioning (P1 = identity) +C = 3 for two-sided preconditioning (and PCG or PCGS) +C IWORK(4) = JACFLG = flag for whether JAC is called. +C = 0 if JAC is not to be called, +C = 1 if JAC is to be called. +C Use JACFLG = 1 if JAC computes any nonconstant data for use in +C preconditioning, such as Jacobian elements. +C The arrays WP and IWP are work arrays under the user's control, +C for use in the routines that perform preconditioning operations. +C +C C. If the problem is stiff, you must supply two routines that deal +C with the preconditioning of the linear systems to be solved. +C These are as follows: +C +C SUBROUTINE JAC (F, NEQ, T, Y, YSV, REWT, FTY, V, HL0, WP,IWP, IER) +C DOUBLE PRECISION T, Y(*),YSV(*), REWT(*), FTY(*), V(*), HL0, WP(*) +C INTEGER IWP(*) +C This routine must evaluate and preprocess any parts of the +C Jacobian matrix df/dy involved in the preconditioners P1, P2, P. +C The Y and FTY arrays contain the current values of y and f(t,y), +C respectively, and YSV also contains the current value of y. +C The array V is work space of length NEQ. +C JAC must multiply all computed Jacobian elements by the scalar +C -HL0, add the identity matrix, and do any factorization +C operations called for, in preparation for solving linear systems +C with a coefficient matrix of P1, P2, or P. The matrix P1*P2 or P +C should be an approximation to identity - HL0 * (df/dy). +C JAC should return IER = 0 if successful, and IER .ne. 0 if not. +C (If IER .ne. 0, a smaller time step will be tried.) +C +C SUBROUTINE PSOL (NEQ, T, Y, FTY, WK, HL0, WP, IWP, B, LR, IER) +C DOUBLE PRECISION T, Y(*), FTY(*), WK(*), HL0, WP(*), B(*) +C INTEGER IWP(*) +C This routine must solve a linear system with B as right-hand +C side and one of the preconditioning matrices, P1, P2, or P, as +C coefficient matrix, and return the solution vector in B. +C LR is a flag concerning left vs right preconditioning, input +C to PSOL. PSOL is to use P1 if LR = 1 and P2 if LR = 2. +C In the case of the PCG or PCGS method, LR will be 3, and PSOL +C should solve the system P*x = B with the preconditioner matrix P. +C In the case MF = 29 (no Krylov iteration), LR will be 0, +C and PSOL is to return in B the desired approximate solution +C to A * x = B, where A = identity - HL0 * (df/dy). +C PSOL can use data generated in the JAC routine and stored in +C WP and IWP. WK is a work array of length NEQ. +C The argument HL0 is the current value of the scalar appearing +C in the linear system. If the old value, at the time of the last +C JAC call, is needed, it must have been saved by JAC in WP. +C On return, PSOL should set the error flag IER as follows: +C IER = 0 if PSOL was successful, +C IER .gt. 0 if a recoverable error occurred, meaning that the +C time step will be retried, +C IER .lt. 0 if an unrecoverable error occurred, meaning that the +C solver is to stop immediately. +C +C D. Write a main program which calls Subroutine DLSODPK once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages by +C DLSODPK. On the first call to DLSODPK, supply arguments as follows: +C F = name of subroutine for right-hand side vector f. +C This name must be declared External in calling program. +C NEQ = number of first order ODEs. +C Y = array of initial values, of length NEQ. +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C the estimated local error in y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: Actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 20 + 16*NEQ for MF = 10, +C 45 + 17*NEQ + LWP for MF = 21, +C 61 + 17*NEQ + LWP for MF = 22, +C 20 + 15*NEQ + LWP for MF = 23 or 24, +C 20 + 12*NEQ + LWP for MF = 29. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least: +C 30 for MF = 10, +C 35 + LIWP for MF = 21, +C 30 + LIWP for MF = 22, 23, 24, or 29. +C LIW = declared length of IWORK (in user's dimension). +C JAC,PSOL = names of subroutines for preconditioning. +C These names must be declared External in the calling program. +C MF = method flag. Standard values are: +C 10 for nonstiff (Adams) method. +C 21 for stiff (BDF) method, with preconditioned SIOM. +C 22 for stiff method, with preconditioned GMRES method. +C 23 for stiff method, with preconditioned CG method. +C 24 for stiff method, with scaled preconditioned CG method. +C 29 for stiff method, with user's PSOL routine only. +C Note that the main program must declare arrays Y, RWORK, IWORK, +C and possibly ATOL. +C +C E. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSODPK was successful, negative otherwise. +C -1 means excess work done on this call (perhaps wrong MF). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad JAC +C or PSOL routine supplied or wrong choice of MF or +C tolerances, or this solver is inappropriate). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 means an unrecoverable error occurred in PSOL. +C +C F. To continue the integration after a successful return, simply +C reset TOUT and call DLSODPK again. No other parameters need be reset. +C +C----------------------------------------------------------------------- +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODPK. +C +C The user interface to DLSODPK consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODPK, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODPK package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODPK package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, PSOL, MF, +C and those used for both input and output are +C Y, T, ISTATE. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODPK to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F = the name of the user-supplied subroutine defining the +C ODE system. The system must be put in the first-order +C form dy/dt = f(t,y), where f is a vector-valued function +C of the scalar t and the vector y. Subroutine F is to +C compute the function f. It is to have the form +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C where NEQ, T, and Y are input, and the array YDOT = f(t,y) +C is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter Y(1),...,Y(NEQ). +C F must be declared External in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODPK, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY instead. +C +C NEQ = the size of the ODE system (number of first order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in the user-supplied subroutines. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODPK package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to F, JAC, and PSOL. Hence, if it is an array, locations +C NEQ(2),... may be used to store other integer data and pass +C it to the user-supplied subroutines. Each such routine must +C include NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 1), and only for output on other calls. +C On the first call, Y must contain the vector of initial +C values. On output, Y contains the computed solution vector, +C evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to F, +C JAC, and PSOL. Hence its length may exceed NEQ, and locations +C Y(NEQ+1),... may be used to store other real data and +C pass it to the user-supplied subroutines. (The DLSODPK +C package accesses only Y(1),...,Y(NEQ).) +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution y is evaluated (usually the same as TOUT). +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should .ne. T for the next call. +C For the initial T, an input value of TOUT .ne. T is used +C in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C the following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C the state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 1 means this is the first call for the problem +C (initializations will be done). See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, +C and any of the optional inputs except H0. +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 1 means nothing was done; TOUT = T and ISTATE = 1 on input. +C 2 means the integration was performed successfully. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means the PSOL routine returned an unrecoverable error +C flag (IER .lt. 0). The integration was successful as +C far as T. +C +C Note: since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real working array (double precision). +C The length of RWORK must be at least +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LENLS + LWP where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LENLS = length of work space for linear system (Krylov) +C method, excluding preconditioning: +C LENLS = 0 if MITER = 0, +C LENLS = NEQ*(MAXL+3) + MAXL**2 if MITER = 1, +C LENLS = NEQ*(MAXL+3+MIN(1,MAXL-KMP)) +C + (MAXL+3)*MAXL + 1 if MITER = 2, +C LENLS = 6*NEQ if MITER = 3 or 4, +C LENLS = 3*NEQ if MITER = 9. +C (See the MF description for METH and MITER, and the +C list of optional inputs for MAXL and KMP.) +C LWP = length of real user work space for preconditioning +C (see JAC/PSOL). +C Thus if default values are used and NEQ is constant, +C this length is: +C 20 + 16*NEQ for MF = 10, +C 45 + 24*NEQ + LWP FOR MF = 11, +C 61 + 24*NEQ + LWP FOR MF = 12, +C 20 + 22*NEQ + LWP FOR MF = 13 OR 14, +C 20 + 19*NEQ + LWP FOR MF = 19, +C 20 + 9*NEQ FOR MF = 20, +C 45 + 17*NEQ + LWP FOR MF = 21, +C 61 + 17*NEQ + LWP FOR MF = 22, +C 20 + 15*NEQ + LWP FOR MF = 23 OR 24, +C 20 + 12*NEQ + LWP for MF = 29. +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 30 if MITER = 0 (MF = 10 or 20), +C 30 + MAXL + LIWP if MITER = 1 (MF = 11, 21), +C 30 + LIWP if MITER = 2, 3, 4, or 9. +C MAXL = 5 unless a different optional input value is given. +C LIWP = length of integer user work space for preconditioning +C (see conditional input list following). +C The first few words of IWORK are used for conditional and +C optional inputs and optional outputs. +C +C The following 4 words in IWORK are conditional inputs, +C required if MITER .ge. 1: +C IWORK(1) = LWP = length of real array WP for use in +C preconditioning (part of RWORK array). +C IWORK(2) = LIWP = length of integer array IWP for use in +C preconditioning (part of IWORK array). +C The arrays WP and IWP are work arrays under the +C user's control, for use in the routines that +C perform preconditioning operations (JAC and PSOL). +C IWORK(3) = JPRE = preconditioner type flag: +C = 0 for no preconditioning (P1 = P2 = P = identity) +C = 1 for left-only preconditioning (P2 = identity) +C = 2 for right-only preconditioning (P1 = identity) +C = 3 for two-sided preconditioning (and PCG or PCGS) +C IWORK(4) = JACFLG = flag for whether JAC is called. +C = 0 if JAC is not to be called, +C = 1 if JAC is to be called. +C Use JACFLG = 1 if JAC computes any nonconstant +C data needed in preconditioning operations, +C such as some of the Jacobian elements. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODPK +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODPK between calls, if +C desired (but not for use by any of the user-supplied subroutines). +C +C JAC = the name of the user-supplied routine to compute any +C Jacobian elements (or approximations) involved in the +C matrix preconditioning operations (MITER .ge. 1). +C It is to have the form +C SUBROUTINE JAC (F, NEQ, T, Y, YSV, REWT, FTY, V, +C 1 HL0, WP, IWP, IER) +C DOUBLE PRECISION T, Y(*),YSV(*), REWT(*), FTY(*), V(*), +C 1 HL0, WP(*) +C INTEGER IWP(*) +C This routine must evaluate and preprocess any parts of the +C Jacobian matrix df/dy used in the preconditioners P1, P2, P. +C the Y and FTY arrays contain the current values of y and +C f(t,y), respectively, and YSV also contains the current +C value of y. The array V is work space of length +C NEQ for use by JAC. REWT is the array of reciprocal error +C weights (1/EWT). JAC must multiply all computed Jacobian +C elements by the scalar -HL0, add the identity matrix, and do +C any factorization operations called for, in preparation +C for solving linear systems with a coefficient matrix of +C P1, P2, or P. The matrix P1*P2 or P should be an +C approximation to identity - HL0 * (df/dy). JAC should +C return IER = 0 if successful, and IER .ne. 0 if not. +C (If IER .ne. 0, a smaller time step will be tried.) +C The arrays WP (of length LWP) and IWP (of length LIWP) +C are for use by JAC and PSOL for work space and for storage +C of data needed for the solution of the preconditioner +C linear systems. Their lengths and contents are under the +C user's control. +C The JAC routine may save relevant Jacobian elements (or +C approximations) used in the preconditioners, along with the +C value of HL0, and use these to reconstruct preconditioner +C matrices later without reevaluationg those elements. +C This may be cost-effective if JAC is called with HL0 +C considerably different from its earlier value, indicating +C that a corrector convergence failure has occurred because +C of the change in HL0, not because of changes in the +C value of the Jacobian. In doing this, use the saved and +C current values of HL0 to decide whether to use saved +C or reevaluated elements. +C JAC may alter V, but may not alter Y, YSV, REWT, FTY, or HL0. +C JAC must be declared External in the calling program. +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C PSOL = the name of the user-supplied routine for the +C solution of preconditioner linear systems. +C It is to have the form +C SUBROUTINE PSOL (NEQ, T, Y, FTY, WK,HL0, WP,IWP, B, LR,IER) +C DOUBLE PRECISION T, Y(*), FTY(*), WK(*), HL0, WP(*), B(*) +C INTEGER IWP(*) +C This routine must solve a linear system with B as right-hand +C side and one of the preconditioning matrices, P1, P2, or P, +C as coefficient matrix, and return the solution vector in B. +C LR is a flag concerning left vs right preconditioning, input +C to PSOL. PSOL is to use P1 if LR = 1 and P2 if LR = 2. +C In the case of the PCG or PCGS method, LR will be 3, and PSOL +C should solve the system P*x = B with the preconditioner P. +C In the case MITER = 9 (no Krylov iteration), LR will be 0, +C and PSOL is to return in B the desired approximate solution +C to A * x = B, where A = identity - HL0 * (df/dy). +C PSOL can use data generated in the JAC routine and stored in +C WP and IWP. +C The Y and FTY arrays contain the current values of y and +C f(t,y), respectively. The array WK is work space of length +C NEQ for use by PSOL. +C The argument HL0 is the current value of the scalar appearing +C in the linear system. If the old value, as of the last +C JAC call, is needed, it must have been saved by JAC in WP. +C On return, PSOL should set the error flag IER as follows: +C IER = 0 if PSOL was successful, +C IER .gt. 0 on a recoverable error, meaning that the +C time step will be retried, +C IER .lt. 0 on an unrecoverable error, meaning that the +C solver is to stop immediately. +C PSOL may not alter Y, FTY, or HL0. +C PSOL must be declared External in the calling program. +C Subroutine PSOL may access user-defined quantities in +C NEQ(2),... and Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in PSOL) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C MF = the method flag. Used only for input. The legal values of +C MF are 10, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, and 29. +C MF has decimal digits METH and MITER: MF = 10*METH + MITER. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFs). +C MITER indicates the corrector iteration method: +C MITER = 0 means functional iteration (no linear system +C is involved). +C MITER = 1 means Newton iteration with Scaled Preconditioned +C Incomplete Orthogonalization Method (SPIOM) +C for the linear systems. +C MITER = 2 means Newton iteration with Scaled Preconditioned +C Generalized Minimal Residual method (SPIGMR) +C for the linear systems. +C MITER = 3 means Newton iteration with Preconditioned +C Conjugate Gradient method (PCG) +C for the linear systems. +C MITER = 4 means Newton iteration with scaled Preconditioned +C Conjugate Gradient method (PCGS) +C for the linear systems. +C MITER = 9 means Newton iteration with only the +C user-supplied PSOL routine called (no Krylov +C iteration) for the linear systems. +C JPRE is ignored, and PSOL is called with LR = 0. +C See comments in the introduction about the choice of MITER. +C If MITER .ge. 1, the user must supply routines JAC and PSOL +C (the names are arbitrary) as described above. +C For MITER = 0, dummy arguments can be used. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C DELT RWORK(8) convergence test constant in Krylov iteration +C algorithm. The default is .05. +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C +C MAXL IWORK(8) maximum number of iterations in the SPIOM, SPIGMR, +C PCG, or PCGS algorithm (.le. NEQ). +C The default is MAXL = MIN(5,NEQ). +C +C KMP IWORK(9) number of vectors on which orthogonalization +C is done in SPIOM or SPIGMR algorithm (.le. MAXL). +C The default is KMP = MAXL. +C Note: When KMP .lt. MAXL and MF = 22, the length +C of RWORK must be defined accordingly. See +C the definition of RWORK above. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODPK, the variables listed +C below are quantities related to the performance of DLSODPK +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODPK, and on any return with +C ISTATE = -1, -2, -4, -5, -6, or -7. On an illegal input return +C (ISTATE = -3), they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NFE IWORK(12) the number of f evaluations for the problem so far. +C +C NPE IWORK(13) the number of calls to JAC so far (for Jacobian +C evaluation associated with preconditioning). +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C NNI IWORK(19) number of nonlinear iterations so far (each of +C which calls an iterative linear solver). +C +C NLI IWORK(20) number of linear iterations so far. +C Note: A measure of the success of algorithm is +C the average number of linear iterations per +C nonlinear iteration, given by NLI/NNI. +C If this is close to MAXL, MAXL may be too small. +C +C NPS IWORK(21) number of preconditioning solve operations +C (PSOL calls) so far. +C +C NCFN IWORK(22) number of convergence failures of the nonlinear +C (Newton) iteration so far. +C Note: A measure of success is the overall +C rate of nonlinear convergence failures, NCFN/NST. +C +C NCFL IWORK(23) number of convergence failures of the linear +C iteration so far. +C Note: A measure of success is the overall +C rate of linear convergence failures, NCFL/NNI. +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output +C to represent the estimated local error in y +C on the last step. This is the vector E in +C the description of the error control. It is +C defined only on a successful return from +C DLSODPK. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODPK. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODPK, if +C the default is not desired. +C The default value of lun is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODPK. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCPK(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODPK (see Part 3 below). +C RSAV must be a real array of length 222 +C or more, and ISAV must be an integer +C array of length 50 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCPK is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODPK. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (See below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODPK. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODPK). +C for valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(T), is already provided +C by DLSODPK directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C RWORK(21) = the base address of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODPK is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODPK, and +C (2) the two internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLPK01/ of length 17 (4 double precision words +C followed by 13 integer words). +C +C If DLSODPK is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODPK is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODPK call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODPK call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCPK (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C below are descriptions of two routines in the DLSODPK package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODPK call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSODPK in the computation +C of the optional output IMXER, the diagonal Jacobian approximation, +C and the increments for difference quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where: +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSODPK. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*W(i)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19860901 DATE WRITTEN +C 19861010 Numerous minor revisions to SPIOM and SPGMR routines; +C minor corrections to prologues and comments. +C 19870114 Changed name SPGMR to SPIGMR; revised residual norm +C calculation in SPIGMR (for incomplete case); +C revised error return logic in SPIGMR; +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODPK; +C in STODPK, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 19871130 Added option MITER = 9; shortened WM array by 2; +C revised early return from SPIOM and SPIGMR; +C replaced copy loops with SCOPY/DCOPY calls; +C minor corrections/revisions to SOLPK, SPIGMR, ATV, ATP; +C corrections to main prologue and internal comments. +C 19880304 Corrections to type declarations in SOLPK, SPIOM, USOL. +C 19891025 Added ISTATE = -7 return; minor revisions to USOL; +C added initialization of JACFLG in main driver; +C removed YH and NYH from PKSET call list; +C minor revisions to SPIOM and SPIGMR; +C corrections to main prologue and internal comments. +C 19900803 Added YSV to JAC call list; minor comment corrections. +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20030603 Corrected duplicate type declaration for DUMACH. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C 20031117 Changed internal name NPE to NJE. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODPK package. +C +C In addition to Subroutine DLSODPK, the DLSODPK package includes the +C following subroutines and function routines: +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSTODPK is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPKSET interfaces between DSTODPK and the JAC routine. +C DSOLPK manages solution of linear system in Newton iteration. +C DSPIOM performs the SPIOM algorithm. +C DATV computes a scaled, preconditioned product (I-hl0*J)*v. +C DORTHOG orthogonalizes a vector against previous basis vectors. +C DHEFA generates an LU factorization of a Hessenberg matrix. +C DHESL solves a Hessenberg square linear system. +C DSPIGMR performs the SPIGMR algorithm. +C DHEQR generates a QR factorization of a Hessenberg matrix. +C DHELS finds the least squares solution of a Hessenberg system. +C DPCG performs Preconditioned Conjugate Gradient algorithm (PCG). +C DPCGS performs the PCGS algorithm. +C DATP computes the product A*p, where A = I - hl0*df/dy. +C DUSOL interfaces to the user's PSOL routine (MITER = 9). +C DSRCPK is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DAXPY, DCOPY, DDOT, DNRM2, and DSCAL are basic linear +C algebra modules (from the BLAS collection). +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DDOT, DNRM2, DUMACH, IXSAV, and IUMACH are function +C routines. All the others are subroutines. +C +C----------------------------------------------------------------------- + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + INTEGER I, I1, I2, IFLAG, IMXER, KGO, LF0, LENIW, + 1 LENIWK, LENRW, LENWM, LENWK, LIWP, LWP, MORD, MXHNL0, MXSTP0, + 2 NCFN0, NCFL0, NLI0, NNI0, NNID, NSTD, NWARN + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + DOUBLE PRECISION ATOLI, AVDIM, AYI, BIG, EWTI, H0, HMAX, HMX, + 1 RCFL, RCFN, RH, RTOLI, TCRIT, + 2 TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT, LAVD, LCFN, LCFL, LWARN + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following two internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODPK, DINTDY, DSTODPK, +C DSOLPK, and DATV. +C The block DLPK01 is declared in subroutines DLSODPK, DSTODPK, DPKSET, +C and DSOLPK. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, MF. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + METH = MF/10 + MITER = MF - 10*METH + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 0) GO TO 608 + IF (MITER .GT. 4 .AND. MITER .LT. 9) GO TO 608 + IF (MITER .GE. 1) JPRE = IWORK(3) + JACFLG = 0 + IF (MITER .GE. 1) JACFLG = IWORK(4) +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .EQ. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + MAXL = MIN(5,N) + KMP = MAXL + DELT = 0.05D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 + MAXL = IWORK(8) + IF (MAXL .EQ. 0) MAXL = 5 + MAXL = MIN(MAXL,N) + KMP = IWORK(9) + IF (KMP .EQ. 0 .OR. KMP .GT. MAXL) KMP = MAXL + DELT = RWORK(8) + IF (DELT .EQ. 0.0D0) DELT = 0.05D0 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C RWORK segments (in order) are denoted YH, WM, EWT, SAVF, SAVX, ACOR. +C----------------------------------------------------------------------- + 60 LYH = 21 + IF (ISTATE .EQ. 1) NYH = N + LWM = LYH + (MAXORD + 1)*NYH + IF (MITER .EQ. 0) LENWK = 0 + IF (MITER .EQ. 1) LENWK = N*(MAXL+2) + MAXL*MAXL + IF (MITER .EQ. 2) + 1 LENWK = N*(MAXL+2+MIN(1,MAXL-KMP)) + (MAXL+3)*MAXL + 1 + IF (MITER .EQ. 3 .OR. MITER .EQ. 4) LENWK = 5*N + IF (MITER .EQ. 9) LENWK = 2*N + LWP = 0 + IF (MITER .GE. 1) LWP = IWORK(1) + LENWM = LENWK + LWP + LOCWP = LENWK + 1 + LEWT = LWM + LENWM + LSAVF = LEWT + N + LSAVX = LSAVF + N + LACOR = LSAVX + N + IF (MITER .EQ. 0) LACOR = LSAVF + N + LENRW = LACOR + N - 1 + IWORK(17) = LENRW + LIWM = 31 + LENIWK = 0 + IF (MITER .EQ. 1) LENIWK = MAXL + LIWP = 0 + IF (MITER .GE. 1) LIWP = IWORK(2) + LENIW = 30 + LENIWK + LIWP + LOCIWP = LENIWK + 1 + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 70 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 70 CONTINUE +C Load SQRT(N) and its reciprocal in Common. --------------------------- + SQRTN = SQRT(REAL(N)) + RSQRTN = 1.0D0/SQRTN + IF (ISTATE .EQ. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTODPK. ------ + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 90 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into SAVF. --------- + DO 80 I = 1,N + 80 RWORK(I+LSAVF-1) = RWORK(I+LWM-1) + 90 CONTINUE + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 110 JSTART = 0 + NHNIL = 0 + NST = 0 + NJE = 0 + NSLAST = 0 + NLI0 = 0 + NNI0 = 0 + NCFN0 = 0 + NCFL0 = 0 + NWARN = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 + NNI = 0 + NLI = 0 + NPS = 0 + NCFN = 0 + NCFL = 0 +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load the initial value vector in YH. --------------------------------- + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 120 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * Sum ( f(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C f(i) = i-th component of initial value of f, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 140 + DO 130 I = 1,N + 130 TOL = MAX(TOL,RTOL(I)) + 140 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LF0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + NLI0 = NLI + NNI0 = NNI + NCFN0 = NCFN + NCFL0 = NCFL + NWARN = 0 + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODPK. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, +C Check for poor Newton/Krylov method performance, update EWT (if not +C at start of problem), check for too much accuracy being requested, +C and check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + NSTD = NST - NSLAST + NNID = NNI - NNI0 + IF (NSTD .LT. 10 .OR. NNID .EQ. 0) GO TO 255 + AVDIM = REAL(NLI - NLI0)/REAL(NNID) + RCFN = REAL(NCFN - NCFN0)/REAL(NSTD) + RCFL = REAL(NCFL - NCFL0)/REAL(NNID) + LAVD = AVDIM .GT. (MAXL - 0.05D0) + LCFN = RCFN .GT. 0.9D0 + LCFL = RCFL .GT. 0.9D0 + LWARN = LAVD .OR. LCFN .OR. LCFL + IF (.NOT.LWARN) GO TO 255 + NWARN = NWARN + 1 + IF (NWARN .GT. 10) GO TO 255 + IF (LAVD) THEN + MSG='DLSODPK- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 111, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LAVD) THEN + MSG=' at T = R1 by average no. of linear iterations = R2 ' + CALL XERRWD (MSG, 60, 111, 0, 0, 0, 0, 2, TN, AVDIM) + ENDIF + IF (LCFN) THEN + MSG='DLSODPK- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 112, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LCFN) THEN + MSG=' at T = R1 by nonlinear convergence failure rate = R2 ' + CALL XERRWD (MSG, 60, 112, 0, 0, 0, 0, 2, TN, RCFN) + ENDIF + IF (LCFL) THEN + MSG='DLSODPK- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 113, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LCFL) THEN + MSG=' at T = R1 by linear convergence failure rate = R2 ' + CALL XERRWD (MSG, 60, 113, 0, 0, 0, 0, 2, TN, RCFL) + ENDIF + 255 CONTINUE + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODPK- Warning..Internal T(=R1) and H(=R2) are ' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODPK- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODPK(NEQ,Y,YH,NYH,YH,EWT,SAVF,SAVX,ACOR,WM,IWM,F,JAC,PSOL) +C----------------------------------------------------------------------- + CALL DSTODPK (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LSAVX), RWORK(LACOR), RWORK(LWM), + 2 IWORK(LIWM), F, JAC, PSOL) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 550), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. see if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODPK. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNI + IWORK(20) = NLI + IWORK(21) = NPS + IWORK(22) = NCFN + IWORK(23) = NCFL + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODPK- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODPK- At T (=R1), EWT(I1) has become R2.le.0. ' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODPK- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODPK- At T(=R1), step size H(=R2), the error ' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODPK- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 560 +C KFLAG = -3. Unrecoverable error from PSOL. -------------------------- + 550 MSG = 'DLSODPK- At T (=R1) an unrecoverable error return' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' was made from Subroutine PSOL ' + CALL XERRWD (MSG, 40, 205, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNI + IWORK(20) = NLI + IWORK(21) = NPS + IWORK(22) = NCFN + IWORK(23) = NCFL + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODPK- ISTATE(=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODPK- ITASK (=I1) illegal.' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODPK- ISTATE.gt.1 but DLSODPK not initialized.' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODPK- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODPK- ISTATE = 3 and NEQ increased (I1 to I2).' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODPK- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODPK- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODPK- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODPK- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODPK- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODPK- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODPK- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODPK- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODPK- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSODPK- RWORK length needed, LENRW(=I1), exceeds LRW(=I2) ' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSODPK- IWORK length needed, LENIW(=I1), exceeds LIW(=I2) ' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODPK- RTOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODPK- ATOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODPK- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODPK- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODPK- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODPK- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODPK- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODPK- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODPK- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODPK- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODPK --------------------- + END +*DECK DLSODKR + SUBROUTINE DLSODKR (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, + 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, PSOL, + 2 MF, G, NG, JROOT) + EXTERNAL F, JAC, PSOL, G + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF, + 1 NG, JROOT + DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW), + 1 JROOT(*) +C----------------------------------------------------------------------- +C This is the 18 November 2003 version of +C DLSODKR: Livermore Solver for Ordinary Differential equations, +C with preconditioned Krylov iteration methods for the +C Newton correction linear systems, and with Rootfinding. +C +C This version is in double precision. +C +C DLSODKR solves the initial value problem for stiff or nonstiff +C systems of first order ODEs, +C dy/dt = f(t,y) , or, in component form, +C dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(NEQ)) (i = 1,...,NEQ). +C At the same time, it locates the roots of any of a set of functions +C g(i) = g(i,t,y(1),...,y(NEQ)) (i = 1,...,ng). +C +C----------------------------------------------------------------------- +C Introduction. +C +C This is a modification of the DLSODE package, and differs from it +C in five ways: +C (a) It uses various preconditioned Krylov subspace iteration methods +C for the linear algebraic systems that arise in the case of stiff +C systems. See the introductory notes below. +C (b) It does automatic switching between functional (fixpoint) +C iteration and Newton iteration in the corrector iteration. +C (c) It finds the root of at least one of a set of constraint +C functions g(i) of the independent and dependent variables. +C It finds only those roots for which some g(i), as a function +C of t, changes sign in the interval of integration. +C It then returns the solution at the root, if that occurs +C sooner than the specified stop condition, and otherwise returns +C the solution according the specified stop condition. +C (d) It supplies to JAC an input flag, JOK, which indicates whether +C JAC may (optionally) bypass the evaluation of Jacobian matrix data +C and instead process saved data (with the current value of scalar hl0). +C (e) It contains a new subroutine that calculates the initial step +C size to be attempted. +C +C +C Introduction to the Krylov methods in DLSODKR: +C +C The linear systems that must be solved have the form +C A * x = b , where A = identity - hl0 * (df/dy) . +C Here hl0 is a scalar, and df/dy is the Jacobian matrix of partial +C derivatives of f (NEQ by NEQ). +C +C The particular Krylov method is chosen by setting the second digit, +C MITER, in the method flag MF. +C Currently, the values of MITER have the following meanings: +C +C MITER = 1 means the Scaled Preconditioned Incomplete +C Orthogonalization Method (SPIOM). +C +C 2 means an incomplete version of the preconditioned scaled +C Generalized Minimal Residual method (SPIGMR). +C This is the best choice in general. +C +C 3 means the Preconditioned Conjugate Gradient method (PCG). +C Recommended only when df/dy is symmetric or nearly so. +C +C 4 means the scaled Preconditioned Conjugate Gradient method +C (PCGS). Recommended only when D-inverse * df/dy * D is +C symmetric or nearly so, where D is the diagonal scaling +C matrix with elements 1/EWT(i) (see RTOL/ATOL description). +C +C 9 means that only a user-supplied matrix P (approximating A) +C will be used, with no Krylov iteration done. This option +C allows the user to provide the complete linear system +C solution algorithm, if desired. +C +C The user can apply preconditioning to the linear system A*x = b, +C by means of arbitrary matrices (the preconditioners). +C In the case of SPIOM and SPIGMR, one can apply left and right +C preconditioners P1 and P2, and the basic iterative method is then +C applied to the matrix (P1-inverse)*A*(P2-inverse) instead of to the +C matrix A. The product P1*P2 should be an approximation to matrix A +C such that linear systems with P1 or P2 are easier to solve than with +C A. Preconditioning from the left only or right only means using +C P2 = identity or P1 = identity, respectively. +C In the case of the PCG and PCGS methods, there is only one +C preconditioner matrix P (but it can be the product of more than one). +C It should approximate the matrix A but allow for relatively +C easy solution of linear systems with coefficient matrix P. +C For PCG, P should be positive definite symmetric, or nearly so, +C and for PCGS, the scaled preconditioner D-inverse * P * D +C should be symmetric or nearly so. +C If the Jacobian J = df/dy splits in a natural way into a sum +C J = J1 + J2, then one possible choice of preconditioners is +C P1 = identity - hl0 * J1 and P2 = identity - hl0 * J2 +C provided each of these is easy to solve (or approximately solve). +C +C----------------------------------------------------------------------- +C References: +C 1. Peter N. Brown and Alan C. Hindmarsh, Reduced Storage Matrix +C Methods in Stiff ODE Systems, J. Appl. Math. & Comp., 31 (1989), +C pp. 40-91; also L.L.N.L. Report UCRL-95088, Rev. 1, June 1987. +C 2. Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C----------------------------------------------------------------------- +C Authors: Alan C. Hindmarsh and Peter N. Brown +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODKR package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the demonstration +C program distributed with this solver. +C +C A. First provide a subroutine of the form: +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C which supplies the vector function f by loading YDOT(i) with f(i). +C +C B. Provide a subroutine of the form: +C SUBROUTINE G (NEQ, T, Y, NG, GOUT) +C DOUBLE PRECISION T, Y(*), GOUT(NG) +C which supplies the vector function g by loading GOUT(i) with +C g(i), the i-th constraint function whose root is sought. +C +C C. Next determine (or guess) whether or not the problem is stiff. +C Stiffness occurs when the Jacobian matrix df/dy has an eigenvalue +C whose real part is negative and large in magnitude, compared to the +C reciprocal of the t span of interest. If the problem is nonstiff, +C use a method flag MF = 10. If it is stiff, MF should be between 21 +C and 24, or possibly 29. MF = 22 is generally the best choice. +C Use 23 or 24 only if symmetry is present. Use MF = 29 if the +C complete linear system solution is to be provided by the user. +C The following four parameters must also be set. +C IWORK(1) = LWP = length of real array WP for preconditioning. +C IWORK(2) = LIWP = length of integer array IWP for preconditioning. +C IWORK(3) = JPRE = preconditioner type flag: +C = 0 for no preconditioning (P1 = P2 = P = identity) +C = 1 for left-only preconditioning (P2 = identity) +C = 2 for right-only preconditioning (P1 = identity) +C = 3 for two-sided preconditioning (and PCG or PCGS) +C IWORK(4) = JACFLG = flag for whether JAC is called. +C = 0 if JAC is not to be called, +C = 1 if JAC is to be called. +C Use JACFLG = 1 if JAC computes any nonconstant data for use in +C preconditioning, such as Jacobian elements. +C The arrays WP and IWP are work arrays under the user's control, +C for use in the routines that perform preconditioning operations. +C +C D. If the problem is stiff, you must supply two routines that deal +C with the preconditioning of the linear systems to be solved. +C These are as follows: +C +C SUBROUTINE JAC (F, NEQ, T, Y, YSV, REWT, FTY,V,HL0,JOK,WP,IWP,IER) +C DOUBLE PRECISION T, Y(*), YSV(*), REWT(*), FTY(*), V(*), HL0,WP(*) +C INTEGER IWP(*) +C This routine must evaluate and preprocess any parts of the +C Jacobian matrix df/dy involved in the preconditioners P1, P2, P. +C The Y and FTY arrays contain the current values of y and f(t,y), +C respectively, and YSV also contains the current value of y. +C The array V is work space of length NEQ. +C JAC must multiply all computed Jacobian elements by the scalar +C -HL0, add the identity matrix, and do any factorization +C operations called for, in preparation for solving linear systems +C with a coefficient matrix of P1, P2, or P. The matrix P1*P2 or P +C should be an approximation to identity - hl0 * (df/dy). +C JAC should return IER = 0 if successful, and IER .ne. 0 if not. +C (If IER .ne. 0, a smaller time step will be tried.) +C JAC may alter Y and V, but not YSV, REWT, FTY, or HL0. +C The JOK argument can be ignored (or see full description below). +C +C SUBROUTINE PSOL (NEQ, T, Y, FTY, WK, HL0, WP, IWP, B, LR, IER) +C DOUBLE PRECISION T, Y(*), FTY(*), WK(*), HL0, WP(*), B(*) +C INTEGER IWP(*) +C This routine must solve a linear system with B as right-hand +C side and one of the preconditioning matrices, P1, P2, or P, as +C coefficient matrix, and return the solution vector in B. +C LR is a flag concerning left vs right preconditioning, input +C to PSOL. PSOL is to use P1 if LR = 1 and P2 if LR = 2. +C In the case of the PCG or PCGS method, LR will be 3, and PSOL +C should solve the system P*x = B with the preconditioner matrix P. +C In the case MF = 29 (no Krylov iteration), LR will be 0, +C and PSOL is to return in B the desired approximate solution +C to A * x = B, where A = identity - hl0 * (df/dy). +C PSOL can use data generated in the JAC routine and stored in +C WP and IWP. WK is a work array of length NEQ. +C The argument HL0 is the current value of the scalar appearing +C in the linear system. If the old value, at the time of the last +C JAC call, is needed, it must have been saved by JAC in WP. +C on return, PSOL should set the error flag IER as follows: +C IER = 0 if PSOL was successful, +C IER .gt. 0 if a recoverable error occurred, meaning that the +C time step will be retried, +C IER .lt. 0 if an unrecoverable error occurred, meaning that the +C solver is to stop immediately. +C +C E. Write a main program which calls Subroutine DLSODKR once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages +C by DLSODKR. On the first call to DLSODKR, supply arguments as +C follows: +C F = name of subroutine for right-hand side vector f. +C This name must be declared External in calling program. +C NEQ = number of first order ODEs. +C Y = array of initial values, of length NEQ. +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C The estimated local error in y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: Actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 20 + 16*NEQ + 3*NG for MF = 10, +C 45 + 17*NEQ + 3*NG + LWP for MF = 21, +C 61 + 17*NEQ + 3*NG + LWP for MF = 22, +C 20 + 15*NEQ + 3*NG + LWP for MF = 23 or 24, +C 20 + 12*NEQ + 3*NG + LWP for MF = 29. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least: +C 30 for MF = 10, +C 35 + LIWP for MF = 21, +C 30 + LIWP for MF = 22, 23, 24, or 29. +C LIW = declared length of IWORK (in user's dimension). +C JAC,PSOL = names of subroutines for preconditioning. +C These names must be declared External in the calling program. +C MF = method flag. Standard values are: +C 10 for nonstiff (Adams) method. +C 21 for stiff (BDF) method, with preconditioned SIOM. +C 22 for stiff method, with preconditioned GMRES method. +C 23 for stiff method, with preconditioned CG method. +C 24 for stiff method, with scaled preconditioned CG method. +C 29 for stiff method, with user's PSOL routine only. +C G = name of subroutine for constraint functions, whose +C roots are desired during the integration. +C This name must be declared External in calling program. +C NG = number of constraint functions g(i). If there are none, +C set NG = 0, and pass a dummy name for G. +C JROOT = integer array of length NG for output of root information. +C See next paragraph. +C Note that the main program must declare arrays Y, RWORK, IWORK, +C JROOT, and possibly ATOL. +C +C F. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 or 3 if DLSODKR was successful, negative otherwise. +C 2 means no root was found, and TOUT was reached as desired. +C 3 means a root was found prior to reaching TOUT. +C -1 means excess work done on this call (perhaps wrong MF). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad JAC +C or PSOL routine supplied or wrong choice of MF or +C tolerances, or this solver is inappropriate). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 means an unrecoverable error occurred in PSOL. +C JROOT = array showing roots found if ISTATE = 3 on return. +C JROOT(i) = 1 if g(i) has a root at T, or 0 otherwise. +C +C G. To continue the integration after a successful return, proceed +C as follows: +C (a) If ISTATE = 2 on return, reset TOUT and call DLSODKR again. +C (b) If ISTATE = 3 on return, reset ISTATE to 2 and call DLSODKR again. +C In either case, no other parameters need be reset. +C +C----------------------------------------------------------------------- +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODKR. +C +C The user interface to DLSODKR consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODKR, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODKR package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODKR package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, PSOL, MF, +C G, and NG, +C that used only for output is JROOT, +C and those used for both input and output are +C Y, T, ISTATE. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODKR to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C F = the name of the user-supplied subroutine defining the +C ODE system. The system must be put in the first-order +C form dy/dt = f(t,y), where f is a vector-valued function +C of the scalar t and the vector y. Subroutine F is to +C compute the function f. It is to have the form +C SUBROUTINE F (NEQ, T, Y, YDOT) +C DOUBLE PRECISION T, Y(*), YDOT(*) +C where NEQ, T, and Y are input, and the array YDOT = f(t,y) +C is output. Y and YDOT are arrays of length NEQ. +C Subroutine F should not alter Y(1),...,Y(NEQ). +C F must be declared External in the calling program. +C +C Subroutine F may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in F) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y below. +C +C If quantities computed in the F routine are needed +C externally to DLSODKR, an extra call to F should be made +C for this purpose, for consistent and accurate results. +C If only the derivative dy/dt is needed, use DINTDY instead. +C +C NEQ = the size of the ODE system (number of first order +C ordinary differential equations). Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in the user-supplied routines. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODKR package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to the user-supplied routines. Hence, if it is an array, +C locations NEQ(2),... may be used to store other integer data +C and pass it to the user-supplied routines. Each such routine +C must include NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 1), and only for output on other calls. +C On the first call, Y must contain the vector of initial +C values. On output, Y contains the computed solution vector, +C evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to F, G, +C JAC, and PSOL. Hence its length may exceed NEQ, and +C locations Y(NEQ+1),... may be used to store other real data +C and pass it to the user-supplied routines. +C (The DLSODKR package accesses only Y(1),...,Y(NEQ).) +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution y is evaluated (usually the same as TOUT). +C If a root was found, T is the computed location of the +C root reached first, on output. +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 1), TOUT may be equal +C to T for one call, then should .ne. T for the next call. +C For the initial T, an input value of TOUT .ne. T is used +C in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array array RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at T = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C the state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 1 means this is the first call for the problem +C (initializations will be done). See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, +C and any of the optional inputs except H0. +C In addition, immediately following a return with +C ISTATE = 3 (root found), NG and G may be changed. +C (But changing NG from 0 to .gt. 0 is not allowed.) +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 1 means nothing was done; TOUT = T and ISTATE = 1 on input. +C 2 means the integration was performed successfully. +C 3 means the integration was successful, and one or more +C roots were found before satisfying the stop condition +C specified by ITASK. See JROOT. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means the PSOL routine returned an unrecoverable error +C flag (IER .lt. 0). The integration was successful as +C far as T. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real working array (double precision). +C The length of RWORK must be at least +C 20 + NYH*(MAXORD+1) + 3*NEQ + 3*NG + LENLS + LWP where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LENLS = length of work space for linear system (Krylov) +C method, excluding preconditioning: +C LENLS = 0 if MITER = 0, +C LENLS = NEQ*(MAXL+3) + MAXL**2 if MITER = 1, +C LENLS = NEQ*(MAXL+3+MIN(1,MAXL-KMP)) +C + (MAXL+3)*MAXL + 1 if MITER = 2, +C LENLS = 6*NEQ if MITER = 3 or 4, +C LENLS = 3*NEQ if MITER = 9. +C (See the MF description for METH and MITER, and the +C list of optional inputs for MAXL and KMP.) +C LWP = length of real user work space for preconditioning +C (see JAC/PSOL). +C Thus if default values are used and NEQ is constant, +C this length is: +C 20 + 16*NEQ + 3*NG for MF = 10, +C 45 + 24*NEQ + 3*NG + LWP for MF = 11, +C 61 + 24*NEQ + 3*NG + LWP for MF = 12, +C 20 + 22*NEQ + 3*NG + LWP for MF = 13 or 14, +C 20 + 19*NEQ + 3*NG + LWP for MF = 19, +C 20 + 9*NEQ + 3*NG for MF = 20, +C 45 + 17*NEQ + 3*NG + LWP for MF = 21, +C 61 + 17*NEQ + 3*NG + LWP for MF = 22, +C 20 + 15*NEQ + 3*NG + LWP for MF = 23 or 24, +C 20 + 12*NEQ + 3*NG + LWP for MF = 29. +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 30 if MITER = 0 (MF = 10 or 20), +C 30 + MAXL + LIWP if MITER = 1 (MF = 11, 21), +C 30 + LIWP if MITER = 2, 3, 4, or 9. +C MAXL = 5 unless a different optional input value is given. +C LIWP = length of integer user work space for preconditioning +C (see conditional input list following). +C The first few words of IWORK are used for conditional and +C optional inputs and optional outputs. +C +C The following 4 words in IWORK are conditional inputs, +C required if MITER .ge. 1: +C IWORK(1) = LWP = length of real array WP for use in +C preconditioning (part of RWORK array). +C IWORK(2) = LIWP = length of integer array IWP for use in +C preconditioning (part of IWORK array). +C The arrays WP and IWP are work arrays under the +C user's control, for use in the routines that +C perform preconditioning operations (JAC and PSOL). +C IWORK(3) = JPRE = preconditioner type flag: +C = 0 for no preconditioning (P1 = P2 = P = identity) +C = 1 for left-only preconditioning (P2 = identity) +C = 2 for right-only preconditioning (P1 = identity) +C = 3 for two-sided preconditioning (and PCG or PCGS) +C IWORK(4) = JACFLG = flag for whether JAC is called. +C = 0 if JAC is not to be called, +C = 1 if JAC is to be called. +C Use JACFLG = 1 if JAC computes any nonconstant +C data needed in preconditioning operations, +C such as some of the Jacobian elements. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODKR +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODKR between calls, if +C desired (but not for use by any of the user-supplied routines). +C +C JAC = the name of the user-supplied routine to compute any +C Jacobian elements (or approximations) involved in the +C matrix preconditioning operations (MITER .ge. 1). +C It is to have the form +C SUBROUTINE JAC (F, NEQ, T, Y, YSV, REWT, FTY, V, +C 1 HL0, JOK, WP, IWP, IER) +C DOUBLE PRECISION T, Y(*), YSV(*), REWT(*), FTY(*), V(*), +C 1 HL0, WP(*) +C INTEGER IWP(*) +C This routine must evaluate and preprocess any parts of the +C Jacobian matrix df/dy used in the preconditioners P1, P2, P. +C The Y and FTY arrays contain the current values of y and +C f(t,y), respectively, and the YSV array also contains +C the current y vector. The array V is work space of length +C NEQ for use by JAC. REWT is the array of reciprocal error +C weights (1/EWT). JAC must multiply all computed Jacobian +C elements by the scalar -HL0, add the identity matrix, and do +C any factorization operations called for, in preparation +C for solving linear systems with a coefficient matrix of +C P1, P2, or P. The matrix P1*P2 or P should be an +C approximation to identity - hl0 * (df/dy). JAC should +C return IER = 0 if successful, and IER .ne. 0 if not. +C (If IER .ne. 0, a smaller time step will be tried.) +C The arrays WP (of length LWP) and IWP (of length LIWP) +C are for use by JAC and PSOL for work space and for storage +C of data needed for the solution of the preconditioner +C linear systems. Their lengths and contents are under the +C user's control. +C The argument JOK is an input flag for optional use +C by JAC in deciding whether to recompute Jacobian elements +C or use saved values. If JOK = -1, then JAC must compute +C any relevant Jacobian elements (or approximations) used in +C the preconditioners. Optionally, JAC may also save these +C elements for later reuse. If JOK = 1, the integrator has +C made a judgement (based on the convergence history and the +C value of HL0) that JAC need not recompute Jacobian elements, +C but instead use saved values, and the current value of HL0, +C to reconstruct the preconditioner matrices, followed by +C any required factorizations. This may be cost-effective if +C Jacobian elements are costly and storage is available. +C JAC may alter Y and V, but not YSV, REWT, FTY, or HL0. +C JAC must be declared External in the calling program. +C Subroutine JAC may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in JAC) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C PSOL = the name of the user-supplied routine for the +C solution of preconditioner linear systems. +C It is to have the form +C SUBROUTINE PSOL (NEQ, T, Y, FTY, WK,HL0, WP,IWP, B, LR,IER) +C DOUBLE PRECISION T, Y(*), FTY(*), WK(*), HL0, WP(*), B(*) +C INTEGER IWP(*) +C This routine must solve a linear system with B as right-hand +C side and one of the preconditioning matrices, P1, P2, or P, +C as coefficient matrix, and return the solution vector in B. +C LR is a flag concerning left vs right preconditioning, input +C to PSOL. PSOL is to use P1 if LR = 1 and P2 if LR = 2. +C In the case of the PCG or PCGS method, LR will be 3, and PSOL +C should solve the system P*x = B with the preconditioner P. +C In the case MITER = 9 (no Krylov iteration), LR will be 0, +C and PSOL is to return in B the desired approximate solution +C to A * x = B, where A = identity - hl0 * (df/dy). +C PSOL can use data generated in the JAC routine and stored in +C WP and IWP. +C The Y and FTY arrays contain the current values of y and +C f(t,y), respectively. The array WK is work space of length +C NEQ for use by PSOL. +C The argument HL0 is the current value of the scalar appearing +C in the linear system. If the old value, as of the last +C JAC call, is needed, it must have been saved by JAC in WP. +C On return, PSOL should set the error flag IER as follows: +C IER = 0 if PSOL was successful, +C IER .gt. 0 on a recoverable error, meaning that the +C time step will be retried, +C IER .lt. 0 on an unrecoverable error, meaning that the +C solver is to stop immediately. +C PSOL may not alter Y, FTY, or HL0. +C PSOL must be declared External in the calling program. +C Subroutine PSOL may access user-defined quantities in +C NEQ(2),... and Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in PSOL) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C MF = the method flag. Used only for input. The legal values of +C MF are 10, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, and 29. +C MF has decimal digits METH and MITER: MF = 10*METH + MITER. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFs). +C MITER indicates the corrector iteration method: +C MITER = 0 means functional iteration (no linear system +C is involved). +C MITER = 1 means Newton iteration with Scaled Preconditioned +C Incomplete Orthogonalization Method (SPIOM) +C for the linear systems. +C MITER = 2 means Newton iteration with Scaled Preconditioned +C Incomplete Generalized Minimal Residual method +C (SPIGMR) for the linear systems. +C MITER = 3 means Newton iteration with Preconditioned +C Conjugate Gradient method (PCG) +C for the linear systems. +C MITER = 4 means Newton iteration with scaled preconditioned +C Conjugate Gradient method (PCGS) +C for the linear systems. +C MITER = 9 means Newton iteration with only the +C user-supplied PSOL routine called (no Krylov +C iteration) for the linear systems. +C JPRE is ignored, and PSOL is called with LR = 0. +C See comments in the introduction about the choice of MITER. +C If MITER .ge. 1, the user must supply routines JAC and PSOL +C (the names are arbitrary) as described above. +C For MITER = 0, a dummy argument can be used. +C +C G = the name of subroutine for constraint functions, whose +C roots are desired during the integration. It is to have +C the form +C SUBROUTINE G (NEQ, T, Y, NG, GOUT) +C DOUBLE PRECISION T, Y(*), GOUT(NG) +C where NEQ, T, Y, and NG are input, and the array GOUT +C is output. NEQ, T, and Y have the same meaning as in +C the F routine, and GOUT is an array of length NG. +C For i = 1,...,NG, this routine is to load into GOUT(i) +C the value at (t,y) of the i-th constraint function g(i). +C DLSODKR will find roots of the g(i) of odd multiplicity +C (i.e. sign changes) as they occur during the integration. +C G must be declared External in the calling program. +C +C Caution: Because of numerical errors in the functions +C g(i) due to roundoff and integration error, DLSODKR may +C return false roots, or return the same root at two or more +C nearly equal values of t. If such false roots are +C suspected, the user should consider smaller error tolerances +C and/or higher precision in the evaluation of the g(i). +C +C If a root of some g(i) defines the end of the problem, +C the input to DLSODKR should nevertheless allow integration +C to a point slightly past that root, so that DLSODKR can +C locate the root by interpolation. +C +C Subroutine G may access user-defined quantities in +C NEQ(2),... and Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in G) and/or Y has length exceeding NEQ(1). +C See the descriptions of NEQ and Y above. +C +C NG = number of constraint functions g(i). If there are none, +C set NG = 0, and pass a dummy name for G. +C +C JROOT = integer array of length NG. Used only for output. +C On a return with ISTATE = 3 (one or more roots found), +C JROOT(i) = 1 if g(i) has a root at t, or JROOT(i) = 0 if not. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C DELT RWORK(8) convergence test constant in Krylov iteration +C algorithm. The default is .05. +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C +C MAXL IWORK(8) maximum number of iterations in the SPIOM, SPIGMR, +C PCG, or PCGS algorithm (.le. NEQ). +C The default is MAXL = MIN(5,NEQ). +C +C KMP IWORK(9) number of vectors on which orthogonalization +C is done in SPIOM or SPIGMR algorithm (.le. MAXL). +C The default is KMP = MAXL. +C Note: When KMP .lt. MAXL and MF = 22, the length +C of RWORK must be defined accordingly. See +C the definition of RWORK above. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODKR, the variables listed +C below are quantities related to the performance of DLSODKR +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODKR, and on any return with +C ISTATE = -1, -2, -4, -5, -6, or -7. On an illegal input return +C (ISTATE = -3), they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NGE IWORK(10) the number of g evaluations for the problem so far. +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NFE IWORK(12) the number of f evaluations for the problem so far. +C +C NPE IWORK(13) the number of calls to JAC so far (for evaluation +C of preconditioners). +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C NNI IWORK(19) number of nonlinear iterations so far (each of +C which calls an iterative linear solver). +C +C NLI IWORK(20) number of linear iterations so far. +C Note: A measure of the success of algorithm is +C the average number of linear iterations per +C nonlinear iteration, given by NLI/NNI. +C If this is close to MAXL, MAXL may be too small. +C +C NPS IWORK(21) number of preconditioning solve operations +C (PSOL calls) so far. +C +C NCFN IWORK(22) number of convergence failures of the nonlinear +C (Newton) iteration so far. +C Note: A measure of success is the overall +C rate of nonlinear convergence failures, NCFN/NST. +C +C NCFL IWORK(23) number of convergence failures of the linear +C iteration so far. +C Note: A measure of success is the overall +C rate of linear convergence failures, NCFL/NNI. +C +C NSFI IWORK(24) number of functional iteration steps so far. +C Note: A measure of the extent to which the +C problem is nonstiff is the ratio NSFI/NST. +C +C NJEV IWORK(25) number of JAC calls with JOK = -1 so far +C (number of evaluations of Jacobian data). +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 + 3*NG the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output +C to represent the estimated local error in y +C on the last step. This is the vector E in +C the description of the error control. It is +C defined only on a successful return from +C DLSODKR. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODKR. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODKR, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODKR. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCKR(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODKR (see Part 3 below). +C RSAV must be a real array of length 228 +C or more, and ISAV must be an integer +C array of length 63 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCKR is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODKR. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODKR. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C LYH = 21 + 3*NG +C CALL DINTDY (T, K, RWORK(LYH), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODKR). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(T), is already provided +C by DLSODKR directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C LYH = 21 + 3*NG = base address in RWORK of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODKR is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODKR, and +C (2) the four internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLS002/ of length 5 (1 double precision word +C followed by 4 integer words), +C /DLPK01/ of length 17 (4 double precision words +C followed by 13 integer words), +C /DLSR01/ of length 14 (5 double precision words +C followed by 9 integer words). +C +C If DLSODKR is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODKR is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODKR call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODKR call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCKR (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below are descriptions of two routines in the DLSODKR package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODKR call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSODKR in the computation +C of the optional output IMXER, the diagonal Jacobian approximation, +C and the increments for difference quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where: +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSODKR. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*W(i)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19900117 DATE WRITTEN +C 19900503 Added iteration switching (functional/Newton). +C 19900802 Added flag for Jacobian-saving in user preconditioner. +C 19900910 Added new initial stepsize routine LHIN. +C 19901019 Corrected LHIN - y array restored. +C 19910909 Changed names STOPK to STOKA, PKSET to SETPK; +C removed unused variables in driver declarations; +C minor corrections to main prologue. +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20030603 Corrected duplicate type declaration for DUMACH. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C 20031117 Changed internal name NPE to NJE. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODKR package. +C +C In addition to Subroutine DLSODKR, the DLSODKR package includes the +C following subroutines and function routines: +C DLHIN calculates a step size to be attempted initially. +C DRCHEK does preliminary checking for roots, and serves as an +C interface between Subroutine DLSODKR and Subroutine DROOTS. +C DROOTS finds the leftmost root of a set of functions. +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSTOKA is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DSETPK interfaces between DSTOKA and the JAC routine. +C DSOLPK manages solution of linear system in Newton iteration. +C DSPIOM performs the SPIOM algorithm. +C DATV computes a scaled, preconditioned product (I-hl0*J)*v. +C DORTHOG orthogonalizes a vector against previous basis vectors. +C DHEFA generates an LU factorization of a Hessenberg matrix. +C DHESL solves a Hessenberg square linear system. +C DSPIGMR performs the SPIGMR algorithm. +C DHEQR generates a QR factorization of a Hessenberg matrix. +C DHELS finds the least squares solution of a Hessenberg system. +C DPCG performs preconditioned conjugate gradient algorithm (PCG). +C DPCGS performs the PCGS algorithm. +C DATP computes the product A*p, where A = I - hl0*df/dy. +C DUSOL interfaces to the user's PSOL routine (MITER = 9). +C DSRCKR is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DAXPY, DCOPY, DDOT, DNRM2, and DSCAL are basic linear +C algebra modules (from the BLAS collection). +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DDOT, DNRM2, DUMACH, IXSAV, and IUMACH are function +C routines. All the others are subroutines. +C +C----------------------------------------------------------------------- + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER NEWT, NSFI, NSLJ, NJEV + INTEGER LG0, LG1, LGX, IOWNR3, IRFND, ITASKC, NGC, NGE + INTEGER JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 1 NNI, NLI, NPS, NCFN, NCFL + INTEGER I, I1, I2, IER, IFLAG, IMXER, KGO, LF0, + 1 LENIW, LENIWK, LENRW, LENWM, LENWK, LIWP, LWP, MORD, MXHNL0, + 2 MXSTP0, NCFN0, NCFL0, NITER, NLI0, NNI0, NNID, NSTD, NWARN + INTEGER IRFP, IRT, LENYH, LYHNEW + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION STIFR + DOUBLE PRECISION ROWNR3, T0, TLAST, TOUTC + DOUBLE PRECISION DELT, EPCON, SQRTN, RSQRTN + DOUBLE PRECISION ATOLI, AVDIM, BIG, EWTI, H0, HMAX, HMX, RCFL, + 1 RCFN, RH, RTOLI, TCRIT, TNEXT, TOLSF, TP, SIZE + DIMENSION MORD(2) + LOGICAL IHIT, LAVD, LCFN, LCFL, LWARN + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following four internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODKR, DINTDY, +C DSTOKA, DSOLPK, and DATV. +C The block DLS002 is declared in subroutines DLSODKR and DSTOKA. +C The block DLSR01 is declared in subroutines DLSODKR, DRCHEK, DROOTS. +C The block DLPK01 is declared in subroutines DLSODKR, DSTOKA, DSETPK, +C and DSOLPK. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLS002/ STIFR, NEWT, NSFI, NSLJ, NJEV +C + COMMON /DLSR01/ ROWNR3(2), T0, TLAST, TOUTC, + 1 LG0, LG1, LGX, IOWNR3(2), IRFND, ITASKC, NGC, NGE +C + COMMON /DLPK01/ DELT, EPCON, SQRTN, RSQRTN, + 1 JPRE, JACFLG, LOCWP, LOCIWP, LSAVX, KMP, MAXL, MNEWT, + 2 NNI, NLI, NPS, NCFN, NCFL +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + ITASKC = ITASK + IF (ISTATE .EQ. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 1), +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, MF, +C and NG. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .EQ. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + METH = MF/10 + MITER = MF - 10*METH + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 0) GO TO 608 + IF (MITER .GT. 4 .AND. MITER .LT. 9) GO TO 608 + IF (MITER .GE. 1) JPRE = IWORK(3) + JACFLG = 0 + IF (MITER .GE. 1) JACFLG = IWORK(4) + IF (NG .LT. 0) GO TO 630 + IF (ISTATE .EQ. 1) GO TO 35 + IF (IRFND .EQ. 0 .AND. NG .NE. NGC) GO TO 631 + 35 NGC = NG +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .EQ. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + MAXL = MIN(5,N) + KMP = MAXL + DELT = 0.05D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .NE. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 + MAXL = IWORK(8) + IF (MAXL .EQ. 0) MAXL = 5 + MAXL = MIN(MAXL,N) + KMP = IWORK(9) + IF (KMP .EQ. 0 .OR. KMP .GT. MAXL) KMP = MAXL + DELT = RWORK(8) + IF (DELT .EQ. 0.0D0) DELT = 0.05D0 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C RWORK segments (in order) are denoted G0, G1, GX, YH, WM, +C EWT, SAVF, SAVX, ACOR. +C----------------------------------------------------------------------- + 60 IF (ISTATE .EQ. 1) NYH = N + LG0 = 21 + LG1 = LG0 + NG + LGX = LG1 + NG + LYHNEW = LGX + NG + IF (ISTATE .EQ. 1) LYH = LYHNEW + IF (LYHNEW .EQ. LYH) GO TO 62 +C If ISTATE = 3 and NG was changed, shift YH to its new location. ------ + LENYH = L*NYH + IF (LRW .LT. LYHNEW-1+LENYH) GO TO 62 + I1 = 1 + IF (LYHNEW .GT. LYH) I1 = -1 + CALL DCOPY (LENYH, RWORK(LYH), I1, RWORK(LYHNEW), I1) + LYH = LYHNEW + 62 CONTINUE + LWM = LYH + (MAXORD + 1)*NYH + IF (MITER .EQ. 0) LENWK = 0 + IF (MITER .EQ. 1) LENWK = N*(MAXL+2) + MAXL*MAXL + IF (MITER .EQ. 2) + 1 LENWK = N*(MAXL+2+MIN(1,MAXL-KMP)) + (MAXL+3)*MAXL + 1 + IF (MITER .EQ. 3 .OR. MITER .EQ. 4) LENWK = 5*N + IF (MITER .EQ. 9) LENWK = 2*N + LWP = 0 + IF (MITER .GE. 1) LWP = IWORK(1) + LENWM = LENWK + LWP + LOCWP = LENWK + 1 + LEWT = LWM + LENWM + LSAVF = LEWT + N + LSAVX = LSAVF + N + LACOR = LSAVX + N + IF (MITER .EQ. 0) LACOR = LSAVF + N + LENRW = LACOR + N - 1 + IWORK(17) = LENRW + LIWM = 31 + LENIWK = 0 + IF (MITER .EQ. 1) LENIWK = MAXL + LIWP = 0 + IF (MITER .GE. 1) LIWP = IWORK(2) + LENIW = 30 + LENIWK + LIWP + LOCIWP = LENIWK + 1 + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 70 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 70 CONTINUE +C Load SQRT(N) and its reciprocal in Common. --------------------------- + SQRTN = SQRT(REAL(N)) + RSQRTN = 1.0D0/SQRTN + IF (ISTATE .EQ. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTOKA.-------- + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 90 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into SAVF. --------- + DO 80 I = 1,N + 80 RWORK(I+LSAVF-1) = RWORK(I+LWM-1) + 90 CONTINUE + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 1). +C It contains all remaining initializations, the initial call to F, +C and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 110 JSTART = 0 + NHNIL = 0 + NST = 0 + NJE = 0 + NSLAST = 0 + NLI0 = 0 + NNI0 = 0 + NCFN0 = 0 + NCFL0 = 0 + NWARN = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 + NNI = 0 + NLI = 0 + NPS = 0 + NCFN = 0 + NCFL = 0 + NSFI = 0 + NJEV = 0 +C Initial call to F. (LF0 points to YH(*,2).) ------------------------- + LF0 = LYH + NYH + CALL F (NEQ, T, Y, RWORK(LF0)) + NFE = 1 +C Load the initial value vector in YH. --------------------------------- + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 120 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + IF (H0 .NE. 0.0D0) GO TO 180 +C Call DLHIN to set initial step size H0 to be attempted. -------------- + CALL DLHIN (NEQ, N, T, RWORK(LYH), RWORK(LF0), F, TOUT, UROUND, + 1 RWORK(LEWT), ITOL, ATOL, Y, RWORK(LACOR), H0, NITER, IER) + NFE = NFE + NITER + IF (IER .NE. 0) GO TO 622 +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) +C Check for a zero of g at T. ------------------------------------------ + IRFND = 0 + TOUTC = TOUT + IF (NGC .EQ. 0) GO TO 270 + CALL DRCHEK (1, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .EQ. 0) GO TO 270 + GO TO 632 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C First, DRCHEK is called to check for a root within the last step +C taken, other than the last root found there, if any. +C If ITASK = 2 or 5, and y(TN) has not yet been returned to the user +C because of an intervening root, return through Block G. +C----------------------------------------------------------------------- + 200 NSLAST = NST +C + IRFP = IRFND + IF (NGC .EQ. 0) GO TO 205 + IF (ITASK .EQ. 1 .OR. ITASK .EQ. 4) TOUTC = TOUT + CALL DRCHEK (2, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .NE. 1) GO TO 205 + IRFND = 1 + ISTATE = 3 + T = T0 + GO TO 425 + 205 CONTINUE + IRFND = 0 + IF (IRFP .EQ. 1 .AND. TLAST .NE. TN .AND. ITASK .EQ. 2) GO TO 400 +C + NLI0 = NLI + NNI0 = NNI + NCFN0 = NCFN + NCFL0 = NCFL + NWARN = 0 + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) T = TCRIT + IF (IRFP .EQ. 1 .AND. TLAST .NE. TN .AND. ITASK .EQ. 5) GO TO 400 + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTOKA. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, +C check for poor Newton/Krylov method performance, update EWT (if not +C at start of problem), check for too much accuracy being requested, +C and check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + NSTD = NST - NSLAST + NNID = NNI - NNI0 + IF (NSTD .LT. 10 .OR. NNID .EQ. 0) GO TO 255 + AVDIM = REAL(NLI - NLI0)/REAL(NNID) + RCFN = REAL(NCFN - NCFN0)/REAL(NSTD) + RCFL = REAL(NCFL - NCFL0)/REAL(NNID) + LAVD = AVDIM .GT. (MAXL - 0.05D0) + LCFN = RCFN .GT. 0.9D0 + LCFL = RCFL .GT. 0.9D0 + LWARN = LAVD .OR. LCFN .OR. LCFL + IF (.NOT.LWARN) GO TO 255 + NWARN = NWARN + 1 + IF (NWARN .GT. 10) GO TO 255 + IF (LAVD) THEN + MSG='DLSODKR- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 111, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LAVD) THEN + MSG=' at T = R1 by average no. of linear iterations = R2 ' + CALL XERRWD (MSG, 60, 111, 0, 0, 0, 0, 2, TN, AVDIM) + ENDIF + IF (LCFN) THEN + MSG='DLSODKR- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 112, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LCFN) THEN + MSG=' at T = R1 by nonlinear convergence failure rate = R2 ' + CALL XERRWD (MSG, 60, 112, 0, 0, 0, 0, 2, TN, RCFN) + ENDIF + IF (LCFL) THEN + MSG='DLSODKR- Warning. Poor iterative algorithm performance seen ' + CALL XERRWD (MSG, 60, 113, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (LCFL) THEN + MSG=' at T = R1 by linear convergence failure rate = R2 ' + CALL XERRWD (MSG, 60, 113, 0, 0, 0, 0, 2, TN, RCFL) + ENDIF + 255 CONTINUE + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODKR- Warning.. Internal T(=R1) and H(=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODKR- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTOKA(NEQ,Y,YH,NYH,YH,EWT,SAVF,SAVX,ACOR,WM,IWM,F,JAC,PSOL) +C----------------------------------------------------------------------- + CALL DSTOKA (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 RWORK(LSAVF), RWORK(LSAVX), RWORK(LACOR), RWORK(LWM), + 2 IWORK(LIWM), F, JAC, PSOL) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 550), KGO +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). +C Call DRCHEK to check for a root within the last step. +C Then, if no root was found, check for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 +C + IF (NGC .EQ. 0) GO TO 315 + CALL DRCHEK (3, G, NEQ, Y, RWORK(LYH), NYH, + 1 RWORK(LG0), RWORK(LG1), RWORK(LGX), JROOT, IRT) + IF (IRT .NE. 1) GO TO 315 + IRFND = 1 + ISTATE = 3 + T = T0 + GO TO 425 + 315 CONTINUE +C + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODKR. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + 425 CONTINUE + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNI + IWORK(20) = NLI + IWORK(21) = NPS + IWORK(22) = NCFN + IWORK(23) = NCFL + IWORK(24) = NSFI + IWORK(25) = NJEV + IWORK(10) = NGE + TLAST = T + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODKR- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODKR- At T(=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 580 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODKR- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 580 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODKR- At T(=R1) and step size H(=R2), the error' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 560 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODKR- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 580 +C KFLAG = -3. Unrecoverable error from PSOL. -------------------------- + 550 MSG = 'DLSODKR- At T (=R1) an unrecoverable error return' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' was made from Subroutine PSOL ' + CALL XERRWD (MSG, 40, 206, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 580 +C Compute IMXER if relevant. ------------------------------------------- + 560 BIG = 0.0D0 + IMXER = 1 + DO 570 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 570 + BIG = SIZE + IMXER = I + 570 CONTINUE + IWORK(16) = IMXER +C Set Y vector, T, and optional outputs. ------------------------------- + 580 DO 590 I = 1,N + 590 Y(I) = RWORK(I+LYH-1) + T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNI + IWORK(20) = NLI + IWORK(21) = NPS + IWORK(22) = NCFN + IWORK(23) = NCFL + IWORK(24) = NSFI + IWORK(25) = NJEV + IWORK(10) = NGE + TLAST = T + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODKR- ISTATE(=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODKR- ITASK (=I1) illegal.' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODKR- ISTATE.gt.1 but DLSODKR not initialized. ' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODKR- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODKR- ISTATE = 3 and NEQ increased (I1 to I2).' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODKR- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODKR- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODKR- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODKR- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODKR- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODKR- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODKR- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODKR- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODKR- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSODKR- RWORK length needed, LENRW(=I1), exceeds LRW(=I2) ' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSODKR- IWORK length needed, LENIW(=I1), exceeds LIW(=I2) ' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODKR- RTOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODKR- ATOL(I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODKR- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODKR- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODKR- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODKR- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODKR- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODKR- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODKR- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) + GO TO 700 + 630 MSG = 'DLSODKR- NG (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 30, 0, 1, NG, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 631 MSG = 'DLSODKR- NG changed (from I1 to I2) illegally, ' + CALL XERRWD (MSG, 50, 31, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' i.e. not immediately after a root was found.' + CALL XERRWD (MSG, 50, 31, 0, 2, NGC, NG, 0, 0.0D0, 0.0D0) + GO TO 700 + 632 MSG = 'DLSODKR- One or more components of g has a root ' + CALL XERRWD (MSG, 50, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' too near to the initial point. ' + CALL XERRWD (MSG, 40, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODKR- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODKR --------------------- + END +*DECK DLSODI + SUBROUTINE DLSODI (RES, ADDA, JAC, NEQ, Y, YDOTI, T, TOUT, ITOL, + 1 RTOL, ATOL, ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, MF ) + EXTERNAL RES, ADDA, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, YDOTI, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), YDOTI(*), RTOL(*), ATOL(*), RWORK(LRW), + 1 IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 18 November 2003 version of +C DLSODI: Livermore Solver for Ordinary Differential Equations +C (Implicit form). +C +C This version is in double precision. +C +C DLSODI solves the initial value problem for linearly implicit +C systems of first order ODEs, +C A(t,y) * dy/dt = g(t,y) , where A(t,y) is a square matrix, +C or, in component form, +C ( a * ( dy / dt )) + ... + ( a * ( dy / dt )) = +C i,1 1 i,NEQ NEQ +C +C = g ( t, y , y ,..., y ) ( i = 1,...,NEQ ) +C i 1 2 NEQ +C +C If A is singular, this is a differential-algebraic system. +C +C DLSODI is a variant version of the DLSODE package. +C----------------------------------------------------------------------- +C Reference: +C Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C----------------------------------------------------------------------- +C Authors: Alan C. Hindmarsh and Jeffrey F. Painter +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODI package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First, provide a subroutine of the form: +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C which computes the residual function +C r = g(t,y) - A(t,y) * s , +C as a function of t and the vectors y and s. (s is an internally +C generated approximation to dy/dt.) The arrays Y and S are inputs +C to the RES routine and should not be altered. The residual +C vector is to be stored in the array R. The argument IRES should be +C ignored for casual use of DLSODI. (For uses of IRES, see the +C paragraph on RES in the full description below.) +C +C B. Next, decide whether full or banded form is more economical +C for the storage of matrices. DLSODI must deal internally with the +C matrices A and dr/dy, where r is the residual function defined above. +C DLSODI generates a linear combination of these two matrices, and +C this is treated in either full or banded form. +C The matrix structure is communicated by a method flag MF, +C which is 21 or 22 for the full case, and 24 or 25 in the band case. +C In the banded case, DLSODI requires two half-bandwidth +C parameters ML and MU. These are, respectively, the widths of the +C lower and upper parts of the band, excluding the main diagonal. +C Thus the band consists of the locations (i,j) with +C i-ML .le. j .le. i+MU, and the full bandwidth is ML+MU+1. +C Note that the band must accommodate the nonzero elements of +C A(t,y), dg/dy, and d(A*s)/dy (s fixed). Alternatively, one +C can define a band that encloses only the elements that are relatively +C large in magnitude, and gain some economy in storage and possibly +C also efficiency, although the appropriate threshhold for +C retaining matrix elements is highly problem-dependent. +C +C C. You must also provide a subroutine of the form: +C SUBROUTINE ADDA (NEQ, T, Y, ML, MU, P, NROWP) +C DOUBLE PRECISION T, Y(*), P(NROWP,*) +C which adds the matrix A = A(t,y) to the contents of the array P. +C T and the Y array are input and should not be altered. +C In the full matrix case, this routine should add elements of +C to P in the usual order. I.e., add A(i,j) to P(i,j). (Ignore the +C ML and MU arguments in this case.) +C In the band matrix case, this routine should add element A(i,j) +C to P(i-j+MU+1,j). I.e., add the diagonal lines of A to the rows of +C P from the top down (the top line of A added to the first row of P). +C +C D. For the sake of efficiency, you are encouraged to supply the +C Jacobian matrix dr/dy in closed form, where r = g(t,y) - A(t,y)*s +C (s = a fixed vector) as above. If dr/dy is being supplied, +C use MF = 21 or 24, and provide a subroutine of the form: +C SUBROUTINE JAC (NEQ, T, Y, S, ML, MU, P, NROWP) +C DOUBLE PRECISION T, Y(*), S(*), P(NROWP,*) +C which computes dr/dy as a function of t, y, and s. Here T, Y, and +C S are inputs, and the routine is to load dr/dy into P as follows: +C In the full matrix case (MF = 21), load P(i,j) with dr(i)/dy(j), +C the partial derivative of r(i) with respect to y(j). (Ignore the +C ML and MU arguments in this case.) +C In the band matrix case (MF = 24), load P(i-j+mu+1,j) with +C dr(i)/dy(j), i.e. load the diagonal lines of dr/dy into the rows of +C P from the top down. +C In either case, only nonzero elements need be loaded, and the +C indexing of P is the same as in the ADDA routine. +C Note that if A is independent of y (or this dependence +C is weak enough to be ignored) then JAC is to compute dg/dy. +C If it is not feasible to provide a JAC routine, use +C MF = 22 or 25, and DLSODI will compute an approximate Jacobian +C internally by difference quotients. +C +C E. Next decide whether or not to provide the initial value of the +C derivative vector dy/dt. If the initial value of A(t,y) is +C nonsingular (and not too ill-conditioned), you may let DLSODI compute +C this vector (ISTATE = 0). (DLSODI will solve the system A*s = g for +C s, with initial values of A and g.) If A(t,y) is initially +C singular, then the system is a differential-algebraic system, and +C you must make use of the particular form of the system to compute the +C initial values of y and dy/dt. In that case, use ISTATE = 1 and +C load the initial value of dy/dt into the array YDOTI. +C The input array YDOTI and the initial Y array must be consistent with +C the equations A*dy/dt = g. This implies that the initial residual +C r = g(t,y) - A(t,y)*YDOTI must be approximately zero. +C +C F. Write a main program which calls Subroutine DLSODI once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages +C by DLSODI. On the first call to DLSODI, supply arguments as follows: +C RES = name of user subroutine for residual function r. +C ADDA = name of user subroutine for computing and adding A(t,y). +C JAC = name of user subroutine for Jacobian matrix dr/dy +C (MF = 21 or 24). If not used, pass a dummy name. +C Note: the names for the RES and ADDA routines and (if used) the +C JAC routine must be declared External in the calling program. +C NEQ = number of scalar equations in the system. +C Y = array of initial values, of length NEQ. +C YDOTI = array of length NEQ (containing initial dy/dt if ISTATE = 1). +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C the estimated local error in y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: Actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1 if the +C initial dy/dt is supplied, and 0 otherwise. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22, +C 22 + 10*NEQ + (2*ML + MU)*NEQ for MF = 24 or 25. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least 20 + NEQ. +C If MF = 24 or 25, input in IWORK(1),IWORK(2) the lower +C and upper half-bandwidths ML,MU. +C LIW = declared length of IWORK (in user's dimension). +C MF = method flag. Standard values are: +C 21 for a user-supplied full Jacobian. +C 22 for an internally generated full Jacobian. +C 24 for a user-supplied banded Jacobian. +C 25 for an internally generated banded Jacobian. +C for other choices of MF, see the paragraph on MF in +C the full description below. +C Note that the main program must declare arrays Y, YDOTI, RWORK, IWORK, +C and possibly ATOL. +C +C G. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSODI was successful, negative otherwise. +C -1 means excess work done on this call (check all inputs). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 cannot occur in casual use. +C -8 means DLSODI was unable to compute the initial dy/dt. +C In casual use, this means A(t,y) is initially singular. +C Supply YDOTI and use ISTATE = 1 on the first call. +C +C If DLSODI returns ISTATE = -1, -4, or -5, then the output of +C DLSODI also includes YDOTI = array containing residual vector +C r = g - A * dy/dt evaluated at the current t, y, and dy/dt. +C +C H. To continue the integration after a successful return, simply +C reset TOUT and call DLSODI again. No other parameters need be reset. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is a simple example problem, with the coding +C needed for its solution by DLSODI. The problem is from chemical +C kinetics, and consists of the following three equations: +C dy1/dt = -.04*y1 + 1.e4*y2*y3 +C dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2 +C 0. = y1 + y2 + y3 - 1. +C on the interval from t = 0.0 to t = 4.e10, with initial conditions +C y1 = 1.0, y2 = y3 = 0. +C +C The following coding solves this problem with DLSODI, using MF = 21 +C and printing results at t = .4, 4., ..., 4.e10. It uses +C ITOL = 2 and ATOL much smaller for y2 than y1 or y3 because +C y2 has much smaller values. dy/dt is supplied in YDOTI. We had +C obtained the initial value of dy3/dt by differentiating the +C third equation and evaluating the first two at t = 0. +C At the end of the run, statistical quantities of interest are +C printed (see optional outputs in the full description below). +C +C EXTERNAL RESID, APLUSP, DGBYDY +C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y, YDOTI +C DIMENSION Y(3), YDOTI(3), ATOL(3), RWORK(58), IWORK(23) +C NEQ = 3 +C Y(1) = 1. +C Y(2) = 0. +C Y(3) = 0. +C YDOTI(1) = -.04 +C YDOTI(2) = .04 +C YDOTI(3) = 0. +C T = 0. +C TOUT = .4 +C ITOL = 2 +C RTOL = 1.D-4 +C ATOL(1) = 1.D-6 +C ATOL(2) = 1.D-10 +C ATOL(3) = 1.D-6 +C ITASK = 1 +C ISTATE = 1 +C IOPT = 0 +C LRW = 58 +C LIW = 23 +C MF = 21 +C DO 40 IOUT = 1,12 +C CALL DLSODI(RESID, APLUSP, DGBYDY, NEQ, Y, YDOTI, T, TOUT, ITOL, +C 1 RTOL, ATOL, ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, MF) +C WRITE (6,20) T, Y(1), Y(2), Y(3) +C 20 FORMAT(' At t =',D12.4,' Y =',3D14.6) +C IF (ISTATE .LT. 0 ) GO TO 80 +C 40 TOUT = TOUT*10. +C WRITE (6,60) IWORK(11), IWORK(12), IWORK(13) +C 60 FORMAT(/' No. steps =',I4,' No. r-s =',I4,' No. J-s =',I4) +C STOP +C 80 WRITE (6,90) ISTATE +C 90 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE RESID(NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y, S, R +C DIMENSION Y(3), S(3), R(3) +C R(1) = -.04*Y(1) + 1.D4*Y(2)*Y(3) - S(1) +C R(2) = .04*Y(1) - 1.D4*Y(2)*Y(3) - 3.D7*Y(2)*Y(2) - S(2) +C R(3) = Y(1) + Y(2) + Y(3) - 1. +C RETURN +C END +C +C SUBROUTINE APLUSP(NEQ, T, Y, ML, MU, P, NROWP) +C DOUBLE PRECISION T, Y, P +C DIMENSION Y(3), P(NROWP,3) +C P(1,1) = P(1,1) + 1. +C P(2,2) = P(2,2) + 1. +C RETURN +C END +C +C SUBROUTINE DGBYDY(NEQ, T, Y, S, ML, MU, P, NROWP) +C DOUBLE PRECISION T, Y, S, P +C DIMENSION Y(3), S(3), P(NROWP,3) +C P(1,1) = -.04 +C P(1,2) = 1.D4*Y(3) +C P(1,3) = 1.D4*Y(2) +C P(2,1) = .04 +C P(2,2) = -1.D4*Y(3) - 6.D7*Y(2) +C P(2,3) = -1.D4*Y(2) +C P(3,1) = 1. +C P(3,2) = 1. +C P(3,3) = 1. +C RETURN +C END +C +C The output of this program (on a CDC-7600 in single precision) +C is as follows: +C +C At t = 4.0000e-01 Y = 9.851726e-01 3.386406e-05 1.479357e-02 +C At t = 4.0000e+00 Y = 9.055142e-01 2.240418e-05 9.446344e-02 +C At t = 4.0000e+01 Y = 7.158050e-01 9.184616e-06 2.841858e-01 +C At t = 4.0000e+02 Y = 4.504846e-01 3.222434e-06 5.495122e-01 +C At t = 4.0000e+03 Y = 1.831701e-01 8.940379e-07 8.168290e-01 +C At t = 4.0000e+04 Y = 3.897016e-02 1.621193e-07 9.610297e-01 +C At t = 4.0000e+05 Y = 4.935213e-03 1.983756e-08 9.950648e-01 +C At t = 4.0000e+06 Y = 5.159269e-04 2.064759e-09 9.994841e-01 +C At t = 4.0000e+07 Y = 5.306413e-05 2.122677e-10 9.999469e-01 +C At t = 4.0000e+08 Y = 5.494532e-06 2.197826e-11 9.999945e-01 +C At t = 4.0000e+09 Y = 5.129457e-07 2.051784e-12 9.999995e-01 +C At t = 4.0000e+10 Y = -7.170472e-08 -2.868188e-13 1.000000e+00 +C +C No. steps = 330 No. r-s = 404 No. J-s = 69 +C +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODI. +C +C The user interface to DLSODI consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODI, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODI package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODI package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C RES, ADDA, JAC, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, +C IOPT, LRW, LIW, MF, +C and those used for both input and output are +C Y, T, ISTATE, YDOTI. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODI to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C RES = the name of the user-supplied subroutine which supplies +C the residual vector for the ODE system, defined by +C r = g(t,y) - A(t,y) * s +C as a function of the scalar t and the vectors +C s and y (s approximates dy/dt). This subroutine +C is to have the form +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C where NEQ, T, Y, S, and IRES are input, and R and +C IRES are output. Y, S, and R are arrays of length NEQ. +C On input, IRES indicates how DLSODI will use the +C returned array R, as follows: +C IRES = 1 means that DLSODI needs the full residual, +C r = g - A*s, exactly. +C IRES = -1 means that DLSODI is using R only to compute +C the Jacobian dr/dy by difference quotients. +C The RES routine can ignore IRES, or it can omit some terms +C if IRES = -1. If A does not depend on y, then RES can +C just return R = g when IRES = -1. If g - A*s contains other +C additive terms that are independent of y, these can also be +C dropped, if done consistently, when IRES = -1. +C The subroutine should set the flag IRES if it +C encounters a halt condition or illegal input. +C Otherwise, it should not reset IRES. On output, +C IRES = 1 or -1 represents a normal return, and +C DLSODI continues integrating the ODE. Leave IRES +C unchanged from its input value. +C IRES = 2 tells DLSODI to immediately return control +C to the calling program, with ISTATE = 3. This lets +C the calling program change parameters of the problem, +C if necessary. +C IRES = 3 represents an error condition (for example, an +C illegal value of y). DLSODI tries to integrate the system +C without getting IRES = 3 from RES. If it cannot, DLSODI +C returns with ISTATE = -7 or -1. +C On an DLSODI return with ISTATE = 3, -1, or -7, the values +C of T and Y returned correspond to the last point reached +C successfully without getting the flag IRES = 2 or 3. +C The flag values IRES = 2 and 3 should not be used to +C handle switches or root-stop conditions. This is better +C done by calling DLSODI in a one-step mode and checking the +C stopping function for a sign change at each step. +C If quantities computed in the RES routine are needed +C externally to DLSODI, an extra call to RES should be made +C for this purpose, for consistent and accurate results. +C To get the current dy/dt for the S argument, use DINTDY. +C RES must be declared External in the calling +C program. See note below for more about RES. +C +C ADDA = the name of the user-supplied subroutine which adds the +C matrix A = A(t,y) to another matrix stored in the same form +C as A. The storage form is determined by MITER (see MF). +C This subroutine is to have the form +C SUBROUTINE ADDA (NEQ, T, Y, ML, MU, P, NROWP) +C DOUBLE PRECISION T, Y(*), P(NROWP,*) +C where NEQ, T, Y, ML, MU, and NROWP are input and P is +C output. Y is an array of length NEQ, and the matrix P is +C stored in an NROWP by NEQ array. +C In the full matrix case ( MITER = 1 or 2) ADDA should +C add A to P(i,j). ML and MU are ignored. +C i,j +C In the band matrix case ( MITER = 4 or 5) ADDA should +C add A to P(i-j+MU+1,j). +C i,j +C See JAC for details on this band storage form. +C ADDA must be declared External in the calling program. +C See note below for more information about ADDA. +C +C JAC = the name of the user-supplied subroutine which supplies the +C Jacobian matrix, dr/dy, where r = g - A*s. The form of the +C Jacobian matrix is determined by MITER. JAC is required +C if MITER = 1 or 4 -- otherwise a dummy name can be +C passed. This subroutine is to have the form +C SUBROUTINE JAC ( NEQ, T, Y, S, ML, MU, P, NROWP ) +C DOUBLE PRECISION T, Y(*), S(*), P(NROWP,*) +C where NEQ, T, Y, S, ML, MU, and NROWP are input and P +C is output. Y and S are arrays of length NEQ, and the +C matrix P is stored in an NROWP by NEQ array. +C P is to be loaded with partial derivatives (elements +C of the Jacobian matrix) on output. +C In the full matrix case (MITER = 1), ML and MU +C are ignored and the Jacobian is to be loaded into P +C by columns-- i.e., dr(i)/dy(j) is loaded into P(i,j). +C In the band matrix case (MITER = 4), the elements +C within the band are to be loaded into P by columns, +C with diagonal lines of dr/dy loaded into the +C rows of P. Thus dr(i)/dy(j) is to be loaded +C into P(i-j+MU+1,j). The locations in P in the two +C triangular areas which correspond to nonexistent matrix +C elements can be ignored or loaded arbitrarily, as they +C they are overwritten by DLSODI. ML and MU are the +C half-bandwidth parameters (see IWORK). +C In either case, P is preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Each call to JAC is preceded by a call to RES with the same +C arguments NEQ, T, Y, and S. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may be +C saved in a user Common block by RES and not recomputed by JAC +C if desired. Also, JAC may alter the Y array, if desired. +C JAC need not provide dr/dy exactly. A crude +C approximation (possibly with a smaller bandwidth) will do. +C JAC must be declared External in the calling program. +C See note below for more about JAC. +C +C Note on RES, ADDA, and JAC: +C These subroutines may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in the subroutines) and/or Y has length +C exceeding NEQ(1). However, these routines should not alter +C NEQ(1), Y(1),...,Y(NEQ) or any other input variables. +C See the descriptions of NEQ and Y below. +C +C NEQ = the size of the system (number of first order ordinary +C differential equations or scalar algebraic equations). +C Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in RES, ADDA, or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODI package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to RES, ADDA, and JAC. Hence, if it is an array, +C locations NEQ(2),... may be used to store other integer data +C and pass it to RES, ADDA, or JAC. Each such subroutine +C must include NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 0 or 1), and only for output on other +C calls. On the first call, Y must contain the vector of +C initial values. On output, Y contains the computed solution +C vector, evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to RES, +C ADDA, and JAC. Hence its length may exceed NEQ, +C and locations Y(NEQ+1),... may be used to store other real +C data and pass it to RES, ADDA, or JAC. (The DLSODI +C package accesses only Y(1),...,Y(NEQ). ) +C +C YDOTI = a real array for the initial value of the vector +C dy/dt and for work space, of dimension at least NEQ. +C +C On input: +C If ISTATE = 0, then DLSODI will compute the initial value +C of dy/dt, if A is nonsingular. Thus YDOTI will +C serve only as work space and may have any value. +C If ISTATE = 1, then YDOTI must contain the initial value +C of dy/dt. +C If ISTATE = 2 or 3 (continuation calls), then YDOTI +C may have any value. +C Note: If the initial value of A is singular, then +C DLSODI cannot compute the initial value of dy/dt, so +C it must be provided in YDOTI, with ISTATE = 1. +C +C On output, when DLSODI terminates abnormally with ISTATE = +C -1, -4, or -5, YDOTI will contain the residual +C r = g(t,y) - A(t,y)*(dy/dt). If r is large, t is near +C its initial value, and YDOTI is supplied with ISTATE = 1, +C then there may have been an incorrect input value of +C YDOTI = dy/dt, or the problem (as given to DLSODI) +C may not have a solution. +C +C If desired, the YDOTI array may be used for other +C purposes between calls to the solver. +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution Y is evaluated (usually the same as TOUT). +C on an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 0 or 1), TOUT may be +C equal to T for one call, then should .ne. T for the next +C call. For the initial T, an input value of TOUT .ne. T is +C used in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array scalar RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 0 means this is the first call for the problem, and +C DLSODI is to compute the initial value of dy/dt +C (while doing other initializations). See note below. +C 1 means this is the first call for the problem, and +C the initial value of dy/dt has been supplied in +C YDOTI (DLSODI will do other initializations). See note +C below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, ML, MU, +C and any of the optional inputs except H0. +C (See IWORK description for ML and MU.) +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 0 or 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 0 or 1 means nothing was done; TOUT = t and +C ISTATE = 0 or 1 on input. +C 2 means that the integration was performed successfully. +C 3 means that the user-supplied Subroutine RES signalled +C DLSODI to halt the integration and return (IRES = 2). +C Integration as far as T was achieved with no occurrence +C of IRES = 2, but this flag was set on attempting the +C next step. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix. +C -6 means EWT(i) became zero for some i during the +C integration. pure relative error control (ATOL(i)=0.0) +C was requested on a variable which has now vanished. +C the integration was successful as far as T. +C -7 means that the user-supplied Subroutine RES set +C its error flag (IRES = 3) despite repeated tries by +C DLSODI to avoid that condition. +C -8 means that ISTATE was 0 on input but DLSODI was unable +C to compute the initial value of dy/dt. See the +C printed message for details. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Similarly, ISTATE (= 3) need not be reset if RES told +C DLSODI to return because the calling program must change +C the parameters of the problem. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real working array (double precision). +C The length of RWORK must be at least +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LENWM where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LENWM = NEQ**2 + 2 if MITER is 1 or 2, and +C LENWM = (2*ML+MU+1)*NEQ + 2 if MITER is 4 or 5. +C (See MF description for the definition of METH and MITER.) +C Thus if MAXORD has its default value and NEQ is constant, +C this length is +C 22 + 16*NEQ + NEQ**2 for MF = 11 or 12, +C 22 + 17*NEQ + (2*ML+MU)*NEQ for MF = 14 or 15, +C 22 + 9*NEQ + NEQ**2 for MF = 21 or 22, +C 22 + 10*NEQ + (2*ML+MU)*NEQ for MF = 24 or 25. +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 20 + NEQ . The first few words of IWORK are used for +C conditional and optional inputs and optional outputs. +C +C The following 2 words in IWORK are conditional inputs: +C IWORK(1) = ML These are the lower and upper +C IWORK(2) = MU half-bandwidths, respectively, of the +C matrices in the problem-- the Jacobian dr/dy +C and the left-hand side matrix A. These +C half-bandwidths exclude the main diagonal, +C so the total bandwidth is ML + MU + 1 . +C The band is defined by the matrix locations +C (i,j) with i-ML .le. j .le. i+MU. ML and MU +C must satisfy 0 .le. ML,MU .le. NEQ-1. +C These are required if MITER is 4 or 5, and +C ignored otherwise. +C ML and MU may in fact be the band parameters +C for matrices to which dr/dy and A are only +C approximately equal. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODI +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODI between calls, if +C desired (but not for use by RES, ADDA, or JAC). +C +C MF = the method flag. Used only for input. The legal values of +C MF are 11, 12, 14, 15, 21, 22, 24, and 25. +C MF has decimal digits METH and MITER: MF = 10*METH + MITER. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFs). +C The BDF method is strongly preferred for stiff +C problems, while the Adams method is preferred when +C the problem is not stiff. If the matrix A(t,y) is +C nonsingular, stiffness here can be taken to mean that of +C the explicit ODE system dy/dt = A-inverse * g. If A is +C singular, the concept of stiffness is not well defined. +C If you do not know whether the problem is stiff, we +C recommend using METH = 2. If it is stiff, the advantage +C of METH = 2 over METH = 1 will be great, while if it is +C not stiff, the advantage of METH = 1 will be slight. +C If maximum efficiency is important, some experimentation +C with METH may be necessary. +C MITER indicates the corrector iteration method: +C MITER = 1 means chord iteration with a user-supplied +C full (NEQ by NEQ) Jacobian. +C MITER = 2 means chord iteration with an internally +C generated (difference quotient) full Jacobian. +C This uses NEQ+1 extra calls to RES per dr/dy +C evaluation. +C MITER = 4 means chord iteration with a user-supplied +C banded Jacobian. +C MITER = 5 means chord iteration with an internally +C generated banded Jacobian (using ML+MU+2 +C extra calls to RES per dr/dy evaluation). +C If MITER = 1 or 4, the user must supply a Subroutine JAC +C (the name is arbitrary) as described above under JAC. +C For other values of MITER, a dummy argument can be used. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C the use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODI, the variables listed +C below are quantities related to the performance of DLSODI +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODI, and on any return with +C ISTATE = -1, -2, -4, -5, -6, or -7. On a return with -3 (illegal +C input) or -8, they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NRE IWORK(12) the number of residual evaluations (RES calls) +C for the problem so far. +C +C NJE IWORK(13) the number of Jacobian evaluations (each involving +C an evaluation of A and dr/dy) for the problem so +C far. This equals the number of calls to ADDA and +C (if MITER = 1 or 4) JAC, and the number of matrix +C LU decompositions. +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output to +C represent the estimated local error in y on the +C last step. This is the vector E in the descrip- +C tion of the error control. It is defined only +C on a return from DLSODI with ISTATE = 2. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODI. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODI, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODI. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCOM(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODI (see Part 3 below). +C RSAV must be a real array of length 218 +C or more, and ISAV must be an integer +C array of length 37 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCOM is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODI. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODI. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODI). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(T), is already provided +C by DLSODI directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C RWORK(21) = the base address of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODI is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODI, and +C (2) the internal Common block +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C +C If DLSODI is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common block in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODI is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODI call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODI call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCOM (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below are descriptions of two routines in the DLSODI package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODI call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSODI in the computation +C of the optional output IMXER, the diagonal Jacobian approximation, +C and the increments for difference quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where: +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSODI. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*W(i)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19800424 DATE WRITTEN +C 19800519 Corrected access of YH on forced order reduction; +C numerous corrections to prologues and other comments. +C 19800617 In main driver, added loading of SQRT(UROUND) in RWORK; +C minor corrections to main prologue. +C 19800903 Corrected ISTATE logic; minor changes in prologue. +C 19800923 Added zero initialization of HU and NQU. +C 19801028 Reorganized RES calls in AINVG, STODI, and PREPJI; +C in LSODI, corrected NRE increment and reset LDY0 at 580; +C numerous corrections to main prologue. +C 19801218 Revised XERRWD routine; minor corrections to main prologue. +C 19810330 Added Common block /LSI001/; use LSODE's INTDY and SOLSY; +C minor corrections to XERRWD and error message at 604; +C minor corrections to declarations; corrections to prologues. +C 19810818 Numerous revisions: replaced EWT by 1/EWT; used flags +C JCUR, ICF, IERPJ, IERSL between STODI and subordinates; +C added tuning parameters CCMAX, MAXCOR, MSBP, MXNCF; +C reorganized returns from STODI; reorganized type decls.; +C fixed message length in XERRWD; changed default LUNIT to 6; +C changed Common lengths; changed comments throughout. +C 19820906 Corrected use of ABS(H) in STODI; minor comment fixes. +C 19830510 Numerous revisions: revised diff. quotient increment; +C eliminated block /LSI001/, using IERPJ flag; +C revised STODI logic after PJAC return; +C revised tuning of H change and step attempts in STODI; +C corrections to main prologue and internal comments. +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODI; +C in STODI, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C converted arithmetic IF statements to logical IF statements; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20031105 Restored 'own' variables to Common block, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C 20031117 Changed internal names NRE, LSAVR to NFE, LSAVF resp. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODI package. +C +C In addition to Subroutine DLSODI, the DLSODI package includes the +C following subroutines and function routines: +C DAINVG computes the initial value of the vector +C dy/dt = A-inverse * g +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODI is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPREPJI computes and preprocesses the Jacobian matrix +C and the Newton iteration matrix P. +C DSOLSY manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSRCOM is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DGEFA and DGESL are routines from LINPACK for solving full +C systems of linear algebraic equations. +C DGBFA and DGBSL are routines from LINPACK for solving banded +C linear systems. +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DUMACH, IXSAV, and IUMACH are function routines. +C All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPREPJI, DSOLSY + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, I2, IER, IFLAG, IMXER, IRES, KGO, + 1 LENIW, LENRW, LENWM, LP, LYD0, ML, MORD, MU, MXHNL0, MXSTP0 + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following internal Common block contains +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODI, DINTDY, DSTODI, +C DPREPJI, and DSOLSY. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 0 or 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 0 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .LE. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 0 or 1) +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C MF, ML, and MU. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .LE. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + METH = MF/10 + MITER = MF - 10*METH + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LE. 0 .OR. MITER .GT. 5) GO TO 608 + IF (MITER .EQ. 3) GO TO 608 + IF (MITER .LT. 3) GO TO 30 + ML = IWORK(1) + MU = IWORK(2) + IF (ML .LT. 0 .OR. ML .GE. N) GO TO 609 + IF (MU .LT. 0 .OR. MU .GE. N) GO TO 610 + 30 CONTINUE +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .LE. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .GT. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted YH, WM, EWT, SAVR, ACOR. +C----------------------------------------------------------------------- + 60 LYH = 21 + IF (ISTATE .LE. 1) NYH = N + LWM = LYH + (MAXORD + 1)*NYH + IF (MITER .LE. 2) LENWM = N*N + 2 + IF (MITER .GE. 4) LENWM = (2*ML + MU + 1)*N + 2 + LEWT = LWM + LENWM + LSAVF = LEWT + N + LACOR = LSAVF + N + LENRW = LACOR + N - 1 + IWORK(17) = LENRW + LIWM = 1 + LENIW = 20 + N + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 70 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 70 CONTINUE + IF (ISTATE .LE. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTODI. ------- + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 90 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into YDOTI.--------- + DO 80 I = 1,N + 80 YDOTI(I) = RWORK(I+LWM-1) +C Reload WM(1) = RWORK(lWM), since lWM may have changed. --------------- + 90 RWORK(LWM) = SQRT(UROUND) + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 0 or 1). +C It contains all remaining initializations, the call to DAINVG +C (if ISTATE = 1), and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 105 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 105 JSTART = 0 + RWORK(LWM) = SQRT(UROUND) + NHNIL = 0 + NST = 0 + NFE = 0 + NJE = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C Compute initial dy/dt, if necessary, and load it and initial Y into YH + LYD0 = LYH + NYH + LP = LWM + 1 + IF (ISTATE .EQ. 1) GO TO 120 +C DLSODI must compute initial dy/dt (LYD0 points to YH(*,2)). ---------- + CALL DAINVG( RES, ADDA, NEQ, T, Y, RWORK(LYD0), MITER, + 1 ML, MU, RWORK(LP), IWORK(21), IER ) + NFE = NFE + 1 + IF (IER .LT. 0) GO TO 560 + IF (IER .GT. 0) GO TO 565 + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) + GO TO 130 +C Initial dy/dt was supplied. Load into YH (LYD0 points to YH(*,2).). - + 120 DO 125 I = 1,N + RWORK(I+LYH-1) = Y(I) + 125 RWORK(I+LYD0-1) = YDOTI(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + 130 CONTINUE + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 135 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 135 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * Sum ( YDOT(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C YDOT(i) = i-th component of initial value of dy/dt, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 145 + DO 140 I = 1,N + 140 TOL = MAX(TOL,RTOL(I)) + 145 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LYD0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LYD0-1) = H0*RWORK(I+LYD0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODI. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODI- Warning..Internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODI- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODI(NEQ,Y,YH,NYH,YH1,EWT,SAVF,SAVR,ACOR,WM,IWM,RES, +C ADDA,JAC,DPREPJI,DSOLSY) +C Note: SAVF in DSTODI occupies the same space as YDOTI in DLSODI. +C----------------------------------------------------------------------- + CALL DSTODI (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 YDOTI, RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), + 2 IWORK(LIWM), RES, ADDA, JAC, DPREPJI, DSOLSY ) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 400, 550), KGO +C +C KGO = 1:success; 2:error test failure; 3:convergence failure; +C 4:RES ordered return. 5:RES returned error. +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. see if TOUT or TCRIT was reached. adjust h if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODI. +C if ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + IF (KFLAG .EQ. -3) ISTATE = 3 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODI- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODI- At T (=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 590 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODI- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 590 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODI- At T(=R1) and step size H(=R2), the error' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 570 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODI- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 570 +C IRES = 3 returned by RES, despite retries by DSTODI. ----------------- + 550 MSG = 'DLSODI- At T (=R1) residual routine returned ' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' error IRES = 3 repeatedly. ' + CALL XERRWD (MSG, 40, 206, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 590 +C DAINVG failed because matrix A was singular. ------------------------- + 560 IER = -IER + MSG='DLSODI- Attempt to initialize dy/dt failed: Matrix A is ' + CALL XERRWD (MSG, 60, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' singular. DGEFA or DGBFA returned INFO = I1' + CALL XERRWD (MSG, 50, 207, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C DAINVG failed because RES set IRES to 2 or 3. ------------------------ + 565 MSG = 'DLSODI- Attempt to initialize dy/dt failed ' + CALL XERRWD (MSG, 50, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' because residual routine set its error flag ' + CALL XERRWD (MSG, 50, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to IRES = (I1)' + CALL XERRWD (MSG, 20, 208, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C Compute IMXER if relevant. ------------------------------------------- + 570 BIG = 0.0D0 + IMXER = 1 + DO 575 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 575 + BIG = SIZE + IMXER = I + 575 CONTINUE + IWORK(16) = IMXER +C Compute residual if relevant. ---------------------------------------- + 580 LYD0 = LYH + NYH + DO 585 I = 1,N + RWORK(I+LSAVF-1) = RWORK(I+LYD0-1)/H + 585 Y(I) = RWORK(I+LYH-1) + IRES = 1 + CALL RES (NEQ, TN, Y, RWORK(LSAVF), YDOTI, IRES ) + NFE = NFE + 1 + IF (IRES .LE. 1) GO TO 595 + MSG = 'DLSODI- Residual routine set its flag IRES ' + CALL XERRWD (MSG, 50, 210, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to (I1) when called for final output. ' + CALL XERRWD (MSG, 50, 210, 0, 1, IRES, 0, 0, 0.0D0, 0.0D0) + GO TO 595 +C Set Y vector, T, and optional outputs. ------------------------------- + 590 DO 592 I = 1,N + 592 Y(I) = RWORK(I+LYH-1) + 595 T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODI- ISTATE (=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODI- ITASK (=I1) illegal. ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODI- ISTATE .gt. 1 but DLSODI not initialized.' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODI- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODI- ISTATE = 3 and NEQ increased (I1 to I2). ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODI- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODI- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODI- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSODI- ML(=I1) illegal: .lt. 0 or .ge. NEQ(=I2) ' + CALL XERRWD (MSG, 50, 9, 0, 2, ML, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 610 MSG = 'DLSODI- MU(=I1) illegal: .lt. 0 or .ge. NEQ(=I2) ' + CALL XERRWD (MSG, 50, 10, 0, 2, MU, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODI- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODI- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODI- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODI- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODI- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODI- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSODI- RWORK length needed, LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSODI- IWORK length needed, LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODI- RTOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODI- ATOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODI- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODI- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODI- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODI- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODI- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODI- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODI- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODI- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODI ---------------------- + END +*DECK DLSOIBT + SUBROUTINE DLSOIBT (RES, ADDA, JAC, NEQ, Y, YDOTI, T, TOUT, ITOL, + 1 RTOL, ATOL, ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, MF ) + EXTERNAL RES, ADDA, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, YDOTI, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), YDOTI(*), RTOL(*), ATOL(*), RWORK(LRW), + 1 IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 18 November 2003 version of +C DLSOIBT: Livermore Solver for Ordinary differential equations given +C in Implicit form, with Block-Tridiagonal Jacobian treatment. +C +C This version is in double precision. +C +C DLSOIBT solves the initial value problem for linearly implicit +C systems of first order ODEs, +C A(t,y) * dy/dt = g(t,y) , where A(t,y) is a square matrix, +C or, in component form, +C ( a * ( dy / dt )) + ... + ( a * ( dy / dt )) = +C i,1 1 i,NEQ NEQ +C +C = g ( t, y , y ,..., y ) ( i = 1,...,NEQ ) +C i 1 2 NEQ +C +C If A is singular, this is a differential-algebraic system. +C +C DLSOIBT is a variant version of the DLSODI package, for the case where +C the matrices A, dg/dy, and d(A*s)/dy are all block-tridiagonal. +C----------------------------------------------------------------------- +C Reference: +C Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE +C Solvers, in Scientific Computing, R. S. Stepleman et al. (Eds.), +C North-Holland, Amsterdam, 1983, pp. 55-64. +C----------------------------------------------------------------------- +C Authors: Alan C. Hindmarsh and Jeffrey F. Painter +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C and +C Charles S. Kenney +C formerly at: Naval Weapons Center +C China Lake, CA 93555 +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSOIBT package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First, provide a subroutine of the form: +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C which computes the residual function +C r = g(t,y) - A(t,y) * s , +C as a function of t and the vectors y and s. (s is an internally +C generated approximation to dy/dt.) The arrays Y and S are inputs +C to the RES routine and should not be altered. The residual +C vector is to be stored in the array R. The argument IRES should be +C ignored for casual use of DLSOIBT. (For uses of IRES, see the +C paragraph on RES in the full description below.) +C +C B. Next, identify the block structure of the matrices A = A(t,y) and +C dr/dy. DLSOIBT must deal internally with a linear combination, P, of +C these two matrices. The matrix P (hence both A and dr/dy) must have +C a block-tridiagonal form with fixed structure parameters +C MB = block size, MB .ge. 1, and +C NB = number of blocks in each direction, NB .ge. 4, +C with MB*NB = NEQ. In each of the NB block-rows of the matrix P +C (each consisting of MB consecutive rows), the nonzero elements are +C to lie in three consecutive MB by MB blocks. In block-rows +C 2 through NB - 1, these are centered about the main diagonal. +C in block-rows 1 and NB, they are the diagonal blocks and the two +C blocks adjacent to the diagonal block. (Thus block positions (1,3) +C and (NB,NB-2) can be nonzero.) +C Alternatively, P (hence A and dr/dy) may be only approximately +C equal to matrices with this form, and DLSOIBT should still succeed. +C The block-tridiagonal matrix P is described by three arrays, +C each of size MB by MB by NB: +C PA = array of diagonal blocks, +C PB = array of superdiagonal (and one subdiagonal) blocks, and +C PC = array of subdiagonal (and one superdiagonal) blocks. +C Specifically, the three MB by MB blocks in the k-th block-row of P +C are stored in (reading across): +C PC(*,*,k) = block to the left of the diagonal block, +C PA(*,*,k) = diagonal block, and +C PB(*,*,k) = block to the right of the diagonal block, +C except for k = 1, where the three blocks (reading across) are +C PA(*,*,1) (= diagonal block), PB(*,*,1), and PC(*,*,1), +C and k = NB, where they are +C PB(*,*,NB), PC(*,*,NB), and PA(*,*,NB) (= diagonal block). +C (Each asterisk * stands for an index that ranges from 1 to MB.) +C +C C. You must also provide a subroutine of the form: +C SUBROUTINE ADDA (NEQ, T, Y, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y(*), PA(MB,MB,NB), PB(MB,MB,NB), PC(MB,MB,NB) +C which adds the nonzero blocks of the matrix A = A(t,y) to the +C contents of the arrays PA, PB, and PC, following the structure +C description in Paragraph B above. +C T and the Y array are input and should not be altered. +C Thus the affect of ADDA should be the following: +C DO 30 K = 1,NB +C DO 20 J = 1,MB +C DO 10 I = 1,MB +C PA(I,J,K) = PA(I,J,K) + +C ( (I,J) element of K-th diagonal block of A) +C PB(I,J,K) = PB(I,J,K) + +C ( (I,J) element of block in block position (K,K+1) of A, +C or in block position (NB,NB-2) if K = NB) +C PC(I,J,K) = PC(I,J,K) + +C ( (I,J) element of block in block position (K,K-1) of A, +C or in block position (1,3) if K = 1) +C 10 CONTINUE +C 20 CONTINUE +C 30 CONTINUE +C +C D. For the sake of efficiency, you are encouraged to supply the +C Jacobian matrix dr/dy in closed form, where r = g(t,y) - A(t,y)*s +C (s = a fixed vector) as above. If dr/dy is being supplied, +C use MF = 21, and provide a subroutine of the form: +C SUBROUTINE JAC (NEQ, T, Y, S, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y(*), S(*), PA(MB,MB,NB), PB(MB,MB,NB), +C 1 PC(MB,MB,NB) +C which computes dr/dy as a function of t, y, and s. Here T, Y, and +C S are inputs, and the routine is to load dr/dy into PA, PB, PC, +C according to the structure description in Paragraph B above. +C That is, load the diagonal blocks into PA, the superdiagonal blocks +C (and block (NB,NB-2) ) into PB, and the subdiagonal blocks (and +C block (1,3) ) into PC. The blocks in block-row k of dr/dy are to +C be loaded into PA(*,*,k), PB(*,*,k), and PC(*,*,k). +C Only nonzero elements need be loaded, and the indexing +C of PA, PB, and PC is the same as in the ADDA routine. +C Note that if A is independent of Y (or this dependence +C is weak enough to be ignored) then JAC is to compute dg/dy. +C If it is not feasible to provide a JAC routine, use +C MF = 22, and DLSOIBT will compute an approximate Jacobian +C internally by difference quotients. +C +C E. Next decide whether or not to provide the initial value of the +C derivative vector dy/dt. If the initial value of A(t,y) is +C nonsingular (and not too ill-conditioned), you may let DLSOIBT compute +C this vector (ISTATE = 0). (DLSOIBT will solve the system A*s = g for +C s, with initial values of A and g.) If A(t,y) is initially +C singular, then the system is a differential-algebraic system, and +C you must make use of the particular form of the system to compute the +C initial values of y and dy/dt. In that case, use ISTATE = 1 and +C load the initial value of dy/dt into the array YDOTI. +C The input array YDOTI and the initial Y array must be consistent with +C the equations A*dy/dt = g. This implies that the initial residual +C r = g(t,y) - A(t,y)*YDOTI must be approximately zero. +C +C F. Write a main program which calls Subroutine DLSOIBT once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages by +C DLSOIBT. on the first call to DLSOIBT, supply arguments as follows: +C RES = name of user subroutine for residual function r. +C ADDA = name of user subroutine for computing and adding A(t,y). +C JAC = name of user subroutine for Jacobian matrix dr/dy +C (MF = 21). If not used, pass a dummy name. +C Note: the names for the RES and ADDA routines and (if used) the +C JAC routine must be declared External in the calling program. +C NEQ = number of scalar equations in the system. +C Y = array of initial values, of length NEQ. +C YDOTI = array of length NEQ (containing initial dy/dt if ISTATE = 1). +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C the estimated local error in y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: Actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1 if the +C initial dy/dt is supplied, and 0 otherwise. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 22 + 9*NEQ + 3*MB*MB*NB for MF = 21 or 22. +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least 20 + NEQ. +C Input in IWORK(1) the block size MB and in IWORK(2) the +C number NB of blocks in each direction along the matrix A. +C These must satisfy MB .ge. 1, NB .ge. 4, and MB*NB = NEQ. +C LIW = declared length of IWORK (in user's dimension). +C MF = method flag. Standard values are: +C 21 for a user-supplied Jacobian. +C 22 for an internally generated Jacobian. +C For other choices of MF, see the paragraph on MF in +C the full description below. +C Note that the main program must declare arrays Y, YDOTI, RWORK, IWORK, +C and possibly ATOL. +C +C G. The output from the first call (or any call) is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSOIBT was successful, negative otherwise. +C -1 means excess work done on this call (check all inputs). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 cannot occur in casual use. +C -8 means DLSOIBT was unable to compute the initial dy/dt. +C In casual use, this means A(t,y) is initially singular. +C Supply YDOTI and use ISTATE = 1 on the first call. +C +C If DLSOIBT returns ISTATE = -1, -4, or -5, then the output of +C DLSOIBT also includes YDOTI = array containing residual vector +C r = g - A * dy/dt evaluated at the current t, y, and dy/dt. +C +C H. To continue the integration after a successful return, simply +C reset TOUT and call DLSOIBT again. No other parameters need be reset. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is an example problem, with the coding needed +C for its solution by DLSOIBT. The problem comes from the partial +C differential equation (the Burgers equation) +C du/dt = - u * du/dx + eta * d**2 u/dx**2, eta = .05, +C on -1 .le. x .le. 1. The boundary conditions are +C du/dx = 0 at x = -1 and at x = 1. +C The initial profile is a square wave, +C u = 1 in ABS(x) .lt. .5, u = .5 at ABS(x) = .5, u = 0 elsewhere. +C The PDE is discretized in x by a simplified Galerkin method, +C using piecewise linear basis functions, on a grid of 40 intervals. +C The equations at x = -1 and 1 use a 3-point difference approximation +C for the right-hand side. The result is a system A * dy/dt = g(y), +C of size NEQ = 41, where y(i) is the approximation to u at x = x(i), +C with x(i) = -1 + (i-1)*delx, delx = 2/(NEQ-1) = .05. The individual +C equations in the system are +C dy(1)/dt = ( y(3) - 2*y(2) + y(1) ) * eta / delx**2, +C dy(NEQ)/dt = ( y(NEQ-2) - 2*y(NEQ-1) + y(NEQ) ) * eta / delx**2, +C and for i = 2, 3, ..., NEQ-1, +C (1/6) dy(i-1)/dt + (4/6) dy(i)/dt + (1/6) dy(i+1)/dt +C = ( y(i-1)**2 - y(i+1)**2 ) / (4*delx) +C + ( y(i+1) - 2*y(i) + y(i-1) ) * eta / delx**2. +C The following coding solves the problem with MF = 21, with output +C of solution statistics at t = .1, .2, .3, and .4, and of the +C solution vector at t = .4. Here the block size is just MB = 1. +C +C EXTERNAL RESID, ADDABT, JACBT +C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y, YDOTI +C DIMENSION Y(41), YDOTI(41), RWORK(514), IWORK(61) +C NEQ = 41 +C DO 10 I = 1,NEQ +C 10 Y(I) = 0.0 +C Y(11) = 0.5 +C DO 20 I = 12,30 +C 20 Y(I) = 1.0 +C Y(31) = 0.5 +C T = 0.0 +C TOUT = 0.1 +C ITOL = 1 +C RTOL = 1.0D-4 +C ATOL = 1.0D-5 +C ITASK = 1 +C ISTATE = 0 +C IOPT = 0 +C LRW = 514 +C LIW = 61 +C IWORK(1) = 1 +C IWORK(2) = NEQ +C MF = 21 +C DO 40 IO = 1,4 +C CALL DLSOIBT (RESID, ADDABT, JACBT, NEQ, Y, YDOTI, T, TOUT, +C 1 ITOL,RTOL,ATOL, ITASK, ISTATE, IOPT, RWORK,LRW,IWORK,LIW, MF) +C WRITE (6,30) T, IWORK(11), IWORK(12), IWORK(13) +C 30 FORMAT(' At t =',F5.2,' No. steps =',I4,' No. r-s =',I4, +C 1 ' No. J-s =',I3) +C IF (ISTATE .NE. 2) GO TO 90 +C TOUT = TOUT + 0.1 +C 40 CONTINUE +C WRITE(6,50) (Y(I),I=1,NEQ) +C 50 FORMAT(/' Final solution values..'/9(5D12.4/)) +C STOP +C 90 WRITE(6,95) ISTATE +C 95 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE RESID (N, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y, S, R, ETA, DELX, EODSQ +C DIMENSION Y(N), S(N), R(N) +C DATA ETA/0.05/, DELX/0.05/ +C EODSQ = ETA/DELX**2 +C R(1) = EODSQ*(Y(3) - 2.0*Y(2) + Y(1)) - S(1) +C NM1 = N - 1 +C DO 10 I = 2,NM1 +C R(I) = (Y(I-1)**2 - Y(I+1)**2)/(4.0*DELX) +C 1 + EODSQ*(Y(I+1) - 2.0*Y(I) + Y(I-1)) +C 2 - (S(I-1) + 4.0*S(I) + S(I+1))/6.0 +C 10 CONTINUE +C R(N) = EODSQ*(Y(N-2) - 2.0*Y(NM1) + Y(N)) - S(N) +C RETURN +C END +C +C SUBROUTINE ADDABT (N, T, Y, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y, PA, PB, PC +C DIMENSION Y(N), PA(MB,MB,NB), PB(MB,MB,NB), PC(MB,MB,NB) +C PA(1,1,1) = PA(1,1,1) + 1.0 +C NM1 = N - 1 +C DO 10 K = 2,NM1 +C PA(1,1,K) = PA(1,1,K) + (4.0/6.0) +C PB(1,1,K) = PB(1,1,K) + (1.0/6.0) +C PC(1,1,K) = PC(1,1,K) + (1.0/6.0) +C 10 CONTINUE +C PA(1,1,N) = PA(1,1,N) + 1.0 +C RETURN +C END +C +C SUBROUTINE JACBT (N, T, Y, S, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y, S, PA, PB, PC, ETA, DELX, EODSQ +C DIMENSION Y(N), S(N), PA(MB,MB,NB),PB(MB,MB,NB),PC(MB,MB,NB) +C DATA ETA/0.05/, DELX/0.05/ +C EODSQ = ETA/DELX**2 +C PA(1,1,1) = EODSQ +C PB(1,1,1) = -2.0*EODSQ +C PC(1,1,1) = EODSQ +C DO 10 K = 2,N +C PA(1,1,K) = -2.0*EODSQ +C PB(1,1,K) = -Y(K+1)*(0.5/DELX) + EODSQ +C PC(1,1,K) = Y(K-1)*(0.5/DELX) + EODSQ +C 10 CONTINUE +C PB(1,1,N) = EODSQ +C PC(1,1,N) = -2.0*EODSQ +C PA(1,1,N) = EODSQ +C RETURN +C END +C +C The output of this program (on a CDC-7600 in single precision) +C is as follows: +C +C At t = 0.10 No. steps = 35 No. r-s = 45 No. J-s = 9 +C At t = 0.20 No. steps = 43 No. r-s = 54 No. J-s = 10 +C At t = 0.30 No. steps = 48 No. r-s = 60 No. J-s = 11 +C At t = 0.40 No. steps = 51 No. r-s = 64 No. J-s = 12 +C +C Final solution values.. +C 1.2747e-02 1.1997e-02 1.5560e-02 2.3767e-02 3.7224e-02 +C 5.6646e-02 8.2645e-02 1.1557e-01 1.5541e-01 2.0177e-01 +C 2.5397e-01 3.1104e-01 3.7189e-01 4.3530e-01 5.0000e-01 +C 5.6472e-01 6.2816e-01 6.8903e-01 7.4612e-01 7.9829e-01 +C 8.4460e-01 8.8438e-01 9.1727e-01 9.4330e-01 9.6281e-01 +C 9.7632e-01 9.8426e-01 9.8648e-01 9.8162e-01 9.6617e-01 +C 9.3374e-01 8.7535e-01 7.8236e-01 6.5321e-01 5.0003e-01 +C 3.4709e-01 2.1876e-01 1.2771e-01 7.3671e-02 5.0642e-02 +C 5.4496e-02 +C +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSOIBT. +C +C The user interface to DLSOIBT consists of the following parts. +C +C 1. The call sequence to Subroutine DLSOIBT, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSOIBT package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSOIBT package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C RES, ADDA, JAC, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, +C IOPT, LRW, LIW, MF, +C and those used for both input and output are +C Y, T, ISTATE, YDOTI. +C The work arrays RWORK and IWORK are also used for additional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSOIBT to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C RES = the name of the user-supplied subroutine which supplies +C the residual vector for the ODE system, defined by +C r = g(t,y) - A(t,y) * s +C as a function of the scalar t and the vectors +C s and y (s approximates dy/dt). This subroutine +C is to have the form +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C where NEQ, T, Y, S, and IRES are input, and R and +C IRES are output. Y, S, and R are arrays of length NEQ. +C On input, IRES indicates how DLSOIBT will use the +C returned array R, as follows: +C IRES = 1 means that DLSOIBT needs the full residual, +C r = g - A*s, exactly. +C IRES = -1 means that DLSOIBT is using R only to compute +C the Jacobian dr/dy by difference quotients. +C The RES routine can ignore IRES, or it can omit some terms +C if IRES = -1. If A does not depend on y, then RES can +C just return R = g when IRES = -1. If g - A*s contains other +C additive terms that are independent of y, these can also be +C dropped, if done consistently, when IRES = -1. +C The subroutine should set the flag IRES if it +C encounters a halt condition or illegal input. +C Otherwise, it should not reset IRES. On output, +C IRES = 1 or -1 represents a normal return, and +C DLSOIBT continues integrating the ODE. Leave IRES +C unchanged from its input value. +C IRES = 2 tells DLSOIBT to immediately return control +C to the calling program, with ISTATE = 3. This lets +C the calling program change parameters of the problem +C if necessary. +C IRES = 3 represents an error condition (for example, an +C illegal value of y). DLSOIBT tries to integrate the system +C without getting IRES = 3 from RES. If it cannot, DLSOIBT +C returns with ISTATE = -7 or -1. +C On an DLSOIBT return with ISTATE = 3, -1, or -7, the +C values of T and Y returned correspond to the last point +C reached successfully without getting the flag IRES = 2 or 3. +C The flag values IRES = 2 and 3 should not be used to +C handle switches or root-stop conditions. This is better +C done by calling DLSOIBT in a one-step mode and checking the +C stopping function for a sign change at each step. +C If quantities computed in the RES routine are needed +C externally to DLSOIBT, an extra call to RES should be made +C for this purpose, for consistent and accurate results. +C To get the current dy/dt for the S argument, use DINTDY. +C RES must be declared External in the calling +C program. See note below for more about RES. +C +C ADDA = the name of the user-supplied subroutine which adds the +C matrix A = A(t,y) to another matrix, P, stored in +C block-tridiagonal form. This routine is to have the form +C SUBROUTINE ADDA (NEQ, T, Y, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y(*), PA(MB,MB,NB), PB(MB,MB,NB), +C 1 PC(MB,MB,NB) +C where NEQ, T, Y, MB, NB, and the arrays PA, PB, and PC +C are input, and the arrays PA, PB, and PC are output. +C Y is an array of length NEQ, and the arrays PA, PB, PC +C are all MB by MB by NB. +C Here a block-tridiagonal structure is assumed for A(t,y), +C and also for the matrix P to which A is added here, +C as described in Paragraph B of the Summary of Usage above. +C Thus the affect of ADDA should be the following: +C DO 30 K = 1,NB +C DO 20 J = 1,MB +C DO 10 I = 1,MB +C PA(I,J,K) = PA(I,J,K) + +C ( (I,J) element of K-th diagonal block of A) +C PB(I,J,K) = PB(I,J,K) + +C ( (I,J) element of block (K,K+1) of A, +C or block (NB,NB-2) if K = NB) +C PC(I,J,K) = PC(I,J,K) + +C ( (I,J) element of block (K,K-1) of A, +C or block (1,3) if K = 1) +C 10 CONTINUE +C 20 CONTINUE +C 30 CONTINUE +C ADDA must be declared External in the calling program. +C See note below for more information about ADDA. +C +C JAC = the name of the user-supplied subroutine which supplies +C the Jacobian matrix, dr/dy, where r = g - A*s. JAC is +C required if MITER = 1. Otherwise a dummy name can be +C passed. This subroutine is to have the form +C SUBROUTINE JAC (NEQ, T, Y, S, MB, NB, PA, PB, PC) +C DOUBLE PRECISION T, Y(*), S(*), PA(MB,MB,NB), +C 1 PB(MB,MB,NB), PC(MB,MB,NB) +C where NEQ, T, Y, S, MB, NB, and the arrays PA, PB, and PC +C are input, and the arrays PA, PB, and PC are output. +C Y and S are arrays of length NEQ, and the arrays PA, PB, PC +C are all MB by MB by NB. +C PA, PB, and PC are to be loaded with partial derivatives +C (elements of the Jacobian matrix) on output, in terms of the +C block-tridiagonal structure assumed, as described +C in Paragraph B of the Summary of Usage above. +C That is, load the diagonal blocks into PA, the +C superdiagonal blocks (and block (NB,NB-2) ) into PB, and +C the subdiagonal blocks (and block (1,3) ) into PC. +C The blocks in block-row k of dr/dy are to be loaded into +C PA(*,*,k), PB(*,*,k), and PC(*,*,k). +C Thus the affect of JAC should be the following: +C DO 30 K = 1,NB +C DO 20 J = 1,MB +C DO 10 I = 1,MB +C PA(I,J,K) = ( (I,J) element of +C K-th diagonal block of dr/dy) +C PB(I,J,K) = ( (I,J) element of block (K,K+1) +C of dr/dy, or block (NB,NB-2) if K = NB) +C PC(I,J,K) = ( (I,J) element of block (K,K-1) +C of dr/dy, or block (1,3) if K = 1) +C 10 CONTINUE +C 20 CONTINUE +C 30 CONTINUE +C PA, PB, and PC are preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Each call to JAC is preceded by a call to RES with the same +C arguments NEQ, T, Y, and S. Thus to gain some efficiency, +C intermediate quantities shared by both calculations may be +C saved in a user Common block by RES and not recomputed by JAC +C if desired. Also, JAC may alter the Y array, if desired. +C JAC need not provide dr/dy exactly. A crude +C approximation will do, so that DLSOIBT may be used when +C A and dr/dy are not really block-tridiagonal, but are close +C to matrices that are. +C JAC must be declared External in the calling program. +C See note below for more about JAC. +C +C Note on RES, ADDA, and JAC: +C These subroutines may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in the subroutines) and/or Y has length +C exceeding NEQ(1). However, these routines should not alter +C NEQ(1), Y(1),...,Y(NEQ) or any other input variables. +C See the descriptions of NEQ and Y below. +C +C NEQ = the size of the system (number of first order ordinary +C differential equations or scalar algebraic equations). +C Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in RES, ADDA, or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSOIBT package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to RES, ADDA, and JAC. Hence, if it is an array, +C locations NEQ(2),... may be used to store other integer data +C and pass it to RES, ADDA, or JAC. Each such subroutine +C must include NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 0 or 1), and only for output on other +C calls. On the first call, Y must contain the vector of +C initial values. On output, Y contains the computed solution +C vector, evaluated at t. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to RES, +C ADDA, and JAC. Hence its length may exceed NEQ, +C and locations Y(NEQ+1),... may be used to store other real +C data and pass it to RES, ADDA, or JAC. (The DLSOIBT +C package accesses only Y(1),...,Y(NEQ). ) +C +C YDOTI = a real array for the initial value of the vector +C dy/dt and for work space, of dimension at least NEQ. +C +C On input: +C If ISTATE = 0 then DLSOIBT will compute the initial value +C of dy/dt, if A is nonsingular. Thus YDOTI will +C serve only as work space and may have any value. +C If ISTATE = 1 then YDOTI must contain the initial value +C of dy/dt. +C If ISTATE = 2 or 3 (continuation calls) then YDOTI +C may have any value. +C Note: If the initial value of A is singular, then +C DLSOIBT cannot compute the initial value of dy/dt, so +C it must be provided in YDOTI, with ISTATE = 1. +C +C On output, when DLSOIBT terminates abnormally with ISTATE = +C -1, -4, or -5, YDOTI will contain the residual +C r = g(t,y) - A(t,y)*(dy/dt). If r is large, t is near +C its initial value, and YDOTI is supplied with ISTATE = 1, +C there may have been an incorrect input value of +C YDOTI = dy/dt, or the problem (as given to DLSOIBT) +C may not have a solution. +C +C If desired, the YDOTI array may be used for other +C purposes between calls to the solver. +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution y is evaluated (usually the same as TOUT). +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 0 or 1), TOUT may be +C equal to T for one call, then should .ne. T for the next +C call. For the initial T, an input value of TOUT .ne. T is +C used in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array scalar RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 0 means this is the first call for the problem, and +C DLSOIBT is to compute the initial value of dy/dt +C (while doing other initializations). See note below. +C 1 means this is the first call for the problem, and +C the initial value of dy/dt has been supplied in +C YDOTI (DLSOIBT will do other initializations). +C See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, MB, NB, +C and any of the optional inputs except H0. +C (See IWORK description for MB and NB.) +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 0 or 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 0 or 1 means nothing was done; TOUT = t and +C ISTATE = 0 or 1 on input. +C 2 means that the integration was performed successfully. +C 3 means that the user-supplied Subroutine RES signalled +C DLSOIBT to halt the integration and return (IRES = 2). +C Integration as far as T was achieved with no occurrence +C of IRES = 2, but this flag was set on attempting the +C next step. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i) = 0.0) +C was requested on a variable which has now vanished. +C The integration was successful as far as T. +C -7 means that the user-supplied Subroutine RES set +C its error flag (IRES = 3) despite repeated tries by +C DLSOIBT to avoid that condition. +C -8 means that ISTATE was 0 on input but DLSOIBT was unable +C to compute the initial value of dy/dt. See the +C printed message for details. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C Similarly, ISTATE (= 3) need not be reset if RES told +C DLSOIBT to return because the calling program must change +C the parameters of the problem. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a real working array (double precision). +C The length of RWORK must be at least +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LENWM where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LENWM = 3*MB*MB*NB + 2. +C (See MF description for the definition of METH.) +C Thus if MAXORD has its default value and NEQ is constant, +C this length is +C 22 + 16*NEQ + 3*MB*MB*NB for MF = 11 or 12, +C 22 + 9*NEQ + 3*MB*MB*NB for MF = 21 or 22. +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 20 + NEQ . The first few words of IWORK are used for +C additional and optional inputs and optional outputs. +C +C The following 2 words in IWORK are additional required +C inputs to DLSOIBT: +C IWORK(1) = MB = block size +C IWORK(2) = NB = number of blocks in the main diagonal +C These must satisfy MB .ge. 1, NB .ge. 4, and MB*NB = NEQ. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSOIBT +C for the same problem, except possibly for the additional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSOIBT between calls, if +C desired (but not for use by RES, ADDA, or JAC). +C +C MF = the method flag. used only for input. The legal values of +C MF are 11, 12, 21, and 22. +C MF has decimal digits METH and MITER: MF = 10*METH + MITER. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFS). +C The BDF method is strongly preferred for stiff +C problems, while the Adams method is preferred when the +C problem is not stiff. If the matrix A(t,y) is +C nonsingular, stiffness here can be taken to mean that of +C the explicit ODE system dy/dt = A-inverse * g. If A is +C singular, the concept of stiffness is not well defined. +C If you do not know whether the problem is stiff, we +C recommend using METH = 2. If it is stiff, the advantage +C of METH = 2 over METH = 1 will be great, while if it is +C not stiff, the advantage of METH = 1 will be slight. +C If maximum efficiency is important, some experimentation +C with METH may be necessary. +C MITER indicates the corrector iteration method: +C MITER = 1 means chord iteration with a user-supplied +C block-tridiagonal Jacobian. +C MITER = 2 means chord iteration with an internally +C generated (difference quotient) block- +C tridiagonal Jacobian approximation, using +C 3*MB+1 extra calls to RES per dr/dy evaluation. +C If MITER = 1, the user must supply a Subroutine JAC +C (the name is arbitrary) as described above under JAC. +C For MITER = 2, a dummy argument can be used. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSOIBT, the variables listed +C below are quantities related to the performance of DLSOIBT +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSOIBT, and on any return with +C ISTATE = -1, -2, -4, -5, -6, or -7. On a return with -3 (illegal +C input) or -8, they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NRE IWORK(12) the number of residual evaluations (RES calls) +C for the problem so far. +C +C NJE IWORK(13) the number of Jacobian evaluations (each involving +C an evaluation of a and dr/dy) for the problem so +C far. This equals the number of calls to ADDA and +C (if MITER = 1) to JAC, and the number of matrix +C LU decompositions. +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C +C The following two arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address in RWORK, and its description. +C +C Name Base Address Description +C +C YH 21 the Nordsieck history array, of size NYH by +C (NQCUR + 1), where NYH is the initial value +C of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output to +C represent the estimated local error in y on +C the last step. This is the vector E in the +C description of the error control. It is +C defined only on a return from DLSOIBT with +C ISTATE = 2. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSOIBT. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSOIBT, if +C the default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSOIBT. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCOM(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSOIBT (see Part 3 below). +C RSAV must be a real array of length 218 +C or more, and ISAV must be an integer +C array of length 37 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCOM is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSOIBT. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSOIBT. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C CALL DINTDY (T, K, RWORK(21), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the t last returned by DLSOIBT). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(t), is already provided +C by DLSOIBT directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C RWORK(21) = the base address of the history array YH. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSOIBT is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSOIBT, and +C (2) the internal Common block +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C +C If DLSOIBT is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common block in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSOIBT is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSOIBT call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSOIBT call for that problem. To save and restore the Common +C blocks, use Subroutine DSRCOM (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below are descriptions of two routines in the DLSOIBT package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSOIBT call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSOIBT in the computation +C of the optional output IMXER, the diagonal Jacobian approximation, +C and the increments for difference quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where: +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSOIBT. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*W(i)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19840625 DATE WRITTEN +C 19870330 Major update: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODI; +C in STODI, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C converted arithmetic IF statements to logical IF statements; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20031105 Restored 'own' variables to Common block, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C 20031117 Changed internal names NRE, LSAVR to NFE, LSAVF resp. +C +C----------------------------------------------------------------------- +C Other routines in the DLSOIBT package. +C +C In addition to Subroutine DLSOIBT, the DLSOIBT package includes the +C following subroutines and function routines: +C DAIGBT computes the initial value of the vector +C dy/dt = A-inverse * g +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODI is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSRCOM is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C DPJIBT computes and preprocesses the Jacobian matrix +C and the Newton iteration matrix P. +C DSLSBT manages solution of linear system in chord iteration. +C DDECBT and DSOLBT are routines for solving block-tridiagonal +C systems of linear algebraic equations. +C DGEFA and DGESL are routines from LINPACK for solving full +C systems of linear algebraic equations. +C DDOT is one of the basic linear algebra modules (BLAS). +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DDOT, DUMACH, IXSAV, and IUMACH are function routines. +C All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPJIBT, DSLSBT + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER I, I1, I2, IER, IFLAG, IMXER, IRES, KGO, + 1 LENIW, LENRW, LENWM, LP, LYD0, MB, MORD, MXHNL0, MXSTP0, NB + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following internal Common block contains +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSOIBT, DINTDY, DSTODI, +C DPJIBT, and DSLSBT. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropriately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 0 or 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 0 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .LE. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 0 or 1) +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, +C MF, MB, and NB. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .LE. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + METH = MF/10 + MITER = MF - 10*METH + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 1 .OR. MITER .GT. 2) GO TO 608 + MB = IWORK(1) + NB = IWORK(2) + IF (MB .LT. 1 .OR. MB .GT. N) GO TO 609 + IF (NB .LT. 4) GO TO 610 + IF (MB*NB .NE. N) GO TO 609 +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .LE. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .GT. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C----------------------------------------------------------------------- +C Set work array pointers and check lengths LRW and LIW. +C Pointers to segments of RWORK and IWORK are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted YH, WM, EWT, SAVR, ACOR. +C----------------------------------------------------------------------- + 60 LYH = 21 + IF (ISTATE .LE. 1) NYH = N + LWM = LYH + (MAXORD + 1)*NYH + LENWM = 3*MB*MB*NB + 2 + LEWT = LWM + LENWM + LSAVF = LEWT + N + LACOR = LSAVF + N + LENRW = LACOR + N - 1 + IWORK(17) = LENRW + LIWM = 1 + LENIW = 20 + N + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 +C Check RTOL and ATOL for legality. ------------------------------------ + RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 70 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 70 CONTINUE + IF (ISTATE .LE. 1) GO TO 100 +C If ISTATE = 3, set flag to signal parameter changes to DSTODI. ------- + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 90 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into YDOTI.--------- + DO 80 I = 1,N + 80 YDOTI(I) = RWORK(I+LWM-1) +C Reload WM(1) = RWORK(lWM), since lWM may have changed. --------------- + 90 RWORK(LWM) = SQRT(UROUND) + IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 0 or 1). +C It contains all remaining initializations, the call to DAIGBT +C (if ISTATE = 1), and the calculation of the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 UROUND = DUMACH() + TN = T + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 105 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T + 105 JSTART = 0 + RWORK(LWM) = SQRT(UROUND) + NHNIL = 0 + NST = 0 + NFE = 0 + NJE = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C Compute initial dy/dt, if necessary, and load it and initial Y into YH + LYD0 = LYH + NYH + LP = LWM + 1 + IF ( ISTATE .EQ. 1 ) GO TO 120 +C DLSOIBT must compute initial dy/dt (LYD0 points to YH(*,2)). --------- + CALL DAIGBT( RES, ADDA, NEQ, T, Y, RWORK(LYD0), + 1 MB, NB, RWORK(LP), IWORK(21), IER ) + NFE = NFE + 1 + IF (IER .LT. 0) GO TO 560 + IF (IER .GT. 0) GO TO 565 + DO 115 I = 1,N + 115 RWORK(I+LYH-1) = Y(I) + GO TO 130 +C Initial dy/dt was supplied. Load into YH (LYD0 points to YH(*,2).). - + 120 DO 125 I = 1,N + RWORK(I+LYH-1) = Y(I) + 125 RWORK(I+LYD0-1) = YDOTI(I) +C Load and invert the EWT array. (H is temporarily set to 1.0.) ------- + 130 CONTINUE + NQ = 1 + H = 1.0D0 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 135 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 135 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * Sum ( YDOT(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C YDOT(i) = i-th component of initial value of dy/dt, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 145 + DO 140 I = 1,N + 140 TOL = MAX(TOL,RTOL(I)) + 145 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LYD0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LYD0-1) = H0*RWORK(I+LYD0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODI. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSOIBT- Warning..Internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSOIBT- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODI(NEQ,Y,YH,NYH,YH1,EWT,SAVF,SAVR,ACOR,WM,IWM,RES, +C ADDA,JAC,DPJIBT,DSLSBT) +C Note: SAVF in DSTODI occupies the same space as YDOTI in DLSOIBT. +C----------------------------------------------------------------------- + CALL DSTODI (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 YDOTI, RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), + 2 IWORK(LIWM), RES, ADDA, JAC, DPJIBT, DSLSBT ) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 400, 550), KGO +C +C KGO = 1:success; 2:error test failure; 3:convergence failure; +C 4:RES ordered return; 5:RES returned error. +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. see if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSOIBT. +C If ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + IF ( KFLAG .EQ. -3 ) ISTATE = 3 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSOIBT- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSOIBT- At T (=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 590 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSOIBT- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 590 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSOIBT- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = 'error test failed repeatedly or with ABS(H) = HMIN' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 570 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSOIBT- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 570 +C IRES = 3 returned by RES, despite retries by DSTODI.------------------ + 550 MSG = 'DLSOIBT- At T (=R1) residual routine returned ' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' error IRES = 3 repeatedly. ' + CALL XERRWD (MSG, 40, 206, 0, 0, 0, 0, 1, TN, 0.0D0) + ISTATE = -7 + GO TO 590 +C DAIGBT failed because a diagonal block of A matrix was singular. ----- + 560 IER = -IER + MSG='DLSOIBT- Attempt to initialize dy/dt failed: Matrix A has a' + CALL XERRWD (MSG, 60, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' singular diagonal block, block no. = (I1) ' + CALL XERRWD (MSG, 50, 207, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C DAIGBT failed because RES set IRES to 2 or 3. ------------------------ + 565 MSG = 'DLSOIBT- Attempt to initialize dy/dt failed ' + CALL XERRWD (MSG, 50, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' because residual routine set its error flag ' + CALL XERRWD (MSG, 50, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to IRES = (I1)' + CALL XERRWD (MSG, 20, 208, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C Compute IMXER if relevant. ------------------------------------------- + 570 BIG = 0.0D0 + IMXER = 1 + DO 575 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 575 + BIG = SIZE + IMXER = I + 575 CONTINUE + IWORK(16) = IMXER +C Compute residual if relevant. ---------------------------------------- + 580 LYD0 = LYH + NYH + DO 585 I = 1,N + RWORK(I+LSAVF-1) = RWORK(I+LYD0-1)/H + 585 Y(I) = RWORK(I+LYH-1) + IRES = 1 + CALL RES (NEQ, TN, Y, RWORK(LSAVF), YDOTI, IRES) + NFE = NFE + 1 + IF (IRES .LE. 1) GO TO 595 + MSG = 'DLSOIBT- Residual routine set its flag IRES ' + CALL XERRWD (MSG, 50, 210, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to (I1) when called for final output. ' + CALL XERRWD (MSG, 50, 210, 0, 1, IRES, 0, 0, 0.0D0, 0.0D0) + GO TO 595 +C Set Y vector, T, and optional outputs. ------------------------------- + 590 DO 592 I = 1,N + 592 Y(I) = RWORK(I+LYH-1) + 595 T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSOIBT- ISTATE (=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSOIBT- ITASK (=I1) illegal. ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSOIBT- ISTATE.gt.1 but DLSOIBT not initialized. ' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSOIBT- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSOIBT- ISTATE = 3 and NEQ increased (I1 to I2). ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSOIBT- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSOIBT- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSOIBT- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 609 MSG = 'DLSOIBT- MB (=I1) or NB (=I2) illegal. ' + CALL XERRWD (MSG, 40, 9, 0, 2, MB, NB, 0, 0.0D0, 0.0D0) + GO TO 700 + 610 MSG = 'DLSOIBT- NB (=I1) .lt. 4 illegal. ' + CALL XERRWD (MSG, 40, 10, 0, 1, NB, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSOIBT- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSOIBT- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSOIBT- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSOIBT- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSOIBT- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSOIBT- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG='DLSOIBT- RWORK length needed, LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG='DLSOIBT- IWORK length needed, LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSOIBT- RTOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSOIBT- ATOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSOIBT- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSOIBT- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSOIBT- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSOIBT- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSOIBT- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSOIBT- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSOIBT- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSOIBT- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSOIBT --------------------- + END +*DECK DLSODIS + SUBROUTINE DLSODIS (RES, ADDA, JAC, NEQ, Y, YDOTI, T, TOUT, ITOL, + 1 RTOL, ATOL, ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, MF ) + EXTERNAL RES, ADDA, JAC + INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF + DOUBLE PRECISION Y, YDOTI, T, TOUT, RTOL, ATOL, RWORK + DIMENSION NEQ(*), Y(*), YDOTI(*), RTOL(*), ATOL(*), RWORK(LRW), + 1 IWORK(LIW) +C----------------------------------------------------------------------- +C This is the 18 November 2003 version of +C DLSODIS: Livermore Solver for Ordinary Differential equations +C (Implicit form) with general Sparse Jacobian matrices. +C +C This version is in double precision. +C +C DLSODIS solves the initial value problem for linearly implicit +C systems of first order ODEs, +C A(t,y) * dy/dt = g(t,y) , where A(t,y) is a square matrix, +C or, in component form, +C ( a * ( dy / dt )) + ... + ( a * ( dy / dt )) = +C i,1 1 i,NEQ NEQ +C +C = g ( t, y , y ,..., y ) ( i = 1,...,NEQ ) +C i 1 2 NEQ +C +C If A is singular, this is a differential-algebraic system. +C +C DLSODIS is a variant version of the DLSODI package, and is intended +C for stiff problems in which the matrix A and the Jacobian matrix +C d(g - A*s)/dy have arbitrary sparse structures. +C +C Authors: Alan C. Hindmarsh +C Center for Applied Scientific Computing, L-561 +C Lawrence Livermore National Laboratory +C Livermore, CA 94551 +C and +C Sheila Balsdon +C Zycor, Inc. +C Austin, TX 78741 +C----------------------------------------------------------------------- +C References: +C 1. M. K. Seager and S. Balsdon, LSODIS, A Sparse Implicit +C ODE Solver, in Proceedings of the IMACS 10th World Congress, +C Montreal, August 8-13, 1982. +C +C 2. Alan C. Hindmarsh, LSODE and LSODI, Two New Initial Value +C Ordinary Differential Equation Solvers, +C ACM-SIGNUM Newsletter, vol. 15, no. 4 (1980), pp. 10-11. +C +C 3. S. C. Eisenstat, M. C. Gursky, M. H. Schultz, and A. H. Sherman, +C Yale Sparse Matrix Package: I. The Symmetric Codes, +C Int. J. Num. Meth. Eng., vol. 18 (1982), pp. 1145-1151. +C +C 4. S. C. Eisenstat, M. C. Gursky, M. H. Schultz, and A. H. Sherman, +C Yale Sparse Matrix Package: II. The Nonsymmetric Codes, +C Research Report No. 114, Dept. of Computer Sciences, Yale +C University, 1977. +C----------------------------------------------------------------------- +C Summary of Usage. +C +C Communication between the user and the DLSODIS package, for normal +C situations, is summarized here. This summary describes only a subset +C of the full set of options available. See the full description for +C details, including optional communication, nonstandard options, +C and instructions for special situations. See also the example +C problem (with program and output) following this summary. +C +C A. First, provide a subroutine of the form: +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C which computes the residual function +C r = g(t,y) - A(t,y) * s , +C as a function of t and the vectors y and s. (s is an internally +C generated approximation to dy/dt.) The arrays Y and S are inputs +C to the RES routine and should not be altered. The residual +C vector is to be stored in the array R. The argument IRES should be +C ignored for casual use of DLSODIS. (For uses of IRES, see the +C paragraph on RES in the full description below.) +C +C B. DLSODIS must deal internally with the matrices A and dr/dy, where +C r is the residual function defined above. DLSODIS generates a linear +C combination of these two matrices in sparse form. +C The matrix structure is communicated by a method flag, MF: +C MF = 21 or 22 when the user provides the structures of +C matrix A and dr/dy, +C MF = 121 or 222 when the user does not provide structure +C information, and +C MF = 321 or 422 when the user provides the structure +C of matrix A. +C +C C. You must also provide a subroutine of the form: +C SUBROUTINE ADDA (NEQ, T, Y, J, IAN, JAN, P) +C DOUBLE PRECISION T, Y(*), P(*) +C INTEGER IAN(*), JAN(*) +C which adds the matrix A = A(t,y) to the contents of the array P. +C NEQ, T, Y, and J are input arguments and should not be altered. +C This routine should add the J-th column of matrix A to the array +C P (of length NEQ). I.e. add A(i,J) to P(i) for all relevant +C values of i. The arguments IAN and JAN should be ignored for normal +C situations. DLSODIS will call the ADDA routine with J = 1,2,...,NEQ. +C +C D. For the sake of efficiency, you are encouraged to supply the +C Jacobian matrix dr/dy in closed form, where r = g(t,y) - A(t,y)*s +C (s = a fixed vector) as above. If dr/dy is being supplied, +C use MF = 21, 121, or 321, and provide a subroutine of the form: +C SUBROUTINE JAC (NEQ, T, Y, S, J, IAN, JAN, PDJ) +C DOUBLE PRECISION T, Y(*), S(*), PDJ(*) +C INTEGER IAN(*), JAN(*) +C which computes dr/dy as a function of t, y, and s. Here NEQ, T, Y, S, +C and J are input arguments, and the JAC routine is to load the array +C PDJ (of length NEQ) with the J-th column of dr/dy. I.e. load PDJ(i) +C with dr(i)/dy(J) for all relevant values of i. The arguments IAN and +C JAN should be ignored for normal situations. DLSODIS will call the +C JAC routine with J = 1,2,...,NEQ. +C Only nonzero elements need be loaded. A crude approximation +C to dr/dy, possibly with fewer nonzero elememts, will suffice. +C Note that if A is independent of y (or this dependence +C is weak enough to be ignored) then JAC is to compute dg/dy. +C If it is not feasible to provide a JAC routine, use +C MF = 22, 222, or 422 and DLSODIS will compute an approximate +C Jacobian internally by difference quotients. +C +C E. Next decide whether or not to provide the initial value of the +C derivative vector dy/dt. If the initial value of A(t,y) is +C nonsingular (and not too ill-conditioned), you may let DLSODIS compute +C this vector (ISTATE = 0). (DLSODIS will solve the system A*s = g for +C s, with initial values of A and g.) If A(t,y) is initially +C singular, then the system is a differential-algebraic system, and +C you must make use of the particular form of the system to compute the +C initial values of y and dy/dt. In that case, use ISTATE = 1 and +C load the initial value of dy/dt into the array YDOTI. +C The input array YDOTI and the initial Y array must be consistent with +C the equations A*dy/dt = g. This implies that the initial residual +C r = g(t,y) - A(t,y)*YDOTI must be approximately zero. +C +C F. Write a main program which calls Subroutine DLSODIS once for +C each point at which answers are desired. This should also provide +C for possible use of logical unit 6 for output of error messages by +C DLSODIS. On the first call to DLSODIS, supply arguments as follows: +C RES = name of user subroutine for residual function r. +C ADDA = name of user subroutine for computing and adding A(t,y). +C JAC = name of user subroutine for Jacobian matrix dr/dy +C (MF = 121). If not used, pass a dummy name. +C Note: The names for the RES and ADDA routines and (if used) the +C JAC routine must be declared External in the calling program. +C NEQ = number of scalar equations in the system. +C Y = array of initial values, of length NEQ. +C YDOTI = array of length NEQ (containing initial dy/dt if ISTATE = 1). +C T = the initial value of the independent variable. +C TOUT = first point where output is desired (.ne. T). +C ITOL = 1 or 2 according as ATOL (below) is a scalar or array. +C RTOL = relative tolerance parameter (scalar). +C ATOL = absolute tolerance parameter (scalar or array). +C The estimated local error in y(i) will be controlled so as +C to be roughly less (in magnitude) than +C EWT(i) = RTOL*ABS(Y(i)) + ATOL if ITOL = 1, or +C EWT(i) = RTOL*ABS(Y(i)) + ATOL(i) if ITOL = 2. +C Thus the local error test passes if, in each component, +C either the absolute error is less than ATOL (or ATOL(i)), +C or the relative error is less than RTOL. +C Use RTOL = 0.0 for pure absolute error control, and +C use ATOL = 0.0 (or ATOL(i) = 0.0) for pure relative error +C control. Caution: Actual (global) errors may exceed these +C local tolerances, so choose them conservatively. +C ITASK = 1 for normal computation of output values of y at t = TOUT. +C ISTATE = integer flag (input and output). Set ISTATE = 1 if the +C initial dy/dt is supplied, and 0 otherwise. +C IOPT = 0 to indicate no optional inputs used. +C RWORK = real work array of length at least: +C 20 + (2 + 1./LENRAT)*NNZ + (11 + 9./LENRAT)*NEQ +C where: +C NNZ = the number of nonzero elements in the sparse +C iteration matrix P = A - con*dr/dy (con = scalar) +C (If NNZ is unknown, use an estimate of it.) +C LENRAT = the real to integer wordlength ratio (usually 1 in +C single precision and 2 in double precision). +C In any case, the required size of RWORK cannot generally +C be predicted in advance for any value of MF, and the +C value above is a rough estimate of a crude lower bound. +C Some experimentation with this size may be necessary. +C (When known, the correct required length is an optional +C output, available in IWORK(17).) +C LRW = declared length of RWORK (in user's dimension). +C IWORK = integer work array of length at least 30. +C LIW = declared length of IWORK (in user's dimension). +C MF = method flag. Standard values are: +C 121 for a user-supplied sparse Jacobian. +C 222 for an internally generated sparse Jacobian. +C For other choices of MF, see the paragraph on MF in +C the full description below. +C Note that the main program must declare arrays Y, YDOTI, RWORK, IWORK, +C and possibly ATOL. +C +C G. The output from the first call, or any call, is: +C Y = array of computed values of y(t) vector. +C T = corresponding value of independent variable (normally TOUT). +C ISTATE = 2 if DLSODIS was successful, negative otherwise. +C -1 means excess work done on this call (check all inputs). +C -2 means excess accuracy requested (tolerances too small). +C -3 means illegal input detected (see printed message). +C -4 means repeated error test failures (check all inputs). +C -5 means repeated convergence failures (perhaps bad Jacobian +C supplied or wrong choice of tolerances). +C -6 means error weight became zero during problem. (Solution +C component i vanished, and ATOL or ATOL(i) = 0.) +C -7 cannot occur in casual use. +C -8 means DLSODIS was unable to compute the initial dy/dt. +C in casual use, this means A(t,y) is initially singular. +C Supply YDOTI and use ISTATE = 1 on the first call. +C -9 means a fatal error return flag came from sparse solver +C CDRV by way of DPRJIS or DSOLSS. Should never happen. +C +C A return with ISTATE = -1, -4, or -5, may result from using +C an inappropriate sparsity structure, one that is quite +C different from the initial structure. Consider calling +C DLSODIS again with ISTATE = 3 to force the structure to be +C reevaluated. See the full description of ISTATE below. +C +C If DLSODIS returns ISTATE = -1, -4 or -5, then the output of +C DLSODIS also includes YDOTI = array containing residual vector +C r = g - A * dy/dt evaluated at the current t, y, and dy/dt. +C +C H. To continue the integration after a successful return, simply +C reset TOUT and call DLSODIS again. No other parameters need be reset. +C +C----------------------------------------------------------------------- +C Example Problem. +C +C The following is an example problem, with the coding needed +C for its solution by DLSODIS. The problem comes from the partial +C differential equation (the Burgers equation) +C du/dt = - u * du/dx + eta * d**2 u/dx**2, eta = .05, +C on -1 .le. x .le. 1. The boundary conditions are periodic: +C u(-1,t) = u(1,t) and du/dx(-1,t) = du/dx(1,t) +C The initial profile is a square wave, +C u = 1 in ABS(x) .lt. .5, u = .5 at ABS(x) = .5, u = 0 elsewhere. +C The PDE is discretized in x by a simplified Galerkin method, +C using piecewise linear basis functions, on a grid of 40 intervals. +C The result is a system A * dy/dt = g(y), of size NEQ = 40, +C where y(i) is the approximation to u at x = x(i), with +C x(i) = -1 + (i-1)*delx, delx = 2/NEQ = .05. +C The individual equations in the system are (in order): +C (1/6)dy(NEQ)/dt+(4/6)dy(1)/dt+(1/6)dy(2)/dt +C = r4d*(y(NEQ)**2-y(2)**2)+eodsq*(y(2)-2*y(1)+y(NEQ)) +C for i = 2,3,...,nm1, +C (1/6)dy(i-1)/dt+(4/6)dy(i)/dt+(1/6)dy(i+1)/dt +C = r4d*(y(i-1)**2-y(i+1)**2)+eodsq*(y(i+1)-2*y(i)+y(i-1)) +C and finally +C (1/6)dy(nm1)/dt+(4/6)dy(NEQ)/dt+(1/6)dy(1)/dt +C = r4d*(y(nm1)**2-y(1)**2)+eodsq*(y(1)-2*y(NEQ)+y(nm1)) +C where r4d = 1/(4*delx), eodsq = eta/delx**2 and nm1 = NEQ-1. +C The following coding solves the problem with MF = 121, with output +C of solution statistics at t = .1, .2, .3, and .4, and of the +C solution vector at t = .4. Optional outputs (run statistics) are +C also printed. +C +C EXTERNAL RESID, ADDASP, JACSP +C DOUBLE PRECISION ATOL, RTOL, RW, T, TOUT, Y, YDOTI, R4D, EODSQ, DELX +C DIMENSION Y(40), YDOTI(40), RW(1409), IW(30) +C COMMON /TEST1/ R4D, EODSQ, NM1 +C DATA ITOL/1/, RTOL/1.0D-3/, ATOL/1.0D-3/, ITASK/1/, IOPT/0/ +C DATA NEQ/40/, LRW/1409/, LIW/30/, MF/121/ +C +C DELX = 2.0/NEQ +C R4D = 0.25/DELX +C EODSQ = 0.05/DELX**2 +C NM1 = NEQ - 1 +C DO 10 I = 1,NEQ +C 10 Y(I) = 0.0 +C Y(11) = 0.5 +C DO 15 I = 12,30 +C 15 Y(I) = 1.0 +C Y(31) = 0.5 +C T = 0.0 +C TOUT = 0.1 +C ISTATE = 0 +C DO 30 IO = 1,4 +C CALL DLSODIS (RESID, ADDASP, JACSP, NEQ, Y, YDOTI, T, TOUT, +C 1 ITOL, RTOL, ATOL, ITASK, ISTATE, IOPT, RW, LRW, IW, LIW, MF) +C WRITE(6,20) T,IW(11),RW(11) +C 20 FORMAT(' At t =',F5.2,' No. steps =',I4, +C 1 ' Last step =',D12.4) +C IF (ISTATE .NE. 2) GO TO 90 +C TOUT = TOUT + 0.1 +C 30 CONTINUE +C WRITE (6,40) (Y(I),I=1,NEQ) +C 40 FORMAT(/' Final solution values..'/8(5D12.4/)) +C WRITE(6,50) IW(17),IW(18),IW(11),IW(12),IW(13) +C NNZLU = IW(25) + IW(26) + NEQ +C WRITE(6,60) IW(19),NNZLU +C 50 FORMAT(/' Required RW size =',I5,' IW size =',I4/ +C 1 ' No. steps =',I4,' No. r-s =',I4,' No. J-s =',i4) +C 60 FORMAT(' No. of nonzeros in P matrix =',I4, +C 1 ' No. of nonzeros in LU =',I4) +C STOP +C 90 WRITE (6,95) ISTATE +C 95 FORMAT(///' Error halt.. ISTATE =',I3) +C STOP +C END +C +C SUBROUTINE GFUN (N, T, Y, G) +C DOUBLE PRECISION T, Y, G, R4D, EODSQ +C DIMENSION G(N), Y(N) +C COMMON /TEST1/ R4D, EODSQ, NM1 +C G(1) = R4D*(Y(N)**2-Y(2)**2) + EODSQ*(Y(2)-2.0*Y(1)+Y(N)) +C DO 10 I = 2,NM1 +C G(I) = R4D*(Y(I-1)**2 - Y(I+1)**2) +C 1 + EODSQ*(Y(I+1) - 2.0*Y(I) + Y(I-1)) +C 10 CONTINUE +C G(N) = R4D*(Y(NM1)**2-Y(1)**2) + EODSQ*(Y(1)-2.0*Y(N)+Y(NM1)) +C RETURN +C END +C +C SUBROUTINE RESID (N, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y, S, R, R4D, EODSQ +C DIMENSION Y(N), S(N), R(N) +C COMMON /TEST1/ R4D, EODSQ, NM1 +C CALL GFUN (N, T, Y, R) +C R(1) = R(1) - (S(N) + 4.0*S(1) + S(2))/6.0 +C DO 10 I = 2,NM1 +C 10 R(I) = R(I) - (S(I-1) + 4.0*S(I) + S(I+1))/6.0 +C R(N) = R(N) - (S(NM1) + 4.0*S(N) + S(1))/6.0 +C RETURN +C END +C +C SUBROUTINE ADDASP (N, T, Y, J, IP, JP, P) +C DOUBLE PRECISION T, Y, P +C DIMENSION Y(N), IP(*), JP(*), P(N) +C JM1 = J - 1 +C JP1 = J + 1 +C IF (J .EQ. N) JP1 = 1 +C IF (J .EQ. 1) JM1 = N +C P(J) = P(J) + (2.0/3.0) +C P(JP1) = P(JP1) + (1.0/6.0) +C P(JM1) = P(JM1) + (1.0/6.0) +C RETURN +C END +C +C SUBROUTINE JACSP (N, T, Y, S, J, IP, JP, PDJ) +C DOUBLE PRECISION T, Y, S, PDJ, R4D, EODSQ +C DIMENSION Y(N), S(N), IP(*), JP(*), PDJ(N) +C COMMON /TEST1/ R4D, EODSQ, NM1 +C JM1 = J - 1 +C JP1 = J + 1 +C IF (J .EQ. 1) JM1 = N +C IF (J .EQ. N) JP1 = 1 +C PDJ(JM1) = -2.0*R4D*Y(J) + EODSQ +C PDJ(J) = -2.0*EODSQ +C PDJ(JP1) = 2.0*R4D*Y(J) + EODSQ +C RETURN +C END +C +C The output of this program (on a CDC-7600 in single precision) +C is as follows: +C +C At t = 0.10 No. steps = 15 Last step = 1.6863e-02 +C At t = 0.20 No. steps = 19 Last step = 2.4101e-02 +C At t = 0.30 No. steps = 22 Last step = 4.3143e-02 +C At t = 0.40 No. steps = 24 Last step = 5.7819e-02 +C +C Final solution values.. +C 1.8371e-02 1.3578e-02 1.5864e-02 2.3805e-02 3.7245e-02 +C 5.6630e-02 8.2538e-02 1.1538e-01 1.5522e-01 2.0172e-01 +C 2.5414e-01 3.1150e-01 3.7259e-01 4.3608e-01 5.0060e-01 +C 5.6482e-01 6.2751e-01 6.8758e-01 7.4415e-01 7.9646e-01 +C 8.4363e-01 8.8462e-01 9.1853e-01 9.4500e-01 9.6433e-01 +C 9.7730e-01 9.8464e-01 9.8645e-01 9.8138e-01 9.6584e-01 +C 9.3336e-01 8.7497e-01 7.8213e-01 6.5315e-01 4.9997e-01 +C 3.4672e-01 2.1758e-01 1.2461e-01 6.6208e-02 3.3784e-02 +C +C Required RW size = 1409 IW size = 30 +C No. steps = 24 No. r-s = 33 No. J-s = 8 +C No. of nonzeros in P matrix = 120 No. of nonzeros in LU = 194 +C +C----------------------------------------------------------------------- +C Full Description of User Interface to DLSODIS. +C +C The user interface to DLSODIS consists of the following parts. +C +C 1. The call sequence to Subroutine DLSODIS, which is a driver +C routine for the solver. This includes descriptions of both +C the call sequence arguments and of user-supplied routines. +C Following these descriptions is a description of +C optional inputs available through the call sequence, and then +C a description of optional outputs (in the work arrays). +C +C 2. Descriptions of other routines in the DLSODIS package that may be +C (optionally) called by the user. These provide the ability to +C alter error message handling, save and restore the internal +C Common, and obtain specified derivatives of the solution y(t). +C +C 3. Descriptions of Common blocks to be declared in overlay +C or similar environments, or to be saved when doing an interrupt +C of the problem and continued solution later. +C +C 4. Description of two routines in the DLSODIS package, either of +C which the user may replace with his/her own version, if desired. +C These relate to the measurement of errors. +C +C----------------------------------------------------------------------- +C Part 1. Call Sequence. +C +C The call sequence parameters used for input only are +C RES, ADDA, JAC, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, +C IOPT, LRW, LIW, MF, +C and those used for both input and output are +C Y, T, ISTATE, YDOTI. +C The work arrays RWORK and IWORK are also used for conditional and +C optional inputs and optional outputs. (The term output here refers +C to the return from Subroutine DLSODIS to the user's calling program.) +C +C The legality of input parameters will be thoroughly checked on the +C initial call for the problem, but not checked thereafter unless a +C change in input parameters is flagged by ISTATE = 3 on input. +C +C The descriptions of the call arguments are as follows. +C +C RES = the name of the user-supplied subroutine which supplies +C the residual vector for the ODE system, defined by +C r = g(t,y) - A(t,y) * s +C as a function of the scalar t and the vectors +C s and y (s approximates dy/dt). This subroutine +C is to have the form +C SUBROUTINE RES (NEQ, T, Y, S, R, IRES) +C DOUBLE PRECISION T, Y(*), S(*), R(*) +C where NEQ, T, Y, S, and IRES are input, and R and +C IRES are output. Y, S, and R are arrays of length NEQ. +C On input, IRES indicates how DLSODIS will use the +C returned array R, as follows: +C IRES = 1 means that DLSODIS needs the full residual, +C r = g - A*s, exactly. +C IRES = -1 means that DLSODIS is using R only to compute +C the Jacobian dr/dy by difference quotients. +C The RES routine can ignore IRES, or it can omit some terms +C if IRES = -1. If A does not depend on y, then RES can +C just return R = g when IRES = -1. If g - A*s contains other +C additive terms that are independent of y, these can also be +C dropped, if done consistently, when IRES = -1. +C The subroutine should set the flag IRES if it +C encounters a halt condition or illegal input. +C Otherwise, it should not reset IRES. On output, +C IRES = 1 or -1 represents a normal return, and +C DLSODIS continues integrating the ODE. Leave IRES +C unchanged from its input value. +C IRES = 2 tells DLSODIS to immediately return control +C to the calling program, with ISTATE = 3. This lets +C the calling program change parameters of the problem +C if necessary. +C IRES = 3 represents an error condition (for example, an +C illegal value of y). DLSODIS tries to integrate the system +C without getting IRES = 3 from RES. If it cannot, DLSODIS +C returns with ISTATE = -7 or -1. +C On a return with ISTATE = 3, -1, or -7, the values +C of T and Y returned correspond to the last point reached +C successfully without getting the flag IRES = 2 or 3. +C The flag values IRES = 2 and 3 should not be used to +C handle switches or root-stop conditions. This is better +C done by calling DLSODIS in a one-step mode and checking the +C stopping function for a sign change at each step. +C If quantities computed in the RES routine are needed +C externally to DLSODIS, an extra call to RES should be made +C for this purpose, for consistent and accurate results. +C To get the current dy/dt for the S argument, use DINTDY. +C RES must be declared External in the calling +C program. See note below for more about RES. +C +C ADDA = the name of the user-supplied subroutine which adds the +C matrix A = A(t,y) to another matrix stored in sparse form. +C This subroutine is to have the form +C SUBROUTINE ADDA (NEQ, T, Y, J, IAN, JAN, P) +C DOUBLE PRECISION T, Y(*), P(*) +C INTEGER IAN(*), JAN(*) +C where NEQ, T, Y, J, IAN, JAN, and P are input. This routine +C should add the J-th column of matrix A to the array P, of +C length NEQ. Thus a(i,J) is to be added to P(i) for all +C relevant values of i. Here T and Y have the same meaning as +C in Subroutine RES, and J is a column index (1 to NEQ). +C IAN and JAN are undefined in calls to ADDA for structure +C determination (MOSS .ne. 0). Otherwise, IAN and JAN are +C structure descriptors, as defined under optional outputs +C below, and so can be used to determine the relevant row +C indices i, if desired. +C Calls to ADDA are made with J = 1,...,NEQ, in that +C order. ADDA must not alter its input arguments. +C ADDA must be declared External in the calling program. +C See note below for more information about ADDA. +C +C JAC = the name of the user-supplied subroutine which supplies +C the Jacobian matrix, dr/dy, where r = g - A*s. JAC is +C required if MITER = 1, or MOSS = 1 or 3. Otherwise a dummy +C name can be passed. This subroutine is to have the form +C SUBROUTINE JAC (NEQ, T, Y, S, J, IAN, JAN, PDJ) +C DOUBLE PRECISION T, Y(*), S(*), PDJ(*) +C INTEGER IAN(*), JAN(*) +C where NEQ, T, Y, S, J, IAN, and JAN are input. The +C array PDJ, of length NEQ, is to be loaded with column J +C of the Jacobian on output. Thus dr(i)/dy(J) is to be +C loaded into PDJ(i) for all relevant values of i. +C Here T, Y, and S have the same meaning as in Subroutine RES, +C and J is a column index (1 to NEQ). IAN and JAN +C are undefined in calls to JAC for structure determination +C (MOSS .ne. 0). Otherwise, IAN and JAN are structure +C descriptors, as defined under optional outputs below, and +C so can be used to determine the relevant row indices i, if +C desired. +C JAC need not provide dr/dy exactly. A crude +C approximation (possibly with greater sparsity) will do. +C In any case, PDJ is preset to zero by the solver, +C so that only the nonzero elements need be loaded by JAC. +C Calls to JAC are made with J = 1,...,NEQ, in that order, and +C each such set of calls is preceded by a call to RES with the +C same arguments NEQ, T, Y, S, and IRES. Thus to gain some +C efficiency intermediate quantities shared by both calculations +C may be saved in a user Common block by RES and not recomputed +C by JAC, if desired. JAC must not alter its input arguments. +C JAC must be declared External in the calling program. +C See note below for more about JAC. +C +C Note on RES, ADDA, and JAC: +C These subroutines may access user-defined quantities in +C NEQ(2),... and/or in Y(NEQ(1)+1),... if NEQ is an array +C (dimensioned in the subroutines) and/or Y has length +C exceeding NEQ(1). However, these subroutines should not +C alter NEQ(1), Y(1),...,Y(NEQ) or any other input variables. +C See the descriptions of NEQ and Y below. +C +C NEQ = the size of the system (number of first order ordinary +C differential equations or scalar algebraic equations). +C Used only for input. +C NEQ may be decreased, but not increased, during the problem. +C If NEQ is decreased (with ISTATE = 3 on input), the +C remaining components of Y should be left undisturbed, if +C these are to be accessed in RES, ADDA, or JAC. +C +C Normally, NEQ is a scalar, and it is generally referred to +C as a scalar in this user interface description. However, +C NEQ may be an array, with NEQ(1) set to the system size. +C (The DLSODIS package accesses only NEQ(1).) In either case, +C this parameter is passed as the NEQ argument in all calls +C to RES, ADDA, and JAC. Hence, if it is an array, +C locations NEQ(2),... may be used to store other integer data +C and pass it to RES, ADDA, or JAC. Each such subroutine +C must include NEQ in a Dimension statement in that case. +C +C Y = a real array for the vector of dependent variables, of +C length NEQ or more. Used for both input and output on the +C first call (ISTATE = 0 or 1), and only for output on other +C calls. On the first call, Y must contain the vector of +C initial values. On output, Y contains the computed solution +C vector, evaluated at T. If desired, the Y array may be used +C for other purposes between calls to the solver. +C +C This array is passed as the Y argument in all calls to RES, +C ADDA, and JAC. Hence its length may exceed NEQ, +C and locations Y(NEQ+1),... may be used to store other real +C data and pass it to RES, ADDA, or JAC. (The DLSODIS +C package accesses only Y(1),...,Y(NEQ). ) +C +C YDOTI = a real array for the initial value of the vector +C dy/dt and for work space, of dimension at least NEQ. +C +C On input: +C If ISTATE = 0 then DLSODIS will compute the initial value +C of dy/dt, if A is nonsingular. Thus YDOTI will +C serve only as work space and may have any value. +C If ISTATE = 1 then YDOTI must contain the initial value +C of dy/dt. +C If ISTATE = 2 or 3 (continuation calls) then YDOTI +C may have any value. +C Note: If the initial value of A is singular, then +C DLSODIS cannot compute the initial value of dy/dt, so +C it must be provided in YDOTI, with ISTATE = 1. +C +C On output, when DLSODIS terminates abnormally with ISTATE = +C -1, -4, or -5, YDOTI will contain the residual +C r = g(t,y) - A(t,y)*(dy/dt). If r is large, t is near +C its initial value, and YDOTI is supplied with ISTATE = 1, +C there may have been an incorrect input value of +C YDOTI = dy/dt, or the problem (as given to DLSODIS) +C may not have a solution. +C +C If desired, the YDOTI array may be used for other +C purposes between calls to the solver. +C +C T = the independent variable. On input, T is used only on the +C first call, as the initial point of the integration. +C On output, after each call, T is the value at which a +C computed solution y is evaluated (usually the same as TOUT). +C On an error return, T is the farthest point reached. +C +C TOUT = the next value of t at which a computed solution is desired. +C Used only for input. +C +C When starting the problem (ISTATE = 0 or 1), TOUT may be +C equal to T for one call, then should .ne. T for the next +C call. For the initial T, an input value of TOUT .ne. T is +C used in order to determine the direction of the integration +C (i.e. the algebraic sign of the step sizes) and the rough +C scale of the problem. Integration in either direction +C (forward or backward in t) is permitted. +C +C If ITASK = 2 or 5 (one-step modes), TOUT is ignored after +C the first call (i.e. the first call with TOUT .ne. T). +C Otherwise, TOUT is required on every call. +C +C If ITASK = 1, 3, or 4, the values of TOUT need not be +C monotone, but a value of TOUT which backs up is limited +C to the current internal T interval, whose endpoints are +C TCUR - HU and TCUR (see optional outputs, below, for +C TCUR and HU). +C +C ITOL = an indicator for the type of error control. See +C description below under ATOL. Used only for input. +C +C RTOL = a relative error tolerance parameter, either a scalar or +C an array of length NEQ. See description below under ATOL. +C Input only. +C +C ATOL = an absolute error tolerance parameter, either a scalar or +C an array of length NEQ. Input only. +C +C The input parameters ITOL, RTOL, and ATOL determine +C the error control performed by the solver. The solver will +C control the vector E = (E(i)) of estimated local errors +C in y, according to an inequality of the form +C RMS-norm of ( E(i)/EWT(i) ) .le. 1, +C where EWT(i) = RTOL(i)*ABS(Y(i)) + ATOL(i), +C and the RMS-norm (root-mean-square norm) here is +C RMS-norm(v) = SQRT(sum v(i)**2 / NEQ). Here EWT = (EWT(i)) +C is a vector of weights which must always be positive, and +C the values of RTOL and ATOL should all be non-negative. +C The following table gives the types (scalar/array) of +C RTOL and ATOL, and the corresponding form of EWT(i). +C +C ITOL RTOL ATOL EWT(i) +C 1 scalar scalar RTOL*ABS(Y(i)) + ATOL +C 2 scalar array RTOL*ABS(Y(i)) + ATOL(i) +C 3 array scalar RTOL(i)*ABS(Y(i)) + ATOL +C 4 array scalar RTOL(i)*ABS(Y(i)) + ATOL(i) +C +C When either of these parameters is a scalar, it need not +C be dimensioned in the user's calling program. +C +C If none of the above choices (with ITOL, RTOL, and ATOL +C fixed throughout the problem) is suitable, more general +C error controls can be obtained by substituting +C user-supplied routines for the setting of EWT and/or for +C the norm calculation. See Part 4 below. +C +C If global errors are to be estimated by making a repeated +C run on the same problem with smaller tolerances, then all +C components of RTOL and ATOL (i.e. of EWT) should be scaled +C down uniformly. +C +C ITASK = an index specifying the task to be performed. +C Input only. ITASK has the following values and meanings. +C 1 means normal computation of output values of y(t) at +C t = TOUT (by overshooting and interpolating). +C 2 means take one step only and return. +C 3 means stop at the first internal mesh point at or +C beyond t = TOUT and return. +C 4 means normal computation of output values of y(t) at +C t = TOUT but without overshooting t = TCRIT. +C TCRIT must be input as RWORK(1). TCRIT may be equal to +C or beyond TOUT, but not behind it in the direction of +C integration. This option is useful if the problem +C has a singularity at or beyond t = TCRIT. +C 5 means take one step, without passing TCRIT, and return. +C TCRIT must be input as RWORK(1). +C +C Note: If ITASK = 4 or 5 and the solver reaches TCRIT +C (within roundoff), it will return T = TCRIT (exactly) to +C indicate this (unless ITASK = 4 and TOUT comes before TCRIT, +C in which case answers at t = TOUT are returned first). +C +C ISTATE = an index used for input and output to specify the +C state of the calculation. +C +C On input, the values of ISTATE are as follows. +C 0 means this is the first call for the problem, and +C DLSODIS is to compute the initial value of dy/dt +C (while doing other initializations). See note below. +C 1 means this is the first call for the problem, and +C the initial value of dy/dt has been supplied in +C YDOTI (DLSODIS will do other initializations). +C See note below. +C 2 means this is not the first call, and the calculation +C is to continue normally, with no change in any input +C parameters except possibly TOUT and ITASK. +C (If ITOL, RTOL, and/or ATOL are changed between calls +C with ISTATE = 2, the new values will be used but not +C tested for legality.) +C 3 means this is not the first call, and the +C calculation is to continue normally, but with +C a change in input parameters other than +C TOUT and ITASK. Changes are allowed in +C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, +C the conditional inputs IA, JA, IC, and JC, +C and any of the optional inputs except H0. +C A call with ISTATE = 3 will cause the sparsity +C structure of the problem to be recomputed. +C (Structure information is reread from IA and JA if +C MOSS = 0, 3, or 4 and from IC and JC if MOSS = 0). +C Note: A preliminary call with TOUT = T is not counted +C as a first call here, as no initialization or checking of +C input is done. (Such a call is sometimes useful for the +C purpose of outputting the initial conditions.) +C Thus the first call for which TOUT .ne. T requires +C ISTATE = 0 or 1 on input. +C +C On output, ISTATE has the following values and meanings. +C 0 or 1 means nothing was done; TOUT = T and +C ISTATE = 0 or 1 on input. +C 2 means that the integration was performed successfully. +C 3 means that the user-supplied Subroutine RES signalled +C DLSODIS to halt the integration and return (IRES = 2). +C Integration as far as T was achieved with no occurrence +C of IRES = 2, but this flag was set on attempting the +C next step. +C -1 means an excessive amount of work (more than MXSTEP +C steps) was done on this call, before completing the +C requested task, but the integration was otherwise +C successful as far as T. (MXSTEP is an optional input +C and is normally 500.) To continue, the user may +C simply reset ISTATE to a value .gt. 1 and call again +C (the excess work step counter will be reset to 0). +C In addition, the user may increase MXSTEP to avoid +C this error return (see below on optional inputs). +C -2 means too much accuracy was requested for the precision +C of the machine being used. This was detected before +C completing the requested task, but the integration +C was successful as far as T. To continue, the tolerance +C parameters must be reset, and ISTATE must be set +C to 3. The optional output TOLSF may be used for this +C purpose. (Note: If this condition is detected before +C taking any steps, then an illegal input return +C (ISTATE = -3) occurs instead.) +C -3 means illegal input was detected, before taking any +C integration steps. See written message for details. +C Note: If the solver detects an infinite loop of calls +C to the solver with illegal input, it will cause +C the run to stop. +C -4 means there were repeated error test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C The problem may have a singularity, or the input +C may be inappropriate. +C -5 means there were repeated convergence test failures on +C one attempted step, before completing the requested +C task, but the integration was successful as far as T. +C This may be caused by an inaccurate Jacobian matrix. +C -6 means EWT(i) became zero for some i during the +C integration. Pure relative error control (ATOL(i) = 0.0) +C was requested on a variable which has now vanished. +C the integration was successful as far as T. +C -7 means that the user-supplied Subroutine RES set +C its error flag (IRES = 3) despite repeated tries by +C DLSODIS to avoid that condition. +C -8 means that ISTATE was 0 on input but DLSODIS was unable +C to compute the initial value of dy/dt. See the +C printed message for details. +C -9 means a fatal error return flag came from the sparse +C solver CDRV by way of DPRJIS or DSOLSS (numerical +C factorization or backsolve). This should never happen. +C The integration was successful as far as T. +C +C Note: An error return with ISTATE = -1, -4, or -5 +C may mean that the sparsity structure of the +C problem has changed significantly since it was last +C determined (or input). In that case, one can attempt to +C complete the integration by setting ISTATE = 3 on the next +C call, so that a new structure determination is done. +C +C Note: Since the normal output value of ISTATE is 2, +C it does not need to be reset for normal continuation. +C similarly, ISTATE (= 3) need not be reset if RES told +C DLSODIS to return because the calling program must change +C the parameters of the problem. +C Also, since a negative input value of ISTATE will be +C regarded as illegal, a negative output value requires the +C user to change it, and possibly other inputs, before +C calling the solver again. +C +C IOPT = an integer flag to specify whether or not any optional +C inputs are being used on this call. Input only. +C The optional inputs are listed separately below. +C IOPT = 0 means no optional inputs are being used. +C Default values will be used in all cases. +C IOPT = 1 means one or more optional inputs are being used. +C +C RWORK = a work array used for a mixture of real (double precision) +C and integer work space. +C The length of RWORK (in real words) must be at least +C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM where +C NYH = the initial value of NEQ, +C MAXORD = 12 (if METH = 1) or 5 (if METH = 2) (unless a +C smaller value is given as an optional input), +C LWM = 2*NNZ + 2*NEQ + (NNZ+9*NEQ)/LENRAT if MITER = 1, +C LWM = 2*NNZ + 2*NEQ + (NNZ+10*NEQ)/LENRAT if MITER = 2. +C in the above formulas, +C NNZ = number of nonzero elements in the iteration matrix +C P = A - con*J (con is a constant and J is the +C Jacobian matrix dr/dy). +C LENRAT = the real to integer wordlength ratio (usually 1 in +C single precision and 2 in double precision). +C (See the MF description for METH and MITER.) +C Thus if MAXORD has its default value and NEQ is constant, +C the minimum length of RWORK is: +C 20 + 16*NEQ + LWM for MF = 11, 111, 311, 12, 212, 412, +C 20 + 9*NEQ + LWM for MF = 21, 121, 321, 22, 222, 422. +C The above formula for LWM is only a crude lower bound. +C The required length of RWORK cannot be readily predicted +C in general, as it depends on the sparsity structure +C of the problem. Some experimentation may be necessary. +C +C The first 20 words of RWORK are reserved for conditional +C and optional inputs and optional outputs. +C +C The following word in RWORK is a conditional input: +C RWORK(1) = TCRIT = critical value of t which the solver +C is not to overshoot. Required if ITASK is +C 4 or 5, and ignored otherwise. (See ITASK.) +C +C LRW = the length of the array RWORK, as declared by the user. +C (This will be checked by the solver.) +C +C IWORK = an integer work array. The length of IWORK must be at least +C 32 + 2*NEQ + NZA + NZC for MOSS = 0, +C 30 for MOSS = 1 or 2, +C 31 + NEQ + NZA for MOSS = 3 or 4. +C (NZA is the number of nonzero elements in matrix A, and +C NZC is the number of nonzero elements in dr/dy.) +C +C In DLSODIS, IWORK is used for conditional and +C optional inputs and optional outputs. +C +C The following two blocks of words in IWORK are conditional +C inputs, required if MOSS = 0, 3, or 4, but not otherwise +C (see the description of MF for MOSS). +C IWORK(30+j) = IA(j) (j=1,...,NEQ+1) +C IWORK(31+NEQ+k) = JA(k) (k=1,...,NZA) +C The two arrays IA and JA describe the sparsity structure +C to be assumed for the matrix A. JA contains the row +C indices where nonzero elements occur, reading in columnwise +C order, and IA contains the starting locations in JA of the +C descriptions of columns 1,...,NEQ, in that order, with +C IA(1) = 1. Thus, for each column index j = 1,...,NEQ, the +C values of the row index i in column j where a nonzero +C element may occur are given by +C i = JA(k), where IA(j) .le. k .lt. IA(j+1). +C If NZA is the total number of nonzero locations assumed, +C then the length of the JA array is NZA, and IA(NEQ+1) must +C be NZA + 1. Duplicate entries are not allowed. +C The following additional blocks of words are required +C if MOSS = 0, but not otherwise. If LC = 31 + NEQ + NZA, then +C IWORK(LC+j) = IC(j) (j=1,...,NEQ+1), and +C IWORK(LC+NEQ+1+k) = JC(k) (k=1,...,NZC) +C The two arrays IC and JC describe the sparsity +C structure to be assumed for the Jacobian matrix dr/dy. +C They are used in the same manner as the above IA and JA +C arrays. If NZC is the number of nonzero locations +C assumed, then the length of the JC array is NZC, and +C IC(NEQ+1) must be NZC + 1. Duplicate entries are not +C allowed. +C +C LIW = the length of the array IWORK, as declared by the user. +C (This will be checked by the solver.) +C +C Note: The work arrays must not be altered between calls to DLSODIS +C for the same problem, except possibly for the conditional and +C optional inputs, and except for the last 3*NEQ words of RWORK. +C The latter space is used for internal scratch space, and so is +C available for use by the user outside DLSODIS between calls, if +C desired (but not for use by RES, ADDA, or JAC). +C +C MF = the method flag. Used only for input. +C MF has three decimal digits-- MOSS, METH, and MITER. +C For standard options: +C MF = 100*MOSS + 10*METH + MITER. +C MOSS indicates the method to be used to obtain the sparsity +C structure of the Jacobian matrix: +C MOSS = 0 means the user has supplied IA, JA, IC, and JC +C (see descriptions under IWORK above). +C MOSS = 1 means the user has supplied JAC (see below) and +C the structure will be obtained from NEQ initial +C calls to JAC and NEQ initial calls to ADDA. +C MOSS = 2 means the structure will be obtained from NEQ+1 +C initial calls to RES and NEQ initial calls to ADDA +C MOSS = 3 like MOSS = 1, except user has supplied IA and JA. +C MOSS = 4 like MOSS = 2, except user has supplied IA and JA. +C METH indicates the basic linear multistep method: +C METH = 1 means the implicit Adams method. +C METH = 2 means the method based on Backward +C Differentiation Formulas (BDFs). +C The BDF method is strongly preferred for stiff problems, +C while the Adams method is preferred when the problem is +C not stiff. If the matrix A(t,y) is nonsingular, +C stiffness here can be taken to mean that of the explicit +C ODE system dy/dt = A-inverse * g. If A is singular, +C the concept of stiffness is not well defined. +C If you do not know whether the problem is stiff, we +C recommend using METH = 2. If it is stiff, the advantage +C of METH = 2 over METH = 1 will be great, while if it is +C not stiff, the advantage of METH = 1 will be slight. +C If maximum efficiency is important, some experimentation +C with METH may be necessary. +C MITER indicates the corrector iteration method: +C MITER = 1 means chord iteration with a user-supplied +C sparse Jacobian, given by Subroutine JAC. +C MITER = 2 means chord iteration with an internally +C generated (difference quotient) sparse +C Jacobian (using NGP extra calls to RES per +C dr/dy value, where NGP is an optional +C output described below.) +C If MITER = 1 or MOSS = 1 or 3 the user must supply a +C Subroutine JAC (the name is arbitrary) as described above +C under JAC. Otherwise, a dummy argument can be used. +C +C The standard choices for MF are: +C MF = 21 or 22 for a stiff problem with IA/JA and IC/JC +C supplied, +C MF = 121 for a stiff problem with JAC supplied, but not +C IA/JA or IC/JC, +C MF = 222 for a stiff problem with neither IA/JA, IC/JC/, +C nor JAC supplied, +C MF = 321 for a stiff problem with IA/JA and JAC supplied, +C but not IC/JC, +C MF = 422 for a stiff problem with IA/JA supplied, but not +C IC/JC or JAC. +C +C The sparseness structure can be changed during the problem +C by making a call to DLSODIS with ISTATE = 3. +C----------------------------------------------------------------------- +C Optional Inputs. +C +C The following is a list of the optional inputs provided for in the +C call sequence. (See also Part 2.) For each such input variable, +C this table lists its name as used in this documentation, its +C location in the call sequence, its meaning, and the default value. +C The use of any of these inputs requires IOPT = 1, and in that +C case all of these inputs are examined. A value of zero for any +C of these optional inputs will cause the default value to be used. +C Thus to use a subset of the optional inputs, simply preload +C locations 5 to 10 in RWORK and IWORK to 0.0 and 0 respectively, and +C then set those of interest to nonzero values. +C +C Name Location Meaning and Default Value +C +C H0 RWORK(5) the step size to be attempted on the first step. +C The default value is determined by the solver. +C +C HMAX RWORK(6) the maximum absolute step size allowed. +C The default value is infinite. +C +C HMIN RWORK(7) the minimum absolute step size allowed. +C The default value is 0. (This lower bound is not +C enforced on the final step before reaching TCRIT +C when ITASK = 4 or 5.) +C +C MAXORD IWORK(5) the maximum order to be allowed. The default +C value is 12 if METH = 1, and 5 if METH = 2. +C If MAXORD exceeds the default value, it will +C be reduced to the default value. +C If MAXORD is changed during the problem, it may +C cause the current order to be reduced. +C +C MXSTEP IWORK(6) maximum number of (internally defined) steps +C allowed during one call to the solver. +C The default value is 500. +C +C MXHNIL IWORK(7) maximum number of messages printed (per problem) +C warning that T + H = T on a step (H = step size). +C This must be positive to result in a non-default +C value. The default value is 10. +C----------------------------------------------------------------------- +C Optional Outputs. +C +C As optional additional output from DLSODIS, the variables listed +C below are quantities related to the performance of DLSODIS +C which are available to the user. These are communicated by way of +C the work arrays, but also have internal mnemonic names as shown. +C Except where stated otherwise, all of these outputs are defined +C on any successful return from DLSODIS, and on any return with +C ISTATE = -1, -2, -4, -5, -6, or -7. On a return with -3 (illegal +C input) or -8, they will be unchanged from their existing values +C (if any), except possibly for TOLSF, LENRW, and LENIW. +C On any error return, outputs relevant to the error will be defined, +C as noted below. +C +C Name Location Meaning +C +C HU RWORK(11) the step size in t last used (successfully). +C +C HCUR RWORK(12) the step size to be attempted on the next step. +C +C TCUR RWORK(13) the current value of the independent variable +C which the solver has actually reached, i.e. the +C current internal mesh point in t. On output, TCUR +C will always be at least as far as the argument +C T, but may be farther (if interpolation was done). +C +C TOLSF RWORK(14) a tolerance scale factor, greater than 1.0, +C computed when a request for too much accuracy was +C detected (ISTATE = -3 if detected at the start of +C the problem, ISTATE = -2 otherwise). If ITOL is +C left unaltered but RTOL and ATOL are uniformly +C scaled up by a factor of TOLSF for the next call, +C then the solver is deemed likely to succeed. +C (The user may also ignore TOLSF and alter the +C tolerance parameters in any other way appropriate.) +C +C NST IWORK(11) the number of steps taken for the problem so far. +C +C NRE IWORK(12) the number of residual evaluations (RES calls) +C for the problem so far, excluding those for +C structure determination (MOSS = 2 or 4). +C +C NJE IWORK(13) the number of Jacobian evaluations (each involving +C an evaluation of A and dr/dy) for the problem so +C far, excluding those for structure determination +C (MOSS = 1 or 3). This equals the number of calls +C to ADDA and (if MITER = 1) JAC. +C +C NQU IWORK(14) the method order last used (successfully). +C +C NQCUR IWORK(15) the order to be attempted on the next step. +C +C IMXER IWORK(16) the index of the component of largest magnitude in +C the weighted local error vector ( E(i)/EWT(i) ), +C on an error return with ISTATE = -4 or -5. +C +C LENRW IWORK(17) the length of RWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C LENIW IWORK(18) the length of IWORK actually required. +C This is defined on normal returns and on an illegal +C input return for insufficient storage. +C +C NNZ IWORK(19) the number of nonzero elements in the iteration +C matrix P = A - con*J (con is a constant and +C J is the Jacobian matrix dr/dy). +C +C NGP IWORK(20) the number of groups of column indices, used in +C difference quotient Jacobian aproximations if +C MITER = 2. This is also the number of extra RES +C evaluations needed for each Jacobian evaluation. +C +C NLU IWORK(21) the number of sparse LU decompositions for the +C problem so far. (Excludes the LU decomposition +C necessary when ISTATE = 0.) +C +C LYH IWORK(22) the base address in RWORK of the history array YH, +C described below in this list. +C +C IPIAN IWORK(23) the base address of the structure descriptor array +C IAN, described below in this list. +C +C IPJAN IWORK(24) the base address of the structure descriptor array +C JAN, described below in this list. +C +C NZL IWORK(25) the number of nonzero elements in the strict lower +C triangle of the LU factorization used in the chord +C iteration. +C +C NZU IWORK(26) the number of nonzero elements in the strict upper +C triangle of the LU factorization used in the chord +C iteration. The total number of nonzeros in the +C factorization is therefore NZL + NZU + NEQ. +C +C The following four arrays are segments of the RWORK array which +C may also be of interest to the user as optional outputs. +C For each array, the table below gives its internal name, +C its base address, and its description. +C For YH and ACOR, the base addresses are in RWORK (a real array). +C The integer arrays IAN and JAN are to be obtained by declaring an +C integer array IWK and identifying IWK(1) with RWORK(21), using either +C an equivalence statement or a subroutine call. Then the base +C addresses IPIAN (of IAN) and IPJAN (of JAN) in IWK are to be obtained +C as optional outputs IWORK(23) and IWORK(24), respectively. +C Thus IAN(1) is IWK(ipian), etc. +C +C Name Base Address Description +C +C IAN IPIAN (in IWK) structure descriptor array of size NEQ + 1. +C JAN IPJAN (in IWK) structure descriptor array of size NNZ. +C (see above) IAN and JAN together describe the sparsity +C structure of the iteration matrix +C P = A - con*J, as used by DLSODIS. +C JAN contains the row indices of the nonzero +C locations, reading in columnwise order, and +C IAN contains the starting locations in JAN of +C the descriptions of columns 1,...,NEQ, in +C that order, with IAN(1) = 1. Thus for each +C j = 1,...,NEQ, the row indices i of the +C nonzero locations in column j are +C i = JAN(k), IAN(j) .le. k .lt. IAN(j+1). +C Note that IAN(NEQ+1) = NNZ + 1. +C YH LYH the Nordsieck history array, of size NYH by +C (optional (NQCUR + 1), where NYH is the initial value +C output) of NEQ. For j = 0,1,...,NQCUR, column j+1 +C of YH contains HCUR**j/factorial(j) times +C the j-th derivative of the interpolating +C polynomial currently representing the solution, +C evaluated at t = TCUR. The base address LYH +C is another optional output, listed above. +C +C ACOR LENRW-NEQ+1 array of size NEQ used for the accumulated +C corrections on each step, scaled on output to +C represent the estimated local error in y on the +C last step. This is the vector E in the +C description of the error control. It is defined +C only on a return from DLSODIS with ISTATE = 2. +C +C----------------------------------------------------------------------- +C Part 2. Other Routines Callable. +C +C The following are optional calls which the user may make to +C gain additional capabilities in conjunction with DLSODIS. +C (The routines XSETUN and XSETF are designed to conform to the +C SLATEC error handling package.) +C +C Form of Call Function +C CALL XSETUN(LUN) Set the logical unit number, LUN, for +C output of messages from DLSODIS, if +C The default is not desired. +C The default value of LUN is 6. +C +C CALL XSETF(MFLAG) Set a flag to control the printing of +C messages by DLSODIS. +C MFLAG = 0 means do not print. (Danger: +C This risks losing valuable information.) +C MFLAG = 1 means print (the default). +C +C Either of the above calls may be made at +C any time and will take effect immediately. +C +C CALL DSRCMS(RSAV,ISAV,JOB) saves and restores the contents of +C the internal Common blocks used by +C DLSODIS (see Part 3 below). +C RSAV must be a real array of length 224 +C or more, and ISAV must be an integer +C array of length 71 or more. +C JOB=1 means save Common into RSAV/ISAV. +C JOB=2 means restore Common from RSAV/ISAV. +C DSRCMS is useful if one is +C interrupting a run and restarting +C later, or alternating between two or +C more problems solved with DLSODIS. +C +C CALL DINTDY(,,,,,) Provide derivatives of y, of various +C (see below) orders, at a specified point t, if +C desired. It may be called only after +C a successful return from DLSODIS. +C +C The detailed instructions for using DINTDY are as follows. +C The form of the call is: +C +C LYH = IWORK(22) +C CALL DINTDY (T, K, RWORK(LYH), NYH, DKY, IFLAG) +C +C The input parameters are: +C +C T = value of independent variable where answers are desired +C (normally the same as the T last returned by DLSODIS). +C For valid results, T must lie between TCUR - HU and TCUR. +C (See optional outputs for TCUR and HU.) +C K = integer order of the derivative desired. K must satisfy +C 0 .le. K .le. NQCUR, where NQCUR is the current order +C (see optional outputs). The capability corresponding +C to K = 0, i.e. computing y(t), is already provided +C by DLSODIS directly. Since NQCUR .ge. 1, the first +C derivative dy/dt is always available with DINTDY. +C LYH = the base address of the history array YH, obtained +C as an optional output as shown above. +C NYH = column length of YH, equal to the initial value of NEQ. +C +C The output parameters are: +C +C DKY = a real array of length NEQ containing the computed value +C of the K-th derivative of y(t). +C IFLAG = integer flag, returned as 0 if K and T were legal, +C -1 if K was illegal, and -2 if T was illegal. +C On an error return, a message is also written. +C----------------------------------------------------------------------- +C Part 3. Common Blocks. +C +C If DLSODIS is to be used in an overlay situation, the user +C must declare, in the primary overlay, the variables in: +C (1) the call sequence to DLSODIS, and +C (2) the two internal Common blocks +C /DLS001/ of length 255 (218 double precision words +C followed by 37 integer words), +C /DLSS01/ of length 40 (6 double precision words +C followed by 34 integer words). +C +C If DLSODIS is used on a system in which the contents of internal +C Common blocks are not preserved between calls, the user should +C declare the above Common blocks in the calling program to insure +C that their contents are preserved. +C +C If the solution of a given problem by DLSODIS is to be interrupted +C and then later continued, such as when restarting an interrupted run +C or alternating between two or more problems, the user should save, +C following the return from the last DLSODIS call prior to the +C interruption, the contents of the call sequence variables and the +C internal Common blocks, and later restore these values before the +C next DLSODIS call for that problem. To save and restore the Common +C blocks, use Subroutines DSRCMS (see Part 2 above). +C +C----------------------------------------------------------------------- +C Part 4. Optionally Replaceable Solver Routines. +C +C Below are descriptions of two routines in the DLSODIS package which +C relate to the measurement of errors. Either routine can be +C replaced by a user-supplied version, if desired. However, since such +C a replacement may have a major impact on performance, it should be +C done only when absolutely necessary, and only with great caution. +C (Note: The means by which the package version of a routine is +C superseded by the user's version may be system-dependent.) +C +C (a) DEWSET. +C The following subroutine is called just before each internal +C integration step, and sets the array of error weights, EWT, as +C described under ITOL/RTOL/ATOL above: +C SUBROUTINE DEWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) +C where NEQ, ITOL, RTOL, and ATOL are as in the DLSODIS call sequence, +C YCUR contains the current dependent variable vector, and +C EWT is the array of weights set by DEWSET. +C +C If the user supplies this subroutine, it must return in EWT(i) +C (i = 1,...,NEQ) a positive quantity suitable for comparing errors +C in y(i) to. The EWT array returned by DEWSET is passed to the DVNORM +C routine (see below), and also used by DLSODIS in the computation +C of the optional output IMXER, and the increments for difference +C quotient Jacobians. +C +C In the user-supplied version of DEWSET, it may be desirable to use +C the current values of derivatives of y. Derivatives up to order NQ +C are available from the history array YH, described above under +C optional outputs. In DEWSET, YH is identical to the YCUR array, +C extended to NQ + 1 columns with a column length of NYH and scale +C factors of H**j/factorial(j). On the first call for the problem, +C given by NST = 0, NQ is 1 and H is temporarily set to 1.0. +C NYH is the initial value of NEQ. The quantities NQ, H, and NST +C can be obtained by including in DEWSET the statements: +C DOUBLE PRECISION RLS +C COMMON /DLS001/ RLS(218),ILS(37) +C NQ = ILS(33) +C NST = ILS(34) +C H = RLS(212) +C Thus, for example, the current value of dy/dt can be obtained as +C YCUR(NYH+i)/H (i=1,...,NEQ) (and the division by H is +C unnecessary when NST = 0). +C +C (b) DVNORM. +C The following is a real function routine which computes the weighted +C root-mean-square norm of a vector v: +C D = DVNORM (N, V, W) +C where: +C N = the length of the vector, +C V = real array of length N containing the vector, +C W = real array of length N containing weights, +C D = SQRT( (1/N) * sum(V(i)*W(i))**2 ). +C DVNORM is called with N = NEQ and with W(i) = 1.0/EWT(i), where +C EWT is as set by Subroutine DEWSET. +C +C If the user supplies this function, it should return a non-negative +C value of DVNORM suitable for use in the error control in DLSODIS. +C None of the arguments should be altered by DVNORM. +C For example, a user-supplied DVNORM routine might: +C -substitute a max-norm of (V(i)*w(I)) for the RMS-norm, or +C -ignore some components of V in the norm, with the effect of +C suppressing the error control on those components of y. +C----------------------------------------------------------------------- +C +C***REVISION HISTORY (YYYYMMDD) +C 19820714 DATE WRITTEN +C 19830812 Major update, based on recent LSODI and LSODES revisions: +C Upgraded MDI in ODRV package: operates on M + M-transpose. +C Numerous revisions in use of work arrays; +C use wordlength ratio LENRAT; added IPISP & LRAT to Common; +C added optional outputs IPIAN/IPJAN; +C Added routine CNTNZU; added NZL and NZU to /LSS001/; +C changed ADJLR call logic; added optional outputs NZL & NZU; +C revised counter initializations; revised PREPI stmt. nos.; +C revised difference quotient increment; +C eliminated block /LSI001/, using IERPJ flag; +C revised STODI logic after PJAC return; +C revised tuning of H change and step attempts in STODI; +C corrections to main prologue and comments throughout. +C 19870320 Corrected jump on test of umax in CDRV routine. +C 20010125 Numerous revisions: corrected comments throughout; +C removed TRET from Common; rewrote EWSET with 4 loops; +C fixed t test in INTDY; added Cray directives in STODI; +C in STODI, fixed DELP init. and logic around PJAC call; +C combined routines to save/restore Common; +C passed LEVEL = 0 in error message calls (except run abort). +C 20010425 Major update: convert source lines to upper case; +C added *DECK lines; changed from 1 to * in dummy dimensions; +C changed names R1MACH/D1MACH to RUMACH/DUMACH; +C renamed routines for uniqueness across single/double prec.; +C converted intrinsic names to generic form; +C removed ILLIN and NTREP (data loaded) from Common; +C removed all 'own' variables from Common; +C changed error messages to quoted strings; +C replaced XERRWV/XERRWD with 1993 revised version; +C converted prologues, comments, error messages to mixed case; +C converted arithmetic IF statements to logical IF statements; +C numerous corrections to prologues and internal comments. +C 20010507 Converted single precision source to double precision. +C 20020502 Corrected declarations in descriptions of user routines. +C 20031021 Fixed address offset bugs in Subroutine DPREPI. +C 20031027 Changed 0. to 0.0D0 in Subroutine DPREPI. +C 20031105 Restored 'own' variables to Common blocks, to enable +C interrupt/restart feature. +C 20031112 Added SAVE statements for data-loaded constants. +C 20031117 Changed internal names NRE, LSAVR to NFE, LSAVF resp. +C +C----------------------------------------------------------------------- +C Other routines in the DLSODIS package. +C +C In addition to Subroutine DLSODIS, the DLSODIS package includes the +C following subroutines and function routines: +C DIPREPI acts as an interface between DLSODIS and DPREPI, and also +C does adjusting of work space pointers and work arrays. +C DPREPI is called by DIPREPI to compute sparsity and do sparse +C matrix preprocessing. +C DAINVGS computes the initial value of the vector +C dy/dt = A-inverse * g +C ADJLR adjusts the length of required sparse matrix work space. +C It is called by DPREPI. +C CNTNZU is called by DPREPI and counts the nonzero elements in the +C strict upper triangle of P + P-transpose. +C JGROUP is called by DPREPI to compute groups of Jacobian column +C indices for use when MITER = 2. +C DINTDY computes an interpolated value of the y vector at t = TOUT. +C DSTODI is the core integrator, which does one step of the +C integration and the associated error control. +C DCFODE sets all method coefficients and test constants. +C DPRJIS computes and preprocesses the Jacobian matrix J = dr/dy +C and the Newton iteration matrix P = A - h*l0*J. +C DSOLSS manages solution of linear system in chord iteration. +C DEWSET sets the error weight vector EWT before each step. +C DVNORM computes the weighted RMS-norm of a vector. +C DSRCMS is a user-callable routine to save and restore +C the contents of the internal Common blocks. +C ODRV constructs a reordering of the rows and columns of +C a matrix by the minimum degree algorithm. ODRV is a +C driver routine which calls Subroutines MD, MDI, MDM, +C MDP, MDU, and SRO. See Ref. 2 for details. (The ODRV +C module has been modified since Ref. 2, however.) +C CDRV performs reordering, symbolic factorization, numerical +C factorization, or linear system solution operations, +C depending on a path argument IPATH. CDRV is a +C driver routine which calls Subroutines NROC, NSFC, +C NNFC, NNSC, and NNTC. See Ref. 3 for details. +C DLSODIS uses CDRV to solve linear systems in which the +C coefficient matrix is P = A - con*J, where A is the +C matrix for the linear system A(t,y)*dy/dt = g(t,y), +C con is a scalar, and J is an approximation to +C the Jacobian dr/dy. Because CDRV deals with rowwise +C sparsity descriptions, CDRV works with P-transpose, not P. +C DLSODIS also uses CDRV to solve the linear system +C A(t,y)*dy/dt = g(t,y) for dy/dt when ISTATE = 0. +C (For this, CDRV works with A-transpose, not A.) +C DUMACH computes the unit roundoff in a machine-independent manner. +C XERRWD, XSETUN, XSETF, IXSAV, and IUMACH handle the printing of all +C error messages and warnings. XERRWD is machine-dependent. +C Note: DVNORM, DUMACH, IXSAV, and IUMACH are function routines. +C All the others are subroutines. +C +C----------------------------------------------------------------------- + EXTERNAL DPRJIS, DSOLSS + DOUBLE PRECISION DUMACH, DVNORM + INTEGER INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS, + 1 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 2 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 3 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU + INTEGER IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 1 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 2 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 3 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU + INTEGER I, I1, I2, IER, IGO, IFLAG, IMAX, IMUL, IMXER, IPFLAG, + 1 IPGO, IREM, IRES, J, KGO, LENRAT, LENYHT, LENIW, LENRW, + 2 LIA, LIC, LJA, LJC, LRTEM, LWTEM, LYD0, LYHD, LYHN, MF1, + 3 MORD, MXHNL0, MXSTP0, NCOLM + DOUBLE PRECISION ROWNS, + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND + DOUBLE PRECISION CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH + DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, + 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0 + DIMENSION MORD(2) + LOGICAL IHIT + CHARACTER*60 MSG + SAVE LENRAT, MORD, MXSTP0, MXHNL0 +C----------------------------------------------------------------------- +C The following two internal Common blocks contain +C (a) variables which are local to any subroutine but whose values must +C be preserved between calls to the routine ("own" variables), and +C (b) variables which are communicated between subroutines. +C The block DLS001 is declared in subroutines DLSODIS, DIPREPI, DPREPI, +C DINTDY, DSTODI, DPRJIS, and DSOLSS. +C The block DLSS01 is declared in subroutines DLSODIS, DAINVGS, +C DIPREPI, DPREPI, DPRJIS, and DSOLSS. +C Groups of variables are replaced by dummy arrays in the Common +C declarations in routines where those variables are not used. +C----------------------------------------------------------------------- + COMMON /DLS001/ ROWNS(209), + 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, + 2 INIT, MXSTEP, MXHNIL, NHNIL, NSLAST, NYH, IOWNS(6), + 3 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, + 4 LYH, LEWT, LACOR, LSAVF, LWM, LIWM, METH, MITER, + 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU +C + COMMON /DLSS01/ CON0, CONMIN, CCMXJ, PSMALL, RBIG, SETH, + 1 IPLOST, IESP, ISTATC, IYS, IBA, IBIAN, IBJAN, IBJGP, + 2 IPIAN, IPJAN, IPJGP, IPIGP, IPR, IPC, IPIC, IPISP, IPRSP, IPA, + 3 LENYH, LENYHM, LENWK, LREQ, LRAT, LREST, LWMIN, MOSS, MSBJ, + 4 NSLJ, NGP, NLU, NNZ, NSP, NZL, NZU +C + DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ +C----------------------------------------------------------------------- +C In the Data statement below, set LENRAT equal to the ratio of +C the wordlength for a real number to that for an integer. Usually, +C LENRAT = 1 for single precision and 2 for double precision. If the +C true ratio is not an integer, use the next smaller integer (.ge. 1), +C----------------------------------------------------------------------- + DATA LENRAT/2/ +C----------------------------------------------------------------------- +C Block A. +C This code block is executed on every call. +C It tests ISTATE and ITASK for legality and branches appropirately. +C If ISTATE .gt. 1 but the flag INIT shows that initialization has +C not yet been done, an error return occurs. +C If ISTATE = 0 or 1 and TOUT = T, return immediately. +C----------------------------------------------------------------------- + IF (ISTATE .LT. 0 .OR. ISTATE .GT. 3) GO TO 601 + IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 + IF (ISTATE .LE. 1) GO TO 10 + IF (INIT .EQ. 0) GO TO 603 + IF (ISTATE .EQ. 2) GO TO 200 + GO TO 20 + 10 INIT = 0 + IF (TOUT .EQ. T) RETURN +C----------------------------------------------------------------------- +C Block B. +C The next code block is executed for the initial call (ISTATE = 0 or 1) +C or for a continuation call with parameter changes (ISTATE = 3). +C It contains checking of all inputs and various initializations. +C If ISTATE = 0 or 1, the final setting of work space pointers, the +C matrix preprocessing, and other initializations are done in Block C. +C +C First check legality of the non-optional inputs NEQ, ITOL, IOPT, and +C MF. +C----------------------------------------------------------------------- + 20 IF (NEQ(1) .LE. 0) GO TO 604 + IF (ISTATE .LE. 1) GO TO 25 + IF (NEQ(1) .GT. N) GO TO 605 + 25 N = NEQ(1) + IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 + IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 + MOSS = MF/100 + MF1 = MF - 100*MOSS + METH = MF1/10 + MITER = MF1 - 10*METH + IF (MOSS .LT. 0 .OR. MOSS .GT. 4) GO TO 608 + IF (MITER .EQ. 2 .AND. MOSS .EQ. 1) MOSS = MOSS + 1 + IF (MITER .EQ. 2 .AND. MOSS .EQ. 3) MOSS = MOSS + 1 + IF (MITER .EQ. 1 .AND. MOSS .EQ. 2) MOSS = MOSS - 1 + IF (MITER .EQ. 1 .AND. MOSS .EQ. 4) MOSS = MOSS - 1 + IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 + IF (MITER .LT. 1 .OR. MITER .GT. 2) GO TO 608 +C Next process and check the optional inputs. -------------------------- + IF (IOPT .EQ. 1) GO TO 40 + MAXORD = MORD(METH) + MXSTEP = MXSTP0 + MXHNIL = MXHNL0 + IF (ISTATE .LE. 1) H0 = 0.0D0 + HMXI = 0.0D0 + HMIN = 0.0D0 + GO TO 60 + 40 MAXORD = IWORK(5) + IF (MAXORD .LT. 0) GO TO 611 + IF (MAXORD .EQ. 0) MAXORD = 100 + MAXORD = MIN(MAXORD,MORD(METH)) + MXSTEP = IWORK(6) + IF (MXSTEP .LT. 0) GO TO 612 + IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 + MXHNIL = IWORK(7) + IF (MXHNIL .LT. 0) GO TO 613 + IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 + IF (ISTATE .GT. 1) GO TO 50 + H0 = RWORK(5) + IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 + 50 HMAX = RWORK(6) + IF (HMAX .LT. 0.0D0) GO TO 615 + HMXI = 0.0D0 + IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX + HMIN = RWORK(7) + IF (HMIN .LT. 0.0D0) GO TO 616 +C Check RTOL and ATOL for legality. ------------------------------------ + 60 RTOLI = RTOL(1) + ATOLI = ATOL(1) + DO 65 I = 1,N + IF (ITOL .GE. 3) RTOLI = RTOL(I) + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + IF (RTOLI .LT. 0.0D0) GO TO 619 + IF (ATOLI .LT. 0.0D0) GO TO 620 + 65 CONTINUE +C----------------------------------------------------------------------- +C Compute required work array lengths, as far as possible, and test +C these against LRW and LIW. Then set tentative pointers for work +C arrays. Pointers to RWORK/IWORK segments are named by prefixing L to +C the name of the segment. E.g., the segment YH starts at RWORK(LYH). +C Segments of RWORK (in order) are denoted WM, YH, SAVR, EWT, ACOR. +C The required length of the matrix work space WM is not yet known, +C and so a crude minimum value is used for the initial tests of LRW +C and LIW, and YH is temporarily stored as far to the right in RWORK +C as possible, to leave the maximum amount of space for WM for matrix +C preprocessing. Thus if MOSS .ne. 2 or 4, some of the segments of +C RWORK are temporarily omitted, as they are not needed in the +C preprocessing. These omitted segments are: ACOR if ISTATE = 1, +C EWT and ACOR if ISTATE = 3 and MOSS = 1, and SAVR, EWT, and ACOR if +C ISTATE = 3 and MOSS = 0. +C----------------------------------------------------------------------- + LRAT = LENRAT + IF (ISTATE .LE. 1) NYH = N + IF (MITER .EQ. 1) LWMIN = 4*N + 10*N/LRAT + IF (MITER .EQ. 2) LWMIN = 4*N + 11*N/LRAT + LENYH = (MAXORD+1)*NYH + LREST = LENYH + 3*N + LENRW = 20 + LWMIN + LREST + IWORK(17) = LENRW + LENIW = 30 + IF (MOSS .NE. 1 .AND. MOSS .NE. 2) LENIW = LENIW + N + 1 + IWORK(18) = LENIW + IF (LENRW .GT. LRW) GO TO 617 + IF (LENIW .GT. LIW) GO TO 618 + LIA = 31 + IF (MOSS .NE. 1 .AND. MOSS .NE. 2) + 1 LENIW = LENIW + IWORK(LIA+N) - 1 + IWORK(18) = LENIW + IF (LENIW .GT. LIW) GO TO 618 + LJA = LIA + N + 1 + LIA = MIN(LIA,LIW) + LJA = MIN(LJA,LIW) + LIC = LENIW + 1 + IF (MOSS .EQ. 0) LENIW = LENIW + N + 1 + IWORK(18) = LENIW + IF (LENIW .GT. LIW) GO TO 618 + IF (MOSS .EQ. 0) LENIW = LENIW + IWORK(LIC+N) - 1 + IWORK(18) = LENIW + IF (LENIW .GT. LIW) GO TO 618 + LJC = LIC + N + 1 + LIC = MIN(LIC,LIW) + LJC = MIN(LJC,LIW) + LWM = 21 + IF (ISTATE .LE. 1) NQ = ISTATE + NCOLM = MIN(NQ+1,MAXORD+2) + LENYHM = NCOLM*NYH + LENYHT = LENYHM + IMUL = 2 + IF (ISTATE .EQ. 3) IMUL = MOSS + IF (ISTATE .EQ. 3 .AND. MOSS .EQ. 3) IMUL = 1 + IF (MOSS .EQ. 2 .OR. MOSS .EQ. 4) IMUL = 3 + LRTEM = LENYHT + IMUL*N + LWTEM = LRW - 20 - LRTEM + LENWK = LWTEM + LYHN = LWM + LWTEM + LSAVF = LYHN + LENYHT + LEWT = LSAVF + N + LACOR = LEWT + N + ISTATC = ISTATE + IF (ISTATE .LE. 1) GO TO 100 +C----------------------------------------------------------------------- +C ISTATE = 3. Move YH to its new location. +C Note that only the part of YH needed for the next step, namely +C MIN(NQ+1,MAXORD+2) columns, is actually moved. +C A temporary error weight array EWT is loaded if MOSS = 2 or 4. +C Sparse matrix processing is done in DIPREPI/DPREPI. +C If MAXORD was reduced below NQ, then the pointers are finally set +C so that SAVR is identical to (YH*,MAXORD+2) +C----------------------------------------------------------------------- + LYHD = LYH - LYHN + IMAX = LYHN - 1 + LENYHM +C Move YH. Move right if LYHD < 0; move left if LYHD > 0. ------------- + IF (LYHD .LT. 0) THEN + DO 72 I = LYHN,IMAX + J = IMAX + LYHN - I + 72 RWORK(J) = RWORK(J+LYHD) + ENDIF + IF (LYHD .GT. 0) THEN + DO 76 I = LYHN,IMAX + 76 RWORK(I) = RWORK(I+LYHD) + ENDIF + 80 LYH = LYHN + IWORK(22) = LYH + IF (MOSS .NE. 2 .AND. MOSS .NE. 4) GO TO 85 +C Temporarily load EWT if MOSS = 2 or 4. + CALL DEWSET (N,ITOL,RTOL,ATOL,RWORK(LYH),RWORK(LEWT)) + DO 82 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 82 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 85 CONTINUE +C DIPREPI and DPREPI do sparse matrix preprocessing. ------------------- + LSAVF = MIN(LSAVF,LRW) + LEWT = MIN(LEWT,LRW) + LACOR = MIN(LACOR,LRW) + CALL DIPREPI (NEQ, Y, YDOTI, RWORK, IWORK(LIA), IWORK(LJA), + 1 IWORK(LIC), IWORK(LJC), IPFLAG, RES, JAC, ADDA) + LENRW = LWM - 1 + LENWK + LREST + IWORK(17) = LENRW + IF (IPFLAG .NE. -1) IWORK(23) = IPIAN + IF (IPFLAG .NE. -1) IWORK(24) = IPJAN + IPGO = -IPFLAG + 1 + GO TO (90, 628, 629, 630, 631, 632, 633, 634, 634), IPGO + 90 IWORK(22) = LYH + LYD0 = LYH + N + IF (LENRW .GT. LRW) GO TO 617 +C Set flag to signal changes to DSTODI.--------------------------------- + JSTART = -1 + IF (NQ .LE. MAXORD) GO TO 94 +C MAXORD was reduced below NQ. Copy YH(*,MAXORD+2) into YDOTI. -------- + DO 92 I = 1,N + 92 YDOTI(I) = RWORK(I+LSAVF-1) + 94 IF (N .EQ. NYH) GO TO 200 +C NEQ was reduced. Zero part of YH to avoid undefined references. ----- + I1 = LYH + L*NYH + I2 = LYH + (MAXORD + 1)*NYH - 1 + IF (I1 .GT. I2) GO TO 200 + DO 95 I = I1,I2 + 95 RWORK(I) = 0.0D0 + GO TO 200 +C----------------------------------------------------------------------- +C Block C. +C The next block is for the initial call only (ISTATE = 0 or 1). +C It contains all remaining initializations, the call to DAINVGS +C (if ISTATE = 0), the sparse matrix preprocessing, and the +C calculation if the initial step size. +C The error weights in EWT are inverted after being loaded. +C----------------------------------------------------------------------- + 100 CONTINUE + LYH = LYHN + IWORK(22) = LYH + TN = T + NST = 0 + NFE = 0 + H = 1.0D0 + NNZ = 0 + NGP = 0 + NZL = 0 + NZU = 0 +C Load the initial value vector in YH.---------------------------------- + DO 105 I = 1,N + 105 RWORK(I+LYH-1) = Y(I) + IF (ISTATE .NE. 1) GO TO 108 +C Initial dy/dt was supplied. Load it into YH (LYD0 points to YH(*,2).) + LYD0 = LYH + NYH + DO 106 I = 1,N + 106 RWORK(I+LYD0-1) = YDOTI(I) + 108 CONTINUE +C Load and invert the EWT array. (H is temporarily set to 1.0.)-------- + CALL DEWSET (N,ITOL,RTOL,ATOL,RWORK(LYH),RWORK(LEWT)) + DO 110 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 + 110 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) +C Call DIPREPI and DPREPI to do sparse matrix preprocessing.------------ + LACOR = MIN(LACOR,LRW) + CALL DIPREPI (NEQ, Y, YDOTI, RWORK, IWORK(LIA), IWORK(LJA), + 1 IWORK(LIC), IWORK(LJC), IPFLAG, RES, JAC, ADDA) + LENRW = LWM - 1 + LENWK + LREST + IWORK(17) = LENRW + IF (IPFLAG .NE. -1) IWORK(23) = IPIAN + IF (IPFLAG .NE. -1) IWORK(24) = IPJAN + IPGO = -IPFLAG + 1 + GO TO (115, 628, 629, 630, 631, 632, 633, 634, 634), IPGO + 115 IWORK(22) = LYH + IF (LENRW .GT. LRW) GO TO 617 +C Compute initial dy/dt, if necessary, and load it into YH.------------- + LYD0 = LYH + N + IF (ISTATE .NE. 0) GO TO 120 + CALL DAINVGS (NEQ, T, Y, RWORK(LWM), RWORK(LWM), RWORK(LACOR), + 1 RWORK(LYD0), IER, RES, ADDA) + NFE = NFE + 1 + IGO = IER + 1 + GO TO (120, 565, 560, 560), IGO +C Check TCRIT for legality (ITASK = 4 or 5). --------------------------- + 120 CONTINUE + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 125 + TCRIT = RWORK(1) + IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 + IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) + 1 H0 = TCRIT - T +C Initialize all remaining parameters. --------------------------------- + 125 UROUND = DUMACH() + JSTART = 0 + RWORK(LWM) = SQRT(UROUND) + NHNIL = 0 + NJE = 0 + NLU = 0 + NSLAST = 0 + HU = 0.0D0 + NQU = 0 + CCMAX = 0.3D0 + MAXCOR = 3 + MSBP = 20 + MXNCF = 10 +C----------------------------------------------------------------------- +C The coding below computes the step size, H0, to be attempted on the +C first step, unless the user has supplied a value for this. +C First check that TOUT - T differs significantly from zero. +C A scalar tolerance quantity TOL is computed, as MAX(RTOL(i)) +C if this is positive, or MAX(ATOL(i)/ABS(Y(i))) otherwise, adjusted +C so as to be between 100*UROUND and 1.0E-3. +C Then the computed value H0 is given by.. +C NEQ +C H0**2 = TOL / ( w0**-2 + (1/NEQ) * Sum ( YDOT(i)/ywt(i) )**2 ) +C 1 +C where w0 = MAX ( ABS(T), ABS(TOUT) ), +C YDOT(i) = i-th component of initial value of dy/dt, +C ywt(i) = EWT(i)/TOL (a weight for y(i)). +C The sign of H0 is inferred from the initial values of TOUT and T. +C----------------------------------------------------------------------- + IF (H0 .NE. 0.0D0) GO TO 180 + TDIST = ABS(TOUT - T) + W0 = MAX(ABS(T),ABS(TOUT)) + IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 + TOL = RTOL(1) + IF (ITOL .LE. 2) GO TO 145 + DO 140 I = 1,N + 140 TOL = MAX(TOL,RTOL(I)) + 145 IF (TOL .GT. 0.0D0) GO TO 160 + ATOLI = ATOL(1) + DO 150 I = 1,N + IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) + AYI = ABS(Y(I)) + IF (AYI .NE. 0.0D0) TOL = MAX(TOL,ATOLI/AYI) + 150 CONTINUE + 160 TOL = MAX(TOL,100.0D0*UROUND) + TOL = MIN(TOL,0.001D0) + SUM = DVNORM (N, RWORK(LYD0), RWORK(LEWT)) + SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 + H0 = 1.0D0/SQRT(SUM) + H0 = MIN(H0,TDIST) + H0 = SIGN(H0,TOUT-T) +C Adjust H0 if necessary to meet HMAX bound. --------------------------- + 180 RH = ABS(H0)*HMXI + IF (RH .GT. 1.0D0) H0 = H0/RH +C Load H with H0 and scale YH(*,2) by H0. ------------------------------ + H = H0 + DO 190 I = 1,N + 190 RWORK(I+LYD0-1) = H0*RWORK(I+LYD0-1) + GO TO 270 +C----------------------------------------------------------------------- +C Block D. +C The next code block is for continuation calls only (ISTATE = 2 or 3) +C and is to check stop conditions before taking a step. +C----------------------------------------------------------------------- + 200 NSLAST = NST + GO TO (210, 250, 220, 230, 240), ITASK + 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) + IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + GO TO 400 + 230 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 + IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + IF (IFLAG .NE. 0) GO TO 627 + T = TOUT + GO TO 420 + 240 TCRIT = RWORK(1) + IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 + 245 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + IF (ISTATE .EQ. 2) JSTART = -2 +C----------------------------------------------------------------------- +C Block E. +C The next block is normally executed for all calls and contains +C the call to the one-step core integrator DSTODI. +C +C This is a looping point for the integration steps. +C +C First check for too many steps being taken, update EWT (if not at +C start of problem), check for too much accuracy being requested, and +C check for H below the roundoff level in T. +C----------------------------------------------------------------------- + 250 CONTINUE + IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 + CALL DEWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) + DO 260 I = 1,N + IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 + 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) + 270 TOLSF = UROUND*DVNORM (N, RWORK(LYH), RWORK(LEWT)) + IF (TOLSF .LE. 1.0D0) GO TO 280 + TOLSF = TOLSF*2.0D0 + IF (NST .EQ. 0) GO TO 626 + GO TO 520 + 280 IF ((TN + H) .NE. TN) GO TO 290 + NHNIL = NHNIL + 1 + IF (NHNIL .GT. MXHNIL) GO TO 290 + MSG = 'DLSODIS- Warning..Internal T (=R1) and H (=R2) are' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' such that in the machine, T + H = T on the next step ' + CALL XERRWD (MSG, 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' (H = step size). Solver will continue anyway.' + CALL XERRWD (MSG, 50, 101, 0, 0, 0, 0, 2, TN, H) + IF (NHNIL .LT. MXHNIL) GO TO 290 + MSG = 'DLSODIS- Above warning has been issued I1 times. ' + CALL XERRWD (MSG, 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' It will not be issued again for this problem.' + CALL XERRWD (MSG, 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + 290 CONTINUE +C----------------------------------------------------------------------- +C CALL DSTODI(NEQ,Y,YH,NYH,YH1,EWT,SAVF,SAVR,ACOR,WM,WM,RES, +C ADDA,JAC,DPRJIS,DSOLSS) +C Note: SAVF in DSTODI occupies the same space as YDOTI in DLSODIS. +C----------------------------------------------------------------------- + CALL DSTODI (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), + 1 YDOTI, RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), + 2 RWORK(LWM), RES, ADDA, JAC, DPRJIS, DSOLSS ) + KGO = 1 - KFLAG + GO TO (300, 530, 540, 400, 550, 555), KGO +C +C KGO = 1:success; 2:error test failure; 3:convergence failure; +C 4:RES ordered return; 5:RES returned error; +C 6:fatal error from CDRV via DPRJIS or DSOLSS. +C----------------------------------------------------------------------- +C Block F. +C The following block handles the case of a successful return from the +C core integrator (KFLAG = 0). Test for stop conditions. +C----------------------------------------------------------------------- + 300 INIT = 1 + GO TO (310, 400, 330, 340, 350), ITASK +C ITASK = 1. If TOUT has been reached, interpolate. ------------------- + 310 iF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 +C ITASK = 3. Jump to exit if TOUT was reached. ------------------------ + 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 + GO TO 250 +C ITASK = 4. See if TOUT or TCRIT was reached. Adjust H if necessary. + 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 + CALL DINTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) + T = TOUT + GO TO 420 + 345 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX + IF (IHIT) GO TO 400 + TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) + IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 + H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) + JSTART = -2 + GO TO 250 +C ITASK = 5. See if TCRIT was reached and jump to exit. --------------- + 350 HMX = ABS(TN) + ABS(H) + IHIT = ABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX +C----------------------------------------------------------------------- +C Block G. +C The following block handles all successful returns from DLSODIS. +C if ITASK .ne. 1, Y is loaded from YH and T is set accordingly. +C ISTATE is set to 2, and the optional outputs are loaded into the +C work arrays before returning. +C----------------------------------------------------------------------- + 400 DO 410 I = 1,N + 410 Y(I) = RWORK(I+LYH-1) + T = TN + IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 + IF (IHIT) T = TCRIT + 420 ISTATE = 2 + IF ( KFLAG .EQ. -3 ) ISTATE = 3 + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNZ + IWORK(20) = NGP + IWORK(21) = NLU + IWORK(25) = NZL + IWORK(26) = NZU + RETURN +C----------------------------------------------------------------------- +C Block H. +C The following block handles all unsuccessful returns other than +C those for illegal input. First the error message routine is called. +C If there was an error test or convergence test failure, IMXER is set. +C Then Y is loaded from YH and T is set to TN. +C The optional outputs are loaded into the work arrays before returning. +C----------------------------------------------------------------------- +C The maximum number of steps was taken before reaching TOUT. ---------- + 500 MSG = 'DLSODIS- At current T (=R1), MXSTEP (=I1) steps ' + CALL XERRWD (MSG, 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' taken on this call before reaching TOUT ' + CALL XERRWD (MSG, 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) + ISTATE = -1 + GO TO 580 +C EWT(i) .le. 0.0 for some i (not at start of problem). ---------------- + 510 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODIS- At T (=R1), EWT(I1) has become R2 .le. 0.' + CALL XERRWD (MSG, 50, 202, 0, 1, I, 0, 2, TN, EWTI) + ISTATE = -6 + GO TO 590 +C Too much accuracy requested for machine precision. ------------------- + 520 MSG = 'DLSODIS- At T (=R1), too much accuracy requested ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' for precision of machine.. See TOLSF (=R2) ' + CALL XERRWD (MSG, 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) + RWORK(14) = TOLSF + ISTATE = -2 + GO TO 590 +C KFLAG = -1. Error test failed repeatedly or with ABS(H) = HMIN. ----- + 530 MSG = 'DLSODIS- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' error test failed repeatedly or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 60, 204, 0, 0, 0, 0, 2, TN, H) + ISTATE = -4 + GO TO 570 +C KFLAG = -2. Convergence failed repeatedly or with ABS(H) = HMIN. ---- + 540 MSG = 'DLSODIS- At T (=R1) and step size H (=R2), the ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' corrector convergence failed repeatedly ' + CALL XERRWD (MSG, 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' or with ABS(H) = HMIN ' + CALL XERRWD (MSG, 30, 205, 0, 0, 0, 0, 2, TN, H) + ISTATE = -5 + GO TO 570 +C IRES = 3 returned by RES, despite retries by DSTODI. ----------------- + 550 MSG = 'DLSODIS- At T (=R1) residual routine returned ' + CALL XERRWD (MSG, 50, 206, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' error IRES = 3 repeatedly.' + CALL XERRWD (MSG, 30, 206, 1, 0, 0, 0, 0, TN, 0.0D0) + ISTATE = -7 + GO TO 590 +C KFLAG = -5. Fatal error flag returned by DPRJIS or DSOLSS (CDRV). --- + 555 MSG = 'DLSODIS- At T (=R1) and step size H (=R2), a fatal' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' error flag was returned by CDRV (by way of ' + CALL XERRWD (MSG, 50, 207, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' Subroutine DPRJIS or DSOLSS) ' + CALL XERRWD (MSG, 40, 207, 0, 0, 0, 0, 2, TN, H) + ISTATE = -9 + GO TO 580 +C DAINVGS failed because matrix A was singular. ------------------------ + 560 MSG='DLSODIS- Attempt to initialize dy/dt failed because matrix A' + CALL XERRWD (MSG, 60, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' was singular. CDRV returned zero pivot error flag. ' + CALL XERRWD (MSG, 60, 208, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = 'DAINVGS set its error flag to IER = (I1)' + CALL XERRWD (MSG, 40, 208, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C DAINVGS failed because RES set IRES to 2 or 3. ----------------------- + 565 MSG = 'DLSODIS- Attempt to initialize dy/dt failed ' + CALL XERRWD (MSG, 50, 209, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' because residual routine set its error flag ' + CALL XERRWD (MSG, 50, 209, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to IRES = (I1)' + CALL XERRWD (MSG, 20, 209, 0, 1, IER, 0, 0, 0.0D0, 0.0D0) + ISTATE = -8 + RETURN +C Compute IMXER if relevant. ------------------------------------------- + 570 BIG = 0.0D0 + IMXER = 1 + DO 575 I = 1,N + SIZE = ABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) + IF (BIG .GE. SIZE) GO TO 575 + BIG = SIZE + IMXER = I + 575 CONTINUE + IWORK(16) = IMXER +C Compute residual if relevant. ---------------------------------------- + 580 LYD0 = LYH + NYH + DO 585 I = 1, N + RWORK(I+LSAVF-1) = RWORK(I+LYD0-1) / H + 585 Y(I) = RWORK(I+LYH-1) + IRES = 1 + CALL RES (NEQ, TN, Y, RWORK(LSAVF), YDOTI, IRES) + NFE = NFE + 1 + IF ( IRES .LE. 1 ) GO TO 595 + MSG = 'DLSODIS- Residual routine set its flag IRES ' + CALL XERRWD (MSG, 50, 210, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG = ' to (I1) when called for final output. ' + CALL XERRWD (MSG, 50, 210, 0, 1, IRES, 0, 0, 0.0D0, 0.0D0) + GO TO 595 +C set y vector, t, and optional outputs. ------------------------------- + 590 DO 592 I = 1,N + 592 Y(I) = RWORK(I+LYH-1) + 595 T = TN + RWORK(11) = HU + RWORK(12) = H + RWORK(13) = TN + IWORK(11) = NST + IWORK(12) = NFE + IWORK(13) = NJE + IWORK(14) = NQU + IWORK(15) = NQ + IWORK(19) = NNZ + IWORK(20) = NGP + IWORK(21) = NLU + IWORK(25) = NZL + IWORK(26) = NZU + RETURN +C----------------------------------------------------------------------- +C Block I. +C The following block handles all error returns due to illegal input +C (ISTATE = -3), as detected before calling the core integrator. +C First the error message routine is called. If the illegal input +C is a negative ISTATE, the run is aborted (apparent infinite loop). +C----------------------------------------------------------------------- + 601 MSG = 'DLSODIS- ISTATE (=I1) illegal.' + CALL XERRWD (MSG, 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) + IF (ISTATE .LT. 0) GO TO 800 + GO TO 700 + 602 MSG = 'DLSODIS- ITASK (=I1) illegal. ' + CALL XERRWD (MSG, 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 603 MSG = 'DLSODIS-ISTATE .gt. 1 but DLSODIS not initialized.' + CALL XERRWD (MSG, 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 604 MSG = 'DLSODIS- NEQ (=I1) .lt. 1 ' + CALL XERRWD (MSG, 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 605 MSG = 'DLSODIS- ISTATE = 3 and NEQ increased (I1 to I2). ' + CALL XERRWD (MSG, 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) + GO TO 700 + 606 MSG = 'DLSODIS- ITOL (=I1) illegal. ' + CALL XERRWD (MSG, 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 607 MSG = 'DLSODIS- IOPT (=I1) illegal. ' + CALL XERRWD (MSG, 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 608 MSG = 'DLSODIS- MF (=I1) illegal. ' + CALL XERRWD (MSG, 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 611 MSG = 'DLSODIS- MAXORD (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 612 MSG = 'DLSODIS- MXSTEP (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 613 MSG = 'DLSODIS- MXHNIL (=I1) .lt. 0 ' + CALL XERRWD (MSG, 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) + GO TO 700 + 614 MSG = 'DLSODIS- TOUT (=R1) behind T (=R2) ' + CALL XERRWD (MSG, 40, 14, 0, 0, 0, 0, 2, TOUT, T) + MSG = ' Integration direction is given by H0 (=R1) ' + CALL XERRWD (MSG, 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) + GO TO 700 + 615 MSG = 'DLSODIS- HMAX (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) + GO TO 700 + 616 MSG = 'DLSODIS- HMIN (=R1) .lt. 0.0 ' + CALL XERRWD (MSG, 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) + GO TO 700 + 617 MSG = 'DLSODIS- RWORK length is insufficient to proceed. ' + CALL XERRWD (MSG, 50, 17, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 618 MSG = 'DLSODIS- IWORK length is insufficient to proceed. ' + CALL XERRWD (MSG, 50, 18, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENIW (=I1), exceeds LIW (=I2)' + CALL XERRWD (MSG, 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) + GO TO 700 + 619 MSG = 'DLSODIS- RTOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) + GO TO 700 + 620 MSG = 'DLSODIS- ATOL(=I1) is R1 .lt. 0.0 ' + CALL XERRWD (MSG, 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) + GO TO 700 + 621 EWTI = RWORK(LEWT+I-1) + MSG = 'DLSODIS- EWT(I1) is R1 .le. 0.0 ' + CALL XERRWD (MSG, 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) + GO TO 700 + 622 MSG='DLSODIS- TOUT(=R1) too close to T(=R2) to start integration.' + CALL XERRWD (MSG, 60, 22, 0, 0, 0, 0, 2, TOUT, T) + GO TO 700 + 623 MSG='DLSODIS- ITASK = I1 and TOUT (=R1) behind TCUR - HU (= R2) ' + CALL XERRWD (MSG, 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) + GO TO 700 + 624 MSG='DLSODIS- ITASK = 4 or 5 and TCRIT (=R1) behind TCUR (=R2) ' + CALL XERRWD (MSG, 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) + GO TO 700 + 625 MSG='DLSODIS- ITASK = 4 or 5 and TCRIT (=R1) behind TOUT (=R2) ' + CALL XERRWD (MSG, 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) + GO TO 700 + 626 MSG = 'DLSODIS- At start of problem, too much accuracy ' + CALL XERRWD (MSG, 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' requested for precision of machine.. See TOLSF (=R1) ' + CALL XERRWD (MSG, 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) + RWORK(14) = TOLSF + GO TO 700 + 627 MSG = 'DLSODIS- Trouble in DINTDY. ITASK = I1, TOUT = R1' + CALL XERRWD (MSG, 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) + GO TO 700 + 628 MSG='DLSODIS- RWORK length insufficient (for Subroutine DPREPI). ' + CALL XERRWD (MSG, 60, 28, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 28, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 629 MSG='DLSODIS- RWORK length insufficient (for Subroutine JGROUP). ' + CALL XERRWD (MSG, 60, 29, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 29, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 630 MSG='DLSODIS- RWORK length insufficient (for Subroutine ODRV). ' + CALL XERRWD (MSG, 60, 30, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 30, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 631 MSG='DLSODIS- Error from ODRV in Yale Sparse Matrix Package. ' + CALL XERRWD (MSG, 60, 31, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + IMUL = (IYS - 1)/N + IREM = IYS - IMUL*N + MSG=' At T (=R1), ODRV returned error flag = I1*NEQ + I2. ' + CALL XERRWD (MSG, 60, 31, 0, 2, IMUL, IREM, 1, TN, 0.0D0) + GO TO 700 + 632 MSG='DLSODIS- RWORK length insufficient (for Subroutine CDRV). ' + CALL XERRWD (MSG, 60, 32, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + MSG=' Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)' + CALL XERRWD (MSG, 60, 32, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) + GO TO 700 + 633 MSG='DLSODIS- Error from CDRV in Yale Sparse Matrix Package. ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + IMUL = (IYS - 1)/N + IREM = IYS - IMUL*N + MSG=' At T (=R1), CDRV returned error flag = I1*NEQ + I2. ' + CALL XERRWD (MSG, 60, 33, 0, 2, IMUL, IREM, 1, TN, 0.0D0) + IF (IMUL .EQ. 2) THEN + MSG=' Duplicate entry in sparsity structure descriptors. ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + IF (IMUL .EQ. 3 .OR. IMUL .EQ. 6) THEN + MSG=' Insufficient storage for NSFC (called by CDRV). ' + CALL XERRWD (MSG, 60, 33, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + ENDIF + GO TO 700 + 634 MSG='DLSODIS- At T (=R1) residual routine (called by DPREPI) ' + CALL XERRWD (MSG, 60, 34, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) + IER = -IPFLAG - 5 + MSG = ' returned error IRES (=I1)' + CALL XERRWD (MSG, 30, 34, 0, 1, IER, 0, 1, TN, 0.0D0) +C + 700 ISTATE = -3 + RETURN +C + 800 MSG = 'DLSODIS- Run aborted.. apparent infinite loop. ' + CALL XERRWD (MSG, 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) + RETURN +C----------------------- End of Subroutine DLSODIS --------------------- + END diff --git a/src/Enzo/turbforcing2D.F b/src/Enzo/turbforcing2D.F new file mode 100644 index 0000000000..c98388de9f --- /dev/null +++ b/src/Enzo/turbforcing2D.F @@ -0,0 +1,295 @@ +c#define STATIONARY_FORCING +c*********************************************************************** + subroutine calcTurbAcc2d(rank, nbox, grid, ni, nj, seed, kk, uv) +c +c PROVIDES QUASI-ISOTROPIC ZERO-MEAN SOLENOIDAL ACCELERATION FOR 2D +c TURBULENCE DRIVING (AND/OR INITIAL CONDITIONS) IN A PERIODIC BOX +c IF STATIONARY_FORCING IS DEFINED, THE ACCELERATION IS STATIONARY +c (I.E. ONLY AMPLITUDE CHANGES WITH TIME SLIGHTLY TO KEEP THE ENERGY +c INJECTION RATE CONSTANT). +c IF NOT, THIS SUBROUTINE PROVIDES DELTA-CORRELATED IN TIME FORCING. +c +c written by: Alexei Kritsuk (adapted for ADPDIS3D by Dmitry Kotov) +c +c date: August 2014 +c +c PURPOSE: +c +c EXTERNALS: +c +c INPUT: +c rank - dimension of problem +c nbox - grid resolution +c grid - grid coordinates +c ni, nj - dimensions of field array +c seed - seed for random numbers generator +c kk - ratios to compute kfi = nint(nbox/kk(1)) and kfa = nint(nbox/kk(2)) +c OUTPUT: +c uv - x and y-velocity/acceleration field +c +c LOCALS: +c +c----------------------------------------------------------------------- + implicit NONE +c----------------------------------------------------------------------- +c +c Arguments +c + real*8 uv(2,ni,nj), grid(3,ni,nj) + integer rank, nbox, ni, nj + integer(kind=8) seed +c +c Locals +c + integer i, j, imo, m, nmode, p, h + integer kx, ky, kfi, kfa + integer, allocatable :: new_seed (:) + real*8, dimension (: , :), allocatable :: mode + real*8 x, y, pi, km, amp, pha, vel, twopi, delta, kk(2) + parameter (pi=3.14159265) +#ifdef STATIONARY_FORCING + integer(kind=4) seed1 +#endif +c +c\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////// +c======================================================================= +c +c Error checks +c + if (rank .ne. 2) then + write(6,*) 'TURBOINIT2D: Only 2D grids are supported.' + write(0,*) 'stop_all_cpus in turboinit2d' + stop + endif +c +c if (max(in,jn) .gt. 1000000) then +c write(6,*) 'TURBOINIT2D: A grid dimension is too long.' +c write(6,*) ' (increase max_any_single_direction.)' +c write(0,*) 'stop_all_cpus in turboinit' +c stop +c endif +c + +c write(6,*) 'TURBOINIT2D: ig =',ig, ' jg =',jg + +c +c Set min and max wavenumbers (should be a parameter) +c + kfi = nint(nbox/kk(1)) + kfa = nint(nbox/kk(2)) +c kfi = nbox/32.0 +c kfa = nbox/30.0 +c scaling tests +c kfi = nint(nbox/14.0) +c kfa = nint(nbox/13.3) +c 512 +c kfi = nint(nbox/24.0) +c kfa = nint(nbox/23.7) +c 2048b, 4096a +c kfi = nint(nbox/48.0) +c kfa = nint(nbox/47.0) +c 2048a and 8192 +c kfi = nint(nbox/96.0) +c kfa = nint(nbox/95.0) +c +c Define modes involved +c + nmode = 0 + do kx=-kfa, kfa + do ky=-kfa, kfa + km = sqrt(real(kx*kx+ky*ky,8)) + if (km .lt. kfa .and. km .gt. kfi) nmode = nmode+1 + enddo + enddo + + if (nmode .lt. 16) then + write(6,*) 'TURBOINIT2D: Too few modes.',nmode,kfi,kfa,km + stop + endif + + allocate(mode(rank, nmode)) + nmode = 1 + do kx=-kfa, kfa + do ky=-kfa, kfa + km = sqrt(real(kx*kx+ky*ky,8)) + if (km .lt. kfa .and. km .gt. kfi) then + mode(1,nmode) = kx + mode(2,nmode) = ky + nmode = nmode+1 + endif + enddo + enddo + nmode = nmode-1 +c +c write(6,*) 'TURBOINIT2D: nmodes =',nmode +c +c initialize velocity arrays with zeroes +c + uv = 0d0 +c do j=1, jn +c do i=1, in +c u(i,j) = 0.0 +c v(i,j) = 0.0 +c enddo +c enddo +c +c fill-in velocity arrays with values; if seed is 12345 => steady force +c +#ifdef STATIONARY_FORCING + seed1 = 12346 + call srand(seed1) +#else + seed = seed + 1 +c +c p is set to the size of the seed array; usually p=6 +c + call random_seed(size=p) + allocate (new_seed(p)) +c +c assign values to new_seed(p) +c + do h=1, p + new_seed(h) = h*seed + enddo + call random_seed(put=new_seed(1:p)) +#endif + twopi = pi*2.0 + delta = 1.0/nbox +c +c use random phases "pha" uniformly sampled from [0, 2*pi) +c use random amplitudes "amp" sampled from a normal distribution (ideally) +c + do m=1, nmode +#ifdef STATIONARY_FORCING + amp = rand() + pha = rand()*twopi +#else + call random_number(amp) + amp = amp + 0.5 + call random_number(pha) + pha = pha*twopi +#endif + km = sqrt(real(mode(1,m)**2 + mode(2,m)**2,8)) + if (km .gt. 0) amp = amp/km + do j=1, nj +! y = delta*(j+jg-1) + do i=1, ni + x = grid(1,i,j) !delta*(i+ig-1) + y = grid(2,i,j) + vel = amp*sin(twopi*(mode(1,m)*x + mode(2,m)*y) + pha) + if (km .gt. 0) then + uv(1,i,j) = uv(1,i,j) + vel*mode(2,m) + uv(2,i,j) = uv(2,i,j) - vel*mode(1,m) + endif + enddo + enddo + enddo +c +c normalize to get rms 2D Mach = 1.0 for seed 12345 and given k_f=512/24 +c +#ifdef STATIONARY_FORCING + uv = uv / 4.2846841d0 +c do j=1, jn +c do i=1, in +c u(i,j) = u(i,j)/4.2846841 +c v(i,j) = v(i,j)/4.2846841 +c enddo +c enddo +#endif +c +c clean up. +c + deallocate(mode) + deallocate(new_seed) +c + return + end +c*********************************************************************** +c 2D Turbulent forcing source term +c Updates res: res = res + source*dt +c by DK +c INPUT: +c nc - number of components +c ni, nj, nk - domain dimensions (nk should be 1) +c w - flow field +c grid - grid coordinates +c jac - jacobian +c wk - work array, size 2*ni*nj +c dt - time step +c update_sol - flag to update w +c OUTPUT: +c res - residual (updated) +c*********************************************************************** + subroutine turbForce2D(nc, ni, nj, nk, nig, njg, nkg, + * w, grid, jac, wk, turbAcc, + * dt, seed, res, update_sol) + implicit none +#ifdef USING_MPI + include 'mpif.h' + integer err + real*8 gvmpi(5) +#endif + integer :: nc, ni, nj, nk, argi(1), nbox, i, j, ol2, nig, njg, nkg + integer(kind=8) :: seed + real*8 :: grid(3,ni,nj), w(nc,ni,nj), wk(2,ni,nj), res(nc,ni,nj) + real*8 :: rho, dt, dumx, ss, kk(2), de, turbAcc(4,ni,nj) + real*8 :: jac(ni,nj), norm, eps, dru, drv, ruavr, rvavr, gv(5) + logical :: update_sol + + if(nk.ne.1) stop "turbForceNorm2d is for 2D only" + if(nig .ne. njg) stop "turbForceNorm2d assume ni=nj" + + if(argi(1).eq.0) return + + nbox = nig - argi(1) ! nig - olap + ol2 = argi(1)/2 + + call calcTurbAcc2d(2, nbox, grid, ni, nj, seed, kk, wk) + + gv = 0d0 + do j=1+ol2,nj-ol2 + do i=1+ol2,ni-ol2 +c ss = jac(i,j) + gv(1) = gv(1) + w(2,i,j)*wk(1,i,j)+w(3,i,j)*wk(2,i,j) ! + gv(2) = gv(2) + w(1,i,j)*(wk(1,i,j)**2 + wk(2,i,j)**2) ! + gv(3) = gv(3) + w(1,i,j)*wk(1,i,j) ! + gv(4) = gv(4) + w(1,i,j)*wk(2,i,j) ! + gv(5) = gv(5) + w(1,i,j) + enddo + enddo + +#ifdef USING_MPI + call MPI_AllReduce(gv, gvmpi, 5, MPI_DOUBLE_PRECISION, MPI_SUM, + * MPI_COMM_WORLD, err ) + gv = gvmpi +#endif + + gv(3:4) = gv(3:4)/gv(5) ! average momentum + + norm = ( sqrt(gv(1)**2+gv(2)*dt*eps*2.d0*nbox**2) - gv(1) )/gv(2) + + do j=1,nj + do i=1,ni + rho = w(1,i,j) + dru = (wk(1,i,j)-gv(3))*norm + drv = (wk(2,i,j)-gv(4))*norm + de = (dru**2+drv**2)*0.5d0*rho + w(2,i,j)*dru + w(3,i,j)*drv + res(2,i,j) = res(2,i,j) + dru*rho + res(3,i,j) = res(3,i,j) + drv*rho + res(5,i,j) = res(5,i,j) + de + turbAcc(4,i,j) = turbAcc(4,i,j) + de + enddo + enddo + + if(update_sol) then + do j=1,nj + do i=1,ni + w(1:nc,i,j) = w(1:nc,i,j) + res(1:nc,i,j) + enddo + enddo + endif + + end subroutine + + + diff --git a/src/Enzo/turbforcingOU.F b/src/Enzo/turbforcingOU.F new file mode 100644 index 0000000000..0760bd2dfb --- /dev/null +++ b/src/Enzo/turbforcingOU.F @@ -0,0 +1,905 @@ +C ********************************************************************** +C *** Forcing terms for OU turbulence (2D or 3D) +C *** Adapted from AREPO code developed by Volker Springel +C ********************************************************************** + subroutine cello_init_turbulence_OU + & (cello_is_root, + & cello_rank, + & cello_domain_size, + & cello_gamma, + & cello_apply_injection_rate, + & cello_cooling_term, + & cello_injection_rate, + & cello_kfi, + & cello_kfa, + & cello_mach, + & cello_read_sol, + & cello_sol_weight, + & cello_weight_norm) + + implicit none + include 'turbforcingOU.h' +C + integer :: cello_is_root + integer :: cello_rank + real*8 :: cello_domain_size(3) + real*8 :: cello_gamma; + integer :: cello_apply_injection_rate + integer :: cello_cooling_term + real*8 :: cello_injection_rate + real*8 :: cello_kfi + real*8 :: cello_kfa + real*8 :: cello_mach + integer :: cello_read_sol + real*8 :: cello_sol_weight + real*8 :: cello_weight_norm + integer :: modes_input +C + real*8 :: Mach, gamma, P0, rho0, c_s, Edot + real*8 :: kmax, kmin, boxSize(3), kx, ky, kz, kk, kc, amp + integer :: ikmax(3), ikx, iky, ikz, N, i, j + real*8 :: RandomPhase, argx(3) + real*8, parameter :: PI_2 = 3.14159265358979323846d0*2.d0 + integer :: myid, seed, modesPerK + logical :: apply_injection_rate + + apply_injection_rate = (cello_apply_injection_rate .ne. 0) + + Ndims = cello_rank + gamma = cello_gamma + boxSize(1) = cello_domain_size(1) + boxSize(2) = cello_domain_size(2) + boxSize(3) = cello_domain_size(3) + if (Ndims.eq.3) then + modesPerK = 4 + boxVolume = boxSize(1) * boxSize(2) * boxSize(3) + elseif(Ndims.eq.2) then + modesPerK = 2 + boxVolume = boxSize(1) * boxSize(2) + else + stop "only dim=2 or dim=3 is supported" + endif + + Edot = cello_injection_rate + SolWeight = cello_sol_weight + Mach = cello_mach + kmin = cello_kfi + kmax = cello_kfa + + P0 = 1.d0 + totTime = 0d0 + rho0 = 1.d0 + c_s = sqrt(gamma*P0/rho0) + kc = 0.5d0*(kmin + kmax) + if (apply_injection_rate) then + Mach = (PI_2 * Edot / (rho0 * kc))**(1.d0/3.d0) / c_s + end if + TDecay = PI_2/(Mach*c_s*kc) + DtFreq = 0.1d0*TDecay + OUVar = (Mach*c_s)/TDecay + + ikmax(1:3) = nint(boxSize(1:3)*(kmax/PI_2)) + if (Ndims.eq.2) ikmax(3) = 0 + + NModes = 0 + do ikx = 0, ikmax(1) + kx = PI_2*dble(ikx)/boxSize(1) + do iky = 0, ikmax(2) + ky = PI_2*dble(iky)/boxSize(2) + do ikz = 0, ikmax(3) + kz = PI_2*dble(ikz)/boxSize(3) + + kk = sqrt(kx*kx + ky*ky + kz*kz) + + if((kk.ge.kmin).and.(kk.le.kmax)) then + NModes = NModes + modesPerK + endif + + enddo + enddo + enddo + + allocate(Mode(3,NModes)) + allocate(OUPhase(2,3,NModes), Ampl(NModes), Phase(2,3,NModes)) + + if (Ndims.eq.3) then + WeightNorm = + & 1.d0/sqrt(1.d0-2.d0*SolWeight+3.d0*SolWeight**2) + else + WeightNorm = + & 1.d0/sqrt(1.d0-2.d0*SolWeight+2.d0*SolWeight**2) + endif + + WeightNorm = WeightNorm * 2.d0 / sqrt(dble(NModes)) + + ! copy out WeightNorm + cello_weight_norm = WeightNorm + + N = 0 + do ikx = 0, ikmax(1) + kx = PI_2*dble(ikx)/boxSize(1) + do iky = 0, ikmax(2) + ky = PI_2*dble(iky)/boxSize(2) + do ikz = 0, ikmax(3) + kz = PI_2*dble(ikz)/boxSize(3) + + kk = sqrt(kx*kx + ky*ky + kz*kz) + + if((kk.ge.kmin).and.(kk.le.kmax)) then + amp = 1.d0 - 4.d0*(kk-kc)**2/(kmax-kmin)**2 + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = ky + Mode(3,N) = kz + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = -ky + Mode(3,N) = kz + + if (Ndims.eq.3) then + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = ky + Mode(3,N) = -kz + + N = N + 1 + Ampl(N) = amp + Mode(1,N) = kx + Mode(2,N) = -ky + Mode(3,N) = -kz + endif + endif + + enddo + enddo + enddo + +C if (cello_is_root .ne. 0) then +C print *, "accDims = ", Ndims +C print '(A,3(G10.4))', " Box = ", boxSize +C print *, "NModes = ", NModes +C print *, "Mach = ", Mach +C print *, 'c_s = ', c_s +C print *, 'TDecay = ', TDecay +C print *, 'DtFreq = ', DtFreq +C print *, 'OUVar = ', OUVar +C print *, 'kc = ', kc +C print *, 'cello_read_sol = ',cello_read_sol +C endif + + if (cello_read_sol .ne. 0) then + open (42, file='OUturb.bin', form='UNFORMATTED', + & access='STREAM', action='read') + read (42) modes_input + if (modes_input .ne. NModes) then + stop "wrong number of modes in OUturb.bin" + endif + if (cello_is_root .ne. 0) print *, 'reading phases for ', + & NModes, ' modes' + read (42) seed, totTime, OUPhase, Phase + close (42) + call initrandomx(seed) + else + call initrandomx(100) + + do j = 1, NModes + do i = 1, 3 + OUPhase(1,i,j) = RandomPhase()*OUVar + OUPhase(2,i,j) = RandomPhase()*OUVar + enddo + enddo + + call calcPhases() + endif + + end subroutine + + +C ********************************************************************** + subroutine saveTurbForcingOUState(myid, nameSuffix) + implicit none + include 'turbforcingOU.h' + integer :: myid, seed, crandseed + character(*) :: nameSuffix + + if (myid.eq.0) then + seed = crandseed() + open (42, file='OUturb.bin'//trim(nameSuffix), + & form='UNFORMATTED', access='STREAM') + write (42) NModes, seed, totTime, OUPhase, Phase + close (42) + endif + + end subroutine +C ********************************************************************** + subroutine cleanupTurbForcingOU(myid) + implicit none + include 'turbforcingOU.h' + integer :: myid + + call saveTurbForcingOUState(myid, char(0)) + deallocate(Mode, OUPhase, Ampl, Phase) + + end subroutine +C ********************************************************************** + real*8 function RandomPhase() + implicit none + real*8 r0, r1, randomnr + real*8, parameter :: PI_2 = 3.14159265358979323846d0*2.d0 + + r0 = randomnr() + r1 = randomnr() + + RandomPhase = sqrt(-2.d0*log(r0))*cos(PI_2*r1) + end function +C ********************************************************************** + subroutine calcPhases() + implicit none + include 'turbforcingOU.h' + integer :: i, j + real*8 :: ka, kb, kk, kk1, diva, divb, curla, curlb + + do j = 1, NModes + ka = 0d0 + kb = 0d0 + kk = 0d0 + + do i = 1, Ndims + kk = kk + Mode(i,j)**2 + ka = ka + Mode(i,j)*OUPhase(2,i,j) + kb = kb + Mode(i,j)*OUPhase(1,i,j) + enddo + + kk1 = 1.d0/kk + + do i = 1, Ndims + diva = Mode(i,j)*ka*kk1 + divb = Mode(i,j)*kb*kk1 + curla = OUPhase(1,i,j) - divb + curlb = OUPhase(2,i,j) - diva + Phase(1,i,j) = SolWeight*curla + (1.d0 - SolWeight)*divb + Phase(2,i,j) = SolWeight*curlb + (1.d0 - SolWeight)*diva + enddo + + enddo + + end subroutine +C ********************************************************************** + subroutine updatePhases() + implicit none + include 'turbforcingOU.h' + real*8 :: damping, dfact, RandomPhase + integer :: i, j, n,crandseed + + damping = exp(-DtFreq/TDecay) + dfact = sqrt(1.d0 - damping**2) + do j = 1, NModes + do i = 1, 3 + do n = 1, 2 + OUPhase(n,i,j) = OUPhase(n,i,j)*damping + + & OUVar*dfact*RandomPhase() + enddo + enddo + enddo + end subroutine +C ********************************************************************** + subroutine cello_turbou_state_size(n_real_state,n_integer_state) + implicit none + include 'turbforcingOU.h' + integer :: n_real_state, n_integer_state + n_real_state = 1+2*(NModes*2*3) + n_integer_state = 2 + + end subroutine +C ********************************************************************** + subroutine cello_get_turbou_state(real_state,integer_state) + implicit none + integer num_modes + real*8 :: real_state(2*3*num_modes) + integer :: integer_state(*),crandseed + include 'turbforcingOU.h' + integer i,j,k,n + + integer_state(1) = NModes + integer_state(2) = crandseed() + + k=1 + real_state(k) = totTime + k=k+1 + do j = 1, NModes + do i = 1, 3 + do n = 1, 2 + real_state(k) = OUPhase(n,i,j) + real_state(k+1) = Phase(n,i,j) + k=k+2 + enddo + enddo + enddo + end subroutine +C ********************************************************************** + subroutine cello_put_turbou_state(real_state,integer_state) + implicit none + integer num_modes + real*8 :: real_state(2*3*num_modes) + integer :: integer_state(*) + include 'turbforcingOU.h' + integer i,j,k,n + + NModes = integer_state(1) + call setcrandseed (integer_state(2)) + + k=1 + TotTime = real_state(k) + k=k+1 + do j = 1, NModes + do i = 1, 3 + do n = 1, 2 + OUPhase(n,i,j) = real_state(k) + Phase (n,i,j) = real_state(k+1) + k=k+2 + enddo + enddo + enddo + end subroutine +C ********************************************************************** +c 3D Turbulent forcing source term +c Updates res: res = res + source*dt +c by DK +c INPUT: +c ni, nj, nk - local domain dimensions +c w - flow field +c grid - grid coordinates +c temperature - temperature field +c wk - work array 3*ni*nj*nk +c dt - time step +c update_sol - flag to update w +c OUTPUT: +c res - residual (updated) +c turbAcc - injected turbulent accelerations and energy (updated) +c*********************************************************************** + subroutine turbForceOU + & (mx,my,mz, + & ni, nj, nk, + & field_density, + & grid, + & wk, time, dt, + & update_sol, + & cello_apply_cooling, + & cello_apply_forcing, + & cello_apply_injection_rate, + & cello_update_phases, + & cello_cooling_term, + & cello_gamma, + & cello_injection_rate, + & cello_olap, + & r_gv + & ) + implicit none + include 'turbforcingOU.h' + + integer :: cello_apply_forcing + integer :: cello_apply_injection_rate + integer :: cello_cooling_term + integer :: cello_apply_cooling + real*8 :: cello_gamma + real*8 :: cello_injection_rate + integer :: cello_olap + real*8 :: r_gv(4) + integer :: cello_update_phases + + integer :: mx,my,mz + integer :: ni, nj, nk, i, j, k, m, dir + integer :: ol2, ol2k, cooling_term + real*8 :: grid(3,mx,my,mz) + real*8 :: field_density(mx,my,mz) + real*8 :: wk(3,mx,my,mz) + real*8 :: gamma + real*8 :: deTurb + real*8 :: rho, time, dt, dumx, acc(3), da(3), kr, de + logical :: update_sol, apply_injection_rate + real*8 :: timeUpdate + if(cello_apply_forcing .eq. 0) return + apply_injection_rate = (cello_apply_injection_rate .ne. 0) + + ol2 = cello_olap/2 + ol2k = ol2 + if (nk.eq.1) ol2k = 0 + + timeUpdate = (floor(time / DtFreq)+1)*DtFreq + + if ( cello_update_phases.ne.0. ) then + totTime = totTime + dt + if ( (time .le. timeUpdate) .and. + & (timeUpdate .lt. time + dt)) then + call updatePhases() + call calcPhases() + totTime = totTime - DtFreq + endif + endif + + r_gv = 0d0 + do k=1,nk + do j=1,nj + do i=1,ni + + acc = 0d0 + do m=1, NModes + kr = 0d0 + do dir=1,3 + kr = kr + Mode(dir,m)*grid(dir,i,j,k) + enddo + + acc(1:3) = acc(1:3) + Ampl(m)*( Phase(1,1:3,m)*cos(kr) - + & Phase(2,1:3,m)*sin(kr) ) + enddo + + acc = acc*WeightNorm + + if ((k.ge.1+ol2k).and.(k.le.nk-ol2k).and. + & (j.ge.1+ol2).and.(j.le.nj-ol2).and. + & (i.ge.1+ol2).and.(i.le.ni-ol2)) then + rho = field_density(i,j,k) + r_gv(1:3) = r_gv(1:3) + acc*rho + r_gv(4) = r_gv(4) + rho + endif + + wk(1:3,i,j,k) = acc + enddo + enddo + enddo + end subroutine +C====================================================================== +c jac - jacobian + subroutine turbForceShift + & (mx,my,mz, + & ni, nj, nk, + & field_density, + & field_momentum_x, + & field_momentum_y, + & field_momentum_z, + & field_jacobian, wk, + & update_sol, + & cello_apply_injection_rate, + & cello_olap, + & cello_injection_rate, + & r_gv, + & r_av + & ) + implicit none + include 'turbforcingOU.h' + + integer :: ni, nj, nk, i, j, k + integer :: cello_apply_injection_rate + integer :: cello_olap + integer :: mx,my,mz + real*8 :: field_density(mx,my,mz) + real*8 :: field_momentum_x(mx,my,mz) + real*8 :: field_momentum_y(mx,my,mz) + real*8 :: field_momentum_z(mx,my,mz) + real*8 :: field_jacobian(mx,my,mz) + real*8 :: wk(3,mx,my,mz) + real*8 :: cello_injection_rate + logical :: update_sol, apply_injection_rate + real*8 :: r_gv(4), r_av(2) + + real*8 :: da(3), acc(3), Edot + integer ol2, ol2k +C +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +C force total impulse to zero using reduction r_gv +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + + da = r_gv(1:3)/r_gv(4) + do k=1,nk + do j=1,nj + do i=1,ni + wk(1:3,i,j,k) = wk(1:3,i,j,k) - da + enddo + enddo + enddo + + apply_injection_rate = (cello_apply_injection_rate .ne. 0) + + if (apply_injection_rate) then + +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +C compute r_av reduction +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + + Edot = cello_injection_rate * boxVolume + + ol2 = cello_olap/2 + ol2k = ol2 + if (nk.eq.1) ol2k = 0 + + r_av = 0d0 + do k=1+ol2k,nk-ol2k + do j=1+ol2,nj-ol2 + do i=1+ol2,ni-ol2 + acc = wk(1:3,i,j,k) + r_av(1) = r_av(1) + 0.5d0 * field_jacobian(i,j,k) * + & field_density(i,j,k) * dot_product(acc, acc) + if (Ndims.eq.2) then + r_av(2) = r_av(2) + + & field_jacobian(i,j,k) * + & (field_momentum_x(i,j,k)*wk(1,i,j,k) + + & field_momentum_y(i,j,k)*wk(2,i,j,k)) + else if (Ndims.eq.3) then + r_av(2) = r_av(2) + + & field_jacobian(i,j,k) * + & (field_momentum_x(i,j,k)*wk(1,i,j,k) + + & field_momentum_y(i,j,k)*wk(2,i,j,k) + + & field_momentum_z(i,j,k)*wk(3,i,j,k)) + endif + enddo + enddo + enddo + endif + end subroutine +C====================================================================== + subroutine turbForceUpdate + & (mx, my, mz, + & ni, nj, nk, + & field_density, + & field_momentum_x, + & field_momentum_y, + & field_momentum_z, + & have_faces, + & field_momentum_xx, + & field_momentum_yx, + & field_momentum_zx, + & field_momentum_xy, + & field_momentum_yy, + & field_momentum_zy, + & field_momentum_xz, + & field_momentum_yz, + & field_momentum_zz, + & field_energy, + & resid_density, + & resid_momentum_x, + & resid_momentum_y, + & resid_momentum_z, + & resid_energy, + & field_temperature, wk, dt, + & turbAcc, update_sol, + & cello_apply_injection_rate, + & cello_injection_rate, + & cello_cooling_term, + & cello_apply_cooling, + & cello_gamma, + & cello_hc_alpha, + & cello_hc_sigma, + & cello_totemp, + & r_av + & ) + implicit none + include 'turbforcingOU.h' + + integer :: mx,my,mz + integer :: ni, nj, nk, i, j, k + real*8 :: field_density(mx,my,mz) + real*8 :: field_momentum_x(mx,my,mz) + real*8 :: field_momentum_y(mx,my,mz) + real*8 :: field_momentum_z(mx,my,mz) + integer :: have_faces + real*8 :: field_momentum_xx(mx,my,mz) + real*8 :: field_momentum_xy(mx,my,mz) + real*8 :: field_momentum_xz(mx,my,mz) + real*8 :: field_momentum_yx(mx,my,mz) + real*8 :: field_momentum_yy(mx,my,mz) + real*8 :: field_momentum_yz(mx,my,mz) + real*8 :: field_momentum_zx(mx,my,mz) + real*8 :: field_momentum_zy(mx,my,mz) + real*8 :: field_momentum_zz(mx,my,mz) + real*8 :: field_energy(mx,my,mz) + integer :: cello_apply_injection_rate + integer :: cello_cooling_term + integer :: cello_apply_cooling + real*8 :: cello_gamma + real*8 :: cello_hc_alpha + real*8 :: cello_hc_sigma + real*8 :: resid_density(mx,my,mz) + real*8 :: resid_momentum_x(mx,my,mz) + real*8 :: resid_momentum_y(mx,my,mz) + real*8 :: resid_momentum_z(mx,my,mz) + real*8 :: resid_energy(mx,my,mz) + real*8 :: dt + real*8 :: field_temperature(mx,my,mz), wk(3,mx,my,mz) + real*8 :: turbAcc(4, mx,my,mz) + real*8 :: cello_injection_rate + real*8 :: cello_totemp + logical :: update_sol, apply_injection_rate + real*8 :: r_av(2) + + real*8 :: deTurb, rho, du(3), Acorr, acc(3), de, Edot, gamma, E0 + real*8 :: gm1, hc_alpha, hc_sigma, totemp + integer nd1, cooling_term + + apply_injection_rate = (cello_apply_injection_rate .ne. 0) + + if (apply_injection_rate) then + Edot = cello_injection_rate * boxVolume + Acorr = solveQuadEquation(r_av(1)*dt, r_av(2), -Edot) + else + Acorr = 1.d0 + endif + gamma = cello_gamma + + E0 = 1.d0 / (gamma - 1.d0) + gm1 = gamma-1 + hc_alpha = cello_hc_alpha + hc_sigma = cello_hc_sigma + +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +C use computed Acorr +C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + cooling_term = cello_cooling_term + + if (cooling_term.eq.-1) then +! backwards compatibility for "apply_cooling" option + if (cello_apply_cooling .eq. 0) then + cooling_term = 0 + else + cooling_term = 1 + endif + endif + + nd1 = Ndims + 1 + do k=1,nk + do j=1,nj + do i=1,ni + acc = Acorr * wk(1:3,i,j,k) + du = acc*dt + + rho = field_density(i,j,k) + if (Ndims.eq.2) then + deTurb = dot_product(du(1:Ndims),du(1:Ndims))* + & 0.5d0*rho + + & (field_momentum_x(i,j,k) * du(1) + + & field_momentum_y(i,j,k) * du(2)) + else if (Ndims.eq.3) then + deTurb = dot_product(du(1:Ndims),du(1:Ndims))* + & 0.5d0*rho + + & (field_momentum_x(i,j,k) * du(1) + + & field_momentum_y(i,j,k) * du(2) + + & field_momentum_z(i,j,k) * du(3)) + end if + de = addCooling (deTurb, rho, + & field_energy(i,j,k), field_temperature(i,j,k)) + resid_momentum_x(i,j,k) = resid_momentum_x(i,j,k) + + & du(1)*rho + resid_momentum_y(i,j,k) = resid_momentum_y(i,j,k) + + & du(2)*rho + if (Ndims.eq.3) then + resid_momentum_z(i,j,k) = resid_momentum_z(i,j,k) + + & du(3)*rho + end if + resid_energy(i,j,k) = resid_energy(i,j,k) + de + + turbAcc(1:Ndims,i,j,k) = + & turbAcc(1:Ndims,i,j,k) + acc(1:Ndims) + turbAcc(4,i,j,k) = turbAcc(4,i,j,k) + de + enddo + enddo + enddo + if(update_sol) then + field_density = field_density + resid_density + field_momentum_x = field_momentum_x + resid_momentum_x + field_momentum_y = field_momentum_y + resid_momentum_y + if (Ndims.eq.3) then + field_momentum_z = field_momentum_z + resid_momentum_z + endif + field_energy = field_energy + resid_energy + + if (have_faces.eq.1) then + do k=1,nk + do j=1,nj + do i=1,ni-1 + field_momentum_xx(i,j,k) = field_momentum_xx(i,j,k) + + & 0.5*(resid_momentum_x(i,j,k) + & + resid_momentum_x(i+1,j,k)) + field_momentum_yx(i,j,k) = field_momentum_yx(i,j,k) + + & 0.5*(resid_momentum_y(i,j,k) + & + resid_momentum_y(i+1,j,k)) + field_momentum_zx(i,j,k) = field_momentum_zx(i,j,k) + + & 0.5*(resid_momentum_z(i,j,k) + & + resid_momentum_z(i+1,j,k)) + end do + end do + end do + do k=1,nk + do j=1,nj-1 + do i=1,ni + field_momentum_xy(i,j,k) = field_momentum_xy(i,j,k) + + & 0.5*(resid_momentum_x(i,j,k) + & + resid_momentum_x(i,j+1,k)) + field_momentum_yy(i,j,k) = field_momentum_yy(i,j,k) + + & 0.5*(resid_momentum_y(i,j,k) + & + resid_momentum_y(i,j+1,k)) + field_momentum_zy(i,j,k) = field_momentum_zy(i,j,k) + + & 0.5*(resid_momentum_z(i,j,k) + & + resid_momentum_z(i,j+1,k)) + end do + end do + end do + do k=1,nk-1 + do j=1,nj + do i=1,ni + field_momentum_xz(i,j,k) = field_momentum_xz(i,j,k) + + & 0.5*(resid_momentum_x(i,j,k) + & + resid_momentum_x(i,j,k+1)) + field_momentum_yz(i,j,k) = field_momentum_yz(i,j,k) + + & 0.5*(resid_momentum_y(i,j,k) + & + resid_momentum_y(i,j,k+1)) + field_momentum_zz(i,j,k) = field_momentum_zz(i,j,k) + + & 0.5*(resid_momentum_z(i,j,k) + & + resid_momentum_z(i,j,k+1)) + end do + end do + end do + end if + endif + + contains +c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + real*8 function solveQuadEquation(a, b, c) + real*8 :: a, b, c, sd + sd = sqrt(b * b - 4 * a * c) + solveQuadEquation = (sd - b) / (2.d0 * a) + end function +c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + real*8 function addCooling(deTurb, rho, E, temp) + external cooling_F2, cooling_F6, cooling_F40 + integer, parameter :: iTask = 1, iOpt = 0, NRW = 32, NIW = 21 + real*8, parameter :: ngas = 1.d0 + integer :: iState, IW(NIW) + real*8 :: deTurb, rho, e, temp, T, T2, X + real*8 :: tm0, tm1, Y(5), RW(NRW), dummy + + select case (cooling_term) + case (0) +c No cooling + addCooling = deTurb + case (1) +c Empiric cooling formula + T = temp*2.d3 ! Convert to SI + + addCooling = deTurb - dt * ngas * rho* + & (1.d7*exp(-1.184d5/(T+1.d3)) + 1.4d-2*sqrt(T)*exp(-92/T))* + & 1.d-5 ! Convert from SI + case (2) +c Stiff version of case 1 => use ODE solver + X = gm1*totemp/rho + Y(1) = E + Y(2) = deTurb/dt + Y(3) = temp - X*E + Y(4) = X + Y(5) = rho + tm0 = 0d0 + tm1 = dt + iState = 1 + 002 CALL DLSODE (cooling_F2, 1, Y, tm0, tm1, 1, 1.D-8, 1.D-10, + & iTask, iState, iOpt, RW, NRW, IW, NIW, dummy, 22) ! 21 TO USE JAC; 22 - NO JAC + + IF(iState .EQ. -1) THEN + iState = 2 + GOTO 002 + ENDIF + addCooling = Y(1) - E +! T = temp*2.d3 ! Convert to SI +! X = deTurb - dt * ngas * rho* +! & (1.d7*exp(-1.184d5/(T+1.d3)) + 1.4d-2*sqrt(T)*exp(-92/T))* +! & 1.d-5 ! Convert from SI +! print *, IW(11), addCooling, X + case (3) +c Linear cooling (as in W.Schmidt & P.Grete 2019) + addCooling = deTurb - dt * hc_alpha * (E - E0) + case (4) +c Stiff version of case 3 => use analytical solution + X = deTurb/(dt * hc_alpha) + addCooling = (E0 + X - E)*(1.0 - exp(-hc_alpha * dt)) + case (40) +c Stiff version of case 3 => use ODE solver (for testing) + Y(1) = E + Y(2) = deTurb/dt + Y(3) = E0 + Y(4) = hc_alpha + tm0 = 0d0 + tm1 = dt + iState = 1 + 040 CALL DLSODE (cooling_F40, 1, Y, tm0, tm1, 1, 1.D-8, 1.D-10, + & iTask, iState, iOpt, RW, NRW, IW, NIW, dummy, 22) ! 21 TO USE JAC; 22 - NO JAC + + IF(iState .EQ. -1) THEN + iState = 2 + GOTO 040 + ENDIF + addCooling = Y(1) - E +! print *, IW(11), addCooling, +! & (E0 + deTurb/(dt * hc_alpha) - E)*(1.0 - exp(-hc_alpha * dt)) + case (5) +c Stefan's law (as in D.Porter 2002) + T2 = temp * temp + addCooling = deTurb - dt * hc_sigma * T2 * T2 + case (6) +c Stiff version of case 5 => use ODE solver + X = gm1*totemp/rho + Y(1) = E + Y(2) = deTurb/dt + Y(3) = temp - X*E + Y(4) = X + Y(5) = hc_sigma + tm0 = 0d0 + tm1 = dt + iState = 1 + 006 CALL DLSODE (cooling_F6, 1, Y, tm0, tm1, 1, 1.D-8, 1.D-10, + & iTask, iState, iOpt, RW, NRW, IW, NIW, dummy, 22) ! 21 TO USE JAC; 22 - NO JAC + + IF(iState .EQ. -1) THEN + iState = 2 + GOTO 006 + ENDIF + addCooling = Y(1) - E +! print *, IW(11), addCooling +! & deTurb - dt * hc_sigma * (temp ** 4) + case default + stop "unsupported cooling term" + end select + + end function +c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + end subroutine +C ********************************************************************** + subroutine cooling_F2(NEQ, tm, Y, Ydot) + implicit none + integer :: NEQ + real*8, parameter :: ngas = 1.d0 + real*8 :: tm, Y(*), Ydot(NEQ) + real*8 :: deTurbDot, T, temp, rho + + deTurbDot = Y(2) + temp = Y(3) + Y(4) * Y(1) ! T = (T0 - k*E0) + k*E + rho = Y(5) + + T = temp*2.d3 ! Convert to SI + + Ydot(1) = deTurbDot - ngas * rho* + & (1.d7*exp(-1.184d5/(T+1.d3)) + 1.4d-2*sqrt(T)*exp(-92/T))* + & 1.d-5 ! Convert from SI + + end subroutine +C ********************************************************************** + subroutine cooling_F6(NEQ, tm, Y, Ydot) + implicit none + integer :: NEQ + real*8, parameter :: ngas = 1.d0 + real*8 :: tm, Y(*), Ydot(NEQ) + real*8 :: deTurbDot, T2, temp, hc_sigma + + deTurbDot = Y(2) + temp = Y(3) + Y(4) * Y(1) ! T = (T0 - k*E0) + k*E + hc_sigma = Y(5) + + T2 = temp * temp + Ydot(1) = deTurbDot - hc_sigma * T2 * T2 + + end subroutine +C ********************************************************************** + subroutine cooling_F40(NEQ, tm, Y, Ydot) + implicit none + integer :: NEQ + real*8, parameter :: ngas = 1.d0 + real*8 :: tm, Y(*), Ydot(NEQ) + real*8 :: deTurbDot, E0, hc_alpha + + deTurbDot = Y(2) + E0 = Y(3) + hc_alpha = Y(4) + + Ydot(1) = deTurbDot - hc_alpha * (Y(1) - E0) + end subroutine diff --git a/src/Enzo/turbforcingOU.h b/src/Enzo/turbforcingOU.h new file mode 100644 index 0000000000..a02066af7c --- /dev/null +++ b/src/Enzo/turbforcingOU.h @@ -0,0 +1,11 @@ + common /TURB3D/ OUPhase, Ampl, Phase, Mode, totTime, DtFreq + common /TURB3D/ OUVar, TDecay, SolWeight, WeightNorm, boxVolume + common /TURB3D/ NModes, Ndims + real*8 :: totTime, TDecay, DtFreq, SolWeight, WeightNorm + real*8 :: boxVolume + real*8 :: OUVar ! Ornstein-Uhlenbeck var + integer :: NModes, Ndims + real*8, pointer :: OUPhase(:,:,:) ! Ornstein-Uhlenbeck phases + real*8, pointer :: Ampl(:) + real*8, pointer :: Phase(:,:,:) + real*8, pointer :: Mode(:,:) diff --git a/src/Enzo/turbulence/CMakeLists.txt b/src/Enzo/turbulence/CMakeLists.txt new file mode 100644 index 0000000000..20bb96286b --- /dev/null +++ b/src/Enzo/turbulence/CMakeLists.txt @@ -0,0 +1,23 @@ +# See LICENSE_CELLO file for license and copyright information + +# STEP 1: adds source files related to Hydro/MHD integrators to the enzo target +# +# in the future, we may want to slightly refactor the files in this +# subdirectory so that they can be compiled into their own subtarget (there's +# a lot here that the rest of Enzo-E doesn't need to know anything about and +# this can improve compile times) + +# Get the list of source files in this directory & the fortran subdirectories +# - we do this using GLOB patterns. This approach is not recommended by the +# authors of CMake (their recommendation is to explicitly list all files that +# must be installed). +# - Some of the disadvantages of this approach are mitigated by inclusion of +# the CONFIGURE_DEPENDS flag. +# - See the CMake Primer section of the developer documentation for more details +file(GLOB LOCAL_SRC_FILES CONFIGURE_DEPENDS + *.cpp *.hpp +) + +# TODO: Check if that file can be removed for good. It also not being used in the SCons build. +# -> PPML_sub.F:(.text+0x5ebf): multiple definition of `qdd6_'; CMakeFiles/enzo-e.dir/PPML_QDD6.F.o:PPML_QDD6.F:(.text+0x0): first defined here +target_sources(enzo PRIVATE ${LOCAL_SRC_FILES}) diff --git a/src/Enzo/turbulence/EnzoInitialTurbulenceMhdIT.cpp b/src/Enzo/turbulence/EnzoInitialTurbulenceMhdIT.cpp new file mode 100644 index 0000000000..068ff48f3b --- /dev/null +++ b/src/Enzo/turbulence/EnzoInitialTurbulenceMhdIT.cpp @@ -0,0 +1,348 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoInitialTurbulenceMhdIT.cpp +/// @author Alexei Kritsuk (akritsuk@ucsd.edu) +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Wed Jul 23 00:30:49 UTC 2014 +/// @date Fri Aug 24 00:30:49 UTC 2018 +/// @brief [\ref Enzo] Initial conditions for isothermal MHD turbulence simulation with PPML-IT solver + +#include "cello.hpp" + +#include "enzo.hpp" + +// #define DEBUG_TURBULENCE + +#ifdef DEBUG_TURBULENCE +# define TRACE_TURBULENCE CkPrintf("%s:%d TRACE DEBUG_TURBULENCE\n",__FILE__,__LINE__); +#else +# define TRACE_TURBULENCE /* */ +#endif +//---------------------------------------------------------------------- + +EnzoInitialTurbulenceMhdIT::EnzoInitialTurbulenceMhdIT +(int init_cycle, double init_time, + double density_initial, + double bfieldx_initial, + double gamma) throw () + : Initial(init_cycle, init_time), + density_initial_(density_initial), + bfieldx_initial_(bfieldx_initial), + gamma_(gamma) +{ } + +//---------------------------------------------------------------------- + +void EnzoInitialTurbulenceMhdIT::pup (PUP::er &p) +{ + // NOTE: update whenever attributes change + + TRACEPUP; + + Initial::pup(p); + + p | density_initial_; + p | bfieldx_initial_; + p | gamma_; + +} + +//---------------------------------------------------------------------- + +void EnzoInitialTurbulenceMhdIT::enforce_block +( Block * block, const Hierarchy * hierarchy ) throw() + +{ + TRACE_TURBULENCE; + if (!block->is_leaf()) return; + + // INCOMPLETE("EnzoInitialTurbulenceMhdIT::enforce_block()"); + + ASSERT("EnzoInitialTurbulenceMhdIT", + "Block does not exist", + block != NULL); + + Field field = block->data()->field(); + + enzo_float * density = (enzo_float *) field.values("density"); + enzo_float * dens_rx = (enzo_float *) field.values("dens_rx"); + enzo_float * dens_ry = (enzo_float *) field.values("dens_ry"); + enzo_float * dens_rz = (enzo_float *) field.values("dens_rz"); + + enzo_float * a3[3] = { (enzo_float *) field.values("drivx"), + (enzo_float *) field.values("drivy"), + (enzo_float *) field.values("drivz") }; + enzo_float * a3_rx[3] = { (enzo_float *) field.values("drivx_rx"), + (enzo_float *) field.values("drivy_rx"), + (enzo_float *) field.values("drivz_rx") }; + enzo_float * a3_ry[3] = { (enzo_float *) field.values("drivx_ry"), + (enzo_float *) field.values("drivy_ry"), + (enzo_float *) field.values("drivz_ry") }; + enzo_float * a3_rz[3] = { (enzo_float *) field.values("drivx_rz"), + (enzo_float *) field.values("drivy_rz"), + (enzo_float *) field.values("drivz_rz") }; + + enzo_float * v3[3] = { (enzo_float *) field.values("velox"), + (enzo_float *) field.values("veloy"), + (enzo_float *) field.values("veloz") }; + enzo_float * v3_rx[3] = { (enzo_float *) field.values("velox_rx"), + (enzo_float *) field.values("veloy_rx"), + (enzo_float *) field.values("veloz_rx") }; + enzo_float * v3_ry[3] = { (enzo_float *) field.values("velox_ry"), + (enzo_float *) field.values("veloy_ry"), + (enzo_float *) field.values("veloz_ry") }; + enzo_float * v3_rz[3] = { (enzo_float *) field.values("velox_rz"), + (enzo_float *) field.values("veloy_rz"), + (enzo_float *) field.values("veloz_rz") }; + + enzo_float * b3[3] = { (enzo_float *) field.values("bfieldx"), + (enzo_float *) field.values("bfieldy"), + (enzo_float *) field.values("bfieldz") }; + enzo_float * b3_rx[3] = { (enzo_float *) field.values("bfieldx_rx"), + (enzo_float *) field.values("bfieldy_rx"), + (enzo_float *) field.values("bfieldz_rx") }; + enzo_float * b3_ry[3] = { (enzo_float *) field.values("bfieldx_ry"), + (enzo_float *) field.values("bfieldy_ry"), + (enzo_float *) field.values("bfieldz_ry") }; + enzo_float * b3_rz[3] = { (enzo_float *) field.values("bfieldx_rz"), + (enzo_float *) field.values("bfieldy_rz"), + (enzo_float *) field.values("bfieldz_rz") }; + + int rank = cello::rank(); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'density'", density); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'dens_rx'", dens_rx); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'dens_ry'", dens_ry); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'dens_rz'", dens_rz); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivx'", a3[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivx_rx'", a3_rx[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivx_ry'", a3_ry[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivx_rz'", a3_rz[0]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivy'", a3[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivy_rx'", a3_rx[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivy_ry'", a3_ry[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivy_rz'", a3_rz[1]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivz'", a3[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivz_rx'", a3_rx[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivz_ry'", a3_ry[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'drivz_rz'", a3_rz[2]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'velox'", v3[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'velox_rx'", v3_rx[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'velox_ry'", v3_ry[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'velox_rz'", v3_rz[0]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloy'", v3[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloy_rx'", v3_rx[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloy_ry'", v3_ry[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloy_rz'", v3_rz[1]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloz'", v3[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloz_rx'", v3_rx[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloz_ry'", v3_ry[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'veloz_rz'", v3_rz[2]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldx'", b3[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldx_rx'", b3_rx[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldx_ry'", b3_ry[0]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldx_rz'", b3_rz[0]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldy'", b3[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldy_rx'", b3_rx[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldy_ry'", b3_ry[1]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldy_rz'", b3_rz[1]); + + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldz'", b3[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldz_rx'", b3_rx[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldz_ry'", b3_ry[2]); + ASSERT("EnzoInitializeMHDTurbulenceIT::enforce_block()", + "Missing Field 'bfieldz_rz'", b3_rz[2]); + + + double xm,ym,zm; + block->data()->lower(&xm,&ym,&zm); + + double xp,yp,zp; + block->data()->upper(&xp,&yp,&zp); + + double hx,hy,hz; + field.cell_width(xm,xp,&hx, + ym,yp,&hy, + zm,zp,&hz); + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + int gx,gy,gz; + field.ghost_depth(0,&gx,&gy,&gz); + + // ndx(yz) include ghost zones + // nx(yz) do not + + int ndx = (rank >= 1) ? nx + 2*gx : nx; + int ndy = (rank >= 2) ? ny + 2*gy : ny; + int ndz = (rank >= 3) ? nz + 2*gz : nz; + + // initialize driving fields using turboinit + + int Nx,Ny,Nz; + cello::hierarchy()->root_size (&Nx, &Ny, &Nz); + + // assumes cubical domain + + ASSERT3 ("EnzoInitialTurbulenceMhdIT::enforce_block()", + "Root grid mesh dimensions %d %d %d must be equal or 1", + Nx,Ny,Nz, + ( Ny == 1) || + ((Nz == 1) && (Nx == Ny)) || + ((Nx == Ny) && (Ny == Nz)) ); + + // scale by level + for (int i=0; ilevel(); i++) Nx *= 2; + + // compute offsets + Index index = block->index(); + + int ix,iy,iz; + index.array(&ix,&iy,&iz); + + int bx,by,bz; + index.tree(&bx,&by,&bz); + + int o3[3] = { ix * nx, iy * ny, iz * nz }; + + int level = index.level(); + + unsigned mask = 1 << (INDEX_BITS_TREE - 1); + + int ix0=gx; + int iy0=gy; + int iz0=gz; + for (int i=0; i> 1; + } + o3[0] += ix0 - gx; + o3[1] += iy0 - gy; + o3[2] += iz0 - gz; + + // Block zone-centered velocities "velox(yz)" are initialized, including ghost zones + + FORTRAN_NAME(turboinit) + (&rank, &Nx, + (enzo_float *)v3[0], + (enzo_float *)v3[1], + (enzo_float *)v3[2], + &ndx,&ndy,&ndz, + &o3[0],&o3[1],&o3[2]); + + // set right velocities using linear interpolation + + // Only active block zones initialized for right states + // Ghost zones for right states will be initialized at refresh step in the preamble of PPML method + // PPML-IT solver takes 7 primitive variables as input + + for (int i=0; irefresh_set_name(ir_post_,name()); + refresh_post->add_all_fields(); + + // TURBULENCE parameters initialized in EnzoBlock::initialize() +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIT::pup (PUP::er &p) +{ + + // NOTE: change this function whenever attributes change + + TRACEPUP; + + Method::pup(p); + + p | edot_; + p | density_initial_; + p | bfieldx_initial_; + p | mach_number_; + p | comoving_coordinates_; + +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIT::compute ( Block * block) throw() +{ + TRACE_TURBULENCE; + + EnzoBlock * enzo_block = static_cast (block); + + Field field = block->data()->field(); + + enzo_float * density = (enzo_float *) field.values("density"); + enzo_float * dens_rx = (enzo_float *) field.values("dens_rx"); + enzo_float * dens_ry = (enzo_float *) field.values("dens_ry"); + enzo_float * dens_rz = (enzo_float *) field.values("dens_rz"); + + enzo_float * velocity[3] = { + (enzo_float *) field.values("velox"), + (enzo_float *) field.values("veloy"), + (enzo_float *) field.values("veloz") }; + + enzo_float * velo_rx[3] = { + (enzo_float *) field.values("velox_rx"), + (enzo_float *) field.values("veloy_rx"), + (enzo_float *) field.values("veloz_rx") }; + + enzo_float * velo_ry[3] = { + (enzo_float *) field.values("velox_ry"), + (enzo_float *) field.values("veloy_ry"), + (enzo_float *) field.values("veloz_ry") }; + + enzo_float * velo_rz[3] = { + (enzo_float *) field.values("velox_rz"), + (enzo_float *) field.values("veloy_rz"), + (enzo_float *) field.values("veloz_rz") }; + + enzo_float * driving[3] = { + (enzo_float *) field.values("drivx"), + (enzo_float *) field.values("drivy"), + (enzo_float *) field.values("drivz") }; + + enzo_float * driv_rx[3] = { + (enzo_float *) field.values("drivx_rx"), + (enzo_float *) field.values("drivy_rx"), + (enzo_float *) field.values("drivz_rx") }; + + enzo_float * driv_ry[3] = { + (enzo_float *) field.values("drivx_ry"), + (enzo_float *) field.values("drivy_ry"), + (enzo_float *) field.values("drivz_ry") }; + + enzo_float * driv_rz[3] = { + (enzo_float *) field.values("drivx_rz"), + (enzo_float *) field.values("drivy_rz"), + (enzo_float *) field.values("drivz_rz") }; + + enzo_float * bfield[3] = { + (enzo_float *) field.values("bfieldx"), + (enzo_float *) field.values("bfieldy"), + (enzo_float *) field.values("bfieldz") }; + + enzo_float * bfield_rx[3] = { + (enzo_float *) field.values("bfieldx_rx"), + (enzo_float *) field.values("bfieldy_rx"), + (enzo_float *) field.values("bfieldz_rx") }; + + enzo_float * bfield_ry[3] = { + (enzo_float *) field.values("bfieldx_ry"), + (enzo_float *) field.values("bfieldy_ry"), + (enzo_float *) field.values("bfieldz_ry") }; + + enzo_float * bfield_rz[3] = { + (enzo_float *) field.values("bfieldx_rz"), + (enzo_float *) field.values("bfieldy_rz"), + (enzo_float *) field.values("bfieldz_rz") }; + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + int gx,gy,gz; + field.ghost_depth(0,&gx,&gy,&gz); + int ndx = nx + 2*gx; + int ndy = ny + 2*gy; + + const int n = max_turbulence_mhd_it_array; + double * g = new double[n]; + + for (int i=0; i::max(); + g[it_maxd] = - std::numeric_limits::max(); + + int mx,my,mz; + field.dimensions (0,&mx,&my,&mz); + const int rank = ((mz == 1) ? ((my == 1) ? 1 : 2) : 3); + + if (block->is_leaf()) { + + // Loops cover only active zones of this block and + // compute averages for zone centers (mostly) to be used for forcing normalization + + for (int iz=0; iz= 2) ? d*velocity[1][i] : 0.0; // 5 + g[it_dvz] += (rank >= 3) ? d*velocity[2][i] : 0.0; // 6 + /* + g[it_dax] += d*driving[0][i]; // 7 + g[it_day] += (rank >= 2) ? d*driving[1][i] : 0.0; // 8 + g[it_daz] += (rank >= 3) ? d*driving[2][i] : 0.0; // 9 + */ + g[it_dax] += ( d*driving[0][i] + dens_rx[i]*driv_rx[0][i] + + dens_ry[i]*driv_ry[0][i] + + dens_rz[i]*driv_rz[0][i] )/4.0; // 7 + g[it_day] += (rank >= 2) ? ( d*driving[1][i] + dens_rx[i]*driv_rx[1][i] + + dens_ry[i]*driv_ry[1][i] + + dens_rz[i]*driv_rz[1][i] )/4.0 : 0.0; // 8 + g[it_daz] += (rank >= 3) ? ( d*driving[2][i] + dens_rx[i]*driv_rx[2][i] + + dens_ry[i]*driv_ry[2][i] + + dens_rz[i]*driv_rz[2][i] )/4.0 : 0.0; // 9 + + g[it_bx] += bfield[0][i]; // 10 + g[it_by] += (rank >= 2) ? bfield[1][i] : 0.0; // 11 + g[it_bz] += (rank >= 3) ? bfield[2][i] : 0.0; // 12 + + // PPML-style divergence calculation in 3D. + // One can also use max|div(b)| for control, see Fig. 18 in Ustyugov et al. (2009, JCP 228, 7614). + int is = 1; + int js = ndx; + int ks = ndx*ndy; + g[it_divb] += fabs(bfield_rx[0][i+is] - bfield_rx[0][i-is] + // 15 + bfield_rx[0][i+is+js] - bfield_rx[0][i-is+js] + + bfield_rx[0][i+is+ks] - bfield_rx[0][i-is+ks] + + bfield_rx[0][i+is+js+ks] - bfield_rx[0][i-is+js+ks] + + + bfield_ry[1][i+js] - bfield_ry[1][i-js] + + bfield_ry[1][i+js+is] - bfield_ry[1][i-js+is] + + bfield_ry[1][i+js+ks] - bfield_ry[1][i-js+ks] + + bfield_ry[1][i+js+is+ks] - bfield_ry[1][i-js+is+ks] + + + bfield_rz[2][i+ks] - bfield_rz[2][i-ks] + + bfield_rz[2][i+ks+is] - bfield_rz[2][i-ks+is] + + bfield_rz[2][i+ks+js] - bfield_rz[2][i-ks+js] + + bfield_rz[2][i+ks+is+js] - bfield_rz[2][i-ks+is+js]); + + g[it_mind] = // 21 + std::min(g[it_mind], (double) d); + g[it_maxd] = // 22 + std::max(g[it_maxd], (double) d); + } + } + } + } + + CkCallback callback (CkIndex_EnzoBlock::r_method_turbulence_mhd_it_end(NULL), + enzo_block->proxy_array()); + enzo_block->contribute(n*sizeof(double),g,r_method_turbulence_mhd_it_type,callback); + + delete [] g; + +} + +//---------------------------------------------------------------------- + +CkReduction::reducerType r_method_turbulence_mhd_it_type; + +void register_method_turbulence_mhd_it(void) +{ + r_method_turbulence_mhd_it_type = CkReduction::addReducer(r_method_turbulence_mhd_it); +} + +CkReductionMsg * r_method_turbulence_mhd_it(int n, CkReductionMsg ** msgs) +{ + double accum[max_turbulence_mhd_it_array]; + for (int i=0; i::max(); + accum[it_maxd] = - std::numeric_limits::max(); + + for (int i=0; igetData(); + for (int ig=0; igcompute_resume (this,msg); + performance_stop_(perf_compute,__FILE__,__LINE__); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIT::compute_resume +(Block * block, + CkReductionMsg * msg) throw() +{ + TRACE_TURBULENCE; + + double * g = (double *)msg->getData(); + + Data * data = block->data(); + Field field = data->field(); + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + + double dt = block->dt(); + + int mx,my,mz; + field.dimensions (0,&mx,&my,&mz); + const int rank = ((mz == 1) ? ((my == 1) ? 1 : 2) : 3); + + double xdm,ydm,zdm; + cello::hierarchy()->lower(&xdm,&ydm,&zdm); + double xdp,ydp,zdp; + cello::hierarchy()->upper(&xdp,&ydp,&zdp); + + double bnotx = bfieldx_initial_; + + // compute edot (TurbulenceSimulationInitialize.C) + + // If RandomForcingEdot (i.e. the energy injection rate) is not set + // in the parameter file, get it from the MacLow (1999) formula. Note: + // the formula is calibrated for generic forcing fields; coefficient + // 0.81 can potentially be inappropriate for a purely solenoidal + // forcing. + + if (edot_ < 0.0) { + // Only compute if needed at the beginning--could/should be in + // EnzoInitialTurbulence + double domain_x = (xdp - xdm); + double domain_y = (rank >= 2) ? (ydp - ydm) : 1.0; + double domain_z = (rank >= 3) ? (zdp - zdm) : 1.0; + double box_size = domain_x; + double box_mass = domain_x * domain_y * domain_z * density_initial_; + + float v_rms = mach_number_; + + edot_ = 0.81/box_size*box_mass*v_rms*v_rms*v_rms; + + // Approximate correction to the MacLow's factor (see eqs (7) - (8)) + // for Enzo's PPM implementation. Seems to be OK for 64^3, 128^3 + // and 256^3 Mach=3,6,10 simulations of solenoidally driven + // turbulence. + // + // (7) $\dot{E}_{\textsf{\scriptsize{kin}}} \simeq - \eta_{\nu} m + // \tilde{k} v^{3}_{\textsf{\scriptsize{rms}}}$ + // + // + // (8) $\dot{E}_{\textsf{\scriptsize{kin}}} = - \eta_{e} m^{-1/2} + // \tilde{k} E^{3/2}_{\textsf{\scriptsize{kin}}}$ + + edot_ *= 0.8; + + } + + // compute norm (ComputeRandomForcingNormalization.C) + + double norm = 0.0; + + if (edot_ != 0.0) { + + // Original code in ComputeRandomForcingNormalization.C: + // + // float gv0 = GlobVal[0]; + // if (gv0 < 1e-30 && gv0 > -1e-30 && MetaData->TopGridRank == 3) {ERROR_MESSAGE} + // else *norm = 1.25*dt*RandomForcingEdot*numberOfGridZones/gv0; + // small push at the start, when gv0==0 due to zero initial velocities + // if (gv0 < 1e-30 && gv0 > -1e-30 && MetaData->TopGridRank == 2) *norm = 0.0001; + // else *norm = 1.25*dt*RandomForcingEdot*numberOfGridZones/gv0; + + + double vad = g[it_vad]; + double aad = g[it_aad]; + double zon = g[it_zones]; + + const bool small_g0 = std::abs(vad) < 1e-30; + + norm = small_g0 ? 0.0001 : 1.25*dt*edot_*zon/vad; + + // norm = (edot_ != 0.0) ? (sqrt(vad*vad + 2.0*zon*aad*dt*edot_) - vad)/aad : 0.0; + + + // OLD COMPUTATION: + // + // norm = ( sqrt(g[0]*g[0] + 2.0*n*g[1]*dt*edot_) - g[0] ) / g[1]; + } + + // ASSUMES CONSTANT TIME STEP + + // double dt0 = dt; + // norm = (dt/dt0)*norm; + + monitor_output_(block,g,norm,bnotx); + + if (block->is_leaf()) { + compute_resume_(block,msg); + } + + delete msg; + block->compute_done(); + +} + +//====================================================================== + +void EnzoMethodTurbulenceMhdIT::monitor_output_ +(Block * block, double * g, double norm, double bnotx) +{ + if (block->index().is_root()) { + + Monitor * monitor = cello::monitor(); + + monitor->print ("Method","sum v*a*d " "%.17g", g[it_vad]); + monitor->print ("Method","sum a*a*d " "%.17g", g[it_aad]); + monitor->print ("Method","sum v*v*d " "%.17g", g[it_vvd]); + monitor->print ("Method","sum v*v " "%.17g", g[it_vv]); + monitor->print ("Method","sum b*b " "%.17g", g[it_bb]); + monitor->print ("Method","sum b*b/d " "%.17g", g[it_bbod]); + + monitor->print ("Method","sum d*ax " "%.17g", g[it_dax]); + monitor->print ("Method","sum d*ay " "%.17g", g[it_day]); + monitor->print ("Method","sum d*az " "%.17g", g[it_daz]); + + monitor->print ("Method","sum d*vx " "%.17g", g[it_dvx]); + monitor->print ("Method","sum d*vy " "%.17g", g[it_dvy]); + monitor->print ("Method","sum d*vz " "%.17g", g[it_dvz]); + + monitor->print ("Method","sum bx " "%.17g", g[it_bx]); + monitor->print ("Method","sum by " "%.17g", g[it_by]); + monitor->print ("Method","sum bz " "%.17g", g[it_bz]); + + monitor->print ("Method","sum d " "%.17g", g[it_d]); + monitor->print ("Method","sum d*d " "%.17g", g[it_dd]); + monitor->print ("Method","sum ln(d) " "%.17g", g[it_lnd]); + monitor->print ("Method","sum d*ln(d) " "%.17g", g[it_dlnd]); + monitor->print ("Method","min d " "%.17g", g[it_mind]); + monitor->print ("Method","max d " "%.17g", g[it_maxd]); + + monitor->print ("Method","sum zones " "%.17g", g[it_zones]); + + monitor->print ("Method","norm " "%.17g", norm); + monitor->print ("Method","edot " "%.17g", edot_); + + monitor->print ("Method","kinetic energy " "%.17g", + 0.50*g[it_vvd]/g[it_zones]); + monitor->print ("Method","turbulent magnetic energy " "%.17g", + 0.50*(g[it_bb]/g[it_zones]-bnotx*bnotx)); + monitor->print ("Method","potential energy " "%.17g", + g[it_dlnd]/g[it_zones]); + monitor->print ("Method","zones " "%.17g", + g[it_zones]); + monitor->print ("Method","bnotx " "%.17g", + bnotx); + monitor->print ("Method"," " "%.17g", + g[it_d]/g[it_zones]); + monitor->print ("Method"," " "%.17g", + g[it_lnd]/g[it_zones]); + monitor->print ("Method","volume-weighed rms Mach_s " "%.17g", + sqrt(g[it_vv]/g[it_zones])); + monitor->print ("Method","volume-weighed rms Mach_a " "%.17g", + sqrt(g[it_vv] / + g[it_bbod])); + monitor->print ("Method","mass-weighted rms Mach_s " "%.17g", + sqrt(g[it_vvd]/g[it_zones])); + monitor->print ("Method","density variance " "%.17g", + sqrt(g[it_dd]/g[it_zones])); + monitor->print ("Method","<|div(b)|> " "%.17g", + g[it_divb]/8.0/g[it_zones]); + monitor->print ("Method","density contrast " "%.17g", + g[it_maxd] / + g[it_mind]); + } +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceMhdIT::compute_resume_ +(Block * block, CkReductionMsg * msg) throw() +{ + + TRACE_TURBULENCE; + + // Compute normalization + + Field field = block->data()->field(); + + int mx,my,mz; // total block size + int nx,ny,nz; // active block size + int gx,gy,gz; // number of ghost layers on each side of the block + field.dimensions (0,&mx,&my,&mz); + field.size (&nx,&ny,&nz); + field.ghost_depth(0,&gx,&gy,&gz); + + int n = nx*ny*nz; + + double * g = (double *)msg->getData(); + + double dt = block->dt(); + + double vad = g[it_vad]; + double aad = g[it_aad]; + double zon = g[it_zones]; + + const bool small_g0 = std::abs(vad) < 1e-30; + + double norm = small_g0 ? 0.0001 : 1.25*dt*edot_*zon/vad; + + // double norm = (edot_ != 0.0) ? (sqrt(vad*vad + 2.0*zon*aad*dt*edot_) - vad)/aad : 0.0; + + // ASSUMES CONSTANT TIME STEP + + double dt0 = dt; + norm = (dt/dt0)*norm; + + const int rank = cello::rank(); + // const int rank = (my == 1) ? 1 : ((mz == 1) ? 2 : 3); + + enzo_float * v3[3] = { + (enzo_float*) field.values ("velox"), + (enzo_float*) field.values ("veloy"), + (enzo_float*) field.values ("veloz") }; + enzo_float * v3_rx[3] = { + (enzo_float*) field.values ("velox_rx"), + (enzo_float*) field.values ("veloy_rx"), + (enzo_float*) field.values ("veloz_rx") }; + enzo_float * v3_ry[3] = { + (enzo_float*) field.values ("velox_ry"), + (enzo_float*) field.values ("veloy_ry"), + (enzo_float*) field.values ("veloz_ry") }; + enzo_float * v3_rz[3] = { + (enzo_float*) field.values ("velox_rz"), + (enzo_float*) field.values ("veloy_rz"), + (enzo_float*) field.values ("veloz_rz") }; + enzo_float * a3[3] = { + (enzo_float*) field.values ("drivx"), + (enzo_float*) field.values ("drivy"), + (enzo_float*) field.values ("drivz") }; + enzo_float * a3_rx[3] = { + (enzo_float*) field.values ("drivx_rx"), + (enzo_float*) field.values ("drivy_rx"), + (enzo_float*) field.values ("drivz_rx") }; + enzo_float * a3_ry[3] = { + (enzo_float*) field.values ("drivx_ry"), + (enzo_float*) field.values ("drivy_ry"), + (enzo_float*) field.values ("drivz_ry") }; + enzo_float * a3_rz[3] = { + (enzo_float*) field.values ("drivx_rz"), + (enzo_float*) field.values ("drivy_rz"), + (enzo_float*) field.values ("drivz_rz") }; + + // compute injected bulk momentum in x, y, and z directions + + const enzo_float bm[3] = + { enzo_float(g[it_dax]/g[it_zones]), + enzo_float(g[it_day]/g[it_zones]), + enzo_float(g[it_daz]/g[it_zones]) }; + + // if (block->index().is_root()) { + // Monitor * monitor = cello::monitor(); + // monitor->print ("Method","bulk momentum " "%.17g %.17g %.17g", bm[0], bm[1], bm[2]); + // } + + // apply forcing + // only active zones are updated (assuming mean density of 1) + + int ndx = (rank >= 1) ? nx + 2*gx : nx; + int ndy = (rank >= 1) ? ny + 2*gy : ny; + int ndz = (rank >= 1) ? nz + 2*gz : nz; + for (int i=0; irefresh_set_name(ir_post_,name()); + Refresh * refresh = cello::refresh(ir_post_); + + cello::define_field("jacobian"); + cello::define_field("resid_density"); + cello::define_field("resid_energy"); + cello::define_field("resid_total_energy"); + cello::define_field("resid_velocity_x"); + cello::define_field("resid_velocity_y"); + cello::define_field("resid_velocity_z"); + cello::define_field("acceleration_x"); + cello::define_field("acceleration_y"); + cello::define_field("acceleration_z"); + cello::define_field("energy"); + + // refresh->add_all_fields(); + + refresh->add_field ("acceleration_x"); + refresh->add_field ("acceleration_y"); + refresh->add_field ("acceleration_z"); + refresh->add_field ("bfieldx"); + refresh->add_field ("bfieldx_rx"); + refresh->add_field ("bfieldx_ry"); + refresh->add_field ("bfieldx_rz"); + refresh->add_field ("bfieldy"); + refresh->add_field ("bfieldy_rx"); + refresh->add_field ("bfieldy_ry"); + refresh->add_field ("bfieldy_rz"); + refresh->add_field ("bfieldz"); + refresh->add_field ("bfieldz_rx"); + refresh->add_field ("bfieldz_ry"); + refresh->add_field ("bfieldz_rz"); + refresh->add_field ("density"); + refresh->add_field ("velocity_x"); + refresh->add_field ("velocity_y"); + refresh->add_field ("velocity_z"); + + // Call fortran initializer + + double domain_size[3] = + { domain_upper[0]-domain_lower[0], + domain_upper[1]-domain_lower[1], + domain_upper[2]-domain_lower[2] }; + + int is_root = (CkMyPe() == 0) ? 1 : 0; + int rank = cello::rank(); + int iapply_injection_rate = apply_injection_rate_ ? 1 : 0; + int iread_sol = read_sol_ ? 1 : 0; + + double weight_norm = 0; + FORTRAN_NAME(cello_init_turbulence_ou) + (&is_root, + &rank, + domain_size, + &gamma_, + &iapply_injection_rate, + &cooling_term_, + &injection_rate_, + &kfi_, + &kfa_, + &mach_, + &iread_sol, + &sol_weight_, + &weight_norm); + static bool first_call = true; + if (first_call && CkMyPe() == 0) { + CkPrintf ("WeightNorm = %24.18g\n",weight_norm); + first_call = false; + } + +} + +//---------------------------------------------------------------------- + +void EnzoSimulation::get_turbou_state() +{ + // Create scalar variables for storing state for checkpoint/restart + + // Allocate state arrays if needed + int n_size_double, n_size_int; + FORTRAN_NAME(cello_turbou_state_size)(&n_size_double,&n_size_int); + if (turbou_real_state_.size() < n_size_double) { + turbou_real_state_.resize(n_size_double); + } + if (turbou_int_state_.size() < n_size_int) { + turbou_int_state_.resize(n_size_int); + } + + // Save state to arrays + FORTRAN_NAME(cello_get_turbou_state) + (turbou_real_state_.data(), turbou_int_state_.data()); +} + +//---------------------------------------------------------------------- + +void EnzoSimulation::put_turbou_state() +{ + // Create scalar variables for storing state for checkpoint/restart + + // Save arrays to state + if (turbou_real_state_.size() > 0) { + FORTRAN_NAME(cello_put_turbou_state) + (turbou_real_state_.data(), turbou_int_state_.data()); + } +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::pup (PUP::er &p) +{ + + // NOTE: change this function whenever attributes change + + TRACEPUP; + + Method::pup(p); + p | gamma_; + p | apply_cooling_; + p | apply_forcing_; + p | apply_injection_rate_; + p | cooling_term_; + p | hc_alpha_; + p | hc_sigma_; + p | injection_rate_; + p | kfi_; + p | kfa_; + p | mach_; + p | olap_; + p | read_sol_; + p | sol_weight_; + p | totemp_; + p | update_solution_; +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::compute ( Block * block) throw() +{ + long double r_gvld1[5] = {4.0, 0.0, 0.0, 0.0, 0.0}; + + if (block->is_leaf()) { + + // Restore Fortran phase arrays if restarting + if (enzo::config()->initial_restart && + EnzoMethodTurbulenceOU::iupdate_phases_ == 1) { + enzo::simulation()->put_turbou_state(); + } + + Field field = block->data()->field(); + int mx,my,mz; + int nx,ny,nz; + field.dimensions(0,&mx,&my,&mz); + field.size(&nx,&ny,&nz); + double * w; + double * jac; + int iupdate_sol = update_solution_ ? 1 : 0; + int iapply_cooling = apply_cooling_ ? 1 : 0; + int iapply_forcing = apply_forcing_ ? 1 : 0; + int iapply_injection_rate = apply_injection_rate_ ? 1 : 0; + int cello_apply_injection_rate; + double r_gv[4] = {0.0,0.0,0.0,0.0}; + + double time = cello::simulation()->time(); + double dt = cello::simulation()->dt(); + + double * field_density = (double *)field.values("density"); + CHECK_FIELD(field_density,"density"); + + double xm,ym,zm; + double xp,yp,zp; + block->lower(&xm,&ym,&zm); + block->upper(&xp,&yp,&zp); + double hx,hy,hz; + field.cell_width (xm,xp,&hx, ym,yp,&hy, zm,zp,&hz); + int gx,gy,gz; + field.ghost_depth(0,&gx,&gy,&gz); + + // Restore work array + double * field_work_1 = (double *)field.values("work_1"); + double * field_work_2 = (double *)field.values("work_2"); + double * field_work_3 = (double *)field.values("work_3"); + CHECK_FIELD(field_work_1,"work_1"); + CHECK_FIELD(field_work_2,"work_2"); + CHECK_FIELD(field_work_3,"work_3"); + const int m = mx*my*mz; + double * array_work = new double [3*m]; + std::copy_n (field_work_1,m,array_work+0*m); + std::copy_n (field_work_2,m,array_work+1*m); + std::copy_n (field_work_3,m,array_work+2*m); + + double * grid = new double [3*m]; + for (int iz=0; iz xm + 0.5*hx + int i=3*(ix+mx*(iy+my*iz)); + grid[i]=x; + grid[i+1]=y; + grid[i+2]=z; + } + } + } + + FIELD_STATS("density force start",field_density,mx,my,mz,gx,gy,gz); + // index of first non-ghost value + const int i0 = gx + mx*(gy + my*gz); + + FORTRAN_NAME(turbforceou) + (&mx, &my, &mz, + &nx, &ny, &nz, + field_density+i0, + grid+3*i0, + array_work+i0, &time, &dt, + &iupdate_sol, + &iapply_cooling, + &iapply_forcing, + &iapply_injection_rate, + &EnzoMethodTurbulenceOU::iupdate_phases_, + &cooling_term_, + &gamma_, + &injection_rate_, + &olap_, + r_gv); + + EnzoMethodTurbulenceOU::iupdate_phases_ = 0; + + FIELD_STATS("density force stop ",field_density,mx,my,mz,gx,gy,gz); + + for (int i=0; i<4; i++) r_gvld1[i+1] = r_gv[i]; + + // Save work array + std::copy_n (array_work+0*m,m,field_work_1); + std::copy_n (array_work+1*m,m,field_work_2); + std::copy_n (array_work+2*m,m,field_work_3); + FIELD_STATS("work_1 force",field_work_1,mx,my,mz,gx,gy,gz); + FIELD_STATS("work_2 force",field_work_2,mx,my,mz,gx,gy,gz); + FIELD_STATS("work_3 force",field_work_3,mx,my,mz,gx,gy,gz); + delete [] array_work; + delete [] grid; + + } + + CkCallback callback = CkCallback + (CkIndex_EnzoBlock::r_method_turbulence_ou_shift(nullptr), + enzo::block_array()); + int n = 4; + + block->contribute((n+1)*sizeof(long double), r_gvld1, + sum_long_double_n_type, callback); + +} + +//---------------------------------------------------------------------- + +void EnzoBlock::r_method_turbulence_ou_shift(CkReductionMsg *msg) +{ + EnzoMethodTurbulenceOU * method = static_cast (this->method()); + method->compute_shift(this, msg); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::compute_shift +(EnzoBlock * enzo_block, CkReductionMsg * msg) +{ + long double * data = (long double *) msg->getData(); + long double r_gvld0[4]; + int id=0; + int n = data[id++]; + ASSERT1 ("EnzoMethodTurbulenceOU::compute_shift()", + "Expected length 4 but actual length %d", + n,(n==4)); + for (int i=0; iis_leaf()) { + + double * w; + int iupdate_sol = update_solution_ ? 1 : 0; + int iapply_cooling = apply_cooling_ ? 1 : 0; + int iapply_forcing = apply_forcing_ ? 1 : 0; + int iapply_injection_rate = apply_injection_rate_ ? 1 : 0; + int cello_apply_injection_rate; + double r_gv[4] = {r_gvld0[0],r_gvld0[1],r_gvld0[2],r_gvld0[3]}; + double r_av[num_reduce]; + std::fill_n(r_av,num_reduce,0.0); + + Field field = enzo_block->data()->field(); + double * field_density = (double *)field.values("density"); + double * field_momentum_x = (double *)field.values("velocity_x"); + double * field_momentum_y = (double *)field.values("velocity_y"); + double * field_momentum_z = (double *)field.values("velocity_z"); + double * field_jacobian = (double *)field.values("jacobian"); + CHECK_FIELD(field_density,"density"); + CHECK_FIELD(field_momentum_x,"velocity_x"); + CHECK_FIELD(field_momentum_y,"velocity_y"); + CHECK_FIELD(field_momentum_z,"velocity_z"); + CHECK_FIELD(field_jacobian,"jacobian"); + + // convert to conservative form + int mx,my,mz; + int nx,ny,nz; + field.dimensions(0,&mx,&my,&mz); + field.size(&nx,&ny,&nz); + for (int iz=0; izdata()->field(); + const bool include_ppml_divb = (field.values("bfieldx") != nullptr); + if (include_ppml_divb && enzo_block->is_leaf()) { + enzo_float * bfield[3] = + { (enzo_float *) field.values("bfieldx"), + (enzo_float *) field.values("bfieldy"), + (enzo_float *) field.values("bfieldz") }; + + enzo_float * bfield_rx[3] = + { (enzo_float *) field.values("bfieldx_rx"), + (enzo_float *) field.values("bfieldy_rx"), + (enzo_float *) field.values("bfieldz_rx") }; + + enzo_float * bfield_ry[3] = + { (enzo_float *) field.values("bfieldx_ry"), + (enzo_float *) field.values("bfieldy_ry"), + (enzo_float *) field.values("bfieldz_ry") }; + + enzo_float * bfield_rz[3] = + { (enzo_float *) field.values("bfieldx_rz"), + (enzo_float *) field.values("bfieldy_rz"), + (enzo_float *) field.values("bfieldz_rz") }; + + CHECK_FIELD(bfield[0],"bfieldx"); + CHECK_FIELD(bfield[1],"bfieldy"); + CHECK_FIELD(bfield[2],"bfieldz"); + CHECK_FIELD(bfield_rx[0],"bfieldx_rx"); + CHECK_FIELD(bfield_ry[1],"bfieldx_ry"); + CHECK_FIELD(bfield_rz[2],"bfieldx_rz"); + CHECK_FIELD(bfield_rx[0],"bfieldy_rx"); + CHECK_FIELD(bfield_ry[1],"bfieldy_ry"); + CHECK_FIELD(bfield_rz[2],"bfieldy_rz"); + CHECK_FIELD(bfield_rx[0],"bfieldz_rx"); + CHECK_FIELD(bfield_ry[1],"bfieldz_ry"); + CHECK_FIELD(bfield_rz[2],"bfieldz_rz"); + + int mx,my,mz; + int nx,ny,nz; + int gx,gy,gz; + field.size(&nx,&ny,&nz); + field.ghost_depth(0,&gx,&gy,&gz); + field.dimensions(0,&mx,&my,&mz); + const int dx = 1; + const int dy = mx; + const int dz = mx*my; + r_avld1[3] = 0.0; + r_avld1[4] = 0.0; + for (int iz=0; izcontribute((num_reduce+1)*sizeof(long double), r_avld1, + sum_long_double_n_type, callback); +} + +void EnzoBlock::r_method_turbulence_ou_update(CkReductionMsg *msg) +{ + EnzoMethodTurbulenceOU * method = static_cast (this->method()); + method->compute_update(this,msg); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::compute_update +(EnzoBlock * enzo_block, CkReductionMsg *msg) +{ + long double * data = (long double *) msg->getData(); + const int num_reduce = 4; + long double r_avld0[num_reduce+1]; + int id=0; + int n = data[id++]; + ASSERT2 ("EnzoMethodTurbulenceOU::compute_shift()", + "Expected length %d but actual length %d", + num_reduce,n,(n==num_reduce)); + for (int i=0; idt(); + int iupdate_sol = update_solution_ ? 1 : 0; + int iapply_cooling = apply_cooling_ ? 1 : 0; + int iapply_forcing = apply_forcing_ ? 1 : 0; + int iapply_injection_rate = apply_injection_rate_ ? 1 : 0; + int cello_apply_injection_rate; + double r_av[2] = {r_avld0[0],r_avld0[1]}; + + Field field = enzo_block->data()->field(); + double * field_density = (double *)field.values("density"); + double * field_momentum_x = (double *)field.values("velocity_x"); + double * field_momentum_y = (double *)field.values("velocity_y"); + double * field_momentum_z = (double *)field.values("velocity_z"); + double * field_energy_total = (double *)field.values("total_energy"); + double * resid_density = (double *)field.values("resid_density"); + double * resid_momentum_x = (double *)field.values("resid_velocity_x"); + double * resid_momentum_y = (double *)field.values("resid_velocity_y"); + double * resid_momentum_z = (double *)field.values("resid_velocity_z"); + double * resid_energy_total = (double *)field.values("resid_total_energy"); + double * field_temperature = (double *)field.values("temperature"); + CHECK_FIELD(field_density,"density"); + CHECK_FIELD(field_momentum_x,"velocity_x"); + CHECK_FIELD(field_momentum_y,"velocity_y"); + CHECK_FIELD(field_momentum_z,"velocity_z"); + CHECK_FIELD(field_energy_total,"total_energy"); + CHECK_FIELD(resid_density,"resid_density"); + CHECK_FIELD(resid_momentum_x,"resid_velocity_x"); + CHECK_FIELD(resid_momentum_y,"resid_velocity_y"); + CHECK_FIELD(resid_momentum_z,"resid_velocity_z"); + CHECK_FIELD(resid_energy_total,"resid_energy_total"); + CHECK_FIELD(field_temperature,"temperature"); + + const bool using_ppml = (field.values("bfieldx") != nullptr); + if (using_ppml && enzo_block->index().is_root()) { + Monitor * monitor = cello::monitor(); + monitor->print ("Method","<|div(b)|> %.17Lg", + r_avld0[2]/8.0/r_avld0[3]); + } + int mx,my,mz; + int nx,ny,nz; + field.dimensions(0,&mx,&my,&mz); + field.size(&nx,&ny,&nz); + const int m = mx*my*mz; + + double * turbAcc = new double [4*m]; + double * field_acceleration_x = (double *)field.values("acceleration_x"); + double * field_acceleration_y = (double *)field.values("acceleration_y"); + double * field_acceleration_z = (double *)field.values("acceleration_z"); + double * field_energy = (double *)field.values("energy"); + CHECK_FIELD(field_acceleration_x,"acceleration_x"); + CHECK_FIELD(field_acceleration_y,"acceleration_y"); + CHECK_FIELD(field_acceleration_z,"acceleration_z"); + CHECK_FIELD(field_energy,"energy"); + + std::fill_n(resid_density,m,0.0); + std::fill_n(resid_momentum_x,m,0.0); + std::fill_n(resid_momentum_y,m,0.0); + std::fill_n(resid_momentum_z,m,0.0); + std::fill_n(resid_energy_total,m,0.0); + + // convert to conservative form + for (int iz=0; izget_turbou_state(); + + compute_reductions_(enzo_block); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::compute_reductions_(EnzoBlock * enzo_block) +{ + Field field = enzo_block->data()->field(); + + const EnzoConfig * enzo_config = enzo::config(); + + EnzoComputeTemperature compute_temperature + (enzo::fluid_props(), enzo_config->physics_cosmology); + + compute_temperature.compute(enzo_block); + + const bool using_ppml = (field.values("bfieldx") != nullptr); + + // default PPML fields + enzo_float * d = (enzo_float *) field.values("density"); + enzo_float * ax = (enzo_float *) field.values("acceleration_x"); + enzo_float * ay = (enzo_float *) field.values("acceleration_y"); + enzo_float * az = (enzo_float *) field.values("acceleration_z"); + enzo_float * vx = (enzo_float *) field.values("velocity_x"); + enzo_float * vy = (enzo_float *) field.values("velocity_y"); + enzo_float * vz = (enzo_float *) field.values("velocity_z"); + enzo_float * t = (enzo_float *) field.values("temperature"); + enzo_float * e = (enzo_float *) field.values("energy"); // turbAcc(4) + enzo_float * p = (enzo_float *) field.values("pressure"); + enzo_float * bx = nullptr; + enzo_float * by = nullptr; + enzo_float * bz = nullptr; + + if (using_ppml) { + // update field names if using PPML + vx = (enzo_float *) field.values("velox"); + vy = (enzo_float *) field.values("veloy"); + vz = (enzo_float *) field.values("veloz"); + bx = (enzo_float *) field.values("bfieldx"); + by = (enzo_float *) field.values("bfieldy"); + bz= (enzo_float *) field.values("bfieldz"); + } + + int nx,ny,nz; + int gx,gy,gz; + field.size(&nx,&ny,&nz); + field.ghost_depth(0,&gx,&gy,&gz); + const int mx = nx + 2*gx; + const int my = ny + 2*gy; + const int mz = nz + 2*gz; + const int dx = 1; + const int dy = mx; + const int dz = mx*my; + + // Allocate zero field if rank < 3 to remove if's from loops + const int rank = cello::rank(); + enzo_float * zero = rank <3 ? new enzo_float[mx*my*mz] : nullptr; + if (rank < 2) { + vy = zero; + ay = zero; + by = zero; + } + if (rank < 3) { + vz = zero; + az = zero; + bz = zero; + } + + // Allocate and initialize reduction array + const int n = 30; + long double g[n+1]; + std::fill_n(g,n+1,0.0); + g[0] = n; + + const double c2 = 29979245800.0 * 29979245800.0; + if (enzo_block->is_leaf()) { + + double xm,ym,zm; + double xp,yp,zp; + enzo_block->lower(&xm,&ym,&zm); + enzo_block->upper(&xp,&yp,&zp); + double hx,hy,hz; + field.cell_width (xm,xp,&hx, ym,yp,&hy, zm,zp,&hz); + double hxi=1.0/hx; + double hyi=(cello::rank() >= 2) ? 1.0/hy : 0.0; + double hzi=(cello::rank() >= 3) ? 1.0/hz : 0.0; + + for (int iz=0; izproxy_array()); + enzo_block->contribute((n+1)*sizeof(long double),g,sum_long_double_n_type,callback); +} + +//---------------------------------------------------------------------- + +void EnzoBlock::r_method_turbulence_ou_end(CkReductionMsg * msg) +{ + performance_start_(perf_compute,__FILE__,__LINE__); + static_cast (method())->compute_reduce (this,msg); + performance_stop_(perf_compute,__FILE__,__LINE__); +} + +//---------------------------------------------------------------------- + +void EnzoMethodTurbulenceOU::compute_reduce +(EnzoBlock * enzo_block,CkReductionMsg * msg) +{ + long double * g = (long double *)msg->getData(); + + Data * data = enzo_block->data(); + Field field = data->field(); + + + int nx,ny,nz; + field.size(&nx,&ny,&nz); + int n = nx*ny*nz; + + double dt = ((Block*)enzo_block)->dt(); + + int mx,my,mz; + field.dimensions (0,&mx,&my,&mz); + const int rank = ((mz == 1) ? ((my == 1) ? 1 : 2) : 3); + + double xdm,ydm,zdm; + data->lower(&xdm,&ydm,&zdm); + double xdp,ydp,zdp; + data->upper(&xdp,&ydp,&zdp); + + if (enzo_block->index().is_root()) { + + Monitor * m = cello::monitor(); +#define FMT "%.17Lg" +#define NAME "Turbulence" + + int i=1; + m->print (NAME,"stat %02d rho " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d log(rho) " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho*log(rho) " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho*u " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho*v " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho*w " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d rho*(u^2 + v^2 + w^2) " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d u^2 + v^2 + w^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d u " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d v " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d w " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d div u " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d (div u)^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d Omega^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d p " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d p/rho " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d Bx " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d By " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d Bz " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d Bx^2 + By^2 + Bz^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d (Bx^2 + By^2 + Bz^2)/rho " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d |div b| " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d E_turb " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d (u^2 + v^2 + w^2)/c^2 " FMT, i,sqrt(g[i])); i++; + m->print (NAME,"stat %02d p*(div u) " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d (p*(div u))^2 " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d total volume " FMT, i,g[i]); i++; + m->print (NAME,"stat %02d div b " FMT, i,g[i]); i++; + } + enzo_block->compute_done(); +} + + diff --git a/src/Enzo/turbulence/EnzoMethodTurbulenceOU.hpp b/src/Enzo/turbulence/EnzoMethodTurbulenceOU.hpp new file mode 100644 index 0000000000..e7cee3840a --- /dev/null +++ b/src/Enzo/turbulence/EnzoMethodTurbulenceOU.hpp @@ -0,0 +1,102 @@ +// See LICENSE_CELLO file for license and copyright information + +/// @file enzo_EnzoMethodTurbulenceOU.hpp +/// @author Alexei Kritsuk (kritsuk@gmail.com) +/// @author James Bordner (jobordner@ucsd.edu) +/// @date Wed Jul 23 00:31:13 UTC 2014 +/// @date Fri Aug 24 00:31:13 UTC 2018 +/// @brief [\ref Enzo] Implementation of Enzo IsoThermal TURBULENCE MHD method + +#ifndef ENZO_ENZO_METHOD_TURBULENCE_OU_HPP +#define ENZO_ENZO_METHOD_TURBULENCE_OU_HPP + +//---------------------------------------------------------------------- + +class EnzoMethodTurbulenceOU : public Method { + + /// @class EnzoMethodTurbulenceOU + /// @ingroup Enzo + /// @brief [\ref Enzo] Encapsulate Enzo's ISOTHERMAL TURBULENCE MHD method + +public: // interface + + /// Create a new EnzoMethodTurbulence object + EnzoMethodTurbulenceOU + (double gamma, + const double domain_lower[3], + const double domain_upper[3], + bool apply_cooling, + bool apply_forcing, + bool apply_injection_rate, + int cooling_term, + double hc_alpha, + double hc_sigma, + double injection_rate, + double kfi, + double kfa, + double mach, + int olap, + bool read_sol, + double sol_weight, + double totemp, + bool update_solution); + + /// Create an uninitialized EnzoMethodTurbulence object + EnzoMethodTurbulenceOU() + : Method() + { } + + /// Charm++ PUP::able declarations + PUPable_decl(EnzoMethodTurbulenceOU); + + /// Charm++ PUP::able migration constructor + EnzoMethodTurbulenceOU (CkMigrateMessage *m) + : Method (m) + { } + + /// CHARM++ Pack / Unpack function + void pup (PUP::er &p); + + /// Apply the method to advance a block one timestep + virtual void compute( Block * block) throw(); + + void compute_shift(EnzoBlock *, CkReductionMsg *msg); + void compute_update(EnzoBlock *, CkReductionMsg *msg); + void compute_reduce(EnzoBlock *, CkReductionMsg * msg); + + virtual std::string name () throw () + { return "turbulence_ou"; } + +private: // methods + + void compute_reductions_ (EnzoBlock * enzo_block); + +private: // attributes + + double gamma_; + bool apply_cooling_; + bool apply_forcing_; + bool apply_injection_rate_; + int cooling_term_; + double hc_alpha_; + double hc_sigma_; + double injection_rate_; + double kfi_; + double kfa_; + double mach_; + int olap_; + bool read_sol_; + double sol_weight_; + double totemp_; + bool update_solution_; + + int is_NModes_; + int is_Ndims_; + + // True only on first block's call on a node each cycle to avoid + // excessive calls + static int iupdate_phases_; + +}; + +#endif /* ENZO_ENZO_METHOD_TURBULENCE_OU_HPP */