Module.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 "Module.hpp"
26 
27 namespace mimmo{
28 
32  m_name = "mimmo.Module";
33 }
34 
39 Module::Module(const bitpit::Config::Section & rootXML){
40 
41  std::string fallback_name = "ClassNONE";
42  std::string input_name = rootXML.get("ClassName", fallback_name);
43  input_name = bitpit::utils::string::trim(input_name);
44 
45  m_name = "mimmo.Module";
46 
47  if(input_name == "mimmo.Module"){
48  absorbSectionXML(rootXML);
49  }else{
51  };
52 }
53 
58 
63 Module::Module(const Module & other):BaseManipulation(other){
64  m_field = other.m_field;
65  m_result = other.m_result;
66 }
67 
72 void Module::swap(Module & x ) noexcept
73 {
74  m_field.swap(x.m_field);
75  m_result.swap(x.m_result);
77 };
78 
84  this->swap(other);
85  return *this;
86 };
87 
91 void
93  bool built = true;
94  built = (built && createPortIn<dmpvecarr3E*, Module>(this, &mimmo::Module::setField, M_VECTORFIELD, true));
95  built = (built && createPortOut<dmpvector1D*, Module>(this, &mimmo::Module::getResult, M_SCALARFIELD));
96  m_arePortsBuilt = built;
97 }
98 
102 void
104  m_field.clear();
105  m_result.clear();
107 };
108 
113 void
115  if(!field) return;
116  m_field = *field;
117 }
118 
123 dmpvector1D *
125  return &m_result;
126 }
127 
131 void
133 
135 
136  m_result.clear();
139 
140  for (long id : m_field.getIds()){
141  double val = norm2(m_field[id]);
142  m_result.insert(id, val);
143  }
144 }
145 
146 
150 void
152 
153  m_result.setName("magnitude");
155 
156 }
157 
163 void Module::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
164 
165  BITPIT_UNUSED(name);
166  BaseManipulation::absorbSectionXML(slotXML, name);
167 
168 };
169 
175 void Module::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
176 
177  BITPIT_UNUSED(name);
178  BaseManipulation::flushSectionXML(slotXML, name);
179 
180 };
181 
182 }
Module & operator=(Module other)
Definition: Module.cpp:83
dmpvecarr3E m_field
Definition: Module.hpp:68
void swap(Module &x) noexcept
Definition: Module.cpp:72
dmpvector1D * getResult()
Definition: Module.cpp:124
MPVLocation
Define data location for the MimmoPiercedVector field.
void clear()
Definition: Module.cpp:103
void setName(std::string name)
void execute()
Definition: Module.cpp:132
void warningXML(bitpit::Logger *log, std::string name)
Module is an executable block class capable of computing the magnitude field of a vector field.
Definition: Module.hpp:66
BaseManipulation is the base class of any manipulation object of the library.
#define M_VECTORFIELD
MimmoSharedPointer< MimmoObject > getGeometry() const
dmpvector1D m_result
Definition: Module.hpp:69
void write(MimmoSharedPointer< MimmoObject > geometry)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setField(dmpvecarr3E *field)
Definition: Module.cpp:114
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void plotOptionalResults()
Definition: Module.cpp:151
void setGeometry(MimmoSharedPointer< MimmoObject > geo)
void setDataLocation(MPVLocation loc)
#define M_SCALARFIELD
virtual ~Module()
Definition: Module.cpp:57
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
Definition: Module.cpp:175
void swap(BaseManipulation &x) noexcept
void buildPorts()
Definition: Module.cpp:92
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Definition: Module.cpp:163