Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hydraulicModel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘乐
hydraulicModel
Commits
0151749c
Commit
0151749c
authored
Jun 05, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1, 水力模型
parent
795d3bed
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
190 additions
and
36 deletions
+190
-36
CivHydrCalc.cpp
pandaAnalysis/CivHydrCalc.cpp
+48
-10
CivInp.cpp
pandaAnalysis/CivInp.cpp
+5
-15
CivInp.h
pandaAnalysis/CivInp.h
+0
-2
main.cpp
pandaAnalysis/main.cpp
+4
-3
CivCommonUtils.cpp
pandaDbManager/CivCommonUtils.cpp
+7
-0
CivCommonUtils.h
pandaDbManager/CivCommonUtils.h
+5
-0
CivDbConnection.cpp
pandaDbManager/CivDbConnection.cpp
+105
-2
CivDbConnection.h
pandaDbManager/CivDbConnection.h
+3
-2
CivTypes.h
pandaDbManager/CivTypes.h
+13
-2
pandaHydrCalc.csprojAssemblyReference.cache
...etstandard2.0/pandaHydrCalc.csprojAssemblyReference.cache
+0
-0
No files found.
pandaAnalysis/CivHydrCalc.cpp
View file @
0151749c
...
...
@@ -23,10 +23,6 @@ bool CivHydrCalc::simulation(char* fileName, char* rptFile, char* binOutFile)
if
(
!
exportInp
(
fileName
))
return
false
;
// 等待
int
index
=
10000
;
while
(
index
-->
0
){}
short
hydCode
=
1
;
long
t
(
0
),
tstep
(
0
);
int
iTime
(
0
);
...
...
@@ -73,6 +69,9 @@ bool CivHydrCalc::simulation(char* fileName, char* rptFile, char* binOutFile)
iTime
++
;
// 获取当前节点和管段数据
getNodeResult
(
t
);
getLinkResult
(
t
);
}
while
(
tstep
>
0
);
// 获取计算结果
...
...
@@ -102,8 +101,6 @@ bool CivHydrCalc::exportInp(char* fileName)
assemble
(
table
,
civInp
);
}
mDbConn
->
close
();
// 主动关闭连接
/*
UNITS LPS
...
...
@@ -233,6 +230,42 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
else
if
(
RESIVOIR
==
table
)
// 水源
{
//;ID Head Pattern
Civitems
coordItems
;
Civitems
resirvoirItems
;
ResivoirFields
fields
;
int
total
=
comps
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
Componet
comp
=
comps
[
i
];
Str
id
=
comp
.
find
(
fields
.
ID
)
->
second
;
Str
elevation
=
comp
.
find
(
fields
.
Elev
)
->
second
;
Str
flow
=
comp
.
find
(
fields
.
Flow
)
->
second
;
Str
head
=
comp
.
find
(
fields
.
Head
)
->
second
;
Str
pattern
=
comp
.
find
(
fields
.
Pattern
)
->
second
;
Str
x_coord
=
comp
.
find
(
fields
.
X_Coord
)
->
second
;
Str
y_coord
=
comp
.
find
(
fields
.
Y_Coord
)
->
second
;
// 注意顺序
//1, coord
CivItem
civItem
;
civItem
.
push_back
(
id
);
civItem
.
push_back
(
head
);
civItem
.
push_back
(
pattern
);
resirvoirItems
.
push_back
(
civItem
);
// 2, 节点坐标
CivItem
nodeCoordItem
;
nodeCoordItem
.
push_back
(
id
);
nodeCoordItem
.
push_back
(
x_coord
);
nodeCoordItem
.
push_back
(
y_coord
);
coordItems
.
push_back
(
nodeCoordItem
);
}
inp
.
writeComponet
(
coordItems
,
_COORDS
);
inp
.
writeComponet
(
resirvoirItems
,
_RESERVOIRS
);
}
else
if
(
PUMP
==
table
)
// 水泵
...
...
@@ -256,8 +289,9 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
Str
minLevel
=
comp
.
find
(
tkfFileds
.
MinLevel
)
->
second
;
Str
maxLevel
=
comp
.
find
(
tkfFileds
.
MaxLevel
)
->
second
;
Str
diametor
=
comp
.
find
(
tkfFileds
.
Diameter
)
->
second
;
Str
minVol
=
comp
.
find
(
tkfFileds
.
MinVol
)
->
second
;
Str
volCurve
=
comp
.
find
(
tkfFileds
.
VolCurve
)
->
second
;
//
Str volCurve = comp.find(tkfFileds.VolCurve)->second;
Str
x_coord
=
comp
.
find
(
tkfFileds
.
X_Coord
)
->
second
;
Str
y_coord
=
comp
.
find
(
tkfFileds
.
Y_Coord
)
->
second
;
...
...
@@ -270,7 +304,8 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
tankNode
.
push_back
(
minLevel
);
tankNode
.
push_back
(
maxLevel
);
tankNode
.
push_back
(
diametor
);
tankNode
.
push_back
(
volCurve
);
tankNode
.
push_back
(
minVol
);
// tankNode.push_back(volCurve);
tankItems
.
push_back
(
tankNode
);
...
...
@@ -281,6 +316,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
nodeCoordItem
.
push_back
(
y_coord
);
nodeCoordItems
.
push_back
(
nodeCoordItem
);
}
inp
.
writeComponet
(
nodeCoordItems
,
_COORDS
);
...
...
@@ -378,15 +414,16 @@ void CivHydrCalc::getLinkResult(short time)
bool
DLLEXPORT
dynamicCompute
(
std
::
string
uri
,
std
::
string
netName
,
std
::
string
flag
)
{
char
*
finalUri
=
const_cast
<
char
*>
(
uri
.
c_str
());
CivHydrCalc
*
calc
=
new
CivHydrC
alc
(
finalUri
,
netName
);
CivHydrCalc
c
alc
(
finalUri
,
netName
);
char
fileName
[
20
];
char
rptR
[
20
];
char
outBinFile
[
20
];
const
char
*
file
=
"test.inp"
;
strcpy_s
(
fileName
,
"test.inp"
);
strcpy_s
(
rptR
,
"test.rpt"
);
strcpy_s
(
outBinFile
,
"test.bin"
);
return
calc
->
simulation
(
fileName
,
rptR
,
outBinFile
);
return
calc
.
simulation
(
fileName
,
rptR
,
outBinFile
);
}
\ No newline at end of file
pandaAnalysis/CivInp.cpp
View file @
0151749c
#include "CivInp.h"
#include "CivCommonUtils.h"
#include<time.h>
CivInp
::
CivInp
(
TimeUnit
timetype
)
:
mTimeUnit
(
timetype
)
...
...
@@ -14,9 +15,11 @@ bool CivInp::writeToFile(const char* fileName)
if
(
file
=
fopen
(
fileName
,
"wb"
))
{
fprintf
(
file
,
mTextStream
.
str
().
c_str
());
mTextStream
.
clear
();
fclose
(
file
);
return
true
;
}
mTextStream
.
clear
();
return
false
;
}
...
...
@@ -246,24 +249,11 @@ void CivInp::writeTags(Civitems items)
writeString
(
""
);
}
std
::
string
CivInp
::
currentTime
()
{
time_t
timep
;
struct
tm
*
p
;
time
(
&
timep
);
p
=
gmtime
(
&
timep
);
std
::
string
currTime
=
std
::
to_string
(
1900
+
p
->
tm_year
)
+
"/"
+
std
::
to_string
(
1
+
p
->
tm_mon
)
+
\
"/"
+
std
::
to_string
(
p
->
tm_mday
)
+
" "
+
std
::
to_string
(
p
->
tm_hour
)
+
":"
+
std
::
to_string
(
p
->
tm_min
)
+
":"
+
\
std
::
to_string
(
p
->
tm_sec
);
return
currTime
;
}
void
CivInp
::
writeTitles
()
{
writeString
(
"[TITLE]"
);
// дǩ
writeString
(
"Scenario: Base"
);
writeString
(
"Date:"
+
currentTime
());
writeString
(
"Date:"
+
CivCommonUtils
::
currentTime
());
writeString
(
""
);
writeString
(
""
);
}
...
...
pandaAnalysis/CivInp.h
View file @
0151749c
...
...
@@ -152,8 +152,6 @@ private:
void
writeOptions
(
const
Civitems
&
items
);
void
writePatterns
(
Civitems
items
);
void
writeDemand
(
Civitems
items
);
std
::
string
currentTime
();
private
:
std
::
ostringstream
mTextStream
;
...
...
pandaAnalysis/main.cpp
View file @
0151749c
...
...
@@ -5,7 +5,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
uri
=
"host=192.168.12.7 port=5432 dbname=
liuletext
user=postgres password=admin"
;
const
char
*
uri
=
"host=192.168.12.7 port=5432 dbname=
2222
user=postgres password=admin"
;
char
*
findUri
=
const_cast
<
char
*>
(
uri
);
CivHydrCalc
*
calc
=
new
CivHydrCalc
(
findUri
,
std
::
string
(
"ˮģ"
));
char
fileName
[
20
];
...
...
@@ -16,8 +16,8 @@ int main(int argc, char* argv[])
strcpy_s
(
rptR
,
"test.rpt"
);
strcpy_s
(
outBinFile
,
"test.bin"
);
//
calc->exportInp(fileName);
//
calc->exportInp(fileName);
calc
->
simulation
(
fileName
,
rptR
,
outBinFile
);
delete
calc
;
return
0
;
}
\ No newline at end of file
pandaDbManager/CivCommonUtils.cpp
View file @
0151749c
...
...
@@ -46,3 +46,9 @@ std::string CivCommonUtils::UTF8_To_string(const std::string& str)
return
strRet
;
}
std
::
string
CivCommonUtils
::
currentTime
()
{
return
std
::
string
();
}
\ No newline at end of file
pandaDbManager/CivCommonUtils.h
View file @
0151749c
...
...
@@ -17,4 +17,9 @@ public:
* 再通过WideCharToMultiByte将宽字符转换为多字节。
*/
static
std
::
string
UTF8_To_string
(
const
std
::
string
&
str
);
/**
*@brief 获取系统当前时间
*/
static
std
::
string
currentTime
();
};
pandaDbManager/CivDbConnection.cpp
View file @
0151749c
...
...
@@ -39,6 +39,7 @@ void CivDbConnection::close()
Tables
CivDbConnection
::
getTables
(
StrQuote
netName
,
StrQuote
schema
)
const
{
if
(
!
isValid
())
return
Tables
();
...
...
@@ -49,8 +50,6 @@ Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema) const
if
(
result
==
NULL
)
return
Tables
();
char
*
error
=
PQresultErrorMessage
(
result
);
Tables
tables
;
int
rows
=
PQntuples
(
result
);
int
columns
=
PQnfields
(
result
);
...
...
@@ -70,12 +69,116 @@ Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema) const
bool
CivDbConnection
::
updateNode
(
const
NodeResultItems
&
nodeItems
)
{
if
(
!
isValid
())
return
false
;
// 2, 参数值
int
total
=
nodeItems
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
NodeResultItem
item
=
nodeItems
[
i
];
char
sql
[
512
]
=
"update public."
;
strcat_s
(
sql
,
"节点"
);
strcat_s
(
sql
,
" as tb1 set("
);
strcat_s
(
sql
,
"总水头"
);
strcat_s
(
sql
,
",压力"
);
strcat_s
(
sql
,
",实际需水量"
);
strcat_s
(
sql
,
")"
);
strcat_s
(
sql
,
"=("
);
// 拼接值
strcat_s
(
sql
,
std
::
to_string
(
item
.
dHead
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dPressure
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dDemand
).
c_str
());
strcat_s
(
sql
,
")"
);
strcat_s
(
sql
,
"where tb1.
\"
"
);
strcat_s
(
sql
,
"本点号"
);
strcat_s
(
sql
,
"
\"
='"
);
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
"'"
);
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
PQstatus
(
mConn
);
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
// or conn==NULL
{
std
::
cout
<<
PQerrorMessage
(
mConn
)
<<
std
::
endl
;
std
::
cout
<<
PQresultErrorMessage
(
result
)
<<
std
::
endl
;
continue
;
}
std
::
cout
<<
PQerrorMessage
(
mConn
)
<<
std
::
endl
;
std
::
cout
<<
PQresultErrorMessage
(
result
)
<<
std
::
endl
;
PQclear
(
result
);
}
return
true
;
}
bool
CivDbConnection
::
updateLink
(
const
LinkResultItems
&
lineItems
)
{
if
(
!
isValid
())
return
false
;
// 2, 参数值
int
total
=
lineItems
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
LinkResultItem
item
=
lineItems
[
i
];
char
sql
[
512
]
=
"update public."
;
strcat_s
(
sql
,
"管段"
);
strcat_s
(
sql
,
" as tb1 set("
);
strcat_s
(
sql
,
"流量"
);
strcat_s
(
sql
,
",流速"
);
strcat_s
(
sql
,
",单位水头损"
);
strcat_s
(
sql
,
",水头总损失"
);
strcat_s
(
sql
,
",摩擦水头损"
);
strcat_s
(
sql
,
",上点水头"
);
strcat_s
(
sql
,
",本点水头"
);
strcat_s
(
sql
,
",局部水头损"
);
strcat_s
(
sql
,
")"
);
strcat_s
(
sql
,
"=("
);
// 拼接值
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFlow
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dVelocity
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dUnitHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFrictionHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFromNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dToNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dLocalHeadloss
).
c_str
());
strcat_s
(
sql
,
")where tb1.
\"
"
);
strcat_s
(
sql
,
"编号"
);
strcat_s
(
sql
,
"
\"
='"
);
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
"'"
);
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
PQstatus
(
mConn
);
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
// or conn==NULL
{
std
::
cout
<<
PQerrorMessage
(
mConn
)
<<
std
::
endl
;
std
::
cout
<<
PQresultErrorMessage
(
result
)
<<
std
::
endl
;
continue
;
}
std
::
cout
<<
PQerrorMessage
(
mConn
)
<<
std
::
endl
;
std
::
cout
<<
PQresultErrorMessage
(
result
)
<<
std
::
endl
;
PQclear
(
result
);
}
return
true
;
}
...
...
pandaDbManager/CivDbConnection.h
View file @
0151749c
...
...
@@ -55,6 +55,6 @@ private:
bool
mIsOpen
=
false
;
char
*
mUri
;
int
mNode
;
// 节
点个数
int
mPipes
;
// 管
线个数
char
mLinkParam
[
256
];
char
mNodeParam
[
256
];
};
\ No newline at end of file
pandaDbManager/CivTypes.h
View file @
0151749c
...
...
@@ -9,7 +9,7 @@ typedef const std::string& StrQuote;
#define PIPELINE Str("管段")
#define PIPENODE Str("节点")
#define RESIVOIR Str("水
源
")
#define RESIVOIR Str("水
库
")
#define TANK Str("水池")
...
...
@@ -58,6 +58,17 @@ struct Report {
// pump
struct
PumpFields
{
};
// 水库字段
struct
ResivoirFields
{
Str
ID
=
"本点号"
;
Str
Elev
=
"高程"
;
Str
Head
=
"水头"
;
Str
X_Coord
=
"横坐标"
;
Str
Y_Coord
=
"纵坐标"
;
Str
Pattern
=
"水头模式曲"
;
Str
Flow
=
"输出流量"
;
};
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
...
...
@@ -95,7 +106,7 @@ struct TanksFields {
Str
MaxLevel
=
"最高水位"
;
Str
Diameter
=
"直径"
;
Str
MinVol
=
"容量"
;
Str
VolCurve
=
"容积
取线ID
"
;
Str
VolCurve
=
"容积"
;
Str
X_Coord
=
"横坐标"
;
Str
Y_Coord
=
"纵坐标"
;
};
...
...
pandaHydrCalc/obj/Release/netstandard2.0/pandaHydrCalc.csprojAssemblyReference.cache
View file @
0151749c
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment