Skip to content
Snippets Groups Projects
Commit 2b64e07c authored by Matteo Cicuttin's avatar Matteo Cicuttin
Browse files

Better organized examples.

parent 365fc147
No related branches found
No related tags found
No related merge requests found
Showing
with 356 additions and 48 deletions
...@@ -144,7 +144,7 @@ None. ...@@ -144,7 +144,7 @@ None.
### Debug and validation ### Debug and validation
The solver has some facilities to allow validation and comparison with analytical solutions. Those facilities are accessed via the `debug` table. In the current implementation the `debug` table is undefined by default, so it must be initialized explicitly in the configuration with a statement `debug = {}`. Possible members of the `debug` table are: The solver has some facilities to allow validation and comparison with analytical solutions. Those facilities are accessed via the `debug` table. In the current implementation the `debug` table is undefined by default, so it must be initialized explicitly in the configuration with a statement `debug = {}`. Possible members of the `debug` table are:
- `analytical_solution(tag, x, y, z, t)`: define the analytical solution of the problem. If defined, the numerical solution is compared with the analytical solution at each timestep in the whole domain. The function has to return 6 values, namely `Ex`, `Ey`, `Ez`, `Hx`, `Hy` and `Hz`. - `analytical_solution`: a function `f(tag, x, y, z, t)` defining the analytical solution of the problem. If defined, it can be used to compare the numerical solution with the analytical solution during the timestepping. The function has to return 6 values, namely `Ex`, `Ey`, `Ez`, `Hx`, `Hy` and `Hz`.
- `dump_cell_ranks` (bool): if true, and if the solver has MPI support compiled in, add to the Silo output a variable named `cell_ranks` showing the cell-to-rank mapping. - `dump_cell_ranks` (bool): if true, and if the solver has MPI support compiled in, add to the Silo output a variable named `cell_ranks` showing the cell-to-rank mapping.
### Postprocessing ### Postprocessing
......
...@@ -29,8 +29,6 @@ std::string quadrature_name(int); ...@@ -29,8 +29,6 @@ std::string quadrature_name(int);
std::string basis_func_name(int); std::string basis_func_name(int);
std::string basis_grad_name(int); std::string basis_grad_name(int);
using face_key = std::array<size_t, 3>;
enum class face_type : int enum class face_type : int
{ {
NONE = 0, NONE = 0,
......
...@@ -435,4 +435,42 @@ void decompress_bndsrc(const solver_state_gpu& state, const field_gpu& csrcs, ...@@ -435,4 +435,42 @@ void decompress_bndsrc(const solver_state_gpu& state, const field_gpu& csrcs,
#endif /* ENABLE_GPU_SOLVER */ #endif /* ENABLE_GPU_SOLVER */
struct field_values {
double Ex;
double Ey;
double Ez;
double Hx;
double Hy;
double Hz;
field_values();
field_values(const vec3d&, const vec3d&);
field_values(double, double, double, double, double, double);
field_values& operator+=(const field_values&);
field_values operator+(const field_values&) const;
field_values& operator-=(const field_values&);
field_values operator-(const field_values&) const;
field_values& operator*=(const field_values&);
field_values operator*(const field_values&) const;
field_values& operator/=(const field_values&);
field_values operator/(const field_values&) const;
field_values& operator*=(double);
field_values operator*(double) const;
field_values& operator/=(double);
field_values operator/(double) const;
};
field_values operator*(double, const field_values&);
std::ostream& operator<<(std::ostream&, const field_values&);
field_values sqrt(const field_values&);
double hsum(const field_values& m);
} // namespace maxwell } // namespace maxwell
#pragma once
#include "maxwell/maxwell_interface.h"
namespace maxwell {
field_values eval_field(const field&, size_t, size_t, const vecxd&);
field_values compute_error(const model&, const solver_state&, const parameter_loader&);
field_values compute_energy(const model&, const solver_state&, const parameter_loader&);
} // namespace maxwell
\ No newline at end of file
l = 0.02;
d = 0.001;
t = 0.0003;
sh = 2*t+d;
SetFactory("OpenCASCADE");
Mesh.Algorithm3D = 10;
Box(1) = {-l/2, -l/2, -sh/2, l, l, t};
Box(2) = {-l/2, -l/2, -sh/2 + t, l, l, d};
Box(3) = {-l/2, -l/2, -sh/2 + t+d, l, l, t};
Sphere(4) = {0, 0, 0, l, -Pi/2, Pi/2, 2*Pi};
Coherence;
MeshSize{ PointsOf{ Volume{1,2,3}; } } = 0.0008;
l = 0.02;
d = 0.001;
epsilon = 10 * 8.85e-12;
t = 1e-13;
J = 1;
A = l*l;
I = J*A;
C = epsilon*A/d;
Q = I*t;
V = Q/C
E = V/d
Q*d/(epsilon*l*A)
R = 0.01; // disk radius
d = 0.001; // dielectric thickness
t = 0.0003; // disk thickness
SetFactory("OpenCASCADE");
Mesh.Algorithm3D = 10;
Cylinder(1) = {0, 0, d/2, 0, 0, t, R};
Cylinder(2) = {0, 0, -d/2, 0, 0, d, R};
Cylinder(3) = {0, 0, -d/2-t, 0, 0, t, R};
Sphere(4) = {0, 0, 0, 2*R, -Pi/2, Pi/2, 2*Pi};
Coherence;
MeshSize{ PointsOf{ Volume{2}; } } = 0.0003;
sim.name = "capacitor" -- simulation name sim.name = "capacitor" -- simulation name
sim.dt = 1e-13 -- timestep size sim.dt = 1e-14 -- timestep size
sim.timesteps = 100000 -- num of iterations sim.timesteps = 301 -- num of iterations
sim.gmsh_model = "capacitor.geo" -- gmsh model filename sim.gmsh_model = "capacitor.geo" -- gmsh model filename
sim.use_gpu = 0 -- 0: cpu, 1: gpu sim.use_gpu = 0 -- 0: cpu, 1: gpu
sim.approx_order = 1 -- approximation order sim.approx_order = 1 -- approximation order
sim.time_integrator = "leapfrog" sim.time_integrator = "leapfrog" -- time integration method
postpro.silo_output_rate = 10 -- rate at which to write silo files postpro.silo_output_rate = 10 -- rate at which to write silo files
postpro.cycle_print_rate = 10 -- console print rate postpro.cycle_print_rate = 10 -- console print rate
local diel_epsr = 10 -- Permittivity of the capacitor dielectric
-- Aluminum plates material parameters
local alu = {1, 3} local alu = {1, 3}
for i,v in ipairs(alu) do for i,v in ipairs(alu) do
materials[v] = {} materials[v] = {}
...@@ -16,14 +19,16 @@ for i,v in ipairs(alu) do ...@@ -16,14 +19,16 @@ for i,v in ipairs(alu) do
materials[v].sigma = 3.69e7 materials[v].sigma = 3.69e7
end end
-- Dielectric parameters
local diel = { 2 } local diel = { 2 }
for i,v in ipairs(diel) do for i,v in ipairs(diel) do
materials[v] = {} materials[v] = {}
materials[v].epsilon = 10 materials[v].epsilon = diel_epsr
materials[v].mu = 1 materials[v].mu = 1
materials[v].sigma = 0 materials[v].sigma = 0
end end
-- Air parameters
local air = { 4 } local air = { 4 }
for i,v in ipairs(air) do for i,v in ipairs(air) do
materials[v] = {} materials[v] = {}
...@@ -43,10 +48,36 @@ function interp(t, t0, t1, y0, y1) ...@@ -43,10 +48,36 @@ function interp(t, t0, t1, y0, y1)
return (t-t0)*(y1-y0)/(t1-t0) + y0 return (t-t0)*(y1-y0)/(t1-t0) + y0
end end
local current_shape = { {0, 1}, {10*sim.dt, 1} } local R = 0.01 -- Capacitor disk radius (must match capacitor.geo)
local d = 0.001 -- Dielectric thickness (must match capacitor.geo)
local tV = 1 -- Target capacitor voltage
local cts = 100 -- Charging current pulse timesteps
local ct = cts*sim.dt
local eps = const.eps0 * diel_epsr
local A = math.pi*R*R
local C = eps*A/d
local J = tV*eps/(ct*d)
local I = J*A
local Q = I*ct
local E = Q/(eps*A) -- Expected capacitor field (should equal tV/d)
local do_IO = (not parallel) or (parallel and parallel.comm_rank == 0)
if ( do_IO ) then
print("\x1b[1mExpected capacitor field: " .. E .. " V/m")
print("Charge: " .. Q .. " C")
print("Current density: " .. J .. " A/m^2\x1b[0m")
end
-- Define the shape of charging current density in terms of
-- {time, current density} pairs. Linear interpolation between
-- pairs is used
local current_shape = { {0, J}, {ct, J} }
function discharge_source(tag, x, y, z, t) -- Define the function evaluating the current source
function current_source(tag, x, y, z, t)
for ii = 1,(#current_shape-1) do for ii = 1,(#current_shape-1) do
local t0 = current_shape[ii][1] local t0 = current_shape[ii][1]
local c0 = current_shape[ii][2] local c0 = current_shape[ii][2]
...@@ -60,7 +91,8 @@ function discharge_source(tag, x, y, z, t) ...@@ -60,7 +91,8 @@ function discharge_source(tag, x, y, z, t)
return 0, 0, 0 return 0, 0, 0
end end
sources[2] = discharge_source -- Apply the current source to entity 2
sources[2] = current_source
...@@ -33,4 +33,3 @@ bndconds[100].kind = "plane_wave_E" ...@@ -33,4 +33,3 @@ bndconds[100].kind = "plane_wave_E"
bndconds[100].source = source bndconds[100].source = source
...@@ -13,7 +13,7 @@ z_base = 0; ...@@ -13,7 +13,7 @@ z_base = 0;
wg_xlen = 0.14; wg_xlen = 0.14;
wg_ylen = 0.0229; wg_ylen = 0.0229;
wg_zlen = 0.005; wg_zlen = 0.01;
rods_start_x = 0.12; rods_start_x = 0.12;
......
File moved
...@@ -7,7 +7,7 @@ sim.timesteps = 50000 -- num of iterations ...@@ -7,7 +7,7 @@ sim.timesteps = 50000 -- num of iterations
sim.gmsh_model = "modeconv.geo" -- gmsh model filename sim.gmsh_model = "modeconv.geo" -- gmsh model filename
sim.use_gpu = 0 -- 0: cpu, 1: gpu sim.use_gpu = 0 -- 0: cpu, 1: gpu
sim.approx_order = 2 -- approximation order sim.approx_order = 2 -- approximation order
--sim_geom_order = 1 -- geometric order, only 1 for now sim.time_integrator = "rk4"
postpro.silo_output_rate = 100 -- rate at which to write silo files postpro.silo_output_rate = 100 -- rate at which to write silo files
postpro.cycle_print_rate = 10 -- console print rate postpro.cycle_print_rate = 10 -- console print rate
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
]]-- ]]--
sim.name = "yagi" -- simulation name sim.name = "yagi" -- simulation name
sim.dt = 1e-12 -- timestep size sim.dt = 1e-12 -- timestep size
sim.timesteps = 2000 -- num of iterations sim.timesteps = 20000 -- num of iterations
sim.gmsh_model = "yagi.geo" -- gmsh model filename sim.gmsh_model = "yagi.geo" -- gmsh model filename
sim.use_gpu = 1 -- 0: cpu, 1: gpu sim.use_gpu = 0 -- 0: cpu, 1: gpu
sim.approx_order = 1 -- approximation order sim.approx_order = 1 -- approximation order
--sim_geom_order = 1 -- geometric order, only 1 for now sim.time_integrator = "leapfrog"
postpro.silo_output_rate = 100 -- rate at which to write silo files postpro.silo_output_rate = 100 -- rate at which to write silo files
postpro.cycle_print_rate = 10 -- console print rate postpro.cycle_print_rate = 10 -- console print rate
......
File moved
...@@ -3,15 +3,14 @@ ...@@ -3,15 +3,14 @@
The source is modeled as a volumetric current between the The source is modeled as a volumetric current between the
two halves of the radiator. two halves of the radiator.
--]] --]]
sim.name = "yagi_rad" -- simulation name sim.name = "yagi_rad" -- simulation name
sim.dt = 1e-13 -- timestep size sim.dt = 1e-13 -- timestep size
sim.timesteps = 50000 -- num of iterations sim.timesteps = 50000 -- num of iterations
sim.gmsh_model = "yagi_rad.geo" -- gmsh model filename sim.gmsh_model = "yagi_rad.geo" -- gmsh model filename
sim.use_gpu = 1 -- 0: cpu, 1: gpu sim.use_gpu = 0 -- 0: cpu, 1: gpu
sim.approx_order = 2 -- approximation order sim.approx_order = 2 -- approximation order
--sim_geom_order = 1 -- geometric order, only 1 for now
sim.time_integrator = "leapfrog" sim.time_integrator = "leapfrog"
postpro.silo_output_rate = 500 -- rate at which to write silo files postpro.silo_output_rate = 500 -- rate at which to write silo files
postpro.cycle_print_rate = 10 -- console print rate postpro.cycle_print_rate = 10 -- console print rate
postpro["H"].silo_mode = "none" postpro["H"].silo_mode = "none"
...@@ -24,7 +23,7 @@ for i,v in ipairs(alu) do ...@@ -24,7 +23,7 @@ for i,v in ipairs(alu) do
materials[v] = {} materials[v] = {}
materials[v].epsilon = 1 materials[v].epsilon = 1
materials[v].mu = 1 materials[v].mu = 1
materials[v].sigma = 3.69e7 materials[v].sigma = 3.69e7
end end
local air = {4, 7} local air = {4, 7}
......
File moved
...@@ -410,6 +410,15 @@ model::map_boundaries(void) ...@@ -410,6 +410,15 @@ model::map_boundaries(void)
#endif /* USE_MPI */ #endif /* USE_MPI */
std::vector<bfk_t> bfk = get_facekey_tag_pairs(); std::vector<bfk_t> bfk = get_facekey_tag_pairs();
for (size_t i = 1; i < bfk.size(); i++)
{
if ( bfk[i-1].first == bfk[i].first )
{
std::cout << bfk[i-1].second << " " << bfk[i].second << std::endl;
throw 42;
}
}
bnd_descriptors.resize( num_faces() ); bnd_descriptors.resize( num_faces() );
size_t fbase = 0; size_t fbase = 0;
/* For each entity */ /* For each entity */
......
...@@ -2,6 +2,7 @@ set(MAXWELL_SOURCES maxwell_interface.cpp ...@@ -2,6 +2,7 @@ set(MAXWELL_SOURCES maxwell_interface.cpp
maxwell_cpu.cpp maxwell_cpu.cpp
maxwell_common.cpp maxwell_common.cpp
maxwell_solver.cpp maxwell_solver.cpp
maxwell_postpro.cpp
) )
if (OPT_ENABLE_GPU_SOLVER) if (OPT_ENABLE_GPU_SOLVER)
......
...@@ -86,6 +86,179 @@ void receive_field(field& f, int src, int tag, size_t offset, size_t length, MPI ...@@ -86,6 +86,179 @@ void receive_field(field& f, int src, int tag, size_t offset, size_t length, MPI
} }
#endif /* USE_MPI */ #endif /* USE_MPI */
field_values::field_values()
: Ex(0.0), Ey(0.0), Ez(0.0),
Hx(0.0), Hy(0.0), Hz(0.0)
{}
field_values::field_values(const vec3d& E, const vec3d& H)
: Ex( E(0) ), Ey( E(1) ), Ez( E(2) ),
Hx( H(0) ), Hy( H(1) ), Hz( H(2) )
{}
field_values::field_values(double pEx, double pEy, double pEz,
double pHx, double pHy, double pHz)
: Ex(pEx), Ey(pEy), Ez(pEz), Hx(pHx), Hy(pHy), Hz(pHz)
{}
field_values&
field_values::operator+=(const field_values& other)
{
Ex += other.Ex;
Ey += other.Ey;
Ez += other.Ez;
Hx += other.Hx;
Hy += other.Hy;
Hz += other.Hz;
return *this;
}
field_values
field_values::operator+(const field_values& other) const
{
field_values ret = *this;
ret += other;
return ret;
}
field_values&
field_values::operator-=(const field_values& other)
{
Ex -= other.Ex;
Ey -= other.Ey;
Ez -= other.Ez;
Hx -= other.Hx;
Hy -= other.Hy;
Hz -= other.Hz;
return *this;
}
field_values
field_values::operator-(const field_values& other) const
{
field_values ret = *this;
ret -= other;
return ret;
}
field_values&
field_values::operator*=(const field_values& other)
{
Ex *= other.Ex;
Ey *= other.Ey;
Ez *= other.Ez;
Hx *= other.Hx;
Hy *= other.Hy;
Hz *= other.Hz;
return *this;
}
field_values
field_values::operator*(const field_values& other) const
{
field_values ret = *this;
ret *= other;
return ret;
}
field_values&
field_values::operator/=(const field_values& other)
{
Ex /= other.Ex;
Ey /= other.Ey;
Ez /= other.Ez;
Hx /= other.Hx;
Hy /= other.Hy;
Hz /= other.Hz;
return *this;
}
field_values
field_values::operator/(const field_values& other) const
{
field_values ret = *this;
ret /= other;
return ret;
}
field_values&
field_values::operator*=(double other)
{
Ex *= other;
Ey *= other;
Ez *= other;
Hx *= other;
Hy *= other;
Hz *= other;
return *this;
}
field_values
field_values::operator*(double other) const
{
field_values ret = *this;
ret *= other;
return ret;
}
field_values&
field_values::operator/=(double other)
{
Ex /= other;
Ey /= other;
Ez /= other;
Hx /= other;
Hy /= other;
Hz /= other;
return *this;
}
field_values
field_values::operator/(double other) const
{
field_values ret = *this;
ret /= other;
return ret;
}
field_values
operator*(double d, const field_values& m)
{
return m*d;
}
std::ostream&
operator<<(std::ostream& os, const field_values& m)
{
os << m.Ex << " " << m.Ey << " " << m.Ez << " ";
os << m.Hx << " " << m.Hy << " " << m.Hz;
return os;
}
field_values
sqrt(const field_values& m)
{
field_values ret;
ret.Ex = std::sqrt(m.Ex);
ret.Ey = std::sqrt(m.Ey);
ret.Ez = std::sqrt(m.Ez);
ret.Hx = std::sqrt(m.Hx);
ret.Hy = std::sqrt(m.Hy);
ret.Hz = std::sqrt(m.Hz);
return ret;
}
double
hsum(const field_values& m)
{
return m.Ex + m.Ey + m.Ez + m.Hx + m.Hy + m.Hz;
}
#ifdef ENABLE_GPU_SOLVER #ifdef ENABLE_GPU_SOLVER
pinned_field::pinned_field() pinned_field::pinned_field()
...@@ -239,7 +412,6 @@ field_gpu::copyout(field& emf) const ...@@ -239,7 +412,6 @@ field_gpu::copyout(field& emf) const
} }
material_params_gpu::raw_ptrs material_params_gpu::raw_ptrs
material_params_gpu::data(void) material_params_gpu::data(void)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment