Commit a818b0dd authored by 刘乐's avatar 刘乐

1,转inp接口增加水泵组件

parent 8db624db
...@@ -8,3 +8,11 @@ pandaDbManager/x64/ ...@@ -8,3 +8,11 @@ pandaDbManager/x64/
/pandaHydrDemo/obj/Release /pandaHydrDemo/obj/Release
/pandaHydrDemo/bin/Debug /pandaHydrDemo/bin/Debug
/EPNAET2/Release /EPNAET2/Release
.suo
.vs/hydraulicModel/v16/Browse.VC.db
.vs/hydraulicModel/v16/Browse.VC.db-shm
.vs/hydraulicModel/v16/Browse.VC.opendb
.vs/hydraulicModel/v16/Solution.VC.db
.vs/hydraulicModel/v16/Solution.VC.db-shm
.vs/hydraulicModel/v16/Solution.VC.db-wal
...@@ -99,29 +99,18 @@ bool CivHydrCalc::exportInp(char* fileName) ...@@ -99,29 +99,18 @@ bool CivHydrCalc::exportInp(char* fileName)
Tables tables = mDbConn->getTables(mNetname); Tables tables = mDbConn->getTables(mNetname);
//2,解析管网组件 //2,解析管网组件
// 解析管网组件顺序: 管线放最后
CivInp civInp(CivInp::HOURS); CivInp civInp(CivInp::HOURS);
int total = tables.size(); int total = tables.size();
for (int i=0;i<total;i++) for (int i=0;i<total;i++)
{ {
std::string table = tables[i]; std::string table = tables[i];
if ("管线" == table)
assemble(table,civInp); continue;
assemble(table,civInp);
} }
assemble("管线", civInp);
/*
UNITS LPS
TRIALS 40
ACCURACY 0.001
EMITTER EXPONENT 0.5
DAMPLIMIT 0
MAXCHECK 10
CHECKFREQ 2
SPECIFIC GRAVITY 0.998
HEADLOSS H-W
TOLERANCE 0.0166666666666667
QUALITY AGE
*/
// 初始化选择 // 初始化选择
Options options; Options options;
options.units = Options::UNITS::LPS; options.units = Options::UNITS::LPS;
...@@ -154,8 +143,7 @@ QUALITY AGE ...@@ -154,8 +143,7 @@ QUALITY AGE
void CivHydrCalc::assemble(const std::string& table, CivInp& inp) void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
{ {
std::string utf8Table = CivCommonUtils::string_To_UTF8(table);
Componets comps = mDbConn->getComponets(utf8Table);
// 根据组建类型解析字段 // 根据组建类型解析字段
if (PIPELINE == table) if (PIPELINE == table)
...@@ -163,12 +151,21 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -163,12 +151,21 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
// 管线 // 管线
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status //;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
// 必备参数 // 必备参数
Componets comps = mDbConn->getComponets(table);
PipeFields pipes; PipeFields pipes;
Civitems items; Civitems items;
int total = comps.size(); int total = comps.size();
for (int i =0 ;i< total;i++) for (int i =0 ;i< total;i++)
{ {
Componet comp = comps[i]; Componet comp = comps[i];
// 过滤掉与阀门和水泵连接的管线
Str number = comp.find("编号")->second;
FiledFilter filter = mDbConn->getFilter();
std::set<Str> lineFilter = filter.find("管线")->second;
if (lineFilter.count(number) > 0)
continue;
Str id = comp.find(pipes.ID)->second; Str id = comp.find(pipes.ID)->second;
Str startNode = comp.find(pipes.Node1)->second; Str startNode = comp.find(pipes.Node1)->second;
Str endNode = comp.find(pipes.Node2)->second; Str endNode = comp.find(pipes.Node2)->second;
...@@ -195,6 +192,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -195,6 +192,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
} }
else if (PIPENODE == table) else if (PIPENODE == table)
{ {
Componets comps = mDbConn->getComponets(table);
// 节点参数 // 节点参数
// ;ID Elev Demand Pattern // ;ID Elev Demand Pattern
// 坐标 // 坐标
...@@ -236,6 +234,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -236,6 +234,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
} }
else if (RESIVOIR == table) // 水源 else if (RESIVOIR == table) // 水源
{ {
Componets comps = mDbConn->getComponets(table);
//;ID Head Pattern //;ID Head Pattern
Civitems coordItems; Civitems coordItems;
Civitems resirvoirItems; Civitems resirvoirItems;
...@@ -278,12 +277,58 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -278,12 +277,58 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
else if (PUMP == table) // 水泵 else if (PUMP == table) // 水泵
{ {
//;ID Node1 Node2 Parameters //;ID Node1 Node2 Parameters
Componets comps = mDbConn->getLikelyPipes(table);
PumpFields fields;
Civitems pumpItems;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(fields.ID)->second;
Str node1 = comp.find(fields.node1)->second;
Str node2 = comp.find(fields.node2)->second;
std::vector<Str> vec;
Str head = comp.find(fields.head)->second;
if (!head.empty())
vec.push_back(fields.head + " " + head);
Str power = comp.find(fields.power)->second;
if (!power.empty())
vec.push_back(fields.power + " " + power);
Str pattern = comp.find(fields.pattern)->second;
if (!pattern.empty())
vec.push_back(fields.pattern + " " + pattern);
Str speed = comp.find(fields.speed)->second;
if (!speed.empty())
vec.push_back(fields.speed + " " + speed);
// 水池数据
CivItem tankNode;
tankNode.push_back(id);
tankNode.push_back(node1);
tankNode.push_back(node2);
// 构建参数
char param[128] = " ";
int total = vec.size();
for(int i=0;i<total;i++)
{
strcat_s(param, vec[i].c_str());
}
tankNode.push_back(param);
pumpItems.push_back(tankNode);
}
inp.writeComponet(pumpItems, _PUMPS);
} }
else if (TANK == table) // 水池 else if (TANK == table) // 水池
{ {
Componets comps = mDbConn->getComponets(table);
// ; ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve // ; ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
TanksFields tkfFileds; TanksFields tkfFileds;
Civitems nodeCoordItems; Civitems nodeCoordItems;
Civitems tankItems; Civitems tankItems;
int total = comps.size(); int total = comps.size();
...@@ -298,8 +343,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -298,8 +343,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
Str diametor = comp.find(tkfFileds.Diameter)->second; Str diametor = comp.find(tkfFileds.Diameter)->second;
Str minVol = comp.find(tkfFileds.MinVol)->second; Str minVol = comp.find(tkfFileds.MinVol)->second;
//Str volCurve = comp.find(tkfFileds.VolCurve)->second;
Str x_coord = comp.find(tkfFileds.X_Coord)->second; Str x_coord = comp.find(tkfFileds.X_Coord)->second;
Str y_coord = comp.find(tkfFileds.Y_Coord)->second; Str y_coord = comp.find(tkfFileds.Y_Coord)->second;
...@@ -312,8 +356,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -312,8 +356,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
tankNode.push_back(maxLevel); tankNode.push_back(maxLevel);
tankNode.push_back(diametor); tankNode.push_back(diametor);
tankNode.push_back(minVol); tankNode.push_back(minVol);
// tankNode.push_back(volCurve);
tankItems.push_back(tankNode); tankItems.push_back(tankNode);
// 2, 节点坐标 // 2, 节点坐标
...@@ -322,10 +365,8 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -322,10 +365,8 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
nodeCoordItem.push_back(x_coord); nodeCoordItem.push_back(x_coord);
nodeCoordItem.push_back(y_coord); nodeCoordItem.push_back(y_coord);
nodeCoordItems.push_back(nodeCoordItem); nodeCoordItems.push_back(nodeCoordItem);
} }
inp.writeComponet(nodeCoordItems, _COORDS); inp.writeComponet(nodeCoordItems, _COORDS);
inp.writeComponet(tankItems, _TANKS); inp.writeComponet(tankItems, _TANKS);
} }
......
#pragma once #pragma once
#include<string> #include<string>
#include<set>
#include "CivInp.h" #include "CivInp.h"
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
class CivDbConnection; class CivDbConnection;
/** /**
* 水力计算类 * 水力计算类
*/ */
......
...@@ -183,16 +183,23 @@ Componets CivDbConnection::getComponets(StrQuote tableName) const ...@@ -183,16 +183,23 @@ Componets CivDbConnection::getComponets(StrQuote tableName) const
return Nodes(); return Nodes();
std::string sql = "select * from public.\"" + tableName + "\""; std::string sql = "select * from public.\"" + tableName + "\"";
std::string utf8Str = CivCommonUtils::string_To_UTF8(sql);
PGresult* result = PQexec(mConn, sql.c_str()); PGresult* result = PQexec(mConn, utf8Str.c_str());
if (result == NULL) if (result == NULL)
{ {
return Nodes(); return Nodes();
} }
// rows count
Componets nodes; Componets nodes;
// 取数据到容器中
getData(result, nodes);
PQclear(result);
return nodes;
}
void CivDbConnection::getData(PGresult* result, Componets& comp) const
{
int rows = PQntuples(result); int rows = PQntuples(result);
int columns = PQnfields(result); int columns = PQnfields(result);
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
...@@ -208,55 +215,110 @@ Componets CivDbConnection::getComponets(StrQuote tableName) const ...@@ -208,55 +215,110 @@ Componets CivDbConnection::getComponets(StrQuote tableName) const
node.insert(std::pair<std::string, std::string>(fieldStr, itemStr)); node.insert(std::pair<std::string, std::string>(fieldStr, itemStr));
} }
nodes.push_back(node); comp.push_back(node);
} }
PQclear(result);
return nodes;
} }
Componets CivDbConnection::getLikelyPipes(StrQuote tableName) const Componets CivDbConnection::getLineByCode(StrQuote table, StrQuote code) const
{ {
if (!isValid()) if (!isValid())
return Nodes(); return Nodes();
// 查询点数据 char sql[125] = "select * from public.\"";
std::string sql = "select * from public.\"" + tableName + "\""; strcat_s(sql, table.c_str());
PGresult* result = PQexec(mConn, sql.c_str()); strcat_s(sql, "where from_code = ");
strcat_s(sql, code.c_str());
strcat_s(sql, "or to_code=");
strcat_s(sql, code.c_str());
std::string utfStr = CivCommonUtils::string_To_UTF8(sql);
PGresult* result = PQexec(mConn, utfStr.c_str());
if (result == NULL) if (result == NULL)
{ {
return Nodes(); return Nodes();
} }
// rows count Componets componets;
getData(result, componets);
PQclear(result);
return componets;
}
Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
{
if (!isValid())
return Componets();
// 查询点数据
char sql[256] = "select * from \"";
strcat_s(sql, tableName.c_str());
strcat_s(sql,"\"");
std::string utfStr = CivCommonUtils::string_To_UTF8(sql);
PGresult* result = PQexec(mConn, utfStr.c_str());
if (result == NULL)
{
return Componets();
}
Componets nodes; Componets nodes;
std::vector<std::string> codes; getData(result, nodes);
int rows = PQntuples(result); PQclear(result);
int columns = PQnfields(result);
for (int i = 0; i < rows; i++) // 查询线表
if (nodes.size() <= 0)
return Componets();
// 根据点数据查询起点和终点,管径
int total = nodes.size();
for (int i = 0; i < total; i++)
{ {
Componet node; Componet componet = nodes[i];
for (int j = 0; j < columns; j++) Str code = componet.find("code")->second;
Componets lines = getLineByCode("管线", code);
int lTotal = lines.size();
for (int j = 0; j < lTotal; j++)
{ {
char* item = PQgetvalue(result, i, j); Componet lin = lines[j];
char* fieldName = PQfname(result, j); // 获取列表字段名 Str from_code = lin.find("from_code")->second;
if ("code" == fieldName) Str to_code = lin.find("to_code")->second;
if (from_code == code)
{
Str lastPointNo = lin.find("上点号")->second;
componet.insert(std::pair<Str, Str>("上点号",lastPointNo));
}
else if (to_code == code)
{ {
codes.push_back(fieldName); Str pointNo = lin.find("本点号")->second;
componet.insert(std::pair<Str, Str>("本点号", pointNo));
} }
std::string itemStr = CivCommonUtils::UTF8_To_string(item); Str diameter = lin.find("管径")->second;
std::string fieldStr = CivCommonUtils::UTF8_To_string(fieldName); componet.insert(std::pair<Str, Str>("管径", diameter));
node.insert(std::pair<std::string, std::string>(fieldStr, itemStr)); Str number = lin.find("编号")->second;
addFilter("管线", number);
} }
nodes.push_back(node); nodes[i] = componet;
} }
return nodes;
}
PQclear(result); void CivDbConnection::addFilter(Str type, Str number)
{
mFilter[type].insert(number);
}
std::string sql2 = "select * from public.\"管线\""; FiledFilter CivDbConnection::getFilter() const
return nodes; {
return mFilter;
} }
bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema) bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema)
......
#pragma once #pragma once
#include "CivTypes.h" #include "CivTypes.h"
#include <vector> #include <vector>
#include <set>
#include <libpq-fe.h> #include <libpq-fe.h>
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
// 字段过滤
#define FiledFilter std::map<Str,std::set<Str>>
class CivDbConnection; class CivDbConnection;
/** /**
...@@ -32,7 +35,8 @@ public: ...@@ -32,7 +35,8 @@ public:
*@brief 水泵,阀门 (节点转换为管线) *@brief 水泵,阀门 (节点转换为管线)
*@tableName: 组件表 *@tableName: 组件表
*/ */
Componets getLikelyPipes(StrQuote tableName) const; Componets getLikelyPipes(StrQuote tableName);
/** /**
*@brief 创建表格 *@brief 创建表格
...@@ -53,9 +57,28 @@ public: ...@@ -53,9 +57,28 @@ public:
bool open(); bool open();
void close(); void close();
void addFilter(Str type, Str number);
FiledFilter getFilter() const;
private: private:
bool isValid() const; bool isValid() const;
/**
*@brief 查询与点连接的线
*@table: 线表
*@code:
*/
Componets getLineByCode(StrQuote table, StrQuote code) const;
/**
*@brief 从查询集取出数据
*@result: 查询结果集
*@comp: 数据容器
*/
void getData(PGresult* result, Componets& comp) const;
private: private:
PGconn* mConn; PGconn* mConn;
bool mIsOpen = false; bool mIsOpen = false;
...@@ -65,4 +88,6 @@ private: ...@@ -65,4 +88,6 @@ private:
char mLinkParam[256]; char mLinkParam[256];
char mNodeParam[256]; char mNodeParam[256];
FiledFilter mFilter; // 表名:对应的编号
}; };
\ No newline at end of file
...@@ -31,8 +31,37 @@ enum SectType { ...@@ -31,8 +31,37 @@ enum SectType {
_REACTIONS, _MIXING, _REPORT, _TIMES, _OPTIONS, _REACTIONS, _MIXING, _REPORT, _TIMES, _OPTIONS,
_COORDS, _VERTICES, _LABELS, _BACKDROP, _TAGS, _END _COORDS, _VERTICES, _LABELS, _BACKDROP, _TAGS, _END
}; };
// 数据库与inp文件所需字段的映射
// 阀门类型
enum ValvesType
{
PRV, /* 减压阀 */
PSV, /* 稳压阀 */
PBV, /* 压力制动阀 */
FCV, /* 流量控制阀 */
TCV, /*节流控制阀 */
GPV /* 常规阀门 */
};
// 阀门数据库的表
struct ValvesTables
{
Str PRV = "减压阀";
Str PSV = "稳压阀";
Str PBV = "压力制动阀";
Str FCV = "流量控制阀";
Str TCV = "节流控制阀";
Str GPV = "常规阀门";
};
// 水泵参数
enum PumpParameter
{
POWER, // 定速能量水泵的功率数值,hp(kW)
HEAD, // 描述了水泵扬程与流量关系的曲线ID
SPEED, // 相对速度设置(额定速度为1.0,0意味着水泵关闭)
PATTERN // 时间模式的ID,描述了速度设置怎样随时间变化
};
// REACTIONS // REACTIONS
// 定义对应于管网中与化学成分反应的参数。 // 定义对应于管网中与化学成分反应的参数。
...@@ -42,7 +71,6 @@ struct Reactions { ...@@ -42,7 +71,6 @@ struct Reactions {
// [REPORT] // [REPORT]
// 描述模拟生成的输出报表内容。 // 描述模拟生成的输出报表内容。
// 描述模拟生成的输出报表内容
struct Report { struct Report {
Str PAGESIZES; Str PAGESIZES;
Str NODES; // NONE/ALL/node1 node2 ... Str NODES; // NONE/ALL/node1 node2 ...
...@@ -52,12 +80,37 @@ struct Report { ...@@ -52,12 +80,37 @@ struct Report {
Str ENERGY; Str ENERGY;
}; };
/*
*/ /****************************** 管网物理组件,参数字段****************************************************/
// pump // 水泵
//[PUMPS]
//; ID Node1 Node2 Parameters
struct PumpFields { struct PumpFields {
/**
* POWER——定速能量水泵的功率数值,hp(kW)
* HEAD——描述了水泵扬程与流量关系的曲线ID
* SPEED——相对速度设置(额定速度为1.0,0意味着水泵关闭)
* PATTERN——时间模式的ID,描述了速度设置怎样随时间变化
*/
Str ID = "编号";
Str node1 = "本点号"; // 与水泵连接的输入段本点号
Str node2 = "上点号"; // 水泵连接的下游管段
Str power = "功率"; // 定速能量水泵的功率数值,hp(kW)
Str head = "扬程曲线";
Str speed = "速度"; // 相对速度设置(额定速度为1.0,0意味着水泵关闭)
Str pattern = "水泵曲线";// 时间模式的ID,描述了速度设置怎样随时间变化
};
//[VALVES]
//; ID Node1 Node2 Diameter Type Setting MinorLoss
struct ValvesFields {
Str ID = "编号"; // 水泵表的本点号
Str node1 = "上点号"; // 与水泵连接的输入段本点号
Str node2 = "本点号"; // 水泵连接的下游管段
Str Diameter = "直径";// 直径
Str type = "类型"; // 阀门类型
Str setting = " 参数设置"; // 不同阀门对应不同参数
Str minorLoss = "局部损失系数";
}; };
// 水库字段 // 水库字段
...@@ -83,8 +136,6 @@ struct PipeFields { ...@@ -83,8 +136,6 @@ struct PipeFields {
Str Status = Str("状态"); Str Status = Str("状态");
}; };
// 节点 // 节点
struct JunctionsFields { struct JunctionsFields {
Str ID = "本点号"; Str ID = "本点号";
...@@ -111,6 +162,8 @@ struct TanksFields { ...@@ -111,6 +162,8 @@ struct TanksFields {
Str Y_Coord = "纵坐标"; Str Y_Coord = "纵坐标";
}; };
/********************************end **************************************************/
// 水力计算管点结果缓存 // 水力计算管点结果缓存
struct NodeResultItem struct NodeResultItem
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment