From dd54d344ba656808f06802e659b44b1e7096c777 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Sun, 6 Mar 2005 02:39:23 +0000 Subject: [PATCH] example for use of BlockMatrixArray and BlockTrianglePrecondition git-svn-id: https://svn.dealii.org/trunk@10008 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/doxygen/Makefile | 40 ++++++ .../examples/doxygen/block_matrix_array.cc | 122 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 deal.II/examples/doxygen/Makefile create mode 100644 deal.II/examples/doxygen/block_matrix_array.cc diff --git a/deal.II/examples/doxygen/Makefile b/deal.II/examples/doxygen/Makefile new file mode 100644 index 0000000000..0a8ac81139 --- /dev/null +++ b/deal.II/examples/doxygen/Makefile @@ -0,0 +1,40 @@ +########################################################################### +# $Id$ +# Version: $Name$ +# +# Copyright (C) 1998 - 2005 by the deal.II authors +# +# This file is subject to QPL and may not be distributed +# without copyright and license information. Please refer +# to the file deal.II/doc/license.html for the text and +# further information on this license. +# +########################################################################### +include ../../common/Make.global_options + +all: block_matrix_array.exe + +###################################################################### +# Compilation of source code +###################################################################### + +%.o : %.cc + @echo =====debug======$(MT)== $< + @$(CXX) $(CXXFLAGS.g) $(CXXFLAGS) -c $< -o $@ + +###################################################################### +# Specific targets +###################################################################### + +block_matrix_array.exe: block_matrix_array.o $(lib-base.g) $(lib-lac.g) + @echo =====linking====$(MT)== $< + @$(CXX) $(CXXFLAGS.g) $(LDFLAGS) -o $@ $^ + + + +###################################################################### +# Pseudo target for cleaning directory +###################################################################### + +clean: + rm *~ *.o *.exe diff --git a/deal.II/examples/doxygen/block_matrix_array.cc b/deal.II/examples/doxygen/block_matrix_array.cc new file mode 100644 index 0000000000..a69b774a3f --- /dev/null +++ b/deal.II/examples/doxygen/block_matrix_array.cc @@ -0,0 +1,122 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- + +// See documentation of BlockMatrixArray for documentation of this example + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +double Adata[] = +{ + 4., .5, .1, 0., + .5, 4., .5, .1, + .1, .5, 4., .5, + 0., .1, .5, 4. +}; + +double B1data[] = +{ + .5, .1, + .4, .2, + .3, .3, + .2, .4 +}; + +double B2data[] = +{ + .3, 0., -.3, 0., + -.3, 0., .3, 0. +}; + +double Cdata[] = +{ + 8., 1., + 1., 8. +}; + +int main () +{ + FullMatrix A(4,4); + FullMatrix B1(4,2); + FullMatrix B2(2,4); + FullMatrix C(2,2); + + A.fill(Adata); + B1.fill(B1data); + B2.fill(B2data); + C.fill(Cdata); + + BlockMatrixArray > matrix(2,2); + + matrix.enter(A,0,0,2.); + matrix.enter(B1,0,1,-1.); + matrix.enter(B2,0,1,1., true); + matrix.enter(B2,1,0,1.); + matrix.enter(B1,1,0,-1., true); + matrix.enter(C,1,1); + matrix.print_latex(deallog); + + std::vector block_sizes(2); + block_sizes[0] = 4; + block_sizes[1] = 2; + + BlockVector result(block_sizes); + BlockVector x(block_sizes); + BlockVector y(block_sizes); + for (unsigned int i=0;i > mem; + PreconditionIdentity id; + + SolverCG > cg(control, mem); + cg.solve(matrix, x, y, id); + x.add(-1., result); + deallog << "Error " << x.l2_norm() << std::endl; + + FullMatrix Ainv(4,4); + Ainv.invert(A); + FullMatrix Cinv(2,2); + Cinv.invert(C); + + BlockTrianglePrecondition > precondition(2,2); + precondition.enter(Ainv,0,0,.5); + precondition.enter(Cinv,1,1); + + cg.solve(matrix, x, y, precondition); + x.add(-1., result); + deallog << "Error " << x.l2_norm() << std::endl; + + precondition.enter(B1,1,0,-1., true); + precondition.enter(B2,1,0,1.); + + SolverGMRES > gmres(control, mem); + gmres.solve(matrix, x, y, precondition); + x.add(-1., result); + deallog << "Error " << x.l2_norm() << std::endl; + + return 0; +} -- 2.39.5