#ifndef SPECIES_GENERATOR_H #define SPECIES_GENERATOR_H #include #include #include #include #include "generators/interaction_generator.h" #include "simulation/jansson_additionals.h" #include "simulation/parameter.h" #include "simulation/species.h" // defined in "simulation/timer.h" class Timer; namespace generator { // structure to store various variables neccessary for the creation // of TrackedSpecies objects struct TrackedSpeciesBuilderInfo { public: std::shared_ptr mover; std::shared_ptr terminator; std::shared_ptr reflector; std::shared_ptr density_field; std::shared_ptr velocity_distribution; std::shared_ptr drift_velocity; std::shared_ptr last_sync_density_field; double mass_kg; double charge_C; species::ImplementedSpecies type; std::string name; json_path path_in_json; }; // structure to store various variables neccessary for the creation // of BackgroundSpecies objects struct BackgroundSpeciesBuilderInfo { public: BackgroundSpeciesBuilderInfo() : density(nullptr), velocity_distribution(nullptr), drift_velocity(nullptr){}; std::shared_ptr density; std::shared_ptr velocity_distribution; std::shared_ptr drift_velocity; double mass_kg; double charge_C; species::ImplementedSpecies type; std::string name; json_path path_in_json; }; // class for mapping between certain strings and ImplementedSpecies enums class SpeciesAlias { public: // return the ImplementedSpecies enum for the given string. If the // name is not defined as an alias an error is thrown static species::ImplementedSpecies alias(const std::string& name); // return the string defined as an alias for the given ImplemetedSpecies enum // if no alias has been defined returns an empty string // (if it were to be defined multiple times return the first found instance) static std::string name(species::ImplementedSpecies specie); // check if the string name is defined as an alias static bool isAlias(const std::string& name); private: // mapping between the string and enum static std::map specie_aliases; }; // class mapping between ImplementedSpecies enum and the charge corresponding to // the physical particle class SpeciesCharges { public: // return the charge of the ImplementedSpecies enum static double charge(species::ImplementedSpecies species); private: static std::map charge_; }; // class for creation of the TrackedSpecies map and the BackgroudSpecies map class SpeciesBuilder { public: // Constructor: takes the Parameter object created by the input json file SpeciesBuilder(Parameter& parameter); // function to create a map of TrackedSpecies and an arbitrary string used to // identify the TrackedSpecies within the map // description for the json-object structure can be found in the private functions of // this class (examples e.g. in "simulation_config/parameter_katrin_example") std::map> trackedSpecies(); // function to create a map of BackgroundSpecies and an arbitrary string used to // identify the BackgroundSpecies within the map // description for the json-object structure can be found in the private functions of // this class (examples e.g. in "simulation_config/parameter_katrin_example") std::map> backgroundSpecies(); // function to create a shared_ptr to a Timer object std::shared_ptr timer(); // function to create a shared_ptr to a Timer object (to be used as a copy of the // main timer object during cpu synchronization) std::shared_ptr lastSyncTimer(); private: std::map background_species_info; std::map tracked_species_info; std::shared_ptr timer_; std::shared_ptr last_sync_timer_; std::map> tracked_species; std::map> background_species; // checks all json-objects (with an aribtrary name used as the name of the corresponding // BackgroundSpecie) in the json-object "Background", which is located in the json-object // "Species" (which is in the root) and creates new entries in the background_species_info // map (and sets the name and path_in_json members) // // example: // { // "Species":{ // "Background": { // "background1": {...}, // ... // } // ... // } // } // in this example the name is set to "background1" and path_in_json to ["Species", "Background", "background1"] void initBackgroundSpecies(Parameter& parameter); // checks all json-objects (with an aribtrary name used as the name of the corresponding // BackgroundSpecie) in the json-object "Tracked", which is located in the json-object // "Species" (which is in the root) and creates new entries in the background_species_info // map (and sets the name and path_in_json members) // // example: // { // "Species":{ // "Tracked": { // "tracked1": {...}, // ... // } // ... // } // } // in this example the name is set to "tracked1" and path_in_json to ["Species", "Tracked", "tracked1"] void initTrackedSpecies(Parameter& parameter); // for each element of the background_species_info element and for each tracked_species_info element // fill the velocity_distribution member with a VelocityDistribution object // described in a json-object called "VelocityDistribution", that has to follow the // format described in "buildVelocityDistribution" (generators/velocity_distribution_generator.h) void fillVelocityDistribution(Parameter& parameter); // for each element of the background_species_info element and for each tracked_species_info element // fill the drift_velocity member with a DirftVelocity object // described in a json-object called "DriftVelocity", that has to follow the // format described in "buildDriftVelocity" (generators/drift_velocity_generator.h) void fillDriftVelocity(Parameter& parameter); // for each element of the background_species_info element and for each tracked_species_info element // fill the mass_kg member with the value defined in the SpeciesMasses class (defined in // "generators/mass_generator.h") void fillMass(); // for each element of the background_species_info element and for each tracked_species_info element // fill the charge_C member with the value defined in the SpeciesCharges class (defined here in // "generators/species_generator.h") void fillCharge(); // for all elements in the tracked_species map add the defined interactions // in the path stored in the corresponding tracked_species_info element (i.e. ["Species", "Tracked", name of the tracked specie]) // a json-object "Interactions" has to exist, this object has to follow the // format described for the "addInteractions" function (defined in "generators/interaction_generator.h") void fillInteractions(Parameter& parameter); // read the json-string "ParticleType" in the json-object at the path stored in // path_in_json in the BackgroundSpeciesBuilderInfo map for all elements // "ParticleType" has to be one of the strings defined as an alias in // the SpeciesAlias class ("generators/species_generator.h") void fillBackgroundSpecieType(Parameter& parameter); // for all elements in the BackgroundSpeciesBuilderInfo map create the // density member with the density field described in the json-object "ConstantDensityField" // (in the json-object at path_in_json) // "ConstantDensityField" has to follow the structure described in "buildConstantDensityField" // (defined in "generators/density_field_generator.h") void fillBackgroundDensity(Parameter& parameter); // read the json-string "ParticleType" in the json-object at the path stored in // path_in_json in the TrackedSpeciesBuilderInfo map for all elements // "ParticleType" has to be one of the strings defined as an alias in // the SpeciesAlias class ("generators/species_generator.h") void fillTrackedSpecieType(Parameter& parameter); // fill current_collector and last_sync_current_collector members of the // TrackedSpecies map, created according to the json-object // "CurrentCollector" (located in at the path_in_json member) // has to follow the form described in "buildCurrentCollector" ("generators/current_collector_generator.h") void fillCurrentCollector(Parameter& parameter); // fill deletion_logger and last_sync_deletion_logger members of the // TrackedSpecies map, created according to the json-object // "Loggers" (located in at the path_in_json member) // has to follow the form described in "buildDeletionLogger" ("generators/logger_generator.h") void fillLoggers(Parameter& parameter); // fill mover member of the TrackedSpeciesBuilderInfo map, // created according to the json-object "Mover" (located in at the path_in_json member) // has to follow the form described in "buildMover" ("generators/mover_generator.h") void fillMover(Parameter& parameter); // fill terminator member of the TrackedSpeciesBuilderInfo map, // created according to the json-object "Terminator" (located in at the path_in_json member) // has to follow the form described in "buildTerminator" ("generators/mover_generator.h") void fillTerminator(Parameter& parameter); // fill reflector member of the TrackedSpeciesBuilderInfo map, // created according to the json-object "Reflector" (located in at the path_in_json member) // has to follow the form described in "buildReflector" ("generators/mover_generator.h") void fillReflector(Parameter& parameter); // fill density_field and last_sync_density_field members of the // TrackedSpeciesBuilderInfo map, created according to the json-object // "DynamicDensityField" (located in at the path_in_json member) // has to follow the form described in "buildDyamicDensityField" void fillTrackedDensity(Parameter& parameter); // fill timer_ and last_sync_timer_ objects (no json-specifications needed) void initTimer(); // create the TrackedSpecies and BackgroundSpecies maps from the data contained in // the corresponding entries of the TrackedSpeciesBuilderInfo and BackgroundSpeciesBuilderInfo // maps void buildSpecies(); }; }; // namespace generator #endif /* SPECIES_GENERATOR_H */