Loop over Entities for two fields

19 views
Skip to first unread message
Assigned to lik...@wp.pl by me

Karol Lewandowski

unread,
Dec 16, 2021, 6:35:46 AM12/16/21
to MoFEM Q&A
Hello,

I would like to use EntityMethod to loop over entities for boundary conditions. However, in the case of spatial positions I need to access fields for both: mesh positions and spatial positions. I found out that I could do it this way:
    MoFEMErrorCode operator()() {
      MoFEMFunctionBegin;
      EntityHandle ent = entPtr->getEnt();

      const FieldEntity_multiIndex *field_ents;
      CHKERR mField.get_field_ents(&field_ents);
      auto &field_ents_by_uid = field_ents->get<Unique_mi_tag>();

      auto get_coords = [&]() {
        VectorDouble3 coords(3);
        if (entPtr->getEntType() == MBVERTEX) {
          auto eit =
              field_ents_by_uid.find(FieldEntity::getLocalUniqueIdCalculate(
                  mField.get_field_bit_number(materialPositions), ent));
          if (eit != field_ents_by_uid.end())
            noalias(coords) = (*eit)->getEntFieldData();
          else
            CHKERR mField.get_moab().get_coords(&ent, 1,
                                                &*coords.data().begin());
        }
        return coords;
      };

Is there maybe a better solution for that? 

Lukasz Kaczmraczyk

unread,
Dec 16, 2021, 6:49:10 AM12/16/21
to MoFEM Q&A
Hello,

I think that EntityMethod is not bad solution, you can look here,


Look as well for options,

However, if you like to have something low level, or make some operations on fields, look at this,

If you look at function FieldBalss::fieldLambda you can find implementation useful.  Note, that implementation in FieldBalss::fieldLambda should be pretty fast.

However, Is better use EntityMethod, or FieldBalss::fieldLambda rather than low level. We can also identify if we missing some functionality.

Kind regards,
Lukasz

Karol Lewandowski

unread,
Dec 16, 2021, 7:05:17 AM12/16/21
to MoFEM Q&A
Maybe it would be useful to implement field blas only on the subset of entities. 

Lukasz Kaczmraczyk

unread,
Dec 16, 2021, 7:54:50 AM12/16/21
to MoFEM Q&A

That is very good idea.

Lukasz Kaczmraczyk

unread,
Dec 16, 2021, 8:08:08 AM12/16/21
to MoFEM Q&A
BTW it would be easy to modify. We can make some short sprint about that. Any time.
Reply all
Reply to author
Forward
0 new messages