Flow123d
Macros | Functions
solve.cc File Reference

Unified interface to various linear solvers. More...

#include <ctype.h>
#include <strings.h>
#include "system/system.hh"
#include "system/sys_profiler.hh"
#include "system/xio.h"
#include "input/input_type.hh"
#include "input/accessors.hh"
#include "la/distribution.hh"
#include "la/solve.h"
#include "la/linsys.hh"

Go to the source code of this file.

Macros

#define TEST_TYPE(name_str, id)   if ( strcmpi( solver->name, name_str ) == 0 ) solver->type = (id);
 Set solver type from its name. More...
 
#define SET_GENERIC_CALL   sprintf( cmdline, "%s %s",solver->executable,solver->params.c_str())
 
#define SET_MATLAB_CALL   sprintf( cmdline, "matlab -r solve" )
 

Functions

static void solver_set_type (struct Solver *solver)
 
static void RunExtern (struct Solver *solver, char *cmdline, void(*write_sys)(struct Solver *), void(*read_sol)(struct Solver *))
 
static void clean_directory (void)
 Clean temporary directory of external solver. More...
 
void solver_init (Solver *solver, Input::AbstractRecord in_rec)
 Initialize a solver structure. More...
 
void solve_system (struct Solver *solver, struct LinSys *system)
 Solves a given linear system. More...
 
void RunExtern (Solver *solver, char *cmdline, void(*write_sys)(Solver *), void(*read_sol)(Solver *))
 Call an external solver. More...
 
void solver_petsc (Solver *solver)
 
static void write_sys_matlab (struct Solver *solver)
 MATLAB call functions. More...
 
static void write_matlab_linsys (LinSys *mtx, int write_nz)
 Write MATLAB system. More...
 
static void read_sol_matlab (struct Solver *solver)
 Read MATLAB solution into solver->LinSys->vx. More...
 
static void isol_params_init (ISOL_params *par)
 ISOL calling functions. More...
 
static void write_sys_isol (struct Solver *solver)
 Write down input for ISOL. More...
 

Detailed Description

Unified interface to various linear solvers.

Copyright (C) 2007 Technical University of Liberec. All rights reserved.

Please make a following refer to Flow123d on your project site if you use the program for any purpose, especially for academic research: Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.

$Id$ $Revision$ $LastChangedBy$ $LastChangedDate$

Author
Jan Brezina

The only internal (linked) solver is PETSC KPS which is already interface to the number of direct and iterative solvers. Further several external solvers are supported: MATLAB, ISOL (due to Pavel Jiranek)

Definition in file solve.cc.

Macro Definition Documentation

#define SET_GENERIC_CALL   sprintf( cmdline, "%s %s",solver->executable,solver->params.c_str())
#define SET_MATLAB_CALL   sprintf( cmdline, "matlab -r solve" )
#define TEST_TYPE (   name_str,
  id 
)    if ( strcmpi( solver->name, name_str ) == 0 ) solver->type = (id);

Set solver type from its name.

The name comparison is case insensitive.one test macro

Definition at line 151 of file solve.cc.

Function Documentation

void clean_directory ( void  )
static

Clean temporary directory of external solver.

Definition at line 280 of file solve.cc.

Here is the caller graph for this function:

void isol_params_init ( ISOL_params par)
static

ISOL calling functions.

Definition at line 480 of file solve.cc.

void read_sol_matlab ( struct Solver solver)
static

Read MATLAB solution into solver->LinSys->vx.

Definition at line 617 of file solve.cc.

Here is the caller graph for this function:

static void RunExtern ( struct Solver solver,
char *  cmdline,
void(*)(struct Solver *)  write_sys,
void(*)(struct Solver *)  read_sol 
)
static

Here is the caller graph for this function:

void RunExtern ( Solver solver,
char *  cmdline,
void(*)(Solver *)  write_sys,
void(*)(Solver *)  read_sol 
)

Call an external solver.

Make temporary directory, write down matrix and RHS vector. Then perform system call of given program and read solution form given file.

Parameters
[in,out]solversolver structure to use (solution in linear system)
[in]cmdlinecalling command line
[in]write_sysfunction to write down linear system
[in]read_solfunction to read the solution

prepare data

if user provides an explicit control file, use that one instead

run the solver

read the solution

Definition at line 227 of file solve.cc.

void solve_system ( struct Solver solver,
struct LinSys system 
)

Solves a given linear system.

Call user selected internal or external solver.

Parameters
[in]solversolver structure to use
[in,out]systemlinear system to solve, conatains also result
Precondition
Initialized solver. Assembled system.
Postcondition
Valid solution.

set command line for external solvers

Definition at line 178 of file solve.cc.

void solver_init ( Solver solver,
Input::AbstractRecord  in_rec 
)

Initialize a solver structure.

Initialize all members form the users options. Possibly initialize specific solver parameters.

Parameters
[in]solveralready allocated structure to be initialized
[in]in_recinput record

Definition at line 99 of file solve.cc.

void solver_petsc ( Solver solver)

Definition at line 319 of file solve.cc.

void solver_set_type ( struct Solver solver)
static

Definition at line 153 of file solve.cc.

void write_matlab_linsys ( LinSys mtx,
int  write_nz 
)
static

Write MATLAB system.

Write matrix in MATLAB format to matrix.dat and RHS into rhs.dat.

Parameters
[in]mtxLinear system to write out.
[in]write_nz(1 - write number of non-zeroes (ISOL); 0 - don't write (MATLAB))

Definition at line 588 of file solve.cc.

Here is the caller graph for this function:

void write_sys_isol ( struct Solver solver)
static

Write down input for ISOL.

write the control file

write the linear system - using MATLAB format

Definition at line 504 of file solve.cc.

Here is the caller graph for this function:

void write_sys_matlab ( struct Solver solver)
static

MATLAB call functions.

Write input for MATLAB

written files: matrix.dat, rhs.dat, solve.m

Definition at line 563 of file solve.cc.

Here is the caller graph for this function: