Skip to content

Commit

Permalink
typos + format
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Nov 28, 2024
1 parent 75290a9 commit c217585
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ikarus/finiteelements/mechanics/truss.hh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public:
}

/**
* \brief Computes the length fo the truss and the coordinate transformation matrix T for the undeformed configuration
* \brief Computes the length of the truss and the coordinate transformation matrix T for the undeformed configuration
*
* \return std::pair of length, and T
*/
Expand Down
3 changes: 2 additions & 1 deletion ikarus/python/utils/registerModalAnalysis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void registerModalAnalysis(pybind11::handle scope, pybind11::class_<ModalAnalysi
cls.def("squaredAngularFrequencies", &ModalAnalysis::squaredAngularFrequencies, pybind11::return_value_policy::copy);
cls.def("eigenmodes", &ModalAnalysis::eigenmodes, pybind11::return_value_policy::copy);
cls.def_property_readonly("nev", &ModalAnalysis::nev);
cls.def("writeEigenModes", &ModalAnalysis::writeEigenModes, pybind11::arg("filename"), pybind11::arg("nev") = std::nullopt);
cls.def("writeEigenModes", &ModalAnalysis::writeEigenModes, pybind11::arg("filename"),
pybind11::arg("nev") = std::nullopt);

cls.def("bindLumpingScheme",
[](ModalAnalysis& self) { self.template bindLumpingScheme<Dynamics::LumpingSchemes::RowSumLumping>(); });
Expand Down
63 changes: 42 additions & 21 deletions ikarus/solver/eigenvaluesolver/generaleigensolver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@

namespace Ikarus {

MAKE_ENUM(EigenSolverTypeTag, Spectra, Eigen);
MAKE_ENUM(EigenValueSolverType, Spectra, Eigen);

template <EigenSolverTypeTag SolverType, Concepts::DenseOrSparseEigenMatrix MT>
template <EigenValueSolverType SolverType, Concepts::DenseOrSparseEigenMatrix MT>
struct GeneralSymEigenSolver
{
};

/**
* \brief
*
* \tparam MT
*/
template <Concepts::DenseOrSparseEigenMatrix MT>
struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>
struct GeneralSymEigenSolver<EigenValueSolverType::Spectra, MT>
{
using ScalarType = typename MT::Scalar;
static constexpr bool isDense = Concepts::EigenMatrix<MT>;
Expand All @@ -45,6 +50,14 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>

using SolverType = Spectra::SymGEigsSolver<ProductType, CholeskyType, Spectra::GEigsMode::Cholesky>;

/**
* \brief Construct a new General Sym Eigen Solver object.
*
* \tparam MATA deduced type of passed matrix A.

Check failure on line 56 in ikarus/solver/eigenvaluesolver/generaleigensolver.hh

View workflow job for this annotation

GitHub Actions / Check for spelling errors

MATA ==> META, MATER
* \tparam MATB deduced type of passed matrix B.
* \param A matrix A.
* \param B matrix B.
*/
template <typename MATA, typename MATB>

Check failure on line 61 in ikarus/solver/eigenvaluesolver/generaleigensolver.hh

View workflow job for this annotation

GitHub Actions / Check for spelling errors

MATA ==> META, MATER
requires(Concepts::DenseOrSparseEigenMatrix<std::remove_cvref_t<MATA>>)

Check failure on line 62 in ikarus/solver/eigenvaluesolver/generaleigensolver.hh

View workflow job for this annotation

GitHub Actions / Check for spelling errors

MATA ==> META, MATER
GeneralSymEigenSolver(MATA&& A, MATB&& B)

Check failure on line 63 in ikarus/solver/eigenvaluesolver/generaleigensolver.hh

View workflow job for this annotation

GitHub Actions / Check for spelling errors

MATA ==> META, MATER
Expand All @@ -62,6 +75,14 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>
assert(nevsPartition_.first + nevsPartition_.second == nev_);
}

/**
* \brief Construct a new General Sym Eigen Solver object.
*
* \tparam AssemblerA the type of the assembler for matrix A.
* \tparam AssemblerB the type of the assembler for matrix B.
* \param assemblerA assembler for matrix A.
* \param assemblerB assembler for matrix B.
*/
template <Concepts::FlatAssembler AssemblerA, Concepts::FlatAssembler AssemblerB>
GeneralSymEigenSolver(const std::shared_ptr<AssemblerA>& assemblerA, const std::shared_ptr<AssemblerB>& assemblerB)
: GeneralSymEigenSolver(assemblerA->matrix(), assemblerB->matrix()) {}
Expand All @@ -70,9 +91,9 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>
* \brief Starts the computation of the eigenvalue solver
*
* \param tolerance given tolerance for iterative eigenvalue solving (default: 1e-10)
* \param maxit givenn maximum iterations for eigenvalue solving (default 1000)
* \return true solving was successfull
* \return false solving was not successfull
* \param maxit givenn maximum iterations for eigenvalue solving (default: 1000)
* \return true solving was successful
* \return false solving was not successful
*/
bool compute(ScalarType tolerance = 1e-10, Eigen::Index maxit = 1000) {
solverSmallest_.init();
Expand All @@ -94,7 +115,7 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>
}

/**
* \brief Returns the eigenvalues of the gerneral eigenvalue problem
* \brief Returns the eigenvalues of the general eigenvalue problem
*
* \return Eigen::VectorXd vector of eigenvalues
*/
Expand All @@ -104,7 +125,7 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MT>
}

/**
* \brief Returns the eigenvectors of the gerneral eigenvalue problem
* \brief Returns the eigenvectors of the general eigenvalue problem
*
* \return auto matrix with the eigevectors as columns
*/
Expand Down Expand Up @@ -136,7 +157,7 @@ private:
};

template <Concepts::EigenMatrix MT>
struct GeneralSymEigenSolver<EigenSolverTypeTag::Eigen, MT>
struct GeneralSymEigenSolver<EigenValueSolverType::Eigen, MT>
{
using ScalarType = typename MT::Scalar;
using MatrixType = MT;
Expand All @@ -161,17 +182,17 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Eigen, MT>
*
* \param options defaults to Eigen::ComputeEigenvectors, can be set to Eigen::EigenvaluesOnly, accessing eigenvectors
* in that case will results in an error
* \return true solving was successfull
* \return false solving was not successfull
* \return true solving was successful
* \return false solving was not successful
*/
bool compute(int options = Eigen::ComputeEigenvectors) {
solver_.compute(matA_, matB_, options);
computed_ = true;
return true; // SelfAdjointEigenSolver will always be successfull if prerequisits are met
return true; // SelfAdjointEigenSolver will always be successful if prerequisites are met
}

/**
* \brief Returns the eigenvalues of the gerneral eigenvalue problem
* \brief Returns the eigenvalues of the general eigenvalue problem
*
* \return Reference to the vector of eigenvalues
*/
Expand All @@ -181,7 +202,7 @@ struct GeneralSymEigenSolver<EigenSolverTypeTag::Eigen, MT>
}

/**
* \brief Returns the eigenvectors of the gerneral eigenvalue problem
* \brief Returns the eigenvectors of the general eigenvalue problem
*
* \param _nev optionally specify how many eigenvectors are requested
* \return Reference to the matrix with the eigevectors as columns
Expand All @@ -203,9 +224,9 @@ private:
}
};

template <EigenSolverTypeTag tag, Concepts::FlatAssembler AS1, Concepts::FlatAssembler AS2>
template <EigenValueSolverType tag, Concepts::FlatAssembler AS1, Concepts::FlatAssembler AS2>
requires(std::same_as<typename AS1::MatrixType, typename AS2::MatrixType> &&
not(tag == EigenSolverTypeTag::Eigen && Concepts::SparseEigenMatrix<typename AS1::MatrixType>))
not(tag == EigenValueSolverType::Eigen && Concepts::SparseEigenMatrix<typename AS1::MatrixType>))
auto makeGeneralSymEigenSolver(const std::shared_ptr<AS1>& as1, const std::shared_ptr<AS2> as2) {
using MatrixType = typename AS1::MatrixType;
constexpr auto isSparse = Concepts::SparseEigenMatrix<MatrixType>;
Expand Down Expand Up @@ -249,9 +270,9 @@ struct PartialGeneralSymEigenSolver
* \brief Starts the computation of the eigenvalue solver
*
* \param tolerance given tolerance for iterative eigenvalue solving (default: 1e-10)
* \param maxit givenn maximum iterations for eigenvalue solving (default 1000)
* \return true solving was successfull
* \return false solving was not successfull
* \param maxit givenn maximum iterations for eigenvalue solving (default: 1000)
* \return true solving was successful
* \return false solving was not successful
*/
bool compute(ScalarType tolerance = 1e-10, Eigen::Index maxit = 1000) {
solver_.init();
Expand All @@ -262,7 +283,7 @@ struct PartialGeneralSymEigenSolver
}

/**
* \brief Returns the eigenvalues of the gerneral eigenvalue problem
* \brief Returns the eigenvalues of the general eigenvalue problem
*
* \return Eigen::VectorXd vector of eigenvalues
*/
Expand All @@ -272,7 +293,7 @@ struct PartialGeneralSymEigenSolver
}

/**
* \brief Returns the eigenvectors of the gerneral eigenvalue problem
* \brief Returns the eigenvectors of the general eigenvalue problem
*
* \param _nev optionally specify how many eigenvectors are requested
* \return auto matrix with the eigevectors as columns
Expand Down
4 changes: 2 additions & 2 deletions ikarus/utils/concepts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ namespace Concepts {

/**
* \concept DenseOrSparseEigenMatrix
* \brief Concept defining the requirements for sparse ot dense Eigen matrices.
* \brief Concept defining the requirements for sparse or dense Eigen matrices.
* \tparam M Type representing a dense or sparse Eigen matrix.
*/
template <typename M>
Expand Down Expand Up @@ -627,7 +627,7 @@ namespace Concepts {
* \brief Concept representing an eigenvalue solver interface
*
* \concept EigenValueSolver
* A type ES satisfies EigenValueSolver if it provides the neccesary member functions and type
* A type ES satisfies EigenValueSolver if it provides the necessary member functions and type
*/
template <typename ES>
concept EigenValueSolver = requires(ES es) {
Expand Down
1 change: 1 addition & 0 deletions ikarus/utils/modalanalysis/lumpingschemes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once
#include <dune/common/rangeutilities.hh>

#include <Eigen/Core>
#include <Eigen/SparseCore>

Expand Down
32 changes: 16 additions & 16 deletions ikarus/utils/modalanalysis/modalanalysis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
namespace Ikarus::Dynamics {

/**
* \brief Opinionated wrapper class for GeneralSymEigenSolver suited for modal analyis
* \brief Opinionated wrapper class for GeneralSymEigenSolver suited for modal analysis
*
* \tparam FEC the type of containner for finite elements
* \tparam FEC the type of container for finite elements
* \tparam DV the type of the DirichletValues
*/
template <typename FEC, typename DV>
Expand All @@ -44,7 +44,7 @@ struct ModalAnalysis
AssemblerManipulator<Assembler, Ikarus::Impl::AssemblerInterfaceHelper<ScalarAssembler, ScalarManipulator>,
Ikarus::Impl::AssemblerInterfaceHelper<VectorAssembler, VectorManipulator>,
Ikarus::Impl::AssemblerInterfaceHelper<MatrixAssembler, MatrixManipulator>>;
using Solver = GeneralSymEigenSolver<EigenSolverTypeTag::Spectra, MatrixType>;
using Solver = GeneralSymEigenSolver<EigenValueSolverType::Spectra, MatrixType>;

/**
* \brief Construct a new Modal Analysis object
Expand Down Expand Up @@ -76,11 +76,11 @@ struct ModalAnalysis
* It resets already bound matrix manipulation functions.
*
* \tparam LumpingScheme The type of the lumping scheme, for example one found at \file
* ikarus/utils/modalanalysis/lumpingschemes.hh.s \param ls the instantiated LumpingScheme (pass either by value or by
* template definition).
* ikarus/utils/modalanalysis/lumpingschemes.hh.s
* \param ls the instantiated LumpingScheme object (pass either by value or by template definition).
*/
template <typename LumpingScheme>
void bindLumpingScheme(LumpingScheme ls = LumpingScheme{}) {
void bindLumpingScheme(LumpingScheme ls = {}) {
lumpedMassAssembler_->unbindAllMatrixFunctions();
lumpedMassAssembler_->bind(ls);
}
Expand All @@ -91,17 +91,17 @@ struct ModalAnalysis
* \brief Starts the computation of the eigenvalue solver
*
* \param tolerance given tolerance for iterative eigenvalue solving (default: 1e-10)
* \param maxit givenn maximum iterations for eigenvalue solving (default 1000)
* \return true solving was successfull
* \return false solving was not successfull
* \param maxit givenn maximum iterations for eigenvalue solving (default: 1000)
* \return true solving was successful
* \return false solving was not successful
*/
bool compute(ScalarType tolerance = 1e-10, Eigen::Index maxit = 1000) {
solver_.emplace(stiffAssembler_, lumpedMassAssembler_);
return solver_->compute();
return solver_->compute(tolerance, maxit);
}

/**
* \brief Returns the angular frequncies as \f$ \omega = \sqrt{\lambda} \f$, with \f$ \lambda \f$: eigenvalues from
* \brief Returns the angular frequencies as \f$ \omega = \sqrt{\lambda} \f$, with \f$ \lambda \f$: eigenvalues from
* the eigenvalue solver
*/
Eigen::VectorXd angularFrequencies() {
Expand All @@ -110,15 +110,15 @@ struct ModalAnalysis
}

/**
* \brief Returns the angular frequncies as \f$ f = \dfrac{\omega}{2\pi} \f$, with \f$ \omega \f$: angular frequency
* \brief Returns the angular frequencies as \f$ f = \dfrac{\omega}{2\pi} \f$, with \f$ \omega \f$: angular frequency
*/
Eigen::VectorXd naturalFrequencies() {
assertCompute();
return angularFrequencies() / (2 * std::numbers::pi);
}

/**
* \brief Returns the angular frequncies as \f$ \omega^2 = \lambda \f$, with \f$ \lambda \f$: eigenvalues from
* \brief Returns the angular frequencies as \f$ \omega^2 = \lambda \f$, with \f$ \lambda \f$: eigenvalues from
* the eigenvalue solver
*/
const Eigen::VectorXd& squaredAngularFrequencies() const {
Expand All @@ -127,7 +127,7 @@ struct ModalAnalysis
}

/**
* \brief Returns the eigenmodes (eigenvectors) of the gerneral eigenvalue problem
* \brief Returns the eigenmodes (eigenvectors) of the general eigenvalue problem
*
* \return auto matrix with the eigevectors as columns
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ struct ModalAnalysis
/** \brief Returns a const reference to the assembler of the stiffness matrix */
auto& stiffnessAssembler() const { return stiffAssembler_; }

/** \brief Returns a const reference to the assembler of the (potentialy lumped) mass matrix */
/** \brief Returns a const reference to the assembler of the (potentially lumped) mass matrix */
auto& massAssembler() const { return lumpedMassAssembler_; }

private:
Expand All @@ -202,7 +202,7 @@ private:
}

/**
* \brief Returns one of the above results accoding to a a specified result type
* \brief Returns one of the above results according to a a specified result type
*
* \param rt specified result type of the modal analysis
*/
Expand Down
1 change: 1 addition & 0 deletions tests/src/testdynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static auto dynamicsTest() {
t.check(frequencies.sum() > frequenciesLumped.sum()) << testLocation();

mA.unBindLumpingScheme();
mA.compute();
auto frequencies2 = mA.angularFrequencies();
t.check(isApproxSame(frequencies, frequencies2, 1e-14)) << testLocation();

Expand Down
12 changes: 7 additions & 5 deletions tests/src/testeigenvaluesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ auto testEigenValues(const SOL1& solver1, const SOL2& solver2, std::optional<Eig
auto eigenvalues2 = solver2.eigenvalues();

if (not nev_.has_value()) {
t.check(isApproxSame(eigenvalues1, eigenvalues2, 1e-10)) << testLocation();
t.check(isApproxSame(eigenvalues1, eigenvalues2, 1e-10)) << testLocation() << "\n"
<< eigenvalues1 << "\n\n"
<< eigenvalues2;
} else {
t.check(isApproxSame(eigenvalues1.head(*nev_).eval(), eigenvalues2.head(*nev_).eval(), 1e-10))
<< testLocation() << "\n"
Expand Down Expand Up @@ -108,20 +110,20 @@ auto testRealWorldProblem() {
assKD->bind(req, Ikarus::AffordanceCollections::elastoStatics, Ikarus::DBCOption::Reduced);

int nev = 10; // number of requested eigenvalues
using Ikarus::EigenSolverTypeTag;
using Ikarus::EigenValueSolverType;

auto partialSolver = Ikarus::PartialGeneralSymEigenSolver(assK, assM, nev);
t.checkThrow([&]() { partialSolver.eigenvalues(); }) << testLocation();
bool success = partialSolver.compute();
t.check(success) << testLocation();

auto solver1 = Ikarus::makeGeneralSymEigenSolver<EigenSolverTypeTag::Eigen>(assKD, assMD);
auto solver1 = Ikarus::makeGeneralSymEigenSolver<EigenValueSolverType::Eigen>(assKD, assMD);
t.check(solver1.compute()) << testLocation();

auto solver2 = Ikarus::makeGeneralSymEigenSolver<EigenSolverTypeTag::Spectra>(assK, assM);
auto solver2 = Ikarus::makeGeneralSymEigenSolver<EigenValueSolverType::Spectra>(assK, assM);
t.check(solver2.compute()) << testLocation();

auto solver3 = Ikarus::makeGeneralSymEigenSolver<EigenSolverTypeTag::Spectra>(assKD, assMD);
auto solver3 = Ikarus::makeGeneralSymEigenSolver<EigenValueSolverType::Spectra>(assKD, assMD);
t.check(solver3.compute()) << testLocation();

t.subTest(testEigenVectors(solver2, solver3, assK));
Expand Down

0 comments on commit c217585

Please sign in to comment.