| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include "../TOOLS/meshmanager.hpp" |
| 11 |
|
| 12 |
template <class Real> |
| 13 |
class MeshManager_Example02 : public MeshManager_Rectangle<Real> { |
| 14 |
|
| 15 |
private: |
| 16 |
|
| 17 |
int nx_; |
| 18 |
int ny_; |
| 19 |
Real width_; |
| 20 |
ROL::Ptr<std::vector<std::vector<std::vector<int> > > > meshSideSets_; |
| 21 |
|
| 22 |
public: |
| 23 |
|
| 24 |
MeshManager_Example02(Teuchos::ParameterList &parlist) : MeshManager_Rectangle<Real>(parlist) |
| 25 |
{ |
| 26 |
nx_ = parlist.sublist("Geometry").get("NX", 3); |
| 27 |
ny_ = parlist.sublist("Geometry").get("NY", 3); |
| 28 |
width_ = parlist.sublist("Geometry").get("Width", 1.0); |
| 29 |
computeSideSets(); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
void computeSideSets() { |
| 34 |
|
| 35 |
int numSideSets = 4; |
| 36 |
meshSideSets_ = ROL::makePtr<std::vector<std::vector<std::vector<int> > >>(numSideSets); |
| 37 |
|
| 38 |
Real patchFrac = static_cast<Real>(1)/static_cast<Real>(6); |
| 39 |
int np1 = static_cast<int>(patchFrac * static_cast<Real>(nx_)); // Source |
| 40 |
int np2 = static_cast<int>(patchFrac * static_cast<Real>(nx_)); |
| 41 |
int np3 = 2*static_cast<int>(patchFrac * static_cast<Real>(nx_)); // Gate |
| 42 |
int np4 = static_cast<int>(patchFrac * static_cast<Real>(nx_)); |
| 43 |
int np5 = nx_-(np1+np2+np3+np4); // Drain |
| 44 |
|
| 45 |
// Neumann |
| 46 |
(*meshSideSets_)[0].resize(4); |
| 47 |
(*meshSideSets_)[0][0].resize(nx_); |
| 48 |
(*meshSideSets_)[0][1].resize(ny_); |
| 49 |
(*meshSideSets_)[0][2].resize(np2+np4); |
| 50 |
(*meshSideSets_)[0][3].resize(ny_); |
| 51 |
// Source |
| 52 |
(*meshSideSets_)[1].resize(4); |
| 53 |
(*meshSideSets_)[1][0].resize(0); |
| 54 |
(*meshSideSets_)[1][1].resize(0); |
| 55 |
(*meshSideSets_)[1][2].resize(np1); |
| 56 |
(*meshSideSets_)[1][3].resize(0); |
| 57 |
// Gate |
| 58 |
(*meshSideSets_)[2].resize(4); |
| 59 |
(*meshSideSets_)[2][0].resize(0); |
| 60 |
(*meshSideSets_)[2][1].resize(0); |
| 61 |
(*meshSideSets_)[2][2].resize(np3); |
| 62 |
(*meshSideSets_)[2][3].resize(0); |
| 63 |
// Drain |
| 64 |
(*meshSideSets_)[3].resize(4); |
| 65 |
(*meshSideSets_)[3][0].resize(0); |
| 66 |
(*meshSideSets_)[3][1].resize(0); |
| 67 |
(*meshSideSets_)[3][2].resize(np5); |
| 68 |
(*meshSideSets_)[3][3].resize(0); |
| 69 |
|
| 70 |
for (int i=0; i<nx_; ++i) { |
| 71 |
(*meshSideSets_)[0][0][i] = i; |
| 72 |
} |
| 73 |
for (int i=0; i<ny_; ++i) { |
| 74 |
(*meshSideSets_)[0][1][i] = (i+1)*nx_-1; |
| 75 |
} |
| 76 |
for (int i=0; i<ny_; ++i) { |
| 77 |
(*meshSideSets_)[0][3][i] = i*nx_; |
| 78 |
} |
| 79 |
for (int i=0; i<np1; ++i) { |
| 80 |
(*meshSideSets_)[1][2][i] = i + nx_*(ny_-1); |
| 81 |
} |
| 82 |
for (int i=0; i<np2; ++i) { |
| 83 |
(*meshSideSets_)[0][2][i] = i + np1 + nx_*(ny_-1); |
| 84 |
} |
| 85 |
for (int i=0; i<np3; ++i) { |
| 86 |
(*meshSideSets_)[2][2][i] = i + (np1+np2) + nx_*(ny_-1); |
| 87 |
} |
| 88 |
for (int i=0; i<np4; ++i) { |
| 89 |
(*meshSideSets_)[0][2][i] = i + (np1+np2+np3) + nx_*(ny_-1); |
| 90 |
} |
| 91 |
for (int i=0; i<np5; ++i) { |
| 92 |
(*meshSideSets_)[3][2][i] = i + (np1+np2+np3+np4) + nx_*(ny_-1); |
| 93 |
} |
| 94 |
|
| 95 |
} // computeSideSets |
| 96 |
|
| 97 |
ROL::Ptr<std::vector<std::vector<std::vector<int> > > > getSideSets( |
| 98 |
const bool verbose = false, |
| 99 |
std::ostream & outStream = std::cout) const { |
| 100 |
if ( verbose ) { |
| 101 |
outStream << "Mesh_TopoOpt: getSideSets called" << std::endl; |
| 102 |
outStream << "Mesh_TopoOpt: numSideSets = " << meshSideSets_->size() << std::endl; |
| 103 |
} |
| 104 |
return meshSideSets_; |
| 105 |
} |
| 106 |
|
| 107 |
}; // MeshManager_TopoOpt |