00001 #include <iostream>
00002 #include <fstream>
00003 #include <assert.h>
00004 #include "myrlog.h"
00005
00006 #include "materials.h"
00007
00008 using namespace colarray;
00009
00010 Materials::Materials(const char* filename) :
00011 _filename(filename), _numOfMaterials(0)
00012 {
00013
00014
00015
00016 if (strcmp(_filename.c_str(), "") == 0){
00017 rInfo("Assuming no materials (vacuum).");
00018 _numOfMaterials = 0;
00019
00020 } else {
00021 rInfo("Reading material file %s...", filename);
00022 ifstream matFile(_filename.c_str());
00023 assert(matFile != 0);
00024
00025 matFile >> _numOfMaterials;
00026 _mu.resize(_numOfMaterials + 1);
00027 _eps.resize(_numOfMaterials + 1);
00028
00029 for(int i=1; i<_numOfMaterials+1; i++){
00030 matFile >> _mu[i];
00031 matFile >> _eps[i];
00032 }
00033 rInfo("%d materials read.", _numOfMaterials);
00034
00035 }
00036 }
00037
00038
00039
00040
00041 Materials::~Materials()
00042 {
00043 }
00044
00045
00046
00047
00048 void Materials::getParameters(int id, Matrix<double>& xi, Matrix<double>& mu, Matrix<double>& eps)
00049 {
00050
00051 mu.fill(0.0);
00052 eps.fill(0.0);
00053
00054
00055 if (_numOfMaterials == 0){
00056 mu(0,0) = mu(1,1) = mu(2,2) = 1.0;
00057 eps(0,0) = eps(1,1) = eps(2,2) = 1.0;
00058 } else {
00059 mu(0,0) = mu(1,1) = mu(2,2) = _mu[id];
00060 eps(0,0) = eps(1,1) = eps(2,2) = _eps[id];
00061 }
00062 }
00063
00064
00065