v0.8.23
loop_entities.cpp

Make a loop over entities

/** \file loop_entities.cpp
\example loop_entities.cpp
\brief Make a loop over entities
*/
/* This file is part of MoFEM.
* MoFEM is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* MoFEM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "...\n\n";
TestEntityMethod(const Range &ents)
: EntityMethod(), allEnts(ents) {}
MoFEMErrorCode preProcess() {
entsIt = allEnts.begin();
}
MoFEMErrorCode operator()() {
if (entPtr->getEnt() != *entsIt)
SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"Entity and entity iterator should be the same");
++entsIt;
}
MoFEMErrorCode postProcess() {
if(entsIt != allEnts.end())
SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
"All entities should be iterated");
}
private:
const Range allEnts;
Range::const_iterator entsIt;
};
int main(int argc, char *argv[]) {
// initialize petsc
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
// read mesh and create moab and mofem data structures
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab, PETSC_COMM_WORLD);
MoFEM::Interface &m_field = core;
// Register DM Manager
DMType dm_name = "DMMOFEM";
EntityHandle root_set = moab.get_root_set();
// Simple interface
Simple *simple_interface;
CHKERR m_field.getInterface(simple_interface);
{
// get options from command line
CHKERR simple_interface->getOptions();
// load mesh file
CHKERR simple_interface->loadFile();
// add fields
CHKERR simple_interface->addDomainField("FIELD1", H1,
// set fields order
CHKERR simple_interface->setFieldOrder("FIELD1", 4);
// setup problem
CHKERR simple_interface->setUp();
Range all_ents;
CHKERR m_field.get_moab().get_entities_by_handle(root_set, all_ents);
all_ents = subtract(all_ents, all_ents.subset_by_type(MBENTITYSET));
auto testingEntitiesInDatabase = [&]() {
TestEntityMethod method(all_ents);
CHKERR m_field.loop_entities("FIELD1", method);
};
CHKERR testingEntitiesInDatabase();
auto testingEntitiesInDatabaseSubRange = [&]() {
Range edges = all_ents.subset_by_type(MBEDGE);
TestEntityMethod method(edges);
CHKERR m_field.loop_entities("FIELD1", method, &edges);
};
CHKERR testingEntitiesInDatabaseSubRange();
auto dm = simple_interface->getDM();
auto testingEntitiesInDM = [&]() {
TestEntityMethod method(all_ents);
const MoFEM::Problem *prb_ptr;
CHKERR m_field.loop_entities(prb_ptr, "FIELD1", ROW, method, 0,
m_field.get_comm_size());
};
CHKERR testingEntitiesInDM();
}
}
// finish work cleaning memory, getting statistics, ect.
return 0;
}