def solve_stokesTimeDep(method=None, Omega=None, tE=None, Prec=None, N=None, NtsList=None, LinaTol=None, MaxIter=None, UsePreTStps=None, SaveTStps=None, SaveIniVal=None ): """system to solve du\dt - lap u + grad p = fv div u = fp """ if N is None: N = 20 if method is None: method = 2 if Omega is None: Omega = 3 methdict = { 1:'HalfExpEulSmaMin', 2:'HalfExpEulInd2', 3:'Heei2Ra'} # instantiate object containing mesh, V, Q, rhs, velbcs, invinds PrP = ProbParams(N,Omega) # instantiate the Time Int Parameters TsP = TimestepParams(methdict[method], N) if NtsList is not None: TsP.Ntslist = NtsList if LinaTol is not None: TsP.linatol = LinaTol if MaxIter is not None: TsP.MaxIter = MaxIter if tE is not None: TsP.tE = tE if Omega is not None: TsP.Omega = Omega if SaveTStps is not None: TsP.SaveTStps = SaveTStps if UsePreTStps is not None: TsP.UsePreTStps = UsePreTStps if SaveIniVal is not None: TsP.SaveIniVal = SaveIniVal print 'Mesh parameter N = %d' % N print 'Time interval [%d,%1.2f]' % (TsP.t0, TsP.tE) print 'Omega = %d' % TsP.Omega print 'You have chosen %s for time integration' % methdict[method] print 'The tolerance for the linear solver is %e' %TsP.linatol # get system matrices as np.arrays Ma, Aa, BTa, Ba, MPa = dtn.get_sysNSmats(PrP.V, PrP.Q) fv, fp = dtn.setget_rhs(PrP.V, PrP.Q, PrP.fv, PrP.fp) # condense the system by resolving the boundary values Mc, Ac, BTc, Bc, fvbc, fpbc, bcinds, bcvals, invinds = \ dtn.condense_sysmatsbybcs(Ma,Aa,BTa,Ba,fv,fp,PrP.velbcs) if method != 2: # Rearrange the matrices and rhs from smamin_utils import col_columns_atend from scipy.io import loadmat MSmeCL, BSme, B2Inds, B2BoolInv, B2BI = smartminex_tayhoomesh.get_smamin_rearrangement(N,PrP,Mc,Bc) FvbcSme = np.vstack([fvbc[~B2BoolInv,],fvbc[B2BoolInv,]]) FpbcSme = fpbc PrP.Pdof = 0 # Thats how the smamin is constructed # inivalue dname = 'IniValSmaMinN%s' % N try: IniV = loadmat(dname) qqpq_init = IniV['qqpq_old'] vp_init = None except IOError: qqpq_init = None ### Output try: os.chdir('json') except OSError: raise Warning('need "json" subdirectory for storing the data') os.chdir('..') if TsP.ParaviewOutput: os.chdir('results/') for fname in glob.glob(TsP.method + '*'): os.remove( fname ) os.chdir('..') ### # Time stepping ### # starting value dimredsys = len(fvbc)+len(fp)-1 vp_init = np.zeros((dimredsys,1)) for i, CurNTs in enumerate(TsP.Ntslist): TsP.Nts = CurNTs if method == 2: tis.halfexp_euler_nseind2(Mc,MPa,Ac,BTc,Bc,fvbc,fpbc, vp_init,PrP,TsP) elif method == 1: tis.halfexp_euler_smarminex(MSmeCL,BSme,MPa,FvbcSme,FpbcSme, B2BoolInv,PrP,TsP,vp_init,qqpq_init=qqpq_init) elif method == 3: tis.halfexp_euler_ind2ra(MSmeCL,BSme,MPa,FvbcSme,FpbcSme, vp_init,B2BoolInv,PrP,TsP) # Output only in first iteration! TsP.ParaviewOutput = False JsD = save_simu(TsP, PrP) return
def solve_euler_timedep(method=1, Omega=8, tE=None, Prec=None, N=40, NtsList=None, LinaTol=None, MaxIter=None, UsePreTStps=None, SaveTStps=None, SaveIniVal=None, scheme='TH', nu=0, Re=None, inikryupd=None, tolcor=False, prob=None): """system to solve du\dt + (u*D)u + grad p = fv div u = fp """ methdict = { 1: 'HalfExpEulSmaMin', 2: 'HalfExpEulInd2'} # instantiate object containing mesh, V, Q, rhs, velbcs, invinds # set nu=0 for Euler flow if prob == 'cyl': femp, stokesmatsc, rhsd_vfrc, rhsd_stbc \ = dnsps.get_sysmats(problem='cylinderwake', N=N, Re=Re, scheme=scheme) Mc, Ac = stokesmatsc['M'], stokesmatsc['A'] MPa = stokesmatsc['MP'] BTc, Bc = stokesmatsc['JT'], stokesmatsc['J'] Ba = stokesmatsc['Jfull'] # bcinds, bcvals = femp['bcinds'], femp['bcvals'] fvbc, fpbc = rhsd_stbc['fv'], rhsd_stbc['fp'] inivdict = dict(A=Ac, J=Bc, JT=BTc, M=Mc, ppin=None, V=femp['V'], Q=femp['Q'], fv=fvbc, fp=fpbc, vel_pcrd_stps=0, vel_nwtn_stps=0, return_vp=True, diribcs=femp['diribcs'], invinds=femp['invinds']) dimredsys = Bc.shape[1] + Bc.shape[0] vp_init = snu.solve_steadystate_nse(**inivdict)[0] PrP = FempToProbParams(N, omega=Omega, femp=femp, pdof=None) PrP.Pdof = None # No p pinning for outflow flow print 'Nv, Np -- w/o boundary nodes', BTc.shape else: if Re is not None: nu = 1./Re PrP = ProbParams(N, omega=Omega, nu=nu, scheme=scheme) # get system matrices as np.arrays smts = dts.get_stokessysmats(PrP.V, PrP.Q, nu=nu) rhsvecs = dts.setget_rhs(PrP.V, PrP.Q, PrP.fv, PrP.fp) # Ma, Aa, BTa, Ba = smts['A'], smts['JT'], smts['J'] # MPa = smts['MP'] # Ma, Aa, BTa, Ba, MPa = dtn.get_sysNSmats(PrP.V, PrP.Q, nu=nu) # fv, fp = rhsvecs['fv'], rhsvecs['fp'] # fv, fp = dtn.setget_rhs(PrP.V, PrP.Q, PrP.fv, PrP.fp) print 'Nv, Np -- w/ boundary nodes', smts['BTa'].shape # condense the system by resolving the boundary values # (Mc, Ac, BTc, Bc, fvbc, fpbc, bcinds, bcvals, # invinds) = dtn.condense_sysmatsbybcs(Ma, Aa, BTa, Ba, smts.update(rhsvecs) smtsc = dts.condense_sysmatsbybcs(smts, PrP.velbcs) Mc, Ac, BTc, Bc = smtsc['Mc'], smtsc['Ac'], smtsc['BTc'], smtsc['Bc'] fvbc, fpbc = smtsc['fvbc'], smtsc['fpbc'] # invinds print 'Nv, Np -- w/o boundary nodes', BTc.shape PrP.Pdof = 0 # Thats how the smamin is constructed dimredsys = Bc.shape[0] + Bc.shape[1] # TODO: this should sol(0) vp_init = np.zeros((dimredsys, 1)) # instantiate the Time Int Parameters TsP = TimestepParams(methdict[method], N, scheme=scheme) if NtsList is not None: TsP.Ntslist = NtsList if LinaTol is not None: TsP.linatol = LinaTol if MaxIter is not None: TsP.MaxIter = MaxIter if tE is not None: TsP.tE = tE if Omega is not None: TsP.Omega = Omega if SaveTStps is not None: TsP.SaveTStps = SaveTStps if UsePreTStps is not None: TsP.UsePreTStps = UsePreTStps if SaveIniVal is not None: TsP.SaveIniVal = SaveIniVal if inikryupd is not None: TsP.inikryupd = inikryupd TsP.TolCorB = tolcor print 'Mesh parameter N = %d' % N print 'Time interval [%d,%1.2f]' % (TsP.t0, TsP.tE) print 'Omega = %d' % TsP.Omega print 'You have chosen %s for time integration' % methdict[method] print 'The tolerance for the linear solver is %e' % TsP.linatol print 'tolcor -- controlling the abs residuals -- is ', tolcor if method == 1: # Rearrange the matrices and rhs # from smamin_utils import col_columns_atend from scipy.io import loadmat if prob == 'cyl' and scheme == 'CR': if N == 0: cricell = 758 elif N == 1: cricell = 1498 elif N == 2: cricell = 2386 elif N == 3: cricell = 4843 else: raise NotImplementedError() # TODO: this is hard coded... # dptatnb = dolfin.Point(2.2, 0.2) # cricell = smt.get_cellid_nexttopoint(PrP.mesh, dptatnb) elif prob == 'cyl': raise NotImplementedError() else: cricell = None MSmeCL, ASmeCL, BSme, B2Inds, B2BoolInv, B2BI = smt.\ get_smamin_rearrangement(N, PrP, M=Mc, A=Ac, B=Bc, crinicell=cricell, addnedgeat=cricell, scheme=scheme, fullB=Ba) FvbcSme = np.vstack([fvbc[~B2BoolInv, ], fvbc[B2BoolInv, ]]) FpbcSme = fpbc # inivalue dname = 'IniValSmaMinN%s' % N try: IniV = loadmat(dname) qqpq_init = IniV['qqpq_old'] vp_init = None except IOError: qqpq_init = None # Output try: os.chdir('json') except OSError: raise Warning('need "json" subdirectory for storing the data') os.chdir('..') if TsP.ParaviewOutput: os.chdir('results/') for fname in glob.glob(TsP.method + scheme + '*'): os.remove(fname) os.chdir('..') # ## Time stepping ## # for i, CurNTs in enumerate(TsP.Ntslist): TsP.Nts = CurNTs if method == 2: tis.halfexp_euler_nseind2(Mc, MPa, Ac, BTc, Bc, fvbc, fpbc, PrP, TsP, vp_init=vp_init) elif method == 1: tis.halfexp_euler_smarminex(MSmeCL, ASmeCL, BSme, MPa, FvbcSme, FpbcSme, B2BoolInv, PrP, TsP, qqpq_init=qqpq_init, vp_init=vp_init) # Output only in first iteration! TsP.ParaviewOutput = False save_simu(TsP, PrP) return