From 642739b20b8b97b96bef8ca95ee033f4a88c6224 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Wed, 27 Jun 2018 01:22:16 +0100
Subject: [PATCH] sync to server

---
 run_paramspace.pl                             | 27 ++++++++++++++++---
 src/binary_c_structures.h                     |  1 +
 .../common_envelope_evolution.c               |  3 ++-
 src/disc/disc_calc_disc_structure.c           |  6 +++--
 src/disc/disc_derivatives.c                   |  1 -
 src/disc/disc_evolve_disc_structure.c         | 17 ++++++++----
 src/disc/disc_natural_timescales.c            | 18 +++++++++++--
 src/logging/log_every_timestep.c              |  5 +++-
 tbse                                          | 16 +++++------
 9 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/run_paramspace.pl b/run_paramspace.pl
index 94f47487c..64501f9bb 100755
--- a/run_paramspace.pl
+++ b/run_paramspace.pl
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Fcntl 'O_RDONLY';
 use Tie::File;
-
+use Term::ANSIColor;
 my $dir = $ARGV[0] // die("you must give a source directory");
 my $n = $ARGV[1] // die("you must give a line number");
 my $filestub = 'paramspace.dat';
@@ -34,11 +34,13 @@ print "System is $system\n";
 my ($M0,$M1,$a,$P,$stellar_type,$lifetime,$final_eccentricity,$prob) =
     split(/\s+/,$system);
 
-my $args = `./src/perl/scripts2/cbdiscs.pl show_opts outdir=/dev/null | grep BSE_OPTIONS`;
+my $args = `$ENV{HOME}/progs/stars/binary_c/src/perl/scripts2/cbdiscs.pl show_opts outdir=/dev/null | grep BSE_OPTIONS`;
 $args=~s/^BSE_OPTIONS\s+//;
 $args=~s/\s+$//;
 $args=~s/extra//;
 $args=~s/--z/--metallicity/;
+$args=~s/--log_fins \d//;
+$args=~s/--disc_log\s+\S+//g;
 $args=~s/ -- //g;
     
 $args = "$args --M_1 $M0 --M_2 $M1 --separation $a --orbital_period 0 --probability $prob --eccentricity 0 --metallicity 0.02 ";
@@ -47,9 +49,28 @@ print "ARGS\n$args\n";
 my $valgrind = 'valgrind --main-stacksize=30000000 --max-stackframe=30000000 --read-var-info=yes --track-origins=yes --tool=memcheck --leak-check=full --show-reachable=yes --freelist-vol=100000000 --partial-loads-ok=no --undef-value-errors=yes -v --vgdb-error=1';
 $valgrind='';
 
+my $pwd = `pwd`; chomp $pwd;
+
+if($pwd eq '/home/izzard/progs/stars/binary_c')
+{
+    # new build
+    $args .= ' --disc_log 2 '; 
+}
+else
+{
+    # old build
+    $args =~ s/--cbdisc_adapt_Rin_to_L2 \d//;
+    $args =~ s/--cbdisc_fail_ring_inside_separation \d//;
+    $args =~ s/--cbdisc_inner_edge_stripping \d//;
+    $args =~ s/--cbdisc_outer_edge_stripping \d//;
+}
+
+$args .= " --comenv_disc_mass_fraction 0.1 --comenv_disc_angmom_fraction -3 ";
+
 # run the system
-my $cmd = "$valgrind tbse $args --disc_log 1 --log_filename /tmp/disc.log  |grep -v DISC_ |grep -v POSTAGB | grep -v XYIELD|grep -v SINGLE_STAR ";
+my $cmd = "$valgrind tbse $args --internal_buffering 0 --log_filename /tmp/disc.log  |grep -v DISC_ |grep -v POSTAGB | grep -v XYIELD|grep -v SINGLE_STAR ";
 
+print "exec: \n\n",color('red'),$cmd,color('white'),"\n\n";
 print `$cmd`;
 
 print "You should have lifetime = $lifetime\n";
diff --git a/src/binary_c_structures.h b/src/binary_c_structures.h
index 6b586bbfa..8dc924e7a 100644
--- a/src/binary_c_structures.h
+++ b/src/binary_c_structures.h
@@ -910,6 +910,7 @@ struct disc_t {
     double lastlogtime;
 #endif
     double t_m;
+    double t_m_slow;
     double t_j;
     double t_e;
     
diff --git a/src/common_envelope/common_envelope_evolution.c b/src/common_envelope/common_envelope_evolution.c
index 512fe1560..bc2c6678c 100644
--- a/src/common_envelope/common_envelope_evolution.c
+++ b/src/common_envelope/common_envelope_evolution.c
@@ -2809,7 +2809,8 @@ static double comenv_dm_bisector(double menv,
 
 
     /* testing */
-    if(news->radius > Rtarget &&
+    if(1 &&
+       news->radius > Rtarget &&
        news->stellar_type != s->stellar_type)
     {
         
diff --git a/src/disc/disc_calc_disc_structure.c b/src/disc/disc_calc_disc_structure.c
index b26408226..242670a7d 100644
--- a/src/disc/disc_calc_disc_structure.c
+++ b/src/disc/disc_calc_disc_structure.c
@@ -88,11 +88,13 @@ int disc_calc_disc_structure(const struct binary_system_t * binary,
     }
 
     /* 
-     * Testing: disc evaporation if evaporation lifetime < 1 year
+     * Testing: disc evaporation if wind evaporation lifetime < 1 year
+     *
+     * NB we allow edge stripping to be faster.
      */
     if(Disc_is_disc(disc) &&
        IS_NOT_ZERO(disc->t_m) &&
-       disc->t_m < DISC_MINIMUM_EVAPORATION_TIMESCALE)
+       disc->t_m_slow < DISC_MINIMUM_EVAPORATION_TIMESCALE)
     {
         disc->dM_ejected += -disc->M;
         disc->dJ_ejected += -disc->J;
diff --git a/src/disc/disc_derivatives.c b/src/disc/disc_derivatives.c
index 02010014d..c55a7950b 100644
--- a/src/disc/disc_derivatives.c
+++ b/src/disc/disc_derivatives.c
@@ -411,7 +411,6 @@ void disc_derivatives(struct disc_t * disc,
 
             if(stardata->preferences->cbdisc_outer_edge_stripping == FALSE)
             {
-        
                 /*
                  * Apply RAM-stripping rate as a smoothed, global rate. 
                  *
diff --git a/src/disc/disc_evolve_disc_structure.c b/src/disc/disc_evolve_disc_structure.c
index 8ed90f73a..c9ca945ab 100644
--- a/src/disc/disc_evolve_disc_structure.c
+++ b/src/disc/disc_evolve_disc_structure.c
@@ -343,7 +343,12 @@ double disc_evolve_disc_structure(struct stardata_t * stardata,
                     if(failure_reason && disc->append==FALSE)
                     {
 #if defined DISC_LOG || defined DISC_LOG_2D
-                        //disc_logging(stardata,binary,DISC_LOG_EVOLVE_DISC_STRUCTURE2);
+                        if(stardata->preferences->disc_log >= 2)
+                        {
+                            disc_logging(stardata,
+                                         binary,
+                                         DISC_LOG_EVOLVE_DISC_STRUCTURE2);
+                        }
 #endif // DISC_LOG or DISC_LOG_2D
                         
                         Discdebug(1,
@@ -410,10 +415,12 @@ double disc_evolve_disc_structure(struct stardata_t * stardata,
                     /*
                      * Do logging 
                      */
-/*                    disc_logging(stardata,
-                                 binary,
-                                 DISC_LOG_EVOLVE_DISC_STRUCTURE);
-*/
+                    if(stardata->preferences->disc_log>=2)
+                    {
+                        disc_logging(stardata,
+                                     binary,
+                                     DISC_LOG_EVOLVE_DISC_STRUCTURE);
+                    }
 #endif//DISC_LOG
                 }
             }
diff --git a/src/disc/disc_natural_timescales.c b/src/disc/disc_natural_timescales.c
index 2821cde4e..4496ffee2 100644
--- a/src/disc/disc_natural_timescales.c
+++ b/src/disc/disc_natural_timescales.c
@@ -20,7 +20,7 @@ void disc_natural_timescales(struct stardata_t * stardata,
      * mass and angular momentum changes
      */
     int i;
-    double mdot=0.0,jdot=0.0,edot=0.0;
+    double mdot=0.0,jdot=0.0,edot=0.0,mdot_slow=0.0;
     
     /*
      * The question here is whether to resolve
@@ -41,6 +41,19 @@ void disc_natural_timescales(struct stardata_t * stardata,
         Show_disc_derivative(i);
     }
 
+    /*
+     * Slow (wind-like) mass loss
+     */
+    mdot_slow =
+        Absolute(disc->loss[DISC_LOSS_GLOBAL].mdot)+
+        Absolute(disc->loss[DISC_LOSS_INNER_VISCOUS].mdot)+
+        Absolute(disc->loss[DISC_LOSS_XRAY].mdot);
+
+    if(stardata->preferences->cbdisc_outer_edge_stripping == FALSE)
+    {
+        Absolute(disc->loss[DISC_LOSS_ISM].mdot);
+    }
+    
     Discdebug(1,
               "MDOT timestep disc %g g/s = %g Msun/y -> timescale = %g (Msun) / %g (Msun/y) = %g y\n",
               mdot,
@@ -104,7 +117,8 @@ void disc_natural_timescales(struct stardata_t * stardata,
     disc->t_m = Timescale(disc->M,mdot);
     disc->t_j = Timescale(disc->J,jdot);
     disc->t_e = Timescale(binary->eccentricity,edot);
-
+    disc->t_m_slow = Timescale(disc->M,mdot_slow);
+                               
     Discdebug(1,
               "natural timescales: t=%30.12e y tM=%g tJ=%g te=%g years (M = %g Msun, mdot = %g Msun/y, jdot = %g; edot = %g; stardata = %g; e = %g)\n",
               disc->lifetime/YEAR_LENGTH_IN_SECONDS,
diff --git a/src/logging/log_every_timestep.c b/src/logging/log_every_timestep.c
index 42b3b059a..b76fb46ab 100644
--- a/src/logging/log_every_timestep.c
+++ b/src/logging/log_every_timestep.c
@@ -2212,7 +2212,10 @@ void log_every_timestep(struct stardata_t * RESTRICT stardata)
 #endif // UNIT_TESTS
 
 #ifdef DISCS
-    disc_logging(stardata,NULL,DISC_LOG_EVERY_TIMESTEP);
+    if(stardata->preferences->disc_log != 0)
+    {
+        disc_logging(stardata,NULL,DISC_LOG_EVERY_TIMESTEP);
+    }
 #endif // DISCS
     /*
       printf("ACCLOG %g %g %g %g\n",
diff --git a/tbse b/tbse
index 2466094fd..c9cf698bf 100755
--- a/tbse
+++ b/tbse
@@ -439,8 +439,8 @@ WIND_DISC_ANGMOM_FRACTION=1e3
 # Disc timestep multiplier (0.01)
 DISC_TIMESTEP_FACTOR=0.01
 
-# soft disc log switch (1=on, 0=off)
-DISC_LOG=1
+# soft disc log switch (0=off, 1=on, 2=on with sub-timestep logging)
+DISC_LOG=2
 
 # Circumbinary disc physical properties
 CBDISC_GAMMA=1.6666666 # 1.6666666
@@ -459,7 +459,7 @@ CBDISC_START_DJDM=0 # (0)
 # require that an initial disc has Rout/Rin > 1 + CBDISC_NEW_EPSILON. 
 # Usually 0.2 is "ok" but this choice is really quite arbitrary.
 # Not used any more? (0.0)
-CBDISC_NEW_EPSILON=0.0
+CBDISC_NEW_EPSILON=0.2
 
 # Circumbinary disc mass loss rate algorithms
 
@@ -469,7 +469,7 @@ CBDISC_NEW_EPSILON=0.0
 CBDISC_MASS_LOSS_CONSTANT_RATE=0.0
 
 # multiplier for inner edge viscous rate (1.0)
-CBDISC_MASS_LOSS_INNER_VISCOUS_MULTIPLIER=1.0
+CBDISC_MASS_LOSS_INNER_VISCOUS_MULTIPLIER=1.0e-10
 
 # algorithm for determining which star the material lands on (1)
 # 0 = Young and Clarke 2015 (MNRAS 452, 3085)
@@ -483,10 +483,10 @@ CBDISC_MASS_LOSS_INNER_VISCOUS_ACCRETION_METHOD=0
 # If you use the viscous coupling, the evaporation
 # radius is scaled appropriately.
 #
-CBDISC_MASS_LOSS_INNER_L2_CROSS_MULTIPLIER=1.0
+CBDISC_MASS_LOSS_INNER_L2_CROSS_MULTIPLIER=0.0
 
 # couple L2 and viscous losses at the inner edge (1)
-CBDISC_VISCOUS_L2_COUPLING=1
+CBDISC_VISCOUS_L2_COUPLING=0
 
 # adapt torque such that Rin == L2, except on the first
 # timestep. After the first timestep, material inside L2 is
@@ -511,8 +511,8 @@ CBDISC_MASS_LOSS_XRAY_MULTIPLIER=1.0
 CBDISC_VISCOUS_PHOTOEVAPORATION_COUPLING=1
 
 # edge stripping (0 or 1, both 1 by default)
-CBDISC_INNER_EDGE_STRIPPING=1
-CBDISC_OUTER_EDGE_STRIPPING=1
+CBDISC_INNER_EDGE_STRIPPING=0
+CBDISC_OUTER_EDGE_STRIPPING=0
 
 # timescales for edge stripping:
 # 0 = instant
-- 
GitLab