Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use the official Miniconda3 image as the base image
FROM continuumio/miniconda3

# Update package list and install necessary tools
RUN apt-get update && \
apt-get install -y gfortran libblas-dev liblapack-dev

# Set up an example Conda environment and install packages
RUN conda create -n myenv python=3.8 -y && \
echo "source activate myenv" > ~/.bashrc

# Set up the environment for running commands
SHELL ["/bin/bash", "-c", "source activate myenv"]

# Install packages within the Conda environment
RUN conda install -c conda-forge numpy scipy matplotlib petsc4py -y

# Set the environment variable
ENV EMCLAW_PATH /home/$USER/emclaw

# Clone the repository and navigate to the riemann directory
RUN git clone https://github.com/MaxwellGEMS/emclaw.git $EMCLAW_PATH && \
cd $EMCLAW_PATH/emclaw/riemann

# Activate the Conda environment and build/install the package
RUN source activate myenv && \
python setup.py build_ext -i && \
conda develop -n myenv $EMCLAW_PATH

# Set the default command to activate the Conda environment
CMD ["bash", "-i"]
114 changes: 62 additions & 52 deletions examples/maxwell_vc_1d/_convergence_sint.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Import necessary libraries
import sys
import os
import numpy as np

# Adding paths to custom modules
sys.path.append(os.path.realpath('../utils'))
sys.path.append(os.path.realpath('../'))


# Import custom modules
from utils.materials import Material1D
from utils.sources import Source1D

# Defining some constants and initialize material properties
x_lower = 0.
x_upper = 100.

Expand All @@ -19,35 +22,40 @@
material.setup()
material.delta_length = x_upper
material.delta_corner = x_lower
material.delta_omega = 12.0*np.pi/200.0
material.delta_omega = 12.0 * np.pi / 200.0

source = Source1D(material,shape='off',wavelength=2.0)
# Create a source object
source = Source1D(material, shape='off', wavelength=2.0)
source.setup()
source.offset = 10.0
source.pulse_width = 2.0

def grid_basic(x_lower,x_upper,mx,cfl):
dx = (x_upper-x_lower)/mx
dt = 0.9*cfl/(material.co*np.sqrt(1.0/(dx**2)))
# Define a function for grid calculations
def grid_basic(x_lower, x_upper, mx, cfl):
dx = (x_upper - x_lower) / mx
dt = 0.9 * cfl / (material.co * np.sqrt(1.0 / (dx ** 2)))
tf = 100.0

return dx,dt,tf
return dx, dt, tf

def dq_source(solver,state,dt):
# Define a function for source terms
def dq_source(solver, state, dt):
"""
Source terms for Maxwell's equations in one spatial dimension.
Assume aux values are averages on the cell i
"""

dq = -dt*state.q*state.aux[2:4,:]/state.aux[0:2,:]
dq = -dt * state.q * state.aux[2:4, :] / state.aux[0:2, :]

return dq

def em1D(mx=1024,num_frames=5,cfl=1.0,outdir='./_output',before_step=True,debug=False,chi3=0.0,chi2=0.0,nl=False,psi=True,em=True,homogeneous=True):
# Define the main simulation function
def em1D(mx=1024, num_frames=5, cfl=1.0, outdir='./_output', before_step=True, debug=False, chi3=0.0, chi2=0.0, nl=False, psi=True, em=True, homogeneous=True):

import clawpack.petclaw as pyclaw
import petsc4py.PETSc as MPI

# Set material properties if not homogeneous
if not homogeneous:
if nl:
material.chi3_e = chi3
Expand All @@ -56,46 +64,48 @@ def em1D(mx=1024,num_frames=5,cfl=1.0,outdir='./_output',before_step=True,debug=
material.chi3_m = chi3
material.chi2_m = chi2

if MPI.COMM_WORLD.rank==0:
if MPI.COMM_WORLD.rank == 0:
material._outdir = outdir
source._outdir = outdir
source._outdir = outdir
material._dump_to_latex()
source._dump_to_latex()

num_eqn = 2
num_eqn = 2
num_waves = 2
num_aux = 4
num_aux = 4

# grid pre calculations and domain setup
dx,dt,tf = grid_basic(x_lower,x_upper,mx,cfl)
x = pyclaw.Dimension('x',x_lower,x_upper,mx)
# Grid pre-calculations and domain setup
dx, dt, tf = grid_basic(x_lower, x_upper, mx, cfl)
x = pyclaw.Dimension('x', x_lower, x_upper, mx)
domain = pyclaw.Domain([x])

# Solver settings
solver=pyclaw.SharpClawSolver1D()
solver.num_waves = num_waves
solver.num_eqn = num_eqn
# Solver settings
solver = pyclaw.SharpClawSolver1D()
solver.num_waves = num_waves
solver.num_eqn = num_eqn
solver.weno_order = 5

solver.dt_variable = True
solver.dt_initial = dt/2.0
solver.dt_max = dt
solver.max_steps = int(2*tf/dt)
solver.dt_initial = dt / 2.0
solver.dt_max = dt
solver.max_steps = int(2 * tf / dt)

# Set the source
# Set the source
if not psi:
print 'using dq_src'
# Python 2-style print statement
# print 'using dq_src'
print('using dq_src')
solver.dq_src = dq_source

# Import Riemann and Tfluct solvers
# Import Riemann and Tfluct solvers
if homogeneous:
import maxwell_1d_rp
else:
import maxwell_1d_nl_rp as maxwell_1d_rp

solver.tfluct_solver = False
solver.fwave = True
solver.fwave = True

solver.rp = maxwell_1d_rp

if solver.tfluct_solver:
Expand All @@ -105,11 +115,11 @@ def em1D(mx=1024,num_frames=5,cfl=1.0,outdir='./_output',before_step=True,debug=
import maxwell_1d_nl_tfluct as maxwell_1d_tfluct

solver.tfluct = maxwell_1d_tfluct
solver.cfl_max = cfl+0.05

solver.cfl_max = cfl + 0.05
solver.cfl_desired = cfl

# boundary conditions
# Boundary conditions
solver.bc_lower[0] = pyclaw.BC.wall
solver.bc_upper[0] = pyclaw.BC.wall

Expand All @@ -118,47 +128,47 @@ def em1D(mx=1024,num_frames=5,cfl=1.0,outdir='./_output',before_step=True,debug=

solver.reflect_index = [0]

# before step configure
# Before step configure
if before_step:
solver.call_before_step_each_stage = True
solver.before_step = material.update_aux

# state setup
state = pyclaw.State(domain,num_eqn,num_aux)
# State setup
state = pyclaw.State(domain, num_eqn, num_aux)

state.problem_data['chi2_e'] = material.chi2_e
state.problem_data['chi3_e'] = material.chi3_e
state.problem_data['chi2_m'] = material.chi2_m
state.problem_data['chi3_m'] = material.chi3_m
state.problem_data['eo'] = material.eo
state.problem_data['mo'] = material.mo
state.problem_data['co'] = material.co
state.problem_data['zo'] = material.zo
state.problem_data['dx'] = state.grid.x.delta
state.problem_data['nl'] = nl
state.problem_data['psi'] = psi

source._dx = state.grid.x.delta
state.problem_data['eo'] = material.eo
state.problem_data['mo'] = material.mo
state.problem_data['co'] = material.co
state.problem_data['zo'] = material.zo
state.problem_data['dx'] = state.grid.x.delta
state.problem_data['nl'] = nl
state.problem_data['psi'] = psi

source._dx = state.grid.x.delta
material._dx = state.grid.x.delta

# array initialization
# Array initialization
source.init(state)
material.init(state)

state.q = state.q*state.aux[0:2,:]
# controller
state.q = state.q * state.aux[0:2, :]

# Controller
claw = pyclaw.Controller()
claw.tfinal = tf
claw.num_output_times = num_frames
claw.solver = solver
claw.solution = pyclaw.Solution(state,domain)
claw.solution = pyclaw.Solution(state, domain)
claw.outdir = outdir
claw.write_aux_always = True

return claw

if __name__=="__main__":
if __name__ == "__main__":
import sys
from clawpack.pyclaw.util import run_app_from_main
output = run_app_from_main(em1D)
output = run_app_from_main(em1D)
Loading