-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tracer_phase_changes.c
95 lines (72 loc) · 2.57 KB
/
Tracer_phase_changes.c
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
/*
Copyright (C) 1995 The GeoFramework Consortium
This file is part of Ellipsis3D.
Ellipsis3D is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2,
as published by the Free Software Foundation.
Ellipsis3D 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.
Author:
Louis Moresi <[email protected]>
*/
#include "config.h"
#include <math.h>
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#include "element_definitions.h"
#include "global_defs.h"
int get_eq_phase(
struct All_variables *E,
int tr
)
{
int phase_no,found,phase_b;
standard_precision Depth,Temp,DPhase;
if(E->tracer.Phases[E->tracer.property_group[tr]] == 1) {
E->tracer.phase_function[tr] = 1.0;
return(0);
}
if(E->data.grav_acc == 0.0) {
report(E,"Phase changes cannot be calculated because gravitational acceleration is zero");
if(E->control.verbose)
fprintf(stderr,"Phase changes cannot be calculated because gravitational acceleration is zero");
return(0);
}
/* Search in phase below each phase boundary, keep track of
phase if found and phase boundary number. If not found,
must be in the highest pressure phase above the highest
phase boundary */
phase_no=0;
phase_b=0;
found=-1;
do {
Depth = E->tracer.PZ0[E->tracer.property_group[tr]*MAX_MATERIAL_PHASES+phase_no] +
(E->tracer.T[tr] - E->tracer.PT0[E->tracer.property_group[tr]*MAX_MATERIAL_PHASES+phase_no] ) *
E->tracer.Clapeyron[E->tracer.property_group[tr]*MAX_MATERIAL_PHASES+phase_no] / (E->data.grav_acc * 0.5 *
(E->tracer.Density[E->tracer.property_group[tr]*MAX_MATERIAL_PHASES+phase_no]+
E->tracer.Density[E->tracer.property_group[tr]*MAX_MATERIAL_PHASES+phase_no+1]));
if(E->tracer.tz[tr] < Depth) {
found=phase_no;
phase_b=phase_no;
break;
}
} while (++phase_no < E->tracer.Phases[E->tracer.property_group[tr]]-1);
if(found==-1) {
phase_no=E->tracer.Phases[E->tracer.property_group[tr]]-1; /* it must be in the highest pressure phase */
phase_b=E->tracer.Phases[E->tracer.property_group[tr]]-2;
}
else {
phase_no=found;
phase_b=found;
}
E->tracer.phase_function[tr] = 0.5 * (1.0 + tanh(fabs(E->tracer.tz[tr] - Depth) / 250.0));
if(E->tracer.tz[tr] < Depth)
E->tracer.phase_function[tr] *= -1.0;
return(phase_no);
}