Skip to content

Commit

Permalink
Add sound absorption
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysgoldstein committed Feb 25, 2019
1 parent 3a30c6c commit f01b35f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
39 changes: 30 additions & 9 deletions src/examples/research/building7m_advanced/acoustics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class acoustics_node : public atomic_node

// Ports:
port<flow, input, std::pair<array2d<int64>, std::pair<distance, distance>>> building_layout_input;
port<flow, input, float64> wall_sound_absorption_input;
port<flow, input, float64> floor_sound_absorption_input;
port<flow, input, float64> ceiling_sound_absorption_input;
port<message, input, std::tuple<occupant_id, array1d<int64>, quantity<decltype(_g/_m/_s/_s)>>> sound_source_input;
port<message, output, array2d<quantity<decltype(_g/_m/_s/_s)>>> sound_field_output;

Expand All @@ -33,7 +36,11 @@ class acoustics_node : public atomic_node
array2d<int64> L; // building layout
int64 nx; // number of cells in the x dimension
int64 ny; // number of cells in the y dimension
float64 wall_R; // wall resistance
distance d; // distance between cells
distance h; // height of ceiling
float64 wall_alpha; // wall sound absorption coefficient
float64 floor_alpha; // floor sound absorption coefficient
float64 ceiling_alpha; // ceiling sound absorption coefficient
array2d<quantity<decltype(_g/_m/_s/_s)>> SF; // sound field
std::map<occupant_id, std::pair<array1d<int64>, quantity<decltype(_g/_m/_s/_s)>>> S; // sound sources
array2d<std::array<float64, 4>> TLM; // transmission line matrix grid
Expand All @@ -51,6 +58,9 @@ class acoustics_node : public atomic_node
inline acoustics_node::acoustics_node(const std::string& node_name, const node_context& external_context)
: atomic_node(node_name, external_context)
, building_layout_input("building_layout_input", external_interface())
, wall_sound_absorption_input("wall_sound_absorption_input", external_interface())
, floor_sound_absorption_input("floor_sound_absorption_input", external_interface())
, ceiling_sound_absorption_input("ceiling_sound_absorption_input", external_interface())
, sound_source_input("sound_source_input", external_interface())
, sound_field_output("sound_field_output", external_interface())
{
Expand All @@ -68,7 +78,11 @@ inline duration acoustics_node::initialization_event()

nx = L.dims()[0];
ny = L.dims()[1];
wall_R = 5.0;
d = building_layout_input.value().second.first;
h = building_layout_input.value().second.second;
wall_alpha = wall_sound_absorption_input.value();
floor_alpha = floor_sound_absorption_input.value();
ceiling_alpha = ceiling_sound_absorption_input.value();
SF = array2d<quantity<decltype(_g/_m/_s/_s)>>({nx, ny}, 0_g/_m/_s/_s);
S = std::map<occupant_id, std::pair<array1d<int64>, quantity<decltype(_g/_m/_s/_s)>>>();
TLM = array2d<std::array<float64, 4>>({nx, ny}, {0.0, 0.0, 0.0, 0.0});
Expand Down Expand Up @@ -108,20 +122,27 @@ inline duration acoustics_node::planned_event(duration elapsed_dt)

// Update the TLM pressure values
auto next_TLM = array2d<std::array<float64, 4>>({nx, ny}, {0.0, 0.0, 0.0, 0.0});
float64 wall_G = 1.0 - wall_alpha;
float64 walkable_G = 1.0 - (floor_alpha + ceiling_alpha)*d/(2.0*h);
for (int64 ix = 0; ix < nx; ++ix) {
for (int64 iy = 0; iy < ny; ++iy) {
array1d<int64> pos({2}, {ix, iy});
const auto& Pxs = TLM(pos);
auto& Pxs = TLM(pos);
for (int64 idir = 0; idir < 4; ++idir) {
auto dir = directions[idir];
auto dPx = Pxs[idir]/2.0;
auto nbr_pos = pos + dir;
if ((nbr_pos(0) >= 0) && (nbr_pos(0) < nx) && (nbr_pos(1) >= 0) && (nbr_pos(1) < ny)) {
auto& nbr_Pxs = next_TLM(nbr_pos);
nbr_Pxs[idir] += dPx;
nbr_Pxs[(idir + 1)%4] += dPx;
nbr_Pxs[(idir + 2)%4] -= dPx;
nbr_Pxs[(idir + 3)%4] += dPx;
if (L(nbr_pos) == wall_code) {
Pxs[idir] = -wall_G*Pxs[idir];
}
else {
auto& nbr_Pxs = next_TLM(nbr_pos);
auto dPx = walkable_G*Pxs[idir]/2.0;
nbr_Pxs[idir] += dPx;
nbr_Pxs[(idir + 1)%4] += dPx;
nbr_Pxs[(idir + 2)%4] -= dPx;
nbr_Pxs[(idir + 3)%4] += dPx;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/examples/research/building7m_advanced/building7m.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void building7m()
{
thermodynamic_temperature average_T = thermodynamic_temperature();
try {
simulation<building_closed_system> sim(10_min, 1, std::cout);
simulation<building_closed_system> sim(5_min, 1, std::cout);
sim.top.frame_duration.set_value(250_ms);
sim.process_remaining_events();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class building_closed_system : public composite_node
building_closed_system::building_closed_system(const std::string& node_name, const node_context& external_context)
: composite_node(node_name, external_context)
, frame_duration("frame_duration", internal_context(), 30_s)
, outdoor_mean_temperature("outdoor_mean_temperature", internal_context(), 273150_mK + 20_K)
, outdoor_temperature_period("outdoor_temperature_period", internal_context(), 7_min)
, outdoor_temperature_time_step("outdoor_temperature_time_step", internal_context(), 15_s)
, outdoor_mean_temperature("outdoor_mean_temperature", internal_context(), 273150_mK + 22_K)
, outdoor_temperature_period("outdoor_temperature_period", internal_context(), 3_min)
, outdoor_temperature_time_step("outdoor_temperature_time_step", internal_context(), 5_s)
, occupant_time_constant("occupant_time_constant", internal_context(), 5_s)
, high_temperature("high_temperature", internal_context(), 273150_mK + 25_K)
, initial_temperature("initial_temperature", internal_context(), 273150_mK + 20_K)
, initial_temperature_rate("initial_temperature_rate", internal_context(), 80_mK/_s)
, initial_temperature_rate("initial_temperature_rate", internal_context(), 150_mK/_s)
, walking_speed("walking_speed", internal_context(), 1400_mm/_s)
, walking_sound("walking_sound", internal_context(), 2_g/_m/_s/_s)
, walking_sound("walking_sound", internal_context(), 10_g/_m/_s/_s)
, occupant_count("occupant_count", internal_context(), 5)
, building_info("building_info", internal_context())
, initial_positions("initial_positions", internal_context())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ building_dynamics_node::building_dynamics_node(const std::string& node_name, con
inward_link(building_layout_input, occupant_planning.building_layout_input);
inward_link(building_layout_input, occupant_steering.building_layout_input);
inward_link(wall_resistance_input, thermodynamics.wall_resistance_input);
//inward_link(wall_sound_absorption_input, acoustics.wall_sound_absorption_input);
//inward_link(floor_sound_absorption_input, acoustics.floor_sound_absorption_input);
//inward_link(ceiling_sound_absorption_input, acoustics.ceiling_sound_absorption_input);
inward_link(wall_sound_absorption_input, acoustics.wall_sound_absorption_input);
inward_link(floor_sound_absorption_input, acoustics.floor_sound_absorption_input);
inward_link(ceiling_sound_absorption_input, acoustics.ceiling_sound_absorption_input);
inward_link(initial_positions_input, occupant_planning.initial_positions_input);
inward_link(initial_positions_input, occupant_steering.initial_positions_input);
inward_link(walking_speed_input, occupant_steering.walking_speed_input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inline void building_info_node::flow_event()

// Placing interior wall cells.
int64 ix_wall = 3 + (nx - 6)/3;
for (int64 iy = 3; iy < ny - 6; ++iy) {
for (int64 iy = 3; iy < ny - 8; ++iy) {
L(ix_wall, iy) = wall_code;
}

Expand Down
10 changes: 5 additions & 5 deletions src/examples/research/building7m_advanced/building_vis_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ inline duration building_vis_node::unplanned_event(duration elapsed_dt)
inline duration building_vis_node::planned_event(duration elapsed_dt)
{
// Print grid if the frame rate is finite and the temperature field is not empty.
std::string frame_str("");
if (frame_dt.finite() && !TF.empty()) {
++frame_index;
//print("Frame " + tostring(frame_index));
std::cout << std::endl;
frame_str += ("Frame " + tostring(frame_index) += "\n");
int64 nx = TF.dims()[0];
int64 ny = TF.dims()[1];
for (int64 iy = ny - 1; iy >= 0; --iy) {
Expand Down Expand Up @@ -149,11 +149,11 @@ inline duration building_vis_node::planned_event(duration elapsed_dt)
}
line += "|";
}
std::cout << line << std::endl;
frame_str += (line + "\n");
}
std::cout << std::endl;
frame_str += "\n";
}
std::cout << std::flush;
std::cout << frame_str << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(50));
planned_dt = frame_dt;
return planned_dt;
Expand Down

0 comments on commit f01b35f

Please sign in to comment.