#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Apr 7 16:21:24 2017 @author: rg """ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Apr 4 00:16:22 2017 @author: Radovan Gospavic """ # -*- coding: utf-8 -*- """ Created on Mon Apr 3 00:46:11 2017 @author: Radovan Gospavic The base classes for dynamcal simulation of temperature distribution in N-Layer wall """ #from __future__ import division # import math #from Package_n_layer_wall import epsloc #import scitools.std # from scitools.std import * # import functools.std as ftool # import matplotlib.pyplot as plt #import sys #import string #import sys #import abc from abc import ABCMeta, abstractmethod, abstractproperty import numpy as np #from numpy import linalg as nplin #from scipy.sparse import csc_matrix, csr_matrix, linalg as sla #import scipy.sparse.linalg as sla #from scipy.sparse import linalg as sla #from copy import deepcopy #import os from nLayerWall_1_0 import EPSILOC12, EPSILOC10, BC_KEYWORDS #, nperiod, BETAMIN, nodebetaT, deepiterbeta from nLayerWall_1_0.classpack.beta_class import BetaSuper, BetaWall #, #AA_Beta_Dirichle , from nLayerWall_1_0.utils.wall_fun import temp_interfun, tempxfun from nLayerWall_1_0.testcheck.check_fun import check_wall, check_number_list from nLayerWall_1_0.utils.util_class import UtilBeta , SuperUtil from nLayerWall_1_0.utils.fun_def import TempXFun, Uf12XFun, TempXFunVec, Uf12XFunVec import sys #import sys #from sympy.combinatorics.permutations import Permutation # New-style class -python3 - inherets from object, class object is featureless object, which is a base for all new-style clasess #os.system('clear') # import os #=========================== Abstract base class WallSuper============================================================== class WallSuper( metaclass = ABCMeta ): """ The class WallSuper is supre class or parent class In general the wall is multilayer wall, with N layers If the layers are homogeneuse (lambda, Ro , C = const) the problem is linear Super Class Wall_super is base class for different subclasses: WallPlanar, WallCilindrical & WallSpherical Atributes: * list1 = ticheses/radii [d1,d2,...,dn] or [R1,R2,...,,Rn+1] * list2 = list of hermal conductivities [lambda1, lambda2, ..., lambdan ] * list3 = list densities [ro1, ro2, ..., ron ] * list3 = list specific heats [C1, C2, ..., Cn ] * wall_type = plan or cilin or spher * Nlayer= number of layers * alf1/2= Heat transfer coefficients from inside/outside """ def __init__(self, input_dictionary, wall_type): # ========================================Check input Data============================================================== # if self.__class__.__name__ != 'WallPlane' and self.__class__.__name__ != 'WallCylSpher' : #----------------------------------------------raise NotImplementedError------------------------------------------------ # raise NotImplementedError('Error, wrong class instance inicialization') list1 = input_dictionary ['tickness'] list2 = input_dictionary ['conductivity'] list3 = input_dictionary ['density'] list4 = input_dictionary ['specific_heat'] list5 = input_dictionary ['inv_th_res'] list6 = input_dictionary ['layer_gap'] #----------------------------------------------------------------------------------------------------------------------- n_layer = input_dictionary ['nlayer'] alf1 = input_dictionary ['alf1'] alf2 = input_dictionary ['alf2'] air_cond = input_dictionary ['air_cond'] contact_res = input_dictionary ['contact_res'] #----------------------------------------------------------------------------------------------------------------------- # print ('======================================================================================================') # print ('list1, n_layer = ', list1, n_layer ) # print ('======================================================================================================') check_wall(list1, list2, list3, list4, list5, list6, kwarg0 =-1, kwarg1 = wall_type, kwarg2 = n_layer, kwarg3 = alf1, kwarg4 = alf2) self.__tickradii = [float(i) for i in list1] self.__conductivity = [float(i) for i in list2] self.__density = [float(i) for i in list3] self.__specheat = [float(i) for i in list4] self.__inv_th_res = [float(i) for i in list5] self.__layergap = [float(i) for i in list6] #----------------------------------------------------------------------------------------------------------------------- self.__walltype, self.__nlayer, self.__alf1, self.__alf2, self.__air_cond, self.__contact_res = wall_type,\ n_layer, float(alf1), float(alf2), air_cond, contact_res #======================================================================================================================= self.super_update () self.bc_wall = None # self.bc_local = None self.alf_steady = input_dictionary ['alf_steady'] self.smoothing = input_dictionary ['smoothing'] self.cut_fl = input_dictionary ['cut_fl'] # ------------------------Getters Methods for all Attributes------------------------------------------------------------ @property def tickradii(self): return self.__tickradii @property def conductivity(self): return self.__conductivity @property def density(self): return self.__density @property def specheat(self): return self.__specheat @property def walltype(self): return self.__walltype @property def nlayer(self): return self.__nlayer @property def alf1(self): return self.__alf1 @property def alf2(self): return self.__alf2 @property def th_diff(self): return self.__th_diff @property def dwall(self): return self.__dwall @property def xrlist(self): return self.__xrlist @property def roce_ekv(self): return self.__roce_ekv @property def heat_corr (self) : return self.__heat_corr #============================================ @property def uu_noalf(self): return self.__uu_noalf @property def uu_alf12(self): return self.__uu_alf12 #============================================ @property def uu_alf1(self): return self.__uu_alf1 #============================================ @property def uu_alf2(self): return self.__uu_alf2 #============================================ @property def temp10_alf12(self): return self.__temp10_alf12 @property def temp01_alf12(self): return self.__temp01_alf12 #============================================ @property def temp10_alf1(self): return self.__temp10_alf1 @property def temp01_alf1(self): return self.__temp01_alf1 #============================================ @property def temp10_alf2(self): return self.__temp10_alf2 @property def temp01_alf2(self): return self.__temp01_alf2 #============================================ @property def temp10_noalf(self): return self.__temp10_noalf @property def temp01_noalf(self): return self.__temp01_noalf #============================================ @property def w_unit(self): return self.__w_unit @property def q_unit_list(self): return self.__q_unit_list @property def c_unit_list(self): return self.__c_unit_list @property def d_cond_list(self): return self.__d_cond_list @property def change_fl(self): return self.__change_fl #======================================================================================================================= @property def inv_th_res(self): return self.__inv_th_res @property def layergap (self): return self.__layergap @property def air_cond(self): return self.__air_cond @property def contact_res(self): return self.__contact_res #======================================================================================================================= #=======================Abstract properties for beta_coeff & ab_coeff=================================================== @abstractproperty def beta_coeff_d(self): ''' getter for beta_coeff_d is defined in subclass WallPlane ''' @abstractproperty def nbeta_d(self): ''' getter for beta_coeff_d is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_d(self): ''' getter for ab_coeff_d is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_n(self): ''' getter for beta_coeff_n is defined in subclass WallPlane ''' @abstractproperty def nbeta_n(self): ''' getter for beta_coeff_d is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_n(self): ''' getter for ab_coeff_n is defined in subclass WallPlane ''' #=======================Abstract properties for beta_coeff & ab_coeff=================================================== @abstractproperty def beta_coeff_tq1(self): ''' getter for beta_coeff_tq1 is defined in subclass WallPlane ''' @abstractproperty def nbeta_tq1(self): ''' getter for beta_coeff_tq1 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_tq1(self): ''' getter for ab_coeff_tq1 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_tq2(self): ''' getter for beta_coeff_tq2 is defined in subclass WallPlane ''' @abstractproperty def nbeta_tq2(self): ''' getter for beta_coeff_tq2 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_tq2(self): ''' getter for ab_coeff_tq2 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_m0(self): ''' getter for beta_coeff_m0 is defined in subclass WallPlane ''' @abstractproperty def nbeta_m0(self): ''' getter for beta_coeff_d is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_m0(self): ''' getter for ab_coeff_m0 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_md1(self): ''' getter for beta_coeff_md1 is defined in subclass WallPlane ''' @abstractproperty def nbeta_md1(self): ''' getter for beta_coeff_md1 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_md1(self): ''' getter for ab_coeff_md1 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_md2(self): ''' getter for beta_coeff_md2 is defined in subclass WallPlane ''' @abstractproperty def nbeta_md2(self): ''' getter for beta_coeff_md2 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_md2(self): ''' getter for ab_coeff_md2 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_mn1(self): ''' getter for beta_coeff_md1 is defined in subclass WallPlane ''' @abstractproperty def nbeta_mn1(self): ''' getter for beta_coeff_md1 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_mn1(self): ''' getter for ab_coeff_md1 is defined in subclass WallPlane ''' #======================================================================================================================= @abstractproperty def beta_coeff_mn2(self): ''' getter for beta_coeff_md2 is defined in subclass WallPlane ''' @abstractproperty def nbeta_mn2(self): ''' getter for beta_coeff_md2 is defined in subclass WallPlane ''' @abstractproperty def ab_coeff_mn2(self): ''' getter for ab_coeff_md2 is defined in subclass WallPlane ''' #======================================================================================================================= # ---------------Setters Methods for all Attributes defined in abstract base class-------------------------------------- @tickradii.setter def tickradii(self, new_input): #-------------------------- Setter for thickness or radii + update for dwall ------------------------------------------- print (new_input) check_wall(new_input, kwarg0=0, kwarg1=self.__walltype, kwarg2=self.__nlayer) new_input = [float(i) for i in new_input] self.__tickradii = new_input #-------------------------- Up date xrlist & dwall---------------------------------------------------------------------- self.update_xrlist() self.update_qunit() self.update_u0() self.update_temp1001() self.update_roce_ekv() self.update_heat_corr() self.__change_fl = True print ('--------------- layer tickness is changed; xrlist, qunit and temp1001 are updated -----------------') @conductivity.setter def conductivity(self, new_input): #-------------------------- Setter for conductivity--------------------------------------------------------------------- check_wall(new_input, kwarg0=1, kwarg2=self.__nlayer) new_input = [float(i) for i in new_input] self.__conductivity = new_input #-------------------------- Up date for th_diff--------------------------------------------------------------------- self.update_thermal_diff() self.update_u0() self.update_temp1001() self.update_heat_corr() self.__change_fl = True print ('----conductivity is changed; thermal diffusity, u0_value and temp1001 are updated -----------------') @density.setter def density(self, new_input): #-------------------------- Setter for density-------------------------------------------------------------------------- check_wall(new_input, kwarg0=2, kwarg2=self.__nlayer) new_input = [float(i) for i in new_input] self.__density = new_input #-------------------------- Up date for th_diff--------------------------------------------------------------------- self.update_thermal_diff() self.update_qunit() self.update_roce_ekv() self.update_heat_corr() self.__change_fl = True print ('-----------------density is changed; thermal diffusity and qunit are updated ----------------------') @specheat.setter def specheat(self, new_input): #-------------------------- Setter for specific heat-------------------------------------------------------------------- check_wall(new_input, kwarg0=3, kwarg2=self.__nlayer) new_input = [float(i) for i in new_input] self.__specheat = new_input #-------------------------- Up date for th_diff--------------------------------------------------------------------- self.update_thermal_diff() self.update_qunit() self.update_roce_ekv() self.update_heat_corr() self.__change_fl = True print ('-------specific heat is changed; thermal diffusity and qunit are updated -------------------------') @alf1.setter def alf1(self, new_input): #-------------------------- Setter for alf1----------------------------------------------------------------------------- check_wall(kwarg0=6, kwarg3=new_input) self.__alf1 = new_input self.update_u0() self.update_temp1001() self.__change_fl = True print ('--------=-----------alf1 is changed; u0_value and temp1001 are updated ---------------------------') @alf2.setter def alf2(self, new_input): #-------------------------- Setter for alf2----------------------------------------------------------------------------- check_wall(kwarg0=7, kwarg4=new_input) self.__alf2 = new_input self.update_u0() self.update_temp1001() self.__change_fl = True print ('-------------------alf2 is changed; u0_value and temp1001 are updated ----------------------------') #----------------------------------------------------------------------------------------------------------------------- @layergap.setter def layergap(self, new_input): self.__layergap = new_input #-------------------------- Up date for inv_th_res--------------------------------------------------------------------- self.update_inv_th_res() self.__change_fl = True print ('-----------------layergap is changed; inverse thermal resistance is updated ----------------------') #----------------------------------------------------------------------------------------------------------------------- @air_cond.setter def air_cond(self, new_input): self.__air_cond = new_input #-------------------------- Up date for inv_th_res--------------------------------------------------------------------- self.update_inv_th_res() self.__change_fl = True print ('-----------------air_cond is changed; inverse thermal resistance is updated ----------------------') #----------------------------------------------------------------------------------------------------------------------- @inv_th_res.setter def inv_th_res(self, new_input): self.__inv_th_res = new_input self.__change_fl = True print ('-----------------inverse thermal resistance is changed; ----------------------') #----------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------- @walltype.setter def walltype(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for walltype: {0:s}.'. format (self.__class__.__name__)) @th_diff.setter def th_diff(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for th_diff: {0:s}.'. format (self.__class__.__name__)) @dwall.setter def dwall(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for dwall: {0:s}.'. format (self.__class__.__name__)) @xrlist.setter def xrlist(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for xrlist: {0:s}.'. format (self.__class__.__name__)) @nlayer.setter def nlayer(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for nlayer: {0:s}.'. format (self.__class__.__name__)) @roce_ekv.setter def roce_ekv(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for roce_ekv: {0:s}.'. format (self.__class__.__name__)) @heat_corr.setter def heat_corr(self, new_input): #-------------------------- No setter warning -------------------------------------------------------------------------- print ('No setter for roce_ekv: {0:s}.'. format (self.__class__.__name__)) @abstractmethod def flux(self): ''' flux method defined in sub-classes ''' @abstractmethod def temp_inter(self): ''' temp_inter method defined in sub-classes ''' @abstractmethod def tempx(self): ''' temppx method defined in sub-classes ''' @abstractmethod def eigen_fun(self) : ''' eigen_fun method defined in sub-classes ''' @abstractmethod def orto_gon (self) : ''' orto_gon method defined in sub-classes ''' @abstractmethod def fourier_coeff (self) : ''' icond method defined in sub-classes ''' def __repr__ (self): #-------------------------------- repr output -------------------------------------------------------------------------- string0 ='Wall parameters: \n' string0 +='{0:s} \n' string0 +='{1:04d} \n' string0 +='{2:14.8f} \n' string0 +='{3:14.8f} \n' formatlist = [self.__walltype, self.__nlayer, self.__alf1, self.__alf2] ind_curent = 3 par_list = [self.__tickradii, self.__conductivity, self.__density, self.__specheat] Number_Tables = len(par_list) for itable in range(Number_Tables): ind = 1 par_list_current = par_list [itable] for ddi in par_list_current: string0 +='{' + str(ind_curent+ind) + ':14.8f}' formatlist += [ ddi] ind += 1 if itable != Number_Tables - 1: string0 +='\n' ind_curent += ind - 1 return string0. format (*formatlist) def __str__ (self): #-------------------------------- "Pretty" print ----------------------------------------------------------------------- string0 ='================================================================================\n' string0 +='Geometry of wall (plane- planar, cylin-cylindrical, spher-spherical):{0:s} \n' string0 +='Number of Layers = {1:04d} \n' string0 +='Interior heat transfer coefficient alf1 = {2:14.8f} \n' string0 +='Exterior heat transfer coefficient alf2 = {3:14.8f} \n' string0 += '--------------------------------------------------------------------------------\n' formatlist = [self.__walltype, self.__nlayer, self.__alf1, self.__alf2] ind_curent = 3 if self.__walltype == 'plane': title_list = [' Thickness \n'] else: title_list = [' Radius \n'] title_list += [' Thermal Cond.\n',\ ' Density \n',\ ' Specific Heat\n',\ ' Thermal Diff \n'] par_list = [self.__tickradii, self.__conductivity, self.__density, self.__specheat, self.__th_diff] Number_Tables = len(title_list) #----------------------------------------------------------------------------------------------------------------------- for itable in range(Number_Tables): ind = 1 ind0 = 1 # string0 +=title_list[itable] string0 +=' layer No' + title_list[itable] string0 += '-----------------------------\n' par_list_current = par_list [itable] for ddi in par_list_current: string0 +='| {' + str(ind_curent + ind) + ':04d} | {' + str(ind_curent + 1 + ind) + ':14.8f} |\n' string0 += '-----------------------------\n' formatlist += [ind0, ddi] ind += 2 ind0 += 1 ind_curent += ind - 1 string0 += '--------------------------------------------------------------------------------\n' #----------------------------------------------------------------------------------------------------------------------- if itable == 0: string0 += 'Overal thickness = {' + str(ind_curent + 1 ) + ':14.8f} \n' ind_curent += 1 formatlist += [self.__dwall] string0 +='--------------------------------------------------------------------------------\n' string0 += 'Eq. th. capacity per area [J/kg*K*m^2] = {' + str(ind_curent + 1 ) + ':14.8f} \n' ind_curent += 1 formatlist += [self.__roce_ekv] string0 +='--------------------------------------------------------------------------------\n' string0 += 'Heat correction [J/W] = {' + str(ind_curent + 1 ) + ':14.8f} \n' ind_curent += 1 formatlist += [self.__heat_corr] string0 +='--------------------------------------------------------------------------------\n' string0 +='================================================================================\n' return string0. format(*formatlist) #======================================================================================================================= def update_thermal_diff (self) : self.__th_diff = [] for i in range(self.__nlayer): self.__th_diff.append(self.__conductivity[i] / (self.__density[i] * self.__specheat[i])) return #======================================================================================================================= def update_xrlist (self): xxd = 0.0 if self.__walltype == 'plane' : self.__xrlist = [0.0] NN = self.__nlayer elif self.__walltype == 'cylin' or self.__walltype == 'spher' : self.__xrlist = [] NN = self.__nlayer + 1 for i in range(NN): xxd += self.__tickradii[i] self.__xrlist.append(xxd) self.__dwall = self.__xrlist[-1] - self.__xrlist[0] return #======================================================================================================================= def update_qunit (self): type_unit = 'uf12' self.__w_unit, self.__q_unit_list, self.__c_unit_list, self.__d_cond_list = temp_interfun(None, self, None, None, type_unit ) return def update_u0 (self) : #======================================================================================================================= # Calculate U value for N-layer plane wall # method: uvalue(self, alf_par=1): # If alf_par=1 the convection in boundary layers and transfer coefficinets alf1,2 are not considered # In this case input temperatures temp1 and temp2 are a wall temperatures #======================================================================================================================= uu_no_alf_loc = 0.0 for i in range(self.__nlayer): uu_no_alf_loc += self.tickradii[i] / self.conductivity[i] if i > 0 : uu_no_alf_loc += self.inv_th_res[i-1] if all ( (self.alf1 != None, self.alf1 > EPSILOC10, self.alf2 != None, self.alf2 > EPSILOC10 ) ) : self.__uu_alf12 = 1.0 / (uu_no_alf_loc + 1.0 / self.alf1 + 1.0 / self.alf2) else : self.__uu_alf12 = None if all ( (self.alf1 != None, self.alf1 > EPSILOC10) ) : self.__uu_alf1 = 1.0 / (uu_no_alf_loc + 1.0 / self.alf1 ) else : self.__uu_alf1 = None if all ( (self.alf2 != None, self.alf2 > EPSILOC10) ) : self.__uu_alf2 = 1.0 / ( uu_no_alf_loc + 1.0 / self.alf2 ) else : self.__uu_alf2 = None self.__uu_noalf = 1.0 / uu_no_alf_loc return #======================================================================================================================= def update_temp1001 (self) : type_unit = 'steady_temp' self.__temp10_noalf = temp_interfun(0, self, 1.0, 0.0, type_unit ) self.__temp01_noalf = temp_interfun(0, self, 0.0, 1.0, type_unit ) if all ((self.alf1 != None, self.alf1 > EPSILOC10)) : self.__temp10_alf1 = temp_interfun(1, self, 1.0, 0.0, type_unit ) self.__temp01_alf1 = temp_interfun(1, self, 0.0, 1.0, type_unit ) else : self.__temp10_alf1 = None self.__temp01_alf1 = None if all ((self.alf2 != None, self.alf1 > EPSILOC10 )) : self.__temp10_alf2 = temp_interfun(2, self, 1.0, 0.0, type_unit ) self.__temp01_alf2 = temp_interfun(2, self, 0.0, 1.0, type_unit ) else : self.__temp10_alf2 = None self.__temp01_alf2 = None if all ((self.alf1 != None, self.alf1 > EPSILOC10, self.alf2 != None, self.alf1 > EPSILOC10 )) : self.__temp10_alf12 = temp_interfun(12, self, 1.0, 0.0, type_unit ) self.__temp01_alf12 = temp_interfun(12, self, 0.0, 1.0, type_unit ) else : self.__temp10_alf12 = None self.__temp01_alf12 = None return def update_roce_ekv (self) : self.__roce_ekv = 0.0 for i in range(self.__nlayer): self.__roce_ekv += self.__specheat[i] * self.__density[i] * self.__tickradii[i] self.__roce_ekv = self.__roce_ekv / self.__dwall return def update_heat_corr (self) : self.__heat_corr = 0.0 for i in range(self.__nlayer): dl_slope = 0.0 for j in range(i + 1) : dl_slope += self.__tickradii[j] / self.__conductivity[j] dl_slope -= 0.5 * self.__tickradii[i] / self.__conductivity[i] self.__heat_corr += self.__specheat[i] * self.__density[i] * self.__tickradii[i] * dl_slope return def update_inv_th_res (self) : for i in range(self.__nlayer - 1 ): if self.__contact_res == 0 : self.__inv_th_res [i] = 0.0 elif self.__contact_res == 1 : pass elif self.__contact_res == 2 : self.__inv_th_res [i] = self.__layergap [i] / self.__air_cond return def super_update (self) : self.update_inv_th_res () self.update_thermal_diff() self.update_xrlist() self.update_qunit() self.update_u0() self.update_temp1001() self.update_roce_ekv() self.update_heat_corr () self.__change_fl = True #======================================================================================================================= class WallPlane (WallSuper): """ Material Attributes (Physical properties of material) : ------------------------------------------------------------------------------------------------------------------------ Class WallPlane, this class in inherited from WallSuper Attributes of class Instances containes all thermal and geomatrical parameters of N-layer planar wall Quantites on the input of the instances (Attributes): * list1 - layer thickesses * list2 - thermal conductivites * list3 - densities * list4 - specific heats * wall_type - type of the wall, for this instances it is 'plane' * n_layer - number of layers * alf1 - Interior heat transfer coefficients * alf2 - Exterior heat transfer coefficients ------------------------------------------------------------------------------------------------------------------------ Attributes : - beta_coef_(d,n,m0,m1,m2) - Eigen values for Dirichlet (d), Neuman (n) and Mixed (m0,1,2) Boundary conditions - ab_coeff_(d,n,m0,m1,m2) - Coeficients for eigen functions in m-th layer: fi,m(x) = Am * sin(beat * x/sqrt(thermal_diff_m)) + Bm * cos(beat * x/sqrt(thermal_diff_m)) - nbeta_(d,n,m0,m1,m2) - Number of beta coefficients for different BC - d10_coeff_(d,n,m0,m1,m2) - Fourier Coefficients for left unit initial conditions (IC) - d01_coeff_(d,n,m0,m1,m2) - Fourier Coefficients for right unit initial conditions (IC) * Definition of left/right unit initial condotions: this is steady state temperature distributio in n-layer wall for floving boundaru condtitons: t1 = 1, t2 = 0 (left unit IC), and t1 = 0 , t2 = 1 (right IC) ------------------------------------------------------------------------------------------------------------------------ - temp10_alf = unit left temperature distribution with alf1/2 - temp01_alf = unit right temperature distribution with alf1/2 - temp10_noalf = unit left temperature distribution without alf1/2 - temp01_noalf = unit right temperature distribution without alf1/2 ------------------------------------------------------------------------------------------------------------------------ Boundary condition (BC): - 'd' - Dirichle fi(x = 0, L) = 0 for all i's - 'n' - Neuman dfi/dx(x = 0, L) = for all i's - 'm0' - Mixed type 0 (pure mixed BC) dfi/dx(x= 0, L) = alf1/2 * fi(x= 0, L) for all i's - 'm1L' - Mixed type 1L ( mixed(x= 0) + Dirichle (x=L) ) dfi/dx(x= 0) = alf1/2 * fi(x= 0) + fi(x = L) = 0 for all i's - 'm1R' - Mixed type 1R ( mixed(x= L) + Dirichle (x=0) ) dfi/dx(x= L) = alf1/2 * fi(x= L) + fi(x = 0) = 0 for all i's - 'm2L' - Mixed type 2L ( mixed(x= 0) + Neuman (x=L) ) dfi/dx(x= 0) = alf1/2 * fi(x= 0) + dfi/dx(x = L) = 0 for all i's - 'm2R' - Mixed type 2R ( mixed(x= L) + Neuman (x=0) ) dfi/dx(x= L) = alf1/2 * fi(x= L) + dfi/dx(x = 0) = 0 for all i's ------------------------------------------------------------------------------------------------------------------------ Methods: * Uvalue - calculate U-value of wall * ICond - calculate steady state-temp distribution which could be served as initial conditions * ThermalCalc - Calculate heat losses (thermal flux [W/m^2]) for prescribed temp differences [C] for steady state case, temperature profilles + interface temperatures ------------------------------------------------------------------------------------------------------------------------ """ def __init__(self, input_dictionary, short_init = False ): # =============================Generate Instance for class Wallplane==================================================== self.x_lsf1 = None self.x_lsf2 = None self.f1_lsf = None self.f2_lsf = None self.lsf = False self.calc_dict = None # self.pure_f12 = False wall_type = 'plane' WallSuper.__init__(self, input_dictionary, wall_type) class_name = self.__class__.__name__ for bc_key in BC_KEYWORDS : exec ('self._' + class_name + '__beta_coeff_' + bc_key + ' = None') exec ('self._' + class_name + '__ab_coeff_' + bc_key + ' = None') exec ('self._' + class_name + '__nbeta_' + bc_key + ' = None') exec ('self.d10_coeff_' + bc_key + ' = None') exec ('self.d01_coeff_' + bc_key + ' = None') exec ('self.dic_coeff_' + bc_key + ' = None') exec ('self.dss10_coeff_' + bc_key + ' = None') exec ('self.dss01_coeff_' + bc_key + ' = None') exec ('self.beta_calc_' + bc_key + ' = False') @property def beta_coeff_d(self): return self.__beta_coeff_d @property def nbeta_d(self): return self.__nbeta_d @property def ab_coeff_d(self): return self.__ab_coeff_d #======================================================================================================================= @beta_coeff_d.setter def beta_coeff_d(self, new_input): self.__beta_coeff_d = new_input print ('-----------------beta_coeff_d is changed; ----------------------') @nbeta_d.setter def nbeta_d(self, new_input): self.__nbeta_d = new_input print ('-----------------nbeta_d is changed; ----------------------') @ab_coeff_d.setter def ab_coeff_d(self, new_input): self.__ab_coeff_d = new_input print ('-----------------ab_coeff_d is changed; ----------------------') #======================================================================================================================= @property def beta_coeff_n(self): return self.__beta_coeff_n @property def nbeta_n(self): return self.__nbeta_n @property def ab_coeff_n(self): return self.__ab_coeff_n #============================================ @property def beta_coeff_tq1(self): return self.__beta_coeff_tq1 @property def nbeta_tq1(self): return self.__nbeta_tq1 @property def ab_coeff_tq1(self): return self.__ab_coeff_tq1 #============================================ @property def beta_coeff_tq2(self): return self.__beta_coeff_tq2 @property def nbeta_tq2(self): return self.__nbeta_tq2 @property def ab_coeff_tq2(self): return self.__ab_coeff_tq2 #============================================ @property def beta_coeff_m0(self): return self.__beta_coeff_m0 @property def nbeta_m0(self): return self.__nbeta_m0 @property def ab_coeff_m0(self): return self.__ab_coeff_m0 #============================================ @property def beta_coeff_md1(self): return self.__beta_coeff_md1 @property def nbeta_md1(self): return self.__nbeta_md1 @property def ab_coeff_md1(self): return self.__ab_coeff_md1 #============================================ @property def beta_coeff_md2(self): return self.__beta_coeff_md2 @property def nbeta_md2(self): return self.__nbeta_md2 @property def ab_coeff_md2(self): return self.__ab_coeff_md2 #============================================ @property def beta_coeff_mn1(self): return self.__beta_coeff_mn1 @property def nbeta_mn1(self): return self.__nbeta_mn1 @property def ab_coeff_mn1(self): return self.__ab_coeff_mn1 #============================================ @property def beta_coeff_mn2(self): return self.__beta_coeff_mn2 @property def nbeta_mn2(self): return self.__nbeta_mn2 @property def ab_coeff_mn2(self): return self.__ab_coeff_mn2 #============================================ # ================================ V E R Y I M P O R T A N T========================================================== # All variables with __Double leading underscore are private variables in WallSuper and unaccesible from other # inherented clasess !!!!!! # Only way to access (get or set ) these variables is to use getters and setters method in WallSuper - parent class # ================================ V E R Y I M P O R T A N T========================================================== def __call__(self, beta_ext = None, print_results = None, fourier_coeff_only = False ): ''' The calculation of beta coefficients and A-B ciefficients which determine the eigen - functions start here A-B coefficients: ith eigen function in mth layer: f[i](x) = A[m]* Sin(beta[i]*x/sqrt(thermal_diffusion[m])) + B[m]* Cos(beta[i]*x/sqrt(thermal_diffusion[m])) f[i](x) - eigen functions, beta[i] - eigenvalues Fourier coefficients for U- functions f1(x) and f2(x) : self.d10_coeff_bc = ; self.d01_coeff_bc = Fourier coefficients for IC distribution : self.dic_coeff_bc = ; FI(x) - initial conditions Fourier coefficients for steady_state temp distribution : self.dss10_coeff_bc = ; self.dss01_coeff_bc = ''' # BeatCalc = BetaCoefficients() #---------------------diferent instancess of sublasess are pased to instance BeatCalc------------------------------------ #---------------------This is EXAMPLE of POLYMORPHISM in OOP !!!!!!!---------------------------------------------------- aa_beta = BetaWall (self.nlayer,self.xrlist,self.th_diff,self.conductivity,self.inv_th_res,self.alf1,self.alf2 ) #----------------------------------------------------------------------------------------------------------------------- beta_coeff_out = [] nbeta_out = [] ab_coeff_out = [] nbeta_list , bc_list = SuperUtil.nbeta_bc_list_util ( self.bc_wall ) class_name = self.__class__.__name__ # print ('------------------------------------------------------------------------------------------------------') # print ('class_name =', class_name) # print ('------------------------------------------------------------------------------------------------------') # sys.exit(0) for bc_i in bc_list : # self.bc_local = bc_i aa_beta.bc_beta = bc_i if beta_ext == None : print ('-------------------------------Boundary Conditions = ' + bc_i + '-----------------------------') for bc_key in BC_KEYWORDS : if bc_i == bc_key : if not fourier_coeff_only : # print ('****************************************************') # print ('self._' + class_name + '__beta_coeff_' + bc_i ) # print ('****************************************************') # sys.exit(0) exec('self._' + class_name + '__beta_coeff_' + bc_i +', self._' + class_name + '__ab_coeff_' + bc_i + '= aa_beta.betacalc( beta_ext )' ) exec('self._' + class_name + '__nbeta_' + bc_i + ' = aa_beta.nbbeta') aa_beta.orto_norm ( self ) beta_coeff_out.append( eval('self.beta_coeff_' + bc_i) ) nbeta_out.append( eval( 'self.nbeta_' + bc_i) ) ab_coeff_out.append( eval('self.ab_coeff_' + bc_i ) ) # self.f1_table # self.f2_table #------------------------Calculate Fourier coefficients for steady_state temp distribution ----------------------------- #!"£$%^&*() self.fourier_coeff(alf_par = self.alf_steady, bc = bc_i, fourier_type = 3 ) #------------------------Calculate Fourier coefficients for f1 and f2 functions ---------------------------------------- self.fourier_coeff( bc = bc_i, fourier_type = 1 ) #-------------------------Set flag beta_calc_bc_i to True, beta ans ab coefficients are successfully calculated--------- exec('self.beta_calc_' + bc_i + '= True') else : beta_coeff_temp, ab_coeff_temp = aa_beta.betacalc( beta_ext ) beta_coeff_out.append( beta_coeff_temp ) ab_coeff_out.append( ab_coeff_temp ) nbeta_out = 1 if print_results == 0 or print_results == 1 : for betaseries_i, nbeta_i, ab_coeff_i, bc_i in zip( beta_coeff_out, nbeta_out, ab_coeff_out , bc_list ) : print ('----------------------------------- Boundary Conditions = ' + bc_i + '------------------------') print('betaseries.shape = \n', betaseries_i.shape ) print ('----------------------------------------------------------------------------------------------') if print_results == 1 : print('betaseries = \n', betaseries_i ) print ('------------------------------------------------------------------------------------------') print('nbeta = \n', nbeta_i ) print ('----------------------------------------------------------------------------------------------') print('ab_coeff.shape = \n', ab_coeff_i.shape ) print ('----------------------------------------------------------------------------------------------') if print_results == 1 : print('ab_coeff = \n', ab_coeff_i ) print ('------------------------------------------------------------------------------------------') return ( beta_coeff_out, nbeta_out, ab_coeff_out , bc_list ) def lsf_calc ( self, alf_par = None, bc = None) : # , calc_dict = None # data_sol.calc_dict # bc_ext, alf_ext, listtemp_ext, temp1_ext, temp2_ext, wallpl_ext, mode, cut_fl # fx_inst = TempXFunVec ( bc, alf_par, listtemp_set, 1.0, 0.0 , self, None, False ) # 'p_lsf': p_lsf, 'm_lsf': m_lsf, 'mdl_lsf': mdl_lsf, 'ncon_lsf': ncon_lsf # data_sol.calc_dict ['p_lsf'] # data_sol.calc_dict ['m_lsf'] n_conv = int ( self.calc_dict ['ncon_lsf'] ) p_lsf = self.calc_dict ['p_lsf'] nn_line = int( 2 * self.calc_dict ['mdl_lsf'] * n_conv ) # x_lsf = np.linspace(self.xrlist[0], self.xrlist[-1], nn_line + 1) x_lsf1 = np.linspace(self.xrlist[0], self.xrlist[1], nn_line + 1) x_lsf2 = np.linspace(self.xrlist[-2], self.xrlist[-1], nn_line + 1) # print('*********************************************') # print (x_lsf1 [0], x_lsf1[-1] ) # print('*********************************************') listtemp_set = None self.lsf = False fx_inst = TempXFunVec ( bc, alf_par, listtemp_set, 1.0, 0.0 , self, None, False ) function1 = fx_inst() fx_inst.temp1_ext = 0.0 fx_inst.temp2_ext = 1.0 function2 = fx_inst() #----------------------------------------------------------------------------------------------------------------------- self.x_lsf1 = x_lsf1 self.x_lsf2 = x_lsf2 self.f1_lsf = function1 ( x_lsf1 ) f1_lsf00 = np.copy ( self.f1_lsf ) #!"£$%^&*()_+ self.f1_lsf [ : p_lsf * n_conv + 1 ] = np.zeros( p_lsf * n_conv + 1 ) # print ('*************************************************') # print ( 'x_lsf1 = ' , x_lsf1 [ p_lsf * n_conv + 1 ] ) # print ( 'x_lsf1 = ' , x_lsf1 [ p_lsf * n_conv ] ) # print ( 'self.xrlist[0] = ' , self.xrlist[0] ) # print ( 'self.xrlist[1] = ' , self.xrlist[1] ) # print ('*************************************************') # print (self.f1_lsf.shape) add_list = - self.f1_lsf[:n_conv + 1] add_list = np.flip(add_list, 0) # np.zeros(n_conv + 1 ) self.f1_lsf = np.concatenate ( ( add_list , self.f1_lsf ) ) i00 = n_conv + 1 # print (self.f1_lsf.shape) # print (i00, nn_line + 1, i00 + nn_line + 1 ) # print('*********************************************') # print (self.f1_lsf [0], self.f1_lsf[-1] ) # print (self.f1_lsf.shape, nn_line ) # print('*********************************************') self.f2_lsf = function2 ( x_lsf2 ) f2_lsf00 = np.copy ( self.f2_lsf ) #!"£$%^&*()_+ self.f2_lsf [ - (p_lsf * n_conv + 1) : ] = np.zeros( p_lsf * n_conv + 1 ) add_list = - self.f1_lsf[-(n_conv + 1) : ] add_list = np.flip(add_list, 0) self.f2_lsf = np.concatenate ( ( self.f2_lsf, add_list ) ) #----------------------------------------------------------------------------------------------------------------------- # print ('----------WALL-------------------') # print('-------------------------------------------------------------------------------------------------------') # print ( 'f1_lsf [0:10] [-10:-1] =' , self.f1_lsf[: 10] , self.f1_lsf [-10:-1] ) # print ( 'f1_lsf [0:10] [-10:-1] =' , self.f1_lsf[: 10] , self.f1_lsf [-10:-1] ) # print('-------------------------------------------------------------------------------------------------------') # print ( 'f2_lsf [0:10] [-10:-1] =' , self.f2_lsf[: 10] , self.f2_lsf [-10:-1] ) # print ( 'f2_lsf [10:20] [-20:-10] =' , self.f2_lsf[10 : 20] , self.f2_lsf [-20:-10] ) # print('-------------------------------------------------------------------------------------------------------') # print ( 'f1_lsf [120,240,360] =' , self.f1_lsf[120] , self.f1_lsf [240], self.f1_lsf [360] ) # print ( 'wallpl2.x_lsf1 [120,240,360] =' , self.x_lsf1[120] , self.x_lsf1[240] , self.x_lsf1[360] ) # print('-------------------------------------------------------------------------------------------------------') #----------------------------------------------------------------------------------------------------------------------- m = int( self.calc_dict ['m_lsf'] ) x_g = np.linspace( 0, 1 , 2 * n_conv + 1) # print ('***************************************************************************************************') # print ( 'm = ', m ) # print ('***************************************************************************************************') if m > 1 : x_g_1 = 1.0 - x_g x_g_m1 = x_g**(m-1) x_g_m = x_g_m1*x_g x_g_min1_m1 = x_g_1**(m-1) x_g_min1_m = x_g_1*x_g_min1_m1 y_gamma = m * x_g_m1 * x_g_min1_m1 y_gamma = y_gamma / (x_g_m + x_g_min1_m )**2.0 y_gamma = y_gamma /( 2 * n_conv ) elif m == 1: # print ('**************************************************************************************************') # print ( n_conv ) # print ( 1.0 / (2 * n_conv + 1) ) # print ('**************************************************************************************************') y_gamma = np.array( ( 2 * n_conv + 1 ) * [ 1.0 / (2 * n_conv + 1) ] ) # print ( y_gamma[0] ) # print ('***************************************************************************************************') # print ( y_gamma [0] ) # print ( y_gamma ) # print ( y_gamma.shape ) # print ( 2 * n_conv + 1 ) # print ( ( 2 * n_conv + 1 ) * y_gamma [0] ) # print ( ( 2 * n_conv ) * y_gamma [0] ) # print ( 1.0 / (2 * n_conv + 1) ) # print ( 1.0 / (2 * n_conv ) ) # print ( 'np.sum( y_gamma ) = ' , np.sum( y_gamma ) ) # print ( 'x_g = ', x_g ) # print ('***************************************************************************************************') for j in range ( self.calc_dict ['p_lsf'] ) : # print ( 'j = ', j ) # print ( 'self.f1_lsf.shape =' , self.f1_lsf.shape ) # print ( 'self.f2_lsf.shape =' , self.f2_lsf.shape ) f1_copy = np.zeros( nn_line + 1 ) f2_copy = np.zeros( nn_line + 1 ) for i in range (nn_line + 1 ) : if i >= n_conv and i + n_conv + 1 <= nn_line : # print ('i, n_conv, i - n_conv, i + n_conv + 1 ' , i , n_conv, i - n_conv, i + n_conv + 1 ) f1_copy[i] = np.dot (self.f1_lsf[i + i00 - n_conv : i + i00 + n_conv + 1 ], y_gamma ) f2_copy[i] = np.dot (self.f2_lsf[i - n_conv : i + n_conv + 1 ], y_gamma ) elif i < n_conv : #!"£$%^&*()_+ and i != 0 #!"£$%^&*()_+ f1_copy[i] = np.dot (self.f1_lsf[ : 2*i + 1], y_gamma [n_conv - i : n_conv + i + 1] ) f1_copy[i] = np.dot (self.f1_lsf[i + i00 - n_conv : i + i00 + n_conv + 1 ], y_gamma ) # f2_copy[i] = np.dot (self.f2_lsf[ : 2*i + 1], y_gamma [n_conv - i : n_conv + i + 1] ) f2_copy[i] = f2_lsf00[i] #!"£$%^&*()_+ elif i == 0 : #!"£$%^&*()_+ f2_copy[i] = f2_lsf00[i] elif i + n_conv + 1 > nn_line : #!"£$%^&*()_+ and i + 1 != nn_line #!"£$%^&*()_+ de_i = nn_line - i # f1_copy[i] = np.dot (self.f1_lsf[i - de_i : nn_line + 1 ], y_gamma [n_conv- de_i: n_conv + de_i + 1] ) # print (f1_lsf00.shape) # print (f1_copy.shape) # print (i, i00, i + i00) f1_copy[i] = f1_lsf00[i] #!"£$%^&*()_+ f2_copy[i] = np.dot (self.f2_lsf[i - de_i : nn_line + 1 ], y_gamma [n_conv- de_i: n_conv + de_i + 1] ) f2_copy[i] = np.dot (self.f2_lsf[i - n_conv : i + n_conv + 1 ], y_gamma ) # elif i == nn_line -1 : # f1_copy[i + i00] = f1_lsf00[i] # elif i == 0 : # print('*********************************************') # print (f1_copy [0], f1_copy [-1] ) # print (f1_copy.shape ) # print('*********************************************') self.f1_lsf = np.copy( f1_copy ) self.f2_lsf = np.copy( f2_copy ) if j != p_lsf - 1 : add_list = - f1_copy [:n_conv + 1] add_list = np.flip(add_list, 0) self.f1_lsf = np.concatenate ( ( add_list , self.f1_lsf ) ) add_list = - f2_copy [-(n_conv + 1) : ] add_list = np.flip(add_list, 0) self.f2_lsf = np.concatenate ( ( self.f2_lsf , add_list ) ) # dd_coeff_temp1 = util_beta_inst.orto_series ( self, bc, function1 ) # dd_coeff_temp2 = util_beta_inst.orto_series ( self, bc, function2 ) # function1 = fx_inst() # fx_inst.which = 2 # function2 = fx_inst() # self.f1_lsf = # self.f2_lsf = # pass self.lsf = True # self.f1_lsf = self.f1_lsf[i00 : ] # self.f2_lsf = self.f2_lsf[ : nn_line + 1] return def no_lsf_calc ( self ) : self.x_lsf1 = None self.x_lsf2 = None self.f1_lsf = None self.f2_lsf = None self.lsf = False # self.calc_dict = None return #---------------- Declaration of methods for class WallPlane------------------------------------------------------------ def flux(self, alf_par = 12, temp1=1.0, temp2=0.0): ''' Calculate thermal flux for steady state case for imput parameters temp1 and temp2 with (alf_par = True) or without (alf_par = False) bondary layer (alf1 and alf2) alf_par=True, temp1=1.0, temp2=0.0 are default values ''' if alf_par == True : alf_par = 12 elif alf_par == False : alf_par = 0 #-------------------------- Check alf_par------------------------------------------------------------------------------- assert isinstance(alf_par, int), 'The input parameter alf_par must be integer; {0:s}'.\ format (self.__class__.__name__) if not any ((alf_par == 0, alf_par == 1, alf_par == 2, alf_par == 12, )) : raise Exception ('The input parameter alf_par could be: 0 or 1 or 2 or or 12 ; {0:s}'.\ format (self.__class__.__name__)) #----------------------------------------------------------------------------------------------------------------------- assert isinstance(temp1, int) or isinstance(temp1, float),\ "The temperature temp1 must be a number; {0:s}". format (self.__class__.__name__) assert isinstance(temp2, int) or isinstance(temp2, float),\ "The temperature temp2 must be a number; {0:s}". format (self.__class__.__name__) temp1 = float(temp1) temp2 = float(temp2) if alf_par == 12 and self.uu_alf12 != None : flux = self.uu_alf12 * (temp1 - temp2) elif alf_par == 0 and self.uu_noalf != None : flux = self.uu_noalf * (temp1 - temp2) elif alf_par == 1 and self.uu_alf1 != None : flux = self.uu_alf1 * (temp1 - temp2) elif alf_par == 2 and self.uu_alf2 != None : flux = self.uu_alf2 * (temp1 - temp2) else : flux = None return flux def temp_inter(self, alf_par = 12, temp1=1.0, temp2=0.0): """" Calculate interface temperatures for N-layer plane wall in steady state case method: temp_inter(self, alf_par=True, temp1=1, temp2=0) method: uvalue(self, alf_par=1): alf_par = False the convection in boundary layers and transfer coefficinets alf1,2 are not considered temp1 & temp2 interior and exterior temperatures with default values 1 and 0 respectively """ if alf_par == True : alf_par = 12 elif alf_par == False : alf_par = 0 #-------------------------- Check alf_par------------------------------------------------------------------------------- assert isinstance(alf_par, int), 'The input parameter alf_par must be integer; {0:s}'.\ format (self.__class__.__name__) if not any ((alf_par == 0, alf_par == 1, alf_par == 2, alf_par == 12, )) : raise Exception ('The input parameter alf_par could be: 0 or 1 or 2 or or 12 ; {0:s}'.\ format (self.__class__.__name__)) #----------------------------------------------------------------------------------------------------------------------- assert isinstance(temp1, int) or isinstance(temp1, float),\ "The temperature temp1 must be a number; {0:s}". format (self.__class__.__name__) assert isinstance(temp2, int) or isinstance(temp2, float),\ "The temperature temp2 must be a number; {0:s}". format (self.__class__.__name__) temp1 = float(temp1) temp2 = float(temp2) if alf_par == 12 : temp10, temp01 = self.temp10_alf12, self.temp01_alf12 elif alf_par == 1 : temp10, temp01 = self.temp10_alf1, self.temp01_noalf elif alf_par == 2 : temp10, temp01 = self.temp10_noalf, self.temp01_alf2 elif alf_par == 0 : temp10, temp01 = self.temp10_noalf, self.temp01_noalf temp_out = [] for temp10_loc, temp01_loc in zip( temp10 , temp01): temp_out.append(temp1 * temp10_loc + temp2 * temp01_loc) return temp_out def tempx(self, x, bc , alf_par = 12, listtemp = None , temp1 = None , temp2 = None, mode = None, cut_fl = False ): """ Calculate steady state temperature at position x inside the planar wall x - coordinate at which the tenperature is calculated listtemp - the temperatures at interfaces temp1,2 - Internal and Extrnal temperatures, 1 & 0 are default values """ # type_unit = 'steady_temp' if alf_par == True : alf_par = 12 elif alf_par == False : alf_par = 0 #-------------------------- Check alf_par------------------------------------------------------------------------------- assert isinstance(alf_par, int), 'The input parameter alf_par must be integer; {0:s}'.\ format (self.__class__.__name__) if not any ((alf_par == 0, alf_par == 1, alf_par == 2, alf_par == 12, )) : raise Exception ('The input parameter alf_par could be: 0 or 1 or 2 or or 12 ; {0:s}'.\ format (self.__class__.__name__)) #-------------------------- Check alf_par------------------------------------------------------------------------------- if (all ((temp1 != None , temp2 != None))) : assert isinstance(temp1, int) or isinstance(temp1, float),\ "The temperature temp1 must be a number; {0:s}". format (self.__class__.__name__) assert isinstance(temp2, int) or isinstance(temp2, float),\ "The temperature temp2 must be a number; {0:s}". format (self.__class__.__name__) temp1 = float(temp1) temp2 = float(temp2) if all ((listtemp != None , temp1 == None , temp2 == None)) : pass elif all ((listtemp == None , temp1 != None , temp2 != None, alf_par != None)) : listtemp = self.temp_inter(alf_par, temp1, temp2) else: raise Exception('wrong input parameters, listtemp OR temp1&temp2 is required {0:s}'. format(self.__class__.__name__)) listtemp = check_number_list ( listtemp )[0] eq_flag = check_number_list ( listtemp )[1] if not eq_flag : if len(listtemp) == self.nlayer + 3: alf_par = 12 elif len(listtemp) == self.nlayer + 1: alf_par = 0 else: raise Exception('lenght of listtemp and number of layers are not consistent !!!!') tempx_out = tempxfun (x, self, bc, None, mode , listtemp, alf_par, cut_fl, steady = True ) else : tempx_out = listtemp[0] return tempx_out #---------------- Uf12 functions---------------------------------------------------------------------------------------- def uf12x (self, x, bc_ext, which = 1, mode = None, cut_fl = False ): ''' Calculate U-functiuons f1(x) 7 f2(x) for different BC The final calculations are performed in function tempxfun in module wall_fun -> package utils ''' if bc_ext == BC_KEYWORDS[0]: alf_par = 0 if which == 1 : listtemp = self.temp_inter(alf_par, 1.0, 0.0) else : listtemp = self.temp_inter(alf_par, 0.0, 1.0) elif bc_ext == BC_KEYWORDS[4]: alf_par = 12 if which == 1 : listtemp = self.temp_inter(alf_par, 1.0, 0.0) else : listtemp = self.temp_inter(alf_par, 0.0, 1.0) else : alf_par = None listtemp = None # print ('listtemp = ', listtemp ) # print ('bc_ext, which, alf_par = ', bc_ext, which, alf_par) u_tq_out = tempxfun (x, self, bc_ext, which, mode, listtemp, alf_par, cut_fl ) return u_tq_out def eigen_fun(self, x , bc = None, index = None, mode = None): ''' Eigen functions, mode - different modes mode: - 'temp' eigen functions fi(x) - 'flux' - thermal conductivity * df(x)/dx - 'deriv' df/dx - 'fseries' density * specific heat * fi(x) ''' if any ((bc == None, index == None)) : print ('bc, index, mode = ', bc, index ) raise Exception ('Input parameters bc, norm and index are not inicialized !!!!!, {0:s}'. format(self.__class__.__name__)) # bc = self.bc_local if index > eval ('self.beta_coeff_' + bc + '.shape[0]') : print('index, bc = ', index, bc) raise Exception('wrong input parameter index, must be less or equal to beta_coeff_d.size, {0:s}'. format(self.__class__.__name__)) # print ('x =', x) assert isinstance(x, int) or isinstance(x, float), 'x must be number' x = float(x) if x <= 0 and x >= self.xrlist[-1] + EPSILOC12: print ('x , self.xrlist[-1] = ', x , self.xrlist[-1]) raise Exception('x must be in range 0 <= x <= L, {0:s}'. format(self.__class__.__name__)) assert (isinstance(index, int) or isinstance(index, np.int64) ),'index must be integer' if index > eval ('self.beta_coeff_' + bc + '.shape[0]') - 1 : print ('bc = ', bc) print ('index = ', index) print ('self.beta_coeff_bc.shape[0] = ', eval ('self.beta_coeff_' + bc + '.shape[0]') - 1) raise Exception('wrong input parameter index, musr be less or equal to beta_coeff_d.size {0:s}'. format(self.__class__.__name__)) if all ((bc != bc_i for bc_i in BC_KEYWORDS)) : raise Exception('wrong input parameter bc, must be in BC_KEYWORDS {0:s}'. format(self.__class__.__name__)) if all ((mode != 'temp', mode != 'flux', mode != 'deriv', mode != 'fseries', mode != None )) : raise Exception('input parameter mode could be only temp, flux, deriv, fseries or None {0:s}'. format(self.__class__.__name__)) xrlist = self.xrlist y = None for i, x1, x2 in zip ( range(len(xrlist)), xrlist, xrlist[1:] ) : if (x1 <= x < x2) or ( abs (x1 - xrlist[0]) <= EPSILOC12 and x1 - EPSILOC12 <= x < x2 )\ or ( abs ( x2 - xrlist[-1] ) <= EPSILOC12 and x1 <= x <= x2 + EPSILOC12 ) : aa = eval ('self.ab_coeff_' + bc + '[index, 2 * i]') bb = eval ('self.ab_coeff_' + bc + '[index, 2 * i + 1]') kk = eval ('self.beta_coeff_' + bc + '[index]')/ np.sqrt(self.th_diff[i]) if mode == 'temp' or mode == None : y = aa * np.sin(kk * x) + bb * np.cos(kk * x) elif mode == 'flux' : y = - self.conductivity[i] * kk * ( aa * np.cos(kk * x) - bb * np.sin(kk * x) ) elif mode == 'deriv' : y = (aa * kk * np.cos(kk * x) - bb * kk* np.sin(kk * x) ) elif mode == 'fseries' : y = self.specheat[i] * self.density[i] * (aa * np.sin(kk * x) + bb * np.cos(kk * x) ) break if y == None : print ( x ) raise Exception('The calcullation is failed, {0:s} '. format(self.__class__.__name__)) return y def orto_gon(self, bc = None, norm = None, index = None ): ''' Up-date ab_coefficients after ortogonalization ''' #----------------------------This method perform ortogonalization of eigen-value functions ----------------------------- #=====================================Here eval DOES NOT WORK !!!!!!!=================================================== # bc = self.bc_local if any((bc == None, norm == None, index == None)) : raise Exception ('Input parameters bc, norm and index are not inicialized !!!!!, {0:s}'. format(self.__class__.__name__)) class_name = self.__class__.__name__ for bc_key in BC_KEYWORDS : if bc == bc_key : exec('self._' + class_name + '__ab_coeff_' + bc + '[index,:] = self._' + class_name + '__ab_coeff_' + bc + '[index,:] / norm') #=====================================Here eval DOES NOT WORK !!!!!!!=================================================== def fourier_coeff (self, alf_par = None, bc = None , function = None, fourier_type = None ): ''' * Calculate the Fourier coefficinets for augmented functions f1(x) and f2(2) (U(x,t) = f1(x) * Ts1 or qs1 (t) + f1(x) * Ts1 or qs1 (t) ) fourier_type = 1 * Calculate the Fourier coefficinets for the initial condition IC (temperature distribution at t = 0) fourier_type = 2 * Calculate the Fourier coefficinets for the steady state temperature distribution fourier_type = 3 * 'function' - function f(x) for which fourier coefficients are calculated the ortogonal function set belongs to coresponding boundary conditions (each set of eigen functions corresponds to different Boundary Conditions ) Using fun_type parameter some standard initial condition could be used ''' if all ((bc != bc_i for bc_i in BC_KEYWORDS)) : raise Exception('wrong input parameter bc, must be in BC_KEYWORDS {0:s}'.format(self.__class__.__name__)) if fourier_type == None : raise Exception ('Input parameter fourier_type is not inicialized !!! , {0:s}'. format(self.__class__.__name__)) if (alf_par != None) : if alf_par == True : alf_par = 12 elif alf_par == False : alf_par = 0 #-------------------------- Check alf_par------------------------------------------------------------------------------- assert isinstance(alf_par, int), 'The input parameter alf_par must be integer; {0:s}'.\ format (self.__class__.__name__) if not any ((alf_par == 0, alf_par == 1, alf_par == 2, alf_par == 12, )) : raise Exception ('The input parameter alf_par could be: 0 or 1 or 2 or or 12 ; {0:s}'. format (self.__class__.__name__)) #-------------------------- Check alf_par------------------------------------------------------------------------------- util_beta_inst = UtilBeta() if fourier_type == 1 : fx_inst = Uf12XFun (bc, 1, self, None, self.cut_fl ) function1 = fx_inst() fx_inst.which = 2 function2 = fx_inst() # print ('check_01') dd_coeff_temp1 = util_beta_inst.orto_series ( self, bc, function1, f12 = 1 ) dd_coeff_temp2 = util_beta_inst.orto_series ( self, bc, function2, f12 = 2 ) elif fourier_type == 2 : dd_coeff_temp1 = util_beta_inst.orto_series ( self, bc, function, f12 = 1 ) elif fourier_type == 3 : listtemp_set = None fx_inst = TempXFun ( bc, alf_par, listtemp_set, 1.0, 0.0 , self, None, self.cut_fl ) function1 = fx_inst() fx_inst.temp1_ext = 0.0 fx_inst.temp2_ext = 1.0 function2 = fx_inst() dd_coeff_temp1 = util_beta_inst.orto_series ( self, bc, function1, f12 = 1 ) dd_coeff_temp2 = util_beta_inst.orto_series ( self, bc, function2, f12 = 2 ) for bc_key in BC_KEYWORDS : if bc == bc_key : if fourier_type == 1 : #----------------------------------------------------------------------------------------------------------------------- exec('self.d10_coeff_' + bc + ' = dd_coeff_temp1') exec('self.d01_coeff_' + bc + ' = dd_coeff_temp2') #----------------------------------------------------------------------------------------------------------------------- exec('self.dss10_coeff_' + bc + ' = dd_coeff_temp1') exec('self.dss01_coeff_' + bc + ' = dd_coeff_temp2') #----------------------------------------------------------------------------------------------------------------------- elif fourier_type == 2 : #----------------------------------------------------------------------------------------------------------------------- exec('self.dic_coeff_' + bc + ' = dd_coeff_temp1') #----------------------------------------------------------------------------------------------------------------------- elif fourier_type == 3 : #----------------------------------------------------------------------------------------------------------------------- exec('self.dss10_coeff_' + bc + ' = dd_coeff_temp1') exec('self.dss01_coeff_' + bc + ' = dd_coeff_temp2') #----------------------------------------------------------------------------------------------------------------------- return class WallCylSpher(WallSuper): # ========================Generate Instance for class WallCylSpher===================================== def __init__(self, input_dictionary, wall_type): WallSuper.__init__(self, input_dictionary, wall_type) """ Class WallPlane, this class in inherited from WallSuper Attributes of class Instances containes all thermal and geomatrical parameters of N-layer planar wall Quantites on the input of the instances (Attributes): * list1 - layer thickesses * list2 - thermal conductivites * list3 - densities * list4 - specific heats * wall_type - type of the wall, for this instances it is 'plane' * n_layer - number of layers * alf1 - Interior heat transfer coefficients * alf2 - Exterior heat transfer coefficients Methods: * Uvalue - calculate U-value of wall * ICond - calculate steady state-temp distribution which could be served as initial conditions * ThermalCalc - Calculate heat losses (thermal flux [W/m^2]) for prescribed temp differences [C] for steady state case, temperature profilles + interface temperatures """ def ur_value(self, alf_par=1): pass def flux(self, alf_par=1, temp1=1.0, temp2=0.0): pass def temp_inter(self, alf_par=True, temp1=1.0, temp2=0.0): pass def tempx(self, x, listtemp, temp1=1.0, temp2=0.0): pass def __betalist(self, beta): pass # def __call__(self, BC = None): # pass def icond(self): pass #--------------- Super class for Dynamical Simulation------------------------------------------------------------------- class WallDynamicplane (object) : pass class WallDynamicCylSpher (object) : pass