Merge lp:~fluidity-core/fluidity/adjoint into lp:fluidity
- adjoint
- Merge into dev-trunk
Status: | Merged |
---|---|
Merged at revision: | 3521 |
Proposed branch: | lp:~fluidity-core/fluidity/adjoint |
Merge into: | lp:fluidity |
Diff against target: |
152406 lines (+52346/-96549) 431 files modified
Makefile.in (+2/-2) aclocal.m4 (+5/-5) adjoint/Adjoint_Controls.F90 (+611/-0) adjoint/Adjoint_Functional_Evaluation.F90 (+108/-28) adjoint/Adjoint_Global_Variables.F90 (+0/-1) adjoint/Adjoint_Main_Loop.F90 (+58/-40) adjoint/Adjoint_Python_Fortran.F90 (+6/-3) adjoint/Burgers_Adjoint_Callbacks.F90 (+340/-20) adjoint/Burgers_Control_Callbacks.F90 (+183/-0) adjoint/Forward_Main_Loop.F90 (+99/-4) adjoint/Libadjoint_Data_Callbacks.F90 (+23/-0) adjoint/Makefile.dependencies (+38/-5) adjoint/Makefile.in (+22/-4) adjoint/Mangle_Dirichlet_Rows_Module.F90 (+23/-1) adjoint/Mangle_Options_Tree.F90 (+19/-10) adjoint/Shallow_Water_Adjoint_Callbacks.F90 (+1/-0) adjoint/Shallow_Water_Control_Callbacks.F90 (+203/-0) adjoint/adBuffer.c (+476/-0) adjoint/adBufferFortran.f (+1848/-0) adjoint/adStack.c (+683/-0) adjoint/adStack.h (+75/-0) adjoint/adjoint_python.c (+14/-2) adjoint/simple_advection.f90 (+83/-0) adjoint/simple_advection_b.f90 (+209/-0) adjoint/simple_advection_d.f90 (+199/-0) adjoint/tests/test_adj_variables_from_python.F90 (+5/-1) assemble/Burgers_Assembly.F90 (+84/-0) assemble/Makefile.dependencies (+16/-9) assemble/Makefile.in (+1/-1) assemble/Manifold_Projections.F90 (+3/-1) configure (+30/-13) configure.in (+24/-8) femtools/Makefile.dependencies (+20/-19) main/Burgers_Equation.F90 (+104/-61) main/Makefile.dependencies (+26/-23) main/Shallow_Water.F90 (+26/-7) main/Simple_Shallow_Water.F90 (+7/-5) python/fluidity_tools.py (+88/-1) schemas/adjoint_options.rnc (+54/-1) schemas/adjoint_options.rng (+79/-0) schemas/optimality.rnc (+189/-0) schemas/optimality.rng (+222/-0) scripts/optimality.py (+720/-0) tests/burgers_adjoint_bc/Makefile (+0/-5) tests/burgers_adjoint_bc/adjoint_bc.bml (+0/-213) tests/burgers_adjoint_bc/burgers_adjoint_bc.xml (+0/-31) tests/burgers_adjoint_bc/notes_from_colin.tex (+0/-154) tests/burgers_adjoint_bc/play.py (+0/-67) tests/burgers_mms_adjoint/Makefile (+0/-10) tests/burgers_mms_adjoint/burgers.sage (+0/-15) tests/burgers_mms_adjoint/burgers_mms_adjoint.xml (+0/-69) tests/burgers_mms_adjoint/mms_A.bml (+0/-231) tests/burgers_mms_adjoint/mms_A.bound (+0/-4) tests/burgers_mms_adjoint/mms_A.ele (+0/-102) tests/burgers_mms_adjoint/mms_A.node (+0/-103) tests/burgers_mms_adjoint/mms_B.bml (+0/-231) tests/burgers_mms_adjoint/mms_B.bound (+0/-4) tests/burgers_mms_adjoint/mms_B.ele (+0/-202) tests/burgers_mms_adjoint/mms_B.node (+0/-203) tests/burgers_mms_adjoint/mms_C.bml (+0/-231) tests/burgers_mms_adjoint/mms_C.bound (+0/-4) tests/burgers_mms_adjoint/mms_C.ele (+0/-402) tests/burgers_mms_adjoint/mms_C.node (+0/-403) tests/burgers_mms_adjoint/mms_D.bml (+0/-231) tests/burgers_mms_adjoint/mms_D.bound (+0/-4) tests/burgers_mms_adjoint/mms_D.ele (+0/-802) tests/burgers_mms_adjoint/mms_D.node (+0/-803) tests/burgers_mms_adjoint/mms_E.bml (+0/-231) tests/burgers_mms_adjoint/mms_E.bound (+0/-4) tests/burgers_mms_adjoint/mms_E.ele (+0/-1602) tests/burgers_mms_adjoint/mms_E.node (+0/-1603) tests/burgers_mms_diffusion_adjoint/Makefile (+0/-10) tests/burgers_mms_diffusion_adjoint/burgers.sage (+0/-22) tests/burgers_mms_diffusion_adjoint/burgers_mms_diffusion_adjoint.xml (+0/-149) tests/burgers_mms_diffusion_adjoint/mms_A.bml (+0/-234) tests/burgers_mms_diffusion_adjoint/mms_A.bound (+0/-4) tests/burgers_mms_diffusion_adjoint/mms_A.ele (+0/-102) tests/burgers_mms_diffusion_adjoint/mms_A.node (+0/-103) tests/burgers_mms_diffusion_adjoint/mms_B.bml (+0/-234) tests/burgers_mms_diffusion_adjoint/mms_B.bound (+0/-4) tests/burgers_mms_diffusion_adjoint/mms_B.ele (+0/-202) tests/burgers_mms_diffusion_adjoint/mms_B.node (+0/-203) tests/burgers_mms_diffusion_adjoint/mms_C.bml (+0/-234) tests/burgers_mms_diffusion_adjoint/mms_C.bound (+0/-4) tests/burgers_mms_diffusion_adjoint/mms_C.ele (+0/-402) tests/burgers_mms_diffusion_adjoint/mms_C.node (+0/-403) tests/burgers_mms_diffusion_adjoint/mms_D.bml (+0/-234) tests/burgers_mms_diffusion_adjoint/mms_D.bound (+0/-4) tests/burgers_mms_diffusion_adjoint/mms_D.ele (+0/-802) tests/burgers_mms_diffusion_adjoint/mms_D.node (+0/-803) tests/burgers_mms_diffusion_adjoint/mms_E.bml (+0/-234) tests/burgers_mms_diffusion_adjoint/mms_E.bound (+0/-4) tests/burgers_mms_diffusion_adjoint/mms_E.ele (+0/-1602) tests/burgers_mms_diffusion_adjoint/mms_E.node (+0/-1603) tests/burgers_mms_diffusion_replay/Makefile (+15/-0) tests/burgers_mms_diffusion_replay/burgers.sage (+27/-0) tests/burgers_mms_diffusion_replay/burgers_mms_diffusion_replay.py (+54/-0) tests/burgers_mms_diffusion_replay/burgers_mms_diffusion_replay.xml (+25/-0) tests/burgers_mms_diffusion_replay/mms_A.bml (+200/-0) tests/burgers_mms_diffusion_replay/mms_A.bound (+4/-0) tests/burgers_mms_diffusion_replay/mms_A.ele (+102/-0) tests/burgers_mms_diffusion_replay/mms_A.node (+103/-0) tests/burgers_mms_diffusion_replay/mms_B.bml (+200/-0) tests/burgers_mms_diffusion_replay/mms_B.bound (+4/-0) tests/burgers_mms_diffusion_replay/mms_B.ele (+202/-0) tests/burgers_mms_diffusion_replay/mms_B.node (+203/-0) tests/burgers_mms_diffusion_replay/mms_C.bml (+200/-0) tests/burgers_mms_diffusion_replay/mms_C.bound (+4/-0) tests/burgers_mms_diffusion_replay/mms_C.ele (+402/-0) tests/burgers_mms_diffusion_replay/mms_C.node (+403/-0) tests/burgers_mms_diffusion_replay/mms_D.bml (+200/-0) tests/burgers_mms_diffusion_replay/mms_D.bound (+4/-0) tests/burgers_mms_diffusion_replay/mms_D.ele (+802/-0) tests/burgers_mms_diffusion_replay/mms_D.node (+803/-0) tests/burgers_mms_diffusion_replay/mms_E.bml (+200/-0) tests/burgers_mms_diffusion_replay/mms_E.bound (+4/-0) tests/burgers_mms_diffusion_replay/mms_E.ele (+1602/-0) tests/burgers_mms_diffusion_replay/mms_E.node (+1603/-0) tests/burgers_mms_diffusion_time_integral/burgers_mms_diffusion_time_integral.xml (+17/-15) tests/burgers_mms_diffusion_time_integral/mms_A.bml (+2/-2) tests/burgers_mms_diffusion_time_integral/mms_B.bml (+2/-2) tests/burgers_mms_diffusion_time_integral/mms_C.bml (+2/-2) tests/burgers_mms_diffusion_time_integral/mms_D.bml (+2/-2) tests/burgers_mms_diffusion_time_integral/mms_E.bml (+2/-2) tests/burgers_mms_gaussian/burgers_mms_gaussian.xml (+1/-1) tests/burgers_mms_gaussian_advection/burgers_mms_gaussian_advection.xml (+1/-1) tests/burgers_mms_replay/Makefile (+15/-0) tests/burgers_mms_replay/burgers.sage (+27/-0) tests/burgers_mms_replay/burgers_mms_replay.py (+54/-0) tests/burgers_mms_replay/burgers_mms_replay.xml (+25/-0) tests/burgers_mms_replay/mms_A.bml (+204/-0) tests/burgers_mms_replay/mms_A.bound (+4/-0) tests/burgers_mms_replay/mms_A.ele (+102/-0) tests/burgers_mms_replay/mms_A.node (+103/-0) tests/burgers_mms_replay/mms_B.bml (+204/-0) tests/burgers_mms_replay/mms_B.bound (+4/-0) tests/burgers_mms_replay/mms_B.ele (+202/-0) tests/burgers_mms_replay/mms_B.node (+203/-0) tests/burgers_mms_replay/mms_C.bml (+204/-0) tests/burgers_mms_replay/mms_C.bound (+4/-0) tests/burgers_mms_replay/mms_C.ele (+402/-0) tests/burgers_mms_replay/mms_C.node (+403/-0) tests/burgers_mms_replay/mms_D.bml (+204/-0) tests/burgers_mms_replay/mms_D.bound (+4/-0) tests/burgers_mms_replay/mms_D.ele (+802/-0) tests/burgers_mms_replay/mms_D.node (+803/-0) tests/burgers_mms_replay/mms_E.bml (+204/-0) tests/burgers_mms_replay/mms_E.bound (+4/-0) tests/burgers_mms_replay/mms_E.ele (+1602/-0) tests/burgers_mms_replay/mms_E.node (+1603/-0) tests/burgers_mms_replay/op_A.oml (+26/-0) tests/burgers_mms_steady_adjoint_gradient_init/Makefile (+16/-0) tests/burgers_mms_steady_adjoint_gradient_init/burgers.sage (+11/-0) tests/burgers_mms_steady_adjoint_gradient_init/burgers_mms_steady_adjoint_gradient_init.xml (+25/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_A.bml (+206/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_A.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_A.ele (+102/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_A.node (+103/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_A_controls.bml (+237/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_B.bml (+206/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_B.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_B.ele (+202/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_B.node (+203/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_C.bml (+206/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_C.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_C.ele (+402/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_C.node (+403/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_D.bml (+206/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_D.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_D.ele (+802/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_D.node (+803/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_E.bml (+209/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_E.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_E.ele (+1602/-0) tests/burgers_mms_steady_adjoint_gradient_init/mms_E.node (+1603/-0) tests/burgers_mms_steady_adjoint_gradient_init/op_A.oml (+19/-0) tests/burgers_mms_steady_adjoint_gradient_init/op_B.oml (+19/-0) tests/burgers_mms_steady_adjoint_gradient_init/op_C.oml (+19/-0) tests/burgers_mms_steady_adjoint_gradient_init/op_D.oml (+19/-0) tests/burgers_mms_steady_adjoint_gradient_init/op_E.oml (+19/-0) tests/burgers_mms_steady_adjoint_gradient_src/Makefile (+14/-0) tests/burgers_mms_steady_adjoint_gradient_src/burgers.sage (+11/-0) tests/burgers_mms_steady_adjoint_gradient_src/burgers_mms_steady_adjoint_gradient_src.xml (+36/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_A.bml (+236/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_A.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_A.ele (+102/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_A.node (+103/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_B.bml (+236/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_B.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_B.ele (+202/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_B.node (+203/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_C.bml (+236/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_C.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_C.ele (+402/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_C.node (+403/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_D.bml (+236/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_D.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_D.ele (+802/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_D.node (+803/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_E.bml (+236/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_E.bound (+4/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_E.ele (+1602/-0) tests/burgers_mms_steady_adjoint_gradient_src/mms_E.node (+1603/-0) tests/burgers_mms_steady_adjoint_gradient_src/op_A.oml (+19/-0) tests/burgers_tadj_mms/Makefile (+0/-10) tests/burgers_tadj_mms/adjoint_A.mv (+0/-84) tests/burgers_tadj_mms/adjoint_E.mv (+0/-84) tests/burgers_tadj_mms/burgers.sage (+0/-17) tests/burgers_tadj_mms/burgers_A.mv (+0/-84) tests/burgers_tadj_mms/burgers_tadj_mms.xml (+0/-53) tests/burgers_tadj_mms/mms_A.bml (+0/-251) tests/burgers_tadj_mms/mms_A.bound (+0/-4) tests/burgers_tadj_mms/mms_A.ele (+0/-12) tests/burgers_tadj_mms/mms_A.node (+0/-13) tests/burgers_tadj_mms/mms_B.bml (+0/-251) tests/burgers_tadj_mms/mms_B.bound (+0/-12) tests/burgers_tadj_mms/mms_B.ele (+0/-606) tests/burgers_tadj_mms/mms_B.node (+0/-609) tests/burgers_tadj_mms/mms_C.bml (+0/-251) tests/burgers_tadj_mms/mms_C.bound (+0/-12) tests/burgers_tadj_mms/mms_C.ele (+0/-1206) tests/burgers_tadj_mms/mms_C.node (+0/-1209) tests/burgers_tadj_mms/mms_D.bml (+0/-251) tests/burgers_tadj_mms/mms_D.bound (+0/-12) tests/burgers_tadj_mms/mms_D.ele (+0/-2406) tests/burgers_tadj_mms/mms_D.node (+0/-2409) tests/burgers_tadj_mms/mms_E.bml (+0/-251) tests/burgers_tadj_mms/mms_E.bound (+0/-12) tests/burgers_tadj_mms/mms_E.ele (+0/-4806) tests/burgers_tadj_mms/mms_E.node (+0/-4809) tests/burgers_tadj_nonlin/Makefile (+0/-10) tests/burgers_tadj_nonlin/burgers.sage (+0/-29) tests/burgers_tadj_nonlin/burgers_tadj_nonlin.xml (+0/-84) tests/burgers_tadj_nonlin/mms_A.bml (+0/-321) tests/burgers_tadj_nonlin/mms_A.bound (+0/-4) tests/burgers_tadj_nonlin/mms_A.ele (+0/-12) tests/burgers_tadj_nonlin/mms_A.node (+0/-13) tests/burgers_tadj_nonlin/mms_B.bml (+0/-321) tests/burgers_tadj_nonlin/mms_B.bound (+0/-12) tests/burgers_tadj_nonlin/mms_B.ele (+0/-606) tests/burgers_tadj_nonlin/mms_B.node (+0/-609) tests/burgers_tadj_nonlin/mms_C.bml (+0/-321) tests/burgers_tadj_nonlin/mms_C.bound (+0/-12) tests/burgers_tadj_nonlin/mms_C.ele (+0/-1206) tests/burgers_tadj_nonlin/mms_C.node (+0/-1209) tests/burgers_tadj_nonlin/mms_D.bml (+0/-321) tests/burgers_tadj_nonlin/mms_D.bound (+0/-12) tests/burgers_tadj_nonlin/mms_D.ele (+0/-2406) tests/burgers_tadj_nonlin/mms_D.node (+0/-2409) tests/burgers_tadj_nonlin/mms_E.bml (+0/-321) tests/burgers_tadj_nonlin/mms_E.bound (+0/-12) tests/burgers_tadj_nonlin/mms_E.ele (+0/-4806) tests/burgers_tadj_nonlin/mms_E.node (+0/-4809) tests/burgers_tadj_simple/Makefile (+0/-10) tests/burgers_tadj_simple/burgers.sage (+0/-29) tests/burgers_tadj_simple/burgers_tadj_simple.xml (+0/-84) tests/burgers_tadj_simple/mms_A.bml (+0/-335) tests/burgers_tadj_simple/mms_A.bound (+0/-4) tests/burgers_tadj_simple/mms_A.ele (+0/-12) tests/burgers_tadj_simple/mms_A.node (+0/-13) tests/burgers_tadj_simple/mms_B.bml (+0/-335) tests/burgers_tadj_simple/mms_B.bound (+0/-12) tests/burgers_tadj_simple/mms_B.ele (+0/-606) tests/burgers_tadj_simple/mms_B.node (+0/-609) tests/burgers_tadj_simple/mms_C.bml (+0/-335) tests/burgers_tadj_simple/mms_C.bound (+0/-12) tests/burgers_tadj_simple/mms_C.ele (+0/-1206) tests/burgers_tadj_simple/mms_C.node (+0/-1209) tests/burgers_tadj_simple/mms_D.bml (+0/-335) tests/burgers_tadj_simple/mms_D.bound (+0/-12) tests/burgers_tadj_simple/mms_D.ele (+0/-2406) tests/burgers_tadj_simple/mms_D.node (+0/-2409) tests/burgers_tadj_simple/mms_E.bml (+0/-335) tests/burgers_tadj_simple/mms_E.bound (+0/-12) tests/burgers_tadj_simple/mms_E.ele (+0/-4806) tests/burgers_tadj_simple/mms_E.node (+0/-4809) tests/burgers_tadj_timestep/Makefile (+0/-10) tests/burgers_tadj_timestep/burgers.sage (+0/-30) tests/burgers_tadj_timestep/burgers_tadj_timestep.xml (+0/-84) tests/burgers_tadj_timestep/mms_A.bml (+0/-333) tests/burgers_tadj_timestep/mms_A.bound (+0/-4) tests/burgers_tadj_timestep/mms_A.ele (+0/-12) tests/burgers_tadj_timestep/mms_A.node (+0/-13) tests/burgers_tadj_timestep/mms_B.bml (+0/-333) tests/burgers_tadj_timestep/mms_B.bound (+0/-12) tests/burgers_tadj_timestep/mms_B.ele (+0/-606) tests/burgers_tadj_timestep/mms_B.node (+0/-609) tests/burgers_tadj_timestep/mms_C.bml (+0/-333) tests/burgers_tadj_timestep/mms_C.bound (+0/-12) tests/burgers_tadj_timestep/mms_C.ele (+0/-1206) tests/burgers_tadj_timestep/mms_C.node (+0/-1209) tests/burgers_tadj_timestep/mms_D.bml (+0/-333) tests/burgers_tadj_timestep/mms_D.bound (+0/-12) tests/burgers_tadj_timestep/mms_D.ele (+0/-2406) tests/burgers_tadj_timestep/mms_D.node (+0/-2409) tests/burgers_tadj_timestep/mms_E.bml (+0/-333) tests/burgers_tadj_timestep/mms_E.bound (+0/-12) tests/burgers_tadj_timestep/mms_E.ele (+0/-4806) tests/burgers_tadj_timestep/mms_E.node (+0/-4809) tests/optimality/Makefile (+11/-0) tests/optimality/dummy.swml (+317/-0) tests/optimality/optimality.xml (+67/-0) tests/optimality/optimiser.oml (+68/-0) tests/optimality/src/Makefile (+2/-0) tests/optimality/src/mesh_A.bound (+4/-0) tests/optimality/src/mesh_A.ele (+6/-0) tests/optimality/src/mesh_A.node (+7/-0) tests/saltfinger2d_quad/saltfinger2d_quad.xml (+1/-1) tests/shallow_water_adjoint_default_controls/Makefile (+17/-0) tests/shallow_water_adjoint_default_controls/adjoint_A.swml (+534/-0) tests/shallow_water_adjoint_default_controls/adjoint_controls_convergence_rate.py (+54/-0) tests/shallow_water_adjoint_default_controls/shallow_water_adjoint_default_controls.py (+21/-0) tests/shallow_water_adjoint_default_controls/shallow_water_adjoint_default_controls.xml (+73/-0) tests/shallow_water_adjoint_default_controls/source_terms.py (+28/-0) tests/shallow_water_adjoint_default_controls/source_terms.sage (+25/-0) tests/shallow_water_adjoint_default_controls/src/Makefile (+6/-0) tests/shallow_water_adjoint_default_controls_2d/Makefile (+17/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_A.swml (+549/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_B.swml (+549/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_C.swml (+549/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_D.swml (+546/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_E.swml (+546/-0) tests/shallow_water_adjoint_default_controls_2d/adjoint_controls_convergence_rate_2d.py (+54/-0) tests/shallow_water_adjoint_default_controls_2d/shallow_water_adjoint_default_controls_2d.py (+29/-0) tests/shallow_water_adjoint_default_controls_2d/shallow_water_adjoint_default_controls_2d.xml (+73/-0) tests/shallow_water_adjoint_default_controls_2d/source_terms.py (+29/-0) tests/shallow_water_adjoint_default_controls_2d/source_terms.sage (+26/-0) tests/shallow_water_adjoint_default_controls_2d/src/Makefile (+9/-0) tests/shallow_water_adjoint_default_controls_2d/src/mesh_A.geo (+15/-0) tests/shallow_water_adjoint_default_controls_2d/src/mesh_B.geo (+15/-0) tests/shallow_water_adjoint_default_controls_2d/src/mesh_C.geo (+15/-0) tests/shallow_water_adjoint_eta/adjoint_A.swml (+16/-14) tests/shallow_water_adjoint_eta/shallow_water_adjoint_eta.xml (+5/-5) tests/shallow_water_adjoint_func_eval/shallow_water_adjoint_func_eval.xml (+1/-5) tests/shallow_water_adjoint_func_eval_2d/shallow_water_adjoint_func_eval_2d.xml (+18/-4) tests/shallow_water_adjoint_func_eval_2d/src/mesh_A.msh (+71/-71) tests/shallow_water_adjoint_func_eval_2d/src/mesh_B.msh (+241/-241) tests/shallow_water_adjoint_func_eval_2d/src/mesh_C.msh (+881/-881) tests/shallow_water_adjoint_func_eval_2d/time_integral_2d.py (+0/-8) tests/shallow_water_optimisation/Makefile (+22/-0) tests/shallow_water_optimisation/adjoint_A.swml (+338/-0) tests/shallow_water_optimisation/adjoint_B.swml (+388/-0) tests/shallow_water_optimisation/adjoint_C.swml (+388/-0) tests/shallow_water_optimisation/adjoint_D.swml (+388/-0) tests/shallow_water_optimisation/adjoint_E.swml (+388/-0) tests/shallow_water_optimisation/optimiser_A.oml (+23/-0) tests/shallow_water_optimisation/shallow_water_optimisation.py (+19/-0) tests/shallow_water_optimisation/shallow_water_optimisation.xml (+62/-0) tests/shallow_water_optimisation/source_terms.sage (+25/-0) tests/shallow_water_optimisation/src/Makefile (+6/-0) tests/shallow_water_optimisation/src/mesh_A.bound (+4/-0) tests/shallow_water_optimisation/src/mesh_A.ele (+12/-0) tests/shallow_water_optimisation/src/mesh_A.node (+13/-0) tests/shallow_water_optimisation/src/mesh_B.bound (+4/-0) tests/shallow_water_optimisation/src/mesh_B.ele (+22/-0) tests/shallow_water_optimisation/src/mesh_B.node (+23/-0) tests/shallow_water_optimisation/src/mesh_C.bound (+4/-0) tests/shallow_water_optimisation/src/mesh_C.ele (+42/-0) tests/shallow_water_optimisation/src/mesh_C.node (+43/-0) tests/shallow_water_optimisation/src/mesh_D.bound (+4/-0) tests/shallow_water_optimisation/src/mesh_D.ele (+82/-0) tests/shallow_water_optimisation/src/mesh_D.node (+83/-0) tests/shallow_water_optimisation/src/mesh_E.bound (+4/-0) tests/shallow_water_optimisation/src/mesh_E.ele (+162/-0) tests/shallow_water_optimisation/src/mesh_E.node (+163/-0) tests/shallow_water_optimisation_2d/Makefile (+21/-0) tests/shallow_water_optimisation_2d/adjoint_A.swml (+349/-0) tests/shallow_water_optimisation_2d/adjoint_B.swml (+398/-0) tests/shallow_water_optimisation_2d/adjoint_C.swml (+398/-0) tests/shallow_water_optimisation_2d/adjoint_D.swml (+398/-0) tests/shallow_water_optimisation_2d/adjoint_E.swml (+398/-0) tests/shallow_water_optimisation_2d/constants_2d.py (+27/-0) tests/shallow_water_optimisation_2d/optimiser_A.log (+15/-0) tests/shallow_water_optimisation_2d/optimiser_A.oml (+20/-0) tests/shallow_water_optimisation_2d/optimiser_B.oml (+20/-0) tests/shallow_water_optimisation_2d/optimiser_C.oml (+20/-0) tests/shallow_water_optimisation_2d/optimiser_D.oml (+20/-0) tests/shallow_water_optimisation_2d/optimiser_E.oml (+20/-0) tests/shallow_water_optimisation_2d/shallow_water_optimisation_2d.xml (+62/-0) tests/shallow_water_optimisation_2d/source_terms.py (+25/-0) tests/shallow_water_optimisation_2d/source_terms.sage (+22/-0) tests/shallow_water_optimisation_2d/src/Makefile (+3/-0) tests/shallow_water_optimisation_2d/src/mesh_A.bound (+4/-0) tests/shallow_water_optimisation_2d/src/mesh_A.edge (+38/-0) tests/shallow_water_optimisation_2d/src/mesh_A.ele (+198/-0) tests/shallow_water_optimisation_2d/src/mesh_A.geo (+15/-0) tests/shallow_water_optimisation_2d/src/mesh_A.msh (+358/-0) tests/shallow_water_optimisation_2d/src/mesh_A.node (+119/-0) tests/shallow_water_optimisation_bounds/Makefile (+19/-0) tests/shallow_water_optimisation_bounds/adjoint_A.swml (+378/-0) tests/shallow_water_optimisation_bounds/adjoint_B.swml (+422/-0) tests/shallow_water_optimisation_bounds/adjoint_C.swml (+422/-0) tests/shallow_water_optimisation_bounds/adjoint_D.swml (+422/-0) tests/shallow_water_optimisation_bounds/optimiser_A.oml (+20/-0) tests/shallow_water_optimisation_bounds/optimiser_B.oml (+20/-0) tests/shallow_water_optimisation_bounds/optimiser_C.oml (+20/-0) tests/shallow_water_optimisation_bounds/optimiser_D.oml (+20/-0) tests/shallow_water_optimisation_bounds/shallow_water_optimisation_bounds.py (+19/-0) tests/shallow_water_optimisation_bounds/shallow_water_optimisation_bounds.xml (+63/-0) tests/shallow_water_optimisation_bounds/source_terms.py (+28/-0) tests/shallow_water_optimisation_bounds/source_terms.sage (+25/-0) tests/shallow_water_optimisation_bounds/src/Makefile (+5/-0) tests/shallow_water_optimisation_check_gradient_2d/Makefile (+11/-0) tests/shallow_water_optimisation_check_gradient_2d/adjoint_A.swml (+350/-0) tests/shallow_water_optimisation_check_gradient_2d/constants_2d.py (+27/-0) tests/shallow_water_optimisation_check_gradient_2d/optimiser_A.oml (+26/-0) tests/shallow_water_optimisation_check_gradient_2d/shallow_water_optimisation_check_gradient_2d.xml (+18/-0) tests/shallow_water_optimisation_check_gradient_2d/src/Makefile (+3/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.bound (+4/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.edge (+14/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.ele (+24/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.geo (+15/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.msh (+61/-0) tests/shallow_water_optimisation_check_gradient_2d/src/mesh_A.node (+20/-0) tests/shallow_water_optimisation_sphere/Makefile (+16/-0) tests/shallow_water_optimisation_sphere/constants_2d.py (+33/-0) tests/shallow_water_optimisation_sphere/optimiser_A.oml (+23/-0) tests/shallow_water_optimisation_sphere/shallow_water_optimisation_sphere.xml (+40/-0) tests/shallow_water_optimisation_sphere/source_terms.py (+31/-0) tests/shallow_water_optimisation_sphere/source_terms.sage (+28/-0) tests/shallow_water_optimisation_sphere/src/Makefile (+7/-0) tests/shallow_water_optimisation_sphere/src/sphere_A.geo (+42/-0) tests/shallow_water_optimisation_sphere/src/sphere_B.geo (+42/-0) tests/shallow_water_optimisation_sphere/src/sphere_C.geo (+42/-0) tests/shallow_water_optimisation_sphere/sw_fsphere_A.swml (+471/-0) tests/shallow_water_optimisation_sphere/sw_fsphere_B.swml (+472/-0) tests/shallow_water_optimisation_sphere/sw_fsphere_C.swml (+472/-0) tests/sw_fsphere/sw_fsphere.swml (+1/-1) tests/sw_kelvin_wave/sw_kelvin_wave.xml (+1/-1) tests/sw_kelvin_wave_xz/sw_kelvin_wave_xz.xml (+1/-1) tools/testharness.py (+13/-4) |
To merge this branch: | bzr merge lp:~fluidity-core/fluidity/adjoint |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Ham | Approve | ||
Review via email: mp+67670@code.launchpad.net |
Commit message
Description of the change
Overview of the major changes:
-------
* The burgers equation adjoint now works, including nonlinear terms (and so their derivatives). The differentiation of the CG discretisation of the advection term is achieved using tapenade.
* The development of a program (scripts/
* More (and more rigorous) test cases. The fundamental tool for verifying the discrete adjoint is the derivative test, which is implemented in optimality.py. Suppose you can compute J(m), and have a candidate for grad(J)(m). Then
|| J(m + dm) - J(m) || should converge at O(||dm||), and
|| J(m + dm) - J(m) - grad(J)(m) . dm || should converge at O(||dm||^2).
* Much stronger tools for debugging adjoint model development, including
- forward replay verification
- transpose action correctness
- nonlinear derivative consistency
- the derivative test in optimality.py
- 3589. By Patrick Farrell
-
Removing shallow_
water_mms_ sphere: it never worked. Simon: I checked out the commit which added this, and the
test is broken there. If you want this test, revive it,
fix it, and add it back. - 3590. By Patrick Farrell
-
In the shallow water model, we now write_diagnostics before the timeloop
begins. (Simon: why? It was r3521. Something to do with the optimiser?)
So we have to change the test to look at stat[1] instead of stat[0] so that
it is looking at the same thing. - 3591. By Patrick Farrell
-
Loosen some tolerances slightly, and activate two new assertions that had been
broken - 3592. By Patrick Farrell
-
Try to get some useful information out of this test; it is failing on
the buildbot, but works when I run it by hand (on my workstation,
and on the buildbot builder) - 3593. By Patrick Farrell
-
Implement David's suggestions during the code review.
Patrick Farrell (pefarrell) wrote : | # |
Patrick Farrell (pefarrell) wrote : | # |
All tests pass with --with-adjoint=no:
http://
(Ignore the colour and look at the stdio; the buildbot is interpreting it incorrectly.)
Just waiting on the --with-adjoint=yes case.
David Ham (david-ham) : | # |
Patrick Farrell (pefarrell) wrote : | # |
The --with-adjoint case also passes:
http://
The only exception is the channel-flow-dg case, which is known broken in the trunk.
Updating diff...
An updated diff will be available in a few minutes. Reload to see the changes.
Preview Diff
1 | === modified file 'Makefile.in' | |||
2 | --- Makefile.in 2011-06-27 14:01:01 +0000 | |||
3 | +++ Makefile.in 2011-07-12 15:56:32 +0000 | |||
4 | @@ -424,7 +424,7 @@ | |||
5 | 424 | @echo " CLEAN tests" | 424 | @echo " CLEAN tests" |
6 | 425 | @cd tests; ../tools/testharness.py --clean >/dev/null | 425 | @cd tests; ../tools/testharness.py --clean >/dev/null |
7 | 426 | 426 | ||
9 | 427 | test: fltools bin/@FLUIDITY@ bin/shallow_water serialtest | 427 | test: fltools bin/@FLUIDITY@ bin/shallow_water serialtest bin/burgers_equation |
10 | 428 | 428 | ||
11 | 429 | serialtest: | 429 | serialtest: |
12 | 430 | ifeq (@MBA2D@,yes) | 430 | ifeq (@MBA2D@,yes) |
13 | @@ -441,7 +441,7 @@ | |||
14 | 441 | endif | 441 | endif |
15 | 442 | endif | 442 | endif |
16 | 443 | 443 | ||
18 | 444 | mediumtest: | 444 | mediumtest: bin/burgers_equation |
19 | 445 | @cd tests; ../tools/testharness.py -l medium $(EXCLUDE_TAGS) -n $(THREADS) | 445 | @cd tests; ../tools/testharness.py -l medium $(EXCLUDE_TAGS) -n $(THREADS) |
20 | 446 | 446 | ||
21 | 447 | mediumzoltantest: | 447 | mediumzoltantest: |
22 | 448 | 448 | ||
23 | === modified file 'aclocal.m4' | |||
24 | --- aclocal.m4 2011-02-01 18:21:13 +0000 | |||
25 | +++ aclocal.m4 2011-07-12 15:56:32 +0000 | |||
26 | @@ -1030,10 +1030,11 @@ | |||
27 | 1030 | [adjoint="$withval"], | 1030 | [adjoint="$withval"], |
28 | 1031 | []) | 1031 | []) |
29 | 1032 | 1032 | ||
30 | 1033 | bakLIBS=$LIBS | ||
31 | 1033 | tmpLIBS=$LIBS | 1034 | tmpLIBS=$LIBS |
32 | 1034 | tmpCPPFLAGS=$CPPFLAGS | 1035 | tmpCPPFLAGS=$CPPFLAGS |
35 | 1035 | if test $adjoint != no; then | 1036 | if test "$adjoint" != "no"; then |
36 | 1036 | if test $adjoint != yes; then | 1037 | if test "$adjoint" != "yes"; then |
37 | 1037 | adjoint_LIBS_PATH="$adjoint/lib" | 1038 | adjoint_LIBS_PATH="$adjoint/lib" |
38 | 1038 | adjoint_INCLUDES_PATH="$adjoint/include" | 1039 | adjoint_INCLUDES_PATH="$adjoint/include" |
39 | 1039 | # Ensure the comiler finds the library... | 1040 | # Ensure the comiler finds the library... |
40 | @@ -1051,10 +1052,9 @@ | |||
41 | 1051 | AC_CHECK_LIB( | 1052 | AC_CHECK_LIB( |
42 | 1052 | [adjoint], | 1053 | [adjoint], |
43 | 1053 | [adj_register_equation], | 1054 | [adj_register_equation], |
46 | 1054 | [AC_DEFINE(HAVE_ADJOINT,1,[Define if you have libadjoint.])], | 1055 | [AC_DEFINE(HAVE_ADJOINT,1,[Define if you have libadjoint.])HAVE_ADJOINT=yes], |
47 | 1055 | [AC_MSG_ERROR( [Could not link in libadjoint ... exiting] )] ) | 1056 | [AC_MSG_WARN( [Could not link in libadjoint ... ] );HAVE_ADJOINT=no;LIBS=$bakLIBS] ) |
48 | 1056 | # Save variables... | 1057 | # Save variables... |
49 | 1057 | AC_LANG_RESTORE | 1058 | AC_LANG_RESTORE |
50 | 1058 | 1059 | ||
51 | 1059 | echo $LIBS | ||
52 | 1060 | ])dnl ACX_adjoint | 1060 | ])dnl ACX_adjoint |
53 | 1061 | 1061 | ||
54 | === added file 'adjoint/Adjoint_Controls.F90' | |||
55 | --- adjoint/Adjoint_Controls.F90 1970-01-01 00:00:00 +0000 | |||
56 | +++ adjoint/Adjoint_Controls.F90 2011-07-12 15:56:32 +0000 | |||
57 | @@ -0,0 +1,611 @@ | |||
58 | 1 | ! Copyright (C) 2006 Imperial College London and others. | ||
59 | 2 | ! | ||
60 | 3 | ! Please see the AUTHORS file in the main source directory for a full list | ||
61 | 4 | ! of copyright holders. | ||
62 | 5 | ! | ||
63 | 6 | ! Prof. C Pain | ||
64 | 7 | ! Applied Modelling and Computation Group | ||
65 | 8 | ! Department of Earth Science and Engineering | ||
66 | 9 | ! Imperial College London | ||
67 | 10 | ! | ||
68 | 11 | ! amcgsoftware@imperial.ac.uk | ||
69 | 12 | ! | ||
70 | 13 | ! This library is free software; you can redistribute it and/or | ||
71 | 14 | ! modify it under the terms of the GNU Lesser General Public | ||
72 | 15 | ! License as published by the Free Software Foundation, | ||
73 | 16 | ! version 2.1 of the License. | ||
74 | 17 | ! | ||
75 | 18 | ! This library is distributed in the hope that it will be useful, | ||
76 | 19 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
77 | 20 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
78 | 21 | ! Lesser General Public License for more details. | ||
79 | 22 | ! | ||
80 | 23 | ! You should have received a copy of the GNU Lesser General Public | ||
81 | 24 | ! License along with this library; if not, write to the Free Software | ||
82 | 25 | ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
83 | 26 | ! USA | ||
84 | 27 | |||
85 | 28 | #include "fdebug.h" | ||
86 | 29 | |||
87 | 30 | module adjoint_controls | ||
88 | 31 | use fields | ||
89 | 32 | use global_parameters, only : PYTHON_FUNC_LEN, OPTION_PATH_LEN | ||
90 | 33 | use boundary_conditions | ||
91 | 34 | use spud | ||
92 | 35 | use state_module | ||
93 | 36 | use python_state | ||
94 | 37 | |||
95 | 38 | implicit none | ||
96 | 39 | |||
97 | 40 | private | ||
98 | 41 | |||
99 | 42 | public :: adjoint_load_controls, adjoint_write_controls, adjoint_write_control_derivatives, allocate_and_insert_control_derivative_fields | ||
100 | 43 | |||
101 | 44 | contains | ||
102 | 45 | |||
103 | 46 | ! Retrieves the control details from control number control_no in the optin tree. The outputs are: | ||
104 | 47 | subroutine get_control_details(states, timestep, control_no, control_name, state_id, field_name, field_type, & | ||
105 | 48 | & active, have_lb, lb_state_id, lb_material_phase_name, lb_field_name, have_ub, & | ||
106 | 49 | & ub_state_id, ub_material_phase_name, ub_field_name) | ||
107 | 50 | |||
108 | 51 | ! Inputs: | ||
109 | 52 | type(state_type), dimension(:), intent(in) :: states | ||
110 | 53 | integer, intent(in) :: control_no, timestep ! control_no: The index of the control in the option tree | ||
111 | 54 | ! timestep: The timestep | ||
112 | 55 | |||
113 | 56 | ! Outputs: | ||
114 | 57 | character(len=OPTION_PATH_LEN), intent(out) :: control_name, field_type, field_name ! control_name: the name of the control | ||
115 | 58 | ! field_name: the name of the associated field | ||
116 | 59 | ! field_type: the type of the associated field | ||
117 | 60 | integer, intent(out) :: state_id ! the state number in which the associated control field exists | ||
118 | 61 | logical, intent(out) :: active ! false if the control is active in this timestep (e.g. InitialConditions for timesteps >0) | ||
119 | 62 | logical, intent(out), optional :: have_ub, have_lb | ||
120 | 63 | integer, intent(out), optional :: lb_state_id, ub_state_id | ||
121 | 64 | character(len=OPTION_PATH_LEN), intent(out), optional :: lb_material_phase_name, ub_material_phase_name | ||
122 | 65 | character(len=OPTION_PATH_LEN), intent(out), optional :: ub_field_name, lb_field_name | ||
123 | 66 | |||
124 | 67 | integer :: s_idx | ||
125 | 68 | character(len=OPTION_PATH_LEN) :: control_type, material_phase_name, name | ||
126 | 69 | type(scalar_field), pointer :: sfield => null(), sfield2 => null() | ||
127 | 70 | type(vector_field), pointer :: vfield => null(), vfield2 => null() | ||
128 | 71 | type(tensor_field), pointer :: tfield => null(), tfield2 => null() | ||
129 | 72 | |||
130 | 73 | call get_option("/adjoint/controls/control[" // int2str(control_no) //"]/name", control_name) | ||
131 | 74 | call get_option("/adjoint/controls/control[" // int2str(control_no) //"]/type/name", control_type) | ||
132 | 75 | call get_option("/adjoint/controls/control[" // int2str(control_no) //"]/type::" // trim(control_type) // "/field_name", name) | ||
133 | 76 | |||
134 | 77 | s_idx = scan(trim(name), "::") | ||
135 | 78 | if (s_idx == 0) then | ||
136 | 79 | FLExit("The control " // trim(control_name) // " uses an invalid field_name. It should be of the form Materialphase::Field") | ||
137 | 80 | end if | ||
138 | 81 | material_phase_name = name(1:s_idx - 1) | ||
139 | 82 | field_name = name(s_idx + 2:len_trim(name)) | ||
140 | 83 | |||
141 | 84 | active = .true. | ||
142 | 85 | |||
143 | 86 | ! Find state associated with the material phase | ||
144 | 87 | do state_id = 1, size(states) | ||
145 | 88 | if (trim(states(state_id)%name) == trim(material_phase_name)) then | ||
146 | 89 | exit | ||
147 | 90 | end if | ||
148 | 91 | end do | ||
149 | 92 | if (.not. trim(states(state_id)%name) == trim(material_phase_name)) then | ||
150 | 93 | FLExit("Could not find state " // trim(material_phase_name) // " as specified in control " // trim(control_name) // ".") | ||
151 | 94 | end if | ||
152 | 95 | |||
153 | 96 | select case (trim(control_type)) | ||
154 | 97 | case ("initial_condition") | ||
155 | 98 | if (timestep > 0) then | ||
156 | 99 | active = .false. | ||
157 | 100 | field_type = '' | ||
158 | 101 | field_name = '' | ||
159 | 102 | return | ||
160 | 103 | endif | ||
161 | 104 | assert(timestep == 0) | ||
162 | 105 | if (has_scalar_field(states(state_id), field_name)) then | ||
163 | 106 | field_type = "scalar" | ||
164 | 107 | elseif (has_vector_field(states(state_id), field_name)) then | ||
165 | 108 | field_type = "vector" | ||
166 | 109 | elseif (has_tensor_field(states(state_id), field_name)) then | ||
167 | 110 | field_type = "tensor" | ||
168 | 111 | else | ||
169 | 112 | ewrite(0, *) "The control field " // trim(field_name) // " specified in control " // trim(control_name) // " is not a field in the state." | ||
170 | 113 | ewrite(0, *) "The current state is: " | ||
171 | 114 | call print_state(states(state_id)) | ||
172 | 115 | FLExit("Check your control's field settings.") | ||
173 | 116 | end if | ||
174 | 117 | |||
175 | 118 | case ("source_term") | ||
176 | 119 | if (timestep == 0) then | ||
177 | 120 | active = .false. | ||
178 | 121 | field_type = '' | ||
179 | 122 | field_name = '' | ||
180 | 123 | return | ||
181 | 124 | end if | ||
182 | 125 | |||
183 | 126 | if (has_scalar_field(states(state_id), field_name)) then | ||
184 | 127 | field_type = "scalar" | ||
185 | 128 | elseif (has_vector_field(states(state_id), field_name)) then | ||
186 | 129 | field_type = "vector" | ||
187 | 130 | elseif (has_tensor_field(states(state_id), field_name)) then | ||
188 | 131 | field_type = "tensor" | ||
189 | 132 | else | ||
190 | 133 | ewrite(0, *) "The control field " // trim(name) // " specified in control " // trim(control_name) // & | ||
191 | 134 | & " is not a field in state " // trim(material_phase_name) // "." | ||
192 | 135 | ewrite(0, *) "The current state is: " | ||
193 | 136 | call print_state(states(state_id)) | ||
194 | 137 | FLExit("Check your control's field settings.") | ||
195 | 138 | end if | ||
196 | 139 | |||
197 | 140 | case ("boundary_condition") | ||
198 | 141 | FLAbort("Boundary condition control not implemented yet.") | ||
199 | 142 | end select | ||
200 | 143 | |||
201 | 144 | !!!! Check bounds settings !!!! | ||
202 | 145 | ! We only execute this when the optional files are present | ||
203 | 146 | if (.not. present(have_lb) .or. .not. present(have_ub)) then | ||
204 | 147 | return | ||
205 | 148 | endif | ||
206 | 149 | |||
207 | 150 | have_ub = have_option("/adjoint/controls/control[0]/bounds/upper_bound") | ||
208 | 151 | have_ub = have_option("/adjoint/controls/control[" // int2str(control_no) //"]/bounds/upper_bound") | ||
209 | 152 | have_lb = have_option("/adjoint/controls/control[" // int2str(control_no) //"]/bounds/lower_bound") | ||
210 | 153 | |||
211 | 154 | ! Find material phase for the lower bound field | ||
212 | 155 | if (have_lb) then | ||
213 | 156 | call get_option("/adjoint/controls/control[" // int2str(control_no) //"]/bounds/lower_bound/field_name", name) | ||
214 | 157 | if (have_lb) then | ||
215 | 158 | s_idx = scan(trim(name), "::") | ||
216 | 159 | if (s_idx == 0) then | ||
217 | 160 | FLExit("The control lower bound for control " // trim(control_name) // " uses an invalid field_name. It should be of the form Materialphase::Field") | ||
218 | 161 | end if | ||
219 | 162 | lb_material_phase_name = name(1:s_idx - 1) | ||
220 | 163 | lb_field_name = name(s_idx + 2:len_trim(name)) | ||
221 | 164 | ! Find state associated with the lower bound material phase | ||
222 | 165 | do lb_state_id = 1, size(states) | ||
223 | 166 | if (trim(states(lb_state_id)%name) == trim(lb_material_phase_name)) then | ||
224 | 167 | exit | ||
225 | 168 | end if | ||
226 | 169 | end do | ||
227 | 170 | if (.not. trim(states(lb_state_id)%name) == trim(lb_material_phase_name)) then | ||
228 | 171 | FLExit("Could not find state " // trim(lb_material_phase_name) // " as specified in the lower bound of control " // trim(control_name) // ".") | ||
229 | 172 | end if | ||
230 | 173 | end if | ||
231 | 174 | end if | ||
232 | 175 | |||
233 | 176 | ! Find material phase for the upper bound field | ||
234 | 177 | if (have_ub) then | ||
235 | 178 | call get_option("/adjoint/controls/control[" // int2str(control_no) //"]/bounds/upper_bound/field_name", name) | ||
236 | 179 | if (have_ub) then | ||
237 | 180 | s_idx = scan(trim(name), "::") | ||
238 | 181 | if (s_idx == 0) then | ||
239 | 182 | FLExit("The control upper bound for control " // trim(control_name) // " uses an invalid field_name. It should be of the form Materialphase::Field") | ||
240 | 183 | end if | ||
241 | 184 | ub_material_phase_name = name(1:s_idx - 1) | ||
242 | 185 | ub_field_name = name(s_idx + 2:len_trim(name)) | ||
243 | 186 | ! Find state associated with the upper bound material phase | ||
244 | 187 | do ub_state_id = 1, size(states) | ||
245 | 188 | if (trim(states(ub_state_id)%name) == trim(ub_material_phase_name)) then | ||
246 | 189 | exit | ||
247 | 190 | end if | ||
248 | 191 | end do | ||
249 | 192 | if (.not. trim(states(ub_state_id)%name) == trim(ub_material_phase_name)) then | ||
250 | 193 | FLExit("Could not find state " // trim(ub_material_phase_name) // " as specified in the upper bound of control " // trim(control_name) // ".") | ||
251 | 194 | end if | ||
252 | 195 | end if | ||
253 | 196 | end if | ||
254 | 197 | |||
255 | 198 | ! Check that the lower/upper bound fields indeed exist and have the same mesh than the control | ||
256 | 199 | select case (trim(field_type)) | ||
257 | 200 | |||
258 | 201 | case ("scalar") | ||
259 | 202 | ! Upper bound | ||
260 | 203 | ! Check that the specified field exist in the state | ||
261 | 204 | if (have_ub) then | ||
262 | 205 | if (.not. has_scalar_field(states(ub_state_id), ub_field_name)) then | ||
263 | 206 | ewrite(0, *) "Can not find the specified field ", trim(ub_field_name), " for the upper bound of control ", trim(control_name) | ||
264 | 207 | FLExit("Check your control's field settings.") | ||
265 | 208 | end if | ||
266 | 209 | |||
267 | 210 | ! Check that the control and the upper bound use the same mesh | ||
268 | 211 | sfield => extract_scalar_field(states(state_id), field_name) | ||
269 | 212 | sfield2 => extract_scalar_field(states(ub_state_id), ub_field_name) | ||
270 | 213 | if (.not. sfield%mesh == sfield2%mesh) then | ||
271 | 214 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The upper bound and the control's mesh have to be the same." | ||
272 | 215 | FLExit("Check your control's field settings.") | ||
273 | 216 | end if | ||
274 | 217 | end if | ||
275 | 218 | |||
276 | 219 | ! Lower bound | ||
277 | 220 | if (have_lb) then | ||
278 | 221 | if (.not. has_scalar_field(states(state_id), lb_field_name)) then | ||
279 | 222 | ewrite(0, *) "Can not find the specified field ", trim(lb_field_name), " for the lower bound of control ", trim(control_name) | ||
280 | 223 | FLExit("Check your control's field settings.") | ||
281 | 224 | end if | ||
282 | 225 | |||
283 | 226 | ! Check that the control and the lower bound use the same mesh | ||
284 | 227 | sfield => extract_scalar_field(states(state_id), field_name) | ||
285 | 228 | sfield2 => extract_scalar_field(states(lb_state_id), lb_field_name) | ||
286 | 229 | if (.not. sfield%mesh == sfield2%mesh) then | ||
287 | 230 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The lower bound and the control's mesh have to be the same." | ||
288 | 231 | FLExit("Check your control's field settings.") | ||
289 | 232 | end if | ||
290 | 233 | end if | ||
291 | 234 | |||
292 | 235 | case ("vector") | ||
293 | 236 | ! Upper bound | ||
294 | 237 | ! Check that the specified field exist in the state | ||
295 | 238 | if (have_ub) then | ||
296 | 239 | if (.not. has_vector_field(states(ub_state_id), ub_field_name)) then | ||
297 | 240 | ewrite(0, *) "Can not find the specified field ", trim(ub_field_name), " for the upper bound of control ", trim(control_name) | ||
298 | 241 | FLExit("Check your control's field settings.") | ||
299 | 242 | end if | ||
300 | 243 | |||
301 | 244 | ! Check that the control and the upper bound use the same mesh | ||
302 | 245 | vfield => extract_vector_field(states(state_id), field_name) | ||
303 | 246 | vfield2 => extract_vector_field(states(ub_state_id), ub_field_name) | ||
304 | 247 | if (.not. vfield%mesh == vfield2%mesh) then | ||
305 | 248 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The upper bound and the control's mesh have to be the same." | ||
306 | 249 | FLExit("Check your control's field settings.") | ||
307 | 250 | end if | ||
308 | 251 | end if | ||
309 | 252 | |||
310 | 253 | ! Lower bound | ||
311 | 254 | if (have_lb) then | ||
312 | 255 | if (.not. has_vector_field(states(state_id), lb_field_name)) then | ||
313 | 256 | ewrite(0, *) "Can not find the specified field ", trim(lb_field_name), " for the lower bound of control ", trim(control_name) | ||
314 | 257 | FLExit("Check your control's field settings.") | ||
315 | 258 | end if | ||
316 | 259 | |||
317 | 260 | ! Check that the control and the lower bound use the same mesh | ||
318 | 261 | vfield => extract_vector_field(states(state_id), field_name) | ||
319 | 262 | vfield2 => extract_vector_field(states(lb_state_id), lb_field_name) | ||
320 | 263 | if (.not. vfield%mesh == vfield2%mesh) then | ||
321 | 264 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The lower bound and the control's mesh have to be the same." | ||
322 | 265 | FLExit("Check your control's field settings.") | ||
323 | 266 | end if | ||
324 | 267 | end if | ||
325 | 268 | |||
326 | 269 | case ("tensor") | ||
327 | 270 | ! Upper bound | ||
328 | 271 | ! Check that the specified field exist in the state | ||
329 | 272 | if (have_ub) then | ||
330 | 273 | if (.not. has_tensor_field(states(ub_state_id), ub_field_name)) then | ||
331 | 274 | ewrite(0, *) "Can not find the specified field ", trim(ub_field_name), " for the upper bound of control ", trim(control_name) | ||
332 | 275 | FLExit("Check your control's field settings.") | ||
333 | 276 | end if | ||
334 | 277 | |||
335 | 278 | ! Check that the control and the upper bound use the same mesh | ||
336 | 279 | tfield => extract_tensor_field(states(state_id), field_name) | ||
337 | 280 | tfield2 => extract_tensor_field(states(ub_state_id), ub_field_name) | ||
338 | 281 | if (.not. tfield%mesh == tfield2%mesh) then | ||
339 | 282 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The lower bound and the control's mesh have to be the same." | ||
340 | 283 | FLExit("Check your control's field settings.") | ||
341 | 284 | end if | ||
342 | 285 | end if | ||
343 | 286 | |||
344 | 287 | ! Lower bound | ||
345 | 288 | if (have_lb) then | ||
346 | 289 | if (.not. has_tensor_field(states(state_id), lb_field_name)) then | ||
347 | 290 | ewrite(0, *) "Can not find the specified field ", trim(lb_field_name), " for the lower bound of control ", trim(control_name) | ||
348 | 291 | FLExit("Check your control's field settings.") | ||
349 | 292 | end if | ||
350 | 293 | |||
351 | 294 | ! Check that the control and the lower bound use the same mesh | ||
352 | 295 | tfield => extract_tensor_field(states(state_id), field_name) | ||
353 | 296 | tfield2 => extract_tensor_field(states(lb_state_id), lb_field_name) | ||
354 | 297 | if (.not. sfield%mesh == sfield2%mesh) then | ||
355 | 298 | ewrite(0, *) "Error in control ", trim(control_name), " definition. The lower bound and the control's mesh have to be the same." | ||
356 | 299 | FLExit("Check your control's field settings.") | ||
357 | 300 | end if | ||
358 | 301 | end if | ||
359 | 302 | |||
360 | 303 | end select | ||
361 | 304 | end subroutine get_control_details | ||
362 | 305 | |||
363 | 306 | ! Loop through all controls in the option file and store them in files. | ||
364 | 307 | subroutine adjoint_write_controls(timestep, dt, states) | ||
365 | 308 | integer, intent(in) :: timestep | ||
366 | 309 | real, intent(in) :: dt | ||
367 | 310 | type(state_type), dimension(:), intent(in) :: states | ||
368 | 311 | #ifdef HAVE_ADJOINT | ||
369 | 312 | integer :: nb_controls, i, state_id | ||
370 | 313 | logical :: active | ||
371 | 314 | character(len=OPTION_PATH_LEN) :: simulation_name, field_name, field_type, control_name | ||
372 | 315 | logical :: have_ub, have_lb | ||
373 | 316 | integer :: lb_state_id, ub_state_id | ||
374 | 317 | character(len=OPTION_PATH_LEN) :: lb_material_phase_name, ub_material_phase_name | ||
375 | 318 | character(len=OPTION_PATH_LEN) :: ub_field_name, lb_field_name | ||
376 | 319 | |||
377 | 320 | if (.not. have_option("/adjoint/controls")) then | ||
378 | 321 | return | ||
379 | 322 | end if | ||
380 | 323 | |||
381 | 324 | nb_controls = option_count("/adjoint/controls/control") | ||
382 | 325 | call get_option("/simulation_name", simulation_name) | ||
383 | 326 | ! Now loop over the controls and save them to disk | ||
384 | 327 | do i = 0, nb_controls-1 | ||
385 | 328 | call get_control_details(states, timestep, i, control_name, state_id, field_name, field_type, active, have_lb, lb_state_id, lb_material_phase_name, lb_field_name, have_ub, ub_state_id, ub_material_phase_name, ub_field_name) | ||
386 | 329 | if (active) then | ||
387 | 330 | |||
388 | 331 | ! Save the control parameter to disk | ||
389 | 332 | call python_reset() | ||
390 | 333 | call python_add_state(states(state_id)) | ||
391 | 334 | call python_run_string("import pickle;" // & | ||
392 | 335 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_name) // "_" // int2str(timestep) // ".pkl';" // & | ||
393 | 336 | & "f = open(fname, 'wb');" // & | ||
394 | 337 | & "field = state." // trim(field_type) // "_fields['" // trim(field_name) // "'];" // & | ||
395 | 338 | & "pickle.dump(field.val[:], f);" // & | ||
396 | 339 | & "f.close();") | ||
397 | 340 | |||
398 | 341 | ! And its bounds | ||
399 | 342 | call python_reset() | ||
400 | 343 | if (have_lb) then | ||
401 | 344 | call python_add_state(states(lb_state_id)) | ||
402 | 345 | call python_run_string("import pickle;" // & | ||
403 | 346 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_name) // "_lower_bound_" // int2str(timestep) // ".pkl';" // & | ||
404 | 347 | & "f = open(fname, 'wb');" // & | ||
405 | 348 | & "field = state." // trim(field_type) // "_fields['" // trim(lb_field_name) // "'];" // & | ||
406 | 349 | & "pickle.dump(field.val[:], f);" // & | ||
407 | 350 | & "f.close();") | ||
408 | 351 | call python_reset() | ||
409 | 352 | end if | ||
410 | 353 | |||
411 | 354 | if (have_ub) then | ||
412 | 355 | call python_add_state(states(ub_state_id)) | ||
413 | 356 | call python_run_string("import pickle;" // & | ||
414 | 357 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_name) // "_upper_bound_" // int2str(timestep) // ".pkl';" // & | ||
415 | 358 | & "f = open(fname, 'wb');" // & | ||
416 | 359 | & "field = state." // trim(field_type) // "_fields['" // trim(ub_field_name) // "'];" // & | ||
417 | 360 | & "pickle.dump(field.val[:], f);" // & | ||
418 | 361 | & "f.close();") | ||
419 | 362 | call python_reset() | ||
420 | 363 | endif | ||
421 | 364 | |||
422 | 365 | end if | ||
423 | 366 | end do | ||
424 | 367 | #endif | ||
425 | 368 | end subroutine adjoint_write_controls | ||
426 | 369 | |||
427 | 370 | ! The counterpart of adjoint_write_controls: Loop through all controls in the option file and fill the fields from the control files. | ||
428 | 371 | subroutine adjoint_load_controls(timestep, dt, states) | ||
429 | 372 | integer, intent(in) :: timestep | ||
430 | 373 | real, intent(in) :: dt | ||
431 | 374 | type(state_type), dimension(:), intent(in) :: states | ||
432 | 375 | #ifdef HAVE_ADJOINT | ||
433 | 376 | integer :: nb_controls, i, state_id, s_idx | ||
434 | 377 | logical :: active, file_exists | ||
435 | 378 | character(len=OPTION_PATH_LEN) :: field_name, field_type, control_name, simulation_name, control_type | ||
436 | 379 | |||
437 | 380 | ! Do not read anything if we are supposed to write the controls | ||
438 | 381 | if (.not. have_option("/adjoint/controls/load_controls")) then | ||
439 | 382 | return | ||
440 | 383 | end if | ||
441 | 384 | |||
442 | 385 | call get_option("/simulation_name", simulation_name) | ||
443 | 386 | nb_controls = option_count("/adjoint/controls/control") | ||
444 | 387 | |||
445 | 388 | ! Now loop over the controls, read their controls files and fill the associated fields | ||
446 | 389 | do i = 0, nb_controls-1 | ||
447 | 390 | call get_control_details(states, timestep, i, control_name, state_id, field_name, field_type, active) | ||
448 | 391 | call get_option("/adjoint/controls/control[" // int2str(i) // "]/type/name", control_type) | ||
449 | 392 | |||
450 | 393 | ! We load all OTHER controls, then apply our strong boundary conditions, then load BC controls | ||
451 | 394 | if (trim(control_type) == "boundary_condition") cycle | ||
452 | 395 | |||
453 | 396 | if (active) then | ||
454 | 397 | ! Check that the control parameter file extists | ||
455 | 398 | inquire(file="control_" // trim(simulation_name) // "_" // trim(control_name) // "_" // int2str(timestep) // ".pkl", exist=file_exists) | ||
456 | 399 | if (.not. file_exists) then | ||
457 | 400 | ewrite (0, *) "File 'control_" // trim(simulation_name) // "_" // trim(control_name) // & | ||
458 | 401 | & "_" // int2str(timestep) // ".pkl' does not exist." | ||
459 | 402 | FLExit("Error while loading control files. You might want to remove '/adjoint/controls/load_controls'?") | ||
460 | 403 | end if | ||
461 | 404 | ! Read the control parameter from disk | ||
462 | 405 | call python_reset() | ||
463 | 406 | call python_add_state(states(state_id)) | ||
464 | 407 | call python_run_string("import pickle;" // & | ||
465 | 408 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_name) // "_" // int2str(timestep) // ".pkl';" // & | ||
466 | 409 | & "f = open(fname, 'rb');" // & | ||
467 | 410 | & "field = state." // trim(field_type) // "_fields['" // trim(field_name) // "'];" // & | ||
468 | 411 | & "field.val[:] = pickle.load(f);" // & | ||
469 | 412 | & "f.close();") | ||
470 | 413 | call python_reset() | ||
471 | 414 | end if | ||
472 | 415 | end do | ||
473 | 416 | |||
474 | 417 | ! Now apply the BCs, because the BCs should overwrite (say) an initial_condition control | ||
475 | 418 | call set_dirichlet_consistent(states) | ||
476 | 419 | |||
477 | 420 | do i = 0, nb_controls-1 | ||
478 | 421 | call get_control_details(states, timestep, i, control_name, state_id, field_name, field_type, active) | ||
479 | 422 | call get_option("/adjoint/controls/control[" // int2str(i) // "]/type/name", control_type) | ||
480 | 423 | |||
481 | 424 | ! We load all OTHER controls, then apply our strong boundary conditions, then load BC controls | ||
482 | 425 | if (trim(control_type) /= "boundary_condition") cycle | ||
483 | 426 | |||
484 | 427 | if (active) then | ||
485 | 428 | ! Check that the control parameter file extists | ||
486 | 429 | inquire(file="control_" // trim(simulation_name) // "_" // trim(control_name) // "_" // int2str(timestep) // ".pkl", exist=file_exists) | ||
487 | 430 | if (.not. file_exists) then | ||
488 | 431 | ewrite (0, *) "File 'control_" // trim(simulation_name) // "_" // trim(control_name) // & | ||
489 | 432 | & "_" // int2str(timestep) // ".pkl' does not exist." | ||
490 | 433 | FLExit("Error while loading control files. You might want to remove '/adjoint/controls/load_controls'?") | ||
491 | 434 | end if | ||
492 | 435 | ! Read the control parameter from disk | ||
493 | 436 | call python_reset() | ||
494 | 437 | call python_add_state(states(state_id)) | ||
495 | 438 | call python_run_string("import pickle;" // & | ||
496 | 439 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_name) // "_" // int2str(timestep) // ".pkl';" // & | ||
497 | 440 | & "f = open(fname, 'rb');" // & | ||
498 | 441 | & "field = state." // trim(field_type) // "_fields['" // trim(field_name) // "'];" // & | ||
499 | 442 | & "field.val[:] = pickle.load(f);" // & | ||
500 | 443 | & "f.close();") | ||
501 | 444 | call python_reset() | ||
502 | 445 | end if | ||
503 | 446 | end do | ||
504 | 447 | #endif | ||
505 | 448 | end subroutine adjoint_load_controls | ||
506 | 449 | |||
507 | 450 | ! Extracts the total derivatives of the functional and saves them to disk. | ||
508 | 451 | subroutine adjoint_write_control_derivatives(states, timestep, functional_name) | ||
509 | 452 | type(state_type), dimension(:), intent(inout) :: states | ||
510 | 453 | integer, intent(in) :: timestep | ||
511 | 454 | character(len=*), intent(in) :: functional_name | ||
512 | 455 | character(len=OPTION_PATH_LEN) :: field_name, control_type, control_deriv_name, field_deriv_name, name, material_phase_name, simulation_name, field_type | ||
513 | 456 | integer :: nb_controls | ||
514 | 457 | integer :: i, state_id, s_idx | ||
515 | 458 | type(scalar_field), pointer :: sfield => null() | ||
516 | 459 | type(vector_field), pointer :: vfield => null() | ||
517 | 460 | type(tensor_field), pointer :: tfield => null() | ||
518 | 461 | |||
519 | 462 | if (.not. have_option("/adjoint/controls")) then | ||
520 | 463 | return | ||
521 | 464 | end if | ||
522 | 465 | call get_option("/simulation_name", simulation_name) | ||
523 | 466 | ! Remove the suffix _adjoint from the simulation_name | ||
524 | 467 | |||
525 | 468 | nb_controls = option_count("/adjoint/controls/control") | ||
526 | 469 | do i = 0, nb_controls-1 | ||
527 | 470 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/name", control_deriv_name) | ||
528 | 471 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type/name", control_type) | ||
529 | 472 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type::" // trim(control_type) // "/field_name", name) | ||
530 | 473 | s_idx = scan(trim(name), "::") | ||
531 | 474 | if (s_idx == 0) then | ||
532 | 475 | FLExit("The control " // trim(control_deriv_name) // " uses an invalid field_name. It should be of the form Materialphase::Fieldname") | ||
533 | 476 | end if | ||
534 | 477 | material_phase_name = name(1:s_idx - 1) | ||
535 | 478 | field_name = name(s_idx + 2:len_trim(name)) | ||
536 | 479 | ! Find state associated with the material phase | ||
537 | 480 | do state_id = 1, size(states) | ||
538 | 481 | if (trim(states(state_id)%name) == trim(material_phase_name)) then | ||
539 | 482 | exit | ||
540 | 483 | end if | ||
541 | 484 | end do | ||
542 | 485 | ! Make sure we found the state | ||
543 | 486 | if (.not. trim(states(state_id)%name) == trim(material_phase_name)) then | ||
544 | 487 | FLExit("Could not find state " // trim(material_phase_name) // " as specified in control " // trim(control_deriv_name) // ".") | ||
545 | 488 | end if | ||
546 | 489 | |||
547 | 490 | field_name = "Adjoint" // trim(field_name) | ||
548 | 491 | control_deriv_name = trim(control_deriv_name) // "_TotalDerivative" | ||
549 | 492 | if (trim(control_type) == "initial_condition" .or. trim(control_type) == "source_term") then | ||
550 | 493 | |||
551 | 494 | if (trim(control_type) == "initial_condition" .and. timestep > 0) then | ||
552 | 495 | cycle | ||
553 | 496 | end if | ||
554 | 497 | |||
555 | 498 | if (trim(control_type) == "source_term" .and. timestep == 0) then | ||
556 | 499 | cycle | ||
557 | 500 | end if | ||
558 | 501 | |||
559 | 502 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
560 | 503 | if (has_scalar_field(states(state_id), field_name)) then | ||
561 | 504 | field_type = "scalar" | ||
562 | 505 | elseif (has_vector_field(states(state_id), field_name)) then | ||
563 | 506 | field_type = "vector" | ||
564 | 507 | elseif (has_tensor_field(states(state_id), field_name)) then | ||
565 | 508 | field_type = "tensor" | ||
566 | 509 | else | ||
567 | 510 | ewrite(0, *) "The control field " // trim(field_deriv_name) // " specified in control " // trim(control_deriv_name) // " is not a field in the state." | ||
568 | 511 | ewrite(0, *) "The current state is: " | ||
569 | 512 | call print_state(states(state_id)) | ||
570 | 513 | FLExit("Check your control's field settings.") | ||
571 | 514 | end if | ||
572 | 515 | elseif (trim(control_type) == "boundary_condition") then | ||
573 | 516 | FLAbort("Boundary condition control not implemented yet.") | ||
574 | 517 | end if | ||
575 | 518 | ! Save the control parameter to disk | ||
576 | 519 | call python_reset() | ||
577 | 520 | call python_add_state(states(state_id)) | ||
578 | 521 | call python_run_string("import pickle;" // & | ||
579 | 522 | & "fname = 'control_" // trim(simulation_name) // "_" // trim(control_deriv_name) // "_" // int2str(timestep) // ".pkl';" // & | ||
580 | 523 | & "f = open(fname, 'wb');" // & | ||
581 | 524 | & "field = state." // trim(field_type) // "_fields['" // trim(field_deriv_name) // "'];" // & | ||
582 | 525 | & "pickle.dump(field.val[:], f);" // & | ||
583 | 526 | & "f.close();") | ||
584 | 527 | call python_reset() | ||
585 | 528 | end do | ||
586 | 529 | end subroutine adjoint_write_control_derivatives | ||
587 | 530 | |||
588 | 531 | subroutine allocate_and_insert_control_derivative_fields(states) | ||
589 | 532 | type(state_type), dimension(:), intent(inout) :: states | ||
590 | 533 | integer :: nb_controls, nb_functionals, i, state_id, functional, s_idx | ||
591 | 534 | character(len=OPTION_PATH_LEN) :: field_name, control_type, control_deriv_name, functional_name, field_deriv_name, material_phase_name, name | ||
592 | 535 | type(scalar_field), pointer :: sfield => null() | ||
593 | 536 | type(vector_field), pointer :: vfield => null() | ||
594 | 537 | type(tensor_field), pointer :: tfield => null() | ||
595 | 538 | type(scalar_field) :: sfield_deriv | ||
596 | 539 | type(vector_field) :: vfield_deriv | ||
597 | 540 | type(tensor_field) :: tfield_deriv | ||
598 | 541 | |||
599 | 542 | nb_controls = option_count("/adjoint/controls/control") | ||
600 | 543 | nb_functionals = option_count("/adjoint/functional") | ||
601 | 544 | ! Loop over the functionals | ||
602 | 545 | do functional = 0, nb_functionals-1 | ||
603 | 546 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
604 | 547 | ! Now loop over the controls | ||
605 | 548 | do i = 0, nb_controls-1 | ||
606 | 549 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/name", control_deriv_name) | ||
607 | 550 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type/name", control_type) | ||
608 | 551 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type::" // trim(control_type) // "/field_name", name) | ||
609 | 552 | s_idx = scan(trim(name), "::") | ||
610 | 553 | if (s_idx == 0) then | ||
611 | 554 | FLExit("The control " // trim(control_deriv_name) // " uses an invalid field_name. It should be of the form Materialphase::Fieldname") | ||
612 | 555 | end if | ||
613 | 556 | material_phase_name = name(1:s_idx - 1) | ||
614 | 557 | field_name = name(s_idx + 2:len_trim(name)) | ||
615 | 558 | ! Find state associated with the material phase | ||
616 | 559 | do state_id = 1, size(states) | ||
617 | 560 | if (trim(states(state_id)%name) == trim(material_phase_name)) then | ||
618 | 561 | exit | ||
619 | 562 | end if | ||
620 | 563 | end do | ||
621 | 564 | ! Make sure we found the state | ||
622 | 565 | if (.not. trim(states(state_id)%name) == trim(material_phase_name)) then | ||
623 | 566 | FLExit("Could not find state " // trim(material_phase_name) // " as specified in control " // trim(control_deriv_name) // ".") | ||
624 | 567 | end if | ||
625 | 568 | |||
626 | 569 | field_name = "Adjoint" // trim(field_name) | ||
627 | 570 | control_deriv_name = trim(control_deriv_name) // "_TotalDerivative" | ||
628 | 571 | |||
629 | 572 | if (trim(control_type) == "initial_condition" .or. trim(control_type) == "source_term") then | ||
630 | 573 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
631 | 574 | |||
632 | 575 | if (has_scalar_field(states(state_id), field_name)) then | ||
633 | 576 | sfield => extract_scalar_field(states(state_id), field_name) | ||
634 | 577 | call allocate(sfield_deriv, sfield%mesh, field_deriv_name) | ||
635 | 578 | call zero(sfield_deriv) | ||
636 | 579 | call insert(states(state_id), sfield_deriv, field_deriv_name) | ||
637 | 580 | call deallocate(sfield_deriv) | ||
638 | 581 | |||
639 | 582 | elseif (has_vector_field(states(state_id), field_name)) then | ||
640 | 583 | vfield => extract_vector_field(states(state_id), field_name) | ||
641 | 584 | call allocate(vfield_deriv, vfield%dim, vfield%mesh, field_deriv_name) | ||
642 | 585 | call zero(vfield_deriv) | ||
643 | 586 | call insert(states(state_id), vfield_deriv, field_deriv_name) | ||
644 | 587 | call deallocate(vfield_deriv) | ||
645 | 588 | |||
646 | 589 | elseif (has_tensor_field(states(state_id), field_name)) then | ||
647 | 590 | tfield => extract_tensor_field(states(state_id), field_name) | ||
648 | 591 | call allocate(tfield_deriv, tfield%mesh, field_deriv_name, tfield%field_type, tfield%dim) | ||
649 | 592 | call zero(tfield_deriv) | ||
650 | 593 | call insert(states(state_id), tfield_deriv, field_deriv_name) | ||
651 | 594 | call deallocate(tfield_deriv) | ||
652 | 595 | |||
653 | 596 | else | ||
654 | 597 | ewrite(0, *) "The control field " // trim(field_name) // " specified in control " // trim(control_deriv_name) // " is not a field in the state." | ||
655 | 598 | ewrite(0, *) "The current state is: " | ||
656 | 599 | call print_state(states(state_id)) | ||
657 | 600 | FLExit("Check your control's field settings.") | ||
658 | 601 | end if | ||
659 | 602 | |||
660 | 603 | elseif (trim(control_type) == "boundary_condition") then | ||
661 | 604 | FLAbort("Boundary condition control not implemented yet.") | ||
662 | 605 | end if | ||
663 | 606 | |||
664 | 607 | end do | ||
665 | 608 | end do | ||
666 | 609 | end subroutine allocate_and_insert_control_derivative_fields | ||
667 | 610 | |||
668 | 611 | end module adjoint_controls | ||
669 | 0 | 612 | ||
670 | === modified file 'adjoint/Adjoint_Functional_Evaluation.F90' | |||
671 | --- adjoint/Adjoint_Functional_Evaluation.F90 2011-05-20 17:42:50 +0000 | |||
672 | +++ adjoint/Adjoint_Functional_Evaluation.F90 2011-07-12 15:56:32 +0000 | |||
673 | @@ -48,7 +48,7 @@ | |||
674 | 48 | implicit none | 48 | implicit none |
675 | 49 | 49 | ||
676 | 50 | private | 50 | private |
678 | 51 | public :: libadjoint_functional_derivative, adj_record_anything_necessary | 51 | public :: libadjoint_evaluate_functional, libadjoint_functional_derivative, adj_record_anything_necessary |
679 | 52 | 52 | ||
680 | 53 | contains | 53 | contains |
681 | 54 | 54 | ||
682 | @@ -250,32 +250,6 @@ | |||
683 | 250 | end if | 250 | end if |
684 | 251 | 251 | ||
685 | 252 | if (has_func) then | 252 | if (has_func) then |
686 | 253 | if (.not. functional_computed) then | ||
687 | 254 | ierr = adj_timestep_get_times(adjointer, timelevel, start_time, end_time) | ||
688 | 255 | call adj_chkierr(ierr) | ||
689 | 256 | assert(start_time < end_time) | ||
690 | 257 | |||
691 | 258 | write(buffer,*) timelevel + 1 | ||
692 | 259 | call python_run_string("n = " // trim(buffer)) | ||
693 | 260 | |||
694 | 261 | write(buffer,*) start_time | ||
695 | 262 | call python_run_string("time = " // trim(buffer)) | ||
696 | 263 | |||
697 | 264 | write(buffer, *) abs(start_time - end_time) | ||
698 | 265 | call python_run_string("dt = " // trim(buffer)) | ||
699 | 266 | |||
700 | 267 | call python_run_string(trim(code_func)) | ||
701 | 268 | J = python_fetch_real("J") | ||
702 | 269 | |||
703 | 270 | ! So we've computed the component of the functional associated with this timestep. | ||
704 | 271 | ! We also want to sum them all up ... | ||
705 | 272 | |||
706 | 273 | call set_diagnostic(name=trim(functional_name_f) // "_component", statistic="value", value=(/J/)) | ||
707 | 274 | fn_value => get_diagnostic(name=trim(functional_name_f), statistic="value") | ||
708 | 275 | J = J + fn_value(1) | ||
709 | 276 | call set_diagnostic(name=trim(functional_name_f), statistic="value", value=(/J/)) | ||
710 | 277 | functional_computed = .true. | ||
711 | 278 | end if | ||
712 | 279 | 253 | ||
713 | 280 | if (.not. has_deriv) then | 254 | if (.not. has_deriv) then |
714 | 281 | check_uncertainties = "try: " // achar(10) // & | 255 | check_uncertainties = "try: " // achar(10) // & |
715 | @@ -341,6 +315,111 @@ | |||
716 | 341 | 315 | ||
717 | 342 | end subroutine libadjoint_functional_derivative | 316 | end subroutine libadjoint_functional_derivative |
718 | 343 | 317 | ||
719 | 318 | subroutine libadjoint_evaluate_functional(adjointer, timelevel, ndepends, dependencies, values, functional_name_c, output) bind(c) | ||
720 | 319 | use iso_c_binding | ||
721 | 320 | use libadjoint_data_structures | ||
722 | 321 | type(adj_adjointer), intent(in) :: adjointer | ||
723 | 322 | integer(kind=c_int), intent(in), value :: timelevel | ||
724 | 323 | integer(kind=c_int), intent(in), value :: ndepends | ||
725 | 324 | type(adj_variable), dimension(ndepends), intent(in) :: dependencies | ||
726 | 325 | type(adj_vector), dimension(ndepends), intent(in) :: values | ||
727 | 326 | character(kind=c_char), dimension(ADJ_NAME_LEN), intent(in) :: functional_name_c | ||
728 | 327 | adj_scalar_f, intent(out) :: output | ||
729 | 328 | |||
730 | 329 | type(state_type), dimension(:,:), pointer :: states ! material_phases x timelevels | ||
731 | 330 | character(len=ADJ_NAME_LEN) :: functional_name_f | ||
732 | 331 | logical :: has_func | ||
733 | 332 | character(len=PYTHON_FUNC_LEN) :: code_func | ||
734 | 333 | integer :: ierr, max_timelevel, tmp_timelevel, min_timelevel, nmaterial_phases | ||
735 | 334 | character(len=OPTION_PATH_LEN) :: material_phase_name | ||
736 | 335 | integer :: no_timesteps, timestep, i | ||
737 | 336 | real :: start_time, end_time | ||
738 | 337 | character(len = 30) :: buffer, buffer2 | ||
739 | 338 | |||
740 | 339 | call python_reset | ||
741 | 340 | |||
742 | 341 | functional_name_f = ' ' | ||
743 | 342 | i = 1 | ||
744 | 343 | do while (i <= ADJ_NAME_LEN .and. functional_name_c(i) /= c_null_char) | ||
745 | 344 | functional_name_f(i:i) = functional_name_c(i) | ||
746 | 345 | i = i + 1 | ||
747 | 346 | end do | ||
748 | 347 | |||
749 | 348 | ! Fetch the python code the user has helpfully supplied. | ||
750 | 349 | has_func = have_option("/adjoint/functional::" // trim(functional_name_f) // "/functional_value/algorithm") | ||
751 | 350 | if (.not. has_func) then | ||
752 | 351 | FLAbort("You need to supply code for the functional to evaluate it!") | ||
753 | 352 | endif | ||
754 | 353 | |||
755 | 354 | if (has_func) then | ||
756 | 355 | call get_option("/adjoint/functional::" // trim(functional_name_f) // "/functional_value/algorithm", code_func) | ||
757 | 356 | endif | ||
758 | 357 | |||
759 | 358 | if (ndepends==0) then | ||
760 | 359 | max_timelevel = 0 | ||
761 | 360 | min_timelevel = 0 | ||
762 | 361 | else | ||
763 | 362 | ! Convert from the list of adj_values/adj_vectors to actual states | ||
764 | 363 | ierr = adj_variable_get_timestep(dependencies(1), max_timelevel) | ||
765 | 364 | min_timelevel = max_timelevel | ||
766 | 365 | do i=1,ndepends | ||
767 | 366 | ierr = adj_variable_get_timestep(dependencies(i), tmp_timelevel) | ||
768 | 367 | max_timelevel = max(max_timelevel, tmp_timelevel) | ||
769 | 368 | min_timelevel = min(min_timelevel, tmp_timelevel) | ||
770 | 369 | end do | ||
771 | 370 | end if | ||
772 | 371 | |||
773 | 372 | nmaterial_phases = option_count("/material_phase") | ||
774 | 373 | allocate(states(nmaterial_phases, min_timelevel:max_timelevel)) | ||
775 | 374 | |||
776 | 375 | ! Set the names of the material phases, so that we can look them up and know | ||
777 | 376 | ! which material_phase to put stuff into in convert_adj_vectors_to_states | ||
778 | 377 | do i=0,nmaterial_phases-1 | ||
779 | 378 | call get_option("/material_phase[" // int2str(i) // "]/name", material_phase_name) | ||
780 | 379 | states(i+1,:)%name = trim(material_phase_name) | ||
781 | 380 | end do | ||
782 | 381 | call convert_adj_vectors_to_states(dependencies, values, states) | ||
783 | 382 | call python_add_states_time(states) | ||
784 | 383 | |||
785 | 384 | ! Also set up some useful variables for the user to use | ||
786 | 385 | ierr = adj_timestep_count(adjointer, no_timesteps) | ||
787 | 386 | call adj_chkierr(ierr) | ||
788 | 387 | write(buffer, *) no_timesteps | ||
789 | 388 | call python_run_string("times = [0] * " // trim(buffer)) | ||
790 | 389 | do timestep=0,no_timesteps-2 | ||
791 | 390 | ierr = adj_timestep_get_times(adjointer, timestep, start_time, end_time) | ||
792 | 391 | call adj_chkierr(ierr) | ||
793 | 392 | write(buffer, '(i0)') timestep | ||
794 | 393 | write(buffer2, *) start_time | ||
795 | 394 | call python_run_string("times[" // trim(buffer) // "] = " // trim(buffer2)) | ||
796 | 395 | write(buffer, '(i0)') timestep+1 | ||
797 | 396 | write(buffer2, *) end_time | ||
798 | 397 | call python_run_string("times[" // trim(buffer) // "] = " // trim(buffer2)) | ||
799 | 398 | end do | ||
800 | 399 | |||
801 | 400 | ierr = adj_timestep_get_times(adjointer, timelevel, start_time, end_time) | ||
802 | 401 | call adj_chkierr(ierr) | ||
803 | 402 | assert(start_time < end_time) | ||
804 | 403 | |||
805 | 404 | write(buffer,*) timelevel + 1 | ||
806 | 405 | call python_run_string("n = " // trim(buffer)) | ||
807 | 406 | |||
808 | 407 | write(buffer,*) start_time | ||
809 | 408 | call python_run_string("time = " // trim(buffer)) | ||
810 | 409 | |||
811 | 410 | write(buffer, *) abs(start_time - end_time) | ||
812 | 411 | call python_run_string("dt = " // trim(buffer)) | ||
813 | 412 | |||
814 | 413 | call python_run_string(trim(code_func)) | ||
815 | 414 | output = python_fetch_real("J") | ||
816 | 415 | |||
817 | 416 | if (max_timelevel >= 0) then | ||
818 | 417 | call deallocate(states) | ||
819 | 418 | deallocate(states) | ||
820 | 419 | endif | ||
821 | 420 | |||
822 | 421 | end subroutine libadjoint_evaluate_functional | ||
823 | 422 | |||
824 | 344 | subroutine convert_adj_vectors_to_states(dependencies, values, states) | 423 | subroutine convert_adj_vectors_to_states(dependencies, values, states) |
825 | 345 | type(adj_variable), dimension(:), intent(in) :: dependencies | 424 | type(adj_variable), dimension(:), intent(in) :: dependencies |
826 | 346 | type(adj_vector), dimension(:), intent(in) :: values | 425 | type(adj_vector), dimension(:), intent(in) :: values |
827 | @@ -432,7 +511,7 @@ | |||
828 | 432 | call get_option("/timestepping/finish_time", finish_time) | 511 | call get_option("/timestepping/finish_time", finish_time) |
829 | 433 | 512 | ||
830 | 434 | call get_option("/adjoint/functional::" // trim(functional) // "/functional_dependencies/algorithm", buf) | 513 | call get_option("/adjoint/functional::" // trim(functional) // "/functional_dependencies/algorithm", buf) |
832 | 435 | call adj_variables_from_python(buf, current_time, finish_time, python_timestep, vars) | 514 | call adj_variables_from_python(adjointer, buf, current_time, finish_time, python_timestep, vars) |
833 | 436 | 515 | ||
834 | 437 | variable_loop: do j=1,size(vars) | 516 | variable_loop: do j=1,size(vars) |
835 | 438 | ierr = adj_variable_get_timestep(vars(j), var_timestep) | 517 | ierr = adj_variable_get_timestep(vars(j), var_timestep) |
836 | @@ -522,5 +601,6 @@ | |||
837 | 522 | 601 | ||
838 | 523 | deallocate(vars) | 602 | deallocate(vars) |
839 | 524 | end subroutine adj_record_anything_necessary | 603 | end subroutine adj_record_anything_necessary |
840 | 604 | |||
841 | 525 | #endif | 605 | #endif |
842 | 526 | end module adjoint_functional_evaluation | 606 | end module adjoint_functional_evaluation |
843 | 527 | 607 | ||
844 | === modified file 'adjoint/Adjoint_Global_Variables.F90' | |||
845 | --- adjoint/Adjoint_Global_Variables.F90 2011-04-01 17:40:34 +0000 | |||
846 | +++ adjoint/Adjoint_Global_Variables.F90 2011-07-12 15:56:32 +0000 | |||
847 | @@ -35,6 +35,5 @@ | |||
848 | 35 | 35 | ||
849 | 36 | type(adj_dictionary) :: adj_path_lookup, adj_solver_path_lookup | 36 | type(adj_dictionary) :: adj_path_lookup, adj_solver_path_lookup |
850 | 37 | type(adj_adjointer) :: adjointer | 37 | type(adj_adjointer) :: adjointer |
851 | 38 | logical :: functional_computed = .false. | ||
852 | 39 | #endif | 38 | #endif |
853 | 40 | end module adjoint_global_variables | 39 | end module adjoint_global_variables |
854 | 41 | 40 | ||
855 | === modified file 'adjoint/Adjoint_Main_Loop.F90' | |||
856 | --- adjoint/Adjoint_Main_Loop.F90 2011-05-11 17:15:33 +0000 | |||
857 | +++ adjoint/Adjoint_Main_Loop.F90 2011-07-12 15:56:32 +0000 | |||
858 | @@ -39,6 +39,7 @@ | |||
859 | 39 | use global_parameters, only: OPTION_PATH_LEN, running_adjoint | 39 | use global_parameters, only: OPTION_PATH_LEN, running_adjoint |
860 | 40 | use adjoint_global_variables | 40 | use adjoint_global_variables |
861 | 41 | use adjoint_functional_evaluation | 41 | use adjoint_functional_evaluation |
862 | 42 | use adjoint_controls | ||
863 | 42 | use populate_state_module | 43 | use populate_state_module |
864 | 43 | use signal_vars | 44 | use signal_vars |
865 | 44 | use mangle_options_tree | 45 | use mangle_options_tree |
866 | @@ -53,7 +54,6 @@ | |||
867 | 53 | implicit none | 54 | implicit none |
868 | 54 | 55 | ||
869 | 55 | private | 56 | private |
870 | 56 | public :: adjoint_main_loop_register_diagnostic | ||
871 | 57 | #ifdef HAVE_ADJOINT | 57 | #ifdef HAVE_ADJOINT |
872 | 58 | public :: compute_adjoint | 58 | public :: compute_adjoint |
873 | 59 | #endif | 59 | #endif |
874 | @@ -61,9 +61,28 @@ | |||
875 | 61 | contains | 61 | contains |
876 | 62 | 62 | ||
877 | 63 | #ifdef HAVE_ADJOINT | 63 | #ifdef HAVE_ADJOINT |
879 | 64 | subroutine compute_adjoint(state, dump_no) | 64 | ! Computes the adjoint equation |
880 | 65 | ! The optional adjoint timestep callback is called for each functional after every timestep in the adjoint loop. | ||
881 | 66 | ! It is commonly used to compute the diangostics from the adjoint solution, e.g. the total derivative of the functional. | ||
882 | 67 | subroutine compute_adjoint(state, dump_no, adjoint_timestep_callback, adjoint_timestep_callback_data) | ||
883 | 68 | use iso_c_binding, only: c_ptr | ||
884 | 65 | type(state_type), dimension(:), intent(inout) :: state | 69 | type(state_type), dimension(:), intent(inout) :: state |
885 | 66 | integer, intent(inout) :: dump_no | 70 | integer, intent(inout) :: dump_no |
886 | 71 | optional :: adjoint_timestep_callback | ||
887 | 72 | ! Data is a void pointer used to pass variables into the callback | ||
888 | 73 | type(c_ptr), intent(in), optional :: adjoint_timestep_callback_data | ||
889 | 74 | interface | ||
890 | 75 | subroutine adjoint_timestep_callback(state, timestep, functional_name, data) | ||
891 | 76 | use iso_c_binding, only: c_ptr | ||
892 | 77 | use global_parameters, only: OPTION_PATH_LEN | ||
893 | 78 | use state_module | ||
894 | 79 | type(state_type), dimension(:), intent(inout) :: state | ||
895 | 80 | integer, intent(in) :: timestep | ||
896 | 81 | character(len=OPTION_PATH_LEN), intent(in) :: functional_name | ||
897 | 82 | ! Data is a void pointer used to pass variables into the callback | ||
898 | 83 | type(c_ptr), intent(in) :: data | ||
899 | 84 | end subroutine adjoint_timestep_callback | ||
900 | 85 | end interface | ||
901 | 67 | 86 | ||
902 | 68 | type(adj_vector) :: rhs | 87 | type(adj_vector) :: rhs |
903 | 69 | type(adj_vector) :: soln | 88 | type(adj_vector) :: soln |
904 | @@ -80,10 +99,12 @@ | |||
905 | 80 | integer :: end_timestep, start_timestep, no_timesteps, timestep | 99 | integer :: end_timestep, start_timestep, no_timesteps, timestep |
906 | 81 | real :: start_time, end_time | 100 | real :: start_time, end_time |
907 | 82 | 101 | ||
909 | 83 | character(len=OPTION_PATH_LEN) :: simulation_base_name, functional_name | 102 | character(len=OPTION_PATH_LEN) :: simulation_base_name |
910 | 84 | type(stat_type), dimension(:), allocatable :: functional_stats | 103 | type(stat_type), dimension(:), allocatable :: functional_stats |
911 | 104 | real :: J | ||
912 | 105 | real, dimension(:), pointer :: fn_value | ||
913 | 85 | 106 | ||
915 | 86 | character(len=ADJ_NAME_LEN) :: variable_name, field_name, material_phase_name | 107 | character(len=ADJ_NAME_LEN) :: variable_name, field_name, material_phase_name, functional_name |
916 | 87 | type(scalar_field) :: sfield_soln, sfield_rhs | 108 | type(scalar_field) :: sfield_soln, sfield_rhs |
917 | 88 | type(vector_field) :: vfield_soln, vfield_rhs | 109 | type(vector_field) :: vfield_soln, vfield_rhs |
918 | 89 | type(csr_matrix) :: csr_mat | 110 | type(csr_matrix) :: csr_mat |
919 | @@ -112,17 +133,29 @@ | |||
920 | 112 | allocate(functional_stats(no_functionals)) | 133 | allocate(functional_stats(no_functionals)) |
921 | 113 | 134 | ||
922 | 114 | do functional=0,no_functionals-1 | 135 | do functional=0,no_functionals-1 |
923 | 136 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
924 | 137 | if (have_option("/adjoint/functional::" // trim(functional_name) // "/disable_adjoint_run")) then | ||
925 | 138 | cycle | ||
926 | 139 | end if | ||
927 | 115 | default_stat = functional_stats(functional + 1) | 140 | default_stat = functional_stats(functional + 1) |
928 | 116 | call initialise_walltime | 141 | call initialise_walltime |
929 | 117 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
930 | 118 | call initialise_diagnostics(trim(simulation_base_name) // '_' // trim(functional_name), state) | 142 | call initialise_diagnostics(trim(simulation_base_name) // '_' // trim(functional_name), state) |
931 | 119 | functional_stats(functional + 1) = default_stat | 143 | functional_stats(functional + 1) = default_stat |
933 | 120 | 144 | ||
934 | 145 | ! Register the callback to compute J | ||
935 | 146 | ierr = adj_register_functional_callback(adjointer, trim(functional_name), c_funloc(libadjoint_evaluate_functional)) | ||
936 | 147 | call adj_chkierr(ierr) | ||
937 | 148 | |||
938 | 121 | ! Register the callback to compute delJ/delu | 149 | ! Register the callback to compute delJ/delu |
939 | 122 | ierr = adj_register_functional_derivative_callback(adjointer, trim(functional_name), c_funloc(libadjoint_functional_derivative)) | 150 | ierr = adj_register_functional_derivative_callback(adjointer, trim(functional_name), c_funloc(libadjoint_functional_derivative)) |
940 | 123 | call adj_chkierr(ierr) | 151 | call adj_chkierr(ierr) |
941 | 124 | end do | 152 | end do |
942 | 125 | 153 | ||
943 | 154 | ! Insert the fields for storing the derivatives of the functionals with respect to the controls into the state | ||
944 | 155 | if (have_option("/adjoint/controls")) then | ||
945 | 156 | call allocate_and_insert_control_derivative_fields(state) | ||
946 | 157 | end if | ||
947 | 158 | |||
948 | 126 | ierr = adj_timestep_count(adjointer, no_timesteps) | 159 | ierr = adj_timestep_count(adjointer, no_timesteps) |
949 | 127 | call adj_chkierr(ierr) | 160 | call adj_chkierr(ierr) |
950 | 128 | 161 | ||
951 | @@ -145,18 +178,6 @@ | |||
952 | 145 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | 178 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) |
953 | 146 | call set_option("/simulation_name", trim(simulation_base_name) // "_" // trim(functional_name)) | 179 | call set_option("/simulation_name", trim(simulation_base_name) // "_" // trim(functional_name)) |
954 | 147 | default_stat = functional_stats(functional + 1) | 180 | default_stat = functional_stats(functional + 1) |
955 | 148 | ! We don't want to compute a functional for the dummy timestep added at the end to act | ||
956 | 149 | ! as a container for the last equation | ||
957 | 150 | if (start_time == end_time) then | ||
958 | 151 | assert(timestep == no_timesteps-1) | ||
959 | 152 | if (have_option("/adjoint/functional[" // int2str(functional) // "]/functional_value")) then | ||
960 | 153 | call set_diagnostic(name=trim(functional_name), statistic="value", value=(/0.0/)) | ||
961 | 154 | call set_diagnostic(name=trim(functional_name) // "_component", statistic="value", value=(/0.0/)) | ||
962 | 155 | end if | ||
963 | 156 | functional_computed = .true. | ||
964 | 157 | else | ||
965 | 158 | functional_computed = .false. | ||
966 | 159 | end if | ||
967 | 160 | 181 | ||
968 | 161 | do equation=end_timestep,start_timestep,-1 | 182 | do equation=end_timestep,start_timestep,-1 |
969 | 162 | ierr = adj_get_adjoint_equation(adjointer, equation, trim(functional_name), lhs, rhs, adj_var) | 183 | ierr = adj_get_adjoint_equation(adjointer, equation, trim(functional_name), lhs, rhs, adj_var) |
970 | @@ -201,7 +222,7 @@ | |||
971 | 201 | end if | 222 | end if |
972 | 202 | 223 | ||
973 | 203 | call petsc_solve(sfield_soln, csr_mat, sfield_rhs, option_path=path) | 224 | call petsc_solve(sfield_soln, csr_mat, sfield_rhs, option_path=path) |
975 | 204 | !call compute_inactive_rows(sfield_soln, csr_mat, sfield_rhs) | 225 | call compute_inactive_rows(sfield_soln, csr_mat, sfield_rhs) |
976 | 205 | endif | 226 | endif |
977 | 206 | case(ADJ_BLOCK_CSR_MATRIX) | 227 | case(ADJ_BLOCK_CSR_MATRIX) |
978 | 207 | FLAbort("Cannot map between scalar fields with a block_csr_matrix .. ") | 228 | FLAbort("Cannot map between scalar fields with a block_csr_matrix .. ") |
979 | @@ -240,7 +261,7 @@ | |||
980 | 240 | end if | 261 | end if |
981 | 241 | 262 | ||
982 | 242 | call petsc_solve(vfield_soln, csr_mat, vfield_rhs, option_path=path) | 263 | call petsc_solve(vfield_soln, csr_mat, vfield_rhs, option_path=path) |
984 | 243 | call compute_inactive_rows(vfield_soln, csr_mat, vfield_rhs) | 264 | !call compute_inactive_rows(vfield_soln, csr_mat, vfield_rhs) |
985 | 244 | endif | 265 | endif |
986 | 245 | case(ADJ_BLOCK_CSR_MATRIX) | 266 | case(ADJ_BLOCK_CSR_MATRIX) |
987 | 246 | call matrix_from_adj_matrix(lhs, block_csr_mat) | 267 | call matrix_from_adj_matrix(lhs, block_csr_mat) |
988 | @@ -282,7 +303,16 @@ | |||
989 | 282 | call adjoint_cleanup | 303 | call adjoint_cleanup |
990 | 283 | return | 304 | return |
991 | 284 | end if | 305 | end if |
993 | 285 | end do | 306 | end do ! End of equation loop |
994 | 307 | |||
995 | 308 | ! Callback for the computation of the functional total derivatives | ||
996 | 309 | if (present(adjoint_timestep_callback)) then | ||
997 | 310 | call adjoint_timestep_callback(state, timestep, trim(functional_name), data=adjoint_timestep_callback_data) | ||
998 | 311 | end if | ||
999 | 312 | if (have_option("/adjoint/controls")) then | ||
1000 | 313 | ! Write the functional's total derivatives to file | ||
1001 | 314 | call adjoint_write_control_derivatives(state, timestep, trim(functional_name)) | ||
1002 | 315 | end if | ||
1003 | 286 | 316 | ||
1004 | 287 | call calculate_diagnostic_variables(state, exclude_nonrecalculated = .true.) | 317 | call calculate_diagnostic_variables(state, exclude_nonrecalculated = .true.) |
1005 | 288 | call calculate_diagnostic_variables_new(state, exclude_nonrecalculated = .true.) | 318 | call calculate_diagnostic_variables_new(state, exclude_nonrecalculated = .true.) |
1006 | @@ -296,13 +326,13 @@ | |||
1007 | 296 | endif | 326 | endif |
1008 | 297 | 327 | ||
1009 | 298 | functional_stats(functional + 1) = default_stat | 328 | functional_stats(functional + 1) = default_stat |
1011 | 299 | end do | 329 | end do ! End of functional loop |
1012 | 300 | 330 | ||
1013 | 301 | ! Now forget | 331 | ! Now forget |
1014 | 302 | ierr = adj_forget_adjoint_equation(adjointer, start_timestep) | 332 | ierr = adj_forget_adjoint_equation(adjointer, start_timestep) |
1015 | 303 | call adj_chkierr(ierr) | 333 | call adj_chkierr(ierr) |
1016 | 304 | current_time = start_time | 334 | current_time = start_time |
1018 | 305 | end do | 335 | end do ! End of timestep loop |
1019 | 306 | 336 | ||
1020 | 307 | call get_option("/timestepping/finish_time", finish_time) | 337 | call get_option("/timestepping/finish_time", finish_time) |
1021 | 308 | assert(current_time == finish_time) | 338 | assert(current_time == finish_time) |
1022 | @@ -314,6 +344,10 @@ | |||
1023 | 314 | subroutine adjoint_cleanup | 344 | subroutine adjoint_cleanup |
1024 | 315 | ! Clean up stat files | 345 | ! Clean up stat files |
1025 | 316 | do functional=0,no_functionals-1 | 346 | do functional=0,no_functionals-1 |
1026 | 347 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
1027 | 348 | if (have_option("/adjoint/functional::" // trim(functional_name) // "/disable_adjoint_run")) then | ||
1028 | 349 | cycle | ||
1029 | 350 | end if | ||
1030 | 317 | default_stat = functional_stats(functional + 1) | 351 | default_stat = functional_stats(functional + 1) |
1031 | 318 | call close_diagnostic_files | 352 | call close_diagnostic_files |
1032 | 319 | call uninitialise_diagnostics | 353 | call uninitialise_diagnostics |
1033 | @@ -325,23 +359,7 @@ | |||
1034 | 325 | call adj_chkierr(ierr) | 359 | call adj_chkierr(ierr) |
1035 | 326 | end subroutine adjoint_cleanup | 360 | end subroutine adjoint_cleanup |
1036 | 327 | end subroutine compute_adjoint | 361 | end subroutine compute_adjoint |
1037 | 362 | |||
1038 | 328 | #endif | 363 | #endif |
1039 | 329 | 364 | ||
1040 | 330 | subroutine adjoint_main_loop_register_diagnostic | ||
1041 | 331 | integer :: functional, no_functionals | ||
1042 | 332 | character(len=OPTION_PATH_LEN) :: functional_name | ||
1043 | 333 | |||
1044 | 334 | no_functionals = option_count("/adjoint/functional") | ||
1045 | 335 | |||
1046 | 336 | do functional=0,no_functionals-1 | ||
1047 | 337 | ! Register a diagnostic for each functional | ||
1048 | 338 | if (have_option("/adjoint/functional[" // int2str(functional) // "]/functional_value")) then | ||
1049 | 339 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
1050 | 340 | call register_diagnostic(dim=1, name=trim(functional_name) // "_component", statistic="value") | ||
1051 | 341 | call register_diagnostic(dim=1, name=trim(functional_name), statistic="value") | ||
1052 | 342 | end if | ||
1053 | 343 | end do | ||
1054 | 344 | |||
1055 | 345 | end subroutine adjoint_main_loop_register_diagnostic | ||
1056 | 346 | |||
1057 | 347 | end module adjoint_main_loop | 365 | end module adjoint_main_loop |
1058 | 348 | 366 | ||
1059 | === modified file 'adjoint/Adjoint_Python_Fortran.F90' | |||
1060 | --- adjoint/Adjoint_Python_Fortran.F90 2011-05-01 19:08:55 +0000 | |||
1061 | +++ adjoint/Adjoint_Python_Fortran.F90 2011-07-12 15:56:32 +0000 | |||
1062 | @@ -40,9 +40,11 @@ | |||
1063 | 40 | public :: adj_variables_from_python | 40 | public :: adj_variables_from_python |
1064 | 41 | 41 | ||
1065 | 42 | interface | 42 | interface |
1067 | 43 | subroutine adj_variables_from_python_c(fn, fnlen, start_time, end_time, timestep, result, result_len, stat) & | 43 | subroutine adj_variables_from_python_c(adjointer, fn, fnlen, start_time, end_time, timestep, result, result_len, stat) & |
1068 | 44 | & bind(c, name='adj_variables_from_python') | 44 | & bind(c, name='adj_variables_from_python') |
1069 | 45 | use libadjoint | ||
1070 | 45 | use iso_c_binding | 46 | use iso_c_binding |
1071 | 47 | type(adj_adjointer), intent(in) :: adjointer | ||
1072 | 46 | integer(kind=c_int), intent(in), value :: fnlen | 48 | integer(kind=c_int), intent(in), value :: fnlen |
1073 | 47 | character(kind=c_char), dimension(fnlen), intent(in) :: fn | 49 | character(kind=c_char), dimension(fnlen), intent(in) :: fn |
1074 | 48 | real(kind=c_double), intent(in), value :: start_time, end_time | 50 | real(kind=c_double), intent(in), value :: start_time, end_time |
1075 | @@ -60,7 +62,8 @@ | |||
1076 | 60 | 62 | ||
1077 | 61 | contains | 63 | contains |
1078 | 62 | 64 | ||
1080 | 63 | subroutine adj_variables_from_python(fn, start_time, end_time, timestep, result, extras, stat) | 65 | subroutine adj_variables_from_python(adjointer, fn, start_time, end_time, timestep, result, extras, stat) |
1081 | 66 | type(adj_adjointer), intent(in) :: adjointer | ||
1082 | 64 | character(len=*), intent(in) :: fn | 67 | character(len=*), intent(in) :: fn |
1083 | 65 | real, intent(in) :: start_time, end_time | 68 | real, intent(in) :: start_time, end_time |
1084 | 66 | integer, intent(in) :: timestep | 69 | integer, intent(in) :: timestep |
1085 | @@ -88,7 +91,7 @@ | |||
1086 | 88 | 91 | ||
1087 | 89 | timestep_long = timestep | 92 | timestep_long = timestep |
1088 | 90 | 93 | ||
1090 | 91 | call adj_variables_from_python_c(fn_c, len_trim(fn), start_time, end_time, timestep_long, result_c_ptr, result_len_c, stat_c) | 94 | call adj_variables_from_python_c(adjointer, fn_c, len_trim(fn), start_time, end_time, timestep_long, result_c_ptr, result_len_c, stat_c) |
1091 | 92 | 95 | ||
1092 | 93 | if (stat_c /= 0) then | 96 | if (stat_c /= 0) then |
1093 | 94 | if (present(stat)) then | 97 | if (present(stat)) then |
1094 | 95 | 98 | ||
1095 | === modified file 'adjoint/Burgers_Adjoint_Callbacks.F90' | |||
1096 | --- adjoint/Burgers_Adjoint_Callbacks.F90 2011-04-01 17:40:34 +0000 | |||
1097 | +++ adjoint/Burgers_Adjoint_Callbacks.F90 2011-07-12 15:56:32 +0000 | |||
1098 | @@ -40,6 +40,9 @@ | |||
1099 | 40 | use adjoint_global_variables, only: adj_path_lookup | 40 | use adjoint_global_variables, only: adj_path_lookup |
1100 | 41 | use mangle_options_tree, only: adjoint_field_path | 41 | use mangle_options_tree, only: adjoint_field_path |
1101 | 42 | use mangle_dirichlet_rows_module | 42 | use mangle_dirichlet_rows_module |
1102 | 43 | use populate_state_module | ||
1103 | 44 | use burgers_assembly | ||
1104 | 45 | use global_parameters, only: OPTION_PATH_LEN, running_adjoint | ||
1105 | 43 | implicit none | 46 | implicit none |
1106 | 44 | 47 | ||
1107 | 45 | private | 48 | private |
1108 | @@ -61,6 +64,15 @@ | |||
1109 | 61 | call adj_chkierr(ierr) | 64 | call adj_chkierr(ierr) |
1110 | 62 | ierr = adj_register_operator_callback(adjointer, ADJ_BLOCK_ACTION_CB, "TimesteppingOperator", c_funloc(timestepping_operator_action_callback)) | 65 | ierr = adj_register_operator_callback(adjointer, ADJ_BLOCK_ACTION_CB, "TimesteppingOperator", c_funloc(timestepping_operator_action_callback)) |
1111 | 63 | call adj_chkierr(ierr) | 66 | call adj_chkierr(ierr) |
1112 | 67 | |||
1113 | 68 | ierr = adj_register_operator_callback(adjointer, ADJ_NBLOCK_DERIVATIVE_ACTION_CB, "AdvectionOperator", c_funloc(advection_derivative_action_proc)) | ||
1114 | 69 | call adj_chkierr(ierr) | ||
1115 | 70 | |||
1116 | 71 | ierr = adj_register_operator_callback(adjointer, ADJ_NBLOCK_ACTION_CB, "AdvectionOperator", c_funloc(advection_action_proc)) | ||
1117 | 72 | call adj_chkierr(ierr) | ||
1118 | 73 | |||
1119 | 74 | ierr = adj_register_forward_source_callback(adjointer, c_funloc(burgers_equation_forward_source)) | ||
1120 | 75 | call adj_chkierr(ierr) | ||
1121 | 64 | end subroutine register_burgers_operator_callbacks | 76 | end subroutine register_burgers_operator_callbacks |
1122 | 65 | 77 | ||
1123 | 66 | subroutine velocity_identity_assembly_callback(nvar, variables, dependencies, hermitian, coefficient, context, output, rhs) bind(c) | 78 | subroutine velocity_identity_assembly_callback(nvar, variables, dependencies, hermitian, coefficient, context, output, rhs) bind(c) |
1124 | @@ -114,9 +126,11 @@ | |||
1125 | 114 | type(scalar_field) :: empty_velocity_field, previous_u, iter_u | 126 | type(scalar_field) :: empty_velocity_field, previous_u, iter_u |
1126 | 115 | type(scalar_field), dimension(2) :: deps | 127 | type(scalar_field), dimension(2) :: deps |
1127 | 116 | type(csr_matrix), pointer :: mass_mat, diffusion_mat | 128 | type(csr_matrix), pointer :: mass_mat, diffusion_mat |
1129 | 117 | type(csr_matrix) :: burgers_mat, burgers_mat_T | 129 | type(csr_matrix) :: burgers_mat, burgers_mat_T, advection_mat |
1130 | 130 | type(vector_field), pointer :: positions | ||
1131 | 118 | real :: dt, theta | 131 | real :: dt, theta |
1132 | 119 | integer :: i | 132 | integer :: i |
1133 | 133 | character(len=FIELD_NAME_LEN) :: path | ||
1134 | 120 | 134 | ||
1135 | 121 | if (coefficient /= 1.0) then | 135 | if (coefficient /= 1.0) then |
1136 | 122 | FLAbort("The coefficient in burgers_operator_assembly_callback has to be 1.0") | 136 | FLAbort("The coefficient in burgers_operator_assembly_callback has to be 1.0") |
1137 | @@ -139,13 +153,20 @@ | |||
1138 | 139 | FLAbort("Unknown number of dependencies in burgers_operator_assembly_callback") | 153 | FLAbort("Unknown number of dependencies in burgers_operator_assembly_callback") |
1139 | 140 | end if | 154 | end if |
1140 | 141 | 155 | ||
1142 | 142 | call get_option(trim(adjoint_field_path("/material_phase::Fluid/scalar_field::Velocity/prognostic/temporal_discretisation/theta")), theta) | 156 | path = "/material_phase::Fluid/scalar_field::Velocity" |
1143 | 157 | if (running_adjoint) then | ||
1144 | 158 | path = adjoint_field_path("/material_phase::Fluid/scalar_field::Velocity") | ||
1145 | 159 | end if | ||
1146 | 160 | |||
1147 | 161 | call get_option(trim(path) // "/prognostic/temporal_discretisation/theta", theta, default=0.5) | ||
1148 | 143 | call get_option("/timestepping/timestep", dt) | 162 | call get_option("/timestepping/timestep", dt) |
1149 | 163 | dt = abs(dt) | ||
1150 | 144 | 164 | ||
1151 | 145 | call c_f_pointer(context, matrices) | 165 | call c_f_pointer(context, matrices) |
1152 | 146 | u_mesh => extract_mesh(matrices, "VelocityMesh") | 166 | u_mesh => extract_mesh(matrices, "VelocityMesh") |
1153 | 147 | diffusion_mat => extract_csr_matrix(matrices, "DiffusionMatrix") | 167 | diffusion_mat => extract_csr_matrix(matrices, "DiffusionMatrix") |
1154 | 148 | mass_mat => extract_csr_matrix(matrices, "MassMatrix") | 168 | mass_mat => extract_csr_matrix(matrices, "MassMatrix") |
1155 | 169 | positions => extract_vector_field(matrices, "Coordinate") | ||
1156 | 149 | 170 | ||
1157 | 150 | call allocate(empty_velocity_field, u_mesh, trim("AdjointPressureRhs")) | 171 | call allocate(empty_velocity_field, u_mesh, trim("AdjointPressureRhs")) |
1158 | 151 | call zero(empty_velocity_field) | 172 | call zero(empty_velocity_field) |
1159 | @@ -156,10 +177,18 @@ | |||
1160 | 156 | call allocate(burgers_mat, mass_mat%sparsity, name="BurgersAdjointOutput") | 177 | call allocate(burgers_mat, mass_mat%sparsity, name="BurgersAdjointOutput") |
1161 | 157 | call zero(burgers_mat) | 178 | call zero(burgers_mat) |
1162 | 158 | 179 | ||
1164 | 159 | if (.not. have_option(trim(adjoint_field_path('/material_phase::Fluid/scalar_field::Velocity/prognostic/temporal_discretisation/remove_time_term')))) then | 180 | if (.not. have_option(trim(path) // '/prognostic/temporal_discretisation/remove_time_term')) then |
1165 | 160 | call addto(burgers_mat, mass_mat, 1.0/abs(dt)) | 181 | call addto(burgers_mat, mass_mat, 1.0/abs(dt)) |
1166 | 161 | end if | 182 | end if |
1168 | 162 | !call addto(burgers_mat, advection_mat, theta) | 183 | |
1169 | 184 | if (.not. have_option(trim(path) // '/prognostic/remove_advection_term')) then | ||
1170 | 185 | call allocate(advection_mat, mass_mat%sparsity, name="BurgersCallbackAdvectionMatrix") | ||
1171 | 186 | call zero(advection_mat) | ||
1172 | 187 | call assemble_advection_matrix(advection_mat, positions, previous_u, iter_u) | ||
1173 | 188 | call addto(burgers_mat, advection_mat, theta) | ||
1174 | 189 | call deallocate(advection_mat) | ||
1175 | 190 | end if | ||
1176 | 191 | |||
1177 | 163 | call addto(burgers_mat, diffusion_mat, theta) | 192 | call addto(burgers_mat, diffusion_mat, theta) |
1178 | 164 | 193 | ||
1179 | 165 | ! Ensure that the input velocity has indeed dirichlet bc attached | 194 | ! Ensure that the input velocity has indeed dirichlet bc attached |
1180 | @@ -223,12 +252,15 @@ | |||
1181 | 223 | 252 | ||
1182 | 224 | type(state_type), pointer :: matrices | 253 | type(state_type), pointer :: matrices |
1183 | 225 | type(csr_matrix), pointer :: diffusion_mat, mass_mat | 254 | type(csr_matrix), pointer :: diffusion_mat, mass_mat |
1184 | 226 | type(csr_matrix) :: timestepping_mat | ||
1185 | 227 | type(mesh_type), pointer :: u_mesh | 255 | type(mesh_type), pointer :: u_mesh |
1186 | 228 | ! Input/output variables | 256 | ! Input/output variables |
1187 | 229 | type(scalar_field) :: u_input, previous_u, iter_u | 257 | type(scalar_field) :: u_input, previous_u, iter_u |
1189 | 230 | type(scalar_field) :: u_output | 258 | type(scalar_field) :: u_output, tmp_u |
1190 | 231 | real :: theta, dt | 259 | real :: theta, dt |
1191 | 260 | character(len=FIELD_NAME_LEN) :: path | ||
1192 | 261 | type(csr_matrix) :: advection_mat | ||
1193 | 262 | type(vector_field), pointer :: positions | ||
1194 | 263 | type(csr_matrix) :: timestepping_mat | ||
1195 | 232 | 264 | ||
1196 | 233 | call c_f_pointer(context, matrices) | 265 | call c_f_pointer(context, matrices) |
1197 | 234 | 266 | ||
1198 | @@ -240,6 +272,7 @@ | |||
1199 | 240 | u_mesh => extract_mesh(matrices, "VelocityMesh") | 272 | u_mesh => extract_mesh(matrices, "VelocityMesh") |
1200 | 241 | diffusion_mat => extract_csr_matrix(matrices, "DiffusionMatrix") | 273 | diffusion_mat => extract_csr_matrix(matrices, "DiffusionMatrix") |
1201 | 242 | mass_mat => extract_csr_matrix(matrices, "MassMatrix") | 274 | mass_mat => extract_csr_matrix(matrices, "MassMatrix") |
1202 | 275 | positions => extract_vector_field(matrices, "Coordinate") | ||
1203 | 243 | 276 | ||
1204 | 244 | if (nvar==2) then | 277 | if (nvar==2) then |
1205 | 245 | if (variables(1)%timestep==variables(2)%timestep-1) then | 278 | if (variables(1)%timestep==variables(2)%timestep-1) then |
1206 | @@ -259,29 +292,45 @@ | |||
1207 | 259 | end if | 292 | end if |
1208 | 260 | 293 | ||
1209 | 261 | ! Ensure that the input velocity has indeed dirichlet bc attached | 294 | ! Ensure that the input velocity has indeed dirichlet bc attached |
1210 | 262 | ! Ensure that the input velocity has indeed dirichlet bc attached | ||
1211 | 263 | if (get_boundary_condition_count(previous_u)==0) then | 295 | if (get_boundary_condition_count(previous_u)==0) then |
1212 | 264 | FLAbort("Velocity in callback must have dirichlet conditions attached") | 296 | FLAbort("Velocity in callback must have dirichlet conditions attached") |
1213 | 265 | end if | 297 | end if |
1214 | 266 | 298 | ||
1215 | 267 | call field_from_adj_vector(input, u_input) | 299 | call field_from_adj_vector(input, u_input) |
1217 | 268 | 300 | ||
1218 | 269 | call allocate(u_output, u_mesh, "TimeSteppingAdjointVelocityOutput") | 301 | call allocate(u_output, u_mesh, "TimeSteppingAdjointVelocityOutput") |
1219 | 270 | call zero(u_output) | 302 | call zero(u_output) |
1220 | 303 | call allocate(tmp_u, u_mesh, "TimeSteppingAdjointVelocityOutput") | ||
1221 | 304 | call zero(tmp_u) | ||
1222 | 271 | 305 | ||
1223 | 272 | call allocate(timestepping_mat, mass_mat%sparsity, name="TimesteppingMatrix") | 306 | call allocate(timestepping_mat, mass_mat%sparsity, name="TimesteppingMatrix") |
1224 | 273 | call zero(timestepping_mat) | 307 | call zero(timestepping_mat) |
1225 | 274 | 308 | ||
1236 | 275 | if (.not. have_option(trim(adjoint_field_path('/material_phase::Fluid/scalar_field::Velocity/prognostic/temporal_discretisation/remove_time_term')))) then | 309 | if (running_adjoint) then |
1237 | 276 | call addto(timestepping_mat, mass_mat, scale=1.0/dt) | 310 | path = adjoint_field_path("/material_phase::Fluid/scalar_field::Velocity") |
1238 | 277 | end if | 311 | else |
1239 | 278 | 312 | path = "/material_phase::Fluid/scalar_field::Velocity" | |
1240 | 279 | ! call mult(tmp, advection_mat, u_input) | 313 | end if |
1241 | 280 | ! call scale(tmp, theta - 1.0) | 314 | |
1242 | 281 | ! call addto(u_output, tmp) | 315 | if (.not. have_option(trim(path) // '/prognostic/temporal_discretisation/remove_time_term')) then |
1243 | 282 | 316 | call addto(timestepping_mat, mass_mat, scale=1.0/abs(dt)) | |
1244 | 283 | call addto(timestepping_mat, diffusion_mat, scale=theta - 1.0) | 317 | end if |
1245 | 284 | 318 | ||
1246 | 319 | if (.not. have_option(trim(path) // '/prognostic/remove_advection_term')) then | ||
1247 | 320 | call allocate(advection_mat, mass_mat%sparsity, name="BurgersCallbackAdvectionMatrix") | ||
1248 | 321 | call zero(advection_mat) | ||
1249 | 322 | call assemble_advection_matrix(advection_mat, positions, previous_u, iter_u) | ||
1250 | 323 | call addto(timestepping_mat, advection_mat, scale=theta-1.0) | ||
1251 | 324 | call deallocate(advection_mat) | ||
1252 | 325 | end if | ||
1253 | 326 | |||
1254 | 327 | call addto(timestepping_mat, diffusion_mat, scale=theta-1.0) | ||
1255 | 328 | |||
1256 | 329 | call scale(timestepping_mat, -1.0) | ||
1257 | 330 | if (get_boundary_condition_count(previous_u)==0) then | ||
1258 | 331 | FLAbort("Velocity in callback must have dirichlet conditions attached") | ||
1259 | 332 | end if | ||
1260 | 333 | ! Mangle the dirichlet rows | ||
1261 | 285 | call mangle_dirichlet_rows(timestepping_mat, previous_u, keep_diag=.false.) | 334 | call mangle_dirichlet_rows(timestepping_mat, previous_u, keep_diag=.false.) |
1262 | 286 | 335 | ||
1263 | 287 | if (hermitian==ADJ_FALSE) then | 336 | if (hermitian==ADJ_FALSE) then |
1264 | @@ -289,12 +338,283 @@ | |||
1265 | 289 | else | 338 | else |
1266 | 290 | call mult_T(u_output, timestepping_mat, u_input) | 339 | call mult_T(u_output, timestepping_mat, u_input) |
1267 | 291 | end if | 340 | end if |
1268 | 341 | |||
1269 | 342 | call deallocate(timestepping_mat) | ||
1270 | 343 | |||
1271 | 292 | call scale(u_output, coefficient) | 344 | call scale(u_output, coefficient) |
1272 | 293 | output = field_to_adj_vector(u_output) | 345 | output = field_to_adj_vector(u_output) |
1273 | 294 | call deallocate(u_output) | 346 | call deallocate(u_output) |
1275 | 295 | call deallocate(timestepping_mat) | 347 | call deallocate(tmp_u) |
1276 | 296 | end subroutine timestepping_operator_action_callback | 348 | end subroutine timestepping_operator_action_callback |
1277 | 297 | 349 | ||
1279 | 298 | 350 | subroutine advection_derivative_action_proc(nvar, variables, dependencies, derivative, contraction, hermitian, & | |
1280 | 351 | & input, coefficient, context, output) bind(c) | ||
1281 | 352 | use iso_c_binding | ||
1282 | 353 | use libadjoint_data_structures | ||
1283 | 354 | use simple_advection_d | ||
1284 | 355 | use simple_advection_b | ||
1285 | 356 | integer(kind=c_int), intent(in), value :: nvar | ||
1286 | 357 | type(adj_variable), dimension(nvar), intent(in) :: variables | ||
1287 | 358 | type(adj_vector), dimension(nvar), intent(in) :: dependencies | ||
1288 | 359 | type(adj_variable), intent(in), value :: derivative | ||
1289 | 360 | type(adj_vector), intent(in), value :: contraction | ||
1290 | 361 | integer(kind=c_int), intent(in), value :: hermitian | ||
1291 | 362 | type(adj_vector), intent(in), value :: input | ||
1292 | 363 | adj_scalar_f, intent(in), value :: coefficient | ||
1293 | 364 | type(c_ptr), intent(in), value :: context | ||
1294 | 365 | type(adj_vector), intent(out) :: output | ||
1295 | 366 | |||
1296 | 367 | type(state_type), pointer :: matrices | ||
1297 | 368 | type(vector_field), pointer :: positions | ||
1298 | 369 | type(scalar_field) :: u_left, u_right | ||
1299 | 370 | type(scalar_field) :: contraction_field, udot, Acbar | ||
1300 | 371 | type(scalar_field) :: output_field, tmp_field, u | ||
1301 | 372 | character(len=OPTION_PATH_LEN) :: path | ||
1302 | 373 | |||
1303 | 374 | real :: itheta | ||
1304 | 375 | |||
1305 | 376 | assert(nvar == 1 .or. nvar == 2) | ||
1306 | 377 | call c_f_pointer(context, matrices) | ||
1307 | 378 | positions => extract_vector_field(matrices, "Coordinate") | ||
1308 | 379 | |||
1309 | 380 | call field_from_adj_vector(contraction, contraction_field) | ||
1310 | 381 | call allocate(output_field, contraction_field%mesh, "NonlinearDerivativeOutput") | ||
1311 | 382 | call zero(output_field) | ||
1312 | 383 | |||
1313 | 384 | if (have_option("/material_phase::Fluid/scalar_field::Velocity")) then | ||
1314 | 385 | path = "/material_phase::Fluid/scalar_field::Velocity" | ||
1315 | 386 | else | ||
1316 | 387 | path = "/material_phase::Fluid/scalar_field::Velocity" | ||
1317 | 388 | path = adjoint_field_path(path) | ||
1318 | 389 | end if | ||
1319 | 390 | |||
1320 | 391 | if (hermitian == ADJ_FALSE) then | ||
1321 | 392 | call field_from_adj_vector(input, udot) | ||
1322 | 393 | call get_option(trim(path) // "/prognostic/temporal_discretisation/relaxation", itheta) | ||
1323 | 394 | if (have_option(trim(path) // "/prognostic/remove_advection_term")) then | ||
1324 | 395 | output = field_to_adj_vector(output_field) | ||
1325 | 396 | call deallocate(output_field) | ||
1326 | 397 | return | ||
1327 | 398 | end if | ||
1328 | 399 | else | ||
1329 | 400 | call get_option(trim(path) // "/prognostic/temporal_discretisation/relaxation", itheta) | ||
1330 | 401 | call field_from_adj_vector(input, Acbar) | ||
1331 | 402 | if (have_option(trim(path) // "/prognostic/remove_advection_term")) then | ||
1332 | 403 | output = field_to_adj_vector(output_field) | ||
1333 | 404 | call deallocate(output_field) | ||
1334 | 405 | return | ||
1335 | 406 | end if | ||
1336 | 407 | end if | ||
1337 | 408 | |||
1338 | 409 | call allocate(tmp_field, contraction_field%mesh, "TmpOutput") | ||
1339 | 410 | call zero(tmp_field) | ||
1340 | 411 | |||
1341 | 412 | if (nvar == 1) then | ||
1342 | 413 | call field_from_adj_vector(dependencies(1), u_left) | ||
1343 | 414 | if (hermitian == ADJ_FALSE) then | ||
1344 | 415 | call advection_action_d(positions%val(1,:), u_left%val, udot%val, contraction_field%val, tmp_field%val, output_field%val) | ||
1345 | 416 | else | ||
1346 | 417 | call advection_action_b(positions%val(1,:), u_left%val, output_field%val, contraction_field%val, tmp_field%val, Acbar%val) | ||
1347 | 418 | end if | ||
1348 | 419 | else if (nvar == 2) then | ||
1349 | 420 | call field_from_adj_vector(dependencies(1), u_left) | ||
1350 | 421 | call field_from_adj_vector(dependencies(2), u_right) | ||
1351 | 422 | call allocate(u, u_left%mesh, "AdvectingVelocity") | ||
1352 | 423 | call set(u, u_left) | ||
1353 | 424 | call scale(u, (1.0-itheta)) | ||
1354 | 425 | call addto(u, u_right, scale=itheta) | ||
1355 | 426 | |||
1356 | 427 | if (hermitian == ADJ_FALSE) then | ||
1357 | 428 | call advection_action_d(positions%val(1,:), u%val, udot%val, contraction_field%val, tmp_field%val, output_field%val) | ||
1358 | 429 | else | ||
1359 | 430 | call advection_action_b(positions%val(1,:), u%val, output_field%val, contraction_field%val, tmp_field%val, Acbar%val) | ||
1360 | 431 | end if | ||
1361 | 432 | |||
1362 | 433 | call deallocate(u) | ||
1363 | 434 | |||
1364 | 435 | if (derivative == variables(1)) then | ||
1365 | 436 | call scale(output_field, (1.0-itheta)) | ||
1366 | 437 | else if (derivative == variables(2)) then | ||
1367 | 438 | call scale(output_field, itheta) | ||
1368 | 439 | end if | ||
1369 | 440 | end if | ||
1370 | 441 | |||
1371 | 442 | call deallocate(tmp_field) | ||
1372 | 443 | call scale(output_field, coefficient) | ||
1373 | 444 | output = field_to_adj_vector(output_field) | ||
1374 | 445 | call deallocate(output_field) | ||
1375 | 446 | end subroutine advection_derivative_action_proc | ||
1376 | 447 | |||
1377 | 448 | subroutine burgers_equation_forward_source(adjointer, var, ndepends, dependencies, values, context, output, has_output) bind(c) | ||
1378 | 449 | type(adj_adjointer), intent(in) :: adjointer | ||
1379 | 450 | type(adj_variable), intent(in), value :: var | ||
1380 | 451 | integer(kind=c_int), intent(in), value :: ndepends | ||
1381 | 452 | type(adj_variable), dimension(ndepends), intent(in) :: dependencies | ||
1382 | 453 | type(adj_vector), dimension(ndepends), intent(in) :: values | ||
1383 | 454 | type(c_ptr), intent(in), value :: context | ||
1384 | 455 | type(adj_vector), intent(out) :: output | ||
1385 | 456 | integer(kind=c_int), intent(out) :: has_output | ||
1386 | 457 | |||
1387 | 458 | character(len=ADJ_DICT_LEN) :: path | ||
1388 | 459 | character(len=ADJ_NAME_LEN) :: name | ||
1389 | 460 | integer :: timestep | ||
1390 | 461 | real :: time, dt, end_time | ||
1391 | 462 | real :: theta | ||
1392 | 463 | type(state_type), pointer :: matrices | ||
1393 | 464 | logical :: has_source | ||
1394 | 465 | type(mesh_type), pointer :: u_mesh | ||
1395 | 466 | type(state_type), dimension(1) :: dummy_state | ||
1396 | 467 | type(scalar_field) :: u_output, tmp_u_output, dummy_u | ||
1397 | 468 | type(csr_matrix), pointer :: mass_matrix | ||
1398 | 469 | type(vector_field), pointer :: positions | ||
1399 | 470 | type(csr_matrix) :: mangled_mass_matrix | ||
1400 | 471 | |||
1401 | 472 | integer :: ierr | ||
1402 | 473 | |||
1403 | 474 | ierr = adj_variable_get_name(var, name) | ||
1404 | 475 | call adj_chkierr(ierr) | ||
1405 | 476 | |||
1406 | 477 | ierr = adj_variable_get_timestep(var, timestep) | ||
1407 | 478 | call adj_chkierr(ierr) | ||
1408 | 479 | |||
1409 | 480 | call c_f_pointer(context, matrices) | ||
1410 | 481 | assert(associated(matrices)) | ||
1411 | 482 | u_mesh => extract_mesh(matrices, "VelocityMesh") | ||
1412 | 483 | positions => extract_vector_field(matrices, "Coordinate") | ||
1413 | 484 | mass_matrix => extract_csr_matrix(matrices, "MassMatrix") | ||
1414 | 485 | |||
1415 | 486 | path = "/material_phase::Fluid/scalar_field::Velocity" | ||
1416 | 487 | |||
1417 | 488 | has_source = have_option(trim(path) // "/prognostic/scalar_field::Source") | ||
1418 | 489 | |||
1419 | 490 | if (timestep == 0) then ! initial condition | ||
1420 | 491 | call allocate(u_output, u_mesh, "VelocityInitialCondition") | ||
1421 | 492 | call zero(u_output) | ||
1422 | 493 | u_output%option_path = trim(path) | ||
1423 | 494 | call insert(dummy_state(1), positions, "Coordinate") | ||
1424 | 495 | call insert(dummy_state(1), u_output, "Velocity") | ||
1425 | 496 | call initialise_prognostic_fields(dummy_state) | ||
1426 | 497 | |||
1427 | 498 | ! Set initial condition | ||
1428 | 499 | call populate_boundary_conditions(dummy_state) | ||
1429 | 500 | call set_boundary_conditions_values(dummy_state, shift_time=.false.) | ||
1430 | 501 | call set_dirichlet_consistent(dummy_state) | ||
1431 | 502 | call deallocate(dummy_state(1)) | ||
1432 | 503 | |||
1433 | 504 | output = field_to_adj_vector(u_output) | ||
1434 | 505 | has_output = ADJ_TRUE | ||
1435 | 506 | call deallocate(u_output) | ||
1436 | 507 | else if (timestep > 0) then | ||
1437 | 508 | if (.not. has_source) then | ||
1438 | 509 | has_output = ADJ_FALSE | ||
1439 | 510 | else | ||
1440 | 511 | call allocate(tmp_u_output, u_mesh, "VelocitySource") | ||
1441 | 512 | call allocate(u_output, u_mesh, "VelocitySource") | ||
1442 | 513 | call allocate(dummy_u, u_mesh, "DummyVelocity") | ||
1443 | 514 | call zero(tmp_u_output) | ||
1444 | 515 | call zero(u_output) | ||
1445 | 516 | tmp_u_output%option_path = trim(path) // "/prognostic/scalar_field::Source" | ||
1446 | 517 | dummy_u%option_path = trim(path) | ||
1447 | 518 | |||
1448 | 519 | call insert(dummy_state(1), positions, "Coordinate") | ||
1449 | 520 | call insert(dummy_state(1), tmp_u_output, "VelocitySource") | ||
1450 | 521 | call insert(dummy_state(1), dummy_u, "DummyVelocity") | ||
1451 | 522 | |||
1452 | 523 | call populate_boundary_conditions(dummy_state) | ||
1453 | 524 | |||
1454 | 525 | ierr = adj_timestep_get_times(adjointer, timestep-1, time, end_time) | ||
1455 | 526 | call adj_chkierr(ierr) | ||
1456 | 527 | dt = end_time - time | ||
1457 | 528 | |||
1458 | 529 | call get_option(trim(path) // "/prognostic/temporal_discretisation/theta", theta, default=0.5) | ||
1459 | 530 | call set_prescribed_field_values(dummy_state, time=time + theta*abs(dt)) | ||
1460 | 531 | call deallocate(dummy_state(1)) | ||
1461 | 532 | |||
1462 | 533 | call allocate(mangled_mass_matrix, mass_matrix%sparsity, name="MangledMassMatrix") | ||
1463 | 534 | call set(mangled_mass_matrix, mass_matrix) | ||
1464 | 535 | call mangle_dirichlet_rows(mangled_mass_matrix, dummy_u, keep_diag=.false.) | ||
1465 | 536 | call mult(u_output, mangled_mass_matrix, tmp_u_output) | ||
1466 | 537 | call deallocate(mangled_mass_matrix) | ||
1467 | 538 | |||
1468 | 539 | call deallocate(tmp_u_output) | ||
1469 | 540 | call deallocate(dummy_u) | ||
1470 | 541 | |||
1471 | 542 | output = field_to_adj_vector(u_output) | ||
1472 | 543 | has_output = ADJ_TRUE | ||
1473 | 544 | call deallocate(u_output) | ||
1474 | 545 | end if | ||
1475 | 546 | end if | ||
1476 | 547 | |||
1477 | 548 | end subroutine burgers_equation_forward_source | ||
1478 | 549 | |||
1479 | 550 | subroutine advection_action_proc(nvar, variables, dependencies, input, context, output) bind(c) | ||
1480 | 551 | use iso_c_binding | ||
1481 | 552 | use libadjoint_data_structures | ||
1482 | 553 | use simple_advection | ||
1483 | 554 | integer(kind=c_int), intent(in), value :: nvar | ||
1484 | 555 | type(adj_variable), dimension(nvar), intent(in) :: variables | ||
1485 | 556 | type(adj_vector), dimension(nvar), intent(in) :: dependencies | ||
1486 | 557 | type(adj_vector), intent(in), value :: input | ||
1487 | 558 | type(c_ptr), intent(in), value :: context | ||
1488 | 559 | type(adj_vector), intent(out) :: output | ||
1489 | 560 | |||
1490 | 561 | type(scalar_field) :: u_output, u_check, nonlinear_u | ||
1491 | 562 | type(scalar_field) :: previous_u, iter_u, u_input | ||
1492 | 563 | type(csr_matrix) :: advection_mat | ||
1493 | 564 | type(csr_matrix), pointer :: diffusion_mat | ||
1494 | 565 | type(vector_field), pointer :: positions | ||
1495 | 566 | type(mesh_type), pointer :: u_mesh | ||
1496 | 567 | type(state_type), pointer :: matrices | ||
1497 | 568 | character(len=OPTION_PATH_LEN) :: path | ||
1498 | 569 | real :: itheta | ||
1499 | 570 | |||
1500 | 571 | path = "/material_phase::Fluid/scalar_field::Velocity" | ||
1501 | 572 | if (running_adjoint) then | ||
1502 | 573 | path = adjoint_field_path(path) | ||
1503 | 574 | end if | ||
1504 | 575 | |||
1505 | 576 | if (nvar==2) then | ||
1506 | 577 | if (variables(1)%timestep==variables(2)%timestep-1) then | ||
1507 | 578 | call field_from_adj_vector(dependencies(1), previous_u) | ||
1508 | 579 | call field_from_adj_vector(dependencies(2), iter_u) | ||
1509 | 580 | else if(variables(2)%timestep==variables(1)%timestep-1) then | ||
1510 | 581 | call field_from_adj_vector(dependencies(2), previous_u) | ||
1511 | 582 | call field_from_adj_vector(dependencies(1), iter_u) | ||
1512 | 583 | else | ||
1513 | 584 | FLAbort("Dependencies have no contiguous timesteps.") | ||
1514 | 585 | end if | ||
1515 | 586 | else if (nvar==1) then | ||
1516 | 587 | call field_from_adj_vector(dependencies(1), previous_u) | ||
1517 | 588 | call field_from_adj_vector(dependencies(1), iter_u) | ||
1518 | 589 | else | ||
1519 | 590 | FLAbort("Unknown number of dependencies in burgers_operator_assembly_callback") | ||
1520 | 591 | end if | ||
1521 | 592 | |||
1522 | 593 | call field_from_adj_vector(input, u_input) | ||
1523 | 594 | |||
1524 | 595 | call c_f_pointer(context, matrices) | ||
1525 | 596 | u_mesh => extract_mesh(matrices, "VelocityMesh") | ||
1526 | 597 | diffusion_mat => extract_csr_matrix(matrices, "DiffusionMatrix") | ||
1527 | 598 | positions => extract_vector_field(matrices, "Coordinate") | ||
1528 | 599 | |||
1529 | 600 | call allocate(advection_mat, diffusion_mat%sparsity, name="AdvectionActionMatrix") | ||
1530 | 601 | call zero(advection_mat) | ||
1531 | 602 | if (.not. have_option(trim(path) // "/prognostic/remove_advection_term")) then | ||
1532 | 603 | call assemble_advection_matrix(advection_mat, positions, previous_u, iter_u) | ||
1533 | 604 | end if | ||
1534 | 605 | |||
1535 | 606 | if (get_boundary_condition_count(previous_u) /= 1) then | ||
1536 | 607 | FLAbort("Need to supply boundary conditions on previous_u") | ||
1537 | 608 | end if | ||
1538 | 609 | |||
1539 | 610 | call mangle_dirichlet_rows(advection_mat, previous_u, keep_diag=.true.) | ||
1540 | 611 | |||
1541 | 612 | call allocate(u_output, u_mesh, "AdvectionActionOutput") | ||
1542 | 613 | call mult(u_output, advection_mat, u_input) | ||
1543 | 614 | call deallocate(advection_mat) | ||
1544 | 615 | |||
1545 | 616 | output = field_to_adj_vector(u_output) | ||
1546 | 617 | call deallocate(u_output) | ||
1547 | 618 | end subroutine advection_action_proc | ||
1548 | 299 | #endif | 619 | #endif |
1549 | 300 | end module burgers_adjoint_callbacks | 620 | end module burgers_adjoint_callbacks |
1550 | 301 | 621 | ||
1551 | === added file 'adjoint/Burgers_Control_Callbacks.F90' | |||
1552 | --- adjoint/Burgers_Control_Callbacks.F90 1970-01-01 00:00:00 +0000 | |||
1553 | +++ adjoint/Burgers_Control_Callbacks.F90 2011-07-12 15:56:32 +0000 | |||
1554 | @@ -0,0 +1,183 @@ | |||
1555 | 1 | ! Copyright (C) 2006 Imperial College London and others. | ||
1556 | 2 | ! | ||
1557 | 3 | ! Please see the AUTHORS file in the main source directory for a full list | ||
1558 | 4 | ! of copyright holders. | ||
1559 | 5 | ! | ||
1560 | 6 | ! Prof. C Pain | ||
1561 | 7 | ! Applied Modelling and Computation Group | ||
1562 | 8 | ! Department of Earth Science and Engineering | ||
1563 | 9 | ! Imperial College London | ||
1564 | 10 | ! | ||
1565 | 11 | ! amcgsoftware@imperial.ac.uk | ||
1566 | 12 | ! | ||
1567 | 13 | ! This library is free software; you can redistribute it and/or | ||
1568 | 14 | ! modify it under the terms of the GNU Lesser General Public | ||
1569 | 15 | ! License as published by the Free Software Foundation, | ||
1570 | 16 | ! version 2.1 of the License. | ||
1571 | 17 | ! | ||
1572 | 18 | ! This library is distributed in the hope that it will be useful, | ||
1573 | 19 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1574 | 20 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1575 | 21 | ! Lesser General Public License for more details. | ||
1576 | 22 | ! | ||
1577 | 23 | ! You should have received a copy of the GNU Lesser General Public | ||
1578 | 24 | ! License along with this library; if not, write to the Free Software | ||
1579 | 25 | ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
1580 | 26 | ! USA | ||
1581 | 27 | |||
1582 | 28 | #include "fdebug.h" | ||
1583 | 29 | |||
1584 | 30 | module burgers_adjoint_controls | ||
1585 | 31 | use fields | ||
1586 | 32 | use global_parameters, only : PYTHON_FUNC_LEN, OPTION_PATH_LEN | ||
1587 | 33 | use spud | ||
1588 | 34 | use state_module | ||
1589 | 35 | use python_state | ||
1590 | 36 | use sparse_matrices_fields | ||
1591 | 37 | use manifold_projections | ||
1592 | 38 | use mangle_dirichlet_rows_module | ||
1593 | 39 | |||
1594 | 40 | implicit none | ||
1595 | 41 | |||
1596 | 42 | private | ||
1597 | 43 | |||
1598 | 44 | public :: burgers_adjoint_timestep_callback | ||
1599 | 45 | |||
1600 | 46 | contains | ||
1601 | 47 | |||
1602 | 48 | ! Data is a void pointer used to pass variables into the callback | ||
1603 | 49 | subroutine burgers_adjoint_timestep_callback(states, timestep, functional_name, data) | ||
1604 | 50 | use iso_c_binding, only: c_ptr | ||
1605 | 51 | use global_parameters, only: OPTION_PATH_LEN | ||
1606 | 52 | use state_module | ||
1607 | 53 | type(state_type), dimension(:), intent(inout) :: states | ||
1608 | 54 | integer, intent(in) :: timestep | ||
1609 | 55 | character(len=*), intent(in) :: functional_name | ||
1610 | 56 | type(c_ptr), intent(in) :: data | ||
1611 | 57 | |||
1612 | 58 | type(state_type), pointer :: matrices | ||
1613 | 59 | character(len=OPTION_PATH_LEN) :: field_name, control_type, control_deriv_name, field_deriv_name, name, material_phase_name | ||
1614 | 60 | integer :: nb_controls | ||
1615 | 61 | integer :: i, state_id, s_idx | ||
1616 | 62 | type(scalar_field), pointer :: sfield, adj_sfield, adj_sfield2 | ||
1617 | 63 | type(vector_field), pointer :: vfield, adj_vfield, positions | ||
1618 | 64 | type(tensor_field), pointer :: tfield, adj_tfield | ||
1619 | 65 | type(block_csr_matrix), pointer :: big_mat, div_mat, u_mass_mat | ||
1620 | 66 | type(csr_matrix), pointer :: h_mass_mat | ||
1621 | 67 | type(csr_matrix) :: h_mangled_mass_mat | ||
1622 | 68 | type(state_type), dimension(1) :: dummy_state | ||
1623 | 69 | |||
1624 | 70 | type(scalar_field) :: dummy_u | ||
1625 | 71 | type(vector_field) :: local_src_tmp, local_src_tmp2, src_tmp | ||
1626 | 72 | real :: theta, d0, dt | ||
1627 | 73 | integer :: stat | ||
1628 | 74 | |||
1629 | 75 | ! Cast the data to the matrices state | ||
1630 | 76 | call c_f_pointer(data, matrices) | ||
1631 | 77 | |||
1632 | 78 | |||
1633 | 79 | nb_controls = option_count("/adjoint/controls/control") | ||
1634 | 80 | do i = 0, nb_controls-1 | ||
1635 | 81 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/name", control_deriv_name) | ||
1636 | 82 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type/name", control_type) | ||
1637 | 83 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type::" // trim(control_type) // "/field_name", name) | ||
1638 | 84 | s_idx = scan(trim(name), "::") | ||
1639 | 85 | if (s_idx == 0) then | ||
1640 | 86 | FLAbort("The control " // trim(control_deriv_name) // " uses an invalid field_name. It should be of the form Materialphase::Fieldname") | ||
1641 | 87 | end if | ||
1642 | 88 | material_phase_name = name(1:s_idx - 1) | ||
1643 | 89 | field_name = name(s_idx + 2:len_trim(name)) | ||
1644 | 90 | ! Find state associated with the material phase | ||
1645 | 91 | do state_id = 1, size(states) | ||
1646 | 92 | if (trim(states(state_id)%name) == trim(material_phase_name)) then | ||
1647 | 93 | exit | ||
1648 | 94 | end if | ||
1649 | 95 | end do | ||
1650 | 96 | ! Make sure we found the state | ||
1651 | 97 | if (.not. trim(states(state_id)%name) == trim(material_phase_name)) then | ||
1652 | 98 | FLAbort("Could not find state " // trim(material_phase_name) // " as specified in control " // trim(control_deriv_name) // ".") | ||
1653 | 99 | end if | ||
1654 | 100 | |||
1655 | 101 | control_deriv_name = trim(control_deriv_name) // "_TotalDerivative" | ||
1656 | 102 | select case(trim(control_type)) | ||
1657 | 103 | |||
1658 | 104 | !!!!!!!!!!!!! Initial condition !!!!!!!!!!!! | ||
1659 | 105 | case ("initial_condition") | ||
1660 | 106 | if (timestep /= 0) then | ||
1661 | 107 | cycle | ||
1662 | 108 | end if | ||
1663 | 109 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
1664 | 110 | if (has_scalar_field(states(state_id), field_deriv_name)) then | ||
1665 | 111 | if (trim(field_name) == "Velocity") then | ||
1666 | 112 | adj_sfield => extract_scalar_field(states(state_id), "Adjoint" // trim(field_name)) | ||
1667 | 113 | sfield => extract_scalar_field(states(state_id), field_deriv_name) ! Output field | ||
1668 | 114 | positions => extract_vector_field(matrices, "Coordinate") | ||
1669 | 115 | call set(sfield, adj_sfield) | ||
1670 | 116 | |||
1671 | 117 | ! Populate boundary conditions | ||
1672 | 118 | call allocate(dummy_u, adj_sfield%mesh, "DummyVelocity") | ||
1673 | 119 | dummy_u%option_path = "/material_phase::Fluid/scalar_field::AdjointVelocity" | ||
1674 | 120 | call insert(dummy_state(1), positions, "Coordinate") | ||
1675 | 121 | call insert(dummy_state(1), dummy_u, "AdjointVelocity") | ||
1676 | 122 | call populate_boundary_conditions(dummy_state) | ||
1677 | 123 | |||
1678 | 124 | ! Now we need to zero the derivative field everywhere we have Dirichlet conditions | ||
1679 | 125 | call mangle_dirichlet_rows(sfield, dummy_u) | ||
1680 | 126 | |||
1681 | 127 | call deallocate(dummy_u) | ||
1682 | 128 | call deallocate(dummy_state(1)) | ||
1683 | 129 | else | ||
1684 | 130 | FLAbort("Sorry, I do not know how to compute the intial condition control for " // trim(field_name) // ".") | ||
1685 | 131 | end if | ||
1686 | 132 | else | ||
1687 | 133 | FLAbort("The control derivative field " // trim(field_deriv_name) // " specified for " // trim(control_deriv_name) // " is not a field in the state.") | ||
1688 | 134 | end if | ||
1689 | 135 | |||
1690 | 136 | !!!!!!!!!!!!! Boundary condition !!!!!!!!!!!! | ||
1691 | 137 | case("boundary_condition") | ||
1692 | 138 | FLAbort("Boundary condition control not implemented yet.") | ||
1693 | 139 | |||
1694 | 140 | !!!!!!!!!!!!! Source !!!!!!!!!!!! | ||
1695 | 141 | case("source_term") | ||
1696 | 142 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
1697 | 143 | sfield => extract_scalar_field(states(state_id), field_deriv_name, stat=stat) ! Output field | ||
1698 | 144 | if (stat /= 0) then | ||
1699 | 145 | FLAbort("The control derivative field " // trim(field_deriv_name) // " specified for " // trim(control_deriv_name) // " is not a field in the state.") | ||
1700 | 146 | end if | ||
1701 | 147 | |||
1702 | 148 | if (timestep == 0) then | ||
1703 | 149 | call zero(sfield) | ||
1704 | 150 | else | ||
1705 | 151 | if (trim(field_name) == "VelocitySource") then | ||
1706 | 152 | adj_sfield => extract_scalar_field(states(state_id), "AdjointVelocity") | ||
1707 | 153 | h_mass_mat => extract_csr_matrix(matrices, "MassMatrix") | ||
1708 | 154 | positions => extract_vector_field(matrices, "Coordinate") | ||
1709 | 155 | |||
1710 | 156 | ! Populate boundary conditions | ||
1711 | 157 | call allocate(dummy_u, adj_sfield%mesh, "DummyVelocity") | ||
1712 | 158 | dummy_u%option_path = "/material_phase::Fluid/scalar_field::AdjointVelocity" | ||
1713 | 159 | call insert(dummy_state(1), positions, "Coordinate") | ||
1714 | 160 | call insert(dummy_state(1), dummy_u, "AdjointVelocity") | ||
1715 | 161 | call populate_boundary_conditions(dummy_state) | ||
1716 | 162 | |||
1717 | 163 | ! Mangle the mass matrix | ||
1718 | 164 | call allocate(h_mangled_mass_mat, h_mass_mat%sparsity, name="MangledMassMatrix") | ||
1719 | 165 | call set(h_mangled_mass_mat, h_mass_mat) | ||
1720 | 166 | call mangle_dirichlet_rows(h_mangled_mass_mat, dummy_u, keep_diag=.false.) | ||
1721 | 167 | call mult_T(sfield, h_mangled_mass_mat, adj_sfield) | ||
1722 | 168 | |||
1723 | 169 | ! Deallocate temporary variables | ||
1724 | 170 | call deallocate(dummy_state(1)) | ||
1725 | 171 | call deallocate(dummy_u) | ||
1726 | 172 | call deallocate(h_mangled_mass_mat) | ||
1727 | 173 | |||
1728 | 174 | else | ||
1729 | 175 | FLAbort("Sorry, I do not know how to compute the source condition control for " // trim(field_name) // ".") | ||
1730 | 176 | end if | ||
1731 | 177 | end if | ||
1732 | 178 | end select | ||
1733 | 179 | end do | ||
1734 | 180 | |||
1735 | 181 | end subroutine burgers_adjoint_timestep_callback | ||
1736 | 182 | |||
1737 | 183 | end module burgers_adjoint_controls | ||
1738 | 0 | 184 | ||
1739 | === modified file 'adjoint/Forward_Main_Loop.F90' | |||
1740 | --- adjoint/Forward_Main_Loop.F90 2011-05-13 17:52:57 +0000 | |||
1741 | +++ adjoint/Forward_Main_Loop.F90 2011-07-12 15:56:32 +0000 | |||
1742 | @@ -40,6 +40,7 @@ | |||
1743 | 40 | use adjoint_global_variables | 40 | use adjoint_global_variables |
1744 | 41 | use adjoint_functional_evaluation | 41 | use adjoint_functional_evaluation |
1745 | 42 | use populate_state_module | 42 | use populate_state_module |
1746 | 43 | use boundary_conditions_from_options | ||
1747 | 43 | use signal_vars | 44 | use signal_vars |
1748 | 44 | use mangle_options_tree | 45 | use mangle_options_tree |
1749 | 45 | use mangle_dirichlet_rows_module | 46 | use mangle_dirichlet_rows_module |
1750 | @@ -53,12 +54,13 @@ | |||
1751 | 53 | implicit none | 54 | implicit none |
1752 | 54 | 55 | ||
1753 | 55 | private | 56 | private |
1754 | 57 | public :: forward_main_loop_register_diagnostic | ||
1755 | 56 | #ifdef HAVE_ADJOINT | 58 | #ifdef HAVE_ADJOINT |
1757 | 57 | public :: compute_forward | 59 | public :: compute_forward, calculate_functional_values, register_functional_callbacks |
1758 | 58 | #endif | 60 | #endif |
1759 | 59 | 61 | ||
1760 | 60 | #ifdef HAVE_ADJOINT | ||
1761 | 61 | contains | 62 | contains |
1762 | 63 | #ifdef HAVE_ADJOINT | ||
1763 | 62 | 64 | ||
1764 | 63 | subroutine compute_forward(state) | 65 | subroutine compute_forward(state) |
1765 | 64 | type(state_type), dimension(:), intent(inout) :: state | 66 | type(state_type), dimension(:), intent(inout) :: state |
1766 | @@ -153,6 +155,11 @@ | |||
1767 | 153 | 155 | ||
1768 | 154 | if (has_path) then | 156 | if (has_path) then |
1769 | 155 | sfield_soln%option_path = trim(path) | 157 | sfield_soln%option_path = trim(path) |
1770 | 158 | ! We need to populate the BC values: | ||
1771 | 159 | call insert(state(1), sfield_soln, trim(sfield_soln%name)) | ||
1772 | 160 | call populate_boundary_conditions(state) | ||
1773 | 161 | call set_boundary_conditions_values(state, shift_time=.false.) | ||
1774 | 162 | sfield_soln = extract_scalar_field(state(1), trim(sfield_soln%name)) | ||
1775 | 156 | end if | 163 | end if |
1776 | 157 | 164 | ||
1777 | 158 | select case(lhs%klass) | 165 | select case(lhs%klass) |
1778 | @@ -168,6 +175,10 @@ | |||
1779 | 168 | call adj_chkierr(ierr) | 175 | call adj_chkierr(ierr) |
1780 | 169 | end if | 176 | end if |
1781 | 170 | 177 | ||
1782 | 178 | sfield_rhs%bc => sfield_soln%bc | ||
1783 | 179 | call set_dirichlet_consistent(sfield_rhs) | ||
1784 | 180 | sfield_rhs%bc => null() | ||
1785 | 181 | |||
1786 | 171 | call petsc_solve(sfield_soln, csr_mat, sfield_rhs, option_path=path) | 182 | call petsc_solve(sfield_soln, csr_mat, sfield_rhs, option_path=path) |
1787 | 172 | call compute_inactive_rows(sfield_soln, csr_mat, sfield_rhs) | 183 | call compute_inactive_rows(sfield_soln, csr_mat, sfield_rhs) |
1788 | 173 | endif | 184 | endif |
1789 | @@ -178,6 +189,7 @@ | |||
1790 | 178 | end select | 189 | end select |
1791 | 179 | 190 | ||
1792 | 180 | call insert(state(1), sfield_soln, trim(sfield_soln%name)) | 191 | call insert(state(1), sfield_soln, trim(sfield_soln%name)) |
1793 | 192 | |||
1794 | 181 | soln = field_to_adj_vector(sfield_soln) | 193 | soln = field_to_adj_vector(sfield_soln) |
1795 | 182 | ierr = adj_storage_memory_incref(soln, storage) | 194 | ierr = adj_storage_memory_incref(soln, storage) |
1796 | 183 | call adj_chkierr(ierr) | 195 | call adj_chkierr(ierr) |
1797 | @@ -197,6 +209,11 @@ | |||
1798 | 197 | 209 | ||
1799 | 198 | if (has_path) then | 210 | if (has_path) then |
1800 | 199 | vfield_soln%option_path = trim(path) | 211 | vfield_soln%option_path = trim(path) |
1801 | 212 | ! We need to populate the BC values: | ||
1802 | 213 | call insert(state(1), vfield_soln, trim(vfield_soln%name)) | ||
1803 | 214 | call populate_boundary_conditions(state) | ||
1804 | 215 | call set_boundary_conditions_values(state, shift_time=.false.) | ||
1805 | 216 | vfield_soln = extract_vector_field(state(1), trim(vfield_soln%name)) | ||
1806 | 200 | end if | 217 | end if |
1807 | 201 | 218 | ||
1808 | 202 | select case(lhs%klass) | 219 | select case(lhs%klass) |
1809 | @@ -212,6 +229,10 @@ | |||
1810 | 212 | call adj_chkierr(ierr) | 229 | call adj_chkierr(ierr) |
1811 | 213 | end if | 230 | end if |
1812 | 214 | 231 | ||
1813 | 232 | vfield_rhs%bc => vfield_soln%bc | ||
1814 | 233 | call set_dirichlet_consistent(vfield_rhs) | ||
1815 | 234 | vfield_rhs%bc => null() | ||
1816 | 235 | |||
1817 | 215 | call petsc_solve(vfield_soln, csr_mat, vfield_rhs, option_path=path) | 236 | call petsc_solve(vfield_soln, csr_mat, vfield_rhs, option_path=path) |
1818 | 216 | !call compute_inactive_rows(vfield_soln, csr_mat, vfield_rhs) | 237 | !call compute_inactive_rows(vfield_soln, csr_mat, vfield_rhs) |
1819 | 217 | endif | 238 | endif |
1820 | @@ -233,6 +254,7 @@ | |||
1821 | 233 | end select | 254 | end select |
1822 | 234 | 255 | ||
1823 | 235 | call insert(state(1), vfield_soln, trim(vfield_soln%name)) | 256 | call insert(state(1), vfield_soln, trim(vfield_soln%name)) |
1824 | 257 | |||
1825 | 236 | soln = field_to_adj_vector(vfield_soln) | 258 | soln = field_to_adj_vector(vfield_soln) |
1826 | 237 | ierr = adj_storage_memory_incref(soln, storage) | 259 | ierr = adj_storage_memory_incref(soln, storage) |
1827 | 238 | call adj_chkierr(ierr) | 260 | call adj_chkierr(ierr) |
1828 | @@ -264,8 +286,17 @@ | |||
1829 | 264 | call set_prescribed_field_values(state, exclude_interpolated=.true., exclude_nonreprescribed=.true., time=current_time) | 286 | call set_prescribed_field_values(state, exclude_interpolated=.true., exclude_nonreprescribed=.true., time=current_time) |
1830 | 265 | call calculate_diagnostic_variables(state, exclude_nonrecalculated = .true.) | 287 | call calculate_diagnostic_variables(state, exclude_nonrecalculated = .true.) |
1831 | 266 | call calculate_diagnostic_variables_new(state, exclude_nonrecalculated = .true.) | 288 | call calculate_diagnostic_variables_new(state, exclude_nonrecalculated = .true.) |
1832 | 289 | ! The first timestep is the initialisation of the model. | ||
1833 | 290 | ! We skip the evaluation of the functional at timestep zero to get the correct value. | ||
1834 | 291 | if (timestep > 0) then | ||
1835 | 292 | call calculate_functional_values(timestep-1) | ||
1836 | 293 | ! The last timestep is a the dummy timestep added at the end to act | ||
1837 | 294 | ! as a container for the last equation | ||
1838 | 295 | if (start_time == end_time) then | ||
1839 | 296 | assert(timestep == no_timesteps-1) | ||
1840 | 297 | end if | ||
1841 | 298 | end if | ||
1842 | 267 | call write_diagnostics(state, current_time, dt, equation+1) | 299 | call write_diagnostics(state, current_time, dt, equation+1) |
1843 | 268 | |||
1844 | 269 | if (do_write_state(current_time, timestep)) then | 300 | if (do_write_state(current_time, timestep)) then |
1845 | 270 | call write_state(dump_no, state) | 301 | call write_state(dump_no, state) |
1846 | 271 | endif | 302 | endif |
1847 | @@ -286,5 +317,69 @@ | |||
1848 | 286 | call get_option("/timestepping/finish_time", finish_time) | 317 | call get_option("/timestepping/finish_time", finish_time) |
1849 | 287 | assert(current_time == finish_time) | 318 | assert(current_time == finish_time) |
1850 | 288 | end subroutine compute_forward | 319 | end subroutine compute_forward |
1852 | 289 | #endif | 320 | |
1853 | 321 | subroutine register_functional_callbacks() | ||
1854 | 322 | integer :: no_functionals, functional | ||
1855 | 323 | character(len=ADJ_NAME_LEN) :: functional_name | ||
1856 | 324 | integer :: ierr | ||
1857 | 325 | |||
1858 | 326 | no_functionals = option_count("/adjoint/functional") | ||
1859 | 327 | do functional=0,no_functionals-1 | ||
1860 | 328 | if (have_option("/adjoint/functional[" // int2str(functional) // "]/functional_value")) then | ||
1861 | 329 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
1862 | 330 | ! Register the callback to compute J | ||
1863 | 331 | ierr = adj_register_functional_callback(adjointer, trim(functional_name), c_funloc(libadjoint_evaluate_functional)) | ||
1864 | 332 | call adj_chkierr(ierr) | ||
1865 | 333 | end if | ||
1866 | 334 | end do | ||
1867 | 335 | end subroutine register_functional_callbacks | ||
1868 | 336 | |||
1869 | 337 | subroutine calculate_functional_values(timestep) | ||
1870 | 338 | integer, intent(in) :: timestep | ||
1871 | 339 | integer :: functional, no_functionals | ||
1872 | 340 | character(len=OPTION_PATH_LEN) :: functional_name | ||
1873 | 341 | real, dimension(:), pointer :: fn_value | ||
1874 | 342 | real :: J | ||
1875 | 343 | integer :: ierr | ||
1876 | 344 | |||
1877 | 345 | no_functionals = option_count("/adjoint/functional") | ||
1878 | 346 | do functional=0,no_functionals-1 | ||
1879 | 347 | if (have_option("/adjoint/functional[" // int2str(functional) // "]/functional_value")) then | ||
1880 | 348 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
1881 | 349 | ierr = adj_evaluate_functional(adjointer, timestep, functional_name, J) | ||
1882 | 350 | call adj_chkierr(ierr) | ||
1883 | 351 | ! So we've computed the component of the functional associated with this timestep. | ||
1884 | 352 | ! We also want to sum them all up ... | ||
1885 | 353 | call set_diagnostic(name=trim(functional_name) // "_component", statistic="value", value=(/J/)) | ||
1886 | 354 | fn_value => get_diagnostic(name=trim(functional_name), statistic="value") | ||
1887 | 355 | J = J + fn_value(1) | ||
1888 | 356 | call set_diagnostic(name=trim(functional_name), statistic="value", value=(/J/)) | ||
1889 | 357 | end if | ||
1890 | 358 | end do | ||
1891 | 359 | end subroutine calculate_functional_values | ||
1892 | 360 | |||
1893 | 361 | #endif | ||
1894 | 362 | |||
1895 | 363 | ! Register a diagnostic variable for each functional. | ||
1896 | 364 | subroutine forward_main_loop_register_diagnostic | ||
1897 | 365 | integer :: functional, no_functionals | ||
1898 | 366 | character(len=OPTION_PATH_LEN) :: functional_name | ||
1899 | 367 | |||
1900 | 368 | #ifdef HAVE_ADJOINT | ||
1901 | 369 | no_functionals = option_count("/adjoint/functional") | ||
1902 | 370 | |||
1903 | 371 | do functional=0,no_functionals-1 | ||
1904 | 372 | ! Register a diagnostic for each functional | ||
1905 | 373 | if (have_option("/adjoint/functional[" // int2str(functional) // "]/functional_value")) then | ||
1906 | 374 | call get_option("/adjoint/functional[" // int2str(functional) // "]/name", functional_name) | ||
1907 | 375 | call register_diagnostic(dim=1, name=trim(functional_name) // "_component", statistic="value") | ||
1908 | 376 | call register_diagnostic(dim=1, name=trim(functional_name), statistic="value") | ||
1909 | 377 | ! The functional value will be accumulated, so initialise it with zero. | ||
1910 | 378 | call set_diagnostic(name=trim(functional_name) // "_component", statistic="value", value=(/0.0/)) | ||
1911 | 379 | call set_diagnostic(name=trim(functional_name), statistic="value", value=(/0.0/)) | ||
1912 | 380 | end if | ||
1913 | 381 | end do | ||
1914 | 382 | #endif | ||
1915 | 383 | end subroutine forward_main_loop_register_diagnostic | ||
1916 | 384 | |||
1917 | 290 | end module forward_main_loop | 385 | end module forward_main_loop |
1918 | 291 | 386 | ||
1919 | === modified file 'adjoint/Libadjoint_Data_Callbacks.F90' | |||
1920 | --- adjoint/Libadjoint_Data_Callbacks.F90 2011-05-24 10:42:33 +0000 | |||
1921 | +++ adjoint/Libadjoint_Data_Callbacks.F90 2011-07-12 15:56:32 +0000 | |||
1922 | @@ -88,6 +88,8 @@ | |||
1923 | 88 | call adj_chkierr(ierr) | 88 | call adj_chkierr(ierr) |
1924 | 89 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_GET_NORM_CB, c_funloc(femtools_vec_getnorm_proc)) | 89 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_GET_NORM_CB, c_funloc(femtools_vec_getnorm_proc)) |
1925 | 90 | call adj_chkierr(ierr) | 90 | call adj_chkierr(ierr) |
1926 | 91 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_GET_SIZE_CB, c_funloc(femtools_vec_get_size_proc)) | ||
1927 | 92 | call adj_chkierr(ierr) | ||
1928 | 91 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_DOT_PRODUCT_CB, c_funloc(femtools_vec_dot_product_proc)) | 93 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_DOT_PRODUCT_CB, c_funloc(femtools_vec_dot_product_proc)) |
1929 | 92 | call adj_chkierr(ierr) | 94 | call adj_chkierr(ierr) |
1930 | 93 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_SET_RANDOM_CB, c_funloc(femtools_vec_set_random_proc)) | 95 | ierr = adj_register_data_callback(adjointer, ADJ_VEC_SET_RANDOM_CB, c_funloc(femtools_vec_set_random_proc)) |
1931 | @@ -317,6 +319,27 @@ | |||
1932 | 317 | end if | 319 | end if |
1933 | 318 | end subroutine femtools_vec_set_random_proc | 320 | end subroutine femtools_vec_set_random_proc |
1934 | 319 | 321 | ||
1935 | 322 | subroutine femtools_vec_get_size_proc(vec, sz) bind(c) | ||
1936 | 323 | type(adj_vector), intent(in), value :: vec | ||
1937 | 324 | integer(kind=c_int), intent(out) :: sz | ||
1938 | 325 | type(scalar_field), pointer :: scalar | ||
1939 | 326 | type(vector_field), pointer :: vector | ||
1940 | 327 | type(tensor_field), pointer :: tensor | ||
1941 | 328 | |||
1942 | 329 | if (vec%klass == ADJ_SCALAR_FIELD) then | ||
1943 | 330 | call c_f_pointer(vec%ptr, scalar) | ||
1944 | 331 | sz = node_count(scalar) | ||
1945 | 332 | else if (vec%klass == ADJ_VECTOR_FIELD) then | ||
1946 | 333 | call c_f_pointer(vec%ptr, vector) | ||
1947 | 334 | sz = node_count(vector) * vector%dim | ||
1948 | 335 | else if (vec%klass == ADJ_TENSOR_FIELD) then | ||
1949 | 336 | call c_f_pointer(vec%ptr, tensor) | ||
1950 | 337 | sz = node_count(tensor) * tensor%dim(1) * tensor%dim(2) | ||
1951 | 338 | else | ||
1952 | 339 | FLAbort("adj_vector class not supported.") | ||
1953 | 340 | end if | ||
1954 | 341 | end subroutine femtools_vec_get_size_proc | ||
1955 | 342 | |||
1956 | 320 | subroutine femtools_mat_axpy_proc(Y, alpha, X) bind(c) | 343 | subroutine femtools_mat_axpy_proc(Y, alpha, X) bind(c) |
1957 | 321 | ! Computes Y = alpha*X + Y. | 344 | ! Computes Y = alpha*X + Y. |
1958 | 322 | use iso_c_binding | 345 | use iso_c_binding |
1959 | 323 | 346 | ||
1960 | === modified file 'adjoint/Makefile.dependencies' | |||
1961 | --- adjoint/Makefile.dependencies 2011-05-23 14:44:04 +0000 | |||
1962 | +++ adjoint/Makefile.dependencies 2011-07-12 15:56:32 +0000 | |||
1963 | @@ -1,4 +1,12 @@ | |||
1964 | 1 | # Dependencies generated by create_makefile.py. DO NOT EDIT | 1 | # Dependencies generated by create_makefile.py. DO NOT EDIT |
1965 | 2 | ../include/adjoint_controls.mod: Adjoint_Controls.o | ||
1966 | 3 | @true | ||
1967 | 4 | |||
1968 | 5 | Adjoint_Controls.o ../include/adjoint_controls.mod: Adjoint_Controls.F90 \ | ||
1969 | 6 | ../include/boundary_conditions.mod ../include/global_parameters.mod \ | ||
1970 | 7 | ../include/fields.mod ../include/spud.mod ../include/python_state.mod \ | ||
1971 | 8 | ../include/fdebug.h ../include/state_module.mod | ||
1972 | 9 | |||
1973 | 2 | ../include/adjoint_functional_evaluation.mod: Adjoint_Functional_Evaluation.o | 10 | ../include/adjoint_functional_evaluation.mod: Adjoint_Functional_Evaluation.o |
1974 | 3 | @true | 11 | @true |
1975 | 4 | 12 | ||
1976 | @@ -22,7 +30,7 @@ | |||
1977 | 22 | 30 | ||
1978 | 23 | Adjoint_Main_Loop.o ../include/adjoint_main_loop.mod: Adjoint_Main_Loop.F90 \ | 31 | Adjoint_Main_Loop.o ../include/adjoint_main_loop.mod: Adjoint_Main_Loop.F90 \ |
1979 | 24 | ../include/populate_state_module.mod ../include/sparse_matrices_fields.mod \ | 32 | ../include/populate_state_module.mod ../include/sparse_matrices_fields.mod \ |
1981 | 25 | ../include/diagnostic_fields_new.mod \ | 33 | ../include/diagnostic_fields_new.mod ../include/adjoint_controls.mod \ |
1982 | 26 | ../include/adjoint_functional_evaluation.mod ../include/sparse_tools.mod \ | 34 | ../include/adjoint_functional_evaluation.mod ../include/sparse_tools.mod \ |
1983 | 27 | ../include/fields.mod ../include/diagnostic_variables.mod \ | 35 | ../include/fields.mod ../include/diagnostic_variables.mod \ |
1984 | 28 | ../include/mangle_options_tree.mod ../include/write_state_module.mod \ | 36 | ../include/mangle_options_tree.mod ../include/write_state_module.mod \ |
1985 | @@ -44,12 +52,25 @@ | |||
1986 | 44 | 52 | ||
1987 | 45 | Burgers_Adjoint_Callbacks.o ../include/burgers_adjoint_callbacks.mod: \ | 53 | Burgers_Adjoint_Callbacks.o ../include/burgers_adjoint_callbacks.mod: \ |
1988 | 46 | Burgers_Adjoint_Callbacks.F90 ../include/libadjoint_data_callbacks.mod \ | 54 | Burgers_Adjoint_Callbacks.F90 ../include/libadjoint_data_callbacks.mod \ |
1993 | 47 | ../include/adjoint_global_variables.mod ../include/fields.mod \ | 55 | ../include/simple_advection.mod ../include/burgers_assembly.mod \ |
1994 | 48 | ../include/spud.mod ../include/mangle_options_tree.mod \ | 56 | ../include/populate_state_module.mod \ |
1995 | 49 | ../include/sparse_matrices_fields.mod \ | 57 | ../include/adjoint_global_variables.mod ../include/global_parameters.mod \ |
1996 | 50 | ../include/mangle_dirichlet_rows_module.mod ../include/fdebug.h \ | 58 | ../include/fields.mod ../include/simple_advection_b.mod ../include/spud.mod \ |
1997 | 59 | ../include/mangle_options_tree.mod ../include/sparse_matrices_fields.mod \ | ||
1998 | 60 | ../include/mangle_dirichlet_rows_module.mod \ | ||
1999 | 61 | ../include/simple_advection_d.mod ../include/fdebug.h \ | ||
2000 | 51 | ../include/state_module.mod | 62 | ../include/state_module.mod |
2001 | 52 | 63 | ||
2002 | 64 | ../include/burgers_adjoint_controls.mod: Burgers_Control_Callbacks.o | ||
2003 | 65 | @true | ||
2004 | 66 | |||
2005 | 67 | Burgers_Control_Callbacks.o ../include/burgers_adjoint_controls.mod: \ | ||
2006 | 68 | Burgers_Control_Callbacks.F90 ../include/mangle_dirichlet_rows_module.mod \ | ||
2007 | 69 | ../include/manifold_projections.mod ../include/global_parameters.mod \ | ||
2008 | 70 | ../include/fields.mod ../include/spud.mod \ | ||
2009 | 71 | ../include/sparse_matrices_fields.mod ../include/state_module.mod \ | ||
2010 | 72 | ../include/python_state.mod ../include/fdebug.h | ||
2011 | 73 | |||
2012 | 53 | ../include/forward_main_loop.mod: Forward_Main_Loop.o | 74 | ../include/forward_main_loop.mod: Forward_Main_Loop.o |
2013 | 54 | @true | 75 | @true |
2014 | 55 | 76 | ||
2015 | @@ -58,6 +79,7 @@ | |||
2016 | 58 | ../include/diagnostic_fields_new.mod \ | 79 | ../include/diagnostic_fields_new.mod \ |
2017 | 59 | ../include/adjoint_functional_evaluation.mod ../include/sparse_tools.mod \ | 80 | ../include/adjoint_functional_evaluation.mod ../include/sparse_tools.mod \ |
2018 | 60 | ../include/fields.mod ../include/diagnostic_variables.mod \ | 81 | ../include/fields.mod ../include/diagnostic_variables.mod \ |
2019 | 82 | ../include/boundary_conditions_from_options.mod \ | ||
2020 | 61 | ../include/mangle_options_tree.mod ../include/write_state_module.mod \ | 83 | ../include/mangle_options_tree.mod ../include/write_state_module.mod \ |
2021 | 62 | ../include/spud.mod ../include/mangle_dirichlet_rows_module.mod \ | 84 | ../include/spud.mod ../include/mangle_dirichlet_rows_module.mod \ |
2022 | 63 | ../include/state_module.mod ../include/libadjoint_data_callbacks.mod \ | 85 | ../include/state_module.mod ../include/libadjoint_data_callbacks.mod \ |
2023 | @@ -105,3 +127,14 @@ | |||
2024 | 105 | ../include/manifold_projections.mod ../include/fdebug.h \ | 127 | ../include/manifold_projections.mod ../include/fdebug.h \ |
2025 | 106 | ../include/state_module.mod | 128 | ../include/state_module.mod |
2026 | 107 | 129 | ||
2027 | 130 | ../include/shallow_water_adjoint_controls.mod: \ | ||
2028 | 131 | Shallow_Water_Control_Callbacks.o | ||
2029 | 132 | @true | ||
2030 | 133 | |||
2031 | 134 | Shallow_Water_Control_Callbacks.o \ | ||
2032 | 135 | ../include/shallow_water_adjoint_controls.mod: \ | ||
2033 | 136 | Shallow_Water_Control_Callbacks.F90 ../include/manifold_projections.mod \ | ||
2034 | 137 | ../include/global_parameters.mod ../include/fields.mod ../include/spud.mod \ | ||
2035 | 138 | ../include/sparse_matrices_fields.mod ../include/python_state.mod \ | ||
2036 | 139 | ../include/fdebug.h ../include/state_module.mod | ||
2037 | 140 | |||
2038 | 108 | 141 | ||
2039 | === modified file 'adjoint/Makefile.in' | |||
2040 | --- adjoint/Makefile.in 2011-05-19 14:29:56 +0000 | |||
2041 | +++ adjoint/Makefile.in 2011-07-12 15:56:32 +0000 | |||
2042 | @@ -43,10 +43,16 @@ | |||
2043 | 43 | 43 | ||
2044 | 44 | LIB = ../lib/lib@FLUIDITY@.a | 44 | LIB = ../lib/lib@FLUIDITY@.a |
2045 | 45 | 45 | ||
2050 | 46 | OBJS = $(patsubst %.F90,%.o,$(wildcard *.F90)) $(patsubst %.c,%.o,$(wildcard *.c)) | 46 | OBJS = $(patsubst %.F90,%.o,$(wildcard *.F90)) $(patsubst %.f90,%.o,$(wildcard *.f90)) $(patsubst %.c,%.o,$(wildcard *.c)) $(patsubst %.f,%.o,$(wildcard *.f)) |
2051 | 47 | 47 | ||
2052 | 48 | .SUFFIXES: .F90 .c .cpp .o .a | 48 | .SUFFIXES: .f .f90 .F90 .c .cpp .o .a |
2053 | 49 | 49 | ||
2054 | 50 | .f90.o: | ||
2055 | 51 | @echo " FC $<" | ||
2056 | 52 | $(FC) $(FCFLAGS) $(GENFLAGS) -c $< | ||
2057 | 53 | .f.o: | ||
2058 | 54 | @echo " FC $<" | ||
2059 | 55 | $(FC) $(FCFLAGS) $(GENFLAGS) -c $< | ||
2060 | 50 | .F90.o: | 56 | .F90.o: |
2061 | 51 | @echo " FC $<" | 57 | @echo " FC $<" |
2062 | 52 | $(FC) $(FCFLAGS) $(GENFLAGS) -c $< | 58 | $(FC) $(FCFLAGS) $(GENFLAGS) -c $< |
2063 | @@ -71,4 +77,16 @@ | |||
2064 | 71 | clean: | 77 | clean: |
2065 | 72 | rm -f *.o *.d *.mod | 78 | rm -f *.o *.d *.mod |
2066 | 73 | 79 | ||
2067 | 80 | # Instructions for doing AD with tapenade | ||
2068 | 81 | reverse: | ||
2069 | 82 | tapenade -b -head "advection_action" -outvars "ac" -vars "u" simple_advection.f90 -ext PUSHPOPGeneralLib -extAD PUSHPOPADLib-fixinterface | ||
2070 | 83 | echo "Don't forget to remove the zeroing of acb." | ||
2071 | 84 | |||
2072 | 85 | forward: | ||
2073 | 86 | tapenade -d -head "advection_action" -outvars "ac" -vars "u" simple_advection.f90 | ||
2074 | 87 | |||
2075 | 88 | ../include/simple_advection.mod: simple_advection.o | ||
2076 | 89 | ../include/simple_advection_d.mod: simple_advection_d.o | ||
2077 | 90 | ../include/simple_advection_b.mod: simple_advection_b.o | ||
2078 | 91 | |||
2079 | 74 | include Makefile.dependencies | 92 | include Makefile.dependencies |
2080 | 75 | 93 | ||
2081 | === modified file 'adjoint/Mangle_Dirichlet_Rows_Module.F90' | |||
2082 | --- adjoint/Mangle_Dirichlet_Rows_Module.F90 2011-03-31 17:44:57 +0000 | |||
2083 | +++ adjoint/Mangle_Dirichlet_Rows_Module.F90 2011-07-12 15:56:32 +0000 | |||
2084 | @@ -35,7 +35,7 @@ | |||
2085 | 35 | implicit none | 35 | implicit none |
2086 | 36 | 36 | ||
2087 | 37 | interface mangle_dirichlet_rows | 37 | interface mangle_dirichlet_rows |
2089 | 38 | module procedure mangle_dirichlet_rows_csr_scalar | 38 | module procedure mangle_dirichlet_rows_csr_scalar, mangle_dirichlet_rows_scalar |
2090 | 39 | end interface | 39 | end interface |
2091 | 40 | 40 | ||
2092 | 41 | interface set_inactive_rows | 41 | interface set_inactive_rows |
2093 | @@ -90,6 +90,28 @@ | |||
2094 | 90 | end do | 90 | end do |
2095 | 91 | end subroutine mangle_dirichlet_rows_csr_scalar | 91 | end subroutine mangle_dirichlet_rows_csr_scalar |
2096 | 92 | 92 | ||
2097 | 93 | subroutine mangle_dirichlet_rows_scalar(scalar, bc_field) | ||
2098 | 94 | type(scalar_field), intent(inout) :: scalar | ||
2099 | 95 | type(scalar_field), intent(in) :: bc_field | ||
2100 | 96 | |||
2101 | 97 | integer :: i, j, node | ||
2102 | 98 | character(len=FIELD_NAME_LEN) :: bctype | ||
2103 | 99 | integer, dimension(:), pointer :: node_list | ||
2104 | 100 | |||
2105 | 101 | assert(node_count(scalar) == node_count(bc_field)) | ||
2106 | 102 | |||
2107 | 103 | do i=1,get_boundary_condition_count(bc_field) | ||
2108 | 104 | call get_boundary_condition(bc_field, i, type=bctype, surface_node_list=node_list) | ||
2109 | 105 | |||
2110 | 106 | if (bctype /= "dirichlet") cycle | ||
2111 | 107 | |||
2112 | 108 | do j=1,size(node_list) | ||
2113 | 109 | node = node_list(j) | ||
2114 | 110 | call set(scalar, node, 0.0) | ||
2115 | 111 | end do | ||
2116 | 112 | end do | ||
2117 | 113 | end subroutine mangle_dirichlet_rows_scalar | ||
2118 | 114 | |||
2119 | 93 | subroutine set_inactive_rows_csr_scalar(matrix, field) | 115 | subroutine set_inactive_rows_csr_scalar(matrix, field) |
2120 | 94 | ! Any nodes associated with Dirichlet BCs, we make them inactive | 116 | ! Any nodes associated with Dirichlet BCs, we make them inactive |
2121 | 95 | type(csr_matrix), intent(inout) :: matrix | 117 | type(csr_matrix), intent(inout) :: matrix |
2122 | 96 | 118 | ||
2123 | === modified file 'adjoint/Mangle_Options_Tree.F90' | |||
2124 | --- adjoint/Mangle_Options_Tree.F90 2011-03-10 10:07:19 +0000 | |||
2125 | +++ adjoint/Mangle_Options_Tree.F90 2011-07-12 15:56:32 +0000 | |||
2126 | @@ -139,12 +139,6 @@ | |||
2127 | 139 | deallocate(fields_to_delete) | 139 | deallocate(fields_to_delete) |
2128 | 140 | end do | 140 | end do |
2129 | 141 | 141 | ||
2130 | 142 | ! We delete this because if it exists in the forward run, | ||
2131 | 143 | ! write_diagnostics wants to print it out in the stat file. | ||
2132 | 144 | do functional=0,option_count("/adjoint/functional")-1 | ||
2133 | 145 | call delete_option("/adjoint/functional[" // int2str(functional) // "]/functional_value", stat=stat) | ||
2134 | 146 | end do | ||
2135 | 147 | |||
2136 | 148 | end subroutine mangle_options_tree_forward | 142 | end subroutine mangle_options_tree_forward |
2137 | 149 | 143 | ||
2138 | 150 | subroutine mangle_options_tree_adjoint | 144 | subroutine mangle_options_tree_adjoint |
2139 | @@ -262,8 +256,13 @@ | |||
2140 | 262 | path = "/material_phase[" // int2str(state) // "]/scalar_field::" | 256 | path = "/material_phase[" // int2str(state) // "]/scalar_field::" |
2141 | 263 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) | 257 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) |
2142 | 264 | assert(stat == SPUD_NO_ERROR) | 258 | assert(stat == SPUD_NO_ERROR) |
2145 | 265 | ! Delete any sources specified for the forward model -- we deal with these ourselves | 259 | ! Delete the sources specified for the forward model -- if desired |
2146 | 266 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/scalar_field::Source", stat=stat) | 260 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/scalar_field::Source/")) then |
2147 | 261 | if (have_option(trim(complete_field_path(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/scalar_field::Source/")) & | ||
2148 | 262 | & // "adjoint_storage/exists_in_forward")) then | ||
2149 | 263 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/scalar_field::Source", stat=stat) | ||
2150 | 264 | end if | ||
2151 | 265 | end if | ||
2152 | 267 | ! And delete any initial conditions -- we will also specify these | 266 | ! And delete any initial conditions -- we will also specify these |
2153 | 268 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then | 267 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then |
2154 | 269 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) | 268 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) |
2155 | @@ -294,7 +293,12 @@ | |||
2156 | 294 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) | 293 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) |
2157 | 295 | assert(stat == SPUD_NO_ERROR) | 294 | assert(stat == SPUD_NO_ERROR) |
2158 | 296 | ! Delete any sources specified for the forward model -- we deal with these ourselves | 295 | ! Delete any sources specified for the forward model -- we deal with these ourselves |
2160 | 297 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/vector_field::Source", stat=stat) | 296 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/vector_field::Source/")) then |
2161 | 297 | if (have_option(trim(complete_field_path(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/vector_field::Source/")) & | ||
2162 | 298 | & // "adjoint_storage/exists_in_forward")) then | ||
2163 | 299 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/vector_field::Source", stat=stat) | ||
2164 | 300 | end if | ||
2165 | 301 | end if | ||
2166 | 298 | ! And delete any initial conditions -- we will also specify these | 302 | ! And delete any initial conditions -- we will also specify these |
2167 | 299 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then | 303 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then |
2168 | 300 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) | 304 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) |
2169 | @@ -325,7 +329,12 @@ | |||
2170 | 325 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) | 329 | call move_option(trim(path) // trim(fields_to_move(field)), trim(path) // "Adjoint" // trim(fields_to_move(field)), stat=stat) |
2171 | 326 | assert(stat == SPUD_NO_ERROR) | 330 | assert(stat == SPUD_NO_ERROR) |
2172 | 327 | ! Delete any sources specified for the forward model -- we deal with these ourselves | 331 | ! Delete any sources specified for the forward model -- we deal with these ourselves |
2174 | 328 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/tensor_field::Source", stat=stat) | 332 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/tensor_field::Source/")) then |
2175 | 333 | if (have_option(trim(complete_field_path(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/tensor_field::Source/")) & | ||
2176 | 334 | & // "adjoint_storage/exists_in_forward")) then | ||
2177 | 335 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/tensor_field::Source", stat=stat) | ||
2178 | 336 | end if | ||
2179 | 337 | end if | ||
2180 | 329 | ! And delete any initial conditions -- we will also specify these | 338 | ! And delete any initial conditions -- we will also specify these |
2181 | 330 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then | 339 | if (have_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition")) then |
2182 | 331 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) | 340 | call delete_option(trim(path) // "Adjoint" // trim(fields_to_move(field)) // "/prognostic/initial_condition", stat=stat) |
2183 | 332 | 341 | ||
2184 | === modified file 'adjoint/Shallow_Water_Adjoint_Callbacks.F90' | |||
2185 | --- adjoint/Shallow_Water_Adjoint_Callbacks.F90 2011-05-13 14:06:12 +0000 | |||
2186 | +++ adjoint/Shallow_Water_Adjoint_Callbacks.F90 2011-07-12 15:56:32 +0000 | |||
2187 | @@ -982,5 +982,6 @@ | |||
2188 | 982 | end select | 982 | end select |
2189 | 983 | end if | 983 | end if |
2190 | 984 | end subroutine shallow_water_forward_source | 984 | end subroutine shallow_water_forward_source |
2191 | 985 | |||
2192 | 985 | #endif | 986 | #endif |
2193 | 986 | end module shallow_water_adjoint_callbacks | 987 | end module shallow_water_adjoint_callbacks |
2194 | 987 | 988 | ||
2195 | === added file 'adjoint/Shallow_Water_Control_Callbacks.F90' | |||
2196 | --- adjoint/Shallow_Water_Control_Callbacks.F90 1970-01-01 00:00:00 +0000 | |||
2197 | +++ adjoint/Shallow_Water_Control_Callbacks.F90 2011-07-12 15:56:32 +0000 | |||
2198 | @@ -0,0 +1,203 @@ | |||
2199 | 1 | ! Copyright (C) 2006 Imperial College London and others. | ||
2200 | 2 | ! | ||
2201 | 3 | ! Please see the AUTHORS file in the main source directory for a full list | ||
2202 | 4 | ! of copyright holders. | ||
2203 | 5 | ! | ||
2204 | 6 | ! Prof. C Pain | ||
2205 | 7 | ! Applied Modelling and Computation Group | ||
2206 | 8 | ! Department of Earth Science and Engineering | ||
2207 | 9 | ! Imperial College London | ||
2208 | 10 | ! | ||
2209 | 11 | ! amcgsoftware@imperial.ac.uk | ||
2210 | 12 | ! | ||
2211 | 13 | ! This library is free software; you can redistribute it and/or | ||
2212 | 14 | ! modify it under the terms of the GNU Lesser General Public | ||
2213 | 15 | ! License as published by the Free Software Foundation, | ||
2214 | 16 | ! version 2.1 of the License. | ||
2215 | 17 | ! | ||
2216 | 18 | ! This library is distributed in the hope that it will be useful, | ||
2217 | 19 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2218 | 20 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2219 | 21 | ! Lesser General Public License for more details. | ||
2220 | 22 | ! | ||
2221 | 23 | ! You should have received a copy of the GNU Lesser General Public | ||
2222 | 24 | ! License along with this library; if not, write to the Free Software | ||
2223 | 25 | ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
2224 | 26 | ! USA | ||
2225 | 27 | |||
2226 | 28 | #include "fdebug.h" | ||
2227 | 29 | |||
2228 | 30 | module shallow_water_adjoint_controls | ||
2229 | 31 | use fields | ||
2230 | 32 | use global_parameters, only : PYTHON_FUNC_LEN, OPTION_PATH_LEN | ||
2231 | 33 | use spud | ||
2232 | 34 | use state_module | ||
2233 | 35 | use python_state | ||
2234 | 36 | use sparse_matrices_fields | ||
2235 | 37 | use manifold_projections | ||
2236 | 38 | |||
2237 | 39 | implicit none | ||
2238 | 40 | |||
2239 | 41 | private | ||
2240 | 42 | |||
2241 | 43 | public :: shallow_water_adjoint_timestep_callback | ||
2242 | 44 | |||
2243 | 45 | contains | ||
2244 | 46 | |||
2245 | 47 | ! Data is a void pointer used to pass variables into the callback | ||
2246 | 48 | subroutine shallow_water_adjoint_timestep_callback(states, timestep, functional_name, data) | ||
2247 | 49 | use iso_c_binding, only: c_ptr | ||
2248 | 50 | use global_parameters, only: OPTION_PATH_LEN | ||
2249 | 51 | use state_module | ||
2250 | 52 | type(state_type), dimension(:), intent(inout) :: states | ||
2251 | 53 | integer, intent(in) :: timestep | ||
2252 | 54 | character(len=*), intent(in) :: functional_name | ||
2253 | 55 | type(c_ptr), intent(in) :: data | ||
2254 | 56 | |||
2255 | 57 | type(state_type), pointer :: matrices | ||
2256 | 58 | character(len=OPTION_PATH_LEN) :: field_name, control_type, control_deriv_name, field_deriv_name, name, material_phase_name | ||
2257 | 59 | integer :: nb_controls | ||
2258 | 60 | integer :: i, state_id, s_idx | ||
2259 | 61 | type(scalar_field), pointer :: sfield, adj_sfield, adj_sfield2 | ||
2260 | 62 | type(vector_field), pointer :: vfield, adj_vfield, positions | ||
2261 | 63 | type(tensor_field), pointer :: tfield, adj_tfield | ||
2262 | 64 | type(block_csr_matrix), pointer :: big_mat, div_mat, u_mass_mat | ||
2263 | 65 | type(csr_matrix), pointer :: h_mass_mat | ||
2264 | 66 | |||
2265 | 67 | type(vector_field) :: local_src_tmp, local_src_tmp2, src_tmp | ||
2266 | 68 | real :: theta, d0, dt | ||
2267 | 69 | |||
2268 | 70 | ! Cast the data to the matrices state | ||
2269 | 71 | call c_f_pointer(data, matrices) | ||
2270 | 72 | |||
2271 | 73 | |||
2272 | 74 | nb_controls = option_count("/adjoint/controls/control") | ||
2273 | 75 | do i = 0, nb_controls-1 | ||
2274 | 76 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/name", control_deriv_name) | ||
2275 | 77 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type/name", control_type) | ||
2276 | 78 | call get_option("/adjoint/controls/control[" // int2str(i) //"]/type::" // trim(control_type) // "/field_name", name) | ||
2277 | 79 | s_idx = scan(trim(name), "::") | ||
2278 | 80 | if (s_idx == 0) then | ||
2279 | 81 | FLAbort("The control " // trim(control_deriv_name) // " uses an invalid field_name. It should be of the form Materialphase::Fieldname") | ||
2280 | 82 | end if | ||
2281 | 83 | material_phase_name = name(1:s_idx - 1) | ||
2282 | 84 | field_name = name(s_idx + 2:len_trim(name)) | ||
2283 | 85 | ! Find state associated with the material phase | ||
2284 | 86 | do state_id = 1, size(states) | ||
2285 | 87 | if (trim(states(state_id)%name) == trim(material_phase_name)) then | ||
2286 | 88 | exit | ||
2287 | 89 | end if | ||
2288 | 90 | end do | ||
2289 | 91 | ! Make sure we found the state | ||
2290 | 92 | if (.not. trim(states(state_id)%name) == trim(material_phase_name)) then | ||
2291 | 93 | FLAbort("Could not find state " // trim(material_phase_name) // " as specified in control " // trim(control_deriv_name) // ".") | ||
2292 | 94 | end if | ||
2293 | 95 | |||
2294 | 96 | control_deriv_name = trim(control_deriv_name) // "_TotalDerivative" | ||
2295 | 97 | select case(trim(control_type)) | ||
2296 | 98 | !!!!!!!!!!!!! Initial condition !!!!!!!!!!!! | ||
2297 | 99 | case ("initial_condition") | ||
2298 | 100 | if (timestep /= 0) then | ||
2299 | 101 | cycle | ||
2300 | 102 | end if | ||
2301 | 103 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
2302 | 104 | if (has_scalar_field(states(state_id), field_deriv_name)) then | ||
2303 | 105 | if (trim(field_name) == "LayerThickness") then | ||
2304 | 106 | adj_sfield => extract_scalar_field(states(state_id), "Adjoint" // trim(field_name)) | ||
2305 | 107 | sfield => extract_scalar_field(states(state_id), field_deriv_name) ! Output field | ||
2306 | 108 | h_mass_mat => extract_csr_matrix(matrices, "LayerThicknessMassMatrix") | ||
2307 | 109 | call mult(sfield, h_mass_mat, adj_sfield) | ||
2308 | 110 | else | ||
2309 | 111 | FLAbort("Sorry, I do not know how to compute the intial condition control for " // trim(field_name) // ".") | ||
2310 | 112 | end if | ||
2311 | 113 | elseif (has_vector_field(states(state_id), field_deriv_name)) then | ||
2312 | 114 | if (trim(field_name) == "Velocity") then | ||
2313 | 115 | adj_vfield => extract_vector_field(states(state_id), "Adjoint" // trim(field_name)) | ||
2314 | 116 | vfield => extract_vector_field(states(state_id), field_deriv_name) ! Output field | ||
2315 | 117 | u_mass_mat => extract_block_csr_matrix(matrices, "CartesianVelocityMassMatrix") | ||
2316 | 118 | call mult(vfield, u_mass_mat, adj_vfield) | ||
2317 | 119 | else | ||
2318 | 120 | FLAbort("Sorry, I do not know how to compute the intial condition control for " // trim(field_name) // ".") | ||
2319 | 121 | end if | ||
2320 | 122 | elseif (has_tensor_field(states(state_id), field_deriv_name)) then | ||
2321 | 123 | tfield => extract_tensor_field(states(state_id), field_deriv_name) ! Output field | ||
2322 | 124 | FLAbort("Sorry, I do not know how to compute the intial condition control for " // trim(field_name) // ".") | ||
2323 | 125 | else | ||
2324 | 126 | FLAbort("The control derivative field " // trim(field_deriv_name) // " specified for " // trim(control_deriv_name) // " is not a field in the state.") | ||
2325 | 127 | end if | ||
2326 | 128 | !!!!!!!!!!!!! Boundary condition !!!!!!!!!!!! | ||
2327 | 129 | case("boundary_condition") | ||
2328 | 130 | FLAbort("Boundary condition control not implemented yet.") | ||
2329 | 131 | !!!!!!!!!!!!! Source !!!!!!!!!!!! | ||
2330 | 132 | case("source_term") | ||
2331 | 133 | if (timestep == 0) then | ||
2332 | 134 | cycle | ||
2333 | 135 | end if | ||
2334 | 136 | field_deriv_name = trim(functional_name) // "_" // control_deriv_name | ||
2335 | 137 | call get_option("/timestepping/timestep", dt) | ||
2336 | 138 | if (has_scalar_field(states(state_id), field_deriv_name)) then | ||
2337 | 139 | if (trim(field_name) == "LayerThicknessSource") then | ||
2338 | 140 | adj_sfield => extract_scalar_field(states(state_id), "AdjointLayerThicknessDelta") | ||
2339 | 141 | sfield => extract_scalar_field(states(state_id), field_deriv_name) ! Output field | ||
2340 | 142 | h_mass_mat => extract_csr_matrix(matrices, "LayerThicknessMassMatrix") | ||
2341 | 143 | call mult_T(sfield, h_mass_mat, adj_sfield) | ||
2342 | 144 | call scale(sfield, abs(dt)) | ||
2343 | 145 | else | ||
2344 | 146 | FLAbort("Sorry, I do not know how to compute the source condition control for " // trim(field_name) // ".") | ||
2345 | 147 | end if | ||
2346 | 148 | elseif (has_vector_field(states(state_id), field_deriv_name)) then | ||
2347 | 149 | if (trim(field_name) == "VelocitySource") then | ||
2348 | 150 | ! We want to compute: | ||
2349 | 151 | ! \lambda_{delta \eta} \Delta t^2 d_0 \theta C^T (M+\theta \Delta t L)^{-1} M P_{Cart to local} | ||
2350 | 152 | vfield => extract_vector_field(states(state_id), field_deriv_name) ! Output field | ||
2351 | 153 | adj_sfield => extract_scalar_field(states(state_id), "AdjointLayerThicknessDelta") | ||
2352 | 154 | adj_vfield => extract_vector_field(states(state_id), "AdjointLocalVelocityDelta") | ||
2353 | 155 | ! We need the AdjointVelocity for the option path only | ||
2354 | 156 | adj_sfield2 => extract_scalar_field(states(state_id), "AdjointLayerThickness") | ||
2355 | 157 | call get_option(trim(adj_sfield2%option_path) // "/prognostic/temporal_discretisation/theta", theta) | ||
2356 | 158 | call get_option(trim(adj_sfield2%option_path) // "/prognostic/mean_layer_thickness", d0) | ||
2357 | 159 | |||
2358 | 160 | big_mat => extract_block_csr_matrix(matrices, "InverseBigMatrix") | ||
2359 | 161 | div_mat => extract_block_csr_matrix(matrices, "DivergenceMatrix") | ||
2360 | 162 | h_mass_mat => extract_csr_matrix(matrices, "LayerThicknessMassMatrix") | ||
2361 | 163 | u_mass_mat => extract_block_csr_matrix(matrices, "LocalVelocityMassMatrix") | ||
2362 | 164 | positions => extract_vector_field(matrices, "Coordinate") | ||
2363 | 165 | |||
2364 | 166 | call allocate(local_src_tmp, adj_vfield%dim, adj_vfield%mesh, "TemporaryLocalVelocity") | ||
2365 | 167 | call allocate(local_src_tmp2, adj_vfield%dim, adj_vfield%mesh, "TemporaryLocalVelocity2") | ||
2366 | 168 | call allocate(src_tmp, vfield%dim, vfield%mesh, "TemporaryVelocity") | ||
2367 | 169 | call mult_T(local_src_tmp, div_mat, adj_sfield) | ||
2368 | 170 | call mult_T(local_src_tmp2, big_mat, local_src_tmp) | ||
2369 | 171 | call mult_T(local_src_tmp, u_mass_mat, local_src_tmp2) | ||
2370 | 172 | call project_cartesian_to_local(positions, src_tmp, local_src_tmp, transpose=.true.) | ||
2371 | 173 | call scale(src_tmp, factor = dt*dt * d0 * theta) | ||
2372 | 174 | call zero(vfield) | ||
2373 | 175 | ! TODO: Where does this minus come from? | ||
2374 | 176 | call addto(vfield, src_tmp, scale=-1.0) | ||
2375 | 177 | |||
2376 | 178 | ! Now add the part from \lambda_{\Delta u} | ||
2377 | 179 | ! \lambda_{\Delta u} M M_{big} M P_{cart to local} | ||
2378 | 180 | call mult_T(local_src_tmp, u_mass_mat, adj_vfield) | ||
2379 | 181 | call mult_T(local_src_tmp2, big_mat, local_src_tmp) | ||
2380 | 182 | call mult_T(local_src_tmp, u_mass_mat, local_src_tmp2) | ||
2381 | 183 | call project_cartesian_to_local(positions, src_tmp, local_src_tmp, transpose = .true.) | ||
2382 | 184 | call addto(vfield, src_tmp, scale = abs(dt)) | ||
2383 | 185 | |||
2384 | 186 | call deallocate(local_src_tmp) | ||
2385 | 187 | call deallocate(local_src_tmp2) | ||
2386 | 188 | call deallocate(src_tmp) | ||
2387 | 189 | else | ||
2388 | 190 | FLAbort("Sorry, I do not know how to compute the source condition control for " // trim(field_name) // ".") | ||
2389 | 191 | end if | ||
2390 | 192 | elseif (has_tensor_field(states(state_id), field_deriv_name)) then | ||
2391 | 193 | tfield => extract_tensor_field(states(state_id), field_deriv_name) ! Output field | ||
2392 | 194 | FLAbort("Sorry, I do not know how to compute the source condition control for " // trim(field_name) // ".") | ||
2393 | 195 | else | ||
2394 | 196 | FLAbort("The control derivative field " // trim(field_deriv_name) // " specified for " // trim(control_deriv_name) // " is not a field in the state.") | ||
2395 | 197 | end if | ||
2396 | 198 | end select | ||
2397 | 199 | end do | ||
2398 | 200 | |||
2399 | 201 | end subroutine shallow_water_adjoint_timestep_callback | ||
2400 | 202 | |||
2401 | 203 | end module shallow_water_adjoint_controls | ||
2402 | 0 | 204 | ||
2403 | === added file 'adjoint/adBuffer.c' | |||
2404 | --- adjoint/adBuffer.c 1970-01-01 00:00:00 +0000 | |||
2405 | +++ adjoint/adBuffer.c 2011-07-12 15:56:32 +0000 | |||
2406 | @@ -0,0 +1,476 @@ | |||
2407 | 1 | static char adSid[]="$Id: adBuffer.c $"; | ||
2408 | 2 | |||
2409 | 3 | #include <stdlib.h> | ||
2410 | 4 | #include <stdio.h> | ||
2411 | 5 | #include <string.h> | ||
2412 | 6 | |||
2413 | 7 | #include "adStack.h" | ||
2414 | 8 | |||
2415 | 9 | /************ MEASUREMENT OF PUSH/POP TRAFFIC *************/ | ||
2416 | 10 | |||
2417 | 11 | static int mmftraffic = 0 ; | ||
2418 | 12 | static int mmftrafficM = 0 ; | ||
2419 | 13 | |||
2420 | 14 | void addftraffic(int n) { | ||
2421 | 15 | mmftraffic = mmftraffic+n ; | ||
2422 | 16 | while (mmftraffic >= 1000000) { | ||
2423 | 17 | mmftraffic = mmftraffic-1000000 ; | ||
2424 | 18 | ++mmftrafficM ; | ||
2425 | 19 | } | ||
2426 | 20 | while (mmftraffic < 0) { | ||
2427 | 21 | mmftraffic = mmftraffic+1000000 ; | ||
2428 | 22 | --mmftraffic ; | ||
2429 | 23 | } | ||
2430 | 24 | } | ||
2431 | 25 | |||
2432 | 26 | void printtraffic() { | ||
2433 | 27 | printctraffic_() ; | ||
2434 | 28 | printf(" F Traffic: ") ; | ||
2435 | 29 | printbigbytes(mmftrafficM, 1000000, mmftraffic) ; | ||
2436 | 30 | printf(" bytes\n") ; | ||
2437 | 31 | } | ||
2438 | 32 | |||
2439 | 33 | /************************** integer*4 ************************/ | ||
2440 | 34 | static int adi4buf[512] ; | ||
2441 | 35 | static int adi4ibuf = 0 ; | ||
2442 | 36 | static int adi4lbuf[512] ; | ||
2443 | 37 | static int adi4ilbuf = -1 ; | ||
2444 | 38 | static int adi4inlbuf = 0 ; | ||
2445 | 39 | |||
2446 | 40 | void pushinteger4(int x) { | ||
2447 | 41 | addftraffic(4) ; | ||
2448 | 42 | if (adi4ilbuf != -1) { | ||
2449 | 43 | adi4ilbuf = -1 ; | ||
2450 | 44 | adi4inlbuf = 0 ; | ||
2451 | 45 | } | ||
2452 | 46 | if (adi4ibuf >= 511) { | ||
2453 | 47 | adi4buf[511] = x ; | ||
2454 | 48 | pushNarray((char*)adi4buf, 512*4) ; | ||
2455 | 49 | addftraffic(-512*4) ; | ||
2456 | 50 | adi4ibuf = 0 ; | ||
2457 | 51 | } else { | ||
2458 | 52 | adi4buf[adi4ibuf] = x ; | ||
2459 | 53 | ++adi4ibuf ; | ||
2460 | 54 | } | ||
2461 | 55 | } | ||
2462 | 56 | |||
2463 | 57 | void lookinteger4(int *x) { | ||
2464 | 58 | if (adi4ilbuf == -1) { | ||
2465 | 59 | adi4ilbuf = adi4ibuf ; | ||
2466 | 60 | resetadlookstack_() ; | ||
2467 | 61 | } | ||
2468 | 62 | if (adi4ilbuf <= 0) { | ||
2469 | 63 | lookNarray((char*)adi4lbuf, 512*4) ; | ||
2470 | 64 | adi4inlbuf = 1 ; | ||
2471 | 65 | adi4ilbuf = 511 ; | ||
2472 | 66 | *x = adi4lbuf[511] ; | ||
2473 | 67 | } else { | ||
2474 | 68 | --adi4ilbuf ; | ||
2475 | 69 | if (adi4inlbuf) | ||
2476 | 70 | *x = adi4lbuf[adi4ilbuf] ; | ||
2477 | 71 | else | ||
2478 | 72 | *x = adi4buf[adi4ilbuf] ; | ||
2479 | 73 | } | ||
2480 | 74 | } | ||
2481 | 75 | |||
2482 | 76 | void popinteger4(int *x) { | ||
2483 | 77 | if (adi4ilbuf != -1) { | ||
2484 | 78 | adi4ilbuf = -1 ; | ||
2485 | 79 | adi4inlbuf = 0 ; | ||
2486 | 80 | } | ||
2487 | 81 | if (adi4ibuf <= 0) { | ||
2488 | 82 | popNarray((char*)adi4buf, 512*4) ; | ||
2489 | 83 | adi4ibuf = 511 ; | ||
2490 | 84 | *x = adi4buf[511] ; | ||
2491 | 85 | } else { | ||
2492 | 86 | --adi4ibuf ; | ||
2493 | 87 | *x = adi4buf[adi4ibuf] ; | ||
2494 | 88 | } | ||
2495 | 89 | } | ||
2496 | 90 | |||
2497 | 91 | /*************************** bits *************************/ | ||
2498 | 92 | static unsigned int adbitbuf = 0 ; | ||
2499 | 93 | static int adbitibuf = 1 ; | ||
2500 | 94 | static unsigned int adbitlbuf = 0 ; | ||
2501 | 95 | static int adbitilbuf = -1 ; | ||
2502 | 96 | static int adbitinlbuf = 0 ; | ||
2503 | 97 | |||
2504 | 98 | void pushbit(int bit) { | ||
2505 | 99 | if (adbitilbuf != -1) { | ||
2506 | 100 | adbitilbuf = -1 ; | ||
2507 | 101 | adbitinlbuf = 0 ; | ||
2508 | 102 | } | ||
2509 | 103 | adbitbuf<<=1 ; | ||
2510 | 104 | if (bit) adbitbuf++ ; | ||
2511 | 105 | if (adbitibuf>=32) { | ||
2512 | 106 | pushinteger4(adbitbuf) ; | ||
2513 | 107 | adbitbuf = 0 ; | ||
2514 | 108 | adbitibuf = 1 ; | ||
2515 | 109 | } else | ||
2516 | 110 | adbitibuf++ ; | ||
2517 | 111 | } | ||
2518 | 112 | |||
2519 | 113 | int lookbit() { | ||
2520 | 114 | if (adbitilbuf==-1) { | ||
2521 | 115 | adbitilbuf=adbitibuf ; | ||
2522 | 116 | adbitlbuf = adbitbuf ; | ||
2523 | 117 | } | ||
2524 | 118 | if (adbitilbuf<=1) { | ||
2525 | 119 | lookinteger4(&adbitlbuf) ; | ||
2526 | 120 | adbitilbuf = 32 ; | ||
2527 | 121 | } else | ||
2528 | 122 | adbitilbuf-- ; | ||
2529 | 123 | int bit = adbitlbuf%2 ; | ||
2530 | 124 | adbitlbuf>>=1 ; | ||
2531 | 125 | return bit ; | ||
2532 | 126 | } | ||
2533 | 127 | |||
2534 | 128 | int popbit() { | ||
2535 | 129 | if (adbitilbuf != -1) { | ||
2536 | 130 | adbitilbuf = -1 ; | ||
2537 | 131 | adbitinlbuf = 0 ; | ||
2538 | 132 | } | ||
2539 | 133 | if (adbitibuf<=1) { | ||
2540 | 134 | popinteger4(&adbitbuf) ; | ||
2541 | 135 | adbitibuf = 32 ; | ||
2542 | 136 | } else | ||
2543 | 137 | adbitibuf-- ; | ||
2544 | 138 | int bit = adbitbuf%2 ; | ||
2545 | 139 | adbitbuf>>=1 ; | ||
2546 | 140 | return bit ; | ||
2547 | 141 | } | ||
2548 | 142 | |||
2549 | 143 | /************************* controls ***********************/ | ||
2550 | 144 | |||
2551 | 145 | void pushcontrol1b(int cc) { | ||
2552 | 146 | pushbit(cc) ; | ||
2553 | 147 | } | ||
2554 | 148 | |||
2555 | 149 | void popcontrol1b(int *cc) { | ||
2556 | 150 | *cc = (popbit()?1:0) ; | ||
2557 | 151 | } | ||
2558 | 152 | |||
2559 | 153 | void lookcontrol1b(int *cc) { | ||
2560 | 154 | *cc = (lookbit()?1:0) ; | ||
2561 | 155 | } | ||
2562 | 156 | |||
2563 | 157 | void pushcontrol2b(int cc) { | ||
2564 | 158 | pushbit(cc%2) ; | ||
2565 | 159 | cc >>= 1 ; | ||
2566 | 160 | pushbit(cc) ; | ||
2567 | 161 | } | ||
2568 | 162 | |||
2569 | 163 | void popcontrol2b(int *cc) { | ||
2570 | 164 | *cc = (popbit()?2:0) ; | ||
2571 | 165 | if (popbit()) (*cc)++ ; | ||
2572 | 166 | } | ||
2573 | 167 | |||
2574 | 168 | void lookcontrol2b(int *cc) { | ||
2575 | 169 | *cc = (lookbit()?2:0) ; | ||
2576 | 170 | if (lookbit()) (*cc)++ ; | ||
2577 | 171 | } | ||
2578 | 172 | |||
2579 | 173 | void pushcontrol3b(int cc) { | ||
2580 | 174 | pushbit(cc%2) ; | ||
2581 | 175 | cc >>= 1 ; | ||
2582 | 176 | pushbit(cc%2) ; | ||
2583 | 177 | cc >>= 1 ; | ||
2584 | 178 | pushbit(cc) ; | ||
2585 | 179 | } | ||
2586 | 180 | |||
2587 | 181 | void popcontrol3b(int *cc) { | ||
2588 | 182 | *cc = (popbit()?2:0) ; | ||
2589 | 183 | if (popbit()) (*cc)++ ; | ||
2590 | 184 | (*cc) <<= 1 ; | ||
2591 | 185 | if (popbit()) (*cc)++ ; | ||
2592 | 186 | } | ||
2593 | 187 | |||
2594 | 188 | void lookcontrol3b(int *cc) { | ||
2595 | 189 | *cc = (lookbit()?2:0) ; | ||
2596 | 190 | if (lookbit()) (*cc)++ ; | ||
2597 | 191 | (*cc) <<= 1 ; | ||
2598 | 192 | if (lookbit()) (*cc)++ ; | ||
2599 | 193 | } | ||
2600 | 194 | |||
2601 | 195 | void pushcontrol4b(int cc) { | ||
2602 | 196 | pushbit(cc%2) ; | ||
2603 | 197 | cc >>= 1 ; | ||
2604 | 198 | pushbit(cc%2) ; | ||
2605 | 199 | cc >>= 1 ; | ||
2606 | 200 | pushbit(cc%2) ; | ||
2607 | 201 | cc >>= 1 ; | ||
2608 | 202 | pushbit(cc) ; | ||
2609 | 203 | } | ||
2610 | 204 | |||
2611 | 205 | void popcontrol4b(int *cc) { | ||
2612 | 206 | *cc = (popbit()?2:0) ; | ||
2613 | 207 | if (popbit()) (*cc)++ ; | ||
2614 | 208 | (*cc) <<= 1 ; | ||
2615 | 209 | if (popbit()) (*cc)++ ; | ||
2616 | 210 | (*cc) <<= 1 ; | ||
2617 | 211 | if (popbit()) (*cc)++ ; | ||
2618 | 212 | } | ||
2619 | 213 | |||
2620 | 214 | void lookcontrol4b(int *cc) { | ||
2621 | 215 | *cc = (lookbit()?2:0) ; | ||
2622 | 216 | if (lookbit()) (*cc)++ ; | ||
2623 | 217 | (*cc) <<= 1 ; | ||
2624 | 218 | if (lookbit()) (*cc)++ ; | ||
2625 | 219 | (*cc) <<= 1 ; | ||
2626 | 220 | if (lookbit()) (*cc)++ ; | ||
2627 | 221 | } | ||
2628 | 222 | |||
2629 | 223 | void pushcontrol5b(int cc) { | ||
2630 | 224 | pushbit(cc%2) ; | ||
2631 | 225 | cc >>= 1 ; | ||
2632 | 226 | pushbit(cc%2) ; | ||
2633 | 227 | cc >>= 1 ; | ||
2634 | 228 | pushbit(cc%2) ; | ||
2635 | 229 | cc >>= 1 ; | ||
2636 | 230 | pushbit(cc%2) ; | ||
2637 | 231 | cc >>= 1 ; | ||
2638 | 232 | pushbit(cc) ; | ||
2639 | 233 | } | ||
2640 | 234 | |||
2641 | 235 | void popcontrol5b(int *cc) { | ||
2642 | 236 | *cc = (popbit()?2:0) ; | ||
2643 | 237 | if (popbit()) (*cc)++ ; | ||
2644 | 238 | (*cc) <<= 1 ; | ||
2645 | 239 | if (popbit()) (*cc)++ ; | ||
2646 | 240 | (*cc) <<= 1 ; | ||
2647 | 241 | if (popbit()) (*cc)++ ; | ||
2648 | 242 | (*cc) <<= 1 ; | ||
2649 | 243 | if (popbit()) (*cc)++ ; | ||
2650 | 244 | } | ||
2651 | 245 | |||
2652 | 246 | void lookcontrol5b(int *cc) { | ||
2653 | 247 | *cc = (lookbit()?2:0) ; | ||
2654 | 248 | if (lookbit()) (*cc)++ ; | ||
2655 | 249 | (*cc) <<= 1 ; | ||
2656 | 250 | if (lookbit()) (*cc)++ ; | ||
2657 | 251 | (*cc) <<= 1 ; | ||
2658 | 252 | if (lookbit()) (*cc)++ ; | ||
2659 | 253 | (*cc) <<= 1 ; | ||
2660 | 254 | if (lookbit()) (*cc)++ ; | ||
2661 | 255 | } | ||
2662 | 256 | |||
2663 | 257 | /************************** real*4 ************************/ | ||
2664 | 258 | static float adr4buf[512] ; | ||
2665 | 259 | static int adr4ibuf = 0 ; | ||
2666 | 260 | static float adr4lbuf[512] ; | ||
2667 | 261 | static int adr4ilbuf = -1 ; | ||
2668 | 262 | static int adr4inlbuf = 0 ; | ||
2669 | 263 | |||
2670 | 264 | void pushreal4(float x) { | ||
2671 | 265 | addftraffic(4) ; | ||
2672 | 266 | if (adr4ilbuf != -1) { | ||
2673 | 267 | adr4ilbuf = -1 ; | ||
2674 | 268 | adr4inlbuf = 0 ; | ||
2675 | 269 | } | ||
2676 | 270 | if (adr4ibuf >= 511) { | ||
2677 | 271 | adr4buf[511] = x ; | ||
2678 | 272 | pushNarray((char*)adr4buf, 512*4) ; | ||
2679 | 273 | addftraffic(-512*4) ; | ||
2680 | 274 | adr4ibuf = 0 ; | ||
2681 | 275 | } else { | ||
2682 | 276 | adr4buf[adr4ibuf] = x ; | ||
2683 | 277 | ++adr4ibuf ; | ||
2684 | 278 | } | ||
2685 | 279 | } | ||
2686 | 280 | |||
2687 | 281 | void lookreal4(float *x) { | ||
2688 | 282 | if (adr4ilbuf == -1) { | ||
2689 | 283 | adr4ilbuf = adr4ibuf ; | ||
2690 | 284 | resetadlookstack_() ; | ||
2691 | 285 | } | ||
2692 | 286 | if (adr4ilbuf <= 0) { | ||
2693 | 287 | lookNarray((char*)adr4lbuf, 512*4) ; | ||
2694 | 288 | adr4inlbuf = 1 ; | ||
2695 | 289 | adr4ilbuf = 511 ; | ||
2696 | 290 | *x = adr4lbuf[511] ; | ||
2697 | 291 | } else { | ||
2698 | 292 | --adr4ilbuf ; | ||
2699 | 293 | if (adr4inlbuf) | ||
2700 | 294 | *x = adr4lbuf[adr4ilbuf] ; | ||
2701 | 295 | else | ||
2702 | 296 | *x = adr4buf[adr4ilbuf] ; | ||
2703 | 297 | } | ||
2704 | 298 | } | ||
2705 | 299 | |||
2706 | 300 | void popreal4(float *x) { | ||
2707 | 301 | if (adr4ilbuf != -1) { | ||
2708 | 302 | adr4ilbuf = -1 ; | ||
2709 | 303 | adr4inlbuf = 0 ; | ||
2710 | 304 | } | ||
2711 | 305 | if (adr4ibuf <= 0) { | ||
2712 | 306 | popNarray((char*)adr4buf, 512*4) ; | ||
2713 | 307 | adr4ibuf = 511 ; | ||
2714 | 308 | *x = adr4buf[511] ; | ||
2715 | 309 | } else { | ||
2716 | 310 | --adr4ibuf ; | ||
2717 | 311 | *x = adr4buf[adr4ibuf] ; | ||
2718 | 312 | } | ||
2719 | 313 | } | ||
2720 | 314 | |||
2721 | 315 | /************************** real*8 ************************/ | ||
2722 | 316 | static double adr8buf[512] ; | ||
2723 | 317 | static int adr8ibuf = 0 ; | ||
2724 | 318 | static double adr8lbuf[512] ; | ||
2725 | 319 | static int adr8ilbuf = -1 ; | ||
2726 | 320 | static int adr8inlbuf = 0 ; | ||
2727 | 321 | |||
2728 | 322 | void pushreal8(double x) { | ||
2729 | 323 | addftraffic(8) ; | ||
2730 | 324 | if (adr8ilbuf != -1) { | ||
2731 | 325 | adr8ilbuf = -1 ; | ||
2732 | 326 | adr8inlbuf = 0 ; | ||
2733 | 327 | } | ||
2734 | 328 | if (adr8ibuf >= 511) { | ||
2735 | 329 | adr8buf[511] = x ; | ||
2736 | 330 | pushNarray((char*)adr8buf, 512*8) ; | ||
2737 | 331 | addftraffic(-4096) ; | ||
2738 | 332 | adr8ibuf = 0 ; | ||
2739 | 333 | } else { | ||
2740 | 334 | adr8buf[adr8ibuf] = x ; | ||
2741 | 335 | ++adr8ibuf ; | ||
2742 | 336 | } | ||
2743 | 337 | } | ||
2744 | 338 | |||
2745 | 339 | void lookreal8(double *x) { | ||
2746 | 340 | if (adr8ilbuf == -1) { | ||
2747 | 341 | adr8ilbuf = adr8ibuf ; | ||
2748 | 342 | resetadlookstack_() ; | ||
2749 | 343 | } | ||
2750 | 344 | if (adr8ilbuf <= 0) { | ||
2751 | 345 | lookNarray((char*)adr8lbuf, 512*8) ; | ||
2752 | 346 | adr8inlbuf = 1 ; | ||
2753 | 347 | adr8ilbuf = 511 ; | ||
2754 | 348 | *x = adr8lbuf[511] ; | ||
2755 | 349 | } else { | ||
2756 | 350 | --adr8ilbuf ; | ||
2757 | 351 | if (adr8inlbuf) | ||
2758 | 352 | *x = adr8lbuf[adr8ilbuf] ; | ||
2759 | 353 | else | ||
2760 | 354 | *x = adr8buf[adr8ilbuf] ; | ||
2761 | 355 | } | ||
2762 | 356 | } | ||
2763 | 357 | |||
2764 | 358 | void popreal8(double *x) { | ||
2765 | 359 | if (adr8ilbuf != -1) { | ||
2766 | 360 | adr8ilbuf = -1 ; | ||
2767 | 361 | adr8inlbuf = 0 ; | ||
2768 | 362 | } | ||
2769 | 363 | if (adr8ibuf <= 0) { | ||
2770 | 364 | popNarray((char*)adr8buf, 512*8) ; | ||
2771 | 365 | adr8ibuf = 511 ; | ||
2772 | 366 | *x = adr8buf[511] ; | ||
2773 | 367 | } else { | ||
2774 | 368 | --adr8ibuf ; | ||
2775 | 369 | *x = adr8buf[adr8ibuf] ; | ||
2776 | 370 | } | ||
2777 | 371 | } | ||
2778 | 372 | |||
2779 | 373 | /********* PRINTING THE SIZE OF STACKS AND BUFFERS ********/ | ||
2780 | 374 | |||
2781 | 375 | void printbuffertop() { | ||
2782 | 376 | int size = 0 ; | ||
2783 | 377 | size += adi4ibuf*4 ; | ||
2784 | 378 | size += adr4ibuf*4 ; | ||
2785 | 379 | size += adr8ibuf*8 ; | ||
2786 | 380 | printf("Buffer size:%i bytes i.e. %i Kbytes\n", | ||
2787 | 381 | size, (int) (size/1024.0)) ; | ||
2788 | 382 | } | ||
2789 | 383 | |||
2790 | 384 | void showallstacks() { | ||
2791 | 385 | int i ; | ||
2792 | 386 | printf("BIT STACK : %x == %i\n",adbitbuf,adbitbuf) ; | ||
2793 | 387 | printf("INTEGER*4 BUFFER[%i]:",adi4ibuf) ; | ||
2794 | 388 | for (i=0 ; i<adi4ibuf ; ++i) printf(" %i",adi4buf[i]) ; | ||
2795 | 389 | printf("\n") ; | ||
2796 | 390 | printf("REAL*8 BUFFER[%i]:",adr8ibuf) ; | ||
2797 | 391 | for (i=0 ; i<adr8ibuf ; ++i) printf(" %d",(int) adr8buf[i]) ; | ||
2798 | 392 | printf("\n") ; | ||
2799 | 393 | printf("REAL*4 BUFFER[%i]:",adr4ibuf) ; | ||
2800 | 394 | for (i=0 ; i<adr4ibuf ; ++i) printf(" %f",adr4buf[i]) ; | ||
2801 | 395 | printf("\n") ; | ||
2802 | 396 | showrecentcstack_() ; | ||
2803 | 397 | } | ||
2804 | 398 | |||
2805 | 399 | /********************************************************** | ||
2806 | 400 | * HOW TO CREATE PUSH* LOOK* POP* SUBROUTINES | ||
2807 | 401 | * YET FOR OTHER DATA TYPES | ||
2808 | 402 | * Duplicate and uncomment the commented code below. | ||
2809 | 403 | * In the duplicated code, replace: | ||
2810 | 404 | * ctct -> C type name (e.g. float double, int...) | ||
2811 | 405 | * TTTT -> BASIC TAPENADE TYPE NAME | ||
2812 | 406 | * (in character, boolean, integer, real, complex, pointer,...) | ||
2813 | 407 | * z7 -> LETTER-SIZE FOR TYPE | ||
2814 | 408 | * (in s, b, i, r, c, p, ...) | ||
2815 | 409 | * 7 -> TYPE SIZE IN BYTES | ||
2816 | 410 | * Don't forget to insert the corresponding lines in | ||
2817 | 411 | * procedure printbuffertop(), otherwise the contribution of | ||
2818 | 412 | * this new type to buffer occupation will not be seen. | ||
2819 | 413 | * (not very important anyway...) | ||
2820 | 414 | **********************************************************/ | ||
2821 | 415 | |||
2822 | 416 | /************************** TTTT*7 ************************/ | ||
2823 | 417 | /* | ||
2824 | 418 | static ctct adz7buf[512] ; | ||
2825 | 419 | static int adz7ibuf = 0 ; | ||
2826 | 420 | static ctct adz7lbuf[512] ; | ||
2827 | 421 | static int adz7ilbuf = -1 ; | ||
2828 | 422 | static int adz7inlbuf = 0 ; | ||
2829 | 423 | |||
2830 | 424 | void pushTTTT7(ctct x) { | ||
2831 | 425 | addftraffic(7) ; | ||
2832 | 426 | if (adz7ilbuf != -1) { | ||
2833 | 427 | adz7ilbuf = -1 ; | ||
2834 | 428 | adz7inlbuf = 0 ; | ||
2835 | 429 | } | ||
2836 | 430 | if (adz7ibuf >= 511) { | ||
2837 | 431 | adz7buf[511] = x ; | ||
2838 | 432 | pushNarray((char*)adz7buf, 512*7) ; | ||
2839 | 433 | addftraffic(-512*7) ; | ||
2840 | 434 | adz7ibuf = 0 ; | ||
2841 | 435 | } else { | ||
2842 | 436 | adz7buf[adz7ibuf] = x ; | ||
2843 | 437 | ++adz7ibuf ; | ||
2844 | 438 | } | ||
2845 | 439 | } | ||
2846 | 440 | |||
2847 | 441 | void lookTTTT7(ctct *x) { | ||
2848 | 442 | if (adz7ilbuf == -1) { | ||
2849 | 443 | adz7ilbuf = adz7ibuf ; | ||
2850 | 444 | resetadlookstack_() ; | ||
2851 | 445 | } | ||
2852 | 446 | if (adz7ilbuf <= 0) { | ||
2853 | 447 | lookNarray((char*)adz7lbuf, 512*7) ; | ||
2854 | 448 | adz7inlbuf = 1 ; | ||
2855 | 449 | adz7ilbuf = 511 ; | ||
2856 | 450 | *x = adz7lbuf[511] ; | ||
2857 | 451 | } else { | ||
2858 | 452 | --adz7ilbuf ; | ||
2859 | 453 | if (adz7inlbuf) | ||
2860 | 454 | *x = adz7lbuf[adz7ilbuf] ; | ||
2861 | 455 | else | ||
2862 | 456 | *x = adz7buf[adz7ilbuf] ; | ||
2863 | 457 | } | ||
2864 | 458 | } | ||
2865 | 459 | |||
2866 | 460 | void popTTTT7(ctct *x) { | ||
2867 | 461 | if (adz7ilbuf != -1) { | ||
2868 | 462 | adz7ilbuf = -1 ; | ||
2869 | 463 | adz7inlbuf = 0 ; | ||
2870 | 464 | } | ||
2871 | 465 | if (adz7ibuf <= 0) { | ||
2872 | 466 | popNarray((char*)adz7buf, 512*7) ; | ||
2873 | 467 | adz7ibuf = 511 ; | ||
2874 | 468 | *x = adz7buf[511] ; | ||
2875 | 469 | } else { | ||
2876 | 470 | --adz7ibuf ; | ||
2877 | 471 | *x = adz7buf[adz7ibuf] ; | ||
2878 | 472 | } | ||
2879 | 473 | } | ||
2880 | 474 | */ | ||
2881 | 475 | |||
2882 | 476 | /**********************************************************/ | ||
2883 | 0 | 477 | ||
2884 | === added file 'adjoint/adBufferFortran.f' | |||
2885 | --- adjoint/adBufferFortran.f 1970-01-01 00:00:00 +0000 | |||
2886 | +++ adjoint/adBufferFortran.f 2011-07-12 15:56:32 +0000 | |||
2887 | @@ -0,0 +1,1848 @@ | |||
2888 | 1 | C$Id: adBuffer.f 3922 2011-05-19 08:54:39Z llh $ | ||
2889 | 2 | |||
2890 | 3 | c PISTES D'AMELIORATIONS: | ||
2891 | 4 | c Attention aux IF qui peuvent couter cher. | ||
2892 | 5 | c On pourrait aussi bufferiser les bits avec N entiers, | ||
2893 | 6 | c (1 bit par entier), passer tout le paquet a C et laisser | ||
2894 | 7 | c C faire les jongleries de bitsets. | ||
2895 | 8 | c On pourrait aussi optimiser en -O3 les primitives de ADFirstAidKit | ||
2896 | 9 | c Regarder l'assembleur (option -S (et -o toto.s)) | ||
2897 | 10 | c Pourchasser les divisions! | ||
2898 | 11 | |||
2899 | 12 | BLOCK DATA LOOKINGORNOT | ||
2900 | 13 | LOGICAL looking | ||
2901 | 14 | COMMON /lookingfbuf/looking | ||
2902 | 15 | DATA looking/.FALSE./ | ||
2903 | 16 | END | ||
2904 | 17 | |||
2905 | 18 | c======================== BITS ==========================: | ||
2906 | 19 | BLOCK DATA BITS | ||
2907 | 20 | INTEGER*4 adbitbuf, adbitlbuf | ||
2908 | 21 | INTEGER adbitibuf, adbitilbuf | ||
2909 | 22 | LOGICAL adbitinlbuf | ||
2910 | 23 | COMMON /adbitfbuf/adbitbuf,adbitlbuf, | ||
2911 | 24 | + adbitibuf,adbitilbuf,adbitinlbuf | ||
2912 | 25 | DATA adbitbuf/0/ | ||
2913 | 26 | DATA adbitlbuf/0/ | ||
2914 | 27 | DATA adbitibuf/0/ | ||
2915 | 28 | DATA adbitilbuf/-1/ | ||
2916 | 29 | DATA adbitinlbuf/.FALSE./ | ||
2917 | 30 | END | ||
2918 | 31 | |||
2919 | 32 | c [0,31] are the bit indices we can use in an INTEGER | ||
2920 | 33 | |||
2921 | 34 | SUBROUTINE PUSHBIT(bit) | ||
2922 | 35 | LOGICAL bit | ||
2923 | 36 | INTEGER*4 adbitbuf, adbitlbuf | ||
2924 | 37 | INTEGER adbitibuf, adbitilbuf | ||
2925 | 38 | LOGICAL adbitinlbuf | ||
2926 | 39 | COMMON /adbitfbuf/adbitbuf,adbitlbuf, | ||
2927 | 40 | + adbitibuf,adbitilbuf,adbitinlbuf | ||
2928 | 41 | LOGICAL looking | ||
2929 | 42 | COMMON /lookingfbuf/looking | ||
2930 | 43 | c | ||
2931 | 44 | IF (adbitilbuf.ne.-1) THEN | ||
2932 | 45 | adbitilbuf = -1 | ||
2933 | 46 | adbitinlbuf = .FALSE. | ||
2934 | 47 | looking = .FALSE. | ||
2935 | 48 | ENDIF | ||
2936 | 49 | IF (bit) THEN | ||
2937 | 50 | adbitbuf = IBSET(adbitbuf, adbitibuf) | ||
2938 | 51 | ELSE | ||
2939 | 52 | adbitbuf = IBCLR(adbitbuf, adbitibuf) | ||
2940 | 53 | ENDIF | ||
2941 | 54 | IF (adbitibuf.ge.31) THEN | ||
2942 | 55 | CALL PUSHINTEGER4(adbitbuf) | ||
2943 | 56 | adbitbuf = 0 | ||
2944 | 57 | adbitibuf = 0 | ||
2945 | 58 | ELSE | ||
2946 | 59 | adbitibuf = adbitibuf+1 | ||
2947 | 60 | ENDIF | ||
2948 | 61 | END | ||
2949 | 62 | |||
2950 | 63 | LOGICAL FUNCTION LOOKBIT() | ||
2951 | 64 | INTEGER*4 adbitbuf, adbitlbuf | ||
2952 | 65 | INTEGER adbitibuf, adbitilbuf | ||
2953 | 66 | LOGICAL adbitinlbuf | ||
2954 | 67 | COMMON /adbitfbuf/adbitbuf,adbitlbuf, | ||
2955 | 68 | + adbitibuf,adbitilbuf,adbitinlbuf | ||
2956 | 69 | LOGICAL looking | ||
2957 | 70 | COMMON /lookingfbuf/looking | ||
2958 | 71 | c | ||
2959 | 72 | IF (adbitilbuf.eq.-1) THEN | ||
2960 | 73 | adbitilbuf=adbitibuf | ||
2961 | 74 | adbitlbuf = adbitbuf | ||
2962 | 75 | IF (.not.looking) THEN | ||
2963 | 76 | CALL RESETADLOOKSTACK() | ||
2964 | 77 | looking = .TRUE. | ||
2965 | 78 | ENDIF | ||
2966 | 79 | ENDIF | ||
2967 | 80 | IF (adbitilbuf.le.0) THEN | ||
2968 | 81 | CALL LOOKINTEGER4(adbitlbuf) | ||
2969 | 82 | adbitilbuf = 31 | ||
2970 | 83 | ELSE | ||
2971 | 84 | adbitilbuf = adbitilbuf-1 | ||
2972 | 85 | ENDIF | ||
2973 | 86 | LOOKBIT = BTEST(adbitlbuf, adbitilbuf) | ||
2974 | 87 | END | ||
2975 | 88 | |||
2976 | 89 | LOGICAL FUNCTION POPBIT() | ||
2977 | 90 | INTEGER*4 adbitbuf, adbitlbuf | ||
2978 | 91 | INTEGER adbitibuf, adbitilbuf | ||
2979 | 92 | LOGICAL adbitinlbuf | ||
2980 | 93 | COMMON /adbitfbuf/adbitbuf,adbitlbuf, | ||
2981 | 94 | + adbitibuf,adbitilbuf,adbitinlbuf | ||
2982 | 95 | LOGICAL looking | ||
2983 | 96 | COMMON /lookingfbuf/looking | ||
2984 | 97 | c | ||
2985 | 98 | IF (adbitilbuf.ne.-1) THEN | ||
2986 | 99 | adbitilbuf = -1 | ||
2987 | 100 | adbitinlbuf = .FALSE. | ||
2988 | 101 | looking = .FALSE. | ||
2989 | 102 | ENDIF | ||
2990 | 103 | IF (adbitibuf.le.0) THEN | ||
2991 | 104 | CALL POPINTEGER4(adbitbuf) | ||
2992 | 105 | adbitibuf = 31 | ||
2993 | 106 | ELSE | ||
2994 | 107 | adbitibuf = adbitibuf-1 | ||
2995 | 108 | ENDIF | ||
2996 | 109 | POPBIT = BTEST(adbitbuf, adbitibuf) | ||
2997 | 110 | END | ||
2998 | 111 | |||
2999 | 112 | c====================== CONTROL =========================: | ||
3000 | 113 | |||
3001 | 114 | SUBROUTINE PUSHCONTROL1B(cc) | ||
3002 | 115 | INTEGER cc | ||
3003 | 116 | CALL PUSHBIT(cc.ne.0) | ||
3004 | 117 | END | ||
3005 | 118 | |||
3006 | 119 | SUBROUTINE POPCONTROL1B(cc) | ||
3007 | 120 | INTEGER cc | ||
3008 | 121 | LOGICAL POPBIT | ||
3009 | 122 | IF (POPBIT()) THEN | ||
3010 | 123 | cc = 1 | ||
3011 | 124 | ELSE | ||
3012 | 125 | cc = 0 | ||
3013 | 126 | ENDIF | ||
3014 | 127 | END | ||
3015 | 128 | |||
3016 | 129 | SUBROUTINE LOOKCONTROL1B(cc) | ||
3017 | 130 | INTEGER cc | ||
3018 | 131 | LOGICAL LOOKBIT | ||
3019 | 132 | IF (LOOKBIT()) THEN | ||
3020 | 133 | cc = 1 | ||
3021 | 134 | ELSE | ||
3022 | 135 | cc = 0 | ||
3023 | 136 | ENDIF | ||
3024 | 137 | END | ||
3025 | 138 | |||
3026 | 139 | SUBROUTINE PUSHCONTROL2B(cc) | ||
3027 | 140 | INTEGER cc | ||
3028 | 141 | CALL PUSHBIT(BTEST(cc,0)) | ||
3029 | 142 | CALL PUSHBIT(BTEST(cc,1)) | ||
3030 | 143 | END | ||
3031 | 144 | |||
3032 | 145 | SUBROUTINE POPCONTROL2B(cc) | ||
3033 | 146 | INTEGER cc | ||
3034 | 147 | LOGICAL POPBIT | ||
3035 | 148 | IF (POPBIT()) THEN | ||
3036 | 149 | cc = 2 | ||
3037 | 150 | ELSE | ||
3038 | 151 | cc = 0 | ||
3039 | 152 | ENDIF | ||
3040 | 153 | IF (POPBIT()) cc = IBSET(cc,0) | ||
3041 | 154 | END | ||
3042 | 155 | |||
3043 | 156 | SUBROUTINE LOOKCONTROL2B(cc) | ||
3044 | 157 | INTEGER cc | ||
3045 | 158 | LOGICAL LOOKBIT | ||
3046 | 159 | IF (LOOKBIT()) THEN | ||
3047 | 160 | cc = 2 | ||
3048 | 161 | ELSE | ||
3049 | 162 | cc = 0 | ||
3050 | 163 | ENDIF | ||
3051 | 164 | IF (LOOKBIT()) cc = IBSET(cc,0) | ||
3052 | 165 | END | ||
3053 | 166 | |||
3054 | 167 | SUBROUTINE PUSHCONTROL3B(cc) | ||
3055 | 168 | INTEGER cc | ||
3056 | 169 | CALL PUSHBIT(BTEST(cc,0)) | ||
3057 | 170 | CALL PUSHBIT(BTEST(cc,1)) | ||
3058 | 171 | CALL PUSHBIT(BTEST(cc,2)) | ||
3059 | 172 | END | ||
3060 | 173 | |||
3061 | 174 | SUBROUTINE POPCONTROL3B(cc) | ||
3062 | 175 | INTEGER cc | ||
3063 | 176 | LOGICAL POPBIT | ||
3064 | 177 | IF (POPBIT()) THEN | ||
3065 | 178 | cc = 4 | ||
3066 | 179 | ELSE | ||
3067 | 180 | cc = 0 | ||
3068 | 181 | ENDIF | ||
3069 | 182 | IF (POPBIT()) cc = IBSET(cc,1) | ||
3070 | 183 | IF (POPBIT()) cc = IBSET(cc,0) | ||
3071 | 184 | END | ||
3072 | 185 | |||
3073 | 186 | SUBROUTINE LOOKCONTROL3B(cc) | ||
3074 | 187 | INTEGER cc | ||
3075 | 188 | LOGICAL LOOKBIT | ||
3076 | 189 | IF (LOOKBIT()) THEN | ||
3077 | 190 | cc = 4 | ||
3078 | 191 | ELSE | ||
3079 | 192 | cc = 0 | ||
3080 | 193 | ENDIF | ||
3081 | 194 | IF (LOOKBIT()) cc = IBSET(cc,1) | ||
3082 | 195 | IF (LOOKBIT()) cc = IBSET(cc,0) | ||
3083 | 196 | END | ||
3084 | 197 | |||
3085 | 198 | SUBROUTINE PUSHCONTROL4B(cc) | ||
3086 | 199 | INTEGER cc | ||
3087 | 200 | CALL PUSHBIT(BTEST(cc,0)) | ||
3088 | 201 | CALL PUSHBIT(BTEST(cc,1)) | ||
3089 | 202 | CALL PUSHBIT(BTEST(cc,2)) | ||
3090 | 203 | CALL PUSHBIT(BTEST(cc,3)) | ||
3091 | 204 | END | ||
3092 | 205 | |||
3093 | 206 | SUBROUTINE POPCONTROL4B(cc) | ||
3094 | 207 | INTEGER cc | ||
3095 | 208 | LOGICAL POPBIT | ||
3096 | 209 | IF (POPBIT()) THEN | ||
3097 | 210 | cc = 8 | ||
3098 | 211 | ELSE | ||
3099 | 212 | cc = 0 | ||
3100 | 213 | ENDIF | ||
3101 | 214 | IF (POPBIT()) cc = IBSET(cc,2) | ||
3102 | 215 | IF (POPBIT()) cc = IBSET(cc,1) | ||
3103 | 216 | IF (POPBIT()) cc = IBSET(cc,0) | ||
3104 | 217 | END | ||
3105 | 218 | |||
3106 | 219 | SUBROUTINE LOOKCONTROL4B(cc) | ||
3107 | 220 | INTEGER cc | ||
3108 | 221 | LOGICAL LOOKBIT | ||
3109 | 222 | IF (LOOKBIT()) THEN | ||
3110 | 223 | cc = 8 | ||
3111 | 224 | ELSE | ||
3112 | 225 | cc = 0 | ||
3113 | 226 | ENDIF | ||
3114 | 227 | IF (LOOKBIT()) cc = IBSET(cc,2) | ||
3115 | 228 | IF (LOOKBIT()) cc = IBSET(cc,1) | ||
3116 | 229 | IF (LOOKBIT()) cc = IBSET(cc,0) | ||
3117 | 230 | END | ||
3118 | 231 | |||
3119 | 232 | SUBROUTINE PUSHCONTROL5B(cc) | ||
3120 | 233 | INTEGER cc | ||
3121 | 234 | CALL PUSHBIT(BTEST(cc,0)) | ||
3122 | 235 | CALL PUSHBIT(BTEST(cc,1)) | ||
3123 | 236 | CALL PUSHBIT(BTEST(cc,2)) | ||
3124 | 237 | CALL PUSHBIT(BTEST(cc,3)) | ||
3125 | 238 | CALL PUSHBIT(BTEST(cc,4)) | ||
3126 | 239 | END | ||
3127 | 240 | |||
3128 | 241 | SUBROUTINE POPCONTROL5B(cc) | ||
3129 | 242 | INTEGER cc | ||
3130 | 243 | LOGICAL POPBIT | ||
3131 | 244 | IF (POPBIT()) THEN | ||
3132 | 245 | cc = 16 | ||
3133 | 246 | ELSE | ||
3134 | 247 | cc = 0 | ||
3135 | 248 | ENDIF | ||
3136 | 249 | IF (POPBIT()) cc = IBSET(cc,3) | ||
3137 | 250 | IF (POPBIT()) cc = IBSET(cc,2) | ||
3138 | 251 | IF (POPBIT()) cc = IBSET(cc,1) | ||
3139 | 252 | IF (POPBIT()) cc = IBSET(cc,0) | ||
3140 | 253 | END | ||
3141 | 254 | |||
3142 | 255 | SUBROUTINE LOOKCONTROL5B(cc) | ||
3143 | 256 | INTEGER cc | ||
3144 | 257 | LOGICAL LOOKBIT | ||
3145 | 258 | IF (LOOKBIT()) THEN | ||
3146 | 259 | cc = 16 | ||
3147 | 260 | ELSE | ||
3148 | 261 | cc = 0 | ||
3149 | 262 | ENDIF | ||
3150 | 263 | IF (LOOKBIT()) cc = IBSET(cc,3) | ||
3151 | 264 | IF (LOOKBIT()) cc = IBSET(cc,2) | ||
3152 | 265 | IF (LOOKBIT()) cc = IBSET(cc,1) | ||
3153 | 266 | IF (LOOKBIT()) cc = IBSET(cc,0) | ||
3154 | 267 | END | ||
3155 | 268 | |||
3156 | 269 | c======================= BOOLEANS ========================= | ||
3157 | 270 | |||
3158 | 271 | SUBROUTINE PUSHBOOLEAN(x) | ||
3159 | 272 | LOGICAL x | ||
3160 | 273 | CALL PUSHBIT(x) | ||
3161 | 274 | END | ||
3162 | 275 | |||
3163 | 276 | SUBROUTINE LOOKBOOLEAN(x) | ||
3164 | 277 | LOGICAL x, LOOKBIT | ||
3165 | 278 | x = LOOKBIT() | ||
3166 | 279 | END | ||
3167 | 280 | |||
3168 | 281 | SUBROUTINE POPBOOLEAN(x) | ||
3169 | 282 | LOGICAL x, POPBIT | ||
3170 | 283 | x = POPBIT() | ||
3171 | 284 | END | ||
3172 | 285 | |||
3173 | 286 | c===================== CHARACTERS =======================: | ||
3174 | 287 | BLOCK DATA CHARACTERS | ||
3175 | 288 | CHARACTER ads1buf(512), ads1lbuf(512) | ||
3176 | 289 | INTEGER ads1ibuf,ads1ilbuf | ||
3177 | 290 | LOGICAL ads1inlbuf | ||
3178 | 291 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
3179 | 292 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
3180 | 293 | DATA ads1ibuf/1/ | ||
3181 | 294 | DATA ads1ilbuf/-1/ | ||
3182 | 295 | DATA ads1inlbuf/.FALSE./ | ||
3183 | 296 | END | ||
3184 | 297 | |||
3185 | 298 | SUBROUTINE PUSHCHARACTER(x) | ||
3186 | 299 | CHARACTER x, ads1buf(512), ads1lbuf(512) | ||
3187 | 300 | INTEGER ads1ibuf,ads1ilbuf | ||
3188 | 301 | LOGICAL ads1inlbuf | ||
3189 | 302 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
3190 | 303 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
3191 | 304 | LOGICAL looking | ||
3192 | 305 | COMMON /lookingfbuf/looking | ||
3193 | 306 | c | ||
3194 | 307 | CALL addftraffic(1) | ||
3195 | 308 | IF (ads1ilbuf.ne.-1) THEN | ||
3196 | 309 | ads1ilbuf = -1 | ||
3197 | 310 | ads1inlbuf = .FALSE. | ||
3198 | 311 | looking = .FALSE. | ||
3199 | 312 | ENDIF | ||
3200 | 313 | IF (ads1ibuf.ge.512) THEN | ||
3201 | 314 | ads1buf(512) = x | ||
3202 | 315 | CALL PUSHCHARACTERARRAY(ads1buf, 512) | ||
3203 | 316 | CALL addftraffic(-512) | ||
3204 | 317 | ads1ibuf = 1 | ||
3205 | 318 | ELSE | ||
3206 | 319 | ads1buf(ads1ibuf) = x | ||
3207 | 320 | ads1ibuf = ads1ibuf+1 | ||
3208 | 321 | ENDIF | ||
3209 | 322 | END | ||
3210 | 323 | |||
3211 | 324 | SUBROUTINE LOOKCHARACTER(x) | ||
3212 | 325 | CHARACTER x, ads1buf(512), ads1lbuf(512) | ||
3213 | 326 | INTEGER ads1ibuf,ads1ilbuf | ||
3214 | 327 | LOGICAL ads1inlbuf | ||
3215 | 328 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
3216 | 329 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
3217 | 330 | LOGICAL looking | ||
3218 | 331 | COMMON /lookingfbuf/looking | ||
3219 | 332 | c | ||
3220 | 333 | IF (ads1ilbuf.eq.-1) THEN | ||
3221 | 334 | ads1ilbuf=ads1ibuf | ||
3222 | 335 | IF (.not.looking) THEN | ||
3223 | 336 | CALL RESETADLOOKSTACK() | ||
3224 | 337 | looking = .TRUE. | ||
3225 | 338 | ENDIF | ||
3226 | 339 | ENDIF | ||
3227 | 340 | IF (ads1ilbuf.le.1) THEN | ||
3228 | 341 | CALL LOOKCHARACTERARRAY(ads1lbuf, 512) | ||
3229 | 342 | ads1inlbuf = .TRUE. | ||
3230 | 343 | ads1ilbuf = 512 | ||
3231 | 344 | x = ads1lbuf(512) | ||
3232 | 345 | ELSE | ||
3233 | 346 | ads1ilbuf = ads1ilbuf-1 | ||
3234 | 347 | if (ads1inlbuf) THEN | ||
3235 | 348 | x = ads1lbuf(ads1ilbuf) | ||
3236 | 349 | ELSE | ||
3237 | 350 | x = ads1buf(ads1ilbuf) | ||
3238 | 351 | ENDIF | ||
3239 | 352 | ENDIF | ||
3240 | 353 | END | ||
3241 | 354 | |||
3242 | 355 | SUBROUTINE POPCHARACTER(x) | ||
3243 | 356 | CHARACTER x, ads1buf(512), ads1lbuf(512) | ||
3244 | 357 | INTEGER ads1ibuf,ads1ilbuf | ||
3245 | 358 | LOGICAL ads1inlbuf | ||
3246 | 359 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
3247 | 360 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
3248 | 361 | LOGICAL looking | ||
3249 | 362 | COMMON /lookingfbuf/looking | ||
3250 | 363 | c | ||
3251 | 364 | IF (ads1ilbuf.ne.-1) THEN | ||
3252 | 365 | ads1ilbuf = -1 | ||
3253 | 366 | ads1inlbuf = .FALSE. | ||
3254 | 367 | looking = .FALSE. | ||
3255 | 368 | ENDIF | ||
3256 | 369 | IF (ads1ibuf.le.1) THEN | ||
3257 | 370 | CALL POPCHARACTERARRAY(ads1buf, 512) | ||
3258 | 371 | ads1ibuf = 512 | ||
3259 | 372 | x = ads1buf(512) | ||
3260 | 373 | ELSE | ||
3261 | 374 | ads1ibuf = ads1ibuf-1 | ||
3262 | 375 | x = ads1buf(ads1ibuf) | ||
3263 | 376 | ENDIF | ||
3264 | 377 | END | ||
3265 | 378 | |||
3266 | 379 | c======================= INTEGER*4 =========================: | ||
3267 | 380 | BLOCK DATA INTEGERS4 | ||
3268 | 381 | INTEGER*4 adi4buf(512), adi4lbuf(512) | ||
3269 | 382 | INTEGER adi4ibuf,adi4ilbuf | ||
3270 | 383 | LOGICAL adi4inlbuf | ||
3271 | 384 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
3272 | 385 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
3273 | 386 | DATA adi4ibuf/1/ | ||
3274 | 387 | DATA adi4ilbuf/-1/ | ||
3275 | 388 | DATA adi4inlbuf/.FALSE./ | ||
3276 | 389 | END | ||
3277 | 390 | |||
3278 | 391 | SUBROUTINE PUSHINTEGER4(x) | ||
3279 | 392 | INTEGER*4 x, adi4buf(512), adi4lbuf(512) | ||
3280 | 393 | INTEGER adi4ibuf,adi4ilbuf | ||
3281 | 394 | LOGICAL adi4inlbuf | ||
3282 | 395 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
3283 | 396 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
3284 | 397 | LOGICAL looking | ||
3285 | 398 | COMMON /lookingfbuf/looking | ||
3286 | 399 | c | ||
3287 | 400 | CALL addftraffic(4) | ||
3288 | 401 | IF (adi4ilbuf.ne.-1) THEN | ||
3289 | 402 | adi4ilbuf = -1 | ||
3290 | 403 | adi4inlbuf = .FALSE. | ||
3291 | 404 | looking = .FALSE. | ||
3292 | 405 | ENDIF | ||
3293 | 406 | IF (adi4ibuf.ge.512) THEN | ||
3294 | 407 | adi4buf(512) = x | ||
3295 | 408 | CALL PUSHINTEGER4ARRAY(adi4buf, 512) | ||
3296 | 409 | CALL addftraffic(-2048) | ||
3297 | 410 | adi4ibuf = 1 | ||
3298 | 411 | ELSE | ||
3299 | 412 | adi4buf(adi4ibuf) = x | ||
3300 | 413 | adi4ibuf = adi4ibuf+1 | ||
3301 | 414 | ENDIF | ||
3302 | 415 | END | ||
3303 | 416 | |||
3304 | 417 | SUBROUTINE LOOKINTEGER4(x) | ||
3305 | 418 | INTEGER*4 x, adi4buf(512), adi4lbuf(512) | ||
3306 | 419 | INTEGER adi4ibuf,adi4ilbuf | ||
3307 | 420 | LOGICAL adi4inlbuf | ||
3308 | 421 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
3309 | 422 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
3310 | 423 | LOGICAL looking | ||
3311 | 424 | COMMON /lookingfbuf/looking | ||
3312 | 425 | c | ||
3313 | 426 | IF (adi4ilbuf.eq.-1) THEN | ||
3314 | 427 | adi4ilbuf=adi4ibuf | ||
3315 | 428 | IF (.not.looking) THEN | ||
3316 | 429 | CALL RESETADLOOKSTACK() | ||
3317 | 430 | looking = .TRUE. | ||
3318 | 431 | ENDIF | ||
3319 | 432 | ENDIF | ||
3320 | 433 | IF (adi4ilbuf.le.1) THEN | ||
3321 | 434 | CALL LOOKINTEGER4ARRAY(adi4lbuf, 512) | ||
3322 | 435 | adi4inlbuf = .TRUE. | ||
3323 | 436 | adi4ilbuf = 512 | ||
3324 | 437 | x = adi4lbuf(512) | ||
3325 | 438 | ELSE | ||
3326 | 439 | adi4ilbuf = adi4ilbuf-1 | ||
3327 | 440 | if (adi4inlbuf) THEN | ||
3328 | 441 | x = adi4lbuf(adi4ilbuf) | ||
3329 | 442 | ELSE | ||
3330 | 443 | x = adi4buf(adi4ilbuf) | ||
3331 | 444 | ENDIF | ||
3332 | 445 | ENDIF | ||
3333 | 446 | END | ||
3334 | 447 | |||
3335 | 448 | SUBROUTINE POPINTEGER4(x) | ||
3336 | 449 | INTEGER*4 x, adi4buf(512), adi4lbuf(512) | ||
3337 | 450 | INTEGER adi4ibuf,adi4ilbuf | ||
3338 | 451 | LOGICAL adi4inlbuf | ||
3339 | 452 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
3340 | 453 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
3341 | 454 | LOGICAL looking | ||
3342 | 455 | COMMON /lookingfbuf/looking | ||
3343 | 456 | c | ||
3344 | 457 | IF (adi4ilbuf.ne.-1) THEN | ||
3345 | 458 | adi4ilbuf = -1 | ||
3346 | 459 | adi4inlbuf = .FALSE. | ||
3347 | 460 | looking = .FALSE. | ||
3348 | 461 | ENDIF | ||
3349 | 462 | IF (adi4ibuf.le.1) THEN | ||
3350 | 463 | CALL POPINTEGER4ARRAY(adi4buf, 512) | ||
3351 | 464 | adi4ibuf = 512 | ||
3352 | 465 | x = adi4buf(512) | ||
3353 | 466 | ELSE | ||
3354 | 467 | adi4ibuf = adi4ibuf-1 | ||
3355 | 468 | x = adi4buf(adi4ibuf) | ||
3356 | 469 | ENDIF | ||
3357 | 470 | END | ||
3358 | 471 | |||
3359 | 472 | c======================= INTEGER*8 ========================= | ||
3360 | 473 | BLOCK DATA INTEGERS8 | ||
3361 | 474 | INTEGER*8 adi8buf(512), adi8lbuf(512) | ||
3362 | 475 | INTEGER adi8ibuf,adi8ilbuf | ||
3363 | 476 | LOGICAL adi8inlbuf | ||
3364 | 477 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
3365 | 478 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
3366 | 479 | DATA adi8ibuf/1/ | ||
3367 | 480 | DATA adi8ilbuf/-1/ | ||
3368 | 481 | DATA adi8inlbuf/.FALSE./ | ||
3369 | 482 | END | ||
3370 | 483 | |||
3371 | 484 | SUBROUTINE PUSHINTEGER8(x) | ||
3372 | 485 | INTEGER*8 x, adi8buf(512), adi8lbuf(512) | ||
3373 | 486 | INTEGER adi8ibuf,adi8ilbuf | ||
3374 | 487 | LOGICAL adi8inlbuf | ||
3375 | 488 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
3376 | 489 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
3377 | 490 | LOGICAL looking | ||
3378 | 491 | COMMON /lookingfbuf/looking | ||
3379 | 492 | c | ||
3380 | 493 | CALL addftraffic(8) | ||
3381 | 494 | IF (adi8ilbuf.ne.-1) THEN | ||
3382 | 495 | adi8ilbuf = -1 | ||
3383 | 496 | adi8inlbuf = .FALSE. | ||
3384 | 497 | looking = .FALSE. | ||
3385 | 498 | ENDIF | ||
3386 | 499 | IF (adi8ibuf.ge.512) THEN | ||
3387 | 500 | adi8buf(512) = x | ||
3388 | 501 | CALL PUSHINTEGER8ARRAY(adi8buf, 512) | ||
3389 | 502 | CALL addftraffic(-4096) | ||
3390 | 503 | adi8ibuf = 1 | ||
3391 | 504 | ELSE | ||
3392 | 505 | adi8buf(adi8ibuf) = x | ||
3393 | 506 | adi8ibuf = adi8ibuf+1 | ||
3394 | 507 | ENDIF | ||
3395 | 508 | END | ||
3396 | 509 | |||
3397 | 510 | SUBROUTINE LOOKINTEGER8(x) | ||
3398 | 511 | INTEGER*8 x, adi8buf(512), adi8lbuf(512) | ||
3399 | 512 | INTEGER adi8ibuf,adi8ilbuf | ||
3400 | 513 | LOGICAL adi8inlbuf | ||
3401 | 514 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
3402 | 515 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
3403 | 516 | LOGICAL looking | ||
3404 | 517 | COMMON /lookingfbuf/looking | ||
3405 | 518 | c | ||
3406 | 519 | IF (adi8ilbuf.eq.-1) THEN | ||
3407 | 520 | adi8ilbuf=adi8ibuf | ||
3408 | 521 | IF (.not.looking) THEN | ||
3409 | 522 | CALL RESETADLOOKSTACK() | ||
3410 | 523 | looking = .TRUE. | ||
3411 | 524 | ENDIF | ||
3412 | 525 | ENDIF | ||
3413 | 526 | IF (adi8ilbuf.le.1) THEN | ||
3414 | 527 | CALL LOOKINTEGER8ARRAY(adi8lbuf, 512) | ||
3415 | 528 | adi8inlbuf = .TRUE. | ||
3416 | 529 | adi8ilbuf = 512 | ||
3417 | 530 | x = adi8lbuf(512) | ||
3418 | 531 | ELSE | ||
3419 | 532 | adi8ilbuf = adi8ilbuf-1 | ||
3420 | 533 | if (adi8inlbuf) THEN | ||
3421 | 534 | x = adi8lbuf(adi8ilbuf) | ||
3422 | 535 | ELSE | ||
3423 | 536 | x = adi8buf(adi8ilbuf) | ||
3424 | 537 | ENDIF | ||
3425 | 538 | ENDIF | ||
3426 | 539 | END | ||
3427 | 540 | |||
3428 | 541 | SUBROUTINE POPINTEGER8(x) | ||
3429 | 542 | INTEGER*8 x, adi8buf(512), adi8lbuf(512) | ||
3430 | 543 | INTEGER adi8ibuf,adi8ilbuf | ||
3431 | 544 | LOGICAL adi8inlbuf | ||
3432 | 545 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
3433 | 546 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
3434 | 547 | LOGICAL looking | ||
3435 | 548 | COMMON /lookingfbuf/looking | ||
3436 | 549 | c | ||
3437 | 550 | IF (adi8ilbuf.ne.-1) THEN | ||
3438 | 551 | adi8ilbuf = -1 | ||
3439 | 552 | adi8inlbuf = .FALSE. | ||
3440 | 553 | looking = .FALSE. | ||
3441 | 554 | ENDIF | ||
3442 | 555 | IF (adi8ibuf.le.1) THEN | ||
3443 | 556 | CALL POPINTEGER8ARRAY(adi8buf, 512) | ||
3444 | 557 | adi8ibuf = 512 | ||
3445 | 558 | x = adi8buf(512) | ||
3446 | 559 | ELSE | ||
3447 | 560 | adi8ibuf = adi8ibuf-1 | ||
3448 | 561 | x = adi8buf(adi8ibuf) | ||
3449 | 562 | ENDIF | ||
3450 | 563 | END | ||
3451 | 564 | |||
3452 | 565 | c======================= REAL*4 ========================= | ||
3453 | 566 | BLOCK DATA REALS4 | ||
3454 | 567 | REAL*4 adr4buf(512), adr4lbuf(512) | ||
3455 | 568 | INTEGER adr4ibuf,adr4ilbuf | ||
3456 | 569 | LOGICAL adr4inlbuf | ||
3457 | 570 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
3458 | 571 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
3459 | 572 | DATA adr4ibuf/1/ | ||
3460 | 573 | DATA adr4ilbuf/-1/ | ||
3461 | 574 | DATA adr4inlbuf/.FALSE./ | ||
3462 | 575 | END | ||
3463 | 576 | |||
3464 | 577 | SUBROUTINE PUSHREAL4(x) | ||
3465 | 578 | REAL*4 x, adr4buf(512), adr4lbuf(512) | ||
3466 | 579 | INTEGER adr4ibuf,adr4ilbuf | ||
3467 | 580 | LOGICAL adr4inlbuf | ||
3468 | 581 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
3469 | 582 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
3470 | 583 | LOGICAL looking | ||
3471 | 584 | COMMON /lookingfbuf/looking | ||
3472 | 585 | c | ||
3473 | 586 | CALL addftraffic(4) | ||
3474 | 587 | IF (adr4ilbuf.ne.-1) THEN | ||
3475 | 588 | adr4ilbuf = -1 | ||
3476 | 589 | adr4inlbuf = .FALSE. | ||
3477 | 590 | looking = .FALSE. | ||
3478 | 591 | ENDIF | ||
3479 | 592 | IF (adr4ibuf.ge.512) THEN | ||
3480 | 593 | adr4buf(512) = x | ||
3481 | 594 | CALL PUSHREAL4ARRAY(adr4buf, 512) | ||
3482 | 595 | CALL addftraffic(-2048) | ||
3483 | 596 | adr4ibuf = 1 | ||
3484 | 597 | ELSE | ||
3485 | 598 | adr4buf(adr4ibuf) = x | ||
3486 | 599 | adr4ibuf = adr4ibuf+1 | ||
3487 | 600 | ENDIF | ||
3488 | 601 | END | ||
3489 | 602 | |||
3490 | 603 | SUBROUTINE LOOKREAL4(x) | ||
3491 | 604 | REAL*4 x, adr4buf(512), adr4lbuf(512) | ||
3492 | 605 | INTEGER adr4ibuf,adr4ilbuf | ||
3493 | 606 | LOGICAL adr4inlbuf | ||
3494 | 607 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
3495 | 608 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
3496 | 609 | LOGICAL looking | ||
3497 | 610 | COMMON /lookingfbuf/looking | ||
3498 | 611 | c | ||
3499 | 612 | IF (adr4ilbuf.eq.-1) THEN | ||
3500 | 613 | adr4ilbuf=adr4ibuf | ||
3501 | 614 | IF (.not.looking) THEN | ||
3502 | 615 | CALL RESETADLOOKSTACK() | ||
3503 | 616 | looking = .TRUE. | ||
3504 | 617 | ENDIF | ||
3505 | 618 | ENDIF | ||
3506 | 619 | IF (adr4ilbuf.le.1) THEN | ||
3507 | 620 | CALL LOOKREAL4ARRAY(adr4lbuf, 512) | ||
3508 | 621 | adr4inlbuf = .TRUE. | ||
3509 | 622 | adr4ilbuf = 512 | ||
3510 | 623 | x = adr4lbuf(512) | ||
3511 | 624 | ELSE | ||
3512 | 625 | adr4ilbuf = adr4ilbuf-1 | ||
3513 | 626 | if (adr4inlbuf) THEN | ||
3514 | 627 | x = adr4lbuf(adr4ilbuf) | ||
3515 | 628 | ELSE | ||
3516 | 629 | x = adr4buf(adr4ilbuf) | ||
3517 | 630 | ENDIF | ||
3518 | 631 | ENDIF | ||
3519 | 632 | END | ||
3520 | 633 | |||
3521 | 634 | SUBROUTINE POPREAL4(x) | ||
3522 | 635 | REAL*4 x, adr4buf(512), adr4lbuf(512) | ||
3523 | 636 | INTEGER adr4ibuf,adr4ilbuf | ||
3524 | 637 | LOGICAL adr4inlbuf | ||
3525 | 638 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
3526 | 639 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
3527 | 640 | LOGICAL looking | ||
3528 | 641 | COMMON /lookingfbuf/looking | ||
3529 | 642 | c | ||
3530 | 643 | IF (adr4ilbuf.ne.-1) THEN | ||
3531 | 644 | adr4ilbuf = -1 | ||
3532 | 645 | adr4inlbuf = .FALSE. | ||
3533 | 646 | looking = .FALSE. | ||
3534 | 647 | ENDIF | ||
3535 | 648 | IF (adr4ibuf.le.1) THEN | ||
3536 | 649 | CALL POPREAL4ARRAY(adr4buf, 512) | ||
3537 | 650 | adr4ibuf = 512 | ||
3538 | 651 | x = adr4buf(512) | ||
3539 | 652 | ELSE | ||
3540 | 653 | adr4ibuf = adr4ibuf-1 | ||
3541 | 654 | x = adr4buf(adr4ibuf) | ||
3542 | 655 | ENDIF | ||
3543 | 656 | END | ||
3544 | 657 | |||
3545 | 658 | c======================= REAL*8 ========================= | ||
3546 | 659 | BLOCK DATA REALS8 | ||
3547 | 660 | REAL*8 adr8buf(512), adr8lbuf(512) | ||
3548 | 661 | INTEGER adr8ibuf,adr8ilbuf | ||
3549 | 662 | LOGICAL adr8inlbuf | ||
3550 | 663 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
3551 | 664 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
3552 | 665 | DATA adr8ibuf/1/ | ||
3553 | 666 | DATA adr8ilbuf/-1/ | ||
3554 | 667 | DATA adr8inlbuf/.FALSE./ | ||
3555 | 668 | END | ||
3556 | 669 | |||
3557 | 670 | SUBROUTINE PUSHREAL8(x) | ||
3558 | 671 | REAL*8 x, adr8buf(512), adr8lbuf(512) | ||
3559 | 672 | INTEGER adr8ibuf,adr8ilbuf | ||
3560 | 673 | LOGICAL adr8inlbuf | ||
3561 | 674 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
3562 | 675 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
3563 | 676 | LOGICAL looking | ||
3564 | 677 | COMMON /lookingfbuf/looking | ||
3565 | 678 | c | ||
3566 | 679 | CALL addftraffic(8) | ||
3567 | 680 | IF (adr8ilbuf.ne.-1) THEN | ||
3568 | 681 | adr8ilbuf = -1 | ||
3569 | 682 | adr8inlbuf = .FALSE. | ||
3570 | 683 | looking = .FALSE. | ||
3571 | 684 | ENDIF | ||
3572 | 685 | IF (adr8ibuf.ge.512) THEN | ||
3573 | 686 | adr8buf(512) = x | ||
3574 | 687 | CALL PUSHREAL8ARRAY(adr8buf, 512) | ||
3575 | 688 | CALL addftraffic(-4096) | ||
3576 | 689 | adr8ibuf = 1 | ||
3577 | 690 | ELSE | ||
3578 | 691 | adr8buf(adr8ibuf) = x | ||
3579 | 692 | adr8ibuf = adr8ibuf+1 | ||
3580 | 693 | ENDIF | ||
3581 | 694 | END | ||
3582 | 695 | |||
3583 | 696 | SUBROUTINE LOOKREAL8(x) | ||
3584 | 697 | REAL*8 x, adr8buf(512), adr8lbuf(512) | ||
3585 | 698 | INTEGER adr8ibuf,adr8ilbuf | ||
3586 | 699 | LOGICAL adr8inlbuf | ||
3587 | 700 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
3588 | 701 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
3589 | 702 | LOGICAL looking | ||
3590 | 703 | COMMON /lookingfbuf/looking | ||
3591 | 704 | c | ||
3592 | 705 | IF (adr8ilbuf.eq.-1) THEN | ||
3593 | 706 | adr8ilbuf=adr8ibuf | ||
3594 | 707 | IF (.not.looking) THEN | ||
3595 | 708 | CALL RESETADLOOKSTACK() | ||
3596 | 709 | looking = .TRUE. | ||
3597 | 710 | ENDIF | ||
3598 | 711 | ENDIF | ||
3599 | 712 | IF (adr8ilbuf.le.1) THEN | ||
3600 | 713 | CALL LOOKREAL8ARRAY(adr8lbuf, 512) | ||
3601 | 714 | adr8inlbuf = .TRUE. | ||
3602 | 715 | adr8ilbuf = 512 | ||
3603 | 716 | x = adr8lbuf(512) | ||
3604 | 717 | ELSE | ||
3605 | 718 | adr8ilbuf = adr8ilbuf-1 | ||
3606 | 719 | if (adr8inlbuf) THEN | ||
3607 | 720 | x = adr8lbuf(adr8ilbuf) | ||
3608 | 721 | ELSE | ||
3609 | 722 | x = adr8buf(adr8ilbuf) | ||
3610 | 723 | ENDIF | ||
3611 | 724 | ENDIF | ||
3612 | 725 | END | ||
3613 | 726 | |||
3614 | 727 | SUBROUTINE POPREAL8(x) | ||
3615 | 728 | REAL*8 x, adr8buf(512), adr8lbuf(512) | ||
3616 | 729 | INTEGER adr8ibuf,adr8ilbuf | ||
3617 | 730 | LOGICAL adr8inlbuf | ||
3618 | 731 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
3619 | 732 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
3620 | 733 | LOGICAL looking | ||
3621 | 734 | COMMON /lookingfbuf/looking | ||
3622 | 735 | c | ||
3623 | 736 | IF (adr8ilbuf.ne.-1) THEN | ||
3624 | 737 | adr8ilbuf = -1 | ||
3625 | 738 | adr8inlbuf = .FALSE. | ||
3626 | 739 | looking = .FALSE. | ||
3627 | 740 | ENDIF | ||
3628 | 741 | IF (adr8ibuf.le.1) THEN | ||
3629 | 742 | CALL POPREAL8ARRAY(adr8buf, 512) | ||
3630 | 743 | adr8ibuf = 512 | ||
3631 | 744 | x = adr8buf(512) | ||
3632 | 745 | ELSE | ||
3633 | 746 | adr8ibuf = adr8ibuf-1 | ||
3634 | 747 | x = adr8buf(adr8ibuf) | ||
3635 | 748 | ENDIF | ||
3636 | 749 | END | ||
3637 | 750 | |||
3638 | 751 | c======================= REAL*16 ========================= | ||
3639 | 752 | BLOCK DATA REALS16 | ||
3640 | 753 | DOUBLE PRECISION adr16buf(512), adr16lbuf(512) | ||
3641 | 754 | INTEGER adr16ibuf,adr16ilbuf | ||
3642 | 755 | LOGICAL adr16inlbuf | ||
3643 | 756 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
3644 | 757 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
3645 | 758 | DATA adr16ibuf/1/ | ||
3646 | 759 | DATA adr16ilbuf/-1/ | ||
3647 | 760 | DATA adr16inlbuf/.FALSE./ | ||
3648 | 761 | END | ||
3649 | 762 | |||
3650 | 763 | SUBROUTINE PUSHREAL16(x) | ||
3651 | 764 | DOUBLE PRECISION x, adr16buf(512), adr16lbuf(512) | ||
3652 | 765 | INTEGER adr16ibuf,adr16ilbuf | ||
3653 | 766 | LOGICAL adr16inlbuf | ||
3654 | 767 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
3655 | 768 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
3656 | 769 | LOGICAL looking | ||
3657 | 770 | COMMON /lookingfbuf/looking | ||
3658 | 771 | c | ||
3659 | 772 | CALL addftraffic(16) | ||
3660 | 773 | IF (adr16ilbuf.ne.-1) THEN | ||
3661 | 774 | adr16ilbuf = -1 | ||
3662 | 775 | adr16inlbuf = .FALSE. | ||
3663 | 776 | looking = .FALSE. | ||
3664 | 777 | ENDIF | ||
3665 | 778 | IF (adr16ibuf.ge.512) THEN | ||
3666 | 779 | adr16buf(512) = x | ||
3667 | 780 | CALL PUSHREAL16ARRAY(adr16buf, 512) | ||
3668 | 781 | CALL addftraffic(-8192) | ||
3669 | 782 | adr16ibuf = 1 | ||
3670 | 783 | ELSE | ||
3671 | 784 | adr16buf(adr16ibuf) = x | ||
3672 | 785 | adr16ibuf = adr16ibuf+1 | ||
3673 | 786 | ENDIF | ||
3674 | 787 | END | ||
3675 | 788 | |||
3676 | 789 | SUBROUTINE LOOKREAL16(x) | ||
3677 | 790 | DOUBLE PRECISION x, adr16buf(512), adr16lbuf(512) | ||
3678 | 791 | INTEGER adr16ibuf,adr16ilbuf | ||
3679 | 792 | LOGICAL adr16inlbuf | ||
3680 | 793 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
3681 | 794 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
3682 | 795 | LOGICAL looking | ||
3683 | 796 | COMMON /lookingfbuf/looking | ||
3684 | 797 | c | ||
3685 | 798 | IF (adr16ilbuf.eq.-1) THEN | ||
3686 | 799 | adr16ilbuf=adr16ibuf | ||
3687 | 800 | IF (.not.looking) THEN | ||
3688 | 801 | CALL RESETADLOOKSTACK() | ||
3689 | 802 | looking = .TRUE. | ||
3690 | 803 | ENDIF | ||
3691 | 804 | ENDIF | ||
3692 | 805 | IF (adr16ilbuf.le.1) THEN | ||
3693 | 806 | CALL LOOKREAL16ARRAY(adr16lbuf, 512) | ||
3694 | 807 | adr16inlbuf = .TRUE. | ||
3695 | 808 | adr16ilbuf = 512 | ||
3696 | 809 | x = adr16lbuf(512) | ||
3697 | 810 | ELSE | ||
3698 | 811 | adr16ilbuf = adr16ilbuf-1 | ||
3699 | 812 | if (adr16inlbuf) THEN | ||
3700 | 813 | x = adr16lbuf(adr16ilbuf) | ||
3701 | 814 | ELSE | ||
3702 | 815 | x = adr16buf(adr16ilbuf) | ||
3703 | 816 | ENDIF | ||
3704 | 817 | ENDIF | ||
3705 | 818 | END | ||
3706 | 819 | |||
3707 | 820 | SUBROUTINE POPREAL16(x) | ||
3708 | 821 | DOUBLE PRECISION x, adr16buf(512), adr16lbuf(512) | ||
3709 | 822 | INTEGER adr16ibuf,adr16ilbuf | ||
3710 | 823 | LOGICAL adr16inlbuf | ||
3711 | 824 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
3712 | 825 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
3713 | 826 | LOGICAL looking | ||
3714 | 827 | COMMON /lookingfbuf/looking | ||
3715 | 828 | c | ||
3716 | 829 | IF (adr16ilbuf.ne.-1) THEN | ||
3717 | 830 | adr16ilbuf = -1 | ||
3718 | 831 | adr16inlbuf = .FALSE. | ||
3719 | 832 | looking = .FALSE. | ||
3720 | 833 | ENDIF | ||
3721 | 834 | IF (adr16ibuf.le.1) THEN | ||
3722 | 835 | CALL POPREAL16ARRAY(adr16buf, 512) | ||
3723 | 836 | adr16ibuf = 512 | ||
3724 | 837 | x = adr16buf(512) | ||
3725 | 838 | ELSE | ||
3726 | 839 | adr16ibuf = adr16ibuf-1 | ||
3727 | 840 | x = adr16buf(adr16ibuf) | ||
3728 | 841 | ENDIF | ||
3729 | 842 | END | ||
3730 | 843 | |||
3731 | 844 | c======================= COMPLEX*8 ========================= | ||
3732 | 845 | BLOCK DATA COMPLEXS8 | ||
3733 | 846 | COMPLEX*8 adc8buf(512), adc8lbuf(512) | ||
3734 | 847 | INTEGER adc8ibuf,adc8ilbuf | ||
3735 | 848 | LOGICAL adc8inlbuf | ||
3736 | 849 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
3737 | 850 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
3738 | 851 | DATA adc8ibuf/1/ | ||
3739 | 852 | DATA adc8ilbuf/-1/ | ||
3740 | 853 | DATA adc8inlbuf/.FALSE./ | ||
3741 | 854 | END | ||
3742 | 855 | |||
3743 | 856 | SUBROUTINE PUSHCOMPLEX8(x) | ||
3744 | 857 | COMPLEX*8 x, adc8buf(512), adc8lbuf(512) | ||
3745 | 858 | INTEGER adc8ibuf,adc8ilbuf | ||
3746 | 859 | LOGICAL adc8inlbuf | ||
3747 | 860 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
3748 | 861 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
3749 | 862 | LOGICAL looking | ||
3750 | 863 | COMMON /lookingfbuf/looking | ||
3751 | 864 | c | ||
3752 | 865 | CALL addftraffic(8) | ||
3753 | 866 | IF (adc8ilbuf.ne.-1) THEN | ||
3754 | 867 | adc8ilbuf = -1 | ||
3755 | 868 | adc8inlbuf = .FALSE. | ||
3756 | 869 | looking = .FALSE. | ||
3757 | 870 | ENDIF | ||
3758 | 871 | IF (adc8ibuf.ge.512) THEN | ||
3759 | 872 | adc8buf(512) = x | ||
3760 | 873 | CALL PUSHCOMPLEX8ARRAY(adc8buf, 512) | ||
3761 | 874 | CALL addftraffic(-4096) | ||
3762 | 875 | adc8ibuf = 1 | ||
3763 | 876 | ELSE | ||
3764 | 877 | adc8buf(adc8ibuf) = x | ||
3765 | 878 | adc8ibuf = adc8ibuf+1 | ||
3766 | 879 | ENDIF | ||
3767 | 880 | END | ||
3768 | 881 | |||
3769 | 882 | SUBROUTINE LOOKCOMPLEX8(x) | ||
3770 | 883 | COMPLEX*8 x, adc8buf(512), adc8lbuf(512) | ||
3771 | 884 | INTEGER adc8ibuf,adc8ilbuf | ||
3772 | 885 | LOGICAL adc8inlbuf | ||
3773 | 886 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
3774 | 887 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
3775 | 888 | LOGICAL looking | ||
3776 | 889 | COMMON /lookingfbuf/looking | ||
3777 | 890 | c | ||
3778 | 891 | IF (adc8ilbuf.eq.-1) THEN | ||
3779 | 892 | adc8ilbuf=adc8ibuf | ||
3780 | 893 | IF (.not.looking) THEN | ||
3781 | 894 | CALL RESETADLOOKSTACK() | ||
3782 | 895 | looking = .TRUE. | ||
3783 | 896 | ENDIF | ||
3784 | 897 | ENDIF | ||
3785 | 898 | IF (adc8ilbuf.le.1) THEN | ||
3786 | 899 | CALL LOOKCOMPLEX8ARRAY(adc8lbuf, 512) | ||
3787 | 900 | adc8inlbuf = .TRUE. | ||
3788 | 901 | adc8ilbuf = 512 | ||
3789 | 902 | x = adc8lbuf(512) | ||
3790 | 903 | ELSE | ||
3791 | 904 | adc8ilbuf = adc8ilbuf-1 | ||
3792 | 905 | if (adc8inlbuf) THEN | ||
3793 | 906 | x = adc8lbuf(adc8ilbuf) | ||
3794 | 907 | ELSE | ||
3795 | 908 | x = adc8buf(adc8ilbuf) | ||
3796 | 909 | ENDIF | ||
3797 | 910 | ENDIF | ||
3798 | 911 | END | ||
3799 | 912 | |||
3800 | 913 | SUBROUTINE POPCOMPLEX8(x) | ||
3801 | 914 | COMPLEX*8 x, adc8buf(512), adc8lbuf(512) | ||
3802 | 915 | INTEGER adc8ibuf,adc8ilbuf | ||
3803 | 916 | LOGICAL adc8inlbuf | ||
3804 | 917 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
3805 | 918 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
3806 | 919 | LOGICAL looking | ||
3807 | 920 | COMMON /lookingfbuf/looking | ||
3808 | 921 | c | ||
3809 | 922 | IF (adc8ilbuf.ne.-1) THEN | ||
3810 | 923 | adc8ilbuf = -1 | ||
3811 | 924 | adc8inlbuf = .FALSE. | ||
3812 | 925 | looking = .FALSE. | ||
3813 | 926 | ENDIF | ||
3814 | 927 | IF (adc8ibuf.le.1) THEN | ||
3815 | 928 | CALL POPCOMPLEX8ARRAY(adc8buf, 512) | ||
3816 | 929 | adc8ibuf = 512 | ||
3817 | 930 | x = adc8buf(512) | ||
3818 | 931 | ELSE | ||
3819 | 932 | adc8ibuf = adc8ibuf-1 | ||
3820 | 933 | x = adc8buf(adc8ibuf) | ||
3821 | 934 | ENDIF | ||
3822 | 935 | END | ||
3823 | 936 | |||
3824 | 937 | c======================= COMPLEX*16 ========================= | ||
3825 | 938 | BLOCK DATA COMPLEXS16 | ||
3826 | 939 | COMPLEX*16 adc16buf(512), adc16lbuf(512) | ||
3827 | 940 | INTEGER adc16ibuf,adc16ilbuf | ||
3828 | 941 | LOGICAL adc16inlbuf | ||
3829 | 942 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
3830 | 943 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
3831 | 944 | DATA adc16ibuf/1/ | ||
3832 | 945 | DATA adc16ilbuf/-1/ | ||
3833 | 946 | DATA adc16inlbuf/.FALSE./ | ||
3834 | 947 | END | ||
3835 | 948 | |||
3836 | 949 | SUBROUTINE PUSHCOMPLEX16(x) | ||
3837 | 950 | COMPLEX*16 x, adc16buf(512), adc16lbuf(512) | ||
3838 | 951 | INTEGER adc16ibuf,adc16ilbuf | ||
3839 | 952 | LOGICAL adc16inlbuf | ||
3840 | 953 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
3841 | 954 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
3842 | 955 | LOGICAL looking | ||
3843 | 956 | COMMON /lookingfbuf/looking | ||
3844 | 957 | c | ||
3845 | 958 | CALL addftraffic(16) | ||
3846 | 959 | IF (adc16ilbuf.ne.-1) THEN | ||
3847 | 960 | adc16ilbuf = -1 | ||
3848 | 961 | adc16inlbuf = .FALSE. | ||
3849 | 962 | looking = .FALSE. | ||
3850 | 963 | ENDIF | ||
3851 | 964 | IF (adc16ibuf.ge.512) THEN | ||
3852 | 965 | adc16buf(512) = x | ||
3853 | 966 | CALL PUSHCOMPLEX16ARRAY(adc16buf, 512) | ||
3854 | 967 | CALL addftraffic(-8192) | ||
3855 | 968 | adc16ibuf = 1 | ||
3856 | 969 | ELSE | ||
3857 | 970 | adc16buf(adc16ibuf) = x | ||
3858 | 971 | adc16ibuf = adc16ibuf+1 | ||
3859 | 972 | ENDIF | ||
3860 | 973 | END | ||
3861 | 974 | |||
3862 | 975 | SUBROUTINE LOOKCOMPLEX16(x) | ||
3863 | 976 | COMPLEX*16 x, adc16buf(512), adc16lbuf(512) | ||
3864 | 977 | INTEGER adc16ibuf,adc16ilbuf | ||
3865 | 978 | LOGICAL adc16inlbuf | ||
3866 | 979 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
3867 | 980 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
3868 | 981 | LOGICAL looking | ||
3869 | 982 | COMMON /lookingfbuf/looking | ||
3870 | 983 | c | ||
3871 | 984 | IF (adc16ilbuf.eq.-1) THEN | ||
3872 | 985 | adc16ilbuf=adc16ibuf | ||
3873 | 986 | IF (.not.looking) THEN | ||
3874 | 987 | CALL RESETADLOOKSTACK() | ||
3875 | 988 | looking = .TRUE. | ||
3876 | 989 | ENDIF | ||
3877 | 990 | ENDIF | ||
3878 | 991 | IF (adc16ilbuf.le.1) THEN | ||
3879 | 992 | CALL LOOKCOMPLEX16ARRAY(adc16lbuf, 512) | ||
3880 | 993 | adc16inlbuf = .TRUE. | ||
3881 | 994 | adc16ilbuf = 512 | ||
3882 | 995 | x = adc16lbuf(512) | ||
3883 | 996 | ELSE | ||
3884 | 997 | adc16ilbuf = adc16ilbuf-1 | ||
3885 | 998 | if (adc16inlbuf) THEN | ||
3886 | 999 | x = adc16lbuf(adc16ilbuf) | ||
3887 | 1000 | ELSE | ||
3888 | 1001 | x = adc16buf(adc16ilbuf) | ||
3889 | 1002 | ENDIF | ||
3890 | 1003 | ENDIF | ||
3891 | 1004 | END | ||
3892 | 1005 | |||
3893 | 1006 | SUBROUTINE POPCOMPLEX16(x) | ||
3894 | 1007 | COMPLEX*16 x, adc16buf(512), adc16lbuf(512) | ||
3895 | 1008 | INTEGER adc16ibuf,adc16ilbuf | ||
3896 | 1009 | LOGICAL adc16inlbuf | ||
3897 | 1010 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
3898 | 1011 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
3899 | 1012 | LOGICAL looking | ||
3900 | 1013 | COMMON /lookingfbuf/looking | ||
3901 | 1014 | c | ||
3902 | 1015 | IF (adc16ilbuf.ne.-1) THEN | ||
3903 | 1016 | adc16ilbuf = -1 | ||
3904 | 1017 | adc16inlbuf = .FALSE. | ||
3905 | 1018 | looking = .FALSE. | ||
3906 | 1019 | ENDIF | ||
3907 | 1020 | IF (adc16ibuf.le.1) THEN | ||
3908 | 1021 | CALL POPCOMPLEX16ARRAY(adc16buf, 512) | ||
3909 | 1022 | adc16ibuf = 512 | ||
3910 | 1023 | x = adc16buf(512) | ||
3911 | 1024 | ELSE | ||
3912 | 1025 | adc16ibuf = adc16ibuf-1 | ||
3913 | 1026 | x = adc16buf(adc16ibuf) | ||
3914 | 1027 | ENDIF | ||
3915 | 1028 | END | ||
3916 | 1029 | |||
3917 | 1030 | C=========== MEASUREMENT OF PUSH/POP TRAFFIC ========== | ||
3918 | 1031 | |||
3919 | 1032 | BLOCK DATA MEMTRAFFIC | ||
3920 | 1033 | INTEGER*8 mmftraffic,mmftrafficM | ||
3921 | 1034 | COMMON /mmcomtraffic/mmftraffic,mmftrafficM | ||
3922 | 1035 | DATA mmftraffic/0/ | ||
3923 | 1036 | DATA mmftrafficM/0/ | ||
3924 | 1037 | END | ||
3925 | 1038 | |||
3926 | 1039 | subroutine addftraffic(n) | ||
3927 | 1040 | INTEGER n | ||
3928 | 1041 | INTEGER*8 mmftraffic,mmftrafficM | ||
3929 | 1042 | COMMON /mmcomtraffic/mmftraffic,mmftrafficM | ||
3930 | 1043 | c | ||
3931 | 1044 | mmftraffic = mmftraffic+n | ||
3932 | 1045 | if (mmftraffic.ge.1000000) then | ||
3933 | 1046 | 100 mmftraffic = mmftraffic-1000000 | ||
3934 | 1047 | mmftrafficM = mmftrafficM+1 | ||
3935 | 1048 | if (mmftraffic.ge.1000000) then | ||
3936 | 1049 | goto 100 | ||
3937 | 1050 | else | ||
3938 | 1051 | goto 300 | ||
3939 | 1052 | endif | ||
3940 | 1053 | else if (mmftraffic.lt.0) then | ||
3941 | 1054 | 200 mmftraffic = mmftraffic+1000000 | ||
3942 | 1055 | mmftrafficM = mmftrafficM-1 | ||
3943 | 1056 | if (mmftraffic.lt.0) then | ||
3944 | 1057 | goto 200 | ||
3945 | 1058 | else | ||
3946 | 1059 | goto 300 | ||
3947 | 1060 | endif | ||
3948 | 1061 | endif | ||
3949 | 1062 | 300 continue | ||
3950 | 1063 | END | ||
3951 | 1064 | |||
3952 | 1065 | SUBROUTINE PRINTTRAFFIC() | ||
3953 | 1066 | INTEGER*8 mmftraffic,mmftrafficM | ||
3954 | 1067 | COMMON /mmcomtraffic/mmftraffic,mmftrafficM | ||
3955 | 1068 | CALL printctraffic() | ||
3956 | 1069 | CALL printftrafficinc(mmftrafficM, 1000000, mmftraffic) | ||
3957 | 1070 | c write (6,1001) ' F Traffic: ',mmftrafficM,' Mb and ', | ||
3958 | 1071 | c + (((mmftraffic*1000)/1024)*1000)/1024, ' millionths' | ||
3959 | 1072 | c 1001 format(a,i6,a,i6,a) | ||
3960 | 1073 | END | ||
3961 | 1074 | |||
3962 | 1075 | C ============ PRINTING THE SIZE OF STACKS AND BUFFERS ========== | ||
3963 | 1076 | |||
3964 | 1077 | SUBROUTINE PRINTBUFFERTOP() | ||
3965 | 1078 | integer*4 SMALLSTACKSIZE | ||
3966 | 1079 | integer*4 size | ||
3967 | 1080 | |||
3968 | 1081 | size = SMALLSTACKSIZE() | ||
3969 | 1082 | print *,'Buffer size:',size,' bytes i.e. ',size/1024.0,' Kbytes' | ||
3970 | 1083 | END | ||
3971 | 1084 | |||
3972 | 1085 | FUNCTION SMALLSTACKSIZE() | ||
3973 | 1086 | CHARACTER ads1buf(512), ads1lbuf(512) | ||
3974 | 1087 | INTEGER ads1ibuf,ads1ilbuf | ||
3975 | 1088 | LOGICAL ads1inlbuf | ||
3976 | 1089 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
3977 | 1090 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
3978 | 1091 | c LOGICAL adl4buf(512), adl4lbuf(512) | ||
3979 | 1092 | c INTEGER adl4ibuf,adl4ilbuf | ||
3980 | 1093 | c LOGICAL adl4inlbuf | ||
3981 | 1094 | c COMMON /adl4fbuf/adl4buf,adl4lbuf, | ||
3982 | 1095 | c + adl4ibuf,adl4ilbuf,adl4inlbuf | ||
3983 | 1096 | INTEGER*4 adi4buf(512), adi4lbuf(512) | ||
3984 | 1097 | INTEGER adi4ibuf,adi4ilbuf | ||
3985 | 1098 | LOGICAL adi4inlbuf | ||
3986 | 1099 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
3987 | 1100 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
3988 | 1101 | INTEGER*8 adi8buf(512), adi8lbuf(512) | ||
3989 | 1102 | INTEGER adi8ibuf,adi8ilbuf | ||
3990 | 1103 | LOGICAL adi8inlbuf | ||
3991 | 1104 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
3992 | 1105 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
3993 | 1106 | c INTEGER*16 adi16buf(512), adi16lbuf(512) | ||
3994 | 1107 | c INTEGER adi16ibuf,adi16ilbuf | ||
3995 | 1108 | c LOGICAL adi16inlbuf | ||
3996 | 1109 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
3997 | 1110 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
3998 | 1111 | REAL*4 adr4buf(512), adr4lbuf(512) | ||
3999 | 1112 | INTEGER adr4ibuf,adr4ilbuf | ||
4000 | 1113 | LOGICAL adr4inlbuf | ||
4001 | 1114 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
4002 | 1115 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
4003 | 1116 | REAL*8 adr8buf(512), adr8lbuf(512) | ||
4004 | 1117 | INTEGER adr8ibuf,adr8ilbuf | ||
4005 | 1118 | LOGICAL adr8inlbuf | ||
4006 | 1119 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
4007 | 1120 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
4008 | 1121 | DOUBLE PRECISION adr16buf(512), adr16lbuf(512) | ||
4009 | 1122 | INTEGER adr16ibuf,adr16ilbuf | ||
4010 | 1123 | LOGICAL adr16inlbuf | ||
4011 | 1124 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
4012 | 1125 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
4013 | 1126 | c REAL*32 x, adr32buf(512), adr32lbuf(512) | ||
4014 | 1127 | c INTEGER adr32ibuf,adr32ilbuf | ||
4015 | 1128 | c LOGICAL adr32inlbuf | ||
4016 | 1129 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4017 | 1130 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4018 | 1131 | c COMPLEX*4 adc4buf(512), adc4lbuf(512) | ||
4019 | 1132 | c INTEGER adc4ibuf,adc4ilbuf | ||
4020 | 1133 | c LOGICAL adc4inlbuf | ||
4021 | 1134 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4022 | 1135 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4023 | 1136 | COMPLEX*8 adc8buf(512), adc8lbuf(512) | ||
4024 | 1137 | INTEGER adc8ibuf,adc8ilbuf | ||
4025 | 1138 | LOGICAL adc8inlbuf | ||
4026 | 1139 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
4027 | 1140 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
4028 | 1141 | COMPLEX*16 adc16buf(512), adc16lbuf(512) | ||
4029 | 1142 | INTEGER adc16ibuf,adc16ilbuf | ||
4030 | 1143 | LOGICAL adc16inlbuf | ||
4031 | 1144 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
4032 | 1145 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
4033 | 1146 | c COMPLEX*32 adc32buf(512), adc32lbuf(512) | ||
4034 | 1147 | c INTEGER adc32ibuf,adc32ilbuf | ||
4035 | 1148 | c LOGICAL adc32inlbuf | ||
4036 | 1149 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4037 | 1150 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4038 | 1151 | integer*4 smallstacksize | ||
4039 | 1152 | c | ||
4040 | 1153 | smallstacksize = 0 | ||
4041 | 1154 | smallstacksize = smallstacksize + (ads1ibuf-1)*1 | ||
4042 | 1155 | c smallstacksize = smallstacksize + (adl4ibuf-1)*4 | ||
4043 | 1156 | smallstacksize = smallstacksize + (adi4ibuf-1)*4 | ||
4044 | 1157 | smallstacksize = smallstacksize + (adi8ibuf-1)*8 | ||
4045 | 1158 | c smallstacksize = smallstacksize + (adi16ibuf-1)*16 | ||
4046 | 1159 | smallstacksize = smallstacksize + (adr4ibuf-1)*4 | ||
4047 | 1160 | smallstacksize = smallstacksize + (adr8ibuf-1)*8 | ||
4048 | 1161 | smallstacksize = smallstacksize + (adr16ibuf-1)*16 | ||
4049 | 1162 | c smallstacksize = smallstacksize + (adr32ibuf-1)*32 | ||
4050 | 1163 | c smallstacksize = smallstacksize + (adc4ibuf-1)*4 | ||
4051 | 1164 | smallstacksize = smallstacksize + (adc8ibuf-1)*8 | ||
4052 | 1165 | smallstacksize = smallstacksize + (adc16ibuf-1)*16 | ||
4053 | 1166 | c smallstacksize = smallstacksize + (adc32ibuf-1)*32 | ||
4054 | 1167 | c | ||
4055 | 1168 | end | ||
4056 | 1169 | |||
4057 | 1170 | c Very complete display of the current size of the | ||
4058 | 1171 | c push/look/pop local Fortran stacks and global C stack. | ||
4059 | 1172 | SUBROUTINE PRINTALLBUFFERS() | ||
4060 | 1173 | CHARACTER ads1buf(512), ads1lbuf(512) | ||
4061 | 1174 | INTEGER ads1ibuf,ads1ilbuf | ||
4062 | 1175 | LOGICAL ads1inlbuf | ||
4063 | 1176 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
4064 | 1177 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
4065 | 1178 | c LOGICAL adl4buf(512), adl4lbuf(512) | ||
4066 | 1179 | c INTEGER adl4ibuf,adl4ilbuf | ||
4067 | 1180 | c LOGICAL adl4inlbuf | ||
4068 | 1181 | c COMMON /adl4fbuf/adl4buf,adl4lbuf, | ||
4069 | 1182 | c + adl4ibuf,adl4ilbuf,adl4inlbuf | ||
4070 | 1183 | INTEGER*4 adi4buf(512), adi4lbuf(512) | ||
4071 | 1184 | INTEGER adi4ibuf,adi4ilbuf | ||
4072 | 1185 | LOGICAL adi4inlbuf | ||
4073 | 1186 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
4074 | 1187 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
4075 | 1188 | INTEGER*8 adi8buf(512), adi8lbuf(512) | ||
4076 | 1189 | INTEGER adi8ibuf,adi8ilbuf | ||
4077 | 1190 | LOGICAL adi8inlbuf | ||
4078 | 1191 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
4079 | 1192 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
4080 | 1193 | c INTEGER*16 adi16buf(512), adi16lbuf(512) | ||
4081 | 1194 | c INTEGER adi16ibuf,adi16ilbuf | ||
4082 | 1195 | c LOGICAL adi16inlbuf | ||
4083 | 1196 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
4084 | 1197 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
4085 | 1198 | REAL*4 adr4buf(512), adr4lbuf(512) | ||
4086 | 1199 | INTEGER adr4ibuf,adr4ilbuf | ||
4087 | 1200 | LOGICAL adr4inlbuf | ||
4088 | 1201 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
4089 | 1202 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
4090 | 1203 | REAL*8 adr8buf(512), adr8lbuf(512) | ||
4091 | 1204 | INTEGER adr8ibuf,adr8ilbuf | ||
4092 | 1205 | LOGICAL adr8inlbuf | ||
4093 | 1206 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
4094 | 1207 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
4095 | 1208 | DOUBLE PRECISION adr16buf(512), adr16lbuf(512) | ||
4096 | 1209 | INTEGER adr16ibuf,adr16ilbuf | ||
4097 | 1210 | LOGICAL adr16inlbuf | ||
4098 | 1211 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
4099 | 1212 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
4100 | 1213 | c REAL*32 x, adr32buf(512), adr32lbuf(512) | ||
4101 | 1214 | c INTEGER adr32ibuf,adr32ilbuf | ||
4102 | 1215 | c LOGICAL adr32inlbuf | ||
4103 | 1216 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4104 | 1217 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4105 | 1218 | c COMPLEX*4 adc4buf(512), adc4lbuf(512) | ||
4106 | 1219 | c INTEGER adc4ibuf,adc4ilbuf | ||
4107 | 1220 | c LOGICAL adc4inlbuf | ||
4108 | 1221 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4109 | 1222 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4110 | 1223 | COMPLEX*8 adc8buf(512), adc8lbuf(512) | ||
4111 | 1224 | INTEGER adc8ibuf,adc8ilbuf | ||
4112 | 1225 | LOGICAL adc8inlbuf | ||
4113 | 1226 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
4114 | 1227 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
4115 | 1228 | COMPLEX*16 adc16buf(512), adc16lbuf(512) | ||
4116 | 1229 | INTEGER adc16ibuf,adc16ilbuf | ||
4117 | 1230 | LOGICAL adc16inlbuf | ||
4118 | 1231 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
4119 | 1232 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
4120 | 1233 | c COMPLEX*32 adc32buf(512), adc32lbuf(512) | ||
4121 | 1234 | c INTEGER adc32ibuf,adc32ilbuf | ||
4122 | 1235 | c LOGICAL adc32inlbuf | ||
4123 | 1236 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4124 | 1237 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4125 | 1238 | integer*4 bsize,lookbsize | ||
4126 | 1239 | integer*4 cblocks, csize, lookcblocks, lookcsize | ||
4127 | 1240 | c | ||
4128 | 1241 | call getbigcsizes(cblocks,csize,lookcblocks,lookcsize) | ||
4129 | 1242 | write (6,'(a,i8,a,i5,a,i8,a,i5,a)') | ||
4130 | 1243 | + 'MAIN stack size (in C) :',cblocks,'B +',csize, | ||
4131 | 1244 | + ' (looking:',lookcblocks,'B +',lookcsize,')' | ||
4132 | 1245 | bsize = (ads1ibuf-1)*1 | ||
4133 | 1246 | lookbsize = -999 | ||
4134 | 1247 | if (ads1inlbuf.or.ads1ilbuf.gt.-1) lookbsize=(ads1ilbuf-1)*1 | ||
4135 | 1248 | write (6,'(a,i4,a,i4,a)') 'CHARs :',bsize, | ||
4136 | 1249 | + ' (looking:',lookbsize,')' | ||
4137 | 1250 | c bsize = (adl4ibuf-1)*4 | ||
4138 | 1251 | bsize = (adi4ibuf-1)*4 | ||
4139 | 1252 | lookbsize = -999 | ||
4140 | 1253 | if (adi4inlbuf.or.adi4ilbuf.gt.-1) lookbsize=(adi4ilbuf-1)*4 | ||
4141 | 1254 | write (6,'(a,i4,a,i4,a)') 'INTs4 :',bsize, | ||
4142 | 1255 | + ' (looking:',lookbsize,')' | ||
4143 | 1256 | bsize = (adi8ibuf-1)*8 | ||
4144 | 1257 | lookbsize = -999 | ||
4145 | 1258 | if (adi8inlbuf.or.adi8ilbuf.gt.-1) lookbsize=(adi8ilbuf-1)*8 | ||
4146 | 1259 | write (6,'(a,i4,a,i4,a)') 'INTs8 :',bsize, | ||
4147 | 1260 | + ' (looking:',lookbsize,')' | ||
4148 | 1261 | c bsize = (adi16ibuf-1)*16 | ||
4149 | 1262 | bsize = (adr4ibuf-1)*4 | ||
4150 | 1263 | lookbsize = -999 | ||
4151 | 1264 | if (adr4inlbuf.or.adr4ilbuf.gt.-1) lookbsize=(adr4ilbuf-1)*4 | ||
4152 | 1265 | write (6,'(a,i4,a,i4,a)') 'REALs4 :',bsize, | ||
4153 | 1266 | + ' (looking:',lookbsize,')' | ||
4154 | 1267 | bsize = (adr8ibuf-1)*8 | ||
4155 | 1268 | lookbsize = -999 | ||
4156 | 1269 | if (adr8inlbuf.or.adr8ilbuf.gt.-1) lookbsize=(adr8ilbuf-1)*8 | ||
4157 | 1270 | write (6,'(a,i4,a,i4,a)') 'REALs8 :',bsize, | ||
4158 | 1271 | + ' (looking:',lookbsize,')' | ||
4159 | 1272 | bsize = (adr16ibuf-1)*16 | ||
4160 | 1273 | lookbsize = -999 | ||
4161 | 1274 | if (adr16inlbuf.or.adr16ilbuf.gt.-1) lookbsize=(adr16ilbuf-1)*16 | ||
4162 | 1275 | write (6,'(a,i4,a,i4,a)') 'REALs16:',bsize, | ||
4163 | 1276 | + ' (looking:',lookbsize,')' | ||
4164 | 1277 | c bsize = (adr32ibuf-1)*32 | ||
4165 | 1278 | c bsize = (adc4ibuf-1)*4 | ||
4166 | 1279 | bsize = (adc8ibuf-1)*8 | ||
4167 | 1280 | lookbsize = -999 | ||
4168 | 1281 | if (adc8inlbuf.or.adc8ilbuf.gt.-1) lookbsize=(adc8ilbuf-1)*8 | ||
4169 | 1282 | write (6,'(a,i4,a,i4,a)') 'CPLXs8 :',bsize, | ||
4170 | 1283 | + ' (looking:',lookbsize,')' | ||
4171 | 1284 | bsize = (adc16ibuf-1)*16 | ||
4172 | 1285 | lookbsize = -999 | ||
4173 | 1286 | if (adc16inlbuf.or.adc16ilbuf.gt.-1) lookbsize=(adc16ilbuf-1)*16 | ||
4174 | 1287 | write (6,'(a,i4,a,i4,a)') 'CPLXs16:',bsize, | ||
4175 | 1288 | + ' (looking:',lookbsize,')' | ||
4176 | 1289 | c bsize = (adc32ibuf-1)*32 | ||
4177 | 1290 | c | ||
4178 | 1291 | end | ||
4179 | 1292 | |||
4180 | 1293 | C FOR INTERNAL DEBUGS ONLY: | ||
4181 | 1294 | SUBROUTINE SHOWALLSTACKS() | ||
4182 | 1295 | INTEGER*4 adbitbuf, adbitlbuf | ||
4183 | 1296 | INTEGER adbitibuf, adbitilbuf | ||
4184 | 1297 | LOGICAL adbitinlbuf | ||
4185 | 1298 | COMMON /adbitfbuf/adbitbuf,adbitlbuf, | ||
4186 | 1299 | + adbitibuf,adbitilbuf,adbitinlbuf | ||
4187 | 1300 | CHARACTER ads1buf(512), ads1lbuf(512) | ||
4188 | 1301 | INTEGER ads1ibuf,ads1ilbuf | ||
4189 | 1302 | LOGICAL ads1inlbuf | ||
4190 | 1303 | COMMON /ads1fbuf/ads1buf,ads1lbuf, | ||
4191 | 1304 | + ads1ibuf,ads1ilbuf,ads1inlbuf | ||
4192 | 1305 | INTEGER*4 adi4buf(512), adi4lbuf(512) | ||
4193 | 1306 | INTEGER adi4ibuf,adi4ilbuf | ||
4194 | 1307 | LOGICAL adi4inlbuf | ||
4195 | 1308 | COMMON /adi4fbuf/adi4buf,adi4lbuf, | ||
4196 | 1309 | + adi4ibuf,adi4ilbuf,adi4inlbuf | ||
4197 | 1310 | INTEGER*8 adi8buf(512), adi8lbuf(512) | ||
4198 | 1311 | INTEGER adi8ibuf,adi8ilbuf | ||
4199 | 1312 | LOGICAL adi8inlbuf | ||
4200 | 1313 | COMMON /adi8fbuf/adi8buf,adi8lbuf, | ||
4201 | 1314 | + adi8ibuf,adi8ilbuf,adi8inlbuf | ||
4202 | 1315 | REAL*4 adr4buf(512), adr4lbuf(512) | ||
4203 | 1316 | INTEGER adr4ibuf,adr4ilbuf | ||
4204 | 1317 | LOGICAL adr4inlbuf | ||
4205 | 1318 | COMMON /adr4fbuf/adr4buf,adr4lbuf, | ||
4206 | 1319 | + adr4ibuf,adr4ilbuf,adr4inlbuf | ||
4207 | 1320 | REAL*8 adr8buf(512), adr8lbuf(512) | ||
4208 | 1321 | INTEGER adr8ibuf,adr8ilbuf | ||
4209 | 1322 | LOGICAL adr8inlbuf | ||
4210 | 1323 | COMMON /adr8fbuf/adr8buf,adr8lbuf, | ||
4211 | 1324 | + adr8ibuf,adr8ilbuf,adr8inlbuf | ||
4212 | 1325 | DOUBLE PRECISION adr16buf(512), adr16lbuf(512) | ||
4213 | 1326 | INTEGER adr16ibuf,adr16ilbuf | ||
4214 | 1327 | LOGICAL adr16inlbuf | ||
4215 | 1328 | COMMON /adr16fbuf/adr16buf,adr16lbuf, | ||
4216 | 1329 | + adr16ibuf,adr16ilbuf,adr16inlbuf | ||
4217 | 1330 | COMPLEX*8 adc8buf(512), adc8lbuf(512) | ||
4218 | 1331 | INTEGER adc8ibuf,adc8ilbuf | ||
4219 | 1332 | LOGICAL adc8inlbuf | ||
4220 | 1333 | COMMON /adc8fbuf/adc8buf,adc8lbuf, | ||
4221 | 1334 | + adc8ibuf,adc8ilbuf,adc8inlbuf | ||
4222 | 1335 | COMPLEX*16 adc16buf(512), adc16lbuf(512) | ||
4223 | 1336 | INTEGER adc16ibuf,adc16ilbuf | ||
4224 | 1337 | LOGICAL adc16inlbuf | ||
4225 | 1338 | COMMON /adc16fbuf/adc16buf,adc16lbuf, | ||
4226 | 1339 | + adc16ibuf,adc16ilbuf,adc16inlbuf | ||
4227 | 1340 | INTEGER i | ||
4228 | 1341 | c | ||
4229 | 1342 | write (6,1010) 'BIT STACK : ',adbitbuf,'==',adbitbuf, | ||
4230 | 1343 | + ' (',adbitibuf,')' | ||
4231 | 1344 | 1010 format(a,i20,a,z16,a,i2,a) | ||
4232 | 1345 | write (6,1011) 'INTEGER*8 BUFFER[',adi8ibuf-1,']: ', | ||
4233 | 1346 | + (adi8buf(i),i=1,adi8ibuf-1) | ||
4234 | 1347 | write (6,1011) 'INTEGER*4 BUFFER[',adi4ibuf-1,']: ', | ||
4235 | 1348 | + (adi4buf(i),i=1,adi4ibuf-1) | ||
4236 | 1349 | 1011 format(a,i3,a,512(i40)) | ||
4237 | 1350 | write (6,1012) 'REAL*16 BUFFER:[',adr16ibuf-1,']: ', | ||
4238 | 1351 | + (adr16buf(i),i=1,adr16ibuf-1) | ||
4239 | 1352 | write (6,1012) 'REAL*8 BUFFER:[',adr8ibuf-1, ']: ', | ||
4240 | 1353 | + (adr8buf(i),i=1,adr8ibuf-1) | ||
4241 | 1354 | write (6,1012) 'REAL*4 BUFFER:[',adr4ibuf-1, ']: ', | ||
4242 | 1355 | + (adr4buf(i),i=1,adr4ibuf-1) | ||
4243 | 1356 | 1012 format(a,i3,a,512(e8.2)) | ||
4244 | 1357 | call showrecentcstack() | ||
4245 | 1358 | c | ||
4246 | 1359 | END | ||
4247 | 1360 | |||
4248 | 1361 | C======================================================== | ||
4249 | 1362 | C PUSH* POP* SUBROUTINES FOR OTHER DATA TYPES | ||
4250 | 1363 | C Uncomment if these types are available on your compiler | ||
4251 | 1364 | C and they are needed by the reverse differentiated code | ||
4252 | 1365 | C Don't forget to uncomment the corresponding lines in | ||
4253 | 1366 | C subroutine PRINTBUFFERTOP, otherwise these types' | ||
4254 | 1367 | C contribution to buffer occupation will not be seen. | ||
4255 | 1368 | C (not very important anyway...) | ||
4256 | 1369 | |||
4257 | 1370 | c======================= INTEGER*16 ========================= | ||
4258 | 1371 | c BLOCK DATA INTEGERS16 | ||
4259 | 1372 | c INTEGER*16 adi16buf(512), adi16lbuf(512) | ||
4260 | 1373 | c INTEGER adi16ibuf,adi16ilbuf | ||
4261 | 1374 | c LOGICAL adi16inlbuf | ||
4262 | 1375 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
4263 | 1376 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
4264 | 1377 | c DATA adi16ibuf/1/ | ||
4265 | 1378 | c DATA adi16ilbuf/-1/ | ||
4266 | 1379 | c DATA adi16inlbuf/.FALSE./ | ||
4267 | 1380 | c END | ||
4268 | 1381 | c c | ||
4269 | 1382 | c SUBROUTINE PUSHINTEGER16(x) | ||
4270 | 1383 | c INTEGER*16 x, adi16buf(512), adi16lbuf(512) | ||
4271 | 1384 | c INTEGER adi16ibuf,adi16ilbuf | ||
4272 | 1385 | c LOGICAL adi16inlbuf | ||
4273 | 1386 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
4274 | 1387 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
4275 | 1388 | c LOGICAL looking | ||
4276 | 1389 | c COMMON /lookingfbuf/looking | ||
4277 | 1390 | c c | ||
4278 | 1391 | c CALL addftraffic(16) | ||
4279 | 1392 | c IF (adi16ilbuf.ne.-1) THEN | ||
4280 | 1393 | c adi16ilbuf = -1 | ||
4281 | 1394 | c adi16inlbuf = .FALSE. | ||
4282 | 1395 | c looking = .FALSE. | ||
4283 | 1396 | c ENDIF | ||
4284 | 1397 | c IF (adi16ibuf.ge.512) THEN | ||
4285 | 1398 | c adi16buf(512) = x | ||
4286 | 1399 | c CALL PUSHINTEGER16ARRAY(adi16buf, 512) | ||
4287 | 1400 | c CALL addftraffic(-8192) | ||
4288 | 1401 | c adi16ibuf = 1 | ||
4289 | 1402 | c ELSE | ||
4290 | 1403 | c adi16buf(adi16ibuf) = x | ||
4291 | 1404 | c adi16ibuf = adi16ibuf+1 | ||
4292 | 1405 | c ENDIF | ||
4293 | 1406 | c END | ||
4294 | 1407 | c | ||
4295 | 1408 | c SUBROUTINE LOOKINTEGER16(x) | ||
4296 | 1409 | c INTEGER*16 x, adi16buf(512), adi16lbuf(512) | ||
4297 | 1410 | c INTEGER adi16ibuf,adi16ilbuf | ||
4298 | 1411 | c LOGICAL adi16inlbuf | ||
4299 | 1412 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
4300 | 1413 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
4301 | 1414 | c LOGICAL looking | ||
4302 | 1415 | c COMMON /lookingfbuf/looking | ||
4303 | 1416 | c c | ||
4304 | 1417 | c IF (adi16ilbuf.eq.-1) THEN | ||
4305 | 1418 | c adi16ilbuf=adi16ibuf | ||
4306 | 1419 | c IF (.not.looking) THEN | ||
4307 | 1420 | c CALL RESETADLOOKSTACK() | ||
4308 | 1421 | c looking = .TRUE. | ||
4309 | 1422 | c ENDIF | ||
4310 | 1423 | c ENDIF | ||
4311 | 1424 | c IF (adi16ilbuf.le.1) THEN | ||
4312 | 1425 | c CALL LOOKINTEGER16ARRAY(adi16lbuf, 512) | ||
4313 | 1426 | c adi16inlbuf = .TRUE. | ||
4314 | 1427 | c adi16ilbuf = 512 | ||
4315 | 1428 | c x = adi16lbuf(512) | ||
4316 | 1429 | c ELSE | ||
4317 | 1430 | c adi16ilbuf = adi16ilbuf-1 | ||
4318 | 1431 | c if (adi16inlbuf) THEN | ||
4319 | 1432 | c x = adi16lbuf(adi16ilbuf) | ||
4320 | 1433 | c ELSE | ||
4321 | 1434 | c x = adi16buf(adi16ilbuf) | ||
4322 | 1435 | c ENDIF | ||
4323 | 1436 | c ENDIF | ||
4324 | 1437 | c END | ||
4325 | 1438 | c | ||
4326 | 1439 | c SUBROUTINE POPINTEGER16(x) | ||
4327 | 1440 | c INTEGER*16 x, adi16buf(512), adi16lbuf(512) | ||
4328 | 1441 | c INTEGER adi16ibuf,adi16ilbuf | ||
4329 | 1442 | c LOGICAL adi16inlbuf | ||
4330 | 1443 | c COMMON /adi16fbuf/adi16buf,adi16lbuf, | ||
4331 | 1444 | c + adi16ibuf,adi16ilbuf,adi16inlbuf | ||
4332 | 1445 | c LOGICAL looking | ||
4333 | 1446 | c COMMON /lookingfbuf/looking | ||
4334 | 1447 | c c | ||
4335 | 1448 | c IF (adi16ilbuf.ne.-1) THEN | ||
4336 | 1449 | c adi16ilbuf = -1 | ||
4337 | 1450 | c adi16inlbuf = .FALSE. | ||
4338 | 1451 | c looking = .FALSE. | ||
4339 | 1452 | c ENDIF | ||
4340 | 1453 | c IF (adi16ibuf.le.1) THEN | ||
4341 | 1454 | c CALL POPINTEGER16ARRAY(adi16buf, 512) | ||
4342 | 1455 | c adi16ibuf = 512 | ||
4343 | 1456 | c x = adi16buf(512) | ||
4344 | 1457 | c ELSE | ||
4345 | 1458 | c adi16ibuf = adi16ibuf-1 | ||
4346 | 1459 | c x = adi16buf(adi16ibuf) | ||
4347 | 1460 | c ENDIF | ||
4348 | 1461 | c END | ||
4349 | 1462 | |||
4350 | 1463 | c======================= REAL*32 ========================= | ||
4351 | 1464 | c BLOCK DATA REALS32 | ||
4352 | 1465 | c REAL*32 adr32buf(512), adr32lbuf(512) | ||
4353 | 1466 | c INTEGER adr32ibuf,adr32ilbuf | ||
4354 | 1467 | c LOGICAL adr32inlbuf | ||
4355 | 1468 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4356 | 1469 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4357 | 1470 | c DATA adr32ibuf/1/ | ||
4358 | 1471 | c DATA adr32ilbuf/-1/ | ||
4359 | 1472 | c DATA adr32inlbuf/.FALSE./ | ||
4360 | 1473 | c END | ||
4361 | 1474 | c c | ||
4362 | 1475 | c SUBROUTINE PUSHREAL32(x) | ||
4363 | 1476 | c REAL*32 x, adr32buf(512), adr32lbuf(512) | ||
4364 | 1477 | c INTEGER adr32ibuf,adr32ilbuf | ||
4365 | 1478 | c LOGICAL adr32inlbuf | ||
4366 | 1479 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4367 | 1480 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4368 | 1481 | c LOGICAL looking | ||
4369 | 1482 | c COMMON /lookingfbuf/looking | ||
4370 | 1483 | c c | ||
4371 | 1484 | c CALL addftraffic(32) | ||
4372 | 1485 | c IF (adr32ilbuf.ne.-1) THEN | ||
4373 | 1486 | c adr32ilbuf = -1 | ||
4374 | 1487 | c adr32inlbuf = .FALSE. | ||
4375 | 1488 | c looking = .FALSE. | ||
4376 | 1489 | c ENDIF | ||
4377 | 1490 | c IF (adr32ibuf.ge.512) THEN | ||
4378 | 1491 | c adr32buf(512) = x | ||
4379 | 1492 | c CALL PUSHREAL32ARRAY(adr32buf, 512) | ||
4380 | 1493 | c CALL addftraffic(-16384) | ||
4381 | 1494 | c adr32ibuf = 1 | ||
4382 | 1495 | c ELSE | ||
4383 | 1496 | c adr32buf(adr32ibuf) = x | ||
4384 | 1497 | c adr32ibuf = adr32ibuf+1 | ||
4385 | 1498 | c ENDIF | ||
4386 | 1499 | c END | ||
4387 | 1500 | c | ||
4388 | 1501 | c SUBROUTINE LOOKREAL32(x) | ||
4389 | 1502 | c REAL*32 x, adr32buf(512), adr32lbuf(512) | ||
4390 | 1503 | c INTEGER adr32ibuf,adr32ilbuf | ||
4391 | 1504 | c LOGICAL adr32inlbuf | ||
4392 | 1505 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4393 | 1506 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4394 | 1507 | c LOGICAL looking | ||
4395 | 1508 | c COMMON /lookingfbuf/looking | ||
4396 | 1509 | c c | ||
4397 | 1510 | c IF (adr32ilbuf.eq.-1) THEN | ||
4398 | 1511 | c adr32ilbuf=adr32ibuf | ||
4399 | 1512 | c IF (.not.looking) THEN | ||
4400 | 1513 | c CALL RESETADLOOKSTACK() | ||
4401 | 1514 | c looking = .TRUE. | ||
4402 | 1515 | c ENDIF | ||
4403 | 1516 | c ENDIF | ||
4404 | 1517 | c IF (adr32ilbuf.le.1) THEN | ||
4405 | 1518 | c CALL LOOKREAL32ARRAY(adr32lbuf, 512) | ||
4406 | 1519 | c adr32inlbuf = .TRUE. | ||
4407 | 1520 | c adr32ilbuf = 512 | ||
4408 | 1521 | c x = adr32lbuf(512) | ||
4409 | 1522 | c ELSE | ||
4410 | 1523 | c adr32ilbuf = adr32ilbuf-1 | ||
4411 | 1524 | c if (adr32inlbuf) THEN | ||
4412 | 1525 | c x = adr32lbuf(adr32ilbuf) | ||
4413 | 1526 | c ELSE | ||
4414 | 1527 | c x = adr32buf(adr32ilbuf) | ||
4415 | 1528 | c ENDIF | ||
4416 | 1529 | c ENDIF | ||
4417 | 1530 | c END | ||
4418 | 1531 | c | ||
4419 | 1532 | c SUBROUTINE POPREAL32(x) | ||
4420 | 1533 | c REAL*32 x, adr32buf(512), adr32lbuf(512) | ||
4421 | 1534 | c INTEGER adr32ibuf,adr32ilbuf | ||
4422 | 1535 | c LOGICAL adr32inlbuf | ||
4423 | 1536 | c COMMON /adr32fbuf/adr32buf,adr32lbuf, | ||
4424 | 1537 | c + adr32ibuf,adr32ilbuf,adr32inlbuf | ||
4425 | 1538 | c LOGICAL looking | ||
4426 | 1539 | c COMMON /lookingfbuf/looking | ||
4427 | 1540 | c c | ||
4428 | 1541 | c IF (adr32ilbuf.ne.-1) THEN | ||
4429 | 1542 | c adr32ilbuf = -1 | ||
4430 | 1543 | c adr32inlbuf = .FALSE. | ||
4431 | 1544 | c looking = .FALSE. | ||
4432 | 1545 | c ENDIF | ||
4433 | 1546 | c IF (adr32ibuf.le.1) THEN | ||
4434 | 1547 | c CALL POPREAL32ARRAY(adr32buf, 512) | ||
4435 | 1548 | c adr32ibuf = 512 | ||
4436 | 1549 | c x = adr32buf(512) | ||
4437 | 1550 | c ELSE | ||
4438 | 1551 | c adr32ibuf = adr32ibuf-1 | ||
4439 | 1552 | c x = adr32buf(adr32ibuf) | ||
4440 | 1553 | c ENDIF | ||
4441 | 1554 | c END | ||
4442 | 1555 | |||
4443 | 1556 | c======================= COMPLEX*4 ========================= | ||
4444 | 1557 | c BLOCK DATA COMPLEXS4 | ||
4445 | 1558 | c COMPLEX*4 adc4buf(512), adc4lbuf(512) | ||
4446 | 1559 | c INTEGER adc4ibuf,adc4ilbuf | ||
4447 | 1560 | c LOGICAL adc4inlbuf | ||
4448 | 1561 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4449 | 1562 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4450 | 1563 | c DATA adc4ibuf/1/ | ||
4451 | 1564 | c DATA adc4ilbuf/-1/ | ||
4452 | 1565 | c DATA adc4inlbuf/.FALSE./ | ||
4453 | 1566 | c END | ||
4454 | 1567 | c c | ||
4455 | 1568 | c SUBROUTINE PUSHCOMPLEX4(x) | ||
4456 | 1569 | c COMPLEX*4 x, adc4buf(512), adc4lbuf(512) | ||
4457 | 1570 | c INTEGER adc4ibuf,adc4ilbuf | ||
4458 | 1571 | c LOGICAL adc4inlbuf | ||
4459 | 1572 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4460 | 1573 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4461 | 1574 | c LOGICAL looking | ||
4462 | 1575 | c COMMON /lookingfbuf/looking | ||
4463 | 1576 | c c | ||
4464 | 1577 | c CALL addftraffic(4) | ||
4465 | 1578 | c IF (adc4ilbuf.ne.-1) THEN | ||
4466 | 1579 | c adc4ilbuf = -1 | ||
4467 | 1580 | c adc4inlbuf = .FALSE. | ||
4468 | 1581 | c looking = .FALSE. | ||
4469 | 1582 | c ENDIF | ||
4470 | 1583 | c IF (adc4ibuf.ge.512) THEN | ||
4471 | 1584 | c adc4buf(512) = x | ||
4472 | 1585 | c CALL PUSHCOMPLEX4ARRAY(adc4buf, 512) | ||
4473 | 1586 | c CALL addftraffic(-2048) | ||
4474 | 1587 | c adc4ibuf = 1 | ||
4475 | 1588 | c ELSE | ||
4476 | 1589 | c adc4buf(adc4ibuf) = x | ||
4477 | 1590 | c adc4ibuf = adc4ibuf+1 | ||
4478 | 1591 | c ENDIF | ||
4479 | 1592 | c END | ||
4480 | 1593 | c | ||
4481 | 1594 | c SUBROUTINE LOOKCOMPLEX4(x) | ||
4482 | 1595 | c COMPLEX*4 x, adc4buf(512), adc4lbuf(512) | ||
4483 | 1596 | c INTEGER adc4ibuf,adc4ilbuf | ||
4484 | 1597 | c LOGICAL adc4inlbuf | ||
4485 | 1598 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4486 | 1599 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4487 | 1600 | c LOGICAL looking | ||
4488 | 1601 | c COMMON /lookingfbuf/looking | ||
4489 | 1602 | c c | ||
4490 | 1603 | c IF (adc4ilbuf.eq.-1) THEN | ||
4491 | 1604 | c adc4ilbuf=adc4ibuf | ||
4492 | 1605 | c IF (.not.looking) THEN | ||
4493 | 1606 | c CALL RESETADLOOKSTACK() | ||
4494 | 1607 | c looking = .TRUE. | ||
4495 | 1608 | c ENDIF | ||
4496 | 1609 | c ENDIF | ||
4497 | 1610 | c IF (adc4ilbuf.le.1) THEN | ||
4498 | 1611 | c CALL LOOKCOMPLEX4ARRAY(adc4lbuf, 512) | ||
4499 | 1612 | c adc4inlbuf = .TRUE. | ||
4500 | 1613 | c adc4ilbuf = 512 | ||
4501 | 1614 | c x = adc4lbuf(512) | ||
4502 | 1615 | c ELSE | ||
4503 | 1616 | c adc4ilbuf = adc4ilbuf-1 | ||
4504 | 1617 | c if (adc4inlbuf) THEN | ||
4505 | 1618 | c x = adc4lbuf(adc4ilbuf) | ||
4506 | 1619 | c ELSE | ||
4507 | 1620 | c x = adc4buf(adc4ilbuf) | ||
4508 | 1621 | c ENDIF | ||
4509 | 1622 | c ENDIF | ||
4510 | 1623 | c END | ||
4511 | 1624 | c | ||
4512 | 1625 | c SUBROUTINE POPCOMPLEX4(x) | ||
4513 | 1626 | c COMPLEX*4 x, adc4buf(512), adc4lbuf(512) | ||
4514 | 1627 | c INTEGER adc4ibuf,adc4ilbuf | ||
4515 | 1628 | c LOGICAL adc4inlbuf | ||
4516 | 1629 | c COMMON /adc4fbuf/adc4buf,adc4lbuf, | ||
4517 | 1630 | c + adc4ibuf,adc4ilbuf,adc4inlbuf | ||
4518 | 1631 | c LOGICAL looking | ||
4519 | 1632 | c COMMON /lookingfbuf/looking | ||
4520 | 1633 | c c | ||
4521 | 1634 | c IF (adc4ilbuf.ne.-1) THEN | ||
4522 | 1635 | c adc4ilbuf = -1 | ||
4523 | 1636 | c adc4inlbuf = .FALSE. | ||
4524 | 1637 | c looking = .FALSE. | ||
4525 | 1638 | c ENDIF | ||
4526 | 1639 | c IF (adc4ibuf.le.1) THEN | ||
4527 | 1640 | c CALL POPCOMPLEX4ARRAY(adc4buf, 512) | ||
4528 | 1641 | c adc4ibuf = 512 | ||
4529 | 1642 | c x = adc4buf(512) | ||
4530 | 1643 | c ELSE | ||
4531 | 1644 | c adc4ibuf = adc4ibuf-1 | ||
4532 | 1645 | c x = adc4buf(adc4ibuf) | ||
4533 | 1646 | c ENDIF | ||
4534 | 1647 | c END | ||
4535 | 1648 | |||
4536 | 1649 | c======================= COMPLEX*32 ========================= | ||
4537 | 1650 | c BLOCK DATA COMPLEXS32 | ||
4538 | 1651 | c COMPLEX*32 adc32buf(512), adc32lbuf(512) | ||
4539 | 1652 | c INTEGER adc32ibuf,adc32ilbuf | ||
4540 | 1653 | c LOGICAL adc32inlbuf | ||
4541 | 1654 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4542 | 1655 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4543 | 1656 | c DATA adc32ibuf/1/ | ||
4544 | 1657 | c DATA adc32ilbuf/-1/ | ||
4545 | 1658 | c DATA adc32inlbuf/.FALSE./ | ||
4546 | 1659 | c END | ||
4547 | 1660 | c c | ||
4548 | 1661 | c SUBROUTINE PUSHCOMPLEX32(x) | ||
4549 | 1662 | c COMPLEX*32 x, adc32buf(512), adc32lbuf(512) | ||
4550 | 1663 | c INTEGER adc32ibuf,adc32ilbuf | ||
4551 | 1664 | c LOGICAL adc32inlbuf | ||
4552 | 1665 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4553 | 1666 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4554 | 1667 | c LOGICAL looking | ||
4555 | 1668 | c COMMON /lookingfbuf/looking | ||
4556 | 1669 | c c | ||
4557 | 1670 | c CALL addftraffic(32) | ||
4558 | 1671 | c IF (adc32ilbuf.ne.-1) THEN | ||
4559 | 1672 | c adc32ilbuf = -1 | ||
4560 | 1673 | c adc32inlbuf = .FALSE. | ||
4561 | 1674 | c looking = .FALSE. | ||
4562 | 1675 | c ENDIF | ||
4563 | 1676 | c IF (adc32ibuf.ge.512) THEN | ||
4564 | 1677 | c adc32buf(512) = x | ||
4565 | 1678 | c CALL PUSHCOMPLEX32ARRAY(adc32buf, 512) | ||
4566 | 1679 | c CALL addftraffic(-16384) | ||
4567 | 1680 | c adc32ibuf = 1 | ||
4568 | 1681 | c ELSE | ||
4569 | 1682 | c adc32buf(adc32ibuf) = x | ||
4570 | 1683 | c adc32ibuf = adc32ibuf+1 | ||
4571 | 1684 | c ENDIF | ||
4572 | 1685 | c END | ||
4573 | 1686 | c | ||
4574 | 1687 | c SUBROUTINE LOOKCOMPLEX32(x) | ||
4575 | 1688 | c COMPLEX*32 x, adc32buf(512), adc32lbuf(512) | ||
4576 | 1689 | c INTEGER adc32ibuf,adc32ilbuf | ||
4577 | 1690 | c LOGICAL adc32inlbuf | ||
4578 | 1691 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4579 | 1692 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4580 | 1693 | c LOGICAL looking | ||
4581 | 1694 | c COMMON /lookingfbuf/looking | ||
4582 | 1695 | c c | ||
4583 | 1696 | c IF (adc32ilbuf.eq.-1) THEN | ||
4584 | 1697 | c adc32ilbuf=adc32ibuf | ||
4585 | 1698 | c IF (.not.looking) THEN | ||
4586 | 1699 | c CALL RESETADLOOKSTACK() | ||
4587 | 1700 | c looking = .TRUE. | ||
4588 | 1701 | c ENDIF | ||
4589 | 1702 | c ENDIF | ||
4590 | 1703 | c IF (adc32ilbuf.le.1) THEN | ||
4591 | 1704 | c CALL LOOKCOMPLEX32ARRAY(adc32lbuf, 512) | ||
4592 | 1705 | c adc32inlbuf = .TRUE. | ||
4593 | 1706 | c adc32ilbuf = 512 | ||
4594 | 1707 | c x = adc32lbuf(512) | ||
4595 | 1708 | c ELSE | ||
4596 | 1709 | c adc32ilbuf = adc32ilbuf-1 | ||
4597 | 1710 | c if (adc32inlbuf) THEN | ||
4598 | 1711 | c x = adc32lbuf(adc32ilbuf) | ||
4599 | 1712 | c ELSE | ||
4600 | 1713 | c x = adc32buf(adc32ilbuf) | ||
4601 | 1714 | c ENDIF | ||
4602 | 1715 | c ENDIF | ||
4603 | 1716 | c END | ||
4604 | 1717 | c | ||
4605 | 1718 | c SUBROUTINE POPCOMPLEX32(x) | ||
4606 | 1719 | c COMPLEX*32 x, adc32buf(512), adc32lbuf(512) | ||
4607 | 1720 | c INTEGER adc32ibuf,adc32ilbuf | ||
4608 | 1721 | c LOGICAL adc32inlbuf | ||
4609 | 1722 | c COMMON /adc32fbuf/adc32buf,adc32lbuf, | ||
4610 | 1723 | c + adc32ibuf,adc32ilbuf,adc32inlbuf | ||
4611 | 1724 | c LOGICAL looking | ||
4612 | 1725 | c COMMON /lookingfbuf/looking | ||
4613 | 1726 | c c | ||
4614 | 1727 | c IF (adc32ilbuf.ne.-1) THEN | ||
4615 | 1728 | c adc32ilbuf = -1 | ||
4616 | 1729 | c adc32inlbuf = .FALSE. | ||
4617 | 1730 | c looking = .FALSE. | ||
4618 | 1731 | c ENDIF | ||
4619 | 1732 | c IF (adc32ibuf.le.1) THEN | ||
4620 | 1733 | c CALL POPCOMPLEX32ARRAY(adc32buf, 512) | ||
4621 | 1734 | c adc32ibuf = 512 | ||
4622 | 1735 | c x = adc32buf(512) | ||
4623 | 1736 | c ELSE | ||
4624 | 1737 | c adc32ibuf = adc32ibuf-1 | ||
4625 | 1738 | c x = adc32buf(adc32ibuf) | ||
4626 | 1739 | c ENDIF | ||
4627 | 1740 | c END | ||
4628 | 1741 | |||
4629 | 1742 | C======================================================== | ||
4630 | 1743 | C HOW TO CREATE PUSH* POP* SUBROUTINES | ||
4631 | 1744 | C YET FOR OTHER DATA TYPES | ||
4632 | 1745 | C ** Duplicate the commented program lines below | ||
4633 | 1746 | c ** In the duplicated subroutines, replace: | ||
4634 | 1747 | c TTTT by the basic name of the type | ||
4635 | 1748 | c z9 by the initial and size of the type | ||
4636 | 1749 | c (integer:i real:r complex:c boolean:b character:s) | ||
4637 | 1750 | c 9 by the size of the type | ||
4638 | 1751 | c ** Uncomment the duplicated subroutines | ||
4639 | 1752 | C ** Don't forget to insert the corresponding lines in | ||
4640 | 1753 | C subroutine PRINTBUFFERTOP, otherwise these types' | ||
4641 | 1754 | C contribution to buffer occupation will not be seen. | ||
4642 | 1755 | C (not very important anyway...) | ||
4643 | 1756 | |||
4644 | 1757 | c======================= TTTT*9 ========================= | ||
4645 | 1758 | c BLOCK DATA TTTTS9 | ||
4646 | 1759 | c TTTT*9 adz9buf(512), adz9lbuf(512) | ||
4647 | 1760 | c INTEGER adz9ibuf,adz9ilbuf | ||
4648 | 1761 | c LOGICAL adz9inlbuf | ||
4649 | 1762 | c COMMON /adz9fbuf/adz9buf,adz9lbuf, | ||
4650 | 1763 | c + adz9ibuf,adz9ilbuf,adz9inlbuf | ||
4651 | 1764 | c DATA adz9ibuf/1/ | ||
4652 | 1765 | c DATA adz9ilbuf/-1/ | ||
4653 | 1766 | c DATA adz9inlbuf/.FALSE./ | ||
4654 | 1767 | c END | ||
4655 | 1768 | c c | ||
4656 | 1769 | c SUBROUTINE PUSHTTTT9(x) | ||
4657 | 1770 | c TTTT*9 x, adz9buf(512), adz9lbuf(512) | ||
4658 | 1771 | c INTEGER adz9ibuf,adz9ilbuf | ||
4659 | 1772 | c LOGICAL adz9inlbuf | ||
4660 | 1773 | c COMMON /adz9fbuf/adz9buf,adz9lbuf, | ||
4661 | 1774 | c + adz9ibuf,adz9ilbuf,adz9inlbuf | ||
4662 | 1775 | c LOGICAL looking | ||
4663 | 1776 | c COMMON /lookingfbuf/looking | ||
4664 | 1777 | c c | ||
4665 | 1778 | c CALL addftraffic(9) | ||
4666 | 1779 | c IF (adz9ilbuf.ne.-1) THEN | ||
4667 | 1780 | c adz9ilbuf = -1 | ||
4668 | 1781 | c adz9inlbuf = .FALSE. | ||
4669 | 1782 | c looking = .FALSE. | ||
4670 | 1783 | c ENDIF | ||
4671 | 1784 | c IF (adz9ibuf.ge.512) THEN | ||
4672 | 1785 | c adz9buf(512) = x | ||
4673 | 1786 | c CALL PUSHTTTT9ARRAY(adz9buf, 512) | ||
4674 | 1787 | c CALL addftraffic(-9*512) | ||
4675 | 1788 | c adz9ibuf = 1 | ||
4676 | 1789 | c ELSE | ||
4677 | 1790 | c adz9buf(adz9ibuf) = x | ||
4678 | 1791 | c adz9ibuf = adz9ibuf+1 | ||
4679 | 1792 | c ENDIF | ||
4680 | 1793 | c END | ||
4681 | 1794 | c | ||
4682 | 1795 | c SUBROUTINE LOOKTTTT9(x) | ||
4683 | 1796 | c TTTT*9 x, adz9buf(512), adz9lbuf(512) | ||
4684 | 1797 | c INTEGER adz9ibuf,adz9ilbuf | ||
4685 | 1798 | c LOGICAL adz9inlbuf | ||
4686 | 1799 | c COMMON /adz9fbuf/adz9buf,adz9lbuf, | ||
4687 | 1800 | c + adz9ibuf,adz9ilbuf,adz9inlbuf | ||
4688 | 1801 | c LOGICAL looking | ||
4689 | 1802 | c COMMON /lookingfbuf/looking | ||
4690 | 1803 | c c | ||
4691 | 1804 | c IF (adz9ilbuf.eq.-1) THEN | ||
4692 | 1805 | c adz9ilbuf=adz9ibuf | ||
4693 | 1806 | c IF (.not.looking) THEN | ||
4694 | 1807 | c CALL RESETADLOOKSTACK() | ||
4695 | 1808 | c looking = .TRUE. | ||
4696 | 1809 | c ENDIF | ||
4697 | 1810 | c ENDIF | ||
4698 | 1811 | c IF (adz9ilbuf.le.1) THEN | ||
4699 | 1812 | c CALL LOOKTTTT9ARRAY(adz9lbuf, 512) | ||
4700 | 1813 | c adz9inlbuf = .TRUE. | ||
4701 | 1814 | c adz9ilbuf = 512 | ||
4702 | 1815 | c x = adz9lbuf(512) | ||
4703 | 1816 | c ELSE | ||
4704 | 1817 | c adz9ilbuf = adz9ilbuf-1 | ||
4705 | 1818 | c if (adz9inlbuf) THEN | ||
4706 | 1819 | c x = adz9lbuf(adz9ilbuf) | ||
4707 | 1820 | c ELSE | ||
4708 | 1821 | c x = adz9buf(adz9ilbuf) | ||
4709 | 1822 | c ENDIF | ||
4710 | 1823 | c ENDIF | ||
4711 | 1824 | c END | ||
4712 | 1825 | c | ||
4713 | 1826 | c SUBROUTINE POPTTTT9(x) | ||
4714 | 1827 | c TTTT*9 x, adz9buf(512), adz9lbuf(512) | ||
4715 | 1828 | c INTEGER adz9ibuf,adz9ilbuf | ||
4716 | 1829 | c LOGICAL adz9inlbuf | ||
4717 | 1830 | c COMMON /adz9fbuf/adz9buf,adz9lbuf, | ||
4718 | 1831 | c + adz9ibuf,adz9ilbuf,adz9inlbuf | ||
4719 | 1832 | c LOGICAL looking | ||
4720 | 1833 | c COMMON /lookingfbuf/looking | ||
4721 | 1834 | c c | ||
4722 | 1835 | c IF (adz9ilbuf.ne.-1) THEN | ||
4723 | 1836 | c adz9ilbuf = -1 | ||
4724 | 1837 | c adz9inlbuf = .FALSE. | ||
4725 | 1838 | c looking = .FALSE. | ||
4726 | 1839 | c ENDIF | ||
4727 | 1840 | c IF (adz9ibuf.le.1) THEN | ||
4728 | 1841 | c CALL POPTTTT9ARRAY(adz9buf, 512) | ||
4729 | 1842 | c adz9ibuf = 512 | ||
4730 | 1843 | c x = adz9buf(512) | ||
4731 | 1844 | c ELSE | ||
4732 | 1845 | c adz9ibuf = adz9ibuf-1 | ||
4733 | 1846 | c x = adz9buf(adz9ibuf) | ||
4734 | 1847 | c ENDIF | ||
4735 | 1848 | c END | ||
4736 | 0 | 1849 | ||
4737 | === added file 'adjoint/adStack.c' | |||
4738 | --- adjoint/adStack.c 1970-01-01 00:00:00 +0000 | |||
4739 | +++ adjoint/adStack.c 2011-07-12 15:56:32 +0000 | |||
4740 | @@ -0,0 +1,683 @@ | |||
4741 | 1 | static char adSid[]="$Id: adStack.c 3919 2011-05-18 15:51:18Z llh $"; | ||
4742 | 2 | |||
4743 | 3 | #include <stdlib.h> | ||
4744 | 4 | #include <stdio.h> | ||
4745 | 5 | #include <string.h> | ||
4746 | 6 | |||
4747 | 7 | #define ONE_BLOCK_SIZE 16384 | ||
4748 | 8 | #ifndef STACK_SIZE_TRACING | ||
4749 | 9 | #define STACK_SIZE_TRACING 1 | ||
4750 | 10 | #endif | ||
4751 | 11 | /* The main stack is a double-chain of DoubleChainedBlock objects. | ||
4752 | 12 | * Each DoubleChainedBlock holds an array[ONE_BLOCK_SIZE] of char. */ | ||
4753 | 13 | typedef struct _doubleChainedBlock{ | ||
4754 | 14 | struct _doubleChainedBlock *prev ; | ||
4755 | 15 | char *contents ; | ||
4756 | 16 | struct _doubleChainedBlock *next ; | ||
4757 | 17 | } DoubleChainedBlock ; | ||
4758 | 18 | |||
4759 | 19 | /* Globals that define the current position in the stack: */ | ||
4760 | 20 | static DoubleChainedBlock *curStack = NULL ; | ||
4761 | 21 | static char *curStackTop = NULL ; | ||
4762 | 22 | /* Globals that define the current LOOKing position in the stack: */ | ||
4763 | 23 | static DoubleChainedBlock *lookStack = NULL ; | ||
4764 | 24 | static char *lookStackTop = NULL ; | ||
4765 | 25 | |||
4766 | 26 | static long int mmctraffic = 0 ; | ||
4767 | 27 | static long int mmctrafficM = 0 ; | ||
4768 | 28 | #ifdef STACK_SIZE_TRACING | ||
4769 | 29 | long int bigStackSize = 0; | ||
4770 | 30 | #endif | ||
4771 | 31 | |||
4772 | 32 | /* PUSHes "nbChars" consecutive chars from a location starting at address "x". | ||
4773 | 33 | * Resets the LOOKing position if it was active. | ||
4774 | 34 | * Checks that there is enough space left to hold "nbChars" chars. | ||
4775 | 35 | * Otherwise, allocates the necessary space. */ | ||
4776 | 36 | void pushNarray(char *x, unsigned int nbChars) { | ||
4777 | 37 | unsigned int nbmax = (curStack)?ONE_BLOCK_SIZE-(curStackTop-(curStack->contents)):0 ; | ||
4778 | 38 | #ifdef STACK_SIZE_TRACING | ||
4779 | 39 | bigStackSize += nbChars; | ||
4780 | 40 | #endif | ||
4781 | 41 | |||
4782 | 42 | mmctraffic += nbChars ; | ||
4783 | 43 | while (mmctraffic >= 1000000) { | ||
4784 | 44 | mmctraffic -= 1000000 ; | ||
4785 | 45 | mmctrafficM++ ; | ||
4786 | 46 | } | ||
4787 | 47 | |||
4788 | 48 | lookStack = NULL ; | ||
4789 | 49 | if (nbChars <= nbmax) { | ||
4790 | 50 | memcpy(curStackTop,x,nbChars) ; | ||
4791 | 51 | curStackTop+=nbChars ; | ||
4792 | 52 | } else { | ||
4793 | 53 | char *inx = x+(nbChars-nbmax) ; | ||
4794 | 54 | if (nbmax>0) memcpy(curStackTop,inx,nbmax) ; | ||
4795 | 55 | while (inx>x) { | ||
4796 | 56 | if ((curStack == NULL) || (curStack->next == NULL)) { | ||
4797 | 57 | /* Create new block: */ | ||
4798 | 58 | DoubleChainedBlock *newStack ; | ||
4799 | 59 | char *contents = (char*)malloc(ONE_BLOCK_SIZE*sizeof(char)) ; | ||
4800 | 60 | newStack = (DoubleChainedBlock*)malloc(sizeof(DoubleChainedBlock)) ; | ||
4801 | 61 | if ((contents == NULL) || (newStack == NULL)) { | ||
4802 | 62 | DoubleChainedBlock *stack = curStack ; | ||
4803 | 63 | int nbBlocks = (stack?-1:0) ; | ||
4804 | 64 | while(stack) { | ||
4805 | 65 | stack = stack->prev ; | ||
4806 | 66 | nbBlocks++ ; | ||
4807 | 67 | } | ||
4808 | 68 | printf("Out of memory (allocated %i blocks of %i bytes)\n", | ||
4809 | 69 | nbBlocks, ONE_BLOCK_SIZE) ; | ||
4810 | 70 | exit(0); | ||
4811 | 71 | } | ||
4812 | 72 | if (curStack != NULL) curStack->next = newStack ; | ||
4813 | 73 | newStack->prev = curStack ; | ||
4814 | 74 | newStack->next = NULL ; | ||
4815 | 75 | newStack->contents = contents ; | ||
4816 | 76 | curStack = newStack ; | ||
4817 | 77 | /* new block created! */ | ||
4818 | 78 | } else | ||
4819 | 79 | curStack = curStack->next ; | ||
4820 | 80 | inx -= ONE_BLOCK_SIZE ; | ||
4821 | 81 | if(inx>x) | ||
4822 | 82 | memcpy(curStack->contents,inx,ONE_BLOCK_SIZE) ; | ||
4823 | 83 | else { | ||
4824 | 84 | unsigned int nbhead = (inx-x)+ONE_BLOCK_SIZE ; | ||
4825 | 85 | curStackTop = curStack->contents ; | ||
4826 | 86 | memcpy(curStackTop,x,nbhead) ; | ||
4827 | 87 | curStackTop += nbhead ; | ||
4828 | 88 | } | ||
4829 | 89 | } | ||
4830 | 90 | } | ||
4831 | 91 | } | ||
4832 | 92 | |||
4833 | 93 | /* POPs "nbChars" consecutive chars to a location starting at address "x". | ||
4834 | 94 | * Resets the LOOKing position if it was active. | ||
4835 | 95 | * Checks that there is enough data to fill "nbChars" chars. | ||
4836 | 96 | * Otherwise, pops as many blocks as necessary. */ | ||
4837 | 97 | void popNarray(char *x, unsigned int nbChars) { | ||
4838 | 98 | unsigned int nbmax = curStackTop-(curStack->contents) ; | ||
4839 | 99 | #ifdef STACK_SIZE_TRACING | ||
4840 | 100 | bigStackSize -= nbChars; | ||
4841 | 101 | #endif | ||
4842 | 102 | lookStack = NULL ; | ||
4843 | 103 | if (nbChars <= nbmax) { | ||
4844 | 104 | curStackTop-=nbChars ; | ||
4845 | 105 | memcpy(x,curStackTop,nbChars); | ||
4846 | 106 | } else { | ||
4847 | 107 | char *tlx = x+nbChars ; | ||
4848 | 108 | if (nbmax>0) memcpy(x,curStack->contents,nbmax) ; | ||
4849 | 109 | x+=nbmax ; | ||
4850 | 110 | while (x<tlx) { | ||
4851 | 111 | curStack = curStack->prev ; | ||
4852 | 112 | if (curStack==NULL) printf("Popping from an empty stack!!!") ; | ||
4853 | 113 | if (x+ONE_BLOCK_SIZE<tlx) { | ||
4854 | 114 | memcpy(x,curStack->contents,ONE_BLOCK_SIZE) ; | ||
4855 | 115 | x += ONE_BLOCK_SIZE ; | ||
4856 | 116 | } else { | ||
4857 | 117 | unsigned int nbtail = tlx-x ; | ||
4858 | 118 | curStackTop=(curStack->contents)+ONE_BLOCK_SIZE-nbtail ; | ||
4859 | 119 | memcpy(x,curStackTop,nbtail) ; | ||
4860 | 120 | x = tlx ; | ||
4861 | 121 | } | ||
4862 | 122 | } | ||
4863 | 123 | } | ||
4864 | 124 | } | ||
4865 | 125 | |||
4866 | 126 | /* LOOKs "nbChars" consecutive chars to a location starting at address "x". | ||
4867 | 127 | * Activates the LOOKing position if it was reset. | ||
4868 | 128 | * LOOKing is just like POPping, except that the main pointer | ||
4869 | 129 | * remains in place, so that the value is not POPped. | ||
4870 | 130 | * Further PUSHs or POPs will start from the same place as if | ||
4871 | 131 | * no LOOK had been made. */ | ||
4872 | 132 | void lookNarray(char *x, unsigned int nbChars) { | ||
4873 | 133 | unsigned int nbmax ; | ||
4874 | 134 | if (lookStack == NULL) { | ||
4875 | 135 | lookStack = curStack ; | ||
4876 | 136 | lookStackTop = curStackTop ; | ||
4877 | 137 | } | ||
4878 | 138 | nbmax = lookStackTop-(lookStack->contents) ; | ||
4879 | 139 | if (nbChars <= nbmax) { | ||
4880 | 140 | lookStackTop-=nbChars ; | ||
4881 | 141 | memcpy(x,lookStackTop,nbChars); | ||
4882 | 142 | } else { | ||
4883 | 143 | char *tlx = x+nbChars ; | ||
4884 | 144 | if (nbmax>0) memcpy(x,lookStack->contents,nbmax) ; | ||
4885 | 145 | x+=nbmax ; | ||
4886 | 146 | while (x<tlx) { | ||
4887 | 147 | lookStack = lookStack->prev ; | ||
4888 | 148 | if (lookStack==NULL) printf("Looking into an empty stack!!!") ; | ||
4889 | 149 | if (x+ONE_BLOCK_SIZE<tlx) { | ||
4890 | 150 | memcpy(x,lookStack->contents,ONE_BLOCK_SIZE) ; | ||
4891 | 151 | x += ONE_BLOCK_SIZE ; | ||
4892 | 152 | } else { | ||
4893 | 153 | unsigned int nbtail = tlx-x ; | ||
4894 | 154 | lookStackTop=(lookStack->contents)+ONE_BLOCK_SIZE-nbtail ; | ||
4895 | 155 | memcpy(x,lookStackTop,nbtail) ; | ||
4896 | 156 | x = tlx ; | ||
4897 | 157 | } | ||
4898 | 158 | } | ||
4899 | 159 | } | ||
4900 | 160 | } | ||
4901 | 161 | |||
4902 | 162 | void resetadlookstack_() { | ||
4903 | 163 | lookStack=NULL ; | ||
4904 | 164 | } | ||
4905 | 165 | |||
4906 | 166 | /****** Exported PUSH/POP/LOOK functions for ARRAYS: ******/ | ||
4907 | 167 | /* --> Called from FORTRAN: */ | ||
4908 | 168 | |||
4909 | 169 | void pushcharacterarray_(char *x, unsigned int *n) { | ||
4910 | 170 | pushNarray(x,*n) ; | ||
4911 | 171 | } | ||
4912 | 172 | void popcharacterarray_(char *x, unsigned int *n) { | ||
4913 | 173 | popNarray(x,*n) ; | ||
4914 | 174 | } | ||
4915 | 175 | void lookcharacterarray_(char *x, unsigned int *n) { | ||
4916 | 176 | lookNarray(x,*n) ; | ||
4917 | 177 | } | ||
4918 | 178 | |||
4919 | 179 | void pushbooleanarray_(char *x, unsigned int *n) { | ||
4920 | 180 | pushNarray(x,(*n*4)) ; | ||
4921 | 181 | } | ||
4922 | 182 | void popbooleanarray_(char *x, unsigned int *n) { | ||
4923 | 183 | popNarray(x,(*n*4)) ; | ||
4924 | 184 | } | ||
4925 | 185 | void lookbooleanarray_(char *x, unsigned int *n) { | ||
4926 | 186 | lookNarray(x,(*n*4)) ; | ||
4927 | 187 | } | ||
4928 | 188 | |||
4929 | 189 | void pushinteger4array_(char *x, unsigned int *n) { | ||
4930 | 190 | pushNarray(x,(*n*4)) ; | ||
4931 | 191 | } | ||
4932 | 192 | void popinteger4array_(char *x, unsigned int *n) { | ||
4933 | 193 | popNarray(x,(*n*4)) ; | ||
4934 | 194 | } | ||
4935 | 195 | void lookinteger4array_(char *x, unsigned int *n) { | ||
4936 | 196 | lookNarray(x,(*n*4)) ; | ||
4937 | 197 | } | ||
4938 | 198 | |||
4939 | 199 | void pushinteger8array_(char *x, unsigned int *n) { | ||
4940 | 200 | pushNarray(x,(*n*8)) ; | ||
4941 | 201 | } | ||
4942 | 202 | void popinteger8array_(char *x, unsigned int *n) { | ||
4943 | 203 | popNarray(x,(*n*8)) ; | ||
4944 | 204 | } | ||
4945 | 205 | void lookinteger8array_(char *x, unsigned int *n) { | ||
4946 | 206 | lookNarray(x,(*n*8)) ; | ||
4947 | 207 | } | ||
4948 | 208 | |||
4949 | 209 | void pushinteger16array_(char *x, unsigned int *n) { | ||
4950 | 210 | pushNarray(x,(*n*16)) ; | ||
4951 | 211 | } | ||
4952 | 212 | void popinteger16array_(char *x, unsigned int *n) { | ||
4953 | 213 | popNarray(x,(*n*16)) ; | ||
4954 | 214 | } | ||
4955 | 215 | void lookinteger16array_(char *x, unsigned int *n) { | ||
4956 | 216 | lookNarray(x,(*n*16)) ; | ||
4957 | 217 | } | ||
4958 | 218 | |||
4959 | 219 | void pushreal4array_(char *x, unsigned int *n) { | ||
4960 | 220 | pushNarray(x,(*n*4)) ; | ||
4961 | 221 | } | ||
4962 | 222 | void popreal4array_(char *x, unsigned int *n) { | ||
4963 | 223 | popNarray(x,(*n*4)) ; | ||
4964 | 224 | } | ||
4965 | 225 | void lookreal4array_(char *x, unsigned int *n) { | ||
4966 | 226 | lookNarray(x,(*n*4)) ; | ||
4967 | 227 | } | ||
4968 | 228 | |||
4969 | 229 | void pushreal8array_(char *x, unsigned int *n) { | ||
4970 | 230 | pushNarray(x,(*n*8)) ; | ||
4971 | 231 | } | ||
4972 | 232 | void popreal8array_(char *x, unsigned int *n) { | ||
4973 | 233 | popNarray(x,(*n*8)) ; | ||
4974 | 234 | } | ||
4975 | 235 | void lookreal8array_(char *x, unsigned int *n) { | ||
4976 | 236 | lookNarray(x,(*n*8)) ; | ||
4977 | 237 | } | ||
4978 | 238 | |||
4979 | 239 | void pushreal16array_(char *x, unsigned int *n) { | ||
4980 | 240 | pushNarray(x,(*n*16)) ; | ||
4981 | 241 | } | ||
4982 | 242 | void popreal16array_(char *x, unsigned int *n) { | ||
4983 | 243 | popNarray(x,(*n*16)) ; | ||
4984 | 244 | } | ||
4985 | 245 | void lookreal16array_(char *x, unsigned int *n) { | ||
4986 | 246 | lookNarray(x,(*n*16)) ; | ||
4987 | 247 | } | ||
4988 | 248 | |||
4989 | 249 | void pushreal32array_(char *x, unsigned int *n) { | ||
4990 | 250 | pushNarray(x,(*n*32)) ; | ||
4991 | 251 | } | ||
4992 | 252 | void popreal32array_(char *x, unsigned int *n) { | ||
4993 | 253 | popNarray(x,(*n*32)) ; | ||
4994 | 254 | } | ||
4995 | 255 | void lookreal32array_(char *x, unsigned int *n) { | ||
4996 | 256 | lookNarray(x,(*n*32)) ; | ||
4997 | 257 | } | ||
4998 | 258 | |||
4999 | 259 | void pushcomplex4array_(char *x, unsigned int *n) { | ||
5000 | 260 | pushNarray(x,(*n*4)) ; |
For posterity, David's review requests were:
- get rid of the boundary_condition control from the schema -- the code currently doesn't honour it. 4_5_OR_ NEWER that David made
- remove the commented-out comparison code in advection_action in the burgers adjoint callbacks
- Makefile targets for ADing simple advection (but I don't think I can do this one)
- Rather than checking if gfortran version is >= 4.5 myself, use the handy env variable $GFORTRAN_
- the testharness should filter out long tests, by default
- have the testharness print out the criteria it's using to search for tests.
These were fixed in r3593.