|
[Sponsors] |
June 9, 2021, 10:49 |
MPI returns wrong objective function values
|
#1 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
Hi all,
I defined a new objective function named inverse_design_temperature, which is similar to inverse_design_pressure. However, when I calculate it without MPI (using SU2_CFD directly), it returns the right value (zero because the target distribution is from the converged results): Code:
+--------------------------------------+ | Inner_Iter| rms[Rho]| Tem_Diff| +--------------------------------------+ | 0| -16.230367| 0.000000| | 1| -16.406737| 0.000000| | 2| -16.452313| 0.000000| | 3| -16.466728| 0.000000| | 4| -16.466144| 0.000000| | 5| -16.455828| 0.000000| | 6| -16.466166| 0.000000| | 7| -16.477467| 0.000000| | 8| -16.486044| 0.000000| | 9| -16.471769| 0.000000| Code:
+--------------------------------------+ | Inner_Iter| rms[Rho]| Tem_Diff| +--------------------------------------+ | 0| -16.001455| 254.651088| | 1| -16.278280| 254.651088| | 2| -16.365279| 254.651088| | 3| -16.376823| 254.651088| | 4| -16.404594| 254.651088| | 5| -16.409816| 254.651088| | 6| -16.443638| 254.651088| | 7| -16.435451| 254.651088| | 8| -16.440441| 254.651088| | 9| -16.451784| 254.651088| I tried the inverse_dedign_pressure, and the solver also gives different results with and without MPI. Could anybody give some clues why this happens and how to fix it? Thanks! Zhen |
|
June 9, 2021, 10:56 |
|
#2 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
The key function is shown following, which is almost a copy of CFlowOutput::Set_CpInverseDesign.
Code:
/*zhen: used for the temperature inverse design*/ void CFlowOutput::Set_TemInverseDesign(CSolver *solver, CGeometry *geometry, CConfig *config){ unsigned short iMarker, icommas, Boundary; unsigned long iVertex, iPoint, (*Point2Vertex)[2], nPointLocal = 0, nPointGlobal = 0; su2double XCoord, YCoord, ZCoord, Temperature = 0, Tem, TemTarget, *Normal = nullptr, Area, TemDiff = 0.0; bool *PointInDomain; string text_line, surfTem_filename; ifstream Surface_file; /*--- Prepare to read the surface pressure files (CSV) ---*/ surfTem_filename = config->GetUnsteady_FileName("TargetTem", (int)curTimeIter, ".dat"); /*--- Read the surface pressure file ---*/ string::size_type position; Surface_file.open(surfTem_filename); if (!(Surface_file.fail())) { nPointLocal = geometry->GetnPoint(); SU2_MPI::Allreduce(&nPointLocal, &nPointGlobal, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm()); Point2Vertex = new unsigned long[nPointGlobal][2]; PointInDomain = new bool[nPointGlobal]; for (iPoint = 0; iPoint < nPointGlobal; iPoint ++) PointInDomain[iPoint] = false; for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { //Boundary = config->GetMarker_All_KindBC(iMarker); //zhen: The temperature inverse design is applied to the Ploted boundarys Boundary = config->GetMarker_All_Plotting(iMarker); //if ((Boundary == EULER_WALL ) || // (Boundary == HEAT_FLUX ) || // (Boundary == ISOTHERMAL ) || // (Boundary == NEARFIELD_BOUNDARY)) { if (Boundary==1){ for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) { /*--- The Temperature file uses the global numbering ---*/ iPoint = geometry->nodes->GetGlobalIndex(geometry->vertex[iMarker][iVertex]->GetNode()); if (geometry->vertex[iMarker][iVertex]->GetNode() < geometry->GetnPointDomain()) { Point2Vertex[iPoint][0] = iMarker; Point2Vertex[iPoint][1] = iVertex; PointInDomain[iPoint] = true; solver->SetTemTarget(iMarker, iVertex, 0.0); } } } } getline(Surface_file, text_line); while (getline(Surface_file, text_line)) { for (icommas = 0; icommas < 50; icommas++) { position = text_line.find( ",", 0 ); if (position!=string::npos) text_line.erase (position,1); } stringstream point_line(text_line); if (geometry->GetnDim() == 2) point_line >> iPoint >> XCoord >> YCoord >> Temperature; if (geometry->GetnDim() == 3) point_line >> iPoint >> XCoord >> YCoord >> ZCoord >> Temperature; if (PointInDomain[iPoint]) { /*--- Find the vertex for the Point and Marker ---*/ iMarker = Point2Vertex[iPoint][0]; iVertex = Point2Vertex[iPoint][1]; solver->SetTemTarget(iMarker, iVertex, Temperature); } } Surface_file.close(); delete [] Point2Vertex; delete [] PointInDomain; /*--- Compute the Temperature difference ---*/ TemDiff = 0.0; for (iMarker = 0; iMarker < config->GetnMarker_All(); iMarker++) { //Boundary = config->GetMarker_All_KindBC(iMarker); Boundary = config->GetMarker_All_Plotting(iMarker); //if ((Boundary == EULER_WALL ) || // (Boundary == HEAT_FLUX ) || // (Boundary == ISOTHERMAL ) || // (Boundary == NEARFIELD_BOUNDARY)) { if (Boundary==1){ for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) { Normal = geometry->vertex[iMarker][iVertex]->GetNormal(); Tem = solver->GetTem(iMarker, iVertex); TemTarget = solver->GetTemTarget(iMarker, iVertex); Area = GeometryToolbox::Norm(nDim, Normal); TemDiff += Area * (TemTarget - Tem) * (TemTarget - Tem); } } } su2double MyTemDiff = TemDiff; SU2_MPI::Allreduce(&MyTemDiff, &TemDiff, 1, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm()); } /*--- Update the Temperature ---*/ solver->SetTotal_TemDiff(TemDiff); SetHistoryOutputValue("INVERSE_DESIGN_TEM", TemDiff); } |
|
June 14, 2021, 00:57 |
|
#3 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
Hi,
Add some test details here. I ran the code with various numbers of threads and the returned Cp_diff and Tem_diff are different. What is the possible cause? Thank you! Code:
parallel_computation.py -f film.cfg -n 1 +---------------------------------------------------+ | Inner_Iter| rms[Rho]| Cp_Diff| Tem_Diff| +---------------------------------------------------+ | 0| -16.230367| 0.031739| 93.212880| | 1| -16.406737| 0.031739| 93.212880| parallel_computation.py -f film.cfg -n 5 +---------------------------------------------------+ | Inner_Iter| rms[Rho]| Cp_Diff| Tem_Diff| +---------------------------------------------------+ | 0| -16.230944| 0.031988| 221.127846| | 1| -16.409077| 0.031988| 221.127846| parallel_computation.py -f film.cfg -n 10 +---------------------------------------------------+ | Inner_Iter| rms[Rho]| Cp_Diff| Tem_Diff| +---------------------------------------------------+ | 0| -16.001455| 0.032101| 347.863969| | 1| -16.278280| 0.032101| 347.863969| parallel_computation.py -f film.cfg -n 20 +---------------------------------------------------+ | Inner_Iter| rms[Rho]| Cp_Diff| Tem_Diff| +---------------------------------------------------+ | 0| -16.485980| 0.033051| 390.210340| | 1| -16.492759| 0.033051| 390.210340| parallel_computation.py -f film.cfg -n 30 +---------------------------------------------------+ | Inner_Iter| rms[Rho]| Cp_Diff| Tem_Diff| +---------------------------------------------------+ | 0| -16.063009| 0.033013| 474.397103| | 1| -16.320353| 0.033013| 474.397103| Code:
WARNING: SU2 was not compiled for an AVX-capable architecture. |
|
June 14, 2021, 06:08 |
|
#4 |
Senior Member
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 14 |
On the second loop to compute the difference between actual and target you also need to skip points that are not "domain points", in which case they are "halo points" created by partitioning, hence redundant.
In the first loop this is covered by the logic "if (PointInDomain[iPoint]) {". The original function seems to have the same bug. If the above made no sense at all I can explain better during the developer meetings (https://meet.jit.si/SU2_DevMeeting Weds 15h UK, I think I posted the link in your other post). |
|
June 15, 2021, 00:04 |
|
#5 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
Hi,
It works just as you pointed out! Thank you! I am very glad to join the developer meeting. Zhen |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
udf error | srihari | FLUENT | 1 | October 31, 2016 15:18 |
[swak4Foam] installation problem with version 0.2.3 | Claudio87 | OpenFOAM Community Contributions | 9 | May 8, 2013 11:20 |
Compile problem | ivanyao | OpenFOAM Running, Solving & CFD | 1 | October 12, 2012 10:31 |
Sgimpi | pere | OpenFOAM | 27 | September 24, 2011 08:57 |
Problem with compile the setParabolicInlet | ivanyao | OpenFOAM Running, Solving & CFD | 6 | September 5, 2008 21:50 |