Commit 1a4bb4bd authored by Dmitry Bagaev's avatar Dmitry Bagaev

mat solve example update, k3biilu2 and fcbiilu2 interfaces

parent 0002d429
.svn
Tests/solver_test001/matrices
SyncToy*
build*/
......@@ -7,4 +7,4 @@ add_subdirectory(FVDiscr)
add_subdirectory(ADFVDiscr)
add_subdirectory(ADMFD)
#add_subdirectory(OctreeCutcell)
add_subdirectory(Solver)
add_subdirectory(Solver)
\ No newline at end of file
project(MatSolve)
set(SOURCE main.cpp)
set(SOURCE main.cpp inner_parser.cpp)
add_executable(MatSolve ${SOURCE})
......@@ -7,10 +7,10 @@ target_link_libraries(MatSolve inmost)
if(USE_MPI)
message("linking MatSolve with MPI")
target_link_libraries(MatSolve ${MPI_LIBRARIES})
target_link_libraries(MatSolve ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(MatSolve PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif()
endif(USE_MPI)
if(USE_SOLVER)
......
enum maximum_iterations 300
enum gmres_substeps 4
real relative_tolerance 1.0e-5
real absolute_tolerance 1.0e-10
real divergence_tolerance 1e+200
enum reorder_nonzeros 0
enum rescale_iterations 8
enum adapt_ddpq_tolerance 0
real drop_tolerance 3.0e-5
real reuse_tolerance 1.0e-5
real ddpq_tolerance 0.0
enum condition_estimation 1
enum schwartz_overlap 6
#include "inner_parser.h"
void removeSpaces(char* source) {
char* i = source;
char* j = source;
while(*j != 0)
{
*i = *j++;
if(*i != ' ')
i++;
}
*i = 0;
}
InnerOptions *parseInnerDatabaseOptions(char *optionsFile) {
FILE *databaseFile = fopen(optionsFile, "r");
if (!databaseFile) {
std::cout << "Inner options file not found" << std::endl;
return nullptr;
}
InnerOptions *options = new InnerOptions();
char *tmp = (char *) calloc(256, sizeof(char));
char *parameterName = (char *) calloc(128, sizeof(char));
char *parameterValue = (char *) calloc(128, sizeof(char));
char *type = (char *) calloc(36, sizeof(char));
while (!feof(databaseFile) && fgets(tmp, 256, databaseFile)) {
//removeSpaces(tmp);
char *line = tmp;
//Comment str
if (line[0] == '#') continue;
//First 4 chars is 'real' or 'enum'
bool isReal = false, isEnum = false;
sscanf(line, "%s %s %s", type, parameterName, parameterValue);
if (strncmp(type, "real", 4) == 0) {
//fprintf(stdout, "Real parameter:");
isReal = true;
} else if (strncmp(type, "enum", 4) == 0) {
//fprintf(stdout, "Enum parameter:");
isEnum = true;
} else {
fprintf(stderr, "Skipping bad line: %s", line);
continue;
}
options->options.push_back(new InnerOption(std::string(parameterName), std::string(parameterValue), isReal ? REAL : ENUM));
}
free(parameterValue);
free(parameterName);
free(tmp);
free(type);
return options;
}
char *findInnerOptions(const char *databaseFilePath) {
FILE *databaseFile = fopen(databaseFilePath, "r");
if (databaseFile == NULL) {
fprintf(stderr, "Database file not found\n");
#if defined(USE_MPI)
MPI_Finalize();
#endif
exit(1);
}
char *tmp = (char *) calloc(256, sizeof(char));
char *parameterName = (char *) calloc(64, sizeof(char));
char *parameterValue = (char *) calloc(64, sizeof(char));
char *fileName = NULL;
while (!feof(databaseFile) && fgets(tmp, 256, databaseFile)) {
removeSpaces(tmp);
char *line = tmp;
if (strncmp(line, "inner", 5) != 0) continue;
line += 6;
size_t fileNameLength = 0;
while (!isspace(*(line + fileNameLength))) fileNameLength += 1;
fileName = (char *) calloc(fileNameLength + 1, sizeof(char));
memcpy(fileName, line, fileNameLength);
fileName[fileNameLength] = 0;
}
free(tmp);
return fileName;
}
#ifndef INMOST_INNER_PARSER_H_H
#define INMOST_INNER_PARSER_H_H
#include <string>
#include <iostream>
#include <vector>
enum OptionType {
REAL,
ENUM
};
class InnerOption {
public:
InnerOption(const std::string &name, const std::string &value, OptionType type) : name(name), value(value),
type(type) { }
std::string name;
std::string value;
OptionType type;
};
class InnerOptions {
public:
std::vector<InnerOption *> options;
};
char *findInnerOptions(const char *databaseFilePath);
InnerOptions *parseInnerDatabaseOptions(char *optionsFile);
#endif //INMOST_INNER_PARSER_H_H
This diff is collapsed.
......@@ -42,23 +42,25 @@ if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h" AND EXISTS "${CMAKE_C
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_FCBIILU2)
set(HAVE_SOLVER_FCBIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp fcbiilu2.cpp)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp)
else()
set(HAVE_SOLVER_FCBIILU2 FALSE)
endif()
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS
if (USE_MPI)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp" )
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2)
set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp)
else()
set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE)
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2)
set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp)
else()
set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE)
endif()
endif()
set(HEADER ${HEADER} PARENT_SCOPE)
set(SOURCE ${SOURCE} PARENT_SCOPE)
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} PARENT_SCOPE)
\ No newline at end of file
......@@ -1644,7 +1644,7 @@ namespace INMOST
ia[0] = shift;
for(Sparse::Matrix::iterator it = A.Begin(); it != A.End(); it++)
{
for(Row::iterator jt = it->Begin(); jt != it->End(); jt++)
for(Sparse::Row::iterator jt = it->Begin(); jt != it->End(); jt++)
{
ja[k] = jt->first + 1;
values[k] = jt->second;
......
This diff is collapsed.
#ifndef SOLVER_FCBIILU2_H_INCLUDED
#define SOLVER_FCBIILU2_H_INCLUDED
#include "inmost_solver.h"
//#define USE_SOLVER_FCBIILU2 //just for test; see flag HAVE_SOLVER_FCBIILU2
//#if defined(USE_SOLVER_FCBIILU2)
void MatrixCopyDataFcbiilu2(void ** ppA, void * pB);
void MatrixAssignDataFcbiilu2(void * pA, void * pB);
void MatrixInitDataFcbiilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void MatrixDestroyDataFcbiilu2(void ** pA);
void MatrixFillFcbiilu2(void * pA, int size, int nproc, int * ibl, int * ia, int * ja, double * values);
void MatrixFillValuesFcbiilu2(void * pA, double * values);
void MatrixFinalizeFcbiilu2(void * data);
void VectorInitDataFcbiilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void VectorCopyDataFcbiilu2(void ** ppA, void * pB);
void VectorAssignDataFcbiilu2(void * pA, void * pB);
void VectorPreallocateFcbiilu2(void * pA, int size);
void VectorFillFcbiilu2(void * pA, double * values);
void VectorLoadFcbiilu2(void * pA, double * values);
void VectorFinalizeFcbiilu2(void * data);
void VectorDestroyDataFcbiilu2(void ** ppA);
void SolverInitializeFcbiilu2(int * argc,char *** argv, const char * file_options);
bool SolverIsFinalizedFcbiilu2();
void SolverFinalizeFcbiilu2();
void SolverDestroyDataFcbiilu2(void ** data);
void SolverInitDataFcbiilu2(void ** data, INMOST_MPI_Comm comm, const char * name);
void SolverCopyDataFcbiilu2(void ** data, void * other_data, INMOST_MPI_Comm comm);
void SolverAssignDataFcbiilu2(void * data, void * other_data);
void SolverSetMatrixFcbiilu2(void * data, void * matrix_data, bool same_pattern, bool reuse_preconditioner);
bool SolverSolveFcbiilu2(void * data, void * rhs_data, void * sol_data);
int SolverIterationNumberFcbiilu2(void * data);
double SolverResidualNormFcbiilu2(void * data);
void SolverAddOtherStatFcbiilu2(void * data, unsigned int * pivmod, double * prdens, double * t_prec, double * t_iter);
//#endif //USE_FCSOLVER_BIILU2
#endif //SOLVER_FCBIILU2_H_INCLUDED
This diff is collapsed.
#ifndef SOLVER_K3BIILU2_H_INCLUDED
#define SOLVER_K3BIILU2_H_INCLUDED
#include "inmost_solver.h"
//#define USE_SOLVER_K3BIILU2 //just for test; see flag HAVE_SOLVER_K3BIILU2
//#if defined(USE_SOLVER_K3BIILU2)
void MatrixCopyDataK3biilu2(void ** ppA, void * pB);
void MatrixAssignDataK3biilu2(void * pA, void * pB);
void MatrixInitDataK3biilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void MatrixDestroyDataK3biilu2(void ** pA);
void MatrixFillK3biilu2(void * pA, int size, int nproc, int * ibl, int * ia, int * ja, double * values);
void MatrixFillValuesK3biilu2(void * pA, double * values);
void MatrixFinalizeK3biilu2(void * data);
void VectorInitDataK3biilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void VectorCopyDataK3biilu2(void ** ppA, void * pB);
void VectorAssignDataK3biilu2(void * pA, void * pB);
void VectorPreallocateK3biilu2(void * pA, int size);
void VectorFillK3biilu2(void * pA, double * values);
void VectorLoadK3biilu2(void * pA, double * values);
void VectorFinalizeK3biilu2(void * data);
void VectorDestroyDataK3biilu2(void ** ppA);
void SolverInitializeK3biilu2(int * argc,char *** argv, const char * file_options);
bool SolverIsFinalizedK3biilu2();
void SolverFinalizeK3biilu2();
void SolverDestroyDataK3biilu2(void ** data);
void SolverInitDataK3biilu2(void ** data, INMOST_MPI_Comm comm, const char * name);
void SolverCopyDataK3biilu2(void ** data, void * other_data, INMOST_MPI_Comm comm);
void SolverAssignDataK3biilu2(void * data, void * other_data);
void SolverSetMatrixK3biilu2(void * data, void * matrix_data, bool same_pattern, bool reuse_preconditioner);
bool SolverSolveK3biilu2(void * data, void * rhs_data, void * sol_data);
int SolverIterationNumberK3biilu2(void * data);
double SolverResidualNormK3biilu2(void * data);
void SolverAddOtherStatK3biilu2(void * data, unsigned int * pivmod, double * prdens, double * t_prec, double * t_iter);
//#endif //USE_K3SOLVER_BIILU2
#endif //SOLVER_K3BIILU2_H_INCLUDED
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment