示例#1
0
 def compute_sol(self, stop, monitors):
     rhs = modeldisc.fvm(self.eulermodel,
                         self.mesh50,
                         self.xsch,
                         bcL=self.bcL,
                         bcR=self.bcR)
     finit = rhs.fdata_fromprim([1., 0., 1.])  # rho, u, p
     solver = tnum.rk4(self.mesh50, rhs)
     fsol = solver.solve(finit, self.cfl, stop=stop, monitors=monitors)
     return fsol
示例#2
0
 def test_checkend_maxit_noendtime(self):
     endtime = 5.
     cfl = .5
     maxit = 100
     stop_directive = {'maxit': maxit}
     finit = field.fdata(self.convmodel, self.curmesh,
                         [self.init_sinperk(self.curmesh, k=4)])
     rhs = modeldisc.fvm(self.convmodel, self.curmesh, self.xsch)
     solver = tnum.rk4(self.curmesh, rhs)
     fsol = solver.solve(finit, cfl, stop=stop_directive)
     assert len(fsol) == 1  # end before expected by tsave
     assert not fsol[-1].isnan()
     assert solver.nit() == 100
示例#3
0
 def test_checkend_tottime(self):
     endtime = 5.
     cfl = .5
     stop_directive = {'tottime': endtime}
     finit = field.fdata(self.convmodel, self.curmesh,
                         [self.init_sinperk(self.curmesh, k=4)])
     rhs = modeldisc.fvm(self.convmodel, self.curmesh, self.xsch)
     solver = tnum.rk4(self.curmesh, rhs)
     nsol = 11
     tsave = np.linspace(0, 2 * endtime, nsol, endpoint=True)
     fsol = solver.solve(finit, cfl, tsave, stop=stop_directive)
     assert len(fsol) < nsol  # end before expected by tsave
     assert not fsol[-1].isnan()
     assert fsol[-1].time < 2 * endtime
示例#4
0
 def test_interpolation_regression(self):
     endtime = 5
     cfl = .5
     finit = field.fdata(self.convmodel, self.curmesh,
                         [self.init_sinperk(self.curmesh, k=4)])
     rhs = modeldisc.fvm(self.convmodel, self.curmesh, self.xsch)
     solver = tnum.rk4(self.curmesh, rhs)
     nsol = 5
     tsave = np.linspace(0, endtime, nsol, endpoint=True)
     fsol = solver.solve(finit, cfl, tsave)
     fleg = solver.solve_legacy(finit, cfl, tsave)
     assert len(fsol) == nsol
     assert len(fleg) == nsol
     for fs, fl in zip(fsol, fleg):
         assert not fs.isnan()
         diff = fs.diff(fl)
         assert diff.time == pytest.approx(0., abs=1.e-12)
         for d in diff.data:
             assert np.average(np.abs(d)) == pytest.approx(0., abs=1.e-6)
示例#5
0
 def test_frequency(self, montype):
     endtime = 5.
     cfl = .5
     finit = field.fdata(self.convmodel, self.mesh50,
                         [self.init_sinperk(self.mesh50, k=4)])
     rhs = modeldisc.fvm(self.convmodel, self.mesh50, self.xsch)
     maxit = 500
     stop_directive = {'maxit': maxit}
     solver = tnum.rk4(self.mesh50, rhs)
     mondict = {}
     for f in 1, 2, 10, 50, 100:
         monitors = {montype: {'frequency': f}}
         fsol = solver.solve(finit,
                             cfl, [endtime],
                             stop=stop_directive,
                             monitors=monitors)
         mondict[f] = monitors[montype]['output']
         assert not fsol[-1].isnan()
         assert mondict[f]._it[-1] == maxit
         assert (len(mondict[f]._it) - 1) * f == maxit
示例#6
0
 def test_restart(self):
     tottime = 10.
     breaktime = 5.
     cfl = .5
     finit = field.fdata(self.convmodel, self.curmesh,
                         [self.init_sinperk(self.curmesh, k=4)])
     rhs = modeldisc.fvm(self.convmodel, self.curmesh, self.xsch)
     solver = tnum.rk4(self.curmesh, rhs)
     nsol = 10 + 1  # every second
     tsave = np.linspace(0, tottime, nsol, endpoint=True)
     #
     stop_directive = {'tottime': breaktime}
     fsol0 = solver.solve(finit, cfl, tsave, stop=stop_directive)
     assert len(fsol0) == 6  # end before expected by tsave
     assert not fsol0[-1].isnan()
     assert fsol0[-1].time == breaktime
     #
     fsol = solver.restart(fsol0[-1], cfl, tsave)
     assert len(fsol) == 6  # only last snapshots ; time 5. is saved again
     assert not fsol[-1].isnan()
     assert fsol[-1].time == tottime
import flowdyn.modelphy.euler as euler
import flowdyn.modeldisc      as modeldisc
#import flowdyn.solution.euler_riemann as sol

nx = 100
ny = 100

meshsim  = mesh2d.unimesh(nx, ny)

model = euler.euler2d()

#bcL = { 'type': 'insub',  'ptot': 1.4, 'rttot': 1. }
bcR = { 'type': 'outsub', 'p': 1. }

rhs = modeldisc.fvm2d(model, meshsim, num=None, numflux='centered', bclist={} )
solver = integ.rk4(meshsim, rhs)

# computation
#
endtime = 5.
cfl     = 2.

# initial functions
def fuv(x,y):
    vmag = .01 ; k = 10.
    return euler.datavector(0.*x+.4, 0.*x+.2)
def fp(x,y): # gamma = 1.4
    return 0.*x+1.
def frho(x,y):
    return 1.4 * (1.+.5*np.exp(-((x-.5)**2+(y-.5)**2)/(.1)**2))
示例#8
0
import flowdyn.integration as tnum


curmesh = mesh.unimesh(ncell=50, length=1.)
convmodel = conv.model(convcoef=1.)

def init_sinperk(mesh, k):
    return np.sin(2*k*np.pi/mesh.length*mesh.centers())

xsch = xnum.extrapol3()

tottime = 10.
breaktime = 5.
cfl     = .5
finit = field.fdata(convmodel, curmesh, [ init_sinperk(curmesh, k=4) ] )
rhs = modeldisc.fvm(convmodel, curmesh, xsch)
solver = tnum.rk4(curmesh, rhs)
nsol = 10+1 # every second
tsave = np.linspace(0, tottime, nsol, endpoint=True)
#
stop_directive = { 'tottime': breaktime }
fsol0 = solver.solve(finit, cfl, tsave, stop=stop_directive)
assert len(fsol0) < nsol # end before expected by tsave
assert not fsol0[-1].isnan()
assert fsol0[-1].time == breaktime
#
stop_directive = { 'tottime': tottime }
fsol = solver.restart(fsol0[-1], cfl, tsave, stop=stop_directive, directives={'verbose':1})
print(len(fsol),nsol) # only last snapshots
assert not fsol[-1].isnan()
assert fsol[-1].time == tottime