swh:1:snp:f521c49ab17ef7db6ec70b2430e1ed203f50383f
Raw File
Tip revision: 9918a4754ed66e638e3190cc9b50e930d2ff48f9 authored by Lars Bilke on 15 February 2021, 20:33:08 UTC
[CMake] Fix to create OGS.sln instead of iphreeqc.sln (Win).
Tip revision: 9918a47
FlipElements.cpp
/**
 * \file
 * \copyright
 * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 *
 */

#include "FlipElements.h"

#include "MeshLib/Elements/Element.h"
#include "MeshLib/Node.h"
#include "MeshLib/Elements/Line.h"
#include "MeshLib/Elements/Tri.h"
#include "MeshLib/Elements/Quad.h"
#include "DuplicateMeshComponents.h"

namespace MeshLib
{
std::unique_ptr<MeshLib::Element> createFlippedElement(
    MeshLib::Element const& elem, std::vector<MeshLib::Node*> const& nodes)
{
    if (elem.getDimension() > 2)
    {
        return nullptr;
    }

    unsigned const n_nodes(elem.getNumberOfNodes());
    auto elem_nodes = std::make_unique<MeshLib::Node*[]>(n_nodes);
    for (unsigned i = 0; i < n_nodes; ++i)
    {
        elem_nodes[i] = nodes[elem.getNode(i)->getID()];
    }
    std::swap(elem_nodes[0], elem_nodes[1]);

    if (elem.getGeomType() == MeshElemType::LINE)
    {
        return std::make_unique<MeshLib::Line>(elem_nodes.release(),
                                               elem.getID());
    }
    if (elem.getGeomType() == MeshElemType::TRIANGLE)
    {
        return std::make_unique<MeshLib::Tri>(elem_nodes.release(),
                                              elem.getID());
    }
    if (elem.getGeomType() == MeshElemType::QUAD)
    {
        std::swap(elem_nodes[2], elem_nodes[3]);
        return std::make_unique<MeshLib::Quad>(elem_nodes.release(),
                                               elem.getID());
    }
    return nullptr;
}

std::unique_ptr<MeshLib::Mesh> createFlippedMesh(MeshLib::Mesh const& mesh)
{
    if (mesh.getDimension() > 2)
    {
        return nullptr;
    }

    std::vector<MeshLib::Node*> new_nodes(
        MeshLib::copyNodeVector(mesh.getNodes()));
    std::vector<MeshLib::Element*> const& elems(mesh.getElements());
    std::vector<MeshLib::Element*> new_elems;
    std::size_t n_elems(mesh.getNumberOfElements());
    new_elems.reserve(n_elems);

    for (std::size_t i = 0; i < n_elems; ++i)
    {
        new_elems.push_back(
            createFlippedElement(*elems[i], new_nodes).release());
    }

    return std::make_unique<MeshLib::Mesh>("FlippedElementMesh", new_nodes,
                                           new_elems, mesh.getProperties());
}

}  // end namespace MeshLib
back to top