FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor startup routines · idefix-code/idefix@3b8e491 · GitHub

Repository navigation

Commit 3b8e491

Browse files
committed
refactor startup routines
1 parent df97559 commit 3b8e491

25 files changed

Lines changed: 418 additions & 167 deletions

‎src/dataBlock/dataBlock.cpp‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ void DataBlock::InitFromGrid(Grid &grid, Input &input) {
6060
xend[dir] = gridHost.xr[dir](gend[dir]-1);
6161
}
6262

63-
if(idfx::psize>1) {
64-
idfx::cout << "DataBlock::InitFromGrid: local size is " << std::endl;
65-
66-
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
67-
idfx::cout << "\t Direction X" << (dir+1) << ": " << xbeg[dir] << "...." << np_int[dir]
68-
<< "...." << xend[dir] << std::endl;
69-
}
70-
}
71-
7263
// Allocate the required fields
7364
for(int dir = 0 ; dir < 3 ; dir++) {
7465
x[dir] = IdefixArray1D<real>("DataBlock_x",np_tot[dir]);
@@ -146,3 +137,17 @@ void DataBlock::ResetStage() {
146137
void DataBlock::SetBoundaries() {
147138
hydro.boundary.SetBoundaries(t);
148139
}
140+
141+
void DataBlock::ShowConfig() {
142+
if(idfx::psize>1) {
143+
idfx::cout << "DataBlock: this process grid size is " << std::endl;
144+
145+
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
146+
idfx::cout << "\t Direction X" << (dir+1) << ": " << xbeg[dir] << "...." << np_int[dir]
147+
<< "...." << xend[dir] << std::endl;
148+
}
149+
}
150+
hydro.ShowConfig();
151+
if(haveFargo) fargo.ShowConfig();
152+
if(haveGravity) gravity.ShowConfig();
153+
}

‎src/dataBlock/dataBlock.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DataBlock {
7676

7777
void EvolveStage(); ///< Evolve this DataBlock by dt
7878
void SetBoundaries(); ///< Enforce boundary conditions to this datablock
79-
79+
void ShowConfig(); ///< Show the datablock's configuration
8080

8181
void ResetStage(); ///< Reset the variables needed at each major integration Stage
8282

‎src/dataBlock/dataBlockHost.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ class DataBlockHost {
2323
IdefixArray3D<real>::HostMirror A[3]; // cell right interface area
2424

2525
IdefixArray4D<real>::HostMirror Vc; // Main cell-centered primitive variables index
26+
#if MHD == YES
2627
IdefixArray4D<real>::HostMirror Vs; // Main face-centered primitive variables index
2728
IdefixArray4D<real>::HostMirror Ve; // Main edge-centered primitive variables index
2829
IdefixArray4D<real>::HostMirror J; // Current (only when haveCurrent is enabled)
30+
#endif
2931
IdefixArray4D<real>::HostMirror Uc; // Main cell-centered conservative variables
3032
IdefixArray3D<real>::HostMirror InvDt;
3133

‎src/dataBlock/fargo.cpp‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,19 @@ void Fargo::Init(Input &input, DataBlock *data) {
242242
}
243243
#endif
244244

245+
246+
idfx::popRegion();
247+
}
248+
249+
void Fargo::ShowConfig() {
250+
idfx::pushRegion("Fargo::ShowConfig");
245251
if(type==userdef) {
246-
idfx::cout << "Fargo: Enabled with user-defined velocity function" << std::endl;
252+
idfx::cout << "Fargo: ENABLED with user-defined velocity function." << std::endl;
253+
if(!fargoVelocityFunc) {
254+
IDEFIX_ERROR("No Fargo velocity function has been enabled.");
255+
}
247256
} else if(type==shearingbox) {
248-
idfx::cout << "Fargo: Enabled with shearing-box velocity function" << std::endl;
257+
idfx::cout << "Fargo: ENABLED with shearing-box velocity function." << std::endl;
249258
} else {
250259
IDEFIX_ERROR("Something went wrong during Fargo initialisation");
251260
}
@@ -267,7 +276,6 @@ void Fargo::EnrollVelocity(FargoVelocityFunc myFunc) {
267276
"to be set to userdef in .ini file");
268277
}
269278
this->fargoVelocityFunc = myFunc;
270-
idfx::cout << "Fargo: User-defined velocity function has been enrolled." << std::endl;
271279
}
272280

273281
// This function fetches Fargo velocity when required

‎src/dataBlock/fargo.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Fargo {
2626
void EnrollVelocity(FargoVelocityFunc);
2727
void StoreToScratch();
2828
void CheckMaxDisplacement();
29+
void ShowConfig();
2930

3031
private:
3132
friend class Hydro;

‎src/global.cpp‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ void popRegion() {
7777

7878
// Init the iostream with defined rank
7979
void IdefixOutStream::init(int rank) {
80-
std::stringstream sslogFileName;
81-
sslogFileName << "idefix." << rank << ".log";
82-
83-
std::string logFileName(sslogFileName.str());
84-
this->my_fstream.open(logFileName.c_str());
85-
8680
if(rank==0)
8781
this->toscreen=true;
8882
else
@@ -91,10 +85,14 @@ void IdefixOutStream::init(int rank) {
9185

9286

9387
// disable the log file
94-
void IdefixOutStream::disableLogFile() {
95-
my_fstream << "Log files have been disabled (e.g. using -nowrite)." << std::endl;
96-
my_fstream.close();
97-
this->logFileEnabled = false;
88+
void IdefixOutStream::enableLogFile() {
89+
std::stringstream sslogFileName;
90+
sslogFileName << "idefix." << idfx::prank << ".log";
91+
92+
std::string logFileName(sslogFileName.str());
93+
this->my_fstream.open(logFileName.c_str());
94+
95+
this->logFileEnabled = true;
9896
}
9997

10098
} // namespace idfx

‎src/global.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ IdefixArray1D<T> ConvertVectorToIdefixArray(std::vector<T> &inputVector) {
4646
class idfx::IdefixOutStream {
4747
public:
4848
void init(int);
49-
void disableLogFile();
49+
void enableLogFile();
5050
// for regular output of variables and stuff
5151
template<typename T> IdefixOutStream& operator<<(const T& something) {
5252
if(toscreen) std::cout << something;
@@ -63,7 +63,7 @@ class idfx::IdefixOutStream {
6363
private:
6464
std::ofstream my_fstream;
6565
bool toscreen;
66-
bool logFileEnabled{true}; //< whether streams are also written to a log file
66+
bool logFileEnabled{false}; //< whether streams are also written to a log file
6767
};
6868

6969
class idfx::IdefixErrStream {

‎src/gravity/gravity.cpp‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ void Gravity::Init(Input &input, DataBlock *datain) {
2222
std::string potentialString = input.Get<std::string>("Gravity","potential",i);
2323
if(potentialString.compare("userdef") == 0) {
2424
this->haveUserDefPotential = true;
25-
idfx::cout << "Gravity: Enabling user-defined gravitational potential" << std::endl;
2625
} else if (potentialString.compare("central") == 0) {
2726
this->haveCentralMassPotential = true;
2827
this->centralMass = input.GetOrSet<real>("Gravity","Mcentral",0, 1.0);
29-
idfx::cout << "Gravity: Enabling central mass gravitational potential with M="
30-
<< this->centralMass << std::endl;
3128
} else if (potentialString.compare("selfgravity") == 0) {
3229
this->haveSelfGravityPotential = true;
33-
idfx::cout << "Gravity: Enabling self Gravity" << std::endl;
3430
} else {
3531
IDEFIX_ERROR("Unknown type of gravitational potential in idefix.ini. ");
3632
}
@@ -42,7 +38,6 @@ void Gravity::Init(Input &input, DataBlock *datain) {
4238
std::string potentialString = input.Get<std::string>("Gravity","bodyForce",0);
4339
if(potentialString.compare("userdef") == 0) {
4440
this->haveBodyForce = true;
45-
idfx::cout << "Gravity:: Enabling user-defined body force" << std::endl;
4641
} else {
4742
IDEFIX_ERROR("Unknown type of body force in idefix.ini. "
4843
"Only userdef is implemented");
@@ -62,6 +57,31 @@ void Gravity::Init(Input &input, DataBlock *datain) {
6257
}
6358
}
6459

60+
void Gravity::ShowConfig() {
61+
if(data->haveGravity) {
62+
idfx::cout << "Gravity: ENABLED." << std::endl;
63+
if(haveUserDefPotential) {
64+
idfx::cout << "Gravity: User-defined gravitational potential ENABLED." << std::endl;
65+
if(!gravPotentialFunc) {
66+
IDEFIX_ERROR("No user-defined gravitational potential has been enrolled.");
67+
}
68+
}
69+
if(haveCentralMassPotential) {
70+
idfx::cout << "Gravity: central mass gravitational potential ENABLED with M="
71+
<< this->centralMass << std::endl;
72+
}
73+
if(haveSelfGravityPotential) {
74+
idfx::cout << "Gravity: self-gravity ENABLED." << std::endl;
75+
}
76+
if(haveBodyForce) {
77+
idfx::cout << "Gravity: user-defined body force ENABLED." << std::endl;
78+
if(!bodyForceFunc) {
79+
IDEFIX_ERROR("No user-defined body force has been enrolled.");
80+
}
81+
}
82+
83+
}
84+
}
6585
// This function compute the gravitational field, using both body force and potential
6686
void Gravity::ComputeGravity() {
6787
idfx::pushRegion("Gravity::ComputeGravity");
@@ -107,7 +127,6 @@ void Gravity::EnrollPotential(GravPotentialFunc myFunc) {
107127
"with the potential entry in [Gravity].");
108128
}
109129
this->gravPotentialFunc = myFunc;
110-
idfx::cout << "Gravity: User-defined gravitational potential has been enrolled" << std::endl;
111130
}
112131

113132
void Gravity::EnrollBodyForce(BodyForceFunc myFunc) {
@@ -117,7 +136,6 @@ void Gravity::EnrollBodyForce(BodyForceFunc myFunc) {
117136
"with the bodyForce entry in [Gravity].");
118137
}
119138
this->bodyForceFunc = myFunc;
120-
idfx::cout << "Gravity: User-defined body force function has been enrolled" << std::endl;
121139
}
122140

123141
// Fill the gravitational potential with zeros

‎src/gravity/gravity.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Gravity {
3535

3636
void AddCentralMassPotential(); ///< Àdd the potential due to a centrall mass
3737

38+
void ShowConfig(); ///< Show the gravity configuration
3839
bool havePotential{false}; ///< Whether a gravitational potential is present
3940
///< in which case, (at least) one of the following is true
4041
bool haveUserDefPotential{false}; ///< Whether a potential is defined by user

‎src/grid.cpp‎

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Grid::Grid() {
1818
Grid::Grid(Input &input) {
1919
idfx::pushRegion("Grid::Grid(Input)");
2020

21-
idfx::cout << "Grid: allocating Grid." << std::endl;
22-
2321
// Get grid size from input file, block [Grid]
2422
int npoints[3];
2523
for(int dir = 0 ; dir < 3 ; dir++) {
@@ -257,3 +255,64 @@ Grid& Grid::operator=(const Grid& grid) {
257255
return *this;
258256
}
259257
*/
258+
259+
void Grid::ShowConfig() {
260+
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
261+
idfx::cout << "Grid: ";
262+
std::string lboundString, rboundString;
263+
switch(lbound[dir]) {
264+
case outflow:
265+
lboundString="outflow";
266+
break;
267+
case reflective:
268+
lboundString="reflective";
269+
break;
270+
case periodic:
271+
lboundString="periodic";
272+
break;
273+
case internal:
274+
lboundString="internal";
275+
break;
276+
case shearingbox:
277+
lboundString="shearingbox";
278+
break;
279+
case axis:
280+
lboundString="axis";
281+
break;
282+
case userdef:
283+
lboundString="userdef";
284+
break;
285+
default:
286+
lboundString="unknown";
287+
}
288+
switch(rbound[dir]) {
289+
case outflow:
290+
rboundString="outflow";
291+
break;
292+
case reflective:
293+
rboundString="reflective";
294+
break;
295+
case periodic:
296+
rboundString="periodic";
297+
break;
298+
case internal:
299+
rboundString="internal";
300+
break;
301+
case shearingbox:
302+
rboundString="shearingbox";
303+
break;
304+
case axis:
305+
rboundString="axis";
306+
break;
307+
case userdef:
308+
rboundString="userdef";
309+
break;
310+
default:
311+
rboundString="unknown";
312+
}
313+
314+
idfx::cout << "Direction X" << (dir+1) << ": " << lboundString << "\t" << xbeg[dir]
315+
<< "...." << np_int[dir] << "...." << xend[dir] << "\t" << rboundString
316+
<< std::endl;
317+
}
318+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL