Skip to content

Commit

Permalink
LevelBld
Browse files Browse the repository at this point in the history
In Amr class, we need to get LevelBld* and use it to build AmrLevels.
Previously, Amr called a function `LevelBld* getLevelBld()` to get that.
The problem was that `getLevelBld` was not defined by amrex but it was being
called by amrex.  This caused issues in building amrex as a shared library
on Mac and Windows, because they do not support weak symbols.

In this PR, the constructors of Amr now take `LevelBld*` as an argument.
This is unfortunately a breaking change.  However, it's a compile time
failure and it's easy to fix.
  • Loading branch information
WeiqunZhang authored and ax3l committed Mar 16, 2021
1 parent 85ca90d commit 0b7e57f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Src/Amr/AMReX_Amr.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class Amr

public:
//! The constructor.
Amr ();
Amr (LevelBld* a_levelbld /* One must pass LevelBld* as an argument now*/);

Amr (const RealBox* rb, int max_level_in, const Vector<int>& n_cell_in, int coord);
Amr (const RealBox* rb, int max_level_in, const Vector<int>& n_cell_in, int coord,
LevelBld* a_levelbld /* One must pass LevelBld* as an argument now*/);

Amr (const Amr& rhs) = delete;
Amr& operator= (const Amr& rhs) = delete;
Expand Down
17 changes: 9 additions & 8 deletions Src/Amr/AMReX_Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,20 @@ Amr::derive (const std::string& name,
return amr_level[lev]->derive(name,time,ngrow);
}

Amr::Amr ()
Amr::Amr (LevelBld* a_levelbld)
:
AmrCore()
AmrCore(),
levelbld(a_levelbld)
{
Initialize();
InitAmr();
}

Amr::Amr (const RealBox* rb, int max_level_in, const Vector<int>& n_cell_in, int coord)
Amr::Amr (const RealBox* rb, int max_level_in, const Vector<int>& n_cell_in, int coord,
LevelBld* a_levelbld)
:
AmrCore(rb,max_level_in,n_cell_in,coord)
AmrCore(rb,max_level_in,n_cell_in,coord),
levelbld(a_levelbld)
{
Initialize();
InitAmr();
Expand All @@ -224,10 +227,8 @@ void
Amr::InitAmr ()
{
BL_PROFILE("Amr::InitAmr()");
//
// Determine physics class.
//
levelbld = getLevelBld();

AMREX_ALWAYS_ASSERT_WITH_MESSAGE(levelbld != nullptr, "ERROR: levelbld is nullptr");
//
// Global function that define state variables.
//
Expand Down
2 changes: 0 additions & 2 deletions Src/Amr/AMReX_LevelBld.H
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,4 @@ public:

}

extern amrex::LevelBld* getLevelBld () AMREX_ATTRIBUTE_WEAK;

#endif /*_LEVELBLD_H_*/
4 changes: 3 additions & 1 deletion Tutorials/Amr/Advection_AmrLevel/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

using namespace amrex;

amrex::LevelBld* getLevelBld ();

int
main (int argc,
char* argv[])
Expand Down Expand Up @@ -43,7 +45,7 @@ main (int argc,
}

{
Amr amr;
Amr amr(getLevelBld());

amr.init(strt_time,stop_time);

Expand Down
3 changes: 2 additions & 1 deletion Tutorials/EB/CNS/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace amrex;

amrex::LevelBld* getLevelBld ();
void initialize_EB2 (const Geometry& geom, const int required_level, const int max_level);

int main (int argc, char* argv[])
Expand Down Expand Up @@ -48,7 +49,7 @@ int main (int argc, char* argv[])
{
timer_init = amrex::second();

Amr amr;
Amr amr(getLevelBld());
AmrLevel::SetEBSupportLevel(EBSupport::full);
AmrLevel::SetEBMaxGrowCells(CNS::numGrow(),4,2);

Expand Down
4 changes: 3 additions & 1 deletion Tutorials/GPU/CNS/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

using namespace amrex;

amrex::LevelBld* getLevelBld ();

int main (int argc, char* argv[])
{
amrex::Initialize(argc,argv);
Expand Down Expand Up @@ -45,7 +47,7 @@ int main (int argc, char* argv[])
{
timer_init = amrex::second();

Amr amr;
Amr amr(getLevelBld());
amr.init(strt_time,stop_time);

timer_init = amrex::second() - timer_init;
Expand Down
3 changes: 2 additions & 1 deletion Tutorials/GPU/EBCNS/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace amrex;

amrex::LevelBld* getLevelBld ();
void initialize_EB2 (const Geometry& geom, const int required_level, const int max_level);

int main (int argc, char* argv[])
Expand Down Expand Up @@ -48,7 +49,7 @@ int main (int argc, char* argv[])
{
timer_init = amrex::second();

Amr amr;
Amr amr(getLevelBld());
AmrLevel::SetEBSupportLevel(EBSupport::full);
AmrLevel::SetEBMaxGrowCells(CNS::numGrow(),4,2);

Expand Down

0 comments on commit 0b7e57f

Please sign in to comment.