File: scalar_test_poisson.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (154 lines) | stat: -rw-r--r-- 3,716 bytes parent folder | download | duplicates (2)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Method of class Scalar to check if a Poisson equation has been correctly
 * solved.
 *
 * (see file cmp.h for documentation)
 *
 */

/*
 *   Copyright (c) 2003 Eric Gourgoulhon & Jerome Novak
 *
 *   Copyright (c) 2000-2001 Eric Gourgoulhon (for a preceding Cmp version)
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


char scalar_test_poisson_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_test_poisson.C,v 1.4 2014/10/13 08:53:47 j_novak Exp $" ;

/*
 * $Id: scalar_test_poisson.C,v 1.4 2014/10/13 08:53:47 j_novak Exp $
 * $Log: scalar_test_poisson.C,v $
 * Revision 1.4  2014/10/13 08:53:47  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.3  2003/10/29 13:14:29  e_gourgoulhon
 * Change of method name: laplacien --> laplacian.
 *
 * Revision 1.2  2003/10/01 13:04:44  e_gourgoulhon
 * The method Tensor::get_mp() returns now a reference (and not
 * a pointer) onto a mapping.
 *
 * Revision 1.1  2003/09/25 09:13:11  e_gourgoulhon
 * First version.
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_test_poisson.C,v 1.4 2014/10/13 08:53:47 j_novak Exp $
 *
 */

// Headers Lorene
#include "tensor.h"

namespace Lorene {
Tbl Scalar::test_poisson(const Scalar& uu, ostream& ostr, bool detail) const {
    
    assert( &(uu.get_mp()) == mp ) ; 
    
    // Computation of the absolute and relative errors
    // -----------------------------------------------
    
    int dzi ;
    if ( check_dzpuis(4) ) {
	dzi = 4 ; 
    }
    else{
	if ( check_dzpuis(2) ) {
	    dzi = 2 ; 
	}
	else{
	    assert( check_dzpuis(0) ) ; 
	    dzi = 0 ; 
	}
    }
    
    Tbl tdiff = max( abs( uu.laplacian(dzi) - *this ) ) ;

    Tbl tmax = max( abs(*this) ) ; 
    
    int nz = mp->get_mg()->get_nzone() ; 
    int nzm1 = nz - 1 ; 
    
    Tbl trel(nz) ; 
    trel.set_etat_qcq() ; 

    if ( (dzpuis == 0) || (tmax(nzm1) == double(0)) ) {

	double s_max = max( tmax ) ; 

	for (int l=0; l<nz; l++) {
	    trel.set(l) = tdiff(l) / s_max ;     
	}

    }
    else{

	double s_max = 0 ; 
	for (int l=0; l<nzm1; l++) {
	    s_max = (tmax(l) > s_max) ? tmax(l) : s_max ;     
	}

	for (int l=0; l<nzm1; l++) {
	    trel.set(l) = tdiff(l) / s_max ;     
	}

	trel.set(nzm1) = tdiff(nzm1) / tmax(nzm1) ; 

    }
    
    // All the errors are set in the same output 2-D Tbl
    // -------------------------------------------------

    Tbl err(3, nz) ; 
    
    err.set_etat_qcq() ; 
    
    for(int l=0; l<nz; l++) {
	err.set(0, l) = trel(l) ; 
	err.set(1, l) = tdiff(l) ; 
	err.set(2, l) = tmax(l) ; 
    }

    // Display
    // -------
    
    if (detail) {
	ostr << "Max. source :" ;
	for (int l=0; l<nz; l++) {
	    ostr << "  " << err(2, l) ;
	}
    
	ostr << endl << "Abs. error : " ;
	for (int l=0; l<nz; l++) {
	    ostr << "  " << err(1, l) ;
	}
    }
    
    ostr << endl << "Rel. error : " ;
    for (int l=0; l<nz; l++) {
	ostr << "  " << err(0, l) ;
    }
    
    ostr << endl ; 
    
    return err ; 

}

}