DofProgramWiseIndexListPerVertexCoordIndexListManager.cpp 4.77 KB
Newer Older
GILLES Sebastien's avatar
GILLES Sebastien committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*!
//
// \file
//
//
// Created by Sebastien Gilles <sebastien.gilles@inria.fr> on the Fri, 18 Dec 2015 15:36:26 +0100
// Copyright (c) Inria. All rights reserved.
//
// \ingroup FiniteElementGroup
// \addtogroup FiniteElementGroup
// \{
*/

14

15 16
#include "FiniteElement/FiniteElementSpace/GodOfDof.hpp"
#include "FiniteElement/FiniteElementSpace/Internal/DofProgramWiseIndexListPerVertexCoordIndexListManager.hpp"
17 18


19
namespace MoReFEM
20 21 22
{
    
    
23
    namespace Internal
24 25 26
    {
        
        
27
        namespace FEltSpaceNS
28
        {
29 30


31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
            DofProgramWiseIndexListPerVertexCoordIndexListManager
            ::DofProgramWiseIndexListPerVertexCoordIndexListManager(Advanced::parallelism_strategy strategy)
            {
                switch(strategy)
                {
                case Advanced::parallelism_strategy::none:
                case Advanced::parallelism_strategy::parallel:
                case Advanced::parallelism_strategy::precompute:
                case Advanced::parallelism_strategy::parallel_no_write:
                    break;
                case Advanced::parallelism_strategy::run_from_preprocessed:
                    {
                        assert(false && "This class has no business being called in this mode; you should instead "
                               "add in your Model the storage in parallelism directory of the VertexMatching "
                               "interpolation matrix.");
                        exit(EXIT_FAILURE);
                    }
                }
            }


52 53
            DofProgramWiseIndexListPerVertexCoordIndexListManager
            ::~DofProgramWiseIndexListPerVertexCoordIndexListManager() = default;
54 55
        
        
56
            const std::string& DofProgramWiseIndexListPerVertexCoordIndexListManager::ClassName()
57
            {
58
                static std::string ret("DofProgramWiseIndexListPerVertexCoordIndexListManager");
59
                return ret;
60
            }
GILLES Sebastien's avatar
GILLES Sebastien committed
61

62
            
GILLES Sebastien's avatar
GILLES Sebastien committed
63 64 65 66 67
            void DofProgramWiseIndexListPerVertexCoordIndexListManager
            ::Create(const unsigned int unique_id,
                     const GodOfDof& god_of_dof,
                     const unsigned int felt_space_index,
                     const unsigned int numbering_subset_index)
68
            {
69
                // This method will be called from all GodOfDofs, but only the one that encompass felt_space
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
                // is allowed to proceed.
                if (!god_of_dof.IsFEltSpace(felt_space_index))
                    return;

                decltype(auto) felt_space = god_of_dof.GetFEltSpace(felt_space_index);
                
                #ifndef NDEBUG
                {
                    const auto god_of_dof_from_felt_space_ptr = felt_space.GetGodOfDofFromWeakPtr();
                
                    if (god_of_dof.GetUniqueId() != god_of_dof_from_felt_space_ptr->GetUniqueId())
                        return;
                }
                #endif // NDEBUG
                
                decltype(auto) numbering_subset = god_of_dof.GetNumberingSubset(numbering_subset_index);
                
                // make_unique is not accepted here: it makes the code yell about private status of the constructor
                // with both clang and gcc.
89 90
                DofProgramWiseIndexListPerVertexCoordIndexList* buf
                    = new DofProgramWiseIndexListPerVertexCoordIndexList(unique_id, felt_space, numbering_subset);
91
                                                                 
92
                auto&& ptr = DofProgramWiseIndexListPerVertexCoordIndexList::const_unique_ptr(buf);
93 94 95 96 97 98 99 100 101 102 103
                
                assert(ptr->GetUniqueId() == unique_id);
                
                auto&& pair = std::make_pair(unique_id, std::move(ptr));
                
                auto insert_return_value = list_.insert(std::move(pair));
                
                if (!insert_return_value.second)
                    throw Exception("Two InitVertexMatching objects can't share the same unique identifier! (namely "
                                    + std::to_string(unique_id) + ").", __FILE__, __LINE__);
            }
104 105
            
            
106 107
            const DofProgramWiseIndexListPerVertexCoordIndexList& DofProgramWiseIndexListPerVertexCoordIndexListManager
            ::GetDofProgramWiseIndexListPerVertexCoordIndexList(unsigned int unique_id) const
108 109 110 111 112 113 114 115 116 117
            {
                const auto& list = GetStorage();
                
                auto it = list.find(unique_id);
                assert(it != list.cend());
                
                assert(!(!(it->second)));
                
                return *(it->second);
            }
118 119
            
            
120
        } // namespace FEltSpaceNS
121 122
            
        
123
    } // namespace Internal
124 125


126
} // namespace MoReFEM
127 128 129


/// @} // addtogroup FiniteElementGroup