Ice Sheet System Model
4.18
Code documentation
src
c
shared
Numerics
NewtonSolveDnorm.cpp
Go to the documentation of this file.
1
#include <math.h>
2
#include "
./types.h
"
3
#include "../Exceptions/exceptions.h"
4
5
int
NewtonSolveDnorm
(
IssmDouble
* pdnorm,
IssmDouble
c1,
IssmDouble
c2,
IssmDouble
c3,
IssmDouble
n,
IssmDouble
dnorm){
6
/* solve the following equation using Newton-Raphson
7
*
8
* c1*x^(s-1) + c2*x = c3
9
*
10
* s = (1+n)/n
11
*
12
* we solve y = 10^x:
13
*/
14
15
/*trivial solution*/
16
if
(c3==0.){
17
*pdnorm = 0.;
18
return
0;
19
}
20
21
/*Intermediaries*/
22
int
counter = 0;
23
IssmDouble
s = (1.+n)/n;
24
IssmDouble
y2;
25
IssmDouble
threshold = 1.e-12;
26
27
/*Initial guess*/
28
_assert_
(dnorm>0.);
29
IssmDouble
y1 = log10(dnorm);
30
31
while
(
true
){
32
33
/*Newton step*/
34
y2 = y1 - (c1*pow(pow(10.,y1),s-1.) + c2*pow(10.,y1) - c3)/((s-1)*c1*log(10.)*pow(pow(10.,y1),s-1.) + c2*log(10.)*pow(10.,y1));
35
36
if
( fabs(y2-y1)/(fabs(y2))<threshold ){
37
break
;
38
}
39
else
{
40
y1=y2;
41
counter++;
42
}
43
44
if
(counter>50)
break
;
45
}
46
47
/*Avoid extremely large values that indicate non convergence*/
48
if
(y2>50.) y2 = 50;
49
50
/*Assign output pointer*/
51
*pdnorm = pow(10.,y2);
52
return
0;
53
}
_assert_
#define _assert_(ignore)
Definition:
exceptions.h:37
IssmDouble
double IssmDouble
Definition:
types.h:37
types.h
prototypes for types.h
NewtonSolveDnorm
int NewtonSolveDnorm(IssmDouble *pdnorm, IssmDouble c1, IssmDouble c2, IssmDouble c3, IssmDouble n, IssmDouble dnorm)
Definition:
NewtonSolveDnorm.cpp:5
Generated on Thu Jul 2 2020 08:09:22 for Ice Sheet System Model by
1.8.19