Revision 71de76f6c662926f5da5408853e22786055a6194 authored by Thomas Fischer on 09 July 2021, 06:29:00 UTC, committed by Thomas Fischer on 30 August 2021, 05:26:04 UTC
The getContent() method is used only on very few
places. Especially, it isn't used in the computation
of any THMC processes. So the content doesn't need
to be stored which saves memory. Furthermore, the time
time for reading / initializing a mesh is reduced.

In a hex mesh with 100x100x100 elements this saves
2.6% of storage and circa 25% time.
1 parent deb816d
Raw File
SpatialPosition.h
/**
 * \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
 *
 */

#pragma once

#include <optional>

#include "MathLib/TemplatePoint.h"

namespace ParameterLib
{
//! Represents a position in space which can be either one of
//! a node, an element, an integration point or a cartesian coordinates triple.
//!
//! The setters of this class make sure that only compatible information can be
//! stored at the same time; e.g., it is not possible to specify an element ID
//! and a node ID at the same time (the setAll() method being an exception to
//! that rule).
class SpatialPosition
{
public:
    SpatialPosition() = default;

    SpatialPosition(
        std::optional<std::size_t> const& node_id,
        std::optional<std::size_t> const& element_id,
        std::optional<unsigned> const& integration_point,
        std::optional<MathLib::TemplatePoint<double, 3>> const& coordinates)
        : _node_id(node_id),
          _element_id(element_id),
          _integration_point(integration_point),
          _coordinates(coordinates)
    {
    }

    std::optional<std::size_t> getNodeID() const { return _node_id; }
    std::optional<std::size_t> getElementID() const { return _element_id; }
    std::optional<unsigned> getIntegrationPoint() const
    {
        return _integration_point;
    }
    std::optional<MathLib::TemplatePoint<double, 3>> const& getCoordinates()
        const
    {
        return _coordinates;
    }

    void setNodeID(std::size_t node_id)
    {
        clear();
        _node_id = node_id;
    }

    void setElementID(std::size_t element_id)
    {
        clear();
        _element_id = element_id;
    }

    void setIntegrationPoint(unsigned integration_point)
    {
        assert(_element_id);
        _integration_point = integration_point;
    }

    void setCoordinates(MathLib::TemplatePoint<double, 3> const& coordinates)
    {
        _coordinates = coordinates;
    }

    void setAll(
        std::optional<std::size_t> const& node_id,
        std::optional<std::size_t> const& element_id,
        std::optional<unsigned> const& integration_point,
        std::optional<MathLib::TemplatePoint<double, 3>> const& coordinates)
    {
        _node_id = node_id;
        _element_id = element_id;
        _integration_point = integration_point;
        _coordinates = coordinates;
    }

    void clear()
    {
        _node_id = std::nullopt;
        _element_id = std::nullopt;
        _integration_point = std::nullopt;
        _coordinates = std::nullopt;
    }

private:
    std::optional<std::size_t> _node_id;
    std::optional<std::size_t> _element_id;
    std::optional<unsigned> _integration_point;
    std::optional<MathLib::TemplatePoint<double, 3>> _coordinates;
};

}  // namespace ParameterLib
back to top