v0.8.20
AuxPETSc.hpp
Go to the documentation of this file.
1 /** \file AuxPETSc.hpp
2  * \brief Auxuliary MoFEM-PETSc structures
3  */
4 
5 /* This file is part of MoFEM.
6  * MoFEM is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
18 
19 #ifndef __AUXPETSC_HPP__
20 #define __AUXPETSC_HPP__
21 
22 namespace MoFEM {
23 
24 struct PairNameFEMethodPtr : public std::pair<std::string, FEMethod *> {
25 
26  PairNameFEMethodPtr(std::string name, FEMethod *ptr)
27  : std::pair<std::string, FEMethod *>(name, ptr) {}
28  PairNameFEMethodPtr(std::string name, boost::shared_ptr<FEMethod> &ptr)
29  : std::pair<std::string, FEMethod *>(name, ptr.get()), fePtr(ptr) {}
30  virtual ~PairNameFEMethodPtr() {}
31 
32  inline boost::shared_ptr<BasicMethod> getSharedPtr() const {
33  if (!fePtr)
34  THROW_MESSAGE("Shared pointer not set. You have to be using raw "
35  "pointer, that is unsafe.");
36  return fePtr;
37  }
38 
39 private:
40  boost::shared_ptr<FEMethod> fePtr;
41 };
42 
45  BasicMethodPtr(boost::shared_ptr<BasicMethod> &ptr)
46  : rawPtr(ptr.get()), bmPtr(ptr) {}
47  BasicMethodPtr(boost::shared_ptr<FEMethod> &ptr)
48  : rawPtr(ptr.get()), bmPtr(ptr) {}
49  inline BasicMethod &operator*() const { return *rawPtr; };
50  inline BasicMethod *operator->() const { return rawPtr; }
51 
52  inline boost::shared_ptr<BasicMethod> getSharedPtr() const {
53  if (!bmPtr)
54  THROW_MESSAGE("Shared pointer not set. You have to be using raw "
55  "pointer, that is unsafe.");
56  return bmPtr;
57  }
58 
59 private:
61  boost::shared_ptr<BasicMethod> bmPtr;
62 };
63 
64 typedef std::vector<PairNameFEMethodPtr> FEMethodsSequence;
65 typedef std::vector<BasicMethodPtr> BasicMethodsSequence;
66 
67 } // namespace MoFEM
68 
69 #endif // __AUXPETSC_HPP__
BasicMethodPtr(BasicMethod *ptr)
Definition: AuxPETSc.hpp:44
structure for User Loop Methods on finite elementsIt can be used to calculate stiffness matrices...
virtual ~PairNameFEMethodPtr()
Definition: AuxPETSc.hpp:30
STL namespace.
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:618
boost::shared_ptr< BasicMethod > getSharedPtr() const
Definition: AuxPETSc.hpp:32
BasicMethodPtr(boost::shared_ptr< FEMethod > &ptr)
Definition: AuxPETSc.hpp:47
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
BasicMethod * rawPtr
Definition: AuxPETSc.hpp:60
std::vector< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:65
PairNameFEMethodPtr(std::string name, boost::shared_ptr< FEMethod > &ptr)
Definition: AuxPETSc.hpp:28
BasicMethodPtr(boost::shared_ptr< BasicMethod > &ptr)
Definition: AuxPETSc.hpp:45
std::vector< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:64
boost::shared_ptr< BasicMethod > getSharedPtr() const
Definition: AuxPETSc.hpp:52
BasicMethod * operator->() const
Definition: AuxPETSc.hpp:50
boost::shared_ptr< BasicMethod > bmPtr
Definition: AuxPETSc.hpp:61
boost::shared_ptr< FEMethod > fePtr
Definition: AuxPETSc.hpp:40
Data structure to exchange data between mofem and User Loop Methods.It allows to exchange data betwee...
BasicMethod & operator*() const
Definition: AuxPETSc.hpp:49
PairNameFEMethodPtr(std::string name, FEMethod *ptr)
Definition: AuxPETSc.hpp:26