Electrodes.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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; // currently start time = 0 is hardcoded here
00044     mAreActive = true; // switch electrodes on!
00045     
00046     // check min x_i = a and max x_i = b, where i = index
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     // loop over boundary elements and add a non-zero phi_e boundary condition (ie extracellular
00077     // stimulus) if (assuming index=0, etc) x=lowerValue (where x is the x-value of the centroid)
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     // set up mGroundedNodes using opposite surface is second electrode is 
00098     // grounded
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         //Unused boundary conditions will not be deleted by the b.c. container
00112         delete p_bc_flux_out;
00113     }     
00114 }
00115 
00117 // Explicit instantiation
00119 
00120 template class Electrodes<1>;
00121 template class Electrodes<2>;
00122 template class Electrodes<3>;

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5