[cig-commits] commit: make compute_Cp only uses distance functions

Mercurial hg at geodynamics.org
Tue Mar 13 06:44:20 PDT 2012


changeset:   92:5f9e41c248b1
tag:         tip
user:        Walter Landry <wlandry at caltech.edu>
date:        Tue Mar 13 06:44:05 2012 -0700
files:       compute_Cp.cxx sign.hxx
description:
make compute_Cp only uses distance functions


diff -r c37e7e135922 -r 5f9e41c248b1 compute_Cp.cxx
--- a/compute_Cp.cxx	Tue Mar 13 06:23:57 2012 -0700
+++ b/compute_Cp.cxx	Tue Mar 13 06:44:05 2012 -0700
@@ -3,6 +3,7 @@
 #include <iostream>
 #include "compute_v_on_interface.hxx"
 #include "FTensor.hpp"
+#include "sign.hxx"
 
 void compute_Cp(const Model &model, const double zx[Nx+1][Ny],
                 const double zy[Nx][Ny+1],
@@ -14,20 +15,25 @@ void compute_Cp(const Model &model, cons
 {
   Cp=0;
 
-  FTensor::Tensor1<bool,2> intersects;
+  bool intersects[]={sign(distx[i][j])!=sign(distx[i+1][j]),
+                     sign(disty[i][j])!=sign(disty[i][j+1])};
 
   FTensor::Tensor1<double,2> pos((i+0.5)*h,(j+0.5)*h);
-  intersects(0)=(pos(0)+h/2>middle && pos(0)-h/2<middle);
-  intersects(1)=false;
   
   FTensor::Tensor1<double,2> interface_pos[2];
-  interface_pos[0](0)=middle;
-  interface_pos[0](1)=pos(1);
-  interface_pos[1](0)=0;
-  interface_pos[1](1)=0;
+  if(intersects[0])
+    {
+      interface_pos[0](0)=i*h-distx[i][j]*h/(distx[i+1][j]-distx[i][j]);
+      interface_pos[0](1)=(j+0.5)*h;
+    }
+  else if(intersects[1])
+    {
+      interface_pos[1](0)=(i+0.5)*h;
+      interface_pos[1](1)=j*h-disty[i][j]*h/(disty[i][j+1]-disty[i][j]);
+    }
 
   for(int dd=0;dd<2;++dd)
-    if(intersects(dd))
+    if(intersects[dd])
       {
         FTensor::Tensor1<double,2> v, dv;
         FTensor::Tensor1<int,2> dir(0,0);
diff -r c37e7e135922 -r 5f9e41c248b1 sign.hxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sign.hxx	Tue Mar 13 06:44:05 2012 -0700
@@ -0,0 +1,8 @@
+#ifndef GAMR_SIGN_HXX
+#define GAMR_SIGN_HXX
+
+template <typename T> int sign(T val) {
+    return (val > T(0)) - (val < T(0));
+}
+
+#endif



More information about the CIG-COMMITS mailing list