36 #include "Electrodes.hpp"
37 #include "DistributedTetrahedralMesh.hpp"
39 #include "HeartConfig.hpp"
41 template<
unsigned DIM>
44 mLeftElectrodeArea(0.0),
45 mRightElectrodeArea(0.0)
48 double magnitude, duration;
52 assert(axis_index < DIM);
70 input_flux = magnitude;
71 output_flux = -input_flux;
77 input_flux = magnitude;
81 assert( ! std::isnan(output_flux));
82 assert( output_flux != 0.0);
95 if (fabs((*iter)->CalculateCentroid()[axis_index] - global_min) < 1e-6)
102 if (fabs((*iter)->CalculateCentroid()[axis_index] - global_max) < 1e-6)
121 if (fabs((*iter).rGetLocation()[axis_index]-global_max) < 1e-6)
128 delete p_bc_flux_out;
134 template<
unsigned DIM>
138 return mpBoundaryConditionsContainer;
142 template<
unsigned DIM>
147 double smidge = 1e-10;
148 if (mAreActive && time>mEndTime-smidge)
157 template<
unsigned DIM>
162 double smidge = 1e-10;
163 if (!mAreActive && time>=mStartTime && time<=mEndTime - smidge)
172 template<
unsigned DIM>
178 double local_left_area = 0.0;
179 double local_right_area = 0.0;
181 c_vector<double,DIM> weighted_direction;
182 double jacobian_determinant;
187 iter != mpMesh->GetBoundaryElementIteratorEnd();
190 if ( mpMesh->CalculateDesignatedOwnershipOfBoundaryElement( (*iter)->GetIndex() ))
192 if (fabs((*iter)->CalculateCentroid()[dimensionIndex] - lowerValue) < 1e-6)
194 mpMesh->GetWeightedDirectionForBoundaryElement((*iter)->GetIndex(), weighted_direction, jacobian_determinant);
195 local_left_area += jacobian_determinant;
198 if (fabs((*iter)->CalculateCentroid()[dimensionIndex] - upperValue) < 1e-6)
200 mpMesh->GetWeightedDirectionForBoundaryElement((*iter)->GetIndex(), weighted_direction, jacobian_determinant);
201 local_right_area += jacobian_determinant;
215 local_left_area /= 2.0;
216 local_right_area /= 2.0;
219 int mpi_ret = MPI_Allreduce(&local_left_area, &mLeftElectrodeArea, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD);
221 assert(mpi_ret == MPI_SUCCESS);
223 mpi_ret = MPI_Allreduce(&local_right_area, &mRightElectrodeArea, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD);
224 assert(mpi_ret == MPI_SUCCESS);
226 if (mLeftElectrodeArea != mRightElectrodeArea)
228 EXCEPTION(
"Electrodes have different area");
bool mGroundSecondElectrode
BoundaryElementIterator GetBoundaryElementIteratorBegin() const
#define EXCEPTION(message)
double mLeftElectrodeArea
NodeIterator GetNodeIteratorEnd()
boost::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 2 > > mpBoundaryConditionsContainer
AbstractTetrahedralMesh< DIM, DIM > * mpMesh
const ChastePoint< SPACE_DIM > & rGetUpperCorner() const
boost::shared_ptr< BoundaryConditionsContainer< DIM, DIM, 2 > > GetBoundaryConditionsContainer()
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void GetElectrodeParameters(bool &rGroundSecondElectrode, unsigned &rIndex, double &rMagnitude, double &rStartTime, double &rDuration)
NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true)
ChasteCuboid< SPACE_DIM > CalculateBoundingBox(const std::vector< Node< SPACE_DIM > * > &rNodes) const
double mRightElectrodeArea
bool SwitchOn(double time)
static HeartConfig * Instance()
void ComputeElectrodesAreasAndCheckEquality(unsigned index, double lowerValue, double upperValue)
bool SwitchOff(double time)
BoundaryElementIterator GetBoundaryElementIteratorEnd() const
const ChastePoint< SPACE_DIM > & rGetLowerCorner() const