-
Notifications
You must be signed in to change notification settings - Fork 2
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
Projection-based ROM example #3
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…s executed separately, in cmake.
chldkdtn
approved these changes
Aug 10, 2023
Merged
bumpwy
approved these changes
Aug 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Poisson Global ROM example
Demonstration result
Offline phase
Following is the output from one of the commands above. It takes longer than c++ libROM example, as we're using serial MFEM (details explained later)
Merge phase
Following is the output from the merge command:
FOM phase
The resulting output is similar to offline phase.
Online phase
Following is the output of the online command above:
Differences from c++ libROM
ComputeCtAB
defined in python sideWhile there is
ComputeCtAB
provided from c++ libROM, this example defines its ownComputeCtAB
, which is essentially a python copy of the same function. There are mainly two reasons why it is done this way:ComputeCtAB
from c++ libROM only supports parallel MFEM, which is currently not available due to the installation issue.SWIG
andpybind11
. WhileSWIG Object of type 'double *'
has a workaround sincedouble *
is a fundamental data type, other objects such asmfem::HypreParMatrix
ormfem::Operator
do not have a way to convert fromSWIG
topybind11
.Installation process updates
MFEM dependencies removed
libROM/lib/mfem
require explicit access to MFEM class/functions. To bind them in pybind11, pylibROM now has explicit include/link to the mfem dependencies.libROM/lib/mfem
functions purely in python, with combination ofPyMFEM
objects andpylibROM
. In this case, libROM needs not be compiled with mfem dependencies, which simplifies the installation a little bit.Pure python functions added
As a result, we re-implement these
mfem
-related functions purely in python. Currently two python functions are added:pylibROM.mfem.ComputeCtAB
: compute projected reduced matrix frommfem::HypreParMatrix
ormfem::Operator
.pylibROM.python_utils.swigdouble2numpyarray
: return numpy array fromSWIG Object of type 'double *'
Previous
__init__.py
files were not written properly, and in fact not doing any job. Now they are properly re-written.NOTE: usual
cmake
installation only includes c++ bindings from c++ libROM library, and thus these python modules are not available forcmake
installation. They will be built into the module only withpip
installation.c++ bindings renamed as
_pylibROM
In order to include both c++ bindings/python routines, the c++ bindings need to be renamed. Common practice is to prepand with an underscore:
_pylibROM
.NOTE: usual
cmake
installation would have_pylibROM
package, notpylibROM
itself. If the package is compiled viacmake
, then the users need to import_pylibROM
instead ofpylibROM
.Enforce memory contiguity of input numpy 1d array
Our current convention for
double *
is to handle them in the form ofnumpy.array
. One issue with this is thatnumpy.array
sometimes does not necessarily have a contiguous memory. libROM's implementation withdouble *
is predicated upon the assumption that the array memory is always contiguous, thus requiring an enforcement at pybind interface.For example, the numpy array
col_vec
in the following examples is contiguous in memory:Valid case 1 Column vectors from fortran-contiguous 2d numpy array
Valid case 2 The transpose of the matrix is constructed first then transposed back to the original shape. Its column vector is then contiguous in memory
However, the following examples are not contiguous in memory:
Invalid case 1 Column vectors from the default 2d numpy array (row-major order)
Invalid case 2 Row vectors of the transposed matrix, which originally constructed in default row-major order
Now
bindings/pylibROM/python_utils/cpp_utils.hpp
provides auxiliary functions that ensure this contiguity. Mainly,double* getPointer(py::array_t<double> &u_in)
: returnsdouble *
from numpy array. If numpy array is 1D, then checks the contiguity.double* getVectorPointer(py::array_t<double> &u_in)
: returnsdouble *
from numpy array. Checks if the array is 1D and contiguous in memory.All the libROM functions that take
double *
as an input 1d array are now simplified using the functions above. For example ofDMD::takeSample
,Minor fixes
Database::formats
was wrongly placed withinBasisGenerator
. This is now properly implemented with the pure classDatabase
inutils
.