@@ -695,123 +695,96 @@ void CFlowOutput::SetRotatingFrameCoefficients(CConfig *config, CSolver *flow_so
695
695
}
696
696
697
697
698
- void CFlowOutput::Add_CpInverseDesignOutput (CConfig *config ){
698
+ void CFlowOutput::Add_CpInverseDesignOutput (){
699
699
700
700
AddHistoryOutput (" INVERSE_DESIGN_PRESSURE" , " Cp_Diff" , ScreenOutputFormat::FIXED, " CP_DIFF" , " Cp difference for inverse design" );
701
701
702
702
}
703
703
704
- void CFlowOutput::Set_CpInverseDesign (CSolver *solver, CGeometry *geometry, CConfig *config){
705
-
706
- unsigned short iMarker, icommas, Boundary;
707
- unsigned long iVertex, iPoint, (*Point2Vertex)[2 ], nPointLocal = 0 , nPointGlobal = 0 ;
708
- su2double XCoord, YCoord, ZCoord, Pressure, PressureCoeff = 0 , Cp, CpTarget, *Normal = nullptr , Area, PressDiff = 0.0 ;
709
- bool *PointInDomain;
710
- string text_line, surfCp_filename;
711
- ifstream Surface_file;
704
+ void CFlowOutput::Set_CpInverseDesign (CSolver *solver, const CGeometry *geometry, const CConfig *config){
712
705
713
706
/* --- Prepare to read the surface pressure files (CSV) ---*/
714
707
715
- surfCp_filename = config->GetUnsteady_FileName (" TargetCp" , (int )curTimeIter, " .dat" );
716
-
717
- /* --- Read the surface pressure file ---*/
708
+ const auto surfCp_filename = config->GetUnsteady_FileName (" TargetCp" , curTimeIter, " .dat" );
718
709
719
- string::size_type position;
710
+ /* --- Read the surface pressure file, on the first inner iteration. --- */
720
711
712
+ ifstream Surface_file;
721
713
Surface_file.open (surfCp_filename);
722
714
723
- if (!(Surface_file.fail ())) {
724
-
725
- nPointLocal = geometry->GetnPoint ();
726
- SU2_MPI::Allreduce (&nPointLocal, &nPointGlobal, 1 , MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm ());
727
-
728
- Point2Vertex = new unsigned long [nPointGlobal][2 ];
729
- PointInDomain = new bool [nPointGlobal];
730
-
731
- for (iPoint = 0 ; iPoint < nPointGlobal; iPoint ++)
732
- PointInDomain[iPoint] = false ;
733
-
734
- for (iMarker = 0 ; iMarker < config->GetnMarker_All (); iMarker++) {
735
- Boundary = config->GetMarker_All_KindBC (iMarker);
736
-
737
- if (config->GetSolid_Wall (iMarker) || (Boundary == NEARFIELD_BOUNDARY)) {
738
- for (iVertex = 0 ; iVertex < geometry->GetnVertex (iMarker); iVertex++) {
739
-
740
- /* --- The Pressure file uses the global numbering ---*/
741
-
742
- iPoint = geometry->nodes ->GetGlobalIndex (geometry->vertex [iMarker][iVertex]->GetNode ());
743
-
744
- if (geometry->vertex [iMarker][iVertex]->GetNode () < geometry->GetnPointDomain ()) {
745
- Point2Vertex[iPoint][0 ] = iMarker;
746
- Point2Vertex[iPoint][1 ] = iVertex;
747
- PointInDomain[iPoint] = true ;
748
- solver->SetCPressureTarget (iMarker, iVertex, 0.0 );
749
- }
750
-
751
- }
752
- }
753
- }
715
+ if (!Surface_file.good ()) {
716
+ solver->SetTotal_CpDiff (0.0 );
717
+ SetHistoryOutputValue (" INVERSE_DESIGN_PRESSURE" , 0.0 );
718
+ return ;
719
+ }
754
720
721
+ if ((config->GetInnerIter () == 0 ) || config->GetDiscrete_Adjoint ()) {
722
+ string text_line;
755
723
getline (Surface_file, text_line);
756
724
757
725
while (getline (Surface_file, text_line)) {
758
- for (icommas = 0 ; icommas < 50 ; icommas++) {
759
- position = text_line.find ( " ," , 0 );
760
- if (position!=string::npos) text_line.erase (position,1 );
761
- }
762
- stringstream point_line (text_line);
763
-
764
- if (geometry->GetnDim () == 2 ) point_line >> iPoint >> XCoord >> YCoord >> Pressure >> PressureCoeff;
765
- if (geometry->GetnDim () == 3 ) point_line >> iPoint >> XCoord >> YCoord >> ZCoord >> Pressure >> PressureCoeff;
766
-
767
- if (PointInDomain[iPoint]) {
768
-
769
- /* --- Find the vertex for the Point and Marker ---*/
770
-
771
- iMarker = Point2Vertex[iPoint][0 ];
772
- iVertex = Point2Vertex[iPoint][1 ];
773
-
774
- solver->SetCPressureTarget (iMarker, iVertex, PressureCoeff);
775
-
726
+ /* --- remove commas ---*/
727
+ for (auto & c : text_line) if (c == ' ,' ) c = ' ' ;
728
+ stringstream point_line (text_line);
729
+
730
+ /* --- parse line ---*/
731
+ unsigned long iPointGlobal;
732
+ su2double XCoord, YCoord, ZCoord=0 , Pressure, PressureCoeff;
733
+
734
+ point_line >> iPointGlobal >> XCoord >> YCoord;
735
+ if (nDim == 3 ) point_line >> ZCoord;
736
+ point_line >> Pressure >> PressureCoeff;
737
+
738
+ const auto iPoint = geometry->GetGlobal_to_Local_Point (iPointGlobal);
739
+
740
+ /* --- If the point is on this rank set the Cp to associated vertices
741
+ * (one point may be shared by multiple vertices). ---*/
742
+ if (iPoint >= 0 ) {
743
+ bool set = false ;
744
+ for (auto iMarker = 0u ; iMarker < geometry->GetnMarker (); ++iMarker) {
745
+ const auto iVertex = geometry->nodes ->GetVertex (iPoint, iMarker);
746
+
747
+ if (iVertex >= 0 ) {
748
+ solver->SetCPressureTarget (iMarker, iVertex, PressureCoeff);
749
+ set = true ;
750
+ }
751
+ }
752
+ if (!set)
753
+ cout << " WARNING: In file " << surfCp_filename << " , point " << iPointGlobal << " is not a vertex." << endl;
776
754
}
777
-
778
755
}
756
+ }
779
757
780
- Surface_file.close ();
781
-
782
- delete [] Point2Vertex;
783
- delete [] PointInDomain;
758
+ /* --- Compute the pressure difference. ---*/
784
759
785
- /* --- Compute the pressure difference --- */
760
+ su2double PressDiff = 0.0 ;
786
761
787
- PressDiff = 0.0 ;
788
- for (iMarker = 0 ; iMarker < config->GetnMarker_All (); iMarker++) {
789
- Boundary = config->GetMarker_All_KindBC (iMarker);
762
+ for (auto iMarker = 0u ; iMarker < geometry->GetnMarker (); ++iMarker) {
790
763
791
- if (config->GetSolid_Wall (iMarker) || (Boundary == NEARFIELD_BOUNDARY)) {
792
- for (iVertex = 0 ; iVertex < geometry->GetnVertex (iMarker); iVertex++) {
764
+ const auto Boundary = config->GetMarker_All_KindBC (iMarker);
793
765
794
- Normal = geometry->vertex [iMarker][iVertex]->GetNormal ();
766
+ if (config->GetSolid_Wall (iMarker) || (Boundary == NEARFIELD_BOUNDARY)) {
767
+ for (auto iVertex = 0ul ; iVertex < geometry->GetnVertex (iMarker); iVertex++) {
795
768
796
- Cp = solver-> GetCPressure ( iMarker, iVertex);
797
- CpTarget = solver-> GetCPressureTarget (iMarker, iVertex) ;
769
+ const auto iPoint = geometry-> vertex [ iMarker][ iVertex]-> GetNode ( );
770
+ if (!geometry-> nodes -> GetDomain (iPoint)) continue ;
798
771
799
- Area = GeometryToolbox::Norm (nDim, Normal);
772
+ const auto Cp = solver->GetCPressure (iMarker, iVertex);
773
+ const auto CpTarget = solver->GetCPressureTarget (iMarker, iVertex);
800
774
801
- PressDiff += Area * (CpTarget - Cp) * (CpTarget - Cp );
802
- }
775
+ const auto Normal = geometry-> vertex [iMarker][iVertex]-> GetNormal ( );
776
+ const auto Area = GeometryToolbox::Norm (nDim, Normal);
803
777
778
+ PressDiff += Area * pow (CpTarget-Cp, 2 );
804
779
}
805
780
}
806
-
807
- su2double MyPressDiff = PressDiff;
808
- SU2_MPI::Allreduce (&MyPressDiff, &PressDiff, 1 , MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm ());
809
781
}
782
+ su2double tmp = PressDiff;
783
+ SU2_MPI::Allreduce (&tmp, &PressDiff, 1 , MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm ());
810
784
811
- /* --- Update the total Cp difference coeffient ---*/
785
+ /* --- Update the total Cp difference coeffient. ---*/
812
786
813
787
solver->SetTotal_CpDiff (PressDiff);
814
-
815
788
SetHistoryOutputValue (" INVERSE_DESIGN_PRESSURE" , PressDiff);
816
789
817
790
}
@@ -820,7 +793,7 @@ su2double CFlowOutput::GetQ_Criterion(su2double** VelocityGradient) const {
820
793
821
794
/* --- Make a 3D copy of the gradient so we do not have worry about nDim ---*/
822
795
823
- su2double Grad_Vel[3 ][3 ] = {{0.0 , 0.0 , 0.0 },{ 0.0 , 0.0 , 0.0 },{ 0.0 , 0.0 , 0.0 }};
796
+ su2double Grad_Vel[3 ][3 ] = {{0.0 }};
824
797
825
798
for (unsigned short iDim = 0 ; iDim < nDim; iDim++)
826
799
for (unsigned short jDim = 0 ; jDim < nDim; jDim++)
0 commit comments