Temporal Reconstruction from Proper Orthogonal Decomposition¶
Description¶
This treatment computes the temporal evolution of modes from a POD decomposition of a given input Base.
Parameters¶
- base_pod:
Base
The input base resulting from a treatment
antares.treatment.TreatmentPOD
, or having the same structure.
- base_pod:
- base_mesh:
Base
The input base containing the mesh of the domain used in the POD treatment. This base must only contain one zone.
- base_mesh:
- mode: int, default= 0
The POD mode number that has to be reconstructed in time. The first mode is the mode 0 and has the highest eigenvalue (largest energy content).
- variables: list(str), default= []
The variable names considered for the temporal reconstruction.
- coordinates: list(str)
The variable names that define the set of coordinates. If no value is given, the default coordinate system of the base base_mesh is used (see
Base.coordinate_names
).
Preconditions¶
The input base base must be issued from the
antares.treatment.TreatmentPOD
treatment, or it must respect the same
structure as the output base of this treatment.
The input base base_mesh must only contain one zone.
Postconditions¶
The output base will contain one zone for the given mode.
The output base contains the coordinates of base_mesh and the instants that have been reconstructed from the POD mode considered.
Example¶
import antares
myt = antares.Treatment('PODtoTemporal')
myt['base_pod'] = POD_base
myt['base_mesh'] = mesh_base
myt['mode'] = 0
myt['variables'] = ['psta']
output_base = myt.execute()
Main functions¶
Example¶
"""
This example illustrates the Proper Orthogonal Decomposition.
"""
import os
import numpy as np
import antares
if not os.path.isdir('OUTPUT'):
os.makedirs('OUTPUT')
# Create the input Base
time_step = 0.0003
nb_snapshot = 50
nb_space_points = 100
base = antares.Base()
zone = base['zone_0'] = antares.Zone()
for snapshot_idx in range(nb_snapshot):
instant_name = 'snapshot_%s' % snapshot_idx
inst = zone[instant_name] = antares.Instant()
inst['pressure'] = 25.4 * np.cos(2 * np.pi * 250 * snapshot_idx * time_step + np.linspace(0, 2.5 * np.pi, nb_space_points))
# constant pressure over the space domain evolving in time
# base[0][instant_name]['pressure'] = np.cos(2 * np.pi * 0.01 * snapshot_idx * 2 + np.zeros((nb_space_points,)))
# ------------------
# Compute the POD
# ------------------
treatment = antares.Treatment('POD')
treatment['base'] = base
treatment['tolerance'] = 0.99
treatment['dim_max'] = 100
treatment['POD_vectors'] = True
treatment['variables'] = ['pressure']
result = treatment.execute()
result.show()
# ------------------
# Get some results
# ------------------
print("POD modes: ", result[0]['modes'][0])
print("POD parameters: ")
for k, v in result.attrs.items():
print(k, v)
base_mesh = antares.Base()
base_mesh.init()
base_mesh[0][0]['x'] = range(nb_space_points)
t = antares.Treatment('PODtoTemporal')
t['base_mesh'] = base_mesh
t['base_pod'] = result
t['variable'] = ['pressure']
t['mode'] = 0
t['coordinates'] = ['x']
base_pod_temporal = t.execute()
writer = antares.Writer('bin_tp')
writer['base'] = base_pod_temporal
writer['filename'] = os.path.join('OUTPUT', 'ex_mode_0_reconstructed_temporal.plt')
writer.dump()