
org.jbox2d.util.sph.SPHGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbox2d-library Show documentation
Show all versions of jbox2d-library Show documentation
A 2D java physics engine, a port of the C++ Box2d engine. This is the core physics engine.
/*******************************************************************************
* Copyright (c) 2011, Daniel Murphy
* All rights reserved.
*
* 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 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 DANIEL MURPHY 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.
******************************************************************************/
package org.jbox2d.util.sph;
import org.jbox2d.collision.AABB;
import org.jbox2d.common.MathUtils;
import org.jbox2d.common.Vec2;
//Some default values are in Master.cpp
public class SPHGroup {
public SmoothParticle[] t;
public Parameter param;
public SPHGroup(int nParts, AABB aabb, float tStep) {
// set the parameters to some default values
param = new Parameter();
param.numPts = nParts;
param.initVel = new Vec2(0.0f,0.0f);
param.machNum = 0.5;
param.initDensity = 1000.0;
param.initPressure = 10000.0f;
param.nu = 1000.0;
param.deltaT = tStep;
param.numSteps = 500000;
param.outputEvery = 5000;
param.firstOutput = 0;
param.densityVariation = 0.3;
param.lengthScale = 1000.0;
param.bodyFX = 0.0;
param.bodyFY = 0.0;
param.c = 1.0f;
param.h = 1000.0f;
t = new SmoothParticle[nParts];
for (int i=0; i maxAccelSquared)
maxAccelSquared = accelSquared;
}
}
double calcDeltaT = 10000000;
if(maxAccelSquared > 0.0) {
calcDeltaT = 0.25*Math.sqrt(param.h / Math.sqrt(maxAccelSquared));
}
if(calcDeltaT < param.deltaT) {
System.out.println("current DT: " + param.deltaT + " is not small enough.");
System.out.println("It should be: " + calcDeltaT);
}
}
/**
* Handle a time step, including SPH forces
*/
public void updateParticles() {
calcPressure();
// Interact
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy