Skip to content

Commit

Permalink
Maxwell solver example (#90)
Browse files Browse the repository at this point in the history
* WIP: adding test code for time-domain maxwell equations on tri and tet meshes

* WIP: tidied up volume kernel code and adding a profiling tip

* WIP: close to working. Added error detector

* WIP: updated setups to solve a mode problem

* WIP: adding a maxwell test

* WIP: adding maxwell to makefiles

* WIP: adjust to use global NX and NY

* WIP: added missing factor of 0.5 in surface flux

* WIP: fixed checksum for maxwell tet3d test

* Only output l2 norm if we're computing it

* Test maxwell solver after advection

* WIP: remove tips file

* WIP: reduced size of tet mesh in setup for maxwell

---------

Co-authored-by: Noel Chalmers <[email protected]>
  • Loading branch information
tcew and noelchalmers authored Nov 29, 2023
1 parent b27e086 commit 7190faa
Show file tree
Hide file tree
Showing 27 changed files with 2,533 additions and 7 deletions.
22 changes: 17 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ make solvers
Builds each solver executable.
make {solver}
Builds a solver executable,
solver can be acoustics/advection/bns/cns/elliptic/fokkerPlanck/gradient/ins.
solver can be acoustics/advection/bns/cns/elliptic/fokkerPlanck/gradient/ins/maxwell.
make clean
Cleans all solver executables, libraries, and object files.
make clean-{solver}
Expand All @@ -64,7 +64,7 @@ Can use "make verbose=true" for verbose output.
endef

ifeq (,$(filter solvers \
acoustics advection bns cns elliptic fokkerPlanck gradient ins \
acoustics advection bns cns elliptic fokkerPlanck gradient ins maxwell \
lib clean clean-kernels \
realclean info help test,$(MAKECMDGOALS)))
ifneq (,$(MAKECMDGOALS))
Expand All @@ -88,12 +88,12 @@ LIBP_CORE_LIBS=timeStepper linearSolver parAlmond mesh ogs linAlg core
SOLVER_DIR =${LIBP_DIR}/solvers

.PHONY: all solvers libp_libs \
acoustics advection bns lbs cns elliptic fokkerPlanck gradient ins \
acoustics advection bns lbs cns elliptic fokkerPlanck gradient ins maxwell\
clean clean-libs realclean help info

all: solvers

solvers: acoustics advection bns lbs cns elliptic fokkerPlanck gradient ins
solvers: acoustics advection bns lbs cns elliptic fokkerPlanck gradient ins maxwell

libp_libs:
ifneq (,${verbose})
Expand Down Expand Up @@ -174,10 +174,19 @@ else
@${MAKE} -C ${SOLVER_DIR}/$(@F) --no-print-directory
endif

maxwell: libp_libs
ifneq (,${verbose})
${MAKE} -C ${SOLVER_DIR}/$(@F) verbose=${verbose}
else
@printf "%b" "$(SOL_COLOR)Building $(@F) solver$(NO_COLOR)\n";
@${MAKE} -C ${SOLVER_DIR}/$(@F) --no-print-directory
endif


#cleanup
clean: clean-acoustics clean-advection clean-bns clean-lbs clean-cns \
clean-elliptic clean-fokkerPlanck clean-gradient clean-ins \
clean-libs
clean-maxwell clean-libs

clean-acoustics:
${MAKE} -C ${SOLVER_DIR}/acoustics clean
Expand Down Expand Up @@ -206,6 +215,9 @@ clean-gradient:
clean-ins:
${MAKE} -C ${SOLVER_DIR}/ins clean

clean-maxwell:
${MAKE} -C ${SOLVER_DIR}/maxwell clean

clean-libs:
${MAKE} -C ${LIBP_LIBS_DIR} clean

Expand Down
45 changes: 45 additions & 0 deletions solvers/maxwell/data/maxwellGaussian2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
The MIT License (MIT)
Copyright (c) 2017-2022 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/


// Boundary conditions
/* PEC 1 */
#define maxwellDirichletConditions2D(bc, t, x, y, nx, ny, HxM, HyM, EzM, HxB, HyB, EzB) \
{ \
if(bc==1){ \
*(HxB) = HxM; \
*(HyB) = HyM; \
*(EzB) = -EzM; \
} \
}

// Initial conditions
#define maxwellInitialConditions2D(t, x, y, Hx, Hy, Ez) \
{ \
*(Hx) = 0.0; \
*(Hy) = 0.0; \
*(Ez) = exp(-3*(x*x+y*y)); \
}
52 changes: 52 additions & 0 deletions solvers/maxwell/data/maxwellGaussian3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
The MIT License (MIT)
Copyright (c) 2017-2022 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/



// Boundary conditions
/* PEC=1 */
#define maxwellDirichletConditions3D(bc, t, x, y, z, nx, ny, nz, HxM, HyM, HzM, ExM, EyM, EzM, HxB, HyB, HzB, ExB, EyB, EzB) \
{ \
if(bc==1){ \
*(HxB) = HxM; \
*(HyB) = HyM; \
*(HzB) = HzM; \
*(ExB) = -ExM; \
*(EyB) = -EyM; \
*(EzB) = -EzM; \
} \
}

// Initial conditions
#define maxwellInitialConditions3D(t, x, y, z, Hx, Hy, Hz, Ex, Ey, Ez) \
{ \
*(Hx) = 0.0; \
*(Hy) = 0.0; \
*(Hz) = 0.0; \
*(Ex) = 0.0; \
*(Ey) = 0.0; \
*(Ez) = exp(-3*(x*x+y*y+z*z)); \
}
48 changes: 48 additions & 0 deletions solvers/maxwell/data/maxwellMode2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
The MIT License (MIT)
Copyright (c) 2017-2022 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/



// Boundary conditions
/* PEC=1 */
#define maxwellDirichletConditions2D(bc, t, x, y, nx, ny, HxM, HyM, EzM, HxB, HyB, EzB) \
{ \
if(bc==1){ \
*(HxB) = HxM; \
*(HyB) = HyM; \
*(EzB) = -EzM; \
} \
}

// Initial conditions
#define maxwellInitialConditions2D(t, x, y, Hx, Hy, Ez) \
{ \
dfloat n = 1., m = 2.; \
dfloat omega = M_PI*sqrt(n*n+m*m); \
*(Hx) = -M_PI*n*sin(m*M_PI*x)*cos(n*M_PI*y)*sin(omega*t)/omega; \
*(Hy) = M_PI*m*cos(m*M_PI*x)*sin(n*M_PI*y)*sin(omega*t)/omega; \
*(Ez) = sin(m*M_PI*x)*sin(n*M_PI*y)*cos(omega*t); \
}
54 changes: 54 additions & 0 deletions solvers/maxwell/data/maxwellMode3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
The MIT License (MIT)
Copyright (c) 2017-2022 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/



// Boundary conditions
/* PEC=1 */
#define maxwellDirichletConditions3D(bc, t, x, y, z, nx, ny, nz, HxM, HyM, HzM, ExM, EyM, EzM, HxB, HyB, HzB, ExB, EyB, EzB) \
{ \
if(bc==1){ \
*(HxB) = HxM; \
*(HyB) = HyM; \
*(HzB) = HzM; \
*(ExB) = -ExM; \
*(EyB) = -EyM; \
*(EzB) = -EzM; \
} \
}

// Initial conditions
#define maxwellInitialConditions3D(t, x, y, z, Hx, Hy, Hz, Ex, Ey, Ez) \
{ \
dfloat n = 1., m = 2.; \
const dfloat omega = M_PI*sqrt(n*n+m*m); \
*(Hx) = -M_PI*n*sin(m*M_PI*x)*cos(n*M_PI*y)*sin(omega*t)/omega; \
*(Hy) = M_PI*m*cos(m*M_PI*x)*sin(n*M_PI*y)*sin(omega*t)/omega; \
*(Hz) = 0; \
*(Ex) = 0; \
*(Ey) = 0; \
*(Ez) = sin(m*M_PI*x)*sin(n*M_PI*y)*cos(omega*t); \
}
Loading

0 comments on commit 7190faa

Please sign in to comment.