Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "ParallelUniqueId.h" 13 : 14 : /** 15 : * Utility class to interface between the object oriented MOOSE app structure and 16 : * global Abaqus utility functions. The class encapsulates static members for 17 : * intermediate data storage. 18 : */ 19 : class AbaqusUtils 20 : { 21 : public: 22 : /** 23 : * Global storage for the simulation output directory, this will be set by any Abaqus class. MOOSE 24 : * will throw a warning if multiple objects try to set this to different values. 25 : */ 26 : static void setInputFile(const std::string & input_file); 27 124 : static std::string getOutputDir() { return _output_dir; } 28 124 : static std::string getJobName() { return _job_name; } 29 : 30 : /** 31 : * Global storage for the MPI communicator, this will be set by any Abaqus class. MOOSE 32 : * will throw a warning if multiple objects try to set this to different values. 33 : */ 34 : static void setCommunicator(const libMesh::Parallel::Communicator * communicator); 35 436 : static const libMesh::Parallel::Communicator * getCommunicator() { return _communicator; } 36 : 37 : /// get data vector iterator with error checking 38 : template <typename T> 39 : static typename std::map<int, std::vector<T>>::iterator 40 : getSMAIterator(std::map<int, std::vector<T>> & array, int id, const std::string & function); 41 : 42 : /// get thread local array 43 : template <typename T> 44 : static typename std::map<int, std::vector<T>> & 45 : getSMAThreadArray(std::vector<std::map<int, std::vector<T>>> & local_array, 46 : const std::string & function); 47 : 48 : /// thread storage initialization 49 : static void smaInitialize(); 50 : 51 : ///@{ Shared Memory Arrays 52 : static std::map<int, std::vector<int>> _sma_int_array; 53 : static std::map<int, std::vector<Real>> _sma_float_array; 54 : static std::vector<std::map<int, std::vector<int>>> _sma_local_int_array; 55 : static std::vector<std::map<int, std::vector<Real>>> _sma_local_float_array; 56 : ///@} 57 : 58 : ///@{ Mutex API 59 : static void mutexInit(std::size_t n); 60 : static void mutexLock(std::size_t n); 61 : static void mutexUnlock(std::size_t n); 62 : ///@} 63 : private: 64 : static std::array<std::unique_ptr<Threads::spin_mutex>, 101> _mutex; 65 : static std::string _output_dir; 66 : static std::string _job_name; 67 : static const libMesh::Parallel::Communicator * _communicator; 68 : }; 69 : 70 : template <typename T> 71 : typename std::map<int, std::vector<T>>::iterator 72 6252 : AbaqusUtils::getSMAIterator(std::map<int, std::vector<T>> & array, 73 : int id, 74 : const std::string & function) 75 : { 76 : auto it = array.find(id); 77 6252 : if (it == array.end()) 78 0 : mooseError("Invalid id ", id, " in ", function, "."); 79 6252 : return it; 80 : } 81 : 82 : template <typename T> 83 : typename std::map<int, std::vector<T>> & 84 5424 : AbaqusUtils::getSMAThreadArray(std::vector<std::map<int, std::vector<T>>> & local_array, 85 : const std::string & function) 86 : { 87 : ParallelUniqueId puid; 88 5424 : if (puid.id >= local_array.size()) 89 0 : mooseError("SMA storage not properly initialized in ", function, "."); 90 5424 : return local_array[puid.id]; 91 : }