General Question Using GetAtmTemperature to get temperature above Earth's atmosphere

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
I have a problem, I want to simulate the temperature in the empty space above the Earth's atmosphere in degrees Celsius.

Using the function GetAtmTemperature above 100 km altitude the temperature is increased to 500 600 degrees, at an altitude of 2500 km the temperature falls to -273 °C

Using this simple formula I solved the problem with the Earth's orbit
Code:
double TMP1 = (GetAtmTemperature()-273.15);// temp in celsius
double ATMP = GetAtmPressure()/100;
double TMP1a ;
 
if (ATMP<1)
{
TMP1a = TMP1*-0.229;
if (TMP1a < 273)TMP1a = 273;
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT]SetTextColor (hDC, RGB(220,220,220));
sprintf(cbuf,"ET %.0f°C",TMP1a);
TextOut(hDC,10,10,cbuf,strlen(cbuf));
}
if (ATMP>1)
{
SetTextColor (hDC, RGB(220,220,220));
sprintf(cbuf,"ET %.0f°C",TMP1);
TextOut(hDC,10,10,cbuf,strlen(cbuf));
}
So the temperature in the space reaches -150 ° c

In the other planets atmosphere will have to change the parameter of reductionTMP1a I think....

My question is, how do I tell the code to change a parameter when I get closer to Mars for example?
 

vchamp

Member
Joined
Mar 24, 2008
Messages
221
Reaction score
6
Points
18
Maybe when a returning value of GetGravityRef() changes?
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Maybe when a returning value of GetGravityRef() changes?

I think this is the solution, I'll have to find ways to apply it.

I also believe that the temperature in space should decrease when you move away from the sun, near the orbit of Mercury should be very high, while in the outer orbits of the planets should be very low.
 

vchamp

Member
Joined
Mar 24, 2008
Messages
221
Reaction score
6
Points
18
If you wish, I can give you my old code that I used for Interplanetary Modular Ship, which calculates the heat from sun's radiation depending on a distance to it and also takes in account whether the ship is in a planet's shadow.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Please note that GetAtmTemperature returns the atmospheric temperature, as defined by kinetic energy of the gas molecules. Without atmosphere, there is no atmospheric temperature. This is the reason why orbiter returns 0 for points outside the defined atmospheric hulls. Of course this means a discontinuity at the atmospheric boundary, from exospheric temperature to zero, but this is irrelevant in practice, since at these altitudes the "atmosphere" simply consists of the occasional molecule whose trajectory is governed by gravity rather than interaction.

I think you are not talking about atmospheric temperature, but radiation temperature, i.e. the equilibrium temperature of a test body irradiated by the sun at a given distance. This has very little to with atmospheric temperature and should be calculated independently. It's not very hard, involves solar flux, cross section, geometry, albedo, probably material heat capacity - anything else?
 

Eli13

Fish Dreamer
Joined
Mar 5, 2011
Messages
1,562
Reaction score
0
Points
0
Location
Somewhere, TN
Please note that GetAtmTemperature returns the atmospheric temperature, as defined by kinetic energy of the gas molecules. Without atmosphere, there is no atmospheric temperature. This is the reason why orbiter returns 0 for points outside the defined atmospheric hulls. Of course this means a discontinuity at the atmospheric boundary, from exospheric temperature to zero, but this is irrelevant in practice, since at these altitudes the "atmosphere" simply consists of the occasional molecule whose trajectory is governed by gravity rather than interaction.

I think you are not talking about atmospheric temperature, but radiation temperature, i.e. the equilibrium temperature of a test body irradiated by the sun at a given distance. This has very little to with atmospheric temperature and should be calculated independently. It's not very hard, involves solar flux, cross section, geometry, albedo, probably material heat capacity - anything else?

This guy amazes me.
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Look at the source code of Precession MFD, there are equilibrium radiation temp calculations for a solar sail.
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Please note that GetAtmTemperature returns the atmospheric temperature, as defined by kinetic energy of the gas molecules. Without atmosphere, there is no atmospheric temperature. This is the reason why orbiter returns 0 for points outside the defined atmospheric hulls.


yes ok, so I wanted to create a formula that would allow me to switch from kinetic heat, heat radiation.

If I go out with my ship by the atmosphere, the heat will decrease gradually because my ship will absorb more heat and less heat radiated kinetic.

The radiated heat will be higher close to the sun, and less as I move away from it

Look at the source code of Precession MFD, there are equilibrium radiation temp calculations for a solar sail.

Will look
 

vchamp

Member
Joined
Mar 24, 2008
Messages
221
Reaction score
6
Points
18
I'm not sure that this code is totally correct, but I think it should be.

Update environment data at sim step:
Code:
const double STBOLC = 5.67e-8;
const double SUNIRRADIANCE = 304.697664e23;

void EnvCalc::UpdateEnvironment() {

    // calculate heat from the sun
    vessel->GetGlobalPos(vesselGlobalPos);
    sunDist = length(vesselGlobalPos);
    sunEnergy = SUNIRRADIANCE / (sunDist * sunDist);

    // determine whether the vessel is in shadow
    OBJHANDLE gravRef = vessel->GetGravityRef();
    VECTOR3 gravRefPos;
    oapiGetGlobalPos(gravRef, &gravRefPos);
    double gravRefDist = length(gravRefPos);
    if (gravRefDist < 100) {
        // the gravity reference is the sun
        inShadow = false;
        return;
    }

    if (sunDist < gravRefDist) {
        inShadow = false;
        return;
    }

    VECTOR3 perp = crossp(gravRefPos, _V(0, 0, 1));
    perp *= oapiGetSize(gravRef) / length(perp);
    VECTOR3 edgePos = gravRefPos + perp;
    double edgeDist = length(edgePos);
    
    double cosVessel = dotp(gravRefPos, vesselGlobalPos) / (gravRefDist * sunDist);
    double cosEdge = dotp(gravRefPos, edgePos) / (gravRefDist * edgeDist);
    inShadow = (cosVessel > cosEdge);
}

Get temperature at the ship's surface:
Code:
double EnvCalc::GetExternalTemperature(double cosSurfaceSunAngle, double absorptance) {
    double qSun = 0;
    double qAl = 0;
    if (!inShadow) {
        qSun = cosSurfaceSunAngle * sunEnergy;
    }
    // Q = S * T^4 / a
    double totalHeat = qSun + qAl;
    return pow(totalHeat * absorptance / STBOLC, 0.25);
}
cosSurfaceSunAngle - a cosine of angle between surface normal and direction to the sun
absorptance - surface material absorptance
qAl - should be energy from albedo radiation but i ignore it here
 

Rtyh-12

New member
Joined
Sep 12, 2010
Messages
918
Reaction score
0
Points
0
Location
Kraken Mare
He made Orbiter, what did you expect? He knows the entire code (or at least, he can look at it whenever he wants). Of course he knows everything about Orbiter. ;)
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Well, I managed to do something with your help:

Code:
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]VECTOR3 sun = _V(0,0,0); 
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]GetGlobalPos(sun);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] sunDist = length(sun);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] sunEnergy = SUNIRRADIANCE / (sunDist * sunDist);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] sunDist1 = ((sunDist/1e9)) ;
OBJHANDLE gravRef = GetGravityRef();
VECTOR3 gravRefPos;
oapiGetGlobalPos(gravRef, &gravRefPos);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] gravRefDist = length(gravRefPos);
VECTOR3 perp = crossp(gravRefPos, _V(0, 0, 1));
perp *= oapiGetSize(gravRef) / length(perp);
VECTOR3 edgePos = gravRefPos + perp;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] edgeDist = length(edgePos);
VECTOR3 (vesselGlobalPos);
GetGlobalPos(vesselGlobalPos);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] cosVessel = dotp(gravRefPos, vesselGlobalPos) / (gravRefDist * sunDist);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] cosEdge = dotp(gravRefPos, edgePos) / (gravRefDist * edgeDist);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] inShadow = (cosVessel > cosEdge);
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (gravRefDist < 100) {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// the gravity reference is the sun
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]inShadow = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// return true;
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (sunDist < gravRefDist) {
inShadow = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// return true;
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] cosSurfaceSunAngle;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] absorptance;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] qSun = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] qAl = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (!inShadow) {
qSun = cosSurfaceSunAngle * sunEnergy;
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] totalHeat = qSun + qAl;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] pow=(totalHeat * absorptance) / (STBOLC, 0.25);
OBJHANDLE GetGravityRef ;

[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// return false;
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] 
 
[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]sprintf(oapiDebugString(),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#a31515][FONT=Courier New][SIZE=2][COLOR=#a31515][FONT=Courier New][SIZE=2][COLOR=#a31515]"DistSun: %.2f EnergySun: %.2f Inshadow: %.2f Pow: %.2f Trim: %.2f"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],sunDist1,sunEnergy,inShadow,pow,G );[/SIZE][/FONT][/SIZE][/FONT]
:cheers:

Now I have another question related to the project .... how do I know my ship in orbit which is it?

I do not know what I mean, I have to tell the program "you are orbiting above the earth "... or" you're orbiting above Mars' in oapidebugString?
 

vchamp

Member
Joined
Mar 24, 2008
Messages
221
Reaction score
6
Points
18
Again use GetGravityRef(), which returns a handle to the main gravity contributor at the vessel's position. And oapiGetObjectName() to get a celestial body name.
 

Wishbone

Clueless developer
Addon Developer
Joined
Sep 12, 2010
Messages
2,421
Reaction score
1
Points
0
Location
Moscow
Marco, have a look at the Precession MFD code for more clues. vchamp has already pointed you to the chain of calls you have to make: 1. get gravity reference (a handle). 2. use the handle to get the object's name.
 
Top