| 1 |
// Copyright (C) 2011 Marie E. Rognes |
| 2 |
// |
| 3 |
// This file is part of DOLFIN. |
| 4 |
// |
| 5 |
// DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU Lesser General Public License as published by |
| 7 |
// the Free Software Foundation, either version 3 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// DOLFIN is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
// |
| 18 |
// Last changed: 2011-03-12 |
| 19 |
|
| 20 |
#include <dolfin.h> |
| 21 |
|
| 22 |
using namespace dolfin; |
| 23 |
|
| 24 |
int main() |
| 25 |
{ |
| 26 |
if (dolfin::MPI::size(MPI_COMM_WORLD) > 1) |
| 27 |
{ |
| 28 |
std::cout << "This demo does not work in parallel" << std::endl; |
| 29 |
return 0; |
| 30 |
} |
| 31 |
|
| 32 |
// Sub domain for right part of mesh |
| 33 |
class Right : public SubDomain |
| 34 |
{ |
| 35 |
bool inside(const Array<double>& x, bool on_boundary) const |
| 36 |
{ |
| 37 |
return x[0] <= 0.5; |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
// Sub domain for inflow (right) |
| 42 |
class Inflow : public SubDomain |
| 43 |
{ |
| 44 |
bool inside(const Array<double>& x, bool on_boundary) const |
| 45 |
{ |
| 46 |
return x[0] > 1.0 - DOLFIN_EPS && on_boundary; |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
auto mesh = std::make_shared<UnitSquareMesh>(5, 5); |
| 52 |
|
| 53 |
parameters["refinement_algorithm"] = "plaza_with_parent_facets"; |
| 54 |
|
| 55 |
// Create MeshFunction over cells |
| 56 |
MeshFunction<std::size_t> right_cells(mesh, mesh->topology().dim(), 0); |
| 57 |
Right right; |
| 58 |
right.mark(right_cells, 1); |
| 59 |
|
| 60 |
// Create MeshFunction over facets |
| 61 |
MeshFunction<std::size_t> inflow_facets(mesh, mesh->topology().dim() - 1, 0); |
| 62 |
Inflow inflow; |
| 63 |
inflow.mark(inflow_facets, 1); |
| 64 |
|
| 65 |
// Mark cells for refinement |
| 66 |
MeshFunction<bool> cell_markers(mesh, mesh->topology().dim(), false); |
| 67 |
Point p(1.0, 0.0); |
| 68 |
for (CellIterator c(*mesh); !c.end(); ++c) |
| 69 |
{ |
| 70 |
if (c->midpoint().distance(p) < 0.5) |
| 71 |
cell_markers[*c] = true; |
| 72 |
} |
| 73 |
|
| 74 |
// Refine mesh |
| 75 |
adapt(*mesh, cell_markers); |
| 76 |
|
| 77 |
// Adapt cell function to refined mesh |
| 78 |
adapt(right_cells, mesh->child_shared_ptr()); |
| 79 |
|
| 80 |
// Adapt facet function to refined mesh |
| 81 |
adapt(inflow_facets, mesh->child_shared_ptr()); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |