Commit 10428607 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

added uni_tests


Former-commit-id: 532d3960
parent 78c7c44f
This diff is collapsed.
This diff is collapsed.
# importing PIL
from PIL import Image
import pydicom
import numpy as np
from pydicom.pixel_data_handlers.util import apply_modality_lut
from copy import deepcopy
def main():
image_name = "mini_phantom.png"
ending = image_name.split('.')[-1];
if(ending == 'dcm'): #dicom ct image
dataset = pydicom.dcmread(image_name)
hu = apply_modality_lut(dataset.pixel_array, dataset)
density = (dataset.RescaleIntercept + dataset.RescaleSlope*hu)/1000 +1
(spacingX, spacingY) = dataset.PixelSpacing
(sizeX,sizeY) = density.shape
dimensions = (spacingX*sizeX, spacingY*sizeY)
return density, dimensions
else: # jpg or png
img = Image.open(image_name).convert('L') #image data
I = np.asarray(img) # image as greyscale
I = I/255; # rescale values to [0,1]
J = deepcopy(np.flipud(I))
np.savetxt("foo.csv", J, delimiter=",")
dimensions = (1,1) # [cm]
return J , dimensions
if __name__ == '__main__':
main()
This diff is collapsed.
% ---- File specifications ----
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = ctscan_test
LOG_DIR = ../../tests/result/logs
MESH_FILE = ../../tests/result/ctscan_test.su2
% ---- Solver specifications ----
CFL_NUMBER = 0.5
TIME_FINAL = 0.5
PROBLEM = LINESOURCE
% ---- Boundary Conditions ----
BC_NEUMANN = ( void )
QUAD_TYPE = GAUSS_LEGENDRE_TENSORIZED
QUAD_ORDER = 10
import pygmsh as pg
import numpy as np
import itertools
import os
def add_block(x0,y0,length,char_length,geom):
coords = np.array([
[x0, y0, 0.0],
[x0+length, y0, 0.0],
[x0+length, y0+length, 0.0],
[x0, y0+length, 0.0]
])
return geom.add_polygon(coords, char_length)
char_length = 0.2
geom = pg.opencascade.Geometry()
domain = add_block(-0.6, -0.6, 1.2, char_length, geom)
geom.add_raw_code('psource = newp;\nPoint(psource) = {0.0, 0.0, 0.0, '+str(char_length)+'};\nPoint{psource} In Surface{'+domain.id+'};')
geom.add_physical(domain.lines, label="void")
mesh_code = geom.get_code()
with open("linesource.geo","w") as mesh_file:
mesh_file.write(mesh_code)
os.system('gmsh linesource.geo -2 -format su2 -save_all')
os.system('rm linesource.geo')
0.000000000000000000e+00,0.000000000000000000e+00,1.725490196078431349e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01
0.000000000000000000e+00,5.490196078431372473e-02,2.039215686274509776e-01,2.039215686274509776e-01,5.333333333333333259e-01,9.098039215686274384e-01,9.137254901960784048e-01,9.098039215686274384e-01,5.333333333333333259e-01,2.039215686274509776e-01
0.000000000000000000e+00,1.333333333333333315e-01,2.039215686274509776e-01,2.039215686274509776e-01,3.215686274509804154e-01,5.098039215686274161e-01,5.098039215686274161e-01,5.098039215686274161e-01,3.215686274509804154e-01,2.078431372549019718e-01
1.568627450980392135e-02,2.000000000000000111e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.196078431372548989e-01,2.588235294117647300e-01,2.941176470588235392e-01
9.411764705882352811e-02,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.313725490196078538e-01,2.784313725490196179e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
1.725490196078431349e-01,2.039215686274509776e-01,2.039215686274509776e-01,2.352941176470588203e-01,2.823529411764705843e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
2.039215686274509776e-01,2.235294117647058931e-01,2.823529411764705843e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
2.666666666666666630e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01,3.019607843137254721e-01
7b59dd696325f2893d35bbbbcf6e1a2fd371dec5
\ No newline at end of file
import pygmsh as pg
import numpy as np
import itertools
import os
def add_block(x0,y0,length,char_length,geom):
coords = np.array([
[x0, y0, 0.0],
[x0+length, y0, 0.0],
[x0+length, y0+length, 0.0],
[x0, y0+length, 0.0]
])
return geom.add_polygon(coords, char_length)
char_length = 0.5
geom = pg.opencascade.Geometry()
domain = add_block(0.0, 0.0, 1.0, char_length, geom)
geom.add_physical(domain.lines, label="void")
mesh_code = geom.get_code()
with open("unit.geo","w") as mesh_file:
mesh_file.write(mesh_code)
os.system('gmsh unit.geo -2 -format su2 -save_all')
os.system('rm unit.geo')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Configuration File reader %
% Author: Steffen Schotthöfer %
% Date: 13.08.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_config.cpp!
% Only specify options that are important for this unit test!
%
% ---- File specifications ----
%
% Output directory
OUTPUT_DIR = ../result
% Output file
OUTPUT_FILE = rtsn_test_unit_config
% Log directory
LOG_DIR = ../result/logs
% Mesh File
MESH_FILE = unit.su2
%
% ---- Solver specifications ----
%
% CFL number
CFL_NUMBER = 0.4
% Final time for simulation
TIME_FINAL = 0.3
%
% ---- Problem Specifications ----
%
% Preselected Problem for Physics Settings
PROBLEM = LINESOURCE
%
% Scattering Kernel
KERNEL = ISOTROPIC
%
%% Quadrature Specifications
% Quadrature Type
QUAD_TYPE = MONTE_CARLO
% Quadrature Order
QUAD_ORDER = 5000
%
%
% ---- Boundary Conditions ----
%
% Example: BC_DIRICLET = (dummyMarker1, dummyMarker2)
% Dirichlet Boundary
BC_DIRICHLET = ( DirichletTestMarker1, DirichletTestMarker2 )
%
% Neumann Boundary
BC_NEUMANN = (NeumannTestMarker1, NeumannTestMarker2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Spherical Harmonics %
% Author: Steffen Schotthöfer %
% Date: 08.06.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_harmonics.cpp!
%
% ---- File specifications ----
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = rtsn_test_unit_harmonics
LOG_DIR = ../../tests/result/logs
% ---- Boundary Conditions ----
QUAD_TYPE = GAUSS_LEGENDRE_TENSORIZED
QUAD_ORDER = 12
%
% Use this option, since default solver is SN. (Solver is not used in this unit test)
SN_ALL_GAUSS_PTS = YES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Kernel %
% Author: Steffen Schotthöfer %
% Date: 13.08.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_kernel.cpp!
% Only specify options that are important for this unit test!
%
% ---- File specifications ----
%
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = rtsn_test_unit_kernel
LOG_DIR = ../../tests/result/logs
%
% ---- Quadrature Settings ----
QUAD_TYPE = LEBEDEV
QUAD_ORDER = 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Mesh %
% Author: Steffen Schotthöfer %
% Date: 13.08.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_mesh.cpp!
% Only specify options that are important for this unit test!
%
% ---- File specifications ----
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = rtsn_test_unit_mesh
LOG_DIR = ../../tests/result/logs
MESH_FILE = unit_mesh.su2
%
% ---- Boundary Conditions ----
BC_DIRICHLET = ( void )
NDIME= 2
NELEM= 14
5 1 9 4 0
5 5 9 1 1
5 3 11 6 2
5 7 11 3 3
5 2 10 5 4
5 6 10 2 5
5 4 8 0 6
5 0 8 7 7
5 9 11 8 8
5 8 11 7 9
5 4 9 8 10
5 10 11 9 11
5 6 11 10 12
5 5 10 9 13
NPOIN= 12
0 0 0
1 0 1
1 1 2
0 1 3
0.5 0 4
1 0.5 5
0.5 1 6
0 0.5 7
0.25 0.25 8
0.625 0.3750000000000001 9
0.71875 0.7187500000000001 10
0.345703125 0.654296875 11
NMARK= 1
MARKER_TAG= void
MARKER_ELEMS= 8
3 0 4
3 4 1
3 1 5
3 5 2
3 2 6
3 6 3
3 3 7
3 7 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Optimizer %
% Author: Steffen Schotthöfer %
% Date: 13.08.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_optimizer.cpp!
% Only specify options that are important for this unit test!
%
% ---- File specifications ----
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = rtsn_test_unit_optimizerNewton
LOG_DIR = ../../tests/result/logs
%
% ---- Solver specifications ----
%
MAX_MOMENT_SOLVER = 1
%
ENTROPY_OPTIMIZER = NEWTON
ENTROPY_FUNCTIONAL = QUADRATIC
%
% ----- Newton Solver Specifications ----
%
NEWTON_FAST_MODE = NO
NEWTON_ITER = 100
NEWTON_EPSILON = 0.01
NEWTON_STEP_SIZE = 0.5
NEWTON_LINE_SEARCH_ITER = 100
%
% ---- Quadrature Specs ----
%
QUAD_TYPE = GAUSS_LEGENDRE_TENSORIZED
QUAD_ORDER = 4
%
% Use this option, since default solver is SN. (Solver is not used in this unit test)
SN_ALL_GAUSS_PTS = YES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Unit: Quadrature %
% Author: Steffen Schotthöfer %
% Date: 13.08.2020 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this config file ONLY for test_quadrature.cpp!
% Only specify options that are important for this unit test!
%
% ---- File specifications ----
OUTPUT_DIR = ../../tests/result
OUTPUT_FILE = rtsn_test_unit_harmonics
LOG_DIR = ../../tests/result/logs
% ---- Boundary Conditions ----
% This is just a dummy value!
QUAD_TYPE = MONTE_CARLO
% This is just a dummy value!
QUAD_ORDER = 1
%
% Use this option, since default solver is SN. (Solver is not used in this unit test)
SN_ALL_GAUSS_PTS = YES
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "common/config.h" #include "common/config.h"
TEST_CASE( "Read in Config Template" ) { TEST_CASE( "Read in Config Template" ) {
std::string filename = std::string( TESTS_PATH ) + "input/unit_config.cfg"; std::string filename = std::string( TESTS_PATH ) + "input/unit_tests/common/unit_config.cfg";
// Load Settings from File // Load Settings from File
Config* config = new Config( filename ); Config* config = new Config( filename );
......
...@@ -30,7 +30,7 @@ double P2_2( double my ) { return sqrt( 15 / ( 16 * M_PI ) ) * ( 1 - my * my ); ...@@ -30,7 +30,7 @@ double P2_2( double my ) { return sqrt( 15 / ( 16 * M_PI ) ) * ( 1 - my * my );
TEST_CASE( "test the spherical harmonics basis computation", "[spherical_harmonics]" ) { TEST_CASE( "test the spherical harmonics basis computation", "[spherical_harmonics]" ) {
std::string filename = std::string( TESTS_PATH ) + "input/unit_harmonics.cfg"; std::string filename = std::string( TESTS_PATH ) + "input/unit_tests/solvers/unit_harmonics.cfg";
// Load Settings from File // Load Settings from File
Config* config = new Config( filename ); Config* config = new Config( filename );
...@@ -86,7 +86,7 @@ TEST_CASE( "test the spherical harmonics basis computation", "[spherical_harmoni ...@@ -86,7 +86,7 @@ TEST_CASE( "test the spherical harmonics basis computation", "[spherical_harmoni
Vector values( 9, 0.0 ); Vector values( 9, 0.0 );
Vector result( 4, 0.0 ); Vector result( 4, 0.0 );
case_file.open( "harmonicBasis_reference.csv", std::ios::in ); case_file.open( "unit_test/solvers/harmonicBasis_reference.csv", std::ios::in );
getline( case_file, text_line ); getline( case_file, text_line );
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
#include "toolboxes/textprocessingtoolbox.h" #include "toolboxes/textprocessingtoolbox.h"
TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) { TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
std::string config_file_name = std::string( TESTS_PATH ) + "input/image_conversion.cfg"; std::string config_file_name = std::string( TESTS_PATH ) + "input/unit_tests/common/image_conversion.cfg";
Config* config = new Config( config_file_name ); // just to init spdlog Config* config = new Config( config_file_name ); // just to init spdlog
std::string testImage = std::string( TESTS_PATH ) + "input/mini_phantom.png"; std::string testImage = std::string( TESTS_PATH ) + "input/unit_tests/common/mini_phantom.png";
std::string testMesh = config->GetMeshFile(); std::string testMesh = config->GetMeshFile();
Matrix gsImage = createSU2MeshFromImage( testImage, testMesh ); Matrix gsImage = createSU2MeshFromImage( testImage, testMesh );
...@@ -26,7 +26,7 @@ TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) { ...@@ -26,7 +26,7 @@ TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
REQUIRE( blaze::max( gsImage ) <= 1.0 ); // upper bound REQUIRE( blaze::max( gsImage ) <= 1.0 ); // upper bound
// load reference matrix from csv file // load reference matrix from csv file
std::string refMatrixFile = std::string( TESTS_PATH ) + "input/phantom.csv"; std::string refMatrixFile = std::string( TESTS_PATH ) + "input/unit_tests/common/phantom.csv";
std::ifstream data( refMatrixFile ); std::ifstream data( refMatrixFile );
REQUIRE( data.is_open() ); REQUIRE( data.is_open() );
std::string line; std::string line;
......
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