MarmotStateVarVectorManager.h
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------
2  * _
3  * _ __ ___ __ _ _ __ _ __ ___ ___ | |_
4  * | '_ ` _ \ / _` | '__| '_ ` _ \ / _ \| __|
5  * | | | | | | (_| | | | | | | | | (_) | |_
6  * |_| |_| |_|\__,_|_| |_| |_| |_|\___/ \__|
7  *
8  * Unit of Strength of Materials and Structural Analysis
9  * University of Innsbruck,
10  * 2020 - today
11  *
12  * festigkeitslehre@uibk.ac.at
13  *
14  * Matthias Neuner matthias.neuner@uibk.ac.at
15  *
16  * This file is part of the MAteRialMOdellingToolbox (marmot).
17  *
18  * This library is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU Lesser General Public
20  * License as published by the Free Software Foundation; either
21  * version 2.1 of the License, or (at your option) any later version.
22  *
23  * The full text of the license can be found in the file LICENSE.md at
24  * the top level directory of marmot.
25  * ---------------------------------------------------------------------
26  */
27 
28 #pragma once
29 #include "Marmot/MarmotUtils.h"
30 #include <memory>
31 #include <string>
32 #include <unordered_map>
33 #include <vector>
34 
38 
39 public:
41  inline StateView getStateView( const std::string& name ) const
42  {
43  auto entry = theLayout.entries.at( name );
44  return { theStateVars + entry.index, entry.length };
45  }
46 
48  inline double& find( const std::string& name ) const { return theStateVars[theLayout.entries.at( name ).index]; }
49 
51  inline bool contains( const std::string& name ) const { return theLayout.entries.count( name ); }
52 
53 protected:
56  std::string name;
57  int length;
58  };
59 
62  int index;
63  int length;
64  };
65 
69  std::unordered_map< std::string, StateVarEntryLocation > entries;
71  };
72 
74  static StateVarVectorLayout makeLayout( const std::vector< StateVarEntryDefinition >& theEntries )
75  {
76  std::unordered_map< std::string, StateVarEntryLocation > theMap;
77  int sizeOccupied = 0;
78  for ( const auto& theEntry : theEntries ) {
79  const auto nextLocation = sizeOccupied;
80  theMap[theEntry.name] = { nextLocation, theEntry.length };
81  sizeOccupied += theEntry.length;
82  }
83  return { theMap, sizeOccupied };
84  }
85 
87  double* theStateVars;
88 
91 
93  : theStateVars( theStateVars ), theLayout( theLayout_ ){};
94 };
MarmotStateVarVectorManager::StateVarVectorLayout
Definition: MarmotStateVarVectorManager.h:68
MarmotStateVarVectorManager::StateVarEntryDefinition
An entry in the statevar vector consists of the name and a certain length.
Definition: MarmotStateVarVectorManager.h:55
MarmotStateVarVectorManager::StateVarEntryLocation
The location in the statevar vector consists of the index and its certain length.
Definition: MarmotStateVarVectorManager.h:61
MarmotStateVarVectorManager::MarmotStateVarVectorManager
MarmotStateVarVectorManager(double *theStateVars, const StateVarVectorLayout &theLayout_)
Definition: MarmotStateVarVectorManager.h:92
MarmotStateVarVectorManager
A convenience auxiliary class for managing multiple statevars with arbitrary length in a single conse...
Definition: MarmotStateVarVectorManager.h:37
MarmotStateVarVectorManager::StateVarVectorLayout::nRequiredStateVars
int nRequiredStateVars
Definition: MarmotStateVarVectorManager.h:70
MarmotStateVarVectorManager::StateVarEntryDefinition::name
std::string name
Definition: MarmotStateVarVectorManager.h:56
StateView
Definition: MarmotUtils.h:29
MarmotUtils.h
MarmotStateVarVectorManager::getStateView
StateView getStateView(const std::string &name) const
get a StateView for a statevar entry
Definition: MarmotStateVarVectorManager.h:41
MarmotStateVarVectorManager::StateVarEntryLocation::index
int index
Definition: MarmotStateVarVectorManager.h:62
MarmotStateVarVectorManager::makeLayout
static StateVarVectorLayout makeLayout(const std::vector< StateVarEntryDefinition > &theEntries)
generate the statevar vector layout from a list of entries, defined by name and length
Definition: MarmotStateVarVectorManager.h:74
MarmotStateVarVectorManager::theLayout
const StateVarVectorLayout & theLayout
a const reference to the respective layout
Definition: MarmotStateVarVectorManager.h:90
MarmotStateVarVectorManager::StateVarEntryLocation::length
int length
Definition: MarmotStateVarVectorManager.h:63
MarmotStateVarVectorManager::contains
bool contains(const std::string &name) const
check if the entry with name is managed
Definition: MarmotStateVarVectorManager.h:51
MarmotStateVarVectorManager::StateVarVectorLayout::entries
std::unordered_map< std::string, StateVarEntryLocation > entries
Definition: MarmotStateVarVectorManager.h:69
MarmotStateVarVectorManager::theStateVars
double * theStateVars
pointer to the first element in the statevar vector
Definition: MarmotStateVarVectorManager.h:87
MarmotStateVarVectorManager::StateVarEntryDefinition::length
int length
Definition: MarmotStateVarVectorManager.h:57
MarmotStateVarVectorManager::find
double & find(const std::string &name) const
get the reference to the first array element of an entry in the statevar vector
Definition: MarmotStateVarVectorManager.h:48