def getframe(self, frameno, outdir=None): """ ClawPlotData.getframe: Return an object of class Solution containing the solution for frame number frameno. If self.refresh_frames == True then this frame is read from the fort files, otherwise it is read from the fort files only if the the dictionary self.framesoln_dict has no key frameno. If it does, the frame has previously been read and the dictionary value is returned. """ from clawpack.pyclaw import solution framesoln_dict = self.framesoln_dict if 0: if outdir: key = (frameno, outdir) else: key = frameno outdir = self.outdir if outdir is None: outdir = self.outdir outdir = os.path.abspath(outdir) key = (frameno, outdir) if self.refresh_frames or (not framesoln_dict.has_key(key)): try: framesoln = solution.Solution(frameno, path=outdir, file_format=self.format) except: print '*** Error reading frame in ClawPlotData.getframe' raise return if not self.save_frames: framesoln_dict.clear() framesoln_dict[key] = framesoln if key != frameno: print ' Reading Frame %s at t = %g from outdir = %s' \ % (frameno,framesoln.t,outdir) else: print ' Reading Frame %s at t = %g ' \ % (frameno,framesoln.t) else: framesoln = self.framesoln_dict[key] return framesoln
def check_frame(self, save=False, indices=[0], frame_num=1, file_name="regression_data.txt", rtol=1e-14, atol=1e-08, tolerance=None): r"""Compare choosen frame to the comparison data :Input: - *save* (bool) - If *True* will save the output from this test to the file *regresion_data.txt*. Default is *False*. - *indices* (tuple) - Contains indices to compare in the gague comparison. Defaults to *(0)*. - *frame_num* (int) - Frame number to load from the run data. Defaults to *1*. - *regression_data_path* (path) - Path to the regression test data. Defaults to 'regression_data.txt'. - *rtol* (float) - Relative tolerance used in the comparison, default is *1e-14*. Note that the old *tolerance* input is now synonymous with this parameter. - *atol* (float) - Absolute tolerance used in the comparison, default is *1e-08*. """ if isinstance(tolerance, float): rtol = tolerance # Load test data data = solution.Solution(frame_num, path=self.temp_path) data_sum = [] for index in indices: data_sum.append(data.q[index, ...].sum()) # Get (and save) regression comparison data regression_data_file = os.path.join(self.test_path, "regression_data", file_name) if save: numpy.savetxt(regression_data_file, data_sum) claw_git_status.make_git_status_file( outdir=os.path.join(self.test_path, "regression_data")) regression_sum = numpy.loadtxt(regression_data_file) assert numpy.allclose(data_sum, regression_sum, rtol=rtol, atol=atol), \ "\n new_data: %s, \n expected: %s" % (data_sum, regression_sum)
def check_frame(self, save=False, indices=[0], frame_num=1, regression_data_path="regression_data.txt", tolerance=1e-14): r"""Compare choosen frame to the comparison data :Input: - *save* (bool) - If *True* will save the output from this test to the file *regresion_data.txt*. Default is *False*. - *indices* (tuple) - Contains indices to compare in the gague comparison. Defaults to *(0)*. - *frame_num* (int) - Frame number to load from the run data. Defaults to *1*. - *regression_data_path* (path) - Path to the regression test data. Defaults to 'regression_data.txt'. - *tolerance* (float) - Tolerance used in the comparison, default is *1e-14*. """ # Load test data data = solution.Solution(frame_num, path=self.temp_path) data_sum = [] for index in indices: data_sum.append(data.q[index, ...].sum()) # Get (and save) regression comparison data regression_data_file = os.path.join(self.test_path, regression_data_path) if save: numpy.savetxt(regression_data_file, data_sum) regression_sum = numpy.loadtxt(regression_data_file) # regression_sum = [] # for index in indices: # regression_sum.append(regression_data[index, :].sum()) assert numpy.allclose(data_sum, regression_sum, tolerance), \ "\n new_data: %s, \n expected: %s" % (data_sum, regression_sum)
#!/usr/bin/env python import numpy import matplotlib.pyplot as plt import clawpack.pyclaw.solution as sol file = open('num_steps.txt', 'r') num_steps = file.read() for i in xrange(int(num_steps)): mySolution = sol.Solution(i, path='./numerical_output') fig = plt.figure() axes = fig.add_subplot(1, 1, 1) axes.plot(mySolution.state.grid.x.centers, mySolution.q[0, :], 'o-') plt.savefig("./graphic_output/q%s.png" % i)
raw_string = r"%." + str(figs) + "g" x = [float(raw_string % value) for value in x] return x if __name__ == '__main__': # Construct path to solutions data_path = os.environ["DATA_PATH"] eigen_method = 2 rho = [0.98, 1.0] for test in ['smooth', 'jump']: for dry in [True, False]: sol_path = os.path.join(data_path, "well_balancing_%s" % test, "ml_e%s_d%s_output" % (eigen_method, dry)) sol = solution.Solution(1, path=sol_path, read_aux=True) if dry: eta = [0.0, -6.0] else: eta = [0.0, -4.0] print "%s, %s =" % (test, dry) print " ", sig_fig_round(compute_error(sol.q, sol.aux, eta, rho, norm=1), figs=3) print " ", sig_fig_round(compute_error(sol.q, sol.aux, eta,
from clawpack.pyclaw import solution sol = solution.Solution()
outdir = "/_output/" else: outdir = "" # Load reference solution and test solution n = numpy.infty # n-norm # Lists to store errors (p-norm) and absolute difference, for h, hu, hv errors = [[], [], []] tbegin = 0 tend = 19 print "### Computing error ({:f}-norm) and maximum difference for time step {:d} to {:d} ###".format( n, tbegin, tend) for t in xrange(tbegin, tend): ref = solution.Solution(t, path=sys.argv[1] + outdir, read_aux=False) sol = solution.Solution(t, path=sys.argv[2] + outdir, read_aux=False) # print "=== Test solution stats for timestep {:d} ===".format(t) # print "Number of cells: " + str(ref.q.shape[0]) # print "Number of cells (x-dir): " + str(ref.q.shape[1]) # print "Number of cells (y-dir): " + str(ref.q.shape[2]) # Format: h = h(x, t) h = sol.q[0, ...] href = ref.q[0, ...] hu = sol.q[1, ...] huref = ref.q[1, ...] hv = sol.q[2, ...] hvref = ref.q[2, ...] #if (t==7):