Skip to content

Commit

Permalink
plotting works for all degrees (#720)
Browse files Browse the repository at this point in the history
* plotting now works for arbitrary degree
  • Loading branch information
mkstoyanov authored Aug 9, 2024
1 parent d202fe6 commit 78a72e7
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 78 deletions.
8 changes: 4 additions & 4 deletions examples/continuity_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ class example_continuity2d : public asgard::PDE<precision>
// function definitions needed to build up the dimension, terms and sources
//

// for all funtions, the "vector x" indicates a batch of quadrature points
// for all functions, the "vector x" indicates a batch of quadrature points
// in the corresponding dimension (e.g., dim0 or dim1)
// the output should be a vector with the same size holding f(x)
// funcitons also accept a "time" scalar but it is often ignored
// functions also accept a "time" scalar but it is often ignored

// specify initial condition vector functions...
static vector initial_condition_x(vector const &x, precision const = 0)
Expand All @@ -143,7 +143,7 @@ class example_continuity2d : public asgard::PDE<precision>
// ignored parameter corresponds to time
vector fx(x.size());
for (int i = 0; i < x.size(); i++)
fx[i] = std::sin(precision{2.0} * M_PI * x[i]);
fx[i] = std::sin(precision{2.0} * M_PI * x[i]);
return fx;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ class example_continuity2d : public asgard::PDE<precision>
}

// a bit of a misnomer, this is a scaling factor applied to dt
// in conjuction with the CFL conidition provided from the command line
// in conjunction with the CFL condition provided from the command line
// (note: this is probably not fully supported at the moment)
static precision get_dt(asgard::dimension<precision> const &dim)
{
Expand Down
5 changes: 2 additions & 3 deletions examples/continuity_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
exit(1)

print("asgard: running the continuity example")
os.system("./example_continuity_2d -p continuity_2 -d 1 -l 6 -w 10 -n 10 -t 0.0001")
os.system("./example_continuity_2d -p continuity_2 -d 2 -l 5 -n 10 -t 0.0001 -of cont1_final.h5")

# the example above will run for 10 time steps and the -w 10 options
# will tell the code to output on the final 10-th step
output_filename = 'asgard_wavelet_10.h5'
output_filename = 'cont1_final.h5'
if not os.path.isfile(output_filename):
print("ERROR: example_continuity_2d did not generate an output file")
exit(1)

# using the ASGarD python module to read from the file
snapshot = asgard.pde_snapshot(output_filename)
Expand Down
4 changes: 2 additions & 2 deletions examples/inputs_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
outfile2 = 'waves2.h5'

# providing the input file and also forcing the degree to 1
os.system("./example_inputs_1d -if inputs_1d_1.txt -d 1 -of %s" % outfile1)
os.system("./example_inputs_1d -if inputs_1d_2.txt -d 1 -of %s" % outfile2)
os.system("./example_inputs_1d -if inputs_1d_1.txt -d 2 -of %s" % outfile1)
os.system("./example_inputs_1d -if inputs_1d_2.txt -d 2 -of %s" % outfile2)

if not os.path.isfile(outfile1) or not os.path.isfile(outfile2):
print("ERROR: example_inputs_1d did not generate an output file")
Expand Down
1 change: 0 additions & 1 deletion python/asgard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, filename, verbose = False):

self.num_dimensions = fdata['ndims'][()]
self.degree = fdata['degree'][()]
assert self.degree <= 1, "only works with constant and linear basis, others will be coming soon"

self.state = fdata['soln'][()]
self.cells = fdata['elements'][()]
Expand Down
15 changes: 8 additions & 7 deletions python/pyasgard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,21 @@ def test2d_basis_reconstruct(self):
# simple IO test
def test_simple1d(self):
print("\ntesting 1d plot")
tols = (1.E-3, 1.E-5)
for degree in range(2):
os.system("./asgard -p continuity_1 -d %d -l 6 -w 10 -dt 0.01 1>/dev/null" % degree)
tols = (1.E-4, 1.E-6, 1.E-8, 1.E-9)
levs = (6, 6, 4, 4)
for degree in range(4):
os.system("./asgard -p continuity_1 -d %d -l 6 -dt 0.005 -of _test_plot.h5 1>/dev/null" % degree)

self.assertTrue(os.path.isfile("asgard_wavelet_10.h5"), "failed to run continuity_1")
self.assertTrue(os.path.isfile("_test_plot.h5"), "failed to run continuity_1")

snapshot = asgard.pde_snapshot("asgard_wavelet_10.h5")
snapshot = asgard.pde_snapshot("_test_plot.h5")

gold_dimension_min = np.array([-1.0, ])
gold_dimension_max = np.array([1.0, ])
self.almost_equal(snapshot.dimension_min, gold_dimension_min,
"mismatch in dimension_min")
"mismatch in dimension_min")
self.almost_equal(snapshot.dimension_max, gold_dimension_max,
"mismatch in dimension_max")
"mismatch in dimension_max")

self.assertEqual(snapshot.num_dimensions, 1, "mismatch in the number of dimensions")
self.assertEqual(snapshot.num_cells, 64, "mismatch in the number of cells")
Expand Down
Loading

0 comments on commit 78a72e7

Please sign in to comment.