Compare commits
26 Commits
main-upstr
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a6104724e4 | |||
| 52bb8ccf12 | |||
| 02c69f6e34 | |||
| 359540af4b | |||
| a628b8e2ff | |||
| c6e1a125b8 | |||
| 547c62a116 | |||
| 3e55068548 | |||
| 4a413d669d | |||
| 9e51793499 | |||
| 66bce8c42d | |||
| 32529f09a6 | |||
| fae4093863 | |||
| 26f5add3fb | |||
| f669180572 | |||
| 0db537479b | |||
| 1f3fd264c0 | |||
| 442674cedc | |||
|
a13b6901f6
|
|||
|
7e67feddbf
|
|||
| 8d28c29a91 | |||
| 0cf58176d9 | |||
| 0f1d0de1e7 | |||
|
c60bc03664
|
|||
| b57d80ca61 | |||
| 9cd3741a90 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
__pycache__
|
||||
GW150914
|
||||
GW150914-origin
|
||||
GW150914*
|
||||
docs
|
||||
*.tmp
|
||||
|
||||
.codex
|
||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -126,6 +126,11 @@ setup.generate_AMSSNCKU_input()
|
||||
#inputvalue = input() ## Wait for user input (press Enter) to proceed
|
||||
#print()
|
||||
|
||||
setup.print_puncture_information()
|
||||
|
||||
|
||||
##################################################################
|
||||
|
||||
## Generate AMSS-NCKU program input files based on the configured parameters
|
||||
|
||||
print( )
|
||||
@@ -172,6 +177,9 @@ print( " AMSS-NCKU macro file macrodef.h has been generated. " )
|
||||
generate_macrodef.generate_macrodef_fh()
|
||||
print( " AMSS-NCKU macro file macrodef.fh has been generated. " )
|
||||
|
||||
generate_macrodef.generate_build_config()
|
||||
print( " AMSS-NCKU build config AMSS_NCKU_build.mk has been generated. " )
|
||||
|
||||
|
||||
##################################################################
|
||||
|
||||
@@ -214,9 +222,11 @@ shutil.copytree(AMSS_NCKU_source_path, AMSS_NCKU_source_copy)
|
||||
|
||||
macrodef_h_path = os.path.join(File_directory, "macrodef.h")
|
||||
macrodef_fh_path = os.path.join(File_directory, "macrodef.fh")
|
||||
build_config_path = os.path.join(File_directory, "AMSS_NCKU_build.mk")
|
||||
|
||||
shutil.copy2(macrodef_h_path, AMSS_NCKU_source_copy)
|
||||
shutil.copy2(macrodef_fh_path, AMSS_NCKU_source_copy)
|
||||
shutil.copy2(build_config_path, AMSS_NCKU_source_copy)
|
||||
|
||||
# Notes on copying files:
|
||||
# shutil.copy2 preserves file metadata such as modification time.
|
||||
@@ -307,7 +317,7 @@ if (input_data.Initial_Data_Method == "Ansorg-TwoPuncture" ):
|
||||
|
||||
import generate_TwoPuncture_input
|
||||
|
||||
generate_TwoPuncture_input.generate_AMSSNCKU_TwoPuncture_input(numerical_grid.puncture_data)
|
||||
generate_TwoPuncture_input.generate_AMSSNCKU_TwoPuncture_input()
|
||||
|
||||
print( )
|
||||
print( " The input parfile for the TwoPunctureABE executable has been generated. " )
|
||||
@@ -349,7 +359,7 @@ if (input_data.Initial_Data_Method == "Ansorg-TwoPuncture" ):
|
||||
|
||||
import renew_puncture_parameter
|
||||
|
||||
renew_puncture_parameter.append_AMSSNCKU_BSSN_input(File_directory, output_directory, numerical_grid.puncture_data)
|
||||
renew_puncture_parameter.append_AMSSNCKU_BSSN_input(File_directory, output_directory)
|
||||
|
||||
|
||||
## Generated AMSS-NCKU input filename
|
||||
|
||||
100
AMSS_NCKU_Program_Plot.py
Normal file
100
AMSS_NCKU_Program_Plot.py
Normal file
@@ -0,0 +1,100 @@
|
||||
##################################################################
|
||||
##
|
||||
## AMSS-NCKU Plot-Only Restart Script
|
||||
## Author: Xiaoqu / Claude
|
||||
## 2026/05/12
|
||||
##
|
||||
## This script checks for existing output data from AMSS_NCKU_Program.py.
|
||||
## If data exists, it skips all computation and goes directly to plotting,
|
||||
## saving time when plotting was interrupted.
|
||||
## If no data is found, it exits with a message.
|
||||
##
|
||||
##################################################################
|
||||
|
||||
## Guard against re-execution by multiprocessing child processes.
|
||||
if __name__ != '__main__':
|
||||
import sys as _sys
|
||||
_sys.exit(0)
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import AMSS_NCKU_Input as input_data
|
||||
|
||||
##################################################################
|
||||
|
||||
## Construct paths from input configuration
|
||||
File_directory = os.path.join(input_data.File_directory)
|
||||
output_directory = os.path.join(File_directory, "AMSS_NCKU_output")
|
||||
binary_results_directory = os.path.join(output_directory, input_data.Output_directory)
|
||||
figure_directory = os.path.join(File_directory, "figure")
|
||||
|
||||
##################################################################
|
||||
|
||||
## Check whether the required output data files exist
|
||||
|
||||
required_files = [
|
||||
os.path.join(binary_results_directory, "bssn_BH.dat"),
|
||||
os.path.join(binary_results_directory, "bssn_ADMQs.dat"),
|
||||
os.path.join(binary_results_directory, "bssn_psi4.dat"),
|
||||
os.path.join(binary_results_directory, "bssn_constraint.dat"),
|
||||
]
|
||||
|
||||
missing_files = [f for f in required_files if not os.path.exists(f)]
|
||||
|
||||
if missing_files:
|
||||
print(" No existing AMSS_NCKU_Program.py output data found. ")
|
||||
print(" The following required files are missing: ")
|
||||
for f in missing_files:
|
||||
print(f" {f}")
|
||||
print()
|
||||
print(" Please run AMSS_NCKU_Program.py first to generate the simulation data. ")
|
||||
print(" Exiting. ")
|
||||
sys.exit(1)
|
||||
|
||||
print(" Found existing AMSS_NCKU_Program.py output data. " )
|
||||
print(" Skipping all computation and going directly to plotting. " )
|
||||
print()
|
||||
|
||||
## Ensure the figure directory exists (it should, but be safe)
|
||||
os.makedirs(figure_directory, exist_ok=True)
|
||||
|
||||
##################################################################
|
||||
|
||||
## Plot the AMSS-NCKU program results
|
||||
|
||||
import plot_xiaoqu
|
||||
import plot_GW_strain_amplitude_xiaoqu
|
||||
from parallel_plot_helper import run_plot_tasks_parallel
|
||||
|
||||
plot_tasks = []
|
||||
|
||||
## Plot black hole trajectory
|
||||
plot_tasks.append((plot_xiaoqu.generate_puncture_orbit_plot, (binary_results_directory, figure_directory)))
|
||||
plot_tasks.append((plot_xiaoqu.generate_puncture_orbit_plot3D, (binary_results_directory, figure_directory)))
|
||||
|
||||
## Plot black hole separation vs. time
|
||||
plot_tasks.append((plot_xiaoqu.generate_puncture_distence_plot, (binary_results_directory, figure_directory)))
|
||||
|
||||
## Plot gravitational waveforms (psi4 and strain amplitude)
|
||||
for i in range(input_data.Detector_Number):
|
||||
plot_tasks.append((plot_xiaoqu.generate_gravitational_wave_psi4_plot, (binary_results_directory, figure_directory, i)))
|
||||
plot_tasks.append((plot_GW_strain_amplitude_xiaoqu.generate_gravitational_wave_amplitude_plot, (binary_results_directory, figure_directory, i)))
|
||||
|
||||
## Plot ADM mass evolution
|
||||
for i in range(input_data.Detector_Number):
|
||||
plot_tasks.append((plot_xiaoqu.generate_ADMmass_plot, (binary_results_directory, figure_directory, i)))
|
||||
|
||||
## Plot Hamiltonian constraint violation over time
|
||||
for i in range(input_data.grid_level):
|
||||
plot_tasks.append((plot_xiaoqu.generate_constraint_check_plot, (binary_results_directory, figure_directory, i)))
|
||||
|
||||
run_plot_tasks_parallel(plot_tasks)
|
||||
|
||||
## Plot stored binary data (runs serially, not in the parallel pool)
|
||||
plot_xiaoqu.generate_binary_data_plot(binary_results_directory, figure_directory)
|
||||
|
||||
print()
|
||||
print(" Plotting completed successfully. ")
|
||||
print()
|
||||
@@ -1,255 +0,0 @@
|
||||
#include "tool.h"
|
||||
/*
|
||||
* 你需要提供 symmetry_bd 的 C 版本(或 Fortran 绑到 C 的接口)。
|
||||
* Fortran: call symmetry_bd(3,ex,f,fh,SoA)
|
||||
*
|
||||
* 约定:
|
||||
* nghost = 3
|
||||
* ex[3] = {ex1,ex2,ex3}
|
||||
* f = 原始网格 (ex1*ex2*ex3)
|
||||
* fh = 扩展网格 ((ex1+3)*(ex2+3)*(ex3+3)),对应 Fortran 的 (-2:ex1, ...)
|
||||
* SoA[3] = 输入参数
|
||||
*/
|
||||
void lopsided(const int ex[3],
|
||||
const double *X, const double *Y, const double *Z,
|
||||
const double *f, double *f_rhs,
|
||||
const double *Sfx, const double *Sfy, const double *Sfz,
|
||||
int Symmetry, const double SoA[3])
|
||||
{
|
||||
const double ZEO = 0.0, ONE = 1.0, F3 = 3.0;
|
||||
const double TWO = 2.0, F6 = 6.0, F18 = 18.0;
|
||||
const double F12 = 12.0, F10 = 10.0, EIT = 8.0;
|
||||
|
||||
const int NO_SYMM = 0, EQ_SYMM = 1, OCTANT = 2;
|
||||
(void)OCTANT; // 这里和 Fortran 一样只是定义了不用也没关系
|
||||
|
||||
const int ex1 = ex[0], ex2 = ex[1], ex3 = ex[2];
|
||||
|
||||
// 对应 Fortran: dX = X(2)-X(1) (Fortran 1-based)
|
||||
// C: X[1]-X[0]
|
||||
const double dX = X[1] - X[0];
|
||||
const double dY = Y[1] - Y[0];
|
||||
const double dZ = Z[1] - Z[0];
|
||||
|
||||
const double d12dx = ONE / F12 / dX;
|
||||
const double d12dy = ONE / F12 / dY;
|
||||
const double d12dz = ONE / F12 / dZ;
|
||||
|
||||
// Fortran 里算了 d2dx/d2dy/d2dz 但本 subroutine 里没用到(保持一致也算出来)
|
||||
const double d2dx = ONE / TWO / dX;
|
||||
const double d2dy = ONE / TWO / dY;
|
||||
const double d2dz = ONE / TWO / dZ;
|
||||
(void)d2dx; (void)d2dy; (void)d2dz;
|
||||
|
||||
// Fortran:
|
||||
// imax = ex(1); jmax = ex(2); kmax = ex(3)
|
||||
const int imaxF = ex1;
|
||||
const int jmaxF = ex2;
|
||||
const int kmaxF = ex3;
|
||||
|
||||
// Fortran:
|
||||
// imin=jmin=kmin=1; 若满足对称条件则设为 -2
|
||||
int iminF = 1, jminF = 1, kminF = 1;
|
||||
if (Symmetry > NO_SYMM && fabs(Z[0]) < dZ) kminF = -2;
|
||||
if (Symmetry > EQ_SYMM && fabs(X[0]) < dX) iminF = -2;
|
||||
if (Symmetry > EQ_SYMM && fabs(Y[0]) < dY) jminF = -2;
|
||||
|
||||
// 分配 fh:大小 (ex1+3)*(ex2+3)*(ex3+3)
|
||||
const size_t nx = (size_t)ex1 + 3;
|
||||
const size_t ny = (size_t)ex2 + 3;
|
||||
const size_t nz = (size_t)ex3 + 3;
|
||||
const size_t fh_size = nx * ny * nz;
|
||||
|
||||
double *fh = (double*)malloc(fh_size * sizeof(double));
|
||||
if (!fh) return; // 内存不足:直接返回(你也可以改成 abort/报错)
|
||||
|
||||
// Fortran: call symmetry_bd(3,ex,f,fh,SoA)
|
||||
symmetry_bd(3, ex, f, fh, SoA);
|
||||
|
||||
/*
|
||||
* Fortran 主循环:
|
||||
* do k=1,ex(3)-1
|
||||
* do j=1,ex(2)-1
|
||||
* do i=1,ex(1)-1
|
||||
*
|
||||
* 转成 C 0-based:
|
||||
* k0 = 0..ex3-2, j0 = 0..ex2-2, i0 = 0..ex1-2
|
||||
*
|
||||
* 并且 Fortran 里的 i/j/k 在 fh 访问时,仍然是 Fortran 索引值:
|
||||
* iF=i0+1, jF=j0+1, kF=k0+1
|
||||
*/
|
||||
for (int k0 = 0; k0 <= ex3 - 2; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = 0; j0 <= ex2 - 2; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = 0; i0 <= ex1 - 2; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
// ---------------- x direction ----------------
|
||||
const double sfx = Sfx[p];
|
||||
if (sfx > ZEO) {
|
||||
// Fortran: if(i+3 <= imax)
|
||||
// iF+3 <= ex1 <=> i0+4 <= ex1 <=> i0 <= ex1-4
|
||||
if (i0 <= ex1 - 4) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF + 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF + 3, jF, kF, ex)]);
|
||||
}
|
||||
// elseif(i+2 <= imax) <=> i0 <= ex1-3
|
||||
else if (i0 <= ex1 - 3) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
( fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
- fh[idx_fh_F(iF + 2, jF, kF, ex)]);
|
||||
}
|
||||
// elseif(i+1 <= imax) <=> i0 <= ex1-2(循环里总成立)
|
||||
else if (i0 <= ex1 - 2) {
|
||||
f_rhs[p] -= sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF - 3, jF, kF, ex)]);
|
||||
}
|
||||
} else if (sfx < ZEO) {
|
||||
// Fortran: if(i-3 >= imin)
|
||||
// (iF-3) >= iminF <=> (i0-2) >= iminF
|
||||
if ((i0 - 2) >= iminF) {
|
||||
f_rhs[p] -= sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF - 3, jF, kF, ex)]);
|
||||
}
|
||||
// elseif(i-2 >= imin) <=> (i0-1) >= iminF
|
||||
else if ((i0 - 1) >= iminF) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
( fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
- fh[idx_fh_F(iF + 2, jF, kF, ex)]);
|
||||
}
|
||||
// elseif(i-1 >= imin) <=> i0 >= iminF
|
||||
else if (i0 >= iminF) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF + 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF + 3, jF, kF, ex)]);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- y direction ----------------
|
||||
const double sfy = Sfy[p];
|
||||
if (sfy > ZEO) {
|
||||
// jF+3 <= ex2 <=> j0+4 <= ex2 <=> j0 <= ex2-4
|
||||
if (j0 <= ex2 - 4) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF + 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF + 3, kF, ex)]);
|
||||
} else if (j0 <= ex2 - 3) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
( fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
- fh[idx_fh_F(iF, jF + 2, kF, ex)]);
|
||||
} else if (j0 <= ex2 - 2) {
|
||||
f_rhs[p] -= sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF - 3, kF, ex)]);
|
||||
}
|
||||
} else if (sfy < ZEO) {
|
||||
if ((j0 - 2) >= jminF) {
|
||||
f_rhs[p] -= sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF - 3, kF, ex)]);
|
||||
} else if ((j0 - 1) >= jminF) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
( fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
- fh[idx_fh_F(iF, jF + 2, kF, ex)]);
|
||||
} else if (j0 >= jminF) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF + 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF + 3, kF, ex)]);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- z direction ----------------
|
||||
const double sfz = Sfz[p];
|
||||
if (sfz > ZEO) {
|
||||
if (k0 <= ex3 - 4) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF + 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF + 3, ex)]);
|
||||
} else if (k0 <= ex3 - 3) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
( fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
- fh[idx_fh_F(iF, jF, kF + 2, ex)]);
|
||||
} else if (k0 <= ex3 - 2) {
|
||||
f_rhs[p] -= sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF - 3, ex)]);
|
||||
}
|
||||
} else if (sfz < ZEO) {
|
||||
if ((k0 - 2) >= kminF) {
|
||||
f_rhs[p] -= sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF - 3, ex)]);
|
||||
} else if ((k0 - 1) >= kminF) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
( fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
- fh[idx_fh_F(iF, jF, kF + 2, ex)]);
|
||||
} else if (k0 >= kminF) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF + 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF + 3, ex)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(fh);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
#include "tool.h"
|
||||
|
||||
/*
|
||||
* Combined advection (lopsided) + KO dissipation (kodis).
|
||||
* Uses one shared symmetry_bd buffer per call.
|
||||
*/
|
||||
void lopsided_kodis(const int ex[3],
|
||||
const double *X, const double *Y, const double *Z,
|
||||
const double *f, double *f_rhs,
|
||||
const double *Sfx, const double *Sfy, const double *Sfz,
|
||||
int Symmetry, const double SoA[3], double eps)
|
||||
{
|
||||
const double ZEO = 0.0, ONE = 1.0, F3 = 3.0;
|
||||
const double F6 = 6.0, F18 = 18.0;
|
||||
const double F12 = 12.0, F10 = 10.0, EIT = 8.0;
|
||||
const double SIX = 6.0, FIT = 15.0, TWT = 20.0;
|
||||
const double cof = 64.0; // 2^6
|
||||
|
||||
const int NO_SYMM = 0, EQ_SYMM = 1;
|
||||
|
||||
const int ex1 = ex[0], ex2 = ex[1], ex3 = ex[2];
|
||||
|
||||
const double dX = X[1] - X[0];
|
||||
const double dY = Y[1] - Y[0];
|
||||
const double dZ = Z[1] - Z[0];
|
||||
|
||||
const double d12dx = ONE / F12 / dX;
|
||||
const double d12dy = ONE / F12 / dY;
|
||||
const double d12dz = ONE / F12 / dZ;
|
||||
|
||||
const int imaxF = ex1;
|
||||
const int jmaxF = ex2;
|
||||
const int kmaxF = ex3;
|
||||
|
||||
int iminF = 1, jminF = 1, kminF = 1;
|
||||
if (Symmetry > NO_SYMM && fabs(Z[0]) < dZ) kminF = -2;
|
||||
if (Symmetry > EQ_SYMM && fabs(X[0]) < dX) iminF = -2;
|
||||
if (Symmetry > EQ_SYMM && fabs(Y[0]) < dY) jminF = -2;
|
||||
|
||||
// fh for Fortran-style domain (-2:ex1,-2:ex2,-2:ex3)
|
||||
const size_t nx = (size_t)ex1 + 3;
|
||||
const size_t ny = (size_t)ex2 + 3;
|
||||
const size_t nz = (size_t)ex3 + 3;
|
||||
const size_t fh_size = nx * ny * nz;
|
||||
|
||||
double *fh = (double*)malloc(fh_size * sizeof(double));
|
||||
if (!fh) return;
|
||||
|
||||
symmetry_bd(3, ex, f, fh, SoA);
|
||||
|
||||
// Advection (same stencil logic as lopsided_c.C)
|
||||
for (int k0 = 0; k0 <= ex3 - 2; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = 0; j0 <= ex2 - 2; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = 0; i0 <= ex1 - 2; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
const double sfx = Sfx[p];
|
||||
if (sfx > ZEO) {
|
||||
if (i0 <= ex1 - 4) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF + 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF + 3, jF, kF, ex)]);
|
||||
} else if (i0 <= ex1 - 3) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
( fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
- fh[idx_fh_F(iF + 2, jF, kF, ex)]);
|
||||
} else if (i0 <= ex1 - 2) {
|
||||
f_rhs[p] -= sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF - 3, jF, kF, ex)]);
|
||||
}
|
||||
} else if (sfx < ZEO) {
|
||||
if ((i0 - 2) >= iminF) {
|
||||
f_rhs[p] -= sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF - 3, jF, kF, ex)]);
|
||||
} else if ((i0 - 1) >= iminF) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
( fh[idx_fh_F(iF - 2, jF, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
- fh[idx_fh_F(iF + 2, jF, kF, ex)]);
|
||||
} else if (i0 >= iminF) {
|
||||
f_rhs[p] += sfx * d12dx *
|
||||
(-F3 * fh[idx_fh_F(iF - 1, jF, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF , jF, kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF + 1, jF, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF + 2, jF, kF, ex)]
|
||||
+ fh[idx_fh_F(iF + 3, jF, kF, ex)]);
|
||||
}
|
||||
}
|
||||
|
||||
const double sfy = Sfy[p];
|
||||
if (sfy > ZEO) {
|
||||
if (j0 <= ex2 - 4) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF + 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF + 3, kF, ex)]);
|
||||
} else if (j0 <= ex2 - 3) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
( fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
- fh[idx_fh_F(iF, jF + 2, kF, ex)]);
|
||||
} else if (j0 <= ex2 - 2) {
|
||||
f_rhs[p] -= sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF - 3, kF, ex)]);
|
||||
}
|
||||
} else if (sfy < ZEO) {
|
||||
if ((j0 - 2) >= jminF) {
|
||||
f_rhs[p] -= sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF - 3, kF, ex)]);
|
||||
} else if ((j0 - 1) >= jminF) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
( fh[idx_fh_F(iF, jF - 2, kF, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
- fh[idx_fh_F(iF, jF + 2, kF, ex)]);
|
||||
} else if (j0 >= jminF) {
|
||||
f_rhs[p] += sfy * d12dy *
|
||||
(-F3 * fh[idx_fh_F(iF, jF - 1, kF, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF , kF, ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF + 1, kF, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF + 2, kF, ex)]
|
||||
+ fh[idx_fh_F(iF, jF + 3, kF, ex)]);
|
||||
}
|
||||
}
|
||||
|
||||
const double sfz = Sfz[p];
|
||||
if (sfz > ZEO) {
|
||||
if (k0 <= ex3 - 4) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF + 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF + 3, ex)]);
|
||||
} else if (k0 <= ex3 - 3) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
( fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
- fh[idx_fh_F(iF, jF, kF + 2, ex)]);
|
||||
} else if (k0 <= ex3 - 2) {
|
||||
f_rhs[p] -= sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF - 3, ex)]);
|
||||
}
|
||||
} else if (sfz < ZEO) {
|
||||
if ((k0 - 2) >= kminF) {
|
||||
f_rhs[p] -= sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF - 3, ex)]);
|
||||
} else if ((k0 - 1) >= kminF) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
( fh[idx_fh_F(iF, jF, kF - 2, ex)]
|
||||
-EIT * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
+EIT * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
- fh[idx_fh_F(iF, jF, kF + 2, ex)]);
|
||||
} else if (k0 >= kminF) {
|
||||
f_rhs[p] += sfz * d12dz *
|
||||
(-F3 * fh[idx_fh_F(iF, jF, kF - 1, ex)]
|
||||
-F10 * fh[idx_fh_F(iF, jF, kF , ex)]
|
||||
+F18 * fh[idx_fh_F(iF, jF, kF + 1, ex)]
|
||||
-F6 * fh[idx_fh_F(iF, jF, kF + 2, ex)]
|
||||
+ fh[idx_fh_F(iF, jF, kF + 3, ex)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KO dissipation (same domain restriction as kodiss_c.C)
|
||||
if (eps > ZEO) {
|
||||
const int i0_lo = (iminF + 2 > 0) ? iminF + 2 : 0;
|
||||
const int j0_lo = (jminF + 2 > 0) ? jminF + 2 : 0;
|
||||
const int k0_lo = (kminF + 2 > 0) ? kminF + 2 : 0;
|
||||
const int i0_hi = imaxF - 4; // inclusive
|
||||
const int j0_hi = jmaxF - 4;
|
||||
const int k0_hi = kmaxF - 4;
|
||||
|
||||
if (!(i0_lo > i0_hi || j0_lo > j0_hi || k0_lo > k0_hi)) {
|
||||
for (int k0 = k0_lo; k0 <= k0_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j0_lo; j0 <= j0_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i0_lo; i0 <= i0_hi; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
const double Dx_term =
|
||||
((fh[idx_fh_F(iF - 3, jF, kF, ex)] + fh[idx_fh_F(iF + 3, jF, kF, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF - 2, jF, kF, ex)] + fh[idx_fh_F(iF + 2, jF, kF, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF - 1, jF, kF, ex)] + fh[idx_fh_F(iF + 1, jF, kF, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF, jF, kF, ex)]) / dX;
|
||||
|
||||
const double Dy_term =
|
||||
((fh[idx_fh_F(iF, jF - 3, kF, ex)] + fh[idx_fh_F(iF, jF + 3, kF, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF, jF - 2, kF, ex)] + fh[idx_fh_F(iF, jF + 2, kF, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF, jF - 1, kF, ex)] + fh[idx_fh_F(iF, jF + 1, kF, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF, jF, kF, ex)]) / dY;
|
||||
|
||||
const double Dz_term =
|
||||
((fh[idx_fh_F(iF, jF, kF - 3, ex)] + fh[idx_fh_F(iF, jF, kF + 3, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF, jF, kF - 2, ex)] + fh[idx_fh_F(iF, jF, kF + 2, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF, jF, kF - 1, ex)] + fh[idx_fh_F(iF, jF, kF + 1, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF, jF, kF, ex)]) / dZ;
|
||||
|
||||
f_rhs[p] += (eps / cof) * (Dx_term + Dy_term + Dz_term);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(fh);
|
||||
}
|
||||
@@ -1,332 +0,0 @@
|
||||
#include "tool.h"
|
||||
void fdderivs(const int ex[3],
|
||||
const double *f,
|
||||
double *fxx, double *fxy, double *fxz,
|
||||
double *fyy, double *fyz, double *fzz,
|
||||
const double *X, const double *Y, const double *Z,
|
||||
double SYM1, double SYM2, double SYM3,
|
||||
int Symmetry, int onoff)
|
||||
{
|
||||
(void)onoff;
|
||||
|
||||
const int NO_SYMM = 0, EQ_SYMM = 1;
|
||||
const double ZEO = 0.0, ONE = 1.0, TWO = 2.0;
|
||||
const double F1o4 = 2.5e-1; // 1/4
|
||||
const double F8 = 8.0;
|
||||
const double F16 = 16.0;
|
||||
const double F30 = 30.0;
|
||||
const double F1o12 = ONE / 12.0;
|
||||
const double F1o144 = ONE / 144.0;
|
||||
|
||||
const int ex1 = ex[0], ex2 = ex[1], ex3 = ex[2];
|
||||
|
||||
const double dX = X[1] - X[0];
|
||||
const double dY = Y[1] - Y[0];
|
||||
const double dZ = Z[1] - Z[0];
|
||||
|
||||
const int imaxF = ex1;
|
||||
const int jmaxF = ex2;
|
||||
const int kmaxF = ex3;
|
||||
|
||||
int iminF = 1, jminF = 1, kminF = 1;
|
||||
if (Symmetry > NO_SYMM && fabs(Z[0]) < dZ) kminF = -1;
|
||||
if (Symmetry > EQ_SYMM && fabs(X[0]) < dX) iminF = -1;
|
||||
if (Symmetry > EQ_SYMM && fabs(Y[0]) < dY) jminF = -1;
|
||||
|
||||
const double SoA[3] = { SYM1, SYM2, SYM3 };
|
||||
|
||||
/* fh: (ex1+2)*(ex2+2)*(ex3+2) because ord=2 */
|
||||
const size_t nx = (size_t)ex1 + 2;
|
||||
const size_t ny = (size_t)ex2 + 2;
|
||||
const size_t nz = (size_t)ex3 + 2;
|
||||
const size_t fh_size = nx * ny * nz;
|
||||
|
||||
static double *fh = NULL;
|
||||
static size_t cap = 0;
|
||||
|
||||
if (fh_size > cap) {
|
||||
free(fh);
|
||||
fh = (double*)aligned_alloc(64, fh_size * sizeof(double));
|
||||
cap = fh_size;
|
||||
}
|
||||
// double *fh = (double*)malloc(fh_size * sizeof(double));
|
||||
if (!fh) return;
|
||||
|
||||
symmetry_bd(2, ex, f, fh, SoA);
|
||||
|
||||
/* 系数:按 Fortran 原式 */
|
||||
const double Sdxdx = ONE / (dX * dX);
|
||||
const double Sdydy = ONE / (dY * dY);
|
||||
const double Sdzdz = ONE / (dZ * dZ);
|
||||
|
||||
const double Fdxdx = F1o12 / (dX * dX);
|
||||
const double Fdydy = F1o12 / (dY * dY);
|
||||
const double Fdzdz = F1o12 / (dZ * dZ);
|
||||
|
||||
const double Sdxdy = F1o4 / (dX * dY);
|
||||
const double Sdxdz = F1o4 / (dX * dZ);
|
||||
const double Sdydz = F1o4 / (dY * dZ);
|
||||
|
||||
const double Fdxdy = F1o144 / (dX * dY);
|
||||
const double Fdxdz = F1o144 / (dX * dZ);
|
||||
const double Fdydz = F1o144 / (dY * dZ);
|
||||
|
||||
/* 只清零不被主循环覆盖的边界面 */
|
||||
{
|
||||
/* 高边界:k0=ex3-1 */
|
||||
for (int j0 = 0; j0 < ex2; ++j0)
|
||||
for (int i0 = 0; i0 < ex1; ++i0) {
|
||||
const size_t p = idx_ex(i0, j0, ex3 - 1, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
/* 高边界:j0=ex2-1 */
|
||||
for (int k0 = 0; k0 < ex3 - 1; ++k0)
|
||||
for (int i0 = 0; i0 < ex1; ++i0) {
|
||||
const size_t p = idx_ex(i0, ex2 - 1, k0, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
/* 高边界:i0=ex1-1 */
|
||||
for (int k0 = 0; k0 < ex3 - 1; ++k0)
|
||||
for (int j0 = 0; j0 < ex2 - 1; ++j0) {
|
||||
const size_t p = idx_ex(ex1 - 1, j0, k0, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
|
||||
/* 低边界:当二阶模板也不可用时,对应 i0/j0/k0=0 面 */
|
||||
if (kminF == 1) {
|
||||
for (int j0 = 0; j0 < ex2; ++j0)
|
||||
for (int i0 = 0; i0 < ex1; ++i0) {
|
||||
const size_t p = idx_ex(i0, j0, 0, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
}
|
||||
if (jminF == 1) {
|
||||
for (int k0 = 0; k0 < ex3; ++k0)
|
||||
for (int i0 = 0; i0 < ex1; ++i0) {
|
||||
const size_t p = idx_ex(i0, 0, k0, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
}
|
||||
if (iminF == 1) {
|
||||
for (int k0 = 0; k0 < ex3; ++k0)
|
||||
for (int j0 = 0; j0 < ex2; ++j0) {
|
||||
const size_t p = idx_ex(0, j0, k0, ex);
|
||||
fxx[p]=ZEO; fyy[p]=ZEO; fzz[p]=ZEO;
|
||||
fxy[p]=ZEO; fxz[p]=ZEO; fyz[p]=ZEO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 两段式:
|
||||
* 1) 二阶可用区域先计算二阶模板
|
||||
* 2) 高阶可用区域再覆盖四阶模板
|
||||
*/
|
||||
const int i2_lo = (iminF > 0) ? iminF : 0;
|
||||
const int j2_lo = (jminF > 0) ? jminF : 0;
|
||||
const int k2_lo = (kminF > 0) ? kminF : 0;
|
||||
const int i2_hi = ex1 - 2;
|
||||
const int j2_hi = ex2 - 2;
|
||||
const int k2_hi = ex3 - 2;
|
||||
|
||||
const int i4_lo = (iminF + 1 > 0) ? (iminF + 1) : 0;
|
||||
const int j4_lo = (jminF + 1 > 0) ? (jminF + 1) : 0;
|
||||
const int k4_lo = (kminF + 1 > 0) ? (kminF + 1) : 0;
|
||||
const int i4_hi = ex1 - 3;
|
||||
const int j4_hi = ex2 - 3;
|
||||
const int k4_hi = ex3 - 3;
|
||||
|
||||
/*
|
||||
* Strategy A:
|
||||
* Avoid redundant work in overlap of 2nd/4th-order regions.
|
||||
* Only compute 2nd-order on shell points that are NOT overwritten by
|
||||
* the 4th-order pass.
|
||||
*/
|
||||
const int has4 = (i4_lo <= i4_hi && j4_lo <= j4_hi && k4_lo <= k4_hi);
|
||||
|
||||
if (i2_lo <= i2_hi && j2_lo <= j2_hi && k2_lo <= k2_hi) {
|
||||
for (int k0 = k2_lo; k0 <= k2_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j2_lo; j0 <= j2_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i2_lo; i0 <= i2_hi; ++i0) {
|
||||
if (has4 &&
|
||||
i0 >= i4_lo && i0 <= i4_hi &&
|
||||
j0 >= j4_lo && j0 <= j4_hi &&
|
||||
k0 >= k4_lo && k0 <= k4_hi) {
|
||||
continue;
|
||||
}
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
fxx[p] = Sdxdx * (
|
||||
fh[idx_fh_F_ord2(iF - 1, jF, kF, ex)] -
|
||||
TWO * fh[idx_fh_F_ord2(iF, jF, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF + 1, jF, kF, ex)]
|
||||
);
|
||||
|
||||
fyy[p] = Sdydy * (
|
||||
fh[idx_fh_F_ord2(iF, jF - 1, kF, ex)] -
|
||||
TWO * fh[idx_fh_F_ord2(iF, jF, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF, jF + 1, kF, ex)]
|
||||
);
|
||||
|
||||
fzz[p] = Sdzdz * (
|
||||
fh[idx_fh_F_ord2(iF, jF, kF - 1, ex)] -
|
||||
TWO * fh[idx_fh_F_ord2(iF, jF, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF, jF, kF + 1, ex)]
|
||||
);
|
||||
|
||||
fxy[p] = Sdxdy * (
|
||||
fh[idx_fh_F_ord2(iF - 1, jF - 1, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF + 1, jF - 1, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF - 1, jF + 1, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF + 1, jF + 1, kF, ex)]
|
||||
);
|
||||
|
||||
fxz[p] = Sdxdz * (
|
||||
fh[idx_fh_F_ord2(iF - 1, jF, kF - 1, ex)] -
|
||||
fh[idx_fh_F_ord2(iF + 1, jF, kF - 1, ex)] -
|
||||
fh[idx_fh_F_ord2(iF - 1, jF, kF + 1, ex)] +
|
||||
fh[idx_fh_F_ord2(iF + 1, jF, kF + 1, ex)]
|
||||
);
|
||||
|
||||
fyz[p] = Sdydz * (
|
||||
fh[idx_fh_F_ord2(iF, jF - 1, kF - 1, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF + 1, kF - 1, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF - 1, kF + 1, ex)] +
|
||||
fh[idx_fh_F_ord2(iF, jF + 1, kF + 1, ex)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (has4) {
|
||||
for (int k0 = k4_lo; k0 <= k4_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j4_lo; j0 <= j4_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i4_lo; i0 <= i4_hi; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
fxx[p] = Fdxdx * (
|
||||
-fh[idx_fh_F_ord2(iF - 2, jF, kF, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF - 1, jF, kF, ex)] -
|
||||
F30 * fh[idx_fh_F_ord2(iF, jF, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF + 2, jF, kF, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF + 1, jF, kF, ex)]
|
||||
);
|
||||
|
||||
fyy[p] = Fdydy * (
|
||||
-fh[idx_fh_F_ord2(iF, jF - 2, kF, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF, jF - 1, kF, ex)] -
|
||||
F30 * fh[idx_fh_F_ord2(iF, jF, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF + 2, kF, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF, jF + 1, kF, ex)]
|
||||
);
|
||||
|
||||
fzz[p] = Fdzdz * (
|
||||
-fh[idx_fh_F_ord2(iF, jF, kF - 2, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF, jF, kF - 1, ex)] -
|
||||
F30 * fh[idx_fh_F_ord2(iF, jF, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF, kF + 2, ex)] +
|
||||
F16 * fh[idx_fh_F_ord2(iF, jF, kF + 1, ex)]
|
||||
);
|
||||
|
||||
{
|
||||
const double t_jm2 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF - 2, kF, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF - 2, kF, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF - 2, kF, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF - 2, kF, ex)] );
|
||||
|
||||
const double t_jm1 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF - 1, kF, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF - 1, kF, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF - 1, kF, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF - 1, kF, ex)] );
|
||||
|
||||
const double t_jp1 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF + 1, kF, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF + 1, kF, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF + 1, kF, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF + 1, kF, ex)] );
|
||||
|
||||
const double t_jp2 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF + 2, kF, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF + 2, kF, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF + 2, kF, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF + 2, kF, ex)] );
|
||||
|
||||
fxy[p] = Fdxdy * ( t_jm2 - F8 * t_jm1 + F8 * t_jp1 - t_jp2 );
|
||||
}
|
||||
|
||||
{
|
||||
const double t_km2 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF, kF - 2, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF, kF - 2, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF, kF - 2, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF, kF - 2, ex)] );
|
||||
|
||||
const double t_km1 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF, kF - 1, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF, kF - 1, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF, kF - 1, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF, kF - 1, ex)] );
|
||||
|
||||
const double t_kp1 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF, kF + 1, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF, kF + 1, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF, kF + 1, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF, kF + 1, ex)] );
|
||||
|
||||
const double t_kp2 =
|
||||
( fh[idx_fh_F_ord2(iF - 2, jF, kF + 2, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF - 1, jF, kF + 2, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF + 1, jF, kF + 2, ex)]
|
||||
- fh[idx_fh_F_ord2(iF + 2, jF, kF + 2, ex)] );
|
||||
|
||||
fxz[p] = Fdxdz * ( t_km2 - F8 * t_km1 + F8 * t_kp1 - t_kp2 );
|
||||
}
|
||||
|
||||
{
|
||||
const double t_km2 =
|
||||
( fh[idx_fh_F_ord2(iF, jF - 2, kF - 2, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF, jF - 1, kF - 2, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF, jF + 1, kF - 2, ex)]
|
||||
- fh[idx_fh_F_ord2(iF, jF + 2, kF - 2, ex)] );
|
||||
|
||||
const double t_km1 =
|
||||
( fh[idx_fh_F_ord2(iF, jF - 2, kF - 1, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF, jF - 1, kF - 1, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF, jF + 1, kF - 1, ex)]
|
||||
- fh[idx_fh_F_ord2(iF, jF + 2, kF - 1, ex)] );
|
||||
|
||||
const double t_kp1 =
|
||||
( fh[idx_fh_F_ord2(iF, jF - 2, kF + 1, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF, jF - 1, kF + 1, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF, jF + 1, kF + 1, ex)]
|
||||
- fh[idx_fh_F_ord2(iF, jF + 2, kF + 1, ex)] );
|
||||
|
||||
const double t_kp2 =
|
||||
( fh[idx_fh_F_ord2(iF, jF - 2, kF + 2, ex)]
|
||||
-F8*fh[idx_fh_F_ord2(iF, jF - 1, kF + 2, ex)]
|
||||
+F8*fh[idx_fh_F_ord2(iF, jF + 1, kF + 2, ex)]
|
||||
- fh[idx_fh_F_ord2(iF, jF + 2, kF + 2, ex)] );
|
||||
|
||||
fyz[p] = Fdydz * ( t_km2 - F8 * t_km1 + F8 * t_kp1 - t_kp2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free(fh);
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
#include "tool.h"
|
||||
|
||||
/*
|
||||
* C 版 fderivs
|
||||
*
|
||||
* Fortran:
|
||||
* subroutine fderivs(ex,f,fx,fy,fz,X,Y,Z,SYM1,SYM2,SYM3,symmetry,onoff)
|
||||
*
|
||||
* 约定:
|
||||
* f, fx, fy, fz: ex1*ex2*ex3,按 idx_ex 布局
|
||||
* X: ex1, Y: ex2, Z: ex3
|
||||
*/
|
||||
void fderivs(const int ex[3],
|
||||
const double *f,
|
||||
double *fx, double *fy, double *fz,
|
||||
const double *X, const double *Y, const double *Z,
|
||||
double SYM1, double SYM2, double SYM3,
|
||||
int Symmetry, int onoff)
|
||||
{
|
||||
(void)onoff; // Fortran 里没用到
|
||||
|
||||
const double ZEO = 0.0, ONE = 1.0;
|
||||
const double TWO = 2.0, EIT = 8.0;
|
||||
const double F12 = 12.0;
|
||||
|
||||
const int NO_SYMM = 0, EQ_SYMM = 1; // OCTANT=2 在本子程序里不直接用
|
||||
|
||||
const int ex1 = ex[0], ex2 = ex[1], ex3 = ex[2];
|
||||
|
||||
// dX = X(2)-X(1) -> C: X[1]-X[0]
|
||||
const double dX = X[1] - X[0];
|
||||
const double dY = Y[1] - Y[0];
|
||||
const double dZ = Z[1] - Z[0];
|
||||
|
||||
// Fortran 1-based bounds
|
||||
const int imaxF = ex1;
|
||||
const int jmaxF = ex2;
|
||||
const int kmaxF = ex3;
|
||||
|
||||
int iminF = 1, jminF = 1, kminF = 1;
|
||||
if (Symmetry > NO_SYMM && fabs(Z[0]) < dZ) kminF = -1;
|
||||
if (Symmetry > EQ_SYMM && fabs(X[0]) < dX) iminF = -1;
|
||||
if (Symmetry > EQ_SYMM && fabs(Y[0]) < dY) jminF = -1;
|
||||
|
||||
// SoA(1:3) = SYM1,SYM2,SYM3
|
||||
const double SoA[3] = { SYM1, SYM2, SYM3 };
|
||||
|
||||
// fh: (ex1+2)*(ex2+2)*(ex3+2) because ord=2
|
||||
const size_t nx = (size_t)ex1 + 2;
|
||||
const size_t ny = (size_t)ex2 + 2;
|
||||
const size_t nz = (size_t)ex3 + 2;
|
||||
const size_t fh_size = nx * ny * nz;
|
||||
static double *fh = NULL;
|
||||
static size_t cap = 0;
|
||||
|
||||
if (fh_size > cap) {
|
||||
free(fh);
|
||||
fh = (double*)aligned_alloc(64, fh_size * sizeof(double));
|
||||
cap = fh_size;
|
||||
}
|
||||
// double *fh = (double*)malloc(fh_size * sizeof(double));
|
||||
if (!fh) return;
|
||||
|
||||
// call symmetry_bd(2,ex,f,fh,SoA)
|
||||
symmetry_bd(2, ex, f, fh, SoA);
|
||||
|
||||
const double d12dx = ONE / F12 / dX;
|
||||
const double d12dy = ONE / F12 / dY;
|
||||
const double d12dz = ONE / F12 / dZ;
|
||||
|
||||
const double d2dx = ONE / TWO / dX;
|
||||
const double d2dy = ONE / TWO / dY;
|
||||
const double d2dz = ONE / TWO / dZ;
|
||||
|
||||
// fx = fy = fz = 0
|
||||
const size_t all = (size_t)ex1 * (size_t)ex2 * (size_t)ex3;
|
||||
for (size_t p = 0; p < all; ++p) {
|
||||
fx[p] = ZEO;
|
||||
fy[p] = ZEO;
|
||||
fz[p] = ZEO;
|
||||
}
|
||||
|
||||
/*
|
||||
* 两段式:
|
||||
* 1) 先在二阶可用区域计算二阶模板
|
||||
* 2) 再在高阶可用区域覆盖为四阶模板
|
||||
*
|
||||
* 与原 if/elseif 逻辑等价,但减少逐点分支判断。
|
||||
*/
|
||||
const int i2_lo = (iminF > 0) ? iminF : 0;
|
||||
const int j2_lo = (jminF > 0) ? jminF : 0;
|
||||
const int k2_lo = (kminF > 0) ? kminF : 0;
|
||||
const int i2_hi = ex1 - 2;
|
||||
const int j2_hi = ex2 - 2;
|
||||
const int k2_hi = ex3 - 2;
|
||||
|
||||
const int i4_lo = (iminF + 1 > 0) ? (iminF + 1) : 0;
|
||||
const int j4_lo = (jminF + 1 > 0) ? (jminF + 1) : 0;
|
||||
const int k4_lo = (kminF + 1 > 0) ? (kminF + 1) : 0;
|
||||
const int i4_hi = ex1 - 3;
|
||||
const int j4_hi = ex2 - 3;
|
||||
const int k4_hi = ex3 - 3;
|
||||
|
||||
if (i2_lo <= i2_hi && j2_lo <= j2_hi && k2_lo <= k2_hi) {
|
||||
for (int k0 = k2_lo; k0 <= k2_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j2_lo; j0 <= j2_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i2_lo; i0 <= i2_hi; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
fx[p] = d2dx * (
|
||||
-fh[idx_fh_F_ord2(iF - 1, jF, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF + 1, jF, kF, ex)]
|
||||
);
|
||||
|
||||
fy[p] = d2dy * (
|
||||
-fh[idx_fh_F_ord2(iF, jF - 1, kF, ex)] +
|
||||
fh[idx_fh_F_ord2(iF, jF + 1, kF, ex)]
|
||||
);
|
||||
|
||||
fz[p] = d2dz * (
|
||||
-fh[idx_fh_F_ord2(iF, jF, kF - 1, ex)] +
|
||||
fh[idx_fh_F_ord2(iF, jF, kF + 1, ex)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i4_lo <= i4_hi && j4_lo <= j4_hi && k4_lo <= k4_hi) {
|
||||
for (int k0 = k4_lo; k0 <= k4_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j4_lo; j0 <= j4_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i4_lo; i0 <= i4_hi; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
fx[p] = d12dx * (
|
||||
fh[idx_fh_F_ord2(iF - 2, jF, kF, ex)] -
|
||||
EIT * fh[idx_fh_F_ord2(iF - 1, jF, kF, ex)] +
|
||||
EIT * fh[idx_fh_F_ord2(iF + 1, jF, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF + 2, jF, kF, ex)]
|
||||
);
|
||||
|
||||
fy[p] = d12dy * (
|
||||
fh[idx_fh_F_ord2(iF, jF - 2, kF, ex)] -
|
||||
EIT * fh[idx_fh_F_ord2(iF, jF - 1, kF, ex)] +
|
||||
EIT * fh[idx_fh_F_ord2(iF, jF + 1, kF, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF + 2, kF, ex)]
|
||||
);
|
||||
|
||||
fz[p] = d12dz * (
|
||||
fh[idx_fh_F_ord2(iF, jF, kF - 2, ex)] -
|
||||
EIT * fh[idx_fh_F_ord2(iF, jF, kF - 1, ex)] +
|
||||
EIT * fh[idx_fh_F_ord2(iF, jF, kF + 1, ex)] -
|
||||
fh[idx_fh_F_ord2(iF, jF, kF + 2, ex)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free(fh);
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
#include "tool.h"
|
||||
|
||||
/*
|
||||
* C 版 kodis
|
||||
*
|
||||
* Fortran signature:
|
||||
* subroutine kodis(ex,X,Y,Z,f,f_rhs,SoA,Symmetry,eps)
|
||||
*
|
||||
* 约定:
|
||||
* X: ex1, Y: ex2, Z: ex3
|
||||
* f, f_rhs: ex1*ex2*ex3 按 idx_ex 布局
|
||||
* SoA[3]
|
||||
* eps: double
|
||||
*/
|
||||
void kodis(const int ex[3],
|
||||
const double *X, const double *Y, const double *Z,
|
||||
const double *f, double *f_rhs,
|
||||
const double SoA[3],
|
||||
int Symmetry, double eps)
|
||||
{
|
||||
const double ONE = 1.0, SIX = 6.0, FIT = 15.0, TWT = 20.0;
|
||||
const double cof = 64.0; // 2^6
|
||||
const int NO_SYMM = 0, OCTANT = 2;
|
||||
|
||||
const int ex1 = ex[0], ex2 = ex[1], ex3 = ex[2];
|
||||
|
||||
// Fortran: dX = X(2)-X(1) -> C: X[1]-X[0]
|
||||
const double dX = X[1] - X[0];
|
||||
const double dY = Y[1] - Y[0];
|
||||
const double dZ = Z[1] - Z[0];
|
||||
(void)ONE; // ONE 在原 Fortran 里只是参数,这里不一定用得上
|
||||
|
||||
// Fortran: imax=ex(1) 等是 1-based 上界
|
||||
const int imaxF = ex1;
|
||||
const int jmaxF = ex2;
|
||||
const int kmaxF = ex3;
|
||||
|
||||
// Fortran: imin=jmin=kmin=1,某些对称情况变 -2
|
||||
int iminF = 1, jminF = 1, kminF = 1;
|
||||
|
||||
if (Symmetry > NO_SYMM && fabs(Z[0]) < dZ) kminF = -2;
|
||||
if (Symmetry == OCTANT && fabs(X[0]) < dX) iminF = -2;
|
||||
if (Symmetry == OCTANT && fabs(Y[0]) < dY) jminF = -2;
|
||||
|
||||
// 分配 fh:大小 (ex1+3)*(ex2+3)*(ex3+3),对应 ord=3
|
||||
const size_t nx = (size_t)ex1 + 3;
|
||||
const size_t ny = (size_t)ex2 + 3;
|
||||
const size_t nz = (size_t)ex3 + 3;
|
||||
const size_t fh_size = nx * ny * nz;
|
||||
|
||||
double *fh = (double*)malloc(fh_size * sizeof(double));
|
||||
if (!fh) return;
|
||||
|
||||
// Fortran: call symmetry_bd(3,ex,f,fh,SoA)
|
||||
symmetry_bd(3, ex, f, fh, SoA);
|
||||
|
||||
/*
|
||||
* Fortran loops:
|
||||
* do k=1,ex3
|
||||
* do j=1,ex2
|
||||
* do i=1,ex1
|
||||
*
|
||||
* C: k0=0..ex3-1, j0=0..ex2-1, i0=0..ex1-1
|
||||
* 并定义 Fortran index: iF=i0+1, ...
|
||||
*/
|
||||
// 收紧循环范围:只遍历满足 iF±3/jF±3/kF±3 条件的内部点
|
||||
// iF-3 >= iminF => iF >= iminF+3 => i0 >= iminF+2 (因为 iF=i0+1)
|
||||
// iF+3 <= imaxF => iF <= imaxF-3 => i0 <= imaxF-4
|
||||
const int i0_lo = (iminF + 2 > 0) ? iminF + 2 : 0;
|
||||
const int j0_lo = (jminF + 2 > 0) ? jminF + 2 : 0;
|
||||
const int k0_lo = (kminF + 2 > 0) ? kminF + 2 : 0;
|
||||
const int i0_hi = imaxF - 4; // inclusive
|
||||
const int j0_hi = jmaxF - 4;
|
||||
const int k0_hi = kmaxF - 4;
|
||||
|
||||
if (i0_lo > i0_hi || j0_lo > j0_hi || k0_lo > k0_hi) {
|
||||
free(fh);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int k0 = k0_lo; k0 <= k0_hi; ++k0) {
|
||||
const int kF = k0 + 1;
|
||||
for (int j0 = j0_lo; j0 <= j0_hi; ++j0) {
|
||||
const int jF = j0 + 1;
|
||||
for (int i0 = i0_lo; i0 <= i0_hi; ++i0) {
|
||||
const int iF = i0 + 1;
|
||||
|
||||
const size_t p = idx_ex(i0, j0, k0, ex);
|
||||
|
||||
// 三个方向各一份同型的 7 点组合(实际上是对称的 6th-order dissipation/filter 核)
|
||||
const double Dx_term =
|
||||
( (fh[idx_fh_F(iF - 3, jF, kF, ex)] + fh[idx_fh_F(iF + 3, jF, kF, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF - 2, jF, kF, ex)] + fh[idx_fh_F(iF + 2, jF, kF, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF - 1, jF, kF, ex)] + fh[idx_fh_F(iF + 1, jF, kF, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF , jF, kF, ex)] ) / dX;
|
||||
|
||||
const double Dy_term =
|
||||
( (fh[idx_fh_F(iF, jF - 3, kF, ex)] + fh[idx_fh_F(iF, jF + 3, kF, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF, jF - 2, kF, ex)] + fh[idx_fh_F(iF, jF + 2, kF, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF, jF - 1, kF, ex)] + fh[idx_fh_F(iF, jF + 1, kF, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF, jF , kF, ex)] ) / dY;
|
||||
|
||||
const double Dz_term =
|
||||
( (fh[idx_fh_F(iF, jF, kF - 3, ex)] + fh[idx_fh_F(iF, jF, kF + 3, ex)]) -
|
||||
SIX * (fh[idx_fh_F(iF, jF, kF - 2, ex)] + fh[idx_fh_F(iF, jF, kF + 2, ex)]) +
|
||||
FIT * (fh[idx_fh_F(iF, jF, kF - 1, ex)] + fh[idx_fh_F(iF, jF, kF + 1, ex)]) -
|
||||
TWT * fh[idx_fh_F(iF, jF, kF , ex)] ) / dZ;
|
||||
|
||||
// Fortran:
|
||||
// f_rhs(i,j,k) = f_rhs(i,j,k) + eps/cof*(Dx_term + Dy_term + Dz_term)
|
||||
f_rhs[p] += (eps / cof) * (Dx_term + Dy_term + Dz_term);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(fh);
|
||||
}
|
||||
@@ -5,6 +5,42 @@
|
||||
#include "misc.h"
|
||||
#include "parameters.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
enum { MAX_DATA_PACKER_VARS = 64 };
|
||||
|
||||
int expand_var_list_pack_info(MyList<var> *src_list, MyList<var> *dst_list,
|
||||
int *src_sgfn, int *dst_sgfn, double **src_soa)
|
||||
{
|
||||
int count = 0;
|
||||
MyList<var> *src_it = src_list;
|
||||
MyList<var> *dst_it = dst_list;
|
||||
|
||||
while (src_it && dst_it)
|
||||
{
|
||||
if (count >= MAX_DATA_PACKER_VARS)
|
||||
{
|
||||
cout << "Parallel::data_packer: too many variables in communication list." << endl;
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
src_sgfn[count] = src_it->data->sgfn;
|
||||
dst_sgfn[count] = dst_it->data->sgfn;
|
||||
src_soa[count] = src_it->data->SoA;
|
||||
count++;
|
||||
src_it = src_it->next;
|
||||
dst_it = dst_it->next;
|
||||
}
|
||||
|
||||
if (src_it || dst_it)
|
||||
{
|
||||
cout << "error in short data packer, var lists does not match." << endl;
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
int Parallel::partition1(int &nx, int split_size, int min_width, int cpusize, int shape) // special for 1 diemnsion
|
||||
{
|
||||
nx = Mymax(1, shape / min_width);
|
||||
@@ -3730,21 +3766,10 @@ int Parallel::data_packer(double *data, MyList<Parallel::gridseg> *src, MyList<P
|
||||
if (!src || !dst)
|
||||
return size_out;
|
||||
|
||||
MyList<var> *varls, *varld;
|
||||
|
||||
varls = VarLists;
|
||||
varld = VarListd;
|
||||
while (varls && varld)
|
||||
{
|
||||
varls = varls->next;
|
||||
varld = varld->next;
|
||||
}
|
||||
|
||||
if (varls || varld)
|
||||
{
|
||||
cout << "error in short data packer, var lists does not match." << endl;
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
int src_sgfn[MAX_DATA_PACKER_VARS];
|
||||
int dst_sgfn[MAX_DATA_PACKER_VARS];
|
||||
double *src_soa[MAX_DATA_PACKER_VARS];
|
||||
const int var_count = expand_var_list_pack_info(VarLists, VarListd, src_sgfn, dst_sgfn, src_soa);
|
||||
|
||||
int type; /* 1 copy, 2 restrict, 3 prolong */
|
||||
if (src->data->Bg->lev == dst->data->Bg->lev)
|
||||
@@ -3756,44 +3781,58 @@ int Parallel::data_packer(double *data, MyList<Parallel::gridseg> *src, MyList<P
|
||||
|
||||
while (src && dst)
|
||||
{
|
||||
if ((dir == PACK && dst->data->Bg->rank == rank_in && src->data->Bg->rank == myrank) ||
|
||||
(dir == UNPACK && src->data->Bg->rank == rank_in && dst->data->Bg->rank == myrank))
|
||||
{
|
||||
varls = VarLists;
|
||||
varld = VarListd;
|
||||
while (varls && varld)
|
||||
const bool rank_match =
|
||||
(dir == PACK && dst->data->Bg->rank == rank_in && src->data->Bg->rank == myrank) ||
|
||||
(dir == UNPACK && src->data->Bg->rank == rank_in && dst->data->Bg->rank == myrank);
|
||||
|
||||
if (rank_match)
|
||||
{
|
||||
const int segment_size = dst->data->shape[0] * dst->data->shape[1] * dst->data->shape[2];
|
||||
int offset = size_out;
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (dir == PACK)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
// attention must be paied to the difference between src's llb,uub and dst's llb,uub
|
||||
case 1:
|
||||
f_copy(DIM, dst->data->llb, dst->data->uub, dst->data->shape, data + size_out,
|
||||
src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape, src->data->Bg->fgfs[varls->data->sgfn],
|
||||
dst->data->llb, dst->data->uub);
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_copy(DIM, dst->data->llb, dst->data->uub, dst->data->shape, data + offset,
|
||||
src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape,
|
||||
src->data->Bg->fgfs[src_sgfn[iv]], dst->data->llb, dst->data->uub);
|
||||
break;
|
||||
case 2:
|
||||
f_restrict3(DIM, dst->data->llb, dst->data->uub, dst->data->shape, data + size_out,
|
||||
src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape, src->data->Bg->fgfs[varls->data->sgfn],
|
||||
dst->data->llb, dst->data->uub, varls->data->SoA, Symmetry);
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_restrict3(DIM, dst->data->llb, dst->data->uub, dst->data->shape, data + offset,
|
||||
src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape,
|
||||
src->data->Bg->fgfs[src_sgfn[iv]], dst->data->llb, dst->data->uub,
|
||||
src_soa[iv], Symmetry);
|
||||
break;
|
||||
case 3:
|
||||
f_prolong3(DIM, src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape, src->data->Bg->fgfs[varls->data->sgfn],
|
||||
dst->data->llb, dst->data->uub, dst->data->shape, data + size_out,
|
||||
dst->data->llb, dst->data->uub, varls->data->SoA, Symmetry);
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_prolong3(DIM, src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape,
|
||||
src->data->Bg->fgfs[src_sgfn[iv]], dst->data->llb, dst->data->uub,
|
||||
dst->data->shape, data + offset, dst->data->llb, dst->data->uub,
|
||||
src_soa[iv], Symmetry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (dir == UNPACK) // from target data to corresponding grid
|
||||
f_copy(DIM, dst->data->Bg->bbox, dst->data->Bg->bbox + dim, dst->data->Bg->shape, dst->data->Bg->fgfs[varld->data->sgfn],
|
||||
dst->data->llb, dst->data->uub, dst->data->shape, data + size_out,
|
||||
dst->data->llb, dst->data->uub);
|
||||
}
|
||||
size_out += dst->data->shape[0] * dst->data->shape[1] * dst->data->shape[2];
|
||||
varls = varls->next;
|
||||
varld = varld->next;
|
||||
else
|
||||
{
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_copy(DIM, dst->data->Bg->bbox, dst->data->Bg->bbox + dim, dst->data->Bg->shape,
|
||||
dst->data->Bg->fgfs[dst_sgfn[iv]], dst->data->llb, dst->data->uub,
|
||||
dst->data->shape, data + offset, dst->data->llb, dst->data->uub);
|
||||
}
|
||||
}
|
||||
|
||||
size_out = offset + ((!data) ? segment_size * var_count : 0);
|
||||
if (data)
|
||||
size_out = offset;
|
||||
}
|
||||
dst = dst->next;
|
||||
src = src->next;
|
||||
}
|
||||
@@ -3819,21 +3858,10 @@ int Parallel::data_packermix(double *data, MyList<Parallel::gridseg> *src, MyLis
|
||||
if (!src || !dst)
|
||||
return size_out;
|
||||
|
||||
MyList<var> *varls, *varld;
|
||||
|
||||
varls = VarLists;
|
||||
varld = VarListd;
|
||||
while (varls && varld)
|
||||
{
|
||||
varls = varls->next;
|
||||
varld = varld->next;
|
||||
}
|
||||
|
||||
if (varls || varld)
|
||||
{
|
||||
cout << "error in short data packer, var lists does not match." << endl;
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
int src_sgfn[MAX_DATA_PACKER_VARS];
|
||||
int dst_sgfn[MAX_DATA_PACKER_VARS];
|
||||
double *src_soa[MAX_DATA_PACKER_VARS];
|
||||
const int var_count = expand_var_list_pack_info(VarLists, VarListd, src_sgfn, dst_sgfn, src_soa);
|
||||
|
||||
int type; /* 1 copy, 2 restrict, 3 prolong */
|
||||
if (src->data->Bg->lev == dst->data->Bg->lev)
|
||||
@@ -3851,31 +3879,42 @@ int Parallel::data_packermix(double *data, MyList<Parallel::gridseg> *src, MyLis
|
||||
|
||||
while (src && dst)
|
||||
{
|
||||
if ((dir == PACK && dst->data->Bg->rank == rank_in && src->data->Bg->rank == myrank) ||
|
||||
(dir == UNPACK && src->data->Bg->rank == rank_in && dst->data->Bg->rank == myrank))
|
||||
{
|
||||
varls = VarLists;
|
||||
varld = VarListd;
|
||||
while (varls && varld)
|
||||
const bool rank_match =
|
||||
(dir == PACK && dst->data->Bg->rank == rank_in && src->data->Bg->rank == myrank) ||
|
||||
(dir == UNPACK && src->data->Bg->rank == rank_in && dst->data->Bg->rank == myrank);
|
||||
|
||||
if (rank_match)
|
||||
{
|
||||
const int segment_size =
|
||||
(src->data->shape[0] + 2 * ghost_width) *
|
||||
(src->data->shape[1] + 2 * ghost_width) *
|
||||
(src->data->shape[2] + 2 * ghost_width);
|
||||
int offset = size_out;
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (dir == PACK)
|
||||
f_prolongcopy3(DIM, src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape, src->data->Bg->fgfs[varls->data->sgfn],
|
||||
dst->data->llb, dst->data->uub, src->data->shape, data + size_out,
|
||||
src->data->llb, src->data->uub, varls->data->SoA, Symmetry);
|
||||
if (dir == UNPACK) // from target data to corresponding grid
|
||||
f_prolongmix3(DIM, dst->data->Bg->bbox, dst->data->Bg->bbox + dim, dst->data->Bg->shape, dst->data->Bg->fgfs[varld->data->sgfn],
|
||||
src->data->llb, src->data->uub, src->data->shape, data + size_out,
|
||||
dst->data->llb, dst->data->uub, varls->data->SoA, Symmetry, dst->data->illb, dst->data->iuub);
|
||||
{
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_prolongcopy3(DIM, src->data->Bg->bbox, src->data->Bg->bbox + dim, src->data->Bg->shape,
|
||||
src->data->Bg->fgfs[src_sgfn[iv]], dst->data->llb, dst->data->uub,
|
||||
src->data->shape, data + offset, src->data->llb, src->data->uub,
|
||||
src_soa[iv], Symmetry);
|
||||
}
|
||||
// the symmetry problem should be dealt in prolongcopy3,
|
||||
// so we always have ghost_width for both sides
|
||||
size_out += (src->data->shape[0] + 2 * ghost_width) * (src->data->shape[1] + 2 * ghost_width) * (src->data->shape[2] + 2 * ghost_width);
|
||||
varls = varls->next;
|
||||
varld = varld->next;
|
||||
else
|
||||
{
|
||||
for (int iv = 0; iv < var_count; iv++, offset += segment_size)
|
||||
f_prolongmix3(DIM, dst->data->Bg->bbox, dst->data->Bg->bbox + dim, dst->data->Bg->shape,
|
||||
dst->data->Bg->fgfs[dst_sgfn[iv]], src->data->llb, src->data->uub,
|
||||
src->data->shape, data + offset, dst->data->llb, dst->data->uub,
|
||||
src_soa[iv], Symmetry, dst->data->illb, dst->data->iuub);
|
||||
}
|
||||
}
|
||||
|
||||
size_out = offset + ((!data) ? segment_size * var_count : 0);
|
||||
if (data)
|
||||
size_out = offset;
|
||||
}
|
||||
dst = dst->next;
|
||||
src = src->next;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -102,6 +102,16 @@ public:
|
||||
//-1: means no dumy dimension at all; 0: means rho; 1: means sigma
|
||||
};
|
||||
|
||||
// Thread-safe search result (no pointers to shared mutable state)
|
||||
struct PointSearchResult
|
||||
{
|
||||
bool found;
|
||||
Block *Bg;
|
||||
double gx, gy, gz; // global Cartesian coordinates
|
||||
double lx, ly, lz; // local coordinates within the found block
|
||||
int ssst; // source shell-patch type (-1 = Cartesian)
|
||||
};
|
||||
|
||||
int myrank;
|
||||
int shape[dim]; // for (rho, sigma, R), for rho and sigma means number of points for every pi/2
|
||||
double Rrange[2]; // for Rmin and Rmax
|
||||
@@ -175,6 +185,12 @@ public:
|
||||
MyList<Patch> *Pp, double CDH[dim], MyList<pointstru> *pss);
|
||||
bool prolongpointstru(MyList<pointstru> *&psul, bool ssyn, int tsst, MyList<ss_patch> *sPp, double DH[dim],
|
||||
MyList<Patch> *Pp, double CDH[dim], double x, double y, double z, int Symmetry, int rank_in);
|
||||
// Read-only point search — thread-safe (no shared mutable state modified)
|
||||
PointSearchResult prolongpointstru_search(bool ssyn, int tsst, MyList<ss_patch> *sPp, double DH[dim],
|
||||
MyList<Patch> *Pp, double CDH[dim], double x, double y, double z,
|
||||
int Symmetry, int rank_in);
|
||||
// Append a search result to a linked list — use inside omp critical section
|
||||
void prolongpointstru_append(MyList<pointstru> *&psul, const PointSearchResult &sr, int tsst);
|
||||
void setupintintstuff(int cpusize, MyList<Patch> *CPatL, int Symmetry);
|
||||
void intertransfer(MyList<pointstru> **src, MyList<pointstru> **dst,
|
||||
MyList<var> *VarList1 /* source */, MyList<var> *VarList2 /*target */,
|
||||
@@ -94,6 +94,7 @@
|
||||
Hcon,Mxcon,Mycon,Mzcon,Gmxcon,Gmycon,Gmzcon, &
|
||||
Symmetry,Lev,eps,co)
|
||||
|
||||
if (co == 0) then
|
||||
#if (ABV == 0)
|
||||
call ricci_gamma(ex, X, Y, Z, &
|
||||
chi, &
|
||||
@@ -117,6 +118,7 @@
|
||||
Rxx,Rxy,Rxz,Ryy,Ryz,Rzz, &
|
||||
Hcon,Mxcon,Mycon,Mzcon,Gmxcon,Gmycon,Gmzcon, &
|
||||
Symmetry)
|
||||
endif
|
||||
|
||||
return
|
||||
|
||||
@@ -227,6 +229,7 @@
|
||||
call get_Z4cparameters(kappa1,kappa2,kappa3,FF,eta)
|
||||
|
||||
!!! sanity check
|
||||
#ifdef DEBUG
|
||||
dX = sum(chi)+sum(trK)+sum(dxx)+sum(gxy)+sum(gxz)+sum(dyy)+sum(gyz)+sum(dzz) &
|
||||
+sum(Axx)+sum(Axy)+sum(Axz)+sum(Ayy)+sum(Ayz)+sum(Azz) &
|
||||
+sum(Gamx)+sum(Gamy)+sum(Gamz) &
|
||||
@@ -261,6 +264,7 @@
|
||||
gont = 1
|
||||
return
|
||||
endif
|
||||
#endif
|
||||
|
||||
PI = dacos(-ONE)
|
||||
|
||||
@@ -1263,6 +1267,7 @@
|
||||
|
||||
endif
|
||||
|
||||
if (co == 0) then
|
||||
#if (ABV == 0)
|
||||
call ricci_gamma(ex, X, Y, Z, &
|
||||
chi, &
|
||||
@@ -1287,6 +1292,7 @@
|
||||
Rxx,Rxy,Rxz,Ryy,Ryz,Rzz, &
|
||||
Hcon,Mxcon,Mycon,Mzcon,Gmxcon,Gmycon,Gmzcon, &
|
||||
Symmetry)
|
||||
endif
|
||||
|
||||
gont = 0
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
call get_Z4cparameters(kappa1,kappa2,kappa3,FF,eta)
|
||||
|
||||
!!! sanity check
|
||||
#ifdef DEBUG
|
||||
dX = sum(chi)+sum(trK)+sum(dxx)+sum(gxy)+sum(gxz)+sum(dyy)+sum(gyz)+sum(dzz) &
|
||||
+sum(Axx)+sum(Axy)+sum(Axz)+sum(Ayy)+sum(Ayz)+sum(Azz) &
|
||||
+sum(Gamx)+sum(Gamy)+sum(Gamz) &
|
||||
@@ -156,6 +157,7 @@
|
||||
gont = 1
|
||||
return
|
||||
endif
|
||||
#endif
|
||||
|
||||
PI = dacos(-ONE)
|
||||
|
||||
@@ -1388,6 +1390,7 @@
|
||||
call kodis_sh(ex,crho,sigma,R,TZ,TZ_rhs,SSS,Symmetry,eps,sst)
|
||||
endif
|
||||
|
||||
if (co == 0) then
|
||||
#if (ABV == 1)
|
||||
call ricci_gamma_ss(ex,crho,sigma,R,X, Y, Z, &
|
||||
drhodx, drhody, drhodz, &
|
||||
@@ -1404,6 +1407,7 @@
|
||||
Gamzxx,Gamzxy,Gamzxz,Gamzyy,Gamzyz,Gamzzz,&
|
||||
Rxx,Rxy,Rxz,Ryy,Ryz,Rzz,&
|
||||
Symmetry,Lev,sst)
|
||||
#endif
|
||||
call constraint_bssn_ss(ex,crho,sigma,R,X, Y, Z, &
|
||||
drhodx, drhody, drhodz, &
|
||||
dsigmadx,dsigmady,dsigmadz, &
|
||||
@@ -1422,7 +1426,7 @@
|
||||
Rxx,Rxy,Rxz,Ryy,Ryz,Rzz, &
|
||||
Hcon,Mxcon,Mycon,Mzcon,Gmxcon,Gmycon,Gmzcon, &
|
||||
Symmetry,Lev,sst)
|
||||
#endif
|
||||
endif
|
||||
|
||||
gont = 0
|
||||
|
||||
@@ -258,6 +258,8 @@ void bssnEM_class::Initialize()
|
||||
PhysTime = StartTime;
|
||||
Setup_Black_Hole_position();
|
||||
}
|
||||
|
||||
setup_transfer_caches();
|
||||
}
|
||||
|
||||
//================================================================================================
|
||||
@@ -26,6 +26,12 @@ using namespace std;
|
||||
#include "shellfunctions.h"
|
||||
#include "parameters.h"
|
||||
|
||||
#if BSSN_USE_ESCALAR_C_KERNEL
|
||||
#define BSSN_ESCALAR_RHS f_compute_rhs_bssn_escalar_c
|
||||
#else
|
||||
#define BSSN_ESCALAR_RHS f_compute_rhs_bssn_escalar
|
||||
#endif
|
||||
|
||||
#ifdef With_AHF
|
||||
#include "derivatives.h"
|
||||
#include "myglobal.h"
|
||||
@@ -133,6 +139,9 @@ void bssnEScalar_class::Initialize()
|
||||
}
|
||||
|
||||
GH = new cgh(0, ngfs, Symmetry, pname, checkrun, ErrorMonitor);
|
||||
ConstraintRefreshLevels = new int[GH->levels];
|
||||
for (int il = 0; il < GH->levels; il++)
|
||||
ConstraintRefreshLevels[il] = 0;
|
||||
if (checkrun)
|
||||
CheckPoint->readcheck_cgh(PhysTime, GH, myrank, nprocs, Symmetry);
|
||||
else
|
||||
@@ -165,6 +174,8 @@ void bssnEScalar_class::Initialize()
|
||||
PhysTime = StartTime;
|
||||
Setup_Black_Hole_position();
|
||||
}
|
||||
|
||||
setup_transfer_caches();
|
||||
}
|
||||
|
||||
//================================================================================================
|
||||
@@ -230,6 +241,9 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
}
|
||||
int BH_NM;
|
||||
double *Porg_here;
|
||||
double *pmom_local;
|
||||
double *spin_local;
|
||||
double *mass_local;
|
||||
// read parameter from file
|
||||
{
|
||||
const int LEN = 256;
|
||||
@@ -271,9 +285,9 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
}
|
||||
|
||||
Porg_here = new double[3 * BH_NM];
|
||||
Pmom = new double[3 * BH_NM];
|
||||
Spin = new double[3 * BH_NM];
|
||||
Mass = new double[BH_NM];
|
||||
pmom_local = new double[3 * BH_NM];
|
||||
spin_local = new double[3 * BH_NM];
|
||||
mass_local = new double[BH_NM];
|
||||
// read parameter from file
|
||||
{
|
||||
const int LEN = 256;
|
||||
@@ -308,7 +322,7 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
if (sgrp == "BSSN" && sind < BH_NM)
|
||||
{
|
||||
if (skey == "Mass")
|
||||
Mass[sind] = atof(sval.c_str());
|
||||
mass_local[sind] = atof(sval.c_str());
|
||||
else if (skey == "Porgx")
|
||||
Porg_here[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Porgy")
|
||||
@@ -316,17 +330,17 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
else if (skey == "Porgz")
|
||||
Porg_here[sind * 3 + 2] = atof(sval.c_str());
|
||||
else if (skey == "Spinx")
|
||||
Spin[sind * 3] = atof(sval.c_str());
|
||||
spin_local[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Spiny")
|
||||
Spin[sind * 3 + 1] = atof(sval.c_str());
|
||||
spin_local[sind * 3 + 1] = atof(sval.c_str());
|
||||
else if (skey == "Spinz")
|
||||
Spin[sind * 3 + 2] = atof(sval.c_str());
|
||||
spin_local[sind * 3 + 2] = atof(sval.c_str());
|
||||
else if (skey == "Pmomx")
|
||||
Pmom[sind * 3] = atof(sval.c_str());
|
||||
pmom_local[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Pmomy")
|
||||
Pmom[sind * 3 + 1] = atof(sval.c_str());
|
||||
pmom_local[sind * 3 + 1] = atof(sval.c_str());
|
||||
else if (skey == "Pmomz")
|
||||
Pmom[sind * 3 + 2] = atof(sval.c_str());
|
||||
pmom_local[sind * 3 + 2] = atof(sval.c_str());
|
||||
}
|
||||
}
|
||||
inf.close();
|
||||
@@ -362,7 +376,7 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
cg->fgfs[Sfx0->sgfn], cg->fgfs[Sfy0->sgfn], cg->fgfs[Sfz0->sgfn],
|
||||
cg->fgfs[dtSfx0->sgfn], cg->fgfs[dtSfy0->sgfn], cg->fgfs[dtSfz0->sgfn],
|
||||
cg->fgfs[Sphi0->sgfn], cg->fgfs[Spi0->sgfn],
|
||||
Mass, Porg_here, Pmom, Spin, BH_NM);
|
||||
mass_local, Porg_here, pmom_local, spin_local, BH_NM);
|
||||
}
|
||||
if (BL == Pp->data->ble)
|
||||
break;
|
||||
@@ -404,7 +418,7 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
cg->fgfs[Sfx0->sgfn], cg->fgfs[Sfy0->sgfn], cg->fgfs[Sfz0->sgfn],
|
||||
cg->fgfs[dtSfx0->sgfn], cg->fgfs[dtSfy0->sgfn], cg->fgfs[dtSfz0->sgfn],
|
||||
cg->fgfs[Sphi0->sgfn], cg->fgfs[Spi0->sgfn],
|
||||
Mass, Porg_here, Pmom, Spin, BH_NM);
|
||||
mass_local, Porg_here, pmom_local, spin_local, BH_NM);
|
||||
}
|
||||
if (BL == Pp->data->ble)
|
||||
break;
|
||||
@@ -415,6 +429,9 @@ void bssnEScalar_class::Read_Ansorg()
|
||||
#endif
|
||||
|
||||
delete[] Porg_here;
|
||||
delete[] pmom_local;
|
||||
delete[] spin_local;
|
||||
delete[] mass_local;
|
||||
// dump read_in initial data
|
||||
// for(int lev=0;lev<GH->levels;lev++) Parallel::Dump_Data(GH->PatL[lev],StateList,0,PhysTime,dT);
|
||||
}
|
||||
@@ -455,6 +472,9 @@ void bssnEScalar_class::Read_Pablo()
|
||||
}
|
||||
int BH_NM;
|
||||
double *Porg_here;
|
||||
double *pmom_local;
|
||||
double *spin_local;
|
||||
double *mass_local;
|
||||
// read parameter from file
|
||||
{
|
||||
const int LEN = 256;
|
||||
@@ -496,9 +516,9 @@ void bssnEScalar_class::Read_Pablo()
|
||||
}
|
||||
|
||||
Porg_here = new double[3 * BH_NM];
|
||||
Pmom = new double[3 * BH_NM];
|
||||
Spin = new double[3 * BH_NM];
|
||||
Mass = new double[BH_NM];
|
||||
pmom_local = new double[3 * BH_NM];
|
||||
spin_local = new double[3 * BH_NM];
|
||||
mass_local = new double[BH_NM];
|
||||
// read parameter from file
|
||||
{
|
||||
const int LEN = 256;
|
||||
@@ -533,7 +553,7 @@ void bssnEScalar_class::Read_Pablo()
|
||||
if (sgrp == "BSSN" && sind < BH_NM)
|
||||
{
|
||||
if (skey == "Mass")
|
||||
Mass[sind] = atof(sval.c_str());
|
||||
mass_local[sind] = atof(sval.c_str());
|
||||
else if (skey == "Porgx")
|
||||
Porg_here[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Porgy")
|
||||
@@ -541,17 +561,17 @@ void bssnEScalar_class::Read_Pablo()
|
||||
else if (skey == "Porgz")
|
||||
Porg_here[sind * 3 + 2] = atof(sval.c_str());
|
||||
else if (skey == "Spinx")
|
||||
Spin[sind * 3] = atof(sval.c_str());
|
||||
spin_local[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Spiny")
|
||||
Spin[sind * 3 + 1] = atof(sval.c_str());
|
||||
spin_local[sind * 3 + 1] = atof(sval.c_str());
|
||||
else if (skey == "Spinz")
|
||||
Spin[sind * 3 + 2] = atof(sval.c_str());
|
||||
spin_local[sind * 3 + 2] = atof(sval.c_str());
|
||||
else if (skey == "Pmomx")
|
||||
Pmom[sind * 3] = atof(sval.c_str());
|
||||
pmom_local[sind * 3] = atof(sval.c_str());
|
||||
else if (skey == "Pmomy")
|
||||
Pmom[sind * 3 + 1] = atof(sval.c_str());
|
||||
pmom_local[sind * 3 + 1] = atof(sval.c_str());
|
||||
else if (skey == "Pmomz")
|
||||
Pmom[sind * 3 + 2] = atof(sval.c_str());
|
||||
pmom_local[sind * 3 + 2] = atof(sval.c_str());
|
||||
}
|
||||
}
|
||||
inf.close();
|
||||
@@ -598,7 +618,7 @@ void bssnEScalar_class::Read_Pablo()
|
||||
cg->fgfs[Sfx0->sgfn], cg->fgfs[Sfy0->sgfn], cg->fgfs[Sfz0->sgfn],
|
||||
cg->fgfs[dtSfx0->sgfn], cg->fgfs[dtSfy0->sgfn], cg->fgfs[dtSfz0->sgfn],
|
||||
cg->fgfs[Sphi0->sgfn], cg->fgfs[Spi0->sgfn],
|
||||
Mass, Porg_here, Pmom, Spin, BH_NM);
|
||||
mass_local, Porg_here, pmom_local, spin_local, BH_NM);
|
||||
}
|
||||
if (BL == Pp->data->ble)
|
||||
break;
|
||||
@@ -662,7 +682,7 @@ void bssnEScalar_class::Read_Pablo()
|
||||
cg->fgfs[Sfx0->sgfn], cg->fgfs[Sfy0->sgfn], cg->fgfs[Sfz0->sgfn],
|
||||
cg->fgfs[dtSfx0->sgfn], cg->fgfs[dtSfy0->sgfn], cg->fgfs[dtSfz0->sgfn],
|
||||
cg->fgfs[Sphi0->sgfn], cg->fgfs[Spi0->sgfn],
|
||||
Mass, Porg_here, Pmom, Spin, BH_NM);
|
||||
mass_local, Porg_here, pmom_local, spin_local, BH_NM);
|
||||
}
|
||||
if (BL == Pp->data->ble)
|
||||
break;
|
||||
@@ -686,6 +706,9 @@ void bssnEScalar_class::Read_Pablo()
|
||||
#endif
|
||||
|
||||
delete[] Porg_here;
|
||||
delete[] pmom_local;
|
||||
delete[] spin_local;
|
||||
delete[] mass_local;
|
||||
if (flag && myrank == 0)
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
// dump read_in initial data
|
||||
@@ -739,7 +762,7 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
cg->fgfs[Ayy0->sgfn], cg->fgfs[Ayz0->sgfn], cg->fgfs[Azz0->sgfn]);
|
||||
#endif
|
||||
|
||||
if (f_compute_rhs_bssn_escalar(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
if (BSSN_ESCALAR_RHS(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
cg->fgfs[phi0->sgfn], cg->fgfs[trK0->sgfn],
|
||||
cg->fgfs[gxx0->sgfn], cg->fgfs[gxy0->sgfn], cg->fgfs[gxz0->sgfn],
|
||||
cg->fgfs[gyy0->sgfn], cg->fgfs[gyz0->sgfn], cg->fgfs[gzz0->sgfn],
|
||||
@@ -993,7 +1016,8 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
}
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_pre, Symmetry);
|
||||
Parallel::AsyncSyncState async_pre;
|
||||
sync_predictor_start(lev, SynchList_pre, async_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -1012,6 +1036,7 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sync_predictor_finish(lev, async_pre, SynchList_pre);
|
||||
|
||||
// for black hole position
|
||||
if (BH_num > 0 && lev == GH->levels - 1)
|
||||
@@ -1081,7 +1106,7 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
cg->fgfs[Ayy->sgfn], cg->fgfs[Ayz->sgfn], cg->fgfs[Azz->sgfn]);
|
||||
#endif
|
||||
|
||||
if (f_compute_rhs_bssn_escalar(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
if (BSSN_ESCALAR_RHS(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
cg->fgfs[phi->sgfn], cg->fgfs[trK->sgfn],
|
||||
cg->fgfs[gxx->sgfn], cg->fgfs[gxy->sgfn], cg->fgfs[gxz->sgfn],
|
||||
cg->fgfs[gyy->sgfn], cg->fgfs[gyz->sgfn], cg->fgfs[gzz->sgfn],
|
||||
@@ -1349,7 +1374,8 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
}
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_cor, Symmetry);
|
||||
Parallel::AsyncSyncState async_cor;
|
||||
sync_corrector_start(lev, SynchList_cor, async_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -1368,6 +1394,7 @@ void bssnEScalar_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sync_corrector_finish(lev, async_cor, SynchList_cor);
|
||||
// for black hole position
|
||||
if (BH_num > 0 && lev == GH->levels - 1)
|
||||
{
|
||||
@@ -1835,8 +1862,11 @@ void bssnEScalar_class::AnalysisStuff_EScalar(int lev, double dT_lev)
|
||||
|
||||
//================================================================================================
|
||||
|
||||
void bssnEScalar_class::Interp_Constraint()
|
||||
void bssnEScalar_class::Interp_Constraint(bool infg)
|
||||
{
|
||||
if (!infg)
|
||||
return;
|
||||
|
||||
// we do not support a_lev != 0 yet.
|
||||
if (a_lev > 0)
|
||||
return;
|
||||
@@ -1858,7 +1888,7 @@ void bssnEScalar_class::Interp_Constraint()
|
||||
if (myrank == cg->rank)
|
||||
{
|
||||
if (lev > 0)
|
||||
f_compute_rhs_bssn_escalar(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
BSSN_ESCALAR_RHS(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
cg->fgfs[phi0->sgfn], cg->fgfs[trK0->sgfn],
|
||||
cg->fgfs[gxx0->sgfn], cg->fgfs[gxy0->sgfn], cg->fgfs[gxz0->sgfn],
|
||||
cg->fgfs[gyy0->sgfn], cg->fgfs[gyz0->sgfn], cg->fgfs[gzz0->sgfn],
|
||||
@@ -2078,7 +2108,7 @@ void bssnEScalar_class::Constraint_Out()
|
||||
if (myrank == cg->rank)
|
||||
{
|
||||
if (lev > 0)
|
||||
f_compute_rhs_bssn_escalar(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
BSSN_ESCALAR_RHS(cg->shape, TRK4, cg->X[0], cg->X[1], cg->X[2],
|
||||
cg->fgfs[phi0->sgfn], cg->fgfs[trK0->sgfn],
|
||||
cg->fgfs[gxx0->sgfn], cg->fgfs[gxy0->sgfn], cg->fgfs[gxz0->sgfn],
|
||||
cg->fgfs[gyy0->sgfn], cg->fgfs[gyz0->sgfn], cg->fgfs[gzz0->sgfn],
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
void Compute_Psi4(int lev);
|
||||
void Step(int lev, int YN);
|
||||
void AnalysisStuff_EScalar(int lev, double dT_lev);
|
||||
void Interp_Constraint();
|
||||
void Interp_Constraint(bool infg);
|
||||
void Constraint_Out();
|
||||
|
||||
protected:
|
||||
@@ -299,6 +299,28 @@ bssn_class::bssn_class(double Couranti, double StartTimei, double TotalTimei,
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
|
||||
|
||||
// Derived classes override Initialize(), so ownership-sensitive members must
|
||||
// be in a known state before any specialized setup path runs.
|
||||
GH = 0;
|
||||
SH = 0;
|
||||
PhysTime = 0.0;
|
||||
BH_num = 0;
|
||||
BH_num_input = 0;
|
||||
Porg0 = 0;
|
||||
Porgbr = 0;
|
||||
Porg = 0;
|
||||
Porg1 = 0;
|
||||
Porg_rhs = 0;
|
||||
Mass = 0;
|
||||
Pmom = 0;
|
||||
Spin = 0;
|
||||
sync_cache_pre = 0;
|
||||
sync_cache_cor = 0;
|
||||
sync_cache_rp_coarse = 0;
|
||||
sync_cache_rp_fine = 0;
|
||||
sync_cache_restrict = 0;
|
||||
sync_cache_outbd = 0;
|
||||
|
||||
// setup Monitors
|
||||
{
|
||||
stringstream a_stream;
|
||||
@@ -986,13 +1008,7 @@ void bssn_class::Initialize()
|
||||
Setup_Black_Hole_position();
|
||||
}
|
||||
|
||||
// Initialize sync caches (per-level, for predictor and corrector)
|
||||
sync_cache_pre = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_cor = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_rp_coarse = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_rp_fine = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_restrict = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_outbd = new Parallel::SyncCache[GH->levels];
|
||||
setup_transfer_caches();
|
||||
}
|
||||
|
||||
//================================================================================================
|
||||
@@ -1247,30 +1263,7 @@ bssn_class::~bssn_class()
|
||||
#endif
|
||||
|
||||
// Destroy sync caches before GH
|
||||
if (sync_cache_pre)
|
||||
{
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_pre[i].destroy();
|
||||
delete[] sync_cache_pre;
|
||||
}
|
||||
if (sync_cache_cor)
|
||||
{
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_cor[i].destroy();
|
||||
delete[] sync_cache_cor;
|
||||
}
|
||||
if (sync_cache_rp_coarse)
|
||||
{
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_rp_coarse[i].destroy();
|
||||
delete[] sync_cache_rp_coarse;
|
||||
}
|
||||
if (sync_cache_rp_fine)
|
||||
{
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_rp_fine[i].destroy();
|
||||
delete[] sync_cache_rp_fine;
|
||||
}
|
||||
destroy_transfer_caches();
|
||||
|
||||
delete GH;
|
||||
#ifdef WithShell
|
||||
@@ -2489,7 +2482,7 @@ void bssn_class::Evolve(int Steps)
|
||||
GH->Regrid(Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_mon, StartTime, dT_mon / 2), ErrorMonitor);
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
STEP_TIMER_ADD(TB_REGRID, timer_regrid);
|
||||
#endif
|
||||
|
||||
@@ -2730,7 +2723,7 @@ void bssn_class::RecursiveStep(int lev)
|
||||
{
|
||||
if (ConstraintRefreshLevels)
|
||||
ConstraintRefreshLevels[lev] = 1;
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
}
|
||||
STEP_TIMER_ADD(TB_REGRID, timer_regrid_onelevel);
|
||||
#endif
|
||||
@@ -2911,7 +2904,7 @@ void bssn_class::ParallelStep()
|
||||
if (GH->Regrid_Onelevel(GH->mylev, Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_lev, StartTime, dT_lev / 2), ErrorMonitor))
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3078,7 +3071,7 @@ void bssn_class::ParallelStep()
|
||||
if (GH->Regrid_Onelevel(lev + 1, Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_levp1, StartTime, dT_levp1 / 2), ErrorMonitor))
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
|
||||
// a_stream.clear();
|
||||
// a_stream.str("");
|
||||
@@ -3093,7 +3086,7 @@ void bssn_class::ParallelStep()
|
||||
if (GH->Regrid_Onelevel(lev, Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_lev, StartTime, dT_lev / 2), ErrorMonitor))
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
|
||||
// a_stream.clear();
|
||||
// a_stream.str("");
|
||||
@@ -3112,7 +3105,7 @@ void bssn_class::ParallelStep()
|
||||
if (GH->Regrid_Onelevel(lev - 1, Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_lev, StartTime, dT_levm1 / 2), ErrorMonitor))
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
|
||||
// a_stream.clear();
|
||||
// a_stream.str("");
|
||||
@@ -3128,7 +3121,7 @@ void bssn_class::ParallelStep()
|
||||
if (GH->Regrid_Onelevel(lev - 1, Symmetry, BH_num, Porgbr, Porg0,
|
||||
SynchList_cor, OldStateList, StateList, SynchList_pre,
|
||||
fgt(PhysTime - dT_lev, StartTime, dT_levm1 / 2), ErrorMonitor))
|
||||
for (int il = 0; il < GH->levels; il++) { sync_cache_pre[il].invalidate(); sync_cache_cor[il].invalidate(); sync_cache_rp_coarse[il].invalidate(); sync_cache_rp_fine[il].invalidate(); sync_cache_restrict[il].invalidate(); sync_cache_outbd[il].invalidate(); }
|
||||
invalidate_transfer_caches();
|
||||
|
||||
// a_stream.clear();
|
||||
// a_stream.str("");
|
||||
@@ -3659,7 +3652,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
|
||||
STEP_TIMER_DECL(timer_predictor_sync);
|
||||
Parallel::AsyncSyncState async_pre;
|
||||
Parallel::Sync_start(GH->PatL[lev], SynchList_pre, Symmetry, sync_cache_pre[lev], async_pre);
|
||||
sync_predictor_start(lev, SynchList_pre, async_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -3678,7 +3671,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Parallel::Sync_finish(sync_cache_pre[lev], async_pre, SynchList_pre, Symmetry);
|
||||
sync_predictor_finish(lev, async_pre, SynchList_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
// Complete non-blocking error reduction and check
|
||||
@@ -4024,7 +4017,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
|
||||
STEP_TIMER_DECL(timer_corrector_sync);
|
||||
Parallel::AsyncSyncState async_cor;
|
||||
Parallel::Sync_start(GH->PatL[lev], SynchList_cor, Symmetry, sync_cache_cor[lev], async_cor);
|
||||
sync_corrector_start(lev, SynchList_cor, async_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -4043,7 +4036,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Parallel::Sync_finish(sync_cache_cor[lev], async_cor, SynchList_cor, Symmetry);
|
||||
sync_corrector_finish(lev, async_cor, SynchList_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
// Complete non-blocking error reduction and check
|
||||
@@ -4532,7 +4525,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
#endif
|
||||
|
||||
Parallel::AsyncSyncState async_pre;
|
||||
Parallel::Sync_start(GH->PatL[lev], SynchList_pre, Symmetry, sync_cache_pre[lev], async_pre);
|
||||
sync_predictor_start(lev, SynchList_pre, async_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -4551,7 +4544,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Parallel::Sync_finish(sync_cache_pre[lev], async_pre, SynchList_pre, Symmetry);
|
||||
sync_predictor_finish(lev, async_pre, SynchList_pre);
|
||||
|
||||
#ifdef WithShell
|
||||
// Complete non-blocking error reduction and check
|
||||
@@ -4880,7 +4873,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
#endif
|
||||
|
||||
Parallel::AsyncSyncState async_cor;
|
||||
Parallel::Sync_start(GH->PatL[lev], SynchList_cor, Symmetry, sync_cache_cor[lev], async_cor);
|
||||
sync_corrector_start(lev, SynchList_cor, async_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
if (lev == 0)
|
||||
@@ -4899,7 +4892,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Parallel::Sync_finish(sync_cache_cor[lev], async_cor, SynchList_cor, Symmetry);
|
||||
sync_corrector_finish(lev, async_cor, SynchList_cor);
|
||||
|
||||
#ifdef WithShell
|
||||
// Complete non-blocking error reduction and check
|
||||
@@ -5291,7 +5284,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
|
||||
// misc::tillherecheck(GH->Commlev[lev],GH->start_rank[lev],"before Predictor sync");
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SynchList_pre, Symmetry, sync_cache_pre[lev]);
|
||||
sync_evolution(lev, SynchList_pre, sync_cache_pre);
|
||||
|
||||
// Complete non-blocking error reduction and check
|
||||
MPI_Wait(&err_req, MPI_STATUS_IGNORE);
|
||||
@@ -5492,7 +5485,7 @@ void bssn_class::Step(int lev, int YN)
|
||||
|
||||
// misc::tillherecheck(GH->Commlev[lev],GH->start_rank[lev],"before Corrector sync");
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SynchList_cor, Symmetry, sync_cache_cor[lev]);
|
||||
sync_evolution(lev, SynchList_cor, sync_cache_cor);
|
||||
|
||||
// misc::tillherecheck(GH->Commlev[lev],GH->start_rank[lev],"after Corrector sync");
|
||||
|
||||
@@ -6081,6 +6074,92 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
//
|
||||
// SynchList_cor old -----------
|
||||
{
|
||||
#if (ABEtype == 1 || ABEtype == 2)
|
||||
#if (PSTR == 1 || PSTR == 2)
|
||||
// stringstream a_stream;
|
||||
// a_stream.setf(ios::left);
|
||||
#endif
|
||||
|
||||
if (lev > 0)
|
||||
{
|
||||
MyList<Patch> *Pp, *Ppc;
|
||||
if (lev > trfls && YN == 0)
|
||||
{
|
||||
Pp = GH->PatL[lev - 1];
|
||||
while (Pp)
|
||||
{
|
||||
if (BB)
|
||||
Parallel::prepare_inter_time_level(Pp->data, SL, OL, corL,
|
||||
SynchList_pre, 0);
|
||||
else
|
||||
Parallel::prepare_inter_time_level(Pp->data, SL, OL,
|
||||
SynchList_pre, 0);
|
||||
Pp = Pp->next;
|
||||
}
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], SynchList_pre, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, SynchList_pre, SL, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, SynchList_pre, SL, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], SL, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, SL, SL, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, SL, SL, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SL, Symmetry);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
STEP_TIMER_DECL(timer_restrict_prolong);
|
||||
#if (PSTR == 1 || PSTR == 2)
|
||||
// stringstream a_stream;
|
||||
@@ -6123,7 +6202,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
#endif
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SL, SynchList_pre);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SL,SynchList_pre,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
@@ -6136,7 +6215,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
// misc::tillherecheck(GH->Commlev[GH->mylev],GH->start_rank[GH->mylev],a_stream.str());
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], SynchList_pre, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, SynchList_pre, sync_cache_rp_coarse);
|
||||
|
||||
#if (PSTR == 1 || PSTR == 2)
|
||||
// a_stream.clear();
|
||||
@@ -6147,7 +6226,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SynchList_pre, SL);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, Symmetry);
|
||||
#endif
|
||||
@@ -6174,7 +6253,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
#endif
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SL, SL);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SL,SL,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->rsul[lev], Symmetry);
|
||||
@@ -6187,7 +6266,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
// misc::tillherecheck(GH->Commlev[GH->mylev],GH->start_rank[GH->mylev],a_stream.str());
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], SL, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, SL, sync_cache_rp_coarse);
|
||||
|
||||
#if (PSTR == 1 || PSTR == 2)
|
||||
// a_stream.clear();
|
||||
@@ -6198,7 +6277,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SL, SL);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry);
|
||||
#endif
|
||||
@@ -6215,7 +6294,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB,
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SL, Symmetry, sync_cache_rp_fine[lev]);
|
||||
sync_evolution(lev, SL, sync_cache_rp_fine);
|
||||
|
||||
#if (PSTR == 1 || PSTR == 2)
|
||||
// a_stream.clear();
|
||||
@@ -6244,6 +6323,91 @@ void bssn_class::RestrictProlong_aux(int lev, int YN, bool BB,
|
||||
//
|
||||
// SynchList_cor old -----------
|
||||
{
|
||||
#if (ABEtype == 1 || ABEtype == 2)
|
||||
if (lev >= GH->levels - 1)
|
||||
return;
|
||||
lev = lev + 1;
|
||||
|
||||
if (lev > 0)
|
||||
{
|
||||
MyList<Patch> *Pp, *Ppc;
|
||||
if (lev > trfls && YN == 0)
|
||||
{
|
||||
Pp = GH->PatL[lev - 1];
|
||||
while (Pp)
|
||||
{
|
||||
if (BB)
|
||||
Parallel::prepare_inter_time_level(Pp->data, SL, OL, corL,
|
||||
SynchList_pre, 0);
|
||||
else
|
||||
Parallel::prepare_inter_time_level(Pp->data, SL, OL,
|
||||
SynchList_pre, 0);
|
||||
Pp = Pp->next;
|
||||
}
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], SynchList_pre, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, SynchList_pre, SL, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, SynchList_pre, SL, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], SL, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, SL, SL, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, SL, SL, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SL, Symmetry);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
STEP_TIMER_DECL(timer_restrict_prolong);
|
||||
// misc::tillherecheck(GH->Commlev[lev],GH->start_rank[lev],"starting RestrictProlong_aux");
|
||||
|
||||
@@ -6269,17 +6433,17 @@ void bssn_class::RestrictProlong_aux(int lev, int YN, bool BB,
|
||||
}
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SL, SynchList_pre);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SL,SynchList_pre,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], SynchList_pre, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, SynchList_pre, sync_cache_rp_coarse);
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SynchList_pre, SL);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SL, Symmetry);
|
||||
#endif
|
||||
@@ -6291,17 +6455,17 @@ void bssn_class::RestrictProlong_aux(int lev, int YN, bool BB,
|
||||
else // no time refinement levels and for all same time levels
|
||||
{
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SL, SL);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SL,SL,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], SL, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, SL, sync_cache_rp_coarse);
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SL, SL);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SL, SL, Symmetry);
|
||||
#endif
|
||||
@@ -6311,7 +6475,11 @@ void bssn_class::RestrictProlong_aux(int lev, int YN, bool BB,
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SL, Symmetry, sync_cache_rp_fine[lev]);
|
||||
#if (ABEtype == 1 || ABEtype == 2)
|
||||
Parallel::Sync(GH->PatL[lev], SL, Symmetry);
|
||||
#else
|
||||
sync_evolution(lev, SL, sync_cache_rp_fine);
|
||||
#endif
|
||||
}
|
||||
STEP_TIMER_ADD(TB_RESTRICT_PROLONG, timer_restrict_prolong);
|
||||
}
|
||||
@@ -6324,8 +6492,93 @@ void bssn_class::RestrictProlong_aux(int lev, int YN, bool BB,
|
||||
|
||||
void bssn_class::RestrictProlong(int lev, int YN, bool BB)
|
||||
{
|
||||
STEP_TIMER_DECL(timer_restrict_prolong);
|
||||
double dT_lev = dT * pow(0.5, Mymax(lev, trfls));
|
||||
#if (ABEtype == 1 || ABEtype == 2)
|
||||
if (lev > 0)
|
||||
{
|
||||
MyList<Patch> *Pp, *Ppc;
|
||||
if (lev > trfls && YN == 0)
|
||||
{
|
||||
if (myrank == 0)
|
||||
cout << "/=: " << GH->Lt[lev - 1] << "," << GH->Lt[lev] + dT_lev << endl;
|
||||
Pp = GH->PatL[lev - 1];
|
||||
while (Pp)
|
||||
{
|
||||
if (BB)
|
||||
Parallel::prepare_inter_time_level(Pp->data, StateList, OldStateList, SynchList_cor,
|
||||
SynchList_pre, 0);
|
||||
else
|
||||
Parallel::prepare_inter_time_level(Pp->data, StateList, OldStateList,
|
||||
SynchList_pre, 0);
|
||||
Pp = Pp->next;
|
||||
}
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, SynchList_pre, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], SynchList_pre, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, SynchList_pre, SynchList_cor, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, SynchList_pre, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SynchList_cor, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myrank == 0)
|
||||
cout << "===: " << GH->Lt[lev - 1] << "," << GH->Lt[lev] + dT_lev << endl;
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, StateList, Symmetry);
|
||||
#elif (RPB == 1)
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, StateList, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync(GH->PatL[lev - 1], StateList, Symmetry);
|
||||
|
||||
#if (RPB == 0)
|
||||
Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, StateList, SynchList_cor, Symmetry);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(Ppc->data, Pp->data, StateList, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
#elif (RPB == 1)
|
||||
Parallel::OutBdLow2Hi_bam(GH->PatL[lev - 1], GH->PatL[lev], StateList, SynchList_cor, GH->bdsul[lev], Symmetry);
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync(GH->PatL[lev], SynchList_cor, Symmetry);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
STEP_TIMER_DECL(timer_restrict_prolong);
|
||||
// we assume for fine
|
||||
// SynchList_cor 1 -----------
|
||||
//
|
||||
@@ -6358,17 +6611,17 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB)
|
||||
}
|
||||
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, SynchList_pre, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SynchList_cor, SynchList_pre);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SynchList_cor,SynchList_pre,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, SynchList_pre, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], SynchList_pre, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, SynchList_pre, sync_cache_rp_coarse);
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SynchList_cor, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SynchList_pre, SynchList_cor);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
@@ -6382,17 +6635,17 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB)
|
||||
if (myrank == 0)
|
||||
cout << "===: " << GH->Lt[lev - 1] << "," << GH->Lt[lev] + dT_lev << endl;
|
||||
#if (RPB == 0)
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, StateList, Symmetry, sync_cache_restrict[lev]);
|
||||
restrict_evolution(lev, SynchList_cor, StateList);
|
||||
#elif (RPB == 1)
|
||||
// Parallel::Restrict_bam(GH->PatL[lev-1],GH->PatL[lev],SynchList_cor,StateList,Symmetry);
|
||||
Parallel::Restrict_bam(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, StateList, GH->rsul[lev], Symmetry);
|
||||
#endif
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], StateList, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, StateList, sync_cache_rp_coarse);
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], StateList, SynchList_cor, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, StateList, SynchList_cor);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], StateList, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
@@ -6402,7 +6655,7 @@ void bssn_class::RestrictProlong(int lev, int YN, bool BB)
|
||||
#endif
|
||||
}
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SynchList_cor, Symmetry, sync_cache_rp_fine[lev]);
|
||||
sync_evolution(lev, SynchList_cor, sync_cache_rp_fine);
|
||||
}
|
||||
STEP_TIMER_ADD(TB_RESTRICT_PROLONG, timer_restrict_prolong);
|
||||
}
|
||||
@@ -6434,7 +6687,7 @@ void bssn_class::ProlongRestrict(int lev, int YN, bool BB)
|
||||
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SynchList_cor, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, SynchList_pre, SynchList_cor);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], SynchList_pre, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
@@ -6447,7 +6700,7 @@ void bssn_class::ProlongRestrict(int lev, int YN, bool BB)
|
||||
{
|
||||
#if (RPB == 0)
|
||||
#if (MIXOUTB == 0)
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], StateList, SynchList_cor, Symmetry, sync_cache_outbd[lev]);
|
||||
outbdlow2hi_evolution(lev, StateList, SynchList_cor);
|
||||
#elif (MIXOUTB == 1)
|
||||
Parallel::OutBdLow2Himix(GH->PatL[lev - 1], GH->PatL[lev], StateList, SynchList_cor, Symmetry);
|
||||
#endif
|
||||
@@ -6466,10 +6719,10 @@ void bssn_class::ProlongRestrict(int lev, int YN, bool BB)
|
||||
#else
|
||||
Parallel::Restrict_after(GH->PatL[lev - 1], GH->PatL[lev], SynchList_cor, StateList, Symmetry);
|
||||
#endif
|
||||
Parallel::Sync_cached(GH->PatL[lev - 1], StateList, Symmetry, sync_cache_rp_coarse[lev]);
|
||||
sync_evolution(lev - 1, StateList, sync_cache_rp_coarse);
|
||||
}
|
||||
|
||||
Parallel::Sync_cached(GH->PatL[lev], SynchList_cor, Symmetry, sync_cache_rp_fine[lev]);
|
||||
sync_evolution(lev, SynchList_cor, sync_cache_rp_fine);
|
||||
}
|
||||
}
|
||||
#undef MIXOUTB
|
||||
@@ -7199,6 +7452,169 @@ void bssn_class::compute_Porg_rhs(double **BH_PS, double **BH_RHS, var *forx, va
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool bssn_class::use_transfer_cache() const
|
||||
{
|
||||
#if BSSN_USE_TRANSFER_CACHE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void bssn_class::setup_transfer_caches()
|
||||
{
|
||||
sync_cache_pre = 0;
|
||||
sync_cache_cor = 0;
|
||||
sync_cache_rp_coarse = 0;
|
||||
sync_cache_rp_fine = 0;
|
||||
sync_cache_restrict = 0;
|
||||
sync_cache_outbd = 0;
|
||||
|
||||
if (!use_transfer_cache() || !GH)
|
||||
return;
|
||||
|
||||
sync_cache_pre = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_cor = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_rp_coarse = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_rp_fine = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_restrict = new Parallel::SyncCache[GH->levels];
|
||||
sync_cache_outbd = new Parallel::SyncCache[GH->levels];
|
||||
}
|
||||
|
||||
void bssn_class::invalidate_transfer_caches()
|
||||
{
|
||||
if (!use_transfer_cache() || !GH || !sync_cache_pre || !sync_cache_cor ||
|
||||
!sync_cache_rp_coarse || !sync_cache_rp_fine || !sync_cache_restrict || !sync_cache_outbd)
|
||||
return;
|
||||
|
||||
for (int il = 0; il < GH->levels; il++)
|
||||
{
|
||||
sync_cache_pre[il].invalidate();
|
||||
sync_cache_cor[il].invalidate();
|
||||
sync_cache_rp_coarse[il].invalidate();
|
||||
sync_cache_rp_fine[il].invalidate();
|
||||
sync_cache_restrict[il].invalidate();
|
||||
sync_cache_outbd[il].invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void bssn_class::destroy_transfer_caches()
|
||||
{
|
||||
if (sync_cache_pre)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_pre[i].destroy();
|
||||
delete[] sync_cache_pre;
|
||||
sync_cache_pre = 0;
|
||||
}
|
||||
if (sync_cache_cor)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_cor[i].destroy();
|
||||
delete[] sync_cache_cor;
|
||||
sync_cache_cor = 0;
|
||||
}
|
||||
if (sync_cache_rp_coarse)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_rp_coarse[i].destroy();
|
||||
delete[] sync_cache_rp_coarse;
|
||||
sync_cache_rp_coarse = 0;
|
||||
}
|
||||
if (sync_cache_rp_fine)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_rp_fine[i].destroy();
|
||||
delete[] sync_cache_rp_fine;
|
||||
sync_cache_rp_fine = 0;
|
||||
}
|
||||
if (sync_cache_restrict)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_restrict[i].destroy();
|
||||
delete[] sync_cache_restrict;
|
||||
sync_cache_restrict = 0;
|
||||
}
|
||||
if (sync_cache_outbd)
|
||||
{
|
||||
if (use_transfer_cache() && GH)
|
||||
for (int i = 0; i < GH->levels; i++)
|
||||
sync_cache_outbd[i].destroy();
|
||||
delete[] sync_cache_outbd;
|
||||
sync_cache_outbd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void bssn_class::sync_predictor_start(int lev, MyList<var> *VarList, Parallel::AsyncSyncState &async_state)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
Parallel::Sync_start(GH->PatL[lev], VarList, Symmetry, sync_cache_pre[lev], async_state);
|
||||
else
|
||||
Parallel::Sync(GH->PatL[lev], VarList, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::sync_predictor_finish(int lev, Parallel::AsyncSyncState &async_state, MyList<var> *VarList)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
Parallel::Sync_finish(sync_cache_pre[lev], async_state, VarList, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::sync_corrector_start(int lev, MyList<var> *VarList, Parallel::AsyncSyncState &async_state)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
Parallel::Sync_start(GH->PatL[lev], VarList, Symmetry, sync_cache_cor[lev], async_state);
|
||||
else
|
||||
Parallel::Sync(GH->PatL[lev], VarList, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::sync_corrector_finish(int lev, Parallel::AsyncSyncState &async_state, MyList<var> *VarList)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
Parallel::Sync_finish(sync_cache_cor[lev], async_state, VarList, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::sync_evolution(int lev, MyList<var> *VarList, Parallel::SyncCache *cache_array)
|
||||
{
|
||||
if (use_transfer_cache() && cache_array)
|
||||
Parallel::Sync_cached(GH->PatL[lev], VarList, Symmetry, cache_array[lev]);
|
||||
else
|
||||
Parallel::Sync(GH->PatL[lev], VarList, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::restrict_evolution(int lev, MyList<var> *src_var_list, MyList<var> *dst_var_list)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
Parallel::Restrict_cached(GH->PatL[lev - 1], GH->PatL[lev], src_var_list, dst_var_list, Symmetry, sync_cache_restrict[lev]);
|
||||
else
|
||||
Parallel::Restrict(GH->PatL[lev - 1], GH->PatL[lev], src_var_list, dst_var_list, Symmetry);
|
||||
}
|
||||
|
||||
void bssn_class::outbdlow2hi_evolution(int lev, MyList<var> *src_var_list, MyList<var> *dst_var_list)
|
||||
{
|
||||
if (use_transfer_cache())
|
||||
{
|
||||
Parallel::OutBdLow2Hi_cached(GH->PatL[lev - 1], GH->PatL[lev], src_var_list, dst_var_list, Symmetry, sync_cache_outbd[lev]);
|
||||
return;
|
||||
}
|
||||
|
||||
MyList<Patch> *Ppc = GH->PatL[lev - 1];
|
||||
while (Ppc)
|
||||
{
|
||||
MyList<Patch> *Pp = GH->PatL[lev];
|
||||
while (Pp)
|
||||
{
|
||||
Parallel::OutBdLow2Hi(Ppc->data, Pp->data, src_var_list, dst_var_list, Symmetry);
|
||||
Pp = Pp->next;
|
||||
}
|
||||
Ppc = Ppc->next;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//================================================================================================
|
||||
@@ -33,6 +33,14 @@ using namespace std;
|
||||
|
||||
extern void setpbh(int iBHN, double **iPBH, double *iMass, int rBHN);
|
||||
|
||||
#ifndef BSSN_USE_TRANSFER_CACHE
|
||||
#define BSSN_USE_TRANSFER_CACHE 1
|
||||
#endif
|
||||
|
||||
#ifndef BSSN_USE_ESCALAR_C_KERNEL
|
||||
#define BSSN_USE_ESCALAR_C_KERNEL 1
|
||||
#endif
|
||||
|
||||
class bssn_class
|
||||
{
|
||||
public:
|
||||
@@ -171,6 +179,17 @@ public:
|
||||
void testOutBd();
|
||||
|
||||
bool check_Stdin_Abort();
|
||||
bool use_transfer_cache() const;
|
||||
void setup_transfer_caches();
|
||||
void invalidate_transfer_caches();
|
||||
void destroy_transfer_caches();
|
||||
void sync_predictor_start(int lev, MyList<var> *VarList, Parallel::AsyncSyncState &async_state);
|
||||
void sync_predictor_finish(int lev, Parallel::AsyncSyncState &async_state, MyList<var> *VarList);
|
||||
void sync_corrector_start(int lev, MyList<var> *VarList, Parallel::AsyncSyncState &async_state);
|
||||
void sync_corrector_finish(int lev, Parallel::AsyncSyncState &async_state, MyList<var> *VarList);
|
||||
void sync_evolution(int lev, MyList<var> *VarList, Parallel::SyncCache *cache_array = 0);
|
||||
void restrict_evolution(int lev, MyList<var> *src_var_list, MyList<var> *dst_var_list);
|
||||
void outbdlow2hi_evolution(int lev, MyList<var> *src_var_list, MyList<var> *dst_var_list);
|
||||
|
||||
virtual void Setup_Initial_Data_Cao();
|
||||
virtual void Setup_Initial_Data_Lousto();
|
||||
323
AMSS_NCKU_source/bssn_em_rhs_c.C
Normal file
323
AMSS_NCKU_source/bssn_em_rhs_c.C
Normal file
@@ -0,0 +1,323 @@
|
||||
#include "macrodef.h"
|
||||
#include "bssn_rhs.h"
|
||||
#include "share_func.h"
|
||||
#include "tool.h"
|
||||
#include <cstddef>
|
||||
|
||||
/*
|
||||
* C 版 BSSN-EM RHS kernel — replaces empart.f90 + bssn_rhs.f90 for BSSN+Maxwell.
|
||||
*
|
||||
* Computes:
|
||||
* 1. All metric and EM field derivatives
|
||||
* 2. Physical metric, Christoffel-like terms
|
||||
* 3. EM field RHS (E, B, Kpsi, Kphi)
|
||||
* 4. Stress-energy tensor (rho, Si, Sij)
|
||||
* 5. Calls f_compute_rhs_bssn (C BSSN RHS) with stress-energy
|
||||
* 6. Advection + KO dissipation for EM fields
|
||||
* 7. NaN check
|
||||
*/
|
||||
int f_compute_rhs_bssn_em_c(int *ex, double &T,
|
||||
double *X, double *Y, double *Z,
|
||||
double *chi, double *trK,
|
||||
double *dxx, double *gxy, double *gxz, double *dyy, double *gyz, double *dzz,
|
||||
double *Axx, double *Axy, double *Axz, double *Ayy, double *Ayz, double *Azz,
|
||||
double *Gamx, double *Gamy, double *Gamz,
|
||||
double *Lap, double *betax, double *betay, double *betaz,
|
||||
double *dtSfx, double *dtSfy, double *dtSfz,
|
||||
double *Ex, double *Ey, double *Ez,
|
||||
double *Bx, double *By, double *Bz,
|
||||
double *Kpsi, double *Kphi,
|
||||
double *Jx, double *Jy, double *Jz, double *qchar,
|
||||
double *chi_rhs, double *trK_rhs,
|
||||
double *gxx_rhs, double *gxy_rhs, double *gxz_rhs,
|
||||
double *gyy_rhs, double *gyz_rhs, double *gzz_rhs,
|
||||
double *Axx_rhs, double *Axy_rhs, double *Axz_rhs,
|
||||
double *Ayy_rhs, double *Ayz_rhs, double *Azz_rhs,
|
||||
double *Gamx_rhs, double *Gamy_rhs, double *Gamz_rhs,
|
||||
double *Lap_rhs, double *betax_rhs, double *betay_rhs, double *betaz_rhs,
|
||||
double *dtSfx_rhs, double *dtSfy_rhs, double *dtSfz_rhs,
|
||||
double *Ex_rhs, double *Ey_rhs, double *Ez_rhs,
|
||||
double *Bx_rhs, double *By_rhs, double *Bz_rhs,
|
||||
double *Kpsi_rhs, double *Kphi_rhs,
|
||||
double *rho, double *Sx, double *Sy, double *Sz,
|
||||
double *Sxx, double *Sxy, double *Sxz,
|
||||
double *Syy, double *Syz, double *Szz,
|
||||
double *Gamxxx, double *Gamxxy, double *Gamxxz,
|
||||
double *Gamxyy, double *Gamxyz, double *Gamxzz,
|
||||
double *Gamyxx, double *Gamyxy, double *Gamyxz,
|
||||
double *Gamyyy, double *Gamyyz, double *Gamyzz,
|
||||
double *Gamzxx, double *Gamzxy, double *Gamzxz,
|
||||
double *Gamzyy, double *Gamzyz, double *Gamzzz,
|
||||
double *Rxx, double *Rxy, double *Rxz,
|
||||
double *Ryy, double *Ryz, double *Rzz,
|
||||
double *ham_Res, double *movx_Res, double *movy_Res, double *movz_Res,
|
||||
double *Gmx_Res, double *Gmy_Res, double *Gmz_Res,
|
||||
int &Symmetry, int &Lev, double &eps, int &co)
|
||||
{
|
||||
(void)T;
|
||||
int gont = 0;
|
||||
const int nx = ex[0], ny = ex[1], nz = ex[2];
|
||||
const int all = nx * ny * nz;
|
||||
const size_t n = (size_t)all;
|
||||
|
||||
const double ZEO = 0.0, ONE = 1.0, TWO = 2.0, FOUR = 4.0, EIT = 8.0;
|
||||
const double HALF = 0.5, THR = 3.0, F3o2 = 1.5, PI = 3.14159265358979323846;
|
||||
const double SYM = 1.0, ANTI = -1.0;
|
||||
const double kappa = 1.0;
|
||||
const double SSS[3]={SYM,SYM,SYM}, AAS[3]={ANTI,ANTI,SYM};
|
||||
const double ASA[3]={ANTI,SYM,ANTI}, SAA[3]={SYM,ANTI,ANTI};
|
||||
const double ASS[3]={ANTI,SYM,SYM}, SAS[3]={SYM,ANTI,SYM};
|
||||
const double SSA[3]={SYM,SYM,ANTI};
|
||||
|
||||
/* ---- allocate temporary arrays ---- */
|
||||
double *chix = (double*)malloc(n*sizeof(double));
|
||||
double *chiy = (double*)malloc(n*sizeof(double));
|
||||
double *chiz = (double*)malloc(n*sizeof(double));
|
||||
double *Exx=(double*)malloc(n*sizeof(double)),*Exy=(double*)malloc(n*sizeof(double)),*Exz=(double*)malloc(n*sizeof(double));
|
||||
double *Eyx=(double*)malloc(n*sizeof(double)),*Eyy=(double*)malloc(n*sizeof(double)),*Eyz=(double*)malloc(n*sizeof(double));
|
||||
double *Ezx=(double*)malloc(n*sizeof(double)),*Ezy=(double*)malloc(n*sizeof(double)),*Ezz=(double*)malloc(n*sizeof(double));
|
||||
double *Bxx=(double*)malloc(n*sizeof(double)),*Bxy=(double*)malloc(n*sizeof(double)),*Bxz=(double*)malloc(n*sizeof(double));
|
||||
double *Byx=(double*)malloc(n*sizeof(double)),*Byy=(double*)malloc(n*sizeof(double)),*Byz=(double*)malloc(n*sizeof(double));
|
||||
double *Bzx=(double*)malloc(n*sizeof(double)),*Bzy=(double*)malloc(n*sizeof(double)),*Bzz=(double*)malloc(n*sizeof(double));
|
||||
double *Kpsix=(double*)malloc(n*sizeof(double)),*Kpsiy=(double*)malloc(n*sizeof(double)),*Kpsiz=(double*)malloc(n*sizeof(double));
|
||||
double *Kphix=(double*)malloc(n*sizeof(double)),*Kphiy=(double*)malloc(n*sizeof(double)),*Kphiz=(double*)malloc(n*sizeof(double));
|
||||
double *Lapx=(double*)malloc(n*sizeof(double)),*Lapy=(double*)malloc(n*sizeof(double)),*Lapz=(double*)malloc(n*sizeof(double));
|
||||
double *betaxx=(double*)malloc(n*sizeof(double)),*betaxy=(double*)malloc(n*sizeof(double)),*betaxz=(double*)malloc(n*sizeof(double));
|
||||
double *betayx=(double*)malloc(n*sizeof(double)),*betayy=(double*)malloc(n*sizeof(double)),*betayz=(double*)malloc(n*sizeof(double));
|
||||
double *betazx=(double*)malloc(n*sizeof(double)),*betazy=(double*)malloc(n*sizeof(double)),*betazz=(double*)malloc(n*sizeof(double));
|
||||
double *gxxx=(double*)malloc(n*sizeof(double)),*gxxy=(double*)malloc(n*sizeof(double)),*gxxz=(double*)malloc(n*sizeof(double));
|
||||
double *gxyx=(double*)malloc(n*sizeof(double)),*gxyy=(double*)malloc(n*sizeof(double)),*gxyz=(double*)malloc(n*sizeof(double));
|
||||
double *gxzx=(double*)malloc(n*sizeof(double)),*gxzy=(double*)malloc(n*sizeof(double)),*gxzz=(double*)malloc(n*sizeof(double));
|
||||
double *gyyx=(double*)malloc(n*sizeof(double)),*gyyy=(double*)malloc(n*sizeof(double)),*gyyz=(double*)malloc(n*sizeof(double));
|
||||
double *gyzx=(double*)malloc(n*sizeof(double)),*gyzy=(double*)malloc(n*sizeof(double)),*gyzz=(double*)malloc(n*sizeof(double));
|
||||
double *gzzx=(double*)malloc(n*sizeof(double)),*gzzy=(double*)malloc(n*sizeof(double)),*gzzz=(double*)malloc(n*sizeof(double));
|
||||
double *gupxx=(double*)malloc(n*sizeof(double)),*gupxy=(double*)malloc(n*sizeof(double)),*gupxz=(double*)malloc(n*sizeof(double));
|
||||
double *gupyy=(double*)malloc(n*sizeof(double)),*gupyz=(double*)malloc(n*sizeof(double)),*gupzz=(double*)malloc(n*sizeof(double));
|
||||
|
||||
if (!chix||!chiy||!chiz||!Exx||!Exy||!Exz||!Eyx||!Eyy||!Eyz||!Ezx||!Ezy||!Ezz||
|
||||
!Bxx||!Bxy||!Bxz||!Byx||!Byy||!Byz||!Bzx||!Bzy||!Bzz||
|
||||
!Kpsix||!Kpsiy||!Kpsiz||!Kphix||!Kphiy||!Kphiz||
|
||||
!Lapx||!Lapy||!Lapz||
|
||||
!betaxx||!betaxy||!betaxz||!betayx||!betayy||!betayz||!betazx||!betazy||!betazz||
|
||||
!gxxx||!gxxy||!gxxz||!gxyx||!gxyy||!gxyz||!gxzx||!gxzy||!gxzz||
|
||||
!gyyx||!gyyy||!gyyz||!gyzx||!gyzy||!gyzz||!gzzx||!gzzy||!gzzz||
|
||||
!gupxx||!gupxy||!gupxz||!gupyy||!gupyz||!gupzz) {
|
||||
gont = 1;
|
||||
}
|
||||
|
||||
/* ==== 1. Compute all derivatives ==== */
|
||||
if (!gont) {
|
||||
|
||||
/* metric derivatives */
|
||||
fderivs(ex, Lap, Lapx, Lapy, Lapz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, betax, betaxx, betaxy, betaxz, X, Y, Z, ANTI, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, betay, betayx, betayy, betayz, X, Y, Z, SYM, ANTI, SYM, Symmetry, Lev);
|
||||
fderivs(ex, betaz, betazx, betazy, betazz, X, Y, Z, SYM, SYM, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, chi, chix, chiy, chiz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, dxx, gxxx, gxxy, gxxz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, gxy, gxyx, gxyy, gxyz, X, Y, Z, ANTI, ANTI, SYM, Symmetry, Lev);
|
||||
fderivs(ex, gxz, gxzx, gxzy, gxzz, X, Y, Z, ANTI, SYM, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, dyy, gyyx, gyyy, gyyz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, gyz, gyzx, gyzy, gyzz, X, Y, Z, SYM, ANTI, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, dzz, gzzx, gzzy, gzzz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
|
||||
/* EM field derivatives */
|
||||
fderivs(ex, Kpsi, Kpsix, Kpsiy, Kpsiz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, Kphi, Kphix, Kphiy, Kphiz, X, Y, Z, SYM, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, Ex, Exx, Exy, Exz, X, Y, Z, ANTI, SYM, SYM, Symmetry, Lev);
|
||||
fderivs(ex, Ey, Eyx, Eyy, Eyz, X, Y, Z, SYM, ANTI, SYM, Symmetry, Lev);
|
||||
fderivs(ex, Ez, Ezx, Ezy, Ezz, X, Y, Z, SYM, SYM, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, Bx, Bxx, Bxy, Bxz, X, Y, Z, SYM, ANTI, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, By, Byx, Byy, Byz, X, Y, Z, ANTI, SYM, ANTI, Symmetry, Lev);
|
||||
fderivs(ex, Bz, Bzx, Bzy, Bzz, X, Y, Z, ANTI, ANTI, SYM, Symmetry, Lev);
|
||||
|
||||
/* ==== 2. Compute EM RHS and stress-energy ==== */
|
||||
const double F1o4PI = ONE / (FOUR * PI);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
const double alpn1 = Lap[i] + ONE;
|
||||
const double chin1 = chi[i] + ONE;
|
||||
const double chi3o2 = sqrt(chin1) * chin1; // chi^{3/2}
|
||||
const double ichi = ONE / chin1;
|
||||
|
||||
/* physical metric */
|
||||
const double pgxx = (dxx[i] + ONE) * ichi;
|
||||
const double pgyy = (dyy[i] + ONE) * ichi;
|
||||
const double pgzz = (dzz[i] + ONE) * ichi;
|
||||
const double pgxy = gxy[i] * ichi;
|
||||
const double pgxz = gxz[i] * ichi;
|
||||
const double pgyz = gyz[i] * ichi;
|
||||
|
||||
/* inverse physical metric */
|
||||
const double det = pgxx * pgyy * pgzz + pgxy * pgyz * pgxz + pgxz * pgxy * pgyz
|
||||
- pgxz * pgyy * pgxz - pgxy * pgxy * pgzz - pgxx * pgyz * pgyz;
|
||||
const double idet = ONE / det;
|
||||
const double upxx = (pgyy * pgzz - pgyz * pgyz) * idet;
|
||||
const double upxy = -(pgxy * pgzz - pgyz * pgxz) * idet;
|
||||
const double upxz = (pgxy * pgyz - pgyy * pgxz) * idet;
|
||||
const double upyy = (pgxx * pgzz - pgxz * pgxz) * idet;
|
||||
const double upyz = -(pgxx * pgyz - pgxy * pgxz) * idet;
|
||||
const double upzz = (pgxx * pgyy - pgxy * pgxy) * idet;
|
||||
gupxx[i]=upxx; gupxy[i]=upxy; gupxz[i]=upxz;
|
||||
gupyy[i]=upyy; gupyz[i]=upyz; gupzz[i]=upzz;
|
||||
|
||||
/* E-field RHS */
|
||||
/* curl(B) part: epsilon^{ijk} ∂_j (alpha * B_k) in coordinate basis */
|
||||
/* Using lower-index B fields: B_i_lower = pg_{ij} * B^j */
|
||||
const double BxL = pgxx*Bx[i] + pgxy*By[i] + pgxz*Bz[i];
|
||||
const double ByL = pgxy*Bx[i] + pgyy*By[i] + pgyz*Bz[i];
|
||||
const double BzL = pgxz*Bx[i] + pgyz*By[i] + pgzz*Bz[i];
|
||||
|
||||
/* Physical metric derivatives (chain rule from conformal) */
|
||||
const double pgxx_x = (gxxx[i] - pgxx*chix[i]) * ichi;
|
||||
/* const double pgxx_y = (gxxy[i] - pgxx*chiy[i]) * ichi; */
|
||||
const double pgxy_x = (gxyx[i] - pgxy*chix[i]) * ichi;
|
||||
const double pgxy_y = (gxyy[i] - pgxy*chiy[i]) * ichi;
|
||||
const double pgxz_x = (gxzx[i] - pgxz*chix[i]) * ichi;
|
||||
const double pgxz_z = (gxzz[i] - pgxz*chiz[i]) * ichi;
|
||||
const double pgyy_y = (gyyy[i] - pgyy*chiy[i]) * ichi;
|
||||
const double pgyz_y = (gyzy[i] - pgyz*chiy[i]) * ichi;
|
||||
const double pgyz_z = (gyzz[i] - pgyz*chiz[i]) * ichi;
|
||||
const double pgzz_z = (gzzz[i] - pgzz*chiz[i]) * ichi;
|
||||
|
||||
/* Curl_x(B) = ∂_y (alpha*BzL) - ∂_z (alpha*ByL) */
|
||||
const double aBx = alpn1*BxL, aBy = alpn1*ByL, aBz = alpn1*BzL;
|
||||
const double curlBx = (aBz*Lapy[i] + alpn1*(pgxz*Bxy[i]+pgyz*Byy[i]+pgzz*Bzy[i]) + alpn1*(Bx[i]*gxzy[i]+By[i]*gyzy[i]+Bz[i]*gzzy[i]))
|
||||
- (aBy*Lapz[i] + alpn1*(pgxy*Bxz[i]+pgyy*Byz[i]+pgyz*Bzz[i]) + alpn1*(Bx[i]*gxyz[i]+By[i]*gyyz[i]+Bz[i]*gyzz[i]));
|
||||
double curlBy = (aBx*Lapz[i] + alpn1*(pgxx*Bxz[i]+pgxy*Byz[i]+pgxz*Bzz[i]) + alpn1*(Bx[i]*gxxz[i]+By[i]*gxyz[i]+Bz[i]*gxzz[i]))
|
||||
- (aBz*Lapx[i] + alpn1*(pgxz*Bxx[i]+pgyz*Byx[i]+pgzz*Bzx[i]) + alpn1*(Bx[i]*gxzx[i]+By[i]*gyzx[i]+Bz[i]*gzzx[i]));
|
||||
double curlBz = (aBy*Lapx[i] + alpn1*(pgxy*Bxx[i]+pgyy*Byx[i]+pgyz*Bzx[i]) + alpn1*(Bx[i]*gxyx[i]+By[i]*gyyx[i]+Bz[i]*gyzx[i]))
|
||||
- (aBx*Lapy[i] + alpn1*(pgxx*Bxy[i]+pgxy*Byy[i]+pgxz*Bzy[i]) + alpn1*(Bx[i]*gxxy[i]+By[i]*gxyy[i]+Bz[i]*gxzy[i]));
|
||||
|
||||
/* Advection part: -beta^j * ∂_j E^i */
|
||||
const double advEx = Ex[i]*betaxx[i] + Ey[i]*betaxy[i] + Ez[i]*betaxz[i];
|
||||
const double advEy = Ex[i]*betayx[i] + Ey[i]*betayy[i] + Ez[i]*betayz[i];
|
||||
const double advEz = Ex[i]*betazx[i] + Ey[i]*betazy[i] + Ez[i]*betazz[i];
|
||||
|
||||
/* grad(Kpsi) contracted with inverse metric */
|
||||
const double gupKx = upxx*Kpsix[i] + upxy*Kpsiy[i] + upxz*Kpsiz[i];
|
||||
const double gupKy = upxy*Kpsix[i] + upyy*Kpsiy[i] + upyz*Kpsiz[i];
|
||||
const double gupKz = upxz*Kpsix[i] + upyz*Kpsiy[i] + upzz*Kpsiz[i];
|
||||
|
||||
Ex_rhs[i] = alpn1*trK[i]*Ex[i] - advEx - FOUR*PI*alpn1*Jx[i] - alpn1*gupKx + chi3o2*curlBx;
|
||||
Ey_rhs[i] = alpn1*trK[i]*Ey[i] - advEy - FOUR*PI*alpn1*Jy[i] - alpn1*gupKy + chi3o2*curlBy;
|
||||
Ez_rhs[i] = alpn1*trK[i]*Ez[i] - advEz - FOUR*PI*alpn1*Jz[i] - alpn1*gupKz + chi3o2*curlBz;
|
||||
|
||||
/* B-field RHS: similar but with -chi^{3/2} * curl(E) and grad(Kphi) */
|
||||
const double ExL = pgxx*Ex[i] + pgxy*Ey[i] + pgxz*Ez[i];
|
||||
const double EyL = pgxy*Ex[i] + pgyy*Ey[i] + pgyz*Ez[i];
|
||||
const double EzL = pgxz*Ex[i] + pgyz*Ey[i] + pgzz*Ez[i];
|
||||
|
||||
const double aEx = alpn1*ExL, aEy = alpn1*EyL, aEz = alpn1*EzL;
|
||||
const double curlEx = (aEz*Lapy[i] + alpn1*(pgxz*Exy[i]+pgyz*Eyy[i]+pgzz*Ezy[i]) + alpn1*(Ex[i]*gxzy[i]+Ey[i]*gyzy[i]+Ez[i]*gzzy[i]))
|
||||
- (aEy*Lapz[i] + alpn1*(pgxy*Exz[i]+pgyy*Eyz[i]+pgyz*Ezz[i]) + alpn1*(Ex[i]*gxyz[i]+Ey[i]*gyyz[i]+Ez[i]*gyzz[i]));
|
||||
double curlEy = (aEx*Lapz[i] + alpn1*(pgxx*Exz[i]+pgxy*Eyz[i]+pgxz*Ezz[i]) + alpn1*(Ex[i]*gxxz[i]+Ey[i]*gxyz[i]+Ez[i]*gxzz[i]))
|
||||
- (aEz*Lapx[i] + alpn1*(pgxz*Exx[i]+pgyz*Eyx[i]+pgzz*Ezx[i]) + alpn1*(Ex[i]*gxzx[i]+Ey[i]*gyzx[i]+Ez[i]*gzzx[i]));
|
||||
double curlEz = (aEy*Lapx[i] + alpn1*(pgxy*Exx[i]+pgyy*Eyx[i]+pgyz*Ezx[i]) + alpn1*(Ex[i]*gxyx[i]+Ey[i]*gyyx[i]+Ez[i]*gyzx[i]))
|
||||
- (aEx*Lapy[i] + alpn1*(pgxx*Exy[i]+pgxy*Eyy[i]+pgxz*Ezy[i]) + alpn1*(Ex[i]*gxxy[i]+Ey[i]*gxyy[i]+Ez[i]*gxzy[i]));
|
||||
|
||||
const double advBx = Bx[i]*betaxx[i] + By[i]*betaxy[i] + Bz[i]*betaxz[i];
|
||||
const double advBy = Bx[i]*betayx[i] + By[i]*betayy[i] + Bz[i]*betayz[i];
|
||||
const double advBz = Bx[i]*betazx[i] + By[i]*betazy[i] + Bz[i]*betazz[i];
|
||||
|
||||
const double gupKphix = upxx*Kphix[i] + upxy*Kphiy[i] + upxz*Kphiz[i];
|
||||
const double gupKphiy = upxy*Kphix[i] + upyy*Kphiy[i] + upyz*Kphiz[i];
|
||||
const double gupKphiz = upxz*Kphix[i] + upyz*Kphiy[i] + upzz*Kphiz[i];
|
||||
|
||||
Bx_rhs[i] = alpn1*trK[i]*Bx[i] - advBx - alpn1*gupKphix - chi3o2*curlEx;
|
||||
By_rhs[i] = alpn1*trK[i]*By[i] - advBy - alpn1*gupKphiy - chi3o2*curlEy;
|
||||
Bz_rhs[i] = alpn1*trK[i]*Bz[i] - advBz - alpn1*gupKphiz - chi3o2*curlEz;
|
||||
|
||||
/* Scalar potential RHS */
|
||||
const double divE = Exx[i] + Eyy[i] + Ezz[i];
|
||||
const double divB = Bxx[i] + Byy[i] + Bzz[i];
|
||||
const double chiCont = F3o2 * ichi * (chix[i]*Ex[i] + chiy[i]*Ey[i] + chiz[i]*Ez[i]);
|
||||
Kpsi_rhs[i] = FOUR*PI*alpn1*qchar[i] - alpn1*kappa*Kpsi[i] - alpn1*(divE - chiCont);
|
||||
Kphi_rhs[i] = -alpn1*kappa*Kphi[i] - alpn1*(divB - F3o2*ichi*(chix[i]*Bx[i] + chiy[i]*By[i] + chiz[i]*Bz[i]));
|
||||
|
||||
/* Stress-energy tensor */
|
||||
const double E2 = pgxx*Ex[i]*Ex[i] + pgyy*Ey[i]*Ey[i] + pgzz*Ez[i]*Ez[i]
|
||||
+ TWO*(pgxy*Ex[i]*Ey[i] + pgxz*Ex[i]*Ez[i] + pgyz*Ey[i]*Ez[i]);
|
||||
const double B2 = pgxx*Bx[i]*Bx[i] + pgyy*By[i]*By[i] + pgzz*Bz[i]*Bz[i]
|
||||
+ TWO*(pgxy*Bx[i]*By[i] + pgxz*Bx[i]*Bz[i] + pgyz*By[i]*Bz[i]);
|
||||
rho[i] = (E2 + B2) / (EIT * PI);
|
||||
const double ichi3o2 = ONE / chi3o2;
|
||||
Sx[i] = (Ey[i]*Bz[i] - Ez[i]*By[i]) * F1o4PI * ichi3o2;
|
||||
Sy[i] = (Ez[i]*Bx[i] - Ex[i]*Bz[i]) * F1o4PI * ichi3o2;
|
||||
Sz[i] = (Ex[i]*By[i] - Ey[i]*Bx[i]) * F1o4PI * ichi3o2;
|
||||
const double lExi = pgxx*Ex[i] + pgxy*Ey[i] + pgxz*Ez[i];
|
||||
const double lEyi = pgxy*Ex[i] + pgyy*Ey[i] + pgyz*Ez[i];
|
||||
const double lEzi = pgxz*Ex[i] + pgyz*Ey[i] + pgzz*Ez[i];
|
||||
const double lBxi = pgxx*Bx[i] + pgxy*By[i] + pgxz*Bz[i];
|
||||
const double lByi = pgxy*Bx[i] + pgyy*By[i] + pgyz*Bz[i];
|
||||
const double lBzi = pgxz*Bx[i] + pgyz*By[i] + pgzz*Bz[i];
|
||||
Sxx[i] = rho[i]*pgxx - (lExi*lExi + lBxi*lBxi) * F1o4PI;
|
||||
Sxy[i] = rho[i]*pgxy - (lExi*lEyi + lBxi*lByi) * F1o4PI;
|
||||
Sxz[i] = rho[i]*pgxz - (lExi*lEzi + lBxi*lBzi) * F1o4PI;
|
||||
Syy[i] = rho[i]*pgyy - (lEyi*lEyi + lByi*lByi) * F1o4PI;
|
||||
Syz[i] = rho[i]*pgyz - (lEyi*lEzi + lByi*lBzi) * F1o4PI;
|
||||
Szz[i] = rho[i]*pgzz - (lEzi*lEzi + lBzi*lBzi) * F1o4PI;
|
||||
}
|
||||
|
||||
/* ==== 3. Call BSSN RHS with EM stress-energy ==== */
|
||||
gont = f_compute_rhs_bssn(ex, T, X, Y, Z,
|
||||
chi, trK, dxx, gxy, gxz, dyy, gyz, dzz,
|
||||
Axx, Axy, Axz, Ayy, Ayz, Azz,
|
||||
Gamx, Gamy, Gamz, Lap, betax, betay, betaz, dtSfx, dtSfy, dtSfz,
|
||||
chi_rhs, trK_rhs,
|
||||
gxx_rhs, gxy_rhs, gxz_rhs, gyy_rhs, gyz_rhs, gzz_rhs,
|
||||
Axx_rhs, Axy_rhs, Axz_rhs, Ayy_rhs, Ayz_rhs, Azz_rhs,
|
||||
Gamx_rhs, Gamy_rhs, Gamz_rhs, Lap_rhs, betax_rhs, betay_rhs, betaz_rhs,
|
||||
dtSfx_rhs, dtSfy_rhs, dtSfz_rhs,
|
||||
rho, Sx, Sy, Sz, Sxx, Sxy, Sxz, Syy, Syz, Szz,
|
||||
Gamxxx, Gamxxy, Gamxxz, Gamxyy, Gamxyz, Gamxzz,
|
||||
Gamyxx, Gamyxy, Gamyxz, Gamyyy, Gamyyz, Gamyzz,
|
||||
Gamzxx, Gamzxy, Gamzxz, Gamzyy, Gamzyz, Gamzzz,
|
||||
Rxx, Rxy, Rxz, Ryy, Ryz, Rzz,
|
||||
ham_Res, movx_Res, movy_Res, movz_Res,
|
||||
Gmx_Res, Gmy_Res, Gmz_Res,
|
||||
Symmetry, Lev, eps, co);
|
||||
if (!gont) {
|
||||
|
||||
/* ==== 4. Advection terms for EM fields ==== */
|
||||
lopsided(ex, X, Y, Z, Kpsi, Kpsi_rhs, betax, betay, betaz, Symmetry, SSS);
|
||||
lopsided(ex, X, Y, Z, Kphi, Kphi_rhs, betax, betay, betaz, Symmetry, SSS);
|
||||
lopsided(ex, X, Y, Z, Ex, Ex_rhs, betax, betay, betaz, Symmetry, ASS);
|
||||
lopsided(ex, X, Y, Z, Ey, Ey_rhs, betax, betay, betaz, Symmetry, SAS);
|
||||
lopsided(ex, X, Y, Z, Ez, Ez_rhs, betax, betay, betaz, Symmetry, SSA);
|
||||
lopsided(ex, X, Y, Z, Bx, Bx_rhs, betax, betay, betaz, Symmetry, SAA);
|
||||
lopsided(ex, X, Y, Z, By, By_rhs, betax, betay, betaz, Symmetry, ASA);
|
||||
lopsided(ex, X, Y, Z, Bz, Bz_rhs, betax, betay, betaz, Symmetry, AAS);
|
||||
|
||||
/* ==== 5. KO dissipation for EM fields ==== */
|
||||
if (eps > ZEO) {
|
||||
kodis(ex, X, Y, Z, Kpsi, Kpsi_rhs, SSS, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Kphi, Kphi_rhs, SSS, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Ex, Ex_rhs, ASS, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Ey, Ey_rhs, SAS, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Ez, Ez_rhs, SSA, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Bx, Bx_rhs, SAA, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, By, By_rhs, ASA, Symmetry, eps);
|
||||
kodis(ex, X, Y, Z, Bz, Bz_rhs, AAS, Symmetry, eps);
|
||||
}
|
||||
|
||||
/* ==== 6. NaN check ==== */
|
||||
for (int i = 0; i < all; ++i) {
|
||||
if (!isfinite(Ex_rhs[i]+Ey_rhs[i]+Ez_rhs[i]+Bx_rhs[i]+By_rhs[i]+Bz_rhs[i]+Kpsi_rhs[i]+Kphi_rhs[i])) {
|
||||
gont = 1; break;
|
||||
}
|
||||
}
|
||||
} /* inner if (!gont) */
|
||||
} /* outer if (!gont) */
|
||||
|
||||
free(chix);free(chiy);free(chiz);
|
||||
free(Exx);free(Exy);free(Exz);free(Eyx);free(Eyy);free(Eyz);free(Ezx);free(Ezy);free(Ezz);
|
||||
free(Bxx);free(Bxy);free(Bxz);free(Byx);free(Byy);free(Byz);free(Bzx);free(Bzy);free(Bzz);
|
||||
free(Kpsix);free(Kpsiy);free(Kpsiz);
|
||||
free(Kphix);free(Kphiy);free(Kphiz);
|
||||
free(Lapx);free(Lapy);free(Lapz);
|
||||
free(betaxx);free(betaxy);free(betaxz);free(betayx);free(betayy);free(betayz);free(betazx);free(betazy);free(betazz);
|
||||
free(gxxx);free(gxxy);free(gxxz);free(gxyx);free(gxyy);free(gxyz);free(gxzx);free(gxzy);free(gxzz);
|
||||
free(gyyx);free(gyyy);free(gyyz);free(gyzx);free(gyzy);free(gyzz);free(gzzx);free(gzzy);free(gzzz);
|
||||
free(gupxx);free(gupxy);free(gupxz);free(gupyy);free(gupyz);free(gupzz);
|
||||
return gont;
|
||||
}
|
||||
169
AMSS_NCKU_source/bssn_escalar_rhs_c.C
Normal file
169
AMSS_NCKU_source/bssn_escalar_rhs_c.C
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "macrodef.h"
|
||||
#include "bssn_rhs.h"
|
||||
#include "share_func.h"
|
||||
#include "tool.h"
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
// Reuse the temporary workspace across block calls to avoid repeated heap churn
|
||||
// in the EScalar wrapper. MPI ranks execute this path sequentially, so a single
|
||||
// process-local buffer is sufficient here.
|
||||
std::vector<double> g_escalar_tmp_store;
|
||||
}
|
||||
|
||||
#ifdef fortran1
|
||||
#define f_frpotential frpotential
|
||||
#endif
|
||||
#ifdef fortran2
|
||||
#define f_frpotential FRPOTENTIAL
|
||||
#endif
|
||||
#ifdef fortran3
|
||||
#define f_frpotential frpotential_
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void f_frpotential(int *, double *, double *, double *);
|
||||
}
|
||||
|
||||
int f_compute_rhs_bssn_escalar_c(int *ex, double &T,
|
||||
double *X, double *Y, double *Z,
|
||||
double *chi, double *trK,
|
||||
double *dxx, double *gxy, double *gxz, double *dyy, double *gyz, double *dzz,
|
||||
double *Axx, double *Axy, double *Axz, double *Ayy, double *Ayz, double *Azz,
|
||||
double *Gamx, double *Gamy, double *Gamz,
|
||||
double *Lap, double *betax, double *betay, double *betaz,
|
||||
double *dtSfx, double *dtSfy, double *dtSfz,
|
||||
double *Sphi, double *Spi,
|
||||
double *chi_rhs, double *trK_rhs,
|
||||
double *gxx_rhs, double *gxy_rhs, double *gxz_rhs, double *gyy_rhs, double *gyz_rhs, double *gzz_rhs,
|
||||
double *Axx_rhs, double *Axy_rhs, double *Axz_rhs, double *Ayy_rhs, double *Ayz_rhs, double *Azz_rhs,
|
||||
double *Gamx_rhs, double *Gamy_rhs, double *Gamz_rhs,
|
||||
double *Lap_rhs, double *betax_rhs, double *betay_rhs, double *betaz_rhs,
|
||||
double *dtSfx_rhs, double *dtSfy_rhs, double *dtSfz_rhs,
|
||||
double *Sphi_rhs, double *Spi_rhs,
|
||||
double *rho, double *Sx, double *Sy, double *Sz,
|
||||
double *Sxx, double *Sxy, double *Sxz, double *Syy, double *Syz, double *Szz,
|
||||
double *Gamxxx, double *Gamxxy, double *Gamxxz, double *Gamxyy, double *Gamxyz, double *Gamxzz,
|
||||
double *Gamyxx, double *Gamyxy, double *Gamyxz, double *Gamyyy, double *Gamyyz, double *Gamyzz,
|
||||
double *Gamzxx, double *Gamzxy, double *Gamzxz, double *Gamzyy, double *Gamzyz, double *Gamzzz,
|
||||
double *Rxx, double *Rxy, double *Rxz, double *Ryy, double *Ryz, double *Rzz,
|
||||
double *ham_Res, double *movx_Res, double *movy_Res, double *movz_Res,
|
||||
double *Gmx_Res, double *Gmy_Res, double *Gmz_Res,
|
||||
int &Symmetry, int &Lev, double &eps, int &co)
|
||||
{
|
||||
const int nx = ex[0], ny = ex[1], nz = ex[2];
|
||||
const int all = nx * ny * nz;
|
||||
|
||||
const size_t workspace_size = size_t(all) * 17;
|
||||
if (g_escalar_tmp_store.size() < workspace_size)
|
||||
g_escalar_tmp_store.resize(workspace_size);
|
||||
|
||||
double *tmp_ptr = g_escalar_tmp_store.data();
|
||||
auto alloc_tmp = [&](int n = 1) -> double *
|
||||
{
|
||||
double *ptr = tmp_ptr;
|
||||
tmp_ptr += size_t(all) * n;
|
||||
return ptr;
|
||||
};
|
||||
|
||||
double *chix = alloc_tmp(), *chiy = alloc_tmp(), *chiz = alloc_tmp();
|
||||
double *Kx = alloc_tmp(), *Ky = alloc_tmp(), *Kz = alloc_tmp();
|
||||
double *fxx = alloc_tmp(), *fxy = alloc_tmp(), *fxz = alloc_tmp();
|
||||
double *fyy = alloc_tmp(), *fyz = alloc_tmp(), *fzz = alloc_tmp();
|
||||
double *Lapx = alloc_tmp(), *Lapy = alloc_tmp(), *Lapz = alloc_tmp();
|
||||
double *V = alloc_tmp(), *dVdSphi = alloc_tmp();
|
||||
|
||||
const double ZEO = 0.0, ONE = 1.0, TWO = 2.0, HALF = 0.5;
|
||||
const double SSS[3] = {1.0, 1.0, 1.0};
|
||||
|
||||
fderivs(ex, chi, chix, chiy, chiz, X, Y, Z, 1.0, 1.0, 1.0, Symmetry, Lev);
|
||||
fderivs(ex, Lap, Lapx, Lapy, Lapz, X, Y, Z, 1.0, 1.0, 1.0, Symmetry, Lev);
|
||||
fderivs(ex, Sphi, Kx, Ky, Kz, X, Y, Z, 1.0, 1.0, 1.0, Symmetry, Lev);
|
||||
fdderivs(ex, Sphi, fxx, fxy, fxz, fyy, fyz, fzz, X, Y, Z, 1.0, 1.0, 1.0, Symmetry, Lev);
|
||||
|
||||
f_frpotential(ex, Sphi, V, dVdSphi);
|
||||
|
||||
for (int i = 0; i < all; ++i)
|
||||
{
|
||||
const double alpn1 = Lap[i] + ONE;
|
||||
const double chin1 = chi[i] + ONE;
|
||||
const double gxx = dxx[i] + ONE;
|
||||
const double gyy = dyy[i] + ONE;
|
||||
const double gzz = dzz[i] + ONE;
|
||||
const double det = gxx * gyy * gzz + gxy[i] * gyz[i] * gxz[i] + gxz[i] * gxy[i] * gyz[i]
|
||||
- gxz[i] * gyy * gxz[i] - gxy[i] * gxy[i] * gzz - gxx * gyz[i] * gyz[i];
|
||||
const double gupxx = (gyy * gzz - gyz[i] * gyz[i]) / det;
|
||||
const double gupxy = -(gxy[i] * gzz - gyz[i] * gxz[i]) / det;
|
||||
const double gupxz = (gxy[i] * gyz[i] - gyy * gxz[i]) / det;
|
||||
const double gupyy = (gxx * gzz - gxz[i] * gxz[i]) / det;
|
||||
const double gupyz = -(gxx * gyz[i] - gxy[i] * gxz[i]) / det;
|
||||
const double gupzz = (gxx * gyy - gxy[i] * gxy[i]) / det;
|
||||
|
||||
Sphi_rhs[i] = alpn1 * Spi[i];
|
||||
|
||||
Spi_rhs[i] = gupxx * fxx[i] + gupyy * fyy[i] + gupzz * fzz[i]
|
||||
+ TWO * (gupxy * fxy[i] + gupxz * fxz[i] + gupyz * fyz[i])
|
||||
- ((Gamx[i] + (gupxx * chix[i] + gupxy * chiy[i] + gupxz * chiz[i]) / TWO / chin1) * Kx[i]
|
||||
+ (Gamy[i] + (gupxy * chix[i] + gupyy * chiy[i] + gupyz * chiz[i]) / TWO / chin1) * Ky[i]
|
||||
+ (Gamz[i] + (gupxz * chix[i] + gupyz * chiy[i] + gupzz * chiz[i]) / TWO / chin1) * Kz[i]);
|
||||
|
||||
Spi_rhs[i] = Spi_rhs[i] * alpn1
|
||||
+ gupxx * Lapx[i] * Kx[i] + gupxy * Lapx[i] * Ky[i] + gupxz * Lapx[i] * Kz[i]
|
||||
+ gupxy * Lapy[i] * Kx[i] + gupyy * Lapy[i] * Ky[i] + gupyz * Lapy[i] * Kz[i]
|
||||
+ gupxz * Lapz[i] * Kx[i] + gupyz * Lapz[i] * Ky[i] + gupzz * Lapz[i] * Kz[i];
|
||||
|
||||
Spi_rhs[i] = Spi_rhs[i] * chin1 + alpn1 * (trK[i] * Spi[i] - dVdSphi[i]);
|
||||
|
||||
rho[i] = chin1 * ((gupxx * Kx[i] * Kx[i] + gupyy * Ky[i] * Ky[i] + gupzz * Kz[i] * Kz[i]) * HALF
|
||||
+ gupxy * Kx[i] * Ky[i] + gupxz * Kx[i] * Kz[i] + gupyz * Ky[i] * Kz[i])
|
||||
+ Spi[i] * Spi[i] * HALF + V[i];
|
||||
Sx[i] = -Spi[i] * Kx[i];
|
||||
Sy[i] = -Spi[i] * Ky[i];
|
||||
Sz[i] = -Spi[i] * Kz[i];
|
||||
|
||||
const double pressure = (rho[i] - Spi[i] * Spi[i]) / chin1;
|
||||
Sxx[i] = Kx[i] * Kx[i] - pressure * gxx;
|
||||
Sxy[i] = Kx[i] * Ky[i] - pressure * gxy[i];
|
||||
Sxz[i] = Kx[i] * Kz[i] - pressure * gxz[i];
|
||||
Syy[i] = Ky[i] * Ky[i] - pressure * gyy;
|
||||
Syz[i] = Ky[i] * Kz[i] - pressure * gyz[i];
|
||||
Szz[i] = Kz[i] * Kz[i] - pressure * gzz;
|
||||
}
|
||||
|
||||
if (f_compute_rhs_bssn(ex, T, X, Y, Z,
|
||||
chi, trK,
|
||||
dxx, gxy, gxz, dyy, gyz, dzz,
|
||||
Axx, Axy, Axz, Ayy, Ayz, Azz,
|
||||
Gamx, Gamy, Gamz,
|
||||
Lap, betax, betay, betaz,
|
||||
dtSfx, dtSfy, dtSfz,
|
||||
chi_rhs, trK_rhs,
|
||||
gxx_rhs, gxy_rhs, gxz_rhs, gyy_rhs, gyz_rhs, gzz_rhs,
|
||||
Axx_rhs, Axy_rhs, Axz_rhs, Ayy_rhs, Ayz_rhs, Azz_rhs,
|
||||
Gamx_rhs, Gamy_rhs, Gamz_rhs,
|
||||
Lap_rhs, betax_rhs, betay_rhs, betaz_rhs,
|
||||
dtSfx_rhs, dtSfy_rhs, dtSfz_rhs,
|
||||
rho, Sx, Sy, Sz,
|
||||
Sxx, Sxy, Sxz, Syy, Syz, Szz,
|
||||
Gamxxx, Gamxxy, Gamxxz, Gamxyy, Gamxyz, Gamxzz,
|
||||
Gamyxx, Gamyxy, Gamyxz, Gamyyy, Gamyyz, Gamyzz,
|
||||
Gamzxx, Gamzxy, Gamzxz, Gamzyy, Gamzyz, Gamzzz,
|
||||
Rxx, Rxy, Rxz, Ryy, Ryz, Rzz,
|
||||
ham_Res, movx_Res, movy_Res, movz_Res,
|
||||
Gmx_Res, Gmy_Res, Gmz_Res,
|
||||
Symmetry, Lev, eps, co))
|
||||
return 1;
|
||||
|
||||
lopsided_kodis(ex, X, Y, Z, Sphi, Sphi_rhs, betax, betay, betaz, Symmetry, SSS, eps);
|
||||
lopsided_kodis(ex, X, Y, Z, Spi, Spi_rhs, betax, betay, betaz, Symmetry, SSS, eps);
|
||||
|
||||
for (int i = 0; i < all; ++i)
|
||||
{
|
||||
if (Sphi_rhs[i] != Sphi_rhs[i] || Spi_rhs[i] != Spi_rhs[i] || rho[i] != rho[i])
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -67,6 +67,27 @@ extern "C"
|
||||
int &, int &, double &, int &);
|
||||
}
|
||||
|
||||
int f_compute_rhs_bssn_escalar_c(int *, double &, double *, double *, double *, // ex,T,X,Y,Z
|
||||
double *, double *, // chi, trK
|
||||
double *, double *, double *, double *, double *, double *, // gij
|
||||
double *, double *, double *, double *, double *, double *, // Aij
|
||||
double *, double *, double *, // Gam
|
||||
double *, double *, double *, double *, double *, double *, double *, // Gauge
|
||||
double *, double *, // Sphi, Spi
|
||||
double *, double *, // chi, trK
|
||||
double *, double *, double *, double *, double *, double *, // gij
|
||||
double *, double *, double *, double *, double *, double *, // Aij
|
||||
double *, double *, double *, // Gam
|
||||
double *, double *, double *, double *, double *, double *, double *, // Gauge
|
||||
double *, double *, // Sphi, Spi
|
||||
double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, // stress-energy
|
||||
double *, double *, double *, double *, double *, double *, // Christoffel
|
||||
double *, double *, double *, double *, double *, double *, // Christoffel
|
||||
double *, double *, double *, double *, double *, double *, // Christoffel
|
||||
double *, double *, double *, double *, double *, double *, // Ricci
|
||||
double *, double *, double *, double *, double *, double *, double *, // constraint violation
|
||||
int &, int &, double &, int &);
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int f_compute_rhs_bssn_ss(int *, double &, double *, double *, double *, // ex,T,rho,sigma,R
|
||||
@@ -241,4 +262,31 @@ extern "C"
|
||||
double *);
|
||||
} // FR_cons
|
||||
|
||||
// BSSN-EM C kernel (replaces empart.f90 + bssn_rhs.f90 for BSSN+Maxwell)
|
||||
int f_compute_rhs_bssn_em_c(int *, double &, double *, double *, double *,
|
||||
double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *,
|
||||
double *, double *,
|
||||
double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *,
|
||||
double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
double *, double *, double *, double *, double *, double *,
|
||||
int &, int &, double &, int &);
|
||||
|
||||
#endif /* BSSN_H */
|
||||
@@ -1075,6 +1075,10 @@ int f_compute_rhs_bssn(int *ex, double &T,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (GAUGE == 2 || GAUGE == 3 || GAUGE == 4 || GAUGE == 5)
|
||||
fderivs(ex,chi,dtSfx_rhs,dtSfy_rhs,dtSfz_rhs,X,Y,Z,SYM,SYM,SYM,Symmetry,Lev);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < all; i += 1) {
|
||||
#if (GAUGE == 0)
|
||||
betax_rhs[i] = FF * dtSfx[i];
|
||||
@@ -1160,11 +1164,17 @@ int f_compute_rhs_bssn(int *ex, double &T,
|
||||
lopsided_kodis(ex,X,Y,Z,gyz,gyz_rhs,betax,betay,betaz,Symmetry,SAA,eps);
|
||||
lopsided_kodis(ex,X,Y,Z,betaz,betaz_rhs,betax,betay,betaz,Symmetry,SSA,eps);
|
||||
lopsided_kodis(ex,X,Y,Z,dzz,gzz_rhs,betax,betay,betaz,Symmetry,SSS,eps);
|
||||
#if (GAUGE == 0 || GAUGE == 2 || GAUGE == 3 || GAUGE == 6 || GAUGE == 7)
|
||||
lopsided_kodis(ex,X,Y,Z,dtSfx,dtSfx_rhs,betax,betay,betaz,Symmetry,ASS,eps);
|
||||
#endif
|
||||
lopsided_kodis(ex,X,Y,Z,Axx,Axx_rhs,betax,betay,betaz,Symmetry,SSS,eps);
|
||||
#if (GAUGE == 0 || GAUGE == 2 || GAUGE == 3 || GAUGE == 6 || GAUGE == 7)
|
||||
lopsided_kodis(ex,X,Y,Z,dtSfy,dtSfy_rhs,betax,betay,betaz,Symmetry,SAS,eps);
|
||||
#endif
|
||||
lopsided_kodis(ex,X,Y,Z,Axy,Axy_rhs,betax,betay,betaz,Symmetry,AAS,eps);
|
||||
#if (GAUGE == 0 || GAUGE == 2 || GAUGE == 3 || GAUGE == 6 || GAUGE == 7)
|
||||
lopsided_kodis(ex,X,Y,Z,dtSfz,dtSfz_rhs,betax,betay,betaz,Symmetry,SSA,eps);
|
||||
#endif
|
||||
lopsided_kodis(ex,X,Y,Z,Axz,Axz_rhs,betax,betay,betaz,Symmetry,ASA,eps);
|
||||
lopsided_kodis(ex,X,Y,Z,Ayy,Ayy_rhs,betax,betay,betaz,Symmetry,SSS,eps);
|
||||
lopsided_kodis(ex,X,Y,Z,Ayz,Ayz_rhs,betax,betay,betaz,Symmetry,SAA,eps);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user