Skip to content

Commit

Permalink
Rename Element to Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
cbritopacheco committed Nov 5, 2023
1 parent b371110 commit eb77d53
Show file tree
Hide file tree
Showing 19 changed files with 433 additions and 118 deletions.
1 change: 1 addition & 0 deletions examples/Variational/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ target_link_libraries(Normal PUBLIC Rodin::Variational)
add_executable(BooleanFunction BooleanFunction.cpp)
target_link_libraries(BooleanFunction PUBLIC Rodin::Variational)

add_subdirectory(P0)
add_subdirectory(P1)
2 changes: 2 additions & 0 deletions examples/Variational/P0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(ScalarP0Build ScalarP0Build.cpp)
target_link_libraries(ScalarP0Build PUBLIC Rodin::Variational)
25 changes: 25 additions & 0 deletions examples/Variational/P0/ScalarP0Build.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Carlos BRITO PACHECO 2021 - 2022.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*/
#include <Rodin/Solver.h>
#include <Rodin/Geometry.h>
#include <Rodin/Variational.h>

using namespace Rodin;
using namespace Rodin::Geometry;
using namespace Rodin::Variational;

int main(int, char**)
{
Mesh mesh;
mesh = mesh.UniformGrid(Polytope::Type::Triangle, 16, 16);

P0 fes(mesh);

std::cout << "Size of the finite element space: " << fes.getSize() << std::endl;
std::cout << "Vector dimension: " << fes.getVectorDimension() << std::endl;
}

14 changes: 7 additions & 7 deletions examples/Variational/P1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
add_executable(P1Potential P1Potential.cpp)
target_link_libraries(P1Potential
PUBLIC Rodin::Variational Rodin::External::MMG)

add_executable(P1GridFunctionIO P1GridFunctionIO.cpp)
target_link_libraries(P1GridFunctionIO PUBLIC Rodin::Variational)

add_executable(ScalarP1Build ScalarP1Build.cpp)
target_link_libraries(ScalarP1Build PUBLIC Rodin::Variational)

add_executable(ScalarP1Projection ScalarP1Projection.cpp)
target_link_libraries(ScalarP1Projection PUBLIC Rodin::Variational)

add_executable(P1GridFunctionIO P1GridFunctionIO.cpp)
target_link_libraries(P1GridFunctionIO PUBLIC Rodin::Variational)

add_executable(VectorP1Build VectorP1Build.cpp)
target_link_libraries(VectorP1Build PUBLIC Rodin::Variational)

Expand All @@ -19,3 +15,7 @@ target_link_libraries(VectorP1Projection PUBLIC Rodin::Variational)

add_executable(P1GridFunctionGradient P1GridFunctionGradient.cpp)
target_link_libraries(P1GridFunctionGradient PUBLIC Rodin::Variational)

add_executable(P1Potential P1Potential.cpp)
target_link_libraries(P1Potential
PUBLIC Rodin::Variational Rodin::External::MMG)
2 changes: 1 addition & 1 deletion src/Rodin/Geometry/ForwardDecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Rodin::Geometry

class Polytope;

class Element;
class Cell;

class Face;

Expand Down
2 changes: 1 addition & 1 deletion src/Rodin/Geometry/Polytope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace Rodin::Geometry
}

// ---- Element -----------------------------------------------------------
Element::Element(Index index, const MeshBase& mesh)
Cell::Cell(Index index, const MeshBase& mesh)
: Polytope(mesh.getDimension(), index, mesh)
{}

Expand Down
14 changes: 5 additions & 9 deletions src/Rodin/Geometry/Polytope.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,21 @@ namespace Rodin::Geometry
bool operator<(const Polytope& lhs, const Polytope& rhs);

/**
* @brief Class for representing elements of the highest dimension in the
* @brief Class for representing polytopes of the highest dimension in the
* mesh, i.e. tetrahedra in 3D, triangles in 2D or lines in 1D.
*
* This class is designed so that modifications cannot be made to the
* element. If one wishes to modify the element then one must use
* ElementView.
*/
class Element : public Polytope
class Cell : public Polytope
{
public:
using Parent = Polytope;

Element(Index index, const MeshBase& mesh);
Cell(Index index, const MeshBase& mesh);

Element(const Element& other)
Cell(const Cell& other)
: Polytope(other)
{}

Element(Element&& other)
Cell(Cell&& other)
: Polytope(std::move(other))
{}
};
Expand Down
8 changes: 4 additions & 4 deletions src/Rodin/Geometry/PolytopeIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ namespace Rodin::Geometry
return *this;
}

Element& CellIterator::operator*() const noexcept
Cell& CellIterator::operator*() const noexcept
{
if (!m_polytope || m_dirty)
m_polytope.reset(generate());
m_dirty = false;
return *m_polytope;
}

Element* CellIterator::operator->() const noexcept
Cell* CellIterator::operator->() const noexcept
{
if (!m_polytope || m_dirty)
m_polytope.reset(generate());
Expand All @@ -91,13 +91,13 @@ namespace Rodin::Geometry
return getMesh().getDimension();
}

Element* CellIterator::generate() const
Cell* CellIterator::generate() const
{
if (end()) return nullptr;
const auto& gen = getIndexGenerator();
const auto& index = *gen;
const auto& mesh = getMesh();
return new Element(index, mesh);
return new Cell(index, mesh);
}

// ---- FaceIterator ------------------------------------------------------
Expand Down
20 changes: 16 additions & 4 deletions src/Rodin/Geometry/PolytopeIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

namespace Rodin::Geometry
{
/**
* @brief Represents an iterator over a set of polytopes of a mesh.
*/
class PolytopeIterator
{
public:
Expand Down Expand Up @@ -81,6 +84,9 @@ namespace Rodin::Geometry
mutable std::unique_ptr<Polytope> m_polytope;
};

/**
* @brief Represents an iterator over a set of cells of a mesh.
*/
class CellIterator
{
public:
Expand All @@ -104,9 +110,9 @@ namespace Rodin::Geometry

CellIterator& operator++();

Element& operator*() const noexcept;
Cell& operator*() const noexcept;

Element* operator->() const noexcept;
Cell* operator->() const noexcept;

size_t getDimension() const;

Expand All @@ -125,7 +131,7 @@ namespace Rodin::Geometry
}

private:
Element* generate() const;
Cell* generate() const;

IndexGeneratorBase& getIndexGenerator()
{
Expand All @@ -136,9 +142,12 @@ namespace Rodin::Geometry
std::optional<std::reference_wrapper<const MeshBase>> m_mesh;
std::unique_ptr<IndexGeneratorBase> m_gen;
mutable bool m_dirty;
mutable std::unique_ptr<Element> m_polytope;
mutable std::unique_ptr<Cell> m_polytope;
};

/**
* @brief Represents an iterator over a set of faces of a mesh.
*/
class FaceIterator
{
public:
Expand Down Expand Up @@ -197,6 +206,9 @@ namespace Rodin::Geometry
mutable std::unique_ptr<Face> m_polytope;
};

/**
* @brief Represents an iterator over a set of vertices of a mesh.
*/
class VertexIterator
{
public:
Expand Down
61 changes: 30 additions & 31 deletions src/Rodin/IO/MFEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@
#include "MFEM.h"

namespace Rodin::IO::MFEM
{}
{
std::istream& getline(std::istream& is, std::string& line, size_t& currentLineNumber)
{
currentLineNumber++;
return std::getline(is, line);
}

std::string skipEmptyLinesAndComments(std::istream& is, size_t& currentLineNumber)
{
std::string line;
while (getline(is, line))
{
if (!MFEM::ParseEmptyLineOrComment()(line.begin(), line.end()))
break;
currentLineNumber++;
}
return line;
}
}

namespace Rodin::IO
{
void MeshLoader<FileFormat::MFEM, Context::Serial>::readHeader(std::istream& is)
{
auto line = skipEmptyLinesAndComments(is);
auto line = MFEM::skipEmptyLinesAndComments(is, m_currentLineNumber);
auto header = MFEM::ParseMeshHeader()(line.begin(), line.end());
if (!header)
{
Expand All @@ -25,7 +43,7 @@ namespace Rodin::IO

void MeshLoader<FileFormat::MFEM, Context::Serial>::readDimension(std::istream& is)
{
auto line = skipEmptyLinesAndComments(is);
auto line = MFEM::skipEmptyLinesAndComments(is, m_currentLineNumber);
auto kw = MFEM::ParseKeyword()(line.begin(), line.end());
if (!kw && *kw != MFEM::Keyword::dimension)
{
Expand All @@ -35,7 +53,7 @@ namespace Rodin::IO
<< " on line " << m_currentLineNumber << "."
<< Alert::Raise;
}
line = skipEmptyLinesAndComments(is);
line = MFEM::skipEmptyLinesAndComments(is, m_currentLineNumber);
auto dimension = MFEM::ParseUnsignedInteger()(line.begin(), line.end());
if (!dimension)
{
Expand All @@ -55,7 +73,7 @@ namespace Rodin::IO
attrs.initialize(m_dimension);

std::string line;
while (getline(is, line))
while (MFEM::getline(is, line, m_currentLineNumber))
{
if (MFEM::ParseEmptyLineOrComment()(line.begin(), line.end()))
continue;
Expand All @@ -81,7 +99,7 @@ namespace Rodin::IO
{
case MFEM::Keyword::boundary:
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto count = MFEM::ParseUnsignedInteger()(line.begin(), line.end());
if (!count)
{
Expand All @@ -93,7 +111,7 @@ namespace Rodin::IO
attrs.reserve(m_dimension - 1, *count);
for (size_t i = 0; i < *count; i++)
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto g = MFEM::ParseGeometry()(line.begin(), line.end());
if (!g)
{
Expand All @@ -109,7 +127,7 @@ namespace Rodin::IO
}
case MFEM::Keyword::elements:
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto count = MFEM::ParseUnsignedInteger()(line.begin(), line.end());
if (!count)
{
Expand All @@ -121,7 +139,7 @@ namespace Rodin::IO
attrs.reserve(m_dimension, *count);
for (size_t i = 0; i < *count; i++)
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto g = MFEM::ParseGeometry()(line.begin(), line.end());
if (!g)
{
Expand All @@ -137,7 +155,7 @@ namespace Rodin::IO
}
case MFEM::Keyword::vertices:
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto count = MFEM::ParseUnsignedInteger()(line.begin(), line.end());
if (!count)
{
Expand All @@ -147,15 +165,15 @@ namespace Rodin::IO
<< Alert::Raise;
}
connectivity.nodes(*count);
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto vdim = MFEM::ParseUnsignedInteger()(line.begin(), line.end());
if (vdim)
{
m_spaceDimension = *vdim;
m_build.initialize(m_spaceDimension).nodes(*count);
for (size_t i = 0; i < *count; i++)
{
getline(is, line);
MFEM::getline(is, line, m_currentLineNumber);
auto x = MFEM::ParseVertex(m_spaceDimension)(line.begin(), line.end());
if (!x)
{
Expand Down Expand Up @@ -205,25 +223,6 @@ namespace Rodin::IO
m_build.setAttributeIndex(std::move(attrs));
}

std::string
MeshLoader<FileFormat::MFEM, Context::Serial>::skipEmptyLinesAndComments(std::istream& is)
{
std::string line;
while (getline(is, line))
{
if (!MFEM::ParseEmptyLineOrComment()(line.begin(), line.end()))
break;
}
return line;
}

std::istream&
MeshLoader<FileFormat::MFEM, Context::Serial>::getline(std::istream& is, std::string& line)
{
m_currentLineNumber++;
return std::getline(is, line);
}

void MeshLoader<IO::FileFormat::MFEM, Context::Serial>::load(std::istream &is)
{
readHeader(is);
Expand Down
Loading

0 comments on commit eb77d53

Please sign in to comment.