Lagrange
Loading...
Searching...
No Matches
DifferentialOperators.h
1/*
2 * Copyright 2025 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/SurfaceMesh.h>
15
16#include <Eigen/Core>
17#include <Eigen/Sparse>
18
19namespace lagrange::polyddg {
20
23
36template <typename Scalar, typename Index>
38{
39public:
40 using Vector = Eigen::Matrix<Scalar, 1, 3>;
41
42public:
49
50public:
59 Eigen::SparseMatrix<Scalar> gradient() const;
60
69 Eigen::SparseMatrix<Scalar> d0() const;
70
79 Eigen::SparseMatrix<Scalar> d1() const;
80
89 Eigen::SparseMatrix<Scalar> star0() const;
90
99 Eigen::SparseMatrix<Scalar> star1() const;
100
109 Eigen::SparseMatrix<Scalar> star2() const;
110
121 Eigen::SparseMatrix<Scalar> flat() const;
122
131 Eigen::SparseMatrix<Scalar> sharp() const;
132
141 Eigen::SparseMatrix<Scalar> projection() const;
142
151 Eigen::SparseMatrix<Scalar> inner_product_0_form() const;
152
163 Eigen::SparseMatrix<Scalar> inner_product_1_form(Scalar lambda = 1) const;
164
173 Eigen::SparseMatrix<Scalar> inner_product_2_form() const;
174
185 Eigen::SparseMatrix<Scalar> divergence(Scalar lambda = 1) const;
186
195 Eigen::SparseMatrix<Scalar> curl() const;
196
207 Eigen::SparseMatrix<Scalar> laplacian(Scalar lambda = 1) const;
208
217 Eigen::SparseMatrix<Scalar> vertex_tangent_coordinates() const;
218
227 Eigen::SparseMatrix<Scalar> facet_tangent_coordinates() const;
228
238 Eigen::SparseMatrix<Scalar> levi_civita() const;
239
254 Eigen::SparseMatrix<Scalar> levi_civita_nrosy(Index n) const;
255
267 Eigen::SparseMatrix<Scalar> covariant_derivative() const;
268
285 Eigen::SparseMatrix<Scalar> covariant_derivative_nrosy(Index n) const;
286
298 Eigen::SparseMatrix<Scalar> connection_laplacian(Scalar lambda = 1) const;
299
315 Eigen::SparseMatrix<Scalar> connection_laplacian_nrosy(Index n, Scalar lambda = 1) const;
316
317public:
328 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> gradient(Index fid) const;
329
341 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> d0(Index fid) const;
342
354 Eigen::Matrix<Scalar, 1, Eigen::Dynamic> d1(Index fid) const;
355
367 Eigen::Matrix<Scalar, Eigen::Dynamic, 3> flat(Index fid) const;
368
380 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> sharp(Index fid) const;
381
393 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> projection(Index fid) const;
394
406 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> inner_product_0_form(Index fid) const;
407
420 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> inner_product_1_form(
421 Index fid,
422 Scalar lambda = 1) const;
423
434 Eigen::Matrix<Scalar, 1, 1> inner_product_2_form(Index fid) const;
435
448 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> laplacian(Index fid, Scalar lambda = 1)
449 const;
450
460 Eigen::Matrix<Scalar, 2, 2> levi_civita(Index fid, Index lv) const;
461
475 Eigen::Matrix<Scalar, 2, 2> levi_civita_nrosy(Index fid, Index lv, Index n) const;
476
488 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> levi_civita(Index fid) const;
489
505 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> levi_civita_nrosy(Index fid, Index n)
506 const;
507
519 Eigen::Matrix<Scalar, 4, Eigen::Dynamic> covariant_derivative(Index fid) const;
520
536 Eigen::Matrix<Scalar, 4, Eigen::Dynamic> covariant_derivative_nrosy(Index fid, Index n) const;
537
549 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> covariant_projection(Index fid) const;
550
566 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> covariant_projection_nrosy(
567 Index fid,
568 Index n) const;
569
583 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> connection_laplacian(
584 Index fid,
585 Scalar lambda = 1) const;
586
604 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>
605 connection_laplacian_nrosy(Index fid, Index n, Scalar lambda = 1) const;
606
607private:
611 void compute_vertex_normal_from_vector_area();
612
613public:
621 Eigen::Matrix<Scalar, 3, 2> facet_basis(Index fid) const;
622
630 Eigen::Matrix<Scalar, 3, 2> vertex_basis(Index vid) const;
631
632public:
638 AttributeId get_vector_area_attribute_id() const { return m_vector_area_id; }
639
645 AttributeId get_centroid_attribute_id() const { return m_centroid_id; }
646
652 AttributeId get_vertex_normal_attribute_id() const { return m_vertex_normal_id; }
653
654private:
656 AttributeId m_vector_area_id = invalid_attribute_id();
657 AttributeId m_centroid_id = invalid_attribute_id();
658 AttributeId m_vertex_normal_id = invalid_attribute_id();
659};
660
662
663} // namespace lagrange::polyddg
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:66
Eigen::Matrix< Scalar, 3, 2 > vertex_basis(Index vid) const
Compute the local tangent basis for a single vertex.
Definition DifferentialOperators.cpp:1200
Eigen::SparseMatrix< Scalar > divergence(Scalar lambda=1) const
Compute the discrete divergence operator.
Definition DifferentialOperators.cpp:492
Eigen::SparseMatrix< Scalar > levi_civita_nrosy(Index n) const
Compute the discrete Levi-Civita connection for n-rosy fields.
Definition DifferentialOperators.cpp:625
Eigen::SparseMatrix< Scalar > projection() const
Compute the projection operator.
Definition DifferentialOperators.cpp:385
Eigen::SparseMatrix< Scalar > d1() const
Compute the discrete d1 operator.
Definition DifferentialOperators.cpp:197
DifferentialOperators(SurfaceMesh< Scalar, Index > &mesh)
Precomputes necessary attributes for the differential operators.
Definition DifferentialOperators.cpp:105
AttributeId get_vector_area_attribute_id() const
Get the attribute ID for the per-facet vector area.
Definition DifferentialOperators.h:638
Eigen::SparseMatrix< Scalar > covariant_derivative_nrosy(Index n) const
Compute the discrete covariant derivative operator for n-rosy fields.
Definition DifferentialOperators.cpp:674
Eigen::SparseMatrix< Scalar > connection_laplacian_nrosy(Index n, Scalar lambda=1) const
Compute the connection Laplacian operator for n-rosy fields.
Definition DifferentialOperators.cpp:740
Eigen::Matrix< Scalar, 3, 2 > facet_basis(Index fid) const
Compute the local tangent basis for a single facet.
Definition DifferentialOperators.cpp:1166
Eigen::SparseMatrix< Scalar > d0() const
Compute the discrete d0 operator.
Definition DifferentialOperators.cpp:172
Eigen::SparseMatrix< Scalar > sharp() const
Compute the discrete sharp operator.
Definition DifferentialOperators.cpp:337
Eigen::SparseMatrix< Scalar > vertex_tangent_coordinates() const
Compute the coordinate transformation that maps a per-vertex tangent vector field expressed in the gl...
Definition DifferentialOperators.cpp:540
Eigen::SparseMatrix< Scalar > star1() const
Compute the discrete Hodge star operator for 1-form.
Definition DifferentialOperators.cpp:237
Eigen::SparseMatrix< Scalar > inner_product_1_form(Scalar lambda=1) const
Compute the discrete inner product operator for 1-forms.
Definition DifferentialOperators.cpp:430
Eigen::SparseMatrix< Scalar > star2() const
Compute the discrete Hodge star operator for 2-form.
Definition DifferentialOperators.cpp:281
Eigen::SparseMatrix< Scalar > flat() const
Compute the discrete flat operator.
Definition DifferentialOperators.cpp:289
Eigen::SparseMatrix< Scalar > laplacian(Scalar lambda=1) const
Compute the discrete Laplacian operator.
Definition DifferentialOperators.cpp:531
Eigen::SparseMatrix< Scalar > connection_laplacian(Scalar lambda=1) const
Compute the connection Laplacian operator.
Definition DifferentialOperators.cpp:732
Eigen::SparseMatrix< Scalar > curl() const
Compute the discrete curl operator.
Definition DifferentialOperators.cpp:501
Eigen::SparseMatrix< Scalar > levi_civita() const
Compute the discrete Levi-Civita connection.
Definition DifferentialOperators.cpp:618
Eigen::SparseMatrix< Scalar > inner_product_0_form() const
Compute the discrete inner product operator for 0-forms.
Definition DifferentialOperators.cpp:398
Eigen::SparseMatrix< Scalar > covariant_derivative() const
Compute the discrete covariant derivative operator.
Definition DifferentialOperators.cpp:667
Eigen::SparseMatrix< Scalar > inner_product_2_form() const
Compute the discrete inner product operator for 2-forms.
Definition DifferentialOperators.cpp:470
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > covariant_projection(Index fid) const
Compute the discrete covariant projection operator for a single facet.
Definition DifferentialOperators.cpp:1091
Eigen::SparseMatrix< Scalar > gradient() const
Compute the discrete polygonal gradient operator.
Definition DifferentialOperators.cpp:122
Eigen::SparseMatrix< Scalar > facet_tangent_coordinates() const
Compute the coordinate transformation that maps a per-facet tangent vector field expressed in the glo...
Definition DifferentialOperators.cpp:579
AttributeId get_vertex_normal_attribute_id() const
Get the attribute ID for the per-vertex normal.
Definition DifferentialOperators.h:652
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > covariant_projection_nrosy(Index fid, Index n) const
Compute the discrete covariant projection operator for a single facet for n-rosy fields.
Definition DifferentialOperators.cpp:1099
Eigen::SparseMatrix< Scalar > star0() const
Compute the discrete Hodge star operator for 0-form.
Definition DifferentialOperators.cpp:230
AttributeId get_centroid_attribute_id() const
Get the attribute ID for the per-facet centroid.
Definition DifferentialOperators.h:645
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
constexpr AttributeId invalid_attribute_id()
Invalid attribute id.
Definition AttributeFwd.h:76
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56