Skip to content

Commit

Permalink
Merge pull request #46 from PaulSt/normal_orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSt authored Jun 10, 2022
2 parents f5c0c0e + 3fb01f5 commit fd027d9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 96 deletions.
85 changes: 48 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,57 @@ jobs:
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3

macos:
runs-on: macos-latest
steps:
- name: install pkgs
run: |
brew install openblas
brew install lapack
echo "LDFLAGS=-L/usr/local/opt/openblas/lib -L/usr/local/opt/lapack/lib" >> $GITHUB_ENV
echo "CPPFLAGS=-I/usr/local/opt/openblas/include -I/usr/local/opt/lapack/include" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/usr/local/opt/openblas/lib/pkgconfig:/usr/local/opt/lapack/lib/pkgconfig" >> $GITHUB_ENV
- name: install ngsolve
run: |
wget https://www.asc.tuwien.ac.at/~mhochsteger/ngsolve/macos/NGSolve_nightly.dmg
hdiutil attach NGSolve_nightly.dmg
cp -R /Volumes/NGSolve/* /Applications
- name: set path
run: |
echo "PYTHONPATH=$PYTHONPATH:/Applications/Netgen.app/Contents/Resources/lib/python3.8/site-packages:." >> $GITHUB_ENV
echo "NETGENDIR=/Applications/Netgen.app/Contents/MacOS" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$NETGENDIR" >> $GITHUB_ENV
echo "DYLD_FRAMEWORK_PATH=$DYLD_FRAMEWORK_PATH:$NETGENDIR/../Frameworks" >> $GITHUB_ENV
echo "$NETGENDIR" >> $GITHUB_PATH
- uses: actions/checkout@v2
with:
submodules: 'True'
path: 'NGSTrefftz'
- name: cmake NGSTrefftz
run: cmake -B $GITHUB_WORKSPACE/NGSTrefftz/make -S $GITHUB_WORKSPACE/NGSTrefftz/src/
- name: compile NGSTrefftz
run: make -C $GITHUB_WORKSPACE/NGSTrefftz/make
#- name: test NGSTrefftz
#run: env CTEST_OUTPUT_ON_FAILURE=1 make -C $GITHUB_WORKSPACE/NGSTrefftz/make test
#- name: install NGSTrefftz
#run: sudo make -C $GITHUB_WORKSPACE/NGSTrefftz/make install
### missing externalprojects...?
#macos:
#runs-on: macos-latest
#steps:
#- name: install pkgs
#run: |
#brew install [email protected]
#brew install openblas
#brew install lapack
#brew install zlib-ng
#brew install zlib bzip2
#echo "LDFLAGS=-L/usr/local/opt/openblas/lib -L/usr/local/opt/lapack/lib" >> $GITHUB_ENV
#echo "CPPFLAGS=-I/usr/local/opt/openblas/include -I/usr/local/opt/lapack/include" >> $GITHUB_ENV
#echo "PKG_CONFIG_PATH=/usr/local/opt/openblas/lib/pkgconfig:/usr/local/opt/lapack/lib/pkgconfig" >> $GITHUB_ENV
#- name: install ngsolve
#run: |
#wget https://www.asc.tuwien.ac.at/~mhochsteger/ngsolve/macos/NGSolve_nightly.dmg
#hdiutil attach NGSolve_nightly.dmg
#cp -R /Volumes/NGSolve/* /Applications
#- name: set path
#run: |
#echo "PYTHONPATH=${{ env.PYTHONPATH }}:/Applications/Netgen.app/Contents/Resources/lib/python3.8/site-packages:." >> $GITHUB_ENV
#echo "NETGENDIR=/Applications/Netgen.app/Contents/MacOS" >> $GITHUB_ENV
#- name: set path II
#run: |
#echo "DYLD_LIBRARY_PATH=${{ env.DYLD_LIBRARY_PATH }}:${{ env.NETGENDIR }}" >> $GITHUB_ENV
#echo "DYLD_FRAMEWORK_PATH=${{ env.DYLD_FRAMEWORK_PATH }}:${{ env.NETGENDIR }}/../Frameworks" >> $GITHUB_ENV
#echo "${{ env.NETGENDIR }}" >> $GITHUB_PATH
##- uses: actions/setup-python@v3
##with:
##python-version: '3.8'
##- name: ngsolve found?
##run: python3 -c "import ngsolve"
#- uses: actions/checkout@v2
#with:
#submodules: 'True'
#path: 'NGSTrefftz'
#- name: cmake NGSTrefftz
#run: cmake -B $GITHUB_WORKSPACE/NGSTrefftz/make -S $GITHUB_WORKSPACE/NGSTrefftz/src/
#- name: compile NGSTrefftz
#run: make -C $GITHUB_WORKSPACE/NGSTrefftz/make
##- name: test NGSTrefftz
##run: env CTEST_OUTPUT_ON_FAILURE=1 make -C $GITHUB_WORKSPACE/NGSTrefftz/make test
##- name: install NGSTrefftz
##run: sudo make -C $GITHUB_WORKSPACE/NGSTrefftz/make install
#- name: Debugging with tmate
#if: ${{ failure() }}
#uses: mxschmitt/action-tmate@v3

pypi-test:
needs: [ubuntu,macos]
needs: [ubuntu]
runs-on: ubuntu-latest
steps:
- name: install pkgs
Expand Down Expand Up @@ -129,7 +140,7 @@ jobs:
password: ${{ secrets.PYPI_API_TOKEN }}

docker:
needs: [ubuntu,macos]
needs: [ubuntu]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
Expand Down Expand Up @@ -164,7 +175,7 @@ jobs:
#labels: ${{ steps.meta.outputs.labels }}

docs:
needs: [ubuntu,macos]
needs: [ubuntu]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NGSTrefftz
**an add-on to NGSolve for Trefftz methods**

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/PaulSt/NGSTrefftz/HEAD?filepath=doc%2Fnotebooks%2Findex.ipynb)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/PaulSt/NGSTrefftz/HEAD?filepath=docs%2Fnotebooks%2Findex.ipynb)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/paulstdocker/ngstrefftz?label=docker&logo=docker&sort=semver)](https://hub.docker.com/r/paulstdocker/ngstrefftz)
[![PyPI](https://img.shields.io/pypi/v/ngstrefftz?color=blue&logo=pypi)](https://pypi.org/project/ngstrefftz/)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/PaulSt/NGSTrefftz/build?logo=github)](https://github.com/PaulSt/NGSTrefftz/actions)
Expand All @@ -13,7 +13,7 @@ NGSTrefftz provides a framework to implement Trefftz finite element spaces for [
## Try it out!
You can try out some jupyter notebooks:
* Launch the Binder here:
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/PaulSt/NGSTrefftz/HEAD?filepath=doc%2Fnotebooks%2Findex.ipynb)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/PaulSt/NGSTrefftz/HEAD?filepath=docs%2Fnotebooks%2Findex.ipynb)
* Or run the docker locally (you need to have docker installed):

```bash
Expand Down
1 change: 0 additions & 1 deletion src/planewavefe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace ngfem
{

template <int D> class PlaneWaveElement : public ScalarMappedElement<D>
{
private:
Expand Down
9 changes: 5 additions & 4 deletions src/specialcoefficientfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <h1lofe.hpp>
#include <regex>
#include <multigrid.hpp>
using namespace ngcomp;

namespace ngfem
{
using namespace ngcomp;

double ClipCoefficientFunction ::Evaluate (
const BaseMappedIntegrationPoint &ip) const
Expand Down Expand Up @@ -206,12 +206,13 @@ namespace ngfem

}

typedef CoefficientFunction CF;
typedef shared_ptr<CoefficientFunction> spCF;

#ifdef NGS_PYTHON
void ExportSpecialCoefficientFunction (py::module m)
{
using namespace ngcomp;
typedef CoefficientFunction CF;
typedef shared_ptr<CoefficientFunction> spCF;

m.def (
"ClipCoefficientFunction",
[] (spCF cf_x, int aclipdim,
Expand Down
2 changes: 1 addition & 1 deletion src/specialcoefficientfunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <h1lofe.hpp>
#include <regex>

using namespace ngcomp;
namespace ngfem
{
using namespace ngcomp;

class ClipCoefficientFunction : public CoefficientFunction
{
Expand Down
60 changes: 11 additions & 49 deletions src/twavetents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace ngcomp
// int nthreads = (task_manager) ? task_manager->GetNumThreads() : 1;
LocalHeap lh (1000 * 1000 * 1000, "trefftz tents", 1);

const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
SIMD_IntegrationRule sir (eltyp, order * 2);
// const int ndomains = ma->GetNDomains();
double max_wavespeed = wavespeed[0];
Expand Down Expand Up @@ -142,10 +140,7 @@ namespace ngcomp
static Timer tint3 ("tent top bilinearform");

HeapReset hr (slh);
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
// double wavespeed = tel.GetWavespeed();
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
ScalarFE<eltyp, 1> faceint; // linear basis for tent faces

Expand Down Expand Up @@ -275,7 +270,6 @@ namespace ngcomp
SliceMatrix<> elmat, SliceVector<> elvec)
{
HeapReset hr (slh);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;

// get vertices of tent face
Expand Down Expand Up @@ -379,24 +373,10 @@ namespace ngcomp
SIMD_IntegrationRule &sir, LocalHeap &slh,
SliceMatrix<> elmat, SliceVector<> elvec)
{
int nsimd = SIMD<double>::Size ();
HeapReset hr (slh);
size_t snip = sir.Size () * nsimd;

Array<int> fnums;
Array<int> orient;
switch (D)
{
case 1:
fnums.Append (fnr);
orient.Append (1);
break;
case 2:
ma->GetElEdges (elnums[0], fnums, orient);
break;
case 3:
ma->GetElFaces (elnums[0], fnums, orient);
break;
}
// Array<int> fnums;

// get vertices of tent face
// Mat<D+1> vert = TentFaceVerts(tent, surfel, 0);
Expand All @@ -417,13 +397,13 @@ namespace ngcomp
}

// build normal vector
Vec<D + 1> n;
n = -orient[fnums.Pos (fnr)] * TentFaceNormal (vert, 0);
if (D == 1) // D=1 special case
{
n[0] = sgn_nozero<int> (tent->vertex - tent->nbv[0]);
n[D] = 0; // time-like faces only
}
IntegrationRule ir (eltyp, order * 2);
MappedIntegrationRule<D, D> mir_fix (ir, ma->GetTrafo (elnums[0], slh),
slh);
auto fnums = ma->GetElFacets (elnums[0]);
mir_fix.ComputeNormalsAndMeasure (eltyp, fnums.Pos (fnr));
auto n = mir_fix[0].GetNV ();

// build mapping to physical boundary simplex
Mat<D + 1, D> map;
for (int i = 0; i < D; i++)
Expand Down Expand Up @@ -497,9 +477,6 @@ namespace ngcomp
SliceMatrix<SIMD<double>> simddshapes)
{
HeapReset hr (slh);
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
ScalarFE<eltyp, 1> faceint; // linear basis for tent faces

Expand Down Expand Up @@ -678,10 +655,7 @@ namespace ngcomp
double time)
{
LocalHeap lh (1000 * 1000 * 1000, "make wavefront", 1);
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
SIMD_IntegrationRule sir (eltyp, order * 2);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
Matrix<> wf (ma->GetNE (), snip * cf->Dimension ());
for (size_t elnr = 0; elnr < ma->GetNE (); elnr++)
Expand Down Expand Up @@ -713,10 +687,7 @@ namespace ngcomp
{
LocalHeap lh (1000 * 1000 * 1000, "error", 1);
double error = 0;
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
SIMD_IntegrationRule sir (eltyp, order * 2);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
for (size_t elnr = 0; elnr < ma->GetNE (); elnr++)
{
Expand Down Expand Up @@ -752,10 +723,7 @@ namespace ngcomp
{
LocalHeap lh (1000 * 1000 * 1000, "l2error", 1);
double l2error = 0;
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
SIMD_IntegrationRule sir (eltyp, order * 2);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
for (size_t elnr = 0; elnr < ma->GetNE (); elnr++)
{
Expand All @@ -776,10 +744,7 @@ namespace ngcomp
{
double energy = 0;
LocalHeap lh (1000 * 1000 * 1000, "energy", 1);
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
SIMD_IntegrationRule sir (eltyp, order * 2);
int nsimd = SIMD<double>::Size ();
size_t snip = sir.Size () * nsimd;
for (size_t elnr = 0; elnr < ma->GetNE (); elnr++)
{
Expand Down Expand Up @@ -923,9 +888,6 @@ namespace ngcomp
LocalHeap lh (1000 * 1000 * 1000, "QT tents", 1);

shared_ptr<MeshAccess> ma = this->ma;
const ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);
const int nsimd = SIMD<double>::Size ();
SIMD_IntegrationRule sir (eltyp, this->order * 2);

QTWaveBasis<D> basis;
Expand Down Expand Up @@ -997,8 +959,8 @@ namespace ngcomp
// if(tent->nbtime[elnr]==(part<0?tent->tbot:tent->ttop))
// continue;
HeapReset hr (slh);
const ELEMENT_TYPE eltyp = (D == 2) ? ET_TET : ET_TRIG;
SIMD_IntegrationRule vsir (eltyp, this->order * 2);
const ELEMENT_TYPE vol_eltyp = (D == 2) ? ET_TET : ET_TRIG;
SIMD_IntegrationRule vsir (vol_eltyp, this->order * 2);

Vec<D + 1> shift;
shift.Range (0, D) = ma->GetPoint<D> (tent->vertex);
Expand Down
10 changes: 8 additions & 2 deletions src/twavetents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace ngcomp
int fosystem = 0;
double timeshift = 0;
int nbasis;
const int nsimd = SIMD<double>::Size ();
static constexpr ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);

template <typename TFUNC>
void
Expand Down Expand Up @@ -104,8 +107,8 @@ namespace ngcomp
for (Ngs_Element el : ma->Elements (VOL))
{
ElementId ei = ElementId (el);
ELEMENT_TYPE eltype = ma->GetElType (ei);
IntegrationRule ir (eltype, 0);
// ELEMENT_TYPE eltype = ma->GetElType(ei);
IntegrationRule ir (eltyp, 0);
ElementTransformation &trafo = ma->GetTrafo (ei, lh);
MappedIntegrationPoint<D, D> mip (ir[0], trafo);
wavespeed[el.Nr ()] = awavespeedcf->Evaluate (mip);
Expand Down Expand Up @@ -156,6 +159,9 @@ namespace ngcomp
Matrix<shared_ptr<CoefficientFunction>> GGder;
Matrix<shared_ptr<CoefficientFunction>> BBder;
double TentXdiam (const Tent *tent);
const int nsimd = SIMD<double>::Size ();
static constexpr ELEMENT_TYPE eltyp
= (D == 3) ? ET_TET : ((D == 2) ? ET_TRIG : ET_SEGM);

using TWaveTents<D>::Solve;
using TWaveTents<D>::TentFaceVerts;
Expand Down
7 changes: 7 additions & 0 deletions test/tents.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def TestQTrefftz(order, initmesh, t_step,qtrefftz=1):
...e-06
Compare to standard Trefftz basis
>>> for h in [4,8,16,32]:
... initmesh = Mesh(SegMesh(h,0,math.pi))
... TestQTrefftz(order,initmesh,t_step,None) # doctest:+ELLIPSIS
0.2...
0.05...
0.01...
0.003...
>>> initmesh = Mesh(unit_square.GenerateMesh(maxh = 0.5))
>>> for h in range(4):
... TestQTrefftz(order,initmesh,t_step,None) # doctest:+ELLIPSIS
Expand Down

0 comments on commit fd027d9

Please sign in to comment.