Skip to content

Commit

Permalink
Prj
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2003 committed Dec 8, 2021
1 parent 70e3414 commit 9c7dfcf
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 101 deletions.
4 changes: 2 additions & 2 deletions codes/cgns/src/CgnsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 100,7 @@ void CgnsFactory::ProcessCgnsBases()
void CgnsFactory::ReadCgnsGrid()
{
cgns_global.cgnsbases = cgnsZbase;
std::string prjFileName = ONEFLOW::GetPrjFileName( grid_para.gridFile );
std::string prjFileName = Prj::GetPrjFileName( grid_para.gridFile );
cgnsZbase->ReadCgnsGrid( prjFileName );
}

Expand Down Expand Up @@ -139,7 139,7 @@ void CgnsFactory::CommonToStrGrid()

void CgnsFactory::DumpUnsCgnsGrid()
{
std::string targetFile = ONEFLOW::GetPrjFileName( grid_para.targetFile );
std::string targetFile = Prj::GetPrjFileName( grid_para.targetFile );
cgnsZbase->OpenCgnsFile( targetFile, CG_MODE_WRITE );
cgnsZbase->DumpCgnsMultiBase();
cgnsZbase->CloseCgnsFile();
Expand Down
2 changes: 1 addition & 1 deletion codes/force/src/AeroForceTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 153,7 @@ void AerodynamicForceTask::Dump()

file << oss.str();

CloseFile( file );
Prj::CloseFile( file );
}

void AerodynamicForceTask::CalcForce()
Expand Down
2 changes: 1 addition & 1 deletion codes/geometry/src/Boundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 235,7 @@ void DumpRegion( const std::string & fileName, CommonNameMap & nameMap )
{
file << iter->index << " " << iter->value << std::endl;
}
CloseFile( file );
Prj::CloseFile( file );
}

CommonNameMap RegionNameMap::nameMap;
Expand Down
2 changes: 1 addition & 1 deletion codes/geometry/src/CalcGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 119,7 @@ void CalcGrid::Dump()
grids[ iZone ]->WriteGrid( file );
}

ONEFLOW::CloseFile( file );
Prj::CloseFile( file );
}

void CalcGrid::Post()
Expand Down
2 changes: 1 addition & 1 deletion codes/geometry/src/DomainInp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 849,7 @@ void DomainInp::Dump( MultiDomain * md, GridMediator * gridMediator, PointSearch
int kkk = 1;
}
}
ONEFLOW::CloseFile( file );
Prj::CloseFile( file );
int kkk = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions codes/geometry/src/Plot3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 157,7 @@ void Plot3D::ReadCoorBinary( GridMediator * gridMediator )
}
}

ONEFLOW::CloseFile( file );
Prj::CloseFile( file );
}

void Plot3D::DumpCoorBinary( GridMediator * gridMediator )
Expand Down Expand Up @@ -217,7 217,7 @@ void Plot3D::DumpCoorBinary( GridMediator * gridMediator )
}
}

ONEFLOW::CloseFile( file );
Prj::CloseFile( file );
}

void Plot3D::ReadCoorAscii( GridMediator * gridMediator )
Expand Down Expand Up @@ -629,7 629,7 @@ void Plot3D::DumpBc( GridMediator * gridMediator )
}
}

CloseFile( file );
Prj::CloseFile( file );
}

void Plot3D::ReadCoor( FileIO * ioFile, RealField & coordinate )
Expand Down
4 changes: 2 additions & 2 deletions codes/io/src/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 82,7 @@ void FileIO::OpenFile( const std::string & fileName, const std::ios_base::openmo
{
this->fileName = fileName;
this->fileOpenMode = fileOpenMode;
ONEFLOW::OpenFile( this->file, fileName, fileOpenMode );
Prj::OpenFile( this->file, fileName, fileOpenMode );
}

void FileIO::OpenPrjFile( const std::string & fileName, const std::ios_base::openmode & fileOpenMode )
Expand All @@ -94,7 94,7 @@ void FileIO::OpenPrjFile( const std::string & fileName, const std::ios_base::ope

void FileIO::CloseFile()
{
ONEFLOW::CloseFile( this->file );
Prj::CloseFile( this->file );
}

void FileIO::MarkCurrentFilePosition()
Expand Down
2 changes: 1 addition & 1 deletion codes/io/src/FileO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 49,7 @@ void FileO::OpenPrjFile( const std::string & fileName, const std::ios_base::open

void FileO::CloseFile()
{
ONEFLOW::CloseFile( * file );
Prj::CloseFile( * file );
}

void FileO::DumpCoorAscii( RealField & coor )
Expand Down
2 changes: 1 addition & 1 deletion codes/io/src/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 41,7 @@ void OpenLogFile( int logFileIndex, std::fstream & file )

if ( ifReWrite == 0 )
{
ONEFLOW::MakePrjDir( "log" );
Prj::MakePrjDir( "log" );

Prj::OpenPrjFile( file, fileName, std::ios_base::out | std::ios_base::trunc );

Expand Down
4 changes: 2 additions & 2 deletions codes/io/src/PIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 49,7 @@ void PIO::ParallelOpen( std::fstream & file, const std::string & fileName, const
{
if ( Parallel::pid != Parallel::GetFid() ) return;

ONEFLOW::OpenFile( file, fileName, openMode );
Prj::OpenFile( file, fileName, openMode );
}

void PIO::OpenPrjFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode )
Expand All @@ -73,7 73,7 @@ void PIO::CloseFile( std::fstream & file )
{
if ( Parallel::pid != Parallel::GetFid() ) return;

ONEFLOW::CloseFile( file );
Prj::CloseFile( file );
}


Expand Down
15 changes: 6 additions & 9 deletions codes/project/include/Prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 43,14 @@ class Prj
~Prj();
public:
static void OpenPrjFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode );

static void OpenFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode );
static void CloseFile( std::fstream & file );
static void CreateDirIfNeeded( std::string & prjFileName );
static std::string GetPrjFileName( const std::string & fileName );
static std::string GetPrjDirName( const std::string & fileName );
static void MakePrjDir( const std::string & dirName );
};

void MakePrjDir( const std::string & dirName );

//void OpenPrjFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode );

std::string GetPrjFileName( const std::string & fileName );
std::string GetPrjDirName( const std::string & fileName );

void OpenFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode );
void CloseFile( std::fstream & file );

EndNameSpace
86 changes: 43 additions & 43 deletions codes/project/src/Prj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 54,45 @@ void PrjStatus::SetPrjBaseDir( const std::string & prjName )
std::cout << " PrjStatus::prjBaseDir = " << PrjStatus::prjBaseDir << "\n";
}

void MakePrjDir( const std::string & dirName )
Prj::Prj()
{
;
}

Prj::~Prj()
{
;
}

void Prj::OpenPrjFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode )
{
ONEFLOW::StrIO.ClearAll();
ONEFLOW::StrIO << PrjStatus::prjBaseDir << fileName;

std::string prjFileName = ONEFLOW::StrIO.str();

CreateDirIfNeeded( prjFileName );

Prj::OpenFile( file, prjFileName, openMode );
}

void Prj::OpenFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode )
{
file.open( fileName.c_str(), openMode );
if ( ! file )
{
std::cout << "could not open " << fileName << std::endl;
Stop( "" );
}
}

void Prj::CloseFile( std::fstream & file )
{
file.close();
file.clear();
}

void Prj::MakePrjDir( const std::string & dirName )
{
ONEFLOW::StrIO.ClearAll();
ONEFLOW::StrIO << PrjStatus::prjBaseDir << dirName;
Expand All @@ -65,7 103,7 @@ void MakePrjDir( const std::string & dirName )
MakeDir( prjDirName );
}

std::string GetPrjDirName( const std::string & fileName )
std::string Prj::GetPrjDirName( const std::string & fileName )
{
size_t pos = fileName.find_last_of("\\/");
if ( std::string::npos == pos )
Expand All @@ -79,17 117,17 @@ std::string GetPrjDirName( const std::string & fileName )
}


void CreateDirIfNeeded( std::string & prjFileName )
void Prj::CreateDirIfNeeded( std::string & prjFileName )
{
std::string prj_dir = ONEFLOW::GetPrjDirName( prjFileName );
std::string prj_dir = Prj::GetPrjDirName( prjFileName );

if ( ! DirExist( prj_dir ) )
{
MakeDir( prj_dir );
}
}

std::string GetPrjFileName( const std::string & fileName )
std::string Prj::GetPrjFileName( const std::string & fileName )
{
ONEFLOW::StrIO.ClearAll();

Expand All @@ -102,42 140,4 @@ std::string GetPrjFileName( const std::string & fileName )
return prjFileName;
}

void OpenFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode )
{
file.open( fileName.c_str(), openMode );
if ( ! file )
{
std::cout << "could not open " << fileName << std::endl;
Stop( "" );
}
}

void CloseFile( std::fstream & file )
{
file.close();
file.clear();
}

Prj::Prj()
{
;
}

Prj::~Prj()
{
;
}

void Prj::OpenPrjFile( std::fstream & file, const std::string & fileName, const std::ios_base::openmode & openMode )
{
ONEFLOW::StrIO.ClearAll();
ONEFLOW::StrIO << PrjStatus::prjBaseDir << fileName;

std::string prjFileName = ONEFLOW::StrIO.str();

CreateDirIfNeeded( prjFileName );

ONEFLOW::OpenFile( file, prjFileName, openMode );
}

EndNameSpace
2 changes: 1 addition & 1 deletion codes/scalar/src/FieldSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 765,7 @@ void FieldSolver::ToTecplot( RealField & xList, RealField & varlist, std::string
file << xm << " " << fm << "\n";
}

CloseFile( file );
Prj::CloseFile( file );
}

void PrepareFieldSendData()
Expand Down
14 changes: 7 additions & 7 deletions codes/scalar/src/Numpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 105,7 @@ void Numpy::Plot( const std::string & fileName, std::vector< double > & x, std::
file << x[ i ] << " " << f[ i ] << " ";
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::ToTecplot( const std::string & fileName, std::vector< double > & x, std::vector< double > & f )
Expand All @@ -122,7 122,7 @@ void Numpy::ToTecplot( const std::string & fileName, std::vector< double > & x,
file << x[ i ] << " " << f[ i ] << "\n";
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::ToTecplot( const std::string & fileName, std::vector< double > & x, std::vector< double > & u, std::vector< double > & v )
Expand All @@ -139,7 139,7 @@ void Numpy::ToTecplot( const std::string & fileName, std::vector< double > & x,
file << x[ i ] << " " << u[ i ] << " " << v[ i ] << "\n";
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::Analysis( const std::string & fileName, std::vector< double > & x, std::vector< std::vector< double > > & du )
Expand All @@ -161,7 161,7 @@ void Numpy::Analysis( const std::string & fileName, std::vector< double > & x, s
file << std::endl;
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::AnalysisNew( const std::string & fileName, std::vector< std::vector< double > > & x, std::vector< std::vector< double > > & du )
Expand All @@ -181,7 181,7 @@ void Numpy::AnalysisNew( const std::string & fileName, std::vector< std::vector<
}
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::DrawL1Norm( const std::string & fileName, std::vector< double > & dxList, std::vector< double > & l1NormList )
Expand All @@ -199,7 199,7 @@ void Numpy::DrawL1Norm( const std::string & fileName, std::vector< double > & dx
file << dxList[ i ] << " " << l1NormList[ i ] << std::endl;
}

CloseFile( file );
Prj::CloseFile( file );
}

void Numpy::DrawNorms( const std::string & fileName, std::vector< double > & dxList, std::vector< double > & l1NormList, std::vector< double > & l2NormList )
Expand All @@ -216,7 216,7 @@ void Numpy::DrawNorms( const std::string & fileName, std::vector< double > & dxL
{
file << dxList[ i ] << " " << l1NormList[ i ] << " " << l2NormList[ i ] << std::endl;
}
CloseFile( file );
Prj::CloseFile( file );
}


Expand Down
2 changes: 1 addition & 1 deletion codes/scalar/src/ScalarField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 100,7 @@ void ScalarField::ToTecplot( RealList & varlist, std::string const & fileName )
file << xm << " " << fm << "\n";
}

CloseFile( file );
Prj::CloseFile( file );
}

void ScalarField::SolveFlowField( FieldPara * para )
Expand Down
6 changes: 3 additions & 3 deletions codes/scalar/src/ScalarGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 548,7 @@ void ScalarGrid::SetCgnsZone( CgnsZone * cgnsZone )
void ScalarGrid::DumpCgnsGrid()
{
std::fstream file;
std::string prjFileName = ONEFLOW::GetPrjFileName( "scalar.cgns" );
std::string prjFileName = Prj::GetPrjFileName( "scalar.cgns" );
CgnsZbase * cgnsZbase = new CgnsZbase();
cgnsZbase->nBases = 1;
cgnsZbase->InitCgnsBase();
Expand Down Expand Up @@ -1151,7 1151,7 @@ void ScalarGrid::DumpCalcGrid()
this->WriteGrid( databook );
databook->WriteFile( file );
delete databook;
CloseFile( file );
Prj::CloseFile( file );
}

void ScalarGrid::WriteGrid( std::fstream & file )
Expand Down Expand Up @@ -1204,7 1204,7 @@ void ScalarGrid::ReadCalcGrid()
databook->ReadFile( file );
this->ReadGrid( databook );
delete databook;
CloseFile( file );
Prj::CloseFile( file );
}

void ScalarGrid::ReadGrid( std::fstream & file )
Expand Down
Loading

0 comments on commit 9c7dfcf

Please sign in to comment.