Skip to content

Commit

Permalink
Move HoleShape to end of parameter list
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed Jan 27, 2025
1 parent 96c0ccf commit 4eb7380
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 70 deletions.
53 changes: 25 additions & 28 deletions include/viennaps/geometries/psMakeHole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

namespace viennaps {

enum class HoleShape {
Full,
Half,
Quarter
};
enum class HoleShape { Full, Half, Quarter };

using namespace viennacore;

Expand Down Expand Up @@ -45,33 +41,34 @@ template <class NumericType, int D> class MakeHole {
const bool makeMask_;
const bool periodicBoundary_;
const Material material_;

const HoleShape shape_;

public:
MakeHole(psDomainType domain, NumericType gridDelta, NumericType xExtent,
NumericType yExtent, NumericType holeRadius, NumericType holeDepth,
NumericType taperAngle = 0., NumericType baseHeight = 0.,
HoleShape shape = HoleShape::Full, bool periodicBoundary = false,
bool makeMask = false, Material material = Material::None)
: domain_(domain), gridDelta_(gridDelta), xExtent_(xExtent),
yExtent_(yExtent), holeRadius_(holeRadius), holeDepth_(holeDepth),
shape_((shape == HoleShape::Full || shape == HoleShape::Half || shape == HoleShape::Quarter)
? shape
: HoleShape::Full),
taperAngle_(taperAngle), baseHeight_(baseHeight),
periodicBoundary_(periodicBoundary && (shape != HoleShape::Half && shape != HoleShape::Quarter)),
makeMask_(makeMask), material_(material) {
if (periodicBoundary && (shape == HoleShape::Half || shape == HoleShape::Quarter)) {
Logger::getInstance()
.addWarning("MakeHole: 'Half' or 'Quarter' shapes do not support periodic boundaries! "
"Defaulting to reflective boundaries!")
.print();
}
MakeHole(psDomainType domain, NumericType gridDelta, NumericType xExtent,
NumericType yExtent, NumericType holeRadius, NumericType holeDepth,
NumericType taperAngle = 0., NumericType baseHeight = 0.,
bool periodicBoundary = false, bool makeMask = false,
Material material = Material::None,
HoleShape shape = HoleShape::Full)
: domain_(domain), gridDelta_(gridDelta), xExtent_(xExtent),
yExtent_(yExtent), holeRadius_(holeRadius), holeDepth_(holeDepth),
shape_(shape), taperAngle_(taperAngle), baseHeight_(baseHeight),
periodicBoundary_(periodicBoundary && (shape != HoleShape::Half &&
shape != HoleShape::Quarter)),
makeMask_(makeMask), material_(material) {
if (periodicBoundary &&
(shape == HoleShape::Half || shape == HoleShape::Quarter)) {
Logger::getInstance()
.addWarning("MakeHole: 'Half' or 'Quarter' shapes do not support "
"periodic boundaries! "
"Defaulting to reflective boundaries!")
.print();
}
}

void apply() {

if constexpr (D != 3) {
Logger::getInstance()
.addWarning("MakeHole: Hole geometry can only be created in 3D! "
Expand All @@ -84,14 +81,14 @@ MakeHole(psDomainType domain, NumericType gridDelta, NumericType xExtent,

return;
}

domain_->clear();
double bounds[2 * D];
bounds[0] = (shape_ != HoleShape::Full) ? 0. : -xExtent_ / 2.;
bounds[1] = xExtent_ / 2.;

if constexpr (D == 3) {
bounds[2] = (shape_ == HoleShape::Quarter) ? 0. : -yExtent_ / 2.;
bounds[2] = (shape_ == HoleShape::Quarter) ? 0. : -yExtent_ / 2.;
bounds[3] = yExtent_ / 2.;
bounds[4] = baseHeight_ - gridDelta_;
bounds[5] = baseHeight_ + holeDepth_ + gridDelta_;
Expand Down
62 changes: 31 additions & 31 deletions python/pyWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,39 +1008,39 @@ PYBIND11_MODULE(VIENNAPS_MODULE_NAME, module) {

// Hole
pybind11::enum_<HoleShape>(module, "HoleShape")
.value("Full", HoleShape::Full)
.value("Half", HoleShape::Half)
.value("Quarter", HoleShape::Quarter)
.export_values();
.value("Full", HoleShape::Full)
.value("Half", HoleShape::Half)
.value("Quarter", HoleShape::Quarter)
.export_values();

pybind11::class_<MakeHole<T, D>>(module, "MakeHole")
.def(pybind11::init<DomainType, const T, const T, const T, const T,
const T, const T, const T, HoleShape, const bool,
const bool, const Material>(),
pybind11::arg("domain"), pybind11::arg("gridDelta"),
pybind11::arg("xExtent"), pybind11::arg("yExtent"),
pybind11::arg("holeRadius"), pybind11::arg("holeDepth"),
pybind11::arg("taperingAngle") = 0.,
pybind11::arg("baseHeight") = 0.,
pybind11::arg("holeShape") = HoleShape::Full, // New argument
pybind11::arg("periodicBoundary") = false,
pybind11::arg("makeMask") = false,
pybind11::arg("material") = Material::None)
.def("apply", &MakeHole<T, D>::apply, "Create a hole geometry.");

// pybind11::class_<MakeHole<T, D>>(module, "MakeHole")
// .def(pybind11::init<DomainType, const T, const T, const T, const T,
// const T, const T, const T, const bool, const bool,
// const Material>(),
// pybind11::arg("domain"), pybind11::arg("gridDelta"),
// pybind11::arg("xExtent"), pybind11::arg("yExtent"),
// pybind11::arg("holeRadius"), pybind11::arg("holeDepth"),
// pybind11::arg("taperingAngle") = 0.,
// pybind11::arg("baseHeight") = 0.,
// pybind11::arg("periodicBoundary") = false,
// pybind11::arg("makeMask") = false,
// pybind11::arg("material") = Material::None)
// .def("apply", &MakeHole<T, D>::apply, "Create a hole geometry.");
.def(pybind11::init<DomainType, const T, const T, const T, const T,
const T, const T, const T, , const bool, const bool,
const Material, HoleShape>(),
pybind11::arg("domain"), pybind11::arg("gridDelta"),
pybind11::arg("xExtent"), pybind11::arg("yExtent"),
pybind11::arg("holeRadius"), pybind11::arg("holeDepth"),
pybind11::arg("taperingAngle") = 0.,
pybind11::arg("baseHeight") = 0.,
pybind11::arg("periodicBoundary") = false,
pybind11::arg("makeMask") = false,
pybind11::arg("material") = Material::None,
pybind11::arg("holeShape") = HoleShape::Full) // New argument
.def("apply", &MakeHole<T, D>::apply, "Create a hole geometry.");

// pybind11::class_<MakeHole<T, D>>(module, "MakeHole")
// .def(pybind11::init<DomainType, const T, const T, const T, const T,
// const T, const T, const T, const bool, const bool,
// const Material>(),
// pybind11::arg("domain"), pybind11::arg("gridDelta"),
// pybind11::arg("xExtent"), pybind11::arg("yExtent"),
// pybind11::arg("holeRadius"), pybind11::arg("holeDepth"),
// pybind11::arg("taperingAngle") = 0.,
// pybind11::arg("baseHeight") = 0.,
// pybind11::arg("periodicBoundary") = false,
// pybind11::arg("makeMask") = false,
// pybind11::arg("material") = Material::None)
// .def("apply", &MakeHole<T, D>::apply, "Create a hole geometry.");

// Fin
pybind11::class_<MakeFin<T, D>>(module, "MakeFin")
Expand Down
20 changes: 9 additions & 11 deletions tests/hole/hole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ namespace viennacore {

using namespace viennaps;

template <class NumericType, int D>
void RunTest() {
template <class NumericType, int D> void RunTest() {
auto domain = SmartPointer<Domain<NumericType, D>>::New();

// Test with HoleShape::Full
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., HoleShape::Full, false, true,
Material::Si)
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., false, true,
Material::Si, HoleShape::Full)
.apply();

VC_TEST_ASSERT(domain->getLevelSets().size() == 2);
Expand All @@ -23,9 +22,9 @@ void RunTest() {
LSTEST_ASSERT_VALID_LS(domain->getLevelSets().back(), NumericType, D);

// Test with HoleShape::Quarter
domain->clear(); // Reset the domain for a new test
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., HoleShape::Quarter, false, true,
Material::Si)
domain->clear(); // Reset the domain for a new test
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., false, true,
Material::Si, HoleShape::Quarter)
.apply();

VC_TEST_ASSERT(domain->getLevelSets().size() == 2);
Expand All @@ -35,9 +34,9 @@ void RunTest() {
LSTEST_ASSERT_VALID_LS(domain->getLevelSets().back(), NumericType, D);

// Test with HoleShape::Half
domain->clear(); // Reset the domain for a new test
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., HoleShape::Half, false, true,
Material::Si)
domain->clear(); // Reset the domain for a new test
MakeHole<NumericType, D>(domain, 1., 10., 10., 2.5, 5., 10., 1., false, true,
Material::Si, HoleShape::Half)
.apply();

VC_TEST_ASSERT(domain->getLevelSets().size() == 2);
Expand All @@ -50,4 +49,3 @@ void RunTest() {
} // namespace viennacore

int main() { VC_RUN_ALL_TESTS }

0 comments on commit 4eb7380

Please sign in to comment.