19 #include "moab/MOABConfig.h"
22 #error Specify MOAB_MESH_DIR path
31 #include "moab/MOABConfig.h"
34 integer :: global_comm
35 integer :: rankinglobalcomm, numprocesses
37 integer :: my_id, num_procs
39 character(:),
allocatable :: atmfilename
40 character(:),
allocatable :: ocnfilename
41 character(:),
allocatable :: baselinefilename
42 character(:),
allocatable ::
readopts, filewriteoptions
43 character :: appname*128
44 character(:),
allocatable :: weights_identifier1
45 character(:),
allocatable :: disc_methods1, disc_methods2, dof_tag_names1, dof_tag_names2
46 integer :: disc_orders1, disc_orders2
47 character(:),
allocatable :: atmocn_map_file_name, intx_from_file_identifier
50 integer :: atmgroup, atmcomm, ocngroup, ocncomm, cplgroup, cplcomm
51 integer :: atmcoucomm, ocncoucomm
53 integer :: cmpatm, cplatm, cmpocn, cplocn, atmocnid
54 integer :: cmpatmpid, cplatmpid
55 integer :: cmpocnpid, cplocnpid
56 integer :: cplatmocnpid
57 integer :: nghlay, partscheme, context_id
58 integer :: fnobubble, fmonotonetypeid, fvolumetric, fnoconserve, fvalidate, finversedistancemap
60 integer,
dimension(2) :: tagindex
61 integer,
dimension (2) :: tagtypes
62 integer :: atmcompndofs
63 integer :: ocncompndofs
64 character(:),
allocatable :: bottomfields, bottomprojectedfields
65 integer,
dimension(3) :: nverts, nelem, nblocks, nsbc, ndbc
66 double precision,
allocatable :: vals(:)
68 integer :: storleng, eetype
69 character(:),
allocatable :: concat_fieldname, concat_fieldnamet, outputfileocn
70 integer :: tagindexin2
71 integer :: dummycpl, dummyrc, dummytype
83 call mpi_comm_rank (mpi_comm_world, my_id, ierr)
84 call errorout(ierr,
'fail to get MPI rank')
86 call mpi_comm_size (mpi_comm_world, num_procs, ierr)
87 call errorout(ierr,
'fail to get MPI size')
88 call mpi_comm_dup(mpi_comm_world, global_comm, ierr)
89 call errorout(ierr,
'fail to get global comm duplicate')
91 call mpi_comm_group( global_comm, jgroup, ierr );
92 call errorout(ierr,
'fail to get joint group')
97 //
'unittest/wholeATM_T.h5m'//c_null_char
100 //
'unittest/recMeshOcn.h5m'//c_null_char
103 //
'unittest/baseline1.txt'//c_null_char
106 atmcomm = mpi_comm_null
107 ocncomm = mpi_comm_null
108 cplcomm = mpi_comm_null
109 atmcoucomm = mpi_comm_null
110 ocncoucomm = mpi_comm_null
111 call mpi_comm_dup(global_comm, atmcomm, ierr)
112 call mpi_comm_dup(global_comm, ocncomm, ierr)
113 call mpi_comm_dup(global_comm, cplcomm, ierr)
114 call mpi_comm_dup(global_comm, atmcoucomm, ierr)
115 call mpi_comm_dup(global_comm, ocncoucomm, ierr)
118 call mpi_comm_group( atmcomm, atmgroup, ierr )
119 call mpi_comm_group( ocncomm, ocngroup, ierr )
120 call mpi_comm_group( cplcomm, cplgroup, ierr )
122 readopts =
'PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS'//c_null_char
124 #ifdef MOAB_HAVE_ZOLTAN
130 if (my_id .eq. 0)
then
131 print *,
' number of tasks: ', num_procs
132 print *,
' Atm file: ', atmfilename
133 print *,
' Ocn file: ', ocnfilename
134 print *,
' baseline file: ', baselinefilename
135 print *,
' using partitioner: ', partscheme
138 ierr = imoab_initialize()
139 appname =
'ATM'//c_null_char
140 ierr = imoab_registerapplication(appname, atmcomm, cmpatm, cmpatmpid)
141 appname =
'ATMX'//c_null_char
142 ierr = imoab_registerapplication(appname, cplcomm, cplatm, cplatmpid)
143 appname =
'OCN'//c_null_char
144 ierr = imoab_registerapplication(appname, ocncomm, cmpocn, cmpocnpid)
145 appname =
'OCNX'//c_null_char
146 ierr = imoab_registerapplication(appname, cplcomm, cplocn, cplocnpid)
148 appname =
'ATMOCN'//c_null_char
149 ierr = imoab_registerapplication(appname, cplcomm, atmocnid, cplatmocnpid)
152 if (atmcomm .NE. mpi_comm_null)
then
153 ierr = imoab_loadmesh(cmpatmpid, atmfilename,
readopts, nghlay)
154 call errorout(ierr,
'fail to load atm')
155 ierr = imoab_sendmesh(cmpatmpid, atmcoucomm, cplgroup, cplatm, partscheme)
156 call errorout(ierr,
'fail to send atm')
158 if (cplcomm .NE. mpi_comm_null)
then
159 ierr = imoab_receivemesh(cplatmpid, atmcoucomm, atmgroup, cmpatm)
160 call errorout(ierr,
'fail to receive atm')
164 if (atmcomm .NE. mpi_comm_null)
then
166 ierr = imoab_freesenderbuffers(cmpatmpid, context_id)
167 call errorout(ierr,
'fail to free atm buffers')
171 if (ocncomm .NE. mpi_comm_null)
then
172 ierr = imoab_loadmesh(cmpocnpid, ocnfilename,
readopts, nghlay)
173 call errorout(ierr,
'fail to load ocn')
174 ierr = imoab_sendmesh(cmpocnpid, ocncoucomm, cplgroup, cplocn, partscheme)
175 call errorout(ierr,
'fail to send ocn')
177 if (cplcomm .NE. mpi_comm_null)
then
178 ierr = imoab_receivemesh(cplocnpid, ocncoucomm, ocngroup, cmpocn)
179 call errorout(ierr,
'fail to receive ocn')
183 if (ocncomm .NE. mpi_comm_null)
then
185 ierr = imoab_freesenderbuffers(cmpocnpid, context_id)
186 call errorout(ierr,
'fail to free ocn buffers')
189 if (cplcomm .NE. mpi_comm_null)
then
190 ierr = imoab_computemeshintersectiononsphere(cplatmpid, cplocnpid, cplatmocnpid)
194 call errorout(ierr,
'cannot compute intersection')
197 if (atmcoucomm .NE. mpi_comm_null)
then
204 ierr = imoab_coveragegraph(atmcoucomm, cmpatmpid, cplatmpid, cplatmocnpid, cmpatm, cplatm, cplocn)
205 call errorout(ierr,
'cannot recompute direct coverage graph for ocean')
208 weights_identifier1 =
'scalar'//c_null_char
209 disc_methods1 =
'cgll'//c_null_char
210 disc_methods2 =
'fv'//c_null_char
213 dof_tag_names1 =
'GLOBAL_DOFS'//c_null_char
214 dof_tag_names2 =
'GLOBAL_ID'//c_null_char
221 finversedistancemap = 0
223 if (cplcomm .NE. mpi_comm_null)
then
225 ierr = imoab_computescalarprojectionweights( &
226 cplatmocnpid, weights_identifier1, disc_methods1, disc_orders1, &
227 disc_methods2, disc_orders2,
""//c_null_char, fnobubble, fmonotonetypeid, fvolumetric, &
228 finversedistancemap, fnoconserve, &
229 fvalidate, dof_tag_names1, dof_tag_names2)
230 call errorout(ierr,
'cannot compute scalar projection weights')
232 ierr = imoab_computescalarprojectionweights( &
233 cplatmocnpid,
"bilinear"//c_null_char,
"fv"//c_null_char, 1, &
234 "fv"//c_null_char, 1,
"bilin"//c_null_char, fnobubble, fmonotonetypeid, fvolumetric, &
235 finversedistancemap, fnoconserve, &
236 fvalidate,
"GLOBAL_ID"//c_null_char,
"GLOBAL_ID"//c_null_char)
237 call errorout(ierr,
'cannot compute scalar projection weights')
239 #ifdef MOAB_HAVE_NETCDF
240 atmocn_map_file_name =
'atm_ocn_map_f.nc'//c_null_char
241 ierr = imoab_writemappingweightstofile( cplatmocnpid, weights_identifier1, atmocn_map_file_name)
242 call errorout(ierr,
'failed to write map file to disk')
243 intx_from_file_identifier =
'map-from-file'//c_null_char
247 ierr = imoab_loadmappingweightsfromfile( cplatmocnpid, dummycpl, dummyrc, dummytype, &
248 intx_from_file_identifier, atmocn_map_file_name)
249 call errorout(ierr,
'failed to load map file from disk')
256 atmcompndofs = disc_orders1*disc_orders1
259 bottomfields =
'a2oTbot:a2oUbot:a2oVbot'//c_null_char
260 bottomprojectedfields =
'a2oTbot_proj:a2oUbot_proj:a2oVbot_proj'//c_null_char
262 if (cplcomm .NE. mpi_comm_null)
then
263 ierr = imoab_definetagstorage(cplatmpid, bottomfields, tagtypes(1), atmcompndofs, tagindex(1))
264 call errorout(ierr,
'failed to define the field tags a2oTbot:a2oUbot:a2oVbot ')
265 ierr = imoab_definetagstorage(cplocnpid, bottomprojectedfields, tagtypes(2), ocncompndofs, tagindex(2))
266 call errorout(ierr,
'failed to define the field tags a2oTbot_proj:a2oUbot_proj:a2oVbot_proj')
270 if (cplatmpid .ge. 0)
then
278 ierr = imoab_getmeshinfo(cplatmpid, nverts, nelem, nblocks, nsbc, ndbc)
279 call errorout(ierr,
'failed to get num primary elems')
280 storleng = nelem(3)*atmcompndofs*3
281 allocate (vals(storleng))
289 ierr = imoab_setdoubletagstorage(cplatmpid, bottomfields, storleng, eetype, vals)
290 call errorout(ierr,
'cannot make tag nul')
295 concat_fieldname =
'a2oTbot:a2oUbot:a2oVbot'//c_null_char
296 concat_fieldnamet =
'a2oTbot_proj:a2oUbot_proj:a2oVbot_proj'//c_null_char
298 if (atmcomm .NE. mpi_comm_null)
then
302 ierr = imoab_sendelementtag(cmpatmpid, concat_fieldname, atmcoucomm, cplocn)
303 call errorout(ierr,
'cannot send tag values')
307 if (cplcomm .NE. mpi_comm_null)
then
309 ierr = imoab_receiveelementtag(cplatmpid, concat_fieldname, atmcoucomm, cplocn)
310 call errorout(ierr,
'cannot receive tag values')
314 if (atmcomm .NE. mpi_comm_null)
then
316 ierr = imoab_freesenderbuffers(cmpatmpid, cplocn)
317 call errorout(ierr,
'cannot free buffers used to resend atm tag towards the coverage mesh')
320 if (cplcomm .ne. mpi_comm_null)
then
322 outputfileocn =
"AtmOnCplF.h5m"//c_null_char
323 filewriteoptions =
'PARALLEL=WRITE_PART'//c_null_char
324 ierr = imoab_writemesh(cplatmpid, outputfileocn, filewriteoptions)
325 call errorout(ierr,
'could not write AtmOnCpl.h5m to disk')
328 if (cplcomm .ne. mpi_comm_null)
then
332 ierr = imoab_applyscalarprojectionweights(cplatmocnpid, weights_identifier1, concat_fieldname, &
334 call errorout(ierr,
'failed to compute projection weight application')
336 outputfileocn =
"OcnOnCplF.h5m"//c_null_char
337 filewriteoptions =
'PARALLEL=WRITE_PART'//c_null_char
338 ierr = imoab_writemesh(cplocnpid, outputfileocn, filewriteoptions)
339 call errorout(ierr,
'could not write OcnOnCpl.h5m to disk')
344 if (ocncomm .ne. mpi_comm_null)
then
346 ierr = imoab_definetagstorage(cmpocnpid, bottomprojectedfields, tagtypes(2), ocncompndofs, tagindexin2)
347 call errorout(ierr,
'failed to define the field tag for receiving back the tag a2oTbot_proj, on ocn pes')
355 if (cplcomm .ne. mpi_comm_null)
then
357 ierr = imoab_sendelementtag(cplocnpid, concat_fieldnamet, ocncoucomm, context_id)
358 call errorout(ierr,
'cannot send tag values back to ocean pes')
361 if (ocncomm .ne. mpi_comm_null)
then
363 ierr = imoab_receiveelementtag(cmpocnpid, concat_fieldnamet, ocncoucomm, context_id)
364 call errorout(ierr,
'cannot receive tag values from ocean mesh on coupler pes')
367 if (cplcomm .ne. mpi_comm_null)
then
369 ierr = imoab_freesenderbuffers(cplocnpid, context_id)
370 call errorout(ierr,
'cannot free sender buffers on coupler')
373 if (ocncomm .ne. mpi_comm_null)
then
375 outputfileocn =
"OcnWithProjF.h5m"//c_null_char
376 filewriteoptions =
'PARALLEL=WRITE_PART'//c_null_char
377 if (my_id .eq. 0)
then
378 print *,
' Writing ocean mesh file with projected solution to disk: ', outputfileocn
380 ierr = imoab_writemesh(cmpocnpid, outputfileocn, filewriteoptions)
381 call errorout(ierr,
'could not write OcnWithProjF.h5m to disk')
386 ierr = imoab_deregisterapplication(cplatmocnpid)
387 call errorout(ierr,
'could not de-register OCN component')
389 ierr = imoab_deregisterapplication(cplocnpid)
390 call errorout(ierr,
'could not de-register OCN component')
391 ierr = imoab_deregisterapplication(cmpocnpid)
392 call errorout(ierr,
'could not de-register OCN component')
393 ierr = imoab_deregisterapplication(cplatmpid)
394 call errorout(ierr,
'could not de-register OCN component')
395 ierr = imoab_deregisterapplication(cmpatmpid)
396 call errorout(ierr,
'could not de-register OCN component')
399 call mpi_comm_free(atmcomm, ierr)
400 call mpi_group_free(atmgroup, ierr)
401 call mpi_comm_free(ocncomm, ierr)
402 call mpi_group_free(ocngroup, ierr)
403 call mpi_comm_free(cplcomm, ierr)
404 call mpi_group_free(cplgroup, ierr)
406 call mpi_comm_free(atmcoucomm, ierr)
407 call mpi_comm_free(ocncoucomm, ierr)
408 call mpi_comm_free(global_comm, ierr)
409 call mpi_group_free(jgroup, ierr)
410 call mpi_finalize(ierr)