1 module virtualdatamanagermodule
27 type,
public :: virtualdatamanagertype
28 integer(I4B) :: nr_solutions
29 integer(I4B),
dimension(:),
allocatable :: solution_ids
30 type(VirtualSolutionType),
dimension(:),
pointer :: virtual_solutions
31 class(RouterBaseType),
pointer :: router
33 procedure :: create => vds_create
34 procedure :: init => vds_init
35 procedure :: add_solution => vds_add_solution
36 procedure :: activate_halo => vds_activate_halo
37 procedure :: compress_halo => vds_compress_halo
38 procedure :: synchronize => vds_synchronize
39 procedure :: synchronize_sln => vds_synchronize_sln
43 procedure,
private :: vds_synchronize
44 procedure,
private :: prepare_all
45 procedure,
private :: link_all
46 procedure,
private :: vds_synchronize_sln
47 procedure,
private :: prepare_sln
48 procedure,
private :: link_sln
49 procedure,
private :: count_nr_solutions
50 end type virtualdatamanagertype
55 subroutine vds_create(this, sim_mode)
56 class(VirtualDataManagerType) :: this
57 character(len=*) :: sim_mode
59 integer(I4B) :: nr_sol
61 nr_sol = this%count_nr_solutions()
62 allocate (this%virtual_solutions(nr_sol))
63 allocate (this%solution_ids(nr_sol))
71 end subroutine vds_create
75 subroutine vds_init(this)
76 class(VirtualDataManagerType) :: this
78 call this%router%initialize()
85 subroutine vds_add_solution(this, num_sol)
86 class(VirtualDataManagerType) :: this
87 class(NumericalSolutionType),
pointer :: num_sol
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
99 this%nr_solutions = this%nr_solutions + 1
100 virt_sol => this%virtual_solutions(this%nr_solutions)
102 call model_ids%init()
103 call exchange_ids%init()
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
111 do im = 1, num_sol%modellist%Count()
116 if (num_mod%id == vdc%id)
then
122 call model_ids%push_back(num_mod%id)
127 do ix = 1, num_sol%exchangelist%Count()
129 if (.not.
associated(exg)) cycle
133 if (exg%id == vdc%id)
then
138 call exchange_ids%push_back_unique(exg%id)
142 do ix = 1, num_sol%exchangelist%Count()
144 if (.not.
associated(conn)) cycle
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)
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)
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)
164 do i = 1, model_ids%size
166 virt_sol%models(i)%ptr => vdc
168 do i = 1, exchange_ids%size
170 virt_sol%exchanges(i)%ptr => vdc
174 call model_ids%destroy()
175 call exchange_ids%destroy()
177 end subroutine vds_add_solution
181 subroutine vds_activate_halo(this)
182 class(VirtualDataManagerType) :: this
184 integer(I4B) :: im, ic, ix
185 type(STLVecInt) :: halo_model_ids
186 class(VirtualModelType),
pointer :: vm
187 class(VirtualExchangeType),
pointer :: ve
188 class(SpatialModelConnectionType),
pointer :: conn
190 call halo_model_ids%init()
195 do im = 1, conn%halo_models%size
196 call halo_model_ids%push_back_unique(conn%halo_models%at(im))
203 if (.not. vm%is_local)
then
204 if (.not. halo_model_ids%contains(vm%id))
then
205 vm%is_active = .false.
214 if (.not. ve%is_local)
then
215 if (.not. halo_model_ids%contains(ve%v_model1%id) .or. &
216 .not. halo_model_ids%contains(ve%v_model2%id))
then
217 ve%is_active = .false.
222 this%router%halo_activated = .true.
224 call halo_model_ids%destroy()
226 end subroutine vds_activate_halo
231 subroutine vds_compress_halo(this)
236 class(VirtualDataManagerType) :: this
238 integer(I4B) :: ivm, isol, iexg, m_idx
239 integer(I4B) :: outunit
240 character(len=128) :: monitor_file
241 type(VirtualSolutionType),
pointer :: virt_sol
242 class(NumericalSolutionType),
pointer :: num_sol
243 class(SpatialModelConnectionType),
pointer :: conn
244 class(VirtualDataContainerType),
pointer :: vdc
245 type(IndexMapType),
pointer :: nmap, cmap
248 do isol = 1, this%nr_solutions
249 virt_sol => this%virtual_solutions(isol)
251 do iexg = 1, num_sol%exchangelist%Count()
253 if (.not.
associated(conn)) cycle
256 call virt_sol%interface_map%add(conn%interface_map)
263 write (monitor_file,
'(a,i0,a)')
"iface.p",
proc_id,
".log"
264 open (unit=outunit, file=monitor_file)
265 do isol = 1, this%nr_solutions
266 write (outunit,
'(a,i0,/)')
"interface map for solution ", &
267 this%virtual_solutions(isol)%solution_id
268 virt_sol => this%virtual_solutions(isol)
269 call virt_sol%interface_map%print_interface(outunit)
275 do isol = 1, this%nr_solutions
276 virt_sol => this%virtual_solutions(isol)
277 do ivm = 1,
size(virt_sol%models)
278 vdc => virt_sol%models(ivm)%ptr
279 if (.not. vdc%is_local .and. vdc%is_active)
then
280 m_idx =
ifind(virt_sol%interface_map%model_ids, vdc%id)
281 if (m_idx == -1) cycle
283 nmap => virt_sol%interface_map%get_node_map(vdc%id)
284 cmap => virt_sol%interface_map%get_connection_map(vdc%id)
291 end subroutine vds_compress_halo
295 subroutine vds_synchronize(this, stage)
296 class(VirtualDataManagerType) :: this
297 integer(I4B) :: stage
299 call this%prepare_all(stage)
300 call this%link_all(stage)
301 call this%router%route_all(stage)
303 end subroutine vds_synchronize
305 subroutine prepare_all(this, stage)
306 class(VirtualDataManagerType) :: this
307 integer(I4B) :: stage
310 class(VirtualDataContainerType),
pointer :: vdc
316 if (.not. vdc%is_active) cycle
317 call vdc%prepare_stage(stage)
321 if (.not. vdc%is_active) cycle
322 call vdc%prepare_stage(stage)
325 end subroutine prepare_all
327 subroutine link_all(this, stage)
328 class(VirtualDataManagerType) :: this
329 integer(I4B) :: stage
332 class(VirtualDataContainerType),
pointer :: vdc
337 call vdc%link_items(stage)
341 call vdc%link_items(stage)
344 end subroutine link_all
348 subroutine vds_synchronize_sln(this, id_sln, stage)
350 class(VirtualDataManagerType) :: this
351 integer(I4B) :: id_sln
352 integer(I4B) :: stage
354 integer(I4B) :: sol_idx
356 sol_idx =
ifind(this%solution_ids, id_sln)
357 call this%prepare_sln(this%virtual_solutions(sol_idx), stage)
358 call this%link_sln(this%virtual_solutions(sol_idx), stage)
359 call this%router%route_sln(this%virtual_solutions(sol_idx), stage)
361 end subroutine vds_synchronize_sln
366 subroutine prepare_sln(this, virtual_sol, stage)
367 class(VirtualDataManagerType) :: this
368 type(VirtualSolutionType) :: virtual_sol
369 integer(I4B) :: stage
372 class(VirtualDataContainerType),
pointer :: vdc
374 do i = 1,
size(virtual_sol%models)
375 vdc => virtual_sol%models(i)%ptr
376 call vdc%prepare_stage(stage)
379 do i = 1,
size(virtual_sol%exchanges)
380 vdc => virtual_sol%exchanges(i)%ptr
381 call vdc%prepare_stage(stage)
384 end subroutine prepare_sln
388 subroutine link_sln(this, virtual_sol, stage)
389 class(VirtualDataManagerType) :: this
390 type(VirtualSolutionType) :: virtual_sol
391 integer(I4B) :: stage
394 class(VirtualDataContainerType),
pointer :: vdc
396 do i = 1,
size(virtual_sol%models)
397 vdc => virtual_sol%models(i)%ptr
398 call vdc%link_items(stage)
401 do i = 1,
size(virtual_sol%exchanges)
402 vdc => virtual_sol%exchanges(i)%ptr
403 call vdc%link_items(stage)
406 end subroutine link_sln
410 function count_nr_solutions(this)
result(count)
413 class(VirtualDataManagerType) :: this
414 integer(I4B) :: count
417 class(*),
pointer :: sol
429 end function count_nr_solutions
432 class(VirtualDataManagerType) :: this
435 class(VirtualDataContainerType),
pointer :: vdc
449 do i = 1, this%nr_solutions
450 deallocate (this%virtual_solutions(i)%models)
451 deallocate (this%virtual_solutions(i)%exchanges)
452 call this%virtual_solutions(i)%interface_map%destroy()
453 deallocate (this%virtual_solutions(i)%interface_map)
455 deallocate (this%virtual_solutions)
457 deallocate (this%router)
461 end module virtualdatamanagermodule
class(disconnexchangetype) function, pointer, public getdisconnexchangefromlist(list, idx)
This module defines variable data types.
type(listtype), public baseconnectionlist
type(listtype), public basesolutionlist
class(numericalexchangetype) function, pointer, public getnumericalexchangefromlist(list, idx)
Retrieve a specific numerical exchange from a list.
class(numericalmodeltype) function, pointer, public getnumericalmodelfromlist(list, idx)
class(numericalsolutiontype) function, pointer, public castasnumericalsolutionclass(obj)
@ brief Cast a object as a Numerical Solution
class(routerbasetype) function, pointer, public create_router(sim_mode)
@ Brief Create the proper router, depends on simulation mode (parallel or sequential) and type of bui...
This module contains simulation variables.
class(spatialmodelconnectiontype) function, pointer, public get_smc_from_list(list, idx)
Get the connection from a list.
integer(i4b), parameter, public map_conn_type
integer(i4b), parameter, public map_node_type
class(virtualdatacontainertype) function, pointer, public get_vdc_from_list(list, idx)
type(listtype), public virtual_model_list
type(listtype), public virtual_exchange_list
class(virtualexchangetype) function, pointer, public get_virtual_exchange_from_list(list, idx)
class(virtualexchangetype) function, pointer, public get_virtual_exchange(exg_id)
Returns a virtual exchange with the specified id.
class(virtualmodeltype) function, pointer, public get_virtual_model_from_list(model_list, idx)
Exchange based on connection between discretizations of DisBaseType. The data specifies the connectio...
Class to manage spatial connection of a model to one or more models of the same type....
The Virtual Exchange is based on two Virtual Models and is therefore not always strictly local or rem...