Commit 701d2f12 authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

[gridcreator] solve FS#267

This solves FS#267:
http://www.dumux.org/flyspray/index.php?do=details&task_id=267&project=3

The solution is to define the static variables inside static functions.
Then they will be destroyed on time, i.e., before MPI_Finalize is
called.

Reviewed by gruenich.



git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@15043 2fb0f335-1f38-0410-981e-8018bf24f1b0
parent 84e29be4
......@@ -337,7 +337,7 @@ public:
}
}
grid_ = factory.createGrid();
gridPtr() = factory.createGrid();
}
static void outputARTtoScreen()
......@@ -398,7 +398,16 @@ public:
*/
static Grid &grid()
{
return *grid_;
return *gridPtr();
}
/*!
* \brief Returns a reference to the shared pointer to the grid.
*/
static GridPointer &gridPtr()
{
static GridPointer grid;
return grid;
}
/*!
......@@ -407,7 +416,7 @@ public:
*/
static void loadBalance()
{
grid_->loadBalance();
gridPtr()->loadBalance();
}
static int vertexNumber()
......@@ -448,11 +457,8 @@ private:
static int edgeNumber_;
static int faceNumber_; //in 2D
static int elementNumber_; //in 3D
static GridPointer grid_;
};
template <class TypeTag>
typename Dumux::ArtGridCreator<TypeTag>::GridPointer ArtGridCreator<TypeTag>::grid_;
template <class TypeTag>
typename Dumux::ArtGridCreator<TypeTag>::VerticesVector ArtGridCreator<TypeTag>::vertices_;
template <class TypeTag>
......
......@@ -80,7 +80,7 @@ public:
cellRes[2] = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, int, Grid, NumberOfCellsZ);
}
cubeGrid_ = Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, cellRes);
gridPtr() = Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, cellRes);
}
/*!
......@@ -88,7 +88,7 @@ public:
*/
static Grid &grid()
{
return *cubeGrid_;
return *gridPtr();
}
/*!
......@@ -97,16 +97,19 @@ public:
*/
static void loadBalance()
{
cubeGrid_->loadBalance();
gridPtr()->loadBalance();
}
protected:
static GridPointer cubeGrid_;
/*!
* \brief Returns a reference to the shared pointer to the grid.
*/
static GridPointer &gridPtr()
{
static GridPointer cubeGrid;
return cubeGrid;
}
};
template <class TypeTag>
typename Dumux::CubeGridCreator<TypeTag>::GridPointer CubeGridCreator<TypeTag>::cubeGrid_;
}
#endif
......@@ -51,8 +51,8 @@ public:
*/
static void makeGrid(const std::string& dgfFileName)
{
gridPtr_ = GridPointer(dgfFileName.c_str(), Dune::MPIHelper::getCommunicator());
};
gridPtr() = GridPointer(dgfFileName.c_str(), Dune::MPIHelper::getCommunicator());
}
/*!
* \brief Load the grid from the dgf file given in the input file.
......@@ -68,16 +68,15 @@ public:
*/
static Grid &grid()
{
return *gridPtr_;
return *gridPtr();
}
/*!
* \brief Returns a reference to the grid pointer.
*
* This method is specific to the DgfGridCreator!
*/
static GridPointer &gridPtr()
{
static GridPointer gridPtr_;
return gridPtr_;
}
......@@ -86,16 +85,10 @@ public:
*/
static void loadBalance()
{
gridPtr_.loadBalance();
gridPtr().loadBalance();
}
private:
static GridPointer gridPtr_;
};
template <class TypeTag>
typename DgfGridCreator<TypeTag>::GridPointer DgfGridCreator<TypeTag>::gridPtr_;
} // namespace Dumux
#endif
......@@ -78,7 +78,7 @@ public:
cellRes[2] = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, int, Grid, NumberOfCellsZ);
}
simplexGrid_ = Dune::StructuredGridFactory<Grid>::createSimplexGrid(lowerLeft, upperRight, cellRes);
gridPtr() = Dune::StructuredGridFactory<Grid>::createSimplexGrid(lowerLeft, upperRight, cellRes);
}
/*!
......@@ -86,7 +86,7 @@ public:
*/
static Grid &grid()
{
return *simplexGrid_;
return *gridPtr();
}
/*!
......@@ -95,16 +95,19 @@ public:
*/
static void loadBalance()
{
simplexGrid_->loadBalance();
gridPtr()->loadBalance();
}
private:
static GridPointer simplexGrid_;
/*!
* \brief Returns a reference to the shared pointer to the grid.
*/
static GridPointer &gridPtr()
{
static GridPointer simplexGrid;
return simplexGrid;
}
};
template <class TypeTag>
typename SimplexGridCreator<TypeTag>::GridPointer SimplexGridCreator<TypeTag>::simplexGrid_;
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment