Marmot.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  * Magdalena Schreter magdalena.schreter@uibk.ac.at
16  *
17  * This file is part of the MAteRialMOdellingToolbox (marmot).
18  *
19  * This library is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU Lesser General Public
21  * License as published by the Free Software Foundation; either
22  * version 2.1 of the License, or (at your option) any later version.
23  *
24  * The full text of the license can be found in the file LICENSE.md at
25  * the top level directory of marmot.
26  * ---------------------------------------------------------------------
27  */
28 #pragma once
29 #include "Marmot/MarmotElement.h"
30 #include "Marmot/MarmotMaterial.h"
31 #include <functional>
32 #include <iostream>
33 #include <string>
34 #include <unordered_map>
35 
36 namespace MarmotLibrary {
37 
38  // MaterialFactory
39  //
40  // - Allows materials to register themselve with their name and ID
41  // - Allows the user to create instances of materials
42 
44  public:
45  using materialFactoryFunction = MarmotMaterial* (*)( const double* materialProperties,
46  int nMaterialProperties,
47  int materialNumber );
49 
50  static int getMaterialCodeFromName( const std::string& materialName );
51 
52  static MarmotMaterial* createMaterial( int materialCode,
53  const double* materialProperties,
54  int nMaterialProperties,
55  int materialNumber );
56 
57  static bool registerMaterial( int materialCode,
58  const std::string& materialName,
59  materialFactoryFunction factoryFunction );
60 
61  private:
62  static std::unordered_map< std::string, int > materialNameToCodeAssociation;
63  static std::unordered_map< int, materialFactoryFunction > materialFactoryFunctionByCode;
64  };
65 
66  // ElementFactory
67  //
68  // - Allows elements to register themselve with their name and ID
69  // - Allows the user to create instances of elements
70 
72  public:
73  using elementFactoryFunction = MarmotElement* (*)( int elementNumber );
75 
76  static int getElementCodeFromName( const std::string& elementName );
77 
78  static MarmotElement* createElement( int elementCode, int elementNumber );
79 
80  static bool registerElement( const std::string& elementName,
81  int elementCode,
82  elementFactoryFunction factoryFunction );
83 
84  private:
85  static std::unordered_map< std::string, int > elementNameToCodeAssociation;
86  static std::unordered_map< int, elementFactoryFunction > elementFactoryFunctionByCode;
87  };
88 
89 } // namespace MarmotLibrary
MarmotLibrary::MarmotMaterialFactory::MarmotMaterialFactory
MarmotMaterialFactory()=delete
MarmotLibrary::MarmotElementFactory
Definition: Marmot.h:71
MarmotElement
Definition: MarmotElement.h:34
MarmotLibrary::MarmotMaterialFactory
Definition: Marmot.h:43
MarmotLibrary::MarmotMaterialFactory::materialFactoryFunctionByCode
static std::unordered_map< int, materialFactoryFunction > materialFactoryFunctionByCode
Definition: Marmot.h:63
MarmotLibrary::MarmotElementFactory::elementFactoryFunction
MarmotElement *(*)(int elementNumber) elementFactoryFunction
Definition: Marmot.h:73
MarmotLibrary::MarmotMaterialFactory::createMaterial
static MarmotMaterial * createMaterial(int materialCode, const double *materialProperties, int nMaterialProperties, int materialNumber)
MarmotLibrary
Definition: Marmot.h:36
MarmotLibrary::MarmotMaterialFactory::getMaterialCodeFromName
static int getMaterialCodeFromName(const std::string &materialName)
MarmotLibrary::MarmotElementFactory::createElement
static MarmotElement * createElement(int elementCode, int elementNumber)
MarmotLibrary::MarmotElementFactory::elementFactoryFunctionByCode
static std::unordered_map< int, elementFactoryFunction > elementFactoryFunctionByCode
Definition: Marmot.h:86
MarmotLibrary::MarmotMaterialFactory::materialNameToCodeAssociation
static std::unordered_map< std::string, int > materialNameToCodeAssociation
Definition: Marmot.h:62
MarmotElement.h
MarmotMaterial
Definition: MarmotMaterial.h:32
MarmotLibrary::MarmotElementFactory::registerElement
static bool registerElement(const std::string &elementName, int elementCode, elementFactoryFunction factoryFunction)
MarmotLibrary::MarmotElementFactory::elementNameToCodeAssociation
static std::unordered_map< std::string, int > elementNameToCodeAssociation
Definition: Marmot.h:85
MarmotLibrary::MarmotMaterialFactory::registerMaterial
static bool registerMaterial(int materialCode, const std::string &materialName, materialFactoryFunction factoryFunction)
MarmotLibrary::MarmotMaterialFactory::materialFactoryFunction
MarmotMaterial *(*)(const double *materialProperties, int nMaterialProperties, int materialNumber) materialFactoryFunction
Definition: Marmot.h:47
MarmotMaterial.h
MarmotLibrary::MarmotElementFactory::getElementCodeFromName
static int getElementCodeFromName(const std::string &elementName)
MarmotLibrary::MarmotElementFactory::MarmotElementFactory
MarmotElementFactory()=delete