00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <string.h> 00004 #include <math.h> 00005 #include <mpi.h> 00006 00007 #include "allvars.h" 00008 #include "proto.h" 00009 00010 00015 #ifdef PMGRID 00016 00020 void long_range_init(void) 00021 { 00022 #ifdef PERIODIC 00023 pm_init_periodic(); 00024 #ifdef PLACEHIGHRESREGION 00025 pm_init_nonperiodic(); 00026 #endif 00027 #else 00028 pm_init_nonperiodic(); 00029 #endif 00030 } 00031 00032 00036 void long_range_init_regionsize(void) 00037 { 00038 #ifdef PERIODIC 00039 #ifdef PLACEHIGHRESREGION 00040 if(RestartFlag != 1) 00041 pm_init_regionsize(); 00042 pm_setup_nonperiodic_kernel(); 00043 #endif 00044 #else 00045 if(RestartFlag != 1) 00046 pm_init_regionsize(); 00047 pm_setup_nonperiodic_kernel(); 00048 #endif 00049 } 00050 00051 00056 void long_range_force(void) 00057 { 00058 int i; 00059 00060 #ifndef PERIODIC 00061 int j; 00062 double fac; 00063 #endif 00064 00065 00066 for(i = 0; i < NumPart; i++) 00067 P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0; 00068 00069 #ifdef NOGRAVITY 00070 return; 00071 #endif 00072 00073 00074 #ifdef PERIODIC 00075 pmforce_periodic(); 00076 #ifdef PLACEHIGHRESREGION 00077 i = pmforce_nonperiodic(1); 00078 #ifdef SYNCHRONIZATION 00079 if(i == 1) /* this is returned if a particle lied outside allowed range */ 00080 { 00081 pm_init_regionsize(); 00082 pm_setup_nonperiodic_kernel(); 00083 i = pmforce_nonperiodic(1); /* try again */ 00084 } 00085 if(i == 1) 00086 endrun(68686); 00087 #endif 00088 #endif 00089 #else 00090 i = pmforce_nonperiodic(0); 00091 #ifdef SYNCHRONIZATION 00092 if(i == 1) /* this is returned if a particle lied outside allowed range */ 00093 { 00094 pm_init_regionsize(); 00095 pm_setup_nonperiodic_kernel(); 00096 i = pmforce_nonperiodic(0); /* try again */ 00097 } 00098 #endif 00099 if(i == 1) 00100 endrun(68687); 00101 #ifdef PLACEHIGHRESREGION 00102 i = pmforce_nonperiodic(1); 00103 #ifdef SYNCHRONIZATION 00104 if(i == 1) /* this is returned if a particle lied outside allowed range */ 00105 { 00106 pm_init_regionsize(); 00107 pm_setup_nonperiodic_kernel(); 00108 00109 /* try again */ 00110 00111 for(i = 0; i < NumPart; i++) 00112 P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0; 00113 00114 i = pmforce_nonperiodic(0) + pmforce_nonperiodic(1); 00115 } 00116 #endif 00117 if(i != 0) 00118 endrun(68688); 00119 #endif 00120 #endif 00121 00122 00123 #ifndef PERIODIC 00124 if(All.ComovingIntegrationOn) 00125 { 00126 fac = 0.5 * All.Hubble * All.Hubble * All.Omega0; 00127 00128 for(i = 0; i < NumPart; i++) 00129 for(j = 0; j < 3; j++) 00130 P[i].GravPM[j] += fac * P[i].Pos[j]; 00131 } 00132 00133 00134 /* Finally, the following factor allows a computation of cosmological simulation 00135 with vacuum energy in physical coordinates */ 00136 00137 if(All.ComovingIntegrationOn == 0) 00138 { 00139 fac = All.OmegaLambda * All.Hubble * All.Hubble; 00140 00141 for(i = 0; i < NumPart; i++) 00142 for(j = 0; j < 3; j++) 00143 P[i].GravPM[j] += fac * P[i].Pos[j]; 00144 } 00145 #endif 00146 00147 } 00148 00149 00150 #endif