86 class(VirtualDataManagerType) :: this
87 class(NumericalSolutionType), pointer :: num_sol
88
89 integer(I4B) :: i, im, ix, ihm, ihx
90 type(VirtualSolutionType), pointer :: virt_sol
91 class(NumericalModelType), pointer :: num_mod
92 class(DisConnExchangeType), pointer :: exg
93 class(SpatialModelConnectionType), pointer :: conn
94 integer(I4B) :: model_id, exg_id
95 type(STLVecInt) :: model_ids, exchange_ids
96 class(VirtualDataContainerType), pointer :: vdc
97 logical :: found
98
99 this%nr_solutions = this%nr_solutions + 1
100 virt_sol => this%virtual_solutions(this%nr_solutions)
101
102 call model_ids%init()
103 call exchange_ids%init()
104
105
106 this%solution_ids(this%nr_solutions) = num_sol%id
107 virt_sol%solution_id = num_sol%id
108 virt_sol%numerical_solution => num_sol
109
110
111 do im = 1, num_sol%modellist%Count()
112 num_mod => getnumericalmodelfromlist(num_sol%modellist, im)
113 found = .false.
114 do i = 1, virtual_model_list%Count()
115 vdc => get_virtual_model_from_list(virtual_model_list, i)
116 if (num_mod%id == vdc%id) then
117 found = .true.
118 exit
119 end if
120 end do
121 if (found) then
122 call model_ids%push_back(num_mod%id)
123 end if
124 end do
125
126
127 do ix = 1, num_sol%exchangelist%Count()
128 exg => getdisconnexchangefromlist(num_sol%exchangelist, ix)
129 if (.not. associated(exg)) cycle
130 found = .false.
131 do i = 1, virtual_exchange_list%Count()
132 vdc => get_virtual_exchange_from_list(virtual_exchange_list, i)
133 if (exg%id == vdc%id) then
134 found = .true.
135 exit
136 end if
137 end do
138 call exchange_ids%push_back_unique(exg%id)
139 end do
140
141
142 do ix = 1, num_sol%exchangelist%Count()
143 conn => get_smc_from_list(num_sol%exchangelist, ix)
144 if (.not. associated(conn)) cycle
145
146
147
148 do ihm = 1, conn%halo_models%size
149 model_id = conn%halo_models%at(ihm)
150 call model_ids%push_back_unique(model_id)
151 end do
152 do ihx = 1, conn%halo_exchanges%size
153 exg_id = conn%halo_exchanges%at(ihx)
154 call exchange_ids%push_back_unique(exg_id)
155 end do
156 end do
157
158 allocate (virt_sol%models(model_ids%size))
159 allocate (virt_sol%exchanges(exchange_ids%size))
160 allocate (virt_sol%interface_map)
161 call virt_sol%interface_map%init(model_ids%size, exchange_ids%size)
162
163
164 do i = 1, model_ids%size
165 vdc => get_virtual_model(model_ids%at(i))
166 virt_sol%models(i)%ptr => vdc
167 end do
168 do i = 1, exchange_ids%size
169 vdc => get_virtual_exchange(exchange_ids%at(i))
170 virt_sol%exchanges(i)%ptr => vdc
171 end do
172
173
174 call model_ids%destroy()
175 call exchange_ids%destroy()
176