FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
core::World Class Reference

The World class manages the simulator environment. More...

#include "world.h"

Public Member Functions

 World ()=default
 
 ~World () noexcept=default
 
 World (const World &)=delete
 
Worldoperator= (const World &)=delete
 
 World (World &&)=delete
 
Worldoperator= (World &&)=delete
 
void add (std::unique_ptr< radar::Platform > plat) noexcept
 Adds a radar platform to the simulation world.
 
void add (std::unique_ptr< radar::Transmitter > trans) noexcept
 Adds a radar transmitter to the simulation world.
 
void add (std::unique_ptr< radar::Receiver > recv) noexcept
 Adds a radar receiver to the simulation world.
 
void add (std::unique_ptr< radar::Target > target) noexcept
 Adds a radar target to the simulation world.
 
void add (std::unique_ptr< fers_signal::RadarSignal > waveform)
 Adds a radar signal (waveform) to the simulation world.
 
void add (std::unique_ptr< antenna::Antenna > antenna)
 Adds an antenna to the simulation world.
 
void add (std::unique_ptr< timing::PrototypeTiming > timing)
 Adds a timing source to the simulation world.
 
fers_signal::RadarSignalfindWaveform (const SimId id)
 Finds a radar signal by ID.
 
antenna::AntennafindAntenna (const SimId id)
 Finds an antenna by ID.
 
timing::PrototypeTimingfindTiming (const SimId id)
 Finds a timing source by ID.
 
radar::PlatformfindPlatform (const SimId id)
 Finds a platform by ID.
 
radar::TransmitterfindTransmitter (const SimId id)
 Finds a transmitter by ID.
 
radar::TransmitterfindTransmitterByName (const std::string &name)
 Finds a transmitter by name.
 
radar::ReceiverfindReceiver (const SimId id)
 Finds a receiver by ID.
 
fers_signal::RadarSignalfindWaveformByName (const std::string &name)
 Finds a waveform by name.
 
RealType earliestPhaseNoiseLookupStart () const
 Finds the earliest simulation time that can require CW phase-noise samples.
 
radar::TargetfindTarget (const SimId id)
 Finds a target by ID.
 
void replace (std::unique_ptr< radar::Target > target)
 Replaces an existing target, updating internal pointers.
 
void replace (std::unique_ptr< antenna::Antenna > antenna)
 Replaces an existing antenna, updating internal pointers.
 
void replace (std::unique_ptr< fers_signal::RadarSignal > waveform)
 Replaces an existing waveform, updating internal pointers.
 
void replace (std::unique_ptr< timing::PrototypeTiming > timing)
 Replaces an existing timing prototype and refreshes dependent radar timing models.
 
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms () const noexcept
 Retrieves the list of platforms.
 
const std::vector< std::unique_ptr< radar::Target > > & getTargets () const noexcept
 Retrieves the list of radar targets.
 
const std::vector< std::unique_ptr< radar::Receiver > > & getReceivers () const noexcept
 Retrieves the list of radar receivers.
 
const std::vector< std::unique_ptr< radar::Transmitter > > & getTransmitters () const noexcept
 Retrieves the list of radar transmitters.
 
const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms () const noexcept
 Retrieves the map of radar signals (waveforms).
 
const std::unordered_map< SimId, std::unique_ptr< antenna::Antenna > > & getAntennas () const noexcept
 Retrieves the map of antennas.
 
const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & getTimings () const noexcept
 Retrieves the map of timing prototypes.
 
void clear () noexcept
 Clears all objects and assets from the simulation world.
 
void swap (World &other) noexcept
 Exchanges all owned world state with another world.
 
void scheduleInitialEvents ()
 Populates the event queue with the initial events for the simulation.
 
void resolveReceiverDechirpReferences ()
 Resolves and validates receiver FMCW dechirp references after all components are loaded.
 
std::string dumpEventQueue () const
 Dumps the current state of the event queue to a string for debugging.
 
std::priority_queue< Event, std::vector< Event >, EventComparator > & getEventQueue () noexcept
 Gets a mutable reference to the global event queue.
 
SimulationStategetSimulationState () noexcept
 Gets a mutable reference to the global simulation state.
 

Detailed Description

The World class manages the simulator environment.

Definition at line 38 of file world.h.

Constructor & Destructor Documentation

◆ World() [1/3]

core::World::World ( )
default

◆ ~World()

core::World::~World ( )
defaultnoexcept

◆ World() [2/3]

core::World::World ( const World )
delete

◆ World() [3/3]

core::World::World ( World &&  )
delete

Member Function Documentation

◆ add() [1/7]

void core::World::add ( std::unique_ptr< antenna::Antenna antenna)

Adds an antenna to the simulation world.

Parameters
antennaA unique pointer to an Antenna object.
Exceptions
std::runtime_errorif an antenna with the same ID already exists.

Definition at line 133 of file world.cpp.

134 {
135 const SimId id = antenna->getId();
136 if (_antennas.contains(id))
137 {
138 throw std::runtime_error("An antenna with the ID " + std::to_string(id) + " already exists.");
139 }
140 _antennas[id] = std::move(antenna);
141 }
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
math::Vec3 max

References max.

◆ add() [2/7]

void core::World::add ( std::unique_ptr< fers_signal::RadarSignal waveform)

Adds a radar signal (waveform) to the simulation world.

Parameters
waveformA unique pointer to a RadarSignal object.
Exceptions
std::runtime_errorif a waveform with the same ID already exists.

Definition at line 122 of file world.cpp.

123 {
124 const SimId id = waveform->getId();
125 if (_waveforms.contains(id))
126 {
127 throw std::runtime_error("A waveform with the ID " + std::to_string(id) + " already exists.");
128 }
129 _waveform_ids_by_name[waveform->getName()] = id;
130 _waveforms[id] = std::move(waveform);
131 }

References max.

◆ add() [3/7]

void core::World::add ( std::unique_ptr< radar::Platform plat)
noexcept

Adds a radar platform to the simulation world.

Parameters
platA unique pointer to a Platform object.

Definition at line 110 of file world.cpp.

110{ _platforms.push_back(std::move(plat)); }

References max.

◆ add() [4/7]

void core::World::add ( std::unique_ptr< radar::Receiver recv)
noexcept

Adds a radar receiver to the simulation world.

Parameters
recvA unique pointer to a Receiver object.

Definition at line 118 of file world.cpp.

118{ _receivers.push_back(std::move(recv)); }

References max.

◆ add() [5/7]

void core::World::add ( std::unique_ptr< radar::Target target)
noexcept

Adds a radar target to the simulation world.

Parameters
targetA unique pointer to a Target object.

Definition at line 120 of file world.cpp.

120{ _targets.push_back(std::move(target)); }

References max.

◆ add() [6/7]

void core::World::add ( std::unique_ptr< radar::Transmitter trans)
noexcept

Adds a radar transmitter to the simulation world.

Parameters
transA unique pointer to a Transmitter object.

Definition at line 112 of file world.cpp.

113 {
114 _transmitters_by_name[trans->getName()] = trans.get();
115 _transmitters.push_back(std::move(trans));
116 }

References max.

◆ add() [7/7]

void core::World::add ( std::unique_ptr< timing::PrototypeTiming timing)

Adds a timing source to the simulation world.

Parameters
timingA unique pointer to a PrototypeTiming object.
Exceptions
std::runtime_errorif a timing source with the same ID already exists.

Definition at line 143 of file world.cpp.

144 {
145 const SimId id = timing->getId();
146 if (_timings.contains(id))
147 {
148 throw std::runtime_error("A timing source with the ID " + std::to_string(id) + " already exists.");
149 }
150 _timings[id] = std::move(timing);
151 }

References max.

◆ clear()

void core::World::clear ( )
noexcept

Clears all objects and assets from the simulation world.

Definition at line 408 of file world.cpp.

409 {
410 _platforms.clear();
411 _transmitters.clear();
412 _transmitters_by_name.clear();
413 _receivers.clear();
414 _targets.clear();
415 _waveforms.clear();
416 _waveform_ids_by_name.clear();
417 _antennas.clear();
418 _timings.clear();
419 _event_queue = {};
420 _simulation_state = {};
421 }

Referenced by serial::parseSimulation(), and serial::parseSimulationFromString().

+ Here is the caller graph for this function:

◆ dumpEventQueue()

std::string core::World::dumpEventQueue ( ) const

Dumps the current state of the event queue to a string for debugging.

Returns
A formatted string representing the contents of the event queue.

Definition at line 619 of file world.cpp.

620 {
621 if (_event_queue.empty())
622 {
623 return "Event Queue is empty.\n";
624 }
625
626 std::stringstream ss;
627 ss << std::fixed << std::setprecision(6);
628
629 const std::string separator = "--------------------------------------------------------------------";
630 const std::string title = "| Event Queue Contents (" + std::to_string(_event_queue.size()) + " events)";
631 if (separator.size() > static_cast<std::size_t>(std::numeric_limits<int>::max()))
632 {
633 throw std::runtime_error("Separator width exceeds stream formatting limits.");
634 }
635 const int title_width = static_cast<int>(separator.size()) - 1;
636
637 ss << separator << "\n"
638 << std::left << std::setw(title_width) << title << "|\n"
639 << separator << "\n"
640 << "| " << std::left << std::setw(12) << "Timestamp" << " | " << std::setw(21) << "Event Type" << " | "
641 << std::setw(25) << "Source Object" << " |\n"
642 << separator << "\n";
643
644 auto queue_copy = _event_queue;
645
646 while (!queue_copy.empty())
647 {
648 const auto [timestamp, event_type, source_object] = queue_copy.top();
649 queue_copy.pop();
650
651 ss << "| " << std::right << std::setw(12) << timestamp << " | " << std::left << std::setw(21)
652 << toString(event_type) << " | " << std::left << std::setw(25) << source_object->getName() << " |\n";
653 }
654 ss << separator << "\n";
655
656 return ss.str();
657 }
std::string toString(const EventType type)
Converts an EventType enum to its string representation.
Definition sim_events.h:74

References max, and core::toString().

+ Here is the call graph for this function:

◆ earliestPhaseNoiseLookupStart()

RealType core::World::earliestPhaseNoiseLookupStart ( ) const

Finds the earliest simulation time that can require CW phase-noise samples.

Includes active streaming transmitters and receivers. Pre-start transmitter periods that cross the simulation start are included so retarded emissions can sample transmitter phase noise before t_start.

Returns
Earliest required lookup time, or params::startTime() if no streaming component overlaps.

Definition at line 209 of file world.cpp.

210 {
211 const auto include_streaming_interval_start = [](std::optional<RealType>& earliest,
212 const RealType segment_start, const RealType segment_end,
213 const bool allow_pre_start)
214 {
218 {
219 return;
220 }
221
223 allow_pre_start && segment_start < sim_start ? segment_start : std::max(sim_start, segment_start);
224 earliest = earliest.has_value() ? std::min(*earliest, required_start) : required_start;
225 };
226
227 std::optional<RealType> earliest;
228 for (const auto& transmitter_ptr : _transmitters)
229 {
230 if (transmitter_ptr == nullptr || !transmitter_ptr->isStreamingMode())
231 {
232 continue;
233 }
234
235 const auto& schedule = transmitter_ptr->getSchedule();
236 if (schedule.empty())
237 {
239 continue;
240 }
241
242 for (const auto& period : schedule)
243 {
245 }
246 }
247
248 for (const auto& receiver_ptr : _receivers)
249 {
250 if (receiver_ptr == nullptr ||
254 {
255 continue;
256 }
257
258 const auto& schedule = receiver_ptr->getSchedule();
259 if (schedule.empty())
260 {
262 continue;
263 }
264
265 for (const auto& period : schedule)
266 {
268 }
269 }
270
271 return earliest.value_or(params::startTime());
272 }
double RealType
Type for real numbers.
Definition config.h:27
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:109
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:103
@ SFCW_MODE
The component operates in a stepped-frequency CW streaming mode.
@ CW_MODE
The component operates in a continuous-wave mode.
@ FMCW_MODE
The component operates in an FMCW streaming mode.

References radar::CW_MODE, params::endTime(), radar::FMCW_MODE, max, radar::SFCW_MODE, and params::startTime().

Referenced by core::projectSimulationMemory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findAntenna()

Antenna * core::World::findAntenna ( const SimId  id)

Finds an antenna by ID.

Parameters
idThe ID of the antenna to find.
Returns
A pointer to the Antenna if found, or nullptr if not found.

Definition at line 159 of file world.cpp.

160 {
161 const auto it = _antennas.find(id);
162 return it != _antennas.end() ? it->second.get() : nullptr;
163 }

References max.

Referenced by serial::update_monostatic_receiver_basics(), serial::update_receiver_antenna_from_json(), and serial::update_transmitter_antenna_from_json().

+ Here is the caller graph for this function:

◆ findPlatform()

Platform * core::World::findPlatform ( const SimId  id)

Finds a platform by ID.

Parameters
idThe ID of the platform to find.
Returns
A pointer to the Platform if found, or nullptr if not found.

Definition at line 171 of file world.cpp.

172 {
173 for (auto& p : _platforms)
174 {
175 if (p->getId() == id)
176 return p.get();
177 }
178 return nullptr;
179 }

References max.

Referenced by fers_update_platform_from_json().

+ Here is the caller graph for this function:

◆ findReceiver()

Receiver * core::World::findReceiver ( const SimId  id)

Finds a receiver by ID.

Parameters
idThe ID of the receiver to find.
Returns
A pointer to the Receiver if found, or nullptr if not found.

Definition at line 195 of file world.cpp.

196 {
197 for (auto& rx : _receivers)
198 if (rx->getId() == id)
199 return rx.get();
200 return nullptr;
201 }

References max.

Referenced by fers_update_receiver_from_json().

+ Here is the caller graph for this function:

◆ findTarget()

Target * core::World::findTarget ( const SimId  id)

Finds a target by ID.

Parameters
idThe ID of the target to find.
Returns
A pointer to the Target if found, or nullptr if not found.

Definition at line 274 of file world.cpp.

275 {
276 for (auto& tgt : _targets)
277 if (tgt->getId() == id)
278 return tgt.get();
279 return nullptr;
280 }

References max.

Referenced by fers_update_target_from_json().

+ Here is the caller graph for this function:

◆ findTiming()

PrototypeTiming * core::World::findTiming ( const SimId  id)

Finds a timing source by ID.

Parameters
idThe ID of the timing source to find.
Returns
A pointer to the PrototypeTiming if found, or nullptr if not found.

Definition at line 165 of file world.cpp.

166 {
167 const auto it = _timings.find(id);
168 return it != _timings.end() ? it->second.get() : nullptr;
169 }

References max.

Referenced by serial::update_monostatic_timing_from_json(), serial::update_receiver_timing_from_json(), serial::update_timing_from_json(), and serial::update_transmitter_timing_from_json().

+ Here is the caller graph for this function:

◆ findTransmitter()

Transmitter * core::World::findTransmitter ( const SimId  id)

Finds a transmitter by ID.

Parameters
idThe ID of the transmitter to find.
Returns
A pointer to the Transmitter if found, or nullptr if not found.

Definition at line 181 of file world.cpp.

182 {
183 for (auto& tx : _transmitters)
184 if (tx->getId() == id)
185 return tx.get();
186 return nullptr;
187 }

References max.

Referenced by fers_update_transmitter_from_json().

+ Here is the caller graph for this function:

◆ findTransmitterByName()

Transmitter * core::World::findTransmitterByName ( const std::string &  name)

Finds a transmitter by name.

Parameters
nameThe transmitter name to find.
Returns
A pointer to the Transmitter if found, or nullptr if not found.

Definition at line 189 of file world.cpp.

190 {
191 const auto it = _transmitters_by_name.find(name);
192 return it != _transmitters_by_name.end() ? it->second : nullptr;
193 }

References max.

Referenced by resolveReceiverDechirpReferences().

+ Here is the caller graph for this function:

◆ findWaveform()

RadarSignal * core::World::findWaveform ( const SimId  id)

Finds a radar signal by ID.

Parameters
idThe ID of the radar signal to find.
Returns
A pointer to the RadarSignal if found, or nullptr if not found.

Definition at line 153 of file world.cpp.

154 {
155 const auto it = _waveforms.find(id);
156 return it != _waveforms.end() ? it->second.get() : nullptr;
157 }

References max.

Referenced by findWaveformByName(), and serial::update_transmitter_waveform_from_json().

+ Here is the caller graph for this function:

◆ findWaveformByName()

RadarSignal * core::World::findWaveformByName ( const std::string &  name)

Finds a waveform by name.

Parameters
nameThe waveform name to find.
Returns
A pointer to the RadarSignal if found, or nullptr if not found.

Definition at line 203 of file world.cpp.

204 {
205 const auto it = _waveform_ids_by_name.find(name);
206 return it != _waveform_ids_by_name.end() ? findWaveform(it->second) : nullptr;
207 }
fers_signal::RadarSignal * findWaveform(const SimId id)
Finds a radar signal by ID.
Definition world.cpp:153

References findWaveform(), and max.

Referenced by resolveReceiverDechirpReferences().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAntennas()

const std::unordered_map< SimId, std::unique_ptr< antenna::Antenna > > & core::World::getAntennas ( ) const
noexcept

Retrieves the map of antennas.

Returns
A const reference to the map of antenna names to Antenna objects.

Definition at line 265 of file world.h.

266 {
267 return _antennas;
268 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getEventQueue()

std::priority_queue< Event, std::vector< Event >, EventComparator > & core::World::getEventQueue ( )
noexcept

Gets a mutable reference to the global event queue.

Returns
A reference to the priority queue of events.

Definition at line 313 of file world.h.

314 {
315 return _event_queue;
316 }

Referenced by core::SimulationEngine::handleRxPulsedWindowEnd(), core::SimulationEngine::handleRxPulsedWindowStart(), core::SimulationEngine::handleTxPulsedStart(), and core::SimulationEngine::run().

+ Here is the caller graph for this function:

◆ getPlatforms()

const std::vector< std::unique_ptr< radar::Platform > > & core::World::getPlatforms ( ) const
noexcept

Retrieves the list of platforms.

Returns
A const reference to a vector of unique pointers to Platform objects.

Definition at line 216 of file world.h.

217 {
218 return _platforms;
219 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getReceivers()

const std::vector< std::unique_ptr< radar::Receiver > > & core::World::getReceivers ( ) const
noexcept

Retrieves the list of radar receivers.

Returns
A const reference to a vector of unique pointers to Receiver objects.

Definition at line 236 of file world.h.

237 {
238 return _receivers;
239 }

Referenced by simulation::calculatePreviewLinks(), core::collectCwPhaseNoiseTimings(), serial::kml_generator_utils::generateKmlToStream(), core::SimulationEngine::handleRxStreamingEnd(), core::SimulationEngine::handleRxStreamingStart(), core::SimulationEngine::handleTxPulsedStart(), core::logSimulationMemoryProjection(), core::projectSimulationMemory(), core::SimulationEngine::run(), serial::xml_serializer_utils::serializePlatform(), and core::SimulationEngine::SimulationEngine().

+ Here is the caller graph for this function:

◆ getSimulationState()

SimulationState & core::World::getSimulationState ( )
noexcept

Gets a mutable reference to the global simulation state.

Returns
A reference to the SimulationState object.

Definition at line 322 of file world.h.

322{ return _simulation_state; }

Referenced by core::SimulationEngine::handleRxStreamingEnd(), core::SimulationEngine::handleRxStreamingStart(), core::SimulationEngine::handleTxStreamingEnd(), core::SimulationEngine::handleTxStreamingStart(), core::SimulationEngine::processStreamingPhysics(), and core::SimulationEngine::run().

+ Here is the caller graph for this function:

◆ getTargets()

const std::vector< std::unique_ptr< radar::Target > > & core::World::getTargets ( ) const
noexcept

Retrieves the list of radar targets.

Returns
A const reference to a vector of unique pointers to Target objects.

Definition at line 226 of file world.h.

227 {
228 return _targets;
229 }

Referenced by serial::kml_generator_utils::generateKmlToStream(), core::SimulationEngine::handleTxPulsedStart(), and serial::xml_serializer_utils::serializePlatform().

+ Here is the caller graph for this function:

◆ getTimings()

const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & core::World::getTimings ( ) const
noexcept

Retrieves the map of timing prototypes.

Returns
A const reference to the map of timing names to PrototypeTiming objects.

Definition at line 275 of file world.h.

276 {
277 return _timings;
278 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getTransmitters()

const std::vector< std::unique_ptr< radar::Transmitter > > & core::World::getTransmitters ( ) const
noexcept

Retrieves the list of radar transmitters.

Returns
A const reference to a vector of unique pointers to Transmitter objects.

Definition at line 246 of file world.h.

247 {
248 return _transmitters;
249 }

Referenced by simulation::calculatePreviewLinks(), core::collectCwPhaseNoiseTimings(), serial::kml_generator_utils::generateKmlToStream(), and serial::xml_serializer_utils::serializePlatform().

+ Here is the caller graph for this function:

◆ getWaveforms()

const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & core::World::getWaveforms ( ) const
noexcept

Retrieves the map of radar signals (waveforms).

Returns
A const reference to the map of signal names to RadarSignal objects.

Definition at line 256 of file world.h.

257 {
258 return _waveforms;
259 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

World & core::World::operator= ( const World )
delete

◆ operator=() [2/2]

World & core::World::operator= ( World &&  )
delete

◆ replace() [1/4]

void core::World::replace ( std::unique_ptr< antenna::Antenna antenna)

Replaces an existing antenna, updating internal pointers.

Parameters
antennaUnique pointer to the new antenna.

Definition at line 296 of file world.cpp.

297 {
298 const SimId id = antenna->getId();
299 const Antenna* new_ptr = antenna.get();
300
301 std::unique_ptr<Antenna> old_owned;
302 const Antenna* old_ptr = nullptr;
303
304 if (auto it = _antennas.find(id); it != _antennas.end())
305 {
306 old_owned = std::move(it->second);
307 old_ptr = old_owned.get();
308 it->second = std::move(antenna);
309 }
310 else
311 {
312 _antennas[id] = std::move(antenna);
313 }
314
315 if ((old_ptr != nullptr) && old_ptr != new_ptr)
316 {
317 for (auto& tx : _transmitters)
318 if (tx->getAntenna() == old_ptr)
319 tx->setAntenna(new_ptr);
320
321 for (auto& rx : _receivers)
322 if (rx->getAntenna() == old_ptr)
323 rx->setAntenna(new_ptr);
324 }
325 }
Abstract base class representing an antenna.

References max.

◆ replace() [2/4]

void core::World::replace ( std::unique_ptr< fers_signal::RadarSignal waveform)

Replaces an existing waveform, updating internal pointers.

Parameters
waveformUnique pointer to the new waveform.

Definition at line 327 of file world.cpp.

328 {
329 const SimId id = waveform->getId();
330 RadarSignal* new_ptr = waveform.get();
331 const std::string new_name = waveform->getName();
332
333 std::unique_ptr<RadarSignal> old_owned;
334 const RadarSignal* old_ptr = nullptr;
335
336 if (auto it = _waveforms.find(id); it != _waveforms.end())
337 {
338 old_owned = std::move(it->second);
339 old_ptr = old_owned.get();
340 _waveform_ids_by_name.erase(old_owned->getName());
341 _waveform_ids_by_name[new_name] = id;
342 it->second = std::move(waveform);
343 }
344 else
345 {
346 _waveform_ids_by_name[new_name] = id;
347 _waveforms[id] = std::move(waveform);
348 }
349
350 if ((old_ptr != nullptr) && old_ptr != new_ptr)
351 {
352 for (auto& tx : _transmitters)
353 if (tx->getSignal() == old_ptr)
354 tx->setSignal(new_ptr);
355 }
356 }
Class representing a radar signal with associated properties.

References max.

◆ replace() [3/4]

void core::World::replace ( std::unique_ptr< radar::Target target)

Replaces an existing target, updating internal pointers.

Parameters
targetUnique pointer to the new target.

Definition at line 282 of file world.cpp.

283 {
284 const SimId id = target->getId();
285 for (auto& t : _targets)
286 {
287 if (t->getId() == id)
288 {
289 t = std::move(target);
290 return;
291 }
292 }
293 _targets.push_back(std::move(target));
294 }

References max.

Referenced by serial::update_antenna_from_json(), serial::update_existing_antenna_pattern_fields(), serial::update_target_from_json(), and serial::update_timing_from_json().

+ Here is the caller graph for this function:

◆ replace() [4/4]

void core::World::replace ( std::unique_ptr< timing::PrototypeTiming timing)

Replaces an existing timing prototype and refreshes dependent radar timing models.

Parameters
timingUnique pointer to the new timing prototype.

Definition at line 358 of file world.cpp.

359 {
360 const SimId id = timing->getId();
361 const PrototypeTiming* new_ptr = timing.get();
362
363 std::unique_ptr<PrototypeTiming> old_owned;
364 const PrototypeTiming* old_ptr = nullptr;
365
366 if (auto it = _timings.find(id); it != _timings.end())
367 {
368 old_owned = std::move(it->second);
369 old_ptr = old_owned.get();
370 it->second = std::move(timing);
371 }
372 else
373 {
374 _timings[id] = std::move(timing);
375 }
376
377 std::unordered_map<const timing::Timing*, std::shared_ptr<timing::Timing>> refreshed_instances;
379 {
380 const auto current_timing = radar_obj->getTiming();
381 if (!current_timing || (current_timing->getId() != id))
382 {
383 return;
384 }
385
386 const timing::Timing* const timing_key = current_timing.get();
387 const auto [it, inserted] = refreshed_instances.try_emplace(timing_key);
388 if (inserted)
389 {
390 auto refreshed =
391 std::make_shared<timing::Timing>(new_ptr->getName(), current_timing->getSeed(), new_ptr->getId());
392 refreshed->initializeModel(new_ptr);
393 it->second = std::move(refreshed);
394 }
395 radar_obj->setTiming(it->second);
396 };
397
398 if ((old_ptr != nullptr) && old_ptr != new_ptr)
399 {
400 for (auto& tx : _transmitters)
402
403 for (auto& rx : _receivers)
405 }
406 }
Manages timing properties such as frequency, offsets, and synchronization.
Represents a timing source for simulation.
Definition timing.h:36

References max.

◆ resolveReceiverDechirpReferences()

void core::World::resolveReceiverDechirpReferences ( )

Resolves and validates receiver FMCW dechirp references after all components are loaded.

Exceptions
std::runtime_errorif a dechirped receiver has an invalid or inactive LO reference.

Definition at line 553 of file world.cpp.

554 {
555 for (const auto& rx_ptr : _receivers)
556 {
557 auto& rx = *rx_ptr;
558 rx.clearResolvedDechirpSources();
559 if (!rx.isDechirpEnabled())
560 {
561 continue;
562 }
563 if (rx.getMode() != radar::OperationMode::FMCW_MODE)
564 {
565 throw std::runtime_error("Receiver '" + rx.getName() + "' enables dechirping outside FMCW mode.");
566 }
567
568 auto reference = rx.getDechirpReference();
569 std::vector<ActiveStreamingSource> sources;
570 const std::string owner = "Receiver '" + rx.getName() + "'";
571 switch (reference.source)
572 {
573 case Receiver::DechirpReferenceSource::Attached:
574 {
575 const auto* const tx = dynamic_cast<const Transmitter*>(rx.getAttached());
577 reference.transmitter_id = tx->getId();
578 reference.transmitter_name = tx->getName();
580 break;
581 }
582 case Receiver::DechirpReferenceSource::Transmitter:
583 {
584 auto* const tx = findTransmitterByName(reference.name);
586 reference.transmitter_id = tx->getId();
587 reference.transmitter_name = tx->getName();
589 break;
590 }
591 case Receiver::DechirpReferenceSource::Custom:
592 {
593 auto* const waveform = findWaveformByName(reference.name);
594 if (waveform == nullptr || !waveform->isFmcwFamily())
595 {
596 throw std::runtime_error(owner + " custom dechirp reference waveform '" + reference.name +
597 "' must be a top-level FMCW waveform.");
598 }
599 reference.waveform_id = waveform->getId();
600 reference.waveform_name = waveform->getName();
601 sources = waveformDechirpSources(waveform, &rx);
602 break;
603 }
604 case Receiver::DechirpReferenceSource::None:
605 throw std::runtime_error(owner + " enables dechirping without a dechirp reference.");
606 }
607
608 if (sources.empty())
609 {
610 throw std::runtime_error(owner + " dechirp reference has no active LO segments in the simulation.");
611 }
612 std::ranges::sort(sources, [](const ActiveStreamingSource& lhs, const ActiveStreamingSource& rhs)
613 { return lhs.segment_start < rhs.segment_start; });
614 rx.setDechirpReference(std::move(reference));
615 rx.setResolvedDechirpSources(std::move(sources));
616 }
617 }
fers_signal::RadarSignal * findWaveformByName(const std::string &name)
Finds a waveform by name.
Definition world.cpp:203
radar::Transmitter * findTransmitterByName(const std::string &name)
Finds a transmitter by name.
Definition world.cpp:189
Represents a radar transmitter system.
Definition transmitter.h:34

References findTransmitterByName(), findWaveformByName(), radar::FMCW_MODE, fers_signal::RadarSignal::getId(), fers_signal::RadarSignal::getName(), fers_signal::RadarSignal::isFmcwFamily(), and max.

Referenced by serial::update_monostatic_from_json(), and serial::update_receiver_from_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scheduleInitialEvents()

void core::World::scheduleInitialEvents ( )

Populates the event queue with the initial events for the simulation.

This method should be called after all simulation objects have been parsed and added to the world.

Definition at line 440 of file world.cpp.

441 {
444
445 for (const auto& transmitter : _transmitters)
446 {
447 scheduleInitialTransmitterEvents(transmitter.get(), sim_start, sim_end);
448 }
449
450 for (const auto& receiver : _receivers)
451 {
452 scheduleInitialReceiverEvents(receiver.get(), sim_start, sim_end);
453 }
454 }
const Transmitter & transmitter
const Receiver & receiver

References params::endTime(), max, receiver, params::startTime(), and transmitter.

+ Here is the call graph for this function:

◆ swap()

void core::World::swap ( World other)
noexcept

Exchanges all owned world state with another world.

Definition at line 423 of file world.cpp.

424 {
425 using std::swap;
426
427 _platforms.swap(other._platforms);
428 _transmitters.swap(other._transmitters);
429 _receivers.swap(other._receivers);
430 _targets.swap(other._targets);
431 _waveforms.swap(other._waveforms);
432 _waveform_ids_by_name.swap(other._waveform_ids_by_name);
433 _transmitters_by_name.swap(other._transmitters_by_name);
434 _antennas.swap(other._antennas);
435 _timings.swap(other._timings);
436 _event_queue.swap(other._event_queue);
437 swap(_simulation_state, other._simulation_state);
438 }
void swap(World &other) noexcept
Exchanges all owned world state with another world.
Definition world.cpp:423

References max.

Referenced by serial::json_to_world().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: