1 subroutine da_check_vchemtox_adjoint(grid, vchem, be, vchem2)
3 !---------------------------------------------------------------------------
4 ! Purpose: Test V to X routine and adjoint for compatibility.
6 ! Method: Standard adjoint test: < x, x > = < v_adj, v >.
7 !---------------------------------------------------------------------------
9 use module_state_description, only : num_chem, PARAM_FIRST_SCALAR
10 use da_define_structures, only : da_zero_xchem_type
11 use module_domain, only : xchem_type
15 type(domain), intent(inout) :: grid
16 type(xchem_type), intent(in) :: vchem ! Grid point/EOF equivalent.
17 type(be_type), intent(in) :: be ! Background error structure.
19 real :: adj_par_lhs ! < x, x >
20 real :: adj_par_rhs ! < x, x >
21 real :: adj_sum_lhs ! < x, x >
22 real :: adj_sum_rhs ! < v_adj, v >
24 type(xchem_type), intent(out) :: vchem2 ! Grid point/EOF equivalent.
26 if (trace_use) call da_trace_entry("da_check_vchemtox_adjoint")
28 write(unit=stdout, fmt='(/a/)') &
29 'da_check_vchemtox_adjoint: Adjoint Test Results:'
31 !----------------------------------------------------------------------
33 !----------------------------------------------------------------------
34 vchem2%chem_ic(:,:,:,:) = 0.D0
37 !----------------------------------------------------------------------
38 ! [2.0] Perform x = U v transform:
39 !----------------------------------------------------------------------
41 call da_zero_xchem_type (grid%xachem)
42 call da_transform_vchemtox(grid, vchem, be)
44 !----------------------------------------------------------------------
45 ! [3.0] Calculate LHS of adjoint test equation:
46 !----------------------------------------------------------------------
48 do ic = PARAM_FIRST_SCALAR ,num_chem
49 adj_par_lhs = adj_par_lhs + sum(grid%xachem%chem_ic(its:ite,jts:jte,kts:kte,ic)**2) / typical_t_rms**2
52 !-------------------------------------------------------------------------
53 ! [4.0] Rescale input to adjoint routine:
54 !-------------------------------------------------------------------------
56 do ic = PARAM_FIRST_SCALAR ,num_chem
57 ! grid%xachem%chem_ic(:,:,:,ic) = grid%xachem%chem_ic(:,:,:,ic) / typical_t_rms**2
58 grid%xachem%chem_ic(its:ite,jts:jte,kts:kte,ic) = grid%xachem%chem_ic(its:ite,jts:jte,kts:kte,ic) / typical_t_rms**2
61 !-------------------------------------------------------------------------
62 ! [5.0] Perform adjoint operation:
63 !-------------------------------------------------------------------------
65 call da_transform_vchemtox_adj(grid, vchem2, be)
67 !-------------------------------------------------------------------------
68 ! [6.0] Calculate RHS of adjoint test equation:
69 !-------------------------------------------------------------------------
71 do ic = PARAM_FIRST_SCALAR ,num_chem
72 adj_par_rhs = adj_par_rhs+sum(vchem%chem_ic(its:ite,jts:jte,1:be%v12(ic-1)%mz,ic) * vchem2%chem_ic(its:ite,jts:jte,1:be%v12(ic-1)%mz,ic))
74 !-------------------------------------------------------------------------
76 !-------------------------------------------------------------------------
78 if (.not. global ) then
79 if( num_procs == 1) then
80 write(unit=stdout, fmt='(/)')
81 write(unit=stdout, fmt='(a,1pe22.14)') &
82 'Single Domain: < x, x > = ', adj_par_lhs, &
83 'Single Domain: < v_adj, v > = ', adj_par_rhs
85 write(unit=stdout, fmt='(/a/,a/)')&
86 'It is Multi Processor Run: ',&
87 'For Single Domain: da_check_vchemtox_adjoint Test: Not Performed'
91 adj_sum_lhs = wrf_dm_sum_real(adj_par_lhs)
94 adj_sum_rhs = adj_par_rhs
96 adj_sum_rhs = wrf_dm_sum_real(adj_par_rhs)
100 write(unit=stdout, fmt='(/)')
101 write(unit=stdout, fmt='(a,1pe22.14)') &
102 'Whole Domain: < x, x > = ', adj_sum_lhs, &
103 'Whole Domain: < vchem_adj, vchem > = ', adj_sum_rhs
106 write(unit=stdout, fmt='(/a/)') 'da_check_vchemtox_adjoint: Finished'
108 if (trace_use) call da_trace_exit("da_check_vchemtox_adjoint")
110 end subroutine da_check_vchemtox_adjoint