Skip to content

Commit

Permalink
include "TimeTest.h"
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2003 committed Dec 10, 2021
1 parent 298afac commit 32be645
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 33 deletions.
1 change: 0 additions & 1 deletion codes/basic/include/HXDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,6 @@ typedef HXVector< std::string > StringField;
typedef HXVector< bool > BoolField;

typedef std::set< int > IntSet;
typedef HXVector< IntSet > LinkSet;

typedef void( * VoidFunc )();

Expand Down
47 changes: 37 additions & 10 deletions codes/scalar/src/FieldPara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 39,49 @@ FieldPara::~FieldPara()
;
}

//void FieldPara::Init()
//{
// //this->nx = 41;
// //this->len = 2.0;
// //this->dx = len / ( nx - 1.0 );
// ////this->nt = 25;
// //this->nt = 25;
// //this->dt = 0.025;
// //this->c = 1;
//
// this->nx = ONEFLOW::GetDataValue< int >("scalar_nx");
// this->len = ONEFLOW::GetDataValue< int >("scalar_len");
// this->nt = ONEFLOW::GetDataValue< int >("scalar_nt");
// this->dt = ONEFLOW::GetDataValue< Real >("scalar_dt");
// this->c = ONEFLOW::GetDataValue< Real >("scalar_c");
// this->dx = this->len / ( this->nx - 1.0 );
//}

void FieldPara::Init()
{
//this->nx = 41;
//this->len = 2.0;
//this->dx = len / ( nx - 1.0 );
////this->nt = 25;
//this->nt = 25;
//this->dt = 0.025;
//this->c = 1;
int nbase = 40;
int base_nt = 25;

this->nx = ONEFLOW::GetDataValue< int >("scalar_nx");
this->len = ONEFLOW::GetDataValue< int >("scalar_len");
this->nt = ONEFLOW::GetDataValue< int >("scalar_nt");
this->dt = ONEFLOW::GetDataValue< Real >("scalar_dt");
this->c = ONEFLOW::GetDataValue< Real >("scalar_c");
this->dx = this->len / ( this->nx - 1.0 );

double base_dx = this->len / nbase;
double base_dt = 0.025;
double cfl = base_dt / base_dx;

double total_t = 25 * 0.025;

this->dx = len / ( this->nx - 1.0 );
int nratio = ( this->nx - 1 ) / nbase;
this->dt = base_dt / nratio;
this->nt = base_nt * nratio;
std::cout << " nratio = " << nratio << "\n";
std::cout << " this->dt = " << this->dt << "\n";
std::cout << " this->nt = " << this->nt << "\n";
std::cout << " this->dx = " << this->dx << "\n";
std::cout << " dx = " << base_dx / nratio << "\n";
}


EndNameSpace
4 changes: 4 additions & 0 deletions codes/scalar/src/FieldSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 47,7 @@ License
#include "ScalarZone.h"
#include "HXCgns.h"
#include "HXMath.h"
#include "TimeTest.h"
#include <iostream>
#include <vector>
#include <algorithm>
Expand Down Expand Up @@ -92,6 93,9 @@ void FieldSolver::Run()
int scalar_flag = ONEFLOW::GetDataValue< int >("scalar_flag");
Dim::SetDimension( ONEFLOW::GetDataValue< int >( "dimension" ) );

TimeTest ts;
ts.RunTest();

if ( scalar_flag == 0 )
{
ScalarMetis::Create1DMesh();
Expand Down
44 changes: 22 additions & 22 deletions codes/scalar/src/ScalarGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,12 1280,12 @@ void ScalarGrid::WriteGridFaceTopology( DataBook * databook )
std::cout << " Dumping this->fTypes \n";
ONEFLOW::HXWrite( databook, this->fTypes.data );

std::cout << "fTypes = \n";
for ( int iFace = 0; iFace < this->fTypes.data.size(); iFace )
{
std::cout << this->fTypes.data[ iFace ] << " ";
}
std::cout << "\n";
//std::cout << "fTypes = \n";
//for ( int iFace = 0; iFace < this->fTypes.data.size(); iFace )
//{
// std::cout << this->fTypes.data[ iFace ] << " ";
//}
//std::cout << "\n";

IntField numFaceNode( this->nFaces );

Expand All @@ -1301,11 1301,11 @@ void ScalarGrid::WriteGridFaceTopology( DataBook * databook )
int nsum = ONEFLOW::SUM( numFaceNode );
std::cout << " nsum = " << nsum << "\n";
std::cout << "numFaceNode = \n";
for ( int iFace = 0; iFace < numFaceNode.size(); iFace )
{
std::cout << numFaceNode[ iFace ] << " ";
}
std::cout << "\n";
//for ( int iFace = 0; iFace < numFaceNode.size(); iFace )
//{
// std::cout << numFaceNode[ iFace ] << " ";
//}
//std::cout << "\n";

IntField faceNodeMem;

Expand Down Expand Up @@ -1335,12 1335,12 @@ void ScalarGrid::ReadGridFaceTopology( DataBook * databook )

ONEFLOW::HXRead( databook, this->fTypes.data );

std::cout << "fTypes = \n";
for ( int iFace = 0; iFace < this->fTypes.data.size(); iFace )
{
std::cout << this->fTypes.data[ iFace ] << " ";
}
std::cout << "\n";
//std::cout << "fTypes = \n";
//for ( int iFace = 0; iFace < this->fTypes.data.size(); iFace )
//{
// std::cout << this->fTypes.data[ iFace ] << " ";
//}
//std::cout << "\n";

IntField numFaceNode( this->nFaces );

Expand All @@ -1352,11 1352,11 @@ void ScalarGrid::ReadGridFaceTopology( DataBook * databook )
std::cout << " nsum = " << nsum << "\n";
std::cout << " this->nFaces = " << this->nFaces << "\n";
std::cout << "numFaceNode = \n";
for ( int iFace = 0; iFace < numFaceNode.size(); iFace )
{
std::cout << numFaceNode[ iFace ] << " ";
}
std::cout << "\n";
//for ( int iFace = 0; iFace < numFaceNode.size(); iFace )
//{
// std::cout << numFaceNode[ iFace ] << " ";
//}
//std::cout << "\n";

std::cout << "Setting the connection mode of face to point......\n";
IntField faceNodeMem( nsum );
Expand Down
52 changes: 52 additions & 0 deletions codes/time/include/TimeTest.h
Original file line number Diff line number Diff line change
@@ -0,0 1,52 @@
/*---------------------------------------------------------------------------*\
OneFLOW - LargeScale Multiphysics Scientific Simulation Environment
Copyright (C) 2017-2021 He Xin and the OneFLOW contributors.
-------------------------------------------------------------------------------
License
This file is part of OneFLOW.
OneFLOW is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OneFLOW is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OneFLOW. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#pragma once
#include "Configure.h"
#include <chrono>
#include <string>


BeginNameSpace( ONEFLOW )

class TimeTest
{
public:
using clock_type = std::chrono::time_point<std::chrono::system_clock>;
public:
TimeTest();
~TimeTest();
public:
void Start();
void Stop();

double ElapsedMilliseconds();
double ElapsedSeconds();
public:
void RunTest();
private:
clock_type startTime;
clock_type endTime;
bool bRunning = false;
};


EndNameSpace
91 changes: 91 additions & 0 deletions codes/time/src/TimeTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 1,91 @@
/*---------------------------------------------------------------------------*\
OneFLOW - LargeScale Multiphysics Scientific Simulation Environment
Copyright (C) 2017-2021 He Xin and the OneFLOW contributors.
-------------------------------------------------------------------------------
License
This file is part of OneFLOW.
OneFLOW is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OneFLOW is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OneFLOW. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/

#include "TimeTest.h"
#include <iostream>
#include <thread>

BeginNameSpace( ONEFLOW )

TimeTest::TimeTest()
{
this->Start();
}

TimeTest::~TimeTest()
{
;
}

void TimeTest::Start()
{
this->startTime = std::chrono::system_clock::now();
this->bRunning = true;
}

void TimeTest::Stop()
{
this->endTime = std::chrono::system_clock::now();
this->bRunning = false;
}

double TimeTest::ElapsedMilliseconds()
{
std::chrono::time_point<std::chrono::system_clock> endTime;

if ( bRunning )
{
this->endTime = std::chrono::system_clock::now();
}

return std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
}

double TimeTest::ElapsedSeconds()
{
return ElapsedMilliseconds() / 1000.0;
}

void TimeTest::RunTest()
{
auto start = std::chrono::steady_clock::now();
auto end = std::chrono::steady_clock::now();

std::cout << "Elapsed time in nanoseconds: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count()
<< " ns" << std::endl;

std::cout << "Elapsed time in microseconds: "
<< std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()
<< " mus" << std::endl;

std::cout << "Elapsed time in milliseconds: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << std::endl;

std::cout << "Elapsed time in seconds: "
<< std::chrono::duration_cast<std::chrono::seconds>(end - start).count()
<< " sec";
}


EndNameSpace

0 comments on commit 32be645

Please sign in to comment.