Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Smart Grid Modell
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
Smart Grid Modell
Commits
630fd566
Commit
630fd566
authored
Aug 31, 2020
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Update modell state.
parent
dfea1452
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ControlMessags.hpp
+14
-0
14 additions, 0 deletions
src/ControlMessags.hpp
src/smg_server.cpp
+47
-12
47 additions, 12 deletions
src/smg_server.cpp
with
61 additions
and
12 deletions
src/ControlMessags.hpp
0 → 100644
+
14
−
0
View file @
630fd566
/// @file ControlMessages.hpp
///
#ifndef CONTROL_MESSAGES_HPP
#define CONTROL_MESSAGES_HPP
#include
<string>
enum
class
CtrlMsgs
{
};
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/smg_server.cpp
+
47
−
12
View file @
630fd566
...
@@ -22,12 +22,15 @@ struct PowerProduction
...
@@ -22,12 +22,15 @@ struct PowerProduction
{
{
double
conventional
;
double
conventional
;
CleanPower
renewable
;
CleanPower
renewable
;
double
clean
(){
return
renewable
.
solar
+
renewable
.
wind
;}
double
sum
(){
return
conventional
+
clean
();}
};
};
struct
PowerUsage
struct
PowerUsage
{
{
double
village
=
0.0
;
double
village
=
0.0
;
double
industry
=
0.0
;
double
industry
=
0.0
;
double
sum
()
{
return
village
+
industry
;}
};
};
...
@@ -35,7 +38,6 @@ struct PowerUsage
...
@@ -35,7 +38,6 @@ struct PowerUsage
///
///
struct
MaxPower
struct
MaxPower
{
{
static
constexpr
double
conventional
=
600
;
static
constexpr
double
village
=
600
;
static
constexpr
double
village
=
600
;
static
constexpr
double
industry
=
200
;
static
constexpr
double
industry
=
200
;
static
constexpr
double
wind
=
250
;
static
constexpr
double
wind
=
250
;
...
@@ -65,7 +67,8 @@ constexpr double power_wind[] {
...
@@ -65,7 +67,8 @@ constexpr double power_wind[] {
class
ModelState
class
ModelState
{
{
public:
public:
ModelState
()
ModelState
(
SmartGridModell
&
modell
)
:
m_modell
{
modell
}
{
{
std
::
srand
(
std
::
time
(
nullptr
));
std
::
srand
(
std
::
time
(
nullptr
));
}
}
...
@@ -75,8 +78,9 @@ public:
...
@@ -75,8 +78,9 @@ public:
update_time
();
update_time
();
update_sun
();
update_sun
();
update_wind
();
update_wind
();
update_power_production
();
update_power_consumption
();
update_power_consumption
();
update_power_production
();
update_modell
();
print_states
();
print_states
();
}
}
...
@@ -109,12 +113,6 @@ private:
...
@@ -109,12 +113,6 @@ private:
auto
random_wind
=
((
std
::
rand
()
*
1.0
)
/
RAND_MAX
)
*
7.0
;
auto
random_wind
=
((
std
::
rand
()
*
1.0
)
/
RAND_MAX
)
*
7.0
;
m_wind
=
power_wind
[
static_cast
<
int
>
(
wind_by_sun
+
random_wind
)];
m_wind
=
power_wind
[
static_cast
<
int
>
(
wind_by_sun
+
random_wind
)];
}
}
void
update_power_production
()
{
m_production
.
renewable
.
solar
=
m_sun
*
solar_size
;
m_production
.
renewable
.
wind
=
m_wind
*
windpark_size
;
m_production
.
conventional
=
MaxPower
::
conventional
;
}
void
update_power_consumption
()
void
update_power_consumption
()
{
{
m_usage
.
village
=
village_consumption_at
[
m_time
]
*
village_size
;
m_usage
.
village
=
village_consumption_at
[
m_time
]
*
village_size
;
...
@@ -127,6 +125,40 @@ private:
...
@@ -127,6 +125,40 @@ private:
m_usage
.
industry
=
0.0
;
m_usage
.
industry
=
0.0
;
}
}
}
}
void
update_power_production
()
{
m_production
.
renewable
.
solar
=
m_sun
*
solar_size
;
m_production
.
renewable
.
wind
=
m_wind
*
windpark_size
;
if
(
m_usage
.
sum
()
>
m_production
.
clean
())
{
m_excess_power
=
0.0
;
m_production
.
conventional
=
m_usage
.
sum
()
-
m_production
.
clean
();
}
else
{
m_excess_power
=
m_production
.
clean
()
-
m_usage
.
sum
();
m_production
.
conventional
=
0
;
}
}
void
update_modell
()
{
auto
sun
=
m_sun
*
2.5
;
auto
wind
=
m_wind
/
8.3
;
auto
renewable
=
(
sun
+
wind
)
/
2
;
m_modell
.
set_solar_plant
(
sun
);
m_modell
.
set_windmill_net
(
wind
);
m_modell
.
set_renewable_net
(
renewable
);
if
(
m_production
.
conventional
>
0
)
{
m_modell
.
set_power_plant
(
200
);
m_modell
.
set_village_color
(
200
,
renewable
);
}
else
{
m_modell
.
set_power_plant
(
0
);
m_modell
.
set_village_color
(
0
,
renewable
);
}
}
static
constexpr
double
solar_size
{
10
};
static
constexpr
double
solar_size
{
10
};
...
@@ -136,9 +168,11 @@ private:
...
@@ -136,9 +168,11 @@ private:
int
m_time
{
0
};
int
m_time
{
0
};
double
m_sun
{
0
};
double
m_sun
{
0
};
double
m_wind
{
0
};
double
m_wind
{
0
};
double
m_excess_power
{
0.0
};
PowerProduction
m_production
;
PowerProduction
m_production
;
PowerUsage
m_usage
;
PowerUsage
m_usage
;
bool
m_producing
{
false
};
bool
m_producing
{
false
};
SmartGridModell
&
m_modell
;
void
print_states
()
void
print_states
()
{
{
...
@@ -168,7 +202,7 @@ void run_sim()
...
@@ -168,7 +202,7 @@ void run_sim()
modell
.
put_modell_into_state
(
SmartGridModell
::
DefaultState
::
Off
);
modell
.
put_modell_into_state
(
SmartGridModell
::
DefaultState
::
Off
);
ModelState
day
{};
ModelState
day
{
modell
};
bool
active
{
true
};
bool
active
{
true
};
while
(
active
)
while
(
active
)
...
@@ -190,7 +224,8 @@ void test_x64()
...
@@ -190,7 +224,8 @@ void test_x64()
ServerSocket
server
(
8080
);
ServerSocket
server
(
8080
);
bool
finished
{
false
};
bool
finished
{
false
};
ModelState
day
{};
SmartGridModell
modell
{
i2c_device
,
SmartGridModell
::
DefaultState
::
Fancy
};
ModelState
day
{
modell
};
while
(
!
finished
)
while
(
!
finished
)
{
{
DataSocket
accept
=
server
.
accept
();
DataSocket
accept
=
server
.
accept
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment