comparison +multiblock/DiffOp.m @ 535:b52ea450f4c3 feature/grids

Merge feature/boundaryGroup
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 07 Aug 2017 09:56:01 +0200
parents 55a7777dfcd0
children b0386d2c180d
comparison
equal deleted inserted replaced
525:3011f9a28ac8 535:b52ea450f4c3
118 % Splits a matrix operator into a cell-matrix of matrix operators for 118 % Splits a matrix operator into a cell-matrix of matrix operators for
119 % each grid. 119 % each grid.
120 ops = sparse2cell(op, obj.NNN); 120 ops = sparse2cell(op, obj.NNN);
121 end 121 end
122 122
123 function op = getBoundaryOperator(obj, op, boundary) 123 % Get a boundary operator specified by opName for the given boundary/BoundaryGroup
124 if iscell(boundary) 124 function op = getBoundaryOperator(obj, opName, boundary)
125 localOpName = [op '_' boundary{2}]; 125 switch class(boundary)
126 blockId = boundary{1}; 126 case 'cell'
127 localOp = obj.diffOps{blockId}.(localOpName); 127 localOpName = [opName '_' boundary{2}];
128 128 blockId = boundary{1};
129 div = {obj.blockmatrixDiv{1}, size(localOp,2)}; 129 localOp = obj.diffOps{blockId}.(localOpName);
130 blockOp = blockmatrix.zero(div); 130
131 blockOp{blockId,1} = localOp; 131 div = {obj.blockmatrixDiv{1}, size(localOp,2)};
132 op = blockmatrix.toMatrix(blockOp); 132 blockOp = blockmatrix.zero(div);
133 return 133 blockOp{blockId,1} = localOp;
134 else 134 op = blockmatrix.toMatrix(blockOp);
135 % Boundary är en sträng med en boundary group i. 135 return
136 case 'multiblock.BoundaryGroup'
137 op = [];
138 for i = 1:length(boundary)
139 op = [op, obj.getBoundaryOperator(opName, boundary{i})];
140 end
141 otherwise
142 error('Unknown boundary indentifier')
136 end 143 end
137 end 144 end
138 145
139 % Creates the closure and penalty matrix for a given boundary condition, 146 % Creates the closure and penalty matrix for a given boundary condition,
140 % boundary -- the name of the boundary on the form {id,name} where 147 % boundary -- the name of the boundary on the form {id,name} where
141 % id is the number of a block and name is the name of a 148 % id is the number of a block and name is the name of a
142 % boundary of that block example: {1,'s'} or {3,'w'} 149 % boundary of that block example: {1,'s'} or {3,'w'}. It
150 % can also be a boundary group
143 function [closure, penalty] = boundary_condition(obj, boundary, type) 151 function [closure, penalty] = boundary_condition(obj, boundary, type)
152 switch class(boundary)
153 case 'cell'
154 [closure, penalty] = obj.singleBoundaryCondition(boundary, type);
155 case 'multiblock.BoundaryGroup'
156 [n,m] = size(obj.D);
157 closure = sparse(n,m);
158 penalty = [];
159 for i = 1:length(boundary)
160 [closurePart, penaltyPart] = obj.boundary_condition(boundary{i}, type);
161 closure = closure + closurePart;
162 penalty = [penalty, penaltyPart];
163 end
164 otherwise
165 error('Unknown boundary indentifier')
166 end
167
168 end
169
170 function [closure, penalty] = singleBoundaryCondition(obj, boundary, type)
144 I = boundary{1}; 171 I = boundary{1};
145 name = boundary{2}; 172 name = boundary{2};
146 173
147 % Get the closure and penaly matrices 174 % Get the closure and penaly matrices
148 [blockClosure, blockPenalty] = obj.diffOps{I}.boundary_condition(name, type); 175 [blockClosure, blockPenalty] = obj.diffOps{I}.boundary_condition(name, type);