Commit 6c87951b authored by Kirill Terekhov's avatar Kirill Terekhov
Browse files

add readmes and examples

parent 09c09f3b
......@@ -2,7 +2,6 @@ projects/
AsmJit/
compile32_vs2013/
compile64_vs2013/
examples/
examples/Data/
examples/Matrices/
examples/Grids/
......
ANI3D solvers
=======
This folder contains solvers from Ani3D package from:
http://sourceforge.net/projects/ani3d/
This folder stores some experimental code
add_subdirectory(DrawGrid)
add_subdirectory(OldDrawGrid)
add_subdirectory(DrawMatrix)
add_subdirectory(MatSolve)
add_subdirectory(OctreeCutcell)
add_subdirectory(Solver)
\ No newline at end of file
project(DrawGrid)
set(SOURCE main.cpp
rotate.cpp
rotate.h
my_glut.h)
find_package(OpenGL)
if (WIN32)
find_path(GLUT_INCLUDE_DIR GL/glut.h )
if (CYGWIN)
find_library(GLUT_glut_LIBRARY glut32 )
else ()
if(BORLAND)
set (GLUT_glut_LIBRARY import32 CACHE STRING "GLUT library for win32")
else()
set (GLUT_glut_LIBRARY opengl32 CACHE STRING "GLUT library for win32")
endif()
endif ()
if(NOT GLUT_glut_LIBRARY)
#-- use old way to find GLUT
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
endif(NOT GLUT_glut_LIBRARY)
#include(FindPackageHandleStandardArgs.cmake)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
if (GLUT_glut_LIBRARY)
message("GLUT library found")
set( GLUT_LIBRARIES ${GLUT_glut_LIBRARY})
#The following deprecated settings are for backwards compatibility with CMake1.4
set (GLUT_LIBRARY ${GLUT_LIBRARIES})
if(NOT GLUT_INCLUDE_DIR)
message("GLUT include directory not found - trying to set OpenGL library")
message("OpenGL library is ${OPENGL_INCLUDE_DIR}")
set(GLUT_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
set(GLUT_FOUND 1)
else(NOT GLUT_INCLUDE_DIR)
set(GLUT_FOUND 1)
endif(NOT GLUT_INCLUDE_DIR)
endif(GLUT_glut_LIBRARY)
else(WIN32)
find_package(GLUT)
endif(WIN32)
if(OPENGL_FOUND)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(GLUT_FOUND)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
add_executable(DrawGrid ${SOURCE})
target_link_libraries(DrawGrid ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} inmost)
if(USE_MPI)
target_link_libraries(DrawGrid ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(DrawGrid PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
else(GLUT_FOUND)
message("GLUT not found")
endif(GLUT_FOUND)
else(OPENGL_FOUND)
message("OpenGL not found")
endif(OPENGL_FOUND)
CXX=mpicxx
CC=mpicxx
#links for cluster
#PETSC_DIR=/data4t/terekhov/Packages/petsc-3.3-p3
#PETSC_ARCH=arch-linux2-c-opt
#INCPATH = -I${PETSC_DIR}/${PETSC_ARCH}/include -I${PETSC_DIR}/include
MSPPLIB = ../../mspp.a
#MSPPLIB = ../../msppd.a
#OPTFLAGS= -O0 -g -Wall -Wno-unused-function
OPTFLAGS= -Ofast -flto -fwhole-program -march=native -DNDEBUG -ftree-vectorize
OPENGL=-L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU
#OPENGL=-framework GLUT -framework OpenGL
#OPENGL=-lglut -lgl -lglu32 -lopengl32
#OPENGL=-L/lib -lglu32 -lopengl32
MYLIBS= $(OPENGL)
CXXFLAGS=$(OPTFLAGS) $(INCPATH)
LDFLAGS=$(OPTFLAGS)
LDLIBS=$(MYLIBS) $(PETSC)
targets=main
all: $(targets)
main: main.o rotate.o $(MSPPLIB)
clean:
rm -f $(targets) *.o
This diff is collapsed.
#if defined (__APPLE__) || defined(MAXOSX)
#include <GLUT/glut.h>
#endif
#if defined(_WIN32)
//#include <GL/glut.h>
// В windows следует скачать тот самый glut по ссылке
// http://www.opengl.org/resources/libraries/glut/
// и положить в папку с компилирующимся файлом
// так же следует установить пару библиотек
#define NOMINMAX
#include <windows.h>
#include <GL/glut.h>
//#include "glut.h"
#pragma comment(lib,"glut32.lib")
#endif
#if defined(__linux__)
#include <GL/glut.h>
#endif
/*********************************
Implementation of quaternion-based
object rotation
Functions
clickmotion - call when holded mouse moved
click - call when user clicks
motion - call when mouse just moves
quatinit - flush rotation value
rotate - multiply GL matrix
Dependency: rotate.h,
Standard: math.h
Specific: glut.h
**********************************/
#include "my_glut.h"
#include "rotate.h"
#include "math.h"
struct quaternion
{
double x,y,z,w;
};
struct vector
{
double x,y,z;
};
// Rotation
struct quaternion q;
struct vector drag, onclick;
double mx,my;
extern int width, height;
extern int interactive;
//
void clickmotion(int nmx, int nmy) // Mouse
{
struct vector n;
double norm,length,t;
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
norm = mx*mx + my*my;
if( norm > 1.0 )
{
length = sqrt(norm);
drag.x = mx/length;
drag.y = my/length;
drag.z = 0.0;
}
else
{
drag.x = mx;
drag.y = my;
drag.z = sqrt(1.0-norm);
}
n.x = drag.y*onclick.z - drag.z*onclick.y;
n.y = drag.z*onclick.x - drag.x*onclick.z;
n.z = drag.x*onclick.y - drag.y*onclick.x;
if ( n.x*n.x + n.y*n.y + n.z*n.z > 10e-7 )
{
t = drag.x*onclick.x + drag.y*onclick.y + drag.z*onclick.z;
q.x = + q.x*t + q.y*n.z - q.z*n.y + q.w*n.x;
q.y = - q.x*n.z + q.y*t + q.z*n.x + q.w*n.y;
q.z = + q.x*n.y - q.y*n.x + q.z*t + q.w*n.z;
q.w = - q.x*n.x - q.y*n.y - q.z*n.z + q.w*t;
onclick.x = drag.x;
onclick.y = drag.y;
onclick.z = drag.z;
}
glutPostRedisplay();
}
void motion(int nmx, int nmy) // Mouse
{
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
}
void click(int b, int s, int nmx, int nmy) // Mouse
{
double norm,length;
switch(b)
{
case GLUT_LEFT_BUTTON:
if( s == GLUT_DOWN ) interactive = 1;
else interactive = 0;
mx = 2.*(nmx/(double)width - 0.5);
my = 2.*(0.5 - nmy/(double)height);
norm = mx*mx + my*my;
if( norm > 1.0 )
{
length = sqrt(norm);
drag.x = mx/length;
drag.y = my/length;
drag.z = 0.0;
}
else
{
drag.x = mx;
drag.y = my;
drag.z = sqrt(1.0-norm);
}
onclick.x = drag.x;
onclick.y = drag.y;
onclick.z = drag.z;
break;
}
glutPostRedisplay();
}
void quatinit()
{
q.x = 0.0;
q.y = 0.0;
q.z = 0.0;
q.w = 1.0;
}
void rotatevector(double * vec)
{
int i;
double rot[16];
double temp[4] = {vec[0],vec[1],vec[2],1.0};
double ret[4];
rot[ 0] = (q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z);
rot[ 1] = 2.*(q.x*q.y - q.w*q.z);
rot[ 2] = 2.*(q.x*q.z + q.w*q.y);
rot[ 3] = 0.0;
rot[ 4] = 2.*(q.x*q.y + q.w*q.z);
rot[ 5] = (q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z);
rot[ 6] = 2.*(q.y*q.z - q.w*q.x);
rot[ 7] = 0.0;
rot[ 8] = 2.*(q.x*q.z - q.w*q.y);
rot[ 9] = 2.*(q.y*q.z + q.w*q.x);
rot[10] = (q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z);
rot[11] = 0.0;
rot[12] = 0.0;
rot[13] = 0.0;
rot[14] = 0.0;
rot[15] = (q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
for(i=0; i < 4; i++)
{
ret[i] = temp[0] * rot[i*4];
ret[i] += temp[1] * rot[i*4+1];
ret[i] += temp[2] * rot[i*4+2];
ret[i] += temp[3] * rot[i*4+3];
}
vec[0] = ret[0]/ret[3];
vec[1] = ret[1]/ret[3];
vec[2] = ret[2]/ret[3];
}
void rotate()
{
double rot[16];
rot[ 0] = (q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z);
rot[ 1] = 2.*(q.x*q.y - q.w*q.z);
rot[ 2] = 2.*(q.x*q.z + q.w*q.y);
rot[ 3] = 0.0;
rot[ 4] = 2.*(q.x*q.y + q.w*q.z);
rot[ 5] = (q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z);
rot[ 6] = 2.*(q.y*q.z - q.w*q.x);
rot[ 7] = 0.0;
rot[ 8] = 2.*(q.x*q.z - q.w*q.y);
rot[ 9] = 2.*(q.y*q.z + q.w*q.x);
rot[10] = (q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z);
rot[11] = 0.0;
rot[12] = 0.0;
rot[13] = 0.0;
rot[14] = 0.0;
rot[15] = (q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
glMultMatrixd(rot);
}
/*********************************
Implementation of quaternion-based
object rotation
Functions
clickmotion - call when holded mouse moved
click - call when user clicks
motion - call when mouse just moves
quatinit - flush rotation value
rotate - multiply GL matrix
Dependency: rotate.h,
Standard: math.h
Specific: glut.h
**********************************/
#ifndef _ROTATE_H
#define _ROTATE_H
void clickmotion(int nmx, int nmy);
void motion(int nmx, int nmy);
void click(int b, int s, int nmx, int nmy);
void quatinit();
void rotate();
void rotatevector(double * vec);
#endif
project(DrawMatrix)
set(SOURCE main.cpp my_glut.h)
find_package(OpenGL)
if (WIN32)
find_path(GLUT_INCLUDE_DIR GL/glut.h )
if (CYGWIN)
find_library(GLUT_glut_LIBRARY glut32 )
else ()
if(BORLAND)
set (GLUT_glut_LIBRARY import32 CACHE STRING "GLUT library for win32")
else()
set (GLUT_glut_LIBRARY opengl32 CACHE STRING "GLUT library for win32")
endif()
endif ()
if(NOT GLUT_glut_LIBRARY)
#-- use old way to find GLUT
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
endif(NOT GLUT_glut_LIBRARY)
#include(FindPackageHandleStandardArgs.cmake)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
if (GLUT_glut_LIBRARY)
message("GLUT library found")
set( GLUT_LIBRARIES ${GLUT_glut_LIBRARY})
#The following deprecated settings are for backwards compatibility with CMake1.4
set (GLUT_LIBRARY ${GLUT_LIBRARIES})
if(NOT GLUT_INCLUDE_DIR)
message("GLUT include directory not found - trying to set OpenGL library")
message("OpenGL library is ${OPENGL_INCLUDE_DIR}")
set(GLUT_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
set(GLUT_FOUND 1)
else(NOT GLUT_INCLUDE_DIR)
set(GLUT_FOUND 1)
endif(NOT GLUT_INCLUDE_DIR)
endif(GLUT_glut_LIBRARY)
else(WIN32)
find_package(GLUT)
endif(WIN32)
if(OPENGL_FOUND)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(GLUT_FOUND)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
add_executable(DrawMatrix ${SOURCE})
target_link_libraries(DrawMatrix ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} inmost)
if(USE_SOLVER_ANI3D)
target_link_libraries(DrawMatrix ani3d)
endif()
if(USE_SOLVER_PETSC)
link_directories(${PETSC_LIBRARY_DIRS})
add_definitions(${PETSC_DEFINITIONS})
target_link_libraries(DrawMatrix ${PETSC_LIBRARIES})
endif()
if(USE_MPI)
target_link_libraries(DrawMatrix ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(DrawMatrix PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
else(GLUT_FOUND)
message("GLUT not found")
endif(GLUT_FOUND)
else(OPENGL_FOUND)
message("OpenGL not found")
endif(OPENGL_FOUND)
CXX=mpicxx
CC=mpicxx
PETSC_DIR=#/data4t/terekhov/Packages/petsc-3.3-p3
PETSC_ARCH=#arch-linux2-c-opt
INCPATH = -I../../ -I${PETSC_DIR}/${PETSC_ARCH}/include -I${PETSC_DIR}/include
OPENGL = -L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU
#OPENGL = -framework GLUT -framework OpenGL
#OPENGL = -lglut -lgl -lglu32 -lopengl32
#OPENGL = -L/lib -lglu32 -lopengl32
PETSC = -L${PETSC_DIR}/${PETSC_ARCH}/lib/ -lpetsc -L/usr/X11R6/lib -lX11 -lparmetis -lmetis -lmpi_f77 -lflapack -lfblas -lgfortran
ILU2 = ../../ILU2/lib/libilu-2.3.a -lgfortran
#OPTFLAGS= -O0 -g -Wall
OPTFLAGS= -O3
MYLIBS=../../mspp.a
#MYLIBS= ../../msppd.a
CXXFLAGS=$(OPTFLAGS) $(INCPATH)
LDFLAGS=$(OPTFLAGS)
LDLIBS=$(MYLIBS) $(OPENGL) $(PETSC) $(ILU2)
targets=main
all: $(targets)
main: main.o
clean:
rm -f $(targets) *.o
//g++ main.cpp rotate.cpp -L/usr/X11R6/lib -lX11 -lXi -lXmu -lGL -lglut -lGLU ../../inmost.a -O5
// press space - explode mesh to see connection
#include "../../inmost.h"
#include "my_glut.h"
#include <iostream>
#include <sstream>
#include <algorithm>
#include <deque>
#include <stdarg.h>
using namespace INMOST;
int width = 1000, height = 1000;
Solver::Matrix * m = NULL;
int zoom = 200;
int block_size = 0;
//~ Storage::real min = 1e20,max = -1e20;
void printtext(const char * fmt, ...)
{
unsigned int i;
char stext[1024];
va_list ap;
if (fmt == NULL) return;
va_start(ap, fmt);
vsprintf(stext, fmt, ap);
va_end(ap);
for (i = 0; i<strlen(stext); i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10,
stext[i]);
}
}
class Input
{
public:
enum InputType { Double, Integer };
private:
std::string str;
void * input_link;
InputType type;
bool done;
public:
Input(int * val) { input_link = val; type = Integer; done = false; str = ""; }
Input(double * val) { input_link = val; type = Double; done = false; str = ""; }
Input(void * link, InputType type) : input_link(link), type(type) { done = false; str = ""; }
Input(const Input & other) :input_link(other.input_link), str(other.str), type(other.type), done(other.done) {}
Input & operator =(Input const & other) { input_link = other.input_link; str = other.str; type = other.type; done = other.done; return *this; }
~Input() {}
void KeyPress(char c)
{
if (c == 13)
{
done = true;
if (type == Double) *((double *)input_link) = atof(str.c_str());
else if (type == Integer) *((int *)input_link) = atoi(str.c_str());
glutPostRedisplay();
}
else if (c == 8)
{
if (!str.empty()) str.erase(str.size() - 1);
glutPostRedisplay();
}
else if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.' || c == 'e' || c == 'E')
{
str += c;
glutPostRedisplay();
}
else if (c == 27)
{
done = true;
glutPostRedisplay();
}
}
bool Done() { return done; }
void Draw()
{
float h = 24.0f / (float)height;
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glVertex3f(-0.99, -0.99, 1);
glVertex3f(-0.99, -0.99 + h, 1);
glVertex3f(0.99, -0.99 + h, 1);
glVertex3f(0.99, -0.99, 1);
glEnd();
glColor3f(0, 0, 0);
glBegin(GL_LINE_LOOP);
glVertex3f(-0.99, -0.99, 1);
glVertex3f(-0.99, -0.99 + h, 1);
glVertex3f(0.99, -0.99 + h, 1);
glVertex3f(0.99, -0.99, 1);
glEnd();
glColor4f(0, 0, 0, 1);
glRasterPos2d(-0.985, -0.985);
//printtext(str.c_str());
printtext("input number (%s): %s", type == Integer ? "integer" : "double", str.c_str());
}
} *CommonInput = NULL;
class Reorder_ddPQ
{
public:
};
class Reorder_ARMS
{
interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> reorder;