main.cpp

来自「利用C」· C++ 代码 · 共 71 行

CPP
71
字号
// Copyright (C) 2006-2007 Anders Logg and Kristian Oelgaard.// Licensed under the GNU LGPL Version 2.1.//// First added:  2006-12-05// Last changed: 2007-08-20//// This demo program solves Poisson's equation////     - div grad u(x, y) = f(x, y)//// on the unit square with source f given by////     f(x, y) = 500*exp(-((x-0.5)^2 + (y-0.5)^2)/0.02)//// and boundary conditions given by////     u(x, y)     = 0//     du/dn(x, y) = 0//// using a discontinuous Galerkin formulation (interior penalty method).#include <dolfin.h>#include "Poisson.h"using namespace dolfin;int main(){  // Source term  class Source : public Function  {  public:        Source(Mesh& mesh) : Function(mesh) {}    real eval(const real* x) const    {      real dx = x[0] - 0.5;      real dy = x[1] - 0.5;      return 500.0*exp(-(dx*dx + dy*dy)/0.02);    }  };   // Create mesh  UnitSquare mesh(64, 64);  // Create functions  Source f(mesh);  FacetNormal n(mesh);  AvgMeshSize h(mesh);  // Define PDE  PoissonBilinearForm a(n, h);  PoissonLinearForm L(f);  LinearPDE pde(a, L, mesh);  // Solve PDE  Function u;  pde.solve(u);  // Plot solution  plot(u);  // Save solution to file  File file("poisson.pvd");  file << u;  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?