#include "AMDiS.h" using namespace std; using namespace AMDiS; // =========================================================================== // ===== main program ======================================================== // =========================================================================== int main(int argc, char* argv[]) { FUNCNAME("main"); // ===== init parameters ===== Parameters::init(false, "./init/compute_displacement.1d"); // ===== create and init the scalar problem ===== ProblemVec vecellipt("vecellipt"); vecellipt.initialize(INIT_ALL); // Works only with global refinement = 1 and one macro element, i.e., two // leave elements in the starting mesh. TEST_EXIT(vecellipt.getMesh(0)->getNumberOfLeaves() == 2)("Wrong macro mesh\n!"); TEST_EXIT(vecellipt.getMesh(1)->getNumberOfLeaves() == 2)("Wrong macro mesh\n!"); // Construct the following mesh (shown as a hierachy tree, a is the macro // element, and b and c construct the starting mesh): // // a // / \ // b c // / \ // / \ // d e // / \ / \ // f g h i // / \ / \ // j k l m // / \ / \ // n o p q // / \ // r s // // The nodes {j, n, o, g, h, p, r, s, m , c} are the leave elements of the // resulting mesh. Mesh *mesh = vecellipt.getMesh(0); Element *el = mesh->getMacroElement(0)->getElement(); el->getChild(0)->setMark(1); vecellipt.getRefinementManager(0)->refineMesh(mesh); el->getChild(0)->getChild(0)->setMark(1); el->getChild(0)->getChild(1)->setMark(1); vecellipt.getRefinementManager(0)->refineMesh(mesh); el->getChild(0)->getChild(0)->getChild(0)->setMark(1); el->getChild(0)->getChild(1)->getChild(1)->setMark(1); vecellipt.getRefinementManager(0)->refineMesh(mesh); el->getChild(0)->getChild(0)->getChild(0)->getChild(1)->setMark(1); el->getChild(0)->getChild(1)->getChild(1)->getChild(0)->setMark(1); vecellipt.getRefinementManager(0)->refineMesh(mesh); el->getChild(0)->getChild(1)->getChild(1)->getChild(0)->getChild(1)->setMark(1); vecellipt.getRefinementManager(0)->refineMesh(mesh); TEST_EXIT(mesh->getNumberOfLeaves() == 10)("Wrong number of leaves!\n"); // Create an array with the expected results of dual traverse. In i-th // step we check the level of the large element (tmp[0]), the level of // the small element (tmp[1]) and the displacement (tmp[2]). std::vector > correctResults(0); std::vector tmp(3); tmp[0] = 1; tmp[1] = 4; tmp[2] = 0; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 5; tmp[2] = 2; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 5; tmp[2] = 3; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 3; tmp[2] = 1; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 3; tmp[2] = 2; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 5; tmp[2] = 12; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 6; tmp[2] = 26; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 6; tmp[2] = 27; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 4; tmp[2] = 7; correctResults.push_back(tmp); tmp[0] = 1; tmp[1] = 1; tmp[2] = 0; correctResults.push_back(tmp); // Create everything for the dual traverse, start the dual traverse and // compare the result with the expected ones. DualTraverse dualTraverse; ElInfo *rowElInfo, *colElInfo; ElInfo *largeElInfo, *smallElInfo; Flag flag = Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET | Mesh::FILL_GRD_LAMBDA | Mesh::FILL_NEIGH; int i = 0; bool cont = dualTraverse.traverseFirst(vecellipt.getMesh(0), vecellipt.getMesh(1), -1, -1, flag, flag, &rowElInfo, &colElInfo, &smallElInfo, &largeElInfo); while (cont) { TEST_EXIT(correctResults[i][0] == largeElInfo->getLevel()) ("Wrong level of large element!\n"); TEST_EXIT(correctResults[i][1] == smallElInfo->getLevel()) ("Wrong level of small element!\n"); TEST_EXIT(correctResults[i][2] == smallElInfo->getDisplacement()) ("Wrong displacement of small element!\n"); i++; cont = dualTraverse.traverseNext(&rowElInfo, &colElInfo, &smallElInfo, &largeElInfo); } return 0; }