// File: /workspace/github_c_makefile_star2_O2/mohuangrui[P]ArtraCFD/numerical_test.c
// Function: ComputeSolutionFunctional
void ComputeSolutionFunctional(const Time *time, Space *space, const Model *model)
{
    FILE *fp = Fopen("solution_functional.csv", "a");
    if (0 == time->stepC) { /* initialization step */
        fprintf(fp, "# time, kinetic energy, enstrophy \n");
    }
    const Partition *const part = &(space->part);
    Node *const node = space->node;
    Real *restrict U = NULL; /* numerical solution */
    int idx = 0; /* linear array index math variable */
    const RealVec d = {part->d[X], part->d[Y], part->d[Z]};
    const int h[DIMS][DIMS] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; /* direction indicator */
    Real rho = model->refRho; /* density */
    RealVec V = {0.0}; /* velocity */
    RealVec W = {0.0}; /* vorticity */
    Real Vs[DIMS][TTN] = {{0.0}}; /* velocity stencil */
    Real dV[DIMS][DIMS] = {{0.0}}; /* velocity gradient */
    Real Ek = 0.0; /* kinetic energy */
    Real Ee = 0.0; /* enstrophy */
    int N = 0; /* number of nodes */
    for (int k = part->ns[PIN][Z][MIN]; k < part->ns[PIN][Z][MAX]; ++k) {
        for (int j = part->ns[PIN][Y][MIN]; j < part->ns[PIN][Y][MAX]; ++j) {
            for (int i = part->ns[PIN][X][MIN]; i < part->ns[PIN][X][MAX]; ++i) {
                for (int s = 0; s < DIMS; ++s) {
                    for (int n = -TCN; n <= TCN; ++n) {
                        idx = IndexNode(k + n * h[s][Z], j + n * h[s][Y], i + n * h[s][X], part->n[Y], part->n[X]);
                        U = node[idx].U[TO];
                        Vs[X][TCN+n] = U[1] / U[0];
                        Vs[Y][TCN+n] = U[2] / U[0];
                        Vs[Z][TCN+n] = U[3] / U[0];
                    }
                    dV[X][s] = (-Vs[X][TCN+2] + 8.0 * Vs[X][TCN+1] - 8.0 * Vs[X][TCN-1] + Vs[X][TCN-2]) / (12.0 * d[s]);
                    dV[Y][s] = (-Vs[Y][TCN+2] + 8.0 * Vs[Y][TCN+1] - 8.0 * Vs[Y][TCN-1] + Vs[Y][TCN-2]) / (12.0 * d[s]);
                    dV[Z][s] = (-Vs[Z][TCN+2] + 8.0 * Vs[Z][TCN+1] - 8.0 * Vs[Z][TCN-1] + Vs[Z][TCN-2]) / (12.0 * d[s]);
                }
                idx = IndexNode(k, j, i, part->n[Y], part->n[X]);
                U = node[idx].U[TO];
                rho = U[0];
                V[X] = U[1] / U[0];
                V[Y] = U[2] / U[0];
                V[Z] = U[3] / U[0];
                W[X] = dV[Z][Y] - dV[Y][Z];
                W[Y] = dV[X][Z] - dV[Z][X];
                W[Z] = dV[Y][X] - dV[X][Y];
                Ek = Ek + rho * Dot(V,V);
                Ee = Ee + rho * Dot(W,W);
                ++N;
            }
        }
    }
    Ek = 0.5 * Ek / N;
    Ee = 0.5 * Ee / N;
    fprintf(fp, "%.6g, %.6g, %.6g\n", time->now, Ek, Ee);
    fclose(fp);
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %r15
movq %rdi, %r14
leaq 0xa493(%rip), %rdi      # 0x1d26d
leaq 0x89ae(%rip), %rsi      # 0x1b78f
callq 0x8820
movq %rax, %rbx
movq %r14, 0x40(%rsp)
cmpl $0x0, 0x8(%r14)
jne 0x12e0a
leaq 0xa489(%rip), %rdi      # 0x1d285
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2210
movq %rbx, 0x48(%rsp)
movq (%r15), %r12
movups 0x58(%r15), %xmm0
movaps %xmm0, 0x1b0(%rsp)
movsd 0x68(%r15), %xmm0
movsd %xmm0, 0x1c0(%rsp)
xorpd %xmm2, %xmm2
movapd %xmm2, 0x60(%rsp)
movapd %xmm2, 0x70(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x60(%rsp)
movl %eax, 0x70(%rsp)
movl %eax, 0x80(%rsp)
leaq 0x90(%rsp), %rax
andq $0x0, 0x10(%rax)
leaq 0x180(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movapd %xmm2, (%rax)
movapd %xmm2, (%rcx)
movapd %xmm2, 0x110(%rsp)
movapd %xmm2, 0x100(%rsp)
movapd %xmm2, 0xf0(%rsp)
movapd %xmm2, 0xe0(%rsp)
movapd %xmm2, 0xd0(%rsp)
movapd %xmm2, 0xc0(%rsp)
movapd %xmm2, 0xb0(%rsp)
andq $0x0, 0x120(%rsp)
movapd %xmm2, 0x160(%rsp)
movapd %xmm2, 0x150(%rsp)
movapd %xmm2, 0x140(%rsp)
movapd %xmm2, 0x130(%rsp)
andq $0x0, 0x170(%rsp)
movl 0xa0(%r15), %ebp
movq $0x0, 0x8(%rsp)
movq %r15, %rcx
movq %r15, 0x18(%rsp)
cmpl 0xa4(%rcx), %ebp
jge 0x13222
movl 0x98(%rcx), %r14d
movl %ebp, 0x10(%rsp)
cmpl 0x9c(%rcx), %r14d
jge 0x1321b
movslq 0x90(%rcx), %r15
movl %r14d, 0x14(%rsp)
movslq 0x94(%rcx), %rax
cmpq %rax, %r15
jge 0x13213
movapd %xmm2, 0x1a0(%rsp)
xorl %eax, %eax
movq %r15, 0x50(%rsp)
cmpq $0x3, %rax
je 0x13102
movq %rax, 0x58(%rsp)
imulq $0xc, %rax, %rax
movl 0x68(%rsp,%rax), %edx
movl 0x60(%rsp,%rax), %esi
movl 0x64(%rsp,%rax), %eax
movq %rax, 0x20(%rsp)
addl %eax, %eax
subl %eax, %r14d
movq %rdx, 0x30(%rsp)
subl %edx, %ebp
subl %edx, %ebp
movq %rsi, %rbx
movl %r15d, %r13d
subl %esi, %r13d
subl %esi, %r13d
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0x1300f
movl 0x34(%rcx), %r8d
movl 0x38(%rcx), %ecx
movl %ebp, %edi
movl %r14d, %esi
movl %r13d, %edx
callq 0x75ec
movq 0x18(%rsp), %rcx
cltq
imulq $0x88, %rax, %rax
movsd 0x10(%r12,%rax), %xmm0
movsd 0x18(%r12,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0xb0(%rsp,%r15,8)
movsd 0x20(%r12,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0xd8(%rsp,%r15,8)
movsd 0x28(%r12,%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x100(%rsp,%r15,8)
incq %r15
addl 0x20(%rsp), %r14d
addl 0x30(%rsp), %ebp
addl %ebx, %r13d
jmp 0x12f90
movsd 0xc8(%rsp), %xmm0
movsd 0xa1e8(%rip), %xmm3     # 0x1d208
mulsd %xmm3, %xmm0
subsd 0xd0(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
movsd 0xa1d2(%rip), %xmm4     # 0x1d210
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
addsd 0xb0(%rsp), %xmm1
movq 0x58(%rsp), %rax
movsd 0x1b0(%rsp,%rax,8), %xmm0
mulsd 0xa1b3(%rip), %xmm0     # 0x1d218
divsd %xmm0, %xmm1
movsd 0xf0(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd 0xf8(%rsp), %xmm2
movsd %xmm1, 0x130(%rsp,%rax,8)
movsd 0xe0(%rsp), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
addsd 0xd8(%rsp), %xmm1
movsd 0x118(%rsp), %xmm2
mulsd %xmm3, %xmm2
subsd 0x120(%rsp), %xmm2
movsd 0x108(%rsp), %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
divsd %xmm0, %xmm1
addsd 0x100(%rsp), %xmm3
movsd %xmm1, 0x148(%rsp,%rax,8)
divsd %xmm0, %xmm3
movsd %xmm3, 0x160(%rsp,%rax,8)
incq %rax
movl 0x10(%rsp), %ebp
movl 0x14(%rsp), %r14d
movq 0x50(%rsp), %r15
jmp 0x12f4f
movl 0x34(%rcx), %r8d
movl 0x38(%rcx), %ecx
movl %ebp, %edi
movl %r14d, %esi
movl %r15d, %edx
callq 0x75ec
cltq
imulq $0x88, %rax, %rax
movsd 0x10(%r12,%rax), %xmm1
movapd %xmm1, 0x30(%rsp)
movsd 0x18(%r12,%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x20(%r12,%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x28(%r12,%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movupd 0x168(%rsp), %xmm0
movupd 0x158(%rsp), %xmm1
movhpd 0x140(%rsp), %xmm0      # xmm0 = xmm0[0],mem[0]
subpd %xmm1, %xmm0
movapd %xmm0, 0x180(%rsp)
movsd 0x148(%rsp), %xmm0
subsd 0x138(%rsp), %xmm0
movsd %xmm0, 0x190(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, %rsi
callq 0x76cc
movapd %xmm0, 0x20(%rsp)
leaq 0x180(%rsp), %rdi
movq %rdi, %rsi
callq 0x76cc
movq 0x18(%rsp), %rcx
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x20(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
movapd %xmm2, %xmm0
movapd 0x1a0(%rsp), %xmm2
addpd %xmm0, %xmm2
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
incq %r15
jmp 0x12f2f
incl %r14d
jmp 0x12f16
incl %ebp
jmp 0x12eff
movsd 0x8286(%rip), %xmm0     # 0x1b4b0
movapd %xmm2, %xmm1
mulsd %xmm0, %xmm1
cvtsi2sdl 0x8(%rsp), %xmm3
divsd %xmm3, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
mulsd %xmm0, %xmm2
divsd %xmm3, %xmm2
movq 0x40(%rsp), %rax
movsd 0x48(%rax), %xmm0
leaq 0xa002(%rip), %rsi      # 0x1d25b
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movb $0x3, %al
callq 0x2160
movq %rbx, %rdi
callq 0x2080
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop