@@ -77,7 +77,6 @@ void BBase::ReadFile(const std::string &fileName)
7777{
7878 // namespace fs = std::filesystem;
7979 // std::cout << "Current path is " << fs::current_path() << '\n';
80-
8180 int openStatus = cg_open ( fileName.c_str (), CG_MODE_READ, & this ->fileId );
8281 std::string stars ( " **************************************************************" );
8382 std::cout << stars << " \n " ;
@@ -157,9 +156,12 @@ void Base::ReadBaseUnits( int fileId, int baseId )
157156{
158157 DataClass_t dclass;
159158 cg_goto (fileId, 1 , " end" );
160- cg_dataclass_read (&dclass);
159+ int ierr = cg_dataclass_read (&dclass);
161160
162- std::cout << " dclass = " << dclass << " dclass name = " << DataClassName[dclass] << " \n " ;
161+ if ( ierr == CG_OK )
162+ {
163+ std::cout << " dclass = " << dclass << " dclass name = " << DataClassName[ dclass ] << " \n " ;
164+ }
163165
164166 CGNS_ENUMT (MassUnits_t) mass;
165167 CGNS_ENUMT (LengthUnits_t) length;
@@ -176,30 +178,41 @@ void Base::ReadBaseUnits( int fileId, int baseId )
176178 CGNS_ENUMT (TemperatureUnits_t) ix;
177179 CGNS_ENUMT (AngleUnits_t) ia;
178180
179- cg_units_read (&im,&il,&it,&ix,&ia);
181+ ierr = cg_units_read (&im,&il,&it,&ix,&ia);
180182
181- std::printf (" \n Units=\n %s\n %s\n %s\n %s\n %s\n " ,
182- MassUnitsName[im],LengthUnitsName[il],TimeUnitsName[it],
183- TemperatureUnitsName[ix],AngleUnitsName[ia]);
183+ if ( ierr == CG_OK )
184+ {
185+ std::printf ( " \n Units=\n %s\n %s\n %s\n %s\n %s\n " ,
186+ MassUnitsName[ im ], LengthUnitsName[ il ], TimeUnitsName[ it ],
187+ TemperatureUnitsName[ ix ], AngleUnitsName[ ia ] );
188+ }
184189
185190 int nunits = -1 ;
186- cg_nunits (&nunits);
187-
188- std::cout << " CGNS nunits = " << nunits << " \n " ;
191+ ierr = cg_nunits (&nunits);
192+ if ( ierr == CG_OK )
193+ {
194+ std::cout << " CGNS nunits = " << nunits << " \n " ;
195+ }
189196
190- cg_unitsfull_read (&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity);
191- std::cout << " mass = " << mass << " MassUnitsName[mass] = " << MassUnitsName[mass]<<" \n " ;
192- std::cout << " length = " << length << " LengthUnitsName[length] = " << LengthUnitsName[length]<<" \n " ;
193- std::cout << " time = " << time << " TimeUnitsName[time] = " << TimeUnitsName[time]<<" \n " ;
194- std::cout << " temp = " << temp << " TemperatureUnitsName[temp] = " << TemperatureUnitsName[temp]<<" \n " ;
195- std::cout << " angle = " << angle<< " AngleUnitsName[angle] = " << AngleUnitsName[angle]<<" \n " ;
196- std::cout << " current = " << current<< " ElectricCurrentUnitsName[current] = " << ElectricCurrentUnitsName[current]<<" \n " ;
197- std::cout << " amount = " << amount<< " SubstanceAmountUnitsName[amount] = " << SubstanceAmountUnitsName[amount]<<" \n " ;
198- std::cout << " intensity = " << intensity << " LuminousIntensityUnitsName[intensity] = " << LuminousIntensityUnitsName[intensity]<<" \n " ;
197+ ierr = cg_unitsfull_read (&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity);
198+ if ( ierr == CG_OK )
199+ {
200+ std::cout << " mass = " << mass << " MassUnitsName[mass] = " << MassUnitsName[ mass ] << " \n " ;
201+ std::cout << " length = " << length << " LengthUnitsName[length] = " << LengthUnitsName[ length ] << " \n " ;
202+ std::cout << " time = " << time << " TimeUnitsName[time] = " << TimeUnitsName[ time ] << " \n " ;
203+ std::cout << " temp = " << temp << " TemperatureUnitsName[temp] = " << TemperatureUnitsName[ temp ] << " \n " ;
204+ std::cout << " angle = " << angle << " AngleUnitsName[angle] = " << AngleUnitsName[ angle ] << " \n " ;
205+ std::cout << " current = " << current << " ElectricCurrentUnitsName[current] = " << ElectricCurrentUnitsName[ current ] << " \n " ;
206+ std::cout << " amount = " << amount << " SubstanceAmountUnitsName[amount] = " << SubstanceAmountUnitsName[ amount ] << " \n " ;
207+ std::cout << " intensity = " << intensity << " LuminousIntensityUnitsName[intensity] = " << LuminousIntensityUnitsName[ intensity ] << " \n " ;
208+ }
199209
200210 int nexps = -1 ;
201- cg_nexponents (&nexps);
202- std::cout << " nexps = " << nexps << " \n " ;
211+ ierr = cg_nexponents (&nexps);
212+ if ( ierr == CG_OK )
213+ {
214+ std::cout << " nexps = " << nexps << " \n " ;
215+ }
203216}
204217
205218void Base::ReadBase ( int fileId, int baseId )
@@ -323,7 +336,7 @@ void Zone::DumpZone()
323336 }
324337 std::cout << " total faces of zone : " << this ->nFaces << " \n " ;
325338 std::cout << " total number face nodes of zone : " << this ->totalNumFaceNodes << " \n " ;
326- this ->DrawZone ();
339+ // this->DrawZone();
327340}
328341
329342void Zone::DrawZone ()
@@ -497,6 +510,47 @@ void Zone::SetDimensions()
497510 this ->nNodes = this ->irmax [ 0 ];
498511 this ->nCells = this ->cellSize [ 0 ];
499512 }
513+ else
514+ {
515+ // lower range index
516+ this ->irmin [ 0 ] = 1 ;
517+ this ->irmin [ 1 ] = 1 ;
518+ this ->irmin [ 2 ] = 1 ;
519+
520+ // upper range index of vertices
521+ this ->irmax [ 0 ] = 1 ;
522+ this ->irmax [ 1 ] = 1 ;
523+ this ->irmax [ 2 ] = 1 ;
524+
525+ this ->cellSize [ 0 ] = 1 ;
526+ this ->cellSize [ 1 ] = 1 ;
527+ this ->cellSize [ 2 ] = 1 ;
528+
529+ // upper range index of vertices
530+ // vertex size
531+ int j = 0 ;
532+ this ->irmax [ 0 ] = this ->isize [ j ++ ];
533+ this ->irmax [ 1 ] = this ->isize [ j ++ ];
534+
535+ int celldim = THREE_D;
536+ if ( celldim == THREE_D )
537+ {
538+ this ->irmax [ 2 ] = this ->isize [ j ++ ];
539+ }
540+ // cell size
541+ this ->cellSize [ 0 ] = this ->isize [ j ++ ];
542+ this ->cellSize [ 1 ] = this ->isize [ j ++ ];
543+ if ( celldim == THREE_D )
544+ {
545+ cellSize[ 2 ] = this ->isize [ j ++ ];
546+ }
547+ std::cout << " The Dimension Of Grid is : \n " ;
548+ std::cout << " I Direction " << std::setw ( 10 ) << irmin[ 0 ] << std::setw ( 10 ) << irmax[ 0 ] << " \n " ;
549+ std::cout << " J Direction " << std::setw ( 10 ) << irmin[ 1 ] << std::setw ( 10 ) << irmax[ 1 ] << " \n " ;
550+ std::cout << " K Direction " << std::setw ( 10 ) << irmin[ 2 ] << std::setw ( 10 ) << irmax[ 2 ] << " \n " ;
551+ this ->nNodes = irmax[ 0 ] * irmax[ 1 ] * irmax[ 2 ];
552+ this ->nCells = cellSize[ 0 ] * cellSize[ 1 ] * cellSize[ 2 ];
553+ }
500554 std::cout << " numberOfNodes = " << this ->nNodes << " numberOfCells = " << this ->nCells << " \n " ;
501555}
502556
@@ -651,12 +705,12 @@ void Coor::DumpCoor()
651705
652706Field::Field ()
653707{
654- this ->data = 0 ;
708+ // this->data = 0;
655709}
656710
657711Field::~Field ()
658712{
659- this ->DeAllocateData ();
713+ // this->DeAllocateData();
660714}
661715
662716void Field::ReadField ( int fileId, int baseId, int zoneId, int solutionId, int fieldId, Zone * zone )
@@ -679,7 +733,7 @@ void Field::ReadField( int fileId, int baseId, int zoneId, int solutionId, int f
679733 this ->AllocateData ( zone->nNodes );
680734
681735 std::cout << " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
682- int ierr = cg_field_read ( fileId, baseId, zoneId, solutionId, this ->fieldName , this ->dataType , zone->irmin , zone->irmax , this ->data );
736+ int ierr = cg_field_read ( fileId, baseId, zoneId, solutionId, this ->fieldName , this ->dataType , zone->irmin , zone->irmax , this ->data . data () );
683737 if ( ierr == CG_OK )
684738 {
685739 std::cout << " cg_field_read ierr = " << ierr << " \n " ;
@@ -737,28 +791,38 @@ void Field::AllocateData( int nNodes )
737791 this ->nNodes = nNodes;
738792 if ( this ->dataType == RealSingle )
739793 {
740- this ->data = new float [ nNodes ];
794+ // this->data = new float [ nNodes ];
795+ this ->data .resize (nNodes * sizeof (float ) );
741796 }
742- else
797+ else if ( this -> dataType == RealDouble )
743798 {
744- this ->data = new double [ nNodes ];
799+ // this->data = new double [ nNodes ];
800+ this ->data .resize (nNodes * sizeof (double ) );
745801 }
746- }
747-
748- void Field::DeAllocateData ()
749- {
750- if ( this ->dataType == RealSingle )
802+ else if ( this ->dataType == ComplexSingle )
751803 {
752- float * f_data = static_cast < float * >( this ->data );
753- delete [] f_data;
804+ this ->data .resize (nNodes * 2 * sizeof (float ) );
754805 }
755- else
806+ else if ( this -> dataType == ComplexDouble )
756807 {
757- double * d_data = static_cast < double * >( this ->data );
758- delete [] d_data;
808+ this ->data .resize (nNodes * 2 * sizeof (double ) );
759809 }
760810}
761811
812+ void Field::DeAllocateData ()
813+ {
814+ // if ( this->dataType == RealSingle )
815+ // {
816+ // float * f_data = static_cast< float * >( this->data );
817+ // delete [] f_data;
818+ // }
819+ // else
820+ // {
821+ // double * d_data = static_cast< double * >( this->data );
822+ // delete [] d_data;
823+ // }
824+ }
825+
762826Solution::Solution ()
763827{
764828 ;
0 commit comments