forked from sandialabs/omega_h
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from matthew-mccall/mmccall/2dmesh
Add Mesh2D
- Loading branch information
Showing
6 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |