Primitive.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 
25 #include "Primitive.hpp"
26 
27 namespace mimmo{
28 
33  m_name = "mimmo.Primitive";
34 };
35 
40 Primitive::Primitive(const bitpit::Config::Section & rootXML){
41  m_name = "mimmo.Primitive";
42  std::string fallback_name = "ClassNONE";
43  std::string input = rootXML.get("ClassName", fallback_name);
44  input = bitpit::utils::string::trim(input);
45  if(input == "mimmo.Primitive"){
46  absorbSectionXML(rootXML);
47  }else{
49  };
50 }
51 
54 
59 };
60 
65 void Primitive::swap(Primitive & x) noexcept
66 {
69 }
70 
75 
76  bool built = true;
77  built = (built && createPortIn<darray3E, Primitive>(this, &mimmo::Primitive::setInfLimits, M_INFLIMITS));
78  built = (built && createPortIn<dmatrix33E, Primitive>(this, &mimmo::Primitive::setRefSystem, M_AXES));
79  built = (built && createPortIn<darray3E, Primitive>(this, &mimmo::Primitive::setSpan, M_SPAN));
80  built = (built && createPortIn<darray3E, Primitive>(this, &mimmo::Primitive::setOrigin, M_POINT));
81  built = (built && createPortIn<mimmo::ShapeType, Primitive>(this, &mimmo::Primitive::setShape, M_SHAPE));
82  built = (built && createPortIn<const BasicShape *, Primitive>(this, &mimmo::Primitive::setShape, M_COPYSHAPE));
83  built = (built && createPortIn<int, Primitive>(this, &mimmo::Primitive::setShape, M_SHAPEI));
84 
85  // creating output ports
86  built = (built && createPortOut<BasicShape *, Primitive>(this, &mimmo::Primitive::getShape, M_COPYSHAPE));
87 
88  m_arePortsBuilt = built;
89 };
90 
95  clear(); //base manipulation stuff clear
96  clearMesh(); // structured mesh cleaned
97 };
98 
102 void
104 };
105 
111 void Primitive::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
112 
113  BITPIT_UNUSED(name);
114 
115  BaseManipulation::absorbSectionXML(slotXML, name);
116 
117  if(slotXML.hasOption("Shape")){
118  std::string input = slotXML.get("Shape");
119  input = bitpit::utils::string::trim(input);
120 
121  if(input == "CYLINDER"){
123  }else if(input =="SPHERE"){
125  }else if(input =="WEDGE"){
127  }else{
129  }
130  };
131 
132  if(slotXML.hasOption("Origin")){
133  std::string input = slotXML.get("Origin");
134  input = bitpit::utils::string::trim(input);
135  darray3E temp = {{0.0,0.0,0.0}};
136  if(!input.empty()){
137  std::stringstream ss(input);
138  for(auto &val : temp) ss>>val;
139  }
140  setOrigin(temp);
141  };
142 
143  if(slotXML.hasOption("Span")){
144  std::string input = slotXML.get("Span");
145  input = bitpit::utils::string::trim(input);
146  darray3E temp = {{0.0,0.0,0.0}};
147  if(!input.empty()){
148  std::stringstream ss(input);
149  for(auto &val : temp) ss>>val;
150  }
151  setSpan(temp);
152  };
153 
154  if(slotXML.hasSection("RefSystem")){
155  const bitpit::Config::Section & rfXML = slotXML.getSection("RefSystem");
156  std::string rootAxis = "axis";
157  std::string axis;
158  dmatrix33E temp;
159  temp[0].fill(0.0); temp[0][0] = 1.0;
160  temp[1].fill(0.0); temp[1][1] = 1.0;
161  temp[2].fill(0.0); temp[2][2] = 1.0;
162  for(int i=0; i<3; ++i){
163  axis = rootAxis + std::to_string(i);
164  std::string input = rfXML.get(axis);
165  input = bitpit::utils::string::trim(input);
166  if(!input.empty()){
167  std::stringstream ss(input);
168  for(auto &val : temp[i]) ss>>val;
169  }
170  }
171  setRefSystem(temp);
172  };
173 
174  if(slotXML.hasOption("InfLimits")){
175  std::string input = slotXML.get("InfLimits");
176  input = bitpit::utils::string::trim(input);
177  darray3E temp = {{0.0,0.0,0.0}};
178  if(!input.empty()){
179  std::stringstream ss(input);
180  for(auto &val : temp) ss>>val;
181  }
182  setInfLimits(temp);
183  };
184 
185 }
186 
192 void Primitive::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
193 
194  BITPIT_UNUSED(name);
195 
196  BaseManipulation::flushSectionXML(slotXML, name);
197 
198  std::string towrite = "CUBE";
199 
201  towrite = "CYLINDER";
202  } else if(getShapeType() == ShapeType::SPHERE){
203  towrite = "SPHERE";
204  } else if(getShapeType() == ShapeType::WEDGE){
205  towrite = "WEDGE";
206  }
207  slotXML.set("Shape", towrite);
208 
209  {
210  std::stringstream ss;
211  ss<<std::scientific<<getOrigin()[0]<<'\t'<<getOrigin()[1]<<'\t'<<getOrigin()[2];
212  slotXML.set("Origin", ss.str());
213  }
214 
215  {
216  std::stringstream ss;
217  ss<<std::scientific<<getSpan()[0]<<'\t'<<getSpan()[1]<<'\t'<<getSpan()[2];
218  slotXML.set("Span", ss.str());
219  }
220 
221  {
222  auto rs = getRefSystem();
223  bitpit::Config::Section & rsXML = slotXML.addSection("RefSystem");
224  std::string rootAxis = "axis";
225  std::string localAxis;
226  int counter=0;
227  for(auto &axis : rs){
228  localAxis = rootAxis+std::to_string(counter);
229  std::stringstream ss;
230  ss<<std::scientific<<axis[0]<<'\t'<<axis[1]<<'\t'<<axis[2];
231  rsXML.set(localAxis, ss.str());
232  ++counter;
233  }
234  }
235 
236 };
237 
238 }
void clearPrimitive()
Definition: Primitive.cpp:94
void setRefSystem(darray3E, darray3E, darray3E)
void setOrigin(darray3E origin)
const BasicShape * getShape() const
#define M_POINT
virtual ~Primitive()
Definition: Primitive.cpp:53
void warningXML(bitpit::Logger *log, std::string name)
BaseManipulation is the base class of any manipulation object of the library.
void setShape(ShapeType type=ShapeType::CUBE)
#define M_SHAPE
#define M_SHAPEI
#define M_INFLIMITS
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::array< darray3E, 3 > dmatrix33E
#define M_SPAN
#define M_AXES
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Definition: Primitive.cpp:111
ShapeType getShapeType()
Class for 3D uniform structured mesh.
Definition: BasicMeshes.hpp:44
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
Definition: Primitive.cpp:192
#define M_COPYSHAPE
std::array< double, 3 > darray3E
void setSpan(double, double, double)
void swap(UStructMesh &x) noexcept
darray3E getOrigin()
void swap(BaseManipulation &x) noexcept
void setInfLimits(double val, int dir)
void swap(Primitive &) noexcept
Definition: Primitive.cpp:65
dmatrix33E getRefSystem()
Primitive object generation.
Definition: Primitive.hpp:92