Exemplo n.º 1
0
 def test_extend_scalararray(self):
     flist = field.fieldlist()
     f1 = field.fdata(self.convmodel, self.curmesh, [1.])
     flist.append(f1)
     f2 = f1.copy()
     f2.set_time(10.)
     flist.append(f2)
     newlist = field.fieldlist()
     f3 = f2.copy()
     newlist.append(f3)
     f3.set_time(20.)
     newlist.append(f2)
     flist.extend(newlist)
     f2.reset(t=100., it=5)
     assert len(flist) == 4  # f1, f2, f3, f2
     assert flist.time_array() == [0., 100., 20., 100.]
     assert flist.it_array() == [-1, 5, -1, 5]
Exemplo n.º 2
0
 def test_append_scalararray(self):
     flist = field.fieldlist()
     f1 = field.fdata(self.convmodel, self.curmesh, [1.])
     flist.append(f1)
     f2 = f1.copy()
     f2.set_time(10.)
     flist.append(f2)
     assert len(flist) == 2
     assert flist[0].time == 0.
     assert flist[-1].time == 10.
     assert flist.time_array() == [0., 10.]
Exemplo n.º 3
0
    def test_flist_plotxtcontourf(self):
        def fn(x, t):
            return np.exp(-2 * np.square(x - .5 + .2 * np.sin(10 * t)))

        times = np.linspace(0., 5., 11, endpoint=True)
        flist = field.fieldlist()
        for t in times:
            f = field.fdata(self.convmodel, self.curmesh,
                            [fn(self.curmesh.centers(), t)])
            f.set_time(t)
            flist.append(f)
        fig, ax = plt.subplots(1, 1)
        flist.xtcontourf('q')
        return fig
Exemplo n.º 4
0
    def _solve(self, f, condition, tsave, stop, flush, monitors, directives):
        """Solve dQ/dt=RHS(Q,t)

        Args:
          f: initial field
          condition: CFL number
          tsave: array/list of time to save
          flush:  (Default value = None)

        Returns:
          list of solution fields (size of tsave)
        """
        self._time = f.time
        # directives
        verbose = 'verbose' in directives.keys()
        #
        self.condition = condition
        # default stopping criterion
        stopcrit = { 'tottime': tsave[-1] } if len(tsave)>0 else {}
        if stop is not None: stopcrit.update(stop)
        if not stopcrit:
            raise ValueError("missing stopping criteria")
        # default monitors
        monitors = { **self.monitors, **monitors }
        # initialization before loop
        self.Qn = f.copy()
        if flush:
            alldata = [d for d in self.Qn.data]
        results = field.fieldlist()
        start = myclock()
        isave, nsave = 0, len(tsave)
        # loop testing all ending criteria
        checkend = self._check_end(stopcrit)
        self._parse_monitors(monitors)
        # find first time to save if exists
        while (isave < nsave) and (self.Qn.time > tsave[isave]):
            isave += 1
        # MAIN LOOP
        while not checkend:
            dtloc = self.modeldisc.calc_timestep(self.Qn, condition)
            mindtloc = min(dtloc)
            Qnn = self.Qn.copy()
            if isave < nsave: # specific step to save result and go back to Qn
                if self.Qn.time+mindtloc >= tsave[isave]:
                    # compute smaller step with same integrator
                    self.step(Qnn, tsave[isave]-self.Qn.time)
                    Qnn.it = self._itstart + self._nit
                    results.append(Qnn)
                    if verbose:
                        print("save state at it {:5d} and time {:6.2e}".format(self._nit, Qnn.time))
                    isave += 1
                    # step back to self.Qn
                    Qnn = self.Qn.copy()
            self.step(Qnn, mindtloc)
            self.Qn = Qnn
            self._nit += 1
            self._time = self.Qn.time
            self._parse_monitors(monitors)
            if flush:
                for i, q in zip(range(len(alldata)), self.Qn.data):
                    alldata[i] = np.vstack((alldata[i], q))
            checkend = self._check_end(stopcrit)
            # save at least current state
            if checkend and len(results)==0:
                results.append(self.Qn)
        self._cputime = myclock() - start
        if flush:
            np.save(flush, alldata)
        return results