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;
132 template<
unsigned DIM>
136 return mpBoundaryConditionsContainer;
139 template<
unsigned DIM>
144 double smidge = 1e-10;
145 if (mAreActive && time>mEndTime-smidge)
154 template<
unsigned DIM>
159 double smidge = 1e-10;
160 if (!mAreActive && time>=mStartTime && time<=mEndTime - smidge)
169 template<
unsigned DIM>
175 double local_left_area = 0.0;
176 double local_right_area = 0.0;
178 c_vector<double,DIM> weighted_direction;
179 double jacobian_determinant;
183 iter != mpMesh->GetBoundaryElementIteratorEnd();
186 if (mpMesh->CalculateDesignatedOwnershipOfBoundaryElement((*iter)->GetIndex()))
188 if (fabs((*iter)->CalculateCentroid()[dimensionIndex] - lowerValue) < 1e-6)
190 mpMesh->GetWeightedDirectionForBoundaryElement((*iter)->GetIndex(), weighted_direction, jacobian_determinant);
191 local_left_area += jacobian_determinant;
194 if (fabs((*iter)->CalculateCentroid()[dimensionIndex] - upperValue) < 1e-6)
196 mpMesh->GetWeightedDirectionForBoundaryElement((*iter)->GetIndex(), weighted_direction, jacobian_determinant);
197 local_right_area += jacobian_determinant;
211 local_left_area /= 2.0;
212 local_right_area /= 2.0;
215 int mpi_ret = MPI_Allreduce(&local_left_area, &mLeftElectrodeArea, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD);
217 assert(mpi_ret == MPI_SUCCESS);
219 mpi_ret = MPI_Allreduce(&local_right_area, &mRightElectrodeArea, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD);
220 assert(mpi_ret == MPI_SUCCESS);
222 if (mLeftElectrodeArea != mRightElectrodeArea)
224 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