ug4
field.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG_field__
34 #define __H__UG_field__
35 
37 #include <boost/serialization/split_member.hpp> // if boost is not from BoostForUG4 for separate load/save methods
38 
39 namespace ug{
40 
41 template <class T>
42 class Field{
43  public:
44  Field();
45  Field(size_t width, size_t height);
46  Field(size_t width, size_t height, const T& value);
47  Field(const Field& f);
48  ~Field();
49 
50  Field& operator=(const Field& field);
51 
52  void resize_no_copy(size_t width, size_t height);
53 
54  inline T& at(size_t x, size_t y);
55  inline const T& at(size_t x, size_t y) const;
56 
57  size_t width() const {return m_width;}
58  size_t height() const {return m_height;}
59  size_t size() const {return m_width * m_height;}
60  size_t capacity() const {return m_capacity;}
61  T* data() {return m_data;}
62  const T* data() const {return m_data;}
63 
64  void fill(size_t x, size_t y, size_t w, size_t h, const T& value);
65  void fill_all(const T& value);
66  void copy(size_t x, size_t y, const Field& f);
67  void swap(Field& f);
68 
69  private:
70  inline size_t array_index(size_t x, size_t y) const;
71 
72  // BEGIN SERIALIZATION
74 
75  template <class Archive>
76  void save( Archive& ar, const unsigned int version) const;
77 
78  template <class Archive>
79  void load( Archive& ar, const unsigned int version);
80 
81  BOOST_SERIALIZATION_SPLIT_MEMBER()
82  // END SERIALIZATION
83 
84  size_t m_width;
85  size_t m_height;
86  size_t m_capacity;
87  T* m_data;
88 };
89 
90 }// end of namespace
91 
92 
94 // include implementation
95 #include "field_impl.hpp"
96 
97 #endif //__H__UG_field__
Definition: field.h:42
size_t size() const
Definition: field.h:59
size_t width() const
Definition: field.h:57
T * m_data
Definition: field.h:87
size_t m_height
Definition: field.h:85
~Field()
Definition: field_impl.hpp:79
size_t capacity() const
Definition: field.h:60
T & at(size_t x, size_t y)
Definition: field_impl.hpp:113
void save(Archive &ar, const unsigned int version) const
Definition: field_impl.hpp:180
void copy(size_t x, size_t y, const Field &f)
Definition: field_impl.hpp:147
size_t array_index(size_t x, size_t y) const
Definition: field_impl.hpp:172
size_t m_width
Definition: field.h:84
const T * data() const
Definition: field.h:62
void fill_all(const T &value)
Definition: field_impl.hpp:139
size_t height() const
Definition: field.h:58
friend class boost::serialization::access
Definition: field.h:73
void fill(size_t x, size_t y, size_t w, size_t h, const T &value)
Definition: field_impl.hpp:123
Field()
Definition: field_impl.hpp:42
T * data()
Definition: field.h:61
size_t m_capacity
Definition: field.h:86
void load(Archive &ar, const unsigned int version)
Definition: field_impl.hpp:193
void swap(Field &f)
Definition: field_impl.hpp:162
void resize_no_copy(size_t width, size_t height)
Definition: field_impl.hpp:100
Field & operator=(const Field &field)
Definition: field_impl.hpp:85
the ug namespace