Skip to content

Commit

Permalink
Brining in some updates from viscous2d
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrunnels committed Nov 8, 2024
1 parent 031d366 commit e0c2a47
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 90 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ jobs:
- name: make (2d)
continue-on-error: true
run: make
- name: unit tests (2d)
continue-on-error: true
run: ./bin/test-2d-coverage-g++
- name: configure (3d)
continue-on-error: true
run: ./configure --dim=3 --coverage
- name: make (3d)
continue-on-error: true
run: make
- name: unit tests (3d)
continue-on-error: true
run: ./bin/test-3d-coverage-g++
- name: regression tests with coverage (2d + 3d)
continue-on-error: true
run: scripts/runtests.py --serial --timeout=50 --permit-timeout --coverage
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ jobs:
run: ./configure --dim=2
- name: make
run: make
- name: unit tests
run: ./bin/test-2d-g++
- name: regression tests
run: scripts/runtests.py --serial --no-coverage --dim=2 --benchmark=github --timeout=200
test-3d-20-04:
Expand All @@ -67,8 +65,6 @@ jobs:
run: ./configure --dim=3
- name: make
run: make
- name: unit tests
run: ./bin/test-3d-g++
- name: regression tests
run: scripts/runtests.py --serial --no-coverage --dim=3 --benchmark=github --timeout=200
test-2d-22-04:
Expand All @@ -82,8 +78,6 @@ jobs:
run: ./configure --dim=2
- name: make
run: make
- name: unit tests
run: ./bin/test-2d-g++
- name: regression tests
run: scripts/runtests.py --serial --no-coverage --dim=2 --benchmark=github --timeout=200
test-3d-22-04:
Expand All @@ -97,8 +91,6 @@ jobs:
run: ./configure --dim=3
- name: make
run: make
- name: unit tests
run: ./bin/test-3d-g++
- name: regression tests
run: scripts/runtests.py --serial --no-coverage --dim=3 --benchmark=github --timeout=200
test-2d-22-04-clang:
Expand All @@ -114,7 +106,5 @@ jobs:
run: ./configure --dim=2 --comp=clang++
- name: make
run: make
- name: unit tests
run: ./bin/test-2d-clang++
- name: regression tests
run: scripts/runtests.py --serial --no-coverage --dim=2 --benchmark=github --comp=clang++ --timeout=200
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ IAMR
obj
cov
githubpages
ext/
*_BACKUP_*
*_BASE_*
*_LOCAL_*
Expand Down
30 changes: 19 additions & 11 deletions scripts/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test(testdir):


p = subprocess.check_output('git rev-parse --abbrev-ref HEAD'.split(),stderr=subprocess.PIPE)
record['branch'] = p.decode('ascii').replace('\n','')
record['branch'] = p.decode('utf-8').replace('\n','')

# In some cases we want to run the exe but can't check it.
# Skipping the check can be done by specifying the "check" input.
Expand Down Expand Up @@ -262,10 +262,18 @@ def test(testdir):
print(" ├ {}{} (skipped - no {} executable){}".format(color.boldyellow,desc,exestr,color.reset))
skips += 1
continue

# If we have enabled "skipping," exit noisily. The script will continue but will return a nonzero
# exit code.
if 'skip' in config[desc].keys():
if config[desc]['skip'].lower() in ['true','yes','1']:
print(" ├ {}{} (skip indicated in input){}".format(color.boldyellow,desc,color.reset))
skips += 1
continue

command += exestr + " "
command += "{}/input ".format(testdir)
command += cmdargs


# Run the actual test.
print(" ├ " + desc)
Expand All @@ -279,10 +287,10 @@ def test(testdir):
executionTime = time.time() - timeStarted
record['executionTime'] = str(executionTime)
fstdout = open("{}/{}_{}/stdout".format(testdir,testid,desc),"w")
fstdout.write(ansi_escape.sub('',p.stdout.decode('ascii')))
fstdout.write(ansi_escape.sub('',p.stdout.decode('utf-8')))
fstdout.close()
fstderr = open("{}/{}_{}/stderr".format(testdir,testid,desc),"w")
fstderr.write(ansi_escape.sub('',p.stderr.decode('ascii')))
fstderr.write(ansi_escape.sub('',p.stderr.decode('utf-8')))
fstderr.close()
print("[{}PASS{}]".format(color.boldgreen,color.reset), "({:.2f}s".format(executionTime),end="")
record['runStatus'] = 'PASS'
Expand All @@ -303,8 +311,8 @@ def test(testdir):
print("[{}FAIL{}]".format(color.red,color.reset))
record['runStatus'] = 'FAIL'
print(" │ {}CMD : {}{}".format(color.red,' '.join(e.cmd),color.reset))
for line in e.stdout.decode('ascii').split('\n'): print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
for line in e.stderr.decode('ascii').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
for line in e.stdout.decode('utf-8').split('\n'): print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
for line in e.stderr.decode('utf-8').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
fails += 1
continue
# If an error is thrown, we'll go here. We will print stdout and stderr to the screen, but
Expand All @@ -314,14 +322,14 @@ def test(testdir):
record['runStatus'] = 'TIMEOUT'
print(" │ {}CMD : {}{}".format(color.red,' '.join(e.cmd),color.reset))
try:
stdoutlines = e.stdout.decode('ascii').split('\n')
stdoutlines = e.stdout.decode('utf-8').split('\n')
if len(stdoutlines) < 10:
for line in stdoutlines: print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
else:
for line in stdoutlines[:5]: print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
for i in range(3): print(" │ {} {}{}".format(color.red,"............",color.reset))
for line in stdoutlines[-5:]: print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
#for line in e.stderr.decode('ascii').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
#for line in e.stderr.decode('utf-8').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
except Exception as e1:
for line in str(e1).split('\n'):
print(" │ {}EXCEPT: {}{}".format(color.red,line,color.reset))
Expand Down Expand Up @@ -360,8 +368,8 @@ def test(testdir):
print("[{}FAIL{}]".format(color.red,color.reset))
record['checkStatus'] = 'FAIL'
print(" │ {}CMD : {}{}".format(color.red,' '.join(e.cmd),color.reset))
for line in e.stdout.decode('ascii').split('\n'): print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
for line in e.stderr.decode('ascii').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
for line in e.stdout.decode('utf-8').split('\n'): print(" │ {}STDOUT: {}{}".format(color.red,line,color.reset))
for line in e.stderr.decode('utf-8').split('\n'): print(" │ {}STDERR: {}{}".format(color.red,line,color.reset))
fails += 1
continue
except DryRunException as e:
Expand Down Expand Up @@ -400,7 +408,7 @@ def test(testdir):
record['platform'] = metadata['Platform']
record['test-section'] = record['testdir'] + '/' + record['section']
p = subprocess.run('git show --no-patch --format=%ci {}'.format(record['git_commit_hash'].split('-')[0]).split(),capture_output=True)
record['git_commit_date'] = p.stdout.decode('ascii').replace('\n','')
record['git_commit_date'] = p.stdout.decode('utf-8').replace('\n','')
except Exception as e:
if not args.permissive:
print("Problem getting metadata, here it is:")
Expand Down
63 changes: 37 additions & 26 deletions scripts/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ def readHeader(path):


def validate(path,
outdir,
vars = [],
start = [0,0,0],
end = [1,1,1],
axis = 2,
intercept = 0,
generate_ref_data = False,
reference=None,
tolerance=1E-8,
coord = 'x',
filename_suffix=None):
outdir,
vars = [],
start = [0,0,0],
end = [1,1,1],
axis = 2,
intercept = 0,
generate_ref_data = False,
reference=None,
tolerance=1E-8,
coord = 'x',
tight_layout = True,
filename_suffix=None):

info = readHeader(path)

Expand Down Expand Up @@ -61,26 +62,27 @@ def validate(path,
print("Reference data generated, now exiting noisily so we don't accidentally pass the test")
exit(-1)

ref_df = pandas.read_csv(reference)

all_ok = True
if not type(tolerance)==list:
tolerance = [tolerance] * len(vars)
elif len(tolerance) != len(vars):
raise Exception("Wrong number of tolerance values")
for var, tol in zip(vars,tolerance):
varname = var
if filename_suffix: varname = var + "_" + filename_suffix

for i, (var, tol) in enumerate(zip(vars,tolerance)):
if isinstance(reference,list):
ref_df = pandas.read_csv(reference[i])
else:
ref_df = pandas.read_csv(reference)

len_x = info["geom_hi"][0]-info["geom_lo"][0]
len_y = info["geom_hi"][1]-info["geom_lo"][1]
data2d = slice2d.to_frb(width=len_x,height=len_y,resolution=(1000,1000*len_y/len_x))[var]
pylab.clf()
pylab.imshow(data2d,origin='lower',cmap='jet',
extent=[info["geom_lo"][0],info["geom_hi"][0],info["geom_lo"][1],info["geom_hi"][1]])
extent=[info["geom_lo"][0],info["geom_hi"][0],info["geom_lo"][1],info["geom_hi"][1]])
pylab.plot([start[0],end[0]],[start[1],end[1]],linestyle='-',color='white')
pylab.tight_layout()
pylab.savefig("{}/2d_{}.png".format(outdir,varname))
if tight_layout: pylab.tight_layout()
pylab.savefig("{}/2d_{}.png".format(outdir,var))

new_x,new_y,new_var = [numpy.array(_x) for _x in zip(*sorted(zip(new_df["x"],new_df["y"],new_df[var])))]
ref_x,ref_y,ref_var = [numpy.array(_x) for _x in zip(*sorted(zip(ref_df["x"],ref_df["y"],ref_df[var])))]
Expand All @@ -92,19 +94,28 @@ def validate(path,
elif coord == 'y':
new_coord = new_y
ref_coord = ref_y


#print(type(ref_coord),axis=None)
final_coord = sorted(numpy.concatenate((ref_coord, new_coord),axis=None))
ref_final_var = numpy.interp(final_coord, ref_coord, ref_var)
new_final_var = numpy.interp(final_coord, new_coord, new_var)

pylab.clf()
pylab.plot(ref_coord,ref_var,color='C0',label='ref')
pylab.plot(new_coord,new_var,color='C1',label='new',linestyle='--')
pylab.plot(final_coord,ref_final_var,color='C0',label='ref')
pylab.plot(final_coord,new_final_var,color='C1',label='new',linestyle='--')
pylab.xlabel(coord)
pylab.ylabel(var)
pylab.legend()
pylab.savefig(outdir+"/{}.png".format(varname))

err = numpy.sqrt(integrate(ref_coord, (numpy.interp(ref_coord, new_coord, new_var) - ref_var)**2))
mag = numpy.sqrt(integrate(ref_coord, (numpy.interp(ref_coord, new_coord, new_var) + ref_var)**2))
pylab.savefig(outdir+"/{}.png".format(var))
err = numpy.sqrt(integrate(final_coord, ( new_final_var - ref_final_var )**2))
mag = numpy.sqrt(integrate(final_coord, (abs(new_final_var) + abs(ref_final_var))**2))



relerr = err/mag

print("{} abs error [tolerance={}]".format(var,tol),err)
print("{} norm".format(var),mag)
print("{} rel error [tolerance={}]".format(var,tol),relerr)

if relerr > tol: all_ok = False
Expand Down
58 changes: 45 additions & 13 deletions src/BC/Constant.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@
// +--------------------------+-----------------------------------------------------------------+
// | BC Type | Description |
// +==========================+=================================================================+
// | :code:`Dirichlet` | Standard Dirichlet boundary condition |
// | :code:`Dirichlet` | Standard Dirichlet boundary condition |
// +--------------------------+ (https://en.wikipedia.org/wiki/Dirichlet_boundary_condition). |
// | :code:`dirichlet` | Fixes the value of the **function** at the boundary. |
// | :code:`dirichlet` | Fixes the value of the **function** at the boundary. |
// +--------------------------+ +
// | :code:`EXT_DIR` | |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`Neumann` | Standard Neumann boundary condition |
// +--------------------------+ (https://en.wikipedia.org/wiki/Neumann_boundary_condition) +
// | :code:`neumann` | |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`Periodic` | Standard periodic boundary condition. |
// | :code:`Periodic` | Standard periodic boundary condition. |
// +--------------------------+ (https://en.wikipedia.org/wiki/Periodic_boundary_conditions). |
// | :code:`periodic` | **Important**: Ensure that your geometry is specified to be |
// +--------------------------+ periodic using :code:`geometry.is_periodic`. For instance, if |
// | :code:`INT_DIR` | periodic in x, set to :code:`1 0 0` |
// | :code:`INT_DIR` | periodic in x, set to :code:`1 0 0` |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`REFLECT_ODD` | Effectively the same as dirichlet but with value fixed to 0 |
// +--------------------------+ +
// | :code:`reflect_odd` | |
// | :code:`reflect_odd` | |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`REFLECT_EVEN` | Effectively the same as neumann but with value fixed to 0 |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`BOGUS_BC` | Used for internal operations - not for general use |
// +--------------------------+-----------------------------------------------------------------+
// | :code:`FOEXTRAP` | These are BC types inherited from AMReX and not yet implemented |
// | :code:`FOEXTRAP` | These are BC types inherited from AMReX and not yet implemented |
// +--------------------------+ in Alamo. If you need BCs of this type, you will need to +
// | :code:`HOEXTRAP` | implement them yourself. |
// | :code:`HOEXTRAP` | implement them yourself. |
// +--------------------------+ +
// | :code:`Interior` | |
// | :code:`Interior` | |
// +--------------------------+ +
// | :code:`Inflow` | |
// +--------------------------+ +
// | :code:`Outflow` | |
// +--------------------------+ +
// | :code:`Symmetry` | |
// | :code:`Symmetry` | |
// +--------------------------+ +
// | :code:`SlipWall` | |
// | :code:`SlipWall` | |
// +--------------------------+ +
// | :code:`NoSlipWall` | |
// | :code:`NoSlipWall` | |
// +--------------------------+ +
// | :code:`interior` | |
// | :code:`interior` | |
// +--------------------------+ +
// | :code:`Marshak` | |
// +--------------------------+ +
// | :code:`SanchezPomraning` | |
// | :code:`SanchezPomraning` | |
// +--------------------------+ +
// | :code:`inflow` | |
// +--------------------------+-----------------------------------------------------------------+
Expand Down Expand Up @@ -118,6 +118,38 @@ public:
amrex::Vector<amrex::Real> _bc_hi_2,
amrex::Vector<amrex::Real> _bc_hi_3));

static Constant ZeroNeumann(int ncomp = 1)
{
Constant ret = Constant(ncomp);

for (int d = 0; d < m_nfaces; d++)
{
ret.m_bc_type[d].clear();
for (int n = 0; n < ncomp; n++)
{
ret.m_bc_type[d].push_back((int)amrex::LinOpBCType::Neumann);
ret.m_bc_val[d].push_back (0.0);;
}
}

return ret;
}

static Constant ZeroDirichlet(int ncomp = 1)
{
Constant ret = Constant(ncomp);

for (int d = 0; d < m_nfaces; d++)
for (int n = 0; n < ncomp; n++)
{
ret.m_bc_type[n][d] = (int)amrex::LinOpBCType::Dirichlet;
ret.m_bc_val [n][d] = 0.0;
}

return ret;
}


virtual ~Constant() {};

virtual void FillBoundary(amrex::BaseFab<Set::Scalar>& in, const amrex::Box& box,
Expand Down
Loading

0 comments on commit e0c2a47

Please sign in to comment.