-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSpaceEParms.h
135 lines (109 loc) · 6.33 KB
/
JSpaceEParms.h
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
//HEAD_DSCODES
/*
<DUALSPHYSICS> Copyright (c) 2020 by Dr Jose M. Dominguez et al. (see http://dual.sphysics.org/index.php/developers/).
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 <http://www.gnu.org/licenses/>.
*/
//:#############################################################################
//:# Cambios:
//:# =========
//:# - Nuevos metodos LoadFileXml() y SaveFileXml() para cargar o generar un
//:# fichero xml de forma directa. (28-11-2010)
//:# - Nuevos metodos GetValueNumInt() y GetValueNumDouble() permiten leer un
//:# valor entre varios dentro del atributo Value. (04-12-2011)
//:# - Traduccion de comentarios al ingles. (10-02-2012)
//:# - Nuevo metodo GetValueNumStr() para leer atributos string. (10-11-2012)
//:# - Nuevo metodo GetValueDouble3() para leer atributos tdouble3. (01-10-2015)
//:# - Se muestran unidades de los parametros. (15-12-2015)
//:# - Nueva definicion del dominio de simulacion. (22-03-2019)
//:# - Objeto JXml pasado como const para operaciones de lectura. (17-03-2020)
//:# - Comprueba que los valores enteros y reales sean validos. (17-03-2020)
//:# - Improved exception managment. (18-03-2020)
//:#############################################################################
/// \file JSpaceEParms.h \brief Declares the class \ref JSpaceEParms.
#ifndef _JSpaceEParms_
#define _JSpaceEParms_
#include <string>
#include <vector>
#include "JObject.h"
#include "TypesDef.h"
class JXml;
class TiXmlElement;
//##############################################################################
//# JSpaceEParms
//##############################################################################
/// \brief Manages the info of execution parameters from the input XML file.
class JSpaceEParms : protected JObject
{
public:
/// Structure used to store information about each parameter.
typedef struct{
std::string key;
std::string value;
std::string comment;
std::string unitscomment;
}JSpaceEParmsItem;
/// Domain configuration mode.
typedef enum{
DC_Fixed=0 ///< Fixed value.
,DC_Default=1 ///< Default.
,DC_DefValue=2 ///< Default +/- value.
,DC_DefPrc=3 ///< Default +/- % of size.
}TpDomainMode;
/// Structure used to store information about default domain position.
typedef struct{
TpDomainMode mode;
double value;
std::string textmod;
}JSpaceEParmsPos;
private:
typedef std::vector<JSpaceEParmsItem> VecList;
typedef std::vector<JSpaceEParmsItem>::iterator VecListIt;
VecList List;
//-Defines simulation domain.
std::string Posminx,Posminy,Posminz;
std::string Posmaxx,Posmaxy,Posmaxz;
int CheckPosValue(const std::string &value,bool isposmin,JSpaceEParmsPos &ps)const;
std::string ReadPosValue(const JXml *sxml,TiXmlElement* ele,const std::string &name,const std::string &subname)const;
JSpaceEParmsItem* GetItemPointer(const std::string &key);
std::string GetValueNum(const std::string &key,int num);
std::string GetValue(const std::string &key);
void ReadXml(const JXml *sxml,TiXmlElement* lis);
void WriteXml(JXml *sxml,TiXmlElement* lis)const;
public:
JSpaceEParms();
~JSpaceEParms();
void Reset();
void Add(const std::string &key,const std::string &value,const std::string &comment,const std::string &unitscomment="");
void SetValue(const std::string &key,const std::string &value);
void SetComment(const std::string &key,const std::string &comment);
bool Exists(const std::string &key){ return(GetItemPointer(key)!=NULL); }
void SetPosmin(std::string x,std::string y,std::string z);
void SetPosmax(std::string x,std::string y,std::string z);
JSpaceEParmsPos GetPosminValue(char key)const;
JSpaceEParmsPos GetPosmaxValue(char key)const;
bool IsPosDefault()const{ return(Posminx=="default" && Posminy=="default" && Posminz=="default" && Posmaxx=="default" && Posmaxy=="default" && Posmaxz=="default"); }
int GetValueNumInt(const std::string &key,int num,bool optional=false,int valdef=0);
double GetValueNumDouble(const std::string &key,int num,bool optional=false,double valdef=0);
float GetValueNumFloat(const std::string &key,int num,bool optional=false,float valdef=0){ return(float(GetValueNumDouble(key,num,optional,valdef))); }
std::string GetValueNumStr(const std::string &key,int num,bool optional=false,std::string valdef="");
int GetValueInt(const std::string &key,bool optional=false,int valdef=0){ return(GetValueNumInt(key,0,optional,valdef)); }
double GetValueDouble(const std::string &key,bool optional=false,double valdef=0){ return(GetValueNumDouble(key,0,optional,valdef)); }
float GetValueFloat(const std::string &key,bool optional=false,float valdef=0){ return(GetValueNumFloat(key,0,optional,valdef)); }
std::string GetValueStr(const std::string &key,bool optional=false,std::string valdef=""){ return(GetValueNumStr(key,0,optional,valdef)); }
tdouble3 GetValueDouble3(const std::string &key,bool optional=false,tdouble3 valdef=TDouble3(0)){ return(TDouble3(GetValueNumDouble(key,0,optional,valdef.x),GetValueNumDouble(key,1,optional,valdef.y),GetValueNumDouble(key,2,optional,valdef.z))); }
unsigned Count()const{ return(unsigned(List.size())); }
std::string ToString(unsigned pos)const;
JSpaceEParmsItem GetParm(unsigned pos)const;
void LoadFileXml(const std::string &file,const std::string &path);
void SaveFileXml(const std::string &file,const std::string &path,bool newfile=true)const;
void LoadXml(const JXml *sxml,const std::string &place);
void SaveXml(JXml *sxml,const std::string &place)const;
};
#endif