EZyRB

Tutorial 2: Model Reduction on a vtk pressure field - online phase

In this tutorial we will show the typical workflow for the online evaluation of the output of interest. First of all we just import ezyrb and numpy package.


In [1]:
import ezyrb.online as on
import numpy as np

Here we set the parameters we need to load the (already saved) offline structures and evaluate the new output:

  • mu_value is the value of the parameters for the new evaluation;
  • output_name is the suffix of the files containing the structures to be loaded. in order to identify the proper structure to upload among others within the same directory, it is the same name as the name of the output extracted in the offline phase;
  • directory is the directory where the structures are stored;
  • is_scalar is a boolean to set if the output of interest is a scalar or a field.

In [2]:
mu_value = np.array([.0, .0])
output_name = 'Pressure'
directory = '../tests/test_datasets/'
is_scalar = False

Now we initialize the online_handler. Then we need to start it in order to evaluate the output for the new value of the parameters value.


In [3]:
online_handler = on.Online(mu_value, output_name, directory=directory, is_scalar=is_scalar)
online_handler.run()

Now we have the output evaluation stored in online_handler.output. This is simply represented by a numpy array. In order to visualize the result we write the vtk file with this ouput. First we set filename (name of the output file) and infile (name of the input file). Then we actually write the file.


In [4]:
filename = 'online_evaluation.vtk'
infile   = '../tests/test_datasets/matlab_online_test.vtk'
online_handler.write_file(filename, infile)

Previously we have already computed the output of interest with the high-fidelity solver. In this way, we can provide a visual comparison between the two fields, as shown in the following. First picture represents the evaluated pressure field, whereas the second represents the "true" pressure.

As you can easily see, the evaluated field is not perfect, but we must recall that we used only 5 snapshots during the offline stage (the four corners and the first parametric point suggested by the argorithm). If you are not satisfied with the result for your problem at hand, you can go back to the offline step and simply enrich the database with more and more solutions.