#ifndef WAVEGUIDE_H
#define WAVEGUIDE_H

/*
 * WMM
 * Wave-matching method for mode analysis of dielectric waveguides
 * Manfred Lohmeyer 
 * University of Osnabrueck, Department of Physics
 * Barbarastrasse 7, D-49069 Osnabrueck, Germany
 * (1999)
 * Manfred Hammer
 * University of Twente, Faculty of Mathematical Sciences
 * P.O. Box 217, 7500AE Enschede, The Netherlands
 * (2002)
 */

/* 
 * waveg.h
 * waveguide definition 
 */

/* Rect: rectangular section on the waveguide cross section plane */
class Rect 
{
public:
	// lower left point
	double x0;
	double y0;
	// upper right point
	double x1;
	double y1;
	// initialize
	Rect();
	Rect(double xa, double ya, double xb, double yb);
	// output
	void write(FILE *dat);
	// input
	void read(FILE *dat);
};

/* waveguide geometry + permittivity profile; vacuum wavelength ... */
class Waveguide 
{
public:
	// number of inner layers perpendicular to direction x
	int nx;
	// number of inner layers perpendicular to direction y
	int ny;
	// x boundary positions
	Dvector hx;
	// y boundary positions
	Dvector hy;

	// get rectangle index (l, m) corresponding to position (x,y)  
	void rectidx(double x, double y, int& l, int& m) const;
	// get rectangle boundaries corresponding to index (l,m)  
	Rect rectbounds(int l, int m) const;
	// get rectangle boundaries corresponding to position (x,y)  
	Rect rectbounds(double x, double y) const;
	// test neighbourhood of two rectangles
	int testconnect(int l0, int m0, int l1, int m1) const;

	// test matching of boundary positions with another waveguide
	int bdmatch(Waveguide w) const; 

	// vacuum wavelength 
	double lambda;
	// refractive index profile
	Dmatrix n;
	// permittivity on rectangle l, m
	double eps(int l, int m) const;
	// permittivity at position x, y
	double eps(double x, double y) const;

	// lower bound for effective mode indices, default value
	double defaultneffmin() const;
	// upper bound for effective mode indices, default value
	double defaultneffmax() const;

	// the entire cross section plane  
	Rect xyplane;

	// translate: hx -> hx+dx, hy -> hy+dy
	void translate(double dx, double dy);

	// output 
	void write(FILE *dat);
	// input
	void read(FILE *dat);

	// initialize
	Waveguide();
	Waveguide(int vnx, int vny); 
	Waveguide(int vnx, Dvector vhx,
		  int vny, Dvector vhy,
		  double l, Dmatrix n);

	// free allocated memory
	void strip();
};

#endif  // WAVEGUIDE_H

