MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
nodeman.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/nodeman.cc,v 1.46 2017/01/12 14:46:10 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /* node manager */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include "dataman.h"
37 #include "search.h"
38 
39 /* DataManager - begin */
40 
41 const char sNMClassName[] = "DataManager";
42 
43 void
45 {
46  for (int i = 0; i < Node::LASTNODETYPE; i++) {
47 #if 0
48  NodeData[i].ppFirstNode = NULL;
49  NodeData[i].iNum = 0;
50 #endif
51  NodeData[i].iExpectedNum = 0;
52  NodeData[i].uFlags = 0U;
53  NodeData[i].DefaultOut(::fDefaultOut == 1); /* Da "output.h" */
54  NodeData[i].OutFile = OutputHandler::UNKNOWN; /* Da "output.h" */
55  }
56 
57  /* Se un tipo scrive su un file di output, aggiungere qui il tipo di file */
59  NodeData[Node::ABSTRACT].Desc = "Abstract";
61 
63  NodeData[Node::STRUCTURAL].Desc = "Structural";
65 
67  NodeData[Node::ELECTRIC].Desc = "Electric";
69 
71  NodeData[Node::THERMAL].Desc = "Thermal";
72  NodeData[Node::THERMAL].ShortDesc = "thermal";
73 
75  NodeData[Node::HYDRAULIC].Desc = "Pressure";
77 
79  NodeData[Node::PARAMETER].Desc = "Parameter";
81 }
82 
83 void
85 {
86  DEBUGCOUT("Entering DataManager::NodeManagerDestructor()" << std::endl);
87 
88  for (NodeVecType::iterator p = Nodes.begin(); p != Nodes.end(); ++p) {
89  DEBUGCOUT("deleting node "
90  << psNodeNames[(*p)->GetNodeType()]
91  << "(" << (*p)->GetLabel() << ")"
92  << std::endl);
93  SAFEDELETE(*p);
94  }
95 }
96 
97 void
99 {
100  for (int iCnt = 0; iCnt < Node::LASTNODETYPE; iCnt++) {
102  }
103 
104  DEBUGCOUT("iTotNodes = " << iTotNodes << std::endl);
105 
106  if (iTotNodes > 0) {
107  Nodes.resize(iTotNodes);
108 
109  for (NodeVecType::iterator i = Nodes.begin(); i != Nodes.end(); ++i) {
110  *i = 0;
111  }
112 
113  } else {
114  silent_cerr("warning, no nodes are defined" << std::endl);
115  }
116 }
117 
118 void
120 {
121 #ifdef USE_NETCDF
122  for (unsigned nt = 0; nt < Node::LASTNODETYPE; nt++) {
123  if (!NodeData[nt].NodeContainer.empty() && OH.UseNetCDF(NodeData[nt].OutFile)) {
125 
126  integer iNumNodes = NodeData[nt].NodeContainer.size();
127 
128  OutputHandler::AttrValVec attrs(1);
129  attrs[0] = OutputHandler::AttrVal("description", std::string(NodeData[nt].Desc) + " nodes labels");
130 
131  OutputHandler::NcDimVec dim(1);
132  dim[0] = OH.CreateDim(std::string(NodeData[nt].ShortDesc) + "_node_labels_dim", iNumNodes);
133 
134  NcVar *VarLabels = OH.CreateVar(std::string("node.") + NodeData[nt].ShortDesc, ncInt, attrs, dim);
135 
136  NodeContainerType::const_iterator p = NodeData[nt].NodeContainer.begin();
137  for (unsigned i = 0; i < unsigned(iNumNodes); i++, p++) {
138  VarLabels->set_cur(i);
139  const long l = p->second->GetLabel();
140  VarLabels->put(&l, 1);
141  }
142  }
143  }
144 #endif // USE_NETCDF
145 
146  for (NodeVecType::iterator i = Nodes.begin(); i != Nodes.end(); ++i) {
147  (*i)->OutputPrepare(OH);
148  }
149 }
150 
151 void
153 {
154  for (NodeVecType::const_iterator i = Nodes.begin(); i != Nodes.end(); ++i) {
155  (*i)->Output(OH);
156  }
157 }
158 
159 void
161  OutputHandler& OH,
162  const VectorHandler& X,
163  const VectorHandler& XP) const
164 {
165  for (NodeVecType::const_iterator i = Nodes.begin(); i != Nodes.end(); ++i) {
166  (*i)->Output(OH, X, XP);
167  }
168 }
169 
170 flag
172 {
173  return NodeData[t].bDefaultOut();
174 }
175 
176 
177 /* cerca un nodo qualsiasi */
178 Node*
179 DataManager::pFindNode(Node::Type Typ, unsigned int uL) const
180 {
181  NodeMapToListType::const_iterator p = NodeData[Typ].NodeMapToList.find(uL);
182  if (p == NodeData[Typ].NodeMapToList.end()) {
183  return 0;
184  }
185 
186  return p->second->second;
187 }
188 
189 /* DataManager - end */
const flag fDefaultOut
Definition: output.h:639
NcBool set_cur(long c0=-1, long c1=-1, long c2=-1, long c3=-1, long c4=-1)
long int flag
Definition: mbdyn.h:43
void NodeOutput(OutputHandler &OH) const
Definition: nodeman.cc:152
Definition: node.h:67
bool UseNetCDF(int out) const
Definition: output.cc:491
flag fGetDefaultOutputFlag(const Elem::Type &t) const
Definition: elman.cc:727
NodeVecType Nodes
Definition: dataman.h:743
unsigned int iTotNodes
Definition: dataman.h:748
bool bDefaultOut(void) const
Definition: dataman.h:725
void NodeDataInit(void)
Definition: nodeman.cc:98
NodeContainerType NodeContainer
Definition: dataman.h:731
const char sNMClassName[]
Definition: nodeman.cc:41
void NodeManagerDestructor(void)
Definition: nodeman.cc:84
void NodeManager(void)
Definition: nodeman.cc:44
struct DataManager::NodeDataStructure NodeData[Node::LASTNODETYPE]
Type
Definition: node.h:71
#define DEBUGCOUT(msg)
Definition: myassert.h:232
bool IsOpen(int out) const
Definition: output.cc:395
#define ASSERT(expression)
Definition: colamd.c:977
const char * psNodeNames[]
Definition: enums.cc:372
NodeMapToListType NodeMapToList
Definition: dataman.h:732
OutputHandler::OutFiles OutFile
Definition: dataman.h:725
long int integer
Definition: colamd.c:51
void NodeOutputPrepare(OutputHandler &OH)
Definition: nodeman.cc:119
Node * pFindNode(Node::Type Typ, unsigned int uNode) const
Definition: nodeman.cc:179
NcBool put(const ncbyte *vals, long c0=0, long c1=0, long c2=0, long c3=0, long c4=0)
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710