LCOV - code coverage report
Current view: top level - src/other - MooseMyTRIMSample.C (source / functions) Hit Total Coverage
Test: idaholab/magpie: 5710af Lines: 36 37 97.3 %
Date: 2025-07-21 23:34:39 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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             : #include "MooseMyTRIMSample.h"
      10             : #include "MooseMesh.h"
      11             : 
      12         198 : MooseMyTRIMSample::MooseMyTRIMSample(const MyTRIMRasterizer & rasterizer,
      13             :                                      const MooseMesh & mesh,
      14         198 :                                      MyTRIM_NS::SimconfType * simconf)
      15             :   : MyTRIM_NS::SampleBase(),
      16         198 :     _rasterizer(rasterizer),
      17         198 :     _trim_parameters(_rasterizer.getTrimParameters()),
      18         198 :     _nvars(_trim_parameters.nVars()),
      19         198 :     _mesh(mesh),
      20         198 :     _dim(_mesh.dimension()),
      21         198 :     _pl(_mesh.getPointLocator()),
      22         198 :     _simconf(simconf)
      23             : {
      24         198 :   if (_dim < 2 || _dim > 3)
      25           0 :     mooseError("TRIM simulation works in 2D or 3D only.");
      26             : 
      27             :   // permit querying points that are potentially outside the mesh
      28         198 :   _pl->enable_out_of_mesh_mode();
      29         198 : }
      30             : 
      31             : void
      32     5594937 : MooseMyTRIMSample::averages(const MyTRIM_NS::IonBase * pka)
      33             : {
      34     5594937 :   _current_ion = pka;
      35             : 
      36             :   // averages do NOT depend on ion energy! Cache averaged materials for all possible PKAs
      37             :   // this means adding comparison operators to PKAs so that we can use them as map indices
      38             :   // have a master material cache and per-PKA-type cache. Do not average stuff in the master
      39             :   // cache at all use it only as a copy construction source for the per-pka-cache
      40             :   // std::map<MyTRIM_NS::IonBase, std::map<Elem *, MooseMyTRIMMaterial> _per_pka_cache
      41     5594937 : }
      42             : 
      43             : MyTRIM_NS::MaterialBase *
      44    64734033 : MooseMyTRIMSample::lookupMaterial(Point & pos)
      45             : {
      46             :   // point to sample the material at
      47    64734033 :   Point p = _rasterizer.periodicPoint(pos);
      48             : 
      49             :   // get element containing the point
      50             :   mooseAssert(_pl != nullptr, "initialize() must be called on the MooseMyTRIMSample object.");
      51    64734033 :   const Elem * elem = (*_pl)(p);
      52             : 
      53             :   // no element found means we have left the mesh
      54    64734033 :   if (elem == nullptr)
      55             :     return nullptr;
      56             : 
      57             :   // obtain the per pka cache entry (insert if not found)
      58    64715091 :   auto & cache = _per_pka_materials_cache[*_current_ion];
      59             : 
      60             :   // look up current element
      61             :   auto i = cache.find(elem);
      62             : 
      63             :   // not averaged yet
      64    64715091 :   if (i == cache.end())
      65             :   {
      66             :     // look up if the element is prepared in the master cache
      67             :     auto j = _materials_master_cache.find(elem);
      68             : 
      69             :     // not prepared yet
      70      338562 :     if (j == _materials_master_cache.end())
      71             :     {
      72             :       // prepare the material using data from the rasterizer
      73      200477 :       const std::vector<Real> & material_data = _rasterizer.material(elem);
      74      200477 :       MooseMyTRIMMaterial material(_simconf);
      75             : 
      76             :       // set elements
      77      200477 :       MyTRIM_NS::Element element;
      78      526492 :       for (unsigned int i = 0; i < _nvars; ++i)
      79             :       {
      80      326015 :         element = _trim_parameters.element_prototypes[i];
      81      326015 :         element._t = material_data[i];
      82      326015 :         material._element.push_back(element);
      83             :       }
      84             : 
      85             :       // calculate the density (must happen first!)
      86      200477 :       material.calculateDensity(_rasterizer.siteVolume(elem));
      87             : 
      88             :       // prepare material
      89      200477 :       material.prepare();
      90      200477 :       j = _materials_master_cache.insert(_materials_master_cache.begin(),
      91      200477 :                                          std::make_pair(elem, material));
      92             :     }
      93             : 
      94             :     // create a copy from the master cache entry, average it and file it
      95             :     MooseMyTRIMMaterial material(j->second);
      96      338562 :     material.average(_current_ion);
      97             : 
      98      338562 :     i = cache.insert(cache.begin(), std::make_pair(elem, material));
      99             :   }
     100             : 
     101    64715091 :   return &i->second;
     102             : }

Generated by: LCOV version 1.14