def to_lti(self): """Convert model to |LTIModel|. This method interprets the given model as an |LTIModel| in the following way:: - self.operator -> A self.rhs -> B self.outputs -> C None -> D self.mass -> E """ if len(self.outputs) == 0: raise ValueError('No outputs defined.') if len(self.outputs) > 1: raise NotImplementedError('Only one output supported.') A = -self.operator B = self.rhs C = next(iter(self.outputs.values())) E = self.mass if not all(op.linear for op in [A, B, C, E]): raise ValueError('Operators not linear.') from pymor.models.iosys import LTIModel return LTIModel(A, B, C, E=E, visualizer=self.visualizer)
def create_cl_fom(Re=110, level=2, palpha=1e-3, control='bc'): """Create model which is used to evaluate the H2-Gap norm.""" setup_str = 'lvl_' + str(level) + ('_' + control if control is not None else '') \ + '_re_' + str(Re) + ('_palpha_' + str(palpha) if control == 'bc' else '') fom = load_fom(Re, level, palpha, control) Bra = fom.B.as_range_array() Cva = fom.C.as_source_array() Z = solve_ricc_lrcf(fom.A, fom.E, Bra, Cva, trans=False) K = fom.E.apply(Z).lincomb(Z.dot(Cva).T) KC = LowRankOperator(K, np.eye(len(K)), Cva) mKB = cat_arrays([-K, Bra]).to_numpy().T mKBop = NumpyMatrixOperator(mKB) mKBop_proj = LerayProjectedOperator(mKBop, fom.A.source.G, fom.A.source.E, projection_space='range') cl_fom = LTIModel(fom.A - KC, mKBop_proj, fom.C, None, fom.E) with open(setup_str + '/cl_fom', 'wb') as cl_fom_file: pickle.dump({'cl_fom': cl_fom}, cl_fom_file)
def to_lti(self): """Convert model to |LTIModel|. This method interprets the given model as an |LTIModel| in the following way:: - self.operator -> A self.rhs -> B self.output_functional -> C None -> D self.mass -> E """ if self.output_functional is None: raise ValueError('No output defined.') A = -self.operator B = self.rhs C = self.output_functional E = self.mass if not all(op.linear for op in [A, B, C, E]): raise ValueError('Operators not linear.') from pymor.models.iosys import LTIModel return LTIModel(A, B, C, E=E, parameter_space=self.parameter_space, visualizer=self.visualizer)
def build_rom(self, projected_operators, error_estimator): return LTIModel(error_estimator=error_estimator, **projected_operators)
def main( n: int = Argument(100, help='Order of the FOM.'), r: int = Argument(10, help='Order of the ROMs.'), ): """Synthetic parametric demo. See the `MOR Wiki page <http://modelreduction.org/index.php/Synthetic_parametric_model>`_. """ # Model # set coefficients a = -np.linspace(1e1, 1e3, n // 2) b = np.linspace(1e1, 1e3, n // 2) c = np.ones(n // 2) d = np.zeros(n // 2) # build 2x2 submatrices aa = np.empty(n) aa[::2] = a aa[1::2] = a bb = np.zeros(n) bb[::2] = b # set up system matrices Amu = sps.diags(aa, format='csc') A0 = sps.diags([bb, -bb], [1, -1], shape=(n, n), format='csc') B = np.zeros((n, 1)) B[::2, 0] = 2 C = np.empty((1, n)) C[0, ::2] = c C[0, 1::2] = d # form operators A0 = NumpyMatrixOperator(A0) Amu = NumpyMatrixOperator(Amu) B = NumpyMatrixOperator(B) C = NumpyMatrixOperator(C) A = A0 + Amu * ProjectionParameterFunctional('mu') # form a model lti = LTIModel(A, B, C) mu_list = [1 / 50, 1 / 20, 1 / 10, 1 / 5, 1 / 2, 1] w = np.logspace(0.5, 3.5, 200) # System poles fig, ax = plt.subplots() for mu in mu_list: poles = lti.poles(mu=mu) ax.plot(poles.real, poles.imag, '.', label=fr'$\mu = {mu}$') ax.set_title('System poles') ax.legend() plt.show() # Magnitude plot fig, ax = plt.subplots() for mu in mu_list: lti.mag_plot(w, ax=ax, mu=mu, label=fr'$\mu = {mu}$') ax.legend() plt.show() # Hankel singular values fig, ax = plt.subplots() for mu in mu_list: hsv = lti.hsv(mu=mu) ax.semilogy(range(1, len(hsv) + 1), hsv, '.-', label=fr'$\mu = {mu}$') ax.set_title('Hankel singular values') ax.legend() plt.show() # System norms for mu in mu_list: print(f'mu = {mu}:') print(f' H_2-norm of the full model: {lti.h2_norm(mu=mu):e}') if config.HAVE_SLYCOT: print( f' H_inf-norm of the full model: {lti.hinf_norm(mu=mu):e}') print(f' Hankel-norm of the full model: {lti.hankel_norm(mu=mu):e}') # Model order reduction run_mor_method_param(lti, r, w, mu_list, BTReductor, 'BT') run_mor_method_param(lti, r, w, mu_list, IRKAReductor, 'IRKA')
C[0, 1::2] = d # In[ ]: A0 = NumpyMatrixOperator(A0) Amu = NumpyMatrixOperator(Amu) B = NumpyMatrixOperator(B) C = NumpyMatrixOperator(C) # In[ ]: A = A0 + Amu * ProjectionParameterFunctional('mu', ()) # In[ ]: lti = LTIModel(A, B, C) # # Magnitude plot # In[ ]: mu_list_short = [1 / 50, 1 / 20, 1 / 10, 1 / 5, 1 / 2, 1] # In[ ]: w = np.logspace(0.5, 3.5, 200) fig, ax = plt.subplots() for mu in mu_list_short: lti.mag_plot(w, ax=ax, mu=mu, label=fr'$\mu = {mu}$') ax.legend()