TranslationGeometry.cpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #include "TranslationGeometry.hpp"
25 
26 namespace mimmo{
27 
28 
33  m_direction = direction;
34  m_alpha = 0.0;
35  m_name = "mimmo.TranslationGeometry";
36 };
37 
42 TranslationGeometry::TranslationGeometry(const bitpit::Config::Section & rootXML){
43 
44  m_direction.fill(0.0);
45  m_alpha = 0.0;
46  m_name = "mimmo.TranslationGeometry";
47 
48  std::string fallback_name = "ClassNONE";
49  std::string input = rootXML.get("ClassName", fallback_name);
50  input = bitpit::utils::string::trim(input);
51  if(input == "mimmo.TranslationGeometry"){
52  absorbSectionXML(rootXML);
53  }else{
55  };
56 }
57 
61 
65  m_direction = other.m_direction;
66  m_alpha = other.m_alpha;
67  m_filter = other.m_filter;
68 };
69 
73  swap(other);
74  return *this;
75 };
76 
82 {
83  std::swap(m_direction, x.m_direction);
84  std::swap(m_alpha, x.m_alpha);
85  m_filter.swap(x.m_filter);
86  m_displ.swap(x.m_displ);
88 }
89 
92 void
94  bool built = true;
95  built = (built && createPortIn<darray3E, TranslationGeometry>(&m_direction, M_AXIS));
96  built = (built && createPortIn<double, TranslationGeometry>(&m_alpha, M_VALUED));
97  built = (built && createPortIn<dmpvector1D*, TranslationGeometry>(this, &mimmo::TranslationGeometry::setFilter, M_FILTER));
98  built = (built && createPortIn<MimmoSharedPointer<MimmoObject>, TranslationGeometry>(&m_geometry, M_GEOM, true));
99  built = (built && createPortOut<dmpvecarr3E*, TranslationGeometry>(this, &mimmo::TranslationGeometry::getDisplacements, M_GDISPLS));
100  built = (built && createPortOut<MimmoSharedPointer<MimmoObject>, TranslationGeometry>(this, &BaseManipulation::getGeometry, M_GEOM));
101  m_arePortsBuilt = built;
102 };
103 
107 void
109  m_direction = direction;
110  double L = norm2(m_direction);
111  for (int i=0; i<3; i++)
112  m_direction[i] /= L;
113 }
114 
118 void
120  m_alpha = alpha;
121 }
122 
127 void
129  if(!filter) return;
130  m_filter = *filter;
131 }
132 
139  return &m_displ;
140 };
141 
145 void
147 
148  if(getGeometry() == nullptr){
149  (*m_log)<<m_name + " : nullptr pointer to linked geometry found"<<std::endl;
150  throw std::runtime_error(m_name + "nullptr pointer to linked geometry found");
151  }
152 
153 
154  checkFilter();
155  m_displ.clear();
156  m_displ.clear();
158  m_displ.reserve(getGeometry()->getNVertices());
159  m_displ.setGeometry(getGeometry());
160 
161 
162  long ID;
163  darray3E value;
164  for (const auto & vertex : m_geometry->getVertices()){
165  ID = vertex.getId();
166  value = m_alpha*m_direction*m_filter[ID];
167  m_displ.insert(ID, value);
168  }
169 };
170 
174 void
176  _apply(m_displ);
177 }
178 
183 void
185  bool check = m_filter.getDataLocation() == mimmo::MPVLocation::POINT;
186  check = check && m_filter.completeMissingData(0.0);
187  check = check && m_filter.getGeometry() == getGeometry();
188 
189  if (!check){
190  m_log->setPriority(bitpit::log::Verbosity::DEBUG);
191  (*m_log)<<"Not valid filter found in "<<m_name<<". Proceeding with default unitary field"<<std::endl;
192  m_log->setPriority(bitpit::log::Verbosity::NORMAL);
193 
194  m_filter.clear();
195  m_filter.setGeometry(m_geometry);
197  m_filter.reserve(getGeometry()->getNVertices());
198  for (const auto & vertex : getGeometry()->getVertices()){
199  m_filter.insert(vertex.getId(), 1.0);
200  }
201  }
202 }
203 
209 void
210 TranslationGeometry::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
211 
212  BITPIT_UNUSED(name);
213 
214  BaseManipulation::absorbSectionXML(slotXML, name);
215 
216  if(slotXML.hasOption("Direction")){
217  std::string input = slotXML.get("Direction");
218  input = bitpit::utils::string::trim(input);
219  darray3E temp = {{0.0,0.0,0.0}};
220  if(!input.empty()){
221  std::stringstream ss(input);
222  for(auto &val : temp) ss>>val;
223  }
224  setDirection(temp);
225  }
226 
227  if(slotXML.hasOption("Translation")){
228  std::string input = slotXML.get("Translation");
229  input = bitpit::utils::string::trim(input);
230  double temp = 0.0;
231  if(!input.empty()){
232  std::stringstream ss(input);
233  ss>>temp;
234  }
235  setTranslation(temp);
236  }
237 
238 };
239 
245 void
246 TranslationGeometry::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
247 
248  BITPIT_UNUSED(name);
249  BaseManipulation::flushSectionXML(slotXML, name);
250  {
251  std::stringstream ss;
252  ss<<std::scientific<<m_direction[0]<<'\t'<<m_direction[1]<<'\t'<<m_direction[2];
253  slotXML.set("Direction", ss.str());
254  }
255 
256  slotXML.set("Translation", std::to_string(m_alpha));
257 };
258 
259 }
void setFilter(dmpvector1D *filter)
#define M_GDISPLS
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setDirection(darray3E direction)
#define M_GEOM
TranslationGeometry(darray3E direction={ {0, 0, 0} })
TranslationGeometry & operator=(TranslationGeometry other)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
bool completeMissingData(const mpv_t &defValue)
void warningXML(bitpit::Logger *log, std::string name)
BaseManipulation is the base class of any manipulation object of the library.
MimmoSharedPointer< MimmoObject > getGeometry() const
void swap(TranslationGeometry &x) noexcept
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
MimmoSharedPointer< MimmoObject > m_geometry
#define M_VALUED
void setGeometry(MimmoSharedPointer< MimmoObject > geo)
void _apply(MimmoPiercedVector< darray3E > &displacements)
void setDataLocation(MPVLocation loc)
std::array< double, 3 > darray3E
#define M_AXIS
TranslationGeometry is the class that applies a translation to a given geometry patch.
MimmoSharedPointer< MimmoObject > getGeometry()
void swap(BaseManipulation &x) noexcept
#define M_FILTER