Commit e2ffb723 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

isolate hxtlsys lib

parent 2793a8a9
Pipeline #7673 failed with stage
in 16 seconds
......@@ -50,4 +50,6 @@ add_subdirectory(python)
add_subdirectory(tools)
add_subdirectory(scontact)
add_subdirectory(fluid)
add_subdirectory(hxtlsys)
......@@ -25,16 +25,8 @@ set(SRC
fluid_problem_concentration.c
mesh.c
mesh_find.c
hxt_linear_system.c
hxt_linear_system_lu.c
hxt_message.c
)
if(PETSC_FOUND)
add_definitions("-DHXT_HAVE_PETSC")
list(APPEND SRC hxt_linear_system_petsc.c)
endif(PETSC_FOUND)
include_directories(. ${CMAKE_SOURCE_DIR}/tools ${EXTERNAL_INCLUDES})
add_library(mbfluid2 SHARED ${SRC})
target_link_libraries(mbfluid2 ${EXTERNAL_LIBRARIES} mbtools2)
......
......@@ -1978,52 +1978,3 @@ void fluid_problem_reset_boundary_force(FluidProblem *problem) {
for (int i=0;i<D*problem->mesh->n_boundaries;i++)
problem->boundary_force[i] = 0;
}
// temporary hxt wrap
#include "hxt_linear_system.h"
void fluid_problem_zero_matrix(HXTLinearSystem *sys) {
hxtLinearSystemZeroMatrix(sys);
}
void fluid_problem_free_linear_system(HXTLinearSystem *sys) {
hxtLinearSystemDelete(&sys);
}
double fluid_problem_get_rhs_norm(HXTLinearSystem *sys, double *rhs) {
double norm0;
hxtLinearSystemGetRhsNorm(sys,rhs,&norm0);
return norm0;
}
void fluid_problem_linear_system_solve(HXTLinearSystem *sys, double *rhs, double *dx) {
hxtLinearSystemSolve(sys, rhs, dx);
}
void fluid_problem_local_to_global(HXTLinearSystem *lsys, int n_elements, int local_size, double *all_local_vector, double *all_local_matrix, double *rhs) {
for (int iel=0; iel <n_elements; ++iel) {
double *local_vector = &all_local_vector[local_size*iel];
double *local_matrix = &all_local_matrix[local_size*local_size*iel];
hxtLinearSystemAddToMatrix(lsys,iel,iel,local_matrix);
hxtLinearSystemAddToRhs(lsys,rhs,iel,local_vector);
}
}
void fluid_problem_free_hxt(HXTLinearSystem *sys) {
hxtLinearSystemDelete(&sys);
}
HXTLinearSystem *fluid_problem_create_linear_system(int n_elements, int n_nodes_by_el, int *elements, int n_fields) {
HXTLinearSystem *sys;
static int initialized = 0;
if (!initialized) {
hxtInitializeLinearSystems(0, NULL);
initialized = 1;
#ifdef HXT_HAVE_PETSC
hxtPETScInsertOptions("-pc_type lu", "fluid");
#endif
}
#ifdef HXT_HAVE_PETSC
hxtLinearSystemCreatePETSc(&sys,n_elements,n_nodes_by_el,n_fields,elements,"fluid");
#else
hxtLinearSystemCreateLU(&sys,n_elements,n_nodes_by_el,n_fields,elements);
#endif
return sys;
}
// end temporary functions
# MigFlow - Copyright (C) <2010-2018>
# <Universite catholique de Louvain (UCL), Belgium
# Universite de Montpellier, France>
#
# List of the contributors to the development of MigFlow: see AUTHORS file.
# Description and complete License: see LICENSE file.
#
# This program (MigFlow) is free software:
# you can redistribute it and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
#
# 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program (see COPYING and COPYING.LESSER files). If not,
# see <http://www.gnu.org/licenses/>.
set(SRC
hxt_linear_system.c
hxt_linear_system_lu.c
hxt_message.c
)
if(PETSC_FOUND)
add_definitions("-DHXT_HAVE_PETSC")
list(APPEND SRC hxt_linear_system_petsc.c)
endif(PETSC_FOUND)
include_directories(. ${EXTERNAL_INCLUDES})
add_library(hxtlsys SHARED ${SRC})
target_link_libraries(hxtlsys ${EXTERNAL_LIBRARIES})
......@@ -37,6 +37,7 @@
operation(opdata,SetRhsEntry,double*,int,int,double,);\
operation(opdata,AddRhsEntry,double*,int,int,double,);\
operation(opdata,HasConverged,int*,);\
operation(opdata,LocalToGlobal,double*,double*,double*,);\
operation(opdata,GetRhsNorm,double*,double*,);
HXT_DECLARE_INTERFACE(LinearSystem)
......
......@@ -476,3 +476,16 @@ HXTStatus hxtLinearSystemLUSize(HXTLinearSystemLU *lsys, int *size)
*size = lsys->n;
return HXT_STATUS_OK;
}
HXTStatus hxtLinearSystemLULocalToGlobal(HXTLinearSystemLU *sys, double *all_local_vector, double *all_local_matrix, double *rhs) {
int local_size = sys->nNodes*sys->nFields;
for (int iel=0; iel <sys->nElements; ++iel) {
double *local_vector = &all_local_vector[local_size*iel];
double *local_matrix = &all_local_matrix[local_size*local_size*iel];
hxtLinearSystemLUAddToMatrix(sys,iel,iel,local_matrix);
hxtLinearSystemLUAddToRhs(sys,rhs,iel,local_vector);
}
return HXT_STATUS_OK;
}
......@@ -42,5 +42,6 @@ HXTStatus hxtLinearSystemLUHasConverged(HXTLinearSystemLU *lsys, int *converged)
HXTStatus hxtLinearSystemLUGetRhsNorm(HXTLinearSystemLU *lsys, double *rhs, double *norm);
HXTStatus hxtLinearSystemLUCreate(HXTLinearSystemLU **pSystem, int nElements, int nNodesByElement, int nFields, uint32_t *elements);
HXTStatus hxtLinearSystemLUSize(HXTLinearSystemLU *lsys, int *size);
HXTStatus hxtLinearSystemLULocalToGlobal(HXTLinearSystemLU *sys, double *all_local_vector, double *all_local_matrix, double *rhs);
#endif
......@@ -401,5 +401,15 @@ HXTStatus hxtLinearSystemPETScMapFromVec(HXTLinearSystemPETSc *system, Vec vec,
HXT_PETSC_CHECK(VecRestoreArrayRead(vec, &vv));
return HXT_STATUS_OK;
}
HXTStatus hxtLinearSystemPETScLocalToGlobal(HXTLinearSystemPETSc *sys, double *all_local_vector, double *all_local_matrix, double *rhs) {
int local_size = sys->nNodesByElement*sys->nFields;
for (int iel=0; iel <sys->nElements; ++iel) {
double *local_vector = &all_local_vector[local_size*iel];
double *local_matrix = &all_local_matrix[local_size*local_size*iel];
hxtLinearSystemPETScAddToMatrix(sys,iel,iel,local_matrix);
hxtLinearSystemPETScAddToRhs(sys,rhs,iel,local_vector);
}
return HXT_STATUS_OK;
}
#endif
......@@ -48,6 +48,7 @@ HXTStatus hxtLinearSystemPETScSize(HXTLinearSystemPETSc *lsys, int *size);
HXTStatus hxtLinearSystemPETScGetMat(HXTLinearSystemPETSc *lsys, Mat *mat);
HXTStatus hxtLinearSystemPETScMapToVec(HXTLinearSystemPETSc *lsys, double *v, Vec vec);
HXTStatus hxtLinearSystemPETScMapFromVec(HXTLinearSystemPETSc *lsys, Vec vec, double *v);
HXTStatus hxtLinearSystemPETScLocalToGlobal(HXTLinearSystemPETSc *sys, double *all_local_vector, double *all_local_matrix, double *rhs);
HXTStatus hxtInitializePETSc(int *argc, char ***argv);
......
......@@ -27,6 +27,7 @@ set(SRC
mesh.py
scontact.py
time_integration.py
hxtlsys.py
VTK.py
)
......
......@@ -34,6 +34,7 @@ import signal
import os
import sys
from . import VTK
from .hxtlsys import LinearSystem
dir_path = os.path.dirname(os.path.realpath(__file__))
lib2 = np.ctypeslib.load_library("libmbfluid2",dir_path)
......@@ -68,33 +69,6 @@ def _np2c(a,dtype=float) :
r.tmp = tmp
return r
class LinearSystem :
def __init__(self, elements, n_fields) :
self._lib = lib2
self._lib.fluid_problem_create_linear_system.restype = c_void_p
self._sysp = c_void_p(self._lib.fluid_problem_create_linear_system(c_int(elements.shape[0]),c_int(elements.shape[1]),_np2c(elements,np.int32),c_int(n_fields)))
self.localsize = n_fields*elements.shape[1]
self._elements = elements
self._lib.fluid_problem_zero_matrix(self._sysp)
self._lib.fluid_problem_get_rhs_norm.restype = c_double
def zero_matrix(self) :
self._lib.fluid_problem_zero_matrix(self._sysp)
def local_to_global(self,localv,localm,rhs):
self._lib.fluid_problem_local_to_global(self._sysp,c_int(self._elements.shape[0]),c_int(self.localsize),_np2c(localv),_np2c(localm),_np2c(rhs))
def rhs_norm(self,rhs) :
return self._lib.fluid_problem_get_rhs_norm(self._sysp,_np2c(rhs));
def solve(self,rhs) :
sol = np.ndarray(rhs.shape)
self._lib.fluid_problem_linear_system_solve(self._sysp,_np2c(rhs),_np2c(sol));
return sol
def __del__(self):
self._lib.fluid_problem_free_linear_system(self._sysp)
class FluidProblem :
"""Create numerical representation of the fluid."""
......
Supports Markdown
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