-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimeVaryingThermalForce.cpp
executable file
·79 lines (66 loc) · 2.71 KB
/
TimeVaryingThermalForce.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
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
/**
* @file TimeVaryingThermalForce.cpp
* @class TimeVaryingThermalForce TimeVaryingThermalForce.h
*
* @brief Computes a random force to model thermal effects
* with a scale factor that changes with a defined function
*
* @license This file is distributed under the BSD Open Source License.
* See LICENSE.TXT for details.
**/
#include "TimeVaryingThermalForce.h"
void TimeVaryingThermalForce::force1(const double currentTime) {
heatVal = calculateHeatVal(currentTime);
ThermalForce::force1(currentTime);
}
void TimeVaryingThermalForce::force2(const double currentTime) {
heatVal = calculateHeatVal(currentTime);
ThermalForce::force2(currentTime);
}
void TimeVaryingThermalForce::force3(const double currentTime) {
heatVal = calculateHeatVal(currentTime);
ThermalForce::force3(currentTime);
}
void TimeVaryingThermalForce::force4(const double currentTime) {
heatVal = calculateHeatVal(currentTime);
ThermalForce::force4(currentTime);
}
/**
* @brief Computes strength of thermal force with function c(t) = m*t + b
where the thermal force F has form F = c(t)*L
*
* @param[in] currentTime Current simulation time
**/
inline const double TimeVaryingThermalForce::calculateHeatVal(const double currentTime) const {
return heatValScale*currentTime + heatValOffset;
}
void TimeVaryingThermalForce::writeForce(fitsfile * const file, int * const error) const {
ThermalForce::writeForce(file, error);
// add flag indicating that the thermal force is used:
if (!*error) {
long forceFlags = 0;
fits_read_key_lng(file, const_cast<char *> ("FORCES"), &forceFlags, NULL, error);
// add TimeVaryingThermalForce bit:
forceFlags |= ThermalForceFlag;
forceFlags |= TimeVaryingThermalForceFlag;
// add or update keyword:
if (!*error)
fits_update_key(file, TLONG, const_cast<char *> ("FORCES"), &forceFlags,
const_cast<char *> ("Force configuration."), error);
}
if (!*error) {
// file, key name, value, precision (scientific format), comment
fits_write_key_dbl(file, const_cast<char *> ("heatingValueScale"), heatValScale,
6, const_cast<char *> ("[N/s] (TimeVaryingThermalForce)"), error);
fits_write_key_dbl(file, const_cast<char *> ("heatingValueOffset"), heatValOffset,
6, const_cast<char *> ("[N] (TimeVaryingThermalForce)"), error);
}
}
void TimeVaryingThermalForce::readForce(fitsfile * const file, int * const error) {
ThermalForce::readForce(file, error);
if (!*error) {
// file, key name, value, don't read comment, error
fits_read_key_dbl(file, const_cast<char *> ("heatingValueScale"), &heatValScale, NULL, error);
fits_read_key_dbl(file, const_cast<char *> ("heatingValueOffset"), &heatValOffset, NULL, error);
}
}