-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
52 lines (42 loc) · 1.39 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Utilities for the Aliev-Panfilov code
*
* Based on code orginally provided by Xing Cai, Simula Research Laboratory
*
* Modified and restructured by Scott B. Baden, UCSD, 11/2/2015
*/
#include <cstdlib>
#include <stdlib.h>
#include <malloc.h>
#include <iostream>
#include <assert.h>
#include <iomanip>
#include <string>
#include <math.h>
#include "apf.h"
using namespace std;
//
// Report statistics about the computation: the sums of the squares
// and the max value of the mesh
// These values should not vary (except to within roundoff)
// when we use different numbers of processes to solve the problem
// We use the sum of squares to compute the L2 norm, which is a normalized
// square root of this sum; see L2Norm() in Helper.cpp
void stats(double *E, int m, int n, double *_mx, double *sumSq){
double mx = -1;
double _sumSq = 0;
int i, j;
for (i=0; i< (m+2)*(n+2); i++) {
int rowIndex = i / (n+2); // gives the current row number in 2D array representation
int colIndex = i % (n+2); // gives the base index (first row's) of the current index
if(colIndex == 0 || colIndex == (n+1) || rowIndex == 0 || rowIndex == (m+1))
continue;
_sumSq += E[i]*E[i];
double fe = fabs(E[i]);
if (fe > mx)
mx = fe;
// printf("%d %d %9.8f\n", rowIndex, colIndex, fe);
}
*_mx = mx;
*sumSq = _sumSq;
}