-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operator refactor #42
Conversation
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
==========================================
- Coverage 89% 88.23% -0.78%
==========================================
Files 16 19 +3
Lines 1110 1113 +3
==========================================
- Hits 988 982 -6
- Misses 122 131 +9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I am pretty happy with the approach. I am failing to remember why the original DealIIOperator
did not inherit from Operator
concept. Inheriting certainly simplifies things.
The only serious issue I have is that the Operator
concept should be split to the original Operator
and MatrixOperator
concept, and make DealIIMatrixOperator
and TrilinosMatrixOperator
inherit from later, while SmootherOperator
and DirectOperator
inherit from former.
include/mfmg/concepts.hpp
Outdated
virtual size_t m() const = 0; | ||
virtual size_t n() const = 0; | ||
virtual void apply(vector_type const &x, vector_type &y) const = 0; | ||
virtual std::shared_ptr<operator_type> transpose() const = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concept of operator should really only have the meaning of how to produce right hand side by operating on left hand side. Its interface should clearly indicate that. Thus, I believe that member functions like transpose()
and multiply()
do not belong in it, as they somewhat restrict the concept to operators corresponding to matrices. It also becomes a rabbit hole if we start creating operators with more required functions and putting them in Operator
. Therefore, I'd like to retain the old interface with apply
and build_{range,domain}_vector
. We could even take m()
and n()
out but that would most likely require Vector
concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would propose to do instead is to create a concept of MatrixOperator
which inherits Operator
. Then, in DealIIMatrixOperator
and TrilinosMatrixOperator
could inherit from that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea.
include/mfmg/dealii_operator.hpp
Outdated
dealii::SparseMatrix<typename VectorType::value_type>, VectorType> | ||
: public DealIIOperator<VectorType> | ||
template <typename VectorType> | ||
class DealIIMatrixOperator : public Operator<VectorType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned above, this should inherit from MatrixOperator
concept.
include/mfmg/dealii_operator.hpp
Outdated
dealii::TrilinosWrappers::SparseMatrix, VectorType> | ||
: public DealIIOperator<VectorType> | ||
template <typename VectorType> | ||
class TrilinosMatrixOperator : public Operator<VectorType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose either renaming TrilinosMatrixOperator
to DealIITrilinosMatrixOperator
or dropping DealII
from DealIIMatrixOperator
for consistency. They both live in some dealii
namespace so that should be fine. Judging of how this patch renames DealIISmootherOperator
to SmootherOperator
, I am fine changing DealIIMatrixOperator
to simply MatrixOperator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then how do you call the matrix operator that derives from Operator
? I have used TrilinosMatrixOperator
and DealIIMatrixOperator
because when Damien saw DealIIMatrixOperator
, he assumed that we had sth called TrilinosMatrixOperator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, while we could differentiate by namespaces, I like calling the concept of matrix operator MatrixOperator
. The only minor issue I have right now is that TrilinosMatrixOperator
does not indicate that it is deal.ii specific. I guess the namespace does that, but that's a bit of extra effort. I could live with leaving it as it is, but would prefer DealIITrilinosMatrixOperator
and then probably DealIIDirectOperator
with DealIISmootherOperator
. In any case, this all is hidden from Hierarchy.
include/mfmg/dealii_operator.hpp
Outdated
} | ||
} | ||
virtual std::shared_ptr<operator_type> | ||
multiply(operator_type const &operator_b) const override final; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions really don't belong to smoother, and should be gone once MatrixOperator
is moved out of Operator
concept.
std::shared_ptr<VectorType> | ||
DealIIMatrixOperator<VectorType>::build_domain_vector() const | ||
{ | ||
ASSERT_THROW_NOT_IMPLEMENTED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build_domain_vector
and build_range_vector
should probably be implemented for DealIIMatrixOperator
. I guess they currently are not only because we don't use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it's fine for now not having them
include/mfmg/dealii_operator.hpp
Outdated
void initialize(std::string const &prec_type); | ||
|
||
matrix_type const &_matrix; | ||
std::unique_ptr<dealii::TrilinosWrappers::PreconditionBase> _smoother; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that was me being stupid, I did not find Trilinos' PreconditionerBase
in deal.ii.
include/mfmg/dealii_operator.hpp
Outdated
dealii::TrilinosWrappers::PreconditionILU _ilu_smoother; | ||
void initialize(std::string const &prec_type); | ||
|
||
matrix_type const &_matrix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a comment here. Something like this:
Currently, dealii preconditioners do not support a mode to update a given vector, instead replacing it. For smoothers, this mode is necessary to operator. We workaround this issue by doing extra computations in "apply", however this requires residual computation. Therefore, we need to store a reference to matrix.
Get ride of DealIIOperator and DealIIMatrixOperator. Instead of using partial template specialization to use different types of matrix, we derive different classes from Operator. This simplifies the structure and allows for ETI.
The first two commits relates to #37 and are mostly cosmetic. The third commit is more interesting. I have talked with @dalg24 and we thought that the current design was too complicated. This PR removes
DealIIOperator
(which was missing some functions and therefore was not anOperator
as defined inconcept.hpp
) and it also removesDealIIMatrixOperator
. Instead of specializingDealIIMatrixOperator
, we now have classes that derived directly fromOperator
. The classes areDealIIMatrixOperator
for thedealii::SparseMatrix
andTrilinosMatrixOperator
for thedealii::TrilinosWrappers::SparseMatrix
. This classes are in thedealii_adapter
namespace and should probably be moved in adealii
subdirectory later. The new structure is simpler and allows us to use ETI.