CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Creating new patch shape for mesh

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 28, 2024, 07:18
Default Creating new patch shape for mesh
  #1
New Member
 
Laura Callegari
Join Date: Feb 2024
Posts: 1
Rep Power: 0
lauracalle is on a distinguished road
Hello,


I have been wanting to create a new file like cylinderToCell to patch a mesh with a conical shape instead of a cylindric one.



To do so, I created a new folder under the path: /src/meshTools/sets/cellSources/



coneToCell and I copied the files in the existing directory cylinderToCell but I changed the code to create a cone. In particular these are files that I wrote:


for coneToCell.C


/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "coneToCell.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
defineTypeNameAndDebug(coneToCell, 0);
addToRunTimeSelectionTable(topoSetSource, coneToCell, word);
}


// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

void Foam::coneToCell::combine(topoSet& set, const bool add) const
{
const vector axis = apex_ - baseCenter_;
const scalar magAxis2 = magSqr(axis);
const scalar theta = atan(radius_ / sqrt(magAxis2)); // Calcolo dell'angolo θ al vertice del cono completo
const pointField& ctrs = mesh_.cellCentres();


forAll(ctrs, celli)
{
vector d = ctrs[celli] - baseCenter_;
scalar magD = d & axis; // Proiezione del vettore della cella sull'asse del cono

if (magD > 0 && magD < magAxis2)
{
scalar coneRadius = radius_ - (magD * tan(theta)); // Calcolo del raggio del cono all'altezza della cella

// Verifica se l'altezza del punto della cella è inferiore al raggio del cono all'altezza della cella
scalar height = sqrt(magSqr(d) - sqr(magD) / magAxis2);
if (height < coneRadius)
{
addOrDelete(set, celli, add);
}
}
}
}




// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::coneToCell::coneToCell
(
const polyMesh& mesh,
const vector& baseCenter,
const vector& apex,
const scalar radius
)
:
topoSetSource(mesh),
baseCenter_(baseCenter),
apex_(apex),
radius_(radius)
{}


Foam::coneToCell::coneToCell
(
const polyMesh& mesh,
const dictionary& dict
)
:
topoSetSource(mesh),
baseCenter_(dict.lookupBackwardsCompatible<point>( {"baseCenter", "bc"})),
apex_(dict.lookupBackwardsCompatible<point>({"apex ", "apex"})),
radius_(dict.lookup<scalar>("radius"))
{}


// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

Foam::coneToCell::~coneToCell()
{}


// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

void Foam::coneToCell::applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const
{
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
{
Info<< " Adding cells with centre within cone, with baseCenter = "
<< baseCenter_ << ", apex = " << apex_ << " and radius = "
<< radius_ << endl;

combine(set, true);
}
else if (action == topoSetSource:ELETE)
{
Info<< " Removing cells with centre within cone, with baseCenter = "
<< baseCenter_ << ", apex = " << apex_ << " and radius = "
<< radius_ << endl;

combine(set, false);
}
}

// ************************************************** *********************** //







and for coneToCell.H






/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Class
Foam::coneToCell

Description
A topoSetSource to select cells based on cell centres inside a cone.

SourceFiles
coneToCell.C

\*---------------------------------------------------------------------------*/

#ifndef coneToCell_H
#define coneToCell_H

#include "topoSetSource.H"

namespace Foam
{

class coneToCell : public topoSetSource
{
private:
vector baseCenter_; // Base center of the cone
vector apex_; // Apex of the cone
scalar radius_; // Radius

void combine(topoSet& set, const bool add) const;

public:
//- Runtime type information
TypeName("coneToCell");

// Constructors
coneToCell(const polyMesh& mesh,
const vector& baseCenter,
const vector& apex,
const scalar radius);

coneToCell(const polyMesh& mesh, const dictionary& dict);

//- Destructor
virtual ~coneToCell();

// Member Functions
virtual sourceType setType() const { return CELLSETSOURCE; }

virtual void applyToSet(const topoSetSource::setAction action, topoSet& set) const;
};

} // End namespace Foam

#endif









In order to compile the files, I added a directory called Make, containing two files: "files" and "options" which are written like:


files:


coneToCell.C


EXE = $(FOAM_APPBIN)/coneToCell





options:


EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude

EXE_LIBS = \
-lfiniteVolume \
-lmeshTools






then inside the coneToCell directory I typed "wmake" and this is the output that I got:



Making dependency list for source file coneToCell.C
g++ -std=c++14 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/home/avio/OpenFOAM/OpenFOAM-10/src/fini
teVolume/lnInclude -I/home/avio/OpenFOAM/OpenFOAM-10/src/meshTools/lnInclude -IlnInclude -I. -I/home/avio/OpenFOAM/OpenFOAM-10/src/OpenFOAM/lnInclude -I/home/avio/OpenFOAM/OpenFOAM-10/src/OSspecific/POSIX/lnInclude -fPIC -c coneToCell.C -o /home/avio/OpenFOAM/OpenFOAM
-10/platforms/linux64GccDPInt32Opt/src/meshTools/sets/cellSources/coneToCell/coneToCell.o
g++ -std=c++14 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/home/avio/OpenFOAM/OpenFOAM-10/src/fini
teVolume/lnInclude -I/home/avio/OpenFOAM/OpenFOAM-10/src/meshTools/lnInclude -IlnInclude -I. -I/home/avio/OpenFOAM/OpenFOAM-10/src/OpenFOAM/lnInclude -I/home/avio/OpenFOAM/OpenFOAM-10/src/OSspecific/POSIX/lnInclude -fPIC -fuse-ld=bfd -Xlinker --add-needed -Xlinker --n
o-as-needed /home/avio/OpenFOAM/OpenFOAM-10/platforms/linux64GccDPInt32Opt/src/meshTools/sets/cellSources/coneToCell/coneToCell.o -L/home/avio/OpenFOAM/OpenFOAM-10/platforms/linux64GccDPInt32Opt/lib \
-lfiniteVolume -lmeshTools -lOpenFOAM -ldl \
-lm -o /home/avio/OpenFOAM/OpenFOAM-10/platforms/linux64GccDPInt32Opt/bin/coneToCell
/usr/bin/ld.bfd: /usr/lib64/gcc/x86_64-suse-linux/7/../../../../lib64/crt1.o: in function `_start':
/home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:104: undefined reference to `main'
collect2: error: ld returned 1 exit status

I do not understand what "main" refers to. Does anyone know what the problem is?


Thank you
lauracalle is offline   Reply With Quote

Reply

Tags
cylindertocell, main c++ file, patches, wmake


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 06:37
PIMPLE Stability CallumG OpenFOAM Running, Solving & CFD 3 July 16, 2022 05:17
[Commercial meshers] Fluent3DMeshToFoam simvun OpenFOAM Meshing & Mesh Conversion 50 January 19, 2020 16:33
Near wall treatment in k-omega SST Arnoldinho OpenFOAM Running, Solving & CFD 38 March 8, 2017 14:48
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 18:51


All times are GMT -4. The time now is 14:21.