Mercurial > repos > public > sbplib
changeset 821:95c26000c0ba feature/operator_files
Add files for parsing operator data stencil file
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Mon, 10 Sep 2018 16:57:17 +0200 |
parents | 501750fbbfdb |
children | 4808c4bd844e |
files | operator_def/assemble_D1.m operator_def/assemble_op.m operator_def/assemble_opTest.m operator_def/d2_2 operator_def/read_stencil.m |
diffstat | 5 files changed, 80 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/operator_def/assemble_D1.m Mon Sep 10 16:57:17 2018 +0200 @@ -0,0 +1,6 @@ +function [D1,e_l,e_r] = assemble_D1(stencil,h,m) + stencil_variables = read_stencil(stencil); + + D1 = assemble_op(stencil_variables.inner_stencil,stencil_variables.boundary_block)/h; + + end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/operator_def/assemble_op.m Mon Sep 10 16:57:17 2018 +0200 @@ -0,0 +1,14 @@ +function [D] = assemble_op(inner_stencil,boundary_block,m) + + [height_b, width_b] = size(boundary_block); + width_i = length(inner_stencil); + + max_offset = floor(width_i/2); + diags = -max_offset:max_offset; + + + D = stripeMatrix(inner_stencil, diags, m); + + D(1:height_b,1:width_b) = boundary_block; + D(m-height_b+1:m,m-width_b+1:m) = rot90( -boundary_block ,2); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/operator_def/assemble_opTest.m Mon Sep 10 16:57:17 2018 +0200 @@ -0,0 +1,24 @@ + +function tests = assemble_opTest() + tests = functiontests(localfunctions); +end + +function TestAssembleD1(testCase) +m = 10; +op = sbp.D2Standard(m,{0 1},4); +h = op.h; + +boundary_block = op.D1(1:4,1:6)*h; +inner = op.D1(5,3:7)*h; + +D1_new = assemble_op(inner,boundary_block,h,m); + +verifyEqual(testCase,D1_new,op.D1,'AbsTol',1e-10) + +end + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/operator_def/d2_2 Mon Sep 10 16:57:17 2018 +0200 @@ -0,0 +1,10 @@ +# D1 order 2 + +boundary_stencil +1 -1 + +inner_stencil +-1/2 0 1/2 + +e +1 0 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/operator_def/read_stencil.m Mon Sep 10 16:57:17 2018 +0200 @@ -0,0 +1,26 @@ +function [stencil_variables] = read_stencil(stencil) +fileID = fopen(stencil,'r'); +line = fgetl(fileID); + + + +while ~feof(fileID) + if isempty(line) + elseif strcmp(line(1),'#') + else + varname = genvarname(line); + val = []; + line = fgetl(fileID); + while ~isempty(str2num(line)) + val = [val; str2num(line)]; + line = fgets(fileID); + if line == -1 + break + end + end + stencil_variables.(varname) = val; + end + line = fgetl(fileID); +end + +end \ No newline at end of file