Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sep bc #764

Merged
merged 24 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ if (ASGARD_USE_PYTHON)
endforeach()
add_custom_target(asgard_python_testing ALL DEPENDS "${_pyasgard_buildstage}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/python/plot.sh" "${CMAKE_CURRENT_BINARY_DIR}/plot.sh" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/python/asgardplot.sh" "${CMAKE_CURRENT_BINARY_DIR}/asgardplot.sh" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/asgardplot.sh" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/python/asgardrun.sh" "${CMAKE_CURRENT_BINARY_DIR}/asgardrun.sh" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/asgardrun.sh" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)

# install the module without the testing files
set(__pyasgard_libasgard_path__ "${__asgard_final_path}")
Expand Down Expand Up @@ -503,7 +507,8 @@ if (${ASGARD_USE_PCH})
target_precompile_headers (asgard_exe REUSE_FROM libasgard)
endif ()

set (_asgard_pdes continuity diffusion two_stream)
set (_asgard_pdes continuity diffusion elliptic sinwav two_stream
mass_internal varcoeff_internal bound_internal)

foreach (_asgexe ${_asgard_pdes})
add_executable (${_asgexe} "${CMAKE_CURRENT_SOURCE_DIR}/src/${_asgexe}.cpp")
Expand Down
2 changes: 2 additions & 0 deletions doxygen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ doxygen_add_docs(asgard_doxygen
examples/inputs_1d.cpp
src/continuity.cpp
src/diffusion.cpp
src/elliptic.cpp
src/sinwav.cpp
src/two_stream.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../
COMMENT "Building the ${PROJECT_NAME} documentation")
Expand Down
2 changes: 1 addition & 1 deletion examples/continuity_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* \par Example 1
* Solves the continuity partial differential equation
* \f[ \frac{d}{dt} f + \nabla \cdot f = s \f]
* \f[ \frac{\partial}{\partial t} f + \nabla \cdot f = s \f]
* where both \b f and \b s are defined over the two dimensional domain
* \f[ (x, y) \in (-1, 1) \otimes (-2, 2) \f]
*
Expand Down
2 changes: 1 addition & 1 deletion examples/inputs_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* \par Example 2
* Solves the continuity partial differential equation
* \f[ \frac{d}{dt} f + \frac{d}{dx} f = s \f]
* \f[ \frac{\partial}{\partial t} f + \frac{\partial}{\partial x} f = s \f]
* where both \b f and \b s are defined over domain
* \f[ (-\pi N_w, \pi N_w) \f]
* where N-w is the number of waves.
Expand Down
28 changes: 25 additions & 3 deletions python/asgard.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def __init__(self, filename, verbose = False):
if 'ndims' in fdata: # using version 1
self.using_version_2 = False

self.default_view = ""

self.num_dimensions = fdata['ndims'][()]

self.cells = fdata['elements'][()]
Expand Down Expand Up @@ -321,11 +323,16 @@ def __str__(self):
print("python -m asgard -s plt.data")
print(" shows summary of the snapshot contained in the out.data")
print("")
print("python -m asgard plt.data <-view string/-fig filename/-grid>")
print(" same as the first example but also adds more options,")
print(" set the view plane, save the figure to a file, add the grid entries")
print("")
print("options:")
print(" -h, -help, --help : shows this help text")
print(" -v, -version, --version : shows the library version info")
print(" -s, -stat, -stats, -summary : shows the summary of a snapshot")
print(" -g, -grid : plot the grid")
print(" -view : adjust the view plane")
print("")
print("no file and no option provided, shows the version of the")
print("")
Expand Down Expand Up @@ -367,6 +374,7 @@ def __str__(self):
# we are plotting, consider extra options
plotview = None
savefig = None
addgrid = False
if len(sys.argv) > 2:
i = 2
n = len(sys.argv)
Expand All @@ -377,6 +385,9 @@ def __str__(self):
elif sys.argv[i] == "-fig":
savefig = sys.argv[i + 1] if i + 1 < n else None
i += 2
elif sys.argv[i] == "-grid":
addgrid = True
i += 1
else:
savefig = sys.argv[i]
i += 1
Expand All @@ -387,6 +398,12 @@ def __str__(self):
z, x = shot.plot_data1d(((),), num_points = 256)
asgplot.plot(x, z)
asgplot.xlabel(shot.dimension_names[0], fontsize = 'large')

if addgrid:
cc = shot.cell_centers()
ymin = np.min(z)
asgplot.plot(cc, ymin * np.ones(cc.shape), 'om')

else:
if plotview is None and shot.default_view != "":
plotview = shot.default_view
Expand All @@ -401,10 +418,11 @@ def __str__(self):
ss = plotview.split(':')
plist = []
dims = []
for s in ss:
for i in range(len(ss)):
s = ss[i]
if '*' in s:
plist.append(())
dims.append(ss.index(s))
dims.append(i)
else:
plist.append(float(s))

Expand All @@ -415,13 +433,17 @@ def __str__(self):
xmax = shot.dimension_max[dims[0]]
ymax = shot.dimension_max[dims[1]]

#p = asgplot.pcolor(x, y, z, cmap='jet') # , extent=[xmin, xmax, ymin, ymax])
#p = asgplot.pcolor(x, y, z, cmap='jet')
p = asgplot.imshow(np.flipud(z), cmap='jet', extent=[xmin, xmax, ymin, ymax])

asgplot.colorbar(p, orientation='vertical')

asgplot.gca().set_anchor('C')

if addgrid:
cc = shot.cell_centers()
asgplot.scatter(cc[:,0], cc[:,1], 5 * np.ones(cc[:,0].shape), color='purple')

asgplot.xlabel(shot.dimension_names[dims[0]], fontsize='large')
asgplot.ylabel(shot.dimension_names[dims[1]], fontsize='large')

Expand Down
25 changes: 25 additions & 0 deletions python/asgardplot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -e

if [[ "$1" == "help" || "$1" == "-help" || "$1" == "--help" ]]; then

echo ""
echo "usage: asgardplot.sh <filename> <plot opts>"
echo ""
echo "calls the asgard python quick plot utility"
echo "for more details see:"
echo "@Python_EXECUTABLE@ -m asgard --help"
echo ""

exit 0;
fi


if [ ! -f $1 ]; then
echo "cannot find file '$1'"
exit 1
fi

@Python_EXECUTABLE@ -m asgard $@

39 changes: 39 additions & 0 deletions python/asgardrun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -e # exit on first error
#set -x # plot every command (debugging purposes)

if [[ "$1" == "help" || "$1" == "-help" || "$1" == "--help" ]]; then

echo ""
echo "usage: asgardrun.sh <executable> <options>"
echo "usage: asgardrun.sh -plt \"<plotter opts>\" <executable> <options>"
echo ""
echo "runs the executable file with the given options"
echo "adding '-of _plt.h5' to save the output in a temp-file"
echo "then calls the plotter on the temp file"
echo "starting with the -plt switch allows passing options to the final plotter"
echo "for example: asgardrun.sh -plt -grid continuity -dims 2 -l 5"
echo ""

exit 0;
fi

plt_opts=""

if [[ "$1" == "-plt" ]]; then
plt_opts="$2"
shift
shift
fi

exename=$1

shift

echo $1

./$exename $@ -of _plt.h5

@Python_EXECUTABLE@ -m asgard _plt.h5 $plt_opts

12 changes: 0 additions & 12 deletions python/plot.sh

This file was deleted.

4 changes: 2 additions & 2 deletions src/asgard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void simulate_builtin(prog_opts const &options)
discretization_manager discretization(make_PDE<precision>(options),
verbosity_level::high);

advance_time(discretization);
discretization.advance_time();

discretization.save_final_snapshot();

Expand Down Expand Up @@ -142,7 +142,7 @@ void simulate(prog_opts const &options, verbosity_level verbosity = verbosity_le
*/
template<typename precision>
void simulate(discretization_manager<precision> &disc) {
asgard::advance_time(disc); // integrate until num-steps or stop-time
disc.advance_time(); // integrate until num-steps or stop-time

if (not disc.stop_verbosity())
disc.progress_report();
Expand Down
132 changes: 2 additions & 130 deletions src/asgard_adapt_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,135 +33,7 @@ int main(int argc, char *argv[])
return result;
}

template<typename P>
void test_adapt(prog_opts const &opts, std::filesystem::path gold_base)
TEMPLATE_TEST_CASE("no-test", "[none]", test_precs)
{
auto const prefix = gold_base.filename().string();
gold_base.remove_filename();
auto const fval_orig_path = gold_base / (prefix + "orig.dat");
auto const fval_refine_path = gold_base / (prefix + "refine.dat");
auto const fval_coarse_path = gold_base / (prefix + "coarse.dat");
auto const table_refine_path = gold_base / (prefix + "refine_table.dat");
auto const table_coarse_path = gold_base / (prefix + "coarse_table.dat");

auto const fval_orig = read_vector_from_txt_file<P>(fval_orig_path);
auto const gold_coarse = read_vector_from_txt_file<P>(fval_coarse_path);
auto const gold_refine = [fval_refine_path]() {
auto gold = read_vector_from_txt_file<P>(fval_refine_path);
for (auto i = 0; i < gold.size(); ++i)
{
// matlab stores new refined coefficients as 1e-15 (0 deletes from sparse
// vect)
if (std::abs(gold(i)) < 1e-14)
{
gold(i) = 0.0;
}
}
return gold;
}();

auto const test_tables = [](elements::table const &test,
fk::matrix<int> const &gold) {
REQUIRE(test.size() == gold.nrows());
for (int64_t i = 0; i < test.size(); ++i)
{
auto const &test_coords = test.get_coords(i);
fk::vector<int> const gold_coords =
gold.extract_submatrix(i, 0, 1, gold.ncols());
REQUIRE(test_coords == gold_coords);
}
};

auto const gold_coarse_table =
read_matrix_from_txt_file<int>(table_coarse_path);
auto const gold_refine_table =
fk::matrix<int>(read_matrix_from_txt_file<int>(table_refine_path));

auto const pde = make_PDE<P>(opts);
// using second opts after reset from the pde
auto const &opts2 = pde->options();

adapt::distributed_grid<P> refine_grid(*pde);
auto const my_subgrid = refine_grid.get_subgrid(get_rank());
auto const segment_size = element_segment_size(*pde);
auto const my_fval_orig =
fval_orig.extract(my_subgrid.col_start * segment_size,
(my_subgrid.col_stop + 1) * segment_size - 1);

auto const test_refine = refine_grid.refine(my_fval_orig, opts2);
adapt::distributed_grid<P> coarse_grid(*pde);
auto const test_coarse = coarse_grid.coarsen(my_fval_orig, opts2);
test_tables(coarse_grid.get_table(), gold_coarse_table);
test_tables(refine_grid.get_table(), gold_refine_table);

auto const refine_subgrid = refine_grid.get_subgrid(get_rank());
fk::vector<P, mem_type::const_view> const my_gold_refine(
gold_refine, refine_subgrid.col_start * segment_size,
(refine_subgrid.col_stop + 1) * segment_size - 1);
REQUIRE(test_refine == my_gold_refine);

auto const coarsen_subgrid = coarse_grid.get_subgrid(get_rank());
fk::vector<P, mem_type::const_view> const my_gold_coarse(
gold_coarse, coarsen_subgrid.col_start * segment_size,
(coarsen_subgrid.col_stop + 1) * segment_size - 1);
REQUIRE(test_coarse == my_gold_coarse);
}

template<typename P>
void test_initial(prog_opts const &opts, std::string const &gold_filepath)
{
auto const gold = [&gold_filepath]() {
auto raw = read_vector_from_txt_file<P>(gold_filepath);
// matlab stores new refined coefficients as 1e-15 (0 deletes from sparse
// vector)
std::replace_if(
raw.begin(), raw.end(),
[](P old_value) { return std::abs(old_value) < 1.e-14; }, 0.0);
return raw;
}();

discretization_manager<P> disc(make_PDE<P>(opts));

fk::vector<P> const test = disc.current_state();

REQUIRE(gold.size() >= test.size());

auto constexpr tol_factor = get_tolerance<P>(100);
auto const my_subgrid = disc.get_grid().get_subgrid(get_rank());
auto const segment_size = disc.get_hiermanip().block_size();
fk::vector<P, mem_type::const_view> const my_gold(
gold, my_subgrid.col_start * segment_size,
(my_subgrid.col_stop + 1) * segment_size - 1);
rmse_comparison(my_gold, test, tol_factor);
}

TEMPLATE_TEST_CASE("initial - diffusion 1d", "[adapt]", test_precs)
{
auto opts = make_opts("-p diffusion_1 -d 3 -l 3 -m 8");

opts.adapt_threshold = adapt_threshold;
opts.anorm = adapt_norm::linf;

// don't test this in the MPI case -- too small to split table
if (get_num_ranks() == 1)
{
test_initial<TestType>(opts,
adapt_base_dir / "diffusion1_l3_d4_initial.dat");
}
}

TEMPLATE_TEST_CASE("initial - diffusion 2d", "[adapt]", test_precs)
{
if (!is_active())
{
return;
}

auto opts = make_opts("-p diffusion_2 -d 2 -l 2 -m 8");

opts.adapt_threshold = adapt_threshold;
opts.anorm = adapt_norm::linf;

test_initial<TestType>(opts,
adapt_base_dir / "diffusion2_l2_d3_initial.dat");
REQUIRE(true);
}
Loading