{"action":"created","comment":{"url":"https://api.github.com/repos/opesci/opesci-fd/pulls/comments/39724648","id":39724648,"diff_hunk":"@@ -201,51 +202,70 @@ def set(self, dimension, direction):\n         staggered[direction] = True\n         Field.set(self, dimension, staggered)\n \n-    def set_free_surface(self, d, b, side):\n+    def set_free_surface(self, d, b, side, algo=0):\n         \"\"\"\n         - set free surface boundary condition to boundary d, at index b\n         :param d: direction of the boundary surface normal\n         :param b: location of the boundary (index)\n         :param side: lower boundary (0) or upper boundary (1)\n+        :param algo: which algorithm to use to compute ghost cells\n         - e.g. set_free_surface([t,x,y,z],1,2,0)\n         set y-z plane at x=2 to be lower free surface\n         - ghost cells are calculated using reflection of stress fields\n         - store the symbolic equations to populate ghost cells in self.bc\n         \"\"\"\n-        # use this stress field to solve for ghost cell expression\n-        field = self.sfields[d]\n-        expr = field.dt\n-        idx = list(self.indices)\n-        # create substituion dictionary\n-        dict1 = {}\n-        derivatives = get_all_objects(expr, DDerivative)\n-        for deriv in derivatives:\n-            # using 2nd order approximation\n-            dict1[deriv] = deriv.fd[1]\n-        expr = expr.subs(dict1)\n-        if self.staggered[d]:\n-            # if staggered, solve ghost cell using T'[b]=0 (e.g. W at z surface, using Tzz)\n-            eq = Eq(expr)\n-            shift = hf\n-            t = b - hf  # real boundary location\n-        else:\n-            # if not staggered, solve ghost cell using T'[b-1/2]=T'[b+1/2] (e.g. U at z surface, using Txz)\n-            eq = Eq(expr.subs(idx[d], idx[d]-hf),\n-                    expr.subs(idx[d], idx[d]+hf))\n-            shift = 1\n-            t = b\n-\n-        idx[d] -= ((-1)**side)*shift\n-        lhs = self[idx]\n-        rhs = solve(eq, lhs)[0]\n-        lhs = lhs.subs(self.indices[d], t)\n-        rhs = self.align(rhs.subs(self.indices[d], t))\n-\n-        # change ti to t+1\n-        lhs = lhs.subs(idx[0], idx[0]+1)\n-        rhs = rhs.subs(idx[0], idx[0]+1)\n-\n-        self.bc[d][side] = [Eq(lhs, rhs)]\n+        if algo == 0:\n+            # use this stress field to solve for ghost cell expression\n+            field = self.sfields[d]\n+            expr = field.dt\n+            idx = list(self.indices)\n+            # create substituion dictionary\n+            dict1 = {}\n+            derivatives = get_all_objects(expr, DDerivative)\n+            for deriv in derivatives:\n+                # using 2nd order approximation\n+                dict1[deriv] = deriv.fd[1]\n+            expr = expr.subs(dict1)\n+            if self.staggered[d]:\n+                # if staggered, solve ghost cell using T'[b]=0 (e.g. W at z surface, using Tzz)\n+                eq = Eq(expr)\n+                shift = hf\n+                t = b - hf  # real boundary location\n+            else:\n+                # if not staggered, solve ghost cell using T'[b-1/2]=T'[b+1/2] (e.g. U at z surface, using Txz)\n+                eq = Eq(expr.subs(idx[d], idx[d]-hf),\n+                        expr.subs(idx[d], idx[d]+hf))\n+                shift = 1\n+                t = b\n+\n+            idx[d] -= ((-1)**side)*shift\n+            lhs = self[idx]\n+            rhs = solve(eq, lhs)[0]\n+            lhs = lhs.subs(self.indices[d], t)\n+            rhs = self.align(rhs.subs(self.indices[d], t))\n+\n+            # change ti to t+1\n+            lhs = lhs.subs(idx[0], idx[0]+1)\n+            rhs = rhs.subs(idx[0], idx[0]+1)\n+\n+            self.bc[d][side] = [Eq(lhs, rhs)]\n+        elif algo == 1:\n+            idx = list(self.indices)\n+            if self.staggered[d]:\n+                # e.g. W at z boundary\n+                idx[d] = b - (1-side)\n+            else:\n+                # e.g. U at z boundary\n+                idx[d] = b - (-1)**side\n+            eq = Eq(self[idx])\n+            eq = eq.subs(idx[0], idx[0]+1)\n+            self.bc[d][side] = [eq]\n+            # populate all ghost cells\n+            for depth in range(self.accuracy[d]-1):\n+                idx[d] -= (-1)**side\n+                eq = Eq(self[idx])\n+                eq = eq.subs(idx[0], idx[0]+1)\n+                self.bc[d][side].append(eq)","path":"opesci/fields.py","position":112,"original_position":112,"commit_id":"ed9729cea4be7297c4b6e75c83f7e2b074b3dd69","original_commit_id":"ed9729cea4be7297c4b6e75c83f7e2b074b3dd69","user":{"login":"ctjacobs","id":5470627,"avatar_url":"https://avatars.githubusercontent.com/u/5470627?v=3","gravatar_id":"","url":"https://api.github.com/users/ctjacobs","html_url":"https://github.com/ctjacobs","followers_url":"https://api.github.com/users/ctjacobs/followers","following_url":"https://api.github.com/users/ctjacobs/following{/other_user}","gists_url":"https://api.github.com/users/ctjacobs/gists{/gist_id}","starred_url":"https://api.github.com/users/ctjacobs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctjacobs/subscriptions","organizations_url":"https://api.github.com/users/ctjacobs/orgs","repos_url":"https://api.github.com/users/ctjacobs/repos","events_url":"https://api.github.com/users/ctjacobs/events{/privacy}","received_events_url":"https://api.github.com/users/ctjacobs/received_events","type":"User","site_admin":false},"body":"```\r\nelse:\r\n   raise ValueError(\"Unknown ghost cell algorithm\")\r\n```","created_at":"2015-09-17T09:06:24Z","updated_at":"2015-09-17T09:06:24Z","html_url":"https://github.com/opesci/opesci-fd/pull/47#discussion_r39724648","pull_request_url":"https://api.github.com/repos/opesci/opesci-fd/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/comments/39724648"},"html":{"href":"https://github.com/opesci/opesci-fd/pull/47#discussion_r39724648"},"pull_request":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/opesci/opesci-fd/pulls/47","id":45176563,"html_url":"https://github.com/opesci/opesci-fd/pull/47","diff_url":"https://github.com/opesci/opesci-fd/pull/47.diff","patch_url":"https://github.com/opesci/opesci-fd/pull/47.patch","issue_url":"https://api.github.com/repos/opesci/opesci-fd/issues/47","number":47,"state":"open","locked":false,"title":"Feature higher spatial order","user":{"login":"tj-sun","id":9328006,"avatar_url":"https://avatars.githubusercontent.com/u/9328006?v=3","gravatar_id":"","url":"https://api.github.com/users/tj-sun","html_url":"https://github.com/tj-sun","followers_url":"https://api.github.com/users/tj-sun/followers","following_url":"https://api.github.com/users/tj-sun/following{/other_user}","gists_url":"https://api.github.com/users/tj-sun/gists{/gist_id}","starred_url":"https://api.github.com/users/tj-sun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tj-sun/subscriptions","organizations_url":"https://api.github.com/users/tj-sun/orgs","repos_url":"https://api.github.com/users/tj-sun/repos","events_url":"https://api.github.com/users/tj-sun/events{/privacy}","received_events_url":"https://api.github.com/users/tj-sun/received_events","type":"User","site_admin":false},"body":"Higher spatial order\r\n\r\n- use -so in command line to generate code for different spatial order (default to 2). e.g. -so 4 to generate 8th order\r\n- fixed previous bug on AI calculation\r\n- simple algorithm for free-surface boundary for now (setting velocity to zero), according to Robertsson's 1996 paper \"A numerical free-surface condition for elastic/viscoelastic finite-difference modeling in the presence of topography\"\r\n- helper functions to compute non-symmetric FD approximation, which is needed for other algorithm for free surface","created_at":"2015-09-16T14:15:09Z","updated_at":"2015-09-17T09:06:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ffd7f0935f5b003d946b1098d34305ab61ae72c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/opesci/opesci-fd/pulls/47/commits","review_comments_url":"https://api.github.com/repos/opesci/opesci-fd/pulls/47/comments","review_comment_url":"https://api.github.com/repos/opesci/opesci-fd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opesci/opesci-fd/issues/47/comments","statuses_url":"https://api.github.com/repos/opesci/opesci-fd/statuses/ed9729cea4be7297c4b6e75c83f7e2b074b3dd69","head":{"label":"opesci:feature_higher_spatial_order","ref":"feature_higher_spatial_order","sha":"ed9729cea4be7297c4b6e75c83f7e2b074b3dd69","user":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":32512811,"name":"opesci-fd","full_name":"opesci/opesci-fd","owner":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/opesci-fd","description":"Solvers for 3D wave equation","fork":false,"url":"https://api.github.com/repos/opesci/opesci-fd","forks_url":"https://api.github.com/repos/opesci/opesci-fd/forks","keys_url":"https://api.github.com/repos/opesci/opesci-fd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/opesci-fd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/opesci-fd/teams","hooks_url":"https://api.github.com/repos/opesci/opesci-fd/hooks","issue_events_url":"https://api.github.com/repos/opesci/opesci-fd/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/opesci-fd/events","assignees_url":"https://api.github.com/repos/opesci/opesci-fd/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/opesci-fd/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/opesci-fd/tags","blobs_url":"https://api.github.com/repos/opesci/opesci-fd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/opesci-fd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/opesci-fd/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/opesci-fd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/opesci-fd/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/opesci-fd/languages","stargazers_url":"https://api.github.com/repos/opesci/opesci-fd/stargazers","contributors_url":"https://api.github.com/repos/opesci/opesci-fd/contributors","subscribers_url":"https://api.github.com/repos/opesci/opesci-fd/subscribers","subscription_url":"https://api.github.com/repos/opesci/opesci-fd/subscription","commits_url":"https://api.github.com/repos/opesci/opesci-fd/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/opesci-fd/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/opesci-fd/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/opesci-fd/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/opesci-fd/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/opesci-fd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/opesci-fd/merges","archive_url":"https://api.github.com/repos/opesci/opesci-fd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/opesci-fd/downloads","issues_url":"https://api.github.com/repos/opesci/opesci-fd/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/opesci-fd/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/opesci-fd/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/opesci-fd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/opesci-fd/labels{/name}","releases_url":"https://api.github.com/repos/opesci/opesci-fd/releases{/id}","created_at":"2015-03-19T09:39:45Z","updated_at":"2015-09-01T19:13:30Z","pushed_at":"2015-09-16T19:47:07Z","git_url":"git://github.com/opesci/opesci-fd.git","ssh_url":"git@github.com:opesci/opesci-fd.git","clone_url":"https://github.com/opesci/opesci-fd.git","svn_url":"https://github.com/opesci/opesci-fd","homepage":null,"size":2759,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":16,"forks":4,"open_issues":16,"watchers":1,"default_branch":"master"}},"base":{"label":"opesci:master","ref":"master","sha":"4d993e36a0826039da6311e9aa10681277b70823","user":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":32512811,"name":"opesci-fd","full_name":"opesci/opesci-fd","owner":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/opesci-fd","description":"Solvers for 3D wave equation","fork":false,"url":"https://api.github.com/repos/opesci/opesci-fd","forks_url":"https://api.github.com/repos/opesci/opesci-fd/forks","keys_url":"https://api.github.com/repos/opesci/opesci-fd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/opesci-fd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/opesci-fd/teams","hooks_url":"https://api.github.com/repos/opesci/opesci-fd/hooks","issue_events_url":"https://api.github.com/repos/opesci/opesci-fd/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/opesci-fd/events","assignees_url":"https://api.github.com/repos/opesci/opesci-fd/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/opesci-fd/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/opesci-fd/tags","blobs_url":"https://api.github.com/repos/opesci/opesci-fd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/opesci-fd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/opesci-fd/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/opesci-fd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/opesci-fd/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/opesci-fd/languages","stargazers_url":"https://api.github.com/repos/opesci/opesci-fd/stargazers","contributors_url":"https://api.github.com/repos/opesci/opesci-fd/contributors","subscribers_url":"https://api.github.com/repos/opesci/opesci-fd/subscribers","subscription_url":"https://api.github.com/repos/opesci/opesci-fd/subscription","commits_url":"https://api.github.com/repos/opesci/opesci-fd/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/opesci-fd/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/opesci-fd/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/opesci-fd/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/opesci-fd/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/opesci-fd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/opesci-fd/merges","archive_url":"https://api.github.com/repos/opesci/opesci-fd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/opesci-fd/downloads","issues_url":"https://api.github.com/repos/opesci/opesci-fd/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/opesci-fd/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/opesci-fd/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/opesci-fd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/opesci-fd/labels{/name}","releases_url":"https://api.github.com/repos/opesci/opesci-fd/releases{/id}","created_at":"2015-03-19T09:39:45Z","updated_at":"2015-09-01T19:13:30Z","pushed_at":"2015-09-16T19:47:07Z","git_url":"git://github.com/opesci/opesci-fd.git","ssh_url":"git@github.com:opesci/opesci-fd.git","clone_url":"https://github.com/opesci/opesci-fd.git","svn_url":"https://github.com/opesci/opesci-fd","homepage":null,"size":2759,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":16,"forks":4,"open_issues":16,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/47"},"html":{"href":"https://github.com/opesci/opesci-fd/pull/47"},"issue":{"href":"https://api.github.com/repos/opesci/opesci-fd/issues/47"},"comments":{"href":"https://api.github.com/repos/opesci/opesci-fd/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opesci/opesci-fd/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/opesci/opesci-fd/statuses/ed9729cea4be7297c4b6e75c83f7e2b074b3dd69"}}}}