Skip to content

Commit

Permalink
More subs, still broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed committed Jul 18, 2023
1 parent 998dfd0 commit 675b744
Show file tree
Hide file tree
Showing 21 changed files with 529 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ namespace meshkernel
/// @brief Constructor taking only a projection
CurvilinearGrid(Projection projection);

/// @brief Lvalue constructor. Creates a new curvilinear grid from a given set of points
/// @param[in] grid The input grid points
/// @param[in] projection The projection to use
CurvilinearGrid(lin_alg::MatrixRowMajor<Point> const& grid, Projection projection);

/// @brief Deletes a curvilinear grid inside a polygon
/// @param[in] polygons The polygons
/// @param[in] polygonIndex The index of the polygon to use for deletion
void Delete(std::shared_ptr<Polygons> polygons, UInt polygonIndex);

/// @brief Lvalue constructor. Creates a new curvilinear grid from a given set of points
/// @param[in] grid The input grid points
/// @param[in] projection The projection to use
CurvilinearGrid(std::vector<std::vector<Point>> const& grid, Projection projection);

/// @brief Check if current curvilinear grid instance is valid
/// @return True if valid, false otherwise
[[nodiscard]] bool IsValid() const;
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace meshkernel

UInt m_numM = 0; ///< The number of m coordinates (vertical lines)
UInt m_numN = 0; ///< The number of n coordinates (horizontal lines)
std::vector<std::vector<Point>> m_gridNodes; ///< Member variable storing the grid
lin_alg::MatrixRowMajor<Point> m_gridNodes; ///< Member variable storing the grid
lin_alg::MatrixRowMajor<bool> m_gridFacesMask; ///< The mask of the grid faces (true/false)
lin_alg::MatrixRowMajor<NodeType> m_gridNodesTypes; ///< The grid node types
std::vector<CurvilinearGridNodeIndices> m_gridIndices; ///< The original mapping of the flatten nodes in the curvilinear grid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,49 @@ namespace meshkernel

OrthogonalizationParameters m_orthogonalizationParameters; ///< The orthogonalization parameters

std::vector<std::vector<double>> m_a; ///< The a term of the orthogonalization equation
std::vector<std::vector<double>> m_b; ///< The b term of the orthogonalization equation
std::vector<std::vector<double>> m_c; ///< The c term of the orthogonalization equation
std::vector<std::vector<double>> m_d; ///< The d term of the orthogonalization equation
std::vector<std::vector<double>> m_e; ///< The e term of the orthogonalization equation
std::vector<std::vector<double>> m_atp; ///< The atp term of the orthogonalization equation

std::vector<std::vector<bool>> m_isGridNodeFrozen; ///< A mask for setting some of the grid nodes frozen
struct Terms
{
Terms(UInt M, UInt N)
{
lin_alg::ResizeAndFillMatrix(a, M, N, false, constants::missing::doubleValue);
lin_alg::ResizeAndFillMatrix(b, M, N, false, constants::missing::doubleValue);
lin_alg::ResizeAndFillMatrix(c, M, N, false, constants::missing::doubleValue);
lin_alg::ResizeAndFillMatrix(d, M, N, false, constants::missing::doubleValue);
lin_alg::ResizeAndFillMatrix(e, M, N, false, constants::missing::doubleValue);
lin_alg::ResizeAndFillMatrix(atp, M, N, false, constants::missing::doubleValue);
}

// Preserves atp
void Reset()
{
a.fill(0.0);
b.fill(0.0);
c.fill(0.0);
d.fill(0.0);
e.fill(0.0);
}

void Invalidate()
{
a.fill(constants::missing::doubleValue);
b.fill(constants::missing::doubleValue);
c.fill(constants::missing::doubleValue);
d.fill(constants::missing::doubleValue);
e.fill(constants::missing::doubleValue);
atp.fill(constants::missing::doubleValue);
}

lin_alg::MatrixRowMajor<double> a; ///< The a term of the orthogonalization equation
lin_alg::MatrixRowMajor<double> b; ///< The b term of the orthogonalization equation
lin_alg::MatrixRowMajor<double> c; ///< The c term of the orthogonalization equation
lin_alg::MatrixRowMajor<double> d; ///< The d term of the orthogonalization equation
lin_alg::MatrixRowMajor<double> e; ///< The e term of the orthogonalization equation
lin_alg::MatrixRowMajor<double> atp; ///< The atp term of the orthogonalization equation
};

Terms m_terms;

lin_alg::MatrixRowMajor<bool> m_isGridNodeFrozen; ///< A mask for setting some of the grid nodes frozen

Splines m_splines; ///< The grid lines stored as splines
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace meshkernel
/// @param[in] n The current n coordinate on the boundary of the curvilinear grid
void ProjectPointOnClosestGridBoundary(Point const& point, UInt m, UInt n);

UInt m_smoothingIterations; ///< The orthogonalization parameters
std::vector<std::vector<Point>> m_gridNodesCache; ///< A cache for storing current iteration node positions
UInt m_smoothingIterations; ///< The orthogonalization parameters
lin_alg::MatrixRowMajor<Point> m_gridNodesCache; ///< A cache for storing current iteration node positions
};
} // namespace meshkernel
5 changes: 5 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Entities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ namespace meshkernel
return !isInvalid;
}

void Invalidate()
{
*this = Point(constants::missing::doubleValue, constants::missing::doubleValue);
}

private:
static double constexpr m_trans_factor =
constants::conversion::degToRad *
Expand Down
15 changes: 8 additions & 7 deletions libs/MeshKernel/include/MeshKernel/Operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <MeshKernel/Constants.hpp>
#include <MeshKernel/Entities.hpp>
#include <MeshKernel/Utilities/LinearAlgebra.hpp>
#include <MeshKernel/Utilities/RTree.hpp>

namespace meshkernel
Expand Down Expand Up @@ -514,13 +515,13 @@ namespace meshkernel
/// @param[in] numM The number of columns to generate (horizontal direction).
/// @param[in] numN The number of rows to generate (vertical direction).
/// @returns The resulting dicretization (expressed as number of points).
[[nodiscard]] std::vector<std::vector<Point>> DiscretizeTransfinite(const std::vector<Point>& leftDiscretization,
const std::vector<Point>& rightDiscretization,
const std::vector<Point>& bottomDiscretization,
const std::vector<Point>& upperDiscretization,
const Projection& projection,
UInt numM,
UInt numN);
[[nodiscard]] lin_alg::MatrixRowMajor<Point> DiscretizeTransfinite(const std::vector<Point>& leftDiscretization,
const std::vector<Point>& rightDiscretization,
const std::vector<Point>& bottomDiscretization,
const std::vector<Point>& upperDiscretization,
const Projection& projection,
UInt numM,
UInt numN);

/// @brief Computes the edge centers
/// @param[in] nodes The vector of edge nodes.
Expand Down
2 changes: 2 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Splines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace meshkernel
/// @param[in] size The end index splines
void AddSpline(const std::vector<Point>& splines, UInt start, UInt size);

void AddSpline(Point const* const splines, UInt start, UInt size);

/// @brief Second order derivative at spline corner points, from the start node to the end node of the spline (splint)
/// @param[in] splines The spline corner points
/// @param[in] startIndex The start spline node
Expand Down
14 changes: 10 additions & 4 deletions libs/MeshKernel/include/MeshKernel/Utilities/LinearAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ namespace meshkernel
bool preserve = false,
T const& fill_value = {})
{
UInt const rows_old = static_cast<UInt>(matrix.rows());
UInt const cols_old = static_cast<UInt>(matrix.cols());
matrix.resize(rows, cols);
if (!preserve)
{
matrix.fill(fill_value);
matrix.setConstant(rows, cols, fill_value);
}
else
{
UInt const rows_old = static_cast<UInt>(matrix.rows());
UInt const cols_old = static_cast<UInt>(matrix.cols());
matrix.conservativeResize(rows, cols);
for (UInt i = rows_old; i < matrix.rows(); ++i)
{
for (UInt j = cols_old; j < matrix.cols(); ++j)
Expand All @@ -53,6 +53,12 @@ namespace meshkernel
}
}
}

template <class T>
[[nodiscard]] inline static bool MatrixIsEmpty(MatrixRowMajor<T> const& matrix)
{
return matrix.size() == 0;
}
} // namespace lin_alg

} // namespace meshkernel
Loading

0 comments on commit 675b744

Please sign in to comment.