Skip to content

Instantly share code, notes, and snippets.

@germannp
Last active July 18, 2018 11:36
Show Gist options
  • Save germannp/e11c154b8e68a6ef968a8e0c3416b417 to your computer and use it in GitHub Desktop.
Save germannp/e11c154b8e68a6ef968a8e0c3416b417 to your computer and use it in GitHub Desktop.
Performance Comparison
! Needs to go into ic.mod.f90 and then be called from default_ic
subroutine ball_of_cells
real*8::r,r_max,phi,theta
nd = 10000
nda = nd
ncels = nd
ncals = nd
if (allocated(node)) deallocate(node)
if (allocated(cels)) deallocate(cels)
allocate(node(nda),cels(ncals))
call iniarrays
!******* #2 DEFINING MODEL PARAMETERS *******
!implementation and initializations
getot=0
itacc=0
nparti=1000
idum=-11111
idumoriginal=idum
realtime=0
nvarglobal_out=5
!physical
temp=1d0 !low value is low temperature
desmax=0.01
resmax=1d-3
prop_noise=0.0d0
deltamax=1d-2 ! miguel 14-10-13
dmax=1
screen_radius=0.85d0
deltamin=1d-2
khold=1d0
angletor=0.05
k_bu=5d0
ramax=0.35d0
k_press=0.0d0!5d-1
m_xwall=0.0d0!0.75 !tooth
mi_xwall=0d0 !tooth
ndmax=9d4
!biological
!functions used
ffu=0
!spring of the ellipse
ffu(1)=1
ffu(2)=0 !to quit if there are too many cells
ffu(3)=0 !screening
ffu(4)=0 !torsion
ffu(5)=0 !external signal source
ffu(6)=0 !buoyancy
ffu(11)=0 !epithelial node plastic deformation
ffu(12)=1 !0 dynamic delta, 1 fixed delta
ffu(13)=0 !neighboring by triangulation
ffu(14)=1 !physical boundaries (walls)
ffu(17)=0 !volume conservation (epithelial)
ffu(22)=1 !0 = noise biased by energies , 1 = unbiased noise
ffu(24)=0
do i=1,nd
node(i)%you=0d0 ; node(i)%adh=5d-1
node(i)%rep=0d0 ; node(i)%repcel=5d-1
node(i)%req=0.4d0
node(i)%reqcr=0.4d0
node(i)%reqs=0d0
node(i)%da=0.5d0;
node(i)%ke=5d0
node(i)%tor=0d0
node(i)%stor=0d0
node(i)%mo=temp
node(i)%dmo=0
node(i)%diffe=0d0
node(i)%khold=0d0
node(i)%kplast=0d0
node(i)%kvol=0d0
end do
!General parameters that depend on node parameters
rv=2*maxval(node(:)%da)
node(:)%hold=0
r_max = (nd/ 0.64)**(1d0/3d0) * 0.4d0;
do i=1,nd
cels(i)%nunodes=1
cels(i)%nodela=1
allocate(cels(i)%node(1))
call random_number(a)
r = r_max * a**(1d0/3d0);
call random_number(a)
phi = a * 2d0 * pi;
call random_number(a)
theta = acos(2d0 * a - 1);
node(i)%x=r * sin(theta) * cos(phi)
node(i)%y=r * sin(theta) * sin(phi)
node(i)%z=r * cos(theta)
node(i)%marge=0
node(i)%tipus=3
cels(i)%node(1)=i
node(i)%icel=i
node(i)%altre=0
cels(i)%ctipus=3
cels(i)%cex=node(i)%x;cels(i)%cey=node(i)%y;cels(i)%cez=node(i)%z
end do
!******* #3 DEFINING CELL PARAMETERS *******
do i=1,ncels
cels(i)%fase=0d0
mmae=node(cels(i)%node(1))%req
cels(i)%minsize_for_div=cels(i)%nunodes*2
cels(i)%maxsize_for_div=10000 !>>> Is 5-2-14
end do
do i=1,ncels !cells start with at random points of the cell cycle, so the divisions are not synchronous
!if(i<=7.or.(i>ncelsepi.and.i<=ncelsepi+7))then
call random_number(a)
cels(i)%fase=a
!end if
end do
!******* #4 DEFINING GENETIC PARAMETERS *******
!Number of genes
ng=1
call initiate_gene
!Gene parameters
!gen(:)%kindof= ; gen(:)%diffu= ; gen(:)%mu=
gen(1)%kindof=1 ; gen(1)%diffu=0d0 ; gen(1)%mu=0d0 ;gen(1)%name="does nothing"
call update_npag
node(:)%talone=0.0d0
end subroutine
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// Integrate N-body problem with limited range springs between all bodies
#include "../include/dtypes.cuh"
#include "../include/inits.cuh"
#include "../include/solvers.cuh"
#include "../include/vtk.cuh"
const auto L_0 = 0.75f; // Relaxed spring length
const auto n_cells = 1000;
const auto n_time_steps = 600u; // Half of Chaste, because 2nd order
const auto dt = 0.001f;
__device__ float3 spring(float3 Xi, float3 r, float dist, int i, int j)
{
float3 dF{0};
if (i == j) return dF;
if (dist > 1) return dF;
dF = r * (L_0 - dist) / dist;
return dF;
}
int main(int argc, const char* argv[])
{
// Prepare initial state
Solution<float3, Grid_solver> bolls{n_cells};
random_sphere(L_0, bolls);
// Integrate positions
Vtk_output output("performance");
for (auto time_step = 0; time_step <= n_time_steps; time_step++) {
bolls.copy_to_host();
bolls.take_step<spring, friction_on_background>(dt);
output.write_positions(bolls);
}
return 0;
}
/*
Copyright (c) 2017, European Molecular Biology Laboratory.
Copyright (c) 2005-2017, University of Oxford.
All rights reserved.
University of Oxford means the Chancellor, Masters and Scholars of the
University of Oxford, having an administrative office at Wellington
Square, Oxford OX1 2JD, UK.
This file is part of Chaste.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the University of Oxford nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <cxxtest/TestSuite.h>
#include "CheckpointArchiveTypes.hpp"
#include "AbstractCellBasedTestSuite.hpp"
#include "CellsGenerator.hpp"
#include "GeneralisedLinearSpringForce.hpp"
#include "HoneycombMeshGenerator.hpp"
#include "NodeBasedCellPopulation.hpp"
#include "NodesOnlyMesh.hpp"
#include "OffLatticeSimulation.hpp"
#include "SmartPointers.hpp"
#include "SphereGeometryBoundaryCondition.hpp"
#include "TransitCellProliferativeType.hpp"
#include "UniformCellCycleModel.hpp"
#include "PetscSetupAndFinalize.hpp"
#include "AbstractSimpleGenerationalCellCycleModel.hpp"
class TestPerformance : public AbstractCellBasedTestSuite
{
public:
void TestSpheroid()
{
EXIT_IF_PARALLEL;
// Prepare initial state
auto t_0 = time(NULL);
auto n_cells = 100;
auto dist_to_nb = 0.75;
auto r_max = pow(n_cells / 0.64, 1. / 3) * dist_to_nb / 2;
std::vector<Node<3>*> nodes;
for (auto i = 0; i < n_cells; i++)
{
auto r = r_max * pow(rand() / (RAND_MAX + 1.), 1. / 3);
auto phi = rand() / (RAND_MAX + 1.) * 2 * M_PI;
auto theta = acos(2. * rand() / (RAND_MAX + 1.) - 1);
nodes.push_back(new Node<3>(i, false, r * sin(theta) * cos(phi),
r * sin(theta) * sin(phi), r * cos(theta)));
}
NodesOnlyMesh<3> mesh;
mesh.ConstructNodesWithoutMesh(nodes, 1.0); // Distance cut-off
std::vector<CellPtr> cells;
MAKE_PTR(TransitCellProliferativeType, p_transit_type);
CellsGenerator<UniformCellCycleModel, 3> cells_generator;
cells_generator.GenerateBasicRandom(cells, mesh.GetNumNodes(), p_transit_type);
NodeBasedCellPopulation<3> cell_population(mesh, cells);
// Setup simulation
OffLatticeSimulation<3> simulator(cell_population);
simulator.SetOutputDirectory("TestPerformance");
simulator.SetSamplingTimestepMultiple(100); // Writes twelve timesteps
simulator.SetEndTime(10.0);
simulator.SetNoBirth(true);
MAKE_PTR(GeneralisedLinearSpringForce<3>, p_force);
p_force->SetMeinekeDivisionRestingSpringLength(0.75);
simulator.AddForce(p_force);
// Run simulation
simulator.Solve();
auto t_f = time(NULL);
auto duration = t_f - t_0;
if (duration < 60)
std::cout << duration << " seconds";
else if (duration < 60 * 60)
std::cout << duration / 60 << "m " << duration % 60 << "s";
else
std::cout << duration / 60 / 60 << "h " << duration % 60 * 60 << "m";
std::cout << " taken." << std::endl;
std::cout << "Timestep: " << simulator.GetDt() << std::endl; // Is 0.00833333
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment