belson17 / modred

Modred main repository
BSD 2-Clause "Simplified" License
76 stars 38 forks source link

Inputs for modred-functions #46

Open SebiK91 opened 4 years ago

SebiK91 commented 4 years ago

Hi everybody,

after installing the modred package I'd like to use it for a model order reduction. For this want to apply the Proper Orthogonal Decomposition (POD) and Eigensystem Realization Algorithm (ERA) on my dataset. This consists of an input (m x n) and an output matrix (n x p). Unfortunately I have a problem with the function variables:

1) According to the modred.pod-documentation I need a inner_product as an input for the calculation: https://modred.readthedocs.io/en/stable/pod.html. How do I get the inner_product from my dataset?

2) According to the modred.era-documentation I need a put_mat as an input for the calculation: https://modred.readthedocs.io/en/stable/era.html. How do I get the put_mat from my dataset? Where do I get the Markov parameters in the next step? As I understand the documentation the function expects it as an input but I don't know how to calculate it.

Thanks and regards Markus

jhtu commented 4 years ago
  1. There are certain requirements for a function to be an inner product. However, for any numerical data that you think of as a vector (a list of numbers), you can use the standard inner product: <x, y> = x^H y, where ^H denotes the Hermitian transpose. That is, if you have vectors [x_0, x_1, x_2, ..., x_n] and [y_0, y_1, y_2, ..., y_n], then you can compute the inner product as <x, y> = conj(x_0) y_0 + conj(x_1) y_1 + conj(x_2) y_2 + ... + conj(x_n) y_n.

For certain problems, you may wish to use a modified inner product. For instance, sometimes data from finite element simulations are meant to approximate continuous functions, which means the inner product sum approximates an integral. In that case, you might want to weight each element of the sum by a differential volume dV, so that large elements in the simulation mesh get more weight. You might also have different weights if different elements of your data have different physical units (e.g. meters vs kilometers). If you have questions on this, let us know.

  1. put_mat is just a function to save data, with certain requirements on the interface. If you don't have a function to save data, you can likely use a standard one, like numpy.save. I believe that you would have to wrap that function though, since I believe that put_mat requires the data argument followed by the filename, while the numpy save function has the opposite order of arguments.
SebiK91 commented 4 years ago

Thanks for the explanation. Unfortunately I can't even run the examples so I can't go on with more complex things...

1) I tried to run the examples of this website: https://modred.readthedocs.io/en/stable/tutorial_modaldecomp.html But as soon as I use the functions 'mr.compute_POD_matrices_snaps_method' and 'mr.compute_POD_matrices_direct_method' I get the following error: AttributeError: module 'modred' has no attribute 'mr.compute_POD_matrices_snaps_method' and AttributeError: module 'modred' has no attribute 'compute_POD_matrices_direct_method' respectively.

Do you know what the problem is? Other functions like 'mr.VecHandleArrayText' work very well so the installation of 'modred' should be ok.

2) Before I can start with ERA I need the Markovs from OKID. For this I tried Markovs = mr.okid.OKID(u, y, 3) with my Inputs u and Outputs y --> Inputs_Outputs.zip

But the following error occurs: File "C:\Users\qxo2456\Anaconda3\lib\site-packages\modred-2.0.4.post6-py3.7.egg\modred\okid.py", line 64, in OKID Markov_aug = np.linalg.lstsq(V.conj().T, outputs.T)[0].conj().T

File "<__array_function__ internals>", line 6, in lstsq

File "C:\Users\qxo2456\AppData\Roaming\Python\Python37\site-packages\numpy\linalg\linalg.py", line 2306, in lstsq x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)

TypeError: No loop matching the specified signature and casting was found for ufunc lstsq_n

Do you know what I am doing wrong here?

Thank you very much!

jhtu commented 4 years ago

I think we forgot to update the documentation. Thanks for pointing that out!

  1. I believe you want mr.compute_POD_arrays_snaps_method and mr.compute_POD_arrays_direct_method. We changed "matrices" to "arrays" since we use numpy arrays and not matrices.

As for your second question, I'm not sure about that one. I would check the value of V. Is it an array of the expected shape?

SebiK91 commented 4 years ago

1) Ah, looks but still doesn't work unfortunately: Traceback (most recent call last):

File "", line 17, in vecs, list(range(num_modes)), inner_product_weights=weights)

ValueError: too many values to unpack (expected 2)

2) I think I know what the problem is. My inputs and outputs are not two vectors but two matrices. Is this algorithm developed for a SISO- or a MIMO-system?

jhtu commented 4 years ago

Regarding the examples, I realize now that the documentation on ReadTheDocs is for the last release. Since you had to build from source, you should also build the documentation locally. The instructions are in the README of the source code, but boils down to running sphinx-build doc doc/build. Sorry again for this. We have fixed a lot of stuff but I haven't had time yet to put out the new release. I will try to get to that soon.

jhtu commented 4 years ago

Regarding OKID, I see in the unittests that there are tests for SISO, SIMO, MISO, and MIMO cases. So I think it should work for MIMO. To be honest, OKID is not a method I know much about. @belson17, since this method is in your domain of expertise, do you have any thoughts?

jhtu commented 3 years ago

I just released a new version of the code, so the documentation on ReadTheDocs should be up-to-date with respect to modred 2.1.0. Did you figure out your issue with MIMO inputs/outputs yet?