00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Electrodes.hpp"
00030
00031 template<unsigned DIM>
00032 Electrodes<DIM>::Electrodes(TetrahedralMesh<DIM,DIM>& rMesh,
00033 bool groundSecondElectrode,
00034 unsigned index,
00035 double lowerValue,
00036 double upperValue,
00037 double magnitude,
00038 double duration)
00039 {
00040 assert(index < DIM);
00041 mGroundSecondElectrode = groundSecondElectrode;
00042 assert(duration > 0);
00043 mEndTime = 0.0 + duration;
00044 mAreActive = true;
00045
00046
00047 double min = DBL_MAX;
00048 double max = -DBL_MIN;
00049 for(unsigned i=0; i<rMesh.GetNumNodes(); i++)
00050 {
00051 double value = rMesh.GetNode(i)->rGetLocation()[index];
00052 if(value < min)
00053 {
00054 min = value;
00055 }
00056 if(value > max)
00057 {
00058 max = value;
00059 }
00060 }
00061
00062 if( fabs(min - lowerValue) > 1e-6 )
00063 {
00064 EXCEPTION("Minimum value of coordinate is not the value given");
00065 }
00066 if( fabs(max - upperValue) > 1e-6 )
00067 {
00068 EXCEPTION("Maximum value of coordinate is not the value given");
00069 }
00070
00071 mpBoundaryConditionsContainer = new BoundaryConditionsContainer<DIM,DIM,2>;
00072
00073 ConstBoundaryCondition<DIM>* p_bc_flux_in = new ConstBoundaryCondition<DIM>(magnitude);
00074 ConstBoundaryCondition<DIM>* p_bc_flux_out = new ConstBoundaryCondition<DIM>(-magnitude);
00075
00076
00077
00078 for (typename TetrahedralMesh<DIM,DIM>::BoundaryElementIterator iter
00079 = rMesh.GetBoundaryElementIteratorBegin();
00080 iter != rMesh.GetBoundaryElementIteratorEnd();
00081 iter++)
00082 {
00083 if ( fabs((*iter)->CalculateCentroid()[index] - lowerValue) < 1e-6 )
00084 {
00085 mpBoundaryConditionsContainer->AddNeumannBoundaryCondition(*iter, p_bc_flux_in, 1);
00086 }
00087
00088 if (!mGroundSecondElectrode)
00089 {
00090 if ( fabs((*iter)->CalculateCentroid()[index] - upperValue) < 1e-6 )
00091 {
00092 mpBoundaryConditionsContainer->AddNeumannBoundaryCondition(*iter, p_bc_flux_out, 1);
00093 }
00094 }
00095 }
00096
00097
00098
00099 if (mGroundSecondElectrode)
00100 {
00101 ConstBoundaryCondition<DIM>* p_zero_bc = new ConstBoundaryCondition<DIM>(0.0);
00102
00103 for (unsigned i=0; i<rMesh.GetNumNodes(); i++)
00104 {
00105 if (fabs(rMesh.GetNode(i)->rGetLocation()[index]-upperValue)<1e-6)
00106 {
00107 mpBoundaryConditionsContainer->AddDirichletBoundaryCondition(rMesh.GetNode(i), p_zero_bc, 1);
00108 }
00109 }
00110
00111
00112 delete p_bc_flux_out;
00113 }
00114 }
00115
00117
00119
00120 template class Electrodes<1>;
00121 template class Electrodes<2>;
00122 template class Electrodes<3>;