From 8c6b4b6b3bd9c17e21141423b03c999aed800648 Mon Sep 17 00:00:00 2001 From: Chloe Mimeau <Chloe.Mimeau@imag.fr> Date: Mon, 3 Feb 2014 10:29:02 +0000 Subject: [PATCH] Delete old test and fix bug for the printing of Noca forces in an output file --- .../hysop/operator/monitors/compute_forces.py | 23 ++++++--- HySoP/hysop/operator/tests/test_forces.py | 50 ------------------- 2 files changed, 16 insertions(+), 57 deletions(-) delete mode 100644 HySoP/hysop/operator/tests/test_forces.py diff --git a/HySoP/hysop/operator/monitors/compute_forces.py b/HySoP/hysop/operator/monitors/compute_forces.py index da84c6436..38099234b 100644 --- a/HySoP/hysop/operator/monitors/compute_forces.py +++ b/HySoP/hysop/operator/monitors/compute_forces.py @@ -24,7 +24,7 @@ class DragAndLift(Monitoring): The present class implements formula (52) of Plouhmans2002. Integral inside the obstacle is not taken into account. """ - def __init__(self, velocity, vorticity, topo, volumeOfControl, + def __init__(self, velocity, vorticity, nu, coefForce, topo, volumeOfControl, obstacles=None, frequency=1, filename=None, safeOutput=None): """ @param velocity field @@ -77,6 +77,11 @@ class DragAndLift(Monitoring): self.vd = None # discrete vorticity field self.wd = None + # viscosity + self.nu = nu + # Normalizing coefficient for forces + # (based on the physics of the flow) + self.coefForce = coefForce # Output file if filename is None: self._writeOuput = False @@ -98,9 +103,11 @@ class DragAndLift(Monitoring): ## during finalize. Cost less but if simu ## crashes, data are lost. self.safeOutput = True + else: + self.safeOutput = safeOutput + if self.safeOutput: self._writeFile = self._fullwrite else: - self.safeOutput = False self._writeFile = self._partialwrite self._file = open(self.filename, 'w') @@ -180,6 +187,8 @@ class DragAndLift(Monitoring): # Reduce results over all MPI process in topo self.mpi_sum() + self.force *= self.coefForce + # Print results, if required if self._writeOuput and self.topo.rank == 0 and (ite % self.freq) == 0: dataout = npw.zeros((1,4)) @@ -230,20 +239,20 @@ class DragAndLift(Monitoring): # Last part # Update fd schemes so to compute laplacian and other derivatives - # only on the surface (i.e. for liste of indices in sl) + # only on the surface (i.e. for list of indices in sl) self._laplacian.fd_scheme.computeIndices(sl) for j in i2: self._work[...] = self._laplacian(vdata[j], self._work) - res[i1] += self._coeff * normal[i1] * np.sum(coords[j] + res[i1] += self._coeff * self.nu * normal[i1] * np.sum(coords[j] * self._work[sl]) - res[j] -= self._coeff * normal[i1] * coords[i1] * \ + res[j] -= self._coeff * self.nu * normal[i1] * coords[i1] * \ np.sum(self._work[sl]) self._fd_scheme.computeIndices(sl) self._fd_scheme.compute(vdata[i1], i1, self._work) - res[i1] += normal[i1] * np.sum(self._work[sl]) + res[i1] += normal[i1] * self.nu * np.sum(self._work[sl]) for j in i2: self._fd_scheme.compute(vdata[i1], j, self._work) - res[j] += normal[i1] * np.sum(self._work[sl]) + res[j] += normal[i1] * self.nu * np.sum(self._work[sl]) res *= dsurf return res diff --git a/HySoP/hysop/operator/tests/test_forces.py b/HySoP/hysop/operator/tests/test_forces.py deleted file mode 100644 index ac74f094a..000000000 --- a/HySoP/hysop/operator/tests/test_forces.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -import parmepy as pp -import numpy as np -from parmepy.domain.obstacle.sphere import Sphere -from parmepy.mpi.topology import Cartesian -from parmepy.operator.monitors.compute_forces import Forces -from parmepy.fields.continuous import Field -from parmepy.problem.simulation import Simulation -import math as m -cos = np.cos -sin = np.sin - - -def computeVel(res, x, y, z, t): - res[0][...] = sin(x) * cos(y) * cos(z) - res[1][...] = - cos(x) * sin(y) * cos(z) - res[2][...] = 0. - return res - -def computeVort(res, x, y, z, t): - res[0][...] = - cos(x) * sin(y) * sin(z) - res[1][...] = - sin(x) * cos(y) * sin(z) - res[2][...] = 2. * sin(x) * sin(y) * cos(z) - return res - -nb = 33 -Lx = Ly = Lz = 1 -dom = pp.Box(dimension=3, length=[Lx, Ly, Lz], origin=[0., 0., 0.]) -resol = [nb, nb, nb] -velo = Field(domain=dom,formula=computeVel, name='Velo', isVector=True) -vorti = Field(domain=dom, formula=computeVort, name='Vorti', isVector=True) -sphere = Sphere(dom, position=[0.4, 0.5, 0.5], radius=0.15) - -ghosts = np.ones((dom.dimension)) * 2.0 -topo = Cartesian(dom, dom.dimension, resol, ghosts=ghosts) - -forces = Forces(velo, vorti, topo, - obstacle=sphere, boxMin= [0., 0., 0.], - boxMax= [1., 1., 1.], Reynolds=200., - method='', frequency=1, prefix='./Noca_sphere') - -# initializations & setups -forces.setUp() -velo.discretize(topo) -velo.initialize() -vorti.discretize(topo) -vorti.initialize() -simu = Simulation() -forces.apply(simu) -ind = topo.mesh.iCompute -- GitLab