class BaseTheoryMaxwellModesFrequency: """[summary] """ help_file = 'http://reptate.readthedocs.io/manual/Applications/LVE/Theory/theory.html#maxwell-modes' single_file = True thname = TheoryMaxwellModesFrequency.thname citations = TheoryMaxwellModesFrequency.citations doi = TheoryMaxwellModesFrequency.doi def __init__(self, name="", parent_dataset=None, ax=None): """ **Constructor** Keyword Arguments: - name {[type]} -- [description] (default: {""}) - parent_dataset {[type]} -- [description] (default: {None}) - ax {[type]} -- [description] (default: {None}) """ super().__init__(name, parent_dataset, ax) self.function = self.MaxwellModesFrequency self.has_modes = True self.MAX_MODES = 40 self.view_modes = True wmin = self.parent_dataset.minpositivecol(0) wmax = self.parent_dataset.maxcol(0) nmodes = int(np.round(np.log10(wmax / wmin))) self.parameters["logwmin"] = Parameter( "logwmin", np.log10(wmin), "Log of frequency range minimum", ParameterType.real, opt_type=OptType.opt) self.parameters["logwmax"] = Parameter( "logwmax", np.log10(wmax), "Log of frequency range maximum", ParameterType.real, opt_type=OptType.opt) self.parameters["nmodes"] = Parameter( name="nmodes", value=nmodes, description="Number of Maxwell modes", type=ParameterType.integer, opt_type=OptType.const, display_flag=False, min_value=1) # Interpolate modes from data w = np.logspace(np.log10(wmin), np.log10(wmax), nmodes) G = np.abs( np.interp(w, self.parent_dataset.files[0].data_table.data[:, 0], self.parent_dataset.files[0].data_table.data[:, 1])) for i in range(self.parameters["nmodes"].value): self.parameters["logG%02d" % i] = Parameter( "logG%02d" % i, np.log10(G[i]), "Log of Mode %d amplitude" % i, ParameterType.real, opt_type=OptType.opt) # GRAPHIC MODES self.graphicmodes = [] self.artistmodes = [] self.setup_graphic_modes() def set_param_value(self, name, value): """Change other parameters when nmodes is changed, else call parent function""" if name == 'nmodes': nmodesold = self.parameters["nmodes"].value wminold = self.parameters["logwmin"].value wmaxold = self.parameters["logwmax"].value wold = np.logspace(wminold, wmaxold, nmodesold) Gold = np.zeros(nmodesold) for i in range(nmodesold): Gold[i] = self.parameters["logG%02d" % i].value del self.parameters["logG%02d" % i] nmodesnew = int(value) message, success = super().set_param_value("nmodes", nmodesnew) wnew = np.logspace(wminold, wmaxold, nmodesnew) Gnew = np.interp(wnew, wold, Gold) for i in range(nmodesnew): self.parameters["logG%02d" % i] = Parameter( "logG%02d" % i, Gnew[i], "Log of Mode %d amplitude" % i, ParameterType.real, opt_type=OptType.opt) if CmdBase.mode == CmdMode.GUI: self.spinbox.blockSignals(True) self.spinbox.setValue(nmodesnew) self.spinbox.blockSignals(False) else: message, success = super().set_param_value(name, value) return message, success def drag_mode(self, dx, dy): """[summary] [description] Arguments: - dx {[type]} -- [description] - dy {[type]} -- [description] """ nmodes = self.parameters["nmodes"].value if self.parent_dataset.parent_application.current_view.log_x: self.set_param_value("logwmin", np.log10(dx[0])) self.set_param_value("logwmax", np.log10(dx[nmodes - 1])) else: self.set_param_value("logwmin", dx[0]) self.set_param_value("logwmax", dx[nmodes - 1]) if self.parent_dataset.parent_application.current_view.log_y: for i in range(nmodes): self.set_param_value("logG%02d" % i, np.log10(dy[i])) else: for i in range(nmodes): self.set_param_value("logG%02d" % i, dy[i]) self.do_calculate("") self.update_parameter_table() def update_modes(self): """[summary] [description] """ pass def setup_graphic_modes(self): """[summary] [description] """ nmodes = self.parameters["nmodes"].value w = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) G = np.zeros(nmodes) for i in range(nmodes): G[i] = np.power(10, self.parameters["logG%02d" % i].value) self.graphicmodes = self.ax.plot(w, G)[0] self.graphicmodes.set_marker('D') self.graphicmodes.set_linestyle('') self.graphicmodes.set_visible(self.view_modes) self.graphicmodes.set_markerfacecolor('yellow') self.graphicmodes.set_markeredgecolor('black') self.graphicmodes.set_markeredgewidth(3) self.graphicmodes.set_markersize(8) self.graphicmodes.set_alpha(0.5) self.artistmodes = DraggableModesSeries( self.graphicmodes, DragType.special, self.parent_dataset.parent_application, self.drag_mode) self.plot_theory_stuff() def destructor(self): """Called when the theory tab is closed [description] """ self.graphicmodes_visible(False) self.ax.lines.remove(self.graphicmodes) def show_theory_extras(self, show=False): """Called when the active theory is changed [description] """ if CmdBase.mode == CmdMode.GUI: self.Qhide_theory_extras(show) self.graphicmodes_visible(show) def graphicmodes_visible(self, state): """[summary] [description] """ self.view_modes = state self.graphicmodes.set_visible(self.view_modes) if self.view_modes: self.artistmodes.connect() else: self.artistmodes.disconnect() # self.do_calculate("") self.parent_dataset.parent_application.update_plot() def get_modes(self): """[summary] [description] Returns: - [type] -- [description] """ nmodes = self.parameters["nmodes"].value freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) tau = 1.0 / freq G = np.zeros(nmodes) for i in range(nmodes): G[i] = np.power(10, self.parameters["logG%02d" % i].value) return tau, G def set_modes(self, tau, G): """[summary] [description] Arguments: - tau {[type]} -- [description] - G {[type]} -- [description] """ print("set_modes not allowed in this theory (%s)" % self.name) def MaxwellModesFrequency(self, f=None): """[summary] [description] Keyword Arguments: - f {[type]} -- [description] (default: {None}) """ ft = f.data_table tt = self.tables[f.file_name_short] tt.num_columns = ft.num_columns tt.num_rows = ft.num_rows tt.data = np.zeros((tt.num_rows, tt.num_columns)) tt.data[:, 0] = ft.data[:, 0] nmodes = self.parameters["nmodes"].value freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) tau = 1.0 / freq for i in range(nmodes): if self.stop_theory_flag: break wT = tt.data[:, 0] * tau[i] wTsq = wT**2 G = np.power(10, self.parameters["logG%02d" % i].value) tt.data[:, 1] += G * wTsq / (1 + wTsq) tt.data[:, 2] += G * wT / (1 + wTsq) def plot_theory_stuff(self): """[summary] [description] """ # if not self.view_modes: # return data_table_tmp = DataTable(self.axarr) data_table_tmp.num_columns = 3 nmodes = self.parameters["nmodes"].value data_table_tmp.num_rows = nmodes data_table_tmp.data = np.zeros((nmodes, 3)) freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) data_table_tmp.data[:, 0] = freq for i in range(nmodes): if self.stop_theory_flag: break data_table_tmp.data[i, 1] = data_table_tmp.data[i, 2] = np.power( 10, self.parameters["logG%02d" % i].value) view = self.parent_dataset.parent_application.current_view try: x, y, success = view.view_proc(data_table_tmp, None) except TypeError as e: print(e) return self.graphicmodes.set_data(x, y) for i in range(data_table_tmp.MAX_NUM_SERIES): for nx in range(len(self.axarr)): self.axarr[nx].lines.remove(data_table_tmp.series[nx][i])
class BaseTheoryRetardationModesTime: """[summary] [description] """ help_file = 'http://reptate.readthedocs.io/manual/Applications/Creep/Theory/theory.html#retardation-modes' single_file = True thname = TheoryRetardationModesTime.thname citations = TheoryRetardationModesTime.citations doi = TheoryRetardationModesTime.doi def __init__(self, name="", parent_dataset=None, ax=None): """ **Constructor** Keyword Arguments: - name {[type]} -- [description] (default: {""}) - parent_dataset {[type]} -- [description] (default: {None}) - ax {[type]} -- [description] (default: {None}) """ super().__init__(name, parent_dataset, ax) self.function = self.RetardationModesTime self.has_modes = True self.MAX_MODES = 40 self.view_modes = True tmin = self.parent_dataset.minpositivecol(0) tmax = self.parent_dataset.maxcol(0) nmodes = int(np.round(np.log10(tmax / tmin))) self.parameters["logJini"] = Parameter( "logJini", -4.0, "Log of Instantaneous Compliance", ParameterType.real, opt_type=OptType.opt) self.parameters["logeta0"] = Parameter("logeta0", 0.0, "Log of Terminal Viscosity", ParameterType.real, opt_type=OptType.opt) self.parameters["logtmin"] = Parameter("logtmin", np.log10(tmin), "Log of time range minimum", ParameterType.real, opt_type=OptType.opt) self.parameters["logtmax"] = Parameter("logtmax", np.log10(tmax), "Log of time range maximum", ParameterType.real, opt_type=OptType.opt) self.parameters["nmodes"] = Parameter( name="nmodes", value=nmodes, description="Number of Retardation modes", type=ParameterType.integer, opt_type=OptType.const, display_flag=False) # Interpolate modes from data try: sigma = float( self.parent_dataset.files[0].file_parameters["stress"]) except (ValueError, KeyError): self.Qprint("Invalid stress value") return tau = np.logspace(np.log10(tmin), np.log10(tmax), nmodes) J = np.abs( np.interp(tau, self.parent_dataset.files[0].data_table.data[:, 0], self.parent_dataset.files[0].data_table.data[:, 1])) / sigma for i in range(self.parameters["nmodes"].value): self.parameters["logJ%02d" % i] = Parameter( "logJ%02d" % i, np.log10(J[i]), "Log of Mode %d amplitude" % i, ParameterType.real, opt_type=OptType.opt) # GRAPHIC MODES self.graphicmodes = None self.artistmodes = None self.setup_graphic_modes() def drag_mode(self, dx, dy): """[summary] [description] Arguments: - dx {[type]} -- [description] - dy {[type]} -- [description] """ nmodes = self.parameters["nmodes"].value self.set_param_value("logtmin", dx[0]) self.set_param_value("logtmax", dx[nmodes - 1]) for i in range(nmodes): self.set_param_value("logJ%02d" % i, dy[i]) self.do_calculate("") self.update_parameter_table() def update_modes(self): """[summary] [description] """ pass def setup_graphic_modes(self): """[summary] [description] """ nmodes = self.parameters["nmodes"].value tau = np.logspace(self.parameters["logtmin"].value, self.parameters["logtmax"].value, nmodes) J = np.zeros(nmodes) for i in range(nmodes): J[i] = np.power(10, self.parameters["logJ%02d" % i].value) self.graphicmodes = self.ax.plot(tau, J)[0] self.graphicmodes.set_marker('D') self.graphicmodes.set_linestyle('') self.graphicmodes.set_visible(self.view_modes) self.graphicmodes.set_markerfacecolor('yellow') self.graphicmodes.set_markeredgecolor('black') self.graphicmodes.set_markeredgewidth(3) self.graphicmodes.set_markersize(8) self.graphicmodes.set_alpha(0.5) self.artistmodes = DraggableModesSeries( self.graphicmodes, DragType.special, self.parent_dataset.parent_application, self.drag_mode) self.plot_theory_stuff() def destructor(self): """Called when the theory tab is closed [description] """ self.graphicmodes_visible(False) self.ax.lines.remove(self.graphicmodes) def show_theory_extras(self, show=False): """Called when the active theory is changed [description] """ if CmdBase.mode == CmdMode.GUI: self.Qhide_theory_extras(show) self.graphicmodes_visible(show) def graphicmodes_visible(self, state): """[summary] [description] """ self.view_modes = state self.graphicmodes.set_visible(self.view_modes) if self.view_modes: self.artistmodes.connect() else: self.artistmodes.disconnect() # self.do_calculate("") self.parent_dataset.parent_application.update_plot() def get_modes(self): """[summary] [description] Returns: - [type] -- [description] """ nmodes = self.parameters["nmodes"].value tau = np.logspace(self.parameters["logtmin"].value, self.parameters["logtmax"].value, nmodes) J = np.zeros(nmodes) for i in range(nmodes): J[i] = 1.0 / np.power(10, self.parameters["logJ%02d" % i].value) return tau, J def set_modes(self, tau, J): """[summary] [description] Arguments: - tau {[type]} -- [description] - J {[type]} -- [description] """ print("set_modes not allowed in this theory (%s)" % self.name) def RetardationModesTime(self, f=None): """[summary] [description] Keyword Arguments: - f {[type]} -- [description] (default: {None}) """ ft = f.data_table tt = self.tables[f.file_name_short] tt.num_columns = ft.num_columns tt.num_rows = ft.num_rows tt.data = np.zeros((tt.num_rows, tt.num_columns)) tt.data[:, 0] = ft.data[:, 0] try: stress = float(f.file_parameters["stress"]) except (ValueError, KeyError): self.Qprint("Invalid stress value") return nmodes = self.parameters["nmodes"].value J0 = np.power(10, self.parameters["logJini"].value) eta0 = np.power(10, self.parameters["logeta0"].value) tau = np.logspace(self.parameters["logtmin"].value, self.parameters["logtmax"].value, nmodes) for i in range(nmodes): if self.stop_theory_flag: break expT_tau = (1.0 - np.exp(-tt.data[:, 0] / tau[i])) J = np.power(10, self.parameters["logJ%02d" % i].value) tt.data[:, 1] += stress * J * expT_tau tt.data[:, 1] += stress * (J0 + tt.data[:, 0] / eta0) def plot_theory_stuff(self): """[summary] [description] """ if not self.view_modes: return data_table_tmp = DataTable(self.axarr) data_table_tmp.num_columns = 2 nmodes = self.parameters["nmodes"].value data_table_tmp.num_rows = nmodes data_table_tmp.data = np.zeros((nmodes, 2)) tau = np.logspace(self.parameters["logtmin"].value, self.parameters["logtmax"].value, nmodes) data_table_tmp.data[:, 0] = tau for i in range(nmodes): if self.stop_theory_flag: break data_table_tmp.data[i, 1] = np.power( 10, self.parameters["logJ%02d" % i].value) view = self.parent_dataset.parent_application.current_view try: x, y, success = view.view_proc(data_table_tmp, None) except TypeError as e: print(e) return self.graphicmodes.set_data(x, y) for i in range(data_table_tmp.MAX_NUM_SERIES): for nx in range(len(self.axarr)): self.axarr[nx].lines.remove(data_table_tmp.series[nx][i])
class BaseTheoryKWWModesFrequency: """[summary] """ help_file = 'http://reptate.readthedocs.io/manual/Applications/Dielectric/Theory/theory.html#kolhrauch-williams-watts-kww-modes' single_file = True thname = TheoryKWWModesFrequency.thname citations = TheoryKWWModesFrequency.citations doi = TheoryKWWModesFrequency.doi def __init__(self, name="", parent_dataset=None, ax=None): """ **Constructor** Keyword Arguments: - name {[type]} -- [description] (default: {""}) - parent_dataset {[type]} -- [description] (default: {None}) - ax {[type]} -- [description] (default: {None}) """ super().__init__(name, parent_dataset, ax) self.function = self.KWWModesFrequency self.has_modes = False self.MAX_MODES = 40 self.view_modes = True wmin = self.parent_dataset.minpositivecol(0) wmax = self.parent_dataset.maxcol(0) nmodes = int(np.round(np.log10(wmax / wmin))) self.parameters["einf"] = Parameter( "einf", 0.0, "Unrelaxed permittivity", ParameterType.real, opt_type=OptType.opt, bracketed=True, min_value=0) self.parameters["beta"] = Parameter( "beta", 0.5, 'Stretched exponential parameter', ParameterType.real, opt_type=OptType.opt, bracketed=True, min_value=0.1, max_value=2.0) self.parameters["logwmin"] = Parameter( "logwmin", np.log10(wmin), "Log of frequency range minimum", ParameterType.real, opt_type=OptType.opt) self.parameters["logwmax"] = Parameter( "logwmax", np.log10(wmax), "Log of frequency range maximum", ParameterType.real, opt_type=OptType.opt) self.parameters["nmodes"] = Parameter( name="nmodes", value=nmodes, description="Number of KWW modes", type=ParameterType.integer, opt_type=OptType.const, display_flag=False) # Interpolate modes from data w = np.logspace(np.log10(wmin), np.log10(wmax), nmodes) eps = np.abs( np.interp(w, self.parent_dataset.files[0].data_table.data[:, 0], self.parent_dataset.files[0].data_table.data[:, 1])) for i in range(self.parameters["nmodes"].value): self.parameters["logDe%02d" % i] = Parameter( "logDe%02d" % i, np.log10(eps[i]), "Log of Mode %d amplitude" % i, ParameterType.real, opt_type=OptType.opt) # GRAPHIC MODES self.graphicmodes = [] self.artistmodes = [] self.setup_graphic_modes() def drag_mode(self, dx, dy): """[summary] [description] Arguments: - dx {[type]} -- [description] - dy {[type]} -- [description] """ nmodes = self.parameters["nmodes"].value if self.parent_dataset.parent_application.current_view.log_x: self.set_param_value("logwmin", np.log10(dx[0])) self.set_param_value("logwmax", np.log10(dx[nmodes - 1])) else: self.set_param_value("logwmin", dx[0]) self.set_param_value("logwmax", dx[nmodes - 1]) if self.parent_dataset.parent_application.current_view.log_y: for i in range(nmodes): self.set_param_value("logDe%02d" % i, np.log10(dy[i])) else: for i in range(nmodes): self.set_param_value("logDe%02d" % i, dy[i]) self.do_calculate("") self.update_parameter_table() def update_modes(self): """[summary] [description] """ pass def setup_graphic_modes(self): """[summary] [description] """ nmodes = self.parameters["nmodes"].value w = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) eps = np.zeros(nmodes) for i in range(nmodes): eps[i] = np.power(10, self.parameters["logDe%02d" % i].value) self.graphicmodes = self.ax.plot(w, eps)[0] self.graphicmodes.set_marker('D') self.graphicmodes.set_linestyle('') self.graphicmodes.set_visible(self.view_modes) self.graphicmodes.set_markerfacecolor('yellow') self.graphicmodes.set_markeredgecolor('black') self.graphicmodes.set_markeredgewidth(3) self.graphicmodes.set_markersize(8) self.graphicmodes.set_alpha(0.5) self.artistmodes = DraggableModesSeries( self.graphicmodes, DragType.special, self.parent_dataset.parent_application, self.drag_mode) self.plot_theory_stuff() def destructor(self): """Called when the theory tab is closed [description] """ self.graphicmodes_visible(False) self.ax.lines.remove(self.graphicmodes) def show_theory_extras(self, show=False): """Called when the active theory is changed [description] """ if CmdBase.mode == CmdMode.GUI: self.Qhide_theory_extras(show) self.graphicmodes_visible(show) def graphicmodes_visible(self, state): """[summary] [description] """ self.view_modes = state self.graphicmodes.set_visible(self.view_modes) if self.view_modes: self.artistmodes.connect() else: self.artistmodes.disconnect() # self.do_calculate("") self.parent_dataset.parent_application.update_plot() def get_modes(self): """[summary] [description] Returns: - [type] -- [description] """ nmodes = self.parameters["nmodes"].value freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) tau = 1.0 / freq eps = np.zeros(nmodes) for i in range(nmodes): eps[i] = np.power(10, self.parameters["logDe%02d" % i].value) return tau, eps def set_modes(self, tau, eps): """[summary] [description] Arguments: - tau {[type]} -- [description] - eps {[type]} -- [description] """ print("set_modes not allowed in this theory (%s)" % self.name) def KWWModesFrequency(self, f=None): """[summary] [description] Keyword Arguments: - f {[type]} -- [description] (default: {None}) """ ft = f.data_table tt = self.tables[f.file_name_short] tt.num_columns = ft.num_columns tt.num_rows = ft.num_rows tt.data = np.zeros((tt.num_rows, tt.num_columns)) tt.data[:, 0] = ft.data[:, 0] einf = self.parameters["einf"].value beta = self.parameters["beta"].value nmodes = self.parameters["nmodes"].value freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) tau = 1.0 / freq tt.data[:, 1] += einf for i in range(nmodes): if self.stop_theory_flag: break eps = np.power(10, self.parameters["logDe%02d" % i].value) for j, w in enumerate(tt.data[:, 0]): tt.data[j, 1] += eps * kwwc(w * tau[i], beta) tt.data[j, 2] += eps * kwws(w * tau[i], beta) def plot_theory_stuff(self): """[summary] [description] """ # if not self.view_modes: # return data_table_tmp = DataTable(self.axarr) data_table_tmp.num_columns = 3 nmodes = self.parameters["nmodes"].value data_table_tmp.num_rows = nmodes data_table_tmp.data = np.zeros((nmodes, 3)) freq = np.logspace(self.parameters["logwmin"].value, self.parameters["logwmax"].value, nmodes) data_table_tmp.data[:, 0] = freq for i in range(nmodes): if self.stop_theory_flag: break data_table_tmp.data[i, 1] = data_table_tmp.data[i, 2] = np.power( 10, self.parameters["logDe%02d" % i].value) view = self.parent_dataset.parent_application.current_view try: x, y, success = view.view_proc(data_table_tmp, None) except TypeError as e: print(e) return self.graphicmodes.set_data(x, y) for i in range(data_table_tmp.MAX_NUM_SERIES): for nx in range(len(self.axarr)): self.axarr[nx].lines.remove(data_table_tmp.series[nx][i])