Open keileg opened 5 months ago
Some of the functionality in po.models.geometry
may also be suited for this approach.
Some of the functionality in
po.models.geometry
may also be suited for this approach.
That's an interesting comment. Is there any chance this approach can help us with representation of tensors and their products?
Perhaps, it depends on what you mean. I suggest we discuss in person.
Implementing this will require three main steps, each split into separate tasks.
__matmul__
, we probably should implement all, and let benchmarking (see below) decide which to use.np.ndarrays
and pp.ad.AdArrays
. Hopefully, copilot can help with this. It is important to consider both small and big arrays, and slicing/prolongation to few and many of the rows. We should also test the existing implementation of multiplying with a sparse matrix.__matmul__
should be used. It could be that the results are similar for some cases, in which case we either prioritize simplicity, or keep several options for a while.SubdomainProjection
, to replace the existing projections. It could be that we need to introduce a new Ad operator to ensure delayed evaluation (the existing projections use SparseArrays), but this should be a relatively simple task.pp.ad.Operator
, but we may need to do modifications to pp.ad.AdArray
to let these know how to deal with the new classes (simply leave the operation to the new class by calling its __matmul__
)SubdomainProjections
. Currently this is based on the projection matrix being explicitly available, but when we only have the action of the slicer, we need to construct the matrix (multiply with one unit vector at a time, build the matrix this way).SubdomainProjection
.MortarProjection
. Modify all projections, but leave out the sign_of_mortar_side
for now.Observations from benchmarking using line_profiler
(which btw seems to have a substantial overhead with my setup, but comparing relative performance, rather than absolute numbers, should give some indications)
Running flow_benchmark_2d_case3, with a grid of 24K cells in the matrix, ~800 mortar cells
Conclusion so far: It seems the projection update project can make an impact.
This may be a stupid question: How will the slicing work for non-matching mortar grids?
This may be a stupid question: How will the slicing work for non-matching mortar grids?
It will be more complicated, involving not only slicing, but weighted sums over rows. I haven't worked out the details, but if it gets too complicated, it could be that we end up using the old solution for non-matching grids, at least until we start using these in earnest.
There turned out to be two natural ways to implement these operations:
Comments:
pp.ad.SubdomainProjections
, however, if we go for this solution, we will not rely on sps.bmat
to construct a combined matrix for multiple subdomains, but rather concatenate indices and construct a single matrix (could be substantially faster).PETSc
backend for the Ad operations, Option 2 may benefit from this (assuming PETSc
speeds up calculations). Option 1 will require that we figure out how to efficiently manipulate the PETSc sparse matrix format.SubdomainProjection
and significant improvements to MortarProjection
(which is horribly inefficient).Two md geometries were considered:
We test both restriction to and prolongation from each subdomain. This is representative for both subdomain and mortar projections, with the assumption that we treat the task of identifying indices to project to and from different from the task of mapping. By similar reasoning, mapping to sets of domains is also covered.
We comment below on time for initialization, and of mapping of vectors, sparse matrices and AdArrays. In Option 2, initialization entails construction of a projection matrix, while Option 1 only stores passed information during initialization. Thus the relative importance of initialization cost depends on how many times a restriction/prolongation object is used; currently this is often only once, but future caching (#1181) may change this.
Summarized as follows:
grid_operators.py
. SubdomainProjection
to use the new classes. This will entail deciding which indices to use based on input tot the methods cell_prolongation()
etc. Note that for the SubdomainProjection
, the weights will always be unitary.MortarProjection
Background
In the Ad operator framework, the classes
SubdomainProjection
,MortarProjection
,Trace
andInvTrace
all represent mappings betweeen grid entities of various kinds. These are all implemented as projection matrices that, during parsing of an operator tree, are left multiplied with arrays and matrices. This is unsatisfactory for two reasons:Suggested change
The projection methods, say
SubdomainProjection.face_restriction()
, now returnpp.ad.SparseArrays
s. Instead, it should return a new slicer-object that roughly looks like this:Comments:
SubdomainProjection
,MortarProjection
etc.pp.models.geometry.basis
, research is needed.Regarding the divergence class
The class
pp.ad.Divergence
represents a differential operator rather than a mapping. This cannot readily be implemented as slicing, and although improvements should be possible there as well, it will not be part of this issue.Dependencies
This can be done independently of #1179, #1181, but should not be done in parallel.