Skip to content

Commit

Permalink
STL example code (#126)
Browse files Browse the repository at this point in the history
As the EB2::Build code is updated, I made some changes to read and produce a plot of a geometry with an stl file. The inputs file also has been updated accordingly.
  • Loading branch information
ejyoo921 authored Jul 16, 2024
1 parent d47e05a commit d7a0662
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
19 changes: 13 additions & 6 deletions ExampleCodes/EB/STLtest/inputs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
prob_lo= 0 0 0
prob_hi= 220 35 60
ncells = 128 32 64
stl_file=airfoil.stl
max_grid_size=8
outside_point=250.0 250.0 250.0
eb2.geom_type = stl
eb2.stl_file = airfoil.stl

eb2.stl_scale = 1 # default is 1
eb2.stl_center = 0 0 0 # default is (0,0,0)
eb2.stl_reverse_normal = 0 # default is 0.

prob_lo = 0 0 0
prob_hi = 220 35 60
ncells = 128 32 64

max_grid_size = 8

37 changes: 12 additions & 25 deletions ExampleCodes/EB/STLtest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@ using namespace amrex;
int main (int argc, char* argv[])
{
amrex::Initialize(argc,argv);

{
int nghost = 1;
int max_grid_size=64;
MultiFab marker,apx,apy,apz;
std::string stl_fname;

Vector<Real> plo;
Vector<Real> phi;
Vector<int> ncells;
Vector<Real> pointoutside;
Vector<int> ncells;
Real dx[3];

ParmParse pp;
amrex::ParmParse pp;
pp.getarr("prob_lo",plo);
pp.getarr("prob_hi",phi);
pp.getarr("ncells",ncells);
pp.get("stl_file",stl_fname);
pp.getarr("outside_point",pointoutside);
pp.query("max_grid_size",max_grid_size);

RealBox real_box({AMREX_D_DECL(plo[0], plo[1], plo[2])},
Expand All @@ -53,26 +47,19 @@ int main (int argc, char* argv[])

Geometry geom(domain,real_box,CoordSys::cartesian,is_periodic);
DistributionMapping dm(ba);
BoxArray nodal_ba = amrex::convert(ba, IntVect::TheNodeVector());

marker.define(nodal_ba, dm, 1, nghost);

STLtools stlobj;

stlobj.read_ascii_stl_file(stl_fname);

Real plo_arr[]={plo[0],plo[1],plo[2]};
Real po_arr[]={pointoutside[0],pointoutside[1],pointoutside[2]};
int required_coarsening_level = 0; // typically the same as the max AMR level index
int max_coarsening_level = 0; // typically a huge number so MG coarsens as much as possible
// build a simple geometry using the "eb2." parameters in the inputs file
EB2::Build(geom, required_coarsening_level, max_coarsening_level);

stlobj.stl_to_markerfab(marker,geom,po_arr);

marker.FillBoundary(geom.periodicity());

//write plot file
std::string pltfile;
pltfile = "plt";
WriteSingleLevelPlotfile(pltfile, marker, {"marker"}, geom, 0.0, 0);
auto const& factory = makeEBFabFactory(geom, ba, dm, {1,1,1}, EBSupport::full);
MultiFab const& vfrc = factory->getVolFrac();
MultiFab object(ba,dm,1,0);
object.setVal(1.0);
MultiFab::Subtract(object, vfrc, 0,0,1,0);
amrex::WriteMLMF("plt", {&object}, {geom});
}

amrex::Finalize();
}

0 comments on commit d7a0662

Please sign in to comment.