1 /*
2 *	Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de)
3 *
4 *	This program is free software: you can redistribute it and/or modify
5 *	it under the terms of the GNU Lesser General Public License as published
6 *	by the Free Software Foundation, either version 3 of the License, or
7 *	(at your option) any later version.
8 *
9 *	This program is distributed in the hope that it will be useful,
10 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *	GNU Lesser General Public License for more details.
13 *
14 *	You should have received a copy of the GNU Lesser General Public License
15 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #pragma once
19 
20 #include "CSProperties.h"
21 
22 
23 //! Continuous Structure Material Property
24 /*!
25   This Property can hold information about the properties of materials, such as epsilon, mue, kappa or sigma (aka. magnetic losses in FDTD).
26   The material can be location dependent and unisotropic.
27   */
28 class CSXCAD_EXPORT CSPropMaterial : public CSProperties
29 {
30 public:
31 	CSPropMaterial(ParameterSet* paraSet);
32 	CSPropMaterial(CSProperties* prop);
33 	CSPropMaterial(unsigned int ID, ParameterSet* paraSet);
34 	virtual ~CSPropMaterial();
35 
36 	//! Get PropertyType as a xml element name \sa PropertyType and GetType
GetTypeXMLString()37 	virtual const std::string GetTypeXMLString() const {return std::string("Material");}
38 
39 	void SetEpsilon(double val, int ny=0)		{SetValue(val,Epsilon,ny);}
40 	int SetEpsilon(const std::string val, int ny=0)	{return SetValue(val,Epsilon,ny);}
41 	double GetEpsilon(int ny=0)					{return GetValue(Epsilon,ny);}
42 	const std::string GetEpsilonTerm(int ny=0)		{return GetTerm(Epsilon,ny);}
43 
SetEpsilonWeightFunction(const std::string fct,int ny)44 	int SetEpsilonWeightFunction(const std::string fct, int ny)	{return SetValue(fct,WeightEpsilon,ny);}
GetEpsilonWeightFunction(int ny)45 	const std::string GetEpsilonWeightFunction(int ny)			{return GetTerm(WeightEpsilon,ny);}
GetEpsilonWeighted(int ny,const double * coords)46 	virtual double GetEpsilonWeighted(int ny, const double* coords)	{return GetWeight(WeightEpsilon,ny,coords)*GetEpsilon(ny);}
47 
48 	void SetMue(double val, int ny=0)			{SetValue(val,Mue,ny);}
49 	int SetMue(const std::string val, int ny=0)		{return SetValue(val,Mue,ny);}
50 	double GetMue(int ny=0)						{return GetValue(Mue,ny);}
51 	const std::string GetMueTerm(int ny=0)			{return GetTerm(Mue,ny);}
52 
SetMueWeightFunction(const std::string fct,int ny)53 	int SetMueWeightFunction(const std::string fct, int ny)	{return SetValue(fct,WeightMue,ny);}
GetMueWeightFunction(int ny)54 	const std::string GetMueWeightFunction(int ny)			{return GetTerm(WeightMue,ny);}
GetMueWeighted(int ny,const double * coords)55 	virtual double GetMueWeighted(int ny, const double* coords)	{return GetWeight(WeightMue,ny,coords)*GetMue(ny);}
56 
57 	void SetKappa(double val, int ny=0)			{SetValue(val,Kappa,ny);}
58 	int SetKappa(const std::string val, int ny=0)	{return SetValue(val,Kappa,ny);}
59 	double GetKappa(int ny=0)					{return GetValue(Kappa,ny);}
60 	const std::string GetKappaTerm(int ny=0)			{return GetTerm(Kappa,ny);}
61 
SetKappaWeightFunction(const std::string fct,int ny)62 	int SetKappaWeightFunction(const std::string fct, int ny)	{return SetValue(fct,WeightKappa,ny);}
GetKappaWeightFunction(int ny)63 	const std::string GetKappaWeightFunction(int ny)				{return GetTerm(WeightKappa,ny);}
GetKappaWeighted(int ny,const double * coords)64 	virtual double GetKappaWeighted(int ny, const double* coords)	{return GetWeight(WeightKappa,ny,coords)*GetKappa(ny);}
65 
66 	void SetSigma(double val, int ny=0)			{SetValue(val,Sigma,ny);}
67 	int SetSigma(const std::string val, int ny=0)	{return SetValue(val,Sigma,ny);}
68 	double GetSigma(int ny=0)					{return GetValue(Sigma,ny);}
69 	const std::string GetSigmaTerm(int ny=0)			{return GetTerm(Sigma,ny);}
70 
SetSigmaWeightFunction(const std::string fct,int ny)71 	int SetSigmaWeightFunction(const std::string fct, int ny)	{return SetValue(fct,WeightSigma,ny);}
GetSigmaWeightFunction(int ny)72 	const std::string GetSigmaWeightFunction(int ny)				{return GetTerm(WeightSigma,ny);}
GetSigmaWeighted(int ny,const double * coords)73 	virtual double GetSigmaWeighted(int ny, const double* coords)	{return GetWeight(WeightSigma,ny,coords)*GetSigma(ny);}
74 
SetDensity(double val)75 	void SetDensity(double val)			{Density.SetValue(val);}
SetDensity(const std::string val)76 	int SetDensity(const std::string val)	{return Density.SetValue(val);}
GetDensity()77 	double GetDensity()					{return Density.GetValue();}
GetDensityTerm()78 	const std::string GetDensityTerm()		{return Density.GetString();}
79 
SetDensityWeightFunction(const std::string fct)80 	int SetDensityWeightFunction(const std::string fct) {return WeightDensity.SetValue(fct);}
GetDensityWeightFunction()81 	const std::string GetDensityWeightFunction() {return WeightDensity.GetString();}
GetDensityWeighted(const double * coords)82 	virtual double GetDensityWeighted(const double* coords)	{return GetWeight(WeightDensity,coords)*GetDensity();}
83 
SetIsotropy(bool val)84 	void SetIsotropy(bool val) {bIsotropy=val;}
GetIsotropy()85 	bool GetIsotropy() {return bIsotropy;}
86 
87 	virtual void Init();
88 	virtual bool Update(std::string *ErrStr=NULL);
89 
90 	virtual bool Write2XML(TiXmlNode& root, bool parameterised=true, bool sparse=false);
91 	virtual bool ReadFromXML(TiXmlNode &root);
92 
93 	virtual void ShowPropertyStatus(std::ostream& stream);
94 
95 protected:
96 	double GetValue(ParameterScalar *ps, int ny);
97 	std::string GetTerm(ParameterScalar *ps, int ny);
98 	void SetValue(double val, ParameterScalar *ps, int ny);
99 	int SetValue(std::string val, ParameterScalar *ps, int ny);
100 
101 	//electro-magnetic properties
102 	ParameterScalar Epsilon[3],Mue[3],Kappa[3],Sigma[3];
103 	ParameterScalar WeightEpsilon[3],WeightMue[3],WeightKappa[3],WeightSigma[3];
104 
105 	//other physical properties
106 	ParameterScalar Density, WeightDensity;
107 
108 	double GetWeight(ParameterScalar &ps, const double* coords);
109 	double GetWeight(ParameterScalar *ps, int ny, const double* coords);
110 	bool bIsotropy;
111 };
112