forked from DualSPHysics/DualSPHysics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJCaseVtkOut.cpp
More file actions
240 lines (210 loc) * 9.71 KB
/
JCaseVtkOut.cpp
File metadata and controls
240 lines (210 loc) * 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//HEAD_DSCODES
/*
EPHYSLAB Environmental Physics Laboratory, Universidade de Vigo, Ourense, Spain.
School of Mechanical, Aerospace and Civil Engineering, University of Manchester, Manchester, U.K.
This file is part of DualSPHysics.
DualSPHysics is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
DualSPHysics is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with DualSPHysics. If not, see .
*/
/// \file JCaseVtkOut.cpp \brief Implements the class \ref JCaseVtkOut.
#include "JCaseVtkOut.h"
#include "Functions.h"
#include "JRangeFilter.h"
#include "JXml.h"
#include <climits>
using namespace std;
//##############################################################################
//# JCaseVtkOutFile
//##############################################################################
//==============================================================================
// Constructor.
//==============================================================================
JCaseVtkOutFile::JCaseVtkOutFile(const std::string &file,const std::string &mks):File(file){
Reset();
SetMks(mks);
}
//==============================================================================
// Destructor.
//==============================================================================
JCaseVtkOutFile::~JCaseVtkOutFile(){
Reset();
}
//==============================================================================
// Initialization of variables.
//==============================================================================
void JCaseVtkOutFile::Reset(){
ListMk="";
}
//==============================================================================
// Replace list of mk values.
//==============================================================================
void JCaseVtkOutFile::SetMks(const std::string &mks){
JRangeFilter rg(mks);
ListMk=rg.ToString();
}
//##############################################################################
//# JCaseVtkOut
//##############################################################################
//==============================================================================
// Constructor.
//==============================================================================
JCaseVtkOut::JCaseVtkOut(){
ClassName="JCaseVtkOut";
Reset();
}
//==============================================================================
// Destructor.
//==============================================================================
JCaseVtkOut::~JCaseVtkOut(){
DestructorActive=true;
Reset();
}
//==============================================================================
// Initialization of variables.
//==============================================================================
void JCaseVtkOut::Reset(){
for(unsigned c=0;csize();c++)delete Files[c];
Files.clear();
}
//==============================================================================
// Configures MkBoundFirst and MkFluidFirst.
//==============================================================================
void JCaseVtkOut::ConfigMkFirst(word mkboundfirst,word mkfluidfirst){
Reset();
MkBoundFirst=mkboundfirst;
MkFluidFirst=mkfluidfirst;
}
//==============================================================================
// Configures MkBoundFirst and MkFluidFirst.
//==============================================================================
void JCaseVtkOut::AddFile(const std::string &fname,const std::string &mks){
unsigned cfile=GetByFileName(fname);
if(cfile==UINT_MAX){
JCaseVtkOutFile* pfile=new JCaseVtkOutFile(fname,mks);
Files.push_back(pfile);
}
else Files[cfile]->SetMks(mks);
}
//==============================================================================
/// Returns position in Files (UINT_MAX when it was not found).
//==============================================================================
unsigned JCaseVtkOut::GetByFileName(std::string fname)const{
unsigned ipos=0;
fname=fun::StrLower(fname);
for(;ipos<Count() && fun::StrLower(Files[ipos]->File)!=fname;ipos++);
return(ipos<Count()? ipos: UINT_MAX);
}
//==============================================================================
/// Returns the requested file by number.
//==============================================================================
std::string JCaseVtkOut::GetFile(unsigned idx)const{
if(idx>=Count())Run_Exceptioon("Number of requested file name is invalid.");
return(Files[idx]->File);
}
//==============================================================================
/// Returns the requested file by number.
//==============================================================================
std::string JCaseVtkOut::GetFileListMk(unsigned idx)const{
if(idx>=Count())Run_Exceptioon("Number of requested file info is invalid.");
return(Files[idx]->GetMks());
}
//==============================================================================
/// Returns list of files with indicated key.
//==============================================================================
unsigned JCaseVtkOut::GetFiles(std::string key,std::vector &list)const{
list.clear();
for(unsigned ipos=0;ipos<Count();ipos++){
if(int(Files[ipos]->File.find(key))>=0)list.push_back(Files[ipos]->File);
}
return(unsigned(Files.size()));
}
//==============================================================================
/// Returns list of files with requested mk.
//==============================================================================
unsigned JCaseVtkOut::GetFilesByMk(bool bound,word mk,std::vector &list)const{
list.clear();
for(unsigned ipos=0;ipos<Count();ipos++){
JRangeFilter rg(Files[ipos]->GetMks());
if(rg.CheckValue(mk))list.push_back(Files[ipos]->File);
}
return(unsigned(Files.size()));
}
//==============================================================================
// Replace list of mk values.
//==============================================================================
std::string JCaseVtkOut::GetListMkType(bool bound,const std::string &mks)const{
std::vector<unsigned> values;
JRangeFilter rg(mks);
rg.GetValues(values);
const unsigned nv=unsigned(values.size());
string txmks;
for(unsigned c=0;c
const word v=word(values[c]);
if(bound && v>=MkBoundFirst)txmks=txmks+","+fun::UintStr(v-MkBoundFirst);//-For mkbound.
if(!bound && v>=MkFluidFirst && v","+fun::UintStr(v-MkFluidFirst);//-For mkfluid.
}
rg.Config(txmks);
return(rg.ToString());
}
//==============================================================================
/// Reads particles information in XML format.
//==============================================================================
void JCaseVtkOut::ReadXml(const JXml *sxml,TiXmlElement* lis){
const word mkboundfirst=(word)sxml->GetAttributeUnsigned(lis,"mkboundfirst");
const word mkfluidfirst=(word)sxml->GetAttributeUnsigned(lis,"mkfluidfirst");
ConfigMkFirst(mkboundfirst,mkfluidfirst);
//-Loads files information.
TiXmlElement* ele=lis->FirstChildElement("vtkfile");
while(ele){
const string name=sxml->GetAttributeStr(ele,"name");
const string mks=sxml->GetAttributeStr(ele,"mk");
AddFile(name,mks);
ele=ele->NextSiblingElement("vtkfile");
}
}
//==============================================================================
/// Writes information in XML format.
//==============================================================================
void JCaseVtkOut::WriteXml(JXml *sxml,TiXmlElement* lis)const{
lis->Clear();
JXml::AddAttribute(lis,"mkboundfirst",MkBoundFirst);
JXml::AddAttribute(lis,"mkfluidfirst",MkFluidFirst);
for(unsigned c=0;c<Count();c++){
TiXmlElement item("vtkfile");
JXml::AddAttribute(&item,"name",Files[c]->File);
const string mks=Files[c]->GetMks();
JXml::AddAttribute(&item,"mk",mks);
string mklist=GetListMkType(true,mks);
if(!mklist.empty())JXml::AddAttribute(&item,"mkbound",mklist);
mklist=GetListMkType(false,mks);
if(!mklist.empty())JXml::AddAttribute(&item,"mkfluid",mklist);
lis->InsertEndChild(item)->ToElement();
}
}
//==============================================================================
/// Loads data in XML format from a file.
//==============================================================================
void JCaseVtkOut::LoadFileXml(const std::string &file,const std::string &path){
JXml jxml;
jxml.LoadFile(file);
LoadXml(&jxml,path,false);
}
//==============================================================================
/// Loads information from the object XML.
//==============================================================================
void JCaseVtkOut::LoadXml(const JXml *sxml,const std::string &place,bool optional){
Reset();
TiXmlNode* node=sxml->GetNodeSimple(place);
if(!node && !optional)Run_Exceptioon(std::string("Cannot find the element \'")+place+"\'.");
if(node)ReadXml(sxml,node->ToElement());
}
//==============================================================================
/// Stores information in the object XML.
//==============================================================================
void JCaseVtkOut::SaveXml(JXml *sxml,const std::string &place)const{
WriteXml(sxml,sxml->GetNode(place,true)->ToElement());
}