CellBasedPdeHandlerOnCuboid.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include "CellBasedPdeHandlerOnCuboid.hpp"
00037 #include "ConstBoundaryCondition.hpp"
00038 
00039 template<unsigned DIM>
00040 CellBasedPdeHandlerOnCuboid<DIM>::CellBasedPdeHandlerOnCuboid(AbstractCellPopulation<DIM>* pCellPopulation,
00041                                               bool deleteMemberPointersInDestructor)
00042     : CellBasedPdeHandler<DIM>(pCellPopulation, deleteMemberPointersInDestructor)
00043 {
00044 }
00045 
00046 template<unsigned DIM>
00047 CellBasedPdeHandlerOnCuboid<DIM>::~CellBasedPdeHandlerOnCuboid()
00048 {
00049     // Delete all boundary conditions
00050     for (unsigned i=0; i<mConstBoundaryConditions.size(); i++)
00051     {
00052         delete mConstBoundaryConditions[i];
00053     }
00054 }
00055 
00056 template<unsigned DIM>
00057 std::auto_ptr<BoundaryConditionsContainer<DIM,DIM,1> > CellBasedPdeHandlerOnCuboid<DIM>::ConstructBoundaryConditionsContainer(
00058         PdeAndBoundaryConditions<DIM>* pPdeAndBc,
00059         TetrahedralMesh<DIM,DIM>* pMesh)
00060 {
00061     // Not using the inputs as there's only one BC
00062     assert(DIM==2);
00063 
00064     std::auto_ptr<BoundaryConditionsContainer<DIM,DIM,1> > p_bcc(new BoundaryConditionsContainer<DIM,DIM,1>(false));
00065 
00066     // Use these two vectors to define what's happening on the top right bottom and left boundaries
00067 
00068     // Specify which sides are Neumann boundaries
00069     c_vector<bool,4> are_neumann_boundaries;
00070     are_neumann_boundaries[0] = false; // Top
00071     are_neumann_boundaries[1] = true;  // Right
00072     are_neumann_boundaries[2] = false; // Bottom
00073     are_neumann_boundaries[3] = true;  // Left
00074 
00075     // Specify the value of the boundary condition on each boundary
00076     c_vector<double,4> boundary_condition_values;
00077     boundary_condition_values[0] = 1.0; // Top
00078     boundary_condition_values[1] = 1.0; // Right
00079     boundary_condition_values[2] = 1.0; // Bottom
00080     boundary_condition_values[3] = 1.0; // Left
00081 
00082     // Delete all previous boundary conditions
00083     for (unsigned i=0; i<mConstBoundaryConditions.size(); i++)
00084     {
00085         delete mConstBoundaryConditions[i];
00086     }
00087     mConstBoundaryConditions.clear();
00088 
00089     mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[0]));
00090     mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[1]));
00091     mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[2]));
00092     mConstBoundaryConditions.push_back(new ConstBoundaryCondition<DIM>(boundary_condition_values[3]));
00093 
00094     ChasteCuboid<DIM> cuboid = pMesh->CalculateBoundingBox();
00095 
00096     double left = cuboid.rGetLowerCorner()[0];
00097     double bottom = cuboid.rGetLowerCorner()[1];
00098     double right = cuboid.rGetUpperCorner()[0];
00099     double top = cuboid.rGetUpperCorner()[1];
00100     double fudge_factor = 1e-6;
00101 
00102     // Apply Neumann boundary conditions
00103     for (typename TetrahedralMesh<DIM,DIM>::BoundaryElementIterator elem_iter = pMesh->GetBoundaryElementIteratorBegin();
00104          elem_iter != pMesh->GetBoundaryElementIteratorEnd();
00105          ++elem_iter)
00106     {
00107         double x_1 = (*elem_iter)->GetNodeLocation(0)[0];
00108 //        double y_1 = (*elem_iter)->GetNodeLocation(0)[1];
00109         double x_2 = (*elem_iter)->GetNodeLocation(1)[0];
00110 //        double y_2 = (*elem_iter)->GetNodeLocation(1)[1];
00111 
00112         assert(!are_neumann_boundaries[0]);
00113 //        if (are_neumann_boundaries[0]) // Top is Neumann boundary
00114 //        {
00115 //            if ( (y_1  > (top-fudge_factor) ) &&  (y_2 > (top-fudge_factor) ))
00116 //            {
00117 //                p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[0]);
00118 //            }
00119 //        }
00120         if (are_neumann_boundaries[1]) // Right is Neumann boundary
00121         {
00122             if ( (x_1  > (right-fudge_factor) ) &&  (x_2 > (right-fudge_factor) ))
00123             {
00124                 p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[1]);
00125             }
00126         }
00127         assert(!are_neumann_boundaries[2]);
00128 //        if (are_neumann_boundaries[2]) // Bottom is Neumann boundary
00129 //        {
00130 //            if ( (y_1  < (bottom+fudge_factor) ) &&  (y_2 < (bottom+fudge_factor) ))
00131 //            {
00132 //                p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[2]);
00133 //            }
00134 //        }
00135         if (are_neumann_boundaries[3]) // Left is Neumann Boundary
00136         {
00137             if ( (x_1  > (left+fudge_factor) ) &&  (x_2 < (left+fudge_factor) ))
00138             {
00139                 p_bcc->AddNeumannBoundaryCondition(*elem_iter, mConstBoundaryConditions[3]);
00140             }
00141         }
00142     }
00143 
00144 
00145     // Apply dirichlet Boundaries
00146     for (typename TetrahedralMesh<DIM,DIM>::BoundaryNodeIterator node_iter = pMesh->GetBoundaryNodeIteratorBegin();
00147          node_iter != pMesh->GetBoundaryNodeIteratorEnd();
00148          ++node_iter)
00149     {
00150 //        double x = (*node_iter)->GetPoint()[0];
00151         double y = (*node_iter)->GetPoint()[1];
00152 
00153         if (!are_neumann_boundaries[0]) // Top is Dirichlet boundary
00154         {
00155             if (y > top-fudge_factor)
00156             {
00157                 p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[0]);
00158             }
00159         }
00160         assert(are_neumann_boundaries[1]);
00161 //        if (!are_neumann_boundaries[1]) // Right is Dirichlet boundary
00162 //        {
00163 //            if (x > right-fudge_factor)
00164 //            {
00165 //                p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[1]);
00166 //            }
00167 //        }
00168         if (!are_neumann_boundaries[2]) // Bottom is Dirichlet boundary
00169         {
00170             if (y < bottom+fudge_factor)
00171             {
00172                 p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[2]);
00173             }
00174         }
00175         assert(are_neumann_boundaries[3]);
00176 //        if (!are_neumann_boundaries[3]) // Left is Dirichlet boundary
00177 //        {
00178 //            if (x < left+fudge_factor)
00179 //            {
00180 //                p_bcc->AddDirichletBoundaryCondition(*node_iter, mConstBoundaryConditions[3]);
00181 //            }
00182 //        }
00183     }
00184 
00185     return p_bcc;
00186 }
00187 
00188 template<unsigned DIM>
00189 void CellBasedPdeHandlerOnCuboid<DIM>::OutputParameters(out_stream& rParamsFile)
00190 {
00191     CellBasedPdeHandler<DIM>::OutputParameters(rParamsFile);
00192 }
00193 
00194 // Serialization for Boost >= 1.36
00195 #include "SerializationExportWrapperForCpp.hpp"
00196 EXPORT_TEMPLATE_CLASS_SAME_DIMS(CellBasedPdeHandlerOnCuboid)
00197 
00198 
00199 // Explicit instantiation
00201 
00202 template class CellBasedPdeHandlerOnCuboid<1>;
00203 template class CellBasedPdeHandlerOnCuboid<2>;
00204 template class CellBasedPdeHandlerOnCuboid<3>;

Generated by  doxygen 1.6.2