v0.10.0
AuxPETSc.hpp
Go to the documentation of this file.
1 /** \file AuxPETSc.hpp
2  * \brief Auxiliary 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  template <typename FEMETHOD>
29  PairNameFEMethodPtr(std::string name, boost::shared_ptr<FEMETHOD> ptr)
30  : std::pair<std::string, FEMethod *>(name, ptr.get()), fePtr(ptr) {}
31  virtual ~PairNameFEMethodPtr() {}
32 
33  inline boost::shared_ptr<BasicMethod> getSharedPtr() const {
34  if (!fePtr)
35  THROW_MESSAGE("Shared pointer not set. You have to be using raw "
36  "pointer, that is unsafe.");
37  return fePtr;
38  }
39 
40 private:
41  boost::shared_ptr<FEMethod> fePtr;
42 };
43 
46  template <typename BASICMETHOD>
47  BasicMethodPtr(boost::shared_ptr<BASICMETHOD> 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__
70 
71 /**
72  * \defgroup mofem_petsc_solvers PETSc solvers
73  * \brief PETSc solvers
74  *
75  * \ingroup mofem
76  */
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:628
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
std::vector< PairNameFEMethodPtr > FEMethodsSequence
Definition: AuxPETSc.hpp:64
std::vector< BasicMethodPtr > BasicMethodsSequence
Definition: AuxPETSc.hpp:65
Data structure to exchange data between mofem and User Loop Methods.
boost::shared_ptr< BasicMethod > getSharedPtr() const
Definition: AuxPETSc.hpp:52
BasicMethod * operator->() const
Definition: AuxPETSc.hpp:50
BasicMethodPtr(boost::shared_ptr< BASICMETHOD > ptr)
Definition: AuxPETSc.hpp:47
boost::shared_ptr< BasicMethod > bmPtr
Definition: AuxPETSc.hpp:61
BasicMethodPtr(BasicMethod *ptr)
Definition: AuxPETSc.hpp:45
BasicMethod * rawPtr
Definition: AuxPETSc.hpp:60
BasicMethod & operator*() const
Definition: AuxPETSc.hpp:49
structure for User Loop Methods on finite elements
PairNameFEMethodPtr(std::string name, boost::shared_ptr< FEMETHOD > ptr)
Definition: AuxPETSc.hpp:29
boost::shared_ptr< BasicMethod > getSharedPtr() const
Definition: AuxPETSc.hpp:33
virtual ~PairNameFEMethodPtr()
Definition: AuxPETSc.hpp:31
boost::shared_ptr< FEMethod > fePtr
Definition: AuxPETSc.hpp:41
PairNameFEMethodPtr(std::string name, FEMethod *ptr)
Definition: AuxPETSc.hpp:26