diff --git a/codes/adt/include/AdtTree.h b/codes/adt/include/AdtTree.h
deleted file mode 100644
index b41f3ae44..000000000
--- a/codes/adt/include/AdtTree.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*---------------------------------------------------------------------------*\
- OneFLOW - LargeScale Multiphysics Scientific Simulation Environment
- Copyright (C) 2017-2026 He Xin and the OneFLOW contributors.
--------------------------------------------------------------------------------
-License
- This file is part of OneFLOW.
-
- OneFLOW 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.
-
- OneFLOW 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 OneFLOW. If not, see .
-
-\*---------------------------------------------------------------------------*/
-
-
-#pragma once
-#include "HXVector.h"
-#include
-#include
-
-#ifndef _WINDOWS
-#include
-#endif
-
-BeginNameSpace( ONEFLOW )
-
-template < typename T, typename U >
-class HXAdtNode
-{
-public:
- using AdtNode = HXAdtNode;
- using AdtNodeList = HXVector;
- using AdtNodeListIter = typename AdtNodeList::iterator;
-
-public:
- HXVector point; // Replaced raw pointer with HXVector for automatic memory management
- int level; // The level in the tree
- AdtNode * left; // The left child (non-owning raw pointer)
- AdtNode * right; // The right child (non-owning raw pointer)
- T item; // Any data stored
- int dim;
-public:
- HXAdtNode( int dim = 3 );
- HXAdtNode( int dim, U * coordinate, T data );
-
- // Intentionally does NOT delete left/right.
- // Memory is centrally managed by HXAdtTree to prevent recursive stack overflow.
- ~HXAdtNode();
-
- // Add an Adt node under the current node
- void AddNode( AdtNode * node, U * nwmin, U * nwmax, const int & dim );
-
- // Is the current node inside region ( pmin, pmax )?
- bool IsInRegion( U * pmin, U * pmax, const int & dim ) const;
-
- // ld carries all the nodes inside region ( pmin, pmax )
- void FindNodesInRegion( U * pmin, U * pmax, U * nwmin, U * nwmax, const int & dim, AdtNodeList & ld ) const;
-
- int nCount() const;
- T GetData() const { return item; }
-};
-
-
-template < typename T, typename U >
-class HXAdtTree
-{
-public:
- using AdtNode = typename HXAdtNode::AdtNode;
- using AdtNodeList = typename HXAdtNode::AdtNodeList;
- using AdtNodeListIter = typename HXAdtNode::AdtNodeListIter;
- using AdtTree = HXAdtTree;
-
-public:
- HXAdtTree( int dim = 3 );
- HXAdtTree( int dim, U * pmin_in, U * pmax_in );
- HXAdtTree( int dim, HXVector< U > & pmin_in, HXVector< U > & pmax_in );
-
- // Destructor relies on ownedNodes to safely clean up all nodes without recursion
- ~HXAdtTree();
-
- // Add an Adt node to the AdtTree (Tree takes ownership of the node)
- void AddNode( AdtNode * node );
-
- // Find all nodes inside the region ( pmin, pmax ) from the tree
- void FindNodesInRegion( U * pmin_in, U * pmax_in, AdtNodeList & ld ) const;
-
- int nCount() const;
-
- // Get the min coordinates of the tree
- U * GetMin() const;
-
- // Get the max coordinates of the tree
- U * GetMax() const;
-
-protected:
- int dim;
- HXVector pmin; // Replaced raw pointer with HXVector
- HXVector pmax; // Replaced raw pointer with HXVector
- AdtNode * root;
-
- // Centralized memory management: owns all nodes, preventing memory leaks and recursive destruction issues
- std::vector< std::unique_ptr > ownedNodes;
-};
-
-
-EndNameSpace
-
-#include "AdtTree.hpp"
diff --git a/codes/adt/include/AdtTree.hpp b/codes/adt/include/AdtTree.hpp
deleted file mode 100644
index 09a997127..000000000
--- a/codes/adt/include/AdtTree.hpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*---------------------------------------------------------------------------*\
- OneFLOW - LargeScale Multiphysics Scientific Simulation Environment
- Copyright (C) 2017-2025 He Xin and the OneFLOW contributors.
--------------------------------------------------------------------------------
-License
- This file is part of OneFLOW.
-
- OneFLOW 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.
-
- OneFLOW 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 OneFLOW. If not, see .
-
-\*---------------------------------------------------------------------------*/
-
-BeginNameSpace( ONEFLOW )
-
-// ============================================================================
-// Template Implementations: HXAdtNode
-// ============================================================================
-
-template < typename T, typename U >
-HXAdtNode::HXAdtNode( int dim )
-{
- this->dim = dim;
- point.resize(dim, static_cast(0));
- level = 0;
- left = nullptr;
- right = nullptr;
-}
-
-template < typename T, typename U >
-HXAdtNode::HXAdtNode( int dim, U * coordinate, T data )
-{
- this->dim = dim;
- point.resize(dim);
- std::memcpy( point.data(), coordinate, dim * sizeof( U ) );
-
- level = 0;
- left = nullptr;
- right = nullptr;
- item = data;
-}
-
-template < typename T, typename U >
-HXAdtNode::~HXAdtNode()
-{
- // Do NOT delete left or right here.
- // HXAdtTree centrally manages memory via std::unique_ptr to avoid deep recursion stack overflow.
- // HXVector 'point' cleans up its own memory automatically.
-}
-
-template < typename T, typename U >
-int HXAdtNode::nCount() const
-{
- int iCount = 1;
- if ( this->left != nullptr )
- {
- iCount += left->nCount();
- }
- if ( this->right != nullptr )
- {
- iCount += right->nCount();
- }
- return iCount;
-}
-
-// Add an Adt node under the current node
-template < typename T, typename U >
-void HXAdtNode::AddNode( AdtNode * node, U * nwmin, U * nwmax, const int & dim )
-{
- int axis = level % dim;
- U mid = static_cast(0.5) * ( nwmin[ axis ] + nwmax[ axis ] );
-
- if ( node->point[ axis ] <= mid )
- {
- if ( left != nullptr )
- {
- U originalMax = nwmax[ axis ];
- nwmax[ axis ] = mid;
- left->AddNode( node, nwmin, nwmax, dim );
- nwmax[ axis ] = originalMax; // Backtrack
- }
- else
- {
- left = node;
- node->level = level + 1;
- }
- }
- else
- {
- if ( right != nullptr )
- {
- U originalMin = nwmin[ axis ];
- nwmin[ axis ] = mid;
- right->AddNode( node, nwmin, nwmax, dim );
- nwmin[ axis ] = originalMin; // Backtrack
- }
- else
- {
- right = node;
- node->level = level + 1;
- }
- }
-}
-
-// Is the current node inside region ( pmin, pmax )?
-template < typename T, typename U >
-bool HXAdtNode::IsInRegion( U * pmin, U * pmax, const int & dim ) const
-{
- for ( int i = 0; i < dim; ++ i )
- {
- if ( point[ i ] < pmin[ i ] || point[ i ] > pmax[ i ] )
- {
- return false;
- }
- }
- return true;
-}
-
-// ld carries all the nodes inside region ( pmin, pmax )
-template < typename T, typename U >
-void HXAdtNode::FindNodesInRegion( U * pmin, U * pmax, U * nwmin, U * nwmax, const int & dim, AdtNodeList & ld ) const
-{
- if ( IsInRegion( pmin, pmax, dim ) )
- {
- // Cast to non-const pointer to match the original AdtNodeList type requirement
- ld.push_back( const_cast(this) );
- }
-
- int axis = level % dim;
- U mid = static_cast(0.5) * ( nwmin[ axis ] + nwmax[ axis ] );
-
- if ( left != nullptr )
- {
- if ( pmin[ axis ] <= mid && pmax[ axis ] >= nwmin[ axis ] )
- {
- U temp = nwmax[ axis ];
- nwmax[ axis ] = mid;
- left->FindNodesInRegion( pmin, pmax, nwmin, nwmax, dim, ld );
- nwmax[ axis ] = temp; // Backtrack
- }
- }
-
- if ( right != nullptr )
- {
- if ( pmax[ axis ] >= mid && pmin[ axis ] <= nwmax[ axis ] )
- {
- U temp = nwmin[ axis ];
- nwmin[ axis ] = mid;
- right->FindNodesInRegion( pmin, pmax, nwmin, nwmax, dim, ld );
- nwmin[ axis ] = temp; // Backtrack
- }
- }
-}
-
-// ============================================================================
-// Template Implementations: HXAdtTree
-// ============================================================================
-
-template < typename T, typename U >
-HXAdtTree::HXAdtTree( int dim )
-{
- this->dim = dim;
- pmin.resize(dim, static_cast(0.0));
- pmax.resize(dim, static_cast(1.0));
- root = nullptr;
-}
-
-template < typename T, typename U >
-HXAdtTree::HXAdtTree( int dim, U * pmin_in, U * pmax_in )
-{
- this->dim = dim;
- pmin.resize(dim);
- pmax.resize(dim);
- for ( int i = 0; i < dim; ++ i )
- {
- this->pmin[ i ] = pmin_in[ i ];
- this->pmax[ i ] = pmax_in[ i ];
- }
- root = nullptr;
-}
-
-template < typename T, typename U >
-HXAdtTree::HXAdtTree( int dim, HXVector< U > & pmin_in, HXVector< U > & pmax_in )
-{
- this->dim = dim;
- pmin = pmin_in;
- pmax = pmax_in;
- root = nullptr;
-}
-
-template < typename T, typename U >
-HXAdtTree::~HXAdtTree()
-{
- // std::vector of unique_ptr automatically cleans up all owned nodes safely.
- // No manual delete[] or recursive delete is needed, preventing stack overflow.
-}
-
-// Add an Adt node to the AdtTree
-template < typename T, typename U >
-void HXAdtTree::AddNode( AdtNode * node )
-{
- // Take ownership of the raw pointer immediately to prevent memory leaks
- ownedNodes.emplace_back( node );
-
- if ( root == nullptr )
- {
- root = node;
- return;
- }
-
- // Use local HXVector to avoid heap allocation (new/delete) during recursion
- HXVector localNwmin = this->pmin;
- HXVector localNwmax = this->pmax;
-
- root->AddNode( node, localNwmin.data(), localNwmax.data(), dim );
-}
-
-// Find all nodes inside the region ( pmin, pmax ) from the tree
-template < typename T, typename U >
-void HXAdtTree::FindNodesInRegion( U * pmin_in, U * pmax_in, AdtNodeList & ld ) const
-{
- if ( root == nullptr )
- {
- return;
- }
-
- // Use local HXVector to avoid heap allocation (new/delete) during recursion
- HXVector localNwmin = this->pmin;
- HXVector localNwmax = this->pmax;
-
- root->FindNodesInRegion( pmin_in, pmax_in, localNwmin.data(), localNwmax.data(), dim, ld );
-}
-
-template < typename T, typename U >
-int HXAdtTree::nCount() const
-{
- if ( root != nullptr )
- {
- return root->nCount();
- }
- return 0;
-}
-
-template < typename T, typename U >
-U * HXAdtTree::GetMin() const
-{
- // Return pointer to internal data.
- // Note: Caller should not modify this data, but signature is kept for backward compatibility.
- return const_cast(pmin.data());
-}
-
-template < typename T, typename U >
-U * HXAdtTree::GetMax() const
-{
- // Return pointer to internal data.
- return const_cast(pmax.data());
-}
-
-
-EndNameSpace
diff --git a/codes/adt/include/HXAdtTree.h b/codes/adt/include/HXAdtTree.h
new file mode 100644
index 000000000..5fbdc6438
--- /dev/null
+++ b/codes/adt/include/HXAdtTree.h
@@ -0,0 +1,287 @@
+/*---------------------------------------------------------------------------*\
+ OneFLOW - LargeScale Multiphysics Scientific Simulation Environment
+ Copyright (C) 2017-2026 He Xin and the OneFLOW contributors.
+-------------------------------------------------------------------------------
+License
+ This file is part of OneFLOW.
+
+ OneFLOW 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.
+
+ OneFLOW 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 OneFLOW. If not, see .
+
+\*---------------------------------------------------------------------------*/
+
+#pragma once
+
+#include "HXVector.h"
+#include
+#include
+#include
+#include
+
+#ifndef _WINDOWS
+#include
+#endif
+
+BeginNameSpace( ONEFLOW )
+
+// ============================================================================
+// Class Declaration & Implementation: HXAdtNode
+// ============================================================================
+
+template < typename T, typename U >
+class HXAdtNode
+{
+public:
+ using AdtNode = HXAdtNode;
+ using AdtNodeList = HXVector;
+ using AdtNodeListIter = typename AdtNodeList::iterator;
+
+public:
+ HXVector point; // Coordinate array managed automatically by HXVector
+ int level; // Depth level of the node in the tree
+ AdtNode * left; // Pointer to the left child node (non-owning)
+ AdtNode * right; // Pointer to the right child node (non-owning)
+ T item; // User data storage (payload)
+ int dim; // Spatial dimension count
+
+public:
+ explicit HXAdtNode( int dim = 3 )
+ : level( 0 ), left( nullptr ), right( nullptr ), dim( dim )
+ {
+ point.resize( dim, static_cast( 0 ) );
+ }
+
+ HXAdtNode( int dim, const U * coordinate, T data )
+ : level( 0 ), left( nullptr ), right( nullptr ), item( std::move( data ) ), dim( dim )
+ {
+ point.resize( dim );
+ std::memcpy( point.data(), coordinate, dim * sizeof( U ) );
+ }
+
+ // Centralized memory management via HXAdtTree avoids recursive destruction stack overflow
+ ~HXAdtNode() = default;
+
+ // Prevent accidental copying
+ HXAdtNode( const HXAdtNode& ) = delete;
+ HXAdtNode& operator=( const HXAdtNode& ) = delete;
+
+ // Allow move semantics
+ HXAdtNode( HXAdtNode&& ) noexcept = default;
+ HXAdtNode& operator=( HXAdtNode&& ) noexcept = default;
+
+ // Insert a child node into the current node
+ void AddNode( AdtNode * node, U * nwmin, U * nwmax, const int & dim )
+ {
+ const int axis = level % dim;
+ const U mid = static_cast( 0.5 ) * ( nwmin[ axis ] + nwmax[ axis ] );
+
+ if ( node->point[ axis ] <= mid )
+ {
+ if ( left != nullptr )
+ {
+ const U originalMax = nwmax[ axis ];
+ nwmax[ axis ] = mid;
+ left->AddNode( node, nwmin, nwmax, dim );
+ nwmax[ axis ] = originalMax; // Backtrack
+ }
+ else
+ {
+ left = node;
+ node->level = level + 1;
+ }
+ }
+ else
+ {
+ if ( right != nullptr )
+ {
+ const U originalMin = nwmin[ axis ];
+ nwmin[ axis ] = mid;
+ right->AddNode( node, nwmin, nwmax, dim );
+ nwmin[ axis ] = originalMin; // Backtrack
+ }
+ else
+ {
+ right = node;
+ node->level = level + 1;
+ }
+ }
+ }
+
+ // Check if the current node is within the query bounding box
+ [[nodiscard]] bool IsInRegion( const U * pmin, const U * pmax, const int & dim ) const
+ {
+ for ( int i = 0; i < dim; ++ i )
+ {
+ if ( point[ i ] < pmin[ i ] || point[ i ] > pmax[ i ] )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Retrieve all nodes located inside region (pmin, pmax)
+ void FindNodesInRegion( const U * pmin, const U * pmax, U * nwmin, U * nwmax, const int & dim, AdtNodeList & ld ) const
+ {
+ if ( IsInRegion( pmin, pmax, dim ) )
+ {
+ ld.push_back( const_cast( this ) );
+ }
+
+ const int axis = level % dim;
+ const U mid = static_cast( 0.5 ) * ( nwmin[ axis ] + nwmax[ axis ] );
+
+ if ( left != nullptr )
+ {
+ if ( pmin[ axis ] <= mid && pmax[ axis ] >= nwmin[ axis ] )
+ {
+ const U temp = nwmax[ axis ];
+ nwmax[ axis ] = mid;
+ left->FindNodesInRegion( pmin, pmax, nwmin, nwmax, dim, ld );
+ nwmax[ axis ] = temp; // Backtrack
+ }
+ }
+
+ if ( right != nullptr )
+ {
+ if ( pmax[ axis ] >= mid && pmin[ axis ] <= nwmax[ axis ] )
+ {
+ const U temp = nwmin[ axis ];
+ nwmin[ axis ] = mid;
+ right->FindNodesInRegion( pmin, pmax, nwmin, nwmax, dim, ld );
+ nwmin[ axis ] = temp; // Backtrack
+ }
+ }
+ }
+
+ [[nodiscard]] int nCount() const
+ {
+ int iCount = 1;
+ if ( this->left != nullptr ) iCount += left->nCount();
+ if ( this->right != nullptr ) iCount += right->nCount();
+ return iCount;
+ }
+
+ [[nodiscard]] T GetData() const { return item; }
+};
+
+
+// ============================================================================
+// Class Declaration & Implementation: HXAdtTree
+// ============================================================================
+
+template < typename T, typename U >
+class HXAdtTree
+{
+public:
+ using AdtNode = typename HXAdtNode::AdtNode;
+ using AdtNodeList = typename HXAdtNode::AdtNodeList;
+ using AdtNodeListIter = typename HXAdtNode::AdtNodeListIter;
+ using AdtTree = HXAdtTree;
+
+public:
+ explicit HXAdtTree( int dim = 3 )
+ : dim( dim ), root( nullptr )
+ {
+ pmin.resize( dim, static_cast( 0.0 ) );
+ pmax.resize( dim, static_cast( 1.0 ) );
+ }
+
+ HXAdtTree( int dim, const U * pmin_in, const U * pmax_in )
+ : dim( dim ), root( nullptr )
+ {
+ pmin.resize( dim );
+ pmax.resize( dim );
+ std::memcpy( pmin.data(), pmin_in, dim * sizeof( U ) );
+ std::memcpy( pmax.data(), pmax_in, dim * sizeof( U ) );
+ }
+
+ HXAdtTree( int dim, const HXVector & pmin_in, const HXVector & pmax_in )
+ : dim( dim ), pmin( pmin_in ), pmax( pmax_in ), root( nullptr )
+ {
+ }
+
+ // Destructor automatically cleans up all nodes safely via unique_ptr
+ ~HXAdtTree() = default;
+
+ // Prevent accidental copying
+ HXAdtTree( const HXAdtTree& ) = delete;
+ HXAdtTree& operator=( const HXAdtTree& ) = delete;
+
+ // Allow move semantics
+ HXAdtTree( HXAdtTree&& ) noexcept = default;
+ HXAdtTree& operator=( HXAdtTree&& ) noexcept = default;
+
+ // Insert a node into the ADT tree (tree takes memory ownership)
+ void AddNode( AdtNode * node )
+ {
+ if ( node == nullptr ) return;
+
+ // Take ownership of memory to prevent memory leaks and stack overflows
+ ownedNodes.emplace_back( node );
+
+ if ( root == nullptr )
+ {
+ root = node;
+ return;
+ }
+
+ // Allocate local vectors to ensure thread-safe backtracking without global side effects
+ HXVector localNwmin = this->pmin;
+ HXVector localNwmax = this->pmax;
+
+ root->AddNode( node, localNwmin.data(), localNwmax.data(), dim );
+ }
+
+ // Find all nodes falling inside region (pmin, pmax)
+ void FindNodesInRegion( const U * pmin_in, const U * pmax_in, AdtNodeList & ld ) const
+ {
+ if ( root == nullptr )
+ {
+ return;
+ }
+
+ HXVector localNwmin = this->pmin;
+ HXVector localNwmax = this->pmax;
+
+ root->FindNodesInRegion( pmin_in, pmax_in, localNwmin.data(), localNwmax.data(), dim, ld );
+ }
+
+ [[nodiscard]] int nCount() const
+ {
+ return root ? root->nCount() : 0;
+ }
+
+ // Get min bounding coordinates
+ [[nodiscard]] U * GetMin() const
+ {
+ return const_cast( pmin.data() );
+ }
+
+ // Get max bounding coordinates
+ [[nodiscard]] U * GetMax() const
+ {
+ return const_cast( pmax.data() );
+ }
+
+protected:
+ int dim;
+ HXVector pmin; // Min boundary array
+ HXVector pmax; // Max boundary array
+ AdtNode * root;
+
+ // Centrally managed node memory: prevents memory leaks and recursive destruction stack overflows
+ std::vector< std::unique_ptr > ownedNodes;
+};
+
+EndNameSpace
\ No newline at end of file
diff --git a/codes/chemical/include/Chemical.h b/codes/chemical/include/Chemical.h
index 0863d703e..c3333f961 100644
--- a/codes/chemical/include/Chemical.h
+++ b/codes/chemical/include/Chemical.h
@@ -21,6 +21,7 @@ License
\*---------------------------------------------------------------------------*/
#pragma once
#include "HXDefine.h"
+#include
BeginNameSpace( ONEFLOW )
@@ -42,11 +43,11 @@ class Chemical
Chemical();
~Chemical();
public:
- MolecularProperty * moleProp;
- ReactionRate * reactionRate;
- Stoichiometric * stoichiometric;
- BlotterCurve * blotterCurve;
- Thermodynamic * thermodynamic;
+ std::unique_ptr< MolecularProperty > moleProp;
+ std::unique_ptr< ReactionRate > reactionRate;
+ std::unique_ptr< Stoichiometric > stoichiometric;
+ std::unique_ptr< BlotterCurve > blotterCurve;
+ std::unique_ptr< Thermodynamic > thermodynamic;
int nSpecies, nReaction;
public:
//working variables
diff --git a/codes/chemical/include/MolecularProperty.h b/codes/chemical/include/MolecularProperty.h
index 539e3f9f1..875018ddf 100644
--- a/codes/chemical/include/MolecularProperty.h
+++ b/codes/chemical/include/MolecularProperty.h
@@ -21,6 +21,7 @@ License
\*---------------------------------------------------------------------------*/
#pragma once
#include "HXDefine.h"
+#include
BeginNameSpace( ONEFLOW )
@@ -44,7 +45,7 @@ class MolecularProperty
StringField species_name;
IntField ion_type;
RealField cs; //collision cross section
- SchmidtNumber * schmidtNumber;
+ std::unique_ptr< SchmidtNumber > schmidtNumber;
Real dim_amw; //dimensional average molecular weight
Real amw; //average molecular weight
public:
diff --git a/codes/chemical/include/Thermodynamic.h b/codes/chemical/include/Thermodynamic.h
index a40e030be..096dbf240 100644
--- a/codes/chemical/include/Thermodynamic.h
+++ b/codes/chemical/include/Thermodynamic.h
@@ -21,6 +21,7 @@ License
\*---------------------------------------------------------------------------*/
#pragma once
#include "HXDefine.h"
+#include
BeginNameSpace( ONEFLOW )
@@ -50,7 +51,7 @@ class Thermodynamic
public:
int nSpecies;
int nTSpan, nPolyCoef;
- HXVector< ThermodynamicFunction * > tfunction;
+ HXVector< std::unique_ptr< ThermodynamicFunction > > tfunction;
RealField trange;
public:
void Init( int nSpecies );
diff --git a/codes/chemical/src/Chemical.cpp b/codes/chemical/src/Chemical.cpp
index 05979d32e..96410f20d 100644
--- a/codes/chemical/src/Chemical.cpp
+++ b/codes/chemical/src/Chemical.cpp
@@ -20,6 +20,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Chemical.h"
+#include
#include "MolecularProperty.h"
#include "ReactionRate.h"
#include "Stoichiometric.h"
@@ -53,20 +54,20 @@ Chemical::~Chemical()
void Chemical::Alloc()
{
- moleProp = new MolecularProperty();
- reactionRate = new ReactionRate();
- stoichiometric = new Stoichiometric();
- blotterCurve = new BlotterCurve();
- thermodynamic = new Thermodynamic();
+ moleProp = std::make_unique< MolecularProperty >();
+ reactionRate = std::make_unique< ReactionRate >();
+ stoichiometric = std::make_unique< Stoichiometric >();
+ blotterCurve = std::make_unique< BlotterCurve >();
+ thermodynamic = std::make_unique< Thermodynamic >();
}
void Chemical::DeAlloc()
{
- delete moleProp;
- delete reactionRate;
- delete stoichiometric;
- delete blotterCurve;
- delete thermodynamic;
+ moleProp.reset();
+ reactionRate.reset();
+ stoichiometric.reset();
+ blotterCurve.reset();
+ thermodynamic.reset();
}
void Chemical::InitGasModel()
diff --git a/codes/chemical/src/MolecularProperty.cpp b/codes/chemical/src/MolecularProperty.cpp
index f160fde2b..0905001c1 100644
--- a/codes/chemical/src/MolecularProperty.cpp
+++ b/codes/chemical/src/MolecularProperty.cpp
@@ -20,6 +20,7 @@ License
\*---------------------------------------------------------------------------*/
#include "MolecularProperty.h"
+#include
#include "SchmidtNumber.h"
#include "TextFileParser.h"
#include "DataBook.h"
@@ -29,12 +30,11 @@ BeginNameSpace( ONEFLOW )
MolecularProperty::MolecularProperty()
{
- schmidtNumber = new SchmidtNumber();
+ schmidtNumber = std::make_unique< SchmidtNumber >();
}
MolecularProperty::~MolecularProperty()
{
- delete schmidtNumber;
}
void MolecularProperty::Init( int nSpecies )
diff --git a/codes/chemical/src/Thermodynamic.cpp b/codes/chemical/src/Thermodynamic.cpp
index 7615aeb2b..d93087619 100644
--- a/codes/chemical/src/Thermodynamic.cpp
+++ b/codes/chemical/src/Thermodynamic.cpp
@@ -20,6 +20,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Thermodynamic.h"
+#include
#include "TextFileParser.h"
#include "DataBook.h"
#include "DataBaseIO.h"
@@ -91,11 +92,6 @@ Thermodynamic::Thermodynamic()
Thermodynamic::~Thermodynamic()
{
- size_t nSize = tfunction.size();
- for ( int i = 0; i < nSize; ++ i )
- {
- delete tfunction[ i ];
- }
}
void Thermodynamic::Init( int nSpecies )
@@ -104,7 +100,7 @@ void Thermodynamic::Init( int nSpecies )
tfunction.resize( nSpecies );
for ( int i = 0; i < nSpecies; ++ i )
{
- tfunction[ i ] = new ThermodynamicFunction();
+ tfunction[ i ] = std::make_unique< ThermodynamicFunction >();
}
}
diff --git a/codes/geometry/include/PointLocator.h b/codes/geometry/include/PointLocator.h
index 458febfa9..46fc779bb 100644
--- a/codes/geometry/include/PointLocator.h
+++ b/codes/geometry/include/PointLocator.h
@@ -23,7 +23,7 @@ License
#pragma once
#include "HXDefine.h"
-#include "AdtTree.h"
+#include "HXAdtTree.h"
#include "GridHandles.h"
BeginNameSpace( ONEFLOW )
diff --git a/codes/geometry/src/UnsGrid.cpp b/codes/geometry/src/UnsGrid.cpp
index efae5a87b..b499c000d 100644
--- a/codes/geometry/src/UnsGrid.cpp
+++ b/codes/geometry/src/UnsGrid.cpp
@@ -21,6 +21,7 @@ License
\*---------------------------------------------------------------------------*/
#include "UnsGrid.h"
+#include
#include "BcRecord.h"
#include "InterFace.h"
#include "HXMath.h"
@@ -452,11 +453,9 @@ void UnsGrid::GetMinMaxDistance( Real & dismin, Real & dismax )
void UnsGrid::WriteGrid( std::fstream & file )
{
- DataBook * databook = new DataBook();
- this->WriteGrid( databook );
+ auto databook = std::make_unique< DataBook >();
+ this->WriteGrid( databook.get() );
databook->WriteFile( file );
- delete databook;
-
}
diff --git a/codes/ins/src/INsRhs.cpp b/codes/ins/src/INsRhs.cpp
index ba15b6373..ef8837ddb 100644
--- a/codes/ins/src/INsRhs.cpp
+++ b/codes/ins/src/INsRhs.cpp
@@ -44,6 +44,7 @@ License
//#include "UINsUnsteady.h"
#include "UINsBcSolver.h"
#include
+#include
BeginNameSpace( ONEFLOW )
@@ -65,10 +66,9 @@ void INsRhs::UpdateResiduals()
void INsCalcBc()
{
- UINsBcSolver * uINsBcSolver = new UINsBcSolver();
+ auto uINsBcSolver = std::make_unique();
uINsBcSolver->Init();
uINsBcSolver->CalcBc();
- delete uINsBcSolver;
}
void INsCalcGamaT(int flag)
@@ -128,100 +128,87 @@ void INsCalcRHS()
void INsCalcTimeStep()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcINsTimeStep();
- delete uINsInvterm;
}
void INsPreflux()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcINsPreflux();
- delete uINsInvterm;
}
void INsCalcInv()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcInvcoff();
- delete uINsInvterm;
}
void INsCalcVis()
{
- UINsVisterm * uINsVisterm = new UINsVisterm();
+ auto uINsVisterm = std::make_unique();
uINsVisterm->CalcViscoff();
- delete uINsVisterm;
}
void INsCalcUnstead()
{
- UINsVisterm * uINsVisterm = new UINsVisterm();
+ auto uINsVisterm = std::make_unique();
uINsVisterm->CalcUnsteadcoff();
- delete uINsVisterm;
}
void INsCalcSrc()
{
- UINsVisterm * uINsVisterm = new UINsVisterm();
+ auto uINsVisterm = std::make_unique();
uINsVisterm->CalcINsSrc();
- delete uINsVisterm;
}
void INsMomPre()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->MomPre();
- delete uINsInvterm;
}
void INsCalcFaceflux()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcFaceflux();
- delete uINsInvterm;
}
void INsCorrectPresscoef()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcCorrectPresscoef();
- delete uINsInvterm;
}
void INsCalcPressCorrectEquandUpdatePress()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->CalcPressCorrectEqu();
- delete uINsInvterm;
}
void INsUpdateFaceflux()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->UpdateFaceflux();
- delete uINsInvterm;
}
void INsCalcSpeedCorrectandUpdateSpeed()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->UpdateSpeed();
- delete uINsInvterm;
}
void INsUpdateRes()
{
- UINsInvterm * uINsInvterm = new UINsInvterm();
+ auto uINsInvterm = std::make_unique();
uINsInvterm->UpdateINsRes();
- delete uINsInvterm;
}
//void INsCorrectSpeed()
//{
-// UINsInvterm * uINsInvterm = new UINsInvterm();
+// auto uINsInvterm = std::make_unique();
// uINsInvterm->CalcCorrectSpeed();
-// delete uINsInvterm;
+//
//}
@@ -238,9 +225,9 @@ void INsCalcTurbEnergy()
//void INsCalcDualTimeStepSrc()
//{
-// UINsUnsteady * uinsUnsteady = new UINsUnsteady();
+// auto uinsUnsteady = std::make_unique();
// uinsUnsteady->CalcDualTimeSrc();
-// delete uinsUnsteady;
+//
//}
diff --git a/codes/ins/src/INsSolverImp.cpp b/codes/ins/src/INsSolverImp.cpp
index 599f765aa..e5b3bbd57 100644
--- a/codes/ins/src/INsSolverImp.cpp
+++ b/codes/ins/src/INsSolverImp.cpp
@@ -37,6 +37,7 @@ License
#include "TurbPlate.h"
#include "SolverRegister.h"
#include "DataBase.h"
+#include
BeginNameSpace( ONEFLOW )
@@ -95,16 +96,14 @@ void INsCalcBoundary( StringField & data )
void INsCalcTimeStep( StringField & data )
{
- UTimeStep * uTimeStep = new UTimeStep();
+ auto uTimeStep = std::make_unique();
uTimeStep->CalcTimeStep();
- delete uTimeStep;
}
void INsUpdateResiduals( StringField & data )
{
- Rhs * rhs = new INsRhs();
+ auto rhs = std::make_unique();
rhs->UpdateResiduals();
- delete rhs;
}
void INsImplicitMethod( StringField & data )
diff --git a/codes/ns/src/NsRhs.cpp b/codes/ns/src/NsRhs.cpp
index 24fd2f362..af3b849e2 100644
--- a/codes/ns/src/NsRhs.cpp
+++ b/codes/ns/src/NsRhs.cpp
@@ -37,6 +37,7 @@ License
#include "Ctrl.h"
#include
+#include
BeginNameSpace( ONEFLOW )
@@ -58,19 +59,17 @@ void NsRhs::UpdateResiduals()
void NsCalcBc()
{
- UNsBcSolver * uNsBcSolver = new UNsBcSolver();
+ auto uNsBcSolver = std::make_unique();
uNsBcSolver->Init();
uNsBcSolver->CalcBc();
- delete uNsBcSolver;
}
void NsCalcBcDebug( const std::string & title )
{
std::cout << title << "\n";
- UNsBcSolver * uNsBcSolver = new UNsBcSolver();
+ auto uNsBcSolver = std::make_unique();
uNsBcSolver->Init();
uNsBcSolver->CalcBc();
- delete uNsBcSolver;
}
@@ -110,16 +109,14 @@ void NsCalcRHS()
void NsCalcInvFlux()
{
- UNsInvFlux * uNsInvFlux = new UNsInvFlux();
+ auto uNsInvFlux = std::make_unique();
uNsInvFlux->CalcFlux();
- delete uNsInvFlux;
}
void NsCalcVisFlux()
{
- UNsVisFlux * uNsVisFlux = new UNsVisFlux();
+ auto uNsVisFlux = std::make_unique();
uNsVisFlux->CalcFlux();
- delete uNsVisFlux;
}
void NsCalcSrcFlux()
@@ -150,9 +147,8 @@ void NsCalcTurbEnergy()
void NsCalcDualTimeStepSrc()
{
- UNsUnsteady * unsUnsteady = new UNsUnsteady();
+ auto unsUnsteady = std::make_unique();
unsUnsteady->CalcDualTimeSrc();
- delete unsUnsteady;
}
EndNameSpace
diff --git a/codes/ns/src/NsSolverImp.cpp b/codes/ns/src/NsSolverImp.cpp
index b746e20b6..1512e1fff 100644
--- a/codes/ns/src/NsSolverImp.cpp
+++ b/codes/ns/src/NsSolverImp.cpp
@@ -39,6 +39,7 @@ License
#include "SolverRegister.h"
#include "DataBase.h"
#include
+#include
BeginNameSpace( ONEFLOW )
@@ -99,16 +100,14 @@ void NsCalcBoundary( StringField & data )
void NsCalcTimeStep( StringField & data )
{
- UTimeStep * uTimeStep = new UTimeStep();
+ auto uTimeStep = std::make_unique();
uTimeStep->CalcTimeStep();
- delete uTimeStep;
}
void NsUpdateResiduals( StringField & data )
{
- Rhs * rhs = new NsRhs();
+ auto rhs = std::make_unique();
rhs->UpdateResiduals();
- delete rhs;
}
void NsImplicitMethod( StringField & data )
diff --git a/codes/residual/src/ResidualTaskReg.cpp b/codes/residual/src/ResidualTaskReg.cpp
index bee50c92f..7bb18aa4d 100644
--- a/codes/residual/src/ResidualTaskReg.cpp
+++ b/codes/residual/src/ResidualTaskReg.cpp
@@ -46,9 +46,8 @@ void DumpResidual( StringField & data )
{
int solverType = SolverState::solverType;
- Residual * residual = new UResidual();
- residual->Dump( solverType );
- delete residual;
+ UResidual residual;
+ residual.Dump( solverType );
}
EndNameSpace
diff --git a/codes/scalar/src/ScalarGrid.cpp b/codes/scalar/src/ScalarGrid.cpp
index e42f253b7..3ba1a793b 100644
--- a/codes/scalar/src/ScalarGrid.cpp
+++ b/codes/scalar/src/ScalarGrid.cpp
@@ -548,13 +548,14 @@ void ScalarGrid::DumpCgnsGrid()
{
std::fstream file;
std::string prjFileName = Prj::GetPrjFileName( "scalar.cgns" );
- CgnsZbase * cgnsZbase = new CgnsZbase();
- cgnsZbase->nBases = 1;
- cgnsZbase->InitCgnsBase();
+ // FIX: Use stack allocation instead of raw pointer
+ CgnsZbase cgnsZbase;
+ cgnsZbase.nBases = 1;
+ cgnsZbase.InitCgnsBase();
- for ( int iBase = 0; iBase < cgnsZbase->nBases; ++ iBase )
+ for ( int iBase = 0; iBase < cgnsZbase.nBases; ++ iBase )
{
- CgnsBase * cgnsBase = cgnsZbase->GetCgnsBase( iBase );
+ CgnsBase * cgnsBase = cgnsZbase.GetCgnsBase( iBase );
cgnsBase->celldim = ONEFLOW::ONE_D;
cgnsBase->phydim = ONEFLOW::ONE_D;
@@ -567,20 +568,19 @@ void ScalarGrid::DumpCgnsGrid()
this->SetCgnsZone( cgnsZone );
}
- cgnsZbase->cgnsFile->OpenCgnsFile( prjFileName, CG_MODE_WRITE );
- cgnsZbase->DumpCgnsMultiBase();
- cgnsZbase->cgnsFile->CloseCgnsFile();
- delete cgnsZbase;
+ cgnsZbase.cgnsFile->OpenCgnsFile( prjFileName, CG_MODE_WRITE );
+ cgnsZbase.DumpCgnsMultiBase();
+ cgnsZbase.cgnsFile->CloseCgnsFile();
}
void ScalarGrid::GenerateGridFromCgns( const std::string & prjFileName )
{
- CgnsZbase * cgnsZbase = new CgnsZbase();
- cgnsZbase->OpenCgnsFile( prjFileName, CG_MODE_READ );
- cgnsZbase->ReadCgnsMultiBase();
- cgnsZbase->CloseCgnsFile();
- this->ReadFromCgnsZbase( cgnsZbase );
- delete cgnsZbase;
+ // FIX: Use stack allocation instead of raw pointer
+ CgnsZbase cgnsZbase;
+ cgnsZbase.OpenCgnsFile( prjFileName, CG_MODE_READ );
+ cgnsZbase.ReadCgnsMultiBase();
+ cgnsZbase.CloseCgnsFile();
+ this->ReadFromCgnsZbase( &cgnsZbase );
}
void ScalarGrid::ReadFromCgnsZbase( CgnsZbase * cgnsZbase )
@@ -590,7 +590,6 @@ void ScalarGrid::ReadFromCgnsZbase( CgnsZbase * cgnsZbase )
CgnsBase * cgnsBase = cgnsZbase->GetCgnsBase( 0 );
CgnsZone * cgnsZone = cgnsBase->GetCgnsZone( iZone );
this->ReadFromCgnsZone( cgnsZone );
-
}
void ScalarGrid::ReadFromCgnsZone( CgnsZone * cgnsZone )
diff --git a/codes/solver/include/SolverInfo.h b/codes/solver/include/SolverInfo.h
index 6f2cffc68..636456701 100644
--- a/codes/solver/include/SolverInfo.h
+++ b/codes/solver/include/SolverInfo.h
@@ -24,6 +24,7 @@ License
#pragma once
#include "HXDefine.h"
#include