| 1 |
#include <dolfin.h> |
| 2 |
#include "MeshView_3D2D.h" |
| 3 |
|
| 4 |
using namespace dolfin; |
| 5 |
|
| 6 |
// Sub domain for Dirichlet boundary condition |
| 7 |
class DirichletBoundary : public SubDomain |
| 8 |
{ |
| 9 |
bool inside(const Array<double>& x, bool on_boundary) const |
| 10 |
{ |
| 11 |
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS; |
| 12 |
} |
| 13 |
}; |
| 14 |
|
| 15 |
// Source term (right-hand side) |
| 16 |
class Source : public Expression |
| 17 |
{ |
| 18 |
void eval(Array<double>& values, const Array<double>& x) const |
| 19 |
{ |
| 20 |
double dx = x[0] - 0.5; |
| 21 |
double dy = x[1] - 0.5; |
| 22 |
values[0] = 10*exp(-(dx*dx + dy*dy) / 0.02); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
int main() |
| 27 |
{ |
| 28 |
// Create mesh and function space |
| 29 |
auto mesh = std::make_shared<UnitCubeMesh>(32, 32, 32); |
| 30 |
|
| 31 |
MeshFunction<std::size_t> marker(mesh, mesh->topology().dim() - 1, 0); |
| 32 |
for (FacetIterator facet(*mesh); !facet.end(); ++facet) |
| 33 |
{ |
| 34 |
auto x = facet->midpoint().coordinates(); |
| 35 |
marker[facet->index()] = 0.5 - DOLFIN_EPS < x[2] && x[2] < 0.5 + DOLFIN_EPS; |
| 36 |
} |
| 37 |
|
| 38 |
std::vector<std::size_t> vertex_map,cell_map; |
| 39 |
auto mapping = std::make_shared<MeshView>(mesh,vertex_map,cell_map); |
| 40 |
auto submesh = std::make_shared<Mesh>(mapping->create(marker, 1)); |
| 41 |
|
| 42 |
// Function spaces associated with each of the function spaces |
| 43 |
auto V1 = std::make_shared<MeshView_3D2D::Form_a00::TestSpace>(mesh); // 3D |
| 44 |
auto V2 = std::make_shared<MeshView_3D2D::Form_a11::TestSpace>(submesh); // 2D |
| 45 |
|
| 46 |
// Bilinear and linear forms |
| 47 |
MeshView_3D2D::Form_a00 a_3D(V1, V1); |
| 48 |
MeshView_3D2D::Form_a11 a_2D(V2, V2); |
| 49 |
MeshView_3D2D::Form_L0 L_3D(V1); |
| 50 |
MeshView_3D2D::Form_L1 L_2D(V2); |
| 51 |
|
| 52 |
// Define boundary conditions |
| 53 |
auto zero = std::make_shared<Constant>(0.0); |
| 54 |
auto boundary = std::make_shared<DirichletBoundary>(); |
| 55 |
DirichletBC bc_3D(V1, zero, boundary); |
| 56 |
DirichletBC bc_2D(V2, zero, boundary); |
| 57 |
|
| 58 |
// Define RHS |
| 59 |
auto f = std::make_shared<Source>(); |
| 60 |
L_3D.f1 = f; |
| 61 |
L_2D.f2 = f; |
| 62 |
|
| 63 |
// Compute solution |
| 64 |
// Subproblem 3D |
| 65 |
Function u_3D(V1); |
| 66 |
solve(a_3D == L_3D, u_3D, bc_3D); |
| 67 |
// Subproblem 2D |
| 68 |
Function u_2D(V2); |
| 69 |
solve(a_2D == L_2D, u_2D, bc_2D); |
| 70 |
|
| 71 |
// Save solution in vtk format |
| 72 |
File out_3D("meshview-mapping-3D2D-3Dsol.pvd"); |
| 73 |
out_3D << u_3D; |
| 74 |
File out_2D("meshview-mapping-3D2D-2Dsol.pvd"); |
| 75 |
out_2D << u_2D; |
| 76 |
} |
| 77 |
|
| 78 |
|