Commit 2c6877e8 authored by 刘乐's avatar 刘乐

1, 水力模型转inp文件,增加阀门,水泵

parent a818b0dd
...@@ -85,7 +85,6 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -85,7 +85,6 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
return true; return true;
} }
bool CivHydrCalc::exportInp(char* fileName) bool CivHydrCalc::exportInp(char* fileName)
{ {
//1 ,获取管网组件 //1 ,获取管网组件
...@@ -105,12 +104,12 @@ bool CivHydrCalc::exportInp(char* fileName) ...@@ -105,12 +104,12 @@ bool CivHydrCalc::exportInp(char* fileName)
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) if (PIPELINE == table)
continue; continue;
assemble(table,civInp); assemble(table,civInp);
} }
assemble("管线", civInp); assemble(PIPELINE, civInp);
// 初始化选择 // 初始化选择
Options options; Options options;
options.units = Options::UNITS::LPS; options.units = Options::UNITS::LPS;
...@@ -160,9 +159,9 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -160,9 +159,9 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
Componet comp = comps[i]; Componet comp = comps[i];
// 过滤掉与阀门和水泵连接的管线 // 过滤掉与阀门和水泵连接的管线
Str number = comp.find("编号")->second; Str number = comp.find("id")->second;
FiledFilter filter = mDbConn->getFilter(); FiledFilter filter = mDbConn->getFilter();
std::set<Str> lineFilter = filter.find("管线")->second; auto lineFilter = filter.find(PIPELINE)->second;
if (lineFilter.count(number) > 0) if (lineFilter.count(number) > 0)
continue; continue;
...@@ -292,23 +291,23 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -292,23 +291,23 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
std::vector<Str> vec; std::vector<Str> vec;
Str head = comp.find(fields.head)->second; Str head = comp.find(fields.head)->second;
if (!head.empty()) if (!head.empty())
vec.push_back(fields.head + " " + head); vec.push_back("HEAD " + head);
Str power = comp.find(fields.power)->second; Str power = comp.find(fields.power)->second;
if (!power.empty()) if (!power.empty())
vec.push_back(fields.power + " " + power); vec.push_back("POWER " + power);
Str pattern = comp.find(fields.pattern)->second; Str pattern = comp.find(fields.pattern)->second;
if (!pattern.empty()) if (!pattern.empty())
vec.push_back(fields.pattern + " " + pattern); vec.push_back("PATTERN " + pattern);
Str speed = comp.find(fields.speed)->second; Str speed = comp.find(fields.speed)->second;
if (!speed.empty()) if (!speed.empty())
vec.push_back(fields.speed + " " + speed); vec.push_back("SPEED " + speed);
// 水池数据 // 水池数据
CivItem tankNode; CivItem tankNode;
tankNode.push_back(id); tankNode.push_back("P"+id);
tankNode.push_back(node1); tankNode.push_back(node1);
tankNode.push_back(node2); tankNode.push_back(node2);
...@@ -370,6 +369,40 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp) ...@@ -370,6 +369,40 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
inp.writeComponet(nodeCoordItems, _COORDS); inp.writeComponet(nodeCoordItems, _COORDS);
inp.writeComponet(tankItems, _TANKS); inp.writeComponet(tankItems, _TANKS);
} }
else
{
// 阀门
//;ID Node1 Node2 Diameter Type Setting MinorLoss
Componets comps = mDbConn->getLikelyPipes(table);
ValvesFields fields;
Civitems vavleItems;
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;
Str diametor = comp.find(fields.Diameter)->second;
Str label = comp.find(fields.type)->second;
Str typeSeting = comp.find(fields.setting)->second;
Str minorLoss = comp.find(fields.minorLoss)->second;
// 阀门数据
CivItem vavleNode;
vavleNode.push_back("V"+id);
vavleNode.push_back(node1);
vavleNode.push_back(node2);
vavleNode.push_back(diametor);
vavleNode.push_back(label);
vavleNode.push_back(typeSeting);
vavleNode.push_back(minorLoss);
vavleItems.push_back(vavleNode);
}
inp.writeComponet(vavleItems, _VALVES);
}
} }
......
...@@ -36,7 +36,6 @@ void CivDbConnection::close() ...@@ -36,7 +36,6 @@ void CivDbConnection::close()
mIsOpen = false; mIsOpen = false;
} }
Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema) const Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema) const
{ {
...@@ -220,17 +219,46 @@ void CivDbConnection::getData(PGresult* result, Componets& comp) const ...@@ -220,17 +219,46 @@ void CivDbConnection::getData(PGresult* result, Componets& comp) const
} }
Componets CivDbConnection::getNodeByCode(StrQuote table, StrQuote code) const
{
if (!isValid())
return Nodes();
char sql[256] = "select * from public.\"";
strcat_s(sql, table.c_str());
strcat_s(sql, "\"");
strcat_s(sql, " where code = '");
strcat_s(sql, code.c_str());
strcat_s(sql, "'");
std::string utfStr = CivCommonUtils::string_To_UTF8(sql);
PGresult* result = PQexec(mConn, utfStr.c_str());
if (result == NULL)
{
return Nodes();
}
Componets componets;
getData(result, componets);
PQclear(result);
return componets;
}
Componets CivDbConnection::getLineByCode(StrQuote table, StrQuote code) const Componets CivDbConnection::getLineByCode(StrQuote table, StrQuote code) const
{ {
if (!isValid()) if (!isValid())
return Nodes(); return Nodes();
char sql[125] = "select * from public.\""; char sql[256] = "select * from public.\"";
strcat_s(sql, table.c_str()); strcat_s(sql, table.c_str());
strcat_s(sql, "where from_code = "); strcat_s(sql,"\"");
strcat_s(sql, " where from_code = '");
strcat_s(sql, code.c_str()); strcat_s(sql, code.c_str());
strcat_s(sql, "or to_code="); strcat_s(sql, "' or to_code= '");
strcat_s(sql, code.c_str()); strcat_s(sql, code.c_str());
strcat_s(sql, "'");
std::string utfStr = CivCommonUtils::string_To_UTF8(sql); std::string utfStr = CivCommonUtils::string_To_UTF8(sql);
PGresult* result = PQexec(mConn, utfStr.c_str()); PGresult* result = PQexec(mConn, utfStr.c_str());
...@@ -272,42 +300,128 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName) ...@@ -272,42 +300,128 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
if (nodes.size() <= 0) if (nodes.size() <= 0)
return Componets(); return Componets();
// 查询:连接节点也有可能连接水源,或者水库
std::vector<Str> tables;
tables.push_back(PIPENODE);
tables.push_back(RESIVOIR);
tables.push_back(TANK);
// 阀门类型映射
std::map<Str, Str> mValvesMap;
mValvesMap.insert(std::pair<Str, Str>(PRV_TYPE,"PRV"));
mValvesMap.insert(std::pair<Str, Str>(PSV_TYPE, "PSV"));
mValvesMap.insert(std::pair<Str, Str>(PBV_TYPE, "PBV"));
mValvesMap.insert(std::pair<Str, Str>(FCV_TYPE, "FCV"));
mValvesMap.insert(std::pair<Str, Str>(TCV_TYPE, "TCV"));
mValvesMap.insert(std::pair<Str, Str>(GPV_TYPE, "PRV"));
std::vector<Str> mVavesTables;
mVavesTables.push_back(PRV_TYPE);
mVavesTables.push_back(PSV_TYPE);
mVavesTables.push_back(PBV_TYPE);
mVavesTables.push_back(FCV_TYPE);
mVavesTables.push_back(TCV_TYPE);
mVavesTables.push_back(GPV_TYPE);
// 不同阀门对应的特殊参数
std::map<Str, Str> mParameterMap;
mParameterMap.insert(std::pair<Str, Str>(PRV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(PSV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(PBV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(FCV_TYPE, "流量设置"));
mParameterMap.insert(std::pair<Str, Str>(TCV_TYPE, "流量设置"));
mParameterMap.insert(std::pair<Str, Str>(GPV_TYPE, "水头损失曲"));
// 根据点数据查询起点和终点,管径 // 根据点数据查询起点和终点,管径
int total = nodes.size(); int total = nodes.size();
for (int i = 0; i < total; i++) for (int i = 0; i < total; i++)
{ {
Componet componet = nodes[i]; Componet componet = nodes[i];
nodes[i]["编号"] = componet.find("id")->second;
Str code = componet.find("code")->second; Str code = componet.find("code")->second;
Componets lines = getLineByCode("管线", code); Componets lines = getLineByCode(PIPELINE, code);
int lTotal = lines.size(); int lTotal = lines.size();
for (int j = 0; j < lTotal; j++) for (int j = 0; j < lTotal; j++)
{ {
Componet lin = lines[j]; Componet lin = lines[j];
Str from_code = lin.find("from_code")->second;
Str to_code = lin.find("to_code")->second; Str fromCode = lin.find("from_code")->second;
Str toCode = lin.find("to_code")->second;
if (from_code == code) Componets codeNodes;
if (fromCode == code)
{ {
Str lastPointNo = lin.find("上点号")->second;
componet.insert(std::pair<Str, Str>("上点号",lastPointNo)); int size = tables.size();
for (int i = 0; i < size; i++)
{
codeNodes = getNodeByCode(tables[i], toCode);
if (codeNodes.size() > 0)
break;
}
if (codeNodes.size() > 0)
{
Componet comp = codeNodes[0];
Str pointNo = comp.find("本点号")->second;
nodes[i]["本点号"] = pointNo;
}
} }
else if (to_code == code) else if (toCode == code)
{ {
Str pointNo = lin.find("本点号")->second; int size = tables.size();
componet.insert(std::pair<Str, Str>("本点号", pointNo)); Str currTable;
for (int i = 0; i < size; i++)
{
currTable = tables[i];
codeNodes = getNodeByCode(tables[i], fromCode);
if (codeNodes.size() > 0)
break;
}
// 查询
// codeNodes = getNodeByCode(PIPENODE, fromCode);
if (codeNodes.size() > 0)
{
Componet comp = codeNodes[0];
Str pointNo = comp.find("本点号")->second;
if (currTable == RESIVOIR || currTable == TANK)
{
// 水源必须为起点:点转换为管线过程需要纠正方向
Str lastPoint = nodes[i]["本点号"];
nodes[i]["本点号"] = pointNo;
if (nodes[i]["上点号"].empty())
nodes[i]["上点号"] = lastPoint;
}
else
{
nodes[i]["上点号"] = pointNo;
}
}
} }
Str diameter = lin.find("管径")->second; Str diameter = lin.find("管径")->second;
componet.insert(std::pair<Str, Str>("管径", diameter)); nodes[i]["管径"] = diameter;
Str number = lin.find("编号")->second; Str number = lin.find("id")->second;
addFilter("管线", number); addFilter(PIPELINE, number);
// 阀门类型设置特殊字段
std::vector<Str>::iterator iter = std::find(mVavesTables.begin(), mVavesTables.end(), tableName);
if (iter!=mVavesTables.end())
{
nodes[i]["类型"] = mValvesMap.find(tableName)->second;
Str fieldType = mParameterMap.find(tableName)->second;
nodes[i]["参数设置"] = componet.find(fieldType)->second;
}
} }
nodes[i] = componet;
} }
return nodes; return nodes;
} }
......
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
*@tableName: 组件表 *@tableName: 组件表
*/ */
Componets getLikelyPipes(StrQuote tableName); Componets getLikelyPipes(StrQuote tableName);
/** /**
*@brief 创建表格 *@brief 创建表格
...@@ -72,6 +72,8 @@ private: ...@@ -72,6 +72,8 @@ private:
*/ */
Componets getLineByCode(StrQuote table, StrQuote code) const; Componets getLineByCode(StrQuote table, StrQuote code) const;
Componets getNodeByCode(StrQuote table, StrQuote code) const;
/** /**
*@brief 从查询集取出数据 *@brief 从查询集取出数据
*@result: 查询结果集 *@result: 查询结果集
......
...@@ -10,11 +10,17 @@ typedef const std::string& StrQuote; ...@@ -10,11 +10,17 @@ typedef const std::string& StrQuote;
#define PIPELINE Str("管段") #define PIPELINE Str("管段")
#define PIPENODE Str("节点") #define PIPENODE Str("节点")
#define RESIVOIR Str("水库") #define RESIVOIR Str("水库")
#define TANK Str("水池") #define TANK Str("水池")
#define PUMP Str("水泵") #define PUMP Str("水泵")
#define PRV_TYPE Str("稳压阀")
#define PSV_TYPE Str("减压阀")
#define PBV_TYPE Str("压力制动阀")
#define FCV_TYPE Str("流量控制阀")
#define TCV_TYPE Str("节流控制阀")
#define GPV_TYPE Str("常规阀门")
// 管点 // 管点
#define Node std::map<Str,Str> #define Node std::map<Str,Str>
#define Nodes std::vector<Node> #define Nodes std::vector<Node>
...@@ -43,17 +49,6 @@ enum ValvesType ...@@ -43,17 +49,6 @@ enum ValvesType
GPV /* 常规阀门 */ GPV /* 常规阀门 */
}; };
// 阀门数据库的表
struct ValvesTables
{
Str PRV = "减压阀";
Str PSV = "稳压阀";
Str PBV = "压力制动阀";
Str FCV = "流量控制阀";
Str TCV = "节流控制阀";
Str GPV = "常规阀门";
};
// 水泵参数 // 水泵参数
enum PumpParameter enum PumpParameter
{ {
...@@ -107,10 +102,10 @@ struct ValvesFields { ...@@ -107,10 +102,10 @@ struct ValvesFields {
Str ID = "编号"; // 水泵表的本点号 Str ID = "编号"; // 水泵表的本点号
Str node1 = "上点号"; // 与水泵连接的输入段本点号 Str node1 = "上点号"; // 与水泵连接的输入段本点号
Str node2 = "本点号"; // 水泵连接的下游管段 Str node2 = "本点号"; // 水泵连接的下游管段
Str Diameter = "径";// 直径 Str Diameter = "径";// 直径
Str type = "类型"; // 阀门类型 Str type = "类型"; // 阀门类型
Str setting = " 参数设置"; // 不同阀门对应不同参数 Str setting = "参数设置"; // 不同阀门对应不同参数
Str minorLoss = "局部损失系数"; Str minorLoss = "局部损失系数"; //
}; };
// 水库字段 // 水库字段
...@@ -121,7 +116,7 @@ struct ResivoirFields { ...@@ -121,7 +116,7 @@ struct ResivoirFields {
Str X_Coord = "横坐标"; Str X_Coord = "横坐标";
Str Y_Coord = "纵坐标"; Str Y_Coord = "纵坐标";
Str Pattern = "水头模式曲"; Str Pattern = "水头模式曲";
Str Flow = "出流量"; Str Flow = "出流量";
}; };
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status //;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
......
...@@ -25,6 +25,11 @@ namespace CivHydr { ...@@ -25,6 +25,11 @@ namespace CivHydr {
return false; return false;
} }
Boolean CivHydrCalcMiddle::getInpFile(String^ inpFile)
{
return mHydrCalc->exportInp(StringToCharStar(inpFile));
}
Boolean CivHydrCalcMiddle::hyDrCompute() Boolean CivHydrCalcMiddle::hyDrCompute()
{ {
return mHydrCalc->hydrSimulation(mInpFile, mRptFile, mBinOutFile); return mHydrCalc->hydrSimulation(mInpFile, mRptFile, mBinOutFile);
......
...@@ -29,6 +29,7 @@ namespace CivHydr { ...@@ -29,6 +29,7 @@ namespace CivHydr {
*@flag: 计算标志, HDY:水力计算 QUALITY:水质计算 *@flag: 计算标志, HDY:水力计算 QUALITY:水质计算
*/ */
Boolean simulation(String^ flag); Boolean simulation(String^ flag);
Boolean getInpFile(String^ inpFile);
void setInpFile(String^ inpFileName); void setInpFile(String^ inpFileName);
......
...@@ -20,8 +20,9 @@ namespace pandaHydrDemo ...@@ -20,8 +20,9 @@ namespace pandaHydrDemo
calc.setOutBinFile("test.bin"); calc.setOutBinFile("test.bin");
String flag = "HDY"; String flag = "HDY";
Boolean sucess = calc.simulation(flag); calc.getInpFile("test.inp");
Console.WriteLine(sucess); // Boolean sucess = calc.simulation(flag);
// Console.WriteLine(sucess);
} }
} }
} }
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