changeset 1121:dd25184e71ec feature/poroelastic

Add diffOp for gradient
author Martin Almquist <malmquist@stanford.edu>
date Sat, 11 May 2019 15:11:04 -0700
parents 7963a9cab637
children ff39d6692489
files +scheme/Gradient.m
diffstat 1 files changed, 113 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r 7963a9cab637 -r dd25184e71ec +scheme/Gradient.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+scheme/Gradient.m	Sat May 11 15:11:04 2019 -0700
@@ -0,0 +1,113 @@
+classdef Gradient < scheme.Scheme
+
+% Approximates the divergence
+% Interface and boundary condition methods are just dummies
+
+    properties
+        m % Number of points in each direction, possibly a vector
+        h % Grid spacing
+
+        grid
+        dim
+
+        order % Order of accuracy for the approximation
+
+        D
+        D1
+        H
+    end
+
+    methods
+
+        function obj = Gradient(g, order, opSet)
+            default_arg('opSet',{@sbp.D2Variable, @sbp.D2Variable});
+
+            dim = 2;
+
+            m = g.size();
+            m_tot = g.N();
+
+            h = g.scaling();
+            lim = g.lim;
+            if isempty(lim)
+                x = g.x;
+                lim = cell(length(x),1);
+                for i = 1:length(x)
+                    lim{i} = {min(x{i}), max(x{i})};
+                end
+            end
+
+            % 1D operators
+            ops = cell(dim,1);
+            for i = 1:dim
+                ops{i} = opSet{i}(m(i), lim{i}, order);
+            end
+
+            I = cell(dim,1);
+            D1 = cell(dim,1);
+
+            for i = 1:dim
+                I{i} = speye(m(i));
+                D1{i} = ops{i}.D1;
+            end
+
+            %====== Assemble full operators ========
+
+            % D1
+            obj.D1{1} = kron(D1{1},I{2});
+            obj.D1{2} = kron(I{1},D1{2});
+
+            I_dim = speye(dim, dim);
+
+            % E{i}^T picks out component i.
+            E = cell(dim,1);
+            I = speye(m_tot,m_tot);
+            for i = 1:dim
+                e = sparse(dim,1);
+                e(i) = 1;
+                E{i} = kron(I,e);
+            end
+
+            Grad = sparse(dim*m_tot, m_tot);
+            for i = 1:dim
+                Grad = Grad + E{i}*obj.D1{i};
+            end
+            obj.D = Grad;
+            obj.H = [];
+            %=========================================%'
+
+        end
+
+
+        % Closure functions return the operators applied to the own domain to close the boundary
+        % Penalty functions return the operators to force the solution. In the case of an interface it returns the operator applied to the other doamin.
+        %       boundary            is a string specifying the boundary e.g. 'l','r' or 'e','w','n','s'.
+        %       bc                  is a cell array of component and bc type, e.g. {1, 'd'} for Dirichlet condition
+        %                           on the first component. Can also be e.g.
+        %                           {'normal', 'd'} or {'tangential', 't'} for conditions on
+        %                           tangential/normal component.
+        %       data                is a function returning the data that should be applied at the boundary.
+        %       neighbour_scheme    is an instance of Scheme that should be interfaced to.
+        %       neighbour_boundary  is a string specifying which boundary to interface to.
+        function [closure, penalty] = boundary_condition(obj, boundary, bc)
+            error('Not implemented')
+        end
+
+        % type     Struct that specifies the interface coupling.
+        %          Fields:
+        %          -- tuning:           penalty strength, defaults to 1.2
+        %          -- interpolation:    type of interpolation, default 'none'
+        function [closure, penalty] = interface(obj,boundary,neighbour_scheme,neighbour_boundary,type)
+
+            [m, n] = size(obj.D);
+            closure = sparse(m, n);
+
+            [m, n] = size(neighbour_scheme.D);
+            penalty = sparse(m, n);
+        end
+
+        function N = size(obj)
+            N = obj.dim*prod(obj.m);
+        end
+    end
+end