diff --git a/fdaPDE/core.h b/fdaPDE/core.h index e904448d..1f0852da 100644 --- a/fdaPDE/core.h +++ b/fdaPDE/core.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_CORE_MOUDLE_H__ -#define __FDAPDE_CORE_MOUDLE_H__ +#ifndef __FDAPDE_CORE_MODULE_H__ +#define __FDAPDE_CORE_MODULE_H__ #include "utils.h" #include "fields.h" @@ -26,4 +26,4 @@ #include "splines.h" #include "multithreading.h" -#endif // __FDAPDE_CORE_MOUDLE_H__ +#endif // __FDAPDE_CORE_MODULE_H__ diff --git a/fdaPDE/fields.h b/fdaPDE/fields.h index 63595edf..676af1c3 100644 --- a/fdaPDE/fields.h +++ b/fdaPDE/fields.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_FIELDS_MOUDLE_H__ -#define __FDAPDE_FIELDS_MOUDLE_H__ +#ifndef __FDAPDE_FIELDS_MODULE_H__ +#define __FDAPDE_FIELDS_MODULE_H__ #include "fields/differentiable_field.h" #include "fields/dot_product.h" @@ -27,4 +27,4 @@ #include "fields/vector_expressions.h" #include "fields/vector_field.h" -#endif // __FDAPDE_FIELDS_MOUDLE_H__ +#endif // __FDAPDE_FIELDS_MODULE_H__ diff --git a/fdaPDE/finite_elements/basis/lagrangian_element.h b/fdaPDE/finite_elements/basis/lagrangian_element.h index 8376ae13..559d3615 100644 --- a/fdaPDE/finite_elements/basis/lagrangian_element.h +++ b/fdaPDE/finite_elements/basis/lagrangian_element.h @@ -27,7 +27,7 @@ namespace fdapde { namespace core { // A Lagrangian basis of degree R over an M-dimensional element -template class LagrangianElement { +template class LagrangianElement { private: std::array, ct_binomial_coefficient(M_ + R_, R_)> nodes_; // nodes of the Lagrangian basis std::array, ct_binomial_coefficient(M_ + R_, R_)> basis_; @@ -35,9 +35,9 @@ template class LagrangianElement { void compute_coefficients_(const std::array, ct_binomial_coefficient(M_ + R_, R_)>& nodes); public: // compile time informations - static constexpr unsigned int R = R_; // basis order - static constexpr unsigned int M = M_; // input space dimension - static constexpr unsigned int n_basis = ct_binomial_coefficient(M + R, R); + static constexpr int R = R_; // basis order + static constexpr int M = M_; // input space dimension + static constexpr int n_basis = ct_binomial_coefficient(M + R, R); typedef MultivariatePolynomial ElementType; typedef typename std::array, n_basis>::const_iterator const_iterator; @@ -59,11 +59,11 @@ template class LagrangianElement { // implementative details // compute coefficients via Vandermonde matrix -template +template void LagrangianElement::compute_coefficients_( const std::array, ct_binomial_coefficient(M_ + R_, R_)>& nodes) { // build vandermonde matrix - constexpr unsigned int n_basis = ct_binomial_coefficient(M_ + R_, R_); + constexpr int n_basis = ct_binomial_coefficient(M_ + R_, R_); constexpr std::array, n_basis> poly_table = MultivariatePolynomial::poly_table; // Vandermonde matrix construction diff --git a/fdaPDE/finite_elements/basis/multivariate_polynomial.h b/fdaPDE/finite_elements/basis/multivariate_polynomial.h index 70d7da65..20d8c5c2 100644 --- a/fdaPDE/finite_elements/basis/multivariate_polynomial.h +++ b/fdaPDE/finite_elements/basis/multivariate_polynomial.h @@ -47,10 +47,9 @@ namespace core { // 2 0 0 | 2 // // ct_poly_exp() computes the above table for any choice of N and R at compile time. -template -using PolyTable = std::array, ct_binomial_coefficient(R + N, R)>; +template using PolyTable = std::array, ct_binomial_coefficient(R + N, R)>; -template constexpr PolyTable ct_poly_exp() { +template constexpr PolyTable ct_poly_exp() { const int monomials = ct_binomial_coefficient(R + N, R); // number of monomials in polynomial p(x) // initialize empty array PolyTable coeff {}; @@ -98,10 +97,10 @@ template constexpr PolyTable ct_poly_exp( // PolyTable PolyGradTable // // ct_grad_exp() computes the PolyGradTable above from a PolyTable for any choice of N and R at compile time. -template +template using PolyGradTable = std::array, ct_binomial_coefficient(R + N, R)>, N>; -template constexpr PolyGradTable ct_grad_exp(const PolyTable poly_table) { +template constexpr PolyGradTable ct_grad_exp(const PolyTable poly_table) { const int monomials = ct_binomial_coefficient(R + N, R); // number of monomials in polynomial p(x) // initialize empty array PolyGradTable coeff {}; @@ -120,9 +119,9 @@ template constexpr PolyGradTable ct_grad_ } // recursive template based unfolding of monomial product x1^i1*x2^i2*...*xN^iN. -template // a row of the polynomial PolyTable (i.e. an array of coefficients [i1 i2 ... iN]) +template // a row of the polynomial PolyTable (i.e. an array of coefficients [i1 i2 ... iN]) struct MonomialProduct { static constexpr double unfold(const P& p, const V& v) { return v[N] == 0 ? MonomialProduct::unfold(p, v) : @@ -135,11 +134,11 @@ template struct MonomialProduct<0, P, V> { // base ca }; // unfold the sum of monomials at compile time to produce the complete polynomial expression -template // the whole polynomial PolyTable +template // the whole polynomial PolyTable struct MonomialSum { static constexpr double unfold(const std::array& c, const P& p, const V& v) { return (c[I] * MonomialProduct, std::array>::unfold(p, v[I])) + @@ -147,14 +146,14 @@ struct MonomialSum { } }; // end of recursion -template struct MonomialSum<0, N, M, P, V> { +template struct MonomialSum<0, N, M, P, V> { static constexpr double unfold(const std::array& c, const P& p, const V& v) { return c[0] * MonomialProduct, std::array>::unfold(p, v[0]); } }; // functor implementing the derivative of a multivariate N-dimensional polynomial of degree R along a given direction -template +template class PolynomialDerivative : public VectorExpr> { private: // compile time informations @@ -184,17 +183,17 @@ class PolynomialDerivative : public VectorExpr> }; // class representing a multivariate polynomial of degree R defined over a space of dimension N -template +template class MultivariatePolynomial : public ScalarExpr> { private: - static const constexpr unsigned MON = ct_binomial_coefficient(R + N, R); + static const constexpr int MON = ct_binomial_coefficient(R + N, R); std::array coeff_vector_; // vector of coefficients VectorField> gradient_; public: // compute this at compile time once, let public access static constexpr PolyTable poly_table = ct_poly_exp(); - static constexpr unsigned int order = R; // polynomial order - static constexpr unsigned int input_space_dimension = N; // input space dimension + static constexpr int order = R; // polynomial order + static constexpr int input_space_dimension = N; // input space dimension // constructor MultivariatePolynomial() = default; @@ -202,7 +201,7 @@ class MultivariatePolynomial : public ScalarExpr // prepare gradient vector std::array, N> gradient; // define i-th element of gradient field - for (size_t i = 0; i < N; ++i) { gradient[i] = PolynomialDerivative(coeff_vector, i); } + for (std::size_t i = 0; i < N; ++i) { gradient[i] = PolynomialDerivative(coeff_vector, i); } gradient_ = VectorField>(gradient); }; // evaluate polynomial at point diff --git a/fdaPDE/linear_algebra.h b/fdaPDE/linear_algebra.h index de0f32b9..f45c5a90 100644 --- a/fdaPDE/linear_algebra.h +++ b/fdaPDE/linear_algebra.h @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_LINEAR_ALGEBRA_MOUDLE_H__ -#define __FDAPDE_LINEAR_ALGEBRA_MOUDLE_H__ +#ifndef __FDAPDE_LINEAR_ALGEBRA_MODULE_H__ +#define __FDAPDE_LINEAR_ALGEBRA_MODULE_H__ #include "linear_algebra/kronecker_product.h" #include "linear_algebra/smw.h" #include "linear_algebra/sparse_block_matrix.h" #include "linear_algebra/vector_space.h" -#endif // __FDAPDE_LINEAR_ALGEBRA_MOUDLE_H__ +#endif // __FDAPDE_LINEAR_ALGEBRA_MODULE_H__ diff --git a/fdaPDE/linear_algebra/vector_space.h b/fdaPDE/linear_algebra/vector_space.h index 2bfa21c5..95541fa3 100644 --- a/fdaPDE/linear_algebra/vector_space.h +++ b/fdaPDE/linear_algebra/vector_space.h @@ -27,7 +27,7 @@ namespace core { // a template class to perform geometric operations in general vector and affine spaces. // M is the vector space dimension, N is the dimension of the embedding space -template class VectorSpace { +template class VectorSpace { private: std::array, M> basis_ {}; // the set of vectors generating the vector space SVector offset_ {}; // a point throught which the vector space passes. (offset_ \neq 0 \implies affine space) @@ -51,12 +51,12 @@ template class VectorSpace { // implementation details -template +template SVector VectorSpace::orthogonal_project(const SVector& u, const SVector& v) const { return ((v.dot(u) / u.squaredNorm()) * (u.array())).matrix(); } -template void VectorSpace::orthonormalize() { +template void VectorSpace::orthonormalize() { std::array, M> orthonormal_basis; orthonormal_basis[0] = basis_[0] / basis_[0].norm(); // implementation of the modified Gram-Schmidt method, see theory for details @@ -70,7 +70,7 @@ template void VectorSpace::orthonormalize } // projects the point x onto the space. -template SVector VectorSpace::project_onto(const SVector& x) { +template SVector VectorSpace::project_onto(const SVector& x) { if constexpr (M == N) { // you are projecting over the same space! return x; } else { @@ -82,7 +82,7 @@ template SVector VectorSpace::project_ } // project the point x into the space -template SVector VectorSpace::project_into(const SVector& x) { +template SVector VectorSpace::project_into(const SVector& x) { // build the projection operator on the space spanned by the basis Eigen::Matrix A; A.resize(N, basis_.size()); @@ -93,12 +93,12 @@ template SVector VectorSpace::project_ } // euclidean distance from x -template double VectorSpace::distance(const SVector& x) { +template double VectorSpace::distance(const SVector& x) { return (x - project_into(x)).squaredNorm(); } // develops the linear combination of basis vectors with respect to the given vector of coefficients. -template +template SVector VectorSpace::operator()(const std::array& coeffs) const { SVector result = offset_; for (std::size_t i = 0; i < M; ++i) result += coeffs[i] * basis_[i]; diff --git a/fdaPDE/mesh.h b/fdaPDE/mesh.h index 4e930a1d..682acae4 100644 --- a/fdaPDE/mesh.h +++ b/fdaPDE/mesh.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_MESH_MOUDLE_H__ -#define __FDAPDE_MESH_MOUDLE_H__ +#ifndef __FDAPDE_MESH_MODULE_H__ +#define __FDAPDE_MESH_MODULE_H__ #include "mesh/mesh.h" #include "mesh/element.h" @@ -25,4 +25,4 @@ #include "mesh/point_location/barycentric_walk.h" #include "mesh/point_location/adt.h" -#endif // __FDAPDE_MESH_MOUDLE_H__ +#endif // __FDAPDE_MESH_MODULE_H__ diff --git a/fdaPDE/mesh/element.h b/fdaPDE/mesh/element.h index 08636762..9353f497 100644 --- a/fdaPDE/mesh/element.h +++ b/fdaPDE/mesh/element.h @@ -29,24 +29,24 @@ namespace fdapde { namespace core { // M local dimension, N embedding dimension, R order of the element (defaulted to linear finite elements) -template class Element; // forward declaration +template class Element; // forward declaration // using declarations for manifold specialization -template using SurfaceElement = Element<2, 3, R>; -template using NetworkElement = Element<1, 2, R>; +template using SurfaceElement = Element<2, 3, R>; +template using NetworkElement = Element<1, 2, R>; // number of degrees of freedom associated to an M-dimensional element of degree R -constexpr unsigned int ct_nnodes(const unsigned int M, const unsigned int R) { +constexpr int ct_nnodes(const int M, const int R) { return ct_factorial(M + R) / (ct_factorial(M) * ct_factorial(R)); } // number of vertices of an M-dimensional element -constexpr unsigned int ct_nvertices(const unsigned int M) { return M + 1; } +constexpr int ct_nvertices(const int M) { return M + 1; } // number of edges of an M-dimensional element -constexpr unsigned int ct_nedges(const unsigned int M) { return (M * (M + 1)) / 2; } +constexpr int ct_nedges(const int M) { return (M * (M + 1)) / 2; } // A single mesh element. This object represents the main **geometrical** abstraction of a physical element. // No functional information is carried by instances of this object. -template class Element { +template class Element { private: std::size_t ID_; // ID of this element std::array node_ids_ {}; // ID of nodes composing the element @@ -60,11 +60,11 @@ template class Element { SMatrix J_; // [J_]_ij = (coords_[j][i] - coords_[0][i]) SMatrix inv_J_; // J^{-1} (Penrose pseudo-inverse for manifold elements) public: - static constexpr unsigned int nodes = ct_nnodes(M, R); - static constexpr unsigned int vertices = ct_nvertices(M); - static constexpr unsigned int local_dimension = M; - static constexpr unsigned int embedding_dimension = N; - static constexpr unsigned int order = R; + static constexpr int nodes = ct_nnodes(M, R); + static constexpr int vertices = ct_nvertices(M); + static constexpr int local_dimension = M; + static constexpr int embedding_dimension = N; + static constexpr int order = R; // constructor Element() = default; @@ -74,7 +74,7 @@ template class Element { // getters const std::array, ct_nvertices(M)> coords() const { return coords_; } const std::vector neighbors() const { return neighbors_; } - const unsigned int ID() const { return ID_; } + const int ID() const { return ID_; } Eigen::Matrix barycentric_matrix() const { return J_; } Eigen::Matrix inv_barycentric_matrix() const { return inv_J_; } std::array node_ids() const { return node_ids_; } @@ -99,7 +99,7 @@ template class Element { // implementation details -template +template Element::Element( std::size_t ID, const std::array& node_ids, const std::array, ct_nvertices(M)>& coords, const std::vector& neighbors, bool boundary) : @@ -127,7 +127,7 @@ Element::Element( } } -template +template SVector Element::to_barycentric_coords(const SVector& x) const { // solve: barycenitrc_matrix_*z = (x-ref) SVector z = inv_J_ * (x - coords_[0]); @@ -137,7 +137,7 @@ SVector Element::to_barycentric_coords(const SVector& x) cons return result; } -template SVector Element::mid_point() const { +template SVector Element::mid_point() const { // The center of gravity of an element has all its barycentric coordinates equal to 1/(M+1). // The midpoint of an element can be computed by mapping it to a cartesian reference system SVector barycentric_mid_point; @@ -145,7 +145,7 @@ template SVector Element +template std::pair, SVector> Element::bounding_box() const { // define lower-left and upper-right corner of bounding box SVector ll, ur; @@ -164,14 +164,14 @@ std::pair, SVector> Element::bounding_box() const { } // check if a point is contained in the element -template +template template typename std::enable_if::type Element::contains(const SVector& x) const { // A point is inside the element if all its barycentric coordinates are positive return (to_barycentric_coords(x).array() >= -10 * std::numeric_limits::epsilon()).all(); } -template VectorSpace Element::spanned_space() const { +template VectorSpace Element::spanned_space() const { // build a basis for the space containing the element std::array, M> basis; for (size_t i = 0; i < M; ++i) { basis[i] = (coords_[i + 1] - coords_[0]); } @@ -179,7 +179,7 @@ template VectorSpace Elem } // specialization for manifold elements of contains() routine. -template +template template typename std::enable_if::type Element::contains(const SVector& x) const { // check if the point is contained in the affine space spanned by the element diff --git a/fdaPDE/mesh/mesh.h b/fdaPDE/mesh/mesh.h index 69fabe5c..f0305f46 100644 --- a/fdaPDE/mesh/mesh.h +++ b/fdaPDE/mesh/mesh.h @@ -33,30 +33,30 @@ namespace fdapde { namespace core { // trait to detect if the mesh is a manifold -template struct is_manifold { +template struct is_manifold { static constexpr bool value = (M != N); }; // trait to detect if the mesh is a linear network -template struct is_linear_network { +template struct is_linear_network { static constexpr bool value = std::conditional<(M == 1 && N == 2), std::true_type, std::false_type>::type::value; }; // trait to select a proper neighboring storage structure depending on the type of mesh. In case of linear networks this // information is stored as a sparse matrix where entry (i,j) is set to 1 if and only if elements i and j are neighbors -template struct neighboring_structure { +template struct neighboring_structure { using type = typename std::conditional::value, SpMatrix, DMatrix>::type; }; // access to domain's triangulation, M: tangent space dimension, N: embedding space dimension, R: FEM mesh order -template class Mesh { +template class Mesh { private: // coordinates of points costituting the vertices of mesh elements DMatrix points_ {}; - unsigned int num_nodes_ = 0; + int num_nodes_ = 0; // identifiers of points (as row indexes in points_ matrix) composing each element, by row Eigen::Matrix elements_ {}; - unsigned int num_elements_ = 0; + int num_elements_ = 0; // vector of binary coefficients such that, boundary_[j] = 1 \iff node j is on boundary DMatrix boundary_ {}; std::size_t dof_; // degrees of freedom, i.e. the maximmum ID in the dof_table @@ -79,12 +79,12 @@ template class Mesh { const typename neighboring_structure::type& neighbors, const DMatrix& boundary); // getters - const Element& element(unsigned int ID) const { return cache_[ID]; } - Element& element(unsigned int ID) { return cache_[ID]; } - SVector node(unsigned int ID) const { return points_.row(ID); } + const Element& element(int ID) const { return cache_[ID]; } + Element& element(int ID) { return cache_[ID]; } + SVector node(int ID) const { return points_.row(ID); } bool is_on_boundary(size_t j) const { return boundary_(j) == 1; } - unsigned int elements() const { return num_elements_; } - unsigned int nodes() const { return num_nodes_; } + int elements() const { return num_elements_; } + int nodes() const { return num_nodes_; } std::array, N> range() const { return range_; } // support for the definition of a finite element basis @@ -154,17 +154,17 @@ template class Mesh { }; // alias exports -template using Mesh2D = Mesh<2, 2, R>; -template using Mesh3D = Mesh<3, 3, R>; +template using Mesh2D = Mesh<2, 2, R>; +template using Mesh3D = Mesh<3, 3, R>; // manifold cases -template using SurfaceMesh = Mesh<2, 3, R>; -template using NetworkMesh = Mesh<1, 2, R>; +template using SurfaceMesh = Mesh<2, 3, R>; +template using NetworkMesh = Mesh<1, 2, R>; // implementative details // builds a node enumeration for the support of a basis of order R. This fills both the elements_ table // and recompute the boundary informations. (support only for order 2 basis) -template +template void Mesh::dof_enumerate(const DMatrix& boundary) { // algorithm initialization int next = num_nodes_; // next valid ID to assign @@ -213,7 +213,7 @@ void Mesh::dof_enumerate(const DMatrix& boundary) { } // construct directly from raw eigen matrix (used from wrappers) -template +template Mesh::Mesh( const DMatrix& points, const DMatrix& elements, const typename neighboring_structure::type& neighbors, const DMatrix& boundary) : @@ -251,7 +251,7 @@ Mesh::Mesh( } // construct a mesh from .csv files -template +template Mesh::Mesh( const std::string& points, const std::string& elements, const std::string& neighbors, const std::string& boundary) { // open and parse CSV files @@ -305,7 +305,7 @@ Mesh::Mesh( } // fill the cache_ data structure with pointers to element objects -template void Mesh::fill_cache() { +template void Mesh::fill_cache() { // reserve space for cache cache_.reserve(num_elements_); @@ -351,7 +351,7 @@ template void Mesh::fi } // produce the matrix of dof coordinates -template DMatrix Mesh::dof_coords() const { +template DMatrix Mesh::dof_coords() const { if constexpr (R == 1) return points_; // for order 1 meshes dofs coincide with vertices else { diff --git a/fdaPDE/mesh/point_location/barycentric_walk.h b/fdaPDE/mesh/point_location/barycentric_walk.h index 956ec224..cb0730c4 100644 --- a/fdaPDE/mesh/point_location/barycentric_walk.h +++ b/fdaPDE/mesh/point_location/barycentric_walk.h @@ -26,7 +26,7 @@ namespace fdapde { namespace core { // barycentric walk strategy for point location problem, works only for 2D and 3D *convex* triangualtions -template class BarycentricWalk : public PointLocator { +template class BarycentricWalk : public PointLocator { static_assert(M == N, "barycentric walk cannot be applied to manifold domains"); private: const Mesh& mesh_; diff --git a/fdaPDE/mesh/point_location/naive_search.h b/fdaPDE/mesh/point_location/naive_search.h index 03dcffc8..0ecee181 100644 --- a/fdaPDE/mesh/point_location/naive_search.h +++ b/fdaPDE/mesh/point_location/naive_search.h @@ -27,7 +27,7 @@ namespace fdapde { namespace core { // naive search strategy for point location problem -template class NaiveSearch : public PointLocator { +template class NaiveSearch : public PointLocator { private: const Mesh& mesh_; public: diff --git a/fdaPDE/mesh/point_location/point_locator.h b/fdaPDE/mesh/point_location/point_locator.h index 0d6fbdb8..4894ff89 100644 --- a/fdaPDE/mesh/point_location/point_locator.h +++ b/fdaPDE/mesh/point_location/point_locator.h @@ -27,7 +27,7 @@ namespace fdapde { namespace core { // interface for point locations algorithms -template struct PointLocator { +template struct PointLocator { // solves the point location problem. returns nullptr if p is not found virtual const Element* locate(const SVector& p) const = 0; diff --git a/fdaPDE/mesh/reference_element.h b/fdaPDE/mesh/reference_element.h index 7f83d00f..64b2171c 100644 --- a/fdaPDE/mesh/reference_element.h +++ b/fdaPDE/mesh/reference_element.h @@ -25,8 +25,8 @@ namespace fdapde { namespace core { // Definition of the M-dimensional unit reference simplices of order R. -template struct ReferenceElement; -template using point_list = std::array, R>; +template struct ReferenceElement; +template using point_list = std::array, R>; template <> // 1D first order basis struct ReferenceElement<1, 1> { diff --git a/fdaPDE/optimization.h b/fdaPDE/optimization.h index 5567a3f4..ae53eb12 100644 --- a/fdaPDE/optimization.h +++ b/fdaPDE/optimization.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_OPTIMIZATION_MOUDLE_H__ -#define __FDAPDE_OPTIMIZATION_MOUDLE_H__ +#ifndef __FDAPDE_OPTIMIZATION_MODULE_H__ +#define __FDAPDE_OPTIMIZATION_MODULE_H__ #include "optimization/grid.h" #include "optimization/newton.h" @@ -25,4 +25,4 @@ #include "optimization/callbacks/backtracking_line_search.h" #include "optimization/callbacks/wolfe_line_search.h" -#endif // __FDAPDE_OPTIMIZATION_MOUDLE_H__ +#endif // __FDAPDE_OPTIMIZATION_MODULE_H__ diff --git a/fdaPDE/optimization/gradient_descent.h b/fdaPDE/optimization/gradient_descent.h index 7a186cb3..9387f848 100644 --- a/fdaPDE/optimization/gradient_descent.h +++ b/fdaPDE/optimization/gradient_descent.h @@ -25,7 +25,7 @@ namespace fdapde { namespace core { // implementation of the gradient descent method for unconstrained nonlinear optimization -template class GradientDescent { +template class GradientDescent { private: std::size_t max_iter_; // maximum number of iterations before forced stop double tol_; // tolerance on error before forced stop diff --git a/fdaPDE/optimization/newton.h b/fdaPDE/optimization/newton.h index 3676ef29..52cda5ac 100644 --- a/fdaPDE/optimization/newton.h +++ b/fdaPDE/optimization/newton.h @@ -25,7 +25,7 @@ namespace fdapde { namespace core { // implementation of the newton method for unconstrained nonlinear optimization -template class Newton { +template class Newton { private: std::size_t max_iter_; // maximum number of iterations before forced stop double tol_; // tolerance on error before forced stop diff --git a/fdaPDE/pde/pde.h b/fdaPDE/pde/pde.h index 61a99046..dcf1febf 100644 --- a/fdaPDE/pde/pde.h +++ b/fdaPDE/pde/pde.h @@ -53,9 +53,9 @@ template , OperatorType>::value, "E is not a valid differential operator"); diff --git a/fdaPDE/splines/basis/spline.h b/fdaPDE/splines/basis/spline.h index 258da851..6d52ef4d 100644 --- a/fdaPDE/splines/basis/spline.h +++ b/fdaPDE/splines/basis/spline.h @@ -32,7 +32,7 @@ namespace core { // A spline of order R centered in knot u_i. // Template parameter M is used to keep track of the order of the spline while developing the Cox-DeBoor recursion. -template class Spline : public ScalarExpr<1, Spline> { +template class Spline : public ScalarExpr<1, Spline> { private: DVector knots_; std::size_t i_; // knot index where this basis is centered @@ -57,7 +57,7 @@ template class Spline : public ScalarExpr<1 // compute derivative of order K as a ScalarExpr // d^K/dx^K N_ij(x) = j/(u_i+j - u_i)*[d^{K-1}/dx^{K-1} N_i,j-1(x)] - j/(u_i+j+1 - u_i+1)* // [d^{K-1}/dx^{K-1} N_i+1,j-1(x)] - template auto derive() const { + template auto derive() const { if constexpr (K == 1) // end of recursion return (R * a_) * Spline(knots_, i_) - (R * b_) * Spline(knots_, i_ + 1); else // exploit Cox-DeBoor recursive formula @@ -67,7 +67,7 @@ template class Spline : public ScalarExpr<1 }; // partial template specialization for order 0 splines (end of recursion) -template class Spline<0, M> : public ScalarExpr<1, Spline<0>> { +template class Spline<0, M> : public ScalarExpr<1, Spline<0>> { private: DVector knots_; std::size_t i_; // knot index where this basis is centered diff --git a/fdaPDE/splines/basis/spline_basis.h b/fdaPDE/splines/basis/spline_basis.h index f4ef8f33..28d5af3b 100644 --- a/fdaPDE/splines/basis/spline_basis.h +++ b/fdaPDE/splines/basis/spline_basis.h @@ -24,7 +24,7 @@ namespace fdapde { namespace core { // a spline basis of order R built over a given set of knots -template class SplineBasis { +template class SplineBasis { private: DVector knots_ {}; // vector of knots std::vector> basis_ {}; diff --git a/fdaPDE/splines/spline_assembler.h b/fdaPDE/splines/spline_assembler.h index a89aa7e4..0090e3e7 100644 --- a/fdaPDE/splines/spline_assembler.h +++ b/fdaPDE/splines/spline_assembler.h @@ -45,7 +45,7 @@ template class Assembler { template template SpMatrix Assembler::discretize_operator(const E& op) { - constexpr std::size_t R = B::order; + constexpr int R = B::order; std::size_t M = basis_.size(); std::vector> triplet_list; SpMatrix discretization_matrix; diff --git a/fdaPDE/utils.h b/fdaPDE/utils.h index c3e726a9..7e20d6d1 100644 --- a/fdaPDE/utils.h +++ b/fdaPDE/utils.h @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __FDAPDE_UTILS_MOUDLE_H__ -#define __FDAPDE_UTILS_MOUDLE_H__ +#ifndef __FDAPDE_UTILS_MODULE_H__ +#define __FDAPDE_UTILS_MODULE_H__ #include "utils/assert.h" #include "utils/compile_time.h" @@ -27,4 +27,4 @@ #include "utils/integration/integrator.h" #include "utils/integration/integrator_tables.h" -#endif // __FDAPDE_UTILS_MOUDLE_H__ +#endif // __FDAPDE_UTILS_MODULE_H__ diff --git a/fdaPDE/utils/compile_time.h b/fdaPDE/utils/compile_time.h index 797f5dd6..6dd36d7d 100644 --- a/fdaPDE/utils/compile_time.h +++ b/fdaPDE/utils/compile_time.h @@ -23,15 +23,15 @@ namespace fdapde { namespace core { // compile time evaluation of the factorial function -constexpr std::size_t ct_factorial(const std::size_t n) { return n ? (n * ct_factorial(n - 1)) : 1; } +constexpr int ct_factorial(const int n) { return n ? (n * ct_factorial(n - 1)) : 1; } // compile time evaluation of binomial coefficient -constexpr std::size_t ct_binomial_coefficient(const std::size_t N, const std::size_t M) { +constexpr int ct_binomial_coefficient(const int N, const int M) { return ct_factorial(N) / (ct_factorial(M) * ct_factorial(N - M)); } // compile time computation of the sum of elements in array -template +template constexpr typename std::enable_if::value, T>::type ct_array_sum(std::array A) { T result = 0; for (int j = 0; j < N; ++j) result += A[j]; diff --git a/fdaPDE/utils/integration/integrator.h b/fdaPDE/utils/integration/integrator.h index 90bac37e..3f9b0396 100644 --- a/fdaPDE/utils/integration/integrator.h +++ b/fdaPDE/utils/integration/integrator.h @@ -29,32 +29,32 @@ namespace core { // A set of utilities to perform numerical integration // M: dimension of the domain of integration, R finite element order, K number of quadrature nodes -template ::K> class Integrator { +template ::K> class Integrator { private: IntegratorTable integration_table_; public: Integrator() : integration_table_(IntegratorTable()) {}; // integrate a callable F over a mesh element e - template double integrate(const Element& e, const F& f) const; + template double integrate(const Element& e, const F& f) const; // integrate a callable F over a triangualtion m - template double integrate(const Mesh& m, const F& f) const; + template double integrate(const Mesh& m, const F& f) const; // computes \int_e [f * \phi] where \phi is a basis function over the *reference element*. - template + template double integrate(const Element& e, const F& f, const B& phi) const; // integrate the weak form of operator L to produce its (i,j)-th discretization matrix element - template double integrate(const Element& e, F& f) const; + template double integrate(const Element& e, F& f) const; // getters - template DMatrix quadrature_nodes(const Mesh& m) const; + template DMatrix quadrature_nodes(const Mesh& m) const; std::size_t num_nodes() const { return integration_table_.num_nodes; } }; // implementative details // integration of bilinear form -template -template +template +template double Integrator::integrate(const Element& e, F& f) const { // apply quadrature rule double value = 0; @@ -73,8 +73,8 @@ double Integrator::integrate(const Element& e, F& f) const { // perform integration of \int_e [f * \phi] using a basis system defined over the reference element and the change of // variables formula: \int_e [f(x) * \phi(x)] = \int_{E} [f(J(X)) * \Phi(X)] |detJ| // where J is the affine mapping from the reference element E to the physical element e -template -template +template +template double Integrator::integrate(const Element& e, const F& f, const B& Phi) const { double value = 0; for (size_t iq = 0; iq < integration_table_.num_nodes; ++iq) { @@ -94,8 +94,8 @@ double Integrator::integrate(const Element& e, const F& f, con } // integrate a callable F over a mesh element e. Do not require any particular structure for F -template -template +template +template double Integrator::integrate(const Element& e, const F& f) const { double value = 0; for (size_t iq = 0; iq < integration_table_.num_nodes; ++iq) { @@ -115,8 +115,8 @@ double Integrator::integrate(const Element& e, const F& f) con } // integrate a callable F over the entire mesh m. -template -template +template +template double Integrator::integrate(const Mesh& m, const F& f) const { double value = 0; // cycle over all mesh elements @@ -125,8 +125,8 @@ double Integrator::integrate(const Mesh& m, const F& f) const } // returns all quadrature points on the mesh -template -template +template +template DMatrix Integrator::quadrature_nodes(const Mesh& m) const { DMatrix quadrature_nodes; quadrature_nodes.resize(m.elements() * integration_table_.num_nodes, N); diff --git a/fdaPDE/utils/integration/integrator_tables.h b/fdaPDE/utils/integration/integrator_tables.h index fe5f75f0..67528a3f 100644 --- a/fdaPDE/utils/integration/integrator_tables.h +++ b/fdaPDE/utils/integration/integrator_tables.h @@ -13,15 +13,15 @@ namespace core { // ** "https://people.sc.fsu.edu/~jburkardt/datasets/datasets.html" // N: dimension of the integration domain, K: number of nodes of the formula. Args: type of quadrature formula -template struct IntegratorTable; +template struct IntegratorTable; // identification tags for quadrature rules struct NewtonCotes { }; struct GaussLegendre { }; // trait for selecting a standard quadrature rule for finite elements, in case K is not supplied -template +template struct standard_fem_quadrature_rule { - static constexpr unsigned int quadrature(const unsigned int dim, const unsigned int order) { + static constexpr int quadrature(const int dim, const int order) { switch (dim) { case 1: // 1D elements switch (order) { @@ -53,7 +53,7 @@ struct standard_fem_quadrature_rule { } return 0; // error } - static constexpr unsigned int K = quadrature(N, R); + static constexpr int K = quadrature(N, R); }; // 1D linear elements (gaussian integration) diff --git a/fdaPDE/utils/symbols.h b/fdaPDE/utils/symbols.h index adc9db49..f1a5d008 100644 --- a/fdaPDE/utils/symbols.h +++ b/fdaPDE/utils/symbols.h @@ -22,8 +22,8 @@ #include // static structures, allocated on stack at compile time. -template using SVector = Eigen::Matrix; -template using SMatrix = Eigen::Matrix; +template using SVector = Eigen::Matrix; +template using SMatrix = Eigen::Matrix; // dynamic size, head-appocated, structures. template using DMatrix = Eigen::Matrix; @@ -72,7 +72,7 @@ struct matrix_hash { }; // oredering relation for SVector, allows SVector to be keys of std::map -template struct s_vector_compare { +template struct s_vector_compare { bool operator()(const SVector& lhs, const SVector& rhs) const { return std::lexicographical_compare(lhs.data(), lhs.data() + lhs.size(), rhs.data(), rhs.data() + rhs.size()); };