Swarm-NG  1.1
utils.hpp File Reference

Defines utility routines for common tasks that most users would need. More...

#include "types/ensemble.hpp"
#include "ensemble_alloc.hpp"
#include "types/config.hpp"
#include <ostream>

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &o, const swarm::ensemble::range_t &r)
 Pretty printing an ensemble::range_t, as a value with tolerance.
 
swarm::hostEnsemble generate_ensemble (swarm::config &cfg)
 Generate an ensemble of random generated star-centeric planetary systems. More...
 
bool validate_configuration (swarm::config &cfg)
 Deprecated: Validate the configuration. More...
 
double find_max_energy_conservation_error (swarm::ensemble &ens, swarm::ensemble &reference_ens)
 Helper function to find the energy conservation error. More...
 
void outputConfigSummary (std::ostream &o, swarm::config &cfg)
 Pretty print selected values in a config data structure. More...
 
swarm::config default_config ()
 Default configuration. More...
 
bool compare_ensembles (swarm::ensemble &e1, swarm::ensemble &e2, double &pos_diff, double &vel_diff, double &time_diff)
 Compare ensembles and find their similarity. More...
 
int number_of_disabled_systems (swarm::defaultEnsemble ens)
 Basic helper function to count the number of systems with SYSTEM_DISABLED status.
 

Detailed Description

Defines utility routines for common tasks that most users would need.

Utility routines that is used by applications.

Contains:

  • Generating ensembles
  • Comparing ensembles
  • Reporting functions
  • Some useful macros

These are routines that are not part of the core swarm but are used quite frequently in applications. For easier use of swarm, these routines can be very useful.

They range from input/output routines, generators and trivial statistical data analysis.

Definition in file utils.hpp.

Function Documentation

bool compare_ensembles ( swarm::ensemble e1,
swarm::ensemble e2,
double &  pos_diff,
double &  vel_diff,
double &  time_diff 
)

Compare ensembles and find their similarity.

This is used when two ensembles are supposed to be identical (e.g. computed by the similar process). The difference in position and velocity and time is calculated and returned in output variables. The function returns false if the ensembles are not comparable (e.g. different number of systems or bodies), otherwise the return value is true.

Referenced by benchmark_item().

swarm::config default_config ( )

Default configuration.

Prepopulate a config data structure with some pre-tested configuration values for non-optional parameters.

Definition at line 149 of file utils.cpp.

double find_max_energy_conservation_error ( swarm::ensemble ens,
swarm::ensemble reference_ens 
)

Helper function to find the energy conservation error.

The total energy for each system in ens and reference_ens is calculated individually. Then the difference in energy for each system is calculated and divided by energy in refrence_ens. The worst (highest) error rate is returned as the result.

Parameters
ensThe ensemble to be examined for energy conservation (after integration)
reference_ensThe ensemble that is used as a reference (initial conditions)

Referenced by benchmark_item(), and main().

swarm::hostEnsemble generate_ensemble ( swarm::config cfg)

Generate an ensemble of random generated star-centeric planetary systems.

The star is at origin and is stationary. The planets are on circular orbits. The spacing factor is set to 1.4 by default but can be changed via cfg["spacing_factor"] config parameter. Number of systems and number of bodies should be specified through cfg["nsys"] and cfg["nbod"] parameters.

Parameters
cfgShould containt "nsys" and "nbod", optionally "spacing_factor"

Generate an ensemble of random generated star-centeric planetary systems.

We get different type of orbit based on ejection_factor: 1/sqrt(2) : circular orbit < 1 : elliptical orbit = 1 : parabolic orbit > 1 : hyperbolic orbit

Configuration options: nsys: Number of systems in the ensemble nbod: Number of bodies per system spacing_factor: determines the spacing between the planets, distance of planet i from star is spacing_factor times the distance of planet i-1 from star. ejection_factor: determines the type of orbit see above planet_mass: ratio of the planet mass to the star mass. defaults to Jupiter mass planets (0.001)

Definition at line 63 of file utils.cpp.

References swarm::EnsembleAlloc< ENSEMBLE_CHUNK_SIZE, DefaultAllocator >::create(), swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::nbod(), swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::nsys(), swarm::config::optional(), swarm::config::require(), and x.

void outputConfigSummary ( std::ostream &  o,
swarm::config cfg 
)

Pretty print selected values in a config data structure.

Definition at line 135 of file utils.cpp.

bool validate_configuration ( swarm::config cfg)

Deprecated: Validate the configuration.

The criterias are very general and will cause problems.

Todo:
This function needs to be restructured or at least updated

Definition at line 119 of file utils.cpp.

References swarm::config::optional().

Referenced by benchmark_item().