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

Add Mesh2D #87

Merged
merged 8 commits into from
Feb 16, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ set(Omega_h_SOURCES
Omega_h_xml.cpp
Omega_h_xml_lite.cpp
Omega_h_yaml.cpp
Omega_h_mesh2d.cpp
)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
Expand Down Expand Up @@ -323,8 +324,7 @@ if(BUILD_TESTING)
endif()
endif()

function(test_func_impl TEST_NAME NUM_PROCS)

function(test_func_impl TEST_NAME NUM_PROCS)
if (ENABLE_CTEST_MEMPOOL)
set(CTEST_MEMPOOL_ARG "--osh-pool")
endif()
Expand All @@ -339,7 +339,11 @@ function(test_func_impl TEST_NAME NUM_PROCS)
endif()
set(TEST_STR ${VALGRIND} ${ARGN} ${CTEST_MEMPOOL_ARG})
endif()
add_test(NAME ${TEST_NAME} COMMAND ${TEST_STR})

# need to run as a cmake script to capture assert and other 'system failures'
# https://cmake.org/cmake/help/latest/prop_test/WILL_FAIL.html#prop_test:WILL_FAIL
add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_COMMAND} -E env ${TEST_STR})

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "PATH=${CMAKE_INSTALL_PREFIX}\\bin;$ENV{PATH}" )
endif()
Expand All @@ -364,6 +368,15 @@ function(test_func_impl TEST_NAME NUM_PROCS)
endif()
endfunction(test_func)

# Unlike test_func, will_fail_test_func assumes the command for the test, thus you should specify it the arguments.
function(will_fail_test_func TEST_NAME NUM_PROCS)
test_func_impl(${TEST_NAME} ${NUM_PROCS} ${ARGN})
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
if(TEST ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS "mesh")
endif()
endfunction()

osh_add_exe(for_test)
osh_add_exe(reprosum_test)
osh_add_exe(arrayops_test)
Expand Down Expand Up @@ -416,6 +429,14 @@ function(test_func_impl TEST_NAME NUM_PROCS)
osh_add_exe(periodic_test)
endif()

osh_add_exe(load_2d)
set(TEST_EXES ${TEST_EXES} load_2d)
will_fail_test_func(load_2d_box_100 1 ./load_2d box_100.osh)

osh_add_exe(osh_scale2d)
set(TEST_EXES ${TEST_EXES} osh_scale2d)
test_func(osh_scale2d 1 ./osh_scale2d ${CMAKE_SOURCE_DIR}/meshes/plate_6elem.osh 100 plate_100.osh)

test_basefunc(run_arrayops 1 ./arrayops_test)
set(TEST_EXES ${TEST_EXES} reprosum_test)
test_basefunc(run_reprosum 1 ./reprosum_test)
Expand Down
11 changes: 7 additions & 4 deletions src/Omega_h_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class Mesh {
void set_comm(CommPtr const& comm);
void set_family(Omega_h_Family family);
void set_matched(I8 is_matched);
void set_dim(Int dim_in);
virtual void set_dim(Int dim_in);
void set_verts(LO nverts_in);
void set_ents(Int ent_dim, Adj down);
void set_parents(Int ent_dim, Parents parents);
Library* library() const;
CommPtr comm() const;
Omega_h_Parting parting() const;
inline Int dim() const {
virtual inline Int dim() const {
OMEGA_H_CHECK(0 <= dim_ && dim_ <= 3);
return dim_;
}
Expand Down Expand Up @@ -229,7 +229,6 @@ class Mesh {
void react_to_set_tag(Int dim, std::string const& name);
Omega_h_Family family_;
I8 matched_ = -1;
Int dim_;
CommPtr comm_;
Int parting_;
Int nghost_layers_;
Expand All @@ -252,6 +251,9 @@ class Mesh {

void add_rcField(Int ent_dim, std::string const& name, TagPtr tag);

protected:
Int dim_;

public:
void add_coords(Reals array);
Reals coords() const;
Expand Down Expand Up @@ -329,7 +331,8 @@ class Mesh {
LO nents_owned(Int ent_dim);
std::string string(int verbose = 0);

public:
virtual ~Mesh() = default;

ClassSets class_sets;
[[nodiscard]] const TagVector& get_rc_tags(Int dim) const {
return rc_field_tags_[dim];
Expand Down
15 changes: 15 additions & 0 deletions src/Omega_h_mesh2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Matthew McCall on 1/29/24.
//

#include "Omega_h_mesh2d.hpp"

namespace Omega_h {

void Mesh2D::set_dim(Int dim_in) {
OMEGA_H_CHECK(dim_ == -1);
OMEGA_H_CHECK(dim_in == 1 || dim_in == 2);
dim_ = dim_in;
}

} // Omega_h
23 changes: 23 additions & 0 deletions src/Omega_h_mesh2d.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef OMEGA_H_2DMESH_HPP
#define OMEGA_H_2DMESH_HPP

#include <Omega_h_mesh.hpp>

namespace Omega_h {

class Mesh2D final : public Mesh {
public:
Mesh2D() = default;
cwsmith marked this conversation as resolved.
Show resolved Hide resolved
explicit Mesh2D(Library* library) : Mesh(library) {}

void set_dim(Int dim_in) override;

[[nodiscard]] inline Int dim() const override {
OMEGA_H_CHECK(0 <= dim_ && dim_ <= 2);
return dim_;
}
};

} // Omega_h

#endif //OMEGA_H_2DMESH_HPP
16 changes: 16 additions & 0 deletions src/load_2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <Omega_h_file.hpp>
#include <Omega_h_library.hpp>
#include <Omega_h_mesh2d.hpp>

#include <cstdlib>

int main(int argc, char** argv) {
auto lib = Omega_h::Library(&argc, &argv);
if(argc != 2) {
fprintf(stderr, "Usage: %s inputMesh.osh\n", argv[0]);
exit(EXIT_FAILURE);
}
OMEGA_H_CHECK(argc == 2);
Omega_h::Mesh2D mesh(&lib);
Omega_h::binary::read(argv[1], lib.world(), &mesh);
}
33 changes: 33 additions & 0 deletions src/osh_scale2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <Omega_h_adapt.hpp>
#include <Omega_h_array_ops.hpp>
#include <Omega_h_file.hpp>
#include <Omega_h_mesh2d.hpp>
#include <Omega_h_metric.hpp>

#include <cstdlib>
#include <iostream>

int main(int argc, char** argv) {
auto lib = Omega_h::Library(&argc, &argv);
Omega_h::CmdLine cmdline;
cmdline.add_arg<std::string>("input.osh");
cmdline.add_arg<double>("<target nelems>");
cmdline.add_arg<std::string>("output.osh");
if (!cmdline.parse_final(lib.world(), &argc, argv)) return -1;
auto path_in = cmdline.get<std::string>("input.osh");
auto target_nelems = cmdline.get<double>("<target nelems>");
auto path_out = cmdline.get<std::string>("output.osh");
Omega_h::Mesh2D mesh(&lib);
Omega_h::binary::read(path_in, lib.world(), &mesh, /*strict=*/true);
mesh.set_parting(OMEGA_H_GHOSTED);
auto metrics = Omega_h::get_implied_isos(&mesh);
auto scalar =
Omega_h::get_metric_scalar_for_nelems(&mesh, metrics, target_nelems);
metrics = multiply_each_by(metrics, scalar);
mesh.add_tag(Omega_h::VERT, "metric", 1, metrics);
auto opts = Omega_h::AdaptOpts(&mesh);
opts.verbosity = Omega_h::EXTRA_STATS;
Omega_h::adapt(&mesh, opts);
mesh.remove_tag(Omega_h::VERT, "metric");
Omega_h::binary::write(path_out, &mesh);
}