ug4
replace_coordinate.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017: 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_replace_coordinate
34 #define __H__UG_replace_coordinate
35 
36 namespace ug{
37 
39 
44 template <int dim>
46 {
47 public:
51 
52  PPP_ReplaceCoordinate (apos_t aPos, ANumber aNewCoord, int newCoordIndex) :
53  m_aPos (aPos),
54  m_aNewCoord (aNewCoord),
55  m_newCoordIndex (newCoordIndex)
56  {}
57 
58 
59  virtual void partitioning_starts ( MultiGrid* mg,
60  IPartitioner* partitioner)
61  {
62  if (!mg->has_vertex_attachment(m_aPos)){
63  UG_LOG("WARNING: Target attachment not found in PartitionPreProcessor "
64  "PPP_ReplaceCoordinate");
65  return;
66  }
67 
69  UG_LOG("WARNING: Attachment 'aNewCoord' not found in PartitionPreProcessor "
70  "PPP_ReplaceCoordinate");
71  return;
72  }
73 
75  "VertexAttachment missing: aNewCoord");
76 
77  // attach a temporary field where we store the original coordinates
79 
80  // store the current original coordinate of m_aPos in m_aOrigCoord
81  // and replace with new coordinate
82 
83  typename aapos_t::ContainerType& positions
85 
86  typename ANumber::ContainerType& origCoords
88 
89  typename ANumber::ContainerType& newCoords
91 
92  UG_COND_THROW ( (positions.size() != origCoords.size())
93  || (positions.size() != newCoords.size()),
94  "Attachment containers have incompatible sizes");
95 
96  for(size_t i = 0; i < positions.size(); ++i){
97  origCoords[i] = positions[i][m_newCoordIndex];
98  positions[i][m_newCoordIndex] = newCoords[i];
99  }
100  }
101 
102 
103  virtual void partitioning_done ( MultiGrid* mg,
104  IPartitioner* partitioner)
105  {
106  if (!mg->has_vertex_attachment(m_aPos)){
107  UG_LOG("WARNING: Target attachment not found in PartitionPreProcessor "
108  "PPP_ReplaceCoordinate");
109  return;
110  }
111 
113  UG_LOG("WARNING: Attachment 'aOrigCoord' not found in PartitionPreProcessor "
114  "PPP_ReplaceCoordinate");
115  return;
116  }
117 
118  typename aapos_t::ContainerType& positions
120 
121  typename ANumber::ContainerType& origCoords
123 
124  UG_COND_THROW ( positions.size() != origCoords.size(),
125  "Attachment containers have incompatible sizes");
126 
127  for(size_t i = 0; i < positions.size(); ++i){
128  positions[i][m_newCoordIndex] = origCoords[i];
129  }
130 
132  }
133 
134 private:
139 };
140 
141 }// end of namespace
142 
143 #endif //__H__UG_replace_coordinate
A generic specialization of IAttachedDataContainer.
Definition: attachment_pipe.h:135
void detach_from_vertices(IAttachment &attachment)
Definition: grid.h:787
bool has_vertex_attachment(IAttachment &attachment)
Definition: grid.h:798
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition: grid.h:728
TAttachment::ContainerType * get_attachment_data_container(TAttachment &attachment)
Definition: grid_impl.hpp:399
allows to pre-process data before partitioning starts
Definition: partitioner.h:119
Partitioners can be used inside a LoadBalancer or separately to create partition maps.
Definition: partitioner.h:162
Definition: multi_grid.h:72
Temporarily replaces the specified coordinate in the given position attachment.
Definition: replace_coordinate.h:46
Grid::VertexAttachmentAccessor< apos_t > aapos_t
Definition: replace_coordinate.h:50
Attachment< vector_t > apos_t
Definition: replace_coordinate.h:49
virtual void partitioning_starts(MultiGrid *mg, IPartitioner *partitioner)
Definition: replace_coordinate.h:59
apos_t m_aPos
Definition: replace_coordinate.h:135
int m_newCoordIndex
Definition: replace_coordinate.h:138
MathVector< dim > vector_t
Definition: replace_coordinate.h:48
ANumber m_aNewCoord
Definition: replace_coordinate.h:136
ANumber m_aOrigCoord
Definition: replace_coordinate.h:137
virtual void partitioning_done(MultiGrid *mg, IPartitioner *partitioner)
Definition: replace_coordinate.h:103
PPP_ReplaceCoordinate(apos_t aPos, ANumber aNewCoord, int newCoordIndex)
Definition: replace_coordinate.h:52
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
#define UG_LOG(msg)
Definition: log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
the ug namespace