From 9fdb743d98b0cb918c84144e2eb5dfd2978d0f7a Mon Sep 17 00:00:00 2001 From: guido Date: Mon, 26 Apr 1999 20:04:34 +0000 Subject: [PATCH] Test fuer iterative Loeser git-svn-id: https://svn.dealii.org/trunk@1210 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/lac/Makefile | 109 ++++++++++++++++++++++++++++++++++++++++ tests/lac/solver.cc | 87 ++++++++++++++++++++++++++++++++ tests/lac/testmatrix.cc | 82 ++++++++++++++++++++++++++++++ tests/lac/testmatrix.h | 39 ++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 tests/lac/Makefile create mode 100644 tests/lac/solver.cc create mode 100644 tests/lac/testmatrix.cc create mode 100644 tests/lac/testmatrix.h diff --git a/tests/lac/Makefile b/tests/lac/Makefile new file mode 100644 index 0000000000..3d1a1cf7ab --- /dev/null +++ b/tests/lac/Makefile @@ -0,0 +1,109 @@ +############################################################ +# Directory with the DEAL distribution +############################################################ + +D = ../.. + + +############################################################ +# Include general settings for including DEAL libraries +############################################################ + +include $D/common/Make.global_options + + +############################################################ +# Set debug-mode as a default +############################################################ + +debug-mode = on + + +############################################################ +# Define library names +############################################################ + +libs = -llac -lbase +libs.g = -llac.g -lbase.g + + +############################################################ +# Select compiler flags according to debug-mode +############################################################ + +ifeq ($(debug-mode),on) +libraries = $(libs.g) +flags = $(CXXFLAGS.g) $(CXXFLAGS) +endif + +ifeq ($(debug-mode),off) +libraries = $(libs) +flags = $(CXXFLAGS.o) $(CXXFLAGS) +endif + +all: solver + +############################################################ +# Typical block for building a running program +# +# 1. provide a list of source files in ...-cc-files +# +# 2. generate the list of object files according to debug-mode +# +# 3. make executable +# +# 4. Explicit dependencies of object files (will be automatic soon) +# +############################################################ + +solver-cc-files = solver.cc testmatrix.cc + +ifeq ($(debug-mode),on) +solver-o-files = $(solver-cc-files:.cc=.go) +else +solver-o-files = $(solver-cc-files:.cc=.o) +endif + +solver: $(solver-o-files) $(libraries) + $(CXX) $(flags) -o $@ $^ + +############################################################ +# Continue with other targets if needed +############################################################ + + +target1-cc-files = t1.cc t2.cc t3.cc + +ifeq ($(debug-mode),on) +target1-o-files = $(target1-cc-files:.cc=.go) +else +target1-o-files = $(target1-cc-files:.cc=.o) +endif + +target1: $(target1-o-files) $(libraries) + $(CXX) $(flags) -o $@ $^ + + + +############################################################ +# Cleanup targets +############################################################ + +clean: + rm -f *.o *.go + +veryclean: clean + rm -f solver *.inp *.gpl *.eps *.gnuplot + +############################################################ +# Automatic generation of dependencies +############################################################ + +all-cc-files = $(solver-cc-files) # $(target2-cc-files) ... + +Make.depend: $(all-cc-files) + @echo =====Dependecies=== Make.depend + @$(CXX) $(flags) $^ -M > $@ + @perl -pi~ -e 's/(^[^.]+)\.o:/\1.o \1.go:/;' $@ + +include Make.depend diff --git a/tests/lac/solver.cc b/tests/lac/solver.cc new file mode 100644 index 0000000000..0ca3ec959d --- /dev/null +++ b/tests/lac/solver.cc @@ -0,0 +1,87 @@ +// $Id$ +// +// Test program for linear solvers. + +#include +#include "testmatrix.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MATRIX SparseMatrix +#define VECTOR Vector + +main() +{ + PrimitiveVectorMemory mem; + SolverControl control(100, 1.e-5, true); + SolverPCG cg(control, mem); + SolverGMRES gmres(control, mem,20); + SolverBicgstab bicgstab(control, mem); + SolverRichardson rich(control, mem); + + for (unsigned int size=10; size <= 10; size *= 10) + { + deallog << "Size " << size << endl; + + unsigned int dim = (size+1)*(size+1); + + // Make matrix + FDMatrix testproblem(size, size); + SparseMatrixStruct structure(dim, dim, 5); + testproblem.build_structure(structure); + structure.compress(); + MATRIX A(structure); + testproblem.laplacian(A); + + PreconditionIdentity + prec_no; + PreconditionRelaxation + prec_ssor(A, &MATRIX::template precondition_SSOR, 1.2); + + VECTOR f(dim); + VECTOR u(dim); + + deallog.push("no"); + + f = 1.; + u = 0.; + cg.solve(A,u,f,prec_no); + + f = 1.; + u = 0.; + bicgstab.solve(A,u,f,prec_no); + + f = 1.; + u = 0.; + gmres.solve(A,u,f,prec_no); + + deallog.pop(); + deallog.push("ssor"); + + f = 1.; + u = 0.; + rich.solve(A,u,f,prec_ssor); + + f = 1.; + u = 0.; + cg.solve(A,u,f,prec_ssor); + + f = 1.; + u = 0.; + bicgstab.solve(A,u,f,prec_ssor); + + f = 1.; + u = 0.; + gmres.solve(A,u,f,prec_ssor); + + deallog.pop(); + } +} diff --git a/tests/lac/testmatrix.cc b/tests/lac/testmatrix.cc new file mode 100644 index 0000000000..656cadef33 --- /dev/null +++ b/tests/lac/testmatrix.cc @@ -0,0 +1,82 @@ +// $Id$ + +#include "testmatrix.h" +#include + +FDMatrix::FDMatrix(unsigned int nx, unsigned int ny) + : + nx(nx), ny(ny) +{} + +void +FDMatrix::build_structure(SparseMatrixStruct& structure) const +{ + for(unsigned int i=0;i<=ny;i++) + { + for(unsigned int j=0;j<=nx; j++) + { + // Number of the row to be entered + unsigned int row = j+(nx+1)*i; + structure.add(row, row); + if (j>0) + { + structure.add(row-1, row); + structure.add(row, row-1); + } + if (j0) + { + structure.add(row-nx, row); + structure.add(row, row-nx); + } + if (i +void +FDMatrix::laplacian(SparseMatrix& A) const +{ + for(unsigned int i=0;i<=ny;i++) + { + for(unsigned int j=0;j<=nx; j++) + { + // Number of the row to be entered + unsigned int row = j+(nx+1)*i; + + A.set(row, row, 4.); + if (j>0) + { + A.set(row-1, row, -1.); + A.set(row, row-1, -1.); + } + if (j0) + { + A.set(row-nx, row, -1.); + A.set(row, row-nx, -1.); + } + if (i&) const; +template void FDMatrix::laplacian(SparseMatrix&) const; diff --git a/tests/lac/testmatrix.h b/tests/lac/testmatrix.h new file mode 100644 index 0000000000..ffb32d8e8a --- /dev/null +++ b/tests/lac/testmatrix.h @@ -0,0 +1,39 @@ +// $Id$ + +#include + +/** + * Finite difference matrix on uniform grid. + * Generator for simple 5-point discretization of Laplace problem. + */ + +class FDMatrix +{ + public: + /** + * Constructor specifying grid resolution. + */ + FDMatrix(unsigned int nx, unsigned int ny); + + /** + * Generate the matrix structure. + */ + void build_structure(SparseMatrixStruct& structure) const; + + /** + * Fill the matrix with values. + */ + template + void laplacian(SparseMatrix&) const; + + private: + /** + * Number of gridpoints in x-direction. + */ + unsigned int nx; + + /** + * Number of gridpoints in y-direction. + */ + unsigned int ny; +}; -- 2.39.5