<div dir="ltr"><div>Hi Olivier, <br></div><div>It has been a while that I looked at MOAB code. As far as I remember, with the native data structure one explicitly computes only the vertex—>entity maps. So, when the add_adjacencies routine is called for new entities, it will create and store only the vertex—>entity map. What this means is that any other query would ultimately go through this look up as you correctly mentioned. </div><br>An immediate work around would be to follow Lorenzo’s advice, and explicitly store the computed adjacency as tags/fields which should have constant lookup time. <br><br>AHF stores a different set of maps (facet-to-facet, vertex-to-facet) and uses them to compute any other adjacency query. We did observe some speedup in few of the adjacency queries, particularly the face-to-cell queries compared to the native data structure. <br><br><div>We did extend AHF to support adaptive meshes, however, its only existing implementation is in a MATLAB code base called NumGeom (developed at Stony Brook University by Prof. Xiangmin Jiao’s group) as we didn’t get to a point where we could add this extended feature to MOAB. Depending on your time constraints, we can discuss further about adding this feature to MOAB. <br></div><div>Best..</div><div>Navamita <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 19, 2019 at 11:53 AM lorenzo alessio botti <<a href="mailto:lorenzoalessiobotti@gmail.com">lorenzoalessiobotti@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">You can also store adjacencies as tags using the specific type for moab entities. That's what I usually do to save computation type at the expense of storing integers. <div dir="auto">Bests</div><div dir="auto">Lorenxo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 19, 2019, 17:32 Vijay S. Mahadevan via moab-dev <<a href="mailto:moab-dev@mcs.anl.gov" target="_blank">moab-dev@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Jamond,<br>
<br>
Good to hear that you are considering MOAB as a mesh database for your<br>
application. Please see my answers inline. Do let me know if something<br>
is unclear.<br>
<br>
> So we consider replacing our legacy data/structure by moab. We already did this replacement in a dedicated branch of our software, and it works (it succeed to pass our test base). But the cpu costs of adjacencies queries increased hugely... For example, for a finite-volume fluid computation (the cells "often" query their adjacent faces, and the faces "often" query their adjacent cells), with our legacy structure, the adjacency queries cost about nothing, and with moab cost about 50% of the total computation!<br>
<br>
Can you provide us a little more detail on the type of meshes you use<br>
in the applications ? I assume 3-D, with mixed hex/tets ? Also, do you<br>
create most meshes in memory or are the initial meshes loaded from a<br>
file.<br>
<br>
> Maybe we just misuse moab? In the moab documentation, it is written that "Non-vertex entity to entity adjacencies are never stored, unless explicitly requested by the application.". Because memory consumption is not our primary concern, we tried that, assuming that the request for storing adjacencies is done with the "add_adjacencies" function (in the end of this message a very simple sample code representative of what we do with moab is provided). But the cost of the adjacency queries is still very high...<br>
<br>
MOAB takes a lazy approach to computing the cell adjacencies. What<br>
that means is that if the adjacency information for face to cell<br>
relation is unavailable on first query, it computes it and caches it<br>
in memory so that the next call to get the adjacency is much faster.<br>
Motivation is to get a balance between memory requirement and cost for<br>
adjacency query. Typically, if you create a mesh in memory, the user<br>
also sets the adjacencies as well so that it can be queried later. So<br>
the workflow would be to call add_adjacencies BEFORE get_adjacencies<br>
here. However, if you loaded a mesh from file, you can query the mesh<br>
with get_adjacencies in addition to "create_if_missing" set to true,<br>
in case the mesh file itself does not store explicit adjacency<br>
information.<br>
<br>
> - for each edge represented by its two vertices, loop over some existing edges represented by their EntityHandle to find which one matches the current edge (a large portion of the computation time is spent in "moab::AEntityFactory::entities_equivalent(unsigned long, unsigned long const*, int, moab::EntityType)" )<br>
<br>
MOAB adjacency datastructure is optimized for vertex to element type<br>
queries since these are explicitly stored and available by default. And this is<br>
why the implementation to get face->element adjacency information goes<br>
through that intermediate step to decipher the relation. The AHF datastructure<br>
does not have this indirection and may provide much faster queries depending<br>
on the use-case.<br>
<br>
> Does moab actually store the adjacencies with "add_adjacencies"? For example, by following in a debugger what moab does on the sample program provided when querying the edges adjacent to a quadrangular cell, it seems that whereas the adjacencies being stored, moab:<br>
<br>
Yes. If the user explicitly calls add_adjacencies, this information is<br>
stored internally so that it can be queried later.<br>
<br>
> We see in the code that there is a "create_adjacency_option" that is not yet supported. Could this option help once implemented?<br>
<br>
Can you point me to this piece of the implementation ?<br>
<br>
> We also checked the AHF feature. At this time, this feature cannot apply in our applications because it is not compatible with modified and mixed-type meshes. Is it planned for AHF to become compatible with modified and mixed-type meshes?<br>
<br>
I am also cc'ing Navamita Ray who implemented AHF [1] in MOAB.<br>
Navamita, can you talk more about the AHF support with the adjacency<br>
cost comparison with native MOAB implementation ? Also, if you can<br>
provide some thoughts about extending AHF to support mixed meshes and<br>
polytopes, that would be good as well.<br>
<br>
Vijay<br>
<br>
[1] <a href="https://imr.sandia.gov/papers/imr22/IMR22_25_Dyedov.pdf" rel="noreferrer noreferrer" target="_blank">https://imr.sandia.gov/papers/imr22/IMR22_25_Dyedov.pdf</a><br>
<br>
<br>
On Wed, Jun 19, 2019 at 11:08 AM JAMOND Olivier via moab-dev<br>
<<a href="mailto:moab-dev@mcs.anl.gov" rel="noreferrer" target="_blank">moab-dev@mcs.anl.gov</a>> wrote:<br>
><br>
> Hello,<br>
><br>
><br>
><br>
> I am working at the french CEA "French Alternative Energies and Atomic Energy Commission" on the development of a new finite-elements/finite-volume software for mechanical applications.<br>
><br>
><br>
><br>
> Until now, we had an internal data base for storing and querying adjencencies/connectivities between mesh entities. In this legacy data structure, every adjacencies/connectivities are computed and stored at the beginning of the computation, and then queries during the actual computation steps just "read" in this data structure. Our problem is that this legacy data structure is way too "static": for example, it is very difficult to add/remove cells (for AMR, or load balancing for example) during the computation steps.<br>
><br>
><br>
><br>
> So we consider replacing our legacy data/structure by moab. We already did this replacement in a dedicated branch of our software, and it works (it succeed to pass our test base). But the cpu costs of adjacencies queries increased hugely... For example, for a finite-volume fluid computation (the cells "often" query their adjacent faces, and the faces "often" query their adjacent cells), with our legacy structure, the adjacency queries cost about nothing, and with moab cost about 50% of the total computation!<br>
><br>
><br>
><br>
> Maybe we just misuse moab? In the moab documentation, it is written that "Non-vertex entity to entity adjacencies are never stored, unless explicitly requested by the application.". Because memory consumption is not our primary concern, we tried that, assuming that the request for storing adjacencies is done with the "add_adjacencies" function (in the end of this message a very simple sample code representative of what we do with moab is provided). But the cost of the adjacency queries is still very high...<br>
><br>
><br>
><br>
> Does moab actually store the adjacencies with "add_adjacencies"? For example, by following in a debugger what moab does on the sample program provided when querying the edges adjacent to a quadrangular cell, it seems that whereas the adjacencies being stored, moab:<br>
><br>
> - get the nodes of each edges of the quadrangle<br>
><br>
> - for each edge represented by its two vertices, loop over some existing edges represented by their EntityHandle to find which one matches the current edge (a large portion of the computation time is spent in "moab::AEntityFactory::entities_equivalent(unsigned long, unsigned long const*, int, moab::EntityType)" )<br>
><br>
><br>
><br>
> We see in the code that there is a "create_adjacency_option" that is not yet supported. Could this option help once implemented? We also checked the AHF feature. At this time, this feature cannot apply in our applications because it is not compatible with modified and mixed-type meshes. Is it planned for AHF to become compatible with modified and mixed-type meshes?<br>
><br>
><br>
><br>
> Is there something that we miss, or a more efficient way to use moab?<br>
><br>
><br>
><br>
> Many thanks,<br>
><br>
> _____________________________<br>
><br>
> Olivier JAMOND<br>
><br>
> Laboratoire d'études de dynamique<br>
><br>
> CEA Saclay, DEN/DANS/DM2S/SEMT/DYN<br>
><br>
> F-91191 GIF SUR YVETTE, FRANCE<br>
><br>
> Tél. : 01.69.08.44.90<br>
><br>
><br>
><br>
><br>
><br>
> * ------------- Sample code --------------- *<br>
><br>
><br>
><br>
> #include <iostream><br>
> #include <sstream><br>
> #include <vector><br>
><br>
> #include "moab/Core.hpp"<br>
><br>
> //<br>
> // 3 ----- 5 ----- 5<br>
> // | | |<br>
> // | | |<br>
> // | | |<br>
> // 0 ----- 1 ----- 4<br>
> //<br>
><br>
> int main()<br>
> {<br>
><br>
> std::vector<moab::EntityHandle> adj;<br>
><br>
> // > init moab<br>
> moab::Core mb;<br>
> mb.set_dimension(2);<br>
> // <<br>
><br>
> // > create the vertices (foo coordinates)<br>
> double coords[3]={0.,0.,0.};<br>
><br>
> std::vector<moab::EntityHandle> nodes;<br>
> nodes.resize(6);<br>
> mb.create_vertex(coords, nodes[0]);<br>
> mb.create_vertex(coords, nodes[1]);<br>
> mb.create_vertex(coords, nodes[2]);<br>
> mb.create_vertex(coords, nodes[3]);<br>
> mb.create_vertex(coords, nodes[4]);<br>
> mb.create_vertex(coords, nodes[5]);<br>
> // <<br>
><br>
> // > create the 2 quadrangles<br>
> moab::EntityHandle q0;<br>
> std::vector<moab::EntityHandle> conn0;<br>
> conn0.resize(4);<br>
> conn0[0]=nodes[0];<br>
> conn0[1]=nodes[1];<br>
> conn0[2]=nodes[2];<br>
> conn0[3]=nodes[3];<br>
> mb.create_element(moab::MBQUAD, conn0.data(), 4, q0);<br>
><br>
> moab::EntityHandle q1;<br>
> std::vector<moab::EntityHandle> conn1;<br>
> conn1.resize(4);<br>
> conn1[0]=nodes[1];<br>
> conn1[1]=nodes[4];<br>
> conn1[2]=nodes[5];<br>
> conn1[3]=nodes[2];<br>
> mb.create_element(moab::MBQUAD, conn1.data(), 4, q1);<br>
> // <<br>
><br>
> // > compute and store cell<->face adjacencies<br>
> adj.clear();<br>
> mb.get_adjacencies (&q0, 1, 1, true, adj);<br>
> mb.add_adjacencies(q0, adj.data(), adj.size(), true);<br>
> adj.clear();<br>
> mb.get_adjacencies (&q1, 1, 1, true, adj);<br>
> mb.add_adjacencies(q1, adj.data(), adj.size(), true);<br>
> // <<br>
><br>
> // > example of queries<br>
> // > get the faces of the first cell<br>
> adj.clear();<br>
> mb.get_adjacencies (&q1, 1, 1, false, adj);<br>
> std::cout << "## face of the first cell -------------------#\n";<br>
> mb.list_entities(adj.data(), adj.size());<br>
> // <<br>
><br>
> // > get the face shared by the two cells<br>
> adj.clear();<br>
> moab::EntityHandle cells[2]={q0,q1};<br>
> mb.get_adjacencies(cells, 2, 1, false, adj);<br>
> std::cout << "## face shared by the two cells -------------#\n";<br>
> mb.list_entities(adj.data(), adj.size());<br>
> // <<br>
><br>
> // > get the two cells from the middle face<br>
> moab::EntityHandle face=adj[0];<br>
> adj.clear();<br>
> mb.get_adjacencies(&face, 1, 2, false, adj);<br>
> std::cout << "## cells adjacent to the middle face --------#\n";<br>
> mb.list_entities(adj.data(), adj.size());<br>
> // <<br>
> // <<br>
><br>
> return 0;<br>
> }<br>
><br>
><br>
><br>
><br>
</blockquote></div>
</blockquote></div>