The URI of TUHH Docker Registry changed from "docker.rz.tu-harburg.de:5000" to "docker.rz.tu-harburg.de". Please update your gitlab-ci.yml files if you use images from this registry.

Commit 4f921d25 authored by Hendrik Preuß's avatar Hendrik Preuß

made p_simple more multi-purpose

parent 61b08b15
......@@ -31,44 +31,65 @@
including the ideces of the materials above and below the inner layers.
All distances are in micro meters.
*/
Waveguide wgdef(int layers, int layer, double n_diff) {
Waveguide wg(layers);
Waveguide wgdef(double lambda,
std::vector<double> hx,
std::vector<double> n,
int layer,
double n_diff) {
Waveguide wg(hx.size());
wg.lambda = lambda;
wg.hx(0) = 0;
wg.hx(1) = 0.140;
wg.n(0) = 1.38;
wg.n(1) = 3.43;
wg.n(2) = 1;
quiet ? 0 : printf("hx =");
for (unsigned i = 0; i < hx.size(); i++) {
quiet ? 0 : printf(" %g", hx[i]);
wg.hx(i+1) = wg.hx(i) + hx[i];
}
quiet ? 0 : printf("\nn =");
for (unsigned i = 0; i < n.size(); i++) {
quiet ? 0 : printf(" %g", n[i]);
wg.n(i) = n[i];
}
wg.n(layer) = wg.n(layer) + n_diff;
wg.lambda = 3.3;
quiet ? 0 : printf("\ndiff_layer = %g\n", wg.n(layer));
return wg;
}
/**
Returns an array of the medium-specific refractive index sensitivites.
*/
void f_p (double p[], int layers, Polarization pol, double n_diff) {
double neff1;
double neff2[layers+2];
void f_p (std::vector<double>* p, double* neff1,
double lambda,
Polarization pol,
std::vector<double> hx,
std::vector<double> n,
double n_diff) {
quiet ? 0 : printf("in f_p\n");
double neff2[n.size()];
Waveguide wg;
ModeArray modes;
wg = wgdef(layers, 0, 0);
wg = wgdef(lambda, hx, n, 0, 0);
modeanalysis(wg, pol, modes, 1);
quiet ? 0 : printf("neff = %g\n", modes(0).neff);
neff1 = modes(0).neff;
printf("%-11.5g", neff1);
for (int i = 0; i < layers + 2; i++) {
wg = wgdef(layers, i, n_diff);
*neff1 = modes(0).neff;
quiet ? 0 : printf("neff = %g\n", *neff1);
for (unsigned i = 0; i < n.size(); i++) {
wg = wgdef(lambda, hx, n, i, n_diff);
modeanalysis(wg, pol, modes, 1);
quiet ? 0 : fprintf(stderr, "neff = %g\n", modes(0).neff);
neff2[i] = modes(0).neff;
p[i] = (neff2[i] - neff1) / n_diff;
quiet ? 0 : printf("p = %g\n", p[i]);
p->push_back((neff2[i] - *neff1) / n_diff);
quiet ? 0 : printf("p = %g\n", p->back());
}
}
int main(int argc, char *argv[]) {
// Number of layers excluding the upper and lower materials
int layers = 1;
// wavelength in um
double lambda = 1.54;
// refective indeces of the layers and claddings (bottom to top)
std::vector<double> n = {1.45, 3.48, 1};
// layer thicknesses in um (bottom to top)
//std::vector<double> hx = {0.22};
// refractive index perturbation
double n_diff = 0.01;
......@@ -76,42 +97,47 @@ int main(int argc, char *argv[]) {
// light polarization (TE or TM)
Polarization pol = TE;
// just for printing
Waveguide wg = wgdef(layers, 0 ,0);
printf("# Wavelength: %g\n", wg.lambda);
printf("# Wavelength: %g\n", lambda);
if (pol == TE) {
printf("# Polarization: TE\n");
} else if (pol == TM) {
printf("# Polarization: TM\n");
}
printf("# Refractive index perturbation: %g\n", n_diff);
printf("# Layer thicknesses: ");
for(int i = 0; i < layers; i++) {
printf("%-9g", wg.hx(i+1)-wg.hx(i));
}
// printf("# Layer thicknesses: ");
// for(unsigned i = 0; i < hx.size(); i++) {
// printf("%-9g", hx[i]);
// }
printf("\n# Refractice indeces: ");
for(int i = 0; i < layers + 2; i++) {
printf("%-9g", wg.n(i));
for(unsigned i = 0; i < n.size(); i++) {
printf("%-9g", n[i]);
}
// layer names as used in wgdef (length = layers + 2)
printf("\n#\n# %-11s %-11s %-11s %-11s\n", // %-11s\n",
printf("\n#\n# %-9s %-11s %-11s %-11s %-11s\n",
"h_slab",
"n_eff",
"Substrate",
"Slab",
// "SiO2",
"Air");
// output array for the sensitivies
double p[layers + 2];
// For a sweep the following section can be put into a loop.
// The function f_p needs to be adapted to include the sweep parameter.
// calcualte the refractive index sensitivity
f_p(p, layers, pol, n_diff);
// print the sensitivites
for(int i = 0; i < layers + 2; i++) {
printf("%-11.5g ", p[i]);
for(double slab = 0.026; slab < 0.5; slab += 0.0001) {
std::vector<double> hx = {slab};
// output vector for the sensitivies
std::vector<double>* p = new std::vector<double>();
// output of the effective refractive index
double* neff = new double();
// calcualte the refractive index sensitivity
f_p(p, neff,
lambda, pol, hx, n, n_diff);
// print the sensitivites
printf("%-11.5g %-11.5g ", slab, *neff);
for(unsigned i = 0; i < p->size(); i++) {
printf("%-11.5g ", p->at(i));
}
printf("\n");
}
printf("\n");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment