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 407 of file world.cpp.

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

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 618 of file world.cpp.

619 {
620 if (_event_queue.empty())
621 {
622 return "Event Queue is empty.\n";
623 }
624
625 std::stringstream ss;
626 ss << std::fixed << std::setprecision(6);
627
628 const std::string separator = "--------------------------------------------------------------------";
629 const std::string title = "| Event Queue Contents (" + std::to_string(_event_queue.size()) + " events)";
630 if (separator.size() > static_cast<std::size_t>(std::numeric_limits<int>::max()))
631 {
632 throw std::runtime_error("Separator width exceeds stream formatting limits.");
633 }
634 const int title_width = static_cast<int>(separator.size()) - 1;
635
636 ss << separator << "\n"
637 << std::left << std::setw(title_width) << title << "|\n"
638 << separator << "\n"
639 << "| " << std::left << std::setw(12) << "Timestamp" << " | " << std::setw(21) << "Event Type" << " | "
640 << std::setw(25) << "Source Object" << " |\n"
641 << separator << "\n";
642
643 auto queue_copy = _event_queue;
644
645 while (!queue_copy.empty())
646 {
647 const auto [timestamp, event_type, source_object] = queue_copy.top();
648 queue_copy.pop();
649
650 ss << "| " << std::right << std::setw(12) << timestamp << " | " << std::left << std::setw(21)
651 << toString(event_type) << " | " << std::left << std::setw(25) << source_object->getName() << " |\n";
652 }
653 ss << separator << "\n";
654
655 return ss.str();
656 }
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 ||
253 {
254 continue;
255 }
256
257 const auto& schedule = receiver_ptr->getSchedule();
258 if (schedule.empty())
259 {
261 continue;
262 }
263
264 for (const auto& period : schedule)
265 {
267 }
268 }
269
270 return earliest.value_or(params::startTime());
271 }
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
@ 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, 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 273 of file world.cpp.

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

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 295 of file world.cpp.

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

327 {
328 const SimId id = waveform->getId();
329 RadarSignal* new_ptr = waveform.get();
330 const std::string new_name = waveform->getName();
331
332 std::unique_ptr<RadarSignal> old_owned;
333 const RadarSignal* old_ptr = nullptr;
334
335 if (auto it = _waveforms.find(id); it != _waveforms.end())
336 {
337 old_owned = std::move(it->second);
338 old_ptr = old_owned.get();
339 _waveform_ids_by_name.erase(old_owned->getName());
340 _waveform_ids_by_name[new_name] = id;
341 it->second = std::move(waveform);
342 }
343 else
344 {
345 _waveform_ids_by_name[new_name] = id;
346 _waveforms[id] = std::move(waveform);
347 }
348
349 if ((old_ptr != nullptr) && old_ptr != new_ptr)
350 {
351 for (auto& tx : _transmitters)
352 if (tx->getSignal() == old_ptr)
353 tx->setSignal(new_ptr);
354 }
355 }
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 281 of file world.cpp.

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

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 357 of file world.cpp.

358 {
359 const SimId id = timing->getId();
360 const PrototypeTiming* new_ptr = timing.get();
361
362 std::unique_ptr<PrototypeTiming> old_owned;
363 const PrototypeTiming* old_ptr = nullptr;
364
365 if (auto it = _timings.find(id); it != _timings.end())
366 {
367 old_owned = std::move(it->second);
368 old_ptr = old_owned.get();
369 it->second = std::move(timing);
370 }
371 else
372 {
373 _timings[id] = std::move(timing);
374 }
375
376 std::unordered_map<const timing::Timing*, std::shared_ptr<timing::Timing>> refreshed_instances;
378 {
379 const auto current_timing = radar_obj->getTiming();
380 if (!current_timing || (current_timing->getId() != id))
381 {
382 return;
383 }
384
385 const timing::Timing* const timing_key = current_timing.get();
386 const auto [it, inserted] = refreshed_instances.try_emplace(timing_key);
387 if (inserted)
388 {
389 auto refreshed =
390 std::make_shared<timing::Timing>(new_ptr->getName(), current_timing->getSeed(), new_ptr->getId());
391 refreshed->initializeModel(new_ptr);
392 it->second = std::move(refreshed);
393 }
394 radar_obj->setTiming(it->second);
395 };
396
397 if ((old_ptr != nullptr) && old_ptr != new_ptr)
398 {
399 for (auto& tx : _transmitters)
401
402 for (auto& rx : _receivers)
404 }
405 }
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 552 of file world.cpp.

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

440 {
443
444 for (const auto& transmitter : _transmitters)
445 {
446 scheduleInitialTransmitterEvents(transmitter.get(), sim_start, sim_end);
447 }
448
449 for (const auto& receiver : _receivers)
450 {
451 scheduleInitialReceiverEvents(receiver.get(), sim_start, sim_end);
452 }
453 }
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 422 of file world.cpp.

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

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: