Skip to content
Snippets Groups Projects
Commit 8450d8e8 authored by Denis Louis's avatar Denis Louis
Browse files

All Project

parent 00f42213
No related branches found
No related tags found
1 merge request!6merge kevin branch
Pipeline #5153 failed
Lx = 5;
Ly = 2;
nx = 5;
ny = 1;
Point(1) = {0, 0, 0, 1.0};
Point(2) = {Lx, 0, 0, 1.0};
Point(3) = {Lx, Ly, 0, 1.0};
Point(4) = {0, Ly, 0, 1.0};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Curve Loop(1) = {4, 1, 2, 3};
Plane Surface(1) = {1};
Transfinite Curve {3, 1} = nx+1 Using Progression 1;
Transfinite Curve {4, 2} = ny+1 Using Progression 1;
Transfinite Surface {1};
Recombine Surface {1}; // quads instead of triangles
Physical Curve("left_edge", 5) = {4};
Physical Surface("domain", 6) = {1};
Physical Curve("top_edge",7) = {3};
// additional parameters given to the solver
SetNumber("Boundary Conditions/left_edge/ux", 0.);
SetNumber("Boundary Conditions/left_edge/uy", 0.);
SetNumber("Materials/domain/Young", 210e3);
SetNumber("Materials/domain/Poisson", 0.3);
SetNumber("Boundary Conditions/top_edge/tx", 0.);
SetNumber("Boundary Conditions/top_edge/ty", -100.);
\ No newline at end of file
File added
Lx = 10;
Ly = 2;
nx = 5;
ny = 1;
Point(1) = {0, 0, 0, 1.0};
Point(2) = {Lx, 0, 0, 1.0};
Point(3) = {Lx, Ly, 0, 1.0};
Point(4) = {0, Ly, 0, 1.0};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Curve Loop(1) = {4, 1, 2, 3};
Plane Surface(1) = {1};
Transfinite Curve {3, 1} = nx+1 Using Progression 1;
Transfinite Curve {4, 2} = ny+1 Using Progression 1;
Transfinite Surface {1};
Recombine Surface {1}; // quads instead of triangles
Physical Curve("left_edge", 5) = {4};
Physical Surface("domain", 6) = {1};
Physical Curve("top_edge",7) = {3};
// additional parameters given to the solver
SetNumber("Boundary Conditions/left_edge/ux", 0.);
SetNumber("Boundary Conditions/left_edge/uy", 0.5);
SetNumber("Materials/domain/Young", 210e3);
SetNumber("Materials/domain/Poisson", 0.3);
SetNumber("Boundary Conditions/top_edge/tx", 0.);
SetNumber("Boundary Conditions/top_edge/ty", -100.);
\ No newline at end of file
PROJECT(SPARSE_SOLVE CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
# ------------------------------------------------------------------------------
# Find libraries and setup compiler
# ------------------------------------------------------------------------------
# build type is "" by default in Linux
IF(NOT CMAKE_BUILD_TYPE)
SET( CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
ENDIF()
# enable C++11
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
IF(APPLE)
# on macOS, do not give priority to frameworks/apps
SET(CMAKE_FIND_APPBUNDLE LAST)
SET(CMAKE_FIND_FRAMEWORK LAST)
ENDIF()
# find gmsh-sdk
# gmsh.h
FIND_PATH(GMSH_INCLUDE_DIRS NAMES "gmsh.h")
MESSAGE(STATUS "GMSH_INCLUDE_DIRS=" ${GMSH_INCLUDE_DIRS})
if(NOT GMSH_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "gmsh.h not found!")
ENDIF()
INCLUDE_DIRECTORIES(${GMSH_INCLUDE_DIRS})
# libgmsh.so
FIND_LIBRARY(GMSH_LIBRARIES gmsh)
MESSAGE(STATUS "GMSH_LIBRARIES=" ${GMSH_LIBRARIES})
IF(NOT GMSH_LIBRARIES)
MESSAGE(FATAL_ERROR "gmsh library not found!")
ENDIF()
# find Eigen
find_path(EIGEN_INCLUDE_DIRS "Eigen/Dense"
PATHS "${PROJECT_SOURCE_DIR}/lib/eigen" "/usr/include/eigen3")
MESSAGE(STATUS "EIGEN_INCLUDE_DIRS=" ${EIGEN_INCLUDE_DIRS})
IF(NOT EIGEN_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Eigen include dir not found!")
ENDIF()
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIRS})
# ------------------------------------------------------------------------------
SET(SRCS Tutorial_sparse_example.cpp Tutorial_sparse_example_details.cpp)
ADD_EXECUTABLE(solve_sparse ${SRCS})
TARGET_LINK_LIBRARIES(solve_sparse ${GMSH_LIBRARIES})
# sparse_solve
This program solves a sparse linear system with Eigen.
The files are directly taken from the Eigen source tree and put here without any modification.
#include <Eigen/Sparse>
#include <vector>
#include <iostream>
typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
typedef Eigen::Triplet<double> T;
void buildProblem(std::vector<T>& coefficients, Eigen::VectorXd& b, int n);
void saveAsBitmap(const Eigen::VectorXd& x, int n, const char* filename);
int main(int argc, char** argv)
{
// if(argc!=2) {
// std::cerr << "Error: expected one and only one argument.\n";
// return -1;
// }
int n = 300; // size of the image
int m = n*n; // number of unknows (=number of pixels)
// Assembly:
std::vector<T> coefficients; // list of non-zeros coefficients
Eigen::VectorXd b(m); // the right hand side-vector resulting from the constraints
buildProblem(coefficients, b, n);
SpMat A(m,m);
A.setFromTriplets(coefficients.begin(), coefficients.end());
// Solving:
Eigen::SimplicialCholesky<SpMat> chol(A); // performs a Cholesky factorization of A
Eigen::VectorXd x = chol.solve(b); // use the factorization to solve for the given right hand side
// Export the result to a file:
// saveAsBitmap(x, n, argv[1]);
return 0;
}
#include <Eigen/Sparse>
#include <vector>
// #include <QImage>
typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
typedef Eigen::Triplet<double> T;
void insertCoefficient(int id, int i, int j, double w, std::vector<T>& coeffs,
Eigen::VectorXd& b, const Eigen::VectorXd& boundary)
{
int n = int(boundary.size());
int id1 = i+j*n;
if(i==-1 || i==n) b(id) -= w * boundary(j); // constrained coefficient
else if(j==-1 || j==n) b(id) -= w * boundary(i); // constrained coefficient
else coeffs.push_back(T(id,id1,w)); // unknown coefficient
}
void buildProblem(std::vector<T>& coefficients, Eigen::VectorXd& b, int n)
{
b.setZero();
Eigen::ArrayXd boundary = Eigen::ArrayXd::LinSpaced(n, 0,M_PI).sin().pow(2);
for(int j=0; j<n; ++j)
{
for(int i=0; i<n; ++i)
{
int id = i+j*n;
insertCoefficient(id, i-1,j, -1, coefficients, b, boundary);
insertCoefficient(id, i+1,j, -1, coefficients, b, boundary);
insertCoefficient(id, i,j-1, -1, coefficients, b, boundary);
insertCoefficient(id, i,j+1, -1, coefficients, b, boundary);
insertCoefficient(id, i,j, 4, coefficients, b, boundary);
}
}
}
// void saveAsBitmap(const Eigen::VectorXd& x, int n, const char* filename)
// {
// Eigen::Array<unsigned char,Eigen::Dynamic,Eigen::Dynamic> bits = (x*255).cast<unsigned char>();
// QImage img(bits.data(), n,n,QImage::Format_Indexed8);
// img.setColorCount(256);
// for(int i=0;i<256;i++) img.setColor(i,qRgb(i,i,i));
// img.save(filename);
// }
# math0471/lib
This folder contains scripts for downloading the 2 external libraries that are required for this project.
\ No newline at end of file
::@echo off
:: download eigen & extract to current folder
set version=3.4.0
set file=eigen-%version%.zip
:: download file
del %file% >nul 2>&1
bitsadmin /transfer get_eigen /dynamic /download /priority foreground "https://gitlab.com/libeigen/eigen/-/archive/%version%/%file%" "%CD%\%file%"
:: unzip
rd /Q/S eigen-%version% >nul 2>&1
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%CD%\%file%', '%CD%'); }"
del %file% >nul 2>&1
:: rename folder
rd /Q/S eigen >nul 2>&1
ren eigen-%version% eigen
#!/bin/bash
set -e
VERSION=3.4.0
wget -q https://gitlab.com/libeigen/eigen/-/archive/${VERSION}/eigen-${VERSION}.tar.gz
tar xzf eigen-${VERSION}.tar.gz
rm eigen-${VERSION}.tar.gz
rm -rf eigen
mv eigen-${VERSION} eigen
::@echo off
:: download gmsh-sdk & extract to current folder
set gmsh=gmsh-4.9.3-Windows64-sdk
set file=%gmsh%.zip
:: download file
del %file% >nul 2>&1
bitsadmin /transfer get_gmsh /dynamic /download /priority foreground "https://gmsh.info/bin/Windows/%file%" "%CD%\%file%"
:: unzip
rd /Q/S %gmsh% >nul 2>&1
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%CD%\%file%', '%CD%'); }"
del %file% >nul 2>&1
:: rename folder
rd /Q/S gmsh-sdk >nul 2>&1
ren %gmsh% gmsh-sdk
:: copy dll to bin folder so that double-clic on gmsh.exe works!
copy /Y gmsh-sdk\lib\gmsh-*.dll gmsh-sdk\bin\
#!/bin/bash
set -e
VERSION=4.9.3
if [[ "$OSTYPE" == "linux-gnu" ]]; then
wget -q https://gmsh.info/bin/Linux/gmsh-${VERSION}-Linux64-sdk.tgz
tar xzf gmsh-${VERSION}-Linux64-sdk.tgz
rm gmsh-${VERSION}-Linux64-sdk.tgz
rm -rf gmsh-sdk
mv gmsh-${VERSION}-Linux64-sdk gmsh-sdk
elif [[ "$OSTYPE" == "darwin"* ]]; then
wget -q https://gmsh.info/bin/MacOSX/gmsh-${VERSION}-MacOSX-sdk.tgz
tar xzf gmsh-${VERSION}-MacOSX-sdk.tgz
rm gmsh-${VERSION}-MacOSX-sdk.tgz
rm -rf gmsh-sdk
mv gmsh-${VERSION}-MacOSX-sdk gmsh-sdk
else
echo "unknown system"
fi
PROJECT(MATH0471 CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
# ------------------------------------------------------------------------------
# Find libraries and setup compiler
# ------------------------------------------------------------------------------
# build type is "" by default in Linux
IF(NOT CMAKE_BUILD_TYPE)
SET( CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
ENDIF()
# enable C++11
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
IF(APPLE)
# on macOS, do not give priority to frameworks/apps
SET(CMAKE_FIND_APPBUNDLE LAST)
SET(CMAKE_FIND_FRAMEWORK LAST)
ENDIF()
# find gmsh-sdk
# gmsh.h
FIND_PATH(GMSH_INCLUDE_DIRS NAMES "gmsh.h")
MESSAGE(STATUS "GMSH_INCLUDE_DIRS=" ${GMSH_INCLUDE_DIRS})
if(NOT GMSH_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "gmsh.h not found!")
ENDIF()
INCLUDE_DIRECTORIES(${GMSH_INCLUDE_DIRS})
# libgmsh.so
FIND_LIBRARY(GMSH_LIBRARIES gmsh)
MESSAGE(STATUS "GMSH_LIBRARIES=" ${GMSH_LIBRARIES})
IF(NOT GMSH_LIBRARIES)
MESSAGE(FATAL_ERROR "gmsh library not found!")
ENDIF()
# find Eigen
find_path(EIGEN_INCLUDE_DIRS "Eigen/Dense"
PATHS "${PROJECT_SOURCE_DIR}/lib/eigen" "/usr/include/eigen3")
MESSAGE(STATUS "EIGEN_INCLUDE_DIRS=" ${EIGEN_INCLUDE_DIRS})
IF(NOT EIGEN_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "Eigen include dir not found!")
ENDIF()
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIRS})
# ------------------------------------------------------------------------------
FILE(GLOB SRCS *.cpp)
ADD_EXECUTABLE(solver ${SRCS})
TARGET_LINK_LIBRARIES(solver ${GMSH_LIBRARIES})
# srcs
You can start your project here.
#include <iostream>
int main(int argc, char **argv)
{
std::cout << "Hello world!\n";
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment