Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ 4 : /* */ 5 : /* Copyright 2017 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #pragma once 10 : 11 : #include "ElementUserObject.h" 12 : #include "PolyatomicDisplacementFunction.h" 13 : #include "PolyatomicDisplacementDerivativeFunction.h" 14 : 15 : #include <map> 16 : #include <array> 17 : #include <vector> 18 : 19 : #include "mytrim/ion.h" 20 : #include "mytrim/element.h" 21 : 22 : class PKAGeneratorBase; 23 : 24 : /** 25 : * This UserObject rasterizes a simulation domain for the MyTRIM library 26 : */ 27 : class MyTRIMRasterizer : public ElementUserObject 28 : { 29 : public: 30 : static InputParameters validParams(); 31 : 32 : MyTRIMRasterizer(const InputParameters & parameters); 33 : 34 : /// determines if a TRIM run is executed during this timestep 35 : virtual bool executeThisTimestep() const; 36 : 37 : virtual void initialize(); 38 : virtual void execute(); 39 : virtual void threadJoin(const UserObject & y); 40 : virtual void finalize(); 41 : 42 : /// get the concentration array 43 : const std::vector<Real> & material(const Elem *) const; 44 : 45 : /// get the site volume 46 : Real siteVolume(const Elem *) const; 47 : 48 : /// get the PKA list 49 133 : const std::vector<MyTRIM_NS::IonBase> & getPKAList() const { return _pka_list; } 50 : 51 : /// get the variable ID of the first coupled variable (to determine the periodicity) 52 : int periodic() const { return _periodic; } 53 : 54 : /// returns a point with the periodic boundary conditions applied 55 : Point periodicPoint(const Point &) const; 56 : 57 : /// checks if species exists 58 : bool isTrackedSpecies(unsigned int atomic_number, Real mass_number) const; 59 : 60 : /// element averaged data 61 455677 : struct AveragedData 62 : { 63 427146 : AveragedData(unsigned int nvars = 0) : _elements(nvars, 0.0), _site_volume(0.0) {} 64 : 65 : std::vector<Real> _elements; 66 : Real _site_volume; 67 : }; 68 : 69 0 : struct PKAParameters 70 : { 71 : /// masses, charges, and mass number tolerances (m_i, Z_i, mtol_i) of the matrix elements 72 : std::vector<std::tuple<Real, Real, Real>> _mass_charge_tuple; 73 : 74 : /// how many isotopes to we have for each element and which index contains the 75 : /// first Z match? (only support up to Z=119!) 76 : std::array<std::pair<unsigned int, std::size_t>, 120> _index_Z; 77 : 78 : /// time interval over which the PKAs are added 79 : Real _dt; 80 : 81 : /// recoil rate scaling 82 : Real _recoil_rate_scaling; 83 : 84 : /// current element volume 85 : Real _volume; 86 : }; 87 : 88 : enum TRIMModuleEnum 89 : { 90 : MYTRIM_CORE = 0, 91 : MYTRIM_ENERGY_DEPOSITION = 1 92 : }; 93 : 94 : enum Unit 95 : { 96 : ANGSTROM = 0, 97 : NANOMETER, 98 : MICROMETER 99 : }; 100 : 101 0 : struct TrimParameters 102 : { 103 : // Element prototype data (charge, mass, displacement and binding energies) 104 : std::vector<MyTRIM_NS::Element> element_prototypes; 105 : 106 : /// conversion factor from chosen length unit to Angstrom 107 : Real length_scale; 108 : 109 : /// the TRIM class to instantiate in the recoil loops 110 : TRIMModuleEnum trim_module; 111 : 112 : /// energy cutoff below which recoils are not followed explicitly but effects are calculated analytically 113 : Real analytical_cutoff; 114 : 115 : /// maximum acceptable distance for matching NRT objects in composition space 116 : Real max_nrt_distance; 117 : 118 : /// logarithmic energy spacing for NRT integration 119 : Real nrt_log_energy_spacing; 120 : 121 : /// enable instantaneous recombination 122 : bool recombination; 123 : 124 : /// recombination radius 125 : Real r_rec; 126 : 127 : /// target number of pkas 128 : unsigned int desired_npka; 129 : 130 : /// original length of pka list 131 : unsigned int original_npka; 132 : 133 : /// length of pka list after rejection 134 : unsigned int scaled_npka; 135 : 136 : /// a scaling factor for the reaction rates to avoid very large PKA lists 137 : Real recoil_rate_scaling; 138 : 139 : /// scaling factor for the results 140 : Real result_scaling_factor; 141 : 142 : /// the _dt for which mytrim was executed last 143 : Real last_executed_dt; 144 : 145 : /// get the number of elements in the TRIM simulation 146 489 : unsigned int nVars() const { return element_prototypes.size(); } 147 : }; 148 : 149 : /// get the simulation parameters 150 495 : const TrimParameters & getTrimParameters() const { return _trim_parameters; } 151 : 152 : protected: 153 : ///@{ pack/unpack the _material_map and _pka_list data into a structure suitable for parallel communication 154 : void serialize(std::string & serialized_buffer); 155 : void deserialize(std::vector<std::string> & serialized_buffers); 156 : ///@} 157 : 158 : /// number of coupled variables to map 159 : const unsigned int _nvars; 160 : 161 : /// dimension of the mesh 162 : const unsigned int _dim; 163 : 164 : /// Simulation parameters 165 : TrimParameters _trim_parameters; 166 : 167 : /// Global (non-spatial dependent) parameters required for PKA generation 168 : PKAParameters _pka_parameters; 169 : 170 : /// coupled variable values 171 : std::vector<const VariableValue *> _var; 172 : 173 : /// lattice site volume material property 174 : const MaterialProperty<Real> * _site_volume_prop; 175 : 176 : /// conversion of site volume if mesh units are not nm and vars are number densities 177 : Real _site_volume_conversion; 178 : 179 : /// @{ PKA generators 180 : const std::vector<UserObjectName> _pka_generator_names; 181 : std::vector<const PKAGeneratorBase *> _pka_generators; 182 : /// @} 183 : 184 : /// @{ material map for the TRIM simulation (spatial dependent) 185 : typedef std::map<dof_id_type, AveragedData> MaterialMap; 186 : MaterialMap _material_map; 187 : /// @} 188 : 189 : /// variable number to use for minPeriodicDistance calls (i.e. use the periodicity of this variable) 190 : const int _periodic; 191 : 192 : /// cumulative PKA list 193 : std::vector<MyTRIM_NS::IonBase> _pka_list; 194 : 195 : /// time for which the next BCMC simulation is responsible (current dt plus skipped steps) 196 : Real _accumulated_time; 197 : 198 : /// rollback buffer for _accumulated_time if the previous step did not converge 199 : Real _accumulated_time_old; 200 : 201 : /// timestep interval on which to run BCMC 202 : const unsigned int _interval; 203 : 204 : /// @{ periodicity data 205 : Point _min_dim; 206 : Point _max_dim; 207 : bool _pbc[LIBMESH_DIM]; 208 : /// @} 209 : 210 : private: 211 : bool _execute_this_timestep; 212 : 213 : /// timers 214 : PerfID _perf_finalize; 215 : };