# include <gsAssembler/gsBiharmonicAssembler.h>
using namespace gismo;
int main(
int argc,
char *argv[])
{
bool plot = false;
gsCmdLine cmd(
"Example for solving the biharmonic problem.");
cmd.addInt("r", "refine", "Number of refinement steps", numRefine);
cmd.addInt("p", "degree", "Polynomial degree", numDegree);
cmd.addSwitch( "plot", "Plot result in ParaView format", plot );
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
dirichlet::strategy dirStrategy = dirichlet::elimination;
iFace::strategy intStrategy = iFace::glue;
gsFunctionExpr<> source (
"256*pi*pi*pi*pi*(4*cos(4*pi*x)*cos(4*pi*y) - cos(4*pi*x) - cos(4*pi*y))",2);
gsFunctionExpr<> laplace (
"-16*pi*pi*(2*cos(4*pi*x)*cos(4*pi*y) - cos(4*pi*x) - cos(4*pi*y))",2);
"-4*pi*(cos(4*pi*x) - 1)*sin(4*pi*y)",2);
"-16*pi^2*(cos(4*pi*x) - 1)*cos(4*pi*y)",
" 16*pi^2*sin(4*pi*x)*sin(4*pi*y)", 2);
gsFunctionWithDerivatives<real_t> solution(solVal, sol1der, sol2der);
for (int i = 0; i < numDegree; ++i)
for (int i = 0; i < numRefine; ++i)
dirStrategy, intStrategy);
gsInfo<<
"Assembling..." <<
"\n";
BiharmonicAssembler.assemble();
gsInfo<<
"Solving with direct solver, "<< BiharmonicAssembler.numDofs()<<
" DoFs..."<<
"\n";
gsSparseSolver<real_t>::LU solver;
solver.analyzePattern(BiharmonicAssembler.matrix() );
solver.factorize(BiharmonicAssembler.matrix());
gsMatrix<> solVector= solver.solve(BiharmonicAssembler.rhs());
BiharmonicAssembler.constructSolution(solVector, mpsol);
gsField<> solField(BiharmonicAssembler.patches(), mpsol);
real_t errorH2Semi = solField.distanceH2(solution, false);
real_t errorH1Semi = solField.distanceH1(solution, false);
real_t errorL2 = solField.distanceL2(solution, false);
real_t errorH1 = math::sqrt(errorH1Semi*errorH1Semi + errorL2*errorL2);
real_t errorH2 = math::sqrt(errorH2Semi*errorH2Semi + errorH1Semi*errorH1Semi + errorL2*errorL2);
gsInfo <<
"The L2 error of the solution is : " << errorL2 <<
"\n";
gsInfo <<
"The H1 error of the solution is : " << errorH1 <<
"\n";
gsInfo <<
"The H2 error of the solution is : " << errorH2 <<
"\n";
if (plot)
{
gsInfo<<
"Plotting in ParaView...\n";
gsWriteParaview<>(solField, "Biharmonic2d", 5000);
const gsField<> exact( geo, solution,
false );
gsWriteParaview<>( exact, "Biharmonic2d_exact", 5000);
}
else
gsInfo <<
"Done. No output created, re-run with --plot to get a ParaView "
"file containing the solution.\n";
return 0;
}