[MOAB-dev] Question about iMesh and Fortran 90/2003

Chris Eldred chris.eldred at gmail.com
Fri Nov 15 16:32:13 CST 2013


Hey Tim,

I am reading in a (2D) mesh using custom mesh readers that I wrote for
our grids, but I've already gone ahead and writen functions to
generate global id's and assign them to an integer tag (for faces,
edges and vertices since I need id's for all those entities). That way
I can just stick with the default iMesh tag reading functions.

Some sort of assign_global_id's function might be useful though,
especially in the context of optimizing global id assignment for
computational efficiency (like using a space filling curve to optimize
memory access patterns for a given type of stencil, etc.). Right now I
take a very simplistic approach and just loop through the entities
returned by get_entities_by_dimension; incrementing the global id and
assigning it.

-Chris

On Fri, Nov 15, 2013 at 3:14 PM, Tim Tautges <tautges at mcs.anl.gov> wrote:
> Are you reading in a mesh or pushing one into MOAB?  If the former, I could
> probably implement a "ASSIGN_GLOBAL_IDS" read option that would generate
> those, then you'd just need to read them out of the tag.  If you don't mind
> writing your own iMeshP/iMesh extension function, there's also already the
> function ParallelComm::assign_global_ids you could use.
>
> - tim
>
>
> On 11/15/2013 02:24 PM, Chris Eldred wrote:
>>
>> Hey Tim,
>>
>> Using an integer tag to number vertices/faces/edges myself seems like
>> the easiest option. I should just be able to use the handle array as
>> an input into iMesh_getIntArrData to get the integer tag array, which
>> is basically converting from handles to some form of (global) integer
>> id.
>>
>> Thanks,
>> Chris
>>
>> On Fri, Nov 15, 2013 at 1:14 PM, Tim Tautges <tautges at mcs.anl.gov> wrote:
>>>
>>> Hi Chris,
>>>    Using the id associated with handles in C++ MOAB is dicey, since there
>>> aren't any guarantees that integer space is contiguous, and in parallel
>>> that
>>> gives local ids but not global ones.  The quick answer to your question
>>> is
>>> that you may want to use an integer tag and number your vertices
>>> yourself,
>>> then use the handle array you get back as connectivity as input to the
>>> function to get that integer tag data for those vertices.
>>>
>>> Secondly, I just this morning committed another example that shows how to
>>> use iMesh from F90 that may help.  It's not exactly what you're doing,
>>> but
>>> it may show some more things about accessing MOAB through ISO_C_BINDING.
>>> It's on my to-do list to document F90+iMesh/MOAB better.
>>>
>>> I'll also look over your code in a minute, but wanted to get this answer
>>> out
>>> quickly.
>>>
>>> - tim
>>>
>>>
>>> On 11/14/2013 08:20 PM, Chris Eldred wrote:
>>>>
>>>>
>>>> Hey Moab-Dev,
>>>>
>>>> I am trying to write a Fortran code that uses iMesh to call MOAB, and
>>>> I keep running into errors. What I would like to be able to do it is
>>>> to convert an adjacency returned by iMesh_getEntAdj from type(c_ptr)
>>>> to integers. In MOAB using C++ this seems to be trivial (use id =
>>>> id_from_handle(HANDLE) . It would also be useful to have the dual of
>>>> this operator (handle = handle_from_id(ID) ). I can't seem to get it
>>>> to work in Fortran however. My code is:
>>>>
>>>> subroutine get_adjacency(entity, entity_requested, adjacencyptr,
>>>> adjacency_size)
>>>> implicit none
>>>>
>>>> integer(kind=c_int) :: alloc, adjacency_size
>>>> integer(kind=c_int) :: entity_requested
>>>> integer(kind=c_int), pointer, dimension(:) :: adjacency
>>>> type(c_ptr) :: entity
>>>> type(c_ptr) :: adjacencyptr_C
>>>> type(c_ptr), pointer, dimension(:) :: adjacencyptr
>>>>
>>>> alloc = 0
>>>> call iMesh_getEntAdj( mesh, entity, entity_requested, adjacencyptr_C,
>>>> alloc, adjacency_size, ierr)
>>>> CHECK("Couldn't get adjacencies")
>>>> call C_F_POINTER(adjacencyptr_C, adjacencyptr, [alloc])
>>>> adjacency = transfer(adjacencyptr,adjacency,adjacency_size)
>>>>
>>>> end subroutine get_adjacency
>>>>
>>>> I have tried using the transfer function, but that produces memory
>>>> (segmentation fault) errors. Everything before this line works fine. I
>>>> am using the Fortran 2003 modules (iMesh_iso.F03) from
>>>>
>>>>
>>>> https://redmine.scorec.rpi.edu/anonsvn/itaps/software/trunk/interfaces/iMesh/examples/FindAdjacency/.
>>>> I've also looked through the iBase and iMesh documentation, but there
>>>> is very little information there about using Fortran instead of C/C++.
>>>> I am not very familiar with mixed C/Fortran programming, so it is
>>>> entirely possible that I just don't understand what is going on.
>>>>
>>>> Thanks,
>>>> Chris Eldred
>>>>
>>>
>>> --
>>> ================================================================
>>> "You will keep in perfect peace him whose mind is
>>>    steadfast, because he trusts in you."               Isaiah 26:3
>>>
>>>               Tim Tautges            Argonne National Laboratory
>>>           (tautges at mcs.anl.gov)      (telecommuting from UW-Madison)
>>>   phone (gvoice): (608) 354-1459      1500 Engineering Dr.
>>>              fax: (608) 263-4499      Madison, WI 53706
>>>
>>
>>
>>
>
> --
> ================================================================
> "You will keep in perfect peace him whose mind is
>   steadfast, because he trusts in you."               Isaiah 26:3
>
>              Tim Tautges            Argonne National Laboratory
>          (tautges at mcs.anl.gov)      (telecommuting from UW-Madison)
>  phone (gvoice): (608) 354-1459      1500 Engineering Dr.
>             fax: (608) 263-4499      Madison, WI 53706
>



-- 
Chris Eldred
DOE Computational Science Graduate Fellow
Graduate Student, Atmospheric Science, Colorado State University
B.S. Applied Computational Physics, Carnegie Mellon University, 2009
chris.eldred at gmail.com / celdred at atmos.colostate.edu


More information about the moab-dev mailing list