Openfoam, multiphaseInterfoam, non-constant inlet - openfoam

I run multiphaseInterfoam, and I have trouble with the inlet being non-constant (I want it to be constant.)
Here are my alpha-files\
/--------------------------------- C++
-----------------------------------\
FoamFile {
version 2.0;
format ascii;
class volScalarField;
location "0";
object alpha.air; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField {
//- Set patchGroups for constraint patches
#includeEtc "caseDicts/setConstraintTypes"
inlet
{
type alphaContactAngle;
thetaProperties
(
( freshWater air ) 90 0 0 0
( saltWater air ) 90 0 0 0
( freshWater saltWater ) 90 0 0 0
);
value uniform 0;
}
outlet
{
type alphaContactAngle;
thetaProperties
(
( freshWater air ) 90 0 0 0
( saltWater air ) 90 0 0 0
( freshWater saltWater ) 90 0 0 0
);
value uniform 0;
}
atmosphere
{
type inletOutlet;
inletValue uniform 1;
value uniform 1;
}
barge
{
type alphaContactAngle;
thetaProperties
(
( freshWater air ) 90 0 0 0
( saltWater air ) 90 0 0 0
( freshWater saltWater ) 90 0 0 0
);
value uniform 0;
} }
alpha.freshwater:
/--------------------------------- C++
-----------------------------------\
FoamFile {
version 2.0;
format ascii;
class volScalarField;
location "0";
object alpha.freshWater; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField {
//- Set patchGroups for constraint patches
#includeEtc "caseDicts/setConstraintTypes"
inlet
{
type fixedValue;
value $internalField;
}
outlet
{
type variableHeightFlowRate;
lowerBound 0;
upperBound 1;
value $internalField;
}
atmosphere
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
barge
{
type zeroGradient;
} }
alpha.saltWater
FoamFile {
version 2.0;
format ascii;
class volScalarField;
location "0";
object alpha.saltWater; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField {
//- Set patchGroups for constraint patches
#includeEtc "caseDicts/setConstraintTypes"
inlet
{
type fixedValue;
value $internalField;
}
outlet
{
type variableHeightFlowRate;
lowerBound 0;
upperBound 1;
value $internalField;
}
atmosphere
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
barge
{
type zeroGradient;
} }
//
************************************************************************* //
alphas
/--------------------------------- C++
-----------------------------------\
FoamFile {
version 2.0;
format ascii;
class volScalarField;
location "0";
object alphas; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField {
//- Set patchGroups for constraint patches
#includeEtc "caseDicts/setConstraintTypes"
inlet
{
type fixedValue;
value $internalField;
}
outlet
{
type variableHeightFlowRate;
lowerBound 0;
upperBound 1;
value $internalField;
}
atmosphere
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
barge
{
type zeroGradient;
} }
//
************************************************************************* //
The above gives the following, wanted, distribtion of fluids for timestep 1
enter image description here
However, after several time the above changes, also at the inlet:
enter image description here
I really don't understand the contactAngle functino used in alpha.air above. I have tried with the following alpha.air
/--------------------------------- C++
-----------------------------------\
FoamFile {
version 2.0;
format ascii;
class volScalarField;
location "0";
object alpha.air; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField {
//- Set patchGroups for constraint patches
#includeEtc "caseDicts/setConstraintTypes"
inlet
{
type fixedValue;
value $internalField;
}
outlet
{
type variableHeightFlowRate;
lowerBound 0;
upperBound 1;
value $internalField;
}
atmosphere
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
barge
{
type zeroGradient;
} }
//
************************************************************************* //
With the alpha.air above I get a long error message that includes stuff that is interpreted as internet links so that I am not allowed to pulblish them here. The error message can be seen on this link to the CDF-online forum, where I have also have asked this question.
Does anybvody know how to modify the above files to make the distribution of alpha's at the inlet constant?

In the last version of alpa.air I changed from "internalField uniform 0" to "internalField uniform 1", and now the inlet is constant. I think the internalFIeld value has to equal the default value set in setFieldsDict.

Related

Null appearing at the end of for loop output in r

for (i in 1:9){
print(cat(replicate(i,"*"),"", replicate((9-i),'*')))
}
Output:
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * *NULL
* * * * * * * * * NULL
how to remove the null.
Remove print statement and use \n for new line.
for (i in 1:9){
cat(replicate(i,"*"),"", replicate((9-i),'*'), '\n')
}
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *

Ionic basic function inside class is not executing fully

calculate_distance(lat1: number, lat2: number, long1: number, long2: number) {
console.log("Inside getting calculate_distance");
console.log(lat1);
console.log(lat2);
console.log(long1);
console.log(long2);
let p = 0.017453292519943295; // Math.PI / 180
let c = Math.cos;
let a = 0.5 - c((lat1 - lat2) * p) / 2 + c(lat2 * p) * c((lat1) * p) * (1 - c(((long1 - long2) * p))) / 2;
let dis = (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
return dis.toFixed(2);
}
calling this function inside other function and i am not getting the distance value.
i just added a promise return type to my function. So that it will return me the value.
calculateDistance(lat1: number, lat2: number, long1: number, long2: number):Promise<any> {
console.log("Inside getting calculate_distance");
console.log(lat1);
console.log(lat2);
console.log(long1);
console.log(long2);
let p = 0.017453292519943295; // Math.PI / 180
let c = Math.cos;
let a = 0.5 - c((lat1 - lat2) * p) / 2 + c(lat2 * p) * c((lat1) * p) * (1 - c(((long1 - long2) * p))) / 2;
let dis = (12742 * Math.asin(Math.sqrt(a))); // 2 * R; R = 6371 km
return dis.toFixed(2);
}
and called calculateDistance like this
this.calculateDistance(this.my_lat, this.proj_lat, this.my_long, this.proj_long).then(result=>{
this.distance = String(result)
})

Printing a triangle in r

I'm trying to write some code to give me an output that looks like:
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Given my limited r experience the closest I got was:
for(i in 1:5) {
print(strrep("*", i))
}
for(i in 4:1) {
print(strrep("*", i))
}
which gives me:
# *
# **
# ***
# ****
# *****
and
# ****
# ***
# **
# *
Any guidance would be really helpful.
Thanks in advance!
Pad extra space
for(i in c(1:5, 4:1))
cat( paste0(strrep(" ", 5 - i), strrep("* ", i), "\n") )
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Symfony validation: range between two numbers, OR a value

I would like to validate a number to be between 10 and 20, or 30 and 40 or equal to 99.
I could imagine the code to be something similar to this, but it does not work:
In Entity\NameOfFile.php:
/*
* #Assert\Range(
* min=10,
* max=20
* )
*
* #Assert\Range(
* min=30,
* max=40
* )
*
* #Assert\IdenticalTo(value = 99)
*/
private $myVariable;
Or maybe something similar to this:
/*
* #Assert\Choice({
* Range({min = 10, max = 20}),
* Range({min = 10, max = 20}),
* 99
* )}
*/
private $myVariable;
I also added min and max messages.
In the first option, apparently only the first Assert is taken into consideration and the second one is ignored. The second option, does not work at all.
Ps: Please, a solution without Regex
EDIT:
Following the advice of M Khalid Juanid, the code looks like this:
/**
* #Assert\Expression(
* "this.getmyVariable() in 10..20 or this.getmyVariable() in 30..40 or this.getmyVariable() == 99",
* message="Your error message", groups{"groupA"}
* )
*private $myVariable;
*/
***
if($appendForm->isValid(array($groupA))
{
***
}
It works fine, but only when the validation is not assigned to groupA. How can, the validation be assigned to a group, in this case?
You can use #Assert\Expression for your mulitple criteria
/**
* #Assert\Expression(
* "this.checkRange()",
* message="Your error message"
* )
*/
class YourEntityName
{
public function checkRange(){
if(
($this->yourPorperty >= 10 && $this->yourPorperty <= 20)
|| ($this->yourPorperty >= 30 && $this->yourPorperty <= 40)
|| ($this->yourPorperty == 90)
){
return true;
}
return false;
}
}
As per docs The expression option is the expression that must return true in order for validation to pass
Even more simpler according to the documentation
/**
* #Assert\Expression(
* "this.getYourPorperty() in 10..20 or this.getYourPorperty() in 30..40 or this.getYourPorperty() == 90",
* message="Your error message"
* )
*/
You can use a custom validation constraint. To create one you can refer to the official documentation: http://symfony.com/doc/3.4/validation/custom_constraint.html
You will have to put all your constraints in the validate function of the Validator class.
Since Symfony 5.1, there is a new validator that can check if at least one of several constraints is met.
AtLeastOneOf
/**
* #Assert\AtLeastOneOf({
* #Assert\Range(
* min=10,
* max=20
* ),
* #Assert\Range(
* min=30,
* max=40
* ),
* #Assert\IdenticalTo(value = 99)
* })
*/
private $myVariable;

How to make an animated wave in threejs

I am trying to make an animated 3D wave with Three.js and Points. It is kind of working. It is starting slow and then the applitude is increasing. But after some time it gets too high and unsteady.
This is how it should be looking. However after some time it is loosing it's shape. The problem is the decreasing period of the sine and increasing amplitude. But I am failing to fix it.
Here is some code.
Creating of the points mesh.
this.particleGeometry = new Geometry()
for (let ix = 0; ix < this.WIDTH; ix++) {
for (let iz = 0; iz < this.HEIGHT; iz++) {
let vert = new Vector3()
vert.x = ix * this.SEPERATION - ((this.WIDTH * this.SEPERATION) / 2)
vert.y = (Math.cos((ix / this.WIDTH) * Math.PI * 6) + Math.sin((iz / this.HEIGHT) * Math.PI * 6))
vert.z = iz * this.SEPERATION - ((this.HEIGHT * this.SEPERATION) / 2)
this.particleGeometry.vertices.push(vert)
}
}
this.particleCloud = new Points(this.particleGeometry, this.material)
this.scene.add(this.particleCloud)
The initial generation is pretty good. But the updating is buggy.
animate() code:
render () {
let index = 0
let time = Date.now() * 0.00005
let h = (360 * (1.0 + time) % 360) / 360
this.theta += 0.0008
this.material.color.setHSL(h, 0.5, 0.5)
for (let ix = 0; ix < this.WIDTH; ix++) {
for (let iz = 0; iz < this.HEIGHT; iz++) {
this.particleCloud.geometry.vertices[index].y = (Math.cos((ix * this.theta / this.WIDTH) * Math.PI * 6) + Math.sin((iz * this.theta / this.HEIGHT) * Math.PI * 6))
index++
}
}
this.particleCloud.geometry.verticesNeedUpdate = true
this.updateGuiSettings()
this.renderer.render(this.scene, this.camera)
},
this.theta starts at 0 and then slowly increasing.
Okay, got it working with (Math.cos((ix / this.WIDTH * PI * 8 + this.theta)) + Math.sin((iz / this.HEIGHT * PI * 8 + this.theta)))
Now it is steady. However will tweak it maybe more.

Resources